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