power.c 2.5 KB

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