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
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/types.h>
26 #include <linux/errno.h>
27 #include <linux/init.h>
28 #include <linux/platform_device.h>
29 #include <linux/usb/otg.h>
33 #include <asm/system.h>
34 #include <asm/hardware.h>
36 #include <asm/arch/mux.h>
37 #include <asm/arch/usb.h>
38 #include <asm/arch/board.h>
40 #ifdef CONFIG_ARCH_OMAP1
42 #define INT_USB_IRQ_GEN IH2_BASE + 20
43 #define INT_USB_IRQ_NISO IH2_BASE + 30
44 #define INT_USB_IRQ_ISO IH2_BASE + 29
45 #define INT_USB_IRQ_HGEN INT_USB_HHC_1
46 #define INT_USB_IRQ_OTG IH2_BASE + 8
50 #define INT_USB_IRQ_GEN INT_24XX_USB_IRQ_GEN
51 #define INT_USB_IRQ_NISO INT_24XX_USB_IRQ_NISO
52 #define INT_USB_IRQ_ISO INT_24XX_USB_IRQ_ISO
53 #define INT_USB_IRQ_HGEN INT_24XX_USB_IRQ_HGEN
54 #define INT_USB_IRQ_OTG INT_24XX_USB_IRQ_OTG
59 /* These routines should handle the standard chip-specific modes
60 * for usb0/1/2 ports, covering basic mux and transceiver setup.
62 * Some board-*.c files will need to set up additional mux options,
63 * like for suspend handling, vbus sensing, GPIOs, and the D+ pullup.
67 * - 1611B H2 (with usb1 mini-AB) using standard Mini-B or OTG cables
68 * - 5912 OSK OHCI (with usb0 standard-A), standard A-to-B cables
69 * - 5912 OSK UDC, with *nonstandard* A-to-A cable
70 * - 1510 Innovator UDC with bundled usb0 cable
71 * - 1510 Innovator OHCI with bundled usb1/usb2 cable
72 * - 1510 Innovator OHCI with custom usb0 cable, feeding 5V VBUS
73 * - 1710 custom development board using alternate pin group
74 * - 1710 H3 (with usb1 mini-AB) using standard Mini-B or OTG cables
77 /*-------------------------------------------------------------------------*/
79 #ifdef CONFIG_ARCH_OMAP_OTG
81 static struct otg_transceiver *xceiv;
84 * otg_get_transceiver - find the (single) OTG transceiver driver
86 * Returns the transceiver driver, after getting a refcount to it; or
87 * null if there is no such transceiver. The caller is responsible for
88 * releasing that count.
90 struct otg_transceiver *otg_get_transceiver(void)
93 get_device(xceiv->dev);
96 EXPORT_SYMBOL(otg_get_transceiver);
98 int otg_set_transceiver(struct otg_transceiver *x)
105 EXPORT_SYMBOL(otg_set_transceiver);
109 /*-------------------------------------------------------------------------*/
111 #if defined(CONFIG_ARCH_OMAP_OTG) || defined(CONFIG_ARCH_OMAP15XX)
113 static u32 __init omap_usb0_init(unsigned nwires, unsigned is_device)
117 if (cpu_is_omap24xx())
118 CONTROL_DEVCONF_REG &= ~USBT0WRMODEI(USB_BIDIR_TLL);
121 if (cpu_class_is_omap1() && !cpu_is_omap15xx()) {
123 USB_TRANSCEIVER_CTRL_REG &= ~(3 << 1);
129 if (cpu_is_omap24xx())
130 omap_cfg_reg(J20_24XX_USB0_PUEN);
132 omap_cfg_reg(W4_USB_PUEN);
135 /* internal transceiver (unavailable on 17xx, 24xx) */
136 if (!cpu_class_is_omap2() && nwires == 2) {
137 // omap_cfg_reg(P9_USB_DP);
138 // omap_cfg_reg(R8_USB_DM);
140 if (cpu_is_omap15xx()) {
141 /* This works on 1510-Innovator */
146 * - peripheral should configure VBUS detection!
147 * - only peripherals may use the internal D+/D- pulldowns
148 * - OTG support on this port not yet written
151 USB_TRANSCEIVER_CTRL_REG &= ~(7 << 4);
153 USB_TRANSCEIVER_CTRL_REG |= (3 << 1);
158 /* alternate pin config, external transceiver */
159 if (cpu_is_omap15xx()) {
160 printk(KERN_ERR "no usb0 alt pin config on 15xx\n");
164 if (cpu_is_omap24xx()) {
165 omap_cfg_reg(K18_24XX_USB0_DAT);
166 omap_cfg_reg(K19_24XX_USB0_TXEN);
167 omap_cfg_reg(J14_24XX_USB0_SE0);
169 omap_cfg_reg(J18_24XX_USB0_RCV);
171 omap_cfg_reg(V6_USB0_TXD);
172 omap_cfg_reg(W9_USB0_TXEN);
173 omap_cfg_reg(W5_USB0_SE0);
175 omap_cfg_reg(Y5_USB0_RCV);
178 /* NOTE: SPEED and SUSP aren't configured here. OTG hosts
179 * may be able to use I2C requests to set those bits along
180 * with VBUS switching and overcurrent detection.
183 if (cpu_class_is_omap1() && nwires != 6)
184 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB2_UNI_R;
189 if (cpu_is_omap24xx())
190 CONTROL_DEVCONF_REG |= USBT0WRMODEI(USB_BIDIR);
194 if (cpu_is_omap24xx())
195 CONTROL_DEVCONF_REG |= USBT0WRMODEI(USB_BIDIR);
199 if (cpu_is_omap24xx()) {
200 omap_cfg_reg(J19_24XX_USB0_VP);
201 omap_cfg_reg(K20_24XX_USB0_VM);
202 CONTROL_DEVCONF_REG |= USBT0WRMODEI(USB_UNIDIR);
204 omap_cfg_reg(AA9_USB0_VP);
205 omap_cfg_reg(R9_USB0_VM);
206 USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;
210 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
213 return syscon1 << 16;
216 static u32 __init omap_usb1_init(unsigned nwires)
220 if (cpu_class_is_omap1() && !cpu_is_omap15xx() && nwires != 6)
221 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB1_UNI_R;
222 if (cpu_is_omap24xx())
223 CONTROL_DEVCONF_REG &= ~USBT1WRMODEI(USB_BIDIR_TLL);
228 /* external transceiver */
229 if (cpu_class_is_omap1()) {
230 omap_cfg_reg(USB1_TXD);
231 omap_cfg_reg(USB1_TXEN);
233 omap_cfg_reg(USB1_RCV);
236 if (cpu_is_omap15xx()) {
237 omap_cfg_reg(USB1_SEO);
238 omap_cfg_reg(USB1_SPEED);
240 } else if (cpu_is_omap1610() || cpu_is_omap5912()) {
241 omap_cfg_reg(W13_1610_USB1_SE0);
242 omap_cfg_reg(R13_1610_USB1_SPEED);
244 } else if (cpu_is_omap1710()) {
245 omap_cfg_reg(R13_1710_USB1_SE0);
247 } else if (cpu_is_omap24xx()) {
248 /* NOTE: board-specific code must set up pin muxing for usb1,
249 * since each signal could come out on either of two balls.
252 pr_debug("usb%d cpu unrecognized\n", 1);
258 if (!cpu_is_omap24xx())
260 /* NOTE: board-specific code must override this setting if
261 * this TLL link is not using DP/DM
264 CONTROL_DEVCONF_REG |= USBT1WRMODEI(USB_BIDIR_TLL);
268 if (cpu_is_omap24xx())
269 CONTROL_DEVCONF_REG |= USBT1WRMODEI(USB_BIDIR);
273 if (cpu_is_omap24xx())
274 CONTROL_DEVCONF_REG |= USBT1WRMODEI(USB_BIDIR);
277 if (cpu_is_omap24xx())
280 omap_cfg_reg(USB1_VP);
281 omap_cfg_reg(USB1_VM);
282 if (!cpu_is_omap15xx())
283 USB_TRANSCEIVER_CTRL_REG |= CONF_USB1_UNI_R;
287 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
290 return syscon1 << 20;
293 static u32 __init omap_usb2_init(unsigned nwires, unsigned alt_pingroup)
297 if (cpu_is_omap24xx()) {
298 CONTROL_DEVCONF_REG &= ~(USBT2WRMODEI(USB_BIDIR_TLL)
303 /* NOTE omap1 erratum: must leave USB2_UNI_R set if usb0 in use */
304 if (alt_pingroup || nwires == 0)
307 if (cpu_class_is_omap1() && !cpu_is_omap15xx() && nwires != 6)
308 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB2_UNI_R;
310 /* external transceiver */
311 if (cpu_is_omap15xx()) {
312 omap_cfg_reg(USB2_TXD);
313 omap_cfg_reg(USB2_TXEN);
314 omap_cfg_reg(USB2_SEO);
316 omap_cfg_reg(USB2_RCV);
317 /* there is no USB2_SPEED */
318 } else if (cpu_is_omap16xx()) {
319 omap_cfg_reg(V6_USB2_TXD);
320 omap_cfg_reg(W9_USB2_TXEN);
321 omap_cfg_reg(W5_USB2_SE0);
323 omap_cfg_reg(Y5_USB2_RCV);
324 // FIXME omap_cfg_reg(USB2_SPEED);
325 } else if (cpu_is_omap24xx()) {
326 omap_cfg_reg(Y11_24XX_USB2_DAT);
327 omap_cfg_reg(AA10_24XX_USB2_SE0);
329 omap_cfg_reg(AA12_24XX_USB2_TXEN);
331 omap_cfg_reg(AA6_24XX_USB2_RCV);
333 pr_debug("usb%d cpu unrecognized\n", 1);
336 // if (cpu_class_is_omap1()) omap_cfg_reg(USB2_SUSP);
340 if (!cpu_is_omap24xx())
342 /* NOTE: board-specific code must override this setting if
343 * this TLL link is not using DP/DM
346 CONTROL_DEVCONF_REG |= USBT2WRMODEI(USB_BIDIR_TLL);
350 if (cpu_is_omap24xx())
351 CONTROL_DEVCONF_REG |= USBT2WRMODEI(USB_BIDIR);
355 if (cpu_is_omap24xx())
356 CONTROL_DEVCONF_REG |= USBT2WRMODEI(USB_BIDIR);
359 if (!cpu_is_omap24xx())
361 omap_cfg_reg(AA4_24XX_USB2_TLLSE0);
362 /* NOTE: board-specific code must override this setting if
363 * this TLL link is not using DP/DM. Something must also
364 * set up OTG_SYSCON2.HMC_TLL{ATTACH,SPEED}
367 CONTROL_DEVCONF_REG |= USBT2WRMODEI(USB_UNIDIR_TLL)
371 if (cpu_is_omap24xx())
374 if (cpu_is_omap15xx()) {
375 omap_cfg_reg(USB2_VP);
376 omap_cfg_reg(USB2_VM);
378 omap_cfg_reg(AA9_USB2_VP);
379 omap_cfg_reg(R9_USB2_VM);
380 USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;
385 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
388 return syscon1 << 24;
393 /*-------------------------------------------------------------------------*/
395 #if defined(CONFIG_USB_GADGET_OMAP) || \
396 defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) || \
397 (defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG))
398 static void usb_release(struct device *dev)
400 /* normally not freed */
404 #ifdef CONFIG_USB_GADGET_OMAP
406 static struct resource udc_resources[] = {
407 /* order is significant! */
410 .end = UDC_BASE + 0xff,
411 .flags = IORESOURCE_MEM,
412 }, { /* general IRQ */
413 .start = INT_USB_IRQ_GEN,
414 .flags = IORESOURCE_IRQ,
416 .start = INT_USB_IRQ_NISO,
417 .flags = IORESOURCE_IRQ,
419 .start = INT_USB_IRQ_ISO,
420 .flags = IORESOURCE_IRQ,
424 static u64 udc_dmamask = ~(u32)0;
426 static struct platform_device udc_device = {
430 .release = usb_release,
431 .dma_mask = &udc_dmamask,
432 .coherent_dma_mask = 0xffffffff,
434 .num_resources = ARRAY_SIZE(udc_resources),
435 .resource = udc_resources,
440 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
442 /* The dmamask must be set for OHCI to work */
443 static u64 ohci_dmamask = ~(u32)0;
445 static struct resource ohci_resources[] = {
447 .start = OMAP_OHCI_BASE,
448 .end = OMAP_OHCI_BASE + 0xff,
449 .flags = IORESOURCE_MEM,
452 .start = INT_USB_IRQ_HGEN,
453 .flags = IORESOURCE_IRQ,
457 static struct platform_device ohci_device = {
461 .release = usb_release,
462 .dma_mask = &ohci_dmamask,
463 .coherent_dma_mask = 0xffffffff,
465 .num_resources = ARRAY_SIZE(ohci_resources),
466 .resource = ohci_resources,
471 #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
473 static struct resource otg_resources[] = {
474 /* order is significant! */
477 .end = OTG_BASE + 0xff,
478 .flags = IORESOURCE_MEM,
480 .start = INT_USB_IRQ_OTG,
481 .flags = IORESOURCE_IRQ,
485 static struct platform_device otg_device = {
489 .release = usb_release,
491 .num_resources = ARRAY_SIZE(otg_resources),
492 .resource = otg_resources,
497 /*-------------------------------------------------------------------------*/
499 #define ULPD_CLOCK_CTRL_REG __REG16(ULPD_CLOCK_CTRL)
500 #define ULPD_SOFT_REQ_REG __REG16(ULPD_SOFT_REQ)
503 // FIXME correct answer depends on hmc_mode,
504 // as does (on omap1) any nonzero value for config->otg port number
505 #ifdef CONFIG_USB_GADGET_OMAP
506 #define is_usb0_device(config) 1
508 #define is_usb0_device(config) 0
511 /*-------------------------------------------------------------------------*/
513 #ifdef CONFIG_ARCH_OMAP_OTG
516 omap_otg_init(struct omap_usb_config *config)
518 u32 syscon = OTG_SYSCON_1_REG & 0xffff;
520 int alt_pingroup = 0;
522 /* NOTE: no bus or clock setup (yet?) */
524 syscon = OTG_SYSCON_1_REG & 0xffff;
525 if (!(syscon & OTG_RESET_DONE))
526 pr_debug("USB resets not complete?\n");
528 // OTG_IRQ_EN_REG = 0;
530 /* pin muxing and transceiver pinouts */
531 if (config->pins[0] > 2) /* alt pingroup 2 */
533 syscon |= omap_usb0_init(config->pins[0], is_usb0_device(config));
534 syscon |= omap_usb1_init(config->pins[1]);
535 syscon |= omap_usb2_init(config->pins[2], alt_pingroup);
536 pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
537 OTG_SYSCON_1_REG = syscon;
539 syscon = config->hmc_mode;
540 syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
541 #ifdef CONFIG_USB_OTG
545 if (cpu_class_is_omap1())
546 pr_debug("USB_TRANSCEIVER_CTRL_REG = %03x\n", USB_TRANSCEIVER_CTRL_REG);
547 pr_debug("OTG_SYSCON_2_REG = %08x\n", syscon);
548 OTG_SYSCON_2_REG = syscon;
550 printk("USB: hmc %d", config->hmc_mode);
552 printk(", usb2 alt %d wires", config->pins[2]);
553 else if (config->pins[0])
554 printk(", usb0 %d wires%s", config->pins[0],
555 is_usb0_device(config) ? " (dev)" : "");
557 printk(", usb1 %d wires", config->pins[1]);
558 if (!alt_pingroup && config->pins[2])
559 printk(", usb2 %d wires", config->pins[2]);
561 printk(", Mini-AB on usb%d", config->otg - 1);
564 if (cpu_class_is_omap1()) {
565 /* leave USB clocks/controllers off until needed */
566 ULPD_SOFT_REQ_REG &= ~SOFT_USB_CLK_REQ;
567 ULPD_CLOCK_CTRL_REG &= ~USB_MCLK_EN;
568 ULPD_CLOCK_CTRL_REG |= DIS_USB_PVCI_CLK;
570 syscon = OTG_SYSCON_1_REG;
571 syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
573 #ifdef CONFIG_USB_GADGET_OMAP
574 if (config->otg || config->register_dev) {
575 syscon &= ~DEV_IDLE_EN;
576 udc_device.dev.platform_data = config;
577 /* FIXME patch IRQ numbers for omap730 */
578 status = platform_device_register(&udc_device);
580 pr_debug("can't register UDC device, %d\n", status);
584 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
585 if (config->otg || config->register_host) {
586 syscon &= ~HST_IDLE_EN;
587 ohci_device.dev.platform_data = config;
588 if (cpu_is_omap730())
589 ohci_resources[1].start = INT_730_USB_HHC_1;
590 status = platform_device_register(&ohci_device);
592 pr_debug("can't register OHCI device, %d\n", status);
596 #ifdef CONFIG_USB_OTG
598 syscon &= ~OTG_IDLE_EN;
599 otg_device.dev.platform_data = config;
600 if (cpu_is_omap730())
601 otg_resources[1].start = INT_730_USB_OTG;
602 status = platform_device_register(&otg_device);
604 pr_debug("can't register OTG device, %d\n", status);
607 pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
608 OTG_SYSCON_1_REG = syscon;
614 static inline void omap_otg_init(struct omap_usb_config *config) {}
617 /*-------------------------------------------------------------------------*/
619 #ifdef CONFIG_ARCH_OMAP15XX
621 #define ULPD_DPLL_CTRL_REG __REG16(ULPD_DPLL_CTRL)
622 #define DPLL_IOB (1 << 13)
623 #define DPLL_PLL_ENABLE (1 << 4)
624 #define DPLL_LOCK (1 << 0)
626 #define ULPD_APLL_CTRL_REG __REG16(ULPD_APLL_CTRL)
627 #define APLL_NDPLL_SWITCH (1 << 0)
630 static void __init omap_1510_usb_init(struct omap_usb_config *config)
634 omap_usb0_init(config->pins[0], is_usb0_device(config));
635 omap_usb1_init(config->pins[1]);
636 omap_usb2_init(config->pins[2], 0);
638 val = omap_readl(MOD_CONF_CTRL_0) & ~(0x3f << 1);
639 val |= (config->hmc_mode << 1);
640 omap_writel(val, MOD_CONF_CTRL_0);
642 printk("USB: hmc %d", config->hmc_mode);
644 printk(", usb0 %d wires%s", config->pins[0],
645 is_usb0_device(config) ? " (dev)" : "");
647 printk(", usb1 %d wires", config->pins[1]);
649 printk(", usb2 %d wires", config->pins[2]);
652 /* use DPLL for 48 MHz function clock */
653 pr_debug("APLL %04x DPLL %04x REQ %04x\n", ULPD_APLL_CTRL_REG,
654 ULPD_DPLL_CTRL_REG, ULPD_SOFT_REQ_REG);
655 ULPD_APLL_CTRL_REG &= ~APLL_NDPLL_SWITCH;
656 ULPD_DPLL_CTRL_REG |= DPLL_IOB | DPLL_PLL_ENABLE;
657 ULPD_SOFT_REQ_REG |= SOFT_UDC_REQ | SOFT_DPLL_REQ;
658 while (!(ULPD_DPLL_CTRL_REG & DPLL_LOCK))
661 #ifdef CONFIG_USB_GADGET_OMAP
662 if (config->register_dev) {
665 udc_device.dev.platform_data = config;
666 status = platform_device_register(&udc_device);
668 pr_debug("can't register UDC device, %d\n", status);
669 /* udc driver gates 48MHz by D+ pullup */
673 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
674 if (config->register_host) {
677 ohci_device.dev.platform_data = config;
678 status = platform_device_register(&ohci_device);
680 pr_debug("can't register OHCI device, %d\n", status);
681 /* hcd explicitly gates 48MHz */
687 static inline void omap_1510_usb_init(struct omap_usb_config *config) {}
690 /*-------------------------------------------------------------------------*/
692 static struct omap_usb_config platform_data;
697 const struct omap_usb_config *config;
699 config = omap_get_config(OMAP_TAG_USB, struct omap_usb_config);
700 if (config == NULL) {
701 printk(KERN_ERR "USB: No board-specific "
702 "platform config found\n");
705 platform_data = *config;
707 if (cpu_is_omap730() || cpu_is_omap16xx() || cpu_is_omap24xx())
708 omap_otg_init(&platform_data);
709 else if (cpu_is_omap15xx())
710 omap_1510_usb_init(&platform_data);
712 printk(KERN_ERR "USB: No init for your chip yet\n");
718 subsys_initcall(omap_usb_init);