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>
37 #include <asm/arch/mux.h>
38 #include <asm/arch/usb.h>
39 #include <asm/arch/board.h>
41 /* These routines should handle the standard chip-specific modes
42 * for usb0/1/2 ports, covering basic mux and transceiver setup.
43 * Call omap_usb_init() once, from INIT_MACHINE().
45 * Some board-*.c files will need to set up additional mux options,
46 * like for suspend handling, vbus sensing, GPIOs, and the D+ pullup.
50 * - 1611B H2 (with usb1 mini-AB) using standard Mini-B or OTG cables
51 * - 5912 OSK OHCI (with usb0 standard-A), standard A-to-B cables
52 * - 5912 OSK UDC, with *nonstandard* A-to-A cable
53 * - 1510 Innovator UDC with bundled usb0 cable
54 * - 1510 Innovator OHCI with bundled usb1/usb2 cable
55 * - 1510 Innovator OHCI with custom usb0 cable, feeding 5V VBUS
56 * - 1710 custom development board using alternate pin group
57 * - 1710 H3 (with usb1 mini-AB) using standard Mini-B or OTG cables
60 /*-------------------------------------------------------------------------*/
62 #ifdef CONFIG_ARCH_OMAP_OTG
64 static struct otg_transceiver *xceiv;
67 * otg_get_transceiver - find the (single) OTG transceiver driver
69 * Returns the transceiver driver, after getting a refcount to it; or
70 * null if there is no such transceiver. The caller is responsible for
71 * releasing that count.
73 struct otg_transceiver *otg_get_transceiver(void)
76 get_device(xceiv->dev);
79 EXPORT_SYMBOL(otg_get_transceiver);
81 int otg_set_transceiver(struct otg_transceiver *x)
88 EXPORT_SYMBOL(otg_set_transceiver);
92 /*-------------------------------------------------------------------------*/
94 static u32 __init omap_usb0_init(unsigned nwires, unsigned is_device)
99 if (!cpu_is_omap15xx()) {
101 USB_TRANSCEIVER_CTRL_REG &= ~(3 << 1);
107 omap_cfg_reg(W4_USB_PUEN);
109 /* internal transceiver */
111 // omap_cfg_reg(P9_USB_DP);
112 // omap_cfg_reg(R8_USB_DM);
114 if (cpu_is_omap15xx()) {
115 /* This works on 1510-Innovator */
120 * - peripheral should configure VBUS detection!
121 * - only peripherals may use the internal D+/D- pulldowns
122 * - OTG support on this port not yet written
125 USB_TRANSCEIVER_CTRL_REG &= ~(7 << 4);
127 USB_TRANSCEIVER_CTRL_REG |= (3 << 1);
132 /* alternate pin config, external transceiver */
133 if (cpu_is_omap15xx()) {
134 printk(KERN_ERR "no usb0 alt pin config on 15xx\n");
138 omap_cfg_reg(V6_USB0_TXD);
139 omap_cfg_reg(W9_USB0_TXEN);
140 omap_cfg_reg(W5_USB0_SE0);
142 /* NOTE: SPEED and SUSP aren't configured here */
145 omap_cfg_reg(Y5_USB0_RCV);
147 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB2_UNI_R;
158 omap_cfg_reg(AA9_USB0_VP);
159 omap_cfg_reg(R9_USB0_VM);
160 USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;
163 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
166 return syscon1 << 16;
169 static u32 __init omap_usb1_init(unsigned nwires)
173 if (nwires != 6 && !cpu_is_omap15xx())
174 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB1_UNI_R;
178 /* external transceiver */
179 omap_cfg_reg(USB1_TXD);
180 omap_cfg_reg(USB1_TXEN);
181 if (cpu_is_omap15xx()) {
182 omap_cfg_reg(USB1_SEO);
183 omap_cfg_reg(USB1_SPEED);
185 } else if (cpu_is_omap1610() || cpu_is_omap5912()) {
186 omap_cfg_reg(W13_1610_USB1_SE0);
187 omap_cfg_reg(R13_1610_USB1_SPEED);
189 } else if (cpu_is_omap1710()) {
190 omap_cfg_reg(R13_1710_USB1_SE0);
193 pr_debug("usb unrecognized\n");
196 omap_cfg_reg(USB1_RCV);
207 omap_cfg_reg(USB1_VP);
208 omap_cfg_reg(USB1_VM);
209 if (!cpu_is_omap15xx())
210 USB_TRANSCEIVER_CTRL_REG |= CONF_USB1_UNI_R;
213 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
216 return syscon1 << 20;
219 static u32 __init omap_usb2_init(unsigned nwires, unsigned alt_pingroup)
223 /* NOTE erratum: must leave USB2_UNI_R set if usb0 in use */
224 if (alt_pingroup || nwires == 0)
226 if (nwires != 6 && !cpu_is_omap15xx())
227 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB2_UNI_R;
229 /* external transceiver */
230 if (cpu_is_omap15xx()) {
231 omap_cfg_reg(USB2_TXD);
232 omap_cfg_reg(USB2_TXEN);
233 omap_cfg_reg(USB2_SEO);
235 omap_cfg_reg(USB2_RCV);
236 /* there is no USB2_SPEED */
237 } else if (cpu_is_omap16xx()) {
238 omap_cfg_reg(V6_USB2_TXD);
239 omap_cfg_reg(W9_USB2_TXEN);
240 omap_cfg_reg(W5_USB2_SE0);
242 omap_cfg_reg(Y5_USB2_RCV);
243 // FIXME omap_cfg_reg(USB2_SPEED);
245 pr_debug("usb unrecognized\n");
247 // omap_cfg_reg(USB2_SUSP);
258 if (cpu_is_omap15xx()) {
259 omap_cfg_reg(USB2_VP);
260 omap_cfg_reg(USB2_VM);
262 omap_cfg_reg(AA9_USB2_VP);
263 omap_cfg_reg(R9_USB2_VM);
264 USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;
268 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
271 return syscon1 << 24;
274 /*-------------------------------------------------------------------------*/
276 #if defined(CONFIG_USB_GADGET_OMAP) || \
277 defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) || \
278 (defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG))
279 static void usb_release(struct device *dev)
281 /* normally not freed */
285 #ifdef CONFIG_USB_GADGET_OMAP
287 static struct resource udc_resources[] = {
288 /* order is significant! */
291 .end = UDC_BASE + 0xff,
292 .flags = IORESOURCE_MEM,
293 }, { /* general IRQ */
294 .start = IH2_BASE + 20,
295 .flags = IORESOURCE_IRQ,
297 .start = IH2_BASE + 30,
298 .flags = IORESOURCE_IRQ,
300 .start = IH2_BASE + 29,
301 .flags = IORESOURCE_IRQ,
305 static u64 udc_dmamask = ~(u32)0;
307 static struct platform_device udc_device = {
311 .release = usb_release,
312 .dma_mask = &udc_dmamask,
313 .coherent_dma_mask = 0xffffffff,
315 .num_resources = ARRAY_SIZE(udc_resources),
316 .resource = udc_resources,
321 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
323 /* The dmamask must be set for OHCI to work */
324 static u64 ohci_dmamask = ~(u32)0;
326 static struct resource ohci_resources[] = {
328 .start = OMAP_OHCI_BASE,
329 .end = OMAP_OHCI_BASE + 4096 - 1,
330 .flags = IORESOURCE_MEM,
333 .start = INT_USB_HHC_1,
334 .flags = IORESOURCE_IRQ,
338 static struct platform_device ohci_device = {
342 .release = usb_release,
343 .dma_mask = &ohci_dmamask,
344 .coherent_dma_mask = 0xffffffff,
346 .num_resources = ARRAY_SIZE(ohci_resources),
347 .resource = ohci_resources,
352 #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
354 static struct resource otg_resources[] = {
355 /* order is significant! */
358 .end = OTG_BASE + 0xff,
359 .flags = IORESOURCE_MEM,
361 .start = IH2_BASE + 8,
362 .flags = IORESOURCE_IRQ,
366 static struct platform_device otg_device = {
370 .release = usb_release,
372 .num_resources = ARRAY_SIZE(otg_resources),
373 .resource = otg_resources,
378 /*-------------------------------------------------------------------------*/
380 #define ULPD_CLOCK_CTRL_REG __REG16(ULPD_CLOCK_CTRL)
381 #define ULPD_SOFT_REQ_REG __REG16(ULPD_SOFT_REQ)
384 // FIXME correct answer depends on hmc_mode,
385 // as does any nonzero value for config->otg port number
386 #ifdef CONFIG_USB_GADGET_OMAP
387 #define is_usb0_device(config) 1
389 #define is_usb0_device(config) 0
392 /*-------------------------------------------------------------------------*/
394 #ifdef CONFIG_ARCH_OMAP_OTG
397 omap_otg_init(struct omap_usb_config *config)
399 u32 syscon = OTG_SYSCON_1_REG & 0xffff;
401 int alt_pingroup = 0;
403 /* NOTE: no bus or clock setup (yet?) */
405 syscon = OTG_SYSCON_1_REG & 0xffff;
406 if (!(syscon & OTG_RESET_DONE))
407 pr_debug("USB resets not complete?\n");
409 // OTG_IRQ_EN_REG = 0;
411 /* pin muxing and transceiver pinouts */
412 if (config->pins[0] > 2) /* alt pingroup 2 */
414 syscon |= omap_usb0_init(config->pins[0], is_usb0_device(config));
415 syscon |= omap_usb1_init(config->pins[1]);
416 syscon |= omap_usb2_init(config->pins[2], alt_pingroup);
417 pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
418 OTG_SYSCON_1_REG = syscon;
420 syscon = config->hmc_mode;
421 syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
422 #ifdef CONFIG_USB_OTG
426 pr_debug("USB_TRANSCEIVER_CTRL_REG = %03x\n", USB_TRANSCEIVER_CTRL_REG);
427 pr_debug("OTG_SYSCON_2_REG = %08x\n", syscon);
428 OTG_SYSCON_2_REG = syscon;
430 printk("USB: hmc %d", config->hmc_mode);
432 printk(", usb2 alt %d wires", config->pins[2]);
433 else if (config->pins[0])
434 printk(", usb0 %d wires%s", config->pins[0],
435 is_usb0_device(config) ? " (dev)" : "");
437 printk(", usb1 %d wires", config->pins[1]);
438 if (!alt_pingroup && config->pins[2])
439 printk(", usb2 %d wires", config->pins[2]);
441 printk(", Mini-AB on usb%d", config->otg - 1);
444 /* leave USB clocks/controllers off until needed */
445 ULPD_SOFT_REQ_REG &= ~SOFT_USB_CLK_REQ;
446 ULPD_CLOCK_CTRL_REG &= ~USB_MCLK_EN;
447 ULPD_CLOCK_CTRL_REG |= DIS_USB_PVCI_CLK;
448 syscon = OTG_SYSCON_1_REG;
449 syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
451 #ifdef CONFIG_USB_GADGET_OMAP
452 if (config->otg || config->register_dev) {
453 syscon &= ~DEV_IDLE_EN;
454 udc_device.dev.platform_data = config;
455 /* FIXME patch IRQ numbers for omap730 */
456 status = platform_device_register(&udc_device);
458 pr_debug("can't register UDC device, %d\n", status);
462 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
463 if (config->otg || config->register_host) {
464 syscon &= ~HST_IDLE_EN;
465 ohci_device.dev.platform_data = config;
466 if (cpu_is_omap730())
467 ohci_resources[1].start = INT_730_USB_HHC_1;
468 status = platform_device_register(&ohci_device);
470 pr_debug("can't register OHCI device, %d\n", status);
474 #ifdef CONFIG_USB_OTG
476 syscon &= ~OTG_IDLE_EN;
477 otg_device.dev.platform_data = config;
478 if (cpu_is_omap730())
479 otg_resources[1].start = INT_730_USB_OTG;
480 status = platform_device_register(&otg_device);
482 pr_debug("can't register OTG device, %d\n", status);
485 pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
486 OTG_SYSCON_1_REG = syscon;
492 static inline void omap_otg_init(struct omap_usb_config *config) {}
495 /*-------------------------------------------------------------------------*/
497 #ifdef CONFIG_ARCH_OMAP1510
499 #define ULPD_DPLL_CTRL_REG __REG16(ULPD_DPLL_CTRL)
500 #define DPLL_IOB (1 << 13)
501 #define DPLL_PLL_ENABLE (1 << 4)
502 #define DPLL_LOCK (1 << 0)
504 #define ULPD_APLL_CTRL_REG __REG16(ULPD_APLL_CTRL)
505 #define APLL_NDPLL_SWITCH (1 << 0)
508 static void __init omap_1510_usb_init(struct omap_usb_config *config)
513 omap_usb0_init(config->pins[0], is_usb0_device(config));
514 omap_usb1_init(config->pins[1]);
515 omap_usb2_init(config->pins[2], 0);
517 val = omap_readl(MOD_CONF_CTRL_0) & ~(0x3f << 1);
518 val |= (config->hmc_mode << 1);
519 omap_writel(val, MOD_CONF_CTRL_0);
521 printk("USB: hmc %d", config->hmc_mode);
523 printk(", usb0 %d wires%s", config->pins[0],
524 is_usb0_device(config) ? " (dev)" : "");
526 printk(", usb1 %d wires", config->pins[1]);
528 printk(", usb2 %d wires", config->pins[2]);
531 /* use DPLL for 48 MHz function clock */
532 pr_debug("APLL %04x DPLL %04x REQ %04x\n", ULPD_APLL_CTRL_REG,
533 ULPD_DPLL_CTRL_REG, ULPD_SOFT_REQ_REG);
534 ULPD_APLL_CTRL_REG &= ~APLL_NDPLL_SWITCH;
535 ULPD_DPLL_CTRL_REG |= DPLL_IOB | DPLL_PLL_ENABLE;
536 ULPD_SOFT_REQ_REG |= SOFT_UDC_REQ | SOFT_DPLL_REQ;
537 while (!(ULPD_DPLL_CTRL_REG & DPLL_LOCK))
540 #ifdef CONFIG_USB_GADGET_OMAP
541 if (config->register_dev) {
542 udc_device.dev.platform_data = config;
543 status = platform_device_register(&udc_device);
545 pr_debug("can't register UDC device, %d\n", status);
546 /* udc driver gates 48MHz by D+ pullup */
550 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
551 if (config->register_host) {
552 ohci_device.dev.platform_data = config;
553 status = platform_device_register(&ohci_device);
555 pr_debug("can't register OHCI device, %d\n", status);
556 /* hcd explicitly gates 48MHz */
562 static inline void omap_1510_usb_init(struct omap_usb_config *config) {}
565 /*-------------------------------------------------------------------------*/
567 static struct omap_usb_config platform_data;
572 const struct omap_usb_config *config;
574 config = omap_get_config(OMAP_TAG_USB, struct omap_usb_config);
575 if (config == NULL) {
576 printk(KERN_ERR "USB: No board-specific "
577 "platform config found\n");
580 platform_data = *config;
582 if (cpu_is_omap730() || cpu_is_omap16xx())
583 omap_otg_init(&platform_data);
584 else if (cpu_is_omap15xx())
585 omap_1510_usb_init(&platform_data);
587 printk(KERN_ERR "USB: No init for your chip yet\n");
593 subsys_initcall(omap_usb_init);