de9de604616d23d5b1ab7e67b5f424fa93b84254
[openembedded.git] / packages / linux / linux-ezx-2.6.20.7 / ezx-emu.patch
1 Index: linux-2.6.20.7/arch/arm/mach-pxa/ezx-emu.c
2 ===================================================================
3 --- /dev/null   1970-01-01 00:00:00.000000000 +0000
4 +++ linux-2.6.20.7/arch/arm/mach-pxa/ezx-emu.c  2007-04-21 12:33:22.000000000 -0300
5 @@ -0,0 +1,215 @@
6 +/*
7 + *  EMU Driver for Motorola EZX phones
8 + *
9 + *  Copyright (c) 2007 Daniel Ribeiro <drwyrm@gmail.com>
10 + *
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.
14 + *
15 + */
16 +
17 +#include <linux/kernel.h>
18 +#include <linux/interrupt.h>
19 +#include <linux/module.h>
20 +#include <linux/platform_device.h>
21 +
22 +#include <asm/arch/hardware.h>
23 +#include <asm/arch/pxa-regs.h>
24 +#include <asm/arch/ezx.h>
25 +#include <asm/arch/ezx-pcap.h>
26 +#include <asm/arch/udc.h>
27 +
28 +static struct pxa2xx_udc_mach_info ezx_udc_info;
29 +extern int ezx_pcap_bit_set(u_int32_t, u_int8_t);
30 +extern int ezx_pcap_read_bit(u_int32_t);
31 +
32 +void emu_switch_to_usb(void)
33 +{
34 +       pxa_gpio_mode(GPIO34_USB_P2_2_MD);
35 +       pxa_gpio_mode(GPIO35_USB_P2_1_MD);
36 +       pxa_gpio_mode(GPIO36_USB_P2_4_MD);
37 +       pxa_gpio_mode(GPIO39_USB_P2_6_MD);
38 +       pxa_gpio_mode(GPIO40_USB_P2_5_MD);
39 +       pxa_gpio_mode(GPIO53_USB_P2_3_MD);
40 +       UP2OCR = 0x02000000;
41 +       ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_RS232ENB, 1);
42 +       ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_FSENB, 0);
43 +       ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_VUSB_EN, 1);
44 +       clr_GPIO(GPIO_EMU_MUX1);
45 +       clr_GPIO(GPIO_EMU_MUX2);
46 +}
47 +EXPORT_SYMBOL(emu_switch_to_usb);
48 +
49 +void emu_switch_to_uart(void)
50 +{
51 +       ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_VUSB_EN,0);
52 +       ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_RS232ENB, 0);
53 +       ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_RS232_DIR, 1);
54 +       set_GPIO(GPIO39_FFTXD);
55 +       pxa_gpio_mode(GPIO34_TXENB | GPIO_OUT);
56 +       set_GPIO(GPIO34_TXENB);
57 +       pxa_gpio_mode(GPIO35_XRXD | GPIO_IN);
58 +       pxa_gpio_mode(GPIO36_VMOUT | GPIO_IN);
59 +       pxa_gpio_mode(GPIO40_VPIN | GPIO_IN);
60 +       pxa_gpio_mode(GPIO39_FFTXD_MD);
61 +       pxa_gpio_mode(GPIO53_FFRXD_MD);
62 +       CKEN |= CKEN6_FFUART;
63 +       clr_GPIO(GPIO_EMU_MUX1);
64 +       clr_GPIO(GPIO_EMU_MUX2);
65 +
66 +}
67 +EXPORT_SYMBOL(emu_switch_to_uart);
68 +
69 +void emu_switch_to_audio(int stereo)
70 +{
71 +       clr_GPIO(GPIO39_VPOUT);
72 +       if (stereo) {
73 +               pxa_gpio_mode(GPIO34_USB_P2_2 | GPIO_IN);
74 +               clr_GPIO(GPIO39_VPOUT);
75 +       } else {
76 +               pxa_gpio_mode(GPIO34_TXENB | GPIO_OUT);
77 +               set_GPIO(GPIO34_TXENB);
78 +       }
79 +
80 +       pxa_gpio_mode(GPIO35_XRXD  | GPIO_IN);
81 +       pxa_gpio_mode(GPIO36_VMOUT | GPIO_IN);
82 +       pxa_gpio_mode(GPIO39_VPOUT | GPIO_IN);
83 +       pxa_gpio_mode(GPIO40_VPIN  | GPIO_IN);
84 +       pxa_gpio_mode(GPIO53_VMIN  | GPIO_IN);
85 +       set_GPIO(GPIO_EMU_MUX1);
86 +       if (stereo)
87 +               set_GPIO(GPIO_EMU_MUX2);
88 +       else
89 +               clr_GPIO(GPIO_EMU_MUX2);
90 +}
91 +
92 +void emu_switch_to_nothing(void)
93 +{
94 +       ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_VUSB_EN, 0);
95 +       ezx_pcap_bit_set(SSP_PCAP_ADJ_BIT_BUSCTRL_RS232ENB, 1);
96 +       pxa_gpio_mode(GPIO34_TXENB | GPIO_OUT);
97 +       set_GPIO(GPIO34_TXENB);
98 +       pxa_gpio_mode(GPIO35_XRXD  | GPIO_IN);
99 +       pxa_gpio_mode(GPIO36_VMOUT | GPIO_IN);
100 +       pxa_gpio_mode(GPIO39_VPOUT | GPIO_IN);
101 +       pxa_gpio_mode(GPIO40_VPIN  | GPIO_IN);
102 +       pxa_gpio_mode(GPIO53_VMIN  | GPIO_IN);
103 +}
104 +
105 +
106 +static irqreturn_t emu_irq(int irq, void *data)
107 +{
108 +       printk("emu_irq(%u) entered: ", irq);
109 +
110 +       switch (irq) {
111 +               case EZX_IRQ_USB4V:
112 +                       printk("usb 4v\n");
113 +                       if(ezx_pcap_read_bit(SSP_PCAP_ADJ_BIT_PSTAT_USBDET_4V))
114 +#if defined CONFIG_PXA_EZX_EMU_USB
115 +                               emu_switch_to_usb();
116 +#elif defined CONFIG_PXA_EZX_EMU_UART
117 +                               emu_switch_to_uart();
118 +#else
119 +                               emu_switch_to_nothing();
120 +#endif
121 +                       else
122 +                               emu_switch_to_nothing();
123 +                       break;
124 +               case EZX_IRQ_USB1V:
125 +                       printk("usb 1v\n");
126 +                       break;
127 +               default:
128 +                       printk("unknown\n");
129 +                       break;
130 +       }
131 +
132 +       return IRQ_HANDLED;
133 +}
134 +
135 +static int __init ezx_emu_probe(struct platform_device *dev)
136 +{
137 +       printk("ezx_emu_probe entered!\n");
138 +       pxa_gpio_mode(GPIO_SNP_INT_IN | GPIO_IN);
139 +       pxa_gpio_mode(GPIO_EMU_MUX1 | GPIO_OUT);
140 +       pxa_gpio_mode(GPIO_EMU_MUX2 | GPIO_OUT);
141 +
142 +       request_irq(EZX_IRQ_USB4V, &emu_irq, SA_INTERRUPT, "usb 4v", NULL);
143 +       request_irq(EZX_IRQ_USB1V, &emu_irq, SA_INTERRUPT, "usb 1v", NULL);
144 +
145 +       pxa_set_udc_info(&ezx_udc_info);
146 +
147 +#if defined CONFIG_PXA_EZX_EMU_USB
148 +       emu_switch_to_usb();
149 +#elif defined CONFIG_PXA_EZX_EMU_UART
150 +       emu_switch_to_uart();
151 +#else
152 +       emu_switch_to_nothing();
153 +#endif
154 +
155 +       return 0;
156 +}
157 +
158 +static int ezx_emu_remove(struct platform_device *dev)
159 +{
160 +       free_irq(EZX_IRQ_USB4V, NULL);
161 +       free_irq(EZX_IRQ_USB1V, NULL);
162 +
163 +       return 0;
164 +}
165 +
166 +/* USB Device Controller */
167 +static int udc_connected_status;
168 +static void ezx_udc_command(int cmd)
169 +{
170 +       switch (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;
175 +                       break;
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;
180 +                       break;
181 +       }
182 +}
183 +
184 +static int ezx_udc_is_connected(void)
185 +{
186 +       return udc_connected_status;
187 +}
188 +
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,
192 +};
193 +
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,
199 +       .driver         = {
200 +               .name   = "ezx-emu",
201 +               .owner  = THIS_MODULE,
202 +       },
203 +};
204 +
205 +int __init ezx_emu_init(void)
206 +{
207 +       return platform_driver_register(&ezxemu_driver);
208 +}
209 +
210 +void ezx_emu_fini(void)
211 +{
212 +       return platform_driver_unregister(&ezxemu_driver);
213 +}
214 +
215 +module_init(ezx_emu_init);
216 +module_exit(ezx_emu_fini);
217 +
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.20.7/arch/arm/mach-pxa/Kconfig
222 ===================================================================
223 --- linux-2.6.20.7.orig/arch/arm/mach-pxa/Kconfig       2007-04-21 12:32:50.000000000 -0300
224 +++ linux-2.6.20.7/arch/arm/mach-pxa/Kconfig    2007-04-21 12:32:54.000000000 -0300
225 @@ -94,6 +94,27 @@
226  
227  endchoice
228  
229 +config PXA_EZX_EMU
230 +       bool "Motorola Enchanced Mini Usb"
231 +
232 +if PXA_EZX_EMU
233 +
234 +choice
235 +       prompt "Select default EMU mode"
236 +
237 +config PXA_EZX_EMU_USB
238 +       bool "USB"
239 +
240 +config PXA_EZX_EMU_UART
241 +       bool "UART"
242 +
243 +config PXA_EZX_EMU_NOTHING
244 +       bool "nothing"
245 +
246 +endchoice
247 +
248 +endif
249 +
250  endif
251  
252  endmenu
253 Index: linux-2.6.20.7/arch/arm/mach-pxa/Makefile
254 ===================================================================
255 --- linux-2.6.20.7.orig/arch/arm/mach-pxa/Makefile      2007-04-21 12:32:50.000000000 -0300
256 +++ linux-2.6.20.7/arch/arm/mach-pxa/Makefile   2007-04-21 12:32:54.000000000 -0300
257 @@ -19,6 +19,7 @@
258  obj-$(CONFIG_MACH_POODLE)      += poodle.o corgi_ssp.o
259  obj-$(CONFIG_MACH_TOSA)         += tosa.o
260  obj-$(CONFIG_PXA_EZX)          += ezx.o ezx_lcd.o ezx_ssp.o ezx-pcap.o ezx-mci.o
261 +obj-$(CONFIG_PXA_EZX_EMU)      += ezx-emu.o
262  
263  # Support for blinky lights
264  led-y := leds.o
265 Index: linux-2.6.20.7/arch/arm/mach-pxa/ezx.c
266 ===================================================================
267 --- linux-2.6.20.7.orig/arch/arm/mach-pxa/ezx.c 2007-04-21 12:32:50.000000000 -0300
268 +++ linux-2.6.20.7/arch/arm/mach-pxa/ezx.c      2007-04-21 12:32:54.000000000 -0300
269 @@ -36,6 +36,7 @@
270  #include <asm/arch/ohci.h>
271  #include <asm/arch/pxa-regs.h>
272  
273 +
274  #include "ezx.h"
275  #include "generic.h"
276  #include <linux/tty.h>
277 @@ -92,6 +93,30 @@
278         .resource       = ezxpcap_resources,
279  };
280  
281 +/* EMU */
282 +static struct resource ezxemu_resources[] = {
283 +       [0] = {
284 +               .start          = EZX_IRQ_USB4V,
285 +               .end            = EZX_IRQ_USB4V,
286 +               .flags          = IORESOURCE_IRQ,
287 +       },
288 +       [1] = {
289 +               .start          = EZX_IRQ_USB1V,
290 +               .end            = EZX_IRQ_USB1V,
291 +               .flags          = IORESOURCE_IRQ,
292 +       },
293 +};
294 +
295 +struct platform_device ezxemu_device = {
296 +       .name           = "ezx-emu",
297 +       .id             = -1,
298 +//     .dev            = {
299 +//             .parent         = &ezxpcap_device.dev,
300 +//     },
301 +       .num_resources  = ARRAY_SIZE(ezxemu_resources),
302 +       .resource       = ezxemu_resources,
303 +};
304 +
305  /* OHCI Controller */
306  
307  static int ezx_ohci_init(struct device *dev)
308 @@ -317,6 +342,7 @@
309         &ezxssp_device,
310         &ezxpcap_device,
311         &ezxbp_device,
312 +       &ezxemu_device,
313  };
314  
315  static void __init a780_init(void)
316 @@ -383,7 +409,15 @@
317         pxa_set_ohci_info(&ezx_ohci_platform_data);
318  
319         platform_add_devices(devices, ARRAY_SIZE(devices));
320 -
321 +/*
322 +#if defined CONFIG_PXA_EZX_EMU_USB
323 +       emu_switch_to_usb();
324 +#elif defined CONFIG_PXA_EZX_EMU_UART
325 +       emu_switch_to_uart();
326 +#else
327 +       emu_switch_to_nothing();
328 +#endif
329 +*/
330  }
331  
332  MACHINE_START(EZX, "Motorola Ezx Platform")