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>
35 /* These routines should handle the standard chip-specific modes
36 * for usb0/1/2 ports, covering basic mux and transceiver setup.
38 * Some board-*.c files will need to set up additional mux options,
39 * like for suspend handling, vbus sensing, GPIOs, and the D+ pullup.
43 * - 1611B H2 (with usb1 mini-AB) using standard Mini-B or OTG cables
44 * - 5912 OSK OHCI (with usb0 standard-A), standard A-to-B cables
45 * - 5912 OSK UDC, with *nonstandard* A-to-A cable
46 * - 1510 Innovator UDC with bundled usb0 cable
47 * - 1510 Innovator OHCI with bundled usb1/usb2 cable
48 * - 1510 Innovator OHCI with custom usb0 cable, feeding 5V VBUS
49 * - 1710 custom development board using alternate pin group
50 * - 1710 H3 (with usb1 mini-AB) using standard Mini-B or OTG cables
53 #define INT_USB_IRQ_GEN IH2_BASE + 20
54 #define INT_USB_IRQ_NISO IH2_BASE + 30
55 #define INT_USB_IRQ_ISO IH2_BASE + 29
56 #define INT_USB_IRQ_HGEN INT_USB_HHC_1
57 #define INT_USB_IRQ_OTG IH2_BASE + 8
59 #ifdef CONFIG_ARCH_OMAP_OTG
62 omap_otg_init(struct omap_usb_config *config)
67 /* NOTE: no bus or clock setup (yet?) */
69 syscon = omap_readl(OTG_SYSCON_1) & 0xffff;
70 if (!(syscon & OTG_RESET_DONE))
71 pr_debug("USB resets not complete?\n");
73 //omap_writew(0, OTG_IRQ_EN);
75 /* pin muxing and transceiver pinouts */
76 if (config->pins[0] > 2) /* alt pingroup 2 */
78 syscon |= config->usb0_init(config->pins[0], is_usb0_device(config));
79 syscon |= config->usb1_init(config->pins[1]);
80 syscon |= config->usb2_init(config->pins[2], alt_pingroup);
81 pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
82 omap_writel(syscon, OTG_SYSCON_1);
84 syscon = config->hmc_mode;
85 syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
90 if (cpu_class_is_omap1())
91 pr_debug("USB_TRANSCEIVER_CTRL = %03x\n",
92 omap_readl(USB_TRANSCEIVER_CTRL));
93 pr_debug("OTG_SYSCON_2 = %08x\n", omap_readl(OTG_SYSCON_2));
94 omap_writel(syscon, OTG_SYSCON_2);
96 printk("USB: hmc %d", config->hmc_mode);
98 printk(", usb2 alt %d wires", config->pins[2]);
99 else if (config->pins[0])
100 printk(", usb0 %d wires%s", config->pins[0],
101 is_usb0_device(config) ? " (dev)" : "");
103 printk(", usb1 %d wires", config->pins[1]);
104 if (!alt_pingroup && config->pins[2])
105 printk(", usb2 %d wires", config->pins[2]);
107 printk(", Mini-AB on usb%d", config->otg - 1);
110 if (cpu_class_is_omap1()) {
113 /* leave USB clocks/controllers off until needed */
114 w = omap_readw(ULPD_SOFT_REQ);
115 w &= ~SOFT_USB_CLK_REQ;
116 omap_writew(w, ULPD_SOFT_REQ);
118 w = omap_readw(ULPD_CLOCK_CTRL);
120 w |= DIS_USB_PVCI_CLK;
121 omap_writew(w, ULPD_CLOCK_CTRL);
123 syscon = omap_readl(OTG_SYSCON_1);
124 syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
126 #if IS_ENABLED(CONFIG_USB_OMAP)
127 if (config->otg || config->register_dev) {
128 struct platform_device *udc_device = config->udc_device;
131 syscon &= ~DEV_IDLE_EN;
132 udc_device->dev.platform_data = config;
133 status = platform_device_register(udc_device);
135 pr_debug("can't register UDC device, %d\n", status);
139 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
140 if (config->otg || config->register_host) {
141 struct platform_device *ohci_device = config->ohci_device;
144 syscon &= ~HST_IDLE_EN;
145 ohci_device->dev.platform_data = config;
146 status = platform_device_register(ohci_device);
148 pr_debug("can't register OHCI device, %d\n", status);
152 #ifdef CONFIG_USB_OTG
154 struct platform_device *otg_device = config->otg_device;
157 syscon &= ~OTG_IDLE_EN;
158 otg_device->dev.platform_data = config;
159 status = platform_device_register(otg_device);
161 pr_debug("can't register OTG device, %d\n", status);
164 pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
165 omap_writel(syscon, OTG_SYSCON_1);
169 void omap_otg_init(struct omap_usb_config *config) {}
172 #if IS_ENABLED(CONFIG_USB_OMAP)
174 static struct resource udc_resources[] = {
175 /* order is significant! */
178 .end = UDC_BASE + 0xff,
179 .flags = IORESOURCE_MEM,
180 }, { /* general IRQ */
181 .start = INT_USB_IRQ_GEN,
182 .flags = IORESOURCE_IRQ,
184 .start = INT_USB_IRQ_NISO,
185 .flags = IORESOURCE_IRQ,
187 .start = INT_USB_IRQ_ISO,
188 .flags = IORESOURCE_IRQ,
192 static u64 udc_dmamask = ~(u32)0;
194 static struct platform_device udc_device = {
198 .dma_mask = &udc_dmamask,
199 .coherent_dma_mask = 0xffffffff,
201 .num_resources = ARRAY_SIZE(udc_resources),
202 .resource = udc_resources,
205 static inline void udc_device_init(struct omap_usb_config *pdata)
207 /* IRQ numbers for omap7xx */
208 if(cpu_is_omap7xx()) {
209 udc_resources[1].start = INT_7XX_USB_GENI;
210 udc_resources[2].start = INT_7XX_USB_NON_ISO;
211 udc_resources[3].start = INT_7XX_USB_ISO;
213 pdata->udc_device = &udc_device;
218 static inline void udc_device_init(struct omap_usb_config *pdata)
224 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
226 /* The dmamask must be set for OHCI to work */
227 static u64 ohci_dmamask = ~(u32)0;
229 static struct resource ohci_resources[] = {
231 .start = OMAP_OHCI_BASE,
232 .end = OMAP_OHCI_BASE + 0xff,
233 .flags = IORESOURCE_MEM,
236 .start = INT_USB_IRQ_HGEN,
237 .flags = IORESOURCE_IRQ,
241 static struct platform_device ohci_device = {
245 .dma_mask = &ohci_dmamask,
246 .coherent_dma_mask = 0xffffffff,
248 .num_resources = ARRAY_SIZE(ohci_resources),
249 .resource = ohci_resources,
252 static inline void ohci_device_init(struct omap_usb_config *pdata)
254 if (cpu_is_omap7xx())
255 ohci_resources[1].start = INT_7XX_USB_HHC_1;
256 pdata->ohci_device = &ohci_device;
257 pdata->ocpi_enable = &ocpi_enable;
262 static inline void ohci_device_init(struct omap_usb_config *pdata)
268 #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
270 static struct resource otg_resources[] = {
271 /* order is significant! */
274 .end = OTG_BASE + 0xff,
275 .flags = IORESOURCE_MEM,
277 .start = INT_USB_IRQ_OTG,
278 .flags = IORESOURCE_IRQ,
282 static struct platform_device otg_device = {
285 .num_resources = ARRAY_SIZE(otg_resources),
286 .resource = otg_resources,
289 static inline void otg_device_init(struct omap_usb_config *pdata)
291 if (cpu_is_omap7xx())
292 otg_resources[1].start = INT_7XX_USB_OTG;
293 pdata->otg_device = &otg_device;
298 static inline void otg_device_init(struct omap_usb_config *pdata)
304 static u32 __init omap1_usb0_init(unsigned nwires, unsigned is_device)
309 if (!cpu_is_omap15xx()) {
313 l = omap_readl(USB_TRANSCEIVER_CTRL);
315 omap_writel(l, USB_TRANSCEIVER_CTRL);
321 if (cpu_is_omap7xx()) {
322 omap_cfg_reg(AA17_7XX_USB_DM);
323 omap_cfg_reg(W16_7XX_USB_PU_EN);
324 omap_cfg_reg(W17_7XX_USB_VBUSI);
325 omap_cfg_reg(W18_7XX_USB_DMCK_OUT);
326 omap_cfg_reg(W19_7XX_USB_DCRST);
328 omap_cfg_reg(W4_USB_PUEN);
334 // omap_cfg_reg(P9_USB_DP);
335 // omap_cfg_reg(R8_USB_DM);
337 if (cpu_is_omap15xx()) {
338 /* This works on 1510-Innovator */
343 * - peripheral should configure VBUS detection!
344 * - only peripherals may use the internal D+/D- pulldowns
345 * - OTG support on this port not yet written
348 /* Don't do this for omap7xx -- it causes USB to not work correctly */
349 if (!cpu_is_omap7xx()) {
350 l = omap_readl(USB_TRANSCEIVER_CTRL);
354 omap_writel(l, USB_TRANSCEIVER_CTRL);
360 /* alternate pin config, external transceiver */
361 if (cpu_is_omap15xx()) {
362 printk(KERN_ERR "no usb0 alt pin config on 15xx\n");
366 omap_cfg_reg(V6_USB0_TXD);
367 omap_cfg_reg(W9_USB0_TXEN);
368 omap_cfg_reg(W5_USB0_SE0);
370 omap_cfg_reg(Y5_USB0_RCV);
372 /* NOTE: SPEED and SUSP aren't configured here. OTG hosts
373 * may be able to use I2C requests to set those bits along
374 * with VBUS switching and overcurrent detection.
380 l = omap_readl(USB_TRANSCEIVER_CTRL);
381 l &= ~CONF_USB2_UNI_R;
382 omap_writel(l, USB_TRANSCEIVER_CTRL);
397 omap_cfg_reg(AA9_USB0_VP);
398 omap_cfg_reg(R9_USB0_VM);
399 l = omap_readl(USB_TRANSCEIVER_CTRL);
400 l |= CONF_USB2_UNI_R;
401 omap_writel(l, USB_TRANSCEIVER_CTRL);
405 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
409 return syscon1 << 16;
412 static u32 __init omap1_usb1_init(unsigned nwires)
416 if (!cpu_is_omap15xx() && nwires != 6) {
419 l = omap_readl(USB_TRANSCEIVER_CTRL);
420 l &= ~CONF_USB1_UNI_R;
421 omap_writel(l, USB_TRANSCEIVER_CTRL);
426 /* external transceiver */
427 omap_cfg_reg(USB1_TXD);
428 omap_cfg_reg(USB1_TXEN);
430 omap_cfg_reg(USB1_RCV);
432 if (cpu_is_omap15xx()) {
433 omap_cfg_reg(USB1_SEO);
434 omap_cfg_reg(USB1_SPEED);
436 } else if (cpu_is_omap1610() || cpu_is_omap5912()) {
437 omap_cfg_reg(W13_1610_USB1_SE0);
438 omap_cfg_reg(R13_1610_USB1_SPEED);
440 } else if (cpu_is_omap1710()) {
441 omap_cfg_reg(R13_1710_USB1_SE0);
444 pr_debug("usb%d cpu unrecognized\n", 1);
459 omap_cfg_reg(USB1_VP);
460 omap_cfg_reg(USB1_VM);
461 if (!cpu_is_omap15xx()) {
464 l = omap_readl(USB_TRANSCEIVER_CTRL);
465 l |= CONF_USB1_UNI_R;
466 omap_writel(l, USB_TRANSCEIVER_CTRL);
471 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
475 return syscon1 << 20;
478 static u32 __init omap1_usb2_init(unsigned nwires, unsigned alt_pingroup)
482 /* NOTE omap1 erratum: must leave USB2_UNI_R set if usb0 in use */
483 if (alt_pingroup || nwires == 0)
486 if (!cpu_is_omap15xx() && nwires != 6) {
489 l = omap_readl(USB_TRANSCEIVER_CTRL);
490 l &= ~CONF_USB2_UNI_R;
491 omap_writel(l, USB_TRANSCEIVER_CTRL);
494 /* external transceiver */
495 if (cpu_is_omap15xx()) {
496 omap_cfg_reg(USB2_TXD);
497 omap_cfg_reg(USB2_TXEN);
498 omap_cfg_reg(USB2_SEO);
500 omap_cfg_reg(USB2_RCV);
501 /* there is no USB2_SPEED */
502 } else if (cpu_is_omap16xx()) {
503 omap_cfg_reg(V6_USB2_TXD);
504 omap_cfg_reg(W9_USB2_TXEN);
505 omap_cfg_reg(W5_USB2_SE0);
507 omap_cfg_reg(Y5_USB2_RCV);
508 // FIXME omap_cfg_reg(USB2_SPEED);
510 pr_debug("usb%d cpu unrecognized\n", 1);
514 // omap_cfg_reg(USB2_SUSP);
529 if (cpu_is_omap15xx()) {
530 omap_cfg_reg(USB2_VP);
531 omap_cfg_reg(USB2_VM);
535 omap_cfg_reg(AA9_USB2_VP);
536 omap_cfg_reg(R9_USB2_VM);
537 l = omap_readl(USB_TRANSCEIVER_CTRL);
538 l |= CONF_USB2_UNI_R;
539 omap_writel(l, USB_TRANSCEIVER_CTRL);
544 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
548 return syscon1 << 24;
551 #ifdef CONFIG_ARCH_OMAP15XX
554 #define DPLL_IOB (1 << 13)
555 #define DPLL_PLL_ENABLE (1 << 4)
556 #define DPLL_LOCK (1 << 0)
559 #define APLL_NDPLL_SWITCH (1 << 0)
561 static void __init omap_1510_usb_init(struct omap_usb_config *config)
566 config->usb0_init(config->pins[0], is_usb0_device(config));
567 config->usb1_init(config->pins[1]);
568 config->usb2_init(config->pins[2], 0);
570 val = omap_readl(MOD_CONF_CTRL_0) & ~(0x3f << 1);
571 val |= (config->hmc_mode << 1);
572 omap_writel(val, MOD_CONF_CTRL_0);
574 printk("USB: hmc %d", config->hmc_mode);
576 printk(", usb0 %d wires%s", config->pins[0],
577 is_usb0_device(config) ? " (dev)" : "");
579 printk(", usb1 %d wires", config->pins[1]);
581 printk(", usb2 %d wires", config->pins[2]);
584 /* use DPLL for 48 MHz function clock */
585 pr_debug("APLL %04x DPLL %04x REQ %04x\n", omap_readw(ULPD_APLL_CTRL),
586 omap_readw(ULPD_DPLL_CTRL), omap_readw(ULPD_SOFT_REQ));
588 w = omap_readw(ULPD_APLL_CTRL);
589 w &= ~APLL_NDPLL_SWITCH;
590 omap_writew(w, ULPD_APLL_CTRL);
592 w = omap_readw(ULPD_DPLL_CTRL);
593 w |= DPLL_IOB | DPLL_PLL_ENABLE;
594 omap_writew(w, ULPD_DPLL_CTRL);
596 w = omap_readw(ULPD_SOFT_REQ);
597 w |= SOFT_UDC_REQ | SOFT_DPLL_REQ;
598 omap_writew(w, ULPD_SOFT_REQ);
600 while (!(omap_readw(ULPD_DPLL_CTRL) & DPLL_LOCK))
603 #if IS_ENABLED(CONFIG_USB_OMAP)
604 if (config->register_dev) {
607 udc_device.dev.platform_data = config;
608 status = platform_device_register(&udc_device);
610 pr_debug("can't register UDC device, %d\n", status);
611 /* udc driver gates 48MHz by D+ pullup */
615 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
616 if (config->register_host) {
619 ohci_device.dev.platform_data = config;
620 status = platform_device_register(&ohci_device);
622 pr_debug("can't register OHCI device, %d\n", status);
623 /* hcd explicitly gates 48MHz */
629 static inline void omap_1510_usb_init(struct omap_usb_config *config) {}
632 void __init omap1_usb_init(struct omap_usb_config *_pdata)
634 struct omap_usb_config *pdata;
636 pdata = kmemdup(_pdata, sizeof(*pdata), GFP_KERNEL);
640 pdata->usb0_init = omap1_usb0_init;
641 pdata->usb1_init = omap1_usb1_init;
642 pdata->usb2_init = omap1_usb2_init;
643 udc_device_init(pdata);
644 ohci_device_init(pdata);
645 otg_device_init(pdata);
647 if (cpu_is_omap7xx() || cpu_is_omap16xx())
648 omap_otg_init(pdata);
649 else if (cpu_is_omap15xx())
650 omap_1510_usb_init(pdata);
652 printk(KERN_ERR "USB: No init for your chip yet\n");