blob: 27b471ce11a00129c40eca799e6d0480438be0bb [file] [log] [blame]
Tony Lindgrenf35ae632008-07-03 12:24:43 +03001 /*
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002 * 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>
Russell Kingfced80c2008-09-06 12:10:45 +010030#include <linux/io.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010031
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010032#include <asm/irq.h>
33#include <asm/system.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010034#include <mach/hardware.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010035
Tony Lindgrence491cf2009-10-20 09:40:47 -070036#include <plat/control.h>
37#include <plat/mux.h>
38#include <plat/usb.h>
39#include <plat/board.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010040
Tony Lindgrenc40fae952006-12-07 13:58:10 -080041#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
46
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010047/* These routines should handle the standard chip-specific modes
48 * for usb0/1/2 ports, covering basic mux and transceiver setup.
49 *
50 * Some board-*.c files will need to set up additional mux options,
51 * like for suspend handling, vbus sensing, GPIOs, and the D+ pullup.
52 */
53
54/* TESTED ON:
55 * - 1611B H2 (with usb1 mini-AB) using standard Mini-B or OTG cables
56 * - 5912 OSK OHCI (with usb0 standard-A), standard A-to-B cables
57 * - 5912 OSK UDC, with *nonstandard* A-to-A cable
58 * - 1510 Innovator UDC with bundled usb0 cable
59 * - 1510 Innovator OHCI with bundled usb1/usb2 cable
60 * - 1510 Innovator OHCI with custom usb0 cable, feeding 5V VBUS
61 * - 1710 custom development board using alternate pin group
62 * - 1710 H3 (with usb1 mini-AB) using standard Mini-B or OTG cables
63 */
64
65/*-------------------------------------------------------------------------*/
66
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000067#if defined(CONFIG_ARCH_OMAP_OTG) || defined(CONFIG_ARCH_OMAP15XX)
68
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010069static u32 __init omap_usb0_init(unsigned nwires, unsigned is_device)
70{
71 u32 syscon1 = 0;
72
73 if (nwires == 0) {
Tony Lindgrendba638d2010-07-05 16:31:28 +030074 if (!cpu_is_omap15xx()) {
Tony Lindgrenf35ae632008-07-03 12:24:43 +030075 u32 l;
76
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010077 /* pulldown D+/D- */
Tony Lindgrenf35ae632008-07-03 12:24:43 +030078 l = omap_readl(USB_TRANSCEIVER_CTRL);
79 l &= ~(3 << 1);
80 omap_writel(l, USB_TRANSCEIVER_CTRL);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010081 }
82 return 0;
83 }
84
Tony Lindgrenc40fae952006-12-07 13:58:10 -080085 if (is_device) {
Tony Lindgrendba638d2010-07-05 16:31:28 +030086 if (cpu_is_omap7xx()) {
Cory Maccarrone106997c2009-12-11 16:16:34 -080087 omap_cfg_reg(AA17_7XX_USB_DM);
88 omap_cfg_reg(W16_7XX_USB_PU_EN);
89 omap_cfg_reg(W17_7XX_USB_VBUSI);
90 omap_cfg_reg(W18_7XX_USB_DMCK_OUT);
91 omap_cfg_reg(W19_7XX_USB_DCRST);
92 } else
Tony Lindgrenc40fae952006-12-07 13:58:10 -080093 omap_cfg_reg(W4_USB_PUEN);
94 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010095
Tony Lindgrendba638d2010-07-05 16:31:28 +030096 if (nwires == 2) {
Tony Lindgrenf35ae632008-07-03 12:24:43 +030097 u32 l;
98
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010099 // omap_cfg_reg(P9_USB_DP);
100 // omap_cfg_reg(R8_USB_DM);
101
102 if (cpu_is_omap15xx()) {
103 /* This works on 1510-Innovator */
104 return 0;
105 }
106
107 /* NOTES:
108 * - peripheral should configure VBUS detection!
109 * - only peripherals may use the internal D+/D- pulldowns
110 * - OTG support on this port not yet written
111 */
112
Cory Maccarrone45f780a2009-11-22 10:10:52 -0800113 /* Don't do this for omap7xx -- it causes USB to not work correctly */
114 if (!cpu_is_omap7xx()) {
115 l = omap_readl(USB_TRANSCEIVER_CTRL);
116 l &= ~(7 << 4);
117 if (!is_device)
118 l |= (3 << 1);
119 omap_writel(l, USB_TRANSCEIVER_CTRL);
120 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100121
122 return 3 << 16;
123 }
124
125 /* alternate pin config, external transceiver */
126 if (cpu_is_omap15xx()) {
127 printk(KERN_ERR "no usb0 alt pin config on 15xx\n");
128 return 0;
129 }
130
Tony Lindgrendba638d2010-07-05 16:31:28 +0300131 omap_cfg_reg(V6_USB0_TXD);
132 omap_cfg_reg(W9_USB0_TXEN);
133 omap_cfg_reg(W5_USB0_SE0);
134 if (nwires != 3)
135 omap_cfg_reg(Y5_USB0_RCV);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100136
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800137 /* NOTE: SPEED and SUSP aren't configured here. OTG hosts
138 * may be able to use I2C requests to set those bits along
Simon Arlott6cbdc8c2007-05-11 20:40:30 +0100139 * with VBUS switching and overcurrent detection.
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800140 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100141
Tony Lindgrendba638d2010-07-05 16:31:28 +0300142 if (nwires != 6) {
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300143 u32 l;
144
145 l = omap_readl(USB_TRANSCEIVER_CTRL);
146 l &= ~CONF_USB2_UNI_R;
147 omap_writel(l, USB_TRANSCEIVER_CTRL);
148 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100149
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;
Tony Lindgrendba638d2010-07-05 16:31:28 +0300159 {
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300160 u32 l;
161
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800162 omap_cfg_reg(AA9_USB0_VP);
163 omap_cfg_reg(R9_USB0_VM);
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300164 l = omap_readl(USB_TRANSCEIVER_CTRL);
165 l |= CONF_USB2_UNI_R;
166 omap_writel(l, USB_TRANSCEIVER_CTRL);
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800167 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100168 break;
169 default:
170 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
171 0, nwires);
172 }
173 return syscon1 << 16;
174}
175
176static u32 __init omap_usb1_init(unsigned nwires)
177{
178 u32 syscon1 = 0;
179
Tony Lindgrendba638d2010-07-05 16:31:28 +0300180 if (!cpu_is_omap15xx() && nwires != 6) {
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300181 u32 l;
182
183 l = omap_readl(USB_TRANSCEIVER_CTRL);
184 l &= ~CONF_USB1_UNI_R;
185 omap_writel(l, USB_TRANSCEIVER_CTRL);
186 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100187 if (nwires == 0)
188 return 0;
189
190 /* external transceiver */
Tony Lindgrendba638d2010-07-05 16:31:28 +0300191 omap_cfg_reg(USB1_TXD);
192 omap_cfg_reg(USB1_TXEN);
193 if (nwires != 3)
194 omap_cfg_reg(USB1_RCV);
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800195
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100196 if (cpu_is_omap15xx()) {
197 omap_cfg_reg(USB1_SEO);
198 omap_cfg_reg(USB1_SPEED);
199 // SUSP
200 } else if (cpu_is_omap1610() || cpu_is_omap5912()) {
201 omap_cfg_reg(W13_1610_USB1_SE0);
202 omap_cfg_reg(R13_1610_USB1_SPEED);
203 // SUSP
204 } else if (cpu_is_omap1710()) {
205 omap_cfg_reg(R13_1710_USB1_SE0);
206 // SUSP
207 } else {
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800208 pr_debug("usb%d cpu unrecognized\n", 1);
209 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100210 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100211
212 switch (nwires) {
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800213 case 2:
Tony Lindgrendba638d2010-07-05 16:31:28 +0300214 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100215 case 3:
216 syscon1 = 2;
217 break;
218 case 4:
219 syscon1 = 1;
220 break;
221 case 6:
222 syscon1 = 3;
223 omap_cfg_reg(USB1_VP);
224 omap_cfg_reg(USB1_VM);
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300225 if (!cpu_is_omap15xx()) {
226 u32 l;
227
228 l = omap_readl(USB_TRANSCEIVER_CTRL);
229 l |= CONF_USB1_UNI_R;
230 omap_writel(l, USB_TRANSCEIVER_CTRL);
231 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100232 break;
233 default:
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800234bad:
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100235 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
236 1, nwires);
237 }
238 return syscon1 << 20;
239}
240
Tony Lindgrendba638d2010-07-05 16:31:28 +0300241static u32 __init omap_usb2_init(unsigned nwires, unsigned alt_pingroup)
242{
243 u32 syscon1 = 0;
244
Tony Lindgrendba638d2010-07-05 16:31:28 +0300245 /* NOTE omap1 erratum: must leave USB2_UNI_R set if usb0 in use */
246 if (alt_pingroup || nwires == 0)
247 return 0;
248
249 if (!cpu_is_omap15xx() && nwires != 6) {
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300250 u32 l;
251
252 l = omap_readl(USB_TRANSCEIVER_CTRL);
253 l &= ~CONF_USB2_UNI_R;
254 omap_writel(l, USB_TRANSCEIVER_CTRL);
255 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100256
257 /* external transceiver */
258 if (cpu_is_omap15xx()) {
259 omap_cfg_reg(USB2_TXD);
260 omap_cfg_reg(USB2_TXEN);
261 omap_cfg_reg(USB2_SEO);
262 if (nwires != 3)
263 omap_cfg_reg(USB2_RCV);
264 /* there is no USB2_SPEED */
265 } else if (cpu_is_omap16xx()) {
266 omap_cfg_reg(V6_USB2_TXD);
267 omap_cfg_reg(W9_USB2_TXEN);
268 omap_cfg_reg(W5_USB2_SE0);
269 if (nwires != 3)
270 omap_cfg_reg(Y5_USB2_RCV);
271 // FIXME omap_cfg_reg(USB2_SPEED);
272 } else {
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800273 pr_debug("usb%d cpu unrecognized\n", 1);
274 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100275 }
Tony Lindgrendba638d2010-07-05 16:31:28 +0300276 // omap_cfg_reg(USB2_SUSP);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100277
278 switch (nwires) {
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800279 case 2:
Tony Lindgrendba638d2010-07-05 16:31:28 +0300280 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100281 case 3:
282 syscon1 = 2;
283 break;
284 case 4:
285 syscon1 = 1;
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800286 break;
287 case 5:
Tony Lindgrendba638d2010-07-05 16:31:28 +0300288 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100289 case 6:
290 syscon1 = 3;
291 if (cpu_is_omap15xx()) {
292 omap_cfg_reg(USB2_VP);
293 omap_cfg_reg(USB2_VM);
294 } else {
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300295 u32 l;
296
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100297 omap_cfg_reg(AA9_USB2_VP);
298 omap_cfg_reg(R9_USB2_VM);
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300299 l = omap_readl(USB_TRANSCEIVER_CTRL);
300 l |= CONF_USB2_UNI_R;
301 omap_writel(l, USB_TRANSCEIVER_CTRL);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100302 }
303 break;
304 default:
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800305bad:
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100306 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
307 2, nwires);
308 }
309 return syscon1 << 24;
310}
311
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300312#else
313#define omap_usb0_init NULL
314#define omap_usb1_init NULL
315#define omap_usb2_init NULL
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000316#endif
317
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100318/*-------------------------------------------------------------------------*/
319
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100320#ifdef CONFIG_USB_GADGET_OMAP
321
322static struct resource udc_resources[] = {
323 /* order is significant! */
324 { /* registers */
325 .start = UDC_BASE,
326 .end = UDC_BASE + 0xff,
327 .flags = IORESOURCE_MEM,
328 }, { /* general IRQ */
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800329 .start = INT_USB_IRQ_GEN,
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100330 .flags = IORESOURCE_IRQ,
331 }, { /* PIO IRQ */
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800332 .start = INT_USB_IRQ_NISO,
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100333 .flags = IORESOURCE_IRQ,
334 }, { /* SOF IRQ */
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800335 .start = INT_USB_IRQ_ISO,
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100336 .flags = IORESOURCE_IRQ,
337 },
338};
339
340static u64 udc_dmamask = ~(u32)0;
341
342static struct platform_device udc_device = {
343 .name = "omap_udc",
344 .id = -1,
345 .dev = {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100346 .dma_mask = &udc_dmamask,
347 .coherent_dma_mask = 0xffffffff,
348 },
349 .num_resources = ARRAY_SIZE(udc_resources),
350 .resource = udc_resources,
351};
352
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300353static inline void udc_device_init(struct omap_usb_config *pdata)
354{
355 pdata->udc_device = &udc_device;
356}
357
358#else
359
360static inline void udc_device_init(struct omap_usb_config *pdata)
361{
362}
363
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100364#endif
365
366#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
367
368/* The dmamask must be set for OHCI to work */
369static u64 ohci_dmamask = ~(u32)0;
370
371static struct resource ohci_resources[] = {
372 {
373 .start = OMAP_OHCI_BASE,
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800374 .end = OMAP_OHCI_BASE + 0xff,
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100375 .flags = IORESOURCE_MEM,
376 },
377 {
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800378 .start = INT_USB_IRQ_HGEN,
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100379 .flags = IORESOURCE_IRQ,
380 },
381};
382
383static struct platform_device ohci_device = {
384 .name = "ohci",
385 .id = -1,
386 .dev = {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100387 .dma_mask = &ohci_dmamask,
388 .coherent_dma_mask = 0xffffffff,
389 },
390 .num_resources = ARRAY_SIZE(ohci_resources),
391 .resource = ohci_resources,
392};
393
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300394static inline void ohci_device_init(struct omap_usb_config *pdata)
395{
396 pdata->ohci_device = &ohci_device;
397}
398
399#else
400
401static inline void ohci_device_init(struct omap_usb_config *pdata)
402{
403}
404
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100405#endif
406
407#if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
408
409static struct resource otg_resources[] = {
410 /* order is significant! */
411 {
412 .start = OTG_BASE,
413 .end = OTG_BASE + 0xff,
414 .flags = IORESOURCE_MEM,
415 }, {
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800416 .start = INT_USB_IRQ_OTG,
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100417 .flags = IORESOURCE_IRQ,
418 },
419};
420
421static struct platform_device otg_device = {
422 .name = "omap_otg",
423 .id = -1,
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100424 .num_resources = ARRAY_SIZE(otg_resources),
425 .resource = otg_resources,
426};
427
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300428static inline void otg_device_init(struct omap_usb_config *pdata)
429{
430 pdata->otg_device = &otg_device;
431}
432
433#else
434
435static inline void otg_device_init(struct omap_usb_config *pdata)
436{
437}
438
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100439#endif
440
441/*-------------------------------------------------------------------------*/
442
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100443// FIXME correct answer depends on hmc_mode,
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800444// as does (on omap1) any nonzero value for config->otg port number
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100445#ifdef CONFIG_USB_GADGET_OMAP
446#define is_usb0_device(config) 1
447#else
448#define is_usb0_device(config) 0
449#endif
450
451/*-------------------------------------------------------------------------*/
452
453#ifdef CONFIG_ARCH_OMAP_OTG
454
455void __init
456omap_otg_init(struct omap_usb_config *config)
457{
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300458 u32 syscon;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100459 int status;
460 int alt_pingroup = 0;
461
462 /* NOTE: no bus or clock setup (yet?) */
463
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300464 syscon = omap_readl(OTG_SYSCON_1) & 0xffff;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100465 if (!(syscon & OTG_RESET_DONE))
466 pr_debug("USB resets not complete?\n");
467
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300468 //omap_writew(0, OTG_IRQ_EN);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100469
470 /* pin muxing and transceiver pinouts */
471 if (config->pins[0] > 2) /* alt pingroup 2 */
472 alt_pingroup = 1;
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300473 syscon |= config->usb0_init(config->pins[0], is_usb0_device(config));
474 syscon |= config->usb1_init(config->pins[1]);
475 syscon |= config->usb2_init(config->pins[2], alt_pingroup);
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300476 pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
477 omap_writel(syscon, OTG_SYSCON_1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100478
479 syscon = config->hmc_mode;
480 syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
481#ifdef CONFIG_USB_OTG
482 if (config->otg)
483 syscon |= OTG_EN;
484#endif
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800485 if (cpu_class_is_omap1())
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300486 pr_debug("USB_TRANSCEIVER_CTRL = %03x\n",
487 omap_readl(USB_TRANSCEIVER_CTRL));
488 pr_debug("OTG_SYSCON_2 = %08x\n", omap_readl(OTG_SYSCON_2));
489 omap_writel(syscon, OTG_SYSCON_2);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100490
491 printk("USB: hmc %d", config->hmc_mode);
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800492 if (!alt_pingroup)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100493 printk(", usb2 alt %d wires", config->pins[2]);
494 else if (config->pins[0])
495 printk(", usb0 %d wires%s", config->pins[0],
496 is_usb0_device(config) ? " (dev)" : "");
497 if (config->pins[1])
498 printk(", usb1 %d wires", config->pins[1]);
499 if (!alt_pingroup && config->pins[2])
500 printk(", usb2 %d wires", config->pins[2]);
501 if (config->otg)
502 printk(", Mini-AB on usb%d", config->otg - 1);
503 printk("\n");
504
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800505 if (cpu_class_is_omap1()) {
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300506 u16 w;
507
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800508 /* leave USB clocks/controllers off until needed */
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300509 w = omap_readw(ULPD_SOFT_REQ);
510 w &= ~SOFT_USB_CLK_REQ;
511 omap_writew(w, ULPD_SOFT_REQ);
512
513 w = omap_readw(ULPD_CLOCK_CTRL);
514 w &= ~USB_MCLK_EN;
515 w |= DIS_USB_PVCI_CLK;
516 omap_writew(w, ULPD_CLOCK_CTRL);
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800517 }
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300518 syscon = omap_readl(OTG_SYSCON_1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100519 syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
520
521#ifdef CONFIG_USB_GADGET_OMAP
522 if (config->otg || config->register_dev) {
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300523 struct platform_device *udc_device = config->udc_device;
524
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100525 syscon &= ~DEV_IDLE_EN;
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300526 udc_device->dev.platform_data = config;
Cory Maccarrone45f780a2009-11-22 10:10:52 -0800527 /* IRQ numbers for omap7xx */
528 if(cpu_is_omap7xx()) {
529 udc_resources[1].start = INT_7XX_USB_GENI;
530 udc_resources[2].start = INT_7XX_USB_NON_ISO;
531 udc_resources[3].start = INT_7XX_USB_ISO;
532 }
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300533 status = platform_device_register(udc_device);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100534 if (status)
535 pr_debug("can't register UDC device, %d\n", status);
536 }
537#endif
538
539#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
540 if (config->otg || config->register_host) {
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300541 struct platform_device *ohci_device = config->ohci_device;
542
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100543 syscon &= ~HST_IDLE_EN;
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300544 ohci_device->dev.platform_data = config;
Alistair Buxton207b0e92009-09-22 06:01:08 +0100545 if (cpu_is_omap7xx())
Alistair Buxton372b1c32009-09-18 04:09:39 +0100546 ohci_resources[1].start = INT_7XX_USB_HHC_1;
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300547 status = platform_device_register(ohci_device);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100548 if (status)
549 pr_debug("can't register OHCI device, %d\n", status);
550 }
551#endif
552
553#ifdef CONFIG_USB_OTG
554 if (config->otg) {
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300555 struct platform_device *otg_device = config->otg_device;
556
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100557 syscon &= ~OTG_IDLE_EN;
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300558 otg_device->dev.platform_data = config;
Alistair Buxton207b0e92009-09-22 06:01:08 +0100559 if (cpu_is_omap7xx())
Alistair Buxton372b1c32009-09-18 04:09:39 +0100560 otg_resources[1].start = INT_7XX_USB_OTG;
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300561 status = platform_device_register(otg_device);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100562 if (status)
563 pr_debug("can't register OTG device, %d\n", status);
564 }
565#endif
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300566 pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
567 omap_writel(syscon, OTG_SYSCON_1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100568
569 status = 0;
570}
571
572#else
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300573void omap_otg_init(struct omap_usb_config *config) {}
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100574#endif
575
576/*-------------------------------------------------------------------------*/
577
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000578#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100579
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300580/* ULPD_DPLL_CTRL */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100581#define DPLL_IOB (1 << 13)
582#define DPLL_PLL_ENABLE (1 << 4)
583#define DPLL_LOCK (1 << 0)
584
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300585/* ULPD_APLL_CTRL */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100586#define APLL_NDPLL_SWITCH (1 << 0)
587
588
589static void __init omap_1510_usb_init(struct omap_usb_config *config)
590{
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100591 unsigned int val;
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300592 u16 w;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100593
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300594 config->usb0_init(config->pins[0], is_usb0_device(config));
595 config->usb1_init(config->pins[1]);
596 config->usb2_init(config->pins[2], 0);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100597
598 val = omap_readl(MOD_CONF_CTRL_0) & ~(0x3f << 1);
599 val |= (config->hmc_mode << 1);
600 omap_writel(val, MOD_CONF_CTRL_0);
601
602 printk("USB: hmc %d", config->hmc_mode);
603 if (config->pins[0])
604 printk(", usb0 %d wires%s", config->pins[0],
605 is_usb0_device(config) ? " (dev)" : "");
606 if (config->pins[1])
607 printk(", usb1 %d wires", config->pins[1]);
608 if (config->pins[2])
609 printk(", usb2 %d wires", config->pins[2]);
610 printk("\n");
611
612 /* use DPLL for 48 MHz function clock */
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300613 pr_debug("APLL %04x DPLL %04x REQ %04x\n", omap_readw(ULPD_APLL_CTRL),
614 omap_readw(ULPD_DPLL_CTRL), omap_readw(ULPD_SOFT_REQ));
615
616 w = omap_readw(ULPD_APLL_CTRL);
617 w &= ~APLL_NDPLL_SWITCH;
618 omap_writew(w, ULPD_APLL_CTRL);
619
620 w = omap_readw(ULPD_DPLL_CTRL);
621 w |= DPLL_IOB | DPLL_PLL_ENABLE;
622 omap_writew(w, ULPD_DPLL_CTRL);
623
624 w = omap_readw(ULPD_SOFT_REQ);
625 w |= SOFT_UDC_REQ | SOFT_DPLL_REQ;
626 omap_writew(w, ULPD_SOFT_REQ);
627
628 while (!(omap_readw(ULPD_DPLL_CTRL) & DPLL_LOCK))
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100629 cpu_relax();
630
631#ifdef CONFIG_USB_GADGET_OMAP
632 if (config->register_dev) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000633 int status;
634
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100635 udc_device.dev.platform_data = config;
636 status = platform_device_register(&udc_device);
637 if (status)
638 pr_debug("can't register UDC device, %d\n", status);
639 /* udc driver gates 48MHz by D+ pullup */
640 }
641#endif
642
643#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
644 if (config->register_host) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000645 int status;
646
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100647 ohci_device.dev.platform_data = config;
648 status = platform_device_register(&ohci_device);
649 if (status)
650 pr_debug("can't register OHCI device, %d\n", status);
651 /* hcd explicitly gates 48MHz */
652 }
653#endif
654}
655
656#else
657static inline void omap_1510_usb_init(struct omap_usb_config *config) {}
658#endif
659
660/*-------------------------------------------------------------------------*/
661
Felipe Balbib0b5aa32009-03-23 18:07:49 -0700662void __init omap_usb_init(struct omap_usb_config *pdata)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100663{
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300664 pdata->usb0_init = omap_usb0_init;
665 pdata->usb1_init = omap_usb1_init;
666 pdata->usb2_init = omap_usb2_init;
667 udc_device_init(pdata);
668 ohci_device_init(pdata);
669 otg_device_init(pdata);
670
671 if (cpu_is_omap7xx() || cpu_is_omap16xx())
Felipe Balbib0b5aa32009-03-23 18:07:49 -0700672 omap_otg_init(pdata);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100673 else if (cpu_is_omap15xx())
Felipe Balbib0b5aa32009-03-23 18:07:49 -0700674 omap_1510_usb_init(pdata);
675 else
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100676 printk(KERN_ERR "USB: No init for your chip yet\n");
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100677}
678