blob: d85296dc896c2090136652997a2d401c5e60e576 [file] [log] [blame]
Felipe Balbi18cb7ac2009-03-23 18:34:06 -07001/*
2 * linux/arch/arm/mach-omap2/usb-musb.c
3 *
4 * This file will contain the board specific details for the
5 * MENTOR USB OTG controller on OMAP3430
6 *
7 * Copyright (C) 2007-2008 Texas Instruments
8 * Copyright (C) 2008 Nokia Corporation
9 * Author: Vikram Pandita
10 *
11 * Generalization by:
12 * Felipe Balbi <felipe.balbi@nokia.com>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 */
18
19#include <linux/types.h>
20#include <linux/errno.h>
21#include <linux/delay.h>
22#include <linux/platform_device.h>
23#include <linux/clk.h>
24#include <linux/dma-mapping.h>
25#include <linux/io.h>
26
27#include <linux/usb/musb.h>
28
29#include <mach/hardware.h>
30#include <mach/irqs.h>
Felipe Balbi18cb7ac2009-03-23 18:34:06 -070031#include <mach/mux.h>
32#include <mach/usb.h>
33
Peter 'p2' De Schrijver94a3ef62009-01-19 19:09:22 +020034#define OTG_SYSCONFIG (OMAP34XX_HSUSB_OTG_BASE + 0x404)
35
36static void __init usb_musb_pm_init(void)
37{
38 /* Ensure force-idle mode for OTG controller */
39 if (cpu_is_omap34xx())
40 omap_writel(0, OTG_SYSCONFIG);
41}
42
43#ifdef CONFIG_USB_MUSB_SOC
44
Felipe Balbi18cb7ac2009-03-23 18:34:06 -070045static struct resource musb_resources[] = {
46 [0] = { /* start and end set dynamically */
47 .flags = IORESOURCE_MEM,
48 },
49 [1] = { /* general IRQ */
50 .start = INT_243X_HS_USB_MC,
51 .flags = IORESOURCE_IRQ,
52 },
53 [2] = { /* DMA IRQ */
54 .start = INT_243X_HS_USB_DMA,
55 .flags = IORESOURCE_IRQ,
56 },
57};
58
59static int clk_on;
60
61static int musb_set_clock(struct clk *clk, int state)
62{
63 if (state) {
64 if (clk_on > 0)
65 return -ENODEV;
66
67 clk_enable(clk);
68 clk_on = 1;
69 } else {
70 if (clk_on == 0)
71 return -ENODEV;
72
73 clk_disable(clk);
74 clk_on = 0;
75 }
76
77 return 0;
78}
79
80static struct musb_hdrc_eps_bits musb_eps[] = {
81 { "ep1_tx", 10, },
82 { "ep1_rx", 10, },
83 { "ep2_tx", 9, },
84 { "ep2_rx", 9, },
85 { "ep3_tx", 3, },
86 { "ep3_rx", 3, },
87 { "ep4_tx", 3, },
88 { "ep4_rx", 3, },
89 { "ep5_tx", 3, },
90 { "ep5_rx", 3, },
91 { "ep6_tx", 3, },
92 { "ep6_rx", 3, },
93 { "ep7_tx", 3, },
94 { "ep7_rx", 3, },
95 { "ep8_tx", 2, },
96 { "ep8_rx", 2, },
97 { "ep9_tx", 2, },
98 { "ep9_rx", 2, },
99 { "ep10_tx", 2, },
100 { "ep10_rx", 2, },
101 { "ep11_tx", 2, },
102 { "ep11_rx", 2, },
103 { "ep12_tx", 2, },
104 { "ep12_rx", 2, },
105 { "ep13_tx", 2, },
106 { "ep13_rx", 2, },
107 { "ep14_tx", 2, },
108 { "ep14_rx", 2, },
109 { "ep15_tx", 2, },
110 { "ep15_rx", 2, },
111};
112
113static struct musb_hdrc_config musb_config = {
114 .multipoint = 1,
115 .dyn_fifo = 1,
116 .soft_con = 1,
117 .dma = 1,
118 .num_eps = 16,
119 .dma_channels = 7,
120 .dma_req_chan = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3),
121 .ram_bits = 12,
122 .eps_bits = musb_eps,
123};
124
125static struct musb_hdrc_platform_data musb_plat = {
126#ifdef CONFIG_USB_MUSB_OTG
127 .mode = MUSB_OTG,
128#elif defined(CONFIG_USB_MUSB_HDRC_HCD)
129 .mode = MUSB_HOST,
130#elif defined(CONFIG_USB_GADGET_MUSB_HDRC)
131 .mode = MUSB_PERIPHERAL,
132#endif
133 /* .clock is set dynamically */
134 .set_clock = musb_set_clock,
135 .config = &musb_config,
136
137 /* REVISIT charge pump on TWL4030 can supply up to
138 * 100 mA ... but this value is board-specific, like
139 * "mode", and should be passed to usb_musb_init().
140 */
141 .power = 50, /* up to 100 mA */
142};
143
Yang Hongyange9304382009-04-13 14:40:14 -0700144static u64 musb_dmamask = DMA_BIT_MASK(32);
Felipe Balbi18cb7ac2009-03-23 18:34:06 -0700145
146static struct platform_device musb_device = {
147 .name = "musb_hdrc",
148 .id = -1,
149 .dev = {
150 .dma_mask = &musb_dmamask,
Yang Hongyange9304382009-04-13 14:40:14 -0700151 .coherent_dma_mask = DMA_BIT_MASK(32),
Felipe Balbi18cb7ac2009-03-23 18:34:06 -0700152 .platform_data = &musb_plat,
153 },
154 .num_resources = ARRAY_SIZE(musb_resources),
155 .resource = musb_resources,
156};
157
158#ifdef CONFIG_NOP_USB_XCEIV
Yang Hongyange9304382009-04-13 14:40:14 -0700159static u64 nop_xceiv_dmamask = DMA_BIT_MASK(32);
Felipe Balbi18cb7ac2009-03-23 18:34:06 -0700160
161static struct platform_device nop_xceiv_device = {
162 .name = "nop_usb_xceiv",
163 .id = -1,
164 .dev = {
165 .dma_mask = &nop_xceiv_dmamask,
Yang Hongyange9304382009-04-13 14:40:14 -0700166 .coherent_dma_mask = DMA_BIT_MASK(32),
Felipe Balbi18cb7ac2009-03-23 18:34:06 -0700167 .platform_data = NULL,
168 },
169};
170#endif
171
172void __init usb_musb_init(void)
173{
174 if (cpu_is_omap243x())
175 musb_resources[0].start = OMAP243X_HS_BASE;
176 else
177 musb_resources[0].start = OMAP34XX_HSUSB_OTG_BASE;
178 musb_resources[0].end = musb_resources[0].start + SZ_8K - 1;
179
180 /*
181 * REVISIT: This line can be removed once all the platforms using
182 * musb_core.c have been converted to use use clkdev.
183 */
184 musb_plat.clock = "ick";
185
186#ifdef CONFIG_NOP_USB_XCEIV
187 if (platform_device_register(&nop_xceiv_device) < 0) {
188 printk(KERN_ERR "Unable to register NOP-XCEIV device\n");
189 return;
190 }
191#endif
192
193 if (platform_device_register(&musb_device) < 0) {
194 printk(KERN_ERR "Unable to register HS-USB (MUSB) device\n");
195 return;
196 }
Peter 'p2' De Schrijver94a3ef62009-01-19 19:09:22 +0200197
198 usb_musb_pm_init();
Felipe Balbi18cb7ac2009-03-23 18:34:06 -0700199}
Peter 'p2' De Schrijver94a3ef62009-01-19 19:09:22 +0200200
201#else
202void __init usb_musb_init(void)
203{
204 usb_musb_pm_init();
205}
206#endif /* CONFIG_USB_MUSB_SOC */