ip22-reset.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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/rtc/ds1286.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/kernel.h>
  13. #include <linux/sched/signal.h>
  14. #include <linux/notifier.h>
  15. #include <linux/pm.h>
  16. #include <linux/timer.h>
  17. #include <asm/io.h>
  18. #include <asm/irq.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 panicked.
  33. */
  34. #define POWERDOWN_FREQ (HZ / 4)
  35. #define PANIC_FREQ (HZ / 8)
  36. static struct timer_list power_timer, blink_timer, debounce_timer;
  37. static unsigned long blink_timer_timeout;
  38. #define MACHINE_PANICED 1
  39. #define MACHINE_SHUTTING_DOWN 2
  40. static int machine_state;
  41. static void __noreturn sgi_machine_power_off(void)
  42. {
  43. unsigned int tmp;
  44. local_irq_disable();
  45. /* Disable watchdog */
  46. tmp = hpc3c0->rtcregs[RTC_CMD] & 0xff;
  47. hpc3c0->rtcregs[RTC_CMD] = tmp | RTC_WAM;
  48. hpc3c0->rtcregs[RTC_WSEC] = 0;
  49. hpc3c0->rtcregs[RTC_WHSEC] = 0;
  50. while (1) {
  51. sgioc->panel = ~SGIOC_PANEL_POWERON;
  52. /* Good bye cruel world ... */
  53. /* If we're still running, we probably got sent an alarm
  54. interrupt. Read the flag to clear it. */
  55. tmp = hpc3c0->rtcregs[RTC_HOURS_ALARM];
  56. }
  57. }
  58. static void __noreturn sgi_machine_restart(char *command)
  59. {
  60. if (machine_state & MACHINE_SHUTTING_DOWN)
  61. sgi_machine_power_off();
  62. sgimc->cpuctrl0 |= SGIMC_CCTRL0_SYSINIT;
  63. while (1);
  64. }
  65. static void __noreturn sgi_machine_halt(void)
  66. {
  67. if (machine_state & MACHINE_SHUTTING_DOWN)
  68. sgi_machine_power_off();
  69. ArcEnterInteractiveMode();
  70. }
  71. static void power_timeout(struct timer_list *unused)
  72. {
  73. sgi_machine_power_off();
  74. }
  75. static void blink_timeout(struct timer_list *unused)
  76. {
  77. /* XXX fix this for fullhouse */
  78. sgi_ioc_reset ^= (SGIOC_RESET_LC0OFF|SGIOC_RESET_LC1OFF);
  79. sgioc->reset = sgi_ioc_reset;
  80. mod_timer(&blink_timer, jiffies + blink_timer_timeout);
  81. }
  82. static void debounce(struct timer_list *unused)
  83. {
  84. del_timer(&debounce_timer);
  85. if (sgint->istat1 & SGINT_ISTAT1_PWR) {
  86. /* Interrupt still being sent. */
  87. debounce_timer.expires = jiffies + (HZ / 20); /* 0.05s */
  88. add_timer(&debounce_timer);
  89. sgioc->panel = SGIOC_PANEL_POWERON | SGIOC_PANEL_POWERINTR |
  90. SGIOC_PANEL_VOLDNINTR | SGIOC_PANEL_VOLDNHOLD |
  91. SGIOC_PANEL_VOLUPINTR | SGIOC_PANEL_VOLUPHOLD;
  92. return;
  93. }
  94. if (machine_state & MACHINE_PANICED)
  95. sgimc->cpuctrl0 |= SGIMC_CCTRL0_SYSINIT;
  96. enable_irq(SGI_PANEL_IRQ);
  97. }
  98. static inline void power_button(void)
  99. {
  100. if (machine_state & MACHINE_PANICED)
  101. return;
  102. if ((machine_state & MACHINE_SHUTTING_DOWN) ||
  103. kill_cad_pid(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_timeout = POWERDOWN_FREQ;
  109. blink_timeout(&blink_timer);
  110. timer_setup(&power_timer, power_timeout, 0);
  111. power_timer.expires = jiffies + POWERDOWN_TIMEOUT * HZ;
  112. add_timer(&power_timer);
  113. }
  114. static irqreturn_t panel_int(int irq, void *dev_id)
  115. {
  116. unsigned int buttons;
  117. buttons = sgioc->panel;
  118. sgioc->panel = SGIOC_PANEL_POWERON | SGIOC_PANEL_POWERINTR;
  119. if (sgint->istat1 & SGINT_ISTAT1_PWR) {
  120. /* Wait until interrupt goes away */
  121. disable_irq_nosync(SGI_PANEL_IRQ);
  122. timer_setup(&debounce_timer, debounce, 0);
  123. debounce_timer.expires = jiffies + 5;
  124. add_timer(&debounce_timer);
  125. }
  126. /* Power button was pressed
  127. * ioc.ps page 22: "The Panel Register is called Power Control by Full
  128. * House. Only lowest 2 bits are used. Guiness uses upper four bits
  129. * for volume control". This is not true, all bits are pulled high
  130. * on fullhouse */
  131. if (!(buttons & SGIOC_PANEL_POWERINTR))
  132. power_button();
  133. return IRQ_HANDLED;
  134. }
  135. static int panic_event(struct notifier_block *this, unsigned long event,
  136. void *ptr)
  137. {
  138. if (machine_state & MACHINE_PANICED)
  139. return NOTIFY_DONE;
  140. machine_state |= MACHINE_PANICED;
  141. blink_timer_timeout = PANIC_FREQ;
  142. blink_timeout(&blink_timer);
  143. return NOTIFY_DONE;
  144. }
  145. static struct notifier_block panic_block = {
  146. .notifier_call = panic_event,
  147. };
  148. static int __init reboot_setup(void)
  149. {
  150. int res;
  151. _machine_restart = sgi_machine_restart;
  152. _machine_halt = sgi_machine_halt;
  153. pm_power_off = sgi_machine_power_off;
  154. res = request_irq(SGI_PANEL_IRQ, panel_int, 0, "Front Panel", NULL);
  155. if (res) {
  156. printk(KERN_ERR "Allocation of front panel IRQ failed\n");
  157. return res;
  158. }
  159. timer_setup(&blink_timer, blink_timeout, 0);
  160. atomic_notifier_chain_register(&panic_notifier_list, &panic_block);
  161. return 0;
  162. }
  163. subsys_initcall(reboot_setup);