ip22-reset.c 6.1 KB

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