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
10 +static struct resource ezxbp_resources[] = {
12 + .start = IRQ_GPIO(GPIO_BP_RDY),
13 + .end = IRQ_GPIO(GPIO_BP_RDY),
14 + .flags = IORESOURCE_IRQ,
17 + .start = IRQ_GPIO(GPIO_BB_WDI2),
18 + .end = IRQ_GPIO(GPIO_BB_WDI2),
19 + .flags = IORESOURCE_IRQ,
22 + .start = IRQ_GPIO(GPIO_BB_WDI),
23 + .end = IRQ_GPIO(GPIO_BB_WDI),
24 + .flags = IORESOURCE_IRQ,
28 +static struct platform_device ezxbp_device = {
35 + .num_resources = ARRAY_SIZE(ezxbp_resources),
36 + .resource = ezxbp_resources,
41 static struct platform_device *devices[] __initdata = {
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
56 + bool "BP Control code for EZX Platform"
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
67 + * BP handshake code for Motorola EZX phones
69 + * Copyright (c) 2007 Daniel Ribeiro <drwyrm@gmail.com>
71 + * Based on Motorola's a780.c Copyright (c) 2003-2005 Motorola
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.
80 +#include <linux/kernel.h>
81 +#include <linux/interrupt.h>
82 +#include <linux/module.h>
83 +#include <linux/platform_device.h>
85 +#include <asm/mach/irq.h>
86 +#include <asm/arch/hardware.h>
87 +#include <asm/arch/pxa-regs.h>
89 +#include <asm/arch/ezx.h>
94 +#define BP_RDY_TIMEOUT 0x000c0000
97 +#define DEBUGP(x, args ...) printk(x, ##args)
99 +#define DEBUGP(x, args ...)
108 +/* check power down condition */
109 +static inline void check_power_off(void)
111 + if (pxa_gpio_get_value(GPIO_BB_WDI2) == 0) {
112 + DEBUGP("BP request poweroff!\n");
117 +static int step = FIRST_STEP;
119 +inline int bp_handshake_passed(void)
121 + return (step > LAST_STEP);
123 +EXPORT_SYMBOL(bp_handshake_passed);
125 +void handshake(void)
127 + /* step 1: check MCU_INT_SW or BP_RDY is low (now it is checked in apboot) */
128 + DEBUGP("bp handshake entered!\n");
130 + int timeout = BP_RDY_TIMEOUT;
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);
136 + while ( timeout -- ) {
137 + if (pxa_gpio_get_value(GPIO_MCU_INT_SW) == 0
138 + || pxa_gpio_get_value(GPIO_BP_RDY) == 0) {
145 + DEBUGP("ezx-bp: handshake step 1\n");
148 + /* step 2: wait BP_RDY is low */
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);
156 + DEBUGP("ezx-bp: handshake step 2\n");
160 + /* step 3: wait BP_RDY is high */
161 + else if (step == 3) {
162 + if (pxa_gpio_get_value(GPIO_BP_RDY)) {
164 + //FIXME delay_bklight();
165 + pxa_gpio_set_value(GPIO_MCU_INT_SW, 1);
166 + printk(KERN_NOTICE "ezx-bp: handshake passed\n");
171 +irqreturn_t bp_wdi_handler(int irq, void *dev_id)
173 + DEBUGP("BP Lowered WDI line. This is not good :(\n");
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.
179 + return IRQ_HANDLED;
182 +static irqreturn_t bp_rdy_handler(int irq, void *dev_id)
184 + struct bp *bp = dev_id;
185 + DEBUGP("BP rdy irq\n");
186 + if (!bp_handshake_passed()) {
188 + if (bp_handshake_passed()) {
189 + disable_irq(bp->irq_wdi2);
191 + /* set bp_rdy handle for usb ipc */
192 + set_irq_type(bp->irq_rdy, IRQT_FALLING);
195 +#ifdef CONFIG_TS0710_MUX_USB
196 + else usb_send_readurb();
198 + return IRQ_HANDLED;
201 +/* BP request for poweroff */
202 +static irqreturn_t bp_wdi2_handler(int irq, void *dev_id)
204 + DEBUGP("BP request poweroff!\n");
206 + return IRQ_HANDLED;
209 +static int __init ezxbp_probe(struct platform_device *dev)
214 + bp = kzalloc(sizeof(*bp), GFP_KERNEL);
218 + bp->irq_rdy = platform_get_irq(dev, 0);
219 + if(bp->irq_rdy < 0) {
224 + bp->irq_wdi2 = platform_get_irq(dev, 1);
225 + if(bp->irq_wdi2 < 0) {
226 + ret = bp->irq_wdi2;
230 + bp->irq_wdi = platform_get_irq(dev, 2);
231 + if(bp->irq_wdi < 0) {
236 + set_irq_type(bp->irq_wdi, IRQT_FALLING);
237 + request_irq(bp->irq_wdi, bp_wdi_handler, SA_INTERRUPT,
240 + set_irq_type(bp->irq_rdy, IRQT_BOTHEDGE);
241 + request_irq(bp->irq_rdy, bp_rdy_handler, SA_INTERRUPT,
244 + set_irq_type(bp->irq_wdi2, IRQT_FALLING);
245 + request_irq(bp->irq_wdi2, bp_wdi2_handler, SA_INTERRUPT,
249 + pxa_gpio_mode(GPIO_BB_RESET|GPIO_OUT);
250 + pxa_gpio_set_value(GPIO_BB_RESET, 1);
262 +static int ezxbp_remove(struct platform_device *dev)
264 + struct bp *bp = platform_get_drvdata(dev);
266 + free_irq(bp->irq_wdi, bp);
267 + free_irq(bp->irq_wdi2, bp);
268 + free_irq(bp->irq_rdy, bp);
274 +static int ezxbp_suspend(struct platform_device *dev, pm_message_t state)
276 + DEBUGP("bp suspend!\n");
277 +// pxa_gpio_set_value(GPIO_MCU_INT_SW, 0);
281 +static int ezxbp_resume(struct platform_device *dev)
283 + DEBUGP("bp resume!\n");
284 +// pxa_gpio_set_value(GPIO_MCU_INT_SW, 1);
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,
295 + .owner = THIS_MODULE,
299 +int __init ezxbp_init(void)
301 + return platform_driver_register(&ezxbp_driver);
304 +void ezxbp_fini(void)
306 + return platform_driver_unregister(&ezxbp_driver);
309 +module_init(ezxbp_init);
310 +module_exit(ezxbp_fini);
312 +MODULE_DESCRIPTION("Motorola BP Control driver");
313 +MODULE_AUTHOR("Daniel Ribeiro <drwyrm@gmail.com>");
314 +MODULE_LICENSE("GPL");
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
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
326 # Support for blinky lights