1 From 6261e59795d861f21f63878944900a3da713348c Mon Sep 17 00:00:00 2001
2 From: Rod Whitby <rod@whitby.id.au>
3 Date: Tue, 29 Jan 2008 09:53:46 +1030
4 Subject: ixp4xx: Button and LED updates for the nas100d board (Patch #4768)
6 * Convert GPIO and IRQ handling to use the <asm/gpio.h> api.
7 * Perform the reset only after the power button has been held down
8 for at least two seconds. Do the reset on the release of the power
9 button, so that NAS devices which have been set to auto-power-on (by
10 solder bridging the power button) do not continuously power cycle.
11 * Remove all superflous constants from nas100d.h
12 * Add LED constants to nas100d.h while we're there.
13 * Update the board LED setup code to use those constants.
15 Signed-off-by: Rod Whitby <rod@whitby.id.au>
16 Acked-by: Lennert Buytenhek <buytenh@wantstofly.org>
19 KernelVersion: 2.6.24-git5
21 Index: linux-2.6.24.7/arch/arm/mach-ixp4xx/nas100d-power.c
22 ===================================================================
23 --- linux-2.6.24.7.orig/arch/arm/mach-ixp4xx/nas100d-power.c
24 +++ linux-2.6.24.7/arch/arm/mach-ixp4xx/nas100d-power.c
26 #include <linux/irq.h>
27 #include <linux/module.h>
28 #include <linux/reboot.h>
29 +#include <linux/jiffies.h>
30 +#include <linux/timer.h>
32 +#include <asm/gpio.h>
33 #include <asm/mach-types.h>
35 -static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
36 +/* This is used to make sure the power-button pusher is serious. The button
37 + * must be held until the value of this counter reaches zero.
39 +static int power_button_countdown;
41 +/* Must hold the button down for at least this many counts to be processed */
42 +#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
44 +static void nas100d_power_handler(unsigned long data);
45 +static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler, 0, 0);
47 +static void nas100d_power_handler(unsigned long data)
49 - /* Signal init to do the ctrlaltdel action, this will bypass init if
50 - * it hasn't started and do a kernel_restart.
51 + /* This routine is called twice per second to check the
52 + * state of the power button.
56 + if (gpio_get_value(NAS100D_PB_GPIO)) {
58 + /* IO Pin is 1 (button pushed) */
59 + if (power_button_countdown > 0)
60 + power_button_countdown--;
64 + /* Done on button release, to allow for auto-power-on mods. */
65 + if (power_button_countdown == 0) {
66 + /* Signal init to do the ctrlaltdel action,
67 + * this will bypass init if it hasn't started
68 + * and do a kernel_restart.
72 + /* Change the state of the power LED to "blink" */
73 + gpio_line_set(NAS100D_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
75 + power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
79 + mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
82 +static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
84 + /* This is the paper-clip reset, it shuts the machine down directly. */
85 + machine_power_off();
89 @@ -39,17 +83,30 @@ static int __init nas100d_power_init(voi
90 if (!(machine_is_nas100d()))
93 - set_irq_type(NAS100D_RB_IRQ, IRQT_LOW);
94 + set_irq_type(gpio_to_irq(NAS100D_RB_GPIO), IRQT_LOW);
96 - if (request_irq(NAS100D_RB_IRQ, &nas100d_reset_handler,
97 + if (request_irq(gpio_to_irq(NAS100D_RB_GPIO), &nas100d_reset_handler,
98 IRQF_DISABLED, "NAS100D reset button", NULL) < 0) {
100 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
102 + gpio_to_irq(NAS100D_RB_GPIO));
107 + /* The power button on the Iomega NAS100d is on GPIO 14, but
108 + * it cannot handle interrupts on that GPIO line. So we'll
109 + * have to poll it with a kernel timer.
112 + /* Make sure that the power button GPIO is set up as an input */
113 + gpio_line_config(NAS100D_PB_GPIO, IXP4XX_GPIO_IN);
115 + /* Set the initial value for the power button IRQ handler */
116 + power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
118 + mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
123 @@ -58,7 +115,9 @@ static void __exit nas100d_power_exit(vo
124 if (!(machine_is_nas100d()))
127 - free_irq(NAS100D_RB_IRQ, NULL);
128 + del_timer_sync(&nas100d_power_timer);
130 + free_irq(gpio_to_irq(NAS100D_RB_GPIO), NULL);
133 module_init(nas100d_power_init);
134 Index: linux-2.6.24.7/arch/arm/mach-ixp4xx/nas100d-setup.c
135 ===================================================================
136 --- linux-2.6.24.7.orig/arch/arm/mach-ixp4xx/nas100d-setup.c
137 +++ linux-2.6.24.7/arch/arm/mach-ixp4xx/nas100d-setup.c
138 @@ -43,20 +43,20 @@ static struct platform_device nas100d_fl
139 static struct resource nas100d_led_resources[] = {
141 .name = "wlan", /* green led */
144 + .start = NAS100D_LED_WLAN_GPIO,
145 + .end = NAS100D_LED_WLAN_GPIO,
146 .flags = IXP4XX_GPIO_LOW,
149 - .name = "ready", /* blue power led (off is flashing!) */
152 + .name = "power", /* blue power led (off=flashing) */
153 + .start = NAS100D_LED_PWR_GPIO,
154 + .end = NAS100D_LED_PWR_GPIO,
155 .flags = IXP4XX_GPIO_LOW,
158 .name = "disk", /* yellow led */
161 + .start = NAS100D_LED_DISK_GPIO,
162 + .end = NAS100D_LED_DISK_GPIO,
163 .flags = IXP4XX_GPIO_LOW,
166 Index: linux-2.6.24.7/include/asm-arm/arch-ixp4xx/nas100d.h
167 ===================================================================
168 --- linux-2.6.24.7.orig/include/asm-arm/arch-ixp4xx/nas100d.h
169 +++ linux-2.6.24.7/include/asm-arm/arch-ixp4xx/nas100d.h
174 -#define NAS100D_PB_GPIO 14
175 -#define NAS100D_RB_GPIO 4
176 +#define NAS100D_PB_GPIO 14 /* power button */
177 +#define NAS100D_RB_GPIO 4 /* reset button */
181 #define NAS100D_PO_GPIO 12 /* power off */
183 -#define NAS100D_PB_IRQ IRQ_IXP4XX_GPIO14
184 -#define NAS100D_RB_IRQ IRQ_IXP4XX_GPIO4
188 -#define NAS100D_PB_BM (1L << NAS100D_PB_GPIO)
189 -#define NAS100D_PO_BM (1L << NAS100D_PO_GPIO)
190 -#define NAS100D_RB_BM (1L << NAS100D_RB_GPIO)
192 +#define NAS100D_LED_WLAN_GPIO 0
193 +#define NAS100D_LED_DISK_GPIO 3
194 +#define NAS100D_LED_PWR_GPIO 15