1 /* power.c: Power management driver.
3 * Copyright (C) 1999, 2007, 2008 David S. Miller (davem@davemloft.net)
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/init.h>
9 #include <linux/interrupt.h>
11 #include <linux/reboot.h>
12 #include <linux/of_device.h>
14 #include <asm/auxio.h>
17 #include <asm/sstate.h>
18 #include <asm/reboot.h>
21 * sysctl - toggle power-off restriction for serial console
22 * systems in machine_power_off()
26 static void __iomem *power_reg;
28 static irqreturn_t power_handler(int irq, void *dev_id)
30 orderly_poweroff(true);
32 /* FIXME: Check registers for status... */
36 static void (*poweroff_method)(void) = machine_alt_power_off;
38 void machine_power_off(void)
41 if (strcmp(of_console_device->type, "serial") || scons_pwroff) {
43 /* Both register bits seem to have the
44 * same effect, so until I figure out
45 * what the difference is...
47 writel(AUXIO_PCIO_CPWR_OFF | AUXIO_PCIO_SPWR_OFF, power_reg);
49 if (poweroff_method != NULL) {
58 void (*pm_power_off)(void) = machine_power_off;
59 EXPORT_SYMBOL(pm_power_off);
61 static int __init has_button_interrupt(unsigned int irq, struct device_node *dp)
63 if (irq == 0xffffffff)
65 if (!of_find_property(dp, "button", NULL))
71 static int __devinit power_probe(struct of_device *op, const struct of_device_id *match)
73 struct resource *res = &op->resource[0];
74 unsigned int irq= op->irqs[0];
76 power_reg = of_ioremap(res, 0, 0x4, "power");
78 printk(KERN_INFO "%s: Control reg at %lx\n",
79 op->node->name, res->start);
81 poweroff_method = machine_halt; /* able to use the standard halt */
83 if (has_button_interrupt(irq, op->node)) {
85 power_handler, 0, "power", NULL) < 0)
86 printk(KERN_ERR "power: Cannot setup IRQ handler.\n");
92 static struct of_device_id power_match[] = {
99 static struct of_platform_driver power_driver = {
100 .match_table = power_match,
101 .probe = power_probe,
107 static int __init power_init(void)
109 return of_register_driver(&power_driver, &of_platform_bus_type);
112 device_initcall(power_init);