Commit | Line | Data |
---|---|---|
13077d80 | 1 | /* power.c: Power management driver. |
1da177e4 | 2 | * |
13077d80 | 3 | * Copyright (C) 1999, 2007 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> | |
9 | #include <linux/sched.h> | |
10 | #include <linux/signal.h> | |
11 | #include <linux/delay.h> | |
12 | #include <linux/interrupt.h> | |
90bf8116 | 13 | #include <linux/pm.h> |
67608567 | 14 | #include <linux/syscalls.h> |
a3761780 | 15 | #include <linux/reboot.h> |
1da177e4 LT |
16 | |
17 | #include <asm/system.h> | |
1da177e4 | 18 | #include <asm/auxio.h> |
abbce6e2 DM |
19 | #include <asm/prom.h> |
20 | #include <asm/of_device.h> | |
21 | #include <asm/io.h> | |
22d6a1cb | 22 | #include <asm/sstate.h> |
1da177e4 | 23 | |
1da177e4 LT |
24 | #include <linux/unistd.h> |
25 | ||
26 | /* | |
27 | * sysctl - toggle power-off restriction for serial console | |
28 | * systems in machine_power_off() | |
29 | */ | |
30 | int scons_pwroff = 1; | |
31 | ||
1da177e4 LT |
32 | static void __iomem *power_reg; |
33 | ||
13077d80 DM |
34 | static irqreturn_t power_handler(int irq, void *dev_id) |
35 | { | |
a3761780 | 36 | orderly_poweroff(true); |
1da177e4 LT |
37 | |
38 | /* FIXME: Check registers for status... */ | |
39 | return IRQ_HANDLED; | |
40 | } | |
1da177e4 LT |
41 | |
42 | extern void machine_halt(void); | |
43 | extern void machine_alt_power_off(void); | |
44 | static void (*poweroff_method)(void) = machine_alt_power_off; | |
45 | ||
46 | void machine_power_off(void) | |
47 | { | |
22d6a1cb | 48 | sstate_poweroff(); |
c73fcc84 | 49 | if (strcmp(of_console_device->type, "serial") || scons_pwroff) { |
1da177e4 LT |
50 | if (power_reg) { |
51 | /* Both register bits seem to have the | |
52 | * same effect, so until I figure out | |
53 | * what the difference is... | |
54 | */ | |
55 | writel(AUXIO_PCIO_CPWR_OFF | AUXIO_PCIO_SPWR_OFF, power_reg); | |
13077d80 | 56 | } else { |
1da177e4 LT |
57 | if (poweroff_method != NULL) { |
58 | poweroff_method(); | |
59 | /* not reached */ | |
60 | } | |
13077d80 | 61 | } |
1da177e4 LT |
62 | } |
63 | machine_halt(); | |
64 | } | |
65 | ||
90bf8116 DM |
66 | void (*pm_power_off)(void) = machine_power_off; |
67 | EXPORT_SYMBOL(pm_power_off); | |
68 | ||
690c8fd3 | 69 | static int __init has_button_interrupt(unsigned int irq, struct device_node *dp) |
1da177e4 | 70 | { |
13077d80 | 71 | if (irq == 0xffffffff) |
1da177e4 | 72 | return 0; |
690c8fd3 | 73 | if (!of_find_property(dp, "button", NULL)) |
1da177e4 LT |
74 | return 0; |
75 | ||
76 | return 1; | |
77 | } | |
78 | ||
abbce6e2 | 79 | static int __devinit power_probe(struct of_device *op, const struct of_device_id *match) |
1da177e4 | 80 | { |
abbce6e2 DM |
81 | struct resource *res = &op->resource[0]; |
82 | unsigned int irq= op->irqs[0]; | |
a2bd4fd1 | 83 | |
abbce6e2 DM |
84 | power_reg = of_ioremap(res, 0, 0x4, "power"); |
85 | ||
2a263021 | 86 | printk(KERN_INFO "%s: Control reg at %lx\n", |
abbce6e2 | 87 | op->node->name, res->start); |
a2bd4fd1 | 88 | |
1da177e4 | 89 | poweroff_method = machine_halt; /* able to use the standard halt */ |
a2bd4fd1 | 90 | |
abbce6e2 | 91 | if (has_button_interrupt(irq, op->node)) { |
2256c13b | 92 | if (request_irq(irq, |
00cde674 | 93 | power_handler, 0, "power", NULL) < 0) |
13077d80 | 94 | printk(KERN_ERR "power: Cannot setup IRQ handler.\n"); |
1da177e4 | 95 | } |
abbce6e2 DM |
96 | |
97 | return 0; | |
1da177e4 | 98 | } |
a2bd4fd1 DM |
99 | |
100 | static struct of_device_id power_match[] = { | |
101 | { | |
102 | .name = "power", | |
103 | }, | |
104 | {}, | |
105 | }; | |
106 | ||
abbce6e2 | 107 | static struct of_platform_driver power_driver = { |
a2bd4fd1 DM |
108 | .name = "power", |
109 | .match_table = power_match, | |
abbce6e2 | 110 | .probe = power_probe, |
a2bd4fd1 DM |
111 | }; |
112 | ||
113 | void __init power_init(void) | |
114 | { | |
37b7754a | 115 | of_register_driver(&power_driver, &of_platform_bus_type); |
a2bd4fd1 DM |
116 | return; |
117 | } |