ip22-reset.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:5k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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 by Ralf Baechle
  7.  */
  8. #include <linux/kernel.h>
  9. #include <linux/sched.h>
  10. #include <linux/notifier.h>
  11. #include <linux/timer.h>
  12. #include <asm/io.h>
  13. #include <asm/irq.h>
  14. #include <asm/system.h>
  15. #include <asm/reboot.h>
  16. #include <asm/ds1286.h>
  17. #include <asm/sgialib.h>
  18. #include <asm/sgi/sgihpc.h>
  19. #include <asm/sgi/sgint23.h>
  20. /*
  21.  * Just powerdown if init hasn't done after POWERDOWN_TIMEOUT seconds.
  22.  * I'm not sure if this feature is a good idea, for now it's here just to
  23.  * make the power button make behave just like under IRIX.
  24.  */
  25. #define POWERDOWN_TIMEOUT 120
  26. /*
  27.  * Blink frequency during reboot grace period and when paniced.
  28.  */
  29. #define POWERDOWN_FREQ (HZ / 4)
  30. #define PANIC_FREQ (HZ / 8)
  31. static unsigned char sgi_volume;
  32. static struct timer_list power_timer, blink_timer, debounce_timer, volume_timer;
  33. static int shuting_down = 0, has_paniced = 0, setup_done = 0;
  34. static void sgi_machine_restart(char *command) __attribute__((noreturn));
  35. static void sgi_machine_halt(void) __attribute__((noreturn));
  36. static void sgi_machine_power_off(void) __attribute__((noreturn));
  37. /* XXX How to pass the reboot command to the firmware??? */
  38. static void sgi_machine_restart(char *command)
  39. {
  40. if (shuting_down)
  41. sgi_machine_power_off();
  42. ArcReboot();
  43. }
  44. static void sgi_machine_halt(void)
  45. {
  46. if (shuting_down)
  47. sgi_machine_power_off();
  48. ArcEnterInteractiveMode();
  49. }
  50. static void sgi_machine_power_off(void)
  51. {
  52. unsigned char val;
  53. cli();
  54. /* Disable watchdog */
  55. val = CMOS_READ(RTC_CMD);
  56. CMOS_WRITE(val|RTC_WAM, RTC_CMD);
  57. CMOS_WRITE(0, RTC_WSEC);
  58. CMOS_WRITE(0, RTC_WHSEC);
  59. while(1) {
  60. hpc3mregs->panel=0xfe;
  61. /* Good bye cruel world ...  */
  62. /* If we're still running, we probably got sent an alarm
  63.    interrupt.  Read the flag to clear it.  */
  64. val = CMOS_READ(RTC_HOURS_ALARM);
  65. }
  66. }
  67. static void power_timeout(unsigned long data)
  68. {
  69. sgi_machine_power_off();
  70. }
  71. static void blink_timeout(unsigned long data)
  72. {
  73. /* XXX fix this for fullhouse  */
  74. sgi_hpc_write1 ^= (HPC3_WRITE1_LC0OFF|HPC3_WRITE1_LC1OFF);
  75. hpc3mregs->write1 = sgi_hpc_write1;
  76. mod_timer(&blink_timer, jiffies+data);
  77. }
  78. static void debounce(unsigned long data)
  79. {
  80. del_timer(&debounce_timer);
  81. if (ioc_icontrol->istat1 & 2) { /* Interrupt still being sent.  */
  82. debounce_timer.expires = jiffies + 5; /* 0.05s  */
  83. add_timer(&debounce_timer);
  84. hpc3mregs->panel = 0xf3;
  85. return;
  86. }
  87. if (has_paniced)
  88. ArcReboot();
  89. enable_irq(SGI_PANEL_IRQ);
  90. }
  91. static inline void power_button(void)
  92. {
  93. if (has_paniced)
  94. return;
  95. if (shuting_down || kill_proc(1, SIGINT, 1)) {
  96. /* No init process or button pressed twice.  */
  97. sgi_machine_power_off();
  98. }
  99. shuting_down = 1;
  100. blink_timer.data = POWERDOWN_FREQ;
  101. blink_timeout(POWERDOWN_FREQ);
  102. init_timer(&power_timer);
  103. power_timer.function = power_timeout;
  104. power_timer.expires = jiffies + POWERDOWN_TIMEOUT * HZ;
  105. add_timer(&power_timer);
  106. }
  107. void inline sgi_volume_set(unsigned char volume)
  108. {
  109. sgi_volume = volume;
  110. hpc3c0->pbus_extregs[2][0] = sgi_volume;
  111. hpc3c0->pbus_extregs[2][1] = sgi_volume;
  112. }
  113. void inline sgi_volume_get(unsigned char *volume)
  114. {
  115. *volume = sgi_volume;
  116. }
  117. static inline void volume_up_button(unsigned long data)
  118. {
  119. del_timer(&volume_timer);
  120. if (sgi_volume < 0xff)
  121. sgi_volume++;
  122. hpc3c0->pbus_extregs[2][0] = sgi_volume;
  123. hpc3c0->pbus_extregs[2][1] = sgi_volume;
  124. if (ioc_icontrol->istat1 & 2) {
  125. volume_timer.expires = jiffies + 1;
  126. add_timer(&volume_timer);
  127. }
  128. }
  129. static inline void volume_down_button(unsigned long data)
  130. {
  131. del_timer(&volume_timer);
  132. if (sgi_volume > 0)
  133. sgi_volume--;
  134. hpc3c0->pbus_extregs[2][0] = sgi_volume;
  135. hpc3c0->pbus_extregs[2][1] = sgi_volume;
  136. if (ioc_icontrol->istat1 & 2) {
  137. volume_timer.expires = jiffies + 1;
  138. add_timer(&volume_timer);
  139. }
  140. }
  141. static void panel_int(int irq, void *dev_id, struct pt_regs *regs)
  142. {
  143. unsigned int buttons;
  144. buttons = hpc3mregs->panel;
  145. hpc3mregs->panel = 0x03; /* power_interrupt | power_supply_on */
  146. if (ioc_icontrol->istat1 & 2) { /* Wait until interrupt goes away */
  147. disable_irq(SGI_PANEL_IRQ);
  148. init_timer(&debounce_timer);
  149. debounce_timer.function = debounce;
  150. debounce_timer.expires = jiffies + 5;
  151. add_timer(&debounce_timer);
  152. }
  153. if (!(buttons & 0x02)) /* Power button was pressed */
  154. power_button();
  155. if (!(buttons & 0x40)) { /* Volume up button was pressed */
  156. init_timer(&volume_timer);
  157. volume_timer.function = volume_up_button;
  158. volume_timer.expires = jiffies + 1;
  159. add_timer(&volume_timer);
  160. }
  161. if (!(buttons & 0x10)) { /* Volume down button was pressed */
  162. init_timer(&volume_timer);
  163. volume_timer.function = volume_down_button;
  164. volume_timer.expires = jiffies + 1;
  165. add_timer(&volume_timer);
  166. }
  167. }
  168. static int panic_event(struct notifier_block *this, unsigned long event,
  169.                       void *ptr)
  170. {
  171. if (has_paniced)
  172. return NOTIFY_DONE;
  173. has_paniced = 1;
  174. blink_timer.data = PANIC_FREQ;
  175. blink_timeout(PANIC_FREQ);
  176. return NOTIFY_DONE;
  177. }
  178. static struct notifier_block panic_block = {
  179. panic_event,
  180. NULL,
  181. 0
  182. };
  183. void indy_reboot_setup(void)
  184. {
  185. if (setup_done)
  186. return;
  187. setup_done = 1;
  188. _machine_restart = sgi_machine_restart;
  189. _machine_halt = sgi_machine_halt;
  190. _machine_power_off = sgi_machine_power_off;
  191. request_irq(SGI_PANEL_IRQ, panel_int, 0, "Front Panel", NULL);
  192. init_timer(&blink_timer);
  193. blink_timer.function = blink_timeout;
  194. notifier_chain_register(&panic_notifier_list, &panic_block);
  195. }