Reordered patches prior to upstream submission (power patches before a new board...
[nslu2-linux/kernel.git] / patches / 2.6.24 / ixp4xx-subsume-dsmg600-power.patch
blobe7ebff1678c9ad3740f6e3610a32dd077d3f0876
1 From 8dcde9462203f72f45395bd6e58fd1d906604bd9 Mon Sep 17 00:00:00 2001
2 From: Rod Whitby <rod@whitby.id.au>
3 Date: Thu, 31 Jan 2008 21:50:15 +1030
4 Subject: ixp4xx: Merge dsmg600-power.c into dsmg600-setup.c
6 There is no reason to have power control in a separate file from the
7 board setup code. Merge it back into the board setup file and remove
8 superfluous header includes.
10 Signed-off-by: Rod Whitby <rod@whitby.id.au>
12 PATCH FOLLOWS
13 KernelVersion: 2.6.24-git9
15 diff --git a/arch/arm/mach-ixp4xx/Makefile b/arch/arm/mach-ixp4xx/Makefile
16 index a7880ab..c195688 100644
17 --- a/arch/arm/mach-ixp4xx/Makefile
18 +++ b/arch/arm/mach-ixp4xx/Makefile
19 @@ -25,7 +25,7 @@ obj-$(CONFIG_ARCH_ADI_COYOTE) += coyote-setup.o
20 obj-$(CONFIG_MACH_GTWX5715) += gtwx5715-setup.o
21 obj-$(CONFIG_MACH_NSLU2) += nslu2-setup.o
22 obj-$(CONFIG_MACH_NAS100D) += nas100d-setup.o
23 -obj-$(CONFIG_MACH_DSMG600) += dsmg600-setup.o dsmg600-power.o
24 +obj-$(CONFIG_MACH_DSMG600) += dsmg600-setup.o
25 obj-$(CONFIG_MACH_GATEWAY7001) += gateway7001-setup.o
26 obj-$(CONFIG_MACH_WG302V2) += wg302v2-setup.o
28 diff --git a/arch/arm/mach-ixp4xx/dsmg600-power.c b/arch/arm/mach-ixp4xx/dsmg600-power.c
29 deleted file mode 100644
30 index db63987..0000000
31 --- a/arch/arm/mach-ixp4xx/dsmg600-power.c
32 +++ /dev/null
33 @@ -1,129 +0,0 @@
34 -/*
35 - * arch/arm/mach-ixp4xx/dsmg600-power.c
36 - *
37 - * DSM-G600 Power/Reset driver
38 - * Author: Michael Westerhof <mwester@dls.net>
39 - *
40 - * Based on nslu2-power.c
41 - * Copyright (C) 2005 Tower Technologies
42 - * Author: Alessandro Zummo <a.zummo@towertech.it>
43 - *
44 - * which was based on nslu2-io.c
45 - * Copyright (C) 2004 Karen Spearel
46 - *
47 - * Maintainers: http://www.nslu2-linux.org/
48 - *
49 - * This program is free software; you can redistribute it and/or modify
50 - * it under the terms of the GNU General Public License version 2 as
51 - * published by the Free Software Foundation.
52 - *
53 - */
55 -#include <linux/module.h>
56 -#include <linux/reboot.h>
57 -#include <linux/interrupt.h>
58 -#include <linux/irq.h>
59 -#include <linux/jiffies.h>
60 -#include <linux/timer.h>
62 -#include <asm/gpio.h>
63 -#include <asm/mach-types.h>
65 -/* This is used to make sure the power-button pusher is serious. The button
66 - * must be held until the value of this counter reaches zero.
67 - */
68 -static int power_button_countdown;
70 -/* Must hold the button down for at least this many counts to be processed */
71 -#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
73 -static void dsmg600_power_handler(unsigned long data);
74 -static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0);
76 -static void dsmg600_power_handler(unsigned long data)
78 - /* This routine is called twice per second to check the
79 - * state of the power button.
80 - */
82 - if (gpio_get_value(DSMG600_PB_GPIO)) {
84 - /* IO Pin is 1 (button pushed) */
85 - if (power_button_countdown > 0)
86 - power_button_countdown--;
88 - } else {
90 - /* Done on button release, to allow for auto-power-on mods. */
91 - if (power_button_countdown == 0) {
92 - /* Signal init to do the ctrlaltdel action,
93 - * this will bypass init if it hasn't started
94 - * and do a kernel_restart.
95 - */
96 - ctrl_alt_del();
98 - /* Change the state of the power LED to "blink" */
99 - gpio_line_set(DSMG600_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
100 - } else {
101 - power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
105 - mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
108 -static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id)
110 - /* This is the paper-clip reset, it shuts the machine down directly. */
111 - machine_power_off();
113 - return IRQ_HANDLED;
116 -static int __init dsmg600_power_init(void)
118 - if (!(machine_is_dsmg600()))
119 - return 0;
121 - if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler,
122 - IRQF_DISABLED | IRQF_TRIGGER_LOW, "DSM-G600 reset button",
123 - NULL) < 0) {
125 - printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
126 - gpio_to_irq(DSMG600_RB_GPIO));
128 - return -EIO;
131 - /* The power button on the D-Link DSM-G600 is on GPIO 15, but
132 - * it cannot handle interrupts on that GPIO line. So we'll
133 - * have to poll it with a kernel timer.
134 - */
136 - /* Make sure that the power button GPIO is set up as an input */
137 - gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN);
139 - /* Set the initial value for the power button IRQ handler */
140 - power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
142 - mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
144 - return 0;
147 -static void __exit dsmg600_power_exit(void)
149 - if (!(machine_is_dsmg600()))
150 - return;
152 - del_timer_sync(&dsmg600_power_timer);
154 - free_irq(gpio_to_irq(DSMG600_RB_GPIO), NULL);
157 -module_init(dsmg600_power_init);
158 -module_exit(dsmg600_power_exit);
160 -MODULE_AUTHOR("Michael Westerhof <mwester@dls.net>");
161 -MODULE_DESCRIPTION("DSM-G600 Power/Reset driver");
162 -MODULE_LICENSE("GPL");
163 diff --git a/arch/arm/mach-ixp4xx/dsmg600-setup.c b/arch/arm/mach-ixp4xx/dsmg600-setup.c
164 index d0e1295..ae48eab 100644
165 --- a/arch/arm/mach-ixp4xx/dsmg600-setup.c
166 +++ b/arch/arm/mach-ixp4xx/dsmg600-setup.c
167 @@ -1,20 +1,29 @@
169 * DSM-G600 board-setup
171 + * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
172 * Copyright (C) 2006 Tower Technologies
173 - * Author: Alessandro Zummo <a.zummo@towertech.it>
175 - * based ixdp425-setup.c:
176 + * based on ixdp425-setup.c:
177 * Copyright (C) 2003-2004 MontaVista Software, Inc.
178 + * based on nslu2-power.c:
179 + * Copyright (C) 2005 Tower Technologies
180 + * based on nslu2-io.c:
181 + * Copyright (C) 2004 Karen Spearel
183 * Author: Alessandro Zummo <a.zummo@towertech.it>
184 + * Author: Michael Westerhof <mwester@dls.net>
185 + * Author: Rod Whitby <rod@whitby.id.au>
186 * Maintainers: http://www.nslu2-linux.org/
189 -#include <linux/kernel.h>
190 +#include <linux/irq.h>
191 +#include <linux/jiffies.h>
192 +#include <linux/timer.h>
193 #include <linux/serial.h>
194 #include <linux/serial_8250.h>
195 #include <linux/leds.h>
196 +#include <linux/reboot.h>
197 #include <linux/i2c.h>
198 #include <linux/i2c-gpio.h>
200 @@ -22,6 +31,7 @@
201 #include <asm/mach/arch.h>
202 #include <asm/mach/flash.h>
203 #include <asm/mach/time.h>
204 +#include <asm/gpio.h>
206 static struct flash_platform_data dsmg600_flash_data = {
207 .map_name = "cfi_probe",
208 @@ -140,6 +150,57 @@ static void dsmg600_power_off(void)
209 gpio_line_set(DSMG600_PO_GPIO, IXP4XX_GPIO_HIGH);
212 +/* This is used to make sure the power-button pusher is serious. The button
213 + * must be held until the value of this counter reaches zero.
214 + */
215 +static int power_button_countdown;
217 +/* Must hold the button down for at least this many counts to be processed */
218 +#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
220 +static void dsmg600_power_handler(unsigned long data);
221 +static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0);
223 +static void dsmg600_power_handler(unsigned long data)
225 + /* This routine is called twice per second to check the
226 + * state of the power button.
227 + */
229 + if (gpio_get_value(DSMG600_PB_GPIO)) {
231 + /* IO Pin is 1 (button pushed) */
232 + if (power_button_countdown > 0)
233 + power_button_countdown--;
235 + } else {
237 + /* Done on button release, to allow for auto-power-on mods. */
238 + if (power_button_countdown == 0) {
239 + /* Signal init to do the ctrlaltdel action,
240 + * this will bypass init if it hasn't started
241 + * and do a kernel_restart.
242 + */
243 + ctrl_alt_del();
245 + /* Change the state of the power LED to "blink" */
246 + gpio_line_set(DSMG600_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
247 + } else {
248 + power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
252 + mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
255 +static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id)
257 + /* This is the paper-clip reset, it shuts the machine down directly. */
258 + machine_power_off();
260 + return IRQ_HANDLED;
263 static void __init dsmg600_timer_init(void)
265 /* The xtal on this machine is non-standard. */
266 @@ -164,8 +225,6 @@ static void __init dsmg600_init(void)
267 dsmg600_flash_resource.end =
268 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
270 - pm_power_off = dsmg600_power_off;
272 i2c_register_board_info(0, dsmg600_i2c_board_info,
273 ARRAY_SIZE(dsmg600_i2c_board_info));
275 @@ -176,6 +235,29 @@ static void __init dsmg600_init(void)
276 (void)platform_device_register(&dsmg600_uart);
278 platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices));
280 + pm_power_off = dsmg600_power_off;
282 + set_irq_type(gpio_to_irq(DSMG600_RB_GPIO), IRQT_LOW);
283 + if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler,
284 + IRQF_DISABLED, "DSM-G600 reset button", NULL) < 0) {
286 + printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
287 + gpio_to_irq(DSMG600_RB_GPIO));
290 + /* The power button on the D-Link DSM-G600 is on GPIO 15, but
291 + * it cannot handle interrupts on that GPIO line. So we'll
292 + * have to poll it with a kernel timer.
293 + */
295 + /* Make sure that the power button GPIO is set up as an input */
296 + gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN);
298 + /* Set the initial value for the power button IRQ handler */
299 + power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
301 + mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
304 MACHINE_START(DSMG600, "D-Link DSM-G600 RevA")
306 1.5.2.5