1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Platform level USB initialization for FS USB OTG controller on omap1
5 * Copyright (C) 2004 Texas Instruments, Inc.
8 #include <linux/module.h>
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <linux/platform_device.h>
12 #include <linux/dma-map-ops.h>
23 /* These routines should handle the standard chip-specific modes
24 * for usb0/1/2 ports, covering basic mux and transceiver setup.
26 * Some board-*.c files will need to set up additional mux options,
27 * like for suspend handling, vbus sensing, GPIOs, and the D+ pullup.
31 * - 1611B H2 (with usb1 mini-AB) using standard Mini-B or OTG cables
32 * - 5912 OSK OHCI (with usb0 standard-A), standard A-to-B cables
33 * - 5912 OSK UDC, with *nonstandard* A-to-A cable
34 * - 1510 Innovator UDC with bundled usb0 cable
35 * - 1510 Innovator OHCI with bundled usb1/usb2 cable
36 * - 1510 Innovator OHCI with custom usb0 cable, feeding 5V VBUS
37 * - 1710 custom development board using alternate pin group
38 * - 1710 H3 (with usb1 mini-AB) using standard Mini-B or OTG cables
41 #define INT_USB_IRQ_GEN IH2_BASE + 20
42 #define INT_USB_IRQ_NISO IH2_BASE + 30
43 #define INT_USB_IRQ_ISO IH2_BASE + 29
44 #define INT_USB_IRQ_HGEN INT_USB_HHC_1
45 #define INT_USB_IRQ_OTG IH2_BASE + 8
47 #ifdef CONFIG_ARCH_OMAP_OTG
50 omap_otg_init(struct omap_usb_config
*config
)
56 /* NOTE: no bus or clock setup (yet?) */
58 syscon
= omap_readl(OTG_SYSCON_1
) & 0xffff;
59 if (!(syscon
& OTG_RESET_DONE
))
60 pr_debug("USB resets not complete?\n");
62 //omap_writew(0, OTG_IRQ_EN);
64 /* pin muxing and transceiver pinouts */
65 if (config
->pins
[0] > 2) /* alt pingroup 2 */
67 syscon
|= config
->usb0_init(config
->pins
[0], is_usb0_device(config
));
68 syscon
|= config
->usb1_init(config
->pins
[1]);
69 syscon
|= config
->usb2_init(config
->pins
[2], alt_pingroup
);
70 pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1
));
71 omap_writel(syscon
, OTG_SYSCON_1
);
73 syscon
= config
->hmc_mode
;
74 syscon
|= USBX_SYNCHRO
| (4 << 16) /* B_ASE0_BRST */;
79 pr_debug("USB_TRANSCEIVER_CTRL = %03x\n",
80 omap_readl(USB_TRANSCEIVER_CTRL
));
81 pr_debug("OTG_SYSCON_2 = %08x\n", omap_readl(OTG_SYSCON_2
));
82 omap_writel(syscon
, OTG_SYSCON_2
);
84 printk("USB: hmc %d", config
->hmc_mode
);
86 pr_cont(", usb2 alt %d wires", config
->pins
[2]);
87 else if (config
->pins
[0])
88 pr_cont(", usb0 %d wires%s", config
->pins
[0],
89 is_usb0_device(config
) ? " (dev)" : "");
91 pr_cont(", usb1 %d wires", config
->pins
[1]);
92 if (!alt_pingroup
&& config
->pins
[2])
93 pr_cont(", usb2 %d wires", config
->pins
[2]);
95 pr_cont(", Mini-AB on usb%d", config
->otg
- 1);
98 /* leave USB clocks/controllers off until needed */
99 w
= omap_readw(ULPD_SOFT_REQ
);
100 w
&= ~SOFT_USB_CLK_REQ
;
101 omap_writew(w
, ULPD_SOFT_REQ
);
103 w
= omap_readw(ULPD_CLOCK_CTRL
);
105 w
|= DIS_USB_PVCI_CLK
;
106 omap_writew(w
, ULPD_CLOCK_CTRL
);
108 syscon
= omap_readl(OTG_SYSCON_1
);
109 syscon
|= HST_IDLE_EN
|DEV_IDLE_EN
|OTG_IDLE_EN
;
111 #if IS_ENABLED(CONFIG_USB_OMAP)
112 if (config
->otg
|| config
->register_dev
) {
113 struct platform_device
*udc_device
= config
->udc_device
;
116 syscon
&= ~DEV_IDLE_EN
;
117 udc_device
->dev
.platform_data
= config
;
118 status
= platform_device_register(udc_device
);
120 pr_debug("can't register UDC device, %d\n", status
);
124 #if IS_ENABLED(CONFIG_USB_OHCI_HCD)
125 if (config
->otg
|| config
->register_host
) {
126 struct platform_device
*ohci_device
= config
->ohci_device
;
129 syscon
&= ~HST_IDLE_EN
;
130 ohci_device
->dev
.platform_data
= config
;
131 status
= platform_device_register(ohci_device
);
133 pr_debug("can't register OHCI device, %d\n", status
);
137 #ifdef CONFIG_USB_OTG
139 struct platform_device
*otg_device
= config
->otg_device
;
142 syscon
&= ~OTG_IDLE_EN
;
143 otg_device
->dev
.platform_data
= config
;
144 status
= platform_device_register(otg_device
);
146 pr_debug("can't register OTG device, %d\n", status
);
149 pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1
));
150 omap_writel(syscon
, OTG_SYSCON_1
);
154 static void omap_otg_init(struct omap_usb_config
*config
) {}
157 #if IS_ENABLED(CONFIG_USB_OMAP)
159 static struct resource udc_resources
[] = {
160 /* order is significant! */
163 .end
= UDC_BASE
+ 0xff,
164 .flags
= IORESOURCE_MEM
,
165 }, { /* general IRQ */
166 .start
= INT_USB_IRQ_GEN
,
167 .flags
= IORESOURCE_IRQ
,
169 .start
= INT_USB_IRQ_NISO
,
170 .flags
= IORESOURCE_IRQ
,
172 .start
= INT_USB_IRQ_ISO
,
173 .flags
= IORESOURCE_IRQ
,
177 static u64 udc_dmamask
= ~(u32
)0;
179 static struct platform_device udc_device
= {
183 .dma_mask
= &udc_dmamask
,
184 .coherent_dma_mask
= 0xffffffff,
186 .num_resources
= ARRAY_SIZE(udc_resources
),
187 .resource
= udc_resources
,
190 static inline void udc_device_init(struct omap_usb_config
*pdata
)
192 /* IRQ numbers for omap7xx */
193 if(cpu_is_omap7xx()) {
194 udc_resources
[1].start
= INT_7XX_USB_GENI
;
195 udc_resources
[2].start
= INT_7XX_USB_NON_ISO
;
196 udc_resources
[3].start
= INT_7XX_USB_ISO
;
198 pdata
->udc_device
= &udc_device
;
203 static inline void udc_device_init(struct omap_usb_config
*pdata
)
209 #if IS_ENABLED(CONFIG_USB_OHCI_HCD)
211 /* The dmamask must be set for OHCI to work */
212 static u64 ohci_dmamask
= ~(u32
)0;
214 static struct resource ohci_resources
[] = {
216 .start
= OMAP_OHCI_BASE
,
217 .end
= OMAP_OHCI_BASE
+ 0xff,
218 .flags
= IORESOURCE_MEM
,
221 .start
= INT_USB_IRQ_HGEN
,
222 .flags
= IORESOURCE_IRQ
,
226 static struct platform_device ohci_device
= {
230 .dma_mask
= &ohci_dmamask
,
231 .coherent_dma_mask
= 0xffffffff,
233 .num_resources
= ARRAY_SIZE(ohci_resources
),
234 .resource
= ohci_resources
,
237 static inline void ohci_device_init(struct omap_usb_config
*pdata
)
239 if (cpu_is_omap7xx())
240 ohci_resources
[1].start
= INT_7XX_USB_HHC_1
;
241 pdata
->ohci_device
= &ohci_device
;
242 pdata
->ocpi_enable
= &ocpi_enable
;
247 static inline void ohci_device_init(struct omap_usb_config
*pdata
)
253 #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
255 static struct resource otg_resources
[] = {
256 /* order is significant! */
259 .end
= OTG_BASE
+ 0xff,
260 .flags
= IORESOURCE_MEM
,
262 .start
= INT_USB_IRQ_OTG
,
263 .flags
= IORESOURCE_IRQ
,
267 static struct platform_device otg_device
= {
270 .num_resources
= ARRAY_SIZE(otg_resources
),
271 .resource
= otg_resources
,
274 static inline void otg_device_init(struct omap_usb_config
*pdata
)
276 if (cpu_is_omap7xx())
277 otg_resources
[1].start
= INT_7XX_USB_OTG
;
278 pdata
->otg_device
= &otg_device
;
283 static inline void otg_device_init(struct omap_usb_config
*pdata
)
289 static u32 __init
omap1_usb0_init(unsigned nwires
, unsigned is_device
)
294 if (!cpu_is_omap15xx()) {
298 l
= omap_readl(USB_TRANSCEIVER_CTRL
);
300 omap_writel(l
, USB_TRANSCEIVER_CTRL
);
306 if (cpu_is_omap7xx()) {
307 omap_cfg_reg(AA17_7XX_USB_DM
);
308 omap_cfg_reg(W16_7XX_USB_PU_EN
);
309 omap_cfg_reg(W17_7XX_USB_VBUSI
);
310 omap_cfg_reg(W18_7XX_USB_DMCK_OUT
);
311 omap_cfg_reg(W19_7XX_USB_DCRST
);
313 omap_cfg_reg(W4_USB_PUEN
);
319 // omap_cfg_reg(P9_USB_DP);
320 // omap_cfg_reg(R8_USB_DM);
322 if (cpu_is_omap15xx()) {
323 /* This works on 1510-Innovator */
328 * - peripheral should configure VBUS detection!
329 * - only peripherals may use the internal D+/D- pulldowns
330 * - OTG support on this port not yet written
333 /* Don't do this for omap7xx -- it causes USB to not work correctly */
334 if (!cpu_is_omap7xx()) {
335 l
= omap_readl(USB_TRANSCEIVER_CTRL
);
339 omap_writel(l
, USB_TRANSCEIVER_CTRL
);
345 /* alternate pin config, external transceiver */
346 if (cpu_is_omap15xx()) {
347 printk(KERN_ERR
"no usb0 alt pin config on 15xx\n");
351 omap_cfg_reg(V6_USB0_TXD
);
352 omap_cfg_reg(W9_USB0_TXEN
);
353 omap_cfg_reg(W5_USB0_SE0
);
355 omap_cfg_reg(Y5_USB0_RCV
);
357 /* NOTE: SPEED and SUSP aren't configured here. OTG hosts
358 * may be able to use I2C requests to set those bits along
359 * with VBUS switching and overcurrent detection.
365 l
= omap_readl(USB_TRANSCEIVER_CTRL
);
366 l
&= ~CONF_USB2_UNI_R
;
367 omap_writel(l
, USB_TRANSCEIVER_CTRL
);
382 omap_cfg_reg(AA9_USB0_VP
);
383 omap_cfg_reg(R9_USB0_VM
);
384 l
= omap_readl(USB_TRANSCEIVER_CTRL
);
385 l
|= CONF_USB2_UNI_R
;
386 omap_writel(l
, USB_TRANSCEIVER_CTRL
);
390 printk(KERN_ERR
"illegal usb%d %d-wire transceiver\n",
394 return syscon1
<< 16;
397 static u32 __init
omap1_usb1_init(unsigned nwires
)
401 if (!cpu_is_omap15xx() && nwires
!= 6) {
404 l
= omap_readl(USB_TRANSCEIVER_CTRL
);
405 l
&= ~CONF_USB1_UNI_R
;
406 omap_writel(l
, USB_TRANSCEIVER_CTRL
);
411 /* external transceiver */
412 omap_cfg_reg(USB1_TXD
);
413 omap_cfg_reg(USB1_TXEN
);
415 omap_cfg_reg(USB1_RCV
);
417 if (cpu_is_omap15xx()) {
418 omap_cfg_reg(USB1_SEO
);
419 omap_cfg_reg(USB1_SPEED
);
421 } else if (cpu_is_omap1610() || cpu_is_omap5912()) {
422 omap_cfg_reg(W13_1610_USB1_SE0
);
423 omap_cfg_reg(R13_1610_USB1_SPEED
);
425 } else if (cpu_is_omap1710()) {
426 omap_cfg_reg(R13_1710_USB1_SE0
);
429 pr_debug("usb%d cpu unrecognized\n", 1);
444 omap_cfg_reg(USB1_VP
);
445 omap_cfg_reg(USB1_VM
);
446 if (!cpu_is_omap15xx()) {
449 l
= omap_readl(USB_TRANSCEIVER_CTRL
);
450 l
|= CONF_USB1_UNI_R
;
451 omap_writel(l
, USB_TRANSCEIVER_CTRL
);
456 printk(KERN_ERR
"illegal usb%d %d-wire transceiver\n",
460 return syscon1
<< 20;
463 static u32 __init
omap1_usb2_init(unsigned nwires
, unsigned alt_pingroup
)
467 /* NOTE omap1 erratum: must leave USB2_UNI_R set if usb0 in use */
468 if (alt_pingroup
|| nwires
== 0)
471 if (!cpu_is_omap15xx() && nwires
!= 6) {
474 l
= omap_readl(USB_TRANSCEIVER_CTRL
);
475 l
&= ~CONF_USB2_UNI_R
;
476 omap_writel(l
, USB_TRANSCEIVER_CTRL
);
479 /* external transceiver */
480 if (cpu_is_omap15xx()) {
481 omap_cfg_reg(USB2_TXD
);
482 omap_cfg_reg(USB2_TXEN
);
483 omap_cfg_reg(USB2_SEO
);
485 omap_cfg_reg(USB2_RCV
);
486 /* there is no USB2_SPEED */
487 } else if (cpu_is_omap16xx()) {
488 omap_cfg_reg(V6_USB2_TXD
);
489 omap_cfg_reg(W9_USB2_TXEN
);
490 omap_cfg_reg(W5_USB2_SE0
);
492 omap_cfg_reg(Y5_USB2_RCV
);
493 // FIXME omap_cfg_reg(USB2_SPEED);
495 pr_debug("usb%d cpu unrecognized\n", 1);
499 // omap_cfg_reg(USB2_SUSP);
514 if (cpu_is_omap15xx()) {
515 omap_cfg_reg(USB2_VP
);
516 omap_cfg_reg(USB2_VM
);
520 omap_cfg_reg(AA9_USB2_VP
);
521 omap_cfg_reg(R9_USB2_VM
);
522 l
= omap_readl(USB_TRANSCEIVER_CTRL
);
523 l
|= CONF_USB2_UNI_R
;
524 omap_writel(l
, USB_TRANSCEIVER_CTRL
);
529 printk(KERN_ERR
"illegal usb%d %d-wire transceiver\n",
533 return syscon1
<< 24;
536 #ifdef CONFIG_ARCH_OMAP15XX
539 #define DPLL_IOB (1 << 13)
540 #define DPLL_PLL_ENABLE (1 << 4)
541 #define DPLL_LOCK (1 << 0)
544 #define APLL_NDPLL_SWITCH (1 << 0)
546 static int omap_1510_usb_ohci_notifier(struct notifier_block
*nb
,
547 unsigned long event
, void *data
)
549 struct device
*dev
= data
;
551 if (event
!= BUS_NOTIFY_ADD_DEVICE
)
554 if (strncmp(dev_name(dev
), "ohci", 4) == 0 &&
555 dma_direct_set_offset(dev
, PHYS_OFFSET
, OMAP1510_LB_OFFSET
,
557 WARN_ONCE(1, "failed to set DMA offset\n");
561 static struct notifier_block omap_1510_usb_ohci_nb
= {
562 .notifier_call
= omap_1510_usb_ohci_notifier
,
565 static void __init
omap_1510_usb_init(struct omap_usb_config
*config
)
570 config
->usb0_init(config
->pins
[0], is_usb0_device(config
));
571 config
->usb1_init(config
->pins
[1]);
572 config
->usb2_init(config
->pins
[2], 0);
574 val
= omap_readl(MOD_CONF_CTRL_0
) & ~(0x3f << 1);
575 val
|= (config
->hmc_mode
<< 1);
576 omap_writel(val
, MOD_CONF_CTRL_0
);
578 printk("USB: hmc %d", config
->hmc_mode
);
580 pr_cont(", usb0 %d wires%s", config
->pins
[0],
581 is_usb0_device(config
) ? " (dev)" : "");
583 pr_cont(", usb1 %d wires", config
->pins
[1]);
585 pr_cont(", usb2 %d wires", config
->pins
[2]);
588 /* use DPLL for 48 MHz function clock */
589 pr_debug("APLL %04x DPLL %04x REQ %04x\n", omap_readw(ULPD_APLL_CTRL
),
590 omap_readw(ULPD_DPLL_CTRL
), omap_readw(ULPD_SOFT_REQ
));
592 w
= omap_readw(ULPD_APLL_CTRL
);
593 w
&= ~APLL_NDPLL_SWITCH
;
594 omap_writew(w
, ULPD_APLL_CTRL
);
596 w
= omap_readw(ULPD_DPLL_CTRL
);
597 w
|= DPLL_IOB
| DPLL_PLL_ENABLE
;
598 omap_writew(w
, ULPD_DPLL_CTRL
);
600 w
= omap_readw(ULPD_SOFT_REQ
);
601 w
|= SOFT_UDC_REQ
| SOFT_DPLL_REQ
;
602 omap_writew(w
, ULPD_SOFT_REQ
);
604 while (!(omap_readw(ULPD_DPLL_CTRL
) & DPLL_LOCK
))
607 #if IS_ENABLED(CONFIG_USB_OMAP)
608 if (config
->register_dev
) {
611 udc_device
.dev
.platform_data
= config
;
612 status
= platform_device_register(&udc_device
);
614 pr_debug("can't register UDC device, %d\n", status
);
615 /* udc driver gates 48MHz by D+ pullup */
619 #if IS_ENABLED(CONFIG_USB_OHCI_HCD)
620 if (config
->register_host
) {
623 bus_register_notifier(&platform_bus_type
,
624 &omap_1510_usb_ohci_nb
);
625 ohci_device
.dev
.platform_data
= config
;
626 status
= platform_device_register(&ohci_device
);
628 pr_debug("can't register OHCI device, %d\n", status
);
629 /* hcd explicitly gates 48MHz */
635 static inline void omap_1510_usb_init(struct omap_usb_config
*config
) {}
638 void __init
omap1_usb_init(struct omap_usb_config
*_pdata
)
640 struct omap_usb_config
*pdata
;
642 pdata
= kmemdup(_pdata
, sizeof(*pdata
), GFP_KERNEL
);
646 pdata
->usb0_init
= omap1_usb0_init
;
647 pdata
->usb1_init
= omap1_usb1_init
;
648 pdata
->usb2_init
= omap1_usb2_init
;
649 udc_device_init(pdata
);
650 ohci_device_init(pdata
);
651 otg_device_init(pdata
);
653 if (cpu_is_omap7xx() || cpu_is_omap16xx())
654 omap_otg_init(pdata
);
655 else if (cpu_is_omap15xx())
656 omap_1510_usb_init(pdata
);
658 printk(KERN_ERR
"USB: No init for your chip yet\n");