]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/sparc64/kernel/power.c
[SPARC64] auxio: Remove asm/{sbus,ebus}.h includes.
[mirror_ubuntu-artful-kernel.git] / arch / sparc64 / kernel / power.c
CommitLineData
1da177e4
LT
1/* $Id: power.c,v 1.10 2001/12/11 01:57:16 davem Exp $
2 * power.c: Power management driver.
3 *
4 * Copyright (C) 1999 David S. Miller (davem@redhat.com)
5 */
6
bb49bcda
DM
7#define __KERNEL_SYSCALLS__
8
1da177e4
LT
9#include <linux/config.h>
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/sched.h>
14#include <linux/signal.h>
15#include <linux/delay.h>
16#include <linux/interrupt.h>
90bf8116 17#include <linux/pm.h>
1da177e4
LT
18
19#include <asm/system.h>
20#include <asm/ebus.h>
2256c13b 21#include <asm/isa.h>
1da177e4
LT
22#include <asm/auxio.h>
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 */
30int scons_pwroff = 1;
31
32#ifdef CONFIG_PCI
33static void __iomem *power_reg;
34
35static DECLARE_WAIT_QUEUE_HEAD(powerd_wait);
36static int button_pressed;
37
38static irqreturn_t power_handler(int irq, void *dev_id, struct pt_regs *regs)
39{
40 if (button_pressed == 0) {
41 button_pressed = 1;
42 wake_up(&powerd_wait);
43 }
44
45 /* FIXME: Check registers for status... */
46 return IRQ_HANDLED;
47}
48#endif /* CONFIG_PCI */
49
50extern void machine_halt(void);
51extern void machine_alt_power_off(void);
52static void (*poweroff_method)(void) = machine_alt_power_off;
53
54void machine_power_off(void)
55{
56 if (!serial_console || scons_pwroff) {
57#ifdef CONFIG_PCI
58 if (power_reg) {
59 /* Both register bits seem to have the
60 * same effect, so until I figure out
61 * what the difference is...
62 */
63 writel(AUXIO_PCIO_CPWR_OFF | AUXIO_PCIO_SPWR_OFF, power_reg);
64 } else
65#endif /* CONFIG_PCI */
66 if (poweroff_method != NULL) {
67 poweroff_method();
68 /* not reached */
69 }
70 }
71 machine_halt();
72}
73
90bf8116
DM
74void (*pm_power_off)(void) = machine_power_off;
75EXPORT_SYMBOL(pm_power_off);
76
1da177e4
LT
77#ifdef CONFIG_PCI
78static int powerd(void *__unused)
79{
80 static char *envp[] = { "HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
81 char *argv[] = { "/sbin/shutdown", "-h", "now", NULL };
82 DECLARE_WAITQUEUE(wait, current);
83
84 daemonize("powerd");
85
86 add_wait_queue(&powerd_wait, &wait);
87again:
88 for (;;) {
89 set_task_state(current, TASK_INTERRUPTIBLE);
90 if (button_pressed)
91 break;
92 flush_signals(current);
93 schedule();
94 }
95 __set_current_state(TASK_RUNNING);
96 remove_wait_queue(&powerd_wait, &wait);
97
98 /* Ok, down we go... */
99 button_pressed = 0;
100 if (execve("/sbin/shutdown", argv, envp) < 0) {
101 printk("powerd: shutdown execution failed\n");
102 add_wait_queue(&powerd_wait, &wait);
103 goto again;
104 }
105 return 0;
106}
107
690c8fd3 108static int __init has_button_interrupt(unsigned int irq, struct device_node *dp)
1da177e4 109{
2256c13b 110 if (irq == PCI_IRQ_NONE)
1da177e4 111 return 0;
690c8fd3 112 if (!of_find_property(dp, "button", NULL))
1da177e4
LT
113 return 0;
114
115 return 1;
116}
117
a2bd4fd1 118static void __devinit power_probe_common(struct of_device *dev, struct resource *res, unsigned int irq)
1da177e4 119{
2256c13b 120 power_reg = ioremap(res->start, 0x4);
a2bd4fd1 121
1da177e4 122 printk("power: Control reg at %p ... ", power_reg);
a2bd4fd1 123
1da177e4 124 poweroff_method = machine_halt; /* able to use the standard halt */
a2bd4fd1
DM
125
126 if (has_button_interrupt(irq, dev->node)) {
1da177e4
LT
127 if (kernel_thread(powerd, NULL, CLONE_FS) < 0) {
128 printk("Failed to start power daemon.\n");
129 return;
130 }
131 printk("powerd running.\n");
132
2256c13b 133 if (request_irq(irq,
00cde674 134 power_handler, 0, "power", NULL) < 0)
1da177e4
LT
135 printk("power: Error, cannot register IRQ handler.\n");
136 } else {
137 printk("not using powerd.\n");
138 }
139}
a2bd4fd1
DM
140
141static struct of_device_id power_match[] = {
142 {
143 .name = "power",
144 },
145 {},
146};
147
148static int __devinit ebus_power_probe(struct of_device *dev, const struct of_device_id *match)
149{
150 struct linux_ebus_device *edev = to_ebus_device(&dev->dev);
151 struct resource *res = &edev->resource[0];
152 unsigned int irq = edev->irqs[0];
153
154 power_probe_common(dev, res,irq);
155
156 return 0;
157}
158
159static struct of_platform_driver ebus_power_driver = {
160 .name = "power",
161 .match_table = power_match,
162 .probe = ebus_power_probe,
163};
164
165static int __devinit isa_power_probe(struct of_device *dev, const struct of_device_id *match)
166{
167 struct sparc_isa_device *idev = to_isa_device(&dev->dev);
168 struct resource *res = &idev->resource;
169 unsigned int irq = idev->irq;
170
171 power_probe_common(dev, res,irq);
172
173 return 0;
174}
175
176static struct of_platform_driver isa_power_driver = {
177 .name = "power",
178 .match_table = power_match,
179 .probe = isa_power_probe,
180};
181
182void __init power_init(void)
183{
184 of_register_driver(&ebus_power_driver, &ebus_bus_type);
185 of_register_driver(&isa_power_driver, &isa_bus_type);
186 return;
187}
1da177e4 188#endif /* CONFIG_PCI */