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 <plat/control.h>
39 #include <plat/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_ARCH_OMAP15XX)
82 static void omap2_usb_devconf_clear(u8 port, u32 mask)
86 r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
87 r &= ~USBTXWRMODEI(port, mask);
88 omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
91 static void omap2_usb_devconf_set(u8 port, u32 mask)
95 r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
96 r |= USBTXWRMODEI(port, mask);
97 omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
100 static void omap2_usb2_disable_5pinbitll(void)
104 r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
105 r &= ~(USBTXWRMODEI(2, USB_BIDIR_TLL) | USBT2TLL5PI);
106 omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
109 static void omap2_usb2_enable_5pinunitll(void)
113 r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
114 r |= USBTXWRMODEI(2, USB_UNIDIR_TLL) | USBT2TLL5PI;
115 omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
118 static u32 __init omap_usb0_init(unsigned nwires, unsigned is_device)
122 if (cpu_is_omap24xx())
123 omap2_usb_devconf_clear(0, USB_BIDIR_TLL);
126 if (cpu_class_is_omap1() && !cpu_is_omap15xx()) {
130 l = omap_readl(USB_TRANSCEIVER_CTRL);
132 omap_writel(l, USB_TRANSCEIVER_CTRL);
138 if (cpu_is_omap24xx())
139 omap_cfg_reg(J20_24XX_USB0_PUEN);
141 omap_cfg_reg(W4_USB_PUEN);
144 /* internal transceiver (unavailable on 17xx, 24xx) */
145 if (!cpu_class_is_omap2() && nwires == 2) {
148 // omap_cfg_reg(P9_USB_DP);
149 // omap_cfg_reg(R8_USB_DM);
151 if (cpu_is_omap15xx()) {
152 /* This works on 1510-Innovator */
157 * - peripheral should configure VBUS detection!
158 * - only peripherals may use the internal D+/D- pulldowns
159 * - OTG support on this port not yet written
162 /* Don't do this for omap7xx -- it causes USB to not work correctly */
163 if (!cpu_is_omap7xx()) {
164 l = omap_readl(USB_TRANSCEIVER_CTRL);
168 omap_writel(l, USB_TRANSCEIVER_CTRL);
174 /* alternate pin config, external transceiver */
175 if (cpu_is_omap15xx()) {
176 printk(KERN_ERR "no usb0 alt pin config on 15xx\n");
180 if (cpu_is_omap24xx()) {
181 omap_cfg_reg(K18_24XX_USB0_DAT);
182 omap_cfg_reg(K19_24XX_USB0_TXEN);
183 omap_cfg_reg(J14_24XX_USB0_SE0);
185 omap_cfg_reg(J18_24XX_USB0_RCV);
187 omap_cfg_reg(V6_USB0_TXD);
188 omap_cfg_reg(W9_USB0_TXEN);
189 omap_cfg_reg(W5_USB0_SE0);
191 omap_cfg_reg(Y5_USB0_RCV);
194 /* NOTE: SPEED and SUSP aren't configured here. OTG hosts
195 * may be able to use I2C requests to set those bits along
196 * with VBUS switching and overcurrent detection.
199 if (cpu_class_is_omap1() && nwires != 6) {
202 l = omap_readl(USB_TRANSCEIVER_CTRL);
203 l &= ~CONF_USB2_UNI_R;
204 omap_writel(l, USB_TRANSCEIVER_CTRL);
210 if (cpu_is_omap24xx())
211 omap2_usb_devconf_set(0, USB_BIDIR);
215 if (cpu_is_omap24xx())
216 omap2_usb_devconf_set(0, USB_BIDIR);
220 if (cpu_is_omap24xx()) {
221 omap_cfg_reg(J19_24XX_USB0_VP);
222 omap_cfg_reg(K20_24XX_USB0_VM);
223 omap2_usb_devconf_set(0, USB_UNIDIR);
227 omap_cfg_reg(AA9_USB0_VP);
228 omap_cfg_reg(R9_USB0_VM);
229 l = omap_readl(USB_TRANSCEIVER_CTRL);
230 l |= CONF_USB2_UNI_R;
231 omap_writel(l, USB_TRANSCEIVER_CTRL);
235 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
238 return syscon1 << 16;
241 static u32 __init omap_usb1_init(unsigned nwires)
245 if (cpu_class_is_omap1() && !cpu_is_omap15xx() && nwires != 6) {
248 l = omap_readl(USB_TRANSCEIVER_CTRL);
249 l &= ~CONF_USB1_UNI_R;
250 omap_writel(l, USB_TRANSCEIVER_CTRL);
252 if (cpu_is_omap24xx())
253 omap2_usb_devconf_clear(1, USB_BIDIR_TLL);
258 /* external transceiver */
259 if (cpu_class_is_omap1()) {
260 omap_cfg_reg(USB1_TXD);
261 omap_cfg_reg(USB1_TXEN);
263 omap_cfg_reg(USB1_RCV);
266 if (cpu_is_omap15xx()) {
267 omap_cfg_reg(USB1_SEO);
268 omap_cfg_reg(USB1_SPEED);
270 } else if (cpu_is_omap1610() || cpu_is_omap5912()) {
271 omap_cfg_reg(W13_1610_USB1_SE0);
272 omap_cfg_reg(R13_1610_USB1_SPEED);
274 } else if (cpu_is_omap1710()) {
275 omap_cfg_reg(R13_1710_USB1_SE0);
277 } else if (cpu_is_omap24xx()) {
278 /* NOTE: board-specific code must set up pin muxing for usb1,
279 * since each signal could come out on either of two balls.
282 pr_debug("usb%d cpu unrecognized\n", 1);
288 if (!cpu_is_omap24xx())
290 /* NOTE: board-specific code must override this setting if
291 * this TLL link is not using DP/DM
294 omap2_usb_devconf_set(1, USB_BIDIR_TLL);
298 if (cpu_is_omap24xx())
299 omap2_usb_devconf_set(1, USB_BIDIR);
303 if (cpu_is_omap24xx())
304 omap2_usb_devconf_set(1, USB_BIDIR);
307 if (cpu_is_omap24xx())
310 omap_cfg_reg(USB1_VP);
311 omap_cfg_reg(USB1_VM);
312 if (!cpu_is_omap15xx()) {
315 l = omap_readl(USB_TRANSCEIVER_CTRL);
316 l |= CONF_USB1_UNI_R;
317 omap_writel(l, USB_TRANSCEIVER_CTRL);
322 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
325 return syscon1 << 20;
328 static u32 __init omap_usb2_init(unsigned nwires, unsigned alt_pingroup)
332 if (cpu_is_omap24xx()) {
333 omap2_usb2_disable_5pinbitll();
337 /* NOTE omap1 erratum: must leave USB2_UNI_R set if usb0 in use */
338 if (alt_pingroup || nwires == 0)
341 if (cpu_class_is_omap1() && !cpu_is_omap15xx() && nwires != 6) {
344 l = omap_readl(USB_TRANSCEIVER_CTRL);
345 l &= ~CONF_USB2_UNI_R;
346 omap_writel(l, USB_TRANSCEIVER_CTRL);
349 /* external transceiver */
350 if (cpu_is_omap15xx()) {
351 omap_cfg_reg(USB2_TXD);
352 omap_cfg_reg(USB2_TXEN);
353 omap_cfg_reg(USB2_SEO);
355 omap_cfg_reg(USB2_RCV);
356 /* there is no USB2_SPEED */
357 } else if (cpu_is_omap16xx()) {
358 omap_cfg_reg(V6_USB2_TXD);
359 omap_cfg_reg(W9_USB2_TXEN);
360 omap_cfg_reg(W5_USB2_SE0);
362 omap_cfg_reg(Y5_USB2_RCV);
363 // FIXME omap_cfg_reg(USB2_SPEED);
364 } else if (cpu_is_omap24xx()) {
365 omap_cfg_reg(Y11_24XX_USB2_DAT);
366 omap_cfg_reg(AA10_24XX_USB2_SE0);
368 omap_cfg_reg(AA12_24XX_USB2_TXEN);
370 omap_cfg_reg(AA6_24XX_USB2_RCV);
372 pr_debug("usb%d cpu unrecognized\n", 1);
375 // if (cpu_class_is_omap1()) omap_cfg_reg(USB2_SUSP);
379 if (!cpu_is_omap24xx())
381 /* NOTE: board-specific code must override this setting if
382 * this TLL link is not using DP/DM
385 omap2_usb_devconf_set(2, USB_BIDIR_TLL);
389 if (cpu_is_omap24xx())
390 omap2_usb_devconf_set(2, USB_BIDIR);
394 if (cpu_is_omap24xx())
395 omap2_usb_devconf_set(2, USB_BIDIR);
398 if (!cpu_is_omap24xx())
400 omap_cfg_reg(AA4_24XX_USB2_TLLSE0);
401 /* NOTE: board-specific code must override this setting if
402 * this TLL link is not using DP/DM. Something must also
403 * set up OTG_SYSCON2.HMC_TLL{ATTACH,SPEED}
406 omap2_usb2_enable_5pinunitll();
409 if (cpu_is_omap24xx())
412 if (cpu_is_omap15xx()) {
413 omap_cfg_reg(USB2_VP);
414 omap_cfg_reg(USB2_VM);
418 omap_cfg_reg(AA9_USB2_VP);
419 omap_cfg_reg(R9_USB2_VM);
420 l = omap_readl(USB_TRANSCEIVER_CTRL);
421 l |= CONF_USB2_UNI_R;
422 omap_writel(l, USB_TRANSCEIVER_CTRL);
427 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
430 return syscon1 << 24;
435 /*-------------------------------------------------------------------------*/
437 #ifdef CONFIG_USB_GADGET_OMAP
439 static struct resource udc_resources[] = {
440 /* order is significant! */
443 .end = UDC_BASE + 0xff,
444 .flags = IORESOURCE_MEM,
445 }, { /* general IRQ */
446 .start = INT_USB_IRQ_GEN,
447 .flags = IORESOURCE_IRQ,
449 .start = INT_USB_IRQ_NISO,
450 .flags = IORESOURCE_IRQ,
452 .start = INT_USB_IRQ_ISO,
453 .flags = IORESOURCE_IRQ,
457 static u64 udc_dmamask = ~(u32)0;
459 static struct platform_device udc_device = {
463 .dma_mask = &udc_dmamask,
464 .coherent_dma_mask = 0xffffffff,
466 .num_resources = ARRAY_SIZE(udc_resources),
467 .resource = udc_resources,
472 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
474 /* The dmamask must be set for OHCI to work */
475 static u64 ohci_dmamask = ~(u32)0;
477 static struct resource ohci_resources[] = {
479 .start = OMAP_OHCI_BASE,
480 .end = OMAP_OHCI_BASE + 0xff,
481 .flags = IORESOURCE_MEM,
484 .start = INT_USB_IRQ_HGEN,
485 .flags = IORESOURCE_IRQ,
489 static struct platform_device ohci_device = {
493 .dma_mask = &ohci_dmamask,
494 .coherent_dma_mask = 0xffffffff,
496 .num_resources = ARRAY_SIZE(ohci_resources),
497 .resource = ohci_resources,
502 #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
504 static struct resource otg_resources[] = {
505 /* order is significant! */
508 .end = OTG_BASE + 0xff,
509 .flags = IORESOURCE_MEM,
511 .start = INT_USB_IRQ_OTG,
512 .flags = IORESOURCE_IRQ,
516 static struct platform_device otg_device = {
519 .num_resources = ARRAY_SIZE(otg_resources),
520 .resource = otg_resources,
525 /*-------------------------------------------------------------------------*/
527 // FIXME correct answer depends on hmc_mode,
528 // as does (on omap1) any nonzero value for config->otg port number
529 #ifdef CONFIG_USB_GADGET_OMAP
530 #define is_usb0_device(config) 1
532 #define is_usb0_device(config) 0
535 /*-------------------------------------------------------------------------*/
537 #ifdef CONFIG_ARCH_OMAP_OTG
540 omap_otg_init(struct omap_usb_config *config)
544 int alt_pingroup = 0;
546 /* NOTE: no bus or clock setup (yet?) */
548 syscon = omap_readl(OTG_SYSCON_1) & 0xffff;
549 if (!(syscon & OTG_RESET_DONE))
550 pr_debug("USB resets not complete?\n");
552 //omap_writew(0, OTG_IRQ_EN);
554 /* pin muxing and transceiver pinouts */
555 if (config->pins[0] > 2) /* alt pingroup 2 */
557 syscon |= omap_usb0_init(config->pins[0], is_usb0_device(config));
558 syscon |= omap_usb1_init(config->pins[1]);
559 syscon |= omap_usb2_init(config->pins[2], alt_pingroup);
560 pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
561 omap_writel(syscon, OTG_SYSCON_1);
563 syscon = config->hmc_mode;
564 syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
565 #ifdef CONFIG_USB_OTG
569 if (cpu_class_is_omap1())
570 pr_debug("USB_TRANSCEIVER_CTRL = %03x\n",
571 omap_readl(USB_TRANSCEIVER_CTRL));
572 pr_debug("OTG_SYSCON_2 = %08x\n", omap_readl(OTG_SYSCON_2));
573 omap_writel(syscon, OTG_SYSCON_2);
575 printk("USB: hmc %d", config->hmc_mode);
577 printk(", usb2 alt %d wires", config->pins[2]);
578 else if (config->pins[0])
579 printk(", usb0 %d wires%s", config->pins[0],
580 is_usb0_device(config) ? " (dev)" : "");
582 printk(", usb1 %d wires", config->pins[1]);
583 if (!alt_pingroup && config->pins[2])
584 printk(", usb2 %d wires", config->pins[2]);
586 printk(", Mini-AB on usb%d", config->otg - 1);
589 if (cpu_class_is_omap1()) {
592 /* leave USB clocks/controllers off until needed */
593 w = omap_readw(ULPD_SOFT_REQ);
594 w &= ~SOFT_USB_CLK_REQ;
595 omap_writew(w, ULPD_SOFT_REQ);
597 w = omap_readw(ULPD_CLOCK_CTRL);
599 w |= DIS_USB_PVCI_CLK;
600 omap_writew(w, ULPD_CLOCK_CTRL);
602 syscon = omap_readl(OTG_SYSCON_1);
603 syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
605 #ifdef CONFIG_USB_GADGET_OMAP
606 if (config->otg || config->register_dev) {
607 syscon &= ~DEV_IDLE_EN;
608 udc_device.dev.platform_data = config;
609 /* IRQ numbers for omap7xx */
610 if(cpu_is_omap7xx()) {
611 udc_resources[1].start = INT_7XX_USB_GENI;
612 udc_resources[2].start = INT_7XX_USB_NON_ISO;
613 udc_resources[3].start = INT_7XX_USB_ISO;
615 status = platform_device_register(&udc_device);
617 pr_debug("can't register UDC device, %d\n", status);
621 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
622 if (config->otg || config->register_host) {
623 syscon &= ~HST_IDLE_EN;
624 ohci_device.dev.platform_data = config;
625 if (cpu_is_omap7xx())
626 ohci_resources[1].start = INT_7XX_USB_HHC_1;
627 status = platform_device_register(&ohci_device);
629 pr_debug("can't register OHCI device, %d\n", status);
633 #ifdef CONFIG_USB_OTG
635 syscon &= ~OTG_IDLE_EN;
636 otg_device.dev.platform_data = config;
637 if (cpu_is_omap7xx())
638 otg_resources[1].start = INT_7XX_USB_OTG;
639 status = platform_device_register(&otg_device);
641 pr_debug("can't register OTG device, %d\n", status);
644 pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
645 omap_writel(syscon, OTG_SYSCON_1);
651 static inline void omap_otg_init(struct omap_usb_config *config) {}
654 /*-------------------------------------------------------------------------*/
656 #ifdef CONFIG_ARCH_OMAP15XX
659 #define DPLL_IOB (1 << 13)
660 #define DPLL_PLL_ENABLE (1 << 4)
661 #define DPLL_LOCK (1 << 0)
664 #define APLL_NDPLL_SWITCH (1 << 0)
667 static void __init omap_1510_usb_init(struct omap_usb_config *config)
672 omap_usb0_init(config->pins[0], is_usb0_device(config));
673 omap_usb1_init(config->pins[1]);
674 omap_usb2_init(config->pins[2], 0);
676 val = omap_readl(MOD_CONF_CTRL_0) & ~(0x3f << 1);
677 val |= (config->hmc_mode << 1);
678 omap_writel(val, MOD_CONF_CTRL_0);
680 printk("USB: hmc %d", config->hmc_mode);
682 printk(", usb0 %d wires%s", config->pins[0],
683 is_usb0_device(config) ? " (dev)" : "");
685 printk(", usb1 %d wires", config->pins[1]);
687 printk(", usb2 %d wires", config->pins[2]);
690 /* use DPLL for 48 MHz function clock */
691 pr_debug("APLL %04x DPLL %04x REQ %04x\n", omap_readw(ULPD_APLL_CTRL),
692 omap_readw(ULPD_DPLL_CTRL), omap_readw(ULPD_SOFT_REQ));
694 w = omap_readw(ULPD_APLL_CTRL);
695 w &= ~APLL_NDPLL_SWITCH;
696 omap_writew(w, ULPD_APLL_CTRL);
698 w = omap_readw(ULPD_DPLL_CTRL);
699 w |= DPLL_IOB | DPLL_PLL_ENABLE;
700 omap_writew(w, ULPD_DPLL_CTRL);
702 w = omap_readw(ULPD_SOFT_REQ);
703 w |= SOFT_UDC_REQ | SOFT_DPLL_REQ;
704 omap_writew(w, ULPD_SOFT_REQ);
706 while (!(omap_readw(ULPD_DPLL_CTRL) & DPLL_LOCK))
709 #ifdef CONFIG_USB_GADGET_OMAP
710 if (config->register_dev) {
713 udc_device.dev.platform_data = config;
714 status = platform_device_register(&udc_device);
716 pr_debug("can't register UDC device, %d\n", status);
717 /* udc driver gates 48MHz by D+ pullup */
721 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
722 if (config->register_host) {
725 ohci_device.dev.platform_data = config;
726 status = platform_device_register(&ohci_device);
728 pr_debug("can't register OHCI device, %d\n", status);
729 /* hcd explicitly gates 48MHz */
735 static inline void omap_1510_usb_init(struct omap_usb_config *config) {}
738 /*-------------------------------------------------------------------------*/
740 void __init omap_usb_init(struct omap_usb_config *pdata)
742 if (cpu_is_omap7xx() || cpu_is_omap16xx() || cpu_is_omap24xx())
743 omap_otg_init(pdata);
744 else if (cpu_is_omap15xx())
745 omap_1510_usb_init(pdata);
747 printk(KERN_ERR "USB: No init for your chip yet\n");