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);
198 omap_writel(l, USB_TRANSCEIVER_CTRL);
203 /* alternate pin config, external transceiver */
204 if (cpu_is_omap15xx()) {
205 printk(KERN_ERR "no usb0 alt pin config on 15xx\n");
209 if (cpu_is_omap24xx()) {
210 omap_cfg_reg(K18_24XX_USB0_DAT);
211 omap_cfg_reg(K19_24XX_USB0_TXEN);
212 omap_cfg_reg(J14_24XX_USB0_SE0);
214 omap_cfg_reg(J18_24XX_USB0_RCV);
216 omap_cfg_reg(V6_USB0_TXD);
217 omap_cfg_reg(W9_USB0_TXEN);
218 omap_cfg_reg(W5_USB0_SE0);
220 omap_cfg_reg(Y5_USB0_RCV);
223 /* NOTE: SPEED and SUSP aren't configured here. OTG hosts
224 * may be able to use I2C requests to set those bits along
225 * with VBUS switching and overcurrent detection.
228 if (cpu_class_is_omap1() && nwires != 6) {
231 l = omap_readl(USB_TRANSCEIVER_CTRL);
232 l &= ~CONF_USB2_UNI_R;
233 omap_writel(l, USB_TRANSCEIVER_CTRL);
239 if (cpu_is_omap24xx())
240 omap2_usb_devconf_set(0, USB_BIDIR);
244 if (cpu_is_omap24xx())
245 omap2_usb_devconf_set(0, USB_BIDIR);
249 if (cpu_is_omap24xx()) {
250 omap_cfg_reg(J19_24XX_USB0_VP);
251 omap_cfg_reg(K20_24XX_USB0_VM);
252 omap2_usb_devconf_set(0, USB_UNIDIR);
256 omap_cfg_reg(AA9_USB0_VP);
257 omap_cfg_reg(R9_USB0_VM);
258 l = omap_readl(USB_TRANSCEIVER_CTRL);
259 l |= CONF_USB2_UNI_R;
260 omap_writel(l, USB_TRANSCEIVER_CTRL);
264 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
267 return syscon1 << 16;
270 static u32 __init omap_usb1_init(unsigned nwires)
274 if (cpu_class_is_omap1() && !cpu_is_omap15xx() && nwires != 6) {
277 l = omap_readl(USB_TRANSCEIVER_CTRL);
278 l &= ~CONF_USB1_UNI_R;
279 omap_writel(l, USB_TRANSCEIVER_CTRL);
281 if (cpu_is_omap24xx())
282 omap2_usb_devconf_clear(1, USB_BIDIR_TLL);
287 /* external transceiver */
288 if (cpu_class_is_omap1()) {
289 omap_cfg_reg(USB1_TXD);
290 omap_cfg_reg(USB1_TXEN);
292 omap_cfg_reg(USB1_RCV);
295 if (cpu_is_omap15xx()) {
296 omap_cfg_reg(USB1_SEO);
297 omap_cfg_reg(USB1_SPEED);
299 } else if (cpu_is_omap1610() || cpu_is_omap5912()) {
300 omap_cfg_reg(W13_1610_USB1_SE0);
301 omap_cfg_reg(R13_1610_USB1_SPEED);
303 } else if (cpu_is_omap1710()) {
304 omap_cfg_reg(R13_1710_USB1_SE0);
306 } else if (cpu_is_omap24xx()) {
307 /* NOTE: board-specific code must set up pin muxing for usb1,
308 * since each signal could come out on either of two balls.
311 pr_debug("usb%d cpu unrecognized\n", 1);
317 if (!cpu_is_omap24xx())
319 /* NOTE: board-specific code must override this setting if
320 * this TLL link is not using DP/DM
323 omap2_usb_devconf_set(1, USB_BIDIR_TLL);
327 if (cpu_is_omap24xx())
328 omap2_usb_devconf_set(1, USB_BIDIR);
332 if (cpu_is_omap24xx())
333 omap2_usb_devconf_set(1, USB_BIDIR);
336 if (cpu_is_omap24xx())
339 omap_cfg_reg(USB1_VP);
340 omap_cfg_reg(USB1_VM);
341 if (!cpu_is_omap15xx()) {
344 l = omap_readl(USB_TRANSCEIVER_CTRL);
345 l |= CONF_USB1_UNI_R;
346 omap_writel(l, USB_TRANSCEIVER_CTRL);
351 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
354 return syscon1 << 20;
357 static u32 __init omap_usb2_init(unsigned nwires, unsigned alt_pingroup)
361 if (cpu_is_omap24xx()) {
362 omap2_usb2_disable_5pinbitll();
366 /* NOTE omap1 erratum: must leave USB2_UNI_R set if usb0 in use */
367 if (alt_pingroup || nwires == 0)
370 if (cpu_class_is_omap1() && !cpu_is_omap15xx() && nwires != 6) {
373 l = omap_readl(USB_TRANSCEIVER_CTRL);
374 l &= ~CONF_USB2_UNI_R;
375 omap_writel(l, USB_TRANSCEIVER_CTRL);
378 /* external transceiver */
379 if (cpu_is_omap15xx()) {
380 omap_cfg_reg(USB2_TXD);
381 omap_cfg_reg(USB2_TXEN);
382 omap_cfg_reg(USB2_SEO);
384 omap_cfg_reg(USB2_RCV);
385 /* there is no USB2_SPEED */
386 } else if (cpu_is_omap16xx()) {
387 omap_cfg_reg(V6_USB2_TXD);
388 omap_cfg_reg(W9_USB2_TXEN);
389 omap_cfg_reg(W5_USB2_SE0);
391 omap_cfg_reg(Y5_USB2_RCV);
392 // FIXME omap_cfg_reg(USB2_SPEED);
393 } else if (cpu_is_omap24xx()) {
394 omap_cfg_reg(Y11_24XX_USB2_DAT);
395 omap_cfg_reg(AA10_24XX_USB2_SE0);
397 omap_cfg_reg(AA12_24XX_USB2_TXEN);
399 omap_cfg_reg(AA6_24XX_USB2_RCV);
401 pr_debug("usb%d cpu unrecognized\n", 1);
404 // if (cpu_class_is_omap1()) omap_cfg_reg(USB2_SUSP);
408 if (!cpu_is_omap24xx())
410 /* NOTE: board-specific code must override this setting if
411 * this TLL link is not using DP/DM
414 omap2_usb_devconf_set(2, USB_BIDIR_TLL);
418 if (cpu_is_omap24xx())
419 omap2_usb_devconf_set(2, USB_BIDIR);
423 if (cpu_is_omap24xx())
424 omap2_usb_devconf_set(2, USB_BIDIR);
427 if (!cpu_is_omap24xx())
429 omap_cfg_reg(AA4_24XX_USB2_TLLSE0);
430 /* NOTE: board-specific code must override this setting if
431 * this TLL link is not using DP/DM. Something must also
432 * set up OTG_SYSCON2.HMC_TLL{ATTACH,SPEED}
435 omap2_usb2_enable_5pinunitll();
438 if (cpu_is_omap24xx())
441 if (cpu_is_omap15xx()) {
442 omap_cfg_reg(USB2_VP);
443 omap_cfg_reg(USB2_VM);
447 omap_cfg_reg(AA9_USB2_VP);
448 omap_cfg_reg(R9_USB2_VM);
449 l = omap_readl(USB_TRANSCEIVER_CTRL);
450 l |= CONF_USB2_UNI_R;
451 omap_writel(l, USB_TRANSCEIVER_CTRL);
456 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
459 return syscon1 << 24;
464 /*-------------------------------------------------------------------------*/
466 #if defined(CONFIG_USB_GADGET_OMAP) || \
467 defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) || \
468 (defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG))
469 static void usb_release(struct device *dev)
471 /* normally not freed */
475 #ifdef CONFIG_USB_GADGET_OMAP
477 static struct resource udc_resources[] = {
478 /* order is significant! */
481 .end = UDC_BASE + 0xff,
482 .flags = IORESOURCE_MEM,
483 }, { /* general IRQ */
484 .start = INT_USB_IRQ_GEN,
485 .flags = IORESOURCE_IRQ,
487 .start = INT_USB_IRQ_NISO,
488 .flags = IORESOURCE_IRQ,
490 .start = INT_USB_IRQ_ISO,
491 .flags = IORESOURCE_IRQ,
495 static u64 udc_dmamask = ~(u32)0;
497 static struct platform_device udc_device = {
501 .release = usb_release,
502 .dma_mask = &udc_dmamask,
503 .coherent_dma_mask = 0xffffffff,
505 .num_resources = ARRAY_SIZE(udc_resources),
506 .resource = udc_resources,
511 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
513 /* The dmamask must be set for OHCI to work */
514 static u64 ohci_dmamask = ~(u32)0;
516 static struct resource ohci_resources[] = {
518 .start = OMAP_OHCI_BASE,
519 .end = OMAP_OHCI_BASE + 0xff,
520 .flags = IORESOURCE_MEM,
523 .start = INT_USB_IRQ_HGEN,
524 .flags = IORESOURCE_IRQ,
528 static struct platform_device ohci_device = {
532 .release = usb_release,
533 .dma_mask = &ohci_dmamask,
534 .coherent_dma_mask = 0xffffffff,
536 .num_resources = ARRAY_SIZE(ohci_resources),
537 .resource = ohci_resources,
542 #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
544 static struct resource otg_resources[] = {
545 /* order is significant! */
548 .end = OTG_BASE + 0xff,
549 .flags = IORESOURCE_MEM,
551 .start = INT_USB_IRQ_OTG,
552 .flags = IORESOURCE_IRQ,
556 static struct platform_device otg_device = {
560 .release = usb_release,
562 .num_resources = ARRAY_SIZE(otg_resources),
563 .resource = otg_resources,
568 /*-------------------------------------------------------------------------*/
570 // FIXME correct answer depends on hmc_mode,
571 // as does (on omap1) any nonzero value for config->otg port number
572 #ifdef CONFIG_USB_GADGET_OMAP
573 #define is_usb0_device(config) 1
575 #define is_usb0_device(config) 0
578 /*-------------------------------------------------------------------------*/
580 #ifdef CONFIG_ARCH_OMAP_OTG
583 omap_otg_init(struct omap_usb_config *config)
587 int alt_pingroup = 0;
589 /* NOTE: no bus or clock setup (yet?) */
591 syscon = omap_readl(OTG_SYSCON_1) & 0xffff;
592 if (!(syscon & OTG_RESET_DONE))
593 pr_debug("USB resets not complete?\n");
595 //omap_writew(0, OTG_IRQ_EN);
597 /* pin muxing and transceiver pinouts */
598 if (config->pins[0] > 2) /* alt pingroup 2 */
600 syscon |= omap_usb0_init(config->pins[0], is_usb0_device(config));
601 syscon |= omap_usb1_init(config->pins[1]);
602 syscon |= omap_usb2_init(config->pins[2], alt_pingroup);
603 pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
604 omap_writel(syscon, OTG_SYSCON_1);
606 syscon = config->hmc_mode;
607 syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
608 #ifdef CONFIG_USB_OTG
612 if (cpu_class_is_omap1())
613 pr_debug("USB_TRANSCEIVER_CTRL = %03x\n",
614 omap_readl(USB_TRANSCEIVER_CTRL));
615 pr_debug("OTG_SYSCON_2 = %08x\n", omap_readl(OTG_SYSCON_2));
616 omap_writel(syscon, OTG_SYSCON_2);
618 printk("USB: hmc %d", config->hmc_mode);
620 printk(", usb2 alt %d wires", config->pins[2]);
621 else if (config->pins[0])
622 printk(", usb0 %d wires%s", config->pins[0],
623 is_usb0_device(config) ? " (dev)" : "");
625 printk(", usb1 %d wires", config->pins[1]);
626 if (!alt_pingroup && config->pins[2])
627 printk(", usb2 %d wires", config->pins[2]);
629 printk(", Mini-AB on usb%d", config->otg - 1);
632 if (cpu_class_is_omap1()) {
635 /* leave USB clocks/controllers off until needed */
636 w = omap_readw(ULPD_SOFT_REQ);
637 w &= ~SOFT_USB_CLK_REQ;
638 omap_writew(w, ULPD_SOFT_REQ);
640 w = omap_readw(ULPD_CLOCK_CTRL);
642 w |= DIS_USB_PVCI_CLK;
643 omap_writew(w, ULPD_CLOCK_CTRL);
645 syscon = omap_readl(OTG_SYSCON_1);
646 syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
648 #ifdef CONFIG_USB_GADGET_OMAP
649 if (config->otg || config->register_dev) {
650 syscon &= ~DEV_IDLE_EN;
651 udc_device.dev.platform_data = config;
652 /* FIXME patch IRQ numbers for omap730 */
653 status = platform_device_register(&udc_device);
655 pr_debug("can't register UDC device, %d\n", status);
659 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
660 if (config->otg || config->register_host) {
661 syscon &= ~HST_IDLE_EN;
662 ohci_device.dev.platform_data = config;
663 if (cpu_is_omap730())
664 ohci_resources[1].start = INT_730_USB_HHC_1;
665 status = platform_device_register(&ohci_device);
667 pr_debug("can't register OHCI device, %d\n", status);
671 #ifdef CONFIG_USB_OTG
673 syscon &= ~OTG_IDLE_EN;
674 otg_device.dev.platform_data = config;
675 if (cpu_is_omap730())
676 otg_resources[1].start = INT_730_USB_OTG;
677 status = platform_device_register(&otg_device);
679 pr_debug("can't register OTG device, %d\n", status);
682 pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
683 omap_writel(syscon, OTG_SYSCON_1);
689 static inline void omap_otg_init(struct omap_usb_config *config) {}
692 /*-------------------------------------------------------------------------*/
694 #ifdef CONFIG_ARCH_OMAP15XX
697 #define DPLL_IOB (1 << 13)
698 #define DPLL_PLL_ENABLE (1 << 4)
699 #define DPLL_LOCK (1 << 0)
702 #define APLL_NDPLL_SWITCH (1 << 0)
705 static void __init omap_1510_usb_init(struct omap_usb_config *config)
710 omap_usb0_init(config->pins[0], is_usb0_device(config));
711 omap_usb1_init(config->pins[1]);
712 omap_usb2_init(config->pins[2], 0);
714 val = omap_readl(MOD_CONF_CTRL_0) & ~(0x3f << 1);
715 val |= (config->hmc_mode << 1);
716 omap_writel(val, MOD_CONF_CTRL_0);
718 printk("USB: hmc %d", config->hmc_mode);
720 printk(", usb0 %d wires%s", config->pins[0],
721 is_usb0_device(config) ? " (dev)" : "");
723 printk(", usb1 %d wires", config->pins[1]);
725 printk(", usb2 %d wires", config->pins[2]);
728 /* use DPLL for 48 MHz function clock */
729 pr_debug("APLL %04x DPLL %04x REQ %04x\n", omap_readw(ULPD_APLL_CTRL),
730 omap_readw(ULPD_DPLL_CTRL), omap_readw(ULPD_SOFT_REQ));
732 w = omap_readw(ULPD_APLL_CTRL);
733 w &= ~APLL_NDPLL_SWITCH;
734 omap_writew(w, ULPD_APLL_CTRL);
736 w = omap_readw(ULPD_DPLL_CTRL);
737 w |= DPLL_IOB | DPLL_PLL_ENABLE;
738 omap_writew(w, ULPD_DPLL_CTRL);
740 w = omap_readw(ULPD_SOFT_REQ);
741 w |= SOFT_UDC_REQ | SOFT_DPLL_REQ;
742 omap_writew(w, ULPD_SOFT_REQ);
744 while (!(omap_readw(ULPD_DPLL_CTRL) & DPLL_LOCK))
747 #ifdef CONFIG_USB_GADGET_OMAP
748 if (config->register_dev) {
751 udc_device.dev.platform_data = config;
752 status = platform_device_register(&udc_device);
754 pr_debug("can't register UDC device, %d\n", status);
755 /* udc driver gates 48MHz by D+ pullup */
759 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
760 if (config->register_host) {
763 ohci_device.dev.platform_data = config;
764 status = platform_device_register(&ohci_device);
766 pr_debug("can't register OHCI device, %d\n", status);
767 /* hcd explicitly gates 48MHz */
773 static inline void omap_1510_usb_init(struct omap_usb_config *config) {}
776 /*-------------------------------------------------------------------------*/
778 static struct omap_usb_config platform_data;
783 const struct omap_usb_config *config;
785 config = omap_get_config(OMAP_TAG_USB, struct omap_usb_config);
786 if (config == NULL) {
787 printk(KERN_ERR "USB: No board-specific "
788 "platform config found\n");
791 platform_data = *config;
793 if (cpu_is_omap730() || cpu_is_omap16xx() || cpu_is_omap24xx())
794 omap_otg_init(&platform_data);
795 else if (cpu_is_omap15xx())
796 omap_1510_usb_init(&platform_data);
798 printk(KERN_ERR "USB: No init for your chip yet\n");
804 subsys_initcall(omap_usb_init);