]>
Commit | Line | Data |
---|---|---|
13077d80 | 1 | /* power.c: Power management driver. |
1da177e4 | 2 | * |
c510b9bf | 3 | * Copyright (C) 1999, 2007, 2008 David S. Miller (davem@davemloft.net) |
1da177e4 LT |
4 | */ |
5 | ||
1da177e4 LT |
6 | #include <linux/kernel.h> |
7 | #include <linux/module.h> | |
8 | #include <linux/init.h> | |
1da177e4 | 9 | #include <linux/interrupt.h> |
a3761780 | 10 | #include <linux/reboot.h> |
764f2579 | 11 | #include <linux/of_device.h> |
1da177e4 | 12 | |
abbce6e2 | 13 | #include <asm/prom.h> |
abbce6e2 | 14 | #include <asm/io.h> |
1da177e4 | 15 | |
1da177e4 LT |
16 | static void __iomem *power_reg; |
17 | ||
13077d80 DM |
18 | static irqreturn_t power_handler(int irq, void *dev_id) |
19 | { | |
a3761780 | 20 | orderly_poweroff(true); |
1da177e4 LT |
21 | |
22 | /* FIXME: Check registers for status... */ | |
23 | return IRQ_HANDLED; | |
24 | } | |
1da177e4 | 25 | |
19ab6db6 | 26 | static int __devinit has_button_interrupt(unsigned int irq, struct device_node *dp) |
1da177e4 | 27 | { |
13077d80 | 28 | if (irq == 0xffffffff) |
1da177e4 | 29 | return 0; |
690c8fd3 | 30 | if (!of_find_property(dp, "button", NULL)) |
1da177e4 LT |
31 | return 0; |
32 | ||
33 | return 1; | |
34 | } | |
35 | ||
4ebb24f7 | 36 | static int __devinit power_probe(struct platform_device *op) |
1da177e4 | 37 | { |
abbce6e2 | 38 | struct resource *res = &op->resource[0]; |
1636f8ac | 39 | unsigned int irq = op->archdata.irqs[0]; |
a2bd4fd1 | 40 | |
abbce6e2 DM |
41 | power_reg = of_ioremap(res, 0, 0x4, "power"); |
42 | ||
90181136 | 43 | printk(KERN_INFO "%s: Control reg at %llx\n", |
61c7a080 | 44 | op->dev.of_node->name, res->start); |
a2bd4fd1 | 45 | |
61c7a080 | 46 | if (has_button_interrupt(irq, op->dev.of_node)) { |
2256c13b | 47 | if (request_irq(irq, |
00cde674 | 48 | power_handler, 0, "power", NULL) < 0) |
13077d80 | 49 | printk(KERN_ERR "power: Cannot setup IRQ handler.\n"); |
1da177e4 | 50 | } |
abbce6e2 DM |
51 | |
52 | return 0; | |
1da177e4 | 53 | } |
a2bd4fd1 | 54 | |
3628aa06 | 55 | static const struct of_device_id power_match[] = { |
a2bd4fd1 DM |
56 | { |
57 | .name = "power", | |
58 | }, | |
59 | {}, | |
60 | }; | |
61 | ||
4ebb24f7 | 62 | static struct platform_driver power_driver = { |
abbce6e2 | 63 | .probe = power_probe, |
4018294b GL |
64 | .driver = { |
65 | .name = "power", | |
66 | .owner = THIS_MODULE, | |
67 | .of_match_table = power_match, | |
a2cd1558 | 68 | }, |
a2bd4fd1 DM |
69 | }; |
70 | ||
c510b9bf | 71 | static int __init power_init(void) |
a2bd4fd1 | 72 | { |
4ebb24f7 | 73 | return platform_driver_register(&power_driver); |
a2bd4fd1 | 74 | } |
c510b9bf DM |
75 | |
76 | device_initcall(power_init); |