aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/sgi-ip32/ip32-reset.c
diff options
context:
space:
mode:
authorJoshua Kinard <kumba@gentoo.org>2015-04-16 15:49:09 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-04-17 09:04:11 -0400
commit15beb694c66146e1133b9ff81d54e3ef3daa1d7c (patch)
treede69c469d7f6260c51f8d22a6e0492c7f58f12f2 /arch/mips/sgi-ip32/ip32-reset.c
parent9e522c0d28d1418c2983ffbc3903f7bed3354180 (diff)
mips: ip32: add platform data hooks to use DS1685 driver
This modifies the IP32 (SGI O2) platform and reset code to utilize the new rtc-ds1685 driver. The old mc146818rtc.h header is removed and ip32_defconfig is updated as well. Signed-off-by: Joshua Kinard <kumba@gentoo.org> Acked-by: Ralf Baechle <ralf@linux-mips.org> Cc: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/mips/sgi-ip32/ip32-reset.c')
-rw-r--r--arch/mips/sgi-ip32/ip32-reset.c131
1 files changed, 39 insertions, 92 deletions
diff --git a/arch/mips/sgi-ip32/ip32-reset.c b/arch/mips/sgi-ip32/ip32-reset.c
index 44b3470a0bbb..8bd415c8729f 100644
--- a/arch/mips/sgi-ip32/ip32-reset.c
+++ b/arch/mips/sgi-ip32/ip32-reset.c
@@ -11,10 +11,11 @@
11#include <linux/compiler.h> 11#include <linux/compiler.h>
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/module.h>
14#include <linux/sched.h> 15#include <linux/sched.h>
15#include <linux/notifier.h> 16#include <linux/notifier.h>
16#include <linux/delay.h> 17#include <linux/delay.h>
17#include <linux/ds17287rtc.h> 18#include <linux/rtc/ds1685.h>
18#include <linux/interrupt.h> 19#include <linux/interrupt.h>
19#include <linux/pm.h> 20#include <linux/pm.h>
20 21
@@ -33,53 +34,40 @@
33#define POWERDOWN_FREQ (HZ / 4) 34#define POWERDOWN_FREQ (HZ / 4)
34#define PANIC_FREQ (HZ / 8) 35#define PANIC_FREQ (HZ / 8)
35 36
36static struct timer_list power_timer, blink_timer, debounce_timer; 37extern struct platform_device ip32_rtc_device;
37static int has_panicked, shuting_down;
38 38
39static void ip32_machine_restart(char *command) __noreturn; 39static struct timer_list power_timer, blink_timer;
40static void ip32_machine_halt(void) __noreturn; 40static int has_panicked, shutting_down;
41static void ip32_machine_power_off(void) __noreturn;
42 41
43static void ip32_machine_restart(char *cmd) 42static __noreturn void ip32_poweroff(void *data)
44{ 43{
45 crime->control = CRIME_CONTROL_HARD_RESET; 44 void (*poweroff_func)(struct platform_device *) =
46 while (1); 45 symbol_get(ds1685_rtc_poweroff);
47} 46
47#ifdef CONFIG_MODULES
48 /* If the first __symbol_get failed, our module wasn't loaded. */
49 if (!poweroff_func) {
50 request_module("rtc-ds1685");
51 poweroff_func = symbol_get(ds1685_rtc_poweroff);
52 }
53#endif
48 54
49static inline void ip32_machine_halt(void) 55 if (!poweroff_func)
50{ 56 pr_emerg("RTC not available for power-off. Spinning forever ...\n");
51 ip32_machine_power_off(); 57 else {
52} 58 (*poweroff_func)((struct platform_device *)data);
59 symbol_put(ds1685_rtc_poweroff);
60 }
53 61
54static void ip32_machine_power_off(void) 62 unreachable();
55{
56 unsigned char reg_a, xctrl_a, xctrl_b;
57
58 disable_irq(MACEISA_RTC_IRQ);
59 reg_a = CMOS_READ(RTC_REG_A);
60
61 /* setup for kickstart & wake-up (DS12287 Ref. Man. p. 19) */
62 reg_a &= ~DS_REGA_DV2;
63 reg_a |= DS_REGA_DV1;
64
65 CMOS_WRITE(reg_a | DS_REGA_DV0, RTC_REG_A);
66 wbflush();
67 xctrl_b = CMOS_READ(DS_B1_XCTRL4B)
68 | DS_XCTRL4B_ABE | DS_XCTRL4B_KFE;
69 CMOS_WRITE(xctrl_b, DS_B1_XCTRL4B);
70 xctrl_a = CMOS_READ(DS_B1_XCTRL4A) & ~DS_XCTRL4A_IFS;
71 CMOS_WRITE(xctrl_a, DS_B1_XCTRL4A);
72 wbflush();
73 /* adios amigos... */
74 CMOS_WRITE(xctrl_a | DS_XCTRL4A_PAB, DS_B1_XCTRL4A);
75 CMOS_WRITE(reg_a, RTC_REG_A);
76 wbflush();
77 while (1);
78} 63}
79 64
80static void power_timeout(unsigned long data) 65static void ip32_machine_restart(char *cmd) __noreturn;
66static void ip32_machine_restart(char *cmd)
81{ 67{
82 ip32_machine_power_off(); 68 msleep(20);
69 crime->control = CRIME_CONTROL_HARD_RESET;
70 unreachable();
83} 71}
84 72
85static void blink_timeout(unsigned long data) 73static void blink_timeout(unsigned long data)
@@ -89,44 +77,27 @@ static void blink_timeout(unsigned long data)
89 mod_timer(&blink_timer, jiffies + data); 77 mod_timer(&blink_timer, jiffies + data);
90} 78}
91 79
92static void debounce(unsigned long data) 80static void ip32_machine_halt(void)
93{ 81{
94 unsigned char reg_a, reg_c, xctrl_a; 82 ip32_poweroff(&ip32_rtc_device);
95 83}
96 reg_c = CMOS_READ(RTC_INTR_FLAGS);
97 reg_a = CMOS_READ(RTC_REG_A);
98 CMOS_WRITE(reg_a | DS_REGA_DV0, RTC_REG_A);
99 wbflush();
100 xctrl_a = CMOS_READ(DS_B1_XCTRL4A);
101 if ((xctrl_a & DS_XCTRL4A_IFS) || (reg_c & RTC_IRQF )) {
102 /* Interrupt still being sent. */
103 debounce_timer.expires = jiffies + 50;
104 add_timer(&debounce_timer);
105
106 /* clear interrupt source */
107 CMOS_WRITE(xctrl_a & ~DS_XCTRL4A_IFS, DS_B1_XCTRL4A);
108 CMOS_WRITE(reg_a & ~DS_REGA_DV0, RTC_REG_A);
109 return;
110 }
111 CMOS_WRITE(reg_a & ~DS_REGA_DV0, RTC_REG_A);
112
113 if (has_panicked)
114 ip32_machine_restart(NULL);
115 84
116 enable_irq(MACEISA_RTC_IRQ); 85static void power_timeout(unsigned long data)
86{
87 ip32_poweroff(&ip32_rtc_device);
117} 88}
118 89
119static inline void ip32_power_button(void) 90void ip32_prepare_poweroff(void)
120{ 91{
121 if (has_panicked) 92 if (has_panicked)
122 return; 93 return;
123 94
124 if (shuting_down || kill_cad_pid(SIGINT, 1)) { 95 if (shutting_down || kill_cad_pid(SIGINT, 1)) {
125 /* No init process or button pressed twice. */ 96 /* No init process or button pressed twice. */
126 ip32_machine_power_off(); 97 ip32_poweroff(&ip32_rtc_device);
127 } 98 }
128 99
129 shuting_down = 1; 100 shutting_down = 1;
130 blink_timer.data = POWERDOWN_FREQ; 101 blink_timer.data = POWERDOWN_FREQ;
131 blink_timeout(POWERDOWN_FREQ); 102 blink_timeout(POWERDOWN_FREQ);
132 103
@@ -136,27 +107,6 @@ static inline void ip32_power_button(void)
136 add_timer(&power_timer); 107 add_timer(&power_timer);
137} 108}
138 109
139static irqreturn_t ip32_rtc_int(int irq, void *dev_id)
140{
141 unsigned char reg_c;
142
143 reg_c = CMOS_READ(RTC_INTR_FLAGS);
144 if (!(reg_c & RTC_IRQF)) {
145 printk(KERN_WARNING
146 "%s: RTC IRQ without RTC_IRQF\n", __func__);
147 }
148 /* Wait until interrupt goes away */
149 disable_irq_nosync(MACEISA_RTC_IRQ);
150 init_timer(&debounce_timer);
151 debounce_timer.function = debounce;
152 debounce_timer.expires = jiffies + 50;
153 add_timer(&debounce_timer);
154
155 printk(KERN_DEBUG "Power button pressed\n");
156 ip32_power_button();
157 return IRQ_HANDLED;
158}
159
160static int panic_event(struct notifier_block *this, unsigned long event, 110static int panic_event(struct notifier_block *this, unsigned long event,
161 void *ptr) 111 void *ptr)
162{ 112{
@@ -190,15 +140,12 @@ static __init int ip32_reboot_setup(void)
190 140
191 _machine_restart = ip32_machine_restart; 141 _machine_restart = ip32_machine_restart;
192 _machine_halt = ip32_machine_halt; 142 _machine_halt = ip32_machine_halt;
193 pm_power_off = ip32_machine_power_off; 143 pm_power_off = ip32_machine_halt;
194 144
195 init_timer(&blink_timer); 145 init_timer(&blink_timer);
196 blink_timer.function = blink_timeout; 146 blink_timer.function = blink_timeout;
197 atomic_notifier_chain_register(&panic_notifier_list, &panic_block); 147 atomic_notifier_chain_register(&panic_notifier_list, &panic_block);
198 148
199 if (request_irq(MACEISA_RTC_IRQ, ip32_rtc_int, 0, "rtc", NULL))
200 panic("Can't allocate MACEISA RTC IRQ");
201
202 return 0; 149 return 0;
203} 150}
204 151