blob: f503a0d04b3b5e5f0a0867bcbf88efe86b02f9a5 [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 Yuasacc50b672007-03-06 21:34:44 +090012#include <linux/jiffies.h>
Yoichi Yuasae86169f2007-10-01 19:45:05 +090013#include <linux/leds.h>
Yoichi Yuasacc50b672007-03-06 21:34:44 +090014
15#include <cobalt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Yoichi Yuasae86169f2007-10-01 19:45:05 +090017DEFINE_LED_TRIGGER(power_off_led_trigger);
18
19static int __init ledtrig_power_off_init(void)
20{
21 led_trigger_register_simple("power-off", &power_off_led_trigger);
22 return 0;
23}
24device_initcall(ledtrig_power_off_init);
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026void cobalt_machine_halt(void)
27{
Ralf Baechlec4ed38a2005-02-21 16:18:36 +000028 int state, last, diff;
29 unsigned long mark;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Ralf Baechlec4ed38a2005-02-21 16:18:36 +000031 /*
Yoichi Yuasae86169f2007-10-01 19:45:05 +090032 * turn on power off LED on RaQ
Ralf Baechlec4ed38a2005-02-21 16:18:36 +000033 *
34 * restart if ENTER and SELECT are pressed
35 */
36
37 last = COBALT_KEY_PORT;
38
Yoichi Yuasae86169f2007-10-01 19:45:05 +090039 led_trigger_event(power_off_led_trigger, LED_FULL);
40
Ralf Baechlec4ed38a2005-02-21 16:18:36 +000041 for (state = 0;;) {
Ralf Baechlec4ed38a2005-02-21 16:18:36 +000042 diff = COBALT_KEY_PORT ^ last;
43 last ^= diff;
44
45 if((diff & (COBALT_KEY_ENTER | COBALT_KEY_SELECT)) && !(~last & (COBALT_KEY_ENTER | COBALT_KEY_SELECT)))
46 COBALT_LED_PORT = COBALT_LED_RESET;
47
48 for (mark = jiffies; jiffies - mark < HZ;)
49 ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 }
51}
52
Ralf Baechlec4ed38a2005-02-21 16:18:36 +000053void cobalt_machine_restart(char *command)
54{
55 COBALT_LED_PORT = COBALT_LED_RESET;
56
57 /* we should never get here */
58 cobalt_machine_halt();
59}
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061/*
62 * This triggers the luser mode device driver for the power switch ;-)
63 */
64void cobalt_machine_power_off(void)
65{
66 printk("You can switch the machine off now.\n");
67 cobalt_machine_halt();
68}