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