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 /* These routines should handle the standard chip-specific modes
41 * for usb0/1/2 ports, covering basic mux and transceiver setup.
42 * Call omap_usb_init() once, from INIT_MACHINE().
44 * Some board-*.c files will need to set up additional mux options,
45 * like for suspend handling, vbus sensing, GPIOs, and the D+ pullup.
49 * - 1611B H2 (with usb1 mini-AB) using standard Mini-B or OTG cables
50 * - 5912 OSK OHCI (with usb0 standard-A), standard A-to-B cables
51 * - 5912 OSK UDC, with *nonstandard* A-to-A cable
52 * - 1510 Innovator UDC with bundled usb0 cable
53 * - 1510 Innovator OHCI with bundled usb1/usb2 cable
54 * - 1510 Innovator OHCI with custom usb0 cable, feeding 5V VBUS
55 * - 1710 custom development board using alternate pin group
56 * - 1710 H3 (with usb1 mini-AB) using standard Mini-B or OTG cables
59 /*-------------------------------------------------------------------------*/
61 #ifdef CONFIG_ARCH_OMAP_OTG
63 static struct otg_transceiver *xceiv;
66 * otg_get_transceiver - find the (single) OTG transceiver driver
68 * Returns the transceiver driver, after getting a refcount to it; or
69 * null if there is no such transceiver. The caller is responsible for
70 * releasing that count.
72 struct otg_transceiver *otg_get_transceiver(void)
75 get_device(xceiv->dev);
78 EXPORT_SYMBOL(otg_get_transceiver);
80 int otg_set_transceiver(struct otg_transceiver *x)
87 EXPORT_SYMBOL(otg_set_transceiver);
91 /*-------------------------------------------------------------------------*/
93 #if defined(CONFIG_ARCH_OMAP_OTG) || defined(CONFIG_ARCH_OMAP15XX)
95 static u32 __init omap_usb0_init(unsigned nwires, unsigned is_device)
100 if (!cpu_is_omap15xx()) {
102 USB_TRANSCEIVER_CTRL_REG &= ~(3 << 1);
108 omap_cfg_reg(W4_USB_PUEN);
110 /* internal transceiver */
112 // omap_cfg_reg(P9_USB_DP);
113 // omap_cfg_reg(R8_USB_DM);
115 if (cpu_is_omap15xx()) {
116 /* This works on 1510-Innovator */
121 * - peripheral should configure VBUS detection!
122 * - only peripherals may use the internal D+/D- pulldowns
123 * - OTG support on this port not yet written
126 USB_TRANSCEIVER_CTRL_REG &= ~(7 << 4);
128 USB_TRANSCEIVER_CTRL_REG |= (3 << 1);
133 /* alternate pin config, external transceiver */
134 if (cpu_is_omap15xx()) {
135 printk(KERN_ERR "no usb0 alt pin config on 15xx\n");
139 omap_cfg_reg(V6_USB0_TXD);
140 omap_cfg_reg(W9_USB0_TXEN);
141 omap_cfg_reg(W5_USB0_SE0);
143 /* NOTE: SPEED and SUSP aren't configured here */
146 omap_cfg_reg(Y5_USB0_RCV);
148 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB2_UNI_R;
159 omap_cfg_reg(AA9_USB0_VP);
160 omap_cfg_reg(R9_USB0_VM);
161 USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;
164 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
167 return syscon1 << 16;
170 static u32 __init omap_usb1_init(unsigned nwires)
174 if (nwires != 6 && !cpu_is_omap15xx())
175 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB1_UNI_R;
179 /* external transceiver */
180 omap_cfg_reg(USB1_TXD);
181 omap_cfg_reg(USB1_TXEN);
182 if (cpu_is_omap15xx()) {
183 omap_cfg_reg(USB1_SEO);
184 omap_cfg_reg(USB1_SPEED);
186 } else if (cpu_is_omap1610() || cpu_is_omap5912()) {
187 omap_cfg_reg(W13_1610_USB1_SE0);
188 omap_cfg_reg(R13_1610_USB1_SPEED);
190 } else if (cpu_is_omap1710()) {
191 omap_cfg_reg(R13_1710_USB1_SE0);
194 pr_debug("usb unrecognized\n");
197 omap_cfg_reg(USB1_RCV);
208 omap_cfg_reg(USB1_VP);
209 omap_cfg_reg(USB1_VM);
210 if (!cpu_is_omap15xx())
211 USB_TRANSCEIVER_CTRL_REG |= CONF_USB1_UNI_R;
214 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
217 return syscon1 << 20;
220 static u32 __init omap_usb2_init(unsigned nwires, unsigned alt_pingroup)
224 /* NOTE erratum: must leave USB2_UNI_R set if usb0 in use */
225 if (alt_pingroup || nwires == 0)
227 if (nwires != 6 && !cpu_is_omap15xx())
228 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB2_UNI_R;
230 /* external transceiver */
231 if (cpu_is_omap15xx()) {
232 omap_cfg_reg(USB2_TXD);
233 omap_cfg_reg(USB2_TXEN);
234 omap_cfg_reg(USB2_SEO);
236 omap_cfg_reg(USB2_RCV);
237 /* there is no USB2_SPEED */
238 } else if (cpu_is_omap16xx()) {
239 omap_cfg_reg(V6_USB2_TXD);
240 omap_cfg_reg(W9_USB2_TXEN);
241 omap_cfg_reg(W5_USB2_SE0);
243 omap_cfg_reg(Y5_USB2_RCV);
244 // FIXME omap_cfg_reg(USB2_SPEED);
246 pr_debug("usb unrecognized\n");
248 // omap_cfg_reg(USB2_SUSP);
259 if (cpu_is_omap15xx()) {
260 omap_cfg_reg(USB2_VP);
261 omap_cfg_reg(USB2_VM);
263 omap_cfg_reg(AA9_USB2_VP);
264 omap_cfg_reg(R9_USB2_VM);
265 USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;
269 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
272 return syscon1 << 24;
277 /*-------------------------------------------------------------------------*/
279 #if defined(CONFIG_USB_GADGET_OMAP) || \
280 defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) || \
281 (defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG))
282 static void usb_release(struct device *dev)
284 /* normally not freed */
288 #ifdef CONFIG_USB_GADGET_OMAP
290 static struct resource udc_resources[] = {
291 /* order is significant! */
294 .end = UDC_BASE + 0xff,
295 .flags = IORESOURCE_MEM,
296 }, { /* general IRQ */
297 .start = IH2_BASE + 20,
298 .flags = IORESOURCE_IRQ,
300 .start = IH2_BASE + 30,
301 .flags = IORESOURCE_IRQ,
303 .start = IH2_BASE + 29,
304 .flags = IORESOURCE_IRQ,
308 static u64 udc_dmamask = ~(u32)0;
310 static struct platform_device udc_device = {
314 .release = usb_release,
315 .dma_mask = &udc_dmamask,
316 .coherent_dma_mask = 0xffffffff,
318 .num_resources = ARRAY_SIZE(udc_resources),
319 .resource = udc_resources,
324 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
326 /* The dmamask must be set for OHCI to work */
327 static u64 ohci_dmamask = ~(u32)0;
329 static struct resource ohci_resources[] = {
331 .start = OMAP_OHCI_BASE,
332 .end = OMAP_OHCI_BASE + 4096 - 1,
333 .flags = IORESOURCE_MEM,
336 .start = INT_USB_HHC_1,
337 .flags = IORESOURCE_IRQ,
341 static struct platform_device ohci_device = {
345 .release = usb_release,
346 .dma_mask = &ohci_dmamask,
347 .coherent_dma_mask = 0xffffffff,
349 .num_resources = ARRAY_SIZE(ohci_resources),
350 .resource = ohci_resources,
355 #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
357 static struct resource otg_resources[] = {
358 /* order is significant! */
361 .end = OTG_BASE + 0xff,
362 .flags = IORESOURCE_MEM,
364 .start = IH2_BASE + 8,
365 .flags = IORESOURCE_IRQ,
369 static struct platform_device otg_device = {
373 .release = usb_release,
375 .num_resources = ARRAY_SIZE(otg_resources),
376 .resource = otg_resources,
381 /*-------------------------------------------------------------------------*/
383 #define ULPD_CLOCK_CTRL_REG __REG16(ULPD_CLOCK_CTRL)
384 #define ULPD_SOFT_REQ_REG __REG16(ULPD_SOFT_REQ)
387 // FIXME correct answer depends on hmc_mode,
388 // as does any nonzero value for config->otg port number
389 #ifdef CONFIG_USB_GADGET_OMAP
390 #define is_usb0_device(config) 1
392 #define is_usb0_device(config) 0
395 /*-------------------------------------------------------------------------*/
397 #ifdef CONFIG_ARCH_OMAP_OTG
400 omap_otg_init(struct omap_usb_config *config)
402 u32 syscon = OTG_SYSCON_1_REG & 0xffff;
404 int alt_pingroup = 0;
406 /* NOTE: no bus or clock setup (yet?) */
408 syscon = OTG_SYSCON_1_REG & 0xffff;
409 if (!(syscon & OTG_RESET_DONE))
410 pr_debug("USB resets not complete?\n");
412 // OTG_IRQ_EN_REG = 0;
414 /* pin muxing and transceiver pinouts */
415 if (config->pins[0] > 2) /* alt pingroup 2 */
417 syscon |= omap_usb0_init(config->pins[0], is_usb0_device(config));
418 syscon |= omap_usb1_init(config->pins[1]);
419 syscon |= omap_usb2_init(config->pins[2], alt_pingroup);
420 pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
421 OTG_SYSCON_1_REG = syscon;
423 syscon = config->hmc_mode;
424 syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
425 #ifdef CONFIG_USB_OTG
429 pr_debug("USB_TRANSCEIVER_CTRL_REG = %03x\n", USB_TRANSCEIVER_CTRL_REG);
430 pr_debug("OTG_SYSCON_2_REG = %08x\n", syscon);
431 OTG_SYSCON_2_REG = syscon;
433 printk("USB: hmc %d", config->hmc_mode);
435 printk(", usb2 alt %d wires", config->pins[2]);
436 else if (config->pins[0])
437 printk(", usb0 %d wires%s", config->pins[0],
438 is_usb0_device(config) ? " (dev)" : "");
440 printk(", usb1 %d wires", config->pins[1]);
441 if (!alt_pingroup && config->pins[2])
442 printk(", usb2 %d wires", config->pins[2]);
444 printk(", Mini-AB on usb%d", config->otg - 1);
447 /* leave USB clocks/controllers off until needed */
448 ULPD_SOFT_REQ_REG &= ~SOFT_USB_CLK_REQ;
449 ULPD_CLOCK_CTRL_REG &= ~USB_MCLK_EN;
450 ULPD_CLOCK_CTRL_REG |= DIS_USB_PVCI_CLK;
451 syscon = OTG_SYSCON_1_REG;
452 syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
454 #ifdef CONFIG_USB_GADGET_OMAP
455 if (config->otg || config->register_dev) {
456 syscon &= ~DEV_IDLE_EN;
457 udc_device.dev.platform_data = config;
458 /* FIXME patch IRQ numbers for omap730 */
459 status = platform_device_register(&udc_device);
461 pr_debug("can't register UDC device, %d\n", status);
465 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
466 if (config->otg || config->register_host) {
467 syscon &= ~HST_IDLE_EN;
468 ohci_device.dev.platform_data = config;
469 if (cpu_is_omap730())
470 ohci_resources[1].start = INT_730_USB_HHC_1;
471 status = platform_device_register(&ohci_device);
473 pr_debug("can't register OHCI device, %d\n", status);
477 #ifdef CONFIG_USB_OTG
479 syscon &= ~OTG_IDLE_EN;
480 otg_device.dev.platform_data = config;
481 if (cpu_is_omap730())
482 otg_resources[1].start = INT_730_USB_OTG;
483 status = platform_device_register(&otg_device);
485 pr_debug("can't register OTG device, %d\n", status);
488 pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
489 OTG_SYSCON_1_REG = syscon;
495 static inline void omap_otg_init(struct omap_usb_config *config) {}
498 /*-------------------------------------------------------------------------*/
500 #ifdef CONFIG_ARCH_OMAP15XX
502 #define ULPD_DPLL_CTRL_REG __REG16(ULPD_DPLL_CTRL)
503 #define DPLL_IOB (1 << 13)
504 #define DPLL_PLL_ENABLE (1 << 4)
505 #define DPLL_LOCK (1 << 0)
507 #define ULPD_APLL_CTRL_REG __REG16(ULPD_APLL_CTRL)
508 #define APLL_NDPLL_SWITCH (1 << 0)
511 static void __init omap_1510_usb_init(struct omap_usb_config *config)
515 omap_usb0_init(config->pins[0], is_usb0_device(config));
516 omap_usb1_init(config->pins[1]);
517 omap_usb2_init(config->pins[2], 0);
519 val = omap_readl(MOD_CONF_CTRL_0) & ~(0x3f << 1);
520 val |= (config->hmc_mode << 1);
521 omap_writel(val, MOD_CONF_CTRL_0);
523 printk("USB: hmc %d", config->hmc_mode);
525 printk(", usb0 %d wires%s", config->pins[0],
526 is_usb0_device(config) ? " (dev)" : "");
528 printk(", usb1 %d wires", config->pins[1]);
530 printk(", usb2 %d wires", config->pins[2]);
533 /* use DPLL for 48 MHz function clock */
534 pr_debug("APLL %04x DPLL %04x REQ %04x\n", ULPD_APLL_CTRL_REG,
535 ULPD_DPLL_CTRL_REG, ULPD_SOFT_REQ_REG);
536 ULPD_APLL_CTRL_REG &= ~APLL_NDPLL_SWITCH;
537 ULPD_DPLL_CTRL_REG |= DPLL_IOB | DPLL_PLL_ENABLE;
538 ULPD_SOFT_REQ_REG |= SOFT_UDC_REQ | SOFT_DPLL_REQ;
539 while (!(ULPD_DPLL_CTRL_REG & DPLL_LOCK))
542 #ifdef CONFIG_USB_GADGET_OMAP
543 if (config->register_dev) {
546 udc_device.dev.platform_data = config;
547 status = platform_device_register(&udc_device);
549 pr_debug("can't register UDC device, %d\n", status);
550 /* udc driver gates 48MHz by D+ pullup */
554 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
555 if (config->register_host) {
558 ohci_device.dev.platform_data = config;
559 status = platform_device_register(&ohci_device);
561 pr_debug("can't register OHCI device, %d\n", status);
562 /* hcd explicitly gates 48MHz */
568 static inline void omap_1510_usb_init(struct omap_usb_config *config) {}
571 /*-------------------------------------------------------------------------*/
573 static struct omap_usb_config platform_data;
578 const struct omap_usb_config *config;
580 config = omap_get_config(OMAP_TAG_USB, struct omap_usb_config);
581 if (config == NULL) {
582 printk(KERN_ERR "USB: No board-specific "
583 "platform config found\n");
586 platform_data = *config;
588 if (cpu_is_omap730() || cpu_is_omap16xx())
589 omap_otg_init(&platform_data);
590 else if (cpu_is_omap15xx())
591 omap_1510_usb_init(&platform_data);
593 printk(KERN_ERR "USB: No init for your chip yet\n");
599 subsys_initcall(omap_usb_init);