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)
52 * - 1510 Innovator with built-in transceiver (custom cable feeding 5V VBUS)
53 * - 1710 custom development board using alternate pin group
56 /*-------------------------------------------------------------------------*/
58 #ifdef CONFIG_ARCH_OMAP_OTG
60 static struct otg_transceiver *xceiv;
63 * otg_get_transceiver - find the (single) OTG transceiver driver
65 * Returns the transceiver driver, after getting a refcount to it; or
66 * null if there is no such transceiver. The caller is responsible for
67 * releasing that count.
69 struct otg_transceiver *otg_get_transceiver(void)
72 get_device(xceiv->dev);
75 EXPORT_SYMBOL(otg_get_transceiver);
77 int otg_set_transceiver(struct otg_transceiver *x)
84 EXPORT_SYMBOL(otg_set_transceiver);
88 /*-------------------------------------------------------------------------*/
90 static u32 __init omap_usb0_init(unsigned nwires, unsigned is_device)
95 USB_TRANSCEIVER_CTRL_REG &= ~(1 << 3);
100 * VP and VM are needed for all active usb0 configurations.
101 * USB0_VP and USB0_VM are always set on 1510, there's no muxing
102 * available for them.
104 if (nwires >= 2 && !cpu_is_omap1510()) {
105 omap_cfg_reg(AA9_USB0_VP);
106 omap_cfg_reg(R9_USB0_VM);
109 /* internal transceiver */
111 if (cpu_is_omap1510()) {
112 /* This works for OHCI on 1510-Innovator, nothing to mux */
117 /* NOTE: host OR device mode for now, no OTG */
118 USB_TRANSCEIVER_CTRL_REG &= ~(3 << 4);
120 omap_cfg_reg(W4_USB_PUEN);
121 omap_cfg_reg(R18_1510_USB_GPIO0);
122 // omap_cfg_reg(USB0_VBUS);
123 // omap_cfg_reg(USB0_PUEN);
124 // USB_TRANSCEIVER_CTRL_REG.CONF_USB0_PORT_R = 7
125 // when USB0_PUEN is needed
126 } else /* host mode needs D+ and D- pulldowns */
127 USB_TRANSCEIVER_CTRL_REG &= ~(3 << 1);
130 /* FIXME: 1610 needs to return the right value here */
131 printk(KERN_ERR "usb0 internal transceiver, nyet\n");
136 /* alternate pin config, external transceiver */
137 omap_cfg_reg(V6_USB0_TXD);
138 omap_cfg_reg(W9_USB0_TXEN);
139 omap_cfg_reg(W5_USB0_SE0);
141 #ifdef CONFIG_ARCH_OMAP_USB_SPEED
142 /* FIXME: there's good chance that pin V9 is used for MMC2 port cmddir */
143 omap_cfg_reg(V9_USB0_SPEED);
144 // omap_cfg_reg(V9_USB0_SUSP);
148 omap_cfg_reg(Y5_USB0_RCV);
159 /* REVISIT: Is CONF_USB2_UNI_R only needed when nwires = 6? */
160 USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;
163 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
166 return syscon1 << 16;
169 static u32 __init omap_usb1_init(unsigned nwires)
174 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB1_UNI_R;
178 /* external transceiver */
179 omap_cfg_reg(USB1_TXD);
180 omap_cfg_reg(USB1_TXEN);
181 if (cpu_is_omap1510()) {
182 omap_cfg_reg(USB1_SEO);
183 omap_cfg_reg(USB1_SPEED);
185 } else if (cpu_is_omap1610() || cpu_is_omap5912() || cpu_is_omap1710()) {
186 omap_cfg_reg(W13_1610_USB1_SE0);
187 omap_cfg_reg(R13_1610_USB1_SPEED);
190 pr_debug("usb unrecognized\n");
193 omap_cfg_reg(USB1_RCV);
204 omap_cfg_reg(USB1_VP);
205 omap_cfg_reg(USB1_VM);
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)
222 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB2_UNI_R;
226 /* external transceiver */
227 if (cpu_is_omap1510()) {
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 } else if (cpu_is_omap1610() || cpu_is_omap5912() || cpu_is_omap1710()) {
234 omap_cfg_reg(V6_USB2_TXD);
235 omap_cfg_reg(W9_USB2_TXEN);
236 omap_cfg_reg(W5_USB2_SE0);
238 omap_cfg_reg(Y5_USB2_RCV);
240 pr_debug("usb unrecognized\n");
242 // omap_cfg_reg(USB2_SUSP);
243 // FIXME omap_cfg_reg(USB2_SPEED);
254 if (cpu_is_omap1510()) {
255 omap_cfg_reg(USB2_VP);
256 omap_cfg_reg(USB2_VM);
258 omap_cfg_reg(AA9_USB2_VP);
259 omap_cfg_reg(R9_USB2_VM);
261 USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;
264 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
267 return syscon1 << 24;
270 /*-------------------------------------------------------------------------*/
272 #if defined(CONFIG_USB_GADGET_OMAP) || \
273 defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) || \
274 (defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG))
275 static void usb_release(struct device *dev)
277 /* normally not freed */
281 #ifdef CONFIG_USB_GADGET_OMAP
283 static struct resource udc_resources[] = {
284 /* order is significant! */
286 .start = IO_ADDRESS(UDC_BASE),
287 .end = IO_ADDRESS(UDC_BASE + 0xff),
288 .flags = IORESOURCE_MEM,
289 }, { /* general IRQ */
290 .start = IH2_BASE + 20,
291 .flags = IORESOURCE_IRQ,
293 .start = IH2_BASE + 30,
294 .flags = IORESOURCE_IRQ,
296 .start = IH2_BASE + 29,
297 .flags = IORESOURCE_IRQ,
301 static u64 udc_dmamask = ~(u32)0;
303 static struct platform_device udc_device = {
307 .release = usb_release,
308 .dma_mask = &udc_dmamask,
309 .coherent_dma_mask = 0xffffffff,
311 .num_resources = ARRAY_SIZE(udc_resources),
312 .resource = udc_resources,
317 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
319 /* The dmamask must be set for OHCI to work */
320 static u64 ohci_dmamask = ~(u32)0;
322 static struct resource ohci_resources[] = {
324 .start = IO_ADDRESS(OMAP_OHCI_BASE),
325 .end = IO_ADDRESS(OMAP_OHCI_BASE + 4096),
326 .flags = IORESOURCE_MEM,
329 .start = INT_USB_HHC_1,
330 .flags = IORESOURCE_IRQ,
334 static struct platform_device ohci_device = {
338 .release = usb_release,
339 .dma_mask = &ohci_dmamask,
340 .coherent_dma_mask = 0x0fffffff,
342 .num_resources = ARRAY_SIZE(ohci_resources),
343 .resource = ohci_resources,
348 #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
350 static struct resource otg_resources[] = {
351 /* order is significant! */
353 .start = IO_ADDRESS(OTG_BASE),
354 .end = IO_ADDRESS(OTG_BASE + 0xff),
355 .flags = IORESOURCE_MEM,
357 .start = IH2_BASE + 8,
358 .flags = IORESOURCE_IRQ,
362 static struct platform_device otg_device = {
366 .release = usb_release,
368 .num_resources = ARRAY_SIZE(otg_resources),
369 .resource = otg_resources,
374 /*-------------------------------------------------------------------------*/
376 // FIXME correct answer depends on hmc_mode,
377 // as does any nonzero value for config->otg port number
378 #define is_usb0_device(config) 0
380 /*-------------------------------------------------------------------------*/
382 #ifdef CONFIG_ARCH_OMAP_OTG
385 omap_otg_init(struct omap_usb_config *config)
387 u32 syscon = OTG_SYSCON_1_REG & 0xffff;
389 int alt_pingroup = 0;
391 /* NOTE: no bus or clock setup (yet?) */
393 syscon = OTG_SYSCON_1_REG & 0xffff;
394 if (!(syscon & OTG_RESET_DONE))
395 pr_debug("USB resets not complete?\n");
397 // OTG_IRQ_EN_REG = 0;
399 /* pin muxing and transceiver pinouts */
400 if (config->pins[0] > 2) /* alt pingroup 2 */
402 syscon |= omap_usb0_init(config->pins[0], is_usb0_device(config));
403 syscon |= omap_usb1_init(config->pins[1]);
404 syscon |= omap_usb2_init(config->pins[2], alt_pingroup);
405 pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
406 OTG_SYSCON_1_REG = syscon;
408 syscon = config->hmc_mode;
409 syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
410 if (config->otg || config->register_host)
412 #ifdef CONFIG_USB_OTG
416 pr_debug("OTG_SYSCON_2_REG = %08x\n", syscon);
417 OTG_SYSCON_2_REG = syscon;
419 printk("USB: hmc %d", config->hmc_mode);
421 printk(", usb2 alt %d wires", config->pins[2]);
422 else if (config->pins[0])
423 printk(", usb0 %d wires%s", config->pins[2],
424 is_usb0_device(config) ? " (dev)" : "");
426 printk(", usb1 %d wires", config->pins[1]);
427 if (!alt_pingroup && config->pins[2])
428 printk(", usb2 %d wires", config->pins[2]);
430 printk(", Mini-AB on usb%d", config->otg - 1);
433 /* don't clock unused USB controllers */
434 syscon = OTG_SYSCON_1_REG;
435 syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
437 #ifdef CONFIG_USB_GADGET_OMAP
438 if (config->otg || config->register_dev) {
439 syscon &= ~DEV_IDLE_EN;
440 udc_device.dev.platform_data = config;
441 status = platform_device_register(&udc_device);
443 pr_debug("can't register UDC device, %d\n", status);
447 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
448 if (config->otg || config->register_host) {
449 syscon &= ~HST_IDLE_EN;
450 ohci_device.dev.platform_data = config;
451 status = platform_device_register(&ohci_device);
453 pr_debug("can't register OHCI device, %d\n", status);
457 #ifdef CONFIG_USB_OTG
459 syscon &= ~OTG_IDLE_EN;
460 if (cpu_is_omap730())
461 otg_resources[1].start = INT_730_USB_OTG;
462 status = platform_device_register(&otg_device);
466 pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
467 OTG_SYSCON_1_REG = syscon;
473 static inline void omap_otg_init(struct omap_usb_config *config) {}
476 /*-------------------------------------------------------------------------*/
478 #ifdef CONFIG_ARCH_OMAP1510
480 static void __init omap_1510_usb_init(struct omap_usb_config *config)
485 omap_usb0_init(config->pins[0], is_usb0_device(config));
486 omap_usb1_init(config->pins[1]);
487 omap_usb2_init(config->pins[2], 0);
489 val = omap_readl(MOD_CONF_CTRL_0) & ~(0x3f << 1);
490 val |= (config->hmc_mode << 1);
491 omap_writel(val, MOD_CONF_CTRL_0);
493 // FIXME this has a UDC controller too
495 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
496 if (config->otg || config->register_host) {
497 ohci_device.dev.platform_data = config;
498 status = platform_device_register(&ohci_device);
500 pr_debug("can't register OHCI device, %d\n", status);
502 // FIXME completely untested ...
508 static inline void omap_1510_usb_init(struct omap_usb_config *config) {}
511 /*-------------------------------------------------------------------------*/
513 static struct omap_usb_config platform_data;
518 const struct omap_usb_config *config;
520 config = omap_get_config(OMAP_TAG_USB, struct omap_usb_config);
521 if (config == NULL) {
522 printk(KERN_ERR "USB: No board-specific platform config found\n");
525 platform_data = *config;
530 || cpu_is_omap5912())
531 omap_otg_init(&platform_data);
532 else if (cpu_is_omap1510())
533 omap_1510_usb_init(&platform_data);
535 printk(KERN_ERR "USB: No init for your chip yet\n");
541 subsys_initcall(omap_usb_init);