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 #include "../mach-omap2/control.h"
42 #ifdef CONFIG_ARCH_OMAP1
44 #define INT_USB_IRQ_GEN IH2_BASE + 20
45 #define INT_USB_IRQ_NISO IH2_BASE + 30
46 #define INT_USB_IRQ_ISO IH2_BASE + 29
47 #define INT_USB_IRQ_HGEN INT_USB_HHC_1
48 #define INT_USB_IRQ_OTG IH2_BASE + 8
52 #define INT_USB_IRQ_GEN INT_24XX_USB_IRQ_GEN
53 #define INT_USB_IRQ_NISO INT_24XX_USB_IRQ_NISO
54 #define INT_USB_IRQ_ISO INT_24XX_USB_IRQ_ISO
55 #define INT_USB_IRQ_HGEN INT_24XX_USB_IRQ_HGEN
56 #define INT_USB_IRQ_OTG INT_24XX_USB_IRQ_OTG
61 /* These routines should handle the standard chip-specific modes
62 * for usb0/1/2 ports, covering basic mux and transceiver setup.
64 * Some board-*.c files will need to set up additional mux options,
65 * like for suspend handling, vbus sensing, GPIOs, and the D+ pullup.
69 * - 1611B H2 (with usb1 mini-AB) using standard Mini-B or OTG cables
70 * - 5912 OSK OHCI (with usb0 standard-A), standard A-to-B cables
71 * - 5912 OSK UDC, with *nonstandard* A-to-A cable
72 * - 1510 Innovator UDC with bundled usb0 cable
73 * - 1510 Innovator OHCI with bundled usb1/usb2 cable
74 * - 1510 Innovator OHCI with custom usb0 cable, feeding 5V VBUS
75 * - 1710 custom development board using alternate pin group
76 * - 1710 H3 (with usb1 mini-AB) using standard Mini-B or OTG cables
79 /*-------------------------------------------------------------------------*/
81 #if defined(CONFIG_ARCH_OMAP_OTG) || defined(CONFIG_USB_MUSB_OTG)
83 static struct otg_transceiver *xceiv;
86 * otg_get_transceiver - find the (single) OTG transceiver driver
88 * Returns the transceiver driver, after getting a refcount to it; or
89 * null if there is no such transceiver. The caller is responsible for
90 * releasing that count.
92 struct otg_transceiver *otg_get_transceiver(void)
95 get_device(xceiv->dev);
98 EXPORT_SYMBOL(otg_get_transceiver);
100 int otg_set_transceiver(struct otg_transceiver *x)
107 EXPORT_SYMBOL(otg_set_transceiver);
111 /*-------------------------------------------------------------------------*/
113 #if defined(CONFIG_ARCH_OMAP_OTG) || defined(CONFIG_ARCH_OMAP15XX)
115 static void omap2_usb_devconf_clear(u8 port, u32 mask)
119 r = ctrl_read_reg(CONTROL_DEVCONF0);
120 r &= ~USBTXWRMODEI(port, mask);
121 ctrl_write_reg(r, CONTROL_DEVCONF0);
124 static void omap2_usb_devconf_set(u8 port, u32 mask)
128 r = ctrl_read_reg(CONTROL_DEVCONF0);
129 r |= USBTXWRMODEI(port, mask);
130 ctrl_write_reg(r, CONTROL_DEVCONF0);
133 static void omap2_usb2_disable_5pinbitll(void)
137 r = ctrl_read_reg(CONTROL_DEVCONF0);
138 r &= ~(USBTXWRMODEI(2, USB_BIDIR_TLL) | USBT2TLL5PI);
139 ctrl_write_reg(r, CONTROL_DEVCONF0);
142 static void omap2_usb2_enable_5pinunitll(void)
146 r = ctrl_read_reg(CONTROL_DEVCONF0);
147 r |= USBTXWRMODEI(2, USB_UNIDIR_TLL) | USBT2TLL5PI;
148 ctrl_write_reg(r, CONTROL_DEVCONF0);
151 static u32 __init omap_usb0_init(unsigned nwires, unsigned is_device)
155 if (cpu_is_omap24xx())
156 omap2_usb_devconf_clear(0, USB_BIDIR_TLL);
159 if (cpu_class_is_omap1() && !cpu_is_omap15xx()) {
161 USB_TRANSCEIVER_CTRL_REG &= ~(3 << 1);
167 if (cpu_is_omap24xx())
168 omap_cfg_reg(J20_24XX_USB0_PUEN);
170 omap_cfg_reg(W4_USB_PUEN);
173 /* internal transceiver (unavailable on 17xx, 24xx) */
174 if (!cpu_class_is_omap2() && nwires == 2) {
175 // omap_cfg_reg(P9_USB_DP);
176 // omap_cfg_reg(R8_USB_DM);
178 if (cpu_is_omap15xx()) {
179 /* This works on 1510-Innovator */
184 * - peripheral should configure VBUS detection!
185 * - only peripherals may use the internal D+/D- pulldowns
186 * - OTG support on this port not yet written
189 USB_TRANSCEIVER_CTRL_REG &= ~(7 << 4);
191 USB_TRANSCEIVER_CTRL_REG |= (3 << 1);
196 /* alternate pin config, external transceiver */
197 if (cpu_is_omap15xx()) {
198 printk(KERN_ERR "no usb0 alt pin config on 15xx\n");
202 if (cpu_is_omap24xx()) {
203 omap_cfg_reg(K18_24XX_USB0_DAT);
204 omap_cfg_reg(K19_24XX_USB0_TXEN);
205 omap_cfg_reg(J14_24XX_USB0_SE0);
207 omap_cfg_reg(J18_24XX_USB0_RCV);
209 omap_cfg_reg(V6_USB0_TXD);
210 omap_cfg_reg(W9_USB0_TXEN);
211 omap_cfg_reg(W5_USB0_SE0);
213 omap_cfg_reg(Y5_USB0_RCV);
216 /* NOTE: SPEED and SUSP aren't configured here. OTG hosts
217 * may be able to use I2C requests to set those bits along
218 * with VBUS switching and overcurrent detection.
221 if (cpu_class_is_omap1() && nwires != 6)
222 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB2_UNI_R;
227 if (cpu_is_omap24xx())
228 omap2_usb_devconf_set(0, USB_BIDIR);
232 if (cpu_is_omap24xx())
233 omap2_usb_devconf_set(0, USB_BIDIR);
237 if (cpu_is_omap24xx()) {
238 omap_cfg_reg(J19_24XX_USB0_VP);
239 omap_cfg_reg(K20_24XX_USB0_VM);
240 omap2_usb_devconf_set(0, USB_UNIDIR);
242 omap_cfg_reg(AA9_USB0_VP);
243 omap_cfg_reg(R9_USB0_VM);
244 USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;
248 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
251 return syscon1 << 16;
254 static u32 __init omap_usb1_init(unsigned nwires)
258 if (cpu_class_is_omap1() && !cpu_is_omap15xx() && nwires != 6)
259 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB1_UNI_R;
260 if (cpu_is_omap24xx())
261 omap2_usb_devconf_clear(1, USB_BIDIR_TLL);
266 /* external transceiver */
267 if (cpu_class_is_omap1()) {
268 omap_cfg_reg(USB1_TXD);
269 omap_cfg_reg(USB1_TXEN);
271 omap_cfg_reg(USB1_RCV);
274 if (cpu_is_omap15xx()) {
275 omap_cfg_reg(USB1_SEO);
276 omap_cfg_reg(USB1_SPEED);
278 } else if (cpu_is_omap1610() || cpu_is_omap5912()) {
279 omap_cfg_reg(W13_1610_USB1_SE0);
280 omap_cfg_reg(R13_1610_USB1_SPEED);
282 } else if (cpu_is_omap1710()) {
283 omap_cfg_reg(R13_1710_USB1_SE0);
285 } else if (cpu_is_omap24xx()) {
286 /* NOTE: board-specific code must set up pin muxing for usb1,
287 * since each signal could come out on either of two balls.
290 pr_debug("usb%d cpu unrecognized\n", 1);
296 if (!cpu_is_omap24xx())
298 /* NOTE: board-specific code must override this setting if
299 * this TLL link is not using DP/DM
302 omap2_usb_devconf_set(1, USB_BIDIR_TLL);
306 if (cpu_is_omap24xx())
307 omap2_usb_devconf_set(1, USB_BIDIR);
311 if (cpu_is_omap24xx())
312 omap2_usb_devconf_set(1, USB_BIDIR);
315 if (cpu_is_omap24xx())
318 omap_cfg_reg(USB1_VP);
319 omap_cfg_reg(USB1_VM);
320 if (!cpu_is_omap15xx())
321 USB_TRANSCEIVER_CTRL_REG |= CONF_USB1_UNI_R;
325 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
328 return syscon1 << 20;
331 static u32 __init omap_usb2_init(unsigned nwires, unsigned alt_pingroup)
335 if (cpu_is_omap24xx()) {
336 omap2_usb2_disable_5pinbitll();
340 /* NOTE omap1 erratum: must leave USB2_UNI_R set if usb0 in use */
341 if (alt_pingroup || nwires == 0)
344 if (cpu_class_is_omap1() && !cpu_is_omap15xx() && nwires != 6)
345 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB2_UNI_R;
347 /* external transceiver */
348 if (cpu_is_omap15xx()) {
349 omap_cfg_reg(USB2_TXD);
350 omap_cfg_reg(USB2_TXEN);
351 omap_cfg_reg(USB2_SEO);
353 omap_cfg_reg(USB2_RCV);
354 /* there is no USB2_SPEED */
355 } else if (cpu_is_omap16xx()) {
356 omap_cfg_reg(V6_USB2_TXD);
357 omap_cfg_reg(W9_USB2_TXEN);
358 omap_cfg_reg(W5_USB2_SE0);
360 omap_cfg_reg(Y5_USB2_RCV);
361 // FIXME omap_cfg_reg(USB2_SPEED);
362 } else if (cpu_is_omap24xx()) {
363 omap_cfg_reg(Y11_24XX_USB2_DAT);
364 omap_cfg_reg(AA10_24XX_USB2_SE0);
366 omap_cfg_reg(AA12_24XX_USB2_TXEN);
368 omap_cfg_reg(AA6_24XX_USB2_RCV);
370 pr_debug("usb%d cpu unrecognized\n", 1);
373 // if (cpu_class_is_omap1()) omap_cfg_reg(USB2_SUSP);
377 if (!cpu_is_omap24xx())
379 /* NOTE: board-specific code must override this setting if
380 * this TLL link is not using DP/DM
383 omap2_usb_devconf_set(2, USB_BIDIR_TLL);
387 if (cpu_is_omap24xx())
388 omap2_usb_devconf_set(2, USB_BIDIR);
392 if (cpu_is_omap24xx())
393 omap2_usb_devconf_set(2, USB_BIDIR);
396 if (!cpu_is_omap24xx())
398 omap_cfg_reg(AA4_24XX_USB2_TLLSE0);
399 /* NOTE: board-specific code must override this setting if
400 * this TLL link is not using DP/DM. Something must also
401 * set up OTG_SYSCON2.HMC_TLL{ATTACH,SPEED}
404 omap2_usb2_enable_5pinunitll();
407 if (cpu_is_omap24xx())
410 if (cpu_is_omap15xx()) {
411 omap_cfg_reg(USB2_VP);
412 omap_cfg_reg(USB2_VM);
414 omap_cfg_reg(AA9_USB2_VP);
415 omap_cfg_reg(R9_USB2_VM);
416 USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;
421 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
424 return syscon1 << 24;
429 /*-------------------------------------------------------------------------*/
431 #if defined(CONFIG_USB_GADGET_OMAP) || \
432 defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) || \
433 (defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG))
434 static void usb_release(struct device *dev)
436 /* normally not freed */
440 #ifdef CONFIG_USB_GADGET_OMAP
442 static struct resource udc_resources[] = {
443 /* order is significant! */
446 .end = UDC_BASE + 0xff,
447 .flags = IORESOURCE_MEM,
448 }, { /* general IRQ */
449 .start = INT_USB_IRQ_GEN,
450 .flags = IORESOURCE_IRQ,
452 .start = INT_USB_IRQ_NISO,
453 .flags = IORESOURCE_IRQ,
455 .start = INT_USB_IRQ_ISO,
456 .flags = IORESOURCE_IRQ,
460 static u64 udc_dmamask = ~(u32)0;
462 static struct platform_device udc_device = {
466 .release = usb_release,
467 .dma_mask = &udc_dmamask,
468 .coherent_dma_mask = 0xffffffff,
470 .num_resources = ARRAY_SIZE(udc_resources),
471 .resource = udc_resources,
476 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
478 /* The dmamask must be set for OHCI to work */
479 static u64 ohci_dmamask = ~(u32)0;
481 static struct resource ohci_resources[] = {
483 .start = OMAP_OHCI_BASE,
484 .end = OMAP_OHCI_BASE + 0xff,
485 .flags = IORESOURCE_MEM,
488 .start = INT_USB_IRQ_HGEN,
489 .flags = IORESOURCE_IRQ,
493 static struct platform_device ohci_device = {
497 .release = usb_release,
498 .dma_mask = &ohci_dmamask,
499 .coherent_dma_mask = 0xffffffff,
501 .num_resources = ARRAY_SIZE(ohci_resources),
502 .resource = ohci_resources,
507 #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
509 static struct resource otg_resources[] = {
510 /* order is significant! */
513 .end = OTG_BASE + 0xff,
514 .flags = IORESOURCE_MEM,
516 .start = INT_USB_IRQ_OTG,
517 .flags = IORESOURCE_IRQ,
521 static struct platform_device otg_device = {
525 .release = usb_release,
527 .num_resources = ARRAY_SIZE(otg_resources),
528 .resource = otg_resources,
533 /*-------------------------------------------------------------------------*/
535 #define ULPD_CLOCK_CTRL_REG __REG16(ULPD_CLOCK_CTRL)
536 #define ULPD_SOFT_REQ_REG __REG16(ULPD_SOFT_REQ)
539 // FIXME correct answer depends on hmc_mode,
540 // as does (on omap1) any nonzero value for config->otg port number
541 #ifdef CONFIG_USB_GADGET_OMAP
542 #define is_usb0_device(config) 1
544 #define is_usb0_device(config) 0
547 /*-------------------------------------------------------------------------*/
549 #ifdef CONFIG_ARCH_OMAP_OTG
552 omap_otg_init(struct omap_usb_config *config)
554 u32 syscon = OTG_SYSCON_1_REG & 0xffff;
556 int alt_pingroup = 0;
558 /* NOTE: no bus or clock setup (yet?) */
560 syscon = OTG_SYSCON_1_REG & 0xffff;
561 if (!(syscon & OTG_RESET_DONE))
562 pr_debug("USB resets not complete?\n");
564 // OTG_IRQ_EN_REG = 0;
566 /* pin muxing and transceiver pinouts */
567 if (config->pins[0] > 2) /* alt pingroup 2 */
569 syscon |= omap_usb0_init(config->pins[0], is_usb0_device(config));
570 syscon |= omap_usb1_init(config->pins[1]);
571 syscon |= omap_usb2_init(config->pins[2], alt_pingroup);
572 pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
573 OTG_SYSCON_1_REG = syscon;
575 syscon = config->hmc_mode;
576 syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
577 #ifdef CONFIG_USB_OTG
581 if (cpu_class_is_omap1())
582 pr_debug("USB_TRANSCEIVER_CTRL_REG = %03x\n", USB_TRANSCEIVER_CTRL_REG);
583 pr_debug("OTG_SYSCON_2_REG = %08x\n", syscon);
584 OTG_SYSCON_2_REG = syscon;
586 printk("USB: hmc %d", config->hmc_mode);
588 printk(", usb2 alt %d wires", config->pins[2]);
589 else if (config->pins[0])
590 printk(", usb0 %d wires%s", config->pins[0],
591 is_usb0_device(config) ? " (dev)" : "");
593 printk(", usb1 %d wires", config->pins[1]);
594 if (!alt_pingroup && config->pins[2])
595 printk(", usb2 %d wires", config->pins[2]);
597 printk(", Mini-AB on usb%d", config->otg - 1);
600 if (cpu_class_is_omap1()) {
601 /* leave USB clocks/controllers off until needed */
602 ULPD_SOFT_REQ_REG &= ~SOFT_USB_CLK_REQ;
603 ULPD_CLOCK_CTRL_REG &= ~USB_MCLK_EN;
604 ULPD_CLOCK_CTRL_REG |= DIS_USB_PVCI_CLK;
606 syscon = OTG_SYSCON_1_REG;
607 syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
609 #ifdef CONFIG_USB_GADGET_OMAP
610 if (config->otg || config->register_dev) {
611 syscon &= ~DEV_IDLE_EN;
612 udc_device.dev.platform_data = config;
613 /* FIXME patch IRQ numbers for omap730 */
614 status = platform_device_register(&udc_device);
616 pr_debug("can't register UDC device, %d\n", status);
620 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
621 if (config->otg || config->register_host) {
622 syscon &= ~HST_IDLE_EN;
623 ohci_device.dev.platform_data = config;
624 if (cpu_is_omap730())
625 ohci_resources[1].start = INT_730_USB_HHC_1;
626 status = platform_device_register(&ohci_device);
628 pr_debug("can't register OHCI device, %d\n", status);
632 #ifdef CONFIG_USB_OTG
634 syscon &= ~OTG_IDLE_EN;
635 otg_device.dev.platform_data = config;
636 if (cpu_is_omap730())
637 otg_resources[1].start = INT_730_USB_OTG;
638 status = platform_device_register(&otg_device);
640 pr_debug("can't register OTG device, %d\n", status);
643 pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
644 OTG_SYSCON_1_REG = syscon;
650 static inline void omap_otg_init(struct omap_usb_config *config) {}
653 /*-------------------------------------------------------------------------*/
655 #ifdef CONFIG_ARCH_OMAP15XX
657 #define ULPD_DPLL_CTRL_REG __REG16(ULPD_DPLL_CTRL)
658 #define DPLL_IOB (1 << 13)
659 #define DPLL_PLL_ENABLE (1 << 4)
660 #define DPLL_LOCK (1 << 0)
662 #define ULPD_APLL_CTRL_REG __REG16(ULPD_APLL_CTRL)
663 #define APLL_NDPLL_SWITCH (1 << 0)
666 static void __init omap_1510_usb_init(struct omap_usb_config *config)
670 omap_usb0_init(config->pins[0], is_usb0_device(config));
671 omap_usb1_init(config->pins[1]);
672 omap_usb2_init(config->pins[2], 0);
674 val = omap_readl(MOD_CONF_CTRL_0) & ~(0x3f << 1);
675 val |= (config->hmc_mode << 1);
676 omap_writel(val, MOD_CONF_CTRL_0);
678 printk("USB: hmc %d", config->hmc_mode);
680 printk(", usb0 %d wires%s", config->pins[0],
681 is_usb0_device(config) ? " (dev)" : "");
683 printk(", usb1 %d wires", config->pins[1]);
685 printk(", usb2 %d wires", config->pins[2]);
688 /* use DPLL for 48 MHz function clock */
689 pr_debug("APLL %04x DPLL %04x REQ %04x\n", ULPD_APLL_CTRL_REG,
690 ULPD_DPLL_CTRL_REG, ULPD_SOFT_REQ_REG);
691 ULPD_APLL_CTRL_REG &= ~APLL_NDPLL_SWITCH;
692 ULPD_DPLL_CTRL_REG |= DPLL_IOB | DPLL_PLL_ENABLE;
693 ULPD_SOFT_REQ_REG |= SOFT_UDC_REQ | SOFT_DPLL_REQ;
694 while (!(ULPD_DPLL_CTRL_REG & DPLL_LOCK))
697 #ifdef CONFIG_USB_GADGET_OMAP
698 if (config->register_dev) {
701 udc_device.dev.platform_data = config;
702 status = platform_device_register(&udc_device);
704 pr_debug("can't register UDC device, %d\n", status);
705 /* udc driver gates 48MHz by D+ pullup */
709 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
710 if (config->register_host) {
713 ohci_device.dev.platform_data = config;
714 status = platform_device_register(&ohci_device);
716 pr_debug("can't register OHCI device, %d\n", status);
717 /* hcd explicitly gates 48MHz */
723 static inline void omap_1510_usb_init(struct omap_usb_config *config) {}
726 /*-------------------------------------------------------------------------*/
728 static struct omap_usb_config platform_data;
733 const struct omap_usb_config *config;
735 config = omap_get_config(OMAP_TAG_USB, struct omap_usb_config);
736 if (config == NULL) {
737 printk(KERN_ERR "USB: No board-specific "
738 "platform config found\n");
741 platform_data = *config;
743 if (cpu_is_omap730() || cpu_is_omap16xx() || cpu_is_omap24xx())
744 omap_otg_init(&platform_data);
745 else if (cpu_is_omap15xx())
746 omap_1510_usb_init(&platform_data);
748 printk(KERN_ERR "USB: No init for your chip yet\n");
754 subsys_initcall(omap_usb_init);