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>
18 #include <asm/system.h>
20 #include <asm/auxio.h>
22 #include <linux/unistd.h>
25 * sysctl - toggle power-off restriction for serial console
26 * systems in machine_power_off()
31 static void __iomem
*power_reg
;
33 static DECLARE_WAIT_QUEUE_HEAD(powerd_wait
);
34 static int button_pressed
;
36 static irqreturn_t
power_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
38 if (button_pressed
== 0) {
40 wake_up(&powerd_wait
);
43 /* FIXME: Check registers for status... */
46 #endif /* CONFIG_PCI */
48 extern void machine_halt(void);
49 extern void machine_alt_power_off(void);
50 static void (*poweroff_method
)(void) = machine_alt_power_off
;
52 void machine_power_off(void)
54 if (!serial_console
|| scons_pwroff
) {
57 /* Both register bits seem to have the
58 * same effect, so until I figure out
59 * what the difference is...
61 writel(AUXIO_PCIO_CPWR_OFF
| AUXIO_PCIO_SPWR_OFF
, power_reg
);
63 #endif /* CONFIG_PCI */
64 if (poweroff_method
!= NULL
) {
73 static int powerd(void *__unused
)
75 static char *envp
[] = { "HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL
};
76 char *argv
[] = { "/sbin/shutdown", "-h", "now", NULL
};
77 DECLARE_WAITQUEUE(wait
, current
);
81 add_wait_queue(&powerd_wait
, &wait
);
84 set_task_state(current
, TASK_INTERRUPTIBLE
);
87 flush_signals(current
);
90 __set_current_state(TASK_RUNNING
);
91 remove_wait_queue(&powerd_wait
, &wait
);
93 /* Ok, down we go... */
95 if (execve("/sbin/shutdown", argv
, envp
) < 0) {
96 printk("powerd: shutdown execution failed\n");
97 add_wait_queue(&powerd_wait
, &wait
);
103 static int __init
has_button_interrupt(struct linux_ebus_device
*edev
)
105 if (edev
->irqs
[0] == PCI_IRQ_NONE
)
107 if (!prom_node_has_property(edev
->prom_node
, "button"))
113 void __init
power_init(void)
115 struct linux_ebus
*ebus
;
116 struct linux_ebus_device
*edev
;
123 for_each_ebus(ebus
) {
124 for_each_ebusdev(edev
, ebus
) {
125 if (!strcmp(edev
->prom_name
, "power"))
132 power_reg
= ioremap(edev
->resource
[0].start
, 0x4);
133 printk("power: Control reg at %p ... ", power_reg
);
134 poweroff_method
= machine_halt
; /* able to use the standard halt */
135 if (has_button_interrupt(edev
)) {
136 if (kernel_thread(powerd
, NULL
, CLONE_FS
) < 0) {
137 printk("Failed to start power daemon.\n");
140 printk("powerd running.\n");
142 if (request_irq(edev
->irqs
[0],
143 power_handler
, SA_SHIRQ
, "power", NULL
) < 0)
144 printk("power: Error, cannot register IRQ handler.\n");
146 printk("not using powerd.\n");
149 #endif /* CONFIG_PCI */