blob: e2a2230b69f0d71e214f02adfe2289a74b3116ee [file] [log] [blame]
Alessandro Zummoa7918f32005-11-10 14:05:04 +00001/*
2 * arch/arm/mach-ixp4xx/nslu2-power.c
3 *
4 * NSLU2 Power/Reset driver
5 *
6 * Copyright (C) 2005 Tower Technologies
7 *
8 * based on nslu2-io.c
9 * Copyright (C) 2004 Karen Spearel
10 *
11 * Author: Alessandro Zummo <a.zummo@towertech.it>
12 * Maintainers: http://www.nslu2-linux.org/
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 *
18 */
19
20#include <linux/module.h>
21#include <linux/reboot.h>
22#include <linux/interrupt.h>
Adrian Bunk83cc5ed2006-06-25 05:47:41 -070023#include <linux/reboot.h>
Alessandro Zummoa7918f32005-11-10 14:05:04 +000024
25#include <asm/mach-types.h>
26
Alessandro Zummoa7918f32005-11-10 14:05:04 +000027static irqreturn_t nslu2_power_handler(int irq, void *dev_id, struct pt_regs *regs)
28{
29 /* Signal init to do the ctrlaltdel action, this will bypass init if
30 * it hasn't started and do a kernel_restart.
31 */
32 ctrl_alt_del();
33
34 return IRQ_HANDLED;
35}
36
37static irqreturn_t nslu2_reset_handler(int irq, void *dev_id, struct pt_regs *regs)
38{
39 /* This is the paper-clip reset, it shuts the machine down directly.
40 */
41 machine_power_off();
42
43 return IRQ_HANDLED;
44}
45
46static int __init nslu2_power_init(void)
47{
48 if (!(machine_is_nslu2()))
49 return 0;
50
51 *IXP4XX_GPIO_GPISR = 0x20400000; /* read the 2 irqs to clr */
52
53 set_irq_type(NSLU2_RB_IRQ, IRQT_LOW);
54 set_irq_type(NSLU2_PB_IRQ, IRQT_HIGH);
55
Alessandro Zummoa7918f32005-11-10 14:05:04 +000056 if (request_irq(NSLU2_RB_IRQ, &nslu2_reset_handler,
Thomas Gleixner52e405e2006-07-03 02:20:05 +020057 IRQF_DISABLED, "NSLU2 reset button", NULL) < 0) {
Alessandro Zummoa7918f32005-11-10 14:05:04 +000058
59 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
60 NSLU2_RB_IRQ);
61
62 return -EIO;
63 }
64
65 if (request_irq(NSLU2_PB_IRQ, &nslu2_power_handler,
Thomas Gleixner52e405e2006-07-03 02:20:05 +020066 IRQF_DISABLED, "NSLU2 power button", NULL) < 0) {
Alessandro Zummoa7918f32005-11-10 14:05:04 +000067
68 printk(KERN_DEBUG "Power Button IRQ %d not available\n",
69 NSLU2_PB_IRQ);
70
71 return -EIO;
72 }
73
74 return 0;
75}
76
77static void __exit nslu2_power_exit(void)
78{
Alessandro Zummod7353b22006-02-22 21:12:05 +000079 if (!(machine_is_nslu2()))
80 return;
81
Alessandro Zummoa7918f32005-11-10 14:05:04 +000082 free_irq(NSLU2_RB_IRQ, NULL);
83 free_irq(NSLU2_PB_IRQ, NULL);
84}
85
86module_init(nslu2_power_init);
87module_exit(nslu2_power_exit);
88
89MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
90MODULE_DESCRIPTION("NSLU2 Power/Reset driver");
91MODULE_LICENSE("GPL");