u-boot-mkimage-gta01-native: re-add till uboot-utils actually works
[openembedded.git] / packages / linux / linux-ezx-2.6.21 / ezx-emu.patch
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
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 +#include <linux/kernel.h>
17 +#include <linux/interrupt.h>
18 +#include <linux/module.h>
19 +#include <linux/platform_device.h>
20 +
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>
26 +
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);
30 +
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()
35 +#else
36 +#define emu_switch_to_default() emu_switch_to_nothing()
37 +#endif
38 +
39 +void emu_switch_to_usb(void)
40 +{
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);
53 +}
54 +
55 +void emu_switch_to_uart(void)
56 +{
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);
71 +
72 +}
73 +
74 +void emu_switch_to_audio(int stereo)
75 +{
76 +       clr_GPIO(GPIO39_VPOUT);
77 +       if (stereo) {
78 +               pxa_gpio_mode(GPIO34_TXENB | GPIO_IN);
79 +               clr_GPIO(GPIO39_VPOUT);
80 +       } else {
81 +               pxa_gpio_mode(GPIO34_TXENB | GPIO_OUT);
82 +               set_GPIO(GPIO34_TXENB);
83 +       }
84 +
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);
91 +       if (stereo)
92 +               set_GPIO(GPIO_EMU_MUX2);
93 +       else
94 +               clr_GPIO(GPIO_EMU_MUX2);
95 +}
96 +
97 +void emu_switch_to_nothing(void)
98 +{
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);
108 +}
109 +
110 +
111 +static irqreturn_t emu_irq(int irq, void *data)
112 +{
113 +       switch (irq) {
114 +       case EZX_IRQ_USB4V:
115 +               if(ezx_pcap_read_bit(SSP_PCAP_ADJ_BIT_PSTAT_USBDET_4V))
116 +                       emu_switch_to_default();
117 +               break;
118 +       case EZX_IRQ_USB1V:
119 +               if(!ezx_pcap_read_bit(SSP_PCAP_ADJ_BIT_PSTAT_USBDET_1V))
120 +                       emu_switch_to_nothing();
121 +               break;
122 +       }
123 +
124 +       return IRQ_HANDLED;
125 +}
126 +
127 +static int __init ezx_emu_probe(struct platform_device *dev)
128 +{
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);
132 +
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);
135 +
136 +       pxa_set_udc_info(&ezx_udc_info);
137 +
138 +       if(ezx_pcap_read_bit(SSP_PCAP_ADJ_BIT_PSTAT_USBDET_4V))
139 +               emu_switch_to_default();
140 +       else
141 +               emu_switch_to_nothing();
142 +
143 +       return 0;
144 +}
145 +
146 +static int ezx_emu_remove(struct platform_device *dev)
147 +{
148 +       free_irq(EZX_IRQ_USB4V, NULL);
149 +       free_irq(EZX_IRQ_USB1V, NULL);
150 +
151 +       return 0;
152 +}
153 +
154 +static int ezx_emu_suspend(struct platform_device *dev, pm_message_t state)
155 +{
156 +       emu_switch_to_nothing();
157 +       return 0;
158 +}
159 +
160 +static int ezx_emu_resume(struct platform_device *dev)
161 +{
162 +       emu_switch_to_default();
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.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
225 @@ -73,6 +73,7 @@
226  
227  endchoice
228  
229 +
230  endif
231  
232  if PXA_EZX
233 @@ -100,6 +101,28 @@
234  config EZX_PCAP
235         bool "PCAP Support"
236  
237 +config EZX_EMU
238 +       bool "Motorola Enchanced Mini Usb"
239 +       depends on EZX_PCAP
240 +
241 +if EZX_EMU
242 +
243 +choice
244 +       prompt "Select default EMU mode"
245 +
246 +config EZX_EMU_USB
247 +       bool "USB"
248 +
249 +config EZX_EMU_UART
250 +       bool "UART"
251 +
252 +config EZX_EMU_NOTHING
253 +       bool "nothing"
254 +
255 +endchoice
256 +
257 +endif
258 +
259  endif
260  
261  endmenu
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,
268  };
269  
270 +/* EMU */
271 +static struct resource ezxemu_resources[] = {
272 +       [0] = {
273 +               .start          = EZX_IRQ_USB4V,
274 +               .end            = EZX_IRQ_USB4V,
275 +               .flags          = IORESOURCE_IRQ,
276 +       },
277 +       [1] = {
278 +               .start          = EZX_IRQ_USB1V,
279 +               .end            = EZX_IRQ_USB1V,
280 +               .flags          = IORESOURCE_IRQ,
281 +       },
282 +};
283 +
284 +struct platform_device ezxemu_device = {
285 +       .name           = "ezx-emu",
286 +       .id             = -1,
287 +       .dev            = {
288 +               .parent         = &ezxpcap_device.dev,
289 +       },
290 +       .num_resources  = ARRAY_SIZE(ezxemu_resources),
291 +       .resource       = ezxemu_resources,
292 +};
293  
294  static struct platform_device *devices[] __initdata = {
295         &ezxssp_device,
296         &ezxbp_device,
297         &ezxpcap_device,
298 +       &ezxemu_device,
299  };
300  
301  /* PM */
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
306 @@ -24,6 +24,7 @@
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
311  
312  # Support for blinky lights
313  led-y := leds.o