1 /* $Id: power.c,v 1.10 2001/12/11 01:57:16 davem Exp $
2 * power.c: Power management driver.
4 * Copyright (C) 1999 David S. Miller (davem@redhat.com)
7 #define __KERNEL_SYSCALLS__
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>
19 #include <asm/system.h>
22 #include <asm/auxio.h>
24 #include <linux/unistd.h>
27 * sysctl - toggle power-off restriction for serial console
28 * systems in machine_power_off()
33 static void __iomem *power_reg;
35 static DECLARE_WAIT_QUEUE_HEAD(powerd_wait);
36 static int button_pressed;
38 static irqreturn_t power_handler(int irq, void *dev_id, struct pt_regs *regs)
40 if (button_pressed == 0) {
42 wake_up(&powerd_wait);
45 /* FIXME: Check registers for status... */
48 #endif /* CONFIG_PCI */
50 extern void machine_halt(void);
51 extern void machine_alt_power_off(void);
52 static void (*poweroff_method)(void) = machine_alt_power_off;
54 void machine_power_off(void)
56 if (!serial_console || scons_pwroff) {
59 /* Both register bits seem to have the
60 * same effect, so until I figure out
61 * what the difference is...
63 writel(AUXIO_PCIO_CPWR_OFF | AUXIO_PCIO_SPWR_OFF, power_reg);
65 #endif /* CONFIG_PCI */
66 if (poweroff_method != NULL) {
74 void (*pm_power_off)(void) = machine_power_off;
75 EXPORT_SYMBOL(pm_power_off);
78 static int powerd(void *__unused)
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);
86 add_wait_queue(&powerd_wait, &wait);
89 set_task_state(current, TASK_INTERRUPTIBLE);
92 flush_signals(current);
95 __set_current_state(TASK_RUNNING);
96 remove_wait_queue(&powerd_wait, &wait);
98 /* Ok, down we go... */
100 if (execve("/sbin/shutdown", argv, envp) < 0) {
101 printk("powerd: shutdown execution failed\n");
102 add_wait_queue(&powerd_wait, &wait);
108 static int __init has_button_interrupt(unsigned int irq, struct device_node *dp)
110 if (irq == PCI_IRQ_NONE)
112 if (!of_find_property(dp, "button", NULL))
118 static void __devinit power_probe_common(struct of_device *dev, struct resource *res, unsigned int irq)
120 power_reg = ioremap(res->start, 0x4);
122 printk("power: Control reg at %p ... ", power_reg);
124 poweroff_method = machine_halt; /* able to use the standard halt */
126 if (has_button_interrupt(irq, dev->node)) {
127 if (kernel_thread(powerd, NULL, CLONE_FS) < 0) {
128 printk("Failed to start power daemon.\n");
131 printk("powerd running.\n");
134 power_handler, SA_SHIRQ, "power", NULL) < 0)
135 printk("power: Error, cannot register IRQ handler.\n");
137 printk("not using powerd.\n");
141 static struct of_device_id power_match[] = {
148 static int __devinit ebus_power_probe(struct of_device *dev, const struct of_device_id *match)
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];
154 power_probe_common(dev, res,irq);
159 static struct of_platform_driver ebus_power_driver = {
161 .match_table = power_match,
162 .probe = ebus_power_probe,
165 static int __devinit isa_power_probe(struct of_device *dev, const struct of_device_id *match)
167 struct sparc_isa_device *idev = to_isa_device(&dev->dev);
168 struct resource *res = &idev->resource;
169 unsigned int irq = idev->irq;
171 power_probe_common(dev, res,irq);
176 static struct of_platform_driver isa_power_driver = {
178 .match_table = power_match,
179 .probe = isa_power_probe,
182 void __init power_init(void)
184 of_register_driver(&ebus_power_driver, &ebus_bus_type);
185 of_register_driver(&isa_power_driver, &isa_bus_type);
188 #endif /* CONFIG_PCI */