~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/mips/sgi-ip32/ip32-reset.c

Version: ~ [ linux-5.4 ] ~ [ linux-5.3.13 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.86 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.156 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.203 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.202 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.78 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  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
  4  * for more details.
  5  *
  6  * Copyright (C) 2001 Keith M Wesolowski
  7  * Copyright (C) 2001 Paul Mundt
  8  * Copyright (C) 2003 Guido Guenther <agx@sigxcpu.org>
  9  */
 10 
 11 #include <linux/init.h>
 12 #include <linux/kernel.h>
 13 #include <linux/sched.h>
 14 #include <linux/notifier.h>
 15 #include <linux/delay.h>
 16 #include <linux/ds17287rtc.h>
 17 #include <linux/interrupt.h>
 18 #include <linux/pm.h>
 19 
 20 #include <asm/addrspace.h>
 21 #include <asm/irq.h>
 22 #include <asm/reboot.h>
 23 #include <asm/wbflush.h>
 24 #include <asm/ip32/mace.h>
 25 #include <asm/ip32/crime.h>
 26 #include <asm/ip32/ip32_ints.h>
 27 
 28 #define POWERDOWN_TIMEOUT       120
 29 /*
 30  * Blink frequency during reboot grace period and when panicked.
 31  */
 32 #define POWERDOWN_FREQ          (HZ / 4)
 33 #define PANIC_FREQ              (HZ / 8)
 34 
 35 static struct timer_list power_timer, blink_timer, debounce_timer;
 36 static int has_panicked, shuting_down;
 37 
 38 static void ip32_machine_restart(char *command) __attribute__((noreturn));
 39 static void ip32_machine_halt(void) __attribute__((noreturn));
 40 static void ip32_machine_power_off(void) __attribute__((noreturn));
 41 
 42 static void ip32_machine_restart(char *cmd)
 43 {
 44         crime->control = CRIME_CONTROL_HARD_RESET;
 45         while (1);
 46 }
 47 
 48 static inline void ip32_machine_halt(void)
 49 {
 50         ip32_machine_power_off();
 51 }
 52 
 53 static void ip32_machine_power_off(void)
 54 {
 55         unsigned char reg_a, xctrl_a, xctrl_b;
 56 
 57         disable_irq(MACEISA_RTC_IRQ);
 58         reg_a = CMOS_READ(RTC_REG_A);
 59 
 60         /* setup for kickstart & wake-up (DS12287 Ref. Man. p. 19) */
 61         reg_a &= ~DS_REGA_DV2;
 62         reg_a |= DS_REGA_DV1;
 63 
 64         CMOS_WRITE(reg_a | DS_REGA_DV0, RTC_REG_A);
 65         wbflush();
 66         xctrl_b = CMOS_READ(DS_B1_XCTRL4B)
 67                    | DS_XCTRL4B_ABE | DS_XCTRL4B_KFE;
 68         CMOS_WRITE(xctrl_b, DS_B1_XCTRL4B);
 69         xctrl_a = CMOS_READ(DS_B1_XCTRL4A) & ~DS_XCTRL4A_IFS;
 70         CMOS_WRITE(xctrl_a, DS_B1_XCTRL4A);
 71         wbflush();
 72         /* adios amigos... */
 73         CMOS_WRITE(xctrl_a | DS_XCTRL4A_PAB, DS_B1_XCTRL4A);
 74         CMOS_WRITE(reg_a, RTC_REG_A);
 75         wbflush();
 76         while (1);
 77 }
 78 
 79 static void power_timeout(unsigned long data)
 80 {
 81         ip32_machine_power_off();
 82 }
 83 
 84 static void blink_timeout(unsigned long data)
 85 {
 86         unsigned long led = mace->perif.ctrl.misc ^ MACEISA_LED_RED;
 87         mace->perif.ctrl.misc = led;
 88         mod_timer(&blink_timer, jiffies + data);
 89 }
 90 
 91 static void debounce(unsigned long data)
 92 {
 93         unsigned char reg_a, reg_c, xctrl_a;
 94 
 95         reg_c = CMOS_READ(RTC_INTR_FLAGS);
 96         reg_a = CMOS_READ(RTC_REG_A);
 97         CMOS_WRITE(reg_a | DS_REGA_DV0, RTC_REG_A);
 98         wbflush();
 99         xctrl_a = CMOS_READ(DS_B1_XCTRL4A);
100         if ((xctrl_a & DS_XCTRL4A_IFS) || (reg_c & RTC_IRQF )) {
101                 /* Interrupt still being sent. */
102                 debounce_timer.expires = jiffies + 50;
103                 add_timer(&debounce_timer);
104 
105                 /* clear interrupt source */
106                 CMOS_WRITE(xctrl_a & ~DS_XCTRL4A_IFS, DS_B1_XCTRL4A);
107                 CMOS_WRITE(reg_a & ~DS_REGA_DV0, RTC_REG_A);
108                 return;
109         }
110         CMOS_WRITE(reg_a & ~DS_REGA_DV0, RTC_REG_A);
111 
112         if (has_panicked)
113                 ip32_machine_restart(NULL);
114 
115         enable_irq(MACEISA_RTC_IRQ);
116 }
117 
118 static inline void ip32_power_button(void)
119 {
120         if (has_panicked)
121                 return;
122 
123         if (shuting_down || kill_cad_pid(SIGINT, 1)) {
124                 /* No init process or button pressed twice.  */
125                 ip32_machine_power_off();
126         }
127 
128         shuting_down = 1;
129         blink_timer.data = POWERDOWN_FREQ;
130         blink_timeout(POWERDOWN_FREQ);
131 
132         init_timer(&power_timer);
133         power_timer.function = power_timeout;
134         power_timer.expires = jiffies + POWERDOWN_TIMEOUT * HZ;
135         add_timer(&power_timer);
136 }
137 
138 static irqreturn_t ip32_rtc_int(int irq, void *dev_id)
139 {
140         unsigned char reg_c;
141 
142         reg_c = CMOS_READ(RTC_INTR_FLAGS);
143         if (!(reg_c & RTC_IRQF)) {
144                 printk(KERN_WARNING
145                         "%s: RTC IRQ without RTC_IRQF\n", __func__);
146         }
147         /* Wait until interrupt goes away */
148         disable_irq_nosync(MACEISA_RTC_IRQ);
149         init_timer(&debounce_timer);
150         debounce_timer.function = debounce;
151         debounce_timer.expires = jiffies + 50;
152         add_timer(&debounce_timer);
153 
154         printk(KERN_DEBUG "Power button pressed\n");
155         ip32_power_button();
156         return IRQ_HANDLED;
157 }
158 
159 static int panic_event(struct notifier_block *this, unsigned long event,
160                        void *ptr)
161 {
162         unsigned long led;
163 
164         if (has_panicked)
165                 return NOTIFY_DONE;
166         has_panicked = 1;
167 
168         /* turn off the green LED */
169         led = mace->perif.ctrl.misc | MACEISA_LED_GREEN;
170         mace->perif.ctrl.misc = led;
171 
172         blink_timer.data = PANIC_FREQ;
173         blink_timeout(PANIC_FREQ);
174 
175         return NOTIFY_DONE;
176 }
177 
178 static struct notifier_block panic_block = {
179         .notifier_call = panic_event,
180 };
181 
182 static __init int ip32_reboot_setup(void)
183 {
184         /* turn on the green led only */
185         unsigned long led = mace->perif.ctrl.misc;
186         led |= MACEISA_LED_RED;
187         led &= ~MACEISA_LED_GREEN;
188         mace->perif.ctrl.misc = led;
189 
190         _machine_restart = ip32_machine_restart;
191         _machine_halt = ip32_machine_halt;
192         pm_power_off = ip32_machine_power_off;
193 
194         init_timer(&blink_timer);
195         blink_timer.function = blink_timeout;
196         atomic_notifier_chain_register(&panic_notifier_list, &panic_block);
197 
198         if (request_irq(MACEISA_RTC_IRQ, ip32_rtc_int, 0, "rtc", NULL))
199                 panic("Can't allocate MACEISA RTC IRQ");
200 
201         return 0;
202 }
203 
204 subsys_initcall(ip32_reboot_setup);
205 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp