fix ifxmips image file name (thx, nix)
[openwrt.git] / target / linux / ixp4xx / patches-2.6.23 / 017-nas100d_auto_power_on.patch
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.
10
11 Signed-off-by: Rod Whitby <rod@whitby.id.au>
12
13 Index: linux-2.6.23.17/arch/arm/mach-ixp4xx/nas100d-power.c
14 ===================================================================
15 --- linux-2.6.23.17.orig/arch/arm/mach-ixp4xx/nas100d-power.c
16 +++ linux-2.6.23.17/arch/arm/mach-ixp4xx/nas100d-power.c
17 @@ -21,15 +21,61 @@
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>
23
24 +#include <asm/gpio.h>
25 #include <asm/mach-types.h>
26
27 -static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
28 +extern void ctrl_alt_del(void);
29 +
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.
32 + */
33 +static volatile int power_button_countdown;
34 +
35 +/* Must hold the button down for at least this many counts to be processed */
36 +#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
37 +
38 +static void nas100d_power_handler(unsigned long data);
39 +static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler, 0, 0);
40 +
41 +static void nas100d_power_handler(unsigned long data)
42 {
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.
47 */
48 - ctrl_alt_del();
49 +
50 + if (gpio_get_value(NAS100D_PB_GPIO)) {
51 +
52 + /* IO Pin is 1 (button pushed) */
53 + if (power_button_countdown > 0) {
54 + power_button_countdown--;
55 + }
56 +
57 + } else {
58 +
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.
63 + */
64 + ctrl_alt_del();
65 +
66 + /* Change the state of the power LED to "blink" */
67 + gpio_line_set(NAS100D_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
68 + } else {
69 + power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
70 + }
71 + }
72 +
73 + mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
74 +}
75 +
76 +static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
77 +{
78 + /* This is the paper-clip reset, it shuts the machine down directly. */
79 + machine_power_off();
80
81 return IRQ_HANDLED;
82 }
83 @@ -39,17 +85,30 @@ static int __init nas100d_power_init(voi
84 if (!(machine_is_nas100d()))
85 return 0;
86
87 - set_irq_type(NAS100D_RB_IRQ, IRQT_LOW);
88 + set_irq_type(gpio_to_irq(NAS100D_RB_GPIO), IRQT_LOW);
89
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) {
93
94 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
95 - NAS100D_RB_IRQ);
96 + gpio_to_irq(NAS100D_RB_GPIO));
97
98 return -EIO;
99 }
100
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.
104 + */
105 +
106 + /* Make sure that the power button GPIO is set up as an input */
107 + gpio_line_config(NAS100D_PB_GPIO, IXP4XX_GPIO_IN);
108 +
109 + /* Set the initial value for the power button IRQ handler */
110 + power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
111 +
112 + mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
113 +
114 return 0;
115 }
116
117 @@ -58,7 +117,9 @@ static void __exit nas100d_power_exit(vo
118 if (!(machine_is_nas100d()))
119 return;
120
121 - free_irq(NAS100D_RB_IRQ, NULL);
122 + del_timer_sync(&nas100d_power_timer);
123 +
124 + free_irq(gpio_to_irq(NAS100D_RB_GPIO), NULL);
125 }
126
127 module_init(nas100d_power_init);
128 Index: linux-2.6.23.17/include/asm-arm/arch-ixp4xx/nas100d.h
129 ===================================================================
130 --- linux-2.6.23.17.orig/include/asm-arm/arch-ixp4xx/nas100d.h
131 +++ linux-2.6.23.17/include/asm-arm/arch-ixp4xx/nas100d.h
132 @@ -38,15 +38,15 @@
133
134 /* Buttons */
135
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 */
140 +
141 +/* Power control */
142 +
143 #define NAS100D_PO_GPIO 12 /* power off */
144
145 -#define NAS100D_PB_IRQ IRQ_IXP4XX_GPIO14
146 -#define NAS100D_RB_IRQ IRQ_IXP4XX_GPIO4
147 +/* LEDs */
148
149 -/*
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)
153 -*/
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.17/arch/arm/mach-ixp4xx/nas100d-setup.c
158 ===================================================================
159 --- linux-2.6.23.17.orig/arch/arm/mach-ixp4xx/nas100d-setup.c
160 +++ linux-2.6.23.17/arch/arm/mach-ixp4xx/nas100d-setup.c
161 @@ -42,20 +42,20 @@ static struct platform_device nas100d_fl
162 static struct resource nas100d_led_resources[] = {
163 {
164 .name = "wlan", /* green led */
165 - .start = 0,
166 - .end = 0,
167 + .start = NAS100D_LED_WLAN_GPIO,
168 + .end = NAS100D_LED_WLAN_GPIO,
169 .flags = IXP4XX_GPIO_LOW,
170 },
171 {
172 - .name = "ready", /* blue power led (off is flashing!) */
173 - .start = 15,
174 - .end = 15,
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,
179 },
180 {
181 .name = "disk", /* yellow led */
182 - .start = 3,
183 - .end = 3,
184 + .start = NAS100D_LED_DISK_GPIO,
185 + .end = NAS100D_LED_DISK_GPIO,
186 .flags = IXP4XX_GPIO_LOW,
187 },
188 };
This page took 0.052609 seconds and 5 git commands to generate.