2 * arch/arm/mach-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 * - 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
58 /*-------------------------------------------------------------------------*/
60 #ifdef CONFIG_ARCH_OMAP_OTG
62 static struct otg_transceiver *xceiv;
65 * otg_get_transceiver - find the (single) OTG transceiver driver
67 * Returns the transceiver driver, after getting a refcount to it; or
68 * null if there is no such transceiver. The caller is responsible for
69 * releasing that count.
71 struct otg_transceiver *otg_get_transceiver(void)
74 get_device(xceiv->dev);
77 EXPORT_SYMBOL(otg_get_transceiver);
79 int otg_set_transceiver(struct otg_transceiver *x)
86 EXPORT_SYMBOL(otg_set_transceiver);
90 /*-------------------------------------------------------------------------*/
92 static u32 __init omap_usb0_init(unsigned nwires, unsigned is_device)
97 if (!cpu_is_omap15xx()) {
99 USB_TRANSCEIVER_CTRL_REG &= ~(3 << 1);
105 * VP and VM are needed for all active usb0 configurations.
106 * USB0_VP and USB0_VM are always set on 1510, there's no muxing
107 * available for them.
109 if (nwires >= 2 && !cpu_is_omap15xx()) {
110 omap_cfg_reg(AA9_USB0_VP);
111 omap_cfg_reg(R9_USB0_VM);
114 omap_cfg_reg(W4_USB_PUEN);
116 /* internal transceiver */
118 if (cpu_is_omap15xx()) {
119 /* This works for OHCI on 1510-Innovator */
123 /* NOTE: host OR device mode for now, no OTG */
124 USB_TRANSCEIVER_CTRL_REG &= ~(7 << 4);
126 omap_cfg_reg(R18_1510_USB_GPIO0);
127 // omap_cfg_reg(USB0_VBUS);
128 // USB_TRANSCEIVER_CTRL_REG.CONF_USB0_PORT_R = 7
129 } else /* host mode needs D+ and D- pulldowns */
130 USB_TRANSCEIVER_CTRL_REG &= ~(3 << 1);
135 /* alternate pin config, external transceiver */
136 omap_cfg_reg(V6_USB0_TXD);
137 omap_cfg_reg(W9_USB0_TXEN);
138 omap_cfg_reg(W5_USB0_SE0);
140 #ifdef CONFIG_ARCH_OMAP_USB_SPEED
141 /* FIXME: there's good chance that pin V9 is used for MMC2 port cmddir */
142 omap_cfg_reg(V9_USB0_SPEED);
143 // omap_cfg_reg(V9_USB0_SUSP);
147 omap_cfg_reg(Y5_USB0_RCV);
158 /* REVISIT: Is CONF_USB2_UNI_R only needed when nwires = 6? */
159 USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;
162 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
165 return syscon1 << 16;
168 static u32 __init omap_usb1_init(unsigned nwires)
172 if (nwires != 6 && !cpu_is_omap15xx())
173 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB1_UNI_R;
177 /* external transceiver */
178 omap_cfg_reg(USB1_TXD);
179 omap_cfg_reg(USB1_TXEN);
180 if (cpu_is_omap15xx()) {
181 omap_cfg_reg(USB1_SEO);
182 omap_cfg_reg(USB1_SPEED);
184 } else if (cpu_is_omap16xx()) {
185 omap_cfg_reg(W13_1610_USB1_SE0);
186 omap_cfg_reg(R13_1610_USB1_SPEED);
189 pr_debug("usb unrecognized\n");
192 omap_cfg_reg(USB1_RCV);
203 omap_cfg_reg(USB1_VP);
204 omap_cfg_reg(USB1_VM);
205 if (!cpu_is_omap15xx())
206 USB_TRANSCEIVER_CTRL_REG |= CONF_USB1_UNI_R;
209 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
212 return syscon1 << 20;
215 static u32 __init omap_usb2_init(unsigned nwires, unsigned alt_pingroup)
219 if (alt_pingroup || nwires == 0)
221 if (nwires != 6 && !cpu_is_omap15xx())
222 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB2_UNI_R;
226 /* external transceiver */
227 if (cpu_is_omap15xx()) {
228 omap_cfg_reg(USB2_TXD);
229 omap_cfg_reg(USB2_TXEN);
230 omap_cfg_reg(USB2_SEO);
232 omap_cfg_reg(USB2_RCV);
233 /* there is no USB2_SPEED */
234 } else if (cpu_is_omap16xx()) {
235 omap_cfg_reg(V6_USB2_TXD);
236 omap_cfg_reg(W9_USB2_TXEN);
237 omap_cfg_reg(W5_USB2_SE0);
239 omap_cfg_reg(Y5_USB2_RCV);
240 // FIXME omap_cfg_reg(USB2_SPEED);
242 pr_debug("usb unrecognized\n");
244 // omap_cfg_reg(USB2_SUSP);
255 if (cpu_is_omap15xx()) {
256 omap_cfg_reg(USB2_VP);
257 omap_cfg_reg(USB2_VM);
259 omap_cfg_reg(AA9_USB2_VP);
260 omap_cfg_reg(R9_USB2_VM);
261 USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;
265 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
268 return syscon1 << 24;
271 /*-------------------------------------------------------------------------*/
273 #if defined(CONFIG_USB_GADGET_OMAP) || \
274 defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) || \
275 (defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG))
276 static void usb_release(struct device *dev)
278 /* normally not freed */
282 #ifdef CONFIG_USB_GADGET_OMAP
284 static struct resource udc_resources[] = {
285 /* order is significant! */
287 .start = IO_ADDRESS(UDC_BASE),
288 .end = IO_ADDRESS(UDC_BASE + 0xff),
289 .flags = IORESOURCE_MEM,
290 }, { /* general IRQ */
291 .start = IH2_BASE + 20,
292 .flags = IORESOURCE_IRQ,
294 .start = IH2_BASE + 30,
295 .flags = IORESOURCE_IRQ,
297 .start = IH2_BASE + 29,
298 .flags = IORESOURCE_IRQ,
302 static u64 udc_dmamask = ~(u32)0;
304 static struct platform_device udc_device = {
308 .release = usb_release,
309 .dma_mask = &udc_dmamask,
310 .coherent_dma_mask = 0xffffffff,
312 .num_resources = ARRAY_SIZE(udc_resources),
313 .resource = udc_resources,
318 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
320 /* The dmamask must be set for OHCI to work */
321 static u64 ohci_dmamask = ~(u32)0;
323 static struct resource ohci_resources[] = {
325 .start = IO_ADDRESS(OMAP_OHCI_BASE),
326 .end = IO_ADDRESS(OMAP_OHCI_BASE + 4096),
327 .flags = IORESOURCE_MEM,
330 .start = INT_USB_HHC_1,
331 .flags = IORESOURCE_IRQ,
335 static struct platform_device ohci_device = {
339 .release = usb_release,
340 .dma_mask = &ohci_dmamask,
341 .coherent_dma_mask = 0xffffffff,
343 .num_resources = ARRAY_SIZE(ohci_resources),
344 .resource = ohci_resources,
349 #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
351 static struct resource otg_resources[] = {
352 /* order is significant! */
354 .start = IO_ADDRESS(OTG_BASE),
355 .end = IO_ADDRESS(OTG_BASE + 0xff),
356 .flags = IORESOURCE_MEM,
358 .start = IH2_BASE + 8,
359 .flags = IORESOURCE_IRQ,
363 static struct platform_device otg_device = {
367 .release = usb_release,
369 .num_resources = ARRAY_SIZE(otg_resources),
370 .resource = otg_resources,
375 /*-------------------------------------------------------------------------*/
377 // FIXME correct answer depends on hmc_mode,
378 // as does any nonzero value for config->otg port number
379 #ifdef CONFIG_USB_GADGET_OMAP
380 #define is_usb0_device(config) 1
382 #define is_usb0_device(config) 0
385 /*-------------------------------------------------------------------------*/
387 #ifdef CONFIG_ARCH_OMAP_OTG
390 omap_otg_init(struct omap_usb_config *config)
392 u32 syscon = OTG_SYSCON_1_REG & 0xffff;
394 int alt_pingroup = 0;
396 /* NOTE: no bus or clock setup (yet?) */
398 syscon = OTG_SYSCON_1_REG & 0xffff;
399 if (!(syscon & OTG_RESET_DONE))
400 pr_debug("USB resets not complete?\n");
402 // OTG_IRQ_EN_REG = 0;
404 /* pin muxing and transceiver pinouts */
405 if (config->pins[0] > 2) /* alt pingroup 2 */
407 syscon |= omap_usb0_init(config->pins[0], is_usb0_device(config));
408 syscon |= omap_usb1_init(config->pins[1]);
409 syscon |= omap_usb2_init(config->pins[2], alt_pingroup);
410 pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
411 OTG_SYSCON_1_REG = syscon;
413 syscon = config->hmc_mode;
414 syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
415 if (config->otg || config->register_host)
417 #ifdef CONFIG_USB_OTG
421 pr_debug("OTG_SYSCON_2_REG = %08x\n", syscon);
422 OTG_SYSCON_2_REG = syscon;
424 printk("USB: hmc %d", config->hmc_mode);
426 printk(", usb2 alt %d wires", config->pins[2]);
427 else if (config->pins[0])
428 printk(", usb0 %d wires%s", config->pins[0],
429 is_usb0_device(config) ? " (dev)" : "");
431 printk(", usb1 %d wires", config->pins[1]);
432 if (!alt_pingroup && config->pins[2])
433 printk(", usb2 %d wires", config->pins[2]);
435 printk(", Mini-AB on usb%d", config->otg - 1);
438 /* don't clock unused USB controllers */
439 syscon = OTG_SYSCON_1_REG;
440 syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
442 #ifdef CONFIG_USB_GADGET_OMAP
443 if (config->otg || config->register_dev) {
444 syscon &= ~DEV_IDLE_EN;
445 udc_device.dev.platform_data = config;
446 status = platform_device_register(&udc_device);
448 pr_debug("can't register UDC device, %d\n", status);
452 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
453 if (config->otg || config->register_host) {
454 syscon &= ~HST_IDLE_EN;
455 ohci_device.dev.platform_data = config;
456 status = platform_device_register(&ohci_device);
458 pr_debug("can't register OHCI device, %d\n", status);
462 #ifdef CONFIG_USB_OTG
464 syscon &= ~OTG_IDLE_EN;
465 if (cpu_is_omap730())
466 otg_resources[1].start = INT_730_USB_OTG;
467 status = platform_device_register(&otg_device);
471 pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
472 OTG_SYSCON_1_REG = syscon;
478 static inline void omap_otg_init(struct omap_usb_config *config) {}
481 /*-------------------------------------------------------------------------*/
483 #ifdef CONFIG_ARCH_OMAP1510
485 #define ULPD_SOFT_REQ_REG __REG16(ULPD_SOFT_REQ)
486 #define SOFT_UDC_REQ (1 << 4)
487 #define SOFT_DPLL_REQ (1 << 0)
489 #define ULPD_DPLL_CTRL_REG __REG16(ULPD_DPLL_CTRL)
490 #define DPLL_IOB (1 << 13)
491 #define DPLL_PLL_ENABLE (1 << 4)
492 #define DPLL_LOCK (1 << 0)
494 #define ULPD_APLL_CTRL_REG __REG16(ULPD_APLL_CTRL)
495 #define APLL_NDPLL_SWITCH (1 << 0)
498 static void __init omap_1510_usb_init(struct omap_usb_config *config)
503 omap_usb0_init(config->pins[0], is_usb0_device(config));
504 omap_usb1_init(config->pins[1]);
505 omap_usb2_init(config->pins[2], 0);
507 val = omap_readl(MOD_CONF_CTRL_0) & ~(0x3f << 1);
508 val |= (config->hmc_mode << 1);
509 omap_writel(val, MOD_CONF_CTRL_0);
511 printk("USB: hmc %d", config->hmc_mode);
513 printk(", usb0 %d wires%s", config->pins[0],
514 is_usb0_device(config) ? " (dev)" : "");
516 printk(", usb1 %d wires", config->pins[1]);
518 printk(", usb2 %d wires", config->pins[2]);
521 /* use DPLL for 48 MHz function clock */
522 pr_debug("APLL %04x DPLL %04x REQ %04x\n", ULPD_APLL_CTRL_REG,
523 ULPD_DPLL_CTRL_REG, ULPD_SOFT_REQ_REG);
524 ULPD_APLL_CTRL_REG &= ~APLL_NDPLL_SWITCH;
525 ULPD_DPLL_CTRL_REG |= DPLL_IOB | DPLL_PLL_ENABLE;
526 ULPD_SOFT_REQ_REG |= SOFT_UDC_REQ | SOFT_DPLL_REQ;
527 while (!(ULPD_DPLL_CTRL_REG & DPLL_LOCK))
530 #ifdef CONFIG_USB_GADGET_OMAP
531 if (config->register_dev) {
532 udc_device.dev.platform_data = config;
533 status = platform_device_register(&udc_device);
535 pr_debug("can't register UDC device, %d\n", status);
536 /* udc driver gates 48MHz by D+ pullup */
540 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
541 if (config->register_host) {
542 ohci_device.dev.platform_data = config;
543 status = platform_device_register(&ohci_device);
545 pr_debug("can't register OHCI device, %d\n", status);
546 /* hcd explicitly gates 48MHz */
553 static inline void omap_1510_usb_init(struct omap_usb_config *config) {}
556 /*-------------------------------------------------------------------------*/
558 static struct omap_usb_config platform_data;
563 const struct omap_usb_config *config;
565 config = omap_get_config(OMAP_TAG_USB, struct omap_usb_config);
566 if (config == NULL) {
567 printk(KERN_ERR "USB: No board-specific platform config found\n");
570 platform_data = *config;
572 if (cpu_is_omap730() || cpu_is_omap16xx())
573 omap_otg_init(&platform_data);
574 else if (cpu_is_omap15xx())
575 omap_1510_usb_init(&platform_data);
577 printk(KERN_ERR "USB: No init for your chip yet\n");
583 subsys_initcall(omap_usb_init);