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 <mach/hardware.h>
36 #include <mach/control.h>
39 #include <mach/board.h>
41 #ifdef CONFIG_ARCH_OMAP1
43 #define INT_USB_IRQ_GEN IH2_BASE + 20
44 #define INT_USB_IRQ_NISO IH2_BASE + 30
45 #define INT_USB_IRQ_ISO IH2_BASE + 29
46 #define INT_USB_IRQ_HGEN INT_USB_HHC_1
47 #define INT_USB_IRQ_OTG IH2_BASE + 8
51 #define INT_USB_IRQ_GEN INT_24XX_USB_IRQ_GEN
52 #define INT_USB_IRQ_NISO INT_24XX_USB_IRQ_NISO
53 #define INT_USB_IRQ_ISO INT_24XX_USB_IRQ_ISO
54 #define INT_USB_IRQ_HGEN INT_24XX_USB_IRQ_HGEN
55 #define INT_USB_IRQ_OTG INT_24XX_USB_IRQ_OTG
60 /* These routines should handle the standard chip-specific modes
61 * for usb0/1/2 ports, covering basic mux and transceiver setup.
63 * Some board-*.c files will need to set up additional mux options,
64 * like for suspend handling, vbus sensing, GPIOs, and the D+ pullup.
68 * - 1611B H2 (with usb1 mini-AB) using standard Mini-B or OTG cables
69 * - 5912 OSK OHCI (with usb0 standard-A), standard A-to-B cables
70 * - 5912 OSK UDC, with *nonstandard* A-to-A cable
71 * - 1510 Innovator UDC with bundled usb0 cable
72 * - 1510 Innovator OHCI with bundled usb1/usb2 cable
73 * - 1510 Innovator OHCI with custom usb0 cable, feeding 5V VBUS
74 * - 1710 custom development board using alternate pin group
75 * - 1710 H3 (with usb1 mini-AB) using standard Mini-B or OTG cables
78 /*-------------------------------------------------------------------------*/
80 #if defined(CONFIG_ARCH_OMAP_OTG) || defined(CONFIG_USB_MUSB_OTG)
82 static struct otg_transceiver *xceiv;
85 * otg_get_transceiver - find the (single) OTG transceiver driver
87 * Returns the transceiver driver, after getting a refcount to it; or
88 * null if there is no such transceiver. The caller is responsible for
89 * releasing that count.
91 struct otg_transceiver *otg_get_transceiver(void)
94 get_device(xceiv->dev);
97 EXPORT_SYMBOL(otg_get_transceiver);
99 void otg_put_transceiver(struct otg_transceiver *x)
103 EXPORT_SYMBOL(otg_put_transceiver);
105 int otg_set_transceiver(struct otg_transceiver *x)
112 EXPORT_SYMBOL(otg_set_transceiver);
116 /*-------------------------------------------------------------------------*/
118 #if defined(CONFIG_ARCH_OMAP_OTG) || defined(CONFIG_ARCH_OMAP15XX)
120 static void omap2_usb_devconf_clear(u8 port, u32 mask)
124 r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
125 r &= ~USBTXWRMODEI(port, mask);
126 omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
129 static void omap2_usb_devconf_set(u8 port, u32 mask)
133 r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
134 r |= USBTXWRMODEI(port, mask);
135 omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
138 static void omap2_usb2_disable_5pinbitll(void)
142 r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
143 r &= ~(USBTXWRMODEI(2, USB_BIDIR_TLL) | USBT2TLL5PI);
144 omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
147 static void omap2_usb2_enable_5pinunitll(void)
151 r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
152 r |= USBTXWRMODEI(2, USB_UNIDIR_TLL) | USBT2TLL5PI;
153 omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
156 static u32 __init omap_usb0_init(unsigned nwires, unsigned is_device)
160 if (cpu_is_omap24xx())
161 omap2_usb_devconf_clear(0, USB_BIDIR_TLL);
164 if (cpu_class_is_omap1() && !cpu_is_omap15xx()) {
168 l = omap_readl(USB_TRANSCEIVER_CTRL);
170 omap_writel(l, USB_TRANSCEIVER_CTRL);
176 if (cpu_is_omap24xx())
177 omap_cfg_reg(J20_24XX_USB0_PUEN);
179 omap_cfg_reg(W4_USB_PUEN);
182 /* internal transceiver (unavailable on 17xx, 24xx) */
183 if (!cpu_class_is_omap2() && nwires == 2) {
186 // omap_cfg_reg(P9_USB_DP);
187 // omap_cfg_reg(R8_USB_DM);
189 if (cpu_is_omap15xx()) {
190 /* This works on 1510-Innovator */
195 * - peripheral should configure VBUS detection!
196 * - only peripherals may use the internal D+/D- pulldowns
197 * - OTG support on this port not yet written
200 l = omap_readl(USB_TRANSCEIVER_CTRL);
204 omap_writel(l, USB_TRANSCEIVER_CTRL);
209 /* alternate pin config, external transceiver */
210 if (cpu_is_omap15xx()) {
211 printk(KERN_ERR "no usb0 alt pin config on 15xx\n");
215 if (cpu_is_omap24xx()) {
216 omap_cfg_reg(K18_24XX_USB0_DAT);
217 omap_cfg_reg(K19_24XX_USB0_TXEN);
218 omap_cfg_reg(J14_24XX_USB0_SE0);
220 omap_cfg_reg(J18_24XX_USB0_RCV);
222 omap_cfg_reg(V6_USB0_TXD);
223 omap_cfg_reg(W9_USB0_TXEN);
224 omap_cfg_reg(W5_USB0_SE0);
226 omap_cfg_reg(Y5_USB0_RCV);
229 /* NOTE: SPEED and SUSP aren't configured here. OTG hosts
230 * may be able to use I2C requests to set those bits along
231 * with VBUS switching and overcurrent detection.
234 if (cpu_class_is_omap1() && nwires != 6) {
237 l = omap_readl(USB_TRANSCEIVER_CTRL);
238 l &= ~CONF_USB2_UNI_R;
239 omap_writel(l, USB_TRANSCEIVER_CTRL);
245 if (cpu_is_omap24xx())
246 omap2_usb_devconf_set(0, USB_BIDIR);
250 if (cpu_is_omap24xx())
251 omap2_usb_devconf_set(0, USB_BIDIR);
255 if (cpu_is_omap24xx()) {
256 omap_cfg_reg(J19_24XX_USB0_VP);
257 omap_cfg_reg(K20_24XX_USB0_VM);
258 omap2_usb_devconf_set(0, USB_UNIDIR);
262 omap_cfg_reg(AA9_USB0_VP);
263 omap_cfg_reg(R9_USB0_VM);
264 l = omap_readl(USB_TRANSCEIVER_CTRL);
265 l |= CONF_USB2_UNI_R;
266 omap_writel(l, USB_TRANSCEIVER_CTRL);
270 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
273 return syscon1 << 16;
276 static u32 __init omap_usb1_init(unsigned nwires)
280 if (cpu_class_is_omap1() && !cpu_is_omap15xx() && nwires != 6) {
283 l = omap_readl(USB_TRANSCEIVER_CTRL);
284 l &= ~CONF_USB1_UNI_R;
285 omap_writel(l, USB_TRANSCEIVER_CTRL);
287 if (cpu_is_omap24xx())
288 omap2_usb_devconf_clear(1, USB_BIDIR_TLL);
293 /* external transceiver */
294 if (cpu_class_is_omap1()) {
295 omap_cfg_reg(USB1_TXD);
296 omap_cfg_reg(USB1_TXEN);
298 omap_cfg_reg(USB1_RCV);
301 if (cpu_is_omap15xx()) {
302 omap_cfg_reg(USB1_SEO);
303 omap_cfg_reg(USB1_SPEED);
305 } else if (cpu_is_omap1610() || cpu_is_omap5912()) {
306 omap_cfg_reg(W13_1610_USB1_SE0);
307 omap_cfg_reg(R13_1610_USB1_SPEED);
309 } else if (cpu_is_omap1710()) {
310 omap_cfg_reg(R13_1710_USB1_SE0);
312 } else if (cpu_is_omap24xx()) {
313 /* NOTE: board-specific code must set up pin muxing for usb1,
314 * since each signal could come out on either of two balls.
317 pr_debug("usb%d cpu unrecognized\n", 1);
323 if (!cpu_is_omap24xx())
325 /* NOTE: board-specific code must override this setting if
326 * this TLL link is not using DP/DM
329 omap2_usb_devconf_set(1, USB_BIDIR_TLL);
333 if (cpu_is_omap24xx())
334 omap2_usb_devconf_set(1, USB_BIDIR);
338 if (cpu_is_omap24xx())
339 omap2_usb_devconf_set(1, USB_BIDIR);
342 if (cpu_is_omap24xx())
345 omap_cfg_reg(USB1_VP);
346 omap_cfg_reg(USB1_VM);
347 if (!cpu_is_omap15xx()) {
350 l = omap_readl(USB_TRANSCEIVER_CTRL);
351 l |= CONF_USB1_UNI_R;
352 omap_writel(l, USB_TRANSCEIVER_CTRL);
357 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
360 return syscon1 << 20;
363 static u32 __init omap_usb2_init(unsigned nwires, unsigned alt_pingroup)
367 if (cpu_is_omap24xx()) {
368 omap2_usb2_disable_5pinbitll();
372 /* NOTE omap1 erratum: must leave USB2_UNI_R set if usb0 in use */
373 if (alt_pingroup || nwires == 0)
376 if (cpu_class_is_omap1() && !cpu_is_omap15xx() && nwires != 6) {
379 l = omap_readl(USB_TRANSCEIVER_CTRL);
380 l &= ~CONF_USB2_UNI_R;
381 omap_writel(l, USB_TRANSCEIVER_CTRL);
384 /* external transceiver */
385 if (cpu_is_omap15xx()) {
386 omap_cfg_reg(USB2_TXD);
387 omap_cfg_reg(USB2_TXEN);
388 omap_cfg_reg(USB2_SEO);
390 omap_cfg_reg(USB2_RCV);
391 /* there is no USB2_SPEED */
392 } else if (cpu_is_omap16xx()) {
393 omap_cfg_reg(V6_USB2_TXD);
394 omap_cfg_reg(W9_USB2_TXEN);
395 omap_cfg_reg(W5_USB2_SE0);
397 omap_cfg_reg(Y5_USB2_RCV);
398 // FIXME omap_cfg_reg(USB2_SPEED);
399 } else if (cpu_is_omap24xx()) {
400 omap_cfg_reg(Y11_24XX_USB2_DAT);
401 omap_cfg_reg(AA10_24XX_USB2_SE0);
403 omap_cfg_reg(AA12_24XX_USB2_TXEN);
405 omap_cfg_reg(AA6_24XX_USB2_RCV);
407 pr_debug("usb%d cpu unrecognized\n", 1);
410 // if (cpu_class_is_omap1()) omap_cfg_reg(USB2_SUSP);
414 if (!cpu_is_omap24xx())
416 /* NOTE: board-specific code must override this setting if
417 * this TLL link is not using DP/DM
420 omap2_usb_devconf_set(2, USB_BIDIR_TLL);
424 if (cpu_is_omap24xx())
425 omap2_usb_devconf_set(2, USB_BIDIR);
429 if (cpu_is_omap24xx())
430 omap2_usb_devconf_set(2, USB_BIDIR);
433 if (!cpu_is_omap24xx())
435 omap_cfg_reg(AA4_24XX_USB2_TLLSE0);
436 /* NOTE: board-specific code must override this setting if
437 * this TLL link is not using DP/DM. Something must also
438 * set up OTG_SYSCON2.HMC_TLL{ATTACH,SPEED}
441 omap2_usb2_enable_5pinunitll();
444 if (cpu_is_omap24xx())
447 if (cpu_is_omap15xx()) {
448 omap_cfg_reg(USB2_VP);
449 omap_cfg_reg(USB2_VM);
453 omap_cfg_reg(AA9_USB2_VP);
454 omap_cfg_reg(R9_USB2_VM);
455 l = omap_readl(USB_TRANSCEIVER_CTRL);
456 l |= CONF_USB2_UNI_R;
457 omap_writel(l, USB_TRANSCEIVER_CTRL);
462 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
465 return syscon1 << 24;
470 /*-------------------------------------------------------------------------*/
472 #if defined(CONFIG_USB_GADGET_OMAP) || \
473 defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) || \
474 (defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG))
475 static void usb_release(struct device *dev)
477 /* normally not freed */
481 #ifdef CONFIG_USB_GADGET_OMAP
483 static struct resource udc_resources[] = {
484 /* order is significant! */
487 .end = UDC_BASE + 0xff,
488 .flags = IORESOURCE_MEM,
489 }, { /* general IRQ */
490 .start = INT_USB_IRQ_GEN,
491 .flags = IORESOURCE_IRQ,
493 .start = INT_USB_IRQ_NISO,
494 .flags = IORESOURCE_IRQ,
496 .start = INT_USB_IRQ_ISO,
497 .flags = IORESOURCE_IRQ,
501 static u64 udc_dmamask = ~(u32)0;
503 static struct platform_device udc_device = {
507 .release = usb_release,
508 .dma_mask = &udc_dmamask,
509 .coherent_dma_mask = 0xffffffff,
511 .num_resources = ARRAY_SIZE(udc_resources),
512 .resource = udc_resources,
517 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
519 /* The dmamask must be set for OHCI to work */
520 static u64 ohci_dmamask = ~(u32)0;
522 static struct resource ohci_resources[] = {
524 .start = OMAP_OHCI_BASE,
525 .end = OMAP_OHCI_BASE + 0xff,
526 .flags = IORESOURCE_MEM,
529 .start = INT_USB_IRQ_HGEN,
530 .flags = IORESOURCE_IRQ,
534 static struct platform_device ohci_device = {
538 .release = usb_release,
539 .dma_mask = &ohci_dmamask,
540 .coherent_dma_mask = 0xffffffff,
542 .num_resources = ARRAY_SIZE(ohci_resources),
543 .resource = ohci_resources,
548 #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
550 static struct resource otg_resources[] = {
551 /* order is significant! */
554 .end = OTG_BASE + 0xff,
555 .flags = IORESOURCE_MEM,
557 .start = INT_USB_IRQ_OTG,
558 .flags = IORESOURCE_IRQ,
562 static struct platform_device otg_device = {
566 .release = usb_release,
568 .num_resources = ARRAY_SIZE(otg_resources),
569 .resource = otg_resources,
574 /*-------------------------------------------------------------------------*/
576 // FIXME correct answer depends on hmc_mode,
577 // as does (on omap1) any nonzero value for config->otg port number
578 #ifdef CONFIG_USB_GADGET_OMAP
579 #define is_usb0_device(config) 1
581 #define is_usb0_device(config) 0
584 /*-------------------------------------------------------------------------*/
586 #ifdef CONFIG_ARCH_OMAP_OTG
589 omap_otg_init(struct omap_usb_config *config)
593 int alt_pingroup = 0;
595 /* NOTE: no bus or clock setup (yet?) */
597 syscon = omap_readl(OTG_SYSCON_1) & 0xffff;
598 if (!(syscon & OTG_RESET_DONE))
599 pr_debug("USB resets not complete?\n");
601 //omap_writew(0, OTG_IRQ_EN);
603 /* pin muxing and transceiver pinouts */
604 if (config->pins[0] > 2) /* alt pingroup 2 */
606 syscon |= omap_usb0_init(config->pins[0], is_usb0_device(config));
607 syscon |= omap_usb1_init(config->pins[1]);
608 syscon |= omap_usb2_init(config->pins[2], alt_pingroup);
609 pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
610 omap_writel(syscon, OTG_SYSCON_1);
612 syscon = config->hmc_mode;
613 syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
614 #ifdef CONFIG_USB_OTG
618 if (cpu_class_is_omap1())
619 pr_debug("USB_TRANSCEIVER_CTRL = %03x\n",
620 omap_readl(USB_TRANSCEIVER_CTRL));
621 pr_debug("OTG_SYSCON_2 = %08x\n", omap_readl(OTG_SYSCON_2));
622 omap_writel(syscon, OTG_SYSCON_2);
624 printk("USB: hmc %d", config->hmc_mode);
626 printk(", usb2 alt %d wires", config->pins[2]);
627 else if (config->pins[0])
628 printk(", usb0 %d wires%s", config->pins[0],
629 is_usb0_device(config) ? " (dev)" : "");
631 printk(", usb1 %d wires", config->pins[1]);
632 if (!alt_pingroup && config->pins[2])
633 printk(", usb2 %d wires", config->pins[2]);
635 printk(", Mini-AB on usb%d", config->otg - 1);
638 if (cpu_class_is_omap1()) {
641 /* leave USB clocks/controllers off until needed */
642 w = omap_readw(ULPD_SOFT_REQ);
643 w &= ~SOFT_USB_CLK_REQ;
644 omap_writew(w, ULPD_SOFT_REQ);
646 w = omap_readw(ULPD_CLOCK_CTRL);
648 w |= DIS_USB_PVCI_CLK;
649 omap_writew(w, ULPD_CLOCK_CTRL);
651 syscon = omap_readl(OTG_SYSCON_1);
652 syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
654 #ifdef CONFIG_USB_GADGET_OMAP
655 if (config->otg || config->register_dev) {
656 syscon &= ~DEV_IDLE_EN;
657 udc_device.dev.platform_data = config;
658 /* FIXME patch IRQ numbers for omap730 */
659 status = platform_device_register(&udc_device);
661 pr_debug("can't register UDC device, %d\n", status);
665 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
666 if (config->otg || config->register_host) {
667 syscon &= ~HST_IDLE_EN;
668 ohci_device.dev.platform_data = config;
669 if (cpu_is_omap730())
670 ohci_resources[1].start = INT_730_USB_HHC_1;
671 status = platform_device_register(&ohci_device);
673 pr_debug("can't register OHCI device, %d\n", status);
677 #ifdef CONFIG_USB_OTG
679 syscon &= ~OTG_IDLE_EN;
680 otg_device.dev.platform_data = config;
681 if (cpu_is_omap730())
682 otg_resources[1].start = INT_730_USB_OTG;
683 status = platform_device_register(&otg_device);
685 pr_debug("can't register OTG device, %d\n", status);
688 pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
689 omap_writel(syscon, OTG_SYSCON_1);
695 static inline void omap_otg_init(struct omap_usb_config *config) {}
698 /*-------------------------------------------------------------------------*/
700 #ifdef CONFIG_ARCH_OMAP15XX
703 #define DPLL_IOB (1 << 13)
704 #define DPLL_PLL_ENABLE (1 << 4)
705 #define DPLL_LOCK (1 << 0)
708 #define APLL_NDPLL_SWITCH (1 << 0)
711 static void __init omap_1510_usb_init(struct omap_usb_config *config)
716 omap_usb0_init(config->pins[0], is_usb0_device(config));
717 omap_usb1_init(config->pins[1]);
718 omap_usb2_init(config->pins[2], 0);
720 val = omap_readl(MOD_CONF_CTRL_0) & ~(0x3f << 1);
721 val |= (config->hmc_mode << 1);
722 omap_writel(val, MOD_CONF_CTRL_0);
724 printk("USB: hmc %d", config->hmc_mode);
726 printk(", usb0 %d wires%s", config->pins[0],
727 is_usb0_device(config) ? " (dev)" : "");
729 printk(", usb1 %d wires", config->pins[1]);
731 printk(", usb2 %d wires", config->pins[2]);
734 /* use DPLL for 48 MHz function clock */
735 pr_debug("APLL %04x DPLL %04x REQ %04x\n", omap_readw(ULPD_APLL_CTRL),
736 omap_readw(ULPD_DPLL_CTRL), omap_readw(ULPD_SOFT_REQ));
738 w = omap_readw(ULPD_APLL_CTRL);
739 w &= ~APLL_NDPLL_SWITCH;
740 omap_writew(w, ULPD_APLL_CTRL);
742 w = omap_readw(ULPD_DPLL_CTRL);
743 w |= DPLL_IOB | DPLL_PLL_ENABLE;
744 omap_writew(w, ULPD_DPLL_CTRL);
746 w = omap_readw(ULPD_SOFT_REQ);
747 w |= SOFT_UDC_REQ | SOFT_DPLL_REQ;
748 omap_writew(w, ULPD_SOFT_REQ);
750 while (!(omap_readw(ULPD_DPLL_CTRL) & DPLL_LOCK))
753 #ifdef CONFIG_USB_GADGET_OMAP
754 if (config->register_dev) {
757 udc_device.dev.platform_data = config;
758 status = platform_device_register(&udc_device);
760 pr_debug("can't register UDC device, %d\n", status);
761 /* udc driver gates 48MHz by D+ pullup */
765 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
766 if (config->register_host) {
769 ohci_device.dev.platform_data = config;
770 status = platform_device_register(&ohci_device);
772 pr_debug("can't register OHCI device, %d\n", status);
773 /* hcd explicitly gates 48MHz */
779 static inline void omap_1510_usb_init(struct omap_usb_config *config) {}
782 /*-------------------------------------------------------------------------*/
784 static struct omap_usb_config platform_data;
789 const struct omap_usb_config *config;
791 config = omap_get_config(OMAP_TAG_USB, struct omap_usb_config);
792 if (config == NULL) {
793 printk(KERN_ERR "USB: No board-specific "
794 "platform config found\n");
797 platform_data = *config;
799 if (cpu_is_omap730() || cpu_is_omap16xx() || cpu_is_omap24xx())
800 omap_otg_init(&platform_data);
801 else if (cpu_is_omap15xx())
802 omap_1510_usb_init(&platform_data);
804 printk(KERN_ERR "USB: No init for your chip yet\n");
810 subsys_initcall(omap_usb_init);