sparc: Annotate of_device_id arrays with const or __initdata.
[deliverable/linux.git] / arch / sparc64 / kernel / power.c
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/pm.h>
11 #include <linux/reboot.h>
12 #include <linux/of_device.h>
13
14 #include <asm/auxio.h>
15 #include <asm/prom.h>
16 #include <asm/io.h>
17 #include <asm/sstate.h>
18 #include <asm/reboot.h>
19
20 /*
21 * sysctl - toggle power-off restriction for serial console
22 * systems in machine_power_off()
23 */
24 int scons_pwroff = 1;
25
26 static void __iomem *power_reg;
27
28 static irqreturn_t power_handler(int irq, void *dev_id)
29 {
30 orderly_poweroff(true);
31
32 /* FIXME: Check registers for status... */
33 return IRQ_HANDLED;
34 }
35
36 static void (*poweroff_method)(void) = machine_alt_power_off;
37
38 void machine_power_off(void)
39 {
40 sstate_poweroff();
41 if (strcmp(of_console_device->type, "serial") || scons_pwroff) {
42 if (power_reg) {
43 /* Both register bits seem to have the
44 * same effect, so until I figure out
45 * what the difference is...
46 */
47 writel(AUXIO_PCIO_CPWR_OFF | AUXIO_PCIO_SPWR_OFF, power_reg);
48 } else {
49 if (poweroff_method != NULL) {
50 poweroff_method();
51 /* not reached */
52 }
53 }
54 }
55 machine_halt();
56 }
57
58 void (*pm_power_off)(void) = machine_power_off;
59 EXPORT_SYMBOL(pm_power_off);
60
61 static int __init has_button_interrupt(unsigned int irq, struct device_node *dp)
62 {
63 if (irq == 0xffffffff)
64 return 0;
65 if (!of_find_property(dp, "button", NULL))
66 return 0;
67
68 return 1;
69 }
70
71 static int __devinit power_probe(struct of_device *op, const struct of_device_id *match)
72 {
73 struct resource *res = &op->resource[0];
74 unsigned int irq= op->irqs[0];
75
76 power_reg = of_ioremap(res, 0, 0x4, "power");
77
78 printk(KERN_INFO "%s: Control reg at %lx\n",
79 op->node->name, res->start);
80
81 poweroff_method = machine_halt; /* able to use the standard halt */
82
83 if (has_button_interrupt(irq, op->node)) {
84 if (request_irq(irq,
85 power_handler, 0, "power", NULL) < 0)
86 printk(KERN_ERR "power: Cannot setup IRQ handler.\n");
87 }
88
89 return 0;
90 }
91
92 static struct of_device_id __initdata power_match[] = {
93 {
94 .name = "power",
95 },
96 {},
97 };
98
99 static struct of_platform_driver power_driver = {
100 .match_table = power_match,
101 .probe = power_probe,
102 .driver = {
103 .name = "power",
104 },
105 };
106
107 static int __init power_init(void)
108 {
109 return of_register_driver(&power_driver, &of_platform_bus_type);
110 }
111
112 device_initcall(power_init);
This page took 0.03881 seconds and 5 git commands to generate.