blob: 71eb4ccc4bc15e2a369b26d129526dd1a39e290d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Cobalt Reset operations
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 1995, 1996, 1997 by Ralf Baechle
9 * Copyright (C) 2001 by Liam Davies (ldavies@agile.tv)
10 */
Yoichi Yuasae86169f2007-10-01 19:45:05 +090011#include <linux/init.h>
Yoichi Yuasa3282bd32007-10-02 23:17:38 +090012#include <linux/io.h>
Yoichi Yuasacc50b672007-03-06 21:34:44 +090013#include <linux/jiffies.h>
Yoichi Yuasae86169f2007-10-01 19:45:05 +090014#include <linux/leds.h>
Yoichi Yuasacc50b672007-03-06 21:34:44 +090015
16#include <cobalt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Yoichi Yuasa3282bd32007-10-02 23:17:38 +090018#define RESET_PORT ((void __iomem *)CKSEG1ADDR(0x1c000000))
19#define RESET 0x0f
20
Yoichi Yuasae86169f2007-10-01 19:45:05 +090021DEFINE_LED_TRIGGER(power_off_led_trigger);
22
23static int __init ledtrig_power_off_init(void)
24{
25 led_trigger_register_simple("power-off", &power_off_led_trigger);
26 return 0;
27}
28device_initcall(ledtrig_power_off_init);
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030void cobalt_machine_halt(void)
31{
Ralf Baechlec4ed38a2005-02-21 16:18:36 +000032 int state, last, diff;
33 unsigned long mark;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Ralf Baechlec4ed38a2005-02-21 16:18:36 +000035 /*
Yoichi Yuasae86169f2007-10-01 19:45:05 +090036 * turn on power off LED on RaQ
Ralf Baechlec4ed38a2005-02-21 16:18:36 +000037 *
38 * restart if ENTER and SELECT are pressed
39 */
40
41 last = COBALT_KEY_PORT;
42
Yoichi Yuasae86169f2007-10-01 19:45:05 +090043 led_trigger_event(power_off_led_trigger, LED_FULL);
44
Ralf Baechlec4ed38a2005-02-21 16:18:36 +000045 for (state = 0;;) {
Ralf Baechlec4ed38a2005-02-21 16:18:36 +000046 diff = COBALT_KEY_PORT ^ last;
47 last ^= diff;
48
49 if((diff & (COBALT_KEY_ENTER | COBALT_KEY_SELECT)) && !(~last & (COBALT_KEY_ENTER | COBALT_KEY_SELECT)))
Yoichi Yuasa3282bd32007-10-02 23:17:38 +090050 writeb(RESET, RESET_PORT);
Ralf Baechlec4ed38a2005-02-21 16:18:36 +000051
52 for (mark = jiffies; jiffies - mark < HZ;)
53 ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 }
55}
56
Ralf Baechlec4ed38a2005-02-21 16:18:36 +000057void cobalt_machine_restart(char *command)
58{
Yoichi Yuasa3282bd32007-10-02 23:17:38 +090059 writeb(RESET, RESET_PORT);
Ralf Baechlec4ed38a2005-02-21 16:18:36 +000060
61 /* we should never get here */
62 cobalt_machine_halt();
63}