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/platform_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 #if defined(CONFIG_ARCH_OMAP_OTG) || defined(CONFIG_ARCH_OMAP15XX)
96 static u32 __init
omap_usb0_init(unsigned nwires
, unsigned is_device
)
101 if (!cpu_is_omap15xx()) {
103 USB_TRANSCEIVER_CTRL_REG
&= ~(3 << 1);
109 omap_cfg_reg(W4_USB_PUEN
);
111 /* internal transceiver */
113 // omap_cfg_reg(P9_USB_DP);
114 // omap_cfg_reg(R8_USB_DM);
116 if (cpu_is_omap15xx()) {
117 /* This works on 1510-Innovator */
122 * - peripheral should configure VBUS detection!
123 * - only peripherals may use the internal D+/D- pulldowns
124 * - OTG support on this port not yet written
127 USB_TRANSCEIVER_CTRL_REG
&= ~(7 << 4);
129 USB_TRANSCEIVER_CTRL_REG
|= (3 << 1);
134 /* alternate pin config, external transceiver */
135 if (cpu_is_omap15xx()) {
136 printk(KERN_ERR
"no usb0 alt pin config on 15xx\n");
140 omap_cfg_reg(V6_USB0_TXD
);
141 omap_cfg_reg(W9_USB0_TXEN
);
142 omap_cfg_reg(W5_USB0_SE0
);
144 /* NOTE: SPEED and SUSP aren't configured here */
147 omap_cfg_reg(Y5_USB0_RCV
);
149 USB_TRANSCEIVER_CTRL_REG
&= ~CONF_USB2_UNI_R
;
160 omap_cfg_reg(AA9_USB0_VP
);
161 omap_cfg_reg(R9_USB0_VM
);
162 USB_TRANSCEIVER_CTRL_REG
|= CONF_USB2_UNI_R
;
165 printk(KERN_ERR
"illegal usb%d %d-wire transceiver\n",
168 return syscon1
<< 16;
171 static u32 __init
omap_usb1_init(unsigned nwires
)
175 if (nwires
!= 6 && !cpu_is_omap15xx())
176 USB_TRANSCEIVER_CTRL_REG
&= ~CONF_USB1_UNI_R
;
180 /* external transceiver */
181 omap_cfg_reg(USB1_TXD
);
182 omap_cfg_reg(USB1_TXEN
);
183 if (cpu_is_omap15xx()) {
184 omap_cfg_reg(USB1_SEO
);
185 omap_cfg_reg(USB1_SPEED
);
187 } else if (cpu_is_omap1610() || cpu_is_omap5912()) {
188 omap_cfg_reg(W13_1610_USB1_SE0
);
189 omap_cfg_reg(R13_1610_USB1_SPEED
);
191 } else if (cpu_is_omap1710()) {
192 omap_cfg_reg(R13_1710_USB1_SE0
);
195 pr_debug("usb unrecognized\n");
198 omap_cfg_reg(USB1_RCV
);
209 omap_cfg_reg(USB1_VP
);
210 omap_cfg_reg(USB1_VM
);
211 if (!cpu_is_omap15xx())
212 USB_TRANSCEIVER_CTRL_REG
|= CONF_USB1_UNI_R
;
215 printk(KERN_ERR
"illegal usb%d %d-wire transceiver\n",
218 return syscon1
<< 20;
221 static u32 __init
omap_usb2_init(unsigned nwires
, unsigned alt_pingroup
)
225 /* NOTE erratum: must leave USB2_UNI_R set if usb0 in use */
226 if (alt_pingroup
|| nwires
== 0)
228 if (nwires
!= 6 && !cpu_is_omap15xx())
229 USB_TRANSCEIVER_CTRL_REG
&= ~CONF_USB2_UNI_R
;
231 /* external transceiver */
232 if (cpu_is_omap15xx()) {
233 omap_cfg_reg(USB2_TXD
);
234 omap_cfg_reg(USB2_TXEN
);
235 omap_cfg_reg(USB2_SEO
);
237 omap_cfg_reg(USB2_RCV
);
238 /* there is no USB2_SPEED */
239 } else if (cpu_is_omap16xx()) {
240 omap_cfg_reg(V6_USB2_TXD
);
241 omap_cfg_reg(W9_USB2_TXEN
);
242 omap_cfg_reg(W5_USB2_SE0
);
244 omap_cfg_reg(Y5_USB2_RCV
);
245 // FIXME omap_cfg_reg(USB2_SPEED);
247 pr_debug("usb unrecognized\n");
249 // omap_cfg_reg(USB2_SUSP);
260 if (cpu_is_omap15xx()) {
261 omap_cfg_reg(USB2_VP
);
262 omap_cfg_reg(USB2_VM
);
264 omap_cfg_reg(AA9_USB2_VP
);
265 omap_cfg_reg(R9_USB2_VM
);
266 USB_TRANSCEIVER_CTRL_REG
|= CONF_USB2_UNI_R
;
270 printk(KERN_ERR
"illegal usb%d %d-wire transceiver\n",
273 return syscon1
<< 24;
278 /*-------------------------------------------------------------------------*/
280 #if defined(CONFIG_USB_GADGET_OMAP) || \
281 defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) || \
282 (defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG))
283 static void usb_release(struct device
*dev
)
285 /* normally not freed */
289 #ifdef CONFIG_USB_GADGET_OMAP
291 static struct resource udc_resources
[] = {
292 /* order is significant! */
295 .end
= UDC_BASE
+ 0xff,
296 .flags
= IORESOURCE_MEM
,
297 }, { /* general IRQ */
298 .start
= IH2_BASE
+ 20,
299 .flags
= IORESOURCE_IRQ
,
301 .start
= IH2_BASE
+ 30,
302 .flags
= IORESOURCE_IRQ
,
304 .start
= IH2_BASE
+ 29,
305 .flags
= IORESOURCE_IRQ
,
309 static u64 udc_dmamask
= ~(u32
)0;
311 static struct platform_device udc_device
= {
315 .release
= usb_release
,
316 .dma_mask
= &udc_dmamask
,
317 .coherent_dma_mask
= 0xffffffff,
319 .num_resources
= ARRAY_SIZE(udc_resources
),
320 .resource
= udc_resources
,
325 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
327 /* The dmamask must be set for OHCI to work */
328 static u64 ohci_dmamask
= ~(u32
)0;
330 static struct resource ohci_resources
[] = {
332 .start
= OMAP_OHCI_BASE
,
333 .end
= OMAP_OHCI_BASE
+ 4096 - 1,
334 .flags
= IORESOURCE_MEM
,
337 .start
= INT_USB_HHC_1
,
338 .flags
= IORESOURCE_IRQ
,
342 static struct platform_device ohci_device
= {
346 .release
= usb_release
,
347 .dma_mask
= &ohci_dmamask
,
348 .coherent_dma_mask
= 0xffffffff,
350 .num_resources
= ARRAY_SIZE(ohci_resources
),
351 .resource
= ohci_resources
,
356 #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
358 static struct resource otg_resources
[] = {
359 /* order is significant! */
362 .end
= OTG_BASE
+ 0xff,
363 .flags
= IORESOURCE_MEM
,
365 .start
= IH2_BASE
+ 8,
366 .flags
= IORESOURCE_IRQ
,
370 static struct platform_device otg_device
= {
374 .release
= usb_release
,
376 .num_resources
= ARRAY_SIZE(otg_resources
),
377 .resource
= otg_resources
,
382 /*-------------------------------------------------------------------------*/
384 #define ULPD_CLOCK_CTRL_REG __REG16(ULPD_CLOCK_CTRL)
385 #define ULPD_SOFT_REQ_REG __REG16(ULPD_SOFT_REQ)
388 // FIXME correct answer depends on hmc_mode,
389 // as does any nonzero value for config->otg port number
390 #ifdef CONFIG_USB_GADGET_OMAP
391 #define is_usb0_device(config) 1
393 #define is_usb0_device(config) 0
396 /*-------------------------------------------------------------------------*/
398 #ifdef CONFIG_ARCH_OMAP_OTG
401 omap_otg_init(struct omap_usb_config
*config
)
403 u32 syscon
= OTG_SYSCON_1_REG
& 0xffff;
405 int alt_pingroup
= 0;
407 /* NOTE: no bus or clock setup (yet?) */
409 syscon
= OTG_SYSCON_1_REG
& 0xffff;
410 if (!(syscon
& OTG_RESET_DONE
))
411 pr_debug("USB resets not complete?\n");
413 // OTG_IRQ_EN_REG = 0;
415 /* pin muxing and transceiver pinouts */
416 if (config
->pins
[0] > 2) /* alt pingroup 2 */
418 syscon
|= omap_usb0_init(config
->pins
[0], is_usb0_device(config
));
419 syscon
|= omap_usb1_init(config
->pins
[1]);
420 syscon
|= omap_usb2_init(config
->pins
[2], alt_pingroup
);
421 pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon
);
422 OTG_SYSCON_1_REG
= syscon
;
424 syscon
= config
->hmc_mode
;
425 syscon
|= USBX_SYNCHRO
| (4 << 16) /* B_ASE0_BRST */;
426 #ifdef CONFIG_USB_OTG
430 pr_debug("USB_TRANSCEIVER_CTRL_REG = %03x\n", USB_TRANSCEIVER_CTRL_REG
);
431 pr_debug("OTG_SYSCON_2_REG = %08x\n", syscon
);
432 OTG_SYSCON_2_REG
= syscon
;
434 printk("USB: hmc %d", config
->hmc_mode
);
436 printk(", usb2 alt %d wires", config
->pins
[2]);
437 else if (config
->pins
[0])
438 printk(", usb0 %d wires%s", config
->pins
[0],
439 is_usb0_device(config
) ? " (dev)" : "");
441 printk(", usb1 %d wires", config
->pins
[1]);
442 if (!alt_pingroup
&& config
->pins
[2])
443 printk(", usb2 %d wires", config
->pins
[2]);
445 printk(", Mini-AB on usb%d", config
->otg
- 1);
448 /* leave USB clocks/controllers off until needed */
449 ULPD_SOFT_REQ_REG
&= ~SOFT_USB_CLK_REQ
;
450 ULPD_CLOCK_CTRL_REG
&= ~USB_MCLK_EN
;
451 ULPD_CLOCK_CTRL_REG
|= DIS_USB_PVCI_CLK
;
452 syscon
= OTG_SYSCON_1_REG
;
453 syscon
|= HST_IDLE_EN
|DEV_IDLE_EN
|OTG_IDLE_EN
;
455 #ifdef CONFIG_USB_GADGET_OMAP
456 if (config
->otg
|| config
->register_dev
) {
457 syscon
&= ~DEV_IDLE_EN
;
458 udc_device
.dev
.platform_data
= config
;
459 /* FIXME patch IRQ numbers for omap730 */
460 status
= platform_device_register(&udc_device
);
462 pr_debug("can't register UDC device, %d\n", status
);
466 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
467 if (config
->otg
|| config
->register_host
) {
468 syscon
&= ~HST_IDLE_EN
;
469 ohci_device
.dev
.platform_data
= config
;
470 if (cpu_is_omap730())
471 ohci_resources
[1].start
= INT_730_USB_HHC_1
;
472 status
= platform_device_register(&ohci_device
);
474 pr_debug("can't register OHCI device, %d\n", status
);
478 #ifdef CONFIG_USB_OTG
480 syscon
&= ~OTG_IDLE_EN
;
481 otg_device
.dev
.platform_data
= config
;
482 if (cpu_is_omap730())
483 otg_resources
[1].start
= INT_730_USB_OTG
;
484 status
= platform_device_register(&otg_device
);
486 pr_debug("can't register OTG device, %d\n", status
);
489 pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon
);
490 OTG_SYSCON_1_REG
= syscon
;
496 static inline void omap_otg_init(struct omap_usb_config
*config
) {}
499 /*-------------------------------------------------------------------------*/
501 #ifdef CONFIG_ARCH_OMAP15XX
503 #define ULPD_DPLL_CTRL_REG __REG16(ULPD_DPLL_CTRL)
504 #define DPLL_IOB (1 << 13)
505 #define DPLL_PLL_ENABLE (1 << 4)
506 #define DPLL_LOCK (1 << 0)
508 #define ULPD_APLL_CTRL_REG __REG16(ULPD_APLL_CTRL)
509 #define APLL_NDPLL_SWITCH (1 << 0)
512 static void __init
omap_1510_usb_init(struct omap_usb_config
*config
)
516 omap_usb0_init(config
->pins
[0], is_usb0_device(config
));
517 omap_usb1_init(config
->pins
[1]);
518 omap_usb2_init(config
->pins
[2], 0);
520 val
= omap_readl(MOD_CONF_CTRL_0
) & ~(0x3f << 1);
521 val
|= (config
->hmc_mode
<< 1);
522 omap_writel(val
, MOD_CONF_CTRL_0
);
524 printk("USB: hmc %d", config
->hmc_mode
);
526 printk(", usb0 %d wires%s", config
->pins
[0],
527 is_usb0_device(config
) ? " (dev)" : "");
529 printk(", usb1 %d wires", config
->pins
[1]);
531 printk(", usb2 %d wires", config
->pins
[2]);
534 /* use DPLL for 48 MHz function clock */
535 pr_debug("APLL %04x DPLL %04x REQ %04x\n", ULPD_APLL_CTRL_REG
,
536 ULPD_DPLL_CTRL_REG
, ULPD_SOFT_REQ_REG
);
537 ULPD_APLL_CTRL_REG
&= ~APLL_NDPLL_SWITCH
;
538 ULPD_DPLL_CTRL_REG
|= DPLL_IOB
| DPLL_PLL_ENABLE
;
539 ULPD_SOFT_REQ_REG
|= SOFT_UDC_REQ
| SOFT_DPLL_REQ
;
540 while (!(ULPD_DPLL_CTRL_REG
& DPLL_LOCK
))
543 #ifdef CONFIG_USB_GADGET_OMAP
544 if (config
->register_dev
) {
547 udc_device
.dev
.platform_data
= config
;
548 status
= platform_device_register(&udc_device
);
550 pr_debug("can't register UDC device, %d\n", status
);
551 /* udc driver gates 48MHz by D+ pullup */
555 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
556 if (config
->register_host
) {
559 ohci_device
.dev
.platform_data
= config
;
560 status
= platform_device_register(&ohci_device
);
562 pr_debug("can't register OHCI device, %d\n", status
);
563 /* hcd explicitly gates 48MHz */
569 static inline void omap_1510_usb_init(struct omap_usb_config
*config
) {}
572 /*-------------------------------------------------------------------------*/
574 static struct omap_usb_config platform_data
;
579 const struct omap_usb_config
*config
;
581 config
= omap_get_config(OMAP_TAG_USB
, struct omap_usb_config
);
582 if (config
== NULL
) {
583 printk(KERN_ERR
"USB: No board-specific "
584 "platform config found\n");
587 platform_data
= *config
;
589 if (cpu_is_omap730() || cpu_is_omap16xx())
590 omap_otg_init(&platform_data
);
591 else if (cpu_is_omap15xx())
592 omap_1510_usb_init(&platform_data
);
594 printk(KERN_ERR
"USB: No init for your chip yet\n");
600 subsys_initcall(omap_usb_init
);