1 Index: linux-2.6.21/arch/arm/mach-pxa/ezx-emu.c
2 ===================================================================
3 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4 +++ linux-2.6.21/arch/arm/mach-pxa/ezx-emu.c 2007-05-08 02:31:16.000000000 -0300
7 + * EMU Driver for Motorola EZX phones
9 + * Copyright (c) 2007 Daniel Ribeiro <drwyrm@gmail.com>
11 + * This program is free software; you can redistribute it and/or modify
12 + * it under the terms of the GNU General Public License version 2 as
13 + * published by the Free Software Foundation.
16 +#include <linux/kernel.h>
17 +#include <linux/interrupt.h>
18 +#include <linux/module.h>
19 +#include <linux/platform_device.h>
21 +#include <asm/arch/hardware.h>
22 +#include <asm/arch/pxa-regs.h>
23 +#include <asm/arch/ezx.h>
24 +#include <asm/arch/ezx-pcap.h>
25 +#include <asm/arch/udc.h>
27 +static struct pxa2xx_udc_mach_info ezx_udc_info;
28 +extern int ezx_pcap_bit_set(u_int32_t, u_int8_t);
29 +extern int ezx_pcap_read_bit(u_int32_t);
31 +#if defined CONFIG_EZX_EMU_USB
32 +#define emu_switch_to_default() emu_switch_to_usb()
33 +#elif defined CONFIG_EZX_EMU_UART
34 +#define emu_switch_to_default() emu_switch_to_uart()
36 +#define emu_switch_to_default() emu_switch_to_nothing()
39 +void emu_switch_to_usb(void)
41 + pxa_gpio_mode(GPIO34_USB_P2_2_MD);
42 + pxa_gpio_mode(GPIO35_USB_P2_1_MD);
43 + pxa_gpio_mode(GPIO36_USB_P2_4_MD);
44 + pxa_gpio_mode(GPIO39_USB_P2_6_MD);
45 + pxa_gpio_mode(GPIO40_USB_P2_5_MD);
46 + pxa_gpio_mode(GPIO53_USB_P2_3_MD);
47 + UP2OCR = 0x02000000;
48 + ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_RS232ENB, 1);
49 + ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_FSENB, 0);
50 + ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_VUSB_EN, 1);
51 + clr_GPIO(GPIO_EMU_MUX1);
52 + clr_GPIO(GPIO_EMU_MUX2);
55 +void emu_switch_to_uart(void)
57 + ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_VUSB_EN,0);
58 + ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_RS232ENB, 0);
59 + ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_RS232_DIR, 1);
60 + set_GPIO(GPIO39_FFTXD);
61 + pxa_gpio_mode(GPIO34_TXENB | GPIO_OUT);
62 + set_GPIO(GPIO34_TXENB);
63 + pxa_gpio_mode(GPIO35_XRXD | GPIO_IN);
64 + pxa_gpio_mode(GPIO36_VMOUT | GPIO_IN);
65 + pxa_gpio_mode(GPIO40_VPIN | GPIO_IN);
66 + pxa_gpio_mode(GPIO39_FFTXD_MD);
67 + pxa_gpio_mode(GPIO53_FFRXD_MD);
68 + CKEN |= CKEN6_FFUART;
69 + clr_GPIO(GPIO_EMU_MUX1);
70 + clr_GPIO(GPIO_EMU_MUX2);
74 +void emu_switch_to_audio(int stereo)
76 + clr_GPIO(GPIO39_VPOUT);
78 + pxa_gpio_mode(GPIO34_TXENB | GPIO_IN);
79 + clr_GPIO(GPIO39_VPOUT);
81 + pxa_gpio_mode(GPIO34_TXENB | GPIO_OUT);
82 + set_GPIO(GPIO34_TXENB);
85 + pxa_gpio_mode(GPIO35_XRXD | GPIO_IN);
86 + pxa_gpio_mode(GPIO36_VMOUT | GPIO_IN);
87 + pxa_gpio_mode(GPIO39_VPOUT | GPIO_IN);
88 + pxa_gpio_mode(GPIO40_VPIN | GPIO_IN);
89 + pxa_gpio_mode(GPIO53_VMIN | GPIO_IN);
90 + set_GPIO(GPIO_EMU_MUX1);
92 + set_GPIO(GPIO_EMU_MUX2);
94 + clr_GPIO(GPIO_EMU_MUX2);
97 +void emu_switch_to_nothing(void)
99 + ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_VUSB_EN, 0);
100 + ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_RS232ENB, 1);
101 + pxa_gpio_mode(GPIO34_TXENB | GPIO_OUT);
102 + set_GPIO(GPIO34_TXENB);
103 + pxa_gpio_mode(GPIO35_XRXD | GPIO_IN);
104 + pxa_gpio_mode(GPIO36_VMOUT | GPIO_IN);
105 + pxa_gpio_mode(GPIO39_VPOUT | GPIO_IN);
106 + pxa_gpio_mode(GPIO40_VPIN | GPIO_IN);
107 + pxa_gpio_mode(GPIO53_VMIN | GPIO_IN);
111 +static irqreturn_t emu_irq(int irq, void *data)
114 + case EZX_IRQ_USB4V:
115 + if(ezx_pcap_read_bit(SSP_PCAP_ADJ_BIT_PSTAT_USBDET_4V))
116 + emu_switch_to_default();
118 + case EZX_IRQ_USB1V:
119 + if(!ezx_pcap_read_bit(SSP_PCAP_ADJ_BIT_PSTAT_USBDET_1V))
120 + emu_switch_to_nothing();
124 + return IRQ_HANDLED;
127 +static int __init ezx_emu_probe(struct platform_device *dev)
129 + pxa_gpio_mode(GPIO_SNP_INT_IN | GPIO_IN);
130 + pxa_gpio_mode(GPIO_EMU_MUX1 | GPIO_OUT);
131 + pxa_gpio_mode(GPIO_EMU_MUX2 | GPIO_OUT);
133 + request_irq(EZX_IRQ_USB4V, &emu_irq, SA_INTERRUPT, "usb 4v", NULL);
134 + request_irq(EZX_IRQ_USB1V, &emu_irq, SA_INTERRUPT, "usb 1v", NULL);
136 + pxa_set_udc_info(&ezx_udc_info);
138 + if(ezx_pcap_read_bit(SSP_PCAP_ADJ_BIT_PSTAT_USBDET_4V))
139 + emu_switch_to_default();
141 + emu_switch_to_nothing();
146 +static int ezx_emu_remove(struct platform_device *dev)
148 + free_irq(EZX_IRQ_USB4V, NULL);
149 + free_irq(EZX_IRQ_USB1V, NULL);
154 +static int ezx_emu_suspend(struct platform_device *dev, pm_message_t state)
156 + emu_switch_to_nothing();
160 +static int ezx_emu_resume(struct platform_device *dev)
162 + emu_switch_to_default();
166 +/* USB Device Controller */
167 +static int udc_connected_status;
168 +static void ezx_udc_command(int cmd)
171 + case PXA2XX_UDC_CMD_DISCONNECT:
172 + printk(KERN_NOTICE "USB cmd disconnect\n");
173 + ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_USB_PU,0);
174 + udc_connected_status = 0;
176 + case PXA2XX_UDC_CMD_CONNECT:
177 + printk(KERN_NOTICE "USB cmd connect\n");
178 + ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_USB_PU,1);
179 + udc_connected_status = 1;
184 +static int ezx_udc_is_connected(void)
186 + return udc_connected_status;
189 +static struct pxa2xx_udc_mach_info ezx_udc_info __initdata = {
190 + .udc_is_connected = ezx_udc_is_connected,
191 + .udc_command = ezx_udc_command,
194 +static struct platform_driver ezxemu_driver = {
195 + .probe = ezx_emu_probe,
196 + .remove = ezx_emu_remove,
197 + .suspend = ezx_emu_suspend,
198 + .resume = ezx_emu_resume,
201 + .owner = THIS_MODULE,
205 +int __init ezx_emu_init(void)
207 + return platform_driver_register(&ezxemu_driver);
210 +void ezx_emu_fini(void)
212 + return platform_driver_unregister(&ezxemu_driver);
215 +module_init(ezx_emu_init);
216 +module_exit(ezx_emu_fini);
218 +MODULE_DESCRIPTION("Motorola Enchanced Mini Usb driver");
219 +MODULE_AUTHOR("Daniel Ribeiro <drwyrm@gmail.com>");
220 +MODULE_LICENSE("GPL");
221 Index: linux-2.6.21/arch/arm/mach-pxa/Kconfig
222 ===================================================================
223 --- linux-2.6.21.orig/arch/arm/mach-pxa/Kconfig 2007-05-08 02:28:47.000000000 -0300
224 +++ linux-2.6.21/arch/arm/mach-pxa/Kconfig 2007-05-08 02:31:16.000000000 -0300
238 + bool "Motorola Enchanced Mini Usb"
239 + depends on EZX_PCAP
244 + prompt "Select default EMU mode"
252 +config EZX_EMU_NOTHING
262 Index: linux-2.6.21/arch/arm/mach-pxa/ezx.c
263 ===================================================================
264 --- linux-2.6.21.orig/arch/arm/mach-pxa/ezx.c 2007-05-08 02:28:47.000000000 -0300
265 +++ linux-2.6.21/arch/arm/mach-pxa/ezx.c 2007-05-08 02:31:16.000000000 -0300
266 @@ -150,11 +150,35 @@
267 .resource = ezxpcap_resources,
271 +static struct resource ezxemu_resources[] = {
273 + .start = EZX_IRQ_USB4V,
274 + .end = EZX_IRQ_USB4V,
275 + .flags = IORESOURCE_IRQ,
278 + .start = EZX_IRQ_USB1V,
279 + .end = EZX_IRQ_USB1V,
280 + .flags = IORESOURCE_IRQ,
284 +struct platform_device ezxemu_device = {
288 + .parent = &ezxpcap_device.dev,
290 + .num_resources = ARRAY_SIZE(ezxemu_resources),
291 + .resource = ezxemu_resources,
294 static struct platform_device *devices[] __initdata = {
302 Index: linux-2.6.21/arch/arm/mach-pxa/Makefile
303 ===================================================================
304 --- linux-2.6.21.orig/arch/arm/mach-pxa/Makefile 2007-05-08 02:28:47.000000000 -0300
305 +++ linux-2.6.21/arch/arm/mach-pxa/Makefile 2007-05-08 02:31:16.000000000 -0300
307 obj-$(CONFIG_PXA_EZX_E2) += ezx-e2.o
308 obj-$(CONFIG_EZX_BP) += ezx-bp.o
309 obj-$(CONFIG_EZX_PCAP) += ezx-pcap.o
310 +obj-$(CONFIG_EZX_EMU) += ezx-emu.o
312 # Support for blinky lights