2 * Platform level USB initialization for FS USB OTG controller on omap1 and 24xx
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
21 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/init.h>
24 #include <linux/platform_device.h>
34 /* These routines should handle the standard chip-specific modes
35 * for usb0/1/2 ports, covering basic mux and transceiver setup.
37 * Some board-*.c files will need to set up additional mux options,
38 * like for suspend handling, vbus sensing, GPIOs, and the D+ pullup.
42 * - 1611B H2 (with usb1 mini-AB) using standard Mini-B or OTG cables
43 * - 5912 OSK OHCI (with usb0 standard-A), standard A-to-B cables
44 * - 5912 OSK UDC, with *nonstandard* A-to-A cable
45 * - 1510 Innovator UDC with bundled usb0 cable
46 * - 1510 Innovator OHCI with bundled usb1/usb2 cable
47 * - 1510 Innovator OHCI with custom usb0 cable, feeding 5V VBUS
48 * - 1710 custom development board using alternate pin group
49 * - 1710 H3 (with usb1 mini-AB) using standard Mini-B or OTG cables
52 #define INT_USB_IRQ_GEN IH2_BASE + 20
53 #define INT_USB_IRQ_NISO IH2_BASE + 30
54 #define INT_USB_IRQ_ISO IH2_BASE + 29
55 #define INT_USB_IRQ_HGEN INT_USB_HHC_1
56 #define INT_USB_IRQ_OTG IH2_BASE + 8
58 #ifdef CONFIG_USB_GADGET_OMAP
60 static struct resource udc_resources[] = {
61 /* order is significant! */
64 .end = UDC_BASE + 0xff,
65 .flags = IORESOURCE_MEM,
66 }, { /* general IRQ */
67 .start = INT_USB_IRQ_GEN,
68 .flags = IORESOURCE_IRQ,
70 .start = INT_USB_IRQ_NISO,
71 .flags = IORESOURCE_IRQ,
73 .start = INT_USB_IRQ_ISO,
74 .flags = IORESOURCE_IRQ,
78 static u64 udc_dmamask = ~(u32)0;
80 static struct platform_device udc_device = {
84 .dma_mask = &udc_dmamask,
85 .coherent_dma_mask = 0xffffffff,
87 .num_resources = ARRAY_SIZE(udc_resources),
88 .resource = udc_resources,
91 static inline void udc_device_init(struct omap_usb_config *pdata)
93 /* IRQ numbers for omap7xx */
94 if(cpu_is_omap7xx()) {
95 udc_resources[1].start = INT_7XX_USB_GENI;
96 udc_resources[2].start = INT_7XX_USB_NON_ISO;
97 udc_resources[3].start = INT_7XX_USB_ISO;
99 pdata->udc_device = &udc_device;
104 static inline void udc_device_init(struct omap_usb_config *pdata)
110 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
112 /* The dmamask must be set for OHCI to work */
113 static u64 ohci_dmamask = ~(u32)0;
115 static struct resource ohci_resources[] = {
117 .start = OMAP_OHCI_BASE,
118 .end = OMAP_OHCI_BASE + 0xff,
119 .flags = IORESOURCE_MEM,
122 .start = INT_USB_IRQ_HGEN,
123 .flags = IORESOURCE_IRQ,
127 static struct platform_device ohci_device = {
131 .dma_mask = &ohci_dmamask,
132 .coherent_dma_mask = 0xffffffff,
134 .num_resources = ARRAY_SIZE(ohci_resources),
135 .resource = ohci_resources,
138 static inline void ohci_device_init(struct omap_usb_config *pdata)
140 if (cpu_is_omap7xx())
141 ohci_resources[1].start = INT_7XX_USB_HHC_1;
142 pdata->ohci_device = &ohci_device;
143 pdata->ocpi_enable = &ocpi_enable;
148 static inline void ohci_device_init(struct omap_usb_config *pdata)
154 #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
156 static struct resource otg_resources[] = {
157 /* order is significant! */
160 .end = OTG_BASE + 0xff,
161 .flags = IORESOURCE_MEM,
163 .start = INT_USB_IRQ_OTG,
164 .flags = IORESOURCE_IRQ,
168 static struct platform_device otg_device = {
171 .num_resources = ARRAY_SIZE(otg_resources),
172 .resource = otg_resources,
175 static inline void otg_device_init(struct omap_usb_config *pdata)
177 if (cpu_is_omap7xx())
178 otg_resources[1].start = INT_7XX_USB_OTG;
179 pdata->otg_device = &otg_device;
184 static inline void otg_device_init(struct omap_usb_config *pdata)
190 u32 __init omap1_usb0_init(unsigned nwires, unsigned is_device)
195 if (!cpu_is_omap15xx()) {
199 l = omap_readl(USB_TRANSCEIVER_CTRL);
201 omap_writel(l, USB_TRANSCEIVER_CTRL);
207 if (cpu_is_omap7xx()) {
208 omap_cfg_reg(AA17_7XX_USB_DM);
209 omap_cfg_reg(W16_7XX_USB_PU_EN);
210 omap_cfg_reg(W17_7XX_USB_VBUSI);
211 omap_cfg_reg(W18_7XX_USB_DMCK_OUT);
212 omap_cfg_reg(W19_7XX_USB_DCRST);
214 omap_cfg_reg(W4_USB_PUEN);
220 // omap_cfg_reg(P9_USB_DP);
221 // omap_cfg_reg(R8_USB_DM);
223 if (cpu_is_omap15xx()) {
224 /* This works on 1510-Innovator */
229 * - peripheral should configure VBUS detection!
230 * - only peripherals may use the internal D+/D- pulldowns
231 * - OTG support on this port not yet written
234 /* Don't do this for omap7xx -- it causes USB to not work correctly */
235 if (!cpu_is_omap7xx()) {
236 l = omap_readl(USB_TRANSCEIVER_CTRL);
240 omap_writel(l, USB_TRANSCEIVER_CTRL);
246 /* alternate pin config, external transceiver */
247 if (cpu_is_omap15xx()) {
248 printk(KERN_ERR "no usb0 alt pin config on 15xx\n");
252 omap_cfg_reg(V6_USB0_TXD);
253 omap_cfg_reg(W9_USB0_TXEN);
254 omap_cfg_reg(W5_USB0_SE0);
256 omap_cfg_reg(Y5_USB0_RCV);
258 /* NOTE: SPEED and SUSP aren't configured here. OTG hosts
259 * may be able to use I2C requests to set those bits along
260 * with VBUS switching and overcurrent detection.
266 l = omap_readl(USB_TRANSCEIVER_CTRL);
267 l &= ~CONF_USB2_UNI_R;
268 omap_writel(l, USB_TRANSCEIVER_CTRL);
283 omap_cfg_reg(AA9_USB0_VP);
284 omap_cfg_reg(R9_USB0_VM);
285 l = omap_readl(USB_TRANSCEIVER_CTRL);
286 l |= CONF_USB2_UNI_R;
287 omap_writel(l, USB_TRANSCEIVER_CTRL);
291 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
295 return syscon1 << 16;
298 u32 __init omap1_usb1_init(unsigned nwires)
302 if (!cpu_is_omap15xx() && nwires != 6) {
305 l = omap_readl(USB_TRANSCEIVER_CTRL);
306 l &= ~CONF_USB1_UNI_R;
307 omap_writel(l, USB_TRANSCEIVER_CTRL);
312 /* external transceiver */
313 omap_cfg_reg(USB1_TXD);
314 omap_cfg_reg(USB1_TXEN);
316 omap_cfg_reg(USB1_RCV);
318 if (cpu_is_omap15xx()) {
319 omap_cfg_reg(USB1_SEO);
320 omap_cfg_reg(USB1_SPEED);
322 } else if (cpu_is_omap1610() || cpu_is_omap5912()) {
323 omap_cfg_reg(W13_1610_USB1_SE0);
324 omap_cfg_reg(R13_1610_USB1_SPEED);
326 } else if (cpu_is_omap1710()) {
327 omap_cfg_reg(R13_1710_USB1_SE0);
330 pr_debug("usb%d cpu unrecognized\n", 1);
345 omap_cfg_reg(USB1_VP);
346 omap_cfg_reg(USB1_VM);
347 if (!cpu_is_omap15xx()) {
350 l = omap_readl(USB_TRANSCEIVER_CTRL);
351 l |= CONF_USB1_UNI_R;
352 omap_writel(l, USB_TRANSCEIVER_CTRL);
357 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
361 return syscon1 << 20;
364 u32 __init omap1_usb2_init(unsigned nwires, unsigned alt_pingroup)
368 /* NOTE omap1 erratum: must leave USB2_UNI_R set if usb0 in use */
369 if (alt_pingroup || nwires == 0)
372 if (!cpu_is_omap15xx() && nwires != 6) {
375 l = omap_readl(USB_TRANSCEIVER_CTRL);
376 l &= ~CONF_USB2_UNI_R;
377 omap_writel(l, USB_TRANSCEIVER_CTRL);
380 /* external transceiver */
381 if (cpu_is_omap15xx()) {
382 omap_cfg_reg(USB2_TXD);
383 omap_cfg_reg(USB2_TXEN);
384 omap_cfg_reg(USB2_SEO);
386 omap_cfg_reg(USB2_RCV);
387 /* there is no USB2_SPEED */
388 } else if (cpu_is_omap16xx()) {
389 omap_cfg_reg(V6_USB2_TXD);
390 omap_cfg_reg(W9_USB2_TXEN);
391 omap_cfg_reg(W5_USB2_SE0);
393 omap_cfg_reg(Y5_USB2_RCV);
394 // FIXME omap_cfg_reg(USB2_SPEED);
396 pr_debug("usb%d cpu unrecognized\n", 1);
400 // omap_cfg_reg(USB2_SUSP);
415 if (cpu_is_omap15xx()) {
416 omap_cfg_reg(USB2_VP);
417 omap_cfg_reg(USB2_VM);
421 omap_cfg_reg(AA9_USB2_VP);
422 omap_cfg_reg(R9_USB2_VM);
423 l = omap_readl(USB_TRANSCEIVER_CTRL);
424 l |= CONF_USB2_UNI_R;
425 omap_writel(l, USB_TRANSCEIVER_CTRL);
430 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
434 return syscon1 << 24;
437 #ifdef CONFIG_ARCH_OMAP15XX
440 #define DPLL_IOB (1 << 13)
441 #define DPLL_PLL_ENABLE (1 << 4)
442 #define DPLL_LOCK (1 << 0)
445 #define APLL_NDPLL_SWITCH (1 << 0)
447 static void __init omap_1510_usb_init(struct omap_usb_config *config)
452 config->usb0_init(config->pins[0], is_usb0_device(config));
453 config->usb1_init(config->pins[1]);
454 config->usb2_init(config->pins[2], 0);
456 val = omap_readl(MOD_CONF_CTRL_0) & ~(0x3f << 1);
457 val |= (config->hmc_mode << 1);
458 omap_writel(val, MOD_CONF_CTRL_0);
460 printk("USB: hmc %d", config->hmc_mode);
462 printk(", usb0 %d wires%s", config->pins[0],
463 is_usb0_device(config) ? " (dev)" : "");
465 printk(", usb1 %d wires", config->pins[1]);
467 printk(", usb2 %d wires", config->pins[2]);
470 /* use DPLL for 48 MHz function clock */
471 pr_debug("APLL %04x DPLL %04x REQ %04x\n", omap_readw(ULPD_APLL_CTRL),
472 omap_readw(ULPD_DPLL_CTRL), omap_readw(ULPD_SOFT_REQ));
474 w = omap_readw(ULPD_APLL_CTRL);
475 w &= ~APLL_NDPLL_SWITCH;
476 omap_writew(w, ULPD_APLL_CTRL);
478 w = omap_readw(ULPD_DPLL_CTRL);
479 w |= DPLL_IOB | DPLL_PLL_ENABLE;
480 omap_writew(w, ULPD_DPLL_CTRL);
482 w = omap_readw(ULPD_SOFT_REQ);
483 w |= SOFT_UDC_REQ | SOFT_DPLL_REQ;
484 omap_writew(w, ULPD_SOFT_REQ);
486 while (!(omap_readw(ULPD_DPLL_CTRL) & DPLL_LOCK))
489 #ifdef CONFIG_USB_GADGET_OMAP
490 if (config->register_dev) {
493 udc_device.dev.platform_data = config;
494 status = platform_device_register(&udc_device);
496 pr_debug("can't register UDC device, %d\n", status);
497 /* udc driver gates 48MHz by D+ pullup */
501 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
502 if (config->register_host) {
505 ohci_device.dev.platform_data = config;
506 status = platform_device_register(&ohci_device);
508 pr_debug("can't register OHCI device, %d\n", status);
509 /* hcd explicitly gates 48MHz */
515 static inline void omap_1510_usb_init(struct omap_usb_config *config) {}
518 void __init omap1_usb_init(struct omap_usb_config *pdata)
520 pdata->usb0_init = omap1_usb0_init;
521 pdata->usb1_init = omap1_usb1_init;
522 pdata->usb2_init = omap1_usb2_init;
523 udc_device_init(pdata);
524 ohci_device_init(pdata);
525 otg_device_init(pdata);
527 if (cpu_is_omap7xx() || cpu_is_omap16xx())
528 omap_otg_init(pdata);
529 else if (cpu_is_omap15xx())
530 omap_1510_usb_init(pdata);
532 printk(KERN_ERR "USB: No init for your chip yet\n");