u-boot-mkimage-gta01-native: re-add till uboot-utils actually works
[openembedded.git] / packages / linux / linux-ezx-2.6.21 / ezx-bp.patch
1 Index: linux-2.6.21/arch/arm/mach-pxa/ezx.c
2 ===================================================================
3 --- linux-2.6.21.orig/arch/arm/mach-pxa/ezx.c   2007-05-12 20:40:44.000000000 -0300
4 +++ linux-2.6.21/arch/arm/mach-pxa/ezx.c        2007-05-14 21:12:37.000000000 -0300
5 @@ -100,9 +100,41 @@
6         .init           = ezx_ohci_init,
7  };
8  
9 +/* BP */
10 +static struct resource ezxbp_resources[] = {
11 +       [0] = {
12 +               .start          = IRQ_GPIO(GPIO_BP_RDY),
13 +               .end            = IRQ_GPIO(GPIO_BP_RDY),
14 +               .flags          = IORESOURCE_IRQ,
15 +       },
16 +       [1] = {
17 +               .start          = IRQ_GPIO(GPIO_BB_WDI2),
18 +               .end            = IRQ_GPIO(GPIO_BB_WDI2),
19 +               .flags          = IORESOURCE_IRQ,
20 +       },
21 +       [2] = {
22 +               .start          = IRQ_GPIO(GPIO_BB_WDI),
23 +               .end            = IRQ_GPIO(GPIO_BB_WDI),
24 +               .flags          = IORESOURCE_IRQ,
25 +       },
26 +};
27 +
28 +static struct platform_device ezxbp_device = {
29 +       .name           = "ezx-bp",
30 +       .dev            = {
31 +               //.parent               =
32 +               //.platform_data        =
33 +       },
34 +       .id             = -1,
35 +       .num_resources  = ARRAY_SIZE(ezxbp_resources),
36 +       .resource       = ezxbp_resources,
37 +};
38 +
39 +
40  
41  static struct platform_device *devices[] __initdata = {
42         &ezxssp_device,
43 +       &ezxbp_device,
44  };
45  
46  static int __init ezx_init(void)
47 Index: linux-2.6.21/arch/arm/mach-pxa/Kconfig
48 ===================================================================
49 --- linux-2.6.21.orig/arch/arm/mach-pxa/Kconfig 2007-05-12 20:40:44.000000000 -0300
50 +++ linux-2.6.21/arch/arm/mach-pxa/Kconfig      2007-05-14 21:12:37.000000000 -0300
51 @@ -94,6 +94,9 @@
52  
53  endchoice
54  
55 +config EZX_BP
56 +       bool "BP Control code for EZX Platform"
57 +
58  endif
59  
60  endmenu
61 Index: linux-2.6.21/arch/arm/mach-pxa/ezx-bp.c
62 ===================================================================
63 --- /dev/null   1970-01-01 00:00:00.000000000 +0000
64 +++ linux-2.6.21/arch/arm/mach-pxa/ezx-bp.c     2007-05-12 21:28:07.000000000 -0300
65 @@ -0,0 +1,250 @@
66 +/*
67 + *  BP handshake code for Motorola EZX phones
68 + *
69 + *  Copyright (c) 2007 Daniel Ribeiro <drwyrm@gmail.com>
70 + *
71 + *  Based on Motorola's a780.c Copyright (c) 2003-2005 Motorola
72 + *
73 + *  This program is free software; you can redistribute it and/or modify
74 + *  it under the terms of the GNU General Public License version 2 as
75 + *  published by the Free Software Foundation.
76 + *
77 + */
78 +
79 +
80 +#include <linux/kernel.h>
81 +#include <linux/interrupt.h>
82 +#include <linux/module.h>
83 +#include <linux/platform_device.h>
84 +
85 +#include <asm/mach/irq.h>
86 +#include <asm/arch/hardware.h>
87 +#include <asm/arch/pxa-regs.h>
88 +
89 +#include <asm/arch/ezx.h>
90 +
91 +/* BP Handshake */
92 +#define FIRST_STEP              2
93 +#define LAST_STEP               3
94 +#define BP_RDY_TIMEOUT          0x000c0000
95 +
96 +#if 1
97 +#define DEBUGP(x, args ...)    printk(x, ##args)
98 +#else
99 +#define DEBUGP(x, args ...)
100 +#endif
101 +
102 +struct bp {
103 +       int irq_wdi;
104 +       int irq_wdi2;
105 +       int irq_rdy;
106 +};
107 +
108 +/* check power down condition */
109 +static inline void check_power_off(void)
110 +{
111 +       if (pxa_gpio_get_value(GPIO_BB_WDI2) == 0) {
112 +               DEBUGP("BP request poweroff!\n");
113 +               pm_power_off();
114 +       }
115 +}
116 +
117 +static int step = FIRST_STEP;
118 +
119 +inline int bp_handshake_passed(void)
120 +{
121 +       return (step > LAST_STEP);
122 +}
123 +EXPORT_SYMBOL(bp_handshake_passed);
124 +
125 +void handshake(void)
126 +{
127 +        /* step 1: check MCU_INT_SW or BP_RDY is low (now it is checked in apboot) */
128 +       DEBUGP("bp handshake entered!\n");
129 +        if (step == 1) {
130 +                int timeout = BP_RDY_TIMEOUT;
131 +
132 +                /* config MCU_INT_SW, BP_RDY as input */
133 +               pxa_gpio_mode(GPIO_MCU_INT_SW | GPIO_IN);
134 +               pxa_gpio_mode(GPIO_BP_RDY | GPIO_IN);
135 +
136 +                while ( timeout -- ) {
137 +                        if (pxa_gpio_get_value(GPIO_MCU_INT_SW) == 0
138 +                                || pxa_gpio_get_value(GPIO_BP_RDY) == 0) {
139 +                                step ++;
140 +                                break;
141 +                        }
142 +
143 +                        check_power_off();
144 +                }
145 +               DEBUGP("ezx-bp: handshake step 1\n");
146 +        }
147 +
148 +        /* step 2: wait BP_RDY is low */
149 +        if (step == 2) {
150 +                if (pxa_gpio_get_value(GPIO_BP_RDY) == 0) {
151 +                        /* config MCU_INT_SW as output */
152 +                        pxa_gpio_mode(GPIO_MCU_INT_SW | GPIO_OUT);
153 +                        pxa_gpio_set_value(GPIO_MCU_INT_SW, 0);
154 +
155 +                        step ++;
156 +                       DEBUGP("ezx-bp: handshake step 2\n");
157 +                }
158 +        }
159 +
160 +        /* step 3: wait BP_RDY is high */
161 +        else if (step == 3) {
162 +                if (pxa_gpio_get_value(GPIO_BP_RDY)) {
163 +                        step ++;
164 +                        //FIXME delay_bklight();
165 +                        pxa_gpio_set_value(GPIO_MCU_INT_SW, 1);
166 +                       printk(KERN_NOTICE "ezx-bp: handshake passed\n");
167 +                }
168 +        }
169 +}
170 +
171 +irqreturn_t bp_wdi_handler(int irq, void *dev_id)
172 +{
173 +       DEBUGP("BP Lowered WDI line. This is not good :(\n");
174 +       /*
175 +        * this means that BP is not responsive.
176 +        * we could try to reset BP and then handshake again
177 +        * but i doubt its possible to bring it up again.
178 +        */
179 +       return IRQ_HANDLED;
180 +}
181 +
182 +static irqreturn_t bp_rdy_handler(int irq, void *dev_id)
183 +{
184 +       struct bp *bp = dev_id;
185 +       DEBUGP("BP rdy irq\n");
186 +       if (!bp_handshake_passed()) {
187 +               handshake();
188 +               if (bp_handshake_passed()) {
189 +                       disable_irq(bp->irq_wdi2);
190 +
191 +                       /* set bp_rdy handle for usb ipc */
192 +                       set_irq_type(bp->irq_rdy, IRQT_FALLING);
193 +               }
194 +       }
195 +#ifdef CONFIG_TS0710_MUX_USB
196 +       else usb_send_readurb();
197 +#endif
198 +       return IRQ_HANDLED;
199 +}
200 +
201 +/* BP request for poweroff */
202 +static irqreturn_t bp_wdi2_handler(int irq, void *dev_id)
203 +{
204 +       DEBUGP("BP request poweroff!\n");
205 +       pm_power_off();
206 +       return IRQ_HANDLED;
207 +}
208 +
209 +static int __init ezxbp_probe(struct platform_device *dev)
210 +{
211 +       int ret;
212 +       struct bp *bp;
213 +
214 +       bp = kzalloc(sizeof(*bp), GFP_KERNEL);
215 +       if (!bp)
216 +               return -ENOMEM;
217 +
218 +       bp->irq_rdy = platform_get_irq(dev, 0);
219 +       if(bp->irq_rdy < 0) {
220 +               ret = bp->irq_rdy;
221 +               goto fail;
222 +       }
223 +
224 +       bp->irq_wdi2 = platform_get_irq(dev, 1);
225 +       if(bp->irq_wdi2 < 0) {
226 +               ret = bp->irq_wdi2;
227 +               goto fail;
228 +       }
229 +
230 +       bp->irq_wdi = platform_get_irq(dev, 2);
231 +       if(bp->irq_wdi < 0) {
232 +               ret = bp->irq_wdi;
233 +               goto fail;
234 +       }
235 +
236 +        set_irq_type(bp->irq_wdi, IRQT_FALLING);
237 +        request_irq(bp->irq_wdi, bp_wdi_handler, SA_INTERRUPT,
238 +                       "bp wdi", bp);
239 +
240 +        set_irq_type(bp->irq_rdy, IRQT_BOTHEDGE);
241 +        request_irq(bp->irq_rdy, bp_rdy_handler, SA_INTERRUPT,
242 +                       "bp rdy", bp);
243 +
244 +        set_irq_type(bp->irq_wdi2, IRQT_FALLING);
245 +        request_irq(bp->irq_wdi2, bp_wdi2_handler, SA_INTERRUPT,
246 +                       "bp wdi2", bp);
247 +
248 +        /* turn on BP */
249 +        pxa_gpio_mode(GPIO_BB_RESET|GPIO_OUT);
250 +        pxa_gpio_set_value(GPIO_BB_RESET, 1);
251 +
252 +        check_power_off();
253 +
254 +        handshake();
255 +
256 +       return 0;
257 +fail:
258 +       kfree(bp);
259 +       return ret;
260 +}
261 +
262 +static int ezxbp_remove(struct platform_device *dev)
263 +{
264 +       struct bp *bp = platform_get_drvdata(dev);
265 +
266 +       free_irq(bp->irq_wdi, bp);
267 +       free_irq(bp->irq_wdi2, bp);
268 +       free_irq(bp->irq_rdy, bp);
269 +       kfree(bp);
270 +
271 +       return 0;
272 +}
273 +
274 +static int ezxbp_suspend(struct platform_device *dev, pm_message_t state)
275 +{
276 +       DEBUGP("bp suspend!\n");
277 +//     pxa_gpio_set_value(GPIO_MCU_INT_SW, 0);
278 +        return 0;
279 +}
280 +
281 +static int ezxbp_resume(struct platform_device *dev)
282 +{
283 +       DEBUGP("bp resume!\n");
284 +//     pxa_gpio_set_value(GPIO_MCU_INT_SW, 1);
285 +        return 0;
286 +}
287 +static struct platform_driver ezxbp_driver = {
288 +       .probe          = ezxbp_probe,
289 +       .remove         = ezxbp_remove,
290 +#warning FIXME: missing suspend/resume support
291 +       .suspend        = ezxbp_suspend,
292 +       .resume         = ezxbp_resume,
293 +       .driver         = {
294 +               .name   = "ezx-bp",
295 +               .owner  = THIS_MODULE,
296 +       },
297 +};
298 +
299 +int __init ezxbp_init(void)
300 +{
301 +       return platform_driver_register(&ezxbp_driver);
302 +}
303 +
304 +void ezxbp_fini(void)
305 +{
306 +       return platform_driver_unregister(&ezxbp_driver);
307 +}
308 +
309 +module_init(ezxbp_init);
310 +module_exit(ezxbp_fini);
311 +
312 +MODULE_DESCRIPTION("Motorola BP Control driver");
313 +MODULE_AUTHOR("Daniel Ribeiro <drwyrm@gmail.com>");
314 +MODULE_LICENSE("GPL");
315 +
316 Index: linux-2.6.21/arch/arm/mach-pxa/Makefile
317 ===================================================================
318 --- linux-2.6.21.orig/arch/arm/mach-pxa/Makefile        2007-05-12 20:40:44.000000000 -0300
319 +++ linux-2.6.21/arch/arm/mach-pxa/Makefile     2007-05-14 21:12:37.000000000 -0300
320 @@ -22,6 +22,7 @@
321  obj-$(CONFIG_PXA_EZX_A780)     += ezx-a780.o
322  obj-$(CONFIG_PXA_EZX_E680)     += ezx-e680.o
323  obj-$(CONFIG_PXA_EZX_E2)       += ezx-e2.o
324 +obj-$(CONFIG_EZX_BP)           += ezx-bp.o
325  
326  # Support for blinky lights
327  led-y := leds.o