blob: e2a045c235a10b9d3861e48b7af2e2acab7b50e1 [file] [log] [blame]
David S. Miller13077d82007-07-11 18:18:04 -07001/* power.c: Power management driver.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
David S. Millerc510b9b2008-08-30 01:18:56 -07003 * Copyright (C) 1999, 2007, 2008 David S. Miller (davem@davemloft.net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 */
5
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <linux/kernel.h>
7#include <linux/module.h>
8#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/interrupt.h>
David S. Millera3761782007-07-18 13:12:45 -070010#include <linux/reboot.h>
Stephen Rothwell764f2572008-08-07 15:33:36 -070011#include <linux/of_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
David S. Millerabbce6e2006-06-29 15:22:46 -070013#include <asm/prom.h>
David S. Millerabbce6e2006-06-29 15:22:46 -070014#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Linus Torvalds1da177e2005-04-16 15:20:36 -070016static void __iomem *power_reg;
17
David S. Miller13077d82007-07-11 18:18:04 -070018static irqreturn_t power_handler(int irq, void *dev_id)
19{
David S. Millera3761782007-07-18 13:12:45 -070020 orderly_poweroff(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22 /* FIXME: Check registers for status... */
23 return IRQ_HANDLED;
24}
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
David S. Miller19ab6db2009-04-07 00:47:44 -070026static int __devinit has_button_interrupt(unsigned int irq, struct device_node *dp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
David S. Miller13077d82007-07-11 18:18:04 -070028 if (irq == 0xffffffff)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 return 0;
David S. Miller690c8fd2006-06-22 19:12:03 -070030 if (!of_find_property(dp, "button", NULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 return 0;
32
33 return 1;
34}
35
David S. Millerabbce6e2006-06-29 15:22:46 -070036static int __devinit power_probe(struct of_device *op, const struct of_device_id *match)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
David S. Millerabbce6e2006-06-29 15:22:46 -070038 struct resource *res = &op->resource[0];
39 unsigned int irq= op->irqs[0];
David S. Millera2bd4fd2006-06-23 01:44:10 -070040
David S. Millerabbce6e2006-06-29 15:22:46 -070041 power_reg = of_ioremap(res, 0, 0x4, "power");
42
Sam Ravnborg90181132009-01-06 13:19:28 -080043 printk(KERN_INFO "%s: Control reg at %llx\n",
David S. Millerabbce6e2006-06-29 15:22:46 -070044 op->node->name, res->start);
David S. Millera2bd4fd2006-06-23 01:44:10 -070045
David S. Millerabbce6e2006-06-29 15:22:46 -070046 if (has_button_interrupt(irq, op->node)) {
David S. Miller2256c132005-10-06 20:43:54 -070047 if (request_irq(irq,
David S. Miller00cde672006-06-29 14:39:11 -070048 power_handler, 0, "power", NULL) < 0)
David S. Miller13077d82007-07-11 18:18:04 -070049 printk(KERN_ERR "power: Cannot setup IRQ handler.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 }
David S. Millerabbce6e2006-06-29 15:22:46 -070051
52 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053}
David S. Millera2bd4fd2006-06-23 01:44:10 -070054
David S. Millerfd098312008-08-31 01:23:17 -070055static struct of_device_id __initdata power_match[] = {
David S. Millera2bd4fd2006-06-23 01:44:10 -070056 {
57 .name = "power",
58 },
59 {},
60};
61
David S. Millerabbce6e2006-06-29 15:22:46 -070062static struct of_platform_driver power_driver = {
David S. Millera2bd4fd2006-06-23 01:44:10 -070063 .match_table = power_match,
David S. Millerabbce6e2006-06-29 15:22:46 -070064 .probe = power_probe,
Stephen Rothwella2cd1552007-10-10 23:27:34 -070065 .driver = {
66 .name = "power",
67 },
David S. Millera2bd4fd2006-06-23 01:44:10 -070068};
69
David S. Millerc510b9b2008-08-30 01:18:56 -070070static int __init power_init(void)
David S. Millera2bd4fd2006-06-23 01:44:10 -070071{
David S. Millerc510b9b2008-08-30 01:18:56 -070072 return of_register_driver(&power_driver, &of_platform_bus_type);
David S. Millera2bd4fd2006-06-23 01:44:10 -070073}
David S. Millerc510b9b2008-08-30 01:18:56 -070074
75device_initcall(power_init);