232dd9a8c570cdd06fb5760a45e98efc61514b72
[openwrt/svn-archive/archive.git] / target / linux / ixp4xx / patches-2.6.23 / 017-nas100d_auto_power_on.patch
1 ---
2 arch/arm/mach-ixp4xx/nas100d-power.c | 68 ++++++++++++++++++++++++++++++++--
3 include/asm-arm/arch-ixp4xx/nas100d.h | 18 +++++----
4 2 files changed, 75 insertions(+), 11 deletions(-)
5
6 Index: linux-2.6.22-rc5-armeb/arch/arm/mach-ixp4xx/nas100d-power.c
7 ===================================================================
8 --- linux-2.6.22-rc5-armeb.orig/arch/arm/mach-ixp4xx/nas100d-power.c
9 +++ linux-2.6.22-rc5-armeb/arch/arm/mach-ixp4xx/nas100d-power.c
10 @@ -21,15 +21,60 @@
11 #include <linux/irq.h>
12 #include <linux/module.h>
13 #include <linux/reboot.h>
14 +#include <linux/jiffies.h>
15 +#include <linux/timer.h>
16
17 #include <asm/mach-types.h>
18
19 -static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
20 +extern void ctrl_alt_del(void);
21 +
22 +/* This is used to make sure the power-button pusher is serious. The button
23 + * must be held until the value of this counter reaches zero.
24 + */
25 +static volatile int power_button_countdown;
26 +
27 +/* Must hold the button down for at least this many counts to be processed */
28 +#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
29 +
30 +static void nas100d_power_handler(unsigned long data);
31 +static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler, 0, 0);
32 +
33 +static void nas100d_power_handler(unsigned long data)
34 {
35 - /* Signal init to do the ctrlaltdel action, this will bypass init if
36 - * it hasn't started and do a kernel_restart.
37 + /* This routine is called twice per second to check the
38 + * state of the power button.
39 */
40 - ctrl_alt_del();
41 +
42 + if (*IXP4XX_GPIO_GPINR & NAS100D_PB_BM) {
43 +
44 + /* IO Pin is 1 (button pushed) */
45 + if (power_button_countdown > 0) {
46 + power_button_countdown--;
47 + }
48 +
49 + } else {
50 +
51 + /* Done on button release, to allow for auto-power-on mods. */
52 + if (power_button_countdown == 0) {
53 + /* Signal init to do the ctrlaltdel action, this will bypass
54 + * init if it hasn't started and do a kernel_restart.
55 + */
56 + ctrl_alt_del();
57 +
58 + /* Change the state of the power LED to "blink" */
59 + gpio_line_set(NAS100D_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
60 + } else {
61 + power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
62 + }
63 + }
64 +
65 + mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
66 +}
67 +
68 +static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
69 +{
70 + /* This is the paper-clip reset, it shuts the machine down directly. */
71 + machine_power_off();
72
73 return IRQ_HANDLED;
74 }
75 @@ -50,6 +95,19 @@
76 return -EIO;
77 }
78
79 + /* The power button on the Iomega NAS100d is on GPIO 14, but
80 + * it cannot handle interrupts on that GPIO line. So we'll
81 + * have to poll it with a kernel timer.
82 + */
83 +
84 + /* Make sure that the power button GPIO is set up as an input */
85 + gpio_line_config(NAS100D_PB_GPIO, IXP4XX_GPIO_IN);
86 +
87 + /* Set the initial value for the power button IRQ handler */
88 + power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
89 +
90 + mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
91 +
92 return 0;
93 }
94
95 @@ -58,6 +116,8 @@
96 if (!(machine_is_nas100d()))
97 return;
98
99 + del_timer_sync(&nas100d_power_timer);
100 +
101 free_irq(NAS100D_RB_IRQ, NULL);
102 }
103
104 Index: linux-2.6.22-rc5-armeb/include/asm-arm/arch-ixp4xx/nas100d.h
105 ===================================================================
106 --- linux-2.6.22-rc5-armeb.orig/include/asm-arm/arch-ixp4xx/nas100d.h
107 +++ linux-2.6.22-rc5-armeb/include/asm-arm/arch-ixp4xx/nas100d.h
108 @@ -39,14 +39,18 @@
109 /* Buttons */
110
111 #define NAS100D_PB_GPIO 14
112 +#define NAS100D_PB_BM (1L << NAS100D_PB_GPIO)
113 +
114 #define NAS100D_RB_GPIO 4
115 -#define NAS100D_PO_GPIO 12 /* power off */
116
117 -#define NAS100D_PB_IRQ IRQ_IXP4XX_GPIO14
118 #define NAS100D_RB_IRQ IRQ_IXP4XX_GPIO4
119
120 -/*
121 -#define NAS100D_PB_BM (1L << NAS100D_PB_GPIO)
122 -#define NAS100D_PO_BM (1L << NAS100D_PO_GPIO)
123 -#define NAS100D_RB_BM (1L << NAS100D_RB_GPIO)
124 -*/
125 +#define NAS100D_PO_GPIO 12 /* power off */
126 +
127 +/* LEDs */
128 +
129 +#define NAS100D_LED_PWR_GPIO 15
130 +#define NAS100D_LED_PWR_BM (1L << NAS100D_LED_PWR_GPIO)
131 +
132 +#define NAS100D_LED_WLAN_GPIO 0
133 +#define NAS100D_LED_WLAN_BM (1L << NAS100D_LED_WLAN_GPIO)