blob: add0485703b50941c80f004d522cb80263ba5f41 [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
Russell Kinga09e64f2008-08-05 16:14:15 +010036#include <mach/control.h>
37#include <mach/mux.h>
38#include <mach/usb.h>
39#include <mach/board.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010040
Tony Lindgrenc40fae92006-12-07 13:58:10 -080041#ifdef CONFIG_ARCH_OMAP1
42
43#define INT_USB_IRQ_GEN IH2_BASE + 20
44#define INT_USB_IRQ_NISO IH2_BASE + 30
45#define INT_USB_IRQ_ISO IH2_BASE + 29
46#define INT_USB_IRQ_HGEN INT_USB_HHC_1
47#define INT_USB_IRQ_OTG IH2_BASE + 8
48
49#else
50
51#define INT_USB_IRQ_GEN INT_24XX_USB_IRQ_GEN
52#define INT_USB_IRQ_NISO INT_24XX_USB_IRQ_NISO
53#define INT_USB_IRQ_ISO INT_24XX_USB_IRQ_ISO
54#define INT_USB_IRQ_HGEN INT_24XX_USB_IRQ_HGEN
55#define INT_USB_IRQ_OTG INT_24XX_USB_IRQ_OTG
56
57#endif
58
59
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010060/* These routines should handle the standard chip-specific modes
61 * for usb0/1/2 ports, covering basic mux and transceiver setup.
62 *
63 * Some board-*.c files will need to set up additional mux options,
64 * like for suspend handling, vbus sensing, GPIOs, and the D+ pullup.
65 */
66
67/* TESTED ON:
68 * - 1611B H2 (with usb1 mini-AB) using standard Mini-B or OTG cables
69 * - 5912 OSK OHCI (with usb0 standard-A), standard A-to-B cables
70 * - 5912 OSK UDC, with *nonstandard* A-to-A cable
71 * - 1510 Innovator UDC with bundled usb0 cable
72 * - 1510 Innovator OHCI with bundled usb1/usb2 cable
73 * - 1510 Innovator OHCI with custom usb0 cable, feeding 5V VBUS
74 * - 1710 custom development board using alternate pin group
75 * - 1710 H3 (with usb1 mini-AB) using standard Mini-B or OTG cables
76 */
77
78/*-------------------------------------------------------------------------*/
79
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000080#if defined(CONFIG_ARCH_OMAP_OTG) || defined(CONFIG_ARCH_OMAP15XX)
81
Paul Walmsley69d88a02008-03-18 10:02:50 +020082static void omap2_usb_devconf_clear(u8 port, u32 mask)
83{
84 u32 r;
85
86 r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
87 r &= ~USBTXWRMODEI(port, mask);
88 omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
89}
90
91static void omap2_usb_devconf_set(u8 port, u32 mask)
92{
93 u32 r;
94
95 r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
96 r |= USBTXWRMODEI(port, mask);
97 omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
98}
99
100static void omap2_usb2_disable_5pinbitll(void)
101{
102 u32 r;
103
104 r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
105 r &= ~(USBTXWRMODEI(2, USB_BIDIR_TLL) | USBT2TLL5PI);
106 omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
107}
108
109static void omap2_usb2_enable_5pinunitll(void)
110{
111 u32 r;
112
113 r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
114 r |= USBTXWRMODEI(2, USB_UNIDIR_TLL) | USBT2TLL5PI;
115 omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
116}
117
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100118static u32 __init omap_usb0_init(unsigned nwires, unsigned is_device)
119{
120 u32 syscon1 = 0;
121
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800122 if (cpu_is_omap24xx())
Paul Walmsley69d88a02008-03-18 10:02:50 +0200123 omap2_usb_devconf_clear(0, USB_BIDIR_TLL);
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800124
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100125 if (nwires == 0) {
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800126 if (cpu_class_is_omap1() && !cpu_is_omap15xx()) {
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300127 u32 l;
128
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100129 /* pulldown D+/D- */
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300130 l = omap_readl(USB_TRANSCEIVER_CTRL);
131 l &= ~(3 << 1);
132 omap_writel(l, USB_TRANSCEIVER_CTRL);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100133 }
134 return 0;
135 }
136
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800137 if (is_device) {
138 if (cpu_is_omap24xx())
139 omap_cfg_reg(J20_24XX_USB0_PUEN);
140 else
141 omap_cfg_reg(W4_USB_PUEN);
142 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100143
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800144 /* internal transceiver (unavailable on 17xx, 24xx) */
145 if (!cpu_class_is_omap2() && nwires == 2) {
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300146 u32 l;
147
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100148 // omap_cfg_reg(P9_USB_DP);
149 // omap_cfg_reg(R8_USB_DM);
150
151 if (cpu_is_omap15xx()) {
152 /* This works on 1510-Innovator */
153 return 0;
154 }
155
156 /* NOTES:
157 * - peripheral should configure VBUS detection!
158 * - only peripherals may use the internal D+/D- pulldowns
159 * - OTG support on this port not yet written
160 */
161
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300162 l = omap_readl(USB_TRANSCEIVER_CTRL);
163 l &= ~(7 << 4);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100164 if (!is_device)
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300165 l |= (3 << 1);
166 omap_writel(l, USB_TRANSCEIVER_CTRL);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100167
168 return 3 << 16;
169 }
170
171 /* alternate pin config, external transceiver */
172 if (cpu_is_omap15xx()) {
173 printk(KERN_ERR "no usb0 alt pin config on 15xx\n");
174 return 0;
175 }
176
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800177 if (cpu_is_omap24xx()) {
178 omap_cfg_reg(K18_24XX_USB0_DAT);
179 omap_cfg_reg(K19_24XX_USB0_TXEN);
180 omap_cfg_reg(J14_24XX_USB0_SE0);
181 if (nwires != 3)
182 omap_cfg_reg(J18_24XX_USB0_RCV);
183 } else {
184 omap_cfg_reg(V6_USB0_TXD);
185 omap_cfg_reg(W9_USB0_TXEN);
186 omap_cfg_reg(W5_USB0_SE0);
187 if (nwires != 3)
188 omap_cfg_reg(Y5_USB0_RCV);
189 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100190
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800191 /* NOTE: SPEED and SUSP aren't configured here. OTG hosts
192 * may be able to use I2C requests to set those bits along
Simon Arlott6cbdc8c2007-05-11 20:40:30 +0100193 * with VBUS switching and overcurrent detection.
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800194 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100195
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300196 if (cpu_class_is_omap1() && nwires != 6) {
197 u32 l;
198
199 l = omap_readl(USB_TRANSCEIVER_CTRL);
200 l &= ~CONF_USB2_UNI_R;
201 omap_writel(l, USB_TRANSCEIVER_CTRL);
202 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100203
204 switch (nwires) {
205 case 3:
206 syscon1 = 2;
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800207 if (cpu_is_omap24xx())
Paul Walmsley69d88a02008-03-18 10:02:50 +0200208 omap2_usb_devconf_set(0, USB_BIDIR);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100209 break;
210 case 4:
211 syscon1 = 1;
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800212 if (cpu_is_omap24xx())
Paul Walmsley69d88a02008-03-18 10:02:50 +0200213 omap2_usb_devconf_set(0, USB_BIDIR);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100214 break;
215 case 6:
216 syscon1 = 3;
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800217 if (cpu_is_omap24xx()) {
218 omap_cfg_reg(J19_24XX_USB0_VP);
219 omap_cfg_reg(K20_24XX_USB0_VM);
Paul Walmsley69d88a02008-03-18 10:02:50 +0200220 omap2_usb_devconf_set(0, USB_UNIDIR);
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800221 } else {
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300222 u32 l;
223
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800224 omap_cfg_reg(AA9_USB0_VP);
225 omap_cfg_reg(R9_USB0_VM);
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300226 l = omap_readl(USB_TRANSCEIVER_CTRL);
227 l |= CONF_USB2_UNI_R;
228 omap_writel(l, USB_TRANSCEIVER_CTRL);
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800229 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100230 break;
231 default:
232 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
233 0, nwires);
234 }
235 return syscon1 << 16;
236}
237
238static u32 __init omap_usb1_init(unsigned nwires)
239{
240 u32 syscon1 = 0;
241
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300242 if (cpu_class_is_omap1() && !cpu_is_omap15xx() && nwires != 6) {
243 u32 l;
244
245 l = omap_readl(USB_TRANSCEIVER_CTRL);
246 l &= ~CONF_USB1_UNI_R;
247 omap_writel(l, USB_TRANSCEIVER_CTRL);
248 }
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800249 if (cpu_is_omap24xx())
Paul Walmsley69d88a02008-03-18 10:02:50 +0200250 omap2_usb_devconf_clear(1, USB_BIDIR_TLL);
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800251
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100252 if (nwires == 0)
253 return 0;
254
255 /* external transceiver */
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800256 if (cpu_class_is_omap1()) {
257 omap_cfg_reg(USB1_TXD);
258 omap_cfg_reg(USB1_TXEN);
259 if (nwires != 3)
260 omap_cfg_reg(USB1_RCV);
261 }
262
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100263 if (cpu_is_omap15xx()) {
264 omap_cfg_reg(USB1_SEO);
265 omap_cfg_reg(USB1_SPEED);
266 // SUSP
267 } else if (cpu_is_omap1610() || cpu_is_omap5912()) {
268 omap_cfg_reg(W13_1610_USB1_SE0);
269 omap_cfg_reg(R13_1610_USB1_SPEED);
270 // SUSP
271 } else if (cpu_is_omap1710()) {
272 omap_cfg_reg(R13_1710_USB1_SE0);
273 // SUSP
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800274 } else if (cpu_is_omap24xx()) {
275 /* NOTE: board-specific code must set up pin muxing for usb1,
276 * since each signal could come out on either of two balls.
277 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100278 } else {
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800279 pr_debug("usb%d cpu unrecognized\n", 1);
280 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100281 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100282
283 switch (nwires) {
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800284 case 2:
285 if (!cpu_is_omap24xx())
286 goto bad;
287 /* NOTE: board-specific code must override this setting if
288 * this TLL link is not using DP/DM
289 */
290 syscon1 = 1;
Paul Walmsley69d88a02008-03-18 10:02:50 +0200291 omap2_usb_devconf_set(1, USB_BIDIR_TLL);
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800292 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100293 case 3:
294 syscon1 = 2;
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800295 if (cpu_is_omap24xx())
Paul Walmsley69d88a02008-03-18 10:02:50 +0200296 omap2_usb_devconf_set(1, USB_BIDIR);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100297 break;
298 case 4:
299 syscon1 = 1;
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800300 if (cpu_is_omap24xx())
Paul Walmsley69d88a02008-03-18 10:02:50 +0200301 omap2_usb_devconf_set(1, USB_BIDIR);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100302 break;
303 case 6:
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800304 if (cpu_is_omap24xx())
305 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100306 syscon1 = 3;
307 omap_cfg_reg(USB1_VP);
308 omap_cfg_reg(USB1_VM);
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300309 if (!cpu_is_omap15xx()) {
310 u32 l;
311
312 l = omap_readl(USB_TRANSCEIVER_CTRL);
313 l |= CONF_USB1_UNI_R;
314 omap_writel(l, USB_TRANSCEIVER_CTRL);
315 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100316 break;
317 default:
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800318bad:
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100319 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
320 1, nwires);
321 }
322 return syscon1 << 20;
323}
324
325static u32 __init omap_usb2_init(unsigned nwires, unsigned alt_pingroup)
326{
327 u32 syscon1 = 0;
328
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800329 if (cpu_is_omap24xx()) {
Paul Walmsley69d88a02008-03-18 10:02:50 +0200330 omap2_usb2_disable_5pinbitll();
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800331 alt_pingroup = 0;
332 }
333
334 /* NOTE omap1 erratum: must leave USB2_UNI_R set if usb0 in use */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100335 if (alt_pingroup || nwires == 0)
336 return 0;
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800337
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300338 if (cpu_class_is_omap1() && !cpu_is_omap15xx() && nwires != 6) {
339 u32 l;
340
341 l = omap_readl(USB_TRANSCEIVER_CTRL);
342 l &= ~CONF_USB2_UNI_R;
343 omap_writel(l, USB_TRANSCEIVER_CTRL);
344 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100345
346 /* external transceiver */
347 if (cpu_is_omap15xx()) {
348 omap_cfg_reg(USB2_TXD);
349 omap_cfg_reg(USB2_TXEN);
350 omap_cfg_reg(USB2_SEO);
351 if (nwires != 3)
352 omap_cfg_reg(USB2_RCV);
353 /* there is no USB2_SPEED */
354 } else if (cpu_is_omap16xx()) {
355 omap_cfg_reg(V6_USB2_TXD);
356 omap_cfg_reg(W9_USB2_TXEN);
357 omap_cfg_reg(W5_USB2_SE0);
358 if (nwires != 3)
359 omap_cfg_reg(Y5_USB2_RCV);
360 // FIXME omap_cfg_reg(USB2_SPEED);
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800361 } else if (cpu_is_omap24xx()) {
362 omap_cfg_reg(Y11_24XX_USB2_DAT);
363 omap_cfg_reg(AA10_24XX_USB2_SE0);
364 if (nwires > 2)
365 omap_cfg_reg(AA12_24XX_USB2_TXEN);
366 if (nwires > 3)
367 omap_cfg_reg(AA6_24XX_USB2_RCV);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100368 } else {
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800369 pr_debug("usb%d cpu unrecognized\n", 1);
370 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100371 }
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800372 // if (cpu_class_is_omap1()) omap_cfg_reg(USB2_SUSP);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100373
374 switch (nwires) {
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800375 case 2:
376 if (!cpu_is_omap24xx())
377 goto bad;
378 /* NOTE: board-specific code must override this setting if
379 * this TLL link is not using DP/DM
380 */
381 syscon1 = 1;
Paul Walmsley69d88a02008-03-18 10:02:50 +0200382 omap2_usb_devconf_set(2, USB_BIDIR_TLL);
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800383 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100384 case 3:
385 syscon1 = 2;
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800386 if (cpu_is_omap24xx())
Paul Walmsley69d88a02008-03-18 10:02:50 +0200387 omap2_usb_devconf_set(2, USB_BIDIR);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100388 break;
389 case 4:
390 syscon1 = 1;
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800391 if (cpu_is_omap24xx())
Paul Walmsley69d88a02008-03-18 10:02:50 +0200392 omap2_usb_devconf_set(2, USB_BIDIR);
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800393 break;
394 case 5:
395 if (!cpu_is_omap24xx())
396 goto bad;
397 omap_cfg_reg(AA4_24XX_USB2_TLLSE0);
398 /* NOTE: board-specific code must override this setting if
399 * this TLL link is not using DP/DM. Something must also
400 * set up OTG_SYSCON2.HMC_TLL{ATTACH,SPEED}
401 */
402 syscon1 = 3;
Paul Walmsley69d88a02008-03-18 10:02:50 +0200403 omap2_usb2_enable_5pinunitll();
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100404 break;
405 case 6:
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800406 if (cpu_is_omap24xx())
407 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100408 syscon1 = 3;
409 if (cpu_is_omap15xx()) {
410 omap_cfg_reg(USB2_VP);
411 omap_cfg_reg(USB2_VM);
412 } else {
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300413 u32 l;
414
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100415 omap_cfg_reg(AA9_USB2_VP);
416 omap_cfg_reg(R9_USB2_VM);
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300417 l = omap_readl(USB_TRANSCEIVER_CTRL);
418 l |= CONF_USB2_UNI_R;
419 omap_writel(l, USB_TRANSCEIVER_CTRL);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100420 }
421 break;
422 default:
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800423bad:
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100424 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
425 2, nwires);
426 }
427 return syscon1 << 24;
428}
429
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000430#endif
431
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100432/*-------------------------------------------------------------------------*/
433
434#if defined(CONFIG_USB_GADGET_OMAP) || \
435 defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) || \
436 (defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG))
437static void usb_release(struct device *dev)
438{
439 /* normally not freed */
440}
441#endif
442
443#ifdef CONFIG_USB_GADGET_OMAP
444
445static struct resource udc_resources[] = {
446 /* order is significant! */
447 { /* registers */
448 .start = UDC_BASE,
449 .end = UDC_BASE + 0xff,
450 .flags = IORESOURCE_MEM,
451 }, { /* general IRQ */
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800452 .start = INT_USB_IRQ_GEN,
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100453 .flags = IORESOURCE_IRQ,
454 }, { /* PIO IRQ */
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800455 .start = INT_USB_IRQ_NISO,
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100456 .flags = IORESOURCE_IRQ,
457 }, { /* SOF IRQ */
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800458 .start = INT_USB_IRQ_ISO,
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100459 .flags = IORESOURCE_IRQ,
460 },
461};
462
463static u64 udc_dmamask = ~(u32)0;
464
465static struct platform_device udc_device = {
466 .name = "omap_udc",
467 .id = -1,
468 .dev = {
469 .release = usb_release,
470 .dma_mask = &udc_dmamask,
471 .coherent_dma_mask = 0xffffffff,
472 },
473 .num_resources = ARRAY_SIZE(udc_resources),
474 .resource = udc_resources,
475};
476
477#endif
478
479#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
480
481/* The dmamask must be set for OHCI to work */
482static u64 ohci_dmamask = ~(u32)0;
483
484static struct resource ohci_resources[] = {
485 {
486 .start = OMAP_OHCI_BASE,
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800487 .end = OMAP_OHCI_BASE + 0xff,
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100488 .flags = IORESOURCE_MEM,
489 },
490 {
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800491 .start = INT_USB_IRQ_HGEN,
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100492 .flags = IORESOURCE_IRQ,
493 },
494};
495
496static struct platform_device ohci_device = {
497 .name = "ohci",
498 .id = -1,
499 .dev = {
500 .release = usb_release,
501 .dma_mask = &ohci_dmamask,
502 .coherent_dma_mask = 0xffffffff,
503 },
504 .num_resources = ARRAY_SIZE(ohci_resources),
505 .resource = ohci_resources,
506};
507
508#endif
509
510#if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
511
512static struct resource otg_resources[] = {
513 /* order is significant! */
514 {
515 .start = OTG_BASE,
516 .end = OTG_BASE + 0xff,
517 .flags = IORESOURCE_MEM,
518 }, {
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800519 .start = INT_USB_IRQ_OTG,
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100520 .flags = IORESOURCE_IRQ,
521 },
522};
523
524static struct platform_device otg_device = {
525 .name = "omap_otg",
526 .id = -1,
527 .dev = {
528 .release = usb_release,
529 },
530 .num_resources = ARRAY_SIZE(otg_resources),
531 .resource = otg_resources,
532};
533
534#endif
535
536/*-------------------------------------------------------------------------*/
537
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100538// FIXME correct answer depends on hmc_mode,
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800539// as does (on omap1) any nonzero value for config->otg port number
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100540#ifdef CONFIG_USB_GADGET_OMAP
541#define is_usb0_device(config) 1
542#else
543#define is_usb0_device(config) 0
544#endif
545
546/*-------------------------------------------------------------------------*/
547
548#ifdef CONFIG_ARCH_OMAP_OTG
549
550void __init
551omap_otg_init(struct omap_usb_config *config)
552{
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300553 u32 syscon;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100554 int status;
555 int alt_pingroup = 0;
556
557 /* NOTE: no bus or clock setup (yet?) */
558
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300559 syscon = omap_readl(OTG_SYSCON_1) & 0xffff;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100560 if (!(syscon & OTG_RESET_DONE))
561 pr_debug("USB resets not complete?\n");
562
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300563 //omap_writew(0, OTG_IRQ_EN);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100564
565 /* pin muxing and transceiver pinouts */
566 if (config->pins[0] > 2) /* alt pingroup 2 */
567 alt_pingroup = 1;
568 syscon |= omap_usb0_init(config->pins[0], is_usb0_device(config));
569 syscon |= omap_usb1_init(config->pins[1]);
570 syscon |= omap_usb2_init(config->pins[2], alt_pingroup);
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300571 pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
572 omap_writel(syscon, OTG_SYSCON_1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100573
574 syscon = config->hmc_mode;
575 syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
576#ifdef CONFIG_USB_OTG
577 if (config->otg)
578 syscon |= OTG_EN;
579#endif
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800580 if (cpu_class_is_omap1())
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300581 pr_debug("USB_TRANSCEIVER_CTRL = %03x\n",
582 omap_readl(USB_TRANSCEIVER_CTRL));
583 pr_debug("OTG_SYSCON_2 = %08x\n", omap_readl(OTG_SYSCON_2));
584 omap_writel(syscon, OTG_SYSCON_2);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100585
586 printk("USB: hmc %d", config->hmc_mode);
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800587 if (!alt_pingroup)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100588 printk(", usb2 alt %d wires", config->pins[2]);
589 else if (config->pins[0])
590 printk(", usb0 %d wires%s", config->pins[0],
591 is_usb0_device(config) ? " (dev)" : "");
592 if (config->pins[1])
593 printk(", usb1 %d wires", config->pins[1]);
594 if (!alt_pingroup && config->pins[2])
595 printk(", usb2 %d wires", config->pins[2]);
596 if (config->otg)
597 printk(", Mini-AB on usb%d", config->otg - 1);
598 printk("\n");
599
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800600 if (cpu_class_is_omap1()) {
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300601 u16 w;
602
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800603 /* leave USB clocks/controllers off until needed */
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300604 w = omap_readw(ULPD_SOFT_REQ);
605 w &= ~SOFT_USB_CLK_REQ;
606 omap_writew(w, ULPD_SOFT_REQ);
607
608 w = omap_readw(ULPD_CLOCK_CTRL);
609 w &= ~USB_MCLK_EN;
610 w |= DIS_USB_PVCI_CLK;
611 omap_writew(w, ULPD_CLOCK_CTRL);
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800612 }
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300613 syscon = omap_readl(OTG_SYSCON_1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100614 syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
615
616#ifdef CONFIG_USB_GADGET_OMAP
617 if (config->otg || config->register_dev) {
618 syscon &= ~DEV_IDLE_EN;
619 udc_device.dev.platform_data = config;
620 /* FIXME patch IRQ numbers for omap730 */
621 status = platform_device_register(&udc_device);
622 if (status)
623 pr_debug("can't register UDC device, %d\n", status);
624 }
625#endif
626
627#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
628 if (config->otg || config->register_host) {
629 syscon &= ~HST_IDLE_EN;
630 ohci_device.dev.platform_data = config;
631 if (cpu_is_omap730())
632 ohci_resources[1].start = INT_730_USB_HHC_1;
633 status = platform_device_register(&ohci_device);
634 if (status)
635 pr_debug("can't register OHCI device, %d\n", status);
636 }
637#endif
638
639#ifdef CONFIG_USB_OTG
640 if (config->otg) {
641 syscon &= ~OTG_IDLE_EN;
642 otg_device.dev.platform_data = config;
643 if (cpu_is_omap730())
644 otg_resources[1].start = INT_730_USB_OTG;
645 status = platform_device_register(&otg_device);
646 if (status)
647 pr_debug("can't register OTG device, %d\n", status);
648 }
649#endif
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300650 pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
651 omap_writel(syscon, OTG_SYSCON_1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100652
653 status = 0;
654}
655
656#else
657static inline void omap_otg_init(struct omap_usb_config *config) {}
658#endif
659
660/*-------------------------------------------------------------------------*/
661
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000662#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100663
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300664/* ULPD_DPLL_CTRL */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100665#define DPLL_IOB (1 << 13)
666#define DPLL_PLL_ENABLE (1 << 4)
667#define DPLL_LOCK (1 << 0)
668
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300669/* ULPD_APLL_CTRL */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100670#define APLL_NDPLL_SWITCH (1 << 0)
671
672
673static void __init omap_1510_usb_init(struct omap_usb_config *config)
674{
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100675 unsigned int val;
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300676 u16 w;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100677
678 omap_usb0_init(config->pins[0], is_usb0_device(config));
679 omap_usb1_init(config->pins[1]);
680 omap_usb2_init(config->pins[2], 0);
681
682 val = omap_readl(MOD_CONF_CTRL_0) & ~(0x3f << 1);
683 val |= (config->hmc_mode << 1);
684 omap_writel(val, MOD_CONF_CTRL_0);
685
686 printk("USB: hmc %d", config->hmc_mode);
687 if (config->pins[0])
688 printk(", usb0 %d wires%s", config->pins[0],
689 is_usb0_device(config) ? " (dev)" : "");
690 if (config->pins[1])
691 printk(", usb1 %d wires", config->pins[1]);
692 if (config->pins[2])
693 printk(", usb2 %d wires", config->pins[2]);
694 printk("\n");
695
696 /* use DPLL for 48 MHz function clock */
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300697 pr_debug("APLL %04x DPLL %04x REQ %04x\n", omap_readw(ULPD_APLL_CTRL),
698 omap_readw(ULPD_DPLL_CTRL), omap_readw(ULPD_SOFT_REQ));
699
700 w = omap_readw(ULPD_APLL_CTRL);
701 w &= ~APLL_NDPLL_SWITCH;
702 omap_writew(w, ULPD_APLL_CTRL);
703
704 w = omap_readw(ULPD_DPLL_CTRL);
705 w |= DPLL_IOB | DPLL_PLL_ENABLE;
706 omap_writew(w, ULPD_DPLL_CTRL);
707
708 w = omap_readw(ULPD_SOFT_REQ);
709 w |= SOFT_UDC_REQ | SOFT_DPLL_REQ;
710 omap_writew(w, ULPD_SOFT_REQ);
711
712 while (!(omap_readw(ULPD_DPLL_CTRL) & DPLL_LOCK))
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100713 cpu_relax();
714
715#ifdef CONFIG_USB_GADGET_OMAP
716 if (config->register_dev) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000717 int status;
718
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100719 udc_device.dev.platform_data = config;
720 status = platform_device_register(&udc_device);
721 if (status)
722 pr_debug("can't register UDC device, %d\n", status);
723 /* udc driver gates 48MHz by D+ pullup */
724 }
725#endif
726
727#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
728 if (config->register_host) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000729 int status;
730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100731 ohci_device.dev.platform_data = config;
732 status = platform_device_register(&ohci_device);
733 if (status)
734 pr_debug("can't register OHCI device, %d\n", status);
735 /* hcd explicitly gates 48MHz */
736 }
737#endif
738}
739
740#else
741static inline void omap_1510_usb_init(struct omap_usb_config *config) {}
742#endif
743
744/*-------------------------------------------------------------------------*/
745
746static struct omap_usb_config platform_data;
747
748static int __init
749omap_usb_init(void)
750{
751 const struct omap_usb_config *config;
752
753 config = omap_get_config(OMAP_TAG_USB, struct omap_usb_config);
754 if (config == NULL) {
755 printk(KERN_ERR "USB: No board-specific "
756 "platform config found\n");
757 return -ENODEV;
758 }
759 platform_data = *config;
760
Tony Lindgrenc40fae92006-12-07 13:58:10 -0800761 if (cpu_is_omap730() || cpu_is_omap16xx() || cpu_is_omap24xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100762 omap_otg_init(&platform_data);
763 else if (cpu_is_omap15xx())
764 omap_1510_usb_init(&platform_data);
765 else {
766 printk(KERN_ERR "USB: No init for your chip yet\n");
767 return -ENODEV;
768 }
769 return 0;
770}
771
772subsys_initcall(omap_usb_init);