power.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* power.c: Power management driver.
  2. *
  3. * Copyright (C) 1999, 2007 David S. Miller (davem@davemloft.net)
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/module.h>
  7. #include <linux/init.h>
  8. #include <linux/sched.h>
  9. #include <linux/signal.h>
  10. #include <linux/delay.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/pm.h>
  13. #include <linux/syscalls.h>
  14. #include <linux/reboot.h>
  15. #include <linux/of_device.h>
  16. #include <asm/system.h>
  17. #include <asm/auxio.h>
  18. #include <asm/prom.h>
  19. #include <asm/io.h>
  20. #include <asm/sstate.h>
  21. #include <asm/reboot.h>
  22. #include <linux/unistd.h>
  23. /*
  24. * sysctl - toggle power-off restriction for serial console
  25. * systems in machine_power_off()
  26. */
  27. int scons_pwroff = 1;
  28. static void __iomem *power_reg;
  29. static irqreturn_t power_handler(int irq, void *dev_id)
  30. {
  31. orderly_poweroff(true);
  32. /* FIXME: Check registers for status... */
  33. return IRQ_HANDLED;
  34. }
  35. static void (*poweroff_method)(void) = machine_alt_power_off;
  36. void machine_power_off(void)
  37. {
  38. sstate_poweroff();
  39. if (strcmp(of_console_device->type, "serial") || scons_pwroff) {
  40. if (power_reg) {
  41. /* Both register bits seem to have the
  42. * same effect, so until I figure out
  43. * what the difference is...
  44. */
  45. writel(AUXIO_PCIO_CPWR_OFF | AUXIO_PCIO_SPWR_OFF, power_reg);
  46. } else {
  47. if (poweroff_method != NULL) {
  48. poweroff_method();
  49. /* not reached */
  50. }
  51. }
  52. }
  53. machine_halt();
  54. }
  55. void (*pm_power_off)(void) = machine_power_off;
  56. EXPORT_SYMBOL(pm_power_off);
  57. static int __init has_button_interrupt(unsigned int irq, struct device_node *dp)
  58. {
  59. if (irq == 0xffffffff)
  60. return 0;
  61. if (!of_find_property(dp, "button", NULL))
  62. return 0;
  63. return 1;
  64. }
  65. static int __devinit power_probe(struct of_device *op, const struct of_device_id *match)
  66. {
  67. struct resource *res = &op->resource[0];
  68. unsigned int irq= op->irqs[0];
  69. power_reg = of_ioremap(res, 0, 0x4, "power");
  70. printk(KERN_INFO "%s: Control reg at %lx\n",
  71. op->node->name, res->start);
  72. poweroff_method = machine_halt; /* able to use the standard halt */
  73. if (has_button_interrupt(irq, op->node)) {
  74. if (request_irq(irq,
  75. power_handler, 0, "power", NULL) < 0)
  76. printk(KERN_ERR "power: Cannot setup IRQ handler.\n");
  77. }
  78. return 0;
  79. }
  80. static struct of_device_id power_match[] = {
  81. {
  82. .name = "power",
  83. },
  84. {},
  85. };
  86. static struct of_platform_driver power_driver = {
  87. .match_table = power_match,
  88. .probe = power_probe,
  89. .driver = {
  90. .name = "power",
  91. },
  92. };
  93. void __init power_init(void)
  94. {
  95. of_register_driver(&power_driver, &of_platform_bus_type);
  96. return;
  97. }