power.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* power.c: Power management driver.
  2. *
  3. * Copyright (C) 1999, 2007, 2008 David S. Miller (davem@davemloft.net)
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/export.h>
  7. #include <linux/init.h>
  8. #include <linux/interrupt.h>
  9. #include <linux/reboot.h>
  10. #include <linux/of_device.h>
  11. #include <asm/prom.h>
  12. #include <asm/io.h>
  13. static void __iomem *power_reg;
  14. static irqreturn_t power_handler(int irq, void *dev_id)
  15. {
  16. orderly_poweroff(true);
  17. /* FIXME: Check registers for status... */
  18. return IRQ_HANDLED;
  19. }
  20. static int has_button_interrupt(unsigned int irq, struct device_node *dp)
  21. {
  22. if (irq == 0xffffffff)
  23. return 0;
  24. if (!of_find_property(dp, "button", NULL))
  25. return 0;
  26. return 1;
  27. }
  28. static int power_probe(struct platform_device *op)
  29. {
  30. struct resource *res = &op->resource[0];
  31. unsigned int irq = op->archdata.irqs[0];
  32. power_reg = of_ioremap(res, 0, 0x4, "power");
  33. printk(KERN_INFO "%s: Control reg at %llx\n",
  34. op->dev.of_node->name, res->start);
  35. if (has_button_interrupt(irq, op->dev.of_node)) {
  36. if (request_irq(irq,
  37. power_handler, 0, "power", NULL) < 0)
  38. printk(KERN_ERR "power: Cannot setup IRQ handler.\n");
  39. }
  40. return 0;
  41. }
  42. static const struct of_device_id power_match[] = {
  43. {
  44. .name = "power",
  45. },
  46. {},
  47. };
  48. static struct platform_driver power_driver = {
  49. .probe = power_probe,
  50. .driver = {
  51. .name = "power",
  52. .of_match_table = power_match,
  53. },
  54. };
  55. static int __init power_init(void)
  56. {
  57. return platform_driver_register(&power_driver);
  58. }
  59. device_initcall(power_init);