summaryrefslogtreecommitdiff
path: root/packages/linux/linux-ezx-2.6.21/patches/ezx-emu.patch
blob: 94581d45319c9df6eb65a50e7de6d2362bdee94e (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
Index: linux-2.6.21/arch/arm/mach-pxa/ezx-emu.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6.21/arch/arm/mach-pxa/ezx-emu.c	2007-06-02 20:32:34.000000000 -0300
@@ -0,0 +1,215 @@
+/*
+ *  EMU Driver for Motorola EZX phones
+ *
+ *  Copyright (c) 2007 Daniel Ribeiro <drwyrm@gmail.com>
+ *
+ *  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/arch/hardware.h>
+#include <asm/arch/pxa-regs.h>
+#include <asm/arch/ezx.h>
+#include <asm/arch/ezx-pcap.h>
+#include <asm/arch/udc.h>
+
+static struct pxa2xx_udc_mach_info ezx_udc_info;
+extern int ezx_pcap_bit_set(u_int32_t, u_int8_t);
+extern int ezx_pcap_read_bit(u_int32_t);
+
+#if defined CONFIG_EZX_EMU_USB
+#define emu_switch_to_default() emu_switch_to_usb()
+#elif defined CONFIG_EZX_EMU_UART
+#define emu_switch_to_default() emu_switch_to_uart()
+#else
+#define emu_switch_to_default() emu_switch_to_nothing()
+#endif
+
+void emu_switch_to_usb(void)
+{
+	pxa_gpio_mode(GPIO34_USB_P2_2_MD);
+	pxa_gpio_mode(GPIO35_USB_P2_1_MD);
+	pxa_gpio_mode(GPIO36_USB_P2_4_MD);
+	pxa_gpio_mode(GPIO39_USB_P2_6_MD);
+	pxa_gpio_mode(GPIO40_USB_P2_5_MD);
+	pxa_gpio_mode(GPIO53_USB_P2_3_MD);
+	UP2OCR = 0x02000000;
+	ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_RS232ENB, 1);
+	ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_FSENB, 0);
+	ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_VUSB_EN, 1);
+	clr_GPIO(GPIO_EMU_MUX1);
+	clr_GPIO(GPIO_EMU_MUX2);
+}
+
+void emu_switch_to_uart(void)
+{
+	ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_VUSB_EN,0);
+	ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_RS232ENB, 0);
+	ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_RS232_DIR, 1);
+	set_GPIO(GPIO39_FFTXD);
+	pxa_gpio_mode(GPIO34_TXENB | GPIO_OUT);
+	set_GPIO(GPIO34_TXENB);
+	pxa_gpio_mode(GPIO35_XRXD | GPIO_IN);
+	pxa_gpio_mode(GPIO36_VMOUT | GPIO_IN);
+	pxa_gpio_mode(GPIO40_VPIN | GPIO_IN);
+	pxa_gpio_mode(GPIO39_FFTXD_MD);
+	pxa_gpio_mode(GPIO53_FFRXD_MD);
+	CKEN |= CKEN6_FFUART;
+	clr_GPIO(GPIO_EMU_MUX1);
+	clr_GPIO(GPIO_EMU_MUX2);
+
+}
+
+void emu_switch_to_audio(int stereo)
+{
+	clr_GPIO(GPIO39_VPOUT);
+	if (stereo) {
+		pxa_gpio_mode(GPIO34_TXENB | GPIO_IN);
+		clr_GPIO(GPIO39_VPOUT);
+	} else {
+		pxa_gpio_mode(GPIO34_TXENB | GPIO_OUT);
+		set_GPIO(GPIO34_TXENB);
+	}
+
+	pxa_gpio_mode(GPIO35_XRXD  | GPIO_IN);
+	pxa_gpio_mode(GPIO36_VMOUT | GPIO_IN);
+	pxa_gpio_mode(GPIO39_VPOUT | GPIO_IN);
+	pxa_gpio_mode(GPIO40_VPIN  | GPIO_IN);
+	pxa_gpio_mode(GPIO53_VMIN  | GPIO_IN);
+	set_GPIO(GPIO_EMU_MUX1);
+	if (stereo)
+		set_GPIO(GPIO_EMU_MUX2);
+	else
+		clr_GPIO(GPIO_EMU_MUX2);
+}
+
+void emu_switch_to_nothing(void)
+{
+	ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_VUSB_EN, 0);
+	ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_RS232ENB, 1);
+	pxa_gpio_mode(GPIO34_TXENB | GPIO_OUT);
+	set_GPIO(GPIO34_TXENB);
+	pxa_gpio_mode(GPIO35_XRXD  | GPIO_IN);
+	pxa_gpio_mode(GPIO36_VMOUT | GPIO_IN);
+	pxa_gpio_mode(GPIO39_VPOUT | GPIO_IN);
+	pxa_gpio_mode(GPIO40_VPIN  | GPIO_IN);
+	pxa_gpio_mode(GPIO53_VMIN  | GPIO_IN);
+}
+
+
+static irqreturn_t emu_irq(int irq, void *data)
+{
+	switch (irq) {
+	case EZX_IRQ_USB4V:
+		if(ezx_pcap_read_bit(SSP_PCAP_ADJ_BIT_PSTAT_USBDET_4V))
+			emu_switch_to_default();
+		break;
+	case EZX_IRQ_USB1V:
+		if(!ezx_pcap_read_bit(SSP_PCAP_ADJ_BIT_PSTAT_USBDET_1V))
+			emu_switch_to_nothing();
+		break;
+	}
+
+	return IRQ_HANDLED;
+}
+
+static int __init ezx_emu_probe(struct platform_device *dev)
+{
+	pxa_gpio_mode(GPIO_SNP_INT_IN | GPIO_IN);
+	pxa_gpio_mode(GPIO_EMU_MUX1 | GPIO_OUT);
+	pxa_gpio_mode(GPIO_EMU_MUX2 | GPIO_OUT);
+
+	request_irq(EZX_IRQ_USB4V, &emu_irq, SA_INTERRUPT, "usb 4v", NULL);
+	request_irq(EZX_IRQ_USB1V, &emu_irq, SA_INTERRUPT, "usb 1v", NULL);
+
+	pxa_set_udc_info(&ezx_udc_info);
+
+	if(ezx_pcap_read_bit(SSP_PCAP_ADJ_BIT_PSTAT_USBDET_4V))
+		emu_switch_to_default();
+	else
+		emu_switch_to_nothing();
+
+	return 0;
+}
+
+static int ezx_emu_remove(struct platform_device *dev)
+{
+	free_irq(EZX_IRQ_USB4V, NULL);
+	free_irq(EZX_IRQ_USB1V, NULL);
+
+	return 0;
+}
+
+static int ezx_emu_suspend(struct platform_device *dev, pm_message_t state)
+{
+	emu_switch_to_nothing();
+	return 0;
+}
+
+static int ezx_emu_resume(struct platform_device *dev)
+{
+	emu_switch_to_default();
+	return 0;
+}
+
+/* USB Device Controller */
+static int udc_connected_status;
+static void ezx_udc_command(int cmd)
+{
+	switch (cmd) {
+	case PXA2XX_UDC_CMD_DISCONNECT:
+		printk(KERN_NOTICE "USB cmd disconnect\n");
+		ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_USB_PU,0);
+		udc_connected_status = 0;
+		break;
+	case PXA2XX_UDC_CMD_CONNECT:
+		printk(KERN_NOTICE "USB cmd connect\n");
+		ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_USB_PU,1);
+		udc_connected_status = 1;
+		break;
+	}
+}
+
+static int ezx_udc_is_connected(void)
+{
+	return udc_connected_status;
+}
+
+static struct pxa2xx_udc_mach_info ezx_udc_info __initdata = {
+	.udc_is_connected	= ezx_udc_is_connected,
+	.udc_command		= ezx_udc_command,
+};
+
+static struct platform_driver ezxemu_driver = {
+	.probe		= ezx_emu_probe,
+	.remove		= ezx_emu_remove,
+	.suspend	= ezx_emu_suspend,
+	.resume		= ezx_emu_resume,
+	.driver		= {
+		.name	= "ezx-emu",
+		.owner	= THIS_MODULE,
+	},
+};
+
+int __init ezx_emu_init(void)
+{
+	return platform_driver_register(&ezxemu_driver);
+}
+
+void ezx_emu_fini(void)
+{
+	return platform_driver_unregister(&ezxemu_driver);
+}
+
+module_init(ezx_emu_init);
+module_exit(ezx_emu_fini);
+
+MODULE_DESCRIPTION("Motorola Enchanced Mini Usb driver");
+MODULE_AUTHOR("Daniel Ribeiro <drwyrm@gmail.com>");
+MODULE_LICENSE("GPL");
Index: linux-2.6.21/arch/arm/mach-pxa/Kconfig
===================================================================
--- linux-2.6.21.orig/arch/arm/mach-pxa/Kconfig	2007-06-02 20:32:32.000000000 -0300
+++ linux-2.6.21/arch/arm/mach-pxa/Kconfig	2007-06-02 20:32:34.000000000 -0300
@@ -73,6 +73,7 @@
 
 endchoice
 
+
 endif
 
 if PXA_EZX
@@ -117,6 +118,28 @@
 config EZX_MCI_TF
 	bool
 
+config EZX_EMU
+	bool "Motorola Enchanced Mini Usb"
+	depends on EZX_PCAP
+
+if EZX_EMU
+
+choice
+	prompt "Select default EMU mode"
+
+config EZX_EMU_USB
+	bool "USB"
+
+config EZX_EMU_UART
+	bool "UART"
+
+config EZX_EMU_NOTHING
+	bool "nothing"
+
+endchoice
+
+endif
+
 endif
 
 endmenu
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 20:32:28.000000000 -0300
+++ linux-2.6.21/arch/arm/mach-pxa/ezx.c	2007-06-02 20:32:34.000000000 -0300
@@ -150,11 +150,35 @@
 	.resource	= ezxpcap_resources,
 };
 
+/* EMU */
+static struct resource ezxemu_resources[] = {
+	[0] = {
+		.start		= EZX_IRQ_USB4V,
+		.end		= EZX_IRQ_USB4V,
+		.flags		= IORESOURCE_IRQ,
+	},
+	[1] = {
+		.start		= EZX_IRQ_USB1V,
+		.end		= EZX_IRQ_USB1V,
+		.flags		= IORESOURCE_IRQ,
+	},
+};
+
+struct platform_device ezxemu_device = {
+	.name		= "ezx-emu",
+	.id		= -1,
+	.dev		= {
+		.parent		= &ezxpcap_device.dev,
+	},
+	.num_resources	= ARRAY_SIZE(ezxemu_resources),
+	.resource	= ezxemu_resources,
+};
 
 static struct platform_device *devices[] __initdata = {
 	&ezxssp_device,
 	&ezxbp_device,
 	&ezxpcap_device,
+	&ezxemu_device,
 };
 
 /* PM */
Index: linux-2.6.21/arch/arm/mach-pxa/Makefile
===================================================================
--- linux-2.6.21.orig/arch/arm/mach-pxa/Makefile	2007-06-02 20:32:28.000000000 -0300
+++ linux-2.6.21/arch/arm/mach-pxa/Makefile	2007-06-02 20:32:34.000000000 -0300
@@ -26,6 +26,7 @@
 obj-$(CONFIG_PXA_EZX_E6)	+= ezx-e6.o
 obj-$(CONFIG_EZX_BP)		+= ezx-bp.o
 obj-$(CONFIG_EZX_PCAP)		+= ezx-pcap.o
+obj-$(CONFIG_EZX_EMU)		+= ezx-emu.o
 
 # Support for blinky lights
 led-y := leds.o