aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-omap2/usb-fs.c
diff options
context:
space:
mode:
authorTony Lindgren <tony@atomide.com>2010-07-05 09:31:29 -0400
committerTony Lindgren <tony@atomide.com>2010-07-05 09:31:29 -0400
commitb5e8905bcd7a794b667f6d5eabcb036f25358fdb (patch)
treef4e488d39bb59d57ca8cff6a45df29624fcd6049 /arch/arm/mach-omap2/usb-fs.c
parentdba638d22d5af5486a861e08ab46e57abef7049a (diff)
omap: Move omap2 FS USB platform init code into mach-omap2/usb-fs.c
Move omap2 FS USB platform init code into mach-omap2/usb-fs.c. This will allow further work later on to use omap hwmod for initializing the device. Cc: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Tony Lindgren <tony@atomide.com>
Diffstat (limited to 'arch/arm/mach-omap2/usb-fs.c')
-rw-r--r--arch/arm/mach-omap2/usb-fs.c345
1 files changed, 345 insertions, 0 deletions
diff --git a/arch/arm/mach-omap2/usb-fs.c b/arch/arm/mach-omap2/usb-fs.c
new file mode 100644
index 000000000000..f63e5766b6bc
--- /dev/null
+++ b/arch/arm/mach-omap2/usb-fs.c
@@ -0,0 +1,345 @@
1/*
2 * Platform level USB initialization for FS USB OTG controller on omap1 and 24xx
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#include <linux/module.h>
22#include <linux/kernel.h>
23#include <linux/types.h>
24#include <linux/errno.h>
25#include <linux/init.h>
26#include <linux/platform_device.h>
27
28#include <asm/irq.h>
29
30#include <plat/control.h>
31#include <plat/mux.h>
32#include <plat/usb.h>
33#include <plat/board.h>
34
35#define INT_USB_IRQ_GEN INT_24XX_USB_IRQ_GEN
36#define INT_USB_IRQ_NISO INT_24XX_USB_IRQ_NISO
37#define INT_USB_IRQ_ISO INT_24XX_USB_IRQ_ISO
38#define INT_USB_IRQ_HGEN INT_24XX_USB_IRQ_HGEN
39#define INT_USB_IRQ_OTG INT_24XX_USB_IRQ_OTG
40
41#if defined(CONFIG_ARCH_OMAP2)
42
43#ifdef CONFIG_USB_GADGET_OMAP
44
45static struct resource udc_resources[] = {
46 /* order is significant! */
47 { /* registers */
48 .start = UDC_BASE,
49 .end = UDC_BASE + 0xff,
50 .flags = IORESOURCE_MEM,
51 }, { /* general IRQ */
52 .start = INT_USB_IRQ_GEN,
53 .flags = IORESOURCE_IRQ,
54 }, { /* PIO IRQ */
55 .start = INT_USB_IRQ_NISO,
56 .flags = IORESOURCE_IRQ,
57 }, { /* SOF IRQ */
58 .start = INT_USB_IRQ_ISO,
59 .flags = IORESOURCE_IRQ,
60 },
61};
62
63static u64 udc_dmamask = ~(u32)0;
64
65static struct platform_device udc_device = {
66 .name = "omap_udc",
67 .id = -1,
68 .dev = {
69 .dma_mask = &udc_dmamask,
70 .coherent_dma_mask = 0xffffffff,
71 },
72 .num_resources = ARRAY_SIZE(udc_resources),
73 .resource = udc_resources,
74};
75
76static inline void udc_device_init(struct omap_usb_config *pdata)
77{
78 pdata->udc_device = &udc_device;
79}
80
81#else
82
83static inline void udc_device_init(struct omap_usb_config *pdata)
84{
85}
86
87#endif
88
89#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
90
91/* The dmamask must be set for OHCI to work */
92static u64 ohci_dmamask = ~(u32)0;
93
94static struct resource ohci_resources[] = {
95 {
96 .start = OMAP_OHCI_BASE,
97 .end = OMAP_OHCI_BASE + 0xff,
98 .flags = IORESOURCE_MEM,
99 },
100 {
101 .start = INT_USB_IRQ_HGEN,
102 .flags = IORESOURCE_IRQ,
103 },
104};
105
106static struct platform_device ohci_device = {
107 .name = "ohci",
108 .id = -1,
109 .dev = {
110 .dma_mask = &ohci_dmamask,
111 .coherent_dma_mask = 0xffffffff,
112 },
113 .num_resources = ARRAY_SIZE(ohci_resources),
114 .resource = ohci_resources,
115};
116
117static inline void ohci_device_init(struct omap_usb_config *pdata)
118{
119 pdata->ohci_device = &ohci_device;
120}
121
122#else
123
124static inline void ohci_device_init(struct omap_usb_config *pdata)
125{
126}
127
128#endif
129
130#if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
131
132static struct resource otg_resources[] = {
133 /* order is significant! */
134 {
135 .start = OTG_BASE,
136 .end = OTG_BASE + 0xff,
137 .flags = IORESOURCE_MEM,
138 }, {
139 .start = INT_USB_IRQ_OTG,
140 .flags = IORESOURCE_IRQ,
141 },
142};
143
144static struct platform_device otg_device = {
145 .name = "omap_otg",
146 .id = -1,
147 .num_resources = ARRAY_SIZE(otg_resources),
148 .resource = otg_resources,
149};
150
151static inline void otg_device_init(struct omap_usb_config *pdata)
152{
153 pdata->otg_device = &otg_device;
154}
155
156#else
157
158static inline void otg_device_init(struct omap_usb_config *pdata)
159{
160}
161
162#endif
163
164static void omap2_usb_devconf_clear(u8 port, u32 mask)
165{
166 u32 r;
167
168 r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
169 r &= ~USBTXWRMODEI(port, mask);
170 omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
171}
172
173static void omap2_usb_devconf_set(u8 port, u32 mask)
174{
175 u32 r;
176
177 r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
178 r |= USBTXWRMODEI(port, mask);
179 omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
180}
181
182static void omap2_usb2_disable_5pinbitll(void)
183{
184 u32 r;
185
186 r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
187 r &= ~(USBTXWRMODEI(2, USB_BIDIR_TLL) | USBT2TLL5PI);
188 omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
189}
190
191static void omap2_usb2_enable_5pinunitll(void)
192{
193 u32 r;
194
195 r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
196 r |= USBTXWRMODEI(2, USB_UNIDIR_TLL) | USBT2TLL5PI;
197 omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
198}
199
200static u32 __init omap2_usb0_init(unsigned nwires, unsigned is_device)
201{
202 u32 syscon1 = 0;
203
204 omap2_usb_devconf_clear(0, USB_BIDIR_TLL);
205
206 if (nwires == 0)
207 return 0;
208
209 if (is_device)
210 omap_cfg_reg(J20_24XX_USB0_PUEN);
211
212 omap_cfg_reg(K18_24XX_USB0_DAT);
213 omap_cfg_reg(K19_24XX_USB0_TXEN);
214 omap_cfg_reg(J14_24XX_USB0_SE0);
215 if (nwires != 3)
216 omap_cfg_reg(J18_24XX_USB0_RCV);
217
218 switch (nwires) {
219 case 3:
220 syscon1 = 2;
221 omap2_usb_devconf_set(0, USB_BIDIR);
222 break;
223 case 4:
224 syscon1 = 1;
225 omap2_usb_devconf_set(0, USB_BIDIR);
226 break;
227 case 6:
228 syscon1 = 3;
229 omap_cfg_reg(J19_24XX_USB0_VP);
230 omap_cfg_reg(K20_24XX_USB0_VM);
231 omap2_usb_devconf_set(0, USB_UNIDIR);
232 break;
233 default:
234 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
235 0, nwires);
236 }
237
238 return syscon1 << 16;
239}
240
241static u32 __init omap2_usb1_init(unsigned nwires)
242{
243 u32 syscon1 = 0;
244
245 omap2_usb_devconf_clear(1, USB_BIDIR_TLL);
246
247 if (nwires == 0)
248 return 0;
249
250 /* NOTE: board-specific code must set up pin muxing for usb1,
251 * since each signal could come out on either of two balls.
252 */
253
254 switch (nwires) {
255 case 2:
256 /* NOTE: board-specific code must override this setting if
257 * this TLL link is not using DP/DM
258 */
259 syscon1 = 1;
260 omap2_usb_devconf_set(1, USB_BIDIR_TLL);
261 break;
262 case 3:
263 syscon1 = 2;
264 omap2_usb_devconf_set(1, USB_BIDIR);
265 break;
266 case 4:
267 syscon1 = 1;
268 omap2_usb_devconf_set(1, USB_BIDIR);
269 break;
270 case 6:
271 default:
272 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
273 1, nwires);
274 }
275
276 return syscon1 << 20;
277}
278
279static u32 __init omap2_usb2_init(unsigned nwires, unsigned alt_pingroup)
280{
281 u32 syscon1 = 0;
282
283 omap2_usb2_disable_5pinbitll();
284 alt_pingroup = 0;
285
286 /* NOTE omap1 erratum: must leave USB2_UNI_R set if usb0 in use */
287 if (alt_pingroup || nwires == 0)
288 return 0;
289
290 omap_cfg_reg(Y11_24XX_USB2_DAT);
291 omap_cfg_reg(AA10_24XX_USB2_SE0);
292 if (nwires > 2)
293 omap_cfg_reg(AA12_24XX_USB2_TXEN);
294 if (nwires > 3)
295 omap_cfg_reg(AA6_24XX_USB2_RCV);
296
297 switch (nwires) {
298 case 2:
299 /* NOTE: board-specific code must override this setting if
300 * this TLL link is not using DP/DM
301 */
302 syscon1 = 1;
303 omap2_usb_devconf_set(2, USB_BIDIR_TLL);
304 break;
305 case 3:
306 syscon1 = 2;
307 omap2_usb_devconf_set(2, USB_BIDIR);
308 break;
309 case 4:
310 syscon1 = 1;
311 omap2_usb_devconf_set(2, USB_BIDIR);
312 break;
313 case 5:
314 omap_cfg_reg(AA4_24XX_USB2_TLLSE0);
315 /* NOTE: board-specific code must override this setting if
316 * this TLL link is not using DP/DM. Something must also
317 * set up OTG_SYSCON2.HMC_TLL{ATTACH,SPEED}
318 */
319 syscon1 = 3;
320 omap2_usb2_enable_5pinunitll();
321 break;
322 case 6:
323 default:
324 printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
325 2, nwires);
326 }
327
328 return syscon1 << 24;
329}
330
331void __init omap2_usbfs_init(struct omap_usb_config *pdata)
332{
333 if (!cpu_is_omap24xx())
334 return;
335
336 pdata->usb0_init = omap2_usb0_init;
337 pdata->usb1_init = omap2_usb1_init;
338 pdata->usb2_init = omap2_usb2_init;
339 udc_device_init(pdata);
340 ohci_device_init(pdata);
341 otg_device_init(pdata);
342 omap_otg_init(pdata);
343}
344
345#endif