[ixp4xx] refresh kernel patches
[openwrt.git] / target / linux / ixp4xx / patches-2.6.24 / 032-subsume_power_files.patch
1 From: Rod Whitby <rod@whitby.id.au>
2 Subject: ixp4xx: Merge nslu2-power.c into nslu2-setup.c (Patch #4807)
3
4 There is no reason to have power control in a separate file from the
5 board setup code.  Merge it back into the board setup file, removing
6 superfluous header includes and removing superfluous constants from
7 the machine header file.
8
9 Signed-off-by: Rod Whitby <rod@whitby.id.au>
10 --
11 PATCH FOLLOWS
12 KernelVersion: v2.6.24-1917-gaf66bd3
13
14 Index: linux-2.6.24.7/arch/arm/mach-ixp4xx/Makefile
15 ===================================================================
16 --- linux-2.6.24.7.orig/arch/arm/mach-ixp4xx/Makefile
17 +++ linux-2.6.24.7/arch/arm/mach-ixp4xx/Makefile
18 @@ -26,7 +26,7 @@ obj-$(CONFIG_ARCH_ADI_COYOTE) += coyote-
19  obj-$(CONFIG_MACH_GTWX5715)    += gtwx5715-setup.o
20  obj-$(CONFIG_MACH_NSLU2)       += nslu2-setup.o
21  obj-$(CONFIG_MACH_NAS100D)     += nas100d-setup.o
22 -obj-$(CONFIG_MACH_DSMG600)      += dsmg600-setup.o dsmg600-power.o
23 +obj-$(CONFIG_MACH_DSMG600)      += dsmg600-setup.o
24  obj-$(CONFIG_MACH_GATEWAY7001) += gateway7001-setup.o
25  obj-$(CONFIG_MACH_WG302V2)     += wg302v2-setup.o
26  obj-$(CONFIG_MACH_FSG)         += fsg-setup.o
27 Index: linux-2.6.24.7/arch/arm/mach-ixp4xx/nslu2-power.c
28 ===================================================================
29 --- linux-2.6.24.7.orig/arch/arm/mach-ixp4xx/nslu2-power.c
30 +++ /dev/null
31 @@ -1,92 +0,0 @@
32 -/*
33 - * arch/arm/mach-ixp4xx/nslu2-power.c
34 - *
35 - * NSLU2 Power/Reset driver
36 - *
37 - * Copyright (C) 2005 Tower Technologies
38 - *
39 - * based on nslu2-io.c
40 - *  Copyright (C) 2004 Karen Spearel
41 - *
42 - * Author: Alessandro Zummo <a.zummo@towertech.it>
43 - * Maintainers: http://www.nslu2-linux.org/
44 - *
45 - * This program is free software; you can redistribute it and/or modify
46 - * it under the terms of the GNU General Public License version 2 as
47 - * published by the Free Software Foundation.
48 - *
49 - */
50 -
51 -#include <linux/module.h>
52 -#include <linux/reboot.h>
53 -#include <linux/irq.h>
54 -#include <linux/interrupt.h>
55 -#include <linux/reboot.h>
56 -
57 -#include <asm/mach-types.h>
58 -
59 -static irqreturn_t nslu2_power_handler(int irq, void *dev_id)
60 -{
61 -       /* Signal init to do the ctrlaltdel action, this will bypass init if
62 -        * it hasn't started and do a kernel_restart.
63 -        */
64 -       ctrl_alt_del();
65 -
66 -       return IRQ_HANDLED;
67 -}
68 -
69 -static irqreturn_t nslu2_reset_handler(int irq, void *dev_id)
70 -{
71 -       /* This is the paper-clip reset, it shuts the machine down directly.
72 -        */
73 -       machine_power_off();
74 -
75 -       return IRQ_HANDLED;
76 -}
77 -
78 -static int __init nslu2_power_init(void)
79 -{
80 -       if (!(machine_is_nslu2()))
81 -               return 0;
82 -
83 -       *IXP4XX_GPIO_GPISR = 0x20400000;        /* read the 2 irqs to clr */
84 -
85 -       set_irq_type(NSLU2_RB_IRQ, IRQT_LOW);
86 -       set_irq_type(NSLU2_PB_IRQ, IRQT_HIGH);
87 -
88 -       if (request_irq(NSLU2_RB_IRQ, &nslu2_reset_handler,
89 -               IRQF_DISABLED, "NSLU2 reset button", NULL) < 0) {
90 -
91 -               printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
92 -                       NSLU2_RB_IRQ);
93 -
94 -               return -EIO;
95 -       }
96 -
97 -       if (request_irq(NSLU2_PB_IRQ, &nslu2_power_handler,
98 -               IRQF_DISABLED, "NSLU2 power button", NULL) < 0) {
99 -
100 -               printk(KERN_DEBUG "Power Button IRQ %d not available\n",
101 -                       NSLU2_PB_IRQ);
102 -
103 -               return -EIO;
104 -       }
105 -
106 -       return 0;
107 -}
108 -
109 -static void __exit nslu2_power_exit(void)
110 -{
111 -       if (!(machine_is_nslu2()))
112 -               return;
113 -
114 -       free_irq(NSLU2_RB_IRQ, NULL);
115 -       free_irq(NSLU2_PB_IRQ, NULL);
116 -}
117 -
118 -module_init(nslu2_power_init);
119 -module_exit(nslu2_power_exit);
120 -
121 -MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
122 -MODULE_DESCRIPTION("NSLU2 Power/Reset driver");
123 -MODULE_LICENSE("GPL");
124 Index: linux-2.6.24.7/arch/arm/mach-ixp4xx/nslu2-setup.c
125 ===================================================================
126 --- linux-2.6.24.7.orig/arch/arm/mach-ixp4xx/nslu2-setup.c
127 +++ linux-2.6.24.7/arch/arm/mach-ixp4xx/nslu2-setup.c
128 @@ -3,22 +3,26 @@
129   *
130   * NSLU2 board-setup
131   *
132 - * based ixdp425-setup.c:
133 + * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
134 + *
135 + * based on ixdp425-setup.c:
136   *      Copyright (C) 2003-2004 MontaVista Software, Inc.
137 + * based on nslu2-power.c:
138 + *     Copyright (C) 2005 Tower Technologies
139   *
140   * Author: Mark Rakes <mrakes at mac.com>
141   * Author: Rod Whitby <rod@whitby.id.au>
142 + * Author: Alessandro Zummo <a.zummo@towertech.it>
143   * Maintainers: http://www.nslu2-linux.org/
144   *
145 - * Fixed missing init_time in MACHINE_START kas11 10/22/04
146 - * Changed to conform to new style __init ixdp425 kas11 10/22/04
147   */
148  
149  #include <linux/if_ether.h>
150 -#include <linux/kernel.h>
151 +#include <linux/irq.h>
152  #include <linux/serial.h>
153  #include <linux/serial_8250.h>
154  #include <linux/leds.h>
155 +#include <linux/reboot.h>
156  #include <linux/i2c.h>
157  #include <linux/i2c-gpio.h>
158  
159 @@ -27,6 +31,7 @@
160  #include <asm/mach/flash.h>
161  #include <asm/mach/time.h>
162  #include <asm/io.h>
163 +#include <asm/gpio.h>
164  
165  static struct flash_platform_data nslu2_flash_data = {
166         .map_name               = "cfi_probe",
167 @@ -181,6 +186,25 @@ static void nslu2_power_off(void)
168         gpio_line_set(NSLU2_PO_GPIO, IXP4XX_GPIO_HIGH);
169  }
170  
171 +static irqreturn_t nslu2_power_handler(int irq, void *dev_id)
172 +{
173 +       /* Signal init to do the ctrlaltdel action, this will bypass init if
174 +        * it hasn't started and do a kernel_restart.
175 +        */
176 +       ctrl_alt_del();
177 +
178 +       return IRQ_HANDLED;
179 +}
180 +
181 +static irqreturn_t nslu2_reset_handler(int irq, void *dev_id)
182 +{
183 +       /* This is the paper-clip reset, it shuts the machine down directly.
184 +        */
185 +       machine_power_off();
186 +
187 +       return IRQ_HANDLED;
188 +}
189 +
190  static void __init nslu2_timer_init(void)
191  {
192      /* The xtal on this machine is non-standard. */
193 @@ -206,8 +230,6 @@ static void __init nslu2_init(void)
194         nslu2_flash_resource.end =
195                 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
196  
197 -       pm_power_off = nslu2_power_off;
198 -
199         i2c_register_board_info(0, nslu2_i2c_board_info,
200                                 ARRAY_SIZE(nslu2_i2c_board_info));
201  
202 @@ -220,6 +242,23 @@ static void __init nslu2_init(void)
203  
204         platform_add_devices(nslu2_devices, ARRAY_SIZE(nslu2_devices));
205  
206 +       pm_power_off = nslu2_power_off;
207 +
208 +       if (request_irq(gpio_to_irq(NSLU2_RB_GPIO), &nslu2_reset_handler,
209 +               IRQF_DISABLED | IRQF_TRIGGER_LOW,
210 +               "NSLU2 reset button", NULL) < 0) {
211 +
212 +               printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
213 +                       gpio_to_irq(NSLU2_RB_GPIO));
214 +       }
215 +
216 +       if (request_irq(gpio_to_irq(NSLU2_PB_GPIO), &nslu2_power_handler,
217 +               IRQF_DISABLED | IRQF_TRIGGER_HIGH,
218 +               "NSLU2 power button", NULL) < 0) {
219 +
220 +               printk(KERN_DEBUG "Power Button IRQ %d not available\n",
221 +                       gpio_to_irq(NSLU2_PB_GPIO));
222 +       }
223  
224         /*
225          * Map in a portion of the flash and read the MAC address.
226 Index: linux-2.6.24.7/include/asm-arm/arch-ixp4xx/nslu2.h
227 ===================================================================
228 --- linux-2.6.24.7.orig/include/asm-arm/arch-ixp4xx/nslu2.h
229 +++ linux-2.6.24.7/include/asm-arm/arch-ixp4xx/nslu2.h
230 @@ -39,34 +39,17 @@
231  
232  /* Buttons */
233  
234 -#define NSLU2_PB_GPIO          5
235 +#define NSLU2_PB_GPIO          5       /* power button */
236  #define NSLU2_PO_GPIO          8       /* power off */
237 -#define NSLU2_RB_GPIO          12
238 -
239 -#define NSLU2_PB_IRQ           IRQ_IXP4XX_GPIO5
240 -#define NSLU2_RB_IRQ           IRQ_IXP4XX_GPIO12
241 -
242 -#define NSLU2_PB_BM            (1L << NSLU2_PB_GPIO)
243 -#define NSLU2_PO_BM            (1L << NSLU2_PO_GPIO)
244 -#define NSLU2_RB_BM            (1L << NSLU2_RB_GPIO)
245 +#define NSLU2_RB_GPIO          12      /* reset button */
246  
247  /* Buzzer */
248  
249  #define NSLU2_GPIO_BUZZ                4
250 -#define NSLU2_BZ_BM            (1L << NSLU2_GPIO_BUZZ)
251  
252  /* LEDs */
253  
254  #define NSLU2_LED_RED_GPIO     0
255  #define NSLU2_LED_GRN_GPIO     1
256 -
257 -#define NSLU2_LED_RED_BM       (1L << NSLU2_LED_RED_GPIO)
258 -#define NSLU2_LED_GRN_BM       (1L << NSLU2_LED_GRN_GPIO)
259 -
260  #define NSLU2_LED_DISK1_GPIO   3
261  #define NSLU2_LED_DISK2_GPIO   2
262 -
263 -#define NSLU2_LED_DISK1_BM     (1L << NSLU2_LED_DISK1_GPIO)
264 -#define NSLU2_LED_DISK2_BM     (1L << NSLU2_LED_DISK2_GPIO)
265 -
266 -
267 Index: linux-2.6.24.7/arch/arm/mach-ixp4xx/nas100d-power.c
268 ===================================================================
269 --- linux-2.6.24.7.orig/arch/arm/mach-ixp4xx/nas100d-power.c
270 +++ /dev/null
271 @@ -1,128 +0,0 @@
272 -/*
273 - * arch/arm/mach-ixp4xx/nas100d-power.c
274 - *
275 - * NAS 100d Power/Reset driver
276 - *
277 - * Copyright (C) 2005 Tower Technologies
278 - *
279 - * based on nas100d-io.c
280 - *  Copyright (C) 2004 Karen Spearel
281 - *
282 - * Author: Alessandro Zummo <a.zummo@towertech.it>
283 - * Maintainers: http://www.nslu2-linux.org/
284 - *
285 - * This program is free software; you can redistribute it and/or modify
286 - * it under the terms of the GNU General Public License version 2 as
287 - * published by the Free Software Foundation.
288 - *
289 - */
290 -
291 -#include <linux/interrupt.h>
292 -#include <linux/irq.h>
293 -#include <linux/module.h>
294 -#include <linux/reboot.h>
295 -#include <linux/jiffies.h>
296 -#include <linux/timer.h>
297 -
298 -#include <asm/gpio.h>
299 -#include <asm/mach-types.h>
300 -
301 -/* This is used to make sure the power-button pusher is serious.  The button
302 - * must be held until the value of this counter reaches zero.
303 - */
304 -static int power_button_countdown;
305 -
306 -/* Must hold the button down for at least this many counts to be processed */
307 -#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
308 -
309 -static void nas100d_power_handler(unsigned long data);
310 -static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler, 0, 0);
311 -
312 -static void nas100d_power_handler(unsigned long data)
313 -{
314 -       /* This routine is called twice per second to check the
315 -        * state of the power button.
316 -        */
317 -
318 -       if (gpio_get_value(NAS100D_PB_GPIO)) {
319 -
320 -               /* IO Pin is 1 (button pushed) */
321 -               if (power_button_countdown > 0)
322 -                       power_button_countdown--;
323 -
324 -       } else {
325 -
326 -               /* Done on button release, to allow for auto-power-on mods. */
327 -               if (power_button_countdown == 0) {
328 -                       /* Signal init to do the ctrlaltdel action,
329 -                        * this will bypass init if it hasn't started
330 -                        * and do a kernel_restart.
331 -                        */
332 -                       ctrl_alt_del();
333 -
334 -                       /* Change the state of the power LED to "blink" */
335 -                       gpio_line_set(NAS100D_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
336 -               } else {
337 -                       power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
338 -               }
339 -       }
340 -
341 -       mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
342 -}
343 -
344 -static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
345 -{
346 -       /* This is the paper-clip reset, it shuts the machine down directly. */
347 -       machine_power_off();
348 -
349 -       return IRQ_HANDLED;
350 -}
351 -
352 -static int __init nas100d_power_init(void)
353 -{
354 -       if (!(machine_is_nas100d()))
355 -               return 0;
356 -
357 -       set_irq_type(gpio_to_irq(NAS100D_RB_GPIO), IRQT_LOW);
358 -
359 -       if (request_irq(gpio_to_irq(NAS100D_RB_GPIO), &nas100d_reset_handler,
360 -               IRQF_DISABLED, "NAS100D reset button", NULL) < 0) {
361 -
362 -               printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
363 -                       gpio_to_irq(NAS100D_RB_GPIO));
364 -
365 -               return -EIO;
366 -       }
367 -
368 -       /* The power button on the Iomega NAS100d is on GPIO 14, but
369 -        * it cannot handle interrupts on that GPIO line.  So we'll
370 -        * have to poll it with a kernel timer.
371 -        */
372 -
373 -       /* Make sure that the power button GPIO is set up as an input */
374 -       gpio_line_config(NAS100D_PB_GPIO, IXP4XX_GPIO_IN);
375 -
376 -       /* Set the initial value for the power button IRQ handler */
377 -       power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
378 -
379 -       mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
380 -
381 -       return 0;
382 -}
383 -
384 -static void __exit nas100d_power_exit(void)
385 -{
386 -       if (!(machine_is_nas100d()))
387 -               return;
388 -
389 -       del_timer_sync(&nas100d_power_timer);
390 -
391 -       free_irq(gpio_to_irq(NAS100D_RB_GPIO), NULL);
392 -}
393 -
394 -module_init(nas100d_power_init);
395 -module_exit(nas100d_power_exit);
396 -
397 -MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
398 -MODULE_DESCRIPTION("NAS100D Power/Reset driver");
399 -MODULE_LICENSE("GPL");
400 Index: linux-2.6.24.7/arch/arm/mach-ixp4xx/nas100d-setup.c
401 ===================================================================
402 --- linux-2.6.24.7.orig/arch/arm/mach-ixp4xx/nas100d-setup.c
403 +++ linux-2.6.24.7/arch/arm/mach-ixp4xx/nas100d-setup.c
404 @@ -3,8 +3,14 @@
405   *
406   * NAS 100d board-setup
407   *
408 - * based ixdp425-setup.c:
409 + * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
410 + *
411 + * based on ixdp425-setup.c:
412   *      Copyright (C) 2003-2004 MontaVista Software, Inc.
413 + * based on nas100d-power.c:
414 + *     Copyright (C) 2005 Tower Technologies
415 + * based on nas100d-io.c
416 + *     Copyright (C) 2004 Karen Spearel
417   *
418   * Author: Alessandro Zummo <a.zummo@towertech.it>
419   * Author: Rod Whitby <rod@whitby.id.au>
420 @@ -13,10 +19,13 @@
421   */
422  
423  #include <linux/if_ether.h>
424 -#include <linux/kernel.h>
425 +#include <linux/irq.h>
426 +#include <linux/jiffies.h>
427 +#include <linux/timer.h>
428  #include <linux/serial.h>
429  #include <linux/serial_8250.h>
430  #include <linux/leds.h>
431 +#include <linux/reboot.h>
432  #include <linux/i2c.h>
433  #include <linux/i2c-gpio.h>
434  
435 @@ -24,6 +33,7 @@
436  #include <asm/mach/arch.h>
437  #include <asm/mach/flash.h>
438  #include <asm/io.h>
439 +#include <asm/gpio.h>
440  
441  static struct flash_platform_data nas100d_flash_data = {
442         .map_name               = "cfi_probe",
443 @@ -168,6 +178,57 @@ static void nas100d_power_off(void)
444         gpio_line_set(NAS100D_PO_GPIO, IXP4XX_GPIO_HIGH);
445  }
446  
447 +/* This is used to make sure the power-button pusher is serious.  The button
448 + * must be held until the value of this counter reaches zero.
449 + */
450 +static int power_button_countdown;
451 +
452 +/* Must hold the button down for at least this many counts to be processed */
453 +#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
454 +
455 +static void nas100d_power_handler(unsigned long data);
456 +static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler, 0, 0);
457 +
458 +static void nas100d_power_handler(unsigned long data)
459 +{
460 +       /* This routine is called twice per second to check the
461 +        * state of the power button.
462 +        */
463 +
464 +       if (gpio_get_value(NAS100D_PB_GPIO)) {
465 +
466 +               /* IO Pin is 1 (button pushed) */
467 +               if (power_button_countdown > 0)
468 +                       power_button_countdown--;
469 +
470 +       } else {
471 +
472 +               /* Done on button release, to allow for auto-power-on mods. */
473 +               if (power_button_countdown == 0) {
474 +                       /* Signal init to do the ctrlaltdel action,
475 +                        * this will bypass init if it hasn't started
476 +                        * and do a kernel_restart.
477 +                        */
478 +                       ctrl_alt_del();
479 +
480 +                       /* Change the state of the power LED to "blink" */
481 +                       gpio_line_set(NAS100D_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
482 +               } else {
483 +                       power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
484 +               }
485 +       }
486 +
487 +       mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
488 +}
489 +
490 +static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
491 +{
492 +       /* This is the paper-clip reset, it shuts the machine down directly. */
493 +       machine_power_off();
494 +
495 +       return IRQ_HANDLED;
496 +}
497 +
498  static void __init nas100d_init(void)
499  {
500         DECLARE_MAC_BUF(mac_buf);
501 @@ -183,8 +244,6 @@ static void __init nas100d_init(void)
502         nas100d_flash_resource.end =
503                 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
504  
505 -       pm_power_off = nas100d_power_off;
506 -
507         i2c_register_board_info(0, nas100d_i2c_board_info,
508                                 ARRAY_SIZE(nas100d_i2c_board_info));
509  
510 @@ -197,6 +256,29 @@ static void __init nas100d_init(void)
511  
512         platform_add_devices(nas100d_devices, ARRAY_SIZE(nas100d_devices));
513  
514 +       pm_power_off = nas100d_power_off;
515 +
516 +       if (request_irq(gpio_to_irq(NAS100D_RB_GPIO), &nas100d_reset_handler,
517 +               IRQF_DISABLED | IRQF_TRIGGER_LOW,
518 +               "NAS100D reset button", NULL) < 0) {
519 +
520 +               printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
521 +                       gpio_to_irq(NAS100D_RB_GPIO));
522 +       }
523 +
524 +       /* The power button on the Iomega NAS100d is on GPIO 14, but
525 +        * it cannot handle interrupts on that GPIO line.  So we'll
526 +        * have to poll it with a kernel timer.
527 +        */
528 +
529 +       /* Make sure that the power button GPIO is set up as an input */
530 +       gpio_line_config(NAS100D_PB_GPIO, IXP4XX_GPIO_IN);
531 +
532 +       /* Set the initial value for the power button IRQ handler */
533 +       power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
534 +
535 +       mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
536 +
537         /*
538          * Map in a portion of the flash and read the MAC address.
539          * Since it is stored in BE in the flash itself, we need to
540 Index: linux-2.6.24.7/arch/arm/mach-ixp4xx/dsmg600-power.c
541 ===================================================================
542 --- linux-2.6.24.7.orig/arch/arm/mach-ixp4xx/dsmg600-power.c
543 +++ /dev/null
544 @@ -1,129 +0,0 @@
545 -/*
546 - * arch/arm/mach-ixp4xx/dsmg600-power.c
547 - *
548 - * DSM-G600 Power/Reset driver
549 - * Author: Michael Westerhof <mwester@dls.net>
550 - *
551 - * Based on nslu2-power.c
552 - *  Copyright (C) 2005 Tower Technologies
553 - *  Author: Alessandro Zummo <a.zummo@towertech.it>
554 - *
555 - * which was based on nslu2-io.c
556 - *  Copyright (C) 2004 Karen Spearel
557 - *
558 - * Maintainers: http://www.nslu2-linux.org/
559 - *
560 - * This program is free software; you can redistribute it and/or modify
561 - * it under the terms of the GNU General Public License version 2 as
562 - * published by the Free Software Foundation.
563 - *
564 - */
565 -
566 -#include <linux/module.h>
567 -#include <linux/reboot.h>
568 -#include <linux/interrupt.h>
569 -#include <linux/irq.h>
570 -#include <linux/jiffies.h>
571 -#include <linux/timer.h>
572 -
573 -#include <asm/gpio.h>
574 -#include <asm/mach-types.h>
575 -
576 -/* This is used to make sure the power-button pusher is serious.  The button
577 - * must be held until the value of this counter reaches zero.
578 - */
579 -static int power_button_countdown;
580 -
581 -/* Must hold the button down for at least this many counts to be processed */
582 -#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
583 -
584 -static void dsmg600_power_handler(unsigned long data);
585 -static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0);
586 -
587 -static void dsmg600_power_handler(unsigned long data)
588 -{
589 -       /* This routine is called twice per second to check the
590 -        * state of the power button.
591 -        */
592 -
593 -       if (gpio_get_value(DSMG600_PB_GPIO)) {
594 -
595 -               /* IO Pin is 1 (button pushed) */
596 -               if (power_button_countdown > 0)
597 -                       power_button_countdown--;
598 -
599 -       } else {
600 -
601 -               /* Done on button release, to allow for auto-power-on mods. */
602 -               if (power_button_countdown == 0) {
603 -                       /* Signal init to do the ctrlaltdel action,
604 -                        * this will bypass init if it hasn't started
605 -                        * and do a kernel_restart.
606 -                        */
607 -                       ctrl_alt_del();
608 -
609 -                       /* Change the state of the power LED to "blink" */
610 -                       gpio_line_set(DSMG600_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
611 -               } else {
612 -                       power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
613 -               }
614 -       }
615 -
616 -       mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
617 -}
618 -
619 -static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id)
620 -{
621 -       /* This is the paper-clip reset, it shuts the machine down directly. */
622 -       machine_power_off();
623 -
624 -       return IRQ_HANDLED;
625 -}
626 -
627 -static int __init dsmg600_power_init(void)
628 -{
629 -       if (!(machine_is_dsmg600()))
630 -               return 0;
631 -
632 -       if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler,
633 -               IRQF_DISABLED | IRQF_TRIGGER_LOW, "DSM-G600 reset button",
634 -               NULL) < 0) {
635 -
636 -               printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
637 -                       gpio_to_irq(DSMG600_RB_GPIO));
638 -
639 -               return -EIO;
640 -       }
641 -
642 -       /* The power button on the D-Link DSM-G600 is on GPIO 15, but
643 -        * it cannot handle interrupts on that GPIO line.  So we'll
644 -        * have to poll it with a kernel timer.
645 -        */
646 -
647 -       /* Make sure that the power button GPIO is set up as an input */
648 -       gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN);
649 -
650 -       /* Set the initial value for the power button IRQ handler */
651 -       power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
652 -
653 -       mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
654 -
655 -       return 0;
656 -}
657 -
658 -static void __exit dsmg600_power_exit(void)
659 -{
660 -       if (!(machine_is_dsmg600()))
661 -               return;
662 -
663 -       del_timer_sync(&dsmg600_power_timer);
664 -
665 -       free_irq(gpio_to_irq(DSMG600_RB_GPIO), NULL);
666 -}
667 -
668 -module_init(dsmg600_power_init);
669 -module_exit(dsmg600_power_exit);
670 -
671 -MODULE_AUTHOR("Michael Westerhof <mwester@dls.net>");
672 -MODULE_DESCRIPTION("DSM-G600 Power/Reset driver");
673 -MODULE_LICENSE("GPL");
674 Index: linux-2.6.24.7/arch/arm/mach-ixp4xx/dsmg600-setup.c
675 ===================================================================
676 --- linux-2.6.24.7.orig/arch/arm/mach-ixp4xx/dsmg600-setup.c
677 +++ linux-2.6.24.7/arch/arm/mach-ixp4xx/dsmg600-setup.c
678 @@ -1,20 +1,29 @@
679  /*
680   * DSM-G600 board-setup
681   *
682 + * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
683   * Copyright (C) 2006 Tower Technologies
684 - * Author: Alessandro Zummo <a.zummo@towertech.it>
685   *
686 - * based ixdp425-setup.c:
687 + * based on ixdp425-setup.c:
688   *      Copyright (C) 2003-2004 MontaVista Software, Inc.
689 + * based on nslu2-power.c:
690 + *     Copyright (C) 2005 Tower Technologies
691 + * based on nslu2-io.c:
692 + *     Copyright (C) 2004 Karen Spearel
693   *
694   * Author: Alessandro Zummo <a.zummo@towertech.it>
695 + * Author: Michael Westerhof <mwester@dls.net>
696 + * Author: Rod Whitby <rod@whitby.id.au>
697   * Maintainers: http://www.nslu2-linux.org/
698   */
699  
700 -#include <linux/kernel.h>
701 +#include <linux/irq.h>
702 +#include <linux/jiffies.h>
703 +#include <linux/timer.h>
704  #include <linux/serial.h>
705  #include <linux/serial_8250.h>
706  #include <linux/leds.h>
707 +#include <linux/reboot.h>
708  #include <linux/i2c.h>
709  #include <linux/i2c-gpio.h>
710  
711 @@ -22,6 +31,7 @@
712  #include <asm/mach/arch.h>
713  #include <asm/mach/flash.h>
714  #include <asm/mach/time.h>
715 +#include <asm/gpio.h>
716  
717  static struct flash_platform_data dsmg600_flash_data = {
718         .map_name               = "cfi_probe",
719 @@ -140,6 +150,57 @@ static void dsmg600_power_off(void)
720         gpio_line_set(DSMG600_PO_GPIO, IXP4XX_GPIO_HIGH);
721  }
722  
723 +/* This is used to make sure the power-button pusher is serious.  The button
724 + * must be held until the value of this counter reaches zero.
725 + */
726 +static int power_button_countdown;
727 +
728 +/* Must hold the button down for at least this many counts to be processed */
729 +#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
730 +
731 +static void dsmg600_power_handler(unsigned long data);
732 +static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0);
733 +
734 +static void dsmg600_power_handler(unsigned long data)
735 +{
736 +       /* This routine is called twice per second to check the
737 +        * state of the power button.
738 +        */
739 +
740 +       if (gpio_get_value(DSMG600_PB_GPIO)) {
741 +
742 +               /* IO Pin is 1 (button pushed) */
743 +               if (power_button_countdown > 0)
744 +                       power_button_countdown--;
745 +
746 +       } else {
747 +
748 +               /* Done on button release, to allow for auto-power-on mods. */
749 +               if (power_button_countdown == 0) {
750 +                       /* Signal init to do the ctrlaltdel action,
751 +                        * this will bypass init if it hasn't started
752 +                        * and do a kernel_restart.
753 +                        */
754 +                       ctrl_alt_del();
755 +
756 +                       /* Change the state of the power LED to "blink" */
757 +                       gpio_line_set(DSMG600_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
758 +               } else {
759 +                       power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
760 +               }
761 +       }
762 +
763 +       mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
764 +}
765 +
766 +static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id)
767 +{
768 +       /* This is the paper-clip reset, it shuts the machine down directly. */
769 +       machine_power_off();
770 +
771 +       return IRQ_HANDLED;
772 +}
773 +
774  static void __init dsmg600_timer_init(void)
775  {
776      /* The xtal on this machine is non-standard. */
777 @@ -164,8 +225,6 @@ static void __init dsmg600_init(void)
778         dsmg600_flash_resource.end =
779                 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
780  
781 -       pm_power_off = dsmg600_power_off;
782 -
783         i2c_register_board_info(0, dsmg600_i2c_board_info,
784                                 ARRAY_SIZE(dsmg600_i2c_board_info));
785  
786 @@ -176,6 +235,29 @@ static void __init dsmg600_init(void)
787          (void)platform_device_register(&dsmg600_uart);
788  
789         platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices));
790 +
791 +       pm_power_off = dsmg600_power_off;
792 +
793 +       if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler,
794 +               IRQF_DISABLED | IRQF_TRIGGER_LOW,
795 +               "DSM-G600 reset button", NULL) < 0) {
796 +
797 +               printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
798 +                       gpio_to_irq(DSMG600_RB_GPIO));
799 +       }
800 +
801 +       /* The power button on the D-Link DSM-G600 is on GPIO 15, but
802 +        * it cannot handle interrupts on that GPIO line.  So we'll
803 +        * have to poll it with a kernel timer.
804 +        */
805 +
806 +       /* Make sure that the power button GPIO is set up as an input */
807 +       gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN);
808 +
809 +       /* Set the initial value for the power button IRQ handler */
810 +       power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
811 +
812 +       mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
813  }
814  
815  MACHINE_START(DSMG600, "D-Link DSM-G600 RevA")