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/config.h>
24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/types.h>
27 #include <linux/errno.h>
28 #include <linux/init.h>
29 #include <linux/device.h>
30 #include <linux/usb_otg.h>
34 #include <asm/system.h>
35 #include <asm/hardware.h>
36 #include <asm/mach-types.h>
38 #include <asm/arch/mux.h>
39 #include <asm/arch/usb.h>
40 #include <asm/arch/board.h>
42 /* These routines should handle the standard chip-specific modes
43 * for usb0/1/2 ports, covering basic mux and transceiver setup.
44 * Call omap_usb_init() once, from INIT_MACHINE().
46 * Some board-*.c files will need to set up additional mux options,
47 * like for suspend handling, vbus sensing, GPIOs, and the D+ pullup.
51 * - 1611B H2 (with usb1 mini-AB) using standard Mini-B or OTG cables
52 * - 5912 OSK OHCI (with usb0 standard-A), standard A-to-B cables
53 * - 5912 OSK UDC, with *nonstandard* A-to-A cable
54 * - 1510 Innovator UDC with bundled usb0 cable
55 * - 1510 Innovator OHCI with bundled usb1/usb2 cable
56 * - 1510 Innovator OHCI with custom usb0 cable, feeding 5V VBUS
57 * - 1710 custom development board using alternate pin group
58 * - 1710 H3 (with usb1 mini-AB) using standard Mini-B or OTG cables
61 /*-------------------------------------------------------------------------*/
63 #ifdef CONFIG_ARCH_OMAP_OTG
65 static struct otg_transceiver *xceiv;
68 * otg_get_transceiver - find the (single) OTG transceiver driver
70 * Returns the transceiver driver, after getting a refcount to it; or
71 * null if there is no such transceiver. The caller is responsible for
72 * releasing that count.
74 struct otg_transceiver *otg_get_transceiver(void)
77 get_device(xceiv->dev);
80 EXPORT_SYMBOL(otg_get_transceiver);
82 int otg_set_transceiver(struct otg_transceiver *x)
89 EXPORT_SYMBOL(otg_set_transceiver);
93 /*-------------------------------------------------------------------------*/
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;
275 /*-------------------------------------------------------------------------*/
277 #if defined(CONFIG_USB_GADGET_OMAP) || \
278 defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) || \
279 (defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG))
280 static void usb_release(struct device *dev)
282 /* normally not freed */
286 #ifdef CONFIG_USB_GADGET_OMAP
288 static struct resource udc_resources[] = {
289 /* order is significant! */
292 .end = UDC_BASE + 0xff,
293 .flags = IORESOURCE_MEM,
294 }, { /* general IRQ */
295 .start = IH2_BASE + 20,
296 .flags = IORESOURCE_IRQ,
298 .start = IH2_BASE + 30,
299 .flags = IORESOURCE_IRQ,
301 .start = IH2_BASE + 29,
302 .flags = IORESOURCE_IRQ,
306 static u64 udc_dmamask = ~(u32)0;
308 static struct platform_device udc_device = {
312 .release = usb_release,
313 .dma_mask = &udc_dmamask,
314 .coherent_dma_mask = 0xffffffff,
316 .num_resources = ARRAY_SIZE(udc_resources),
317 .resource = udc_resources,
322 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
324 /* The dmamask must be set for OHCI to work */
325 static u64 ohci_dmamask = ~(u32)0;
327 static struct resource ohci_resources[] = {
329 .start = OMAP_OHCI_BASE,
330 .end = OMAP_OHCI_BASE + 4096 - 1,
331 .flags = IORESOURCE_MEM,
334 .start = INT_USB_HHC_1,
335 .flags = IORESOURCE_IRQ,
339 static struct platform_device ohci_device = {
343 .release = usb_release,
344 .dma_mask = &ohci_dmamask,
345 .coherent_dma_mask = 0xffffffff,
347 .num_resources = ARRAY_SIZE(ohci_resources),
348 .resource = ohci_resources,
353 #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
355 static struct resource otg_resources[] = {
356 /* order is significant! */
359 .end = OTG_BASE + 0xff,
360 .flags = IORESOURCE_MEM,
362 .start = IH2_BASE + 8,
363 .flags = IORESOURCE_IRQ,
367 static struct platform_device otg_device = {
371 .release = usb_release,
373 .num_resources = ARRAY_SIZE(otg_resources),
374 .resource = otg_resources,
379 /*-------------------------------------------------------------------------*/
381 #define ULPD_CLOCK_CTRL_REG __REG16(ULPD_CLOCK_CTRL)
382 #define ULPD_SOFT_REQ_REG __REG16(ULPD_SOFT_REQ)
385 // FIXME correct answer depends on hmc_mode,
386 // as does any nonzero value for config->otg port number
387 #ifdef CONFIG_USB_GADGET_OMAP
388 #define is_usb0_device(config) 1
390 #define is_usb0_device(config) 0
393 /*-------------------------------------------------------------------------*/
395 #ifdef CONFIG_ARCH_OMAP_OTG
398 omap_otg_init(struct omap_usb_config *config)
400 u32 syscon = OTG_SYSCON_1_REG & 0xffff;
402 int alt_pingroup = 0;
404 /* NOTE: no bus or clock setup (yet?) */
406 syscon = OTG_SYSCON_1_REG & 0xffff;
407 if (!(syscon & OTG_RESET_DONE))
408 pr_debug("USB resets not complete?\n");
410 // OTG_IRQ_EN_REG = 0;
412 /* pin muxing and transceiver pinouts */
413 if (config->pins[0] > 2) /* alt pingroup 2 */
415 syscon |= omap_usb0_init(config->pins[0], is_usb0_device(config));
416 syscon |= omap_usb1_init(config->pins[1]);
417 syscon |= omap_usb2_init(config->pins[2], alt_pingroup);
418 pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
419 OTG_SYSCON_1_REG = syscon;
421 syscon = config->hmc_mode;
422 syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
423 #ifdef CONFIG_USB_OTG
427 pr_debug("USB_TRANSCEIVER_CTRL_REG = %03x\n", USB_TRANSCEIVER_CTRL_REG);
428 pr_debug("OTG_SYSCON_2_REG = %08x\n", syscon);
429 OTG_SYSCON_2_REG = syscon;
431 printk("USB: hmc %d", config->hmc_mode);
433 printk(", usb2 alt %d wires", config->pins[2]);
434 else if (config->pins[0])
435 printk(", usb0 %d wires%s", config->pins[0],
436 is_usb0_device(config) ? " (dev)" : "");
438 printk(", usb1 %d wires", config->pins[1]);
439 if (!alt_pingroup && config->pins[2])
440 printk(", usb2 %d wires", config->pins[2]);
442 printk(", Mini-AB on usb%d", config->otg - 1);
445 /* leave USB clocks/controllers off until needed */
446 ULPD_SOFT_REQ_REG &= ~SOFT_USB_CLK_REQ;
447 ULPD_CLOCK_CTRL_REG &= ~USB_MCLK_EN;
448 ULPD_CLOCK_CTRL_REG |= DIS_USB_PVCI_CLK;
449 syscon = OTG_SYSCON_1_REG;
450 syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
452 #ifdef CONFIG_USB_GADGET_OMAP
453 if (config->otg || config->register_dev) {
454 syscon &= ~DEV_IDLE_EN;
455 udc_device.dev.platform_data = config;
456 /* FIXME patch IRQ numbers for omap730 */
457 status = platform_device_register(&udc_device);
459 pr_debug("can't register UDC device, %d\n", status);
463 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
464 if (config->otg || config->register_host) {
465 syscon &= ~HST_IDLE_EN;
466 ohci_device.dev.platform_data = config;
467 if (cpu_is_omap730())
468 ohci_resources[1].start = INT_730_USB_HHC_1;
469 status = platform_device_register(&ohci_device);
471 pr_debug("can't register OHCI device, %d\n", status);
475 #ifdef CONFIG_USB_OTG
477 syscon &= ~OTG_IDLE_EN;
478 otg_device.dev.platform_data = config;
479 if (cpu_is_omap730())
480 otg_resources[1].start = INT_730_USB_OTG;
481 status = platform_device_register(&otg_device);
483 pr_debug("can't register OTG device, %d\n", status);
486 pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
487 OTG_SYSCON_1_REG = syscon;
493 static inline void omap_otg_init(struct omap_usb_config *config) {}
496 /*-------------------------------------------------------------------------*/
498 #ifdef CONFIG_ARCH_OMAP1510
500 #define ULPD_DPLL_CTRL_REG __REG16(ULPD_DPLL_CTRL)
501 #define DPLL_IOB (1 << 13)
502 #define DPLL_PLL_ENABLE (1 << 4)
503 #define DPLL_LOCK (1 << 0)
505 #define ULPD_APLL_CTRL_REG __REG16(ULPD_APLL_CTRL)
506 #define APLL_NDPLL_SWITCH (1 << 0)
509 static void __init omap_1510_usb_init(struct omap_usb_config *config)
514 omap_usb0_init(config->pins[0], is_usb0_device(config));
515 omap_usb1_init(config->pins[1]);
516 omap_usb2_init(config->pins[2], 0);
518 val = omap_readl(MOD_CONF_CTRL_0) & ~(0x3f << 1);
519 val |= (config->hmc_mode << 1);
520 omap_writel(val, MOD_CONF_CTRL_0);
522 printk("USB: hmc %d", config->hmc_mode);
524 printk(", usb0 %d wires%s", config->pins[0],
525 is_usb0_device(config) ? " (dev)" : "");
527 printk(", usb1 %d wires", config->pins[1]);
529 printk(", usb2 %d wires", config->pins[2]);
532 /* use DPLL for 48 MHz function clock */
533 pr_debug("APLL %04x DPLL %04x REQ %04x\n", ULPD_APLL_CTRL_REG,
534 ULPD_DPLL_CTRL_REG, ULPD_SOFT_REQ_REG);
535 ULPD_APLL_CTRL_REG &= ~APLL_NDPLL_SWITCH;
536 ULPD_DPLL_CTRL_REG |= DPLL_IOB | DPLL_PLL_ENABLE;
537 ULPD_SOFT_REQ_REG |= SOFT_UDC_REQ | SOFT_DPLL_REQ;
538 while (!(ULPD_DPLL_CTRL_REG & DPLL_LOCK))
541 #ifdef CONFIG_USB_GADGET_OMAP
542 if (config->register_dev) {
543 udc_device.dev.platform_data = config;
544 status = platform_device_register(&udc_device);
546 pr_debug("can't register UDC device, %d\n", status);
547 /* udc driver gates 48MHz by D+ pullup */
551 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
552 if (config->register_host) {
553 ohci_device.dev.platform_data = config;
554 status = platform_device_register(&ohci_device);
556 pr_debug("can't register OHCI device, %d\n", status);
557 /* hcd explicitly gates 48MHz */
563 static inline void omap_1510_usb_init(struct omap_usb_config *config) {}
566 /*-------------------------------------------------------------------------*/
568 static struct omap_usb_config platform_data;
573 const struct omap_usb_config *config;
575 config = omap_get_config(OMAP_TAG_USB, struct omap_usb_config);
576 if (config == NULL) {
577 printk(KERN_ERR "USB: No board-specific "
578 "platform config found\n");
581 platform_data = *config;
583 if (cpu_is_omap730() || cpu_is_omap16xx())
584 omap_otg_init(&platform_data);
585 else if (cpu_is_omap15xx())
586 omap_1510_usb_init(&platform_data);
588 printk(KERN_ERR "USB: No init for your chip yet\n");
594 subsys_initcall(omap_usb_init);