2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2001 Keith M Wesolowski
7 * Copyright (C) 2001 Paul Mundt
8 * Copyright (C) 2003 Guido Guenther <agx@sigxcpu.org>
11 #include <linux/compiler.h>
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/sched.h>
16 #include <linux/notifier.h>
17 #include <linux/delay.h>
18 #include <linux/rtc/ds1685.h>
19 #include <linux/interrupt.h>
22 #include <asm/addrspace.h>
24 #include <asm/reboot.h>
25 #include <asm/wbflush.h>
26 #include <asm/ip32/mace.h>
27 #include <asm/ip32/crime.h>
28 #include <asm/ip32/ip32_ints.h>
30 #define POWERDOWN_TIMEOUT 120
32 * Blink frequency during reboot grace period and when panicked.
34 #define POWERDOWN_FREQ (HZ / 4)
35 #define PANIC_FREQ (HZ / 8)
37 extern struct platform_device ip32_rtc_device
;
39 static struct timer_list power_timer
, blink_timer
;
40 static int has_panicked
, shutting_down
;
42 static __noreturn
void ip32_poweroff(void *data
)
44 void (*poweroff_func
)(struct platform_device
*) =
45 symbol_get(ds1685_rtc_poweroff
);
48 /* If the first __symbol_get failed, our module wasn't loaded. */
50 request_module("rtc-ds1685");
51 poweroff_func
= symbol_get(ds1685_rtc_poweroff
);
56 pr_emerg("RTC not available for power-off. Spinning forever ...\n");
58 (*poweroff_func
)((struct platform_device
*)data
);
59 symbol_put(ds1685_rtc_poweroff
);
65 static void ip32_machine_restart(char *cmd
) __noreturn
;
66 static void ip32_machine_restart(char *cmd
)
69 crime
->control
= CRIME_CONTROL_HARD_RESET
;
73 static void blink_timeout(unsigned long data
)
75 unsigned long led
= mace
->perif
.ctrl
.misc
^ MACEISA_LED_RED
;
76 mace
->perif
.ctrl
.misc
= led
;
77 mod_timer(&blink_timer
, jiffies
+ data
);
80 static void ip32_machine_halt(void)
82 ip32_poweroff(&ip32_rtc_device
);
85 static void power_timeout(unsigned long data
)
87 ip32_poweroff(&ip32_rtc_device
);
90 void ip32_prepare_poweroff(void)
95 if (shutting_down
|| kill_cad_pid(SIGINT
, 1)) {
96 /* No init process or button pressed twice. */
97 ip32_poweroff(&ip32_rtc_device
);
101 blink_timer
.data
= POWERDOWN_FREQ
;
102 blink_timeout(POWERDOWN_FREQ
);
104 init_timer(&power_timer
);
105 power_timer
.function
= power_timeout
;
106 power_timer
.expires
= jiffies
+ POWERDOWN_TIMEOUT
* HZ
;
107 add_timer(&power_timer
);
110 static int panic_event(struct notifier_block
*this, unsigned long event
,
119 /* turn off the green LED */
120 led
= mace
->perif
.ctrl
.misc
| MACEISA_LED_GREEN
;
121 mace
->perif
.ctrl
.misc
= led
;
123 blink_timer
.data
= PANIC_FREQ
;
124 blink_timeout(PANIC_FREQ
);
129 static struct notifier_block panic_block
= {
130 .notifier_call
= panic_event
,
133 static __init
int ip32_reboot_setup(void)
135 /* turn on the green led only */
136 unsigned long led
= mace
->perif
.ctrl
.misc
;
137 led
|= MACEISA_LED_RED
;
138 led
&= ~MACEISA_LED_GREEN
;
139 mace
->perif
.ctrl
.misc
= led
;
141 _machine_restart
= ip32_machine_restart
;
142 _machine_halt
= ip32_machine_halt
;
143 pm_power_off
= ip32_machine_halt
;
145 init_timer(&blink_timer
);
146 blink_timer
.function
= blink_timeout
;
147 atomic_notifier_chain_register(&panic_notifier_list
, &panic_block
);
152 subsys_initcall(ip32_reboot_setup
);