split npe ethernet and hss patch, sync with upstream
[openwrt.git] / target / linux / ixp4xx / patches-2.6.24 / 017-nas100d_auto_power_on.patch
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)
5
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.
14
15 Signed-off-by: Rod Whitby <rod@whitby.id.au>
16 Acked-by: Lennert Buytenhek <buytenh@wantstofly.org>
17
18 PATCH FOLLOWS
19 KernelVersion: 2.6.24-git5
20
21 diff --git a/arch/arm/mach-ixp4xx/nas100d-power.c b/arch/arm/mach-ixp4xx/nas100d-power.c
22 index 29aa98d..4c1c01b 100644
23 --- a/arch/arm/mach-ixp4xx/nas100d-power.c
24 +++ b/arch/arm/mach-ixp4xx/nas100d-power.c
25 @@ -21,15 +21,59 @@
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>
31
32 +#include <asm/gpio.h>
33 #include <asm/mach-types.h>
34
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.
38 + */
39 +static int power_button_countdown;
40 +
41 +/* Must hold the button down for at least this many counts to be processed */
42 +#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
43 +
44 +static void nas100d_power_handler(unsigned long data);
45 +static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler, 0, 0);
46 +
47 +static void nas100d_power_handler(unsigned long data)
48 {
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.
53 */
54 - ctrl_alt_del();
55 +
56 + if (gpio_get_value(NAS100D_PB_GPIO)) {
57 +
58 + /* IO Pin is 1 (button pushed) */
59 + if (power_button_countdown > 0)
60 + power_button_countdown--;
61 +
62 + } else {
63 +
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.
69 + */
70 + ctrl_alt_del();
71 +
72 + /* Change the state of the power LED to "blink" */
73 + gpio_line_set(NAS100D_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
74 + } else {
75 + power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
76 + }
77 + }
78 +
79 + mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
80 +}
81 +
82 +static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
83 +{
84 + /* This is the paper-clip reset, it shuts the machine down directly. */
85 + machine_power_off();
86
87 return IRQ_HANDLED;
88 }
89 @@ -39,17 +83,30 @@ static int __init nas100d_power_init(void)
90 if (!(machine_is_nas100d()))
91 return 0;
92
93 - set_irq_type(NAS100D_RB_IRQ, IRQT_LOW);
94 + set_irq_type(gpio_to_irq(NAS100D_RB_GPIO), IRQT_LOW);
95
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) {
99
100 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
101 - NAS100D_RB_IRQ);
102 + gpio_to_irq(NAS100D_RB_GPIO));
103
104 return -EIO;
105 }
106
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.
110 + */
111 +
112 + /* Make sure that the power button GPIO is set up as an input */
113 + gpio_line_config(NAS100D_PB_GPIO, IXP4XX_GPIO_IN);
114 +
115 + /* Set the initial value for the power button IRQ handler */
116 + power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
117 +
118 + mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
119 +
120 return 0;
121 }
122
123 @@ -58,7 +115,9 @@ static void __exit nas100d_power_exit(void)
124 if (!(machine_is_nas100d()))
125 return;
126
127 - free_irq(NAS100D_RB_IRQ, NULL);
128 + del_timer_sync(&nas100d_power_timer);
129 +
130 + free_irq(gpio_to_irq(NAS100D_RB_GPIO), NULL);
131 }
132
133 module_init(nas100d_power_init);
134 diff --git a/arch/arm/mach-ixp4xx/nas100d-setup.c b/arch/arm/mach-ixp4xx/nas100d-setup.c
135 index 54d884f..213a4ce 100644
136 --- a/arch/arm/mach-ixp4xx/nas100d-setup.c
137 +++ b/arch/arm/mach-ixp4xx/nas100d-setup.c
138 @@ -43,20 +43,20 @@ static struct platform_device nas100d_flash = {
139 static struct resource nas100d_led_resources[] = {
140 {
141 .name = "wlan", /* green led */
142 - .start = 0,
143 - .end = 0,
144 + .start = NAS100D_LED_WLAN_GPIO,
145 + .end = NAS100D_LED_WLAN_GPIO,
146 .flags = IXP4XX_GPIO_LOW,
147 },
148 {
149 - .name = "ready", /* blue power led (off is flashing!) */
150 - .start = 15,
151 - .end = 15,
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,
156 },
157 {
158 .name = "disk", /* yellow led */
159 - .start = 3,
160 - .end = 3,
161 + .start = NAS100D_LED_DISK_GPIO,
162 + .end = NAS100D_LED_DISK_GPIO,
163 .flags = IXP4XX_GPIO_LOW,
164 },
165 };
166 diff --git a/include/asm-arm/arch-ixp4xx/nas100d.h b/include/asm-arm/arch-ixp4xx/nas100d.h
167 index 131e0a1..98d9378 100644
168 --- a/include/asm-arm/arch-ixp4xx/nas100d.h
169 +++ b/include/asm-arm/arch-ixp4xx/nas100d.h
170 @@ -38,15 +38,15 @@
171
172 /* Buttons */
173
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 */
178 +
179 +/* Power control */
180 +
181 #define NAS100D_PO_GPIO 12 /* power off */
182
183 -#define NAS100D_PB_IRQ IRQ_IXP4XX_GPIO14
184 -#define NAS100D_RB_IRQ IRQ_IXP4XX_GPIO4
185 +/* LEDs */
186
187 -/*
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)
191 -*/
192 +#define NAS100D_LED_WLAN_GPIO 0
193 +#define NAS100D_LED_DISK_GPIO 3
194 +#define NAS100D_LED_PWR_GPIO 15
195 --
196 1.5.2.5
197
This page took 0.052587 seconds and 5 git commands to generate.