nslu2-power.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * arch/arm/mach-ixp4xx/nslu2-power.c
  3. *
  4. * NSLU2 Power/Reset driver
  5. *
  6. * Copyright (C) 2005 Tower Technologies
  7. *
  8. * based on nslu2-io.c
  9. * Copyright (C) 2004 Karen Spearel
  10. *
  11. * Author: Alessandro Zummo <a.zummo@towertech.it>
  12. * Maintainers: http://www.nslu2-linux.org/
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License version 2 as
  16. * published by the Free Software Foundation.
  17. *
  18. */
  19. #include <linux/module.h>
  20. #include <linux/reboot.h>
  21. #include <linux/irq.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/reboot.h>
  24. #include <asm/mach-types.h>
  25. static irqreturn_t nslu2_power_handler(int irq, void *dev_id)
  26. {
  27. /* Signal init to do the ctrlaltdel action, this will bypass init if
  28. * it hasn't started and do a kernel_restart.
  29. */
  30. ctrl_alt_del();
  31. return IRQ_HANDLED;
  32. }
  33. static irqreturn_t nslu2_reset_handler(int irq, void *dev_id)
  34. {
  35. /* This is the paper-clip reset, it shuts the machine down directly.
  36. */
  37. machine_power_off();
  38. return IRQ_HANDLED;
  39. }
  40. static int __init nslu2_power_init(void)
  41. {
  42. if (!(machine_is_nslu2()))
  43. return 0;
  44. *IXP4XX_GPIO_GPISR = 0x20400000; /* read the 2 irqs to clr */
  45. set_irq_type(NSLU2_RB_IRQ, IRQT_LOW);
  46. set_irq_type(NSLU2_PB_IRQ, IRQT_HIGH);
  47. if (request_irq(NSLU2_RB_IRQ, &nslu2_reset_handler,
  48. IRQF_DISABLED, "NSLU2 reset button", NULL) < 0) {
  49. printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
  50. NSLU2_RB_IRQ);
  51. return -EIO;
  52. }
  53. if (request_irq(NSLU2_PB_IRQ, &nslu2_power_handler,
  54. IRQF_DISABLED, "NSLU2 power button", NULL) < 0) {
  55. printk(KERN_DEBUG "Power Button IRQ %d not available\n",
  56. NSLU2_PB_IRQ);
  57. return -EIO;
  58. }
  59. return 0;
  60. }
  61. static void __exit nslu2_power_exit(void)
  62. {
  63. if (!(machine_is_nslu2()))
  64. return;
  65. free_irq(NSLU2_RB_IRQ, NULL);
  66. free_irq(NSLU2_PB_IRQ, NULL);
  67. }
  68. module_init(nslu2_power_init);
  69. module_exit(nslu2_power_exit);
  70. MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
  71. MODULE_DESCRIPTION("NSLU2 Power/Reset driver");
  72. MODULE_LICENSE("GPL");