blob: 7e8096809be2bc227ef4e8acb310455a92d8cbfb [file] [log] [blame]
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001/*
2 * arch/arm/plat-omap/usb.c -- platform level USB initialization
3 *
4 * Copyright (C) 2004 Texas Instruments, Inc.
5 *
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.
10 *
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.
15 *
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
19 */
20
21#undef DEBUG
22
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010023#include <linux/module.h>
24#include <linux/kernel.h>
25#include <linux/types.h>
26#include <linux/errno.h>
27#include <linux/init.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010028#include <linux/platform_device.h>
David Brownell3a16f7b2006-06-29 12:27:23 -070029#include <linux/usb/otg.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010030
31#include <asm/io.h>
32#include <asm/irq.h>
33#include <asm/system.h>
34#include <asm/hardware.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010035
36#include <asm/arch/mux.h>
37#include <asm/arch/usb.h>
38#include <asm/arch/board.h>
39
40/* These routines should handle the standard chip-specific modes
41 * for usb0/1/2 ports, covering basic mux and transceiver setup.
Tony Lindgren92105bb2005-09-07 17:20:26 +010042 * Call omap_usb_init() once, from INIT_MACHINE().
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010043 *
44 * Some board-*.c files will need to set up additional mux options,
45 * like for suspend handling, vbus sensing, GPIOs, and the D+ pullup.
46 */
47
48/* TESTED ON:
49 * - 1611B H2 (with usb1 mini-AB) using standard Mini-B or OTG cables
50 * - 5912 OSK OHCI (with usb0 standard-A), standard A-to-B cables
51 * - 5912 OSK UDC, with *nonstandard* A-to-A cable
52 * - 1510 Innovator UDC with bundled usb0 cable
53 * - 1510 Innovator OHCI with bundled usb1/usb2 cable
54 * - 1510 Innovator OHCI with custom usb0 cable, feeding 5V VBUS
55 * - 1710 custom development board using alternate pin group
56 * - 1710 H3 (with usb1 mini-AB) using standard Mini-B or OTG cables
57 */
58
59/*-------------------------------------------------------------------------*/
60
61#ifdef CONFIG_ARCH_OMAP_OTG
62
63static struct otg_transceiver *xceiv;
64
65/**
66 * otg_get_transceiver - find the (single) OTG transceiver driver
67 *
68 * Returns the transceiver driver, after getting a refcount to it; or
69 * null if there is no such transceiver. The caller is responsible for
70 * releasing that count.
71 */
72struct otg_transceiver *otg_get_transceiver(void)
73{
74 if (xceiv)
75 get_device(xceiv->dev);
76 return xceiv;
77}
78EXPORT_SYMBOL(otg_get_transceiver);
79
80int otg_set_transceiver(struct otg_transceiver *x)
81{
82 if (xceiv && x)
83 return -EBUSY;
84 xceiv = x;
85 return 0;
86}
87EXPORT_SYMBOL(otg_set_transceiver);
88
89#endif
90
91/*-------------------------------------------------------------------------*/
92
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000093#if defined(CONFIG_ARCH_OMAP_OTG) || defined(CONFIG_ARCH_OMAP15XX)
94
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010095static u32 __init omap_usb0_init(unsigned nwires, unsigned is_device)
96{
97 u32 syscon1 = 0;
98
99 if (nwires == 0) {
100 if (!cpu_is_omap15xx()) {
101 /* pulldown D+/D- */
102 USB_TRANSCEIVER_CTRL_REG &= ~(3 << 1);
103 }
104 return 0;
105 }
106
107 if (is_device)
108 omap_cfg_reg(W4_USB_PUEN);
109
110 /* internal transceiver */
111 if (nwires == 2) {
112 // omap_cfg_reg(P9_USB_DP);
113 // omap_cfg_reg(R8_USB_DM);
114
115 if (cpu_is_omap15xx()) {
116 /* This works on 1510-Innovator */
117 return 0;
118 }
119
120 /* NOTES:
121 * - peripheral should configure VBUS detection!
122 * - only peripherals may use the internal D+/D- pulldowns
123 * - OTG support on this port not yet written
124 */
125
126 USB_TRANSCEIVER_CTRL_REG &= ~(7 << 4);
127 if (!is_device)
128 USB_TRANSCEIVER_CTRL_REG |= (3 << 1);
129
130 return 3 << 16;
131 }
132
133 /* alternate pin config, external transceiver */
134 if (cpu_is_omap15xx()) {
135 printk(KERN_ERR "no usb0 alt pin config on 15xx\n");
136 return 0;
137 }
138
139 omap_cfg_reg(V6_USB0_TXD);
140 omap_cfg_reg(W9_USB0_TXEN);
141 omap_cfg_reg(W5_USB0_SE0);
142
143 /* NOTE: SPEED and SUSP aren't configured here */
144
145 if (nwires != 3)
146 omap_cfg_reg(Y5_USB0_RCV);
147 if (nwires != 6)
148 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB2_UNI_R;
149
150 switch (nwires) {
151 case 3:
152 syscon1 = 2;
153 break;
154 case 4:
155 syscon1 = 1;
156 break;
157 case 6:
158 syscon1 = 3;
159 omap_cfg_reg(AA9_USB0_VP);
160 omap_cfg_reg(R9_USB0_VM);
161 USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;
162 break;
163 default:
164 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
165 0, nwires);
166 }
167 return syscon1 << 16;
168}
169
170static u32 __init omap_usb1_init(unsigned nwires)
171{
172 u32 syscon1 = 0;
173
174 if (nwires != 6 && !cpu_is_omap15xx())
175 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB1_UNI_R;
176 if (nwires == 0)
177 return 0;
178
179 /* external transceiver */
180 omap_cfg_reg(USB1_TXD);
181 omap_cfg_reg(USB1_TXEN);
182 if (cpu_is_omap15xx()) {
183 omap_cfg_reg(USB1_SEO);
184 omap_cfg_reg(USB1_SPEED);
185 // SUSP
186 } else if (cpu_is_omap1610() || cpu_is_omap5912()) {
187 omap_cfg_reg(W13_1610_USB1_SE0);
188 omap_cfg_reg(R13_1610_USB1_SPEED);
189 // SUSP
190 } else if (cpu_is_omap1710()) {
191 omap_cfg_reg(R13_1710_USB1_SE0);
192 // SUSP
193 } else {
194 pr_debug("usb unrecognized\n");
195 }
196 if (nwires != 3)
197 omap_cfg_reg(USB1_RCV);
198
199 switch (nwires) {
200 case 3:
201 syscon1 = 2;
202 break;
203 case 4:
204 syscon1 = 1;
205 break;
206 case 6:
207 syscon1 = 3;
208 omap_cfg_reg(USB1_VP);
209 omap_cfg_reg(USB1_VM);
210 if (!cpu_is_omap15xx())
211 USB_TRANSCEIVER_CTRL_REG |= CONF_USB1_UNI_R;
212 break;
213 default:
214 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
215 1, nwires);
216 }
217 return syscon1 << 20;
218}
219
220static u32 __init omap_usb2_init(unsigned nwires, unsigned alt_pingroup)
221{
222 u32 syscon1 = 0;
223
224 /* NOTE erratum: must leave USB2_UNI_R set if usb0 in use */
225 if (alt_pingroup || nwires == 0)
226 return 0;
227 if (nwires != 6 && !cpu_is_omap15xx())
228 USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB2_UNI_R;
229
230 /* external transceiver */
231 if (cpu_is_omap15xx()) {
232 omap_cfg_reg(USB2_TXD);
233 omap_cfg_reg(USB2_TXEN);
234 omap_cfg_reg(USB2_SEO);
235 if (nwires != 3)
236 omap_cfg_reg(USB2_RCV);
237 /* there is no USB2_SPEED */
238 } else if (cpu_is_omap16xx()) {
239 omap_cfg_reg(V6_USB2_TXD);
240 omap_cfg_reg(W9_USB2_TXEN);
241 omap_cfg_reg(W5_USB2_SE0);
242 if (nwires != 3)
243 omap_cfg_reg(Y5_USB2_RCV);
244 // FIXME omap_cfg_reg(USB2_SPEED);
245 } else {
246 pr_debug("usb unrecognized\n");
247 }
248 // omap_cfg_reg(USB2_SUSP);
249
250 switch (nwires) {
251 case 3:
252 syscon1 = 2;
253 break;
254 case 4:
255 syscon1 = 1;
256 break;
257 case 6:
258 syscon1 = 3;
259 if (cpu_is_omap15xx()) {
260 omap_cfg_reg(USB2_VP);
261 omap_cfg_reg(USB2_VM);
262 } else {
263 omap_cfg_reg(AA9_USB2_VP);
264 omap_cfg_reg(R9_USB2_VM);
265 USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;
266 }
267 break;
268 default:
269 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
270 2, nwires);
271 }
272 return syscon1 << 24;
273}
274
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000275#endif
276
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100277/*-------------------------------------------------------------------------*/
278
279#if defined(CONFIG_USB_GADGET_OMAP) || \
280 defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) || \
281 (defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG))
282static void usb_release(struct device *dev)
283{
284 /* normally not freed */
285}
286#endif
287
288#ifdef CONFIG_USB_GADGET_OMAP
289
290static struct resource udc_resources[] = {
291 /* order is significant! */
292 { /* registers */
293 .start = UDC_BASE,
294 .end = UDC_BASE + 0xff,
295 .flags = IORESOURCE_MEM,
296 }, { /* general IRQ */
297 .start = IH2_BASE + 20,
298 .flags = IORESOURCE_IRQ,
299 }, { /* PIO IRQ */
300 .start = IH2_BASE + 30,
301 .flags = IORESOURCE_IRQ,
302 }, { /* SOF IRQ */
303 .start = IH2_BASE + 29,
304 .flags = IORESOURCE_IRQ,
305 },
306};
307
308static u64 udc_dmamask = ~(u32)0;
309
310static struct platform_device udc_device = {
311 .name = "omap_udc",
312 .id = -1,
313 .dev = {
314 .release = usb_release,
315 .dma_mask = &udc_dmamask,
316 .coherent_dma_mask = 0xffffffff,
317 },
318 .num_resources = ARRAY_SIZE(udc_resources),
319 .resource = udc_resources,
320};
321
322#endif
323
324#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
325
326/* The dmamask must be set for OHCI to work */
327static u64 ohci_dmamask = ~(u32)0;
328
329static struct resource ohci_resources[] = {
330 {
331 .start = OMAP_OHCI_BASE,
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +0100332 .end = OMAP_OHCI_BASE + 4096 - 1,
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100333 .flags = IORESOURCE_MEM,
334 },
335 {
336 .start = INT_USB_HHC_1,
337 .flags = IORESOURCE_IRQ,
338 },
339};
340
341static struct platform_device ohci_device = {
342 .name = "ohci",
343 .id = -1,
344 .dev = {
345 .release = usb_release,
346 .dma_mask = &ohci_dmamask,
347 .coherent_dma_mask = 0xffffffff,
348 },
349 .num_resources = ARRAY_SIZE(ohci_resources),
350 .resource = ohci_resources,
351};
352
353#endif
354
355#if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
356
357static struct resource otg_resources[] = {
358 /* order is significant! */
359 {
360 .start = OTG_BASE,
361 .end = OTG_BASE + 0xff,
362 .flags = IORESOURCE_MEM,
363 }, {
364 .start = IH2_BASE + 8,
365 .flags = IORESOURCE_IRQ,
366 },
367};
368
369static struct platform_device otg_device = {
370 .name = "omap_otg",
371 .id = -1,
372 .dev = {
373 .release = usb_release,
374 },
375 .num_resources = ARRAY_SIZE(otg_resources),
376 .resource = otg_resources,
377};
378
379#endif
380
381/*-------------------------------------------------------------------------*/
382
383#define ULPD_CLOCK_CTRL_REG __REG16(ULPD_CLOCK_CTRL)
384#define ULPD_SOFT_REQ_REG __REG16(ULPD_SOFT_REQ)
385
386
387// FIXME correct answer depends on hmc_mode,
388// as does any nonzero value for config->otg port number
389#ifdef CONFIG_USB_GADGET_OMAP
390#define is_usb0_device(config) 1
391#else
392#define is_usb0_device(config) 0
393#endif
394
395/*-------------------------------------------------------------------------*/
396
397#ifdef CONFIG_ARCH_OMAP_OTG
398
399void __init
400omap_otg_init(struct omap_usb_config *config)
401{
402 u32 syscon = OTG_SYSCON_1_REG & 0xffff;
403 int status;
404 int alt_pingroup = 0;
405
406 /* NOTE: no bus or clock setup (yet?) */
407
408 syscon = OTG_SYSCON_1_REG & 0xffff;
409 if (!(syscon & OTG_RESET_DONE))
410 pr_debug("USB resets not complete?\n");
411
412 // OTG_IRQ_EN_REG = 0;
413
414 /* pin muxing and transceiver pinouts */
415 if (config->pins[0] > 2) /* alt pingroup 2 */
416 alt_pingroup = 1;
417 syscon |= omap_usb0_init(config->pins[0], is_usb0_device(config));
418 syscon |= omap_usb1_init(config->pins[1]);
419 syscon |= omap_usb2_init(config->pins[2], alt_pingroup);
420 pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
421 OTG_SYSCON_1_REG = syscon;
422
423 syscon = config->hmc_mode;
424 syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
425#ifdef CONFIG_USB_OTG
426 if (config->otg)
427 syscon |= OTG_EN;
428#endif
429 pr_debug("USB_TRANSCEIVER_CTRL_REG = %03x\n", USB_TRANSCEIVER_CTRL_REG);
430 pr_debug("OTG_SYSCON_2_REG = %08x\n", syscon);
431 OTG_SYSCON_2_REG = syscon;
432
433 printk("USB: hmc %d", config->hmc_mode);
434 if (alt_pingroup)
435 printk(", usb2 alt %d wires", config->pins[2]);
436 else if (config->pins[0])
437 printk(", usb0 %d wires%s", config->pins[0],
438 is_usb0_device(config) ? " (dev)" : "");
439 if (config->pins[1])
440 printk(", usb1 %d wires", config->pins[1]);
441 if (!alt_pingroup && config->pins[2])
442 printk(", usb2 %d wires", config->pins[2]);
443 if (config->otg)
444 printk(", Mini-AB on usb%d", config->otg - 1);
445 printk("\n");
446
447 /* leave USB clocks/controllers off until needed */
448 ULPD_SOFT_REQ_REG &= ~SOFT_USB_CLK_REQ;
449 ULPD_CLOCK_CTRL_REG &= ~USB_MCLK_EN;
450 ULPD_CLOCK_CTRL_REG |= DIS_USB_PVCI_CLK;
451 syscon = OTG_SYSCON_1_REG;
452 syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
453
454#ifdef CONFIG_USB_GADGET_OMAP
455 if (config->otg || config->register_dev) {
456 syscon &= ~DEV_IDLE_EN;
457 udc_device.dev.platform_data = config;
458 /* FIXME patch IRQ numbers for omap730 */
459 status = platform_device_register(&udc_device);
460 if (status)
461 pr_debug("can't register UDC device, %d\n", status);
462 }
463#endif
464
465#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
466 if (config->otg || config->register_host) {
467 syscon &= ~HST_IDLE_EN;
468 ohci_device.dev.platform_data = config;
469 if (cpu_is_omap730())
470 ohci_resources[1].start = INT_730_USB_HHC_1;
471 status = platform_device_register(&ohci_device);
472 if (status)
473 pr_debug("can't register OHCI device, %d\n", status);
474 }
475#endif
476
477#ifdef CONFIG_USB_OTG
478 if (config->otg) {
479 syscon &= ~OTG_IDLE_EN;
480 otg_device.dev.platform_data = config;
481 if (cpu_is_omap730())
482 otg_resources[1].start = INT_730_USB_OTG;
483 status = platform_device_register(&otg_device);
484 if (status)
485 pr_debug("can't register OTG device, %d\n", status);
486 }
487#endif
488 pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
489 OTG_SYSCON_1_REG = syscon;
490
491 status = 0;
492}
493
494#else
495static inline void omap_otg_init(struct omap_usb_config *config) {}
496#endif
497
498/*-------------------------------------------------------------------------*/
499
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000500#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100501
502#define ULPD_DPLL_CTRL_REG __REG16(ULPD_DPLL_CTRL)
503#define DPLL_IOB (1 << 13)
504#define DPLL_PLL_ENABLE (1 << 4)
505#define DPLL_LOCK (1 << 0)
506
507#define ULPD_APLL_CTRL_REG __REG16(ULPD_APLL_CTRL)
508#define APLL_NDPLL_SWITCH (1 << 0)
509
510
511static void __init omap_1510_usb_init(struct omap_usb_config *config)
512{
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100513 unsigned int val;
514
515 omap_usb0_init(config->pins[0], is_usb0_device(config));
516 omap_usb1_init(config->pins[1]);
517 omap_usb2_init(config->pins[2], 0);
518
519 val = omap_readl(MOD_CONF_CTRL_0) & ~(0x3f << 1);
520 val |= (config->hmc_mode << 1);
521 omap_writel(val, MOD_CONF_CTRL_0);
522
523 printk("USB: hmc %d", config->hmc_mode);
524 if (config->pins[0])
525 printk(", usb0 %d wires%s", config->pins[0],
526 is_usb0_device(config) ? " (dev)" : "");
527 if (config->pins[1])
528 printk(", usb1 %d wires", config->pins[1]);
529 if (config->pins[2])
530 printk(", usb2 %d wires", config->pins[2]);
531 printk("\n");
532
533 /* use DPLL for 48 MHz function clock */
534 pr_debug("APLL %04x DPLL %04x REQ %04x\n", ULPD_APLL_CTRL_REG,
535 ULPD_DPLL_CTRL_REG, ULPD_SOFT_REQ_REG);
536 ULPD_APLL_CTRL_REG &= ~APLL_NDPLL_SWITCH;
537 ULPD_DPLL_CTRL_REG |= DPLL_IOB | DPLL_PLL_ENABLE;
538 ULPD_SOFT_REQ_REG |= SOFT_UDC_REQ | SOFT_DPLL_REQ;
539 while (!(ULPD_DPLL_CTRL_REG & DPLL_LOCK))
540 cpu_relax();
541
542#ifdef CONFIG_USB_GADGET_OMAP
543 if (config->register_dev) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000544 int status;
545
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100546 udc_device.dev.platform_data = config;
547 status = platform_device_register(&udc_device);
548 if (status)
549 pr_debug("can't register UDC device, %d\n", status);
550 /* udc driver gates 48MHz by D+ pullup */
551 }
552#endif
553
554#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
555 if (config->register_host) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000556 int status;
557
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100558 ohci_device.dev.platform_data = config;
559 status = platform_device_register(&ohci_device);
560 if (status)
561 pr_debug("can't register OHCI device, %d\n", status);
562 /* hcd explicitly gates 48MHz */
563 }
564#endif
565}
566
567#else
568static inline void omap_1510_usb_init(struct omap_usb_config *config) {}
569#endif
570
571/*-------------------------------------------------------------------------*/
572
573static struct omap_usb_config platform_data;
574
575static int __init
576omap_usb_init(void)
577{
578 const struct omap_usb_config *config;
579
580 config = omap_get_config(OMAP_TAG_USB, struct omap_usb_config);
581 if (config == NULL) {
582 printk(KERN_ERR "USB: No board-specific "
583 "platform config found\n");
584 return -ENODEV;
585 }
586 platform_data = *config;
587
588 if (cpu_is_omap730() || cpu_is_omap16xx())
589 omap_otg_init(&platform_data);
590 else if (cpu_is_omap15xx())
591 omap_1510_usb_init(&platform_data);
592 else {
593 printk(KERN_ERR "USB: No init for your chip yet\n");
594 return -ENODEV;
595 }
596 return 0;
597}
598
599subsys_initcall(omap_usb_init);