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/control.h>
37 #include <asm/arch/mux.h>
38 #include <asm/arch/usb.h>
39 #include <asm/arch/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 int otg_set_transceiver(struct otg_transceiver *x)
106 EXPORT_SYMBOL(otg_set_transceiver);
110 /*-------------------------------------------------------------------------*/
112 #if defined(CONFIG_ARCH_OMAP_OTG) || defined(CONFIG_ARCH_OMAP15XX)
114 static void omap2_usb_devconf_clear(u8 port, u32 mask)
118 r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
119 r &= ~USBTXWRMODEI(port, mask);
120 omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
123 static void omap2_usb_devconf_set(u8 port, u32 mask)
127 r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
128 r |= USBTXWRMODEI(port, mask);
129 omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
132 static void omap2_usb2_disable_5pinbitll(void)
136 r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
137 r &= ~(USBTXWRMODEI(2, USB_BIDIR_TLL) | USBT2TLL5PI);
138 omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
141 static void omap2_usb2_enable_5pinunitll(void)
145 r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
146 r |= USBTXWRMODEI(2, USB_UNIDIR_TLL) | USBT2TLL5PI;
147 omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
150 static u32 __init omap_usb0_init(unsigned nwires, unsigned is_device)
154 if (cpu_is_omap24xx())
155 omap2_usb_devconf_clear(0, USB_BIDIR_TLL);
158 if (cpu_class_is_omap1() && !cpu_is_omap15xx()) {
162 l = omap_readl(USB_TRANSCEIVER_CTRL);
164 omap_writel(l, USB_TRANSCEIVER_CTRL);
170 if (cpu_is_omap24xx())
171 omap_cfg_reg(J20_24XX_USB0_PUEN);
173 omap_cfg_reg(W4_USB_PUEN);
176 /* internal transceiver (unavailable on 17xx, 24xx) */
177 if (!cpu_class_is_omap2() && nwires == 2) {
180 // omap_cfg_reg(P9_USB_DP);
181 // omap_cfg_reg(R8_USB_DM);
183 if (cpu_is_omap15xx()) {
184 /* This works on 1510-Innovator */
189 * - peripheral should configure VBUS detection!
190 * - only peripherals may use the internal D+/D- pulldowns
191 * - OTG support on this port not yet written
194 l = omap_readl(USB_TRANSCEIVER_CTRL);
199 omap_writel(l, USB_TRANSCEIVER_CTRL);
204 /* alternate pin config, external transceiver */
205 if (cpu_is_omap15xx()) {
206 printk(KERN_ERR "no usb0 alt pin config on 15xx\n");
210 if (cpu_is_omap24xx()) {
211 omap_cfg_reg(K18_24XX_USB0_DAT);
212 omap_cfg_reg(K19_24XX_USB0_TXEN);
213 omap_cfg_reg(J14_24XX_USB0_SE0);
215 omap_cfg_reg(J18_24XX_USB0_RCV);
217 omap_cfg_reg(V6_USB0_TXD);
218 omap_cfg_reg(W9_USB0_TXEN);
219 omap_cfg_reg(W5_USB0_SE0);
221 omap_cfg_reg(Y5_USB0_RCV);
224 /* NOTE: SPEED and SUSP aren't configured here. OTG hosts
225 * may be able to use I2C requests to set those bits along
226 * with VBUS switching and overcurrent detection.
229 if (cpu_class_is_omap1() && nwires != 6) {
232 l = omap_readl(USB_TRANSCEIVER_CTRL);
233 l &= ~CONF_USB2_UNI_R;
234 omap_writel(l, USB_TRANSCEIVER_CTRL);
240 if (cpu_is_omap24xx())
241 omap2_usb_devconf_set(0, USB_BIDIR);
245 if (cpu_is_omap24xx())
246 omap2_usb_devconf_set(0, USB_BIDIR);
250 if (cpu_is_omap24xx()) {
251 omap_cfg_reg(J19_24XX_USB0_VP);
252 omap_cfg_reg(K20_24XX_USB0_VM);
253 omap2_usb_devconf_set(0, USB_UNIDIR);
257 omap_cfg_reg(AA9_USB0_VP);
258 omap_cfg_reg(R9_USB0_VM);
259 l = omap_readl(USB_TRANSCEIVER_CTRL);
260 l |= CONF_USB2_UNI_R;
261 omap_writel(l, USB_TRANSCEIVER_CTRL);
265 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
268 return syscon1 << 16;
271 static u32 __init omap_usb1_init(unsigned nwires)
275 if (cpu_class_is_omap1() && !cpu_is_omap15xx() && nwires != 6) {
278 l = omap_readl(USB_TRANSCEIVER_CTRL);
279 l &= ~CONF_USB1_UNI_R;
280 omap_writel(l, USB_TRANSCEIVER_CTRL);
282 if (cpu_is_omap24xx())
283 omap2_usb_devconf_clear(1, USB_BIDIR_TLL);
288 /* external transceiver */
289 if (cpu_class_is_omap1()) {
290 omap_cfg_reg(USB1_TXD);
291 omap_cfg_reg(USB1_TXEN);
293 omap_cfg_reg(USB1_RCV);
296 if (cpu_is_omap15xx()) {
297 omap_cfg_reg(USB1_SEO);
298 omap_cfg_reg(USB1_SPEED);
300 } else if (cpu_is_omap1610() || cpu_is_omap5912()) {
301 omap_cfg_reg(W13_1610_USB1_SE0);
302 omap_cfg_reg(R13_1610_USB1_SPEED);
304 } else if (cpu_is_omap1710()) {
305 omap_cfg_reg(R13_1710_USB1_SE0);
307 } else if (cpu_is_omap24xx()) {
308 /* NOTE: board-specific code must set up pin muxing for usb1,
309 * since each signal could come out on either of two balls.
312 pr_debug("usb%d cpu unrecognized\n", 1);
318 if (!cpu_is_omap24xx())
320 /* NOTE: board-specific code must override this setting if
321 * this TLL link is not using DP/DM
324 omap2_usb_devconf_set(1, USB_BIDIR_TLL);
328 if (cpu_is_omap24xx())
329 omap2_usb_devconf_set(1, USB_BIDIR);
333 if (cpu_is_omap24xx())
334 omap2_usb_devconf_set(1, USB_BIDIR);
337 if (cpu_is_omap24xx())
340 omap_cfg_reg(USB1_VP);
341 omap_cfg_reg(USB1_VM);
342 if (!cpu_is_omap15xx()) {
345 l = omap_readl(USB_TRANSCEIVER_CTRL);
346 l |= CONF_USB1_UNI_R;
347 omap_writel(l, USB_TRANSCEIVER_CTRL);
352 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
355 return syscon1 << 20;
358 static u32 __init omap_usb2_init(unsigned nwires, unsigned alt_pingroup)
362 if (cpu_is_omap24xx()) {
363 omap2_usb2_disable_5pinbitll();
367 /* NOTE omap1 erratum: must leave USB2_UNI_R set if usb0 in use */
368 if (alt_pingroup || nwires == 0)
371 if (cpu_class_is_omap1() && !cpu_is_omap15xx() && nwires != 6) {
374 l = omap_readl(USB_TRANSCEIVER_CTRL);
375 l &= ~CONF_USB2_UNI_R;
376 omap_writel(l, USB_TRANSCEIVER_CTRL);
379 /* external transceiver */
380 if (cpu_is_omap15xx()) {
381 omap_cfg_reg(USB2_TXD);
382 omap_cfg_reg(USB2_TXEN);
383 omap_cfg_reg(USB2_SEO);
385 omap_cfg_reg(USB2_RCV);
386 /* there is no USB2_SPEED */
387 } else if (cpu_is_omap16xx()) {
388 omap_cfg_reg(V6_USB2_TXD);
389 omap_cfg_reg(W9_USB2_TXEN);
390 omap_cfg_reg(W5_USB2_SE0);
392 omap_cfg_reg(Y5_USB2_RCV);
393 // FIXME omap_cfg_reg(USB2_SPEED);
394 } else if (cpu_is_omap24xx()) {
395 omap_cfg_reg(Y11_24XX_USB2_DAT);
396 omap_cfg_reg(AA10_24XX_USB2_SE0);
398 omap_cfg_reg(AA12_24XX_USB2_TXEN);
400 omap_cfg_reg(AA6_24XX_USB2_RCV);
402 pr_debug("usb%d cpu unrecognized\n", 1);
405 // if (cpu_class_is_omap1()) omap_cfg_reg(USB2_SUSP);
409 if (!cpu_is_omap24xx())
411 /* NOTE: board-specific code must override this setting if
412 * this TLL link is not using DP/DM
415 omap2_usb_devconf_set(2, USB_BIDIR_TLL);
419 if (cpu_is_omap24xx())
420 omap2_usb_devconf_set(2, USB_BIDIR);
424 if (cpu_is_omap24xx())
425 omap2_usb_devconf_set(2, USB_BIDIR);
428 if (!cpu_is_omap24xx())
430 omap_cfg_reg(AA4_24XX_USB2_TLLSE0);
431 /* NOTE: board-specific code must override this setting if
432 * this TLL link is not using DP/DM. Something must also
433 * set up OTG_SYSCON2.HMC_TLL{ATTACH,SPEED}
436 omap2_usb2_enable_5pinunitll();
439 if (cpu_is_omap24xx())
442 if (cpu_is_omap15xx()) {
443 omap_cfg_reg(USB2_VP);
444 omap_cfg_reg(USB2_VM);
448 omap_cfg_reg(AA9_USB2_VP);
449 omap_cfg_reg(R9_USB2_VM);
450 l = omap_readl(USB_TRANSCEIVER_CTRL);
451 l |= CONF_USB2_UNI_R;
452 omap_writel(l, USB_TRANSCEIVER_CTRL);
457 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
460 return syscon1 << 24;
465 /*-------------------------------------------------------------------------*/
467 #if defined(CONFIG_USB_GADGET_OMAP) || \
468 defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) || \
469 (defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG))
470 static void usb_release(struct device *dev)
472 /* normally not freed */
476 #ifdef CONFIG_USB_GADGET_OMAP
478 static struct resource udc_resources[] = {
479 /* order is significant! */
482 .end = UDC_BASE + 0xff,
483 .flags = IORESOURCE_MEM,
484 }, { /* general IRQ */
485 .start = INT_USB_IRQ_GEN,
486 .flags = IORESOURCE_IRQ,
488 .start = INT_USB_IRQ_NISO,
489 .flags = IORESOURCE_IRQ,
491 .start = INT_USB_IRQ_ISO,
492 .flags = IORESOURCE_IRQ,
496 static u64 udc_dmamask = ~(u32)0;
498 static struct platform_device udc_device = {
502 .release = usb_release,
503 .dma_mask = &udc_dmamask,
504 .coherent_dma_mask = 0xffffffff,
506 .num_resources = ARRAY_SIZE(udc_resources),
507 .resource = udc_resources,
512 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
514 /* The dmamask must be set for OHCI to work */
515 static u64 ohci_dmamask = ~(u32)0;
517 static struct resource ohci_resources[] = {
519 .start = OMAP_OHCI_BASE,
520 .end = OMAP_OHCI_BASE + 0xff,
521 .flags = IORESOURCE_MEM,
524 .start = INT_USB_IRQ_HGEN,
525 .flags = IORESOURCE_IRQ,
529 static struct platform_device ohci_device = {
533 .release = usb_release,
534 .dma_mask = &ohci_dmamask,
535 .coherent_dma_mask = 0xffffffff,
537 .num_resources = ARRAY_SIZE(ohci_resources),
538 .resource = ohci_resources,
543 #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
545 static struct resource otg_resources[] = {
546 /* order is significant! */
549 .end = OTG_BASE + 0xff,
550 .flags = IORESOURCE_MEM,
552 .start = INT_USB_IRQ_OTG,
553 .flags = IORESOURCE_IRQ,
557 static struct platform_device otg_device = {
561 .release = usb_release,
563 .num_resources = ARRAY_SIZE(otg_resources),
564 .resource = otg_resources,
569 /*-------------------------------------------------------------------------*/
571 // FIXME correct answer depends on hmc_mode,
572 // as does (on omap1) any nonzero value for config->otg port number
573 #ifdef CONFIG_USB_GADGET_OMAP
574 #define is_usb0_device(config) 1
576 #define is_usb0_device(config) 0
579 /*-------------------------------------------------------------------------*/
581 #ifdef CONFIG_ARCH_OMAP_OTG
584 omap_otg_init(struct omap_usb_config *config)
588 int alt_pingroup = 0;
590 /* NOTE: no bus or clock setup (yet?) */
592 syscon = omap_readl(OTG_SYSCON_1) & 0xffff;
593 if (!(syscon & OTG_RESET_DONE))
594 pr_debug("USB resets not complete?\n");
596 //omap_writew(0, OTG_IRQ_EN);
598 /* pin muxing and transceiver pinouts */
599 if (config->pins[0] > 2) /* alt pingroup 2 */
601 syscon |= omap_usb0_init(config->pins[0], is_usb0_device(config));
602 syscon |= omap_usb1_init(config->pins[1]);
603 syscon |= omap_usb2_init(config->pins[2], alt_pingroup);
604 pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
605 omap_writel(syscon, OTG_SYSCON_1);
607 syscon = config->hmc_mode;
608 syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
609 #ifdef CONFIG_USB_OTG
613 if (cpu_class_is_omap1())
614 pr_debug("USB_TRANSCEIVER_CTRL = %03x\n",
615 omap_readl(USB_TRANSCEIVER_CTRL));
616 pr_debug("OTG_SYSCON_2 = %08x\n", omap_readl(OTG_SYSCON_2));
617 omap_writel(syscon, OTG_SYSCON_2);
619 printk("USB: hmc %d", config->hmc_mode);
621 printk(", usb2 alt %d wires", config->pins[2]);
622 else if (config->pins[0])
623 printk(", usb0 %d wires%s", config->pins[0],
624 is_usb0_device(config) ? " (dev)" : "");
626 printk(", usb1 %d wires", config->pins[1]);
627 if (!alt_pingroup && config->pins[2])
628 printk(", usb2 %d wires", config->pins[2]);
630 printk(", Mini-AB on usb%d", config->otg - 1);
633 if (cpu_class_is_omap1()) {
636 /* leave USB clocks/controllers off until needed */
637 w = omap_readw(ULPD_SOFT_REQ);
638 w &= ~SOFT_USB_CLK_REQ;
639 omap_writew(w, ULPD_SOFT_REQ);
641 w = omap_readw(ULPD_CLOCK_CTRL);
643 w |= DIS_USB_PVCI_CLK;
644 omap_writew(w, ULPD_CLOCK_CTRL);
646 syscon = omap_readl(OTG_SYSCON_1);
647 syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
649 #ifdef CONFIG_USB_GADGET_OMAP
650 if (config->otg || config->register_dev) {
651 syscon &= ~DEV_IDLE_EN;
652 udc_device.dev.platform_data = config;
653 /* FIXME patch IRQ numbers for omap730 */
654 status = platform_device_register(&udc_device);
656 pr_debug("can't register UDC device, %d\n", status);
660 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
661 if (config->otg || config->register_host) {
662 syscon &= ~HST_IDLE_EN;
663 ohci_device.dev.platform_data = config;
664 if (cpu_is_omap730())
665 ohci_resources[1].start = INT_730_USB_HHC_1;
666 status = platform_device_register(&ohci_device);
668 pr_debug("can't register OHCI device, %d\n", status);
672 #ifdef CONFIG_USB_OTG
674 syscon &= ~OTG_IDLE_EN;
675 otg_device.dev.platform_data = config;
676 if (cpu_is_omap730())
677 otg_resources[1].start = INT_730_USB_OTG;
678 status = platform_device_register(&otg_device);
680 pr_debug("can't register OTG device, %d\n", status);
683 pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
684 omap_writel(syscon, OTG_SYSCON_1);
690 static inline void omap_otg_init(struct omap_usb_config *config) {}
693 /*-------------------------------------------------------------------------*/
695 #ifdef CONFIG_ARCH_OMAP15XX
698 #define DPLL_IOB (1 << 13)
699 #define DPLL_PLL_ENABLE (1 << 4)
700 #define DPLL_LOCK (1 << 0)
703 #define APLL_NDPLL_SWITCH (1 << 0)
706 static void __init omap_1510_usb_init(struct omap_usb_config *config)
711 omap_usb0_init(config->pins[0], is_usb0_device(config));
712 omap_usb1_init(config->pins[1]);
713 omap_usb2_init(config->pins[2], 0);
715 val = omap_readl(MOD_CONF_CTRL_0) & ~(0x3f << 1);
716 val |= (config->hmc_mode << 1);
717 omap_writel(val, MOD_CONF_CTRL_0);
719 printk("USB: hmc %d", config->hmc_mode);
721 printk(", usb0 %d wires%s", config->pins[0],
722 is_usb0_device(config) ? " (dev)" : "");
724 printk(", usb1 %d wires", config->pins[1]);
726 printk(", usb2 %d wires", config->pins[2]);
729 /* use DPLL for 48 MHz function clock */
730 pr_debug("APLL %04x DPLL %04x REQ %04x\n", omap_readw(ULPD_APLL_CTRL),
731 omap_readw(ULPD_DPLL_CTRL), omap_readw(ULPD_SOFT_REQ));
733 w = omap_readw(ULPD_APLL_CTRL);
734 w &= ~APLL_NDPLL_SWITCH;
735 omap_writew(w, ULPD_APLL_CTRL);
737 w = omap_readw(ULPD_DPLL_CTRL);
738 w |= DPLL_IOB | DPLL_PLL_ENABLE;
739 omap_writew(w, ULPD_DPLL_CTRL);
741 w = omap_readw(ULPD_SOFT_REQ);
742 w |= SOFT_UDC_REQ | SOFT_DPLL_REQ;
743 omap_writew(w, ULPD_SOFT_REQ);
745 while (!(omap_readw(ULPD_DPLL_CTRL) & DPLL_LOCK))
748 #ifdef CONFIG_USB_GADGET_OMAP
749 if (config->register_dev) {
752 udc_device.dev.platform_data = config;
753 status = platform_device_register(&udc_device);
755 pr_debug("can't register UDC device, %d\n", status);
756 /* udc driver gates 48MHz by D+ pullup */
760 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
761 if (config->register_host) {
764 ohci_device.dev.platform_data = config;
765 status = platform_device_register(&ohci_device);
767 pr_debug("can't register OHCI device, %d\n", status);
768 /* hcd explicitly gates 48MHz */
774 static inline void omap_1510_usb_init(struct omap_usb_config *config) {}
777 /*-------------------------------------------------------------------------*/
779 static struct omap_usb_config platform_data;
784 const struct omap_usb_config *config;
786 config = omap_get_config(OMAP_TAG_USB, struct omap_usb_config);
787 if (config == NULL) {
788 printk(KERN_ERR "USB: No board-specific "
789 "platform config found\n");
792 platform_data = *config;
794 if (cpu_is_omap730() || cpu_is_omap16xx() || cpu_is_omap24xx())
795 omap_otg_init(&platform_data);
796 else if (cpu_is_omap15xx())
797 omap_1510_usb_init(&platform_data);
799 printk(KERN_ERR "USB: No init for your chip yet\n");
805 subsys_initcall(omap_usb_init);