ip22-reset.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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) 1997, 1998, 2001, 03, 05, 06 by Ralf Baechle
  7. */
  8. #include <linux/linkage.h>
  9. #include <linux/init.h>
  10. #include <linux/ds1286.h>
  11. #include <linux/module.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/kernel.h>
  14. #include <linux/sched.h>
  15. #include <linux/notifier.h>
  16. #include <linux/pm.h>
  17. #include <linux/timer.h>
  18. #include <asm/io.h>
  19. #include <asm/irq.h>
  20. #include <asm/system.h>
  21. #include <asm/reboot.h>
  22. #include <asm/sgialib.h>
  23. #include <asm/sgi/ioc.h>
  24. #include <asm/sgi/hpc3.h>
  25. #include <asm/sgi/mc.h>
  26. #include <asm/sgi/ip22.h>
  27. /*
  28. * Just powerdown if init hasn't done after POWERDOWN_TIMEOUT seconds.
  29. * I'm not sure if this feature is a good idea, for now it's here just to
  30. * make the power button make behave just like under IRIX.
  31. */
  32. #define POWERDOWN_TIMEOUT 120
  33. /*
  34. * Blink frequency during reboot grace period and when paniced.
  35. */
  36. #define POWERDOWN_FREQ (HZ / 4)
  37. #define PANIC_FREQ (HZ / 8)
  38. static struct timer_list power_timer, blink_timer, debounce_timer, volume_timer;
  39. #define MACHINE_PANICED 1
  40. #define MACHINE_SHUTTING_DOWN 2
  41. static int machine_state;
  42. static void ATTRIB_NORET sgi_machine_power_off(void)
  43. {
  44. unsigned int tmp;
  45. local_irq_disable();
  46. /* Disable watchdog */
  47. tmp = hpc3c0->rtcregs[RTC_CMD] & 0xff;
  48. hpc3c0->rtcregs[RTC_CMD] = tmp | RTC_WAM;
  49. hpc3c0->rtcregs[RTC_WSEC] = 0;
  50. hpc3c0->rtcregs[RTC_WHSEC] = 0;
  51. while (1) {
  52. sgioc->panel = ~SGIOC_PANEL_POWERON;
  53. /* Good bye cruel world ... */
  54. /* If we're still running, we probably got sent an alarm
  55. interrupt. Read the flag to clear it. */
  56. tmp = hpc3c0->rtcregs[RTC_HOURS_ALARM];
  57. }
  58. }
  59. static void ATTRIB_NORET sgi_machine_restart(char *command)
  60. {
  61. if (machine_state & MACHINE_SHUTTING_DOWN)
  62. sgi_machine_power_off();
  63. sgimc->cpuctrl0 |= SGIMC_CCTRL0_SYSINIT;
  64. while (1);
  65. }
  66. static void ATTRIB_NORET sgi_machine_halt(void)
  67. {
  68. if (machine_state & MACHINE_SHUTTING_DOWN)
  69. sgi_machine_power_off();
  70. ArcEnterInteractiveMode();
  71. }
  72. static void power_timeout(unsigned long data)
  73. {
  74. sgi_machine_power_off();
  75. }
  76. static void blink_timeout(unsigned long data)
  77. {
  78. /* XXX fix this for fullhouse */
  79. sgi_ioc_reset ^= (SGIOC_RESET_LC0OFF|SGIOC_RESET_LC1OFF);
  80. sgioc->reset = sgi_ioc_reset;
  81. mod_timer(&blink_timer, jiffies + data);
  82. }
  83. static void debounce(unsigned long data)
  84. {
  85. del_timer(&debounce_timer);
  86. if (sgint->istat1 & SGINT_ISTAT1_PWR) {
  87. /* Interrupt still being sent. */
  88. debounce_timer.expires = jiffies + (HZ / 20); /* 0.05s */
  89. add_timer(&debounce_timer);
  90. sgioc->panel = SGIOC_PANEL_POWERON | SGIOC_PANEL_POWERINTR |
  91. SGIOC_PANEL_VOLDNINTR | SGIOC_PANEL_VOLDNHOLD |
  92. SGIOC_PANEL_VOLUPINTR | SGIOC_PANEL_VOLUPHOLD;
  93. return;
  94. }
  95. if (machine_state & MACHINE_PANICED)
  96. sgimc->cpuctrl0 |= SGIMC_CCTRL0_SYSINIT;
  97. enable_irq(SGI_PANEL_IRQ);
  98. }
  99. static inline void power_button(void)
  100. {
  101. if (machine_state & MACHINE_PANICED)
  102. return;
  103. if ((machine_state & MACHINE_SHUTTING_DOWN) || kill_proc(1,SIGINT,1)) {
  104. /* No init process or button pressed twice. */
  105. sgi_machine_power_off();
  106. }
  107. machine_state |= MACHINE_SHUTTING_DOWN;
  108. blink_timer.data = POWERDOWN_FREQ;
  109. blink_timeout(POWERDOWN_FREQ);
  110. init_timer(&power_timer);
  111. power_timer.function = power_timeout;
  112. power_timer.expires = jiffies + POWERDOWN_TIMEOUT * HZ;
  113. add_timer(&power_timer);
  114. }
  115. void (*indy_volume_button)(int) = NULL;
  116. EXPORT_SYMBOL(indy_volume_button);
  117. static inline void volume_up_button(unsigned long data)
  118. {
  119. del_timer(&volume_timer);
  120. if (indy_volume_button)
  121. indy_volume_button(1);
  122. if (sgint->istat1 & SGINT_ISTAT1_PWR) {
  123. volume_timer.expires = jiffies + (HZ / 100);
  124. add_timer(&volume_timer);
  125. }
  126. }
  127. static inline void volume_down_button(unsigned long data)
  128. {
  129. del_timer(&volume_timer);
  130. if (indy_volume_button)
  131. indy_volume_button(-1);
  132. if (sgint->istat1 & SGINT_ISTAT1_PWR) {
  133. volume_timer.expires = jiffies + (HZ / 100);
  134. add_timer(&volume_timer);
  135. }
  136. }
  137. static irqreturn_t panel_int(int irq, void *dev_id, struct pt_regs *regs)
  138. {
  139. unsigned int buttons;
  140. buttons = sgioc->panel;
  141. sgioc->panel = SGIOC_PANEL_POWERON | SGIOC_PANEL_POWERINTR;
  142. if (sgint->istat1 & SGINT_ISTAT1_PWR) {
  143. /* Wait until interrupt goes away */
  144. disable_irq(SGI_PANEL_IRQ);
  145. init_timer(&debounce_timer);
  146. debounce_timer.function = debounce;
  147. debounce_timer.expires = jiffies + 5;
  148. add_timer(&debounce_timer);
  149. }
  150. /* Power button was pressed
  151. * ioc.ps page 22: "The Panel Register is called Power Control by Full
  152. * House. Only lowest 2 bits are used. Guiness uses upper four bits
  153. * for volume control". This is not true, all bits are pulled high
  154. * on fullhouse */
  155. if (ip22_is_fullhouse() || !(buttons & SGIOC_PANEL_POWERINTR)) {
  156. power_button();
  157. return IRQ_HANDLED;
  158. }
  159. /* TODO: mute/unmute */
  160. /* Volume up button was pressed */
  161. if (!(buttons & SGIOC_PANEL_VOLUPINTR)) {
  162. init_timer(&volume_timer);
  163. volume_timer.function = volume_up_button;
  164. volume_timer.expires = jiffies + (HZ / 100);
  165. add_timer(&volume_timer);
  166. }
  167. /* Volume down button was pressed */
  168. if (!(buttons & SGIOC_PANEL_VOLDNINTR)) {
  169. init_timer(&volume_timer);
  170. volume_timer.function = volume_down_button;
  171. volume_timer.expires = jiffies + (HZ / 100);
  172. add_timer(&volume_timer);
  173. }
  174. return IRQ_HANDLED;
  175. }
  176. static int panic_event(struct notifier_block *this, unsigned long event,
  177. void *ptr)
  178. {
  179. if (machine_state & MACHINE_PANICED)
  180. return NOTIFY_DONE;
  181. machine_state |= MACHINE_PANICED;
  182. blink_timer.data = PANIC_FREQ;
  183. blink_timeout(PANIC_FREQ);
  184. return NOTIFY_DONE;
  185. }
  186. static struct notifier_block panic_block = {
  187. .notifier_call = panic_event,
  188. };
  189. static int __init reboot_setup(void)
  190. {
  191. _machine_restart = sgi_machine_restart;
  192. _machine_halt = sgi_machine_halt;
  193. pm_power_off = sgi_machine_power_off;
  194. request_irq(SGI_PANEL_IRQ, panel_int, 0, "Front Panel", NULL);
  195. init_timer(&blink_timer);
  196. blink_timer.function = blink_timeout;
  197. atomic_notifier_chain_register(&panic_notifier_list, &panic_block);
  198. return 0;
  199. }
  200. subsys_initcall(reboot_setup);