1 From: Rod Whitby <rod@whitby.id.au>
2 Subject: ixp4xx: Merge nslu2-power.c into nslu2-setup.c (Patch #4807)
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.
9 Signed-off-by: Rod Whitby <rod@whitby.id.au>
12 KernelVersion: v2.6.24-1917-gaf66bd3
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
33 - * arch/arm/mach-ixp4xx/nslu2-power.c
35 - * NSLU2 Power/Reset driver
37 - * Copyright (C) 2005 Tower Technologies
39 - * based on nslu2-io.c
40 - * Copyright (C) 2004 Karen Spearel
42 - * Author: Alessandro Zummo <a.zummo@towertech.it>
43 - * Maintainers: http://www.nslu2-linux.org/
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.
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>
57 -#include <asm/mach-types.h>
59 -static irqreturn_t nslu2_power_handler(int irq, void *dev_id)
61 - /* Signal init to do the ctrlaltdel action, this will bypass init if
62 - * it hasn't started and do a kernel_restart.
69 -static irqreturn_t nslu2_reset_handler(int irq, void *dev_id)
71 - /* This is the paper-clip reset, it shuts the machine down directly.
73 - machine_power_off();
78 -static int __init nslu2_power_init(void)
80 - if (!(machine_is_nslu2()))
83 - *IXP4XX_GPIO_GPISR = 0x20400000; /* read the 2 irqs to clr */
85 - set_irq_type(NSLU2_RB_IRQ, IRQT_LOW);
86 - set_irq_type(NSLU2_PB_IRQ, IRQT_HIGH);
88 - if (request_irq(NSLU2_RB_IRQ, &nslu2_reset_handler,
89 - IRQF_DISABLED, "NSLU2 reset button", NULL) < 0) {
91 - printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
97 - if (request_irq(NSLU2_PB_IRQ, &nslu2_power_handler,
98 - IRQF_DISABLED, "NSLU2 power button", NULL) < 0) {
100 - printk(KERN_DEBUG "Power Button IRQ %d not available\n",
109 -static void __exit nslu2_power_exit(void)
111 - if (!(machine_is_nslu2()))
114 - free_irq(NSLU2_RB_IRQ, NULL);
115 - free_irq(NSLU2_PB_IRQ, NULL);
118 -module_init(nslu2_power_init);
119 -module_exit(nslu2_power_exit);
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
132 - * based ixdp425-setup.c:
133 + * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
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
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/
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
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>
160 #include <asm/mach/flash.h>
161 #include <asm/mach/time.h>
163 +#include <asm/gpio.h>
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);
171 +static irqreturn_t nslu2_power_handler(int irq, void *dev_id)
173 + /* Signal init to do the ctrlaltdel action, this will bypass init if
174 + * it hasn't started and do a kernel_restart.
178 + return IRQ_HANDLED;
181 +static irqreturn_t nslu2_reset_handler(int irq, void *dev_id)
183 + /* This is the paper-clip reset, it shuts the machine down directly.
185 + machine_power_off();
187 + return IRQ_HANDLED;
190 static void __init nslu2_timer_init(void)
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;
197 - pm_power_off = nslu2_power_off;
199 i2c_register_board_info(0, nslu2_i2c_board_info,
200 ARRAY_SIZE(nslu2_i2c_board_info));
202 @@ -220,6 +242,23 @@ static void __init nslu2_init(void)
204 platform_add_devices(nslu2_devices, ARRAY_SIZE(nslu2_devices));
206 + pm_power_off = nslu2_power_off;
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) {
212 + printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
213 + gpio_to_irq(NSLU2_RB_GPIO));
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) {
220 + printk(KERN_DEBUG "Power Button IRQ %d not available\n",
221 + gpio_to_irq(NSLU2_PB_GPIO));
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
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
239 -#define NSLU2_PB_IRQ IRQ_IXP4XX_GPIO5
240 -#define NSLU2_RB_IRQ IRQ_IXP4XX_GPIO12
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 */
249 #define NSLU2_GPIO_BUZZ 4
250 -#define NSLU2_BZ_BM (1L << NSLU2_GPIO_BUZZ)
254 #define NSLU2_LED_RED_GPIO 0
255 #define NSLU2_LED_GRN_GPIO 1
257 -#define NSLU2_LED_RED_BM (1L << NSLU2_LED_RED_GPIO)
258 -#define NSLU2_LED_GRN_BM (1L << NSLU2_LED_GRN_GPIO)
260 #define NSLU2_LED_DISK1_GPIO 3
261 #define NSLU2_LED_DISK2_GPIO 2
263 -#define NSLU2_LED_DISK1_BM (1L << NSLU2_LED_DISK1_GPIO)
264 -#define NSLU2_LED_DISK2_BM (1L << NSLU2_LED_DISK2_GPIO)
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
273 - * arch/arm/mach-ixp4xx/nas100d-power.c
275 - * NAS 100d Power/Reset driver
277 - * Copyright (C) 2005 Tower Technologies
279 - * based on nas100d-io.c
280 - * Copyright (C) 2004 Karen Spearel
282 - * Author: Alessandro Zummo <a.zummo@towertech.it>
283 - * Maintainers: http://www.nslu2-linux.org/
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.
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>
298 -#include <asm/gpio.h>
299 -#include <asm/mach-types.h>
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.
304 -static int power_button_countdown;
306 -/* Must hold the button down for at least this many counts to be processed */
307 -#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
309 -static void nas100d_power_handler(unsigned long data);
310 -static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler, 0, 0);
312 -static void nas100d_power_handler(unsigned long data)
314 - /* This routine is called twice per second to check the
315 - * state of the power button.
318 - if (gpio_get_value(NAS100D_PB_GPIO)) {
320 - /* IO Pin is 1 (button pushed) */
321 - if (power_button_countdown > 0)
322 - power_button_countdown--;
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.
334 - /* Change the state of the power LED to "blink" */
335 - gpio_line_set(NAS100D_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
337 - power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
341 - mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
344 -static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
346 - /* This is the paper-clip reset, it shuts the machine down directly. */
347 - machine_power_off();
349 - return IRQ_HANDLED;
352 -static int __init nas100d_power_init(void)
354 - if (!(machine_is_nas100d()))
357 - set_irq_type(gpio_to_irq(NAS100D_RB_GPIO), IRQT_LOW);
359 - if (request_irq(gpio_to_irq(NAS100D_RB_GPIO), &nas100d_reset_handler,
360 - IRQF_DISABLED, "NAS100D reset button", NULL) < 0) {
362 - printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
363 - gpio_to_irq(NAS100D_RB_GPIO));
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.
373 - /* Make sure that the power button GPIO is set up as an input */
374 - gpio_line_config(NAS100D_PB_GPIO, IXP4XX_GPIO_IN);
376 - /* Set the initial value for the power button IRQ handler */
377 - power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
379 - mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
384 -static void __exit nas100d_power_exit(void)
386 - if (!(machine_is_nas100d()))
389 - del_timer_sync(&nas100d_power_timer);
391 - free_irq(gpio_to_irq(NAS100D_RB_GPIO), NULL);
394 -module_init(nas100d_power_init);
395 -module_exit(nas100d_power_exit);
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
406 * NAS 100d board-setup
408 - * based ixdp425-setup.c:
409 + * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
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
418 * Author: Alessandro Zummo <a.zummo@towertech.it>
419 * Author: Rod Whitby <rod@whitby.id.au>
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>
436 #include <asm/mach/arch.h>
437 #include <asm/mach/flash.h>
439 +#include <asm/gpio.h>
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);
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.
450 +static int power_button_countdown;
452 +/* Must hold the button down for at least this many counts to be processed */
453 +#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
455 +static void nas100d_power_handler(unsigned long data);
456 +static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler, 0, 0);
458 +static void nas100d_power_handler(unsigned long data)
460 + /* This routine is called twice per second to check the
461 + * state of the power button.
464 + if (gpio_get_value(NAS100D_PB_GPIO)) {
466 + /* IO Pin is 1 (button pushed) */
467 + if (power_button_countdown > 0)
468 + power_button_countdown--;
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.
480 + /* Change the state of the power LED to "blink" */
481 + gpio_line_set(NAS100D_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
483 + power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
487 + mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
490 +static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
492 + /* This is the paper-clip reset, it shuts the machine down directly. */
493 + machine_power_off();
495 + return IRQ_HANDLED;
498 static void __init nas100d_init(void)
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;
505 - pm_power_off = nas100d_power_off;
507 i2c_register_board_info(0, nas100d_i2c_board_info,
508 ARRAY_SIZE(nas100d_i2c_board_info));
510 @@ -197,6 +256,29 @@ static void __init nas100d_init(void)
512 platform_add_devices(nas100d_devices, ARRAY_SIZE(nas100d_devices));
514 + pm_power_off = nas100d_power_off;
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) {
520 + printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
521 + gpio_to_irq(NAS100D_RB_GPIO));
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.
529 + /* Make sure that the power button GPIO is set up as an input */
530 + gpio_line_config(NAS100D_PB_GPIO, IXP4XX_GPIO_IN);
532 + /* Set the initial value for the power button IRQ handler */
533 + power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
535 + mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
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
546 - * arch/arm/mach-ixp4xx/dsmg600-power.c
548 - * DSM-G600 Power/Reset driver
549 - * Author: Michael Westerhof <mwester@dls.net>
551 - * Based on nslu2-power.c
552 - * Copyright (C) 2005 Tower Technologies
553 - * Author: Alessandro Zummo <a.zummo@towertech.it>
555 - * which was based on nslu2-io.c
556 - * Copyright (C) 2004 Karen Spearel
558 - * Maintainers: http://www.nslu2-linux.org/
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.
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>
573 -#include <asm/gpio.h>
574 -#include <asm/mach-types.h>
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.
579 -static int power_button_countdown;
581 -/* Must hold the button down for at least this many counts to be processed */
582 -#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
584 -static void dsmg600_power_handler(unsigned long data);
585 -static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0);
587 -static void dsmg600_power_handler(unsigned long data)
589 - /* This routine is called twice per second to check the
590 - * state of the power button.
593 - if (gpio_get_value(DSMG600_PB_GPIO)) {
595 - /* IO Pin is 1 (button pushed) */
596 - if (power_button_countdown > 0)
597 - power_button_countdown--;
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.
609 - /* Change the state of the power LED to "blink" */
610 - gpio_line_set(DSMG600_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
612 - power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
616 - mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
619 -static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id)
621 - /* This is the paper-clip reset, it shuts the machine down directly. */
622 - machine_power_off();
624 - return IRQ_HANDLED;
627 -static int __init dsmg600_power_init(void)
629 - if (!(machine_is_dsmg600()))
632 - if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler,
633 - IRQF_DISABLED | IRQF_TRIGGER_LOW, "DSM-G600 reset button",
636 - printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
637 - gpio_to_irq(DSMG600_RB_GPIO));
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.
647 - /* Make sure that the power button GPIO is set up as an input */
648 - gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN);
650 - /* Set the initial value for the power button IRQ handler */
651 - power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
653 - mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
658 -static void __exit dsmg600_power_exit(void)
660 - if (!(machine_is_dsmg600()))
663 - del_timer_sync(&dsmg600_power_timer);
665 - free_irq(gpio_to_irq(DSMG600_RB_GPIO), NULL);
668 -module_init(dsmg600_power_init);
669 -module_exit(dsmg600_power_exit);
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
680 * DSM-G600 board-setup
682 + * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
683 * Copyright (C) 2006 Tower Technologies
684 - * Author: Alessandro Zummo <a.zummo@towertech.it>
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
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/
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>
712 #include <asm/mach/arch.h>
713 #include <asm/mach/flash.h>
714 #include <asm/mach/time.h>
715 +#include <asm/gpio.h>
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);
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.
726 +static int power_button_countdown;
728 +/* Must hold the button down for at least this many counts to be processed */
729 +#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
731 +static void dsmg600_power_handler(unsigned long data);
732 +static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0);
734 +static void dsmg600_power_handler(unsigned long data)
736 + /* This routine is called twice per second to check the
737 + * state of the power button.
740 + if (gpio_get_value(DSMG600_PB_GPIO)) {
742 + /* IO Pin is 1 (button pushed) */
743 + if (power_button_countdown > 0)
744 + power_button_countdown--;
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.
756 + /* Change the state of the power LED to "blink" */
757 + gpio_line_set(DSMG600_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
759 + power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
763 + mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
766 +static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id)
768 + /* This is the paper-clip reset, it shuts the machine down directly. */
769 + machine_power_off();
771 + return IRQ_HANDLED;
774 static void __init dsmg600_timer_init(void)
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;
781 - pm_power_off = dsmg600_power_off;
783 i2c_register_board_info(0, dsmg600_i2c_board_info,
784 ARRAY_SIZE(dsmg600_i2c_board_info));
786 @@ -176,6 +235,29 @@ static void __init dsmg600_init(void)
787 (void)platform_device_register(&dsmg600_uart);
789 platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices));
791 + pm_power_off = dsmg600_power_off;
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) {
797 + printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
798 + gpio_to_irq(DSMG600_RB_GPIO));
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.
806 + /* Make sure that the power button GPIO is set up as an input */
807 + gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN);
809 + /* Set the initial value for the power button IRQ handler */
810 + power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
812 + mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
815 MACHINE_START(DSMG600, "D-Link DSM-G600 RevA")