1 Upgrade the power and reset button handling for the NAS100D:
2 * Convert GPIO and IRQ handling to use the <asm/gpio.h> api.
3 * Perform the reset only after the power button has been held down
4 for at least two seconds. Do the reset on the release of the power
5 button, so that NAS devices which have been set to auto-power-on (by
6 bridging the power button) do not continuously power cycle.
7 * Remove all superflous constants from nas100d.h
8 * Add LED constants to nas100d.h while we're there.
9 Also, update the board LED setup code to use constants.
11 Signed-off-by: Rod Whitby <rod@whitby.id.au>
13 Index: linux-2.6.23.12-armeb/arch/arm/mach-ixp4xx/nas100d-power.c
14 ===================================================================
15 --- linux-2.6.23.12-armeb.orig/arch/arm/mach-ixp4xx/nas100d-power.c 2008-01-11 16:59:20.000000000 +1030
16 +++ linux-2.6.23.12-armeb/arch/arm/mach-ixp4xx/nas100d-power.c 2008-01-11 17:03:23.000000000 +1030
18 #include <linux/irq.h>
19 #include <linux/module.h>
20 #include <linux/reboot.h>
21 +#include <linux/jiffies.h>
22 +#include <linux/timer.h>
24 +#include <asm/gpio.h>
25 #include <asm/mach-types.h>
27 -static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
28 +extern void ctrl_alt_del(void);
30 +/* This is used to make sure the power-button pusher is serious. The button
31 + * must be held until the value of this counter reaches zero.
33 +static volatile int power_button_countdown;
35 +/* Must hold the button down for at least this many counts to be processed */
36 +#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
38 +static void nas100d_power_handler(unsigned long data);
39 +static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler, 0, 0);
41 +static void nas100d_power_handler(unsigned long data)
43 - /* Signal init to do the ctrlaltdel action, this will bypass init if
44 - * it hasn't started and do a kernel_restart.
45 + /* This routine is called twice per second to check the
46 + * state of the power button.
50 + if (gpio_get_value(NAS100D_PB_GPIO)) {
52 + /* IO Pin is 1 (button pushed) */
53 + if (power_button_countdown > 0) {
54 + power_button_countdown--;
59 + /* Done on button release, to allow for auto-power-on mods. */
60 + if (power_button_countdown == 0) {
61 + /* Signal init to do the ctrlaltdel action, this will bypass
62 + * init if it hasn't started and do a kernel_restart.
66 + /* Change the state of the power LED to "blink" */
67 + gpio_line_set(NAS100D_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
69 + power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
73 + mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
76 +static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
78 + /* This is the paper-clip reset, it shuts the machine down directly. */
79 + machine_power_off();
84 if (!(machine_is_nas100d()))
87 - set_irq_type(NAS100D_RB_IRQ, IRQT_LOW);
88 + set_irq_type(gpio_to_irq(NAS100D_RB_GPIO), IRQT_LOW);
90 - if (request_irq(NAS100D_RB_IRQ, &nas100d_reset_handler,
91 + if (request_irq(gpio_to_irq(NAS100D_RB_GPIO), &nas100d_reset_handler,
92 IRQF_DISABLED, "NAS100D reset button", NULL) < 0) {
94 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
96 + gpio_to_irq(NAS100D_RB_GPIO));
101 + /* The power button on the Iomega NAS100d is on GPIO 14, but
102 + * it cannot handle interrupts on that GPIO line. So we'll
103 + * have to poll it with a kernel timer.
106 + /* Make sure that the power button GPIO is set up as an input */
107 + gpio_line_config(NAS100D_PB_GPIO, IXP4XX_GPIO_IN);
109 + /* Set the initial value for the power button IRQ handler */
110 + power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
112 + mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
118 if (!(machine_is_nas100d()))
121 - free_irq(NAS100D_RB_IRQ, NULL);
122 + del_timer_sync(&nas100d_power_timer);
124 + free_irq(gpio_to_irq(NAS100D_RB_GPIO), NULL);
127 module_init(nas100d_power_init);
128 Index: linux-2.6.23.12-armeb/include/asm-arm/arch-ixp4xx/nas100d.h
129 ===================================================================
130 --- linux-2.6.23.12-armeb.orig/include/asm-arm/arch-ixp4xx/nas100d.h 2008-01-11 16:59:20.000000000 +1030
131 +++ linux-2.6.23.12-armeb/include/asm-arm/arch-ixp4xx/nas100d.h 2008-01-11 17:03:23.000000000 +1030
136 -#define NAS100D_PB_GPIO 14
137 -#define NAS100D_RB_GPIO 4
138 +#define NAS100D_PB_GPIO 14 /* power button */
139 +#define NAS100D_RB_GPIO 4 /* reset button */
143 #define NAS100D_PO_GPIO 12 /* power off */
145 -#define NAS100D_PB_IRQ IRQ_IXP4XX_GPIO14
146 -#define NAS100D_RB_IRQ IRQ_IXP4XX_GPIO4
150 -#define NAS100D_PB_BM (1L << NAS100D_PB_GPIO)
151 -#define NAS100D_PO_BM (1L << NAS100D_PO_GPIO)
152 -#define NAS100D_RB_BM (1L << NAS100D_RB_GPIO)
154 +#define NAS100D_LED_WLAN_GPIO 0
155 +#define NAS100D_LED_DISK_GPIO 3
156 +#define NAS100D_LED_PWR_GPIO 15
157 Index: linux-2.6.23.12-armeb/arch/arm/mach-ixp4xx/nas100d-setup.c
158 ===================================================================
159 --- linux-2.6.23.12-armeb.orig/arch/arm/mach-ixp4xx/nas100d-setup.c 2008-01-11 17:03:23.000000000 +1030
160 +++ linux-2.6.23.12-armeb/arch/arm/mach-ixp4xx/nas100d-setup.c 2008-01-11 17:06:15.000000000 +1030
162 static struct resource nas100d_led_resources[] = {
164 .name = "wlan", /* green led */
167 + .start = NAS100D_LED_WLAN_GPIO,
168 + .end = NAS100D_LED_WLAN_GPIO,
169 .flags = IXP4XX_GPIO_LOW,
172 - .name = "ready", /* blue power led (off is flashing!) */
175 + .name = "power", /* blue power led (off is flashing!) */
176 + .start = NAS100D_LED_PWR_GPIO,
177 + .end = NAS100D_LED_PWR_GPIO,
178 .flags = IXP4XX_GPIO_LOW,
181 .name = "disk", /* yellow led */
184 + .start = NAS100D_LED_DISK_GPIO,
185 + .end = NAS100D_LED_DISK_GPIO,
186 .flags = IXP4XX_GPIO_LOW,