Reordered patches prior to upstream submission (power patches before a new board...
[nslu2-linux/kernel.git] / patches / 2.6.24 / ixp4xx-subsume-nas100d-power.patch
blobf9d2cfe971c2763656f24bab8cee56d0a8adb19c
1 From 23a2c7ee8d5636e09c19b473ad5f8a81ff836107 Mon Sep 17 00:00:00 2001
2 From: Rod Whitby <rod@whitby.id.au>
3 Date: Thu, 31 Jan 2008 21:41:53 +1030
4 Subject: ixp4xx: Merge nas100d-power.c into nas100d-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 4fc7316..a7880ab 100644
17 --- a/arch/arm/mach-ixp4xx/Makefile
18 +++ b/arch/arm/mach-ixp4xx/Makefile
19 @@ -24,7 +24,7 @@ obj-$(CONFIG_MACH_IXDPG425) += coyote-setup.o
20 obj-$(CONFIG_ARCH_ADI_COYOTE) += coyote-setup.o
21 obj-$(CONFIG_MACH_GTWX5715) += gtwx5715-setup.o
22 obj-$(CONFIG_MACH_NSLU2) += nslu2-setup.o
23 -obj-$(CONFIG_MACH_NAS100D) += nas100d-setup.o nas100d-power.o
24 +obj-$(CONFIG_MACH_NAS100D) += nas100d-setup.o
25 obj-$(CONFIG_MACH_DSMG600) += dsmg600-setup.o dsmg600-power.o
26 obj-$(CONFIG_MACH_GATEWAY7001) += gateway7001-setup.o
27 obj-$(CONFIG_MACH_WG302V2) += wg302v2-setup.o
28 diff --git a/arch/arm/mach-ixp4xx/nas100d-power.c b/arch/arm/mach-ixp4xx/nas100d-power.c
29 deleted file mode 100644
30 index 4c1c01b..0000000
31 --- a/arch/arm/mach-ixp4xx/nas100d-power.c
32 +++ /dev/null
33 @@ -1,128 +0,0 @@
34 -/*
35 - * arch/arm/mach-ixp4xx/nas100d-power.c
36 - *
37 - * NAS 100d Power/Reset driver
38 - *
39 - * Copyright (C) 2005 Tower Technologies
40 - *
41 - * based on nas100d-io.c
42 - * Copyright (C) 2004 Karen Spearel
43 - *
44 - * Author: Alessandro Zummo <a.zummo@towertech.it>
45 - * Maintainers: http://www.nslu2-linux.org/
46 - *
47 - * This program is free software; you can redistribute it and/or modify
48 - * it under the terms of the GNU General Public License version 2 as
49 - * published by the Free Software Foundation.
50 - *
51 - */
53 -#include <linux/interrupt.h>
54 -#include <linux/irq.h>
55 -#include <linux/module.h>
56 -#include <linux/reboot.h>
57 -#include <linux/jiffies.h>
58 -#include <linux/timer.h>
60 -#include <asm/gpio.h>
61 -#include <asm/mach-types.h>
63 -/* This is used to make sure the power-button pusher is serious. The button
64 - * must be held until the value of this counter reaches zero.
65 - */
66 -static int power_button_countdown;
68 -/* Must hold the button down for at least this many counts to be processed */
69 -#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
71 -static void nas100d_power_handler(unsigned long data);
72 -static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler, 0, 0);
74 -static void nas100d_power_handler(unsigned long data)
76 - /* This routine is called twice per second to check the
77 - * state of the power button.
78 - */
80 - if (gpio_get_value(NAS100D_PB_GPIO)) {
82 - /* IO Pin is 1 (button pushed) */
83 - if (power_button_countdown > 0)
84 - power_button_countdown--;
86 - } else {
88 - /* Done on button release, to allow for auto-power-on mods. */
89 - if (power_button_countdown == 0) {
90 - /* Signal init to do the ctrlaltdel action,
91 - * this will bypass init if it hasn't started
92 - * and do a kernel_restart.
93 - */
94 - ctrl_alt_del();
96 - /* Change the state of the power LED to "blink" */
97 - gpio_line_set(NAS100D_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
98 - } else {
99 - power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
103 - mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
106 -static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
108 - /* This is the paper-clip reset, it shuts the machine down directly. */
109 - machine_power_off();
111 - return IRQ_HANDLED;
114 -static int __init nas100d_power_init(void)
116 - if (!(machine_is_nas100d()))
117 - return 0;
119 - set_irq_type(gpio_to_irq(NAS100D_RB_GPIO), IRQT_LOW);
121 - if (request_irq(gpio_to_irq(NAS100D_RB_GPIO), &nas100d_reset_handler,
122 - IRQF_DISABLED, "NAS100D reset button", NULL) < 0) {
124 - printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
125 - gpio_to_irq(NAS100D_RB_GPIO));
127 - return -EIO;
130 - /* The power button on the Iomega NAS100d is on GPIO 14, but
131 - * it cannot handle interrupts on that GPIO line. So we'll
132 - * have to poll it with a kernel timer.
133 - */
135 - /* Make sure that the power button GPIO is set up as an input */
136 - gpio_line_config(NAS100D_PB_GPIO, IXP4XX_GPIO_IN);
138 - /* Set the initial value for the power button IRQ handler */
139 - power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
141 - mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
143 - return 0;
146 -static void __exit nas100d_power_exit(void)
148 - if (!(machine_is_nas100d()))
149 - return;
151 - del_timer_sync(&nas100d_power_timer);
153 - free_irq(gpio_to_irq(NAS100D_RB_GPIO), NULL);
156 -module_init(nas100d_power_init);
157 -module_exit(nas100d_power_exit);
159 -MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
160 -MODULE_DESCRIPTION("NAS100D Power/Reset driver");
161 -MODULE_LICENSE("GPL");
162 diff --git a/arch/arm/mach-ixp4xx/nas100d-setup.c b/arch/arm/mach-ixp4xx/nas100d-setup.c
163 index a432226..f901a82 100644
164 --- a/arch/arm/mach-ixp4xx/nas100d-setup.c
165 +++ b/arch/arm/mach-ixp4xx/nas100d-setup.c
166 @@ -3,8 +3,14 @@
168 * NAS 100d board-setup
170 - * based ixdp425-setup.c:
171 + * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
173 + * based on ixdp425-setup.c:
174 * Copyright (C) 2003-2004 MontaVista Software, Inc.
175 + * based on nas100d-power.c:
176 + * Copyright (C) 2005 Tower Technologies
177 + * based on nas100d-io.c
178 + * Copyright (C) 2004 Karen Spearel
180 * Author: Alessandro Zummo <a.zummo@towertech.it>
181 * Author: Rod Whitby <rod@whitby.id.au>
182 @@ -13,10 +19,13 @@
185 #include <linux/if_ether.h>
186 -#include <linux/kernel.h>
187 +#include <linux/irq.h>
188 +#include <linux/jiffies.h>
189 +#include <linux/timer.h>
190 #include <linux/serial.h>
191 #include <linux/serial_8250.h>
192 #include <linux/leds.h>
193 +#include <linux/reboot.h>
194 #include <linux/i2c.h>
195 #include <linux/i2c-gpio.h>
197 @@ -24,6 +33,7 @@
198 #include <asm/mach/arch.h>
199 #include <asm/mach/flash.h>
200 #include <asm/io.h>
201 +#include <asm/gpio.h>
203 static struct flash_platform_data nas100d_flash_data = {
204 .map_name = "cfi_probe",
205 @@ -168,6 +178,57 @@ static void nas100d_power_off(void)
206 gpio_line_set(NAS100D_PO_GPIO, IXP4XX_GPIO_HIGH);
209 +/* This is used to make sure the power-button pusher is serious. The button
210 + * must be held until the value of this counter reaches zero.
211 + */
212 +static int power_button_countdown;
214 +/* Must hold the button down for at least this many counts to be processed */
215 +#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
217 +static void nas100d_power_handler(unsigned long data);
218 +static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler, 0, 0);
220 +static void nas100d_power_handler(unsigned long data)
222 + /* This routine is called twice per second to check the
223 + * state of the power button.
224 + */
226 + if (gpio_get_value(NAS100D_PB_GPIO)) {
228 + /* IO Pin is 1 (button pushed) */
229 + if (power_button_countdown > 0)
230 + power_button_countdown--;
232 + } else {
234 + /* Done on button release, to allow for auto-power-on mods. */
235 + if (power_button_countdown == 0) {
236 + /* Signal init to do the ctrlaltdel action,
237 + * this will bypass init if it hasn't started
238 + * and do a kernel_restart.
239 + */
240 + ctrl_alt_del();
242 + /* Change the state of the power LED to "blink" */
243 + gpio_line_set(NAS100D_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
244 + } else {
245 + power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
249 + mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
252 +static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
254 + /* This is the paper-clip reset, it shuts the machine down directly. */
255 + machine_power_off();
257 + return IRQ_HANDLED;
260 static void __init nas100d_init(void)
262 DECLARE_MAC_BUF(mac_buf);
263 @@ -183,8 +244,6 @@ static void __init nas100d_init(void)
264 nas100d_flash_resource.end =
265 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
267 - pm_power_off = nas100d_power_off;
269 i2c_register_board_info(0, nas100d_i2c_board_info,
270 ARRAY_SIZE(nas100d_i2c_board_info));
272 @@ -197,6 +256,29 @@ static void __init nas100d_init(void)
274 platform_add_devices(nas100d_devices, ARRAY_SIZE(nas100d_devices));
276 + pm_power_off = nas100d_power_off;
278 + set_irq_type(gpio_to_irq(NAS100D_RB_GPIO), IRQT_LOW);
279 + if (request_irq(gpio_to_irq(NAS100D_RB_GPIO), &nas100d_reset_handler,
280 + IRQF_DISABLED, "NAS100D reset button", NULL) < 0) {
282 + printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
283 + gpio_to_irq(NAS100D_RB_GPIO));
286 + /* The power button on the Iomega NAS100d is on GPIO 14, but
287 + * it cannot handle interrupts on that GPIO line. So we'll
288 + * have to poll it with a kernel timer.
289 + */
291 + /* Make sure that the power button GPIO is set up as an input */
292 + gpio_line_config(NAS100D_PB_GPIO, IXP4XX_GPIO_IN);
294 + /* Set the initial value for the power button IRQ handler */
295 + power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
297 + mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
300 * Map in a portion of the flash and read the MAC address.
301 * Since it is stored in BE in the flash itself, we need to
303 1.5.2.5