0001
0002
0003
0004
0005
0006
0007 #include <linux/kernel.h>
0008 #include <linux/export.h>
0009 #include <linux/init.h>
0010 #include <linux/interrupt.h>
0011 #include <linux/reboot.h>
0012 #include <linux/of_device.h>
0013
0014 #include <asm/prom.h>
0015 #include <asm/io.h>
0016
0017 static void __iomem *power_reg;
0018
0019 static irqreturn_t power_handler(int irq, void *dev_id)
0020 {
0021 orderly_poweroff(true);
0022
0023
0024 return IRQ_HANDLED;
0025 }
0026
0027 static int has_button_interrupt(unsigned int irq, struct device_node *dp)
0028 {
0029 if (irq == 0xffffffff)
0030 return 0;
0031 if (!of_find_property(dp, "button", NULL))
0032 return 0;
0033
0034 return 1;
0035 }
0036
0037 static int power_probe(struct platform_device *op)
0038 {
0039 struct resource *res = &op->resource[0];
0040 unsigned int irq = op->archdata.irqs[0];
0041
0042 power_reg = of_ioremap(res, 0, 0x4, "power");
0043
0044 printk(KERN_INFO "%pOFn: Control reg at %llx\n",
0045 op->dev.of_node, res->start);
0046
0047 if (has_button_interrupt(irq, op->dev.of_node)) {
0048 if (request_irq(irq,
0049 power_handler, 0, "power", NULL) < 0)
0050 printk(KERN_ERR "power: Cannot setup IRQ handler.\n");
0051 }
0052
0053 return 0;
0054 }
0055
0056 static const struct of_device_id power_match[] = {
0057 {
0058 .name = "power",
0059 },
0060 {},
0061 };
0062
0063 static struct platform_driver power_driver = {
0064 .probe = power_probe,
0065 .driver = {
0066 .name = "power",
0067 .of_match_table = power_match,
0068 },
0069 };
0070
0071 builtin_platform_driver(power_driver);