power.c 2.4 KB

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