[ARM] 3340/1: Fix the PCI setup for direct master access to SDRAM
[pv_ops_mirror.git] / arch / arm / plat-omap / usb.c
blob00afc7a8c2ab036634392214358073235a4f4548
1 /*
2 * arch/arm/plat-omap/usb.c -- platform level USB initialization
4 * Copyright (C) 2004 Texas Instruments, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #undef DEBUG
23 #include <linux/config.h>
24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/types.h>
27 #include <linux/errno.h>
28 #include <linux/init.h>
29 #include <linux/platform_device.h>
30 #include <linux/usb_otg.h>
32 #include <asm/io.h>
33 #include <asm/irq.h>
34 #include <asm/system.h>
35 #include <asm/hardware.h>
37 #include <asm/arch/mux.h>
38 #include <asm/arch/usb.h>
39 #include <asm/arch/board.h>
41 /* These routines should handle the standard chip-specific modes
42 * for usb0/1/2 ports, covering basic mux and transceiver setup.
43 * Call omap_usb_init() once, from INIT_MACHINE().
45 * Some board-*.c files will need to set up additional mux options,
46 * like for suspend handling, vbus sensing, GPIOs, and the D+ pullup.
49 /* TESTED ON:
50 * - 1611B H2 (with usb1 mini-AB) using standard Mini-B or OTG cables
51 * - 5912 OSK OHCI (with usb0 standard-A), standard A-to-B cables
52 * - 5912 OSK UDC, with *nonstandard* A-to-A cable
53 * - 1510 Innovator UDC with bundled usb0 cable
54 * - 1510 Innovator OHCI with bundled usb1/usb2 cable
55 * - 1510 Innovator OHCI with custom usb0 cable, feeding 5V VBUS
56 * - 1710 custom development board using alternate pin group
57 * - 1710 H3 (with usb1 mini-AB) using standard Mini-B or OTG cables
60 /*-------------------------------------------------------------------------*/
62 #ifdef CONFIG_ARCH_OMAP_OTG
64 static struct otg_transceiver *xceiv;
66 /**
67 * otg_get_transceiver - find the (single) OTG transceiver driver
69 * Returns the transceiver driver, after getting a refcount to it; or
70 * null if there is no such transceiver. The caller is responsible for
71 * releasing that count.
73 struct otg_transceiver *otg_get_transceiver(void)
75 if (xceiv)
76 get_device(xceiv->dev);
77 return xceiv;
79 EXPORT_SYMBOL(otg_get_transceiver);
81 int otg_set_transceiver(struct otg_transceiver *x)
83 if (xceiv && x)
84 return -EBUSY;
85 xceiv = x;
86 return 0;
88 EXPORT_SYMBOL(otg_set_transceiver);
90 #endif
92 /*-------------------------------------------------------------------------*/
94 #if defined(CONFIG_ARCH_OMAP_OTG) || defined(CONFIG_ARCH_OMAP15XX)
96 static u32 __init omap_usb0_init(unsigned nwires, unsigned is_device)
98 u32 syscon1 = 0;
100 if (nwires == 0) {
101 if (!cpu_is_omap15xx()) {
102 /* pulldown D+/D- */
103 USB_TRANSCEIVER_CTRL_REG &= ~(3 << 1);
105 return 0;
108 if (is_device)
109 omap_cfg_reg(W4_USB_PUEN);
111 /* internal transceiver */
112 if (nwires == 2) {
113 // omap_cfg_reg(P9_USB_DP);
114 // omap_cfg_reg(R8_USB_DM);
116 if (cpu_is_omap15xx()) {
117 /* This works on 1510-Innovator */
118 return 0;
121 /* NOTES:
122 * - peripheral should configure VBUS detection!
123 * - only peripherals may use the internal D+/D- pulldowns
124 * - OTG support on this port not yet written
127 USB_TRANSCEIVER_CTRL_REG &= ~(7 << 4);
128 if (!is_device)
129 USB_TRANSCEIVER_CTRL_REG |= (3 << 1);
131 return 3 << 16;
134 /* alternate pin config, external transceiver */
135 if (cpu_is_omap15xx()) {
136 printk(KERN_ERR "no usb0 alt pin config on 15xx\n");
137 return 0;
140 omap_cfg_reg(V6_USB0_TXD);
141 omap_cfg_reg(W9_USB0_TXEN);
142 omap_cfg_reg(W5_USB0_SE0);
144 /* NOTE: SPEED and SUSP aren't configured here */
146 if (nwires != 3)
147 omap_cfg_reg(Y5_USB0_RCV);
148 if (nwires != 6)
149 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB2_UNI_R;
151 switch (nwires) {
152 case 3:
153 syscon1 = 2;
154 break;
155 case 4:
156 syscon1 = 1;
157 break;
158 case 6:
159 syscon1 = 3;
160 omap_cfg_reg(AA9_USB0_VP);
161 omap_cfg_reg(R9_USB0_VM);
162 USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;
163 break;
164 default:
165 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
166 0, nwires);
168 return syscon1 << 16;
171 static u32 __init omap_usb1_init(unsigned nwires)
173 u32 syscon1 = 0;
175 if (nwires != 6 && !cpu_is_omap15xx())
176 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB1_UNI_R;
177 if (nwires == 0)
178 return 0;
180 /* external transceiver */
181 omap_cfg_reg(USB1_TXD);
182 omap_cfg_reg(USB1_TXEN);
183 if (cpu_is_omap15xx()) {
184 omap_cfg_reg(USB1_SEO);
185 omap_cfg_reg(USB1_SPEED);
186 // SUSP
187 } else if (cpu_is_omap1610() || cpu_is_omap5912()) {
188 omap_cfg_reg(W13_1610_USB1_SE0);
189 omap_cfg_reg(R13_1610_USB1_SPEED);
190 // SUSP
191 } else if (cpu_is_omap1710()) {
192 omap_cfg_reg(R13_1710_USB1_SE0);
193 // SUSP
194 } else {
195 pr_debug("usb unrecognized\n");
197 if (nwires != 3)
198 omap_cfg_reg(USB1_RCV);
200 switch (nwires) {
201 case 3:
202 syscon1 = 2;
203 break;
204 case 4:
205 syscon1 = 1;
206 break;
207 case 6:
208 syscon1 = 3;
209 omap_cfg_reg(USB1_VP);
210 omap_cfg_reg(USB1_VM);
211 if (!cpu_is_omap15xx())
212 USB_TRANSCEIVER_CTRL_REG |= CONF_USB1_UNI_R;
213 break;
214 default:
215 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
216 1, nwires);
218 return syscon1 << 20;
221 static u32 __init omap_usb2_init(unsigned nwires, unsigned alt_pingroup)
223 u32 syscon1 = 0;
225 /* NOTE erratum: must leave USB2_UNI_R set if usb0 in use */
226 if (alt_pingroup || nwires == 0)
227 return 0;
228 if (nwires != 6 && !cpu_is_omap15xx())
229 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB2_UNI_R;
231 /* external transceiver */
232 if (cpu_is_omap15xx()) {
233 omap_cfg_reg(USB2_TXD);
234 omap_cfg_reg(USB2_TXEN);
235 omap_cfg_reg(USB2_SEO);
236 if (nwires != 3)
237 omap_cfg_reg(USB2_RCV);
238 /* there is no USB2_SPEED */
239 } else if (cpu_is_omap16xx()) {
240 omap_cfg_reg(V6_USB2_TXD);
241 omap_cfg_reg(W9_USB2_TXEN);
242 omap_cfg_reg(W5_USB2_SE0);
243 if (nwires != 3)
244 omap_cfg_reg(Y5_USB2_RCV);
245 // FIXME omap_cfg_reg(USB2_SPEED);
246 } else {
247 pr_debug("usb unrecognized\n");
249 // omap_cfg_reg(USB2_SUSP);
251 switch (nwires) {
252 case 3:
253 syscon1 = 2;
254 break;
255 case 4:
256 syscon1 = 1;
257 break;
258 case 6:
259 syscon1 = 3;
260 if (cpu_is_omap15xx()) {
261 omap_cfg_reg(USB2_VP);
262 omap_cfg_reg(USB2_VM);
263 } else {
264 omap_cfg_reg(AA9_USB2_VP);
265 omap_cfg_reg(R9_USB2_VM);
266 USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;
268 break;
269 default:
270 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
271 2, nwires);
273 return syscon1 << 24;
276 #endif
278 /*-------------------------------------------------------------------------*/
280 #if defined(CONFIG_USB_GADGET_OMAP) || \
281 defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) || \
282 (defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG))
283 static void usb_release(struct device *dev)
285 /* normally not freed */
287 #endif
289 #ifdef CONFIG_USB_GADGET_OMAP
291 static struct resource udc_resources[] = {
292 /* order is significant! */
293 { /* registers */
294 .start = UDC_BASE,
295 .end = UDC_BASE + 0xff,
296 .flags = IORESOURCE_MEM,
297 }, { /* general IRQ */
298 .start = IH2_BASE + 20,
299 .flags = IORESOURCE_IRQ,
300 }, { /* PIO IRQ */
301 .start = IH2_BASE + 30,
302 .flags = IORESOURCE_IRQ,
303 }, { /* SOF IRQ */
304 .start = IH2_BASE + 29,
305 .flags = IORESOURCE_IRQ,
309 static u64 udc_dmamask = ~(u32)0;
311 static struct platform_device udc_device = {
312 .name = "omap_udc",
313 .id = -1,
314 .dev = {
315 .release = usb_release,
316 .dma_mask = &udc_dmamask,
317 .coherent_dma_mask = 0xffffffff,
319 .num_resources = ARRAY_SIZE(udc_resources),
320 .resource = udc_resources,
323 #endif
325 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
327 /* The dmamask must be set for OHCI to work */
328 static u64 ohci_dmamask = ~(u32)0;
330 static struct resource ohci_resources[] = {
332 .start = OMAP_OHCI_BASE,
333 .end = OMAP_OHCI_BASE + 4096 - 1,
334 .flags = IORESOURCE_MEM,
337 .start = INT_USB_HHC_1,
338 .flags = IORESOURCE_IRQ,
342 static struct platform_device ohci_device = {
343 .name = "ohci",
344 .id = -1,
345 .dev = {
346 .release = usb_release,
347 .dma_mask = &ohci_dmamask,
348 .coherent_dma_mask = 0xffffffff,
350 .num_resources = ARRAY_SIZE(ohci_resources),
351 .resource = ohci_resources,
354 #endif
356 #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
358 static struct resource otg_resources[] = {
359 /* order is significant! */
361 .start = OTG_BASE,
362 .end = OTG_BASE + 0xff,
363 .flags = IORESOURCE_MEM,
364 }, {
365 .start = IH2_BASE + 8,
366 .flags = IORESOURCE_IRQ,
370 static struct platform_device otg_device = {
371 .name = "omap_otg",
372 .id = -1,
373 .dev = {
374 .release = usb_release,
376 .num_resources = ARRAY_SIZE(otg_resources),
377 .resource = otg_resources,
380 #endif
382 /*-------------------------------------------------------------------------*/
384 #define ULPD_CLOCK_CTRL_REG __REG16(ULPD_CLOCK_CTRL)
385 #define ULPD_SOFT_REQ_REG __REG16(ULPD_SOFT_REQ)
388 // FIXME correct answer depends on hmc_mode,
389 // as does any nonzero value for config->otg port number
390 #ifdef CONFIG_USB_GADGET_OMAP
391 #define is_usb0_device(config) 1
392 #else
393 #define is_usb0_device(config) 0
394 #endif
396 /*-------------------------------------------------------------------------*/
398 #ifdef CONFIG_ARCH_OMAP_OTG
400 void __init
401 omap_otg_init(struct omap_usb_config *config)
403 u32 syscon = OTG_SYSCON_1_REG & 0xffff;
404 int status;
405 int alt_pingroup = 0;
407 /* NOTE: no bus or clock setup (yet?) */
409 syscon = OTG_SYSCON_1_REG & 0xffff;
410 if (!(syscon & OTG_RESET_DONE))
411 pr_debug("USB resets not complete?\n");
413 // OTG_IRQ_EN_REG = 0;
415 /* pin muxing and transceiver pinouts */
416 if (config->pins[0] > 2) /* alt pingroup 2 */
417 alt_pingroup = 1;
418 syscon |= omap_usb0_init(config->pins[0], is_usb0_device(config));
419 syscon |= omap_usb1_init(config->pins[1]);
420 syscon |= omap_usb2_init(config->pins[2], alt_pingroup);
421 pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
422 OTG_SYSCON_1_REG = syscon;
424 syscon = config->hmc_mode;
425 syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
426 #ifdef CONFIG_USB_OTG
427 if (config->otg)
428 syscon |= OTG_EN;
429 #endif
430 pr_debug("USB_TRANSCEIVER_CTRL_REG = %03x\n", USB_TRANSCEIVER_CTRL_REG);
431 pr_debug("OTG_SYSCON_2_REG = %08x\n", syscon);
432 OTG_SYSCON_2_REG = syscon;
434 printk("USB: hmc %d", config->hmc_mode);
435 if (alt_pingroup)
436 printk(", usb2 alt %d wires", config->pins[2]);
437 else if (config->pins[0])
438 printk(", usb0 %d wires%s", config->pins[0],
439 is_usb0_device(config) ? " (dev)" : "");
440 if (config->pins[1])
441 printk(", usb1 %d wires", config->pins[1]);
442 if (!alt_pingroup && config->pins[2])
443 printk(", usb2 %d wires", config->pins[2]);
444 if (config->otg)
445 printk(", Mini-AB on usb%d", config->otg - 1);
446 printk("\n");
448 /* leave USB clocks/controllers off until needed */
449 ULPD_SOFT_REQ_REG &= ~SOFT_USB_CLK_REQ;
450 ULPD_CLOCK_CTRL_REG &= ~USB_MCLK_EN;
451 ULPD_CLOCK_CTRL_REG |= DIS_USB_PVCI_CLK;
452 syscon = OTG_SYSCON_1_REG;
453 syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
455 #ifdef CONFIG_USB_GADGET_OMAP
456 if (config->otg || config->register_dev) {
457 syscon &= ~DEV_IDLE_EN;
458 udc_device.dev.platform_data = config;
459 /* FIXME patch IRQ numbers for omap730 */
460 status = platform_device_register(&udc_device);
461 if (status)
462 pr_debug("can't register UDC device, %d\n", status);
464 #endif
466 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
467 if (config->otg || config->register_host) {
468 syscon &= ~HST_IDLE_EN;
469 ohci_device.dev.platform_data = config;
470 if (cpu_is_omap730())
471 ohci_resources[1].start = INT_730_USB_HHC_1;
472 status = platform_device_register(&ohci_device);
473 if (status)
474 pr_debug("can't register OHCI device, %d\n", status);
476 #endif
478 #ifdef CONFIG_USB_OTG
479 if (config->otg) {
480 syscon &= ~OTG_IDLE_EN;
481 otg_device.dev.platform_data = config;
482 if (cpu_is_omap730())
483 otg_resources[1].start = INT_730_USB_OTG;
484 status = platform_device_register(&otg_device);
485 if (status)
486 pr_debug("can't register OTG device, %d\n", status);
488 #endif
489 pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
490 OTG_SYSCON_1_REG = syscon;
492 status = 0;
495 #else
496 static inline void omap_otg_init(struct omap_usb_config *config) {}
497 #endif
499 /*-------------------------------------------------------------------------*/
501 #ifdef CONFIG_ARCH_OMAP15XX
503 #define ULPD_DPLL_CTRL_REG __REG16(ULPD_DPLL_CTRL)
504 #define DPLL_IOB (1 << 13)
505 #define DPLL_PLL_ENABLE (1 << 4)
506 #define DPLL_LOCK (1 << 0)
508 #define ULPD_APLL_CTRL_REG __REG16(ULPD_APLL_CTRL)
509 #define APLL_NDPLL_SWITCH (1 << 0)
512 static void __init omap_1510_usb_init(struct omap_usb_config *config)
514 unsigned int val;
516 omap_usb0_init(config->pins[0], is_usb0_device(config));
517 omap_usb1_init(config->pins[1]);
518 omap_usb2_init(config->pins[2], 0);
520 val = omap_readl(MOD_CONF_CTRL_0) & ~(0x3f << 1);
521 val |= (config->hmc_mode << 1);
522 omap_writel(val, MOD_CONF_CTRL_0);
524 printk("USB: hmc %d", config->hmc_mode);
525 if (config->pins[0])
526 printk(", usb0 %d wires%s", config->pins[0],
527 is_usb0_device(config) ? " (dev)" : "");
528 if (config->pins[1])
529 printk(", usb1 %d wires", config->pins[1]);
530 if (config->pins[2])
531 printk(", usb2 %d wires", config->pins[2]);
532 printk("\n");
534 /* use DPLL for 48 MHz function clock */
535 pr_debug("APLL %04x DPLL %04x REQ %04x\n", ULPD_APLL_CTRL_REG,
536 ULPD_DPLL_CTRL_REG, ULPD_SOFT_REQ_REG);
537 ULPD_APLL_CTRL_REG &= ~APLL_NDPLL_SWITCH;
538 ULPD_DPLL_CTRL_REG |= DPLL_IOB | DPLL_PLL_ENABLE;
539 ULPD_SOFT_REQ_REG |= SOFT_UDC_REQ | SOFT_DPLL_REQ;
540 while (!(ULPD_DPLL_CTRL_REG & DPLL_LOCK))
541 cpu_relax();
543 #ifdef CONFIG_USB_GADGET_OMAP
544 if (config->register_dev) {
545 int status;
547 udc_device.dev.platform_data = config;
548 status = platform_device_register(&udc_device);
549 if (status)
550 pr_debug("can't register UDC device, %d\n", status);
551 /* udc driver gates 48MHz by D+ pullup */
553 #endif
555 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
556 if (config->register_host) {
557 int status;
559 ohci_device.dev.platform_data = config;
560 status = platform_device_register(&ohci_device);
561 if (status)
562 pr_debug("can't register OHCI device, %d\n", status);
563 /* hcd explicitly gates 48MHz */
565 #endif
568 #else
569 static inline void omap_1510_usb_init(struct omap_usb_config *config) {}
570 #endif
572 /*-------------------------------------------------------------------------*/
574 static struct omap_usb_config platform_data;
576 static int __init
577 omap_usb_init(void)
579 const struct omap_usb_config *config;
581 config = omap_get_config(OMAP_TAG_USB, struct omap_usb_config);
582 if (config == NULL) {
583 printk(KERN_ERR "USB: No board-specific "
584 "platform config found\n");
585 return -ENODEV;
587 platform_data = *config;
589 if (cpu_is_omap730() || cpu_is_omap16xx())
590 omap_otg_init(&platform_data);
591 else if (cpu_is_omap15xx())
592 omap_1510_usb_init(&platform_data);
593 else {
594 printk(KERN_ERR "USB: No init for your chip yet\n");
595 return -ENODEV;
597 return 0;
600 subsys_initcall(omap_usb_init);