dsmg600-power.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * arch/arm/mach-ixp4xx/dsmg600-power.c
  3. *
  4. * DSM-G600 Power/Reset driver
  5. * Author: Michael Westerhof <mwester@dls.net>
  6. *
  7. * Based on nslu2-power.c
  8. * Copyright (C) 2005 Tower Technologies
  9. * Author: Alessandro Zummo <a.zummo@towertech.it>
  10. *
  11. * which was based on nslu2-io.c
  12. * Copyright (C) 2004 Karen Spearel
  13. *
  14. * Maintainers: http://www.nslu2-linux.org/
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License version 2 as
  18. * published by the Free Software Foundation.
  19. *
  20. */
  21. #include <linux/module.h>
  22. #include <linux/reboot.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/irq.h>
  25. #include <linux/jiffies.h>
  26. #include <linux/timer.h>
  27. #include <asm/mach-types.h>
  28. extern void ctrl_alt_del(void);
  29. /* This is used to make sure the power-button pusher is serious. The button
  30. * must be held until the value of this counter reaches zero.
  31. */
  32. static volatile int power_button_countdown;
  33. /* Must hold the button down for at least this many counts to be processed */
  34. #define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
  35. static void dsmg600_power_handler(unsigned long data);
  36. static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0);
  37. static void dsmg600_power_handler(unsigned long data)
  38. {
  39. /* This routine is called twice per second to check the
  40. * state of the power button.
  41. */
  42. if (*IXP4XX_GPIO_GPINR & DSMG600_PB_BM) {
  43. /* IO Pin is 1 (button pushed) */
  44. if (power_button_countdown == 0) {
  45. /* Signal init to do the ctrlaltdel action, this will bypass
  46. * init if it hasn't started and do a kernel_restart.
  47. */
  48. ctrl_alt_del();
  49. /* Change the state of the power LED to "blink" */
  50. gpio_line_set(DSMG600_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
  51. }
  52. power_button_countdown--;
  53. } else {
  54. power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
  55. }
  56. mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
  57. }
  58. static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id)
  59. {
  60. /* This is the paper-clip reset, it shuts the machine down directly. */
  61. machine_power_off();
  62. return IRQ_HANDLED;
  63. }
  64. static int __init dsmg600_power_init(void)
  65. {
  66. if (!(machine_is_dsmg600()))
  67. return 0;
  68. if (request_irq(DSMG600_RB_IRQ, &dsmg600_reset_handler,
  69. IRQF_DISABLED | IRQF_TRIGGER_LOW, "DSM-G600 reset button",
  70. NULL) < 0) {
  71. printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
  72. DSMG600_RB_IRQ);
  73. return -EIO;
  74. }
  75. /* The power button on the D-Link DSM-G600 is on GPIO 15, but
  76. * it cannot handle interrupts on that GPIO line. So we'll
  77. * have to poll it with a kernel timer.
  78. */
  79. /* Make sure that the power button GPIO is set up as an input */
  80. gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN);
  81. /* Set the initial value for the power button IRQ handler */
  82. power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
  83. mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
  84. return 0;
  85. }
  86. static void __exit dsmg600_power_exit(void)
  87. {
  88. if (!(machine_is_dsmg600()))
  89. return;
  90. del_timer_sync(&dsmg600_power_timer);
  91. free_irq(DSMG600_RB_IRQ, NULL);
  92. }
  93. module_init(dsmg600_power_init);
  94. module_exit(dsmg600_power_exit);
  95. MODULE_AUTHOR("Michael Westerhof <mwester@dls.net>");
  96. MODULE_DESCRIPTION("DSM-G600 Power/Reset driver");
  97. MODULE_LICENSE("GPL");