Commit | Line | Data |
---|---|---|
16fa3dc7 KM |
1 | /** |
2 | * omap-usb-tll.c - The USB TLL driver for OMAP EHCI & OHCI | |
3 | * | |
9f4a3ece | 4 | * Copyright (C) 2012-2013 Texas Instruments Incorporated - http://www.ti.com |
16fa3dc7 | 5 | * Author: Keshava Munegowda <keshava_mgowda@ti.com> |
9f4a3ece | 6 | * Author: Roger Quadros <rogerq@ti.com> |
16fa3dc7 KM |
7 | * |
8 | * This program is free software: you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License version 2 of | |
10 | * the License as published by the Free Software Foundation. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | */ | |
20 | #include <linux/kernel.h> | |
21 | #include <linux/module.h> | |
22 | #include <linux/types.h> | |
23 | #include <linux/slab.h> | |
24 | #include <linux/spinlock.h> | |
25 | #include <linux/platform_device.h> | |
26 | #include <linux/clk.h> | |
27 | #include <linux/io.h> | |
28 | #include <linux/err.h> | |
16fa3dc7 | 29 | #include <linux/pm_runtime.h> |
e8c4a7ac | 30 | #include <linux/platform_data/usb-omap.h> |
48130b8f | 31 | #include <linux/of.h> |
16fa3dc7 KM |
32 | |
33 | #define USBTLL_DRIVER_NAME "usbhs_tll" | |
34 | ||
35 | /* TLL Register Set */ | |
36 | #define OMAP_USBTLL_REVISION (0x00) | |
37 | #define OMAP_USBTLL_SYSCONFIG (0x10) | |
38 | #define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8) | |
39 | #define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3) | |
40 | #define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2) | |
41 | #define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1) | |
42 | #define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0) | |
43 | ||
44 | #define OMAP_USBTLL_SYSSTATUS (0x14) | |
45 | #define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0) | |
46 | ||
47 | #define OMAP_USBTLL_IRQSTATUS (0x18) | |
48 | #define OMAP_USBTLL_IRQENABLE (0x1C) | |
49 | ||
50 | #define OMAP_TLL_SHARED_CONF (0x30) | |
51 | #define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6) | |
52 | #define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5) | |
53 | #define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2) | |
54 | #define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1) | |
55 | #define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0) | |
56 | ||
57 | #define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num) | |
58 | #define OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT 24 | |
300c2f8f RQ |
59 | #define OMAP_TLL_CHANNEL_CONF_DRVVBUS (1 << 16) |
60 | #define OMAP_TLL_CHANNEL_CONF_CHRGVBUS (1 << 15) | |
16fa3dc7 KM |
61 | #define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11) |
62 | #define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10) | |
63 | #define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9) | |
64 | #define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8) | |
300c2f8f | 65 | #define OMAP_TLL_CHANNEL_CONF_MODE_TRANSPARENT_UTMI (2 << 1) |
16fa3dc7 KM |
66 | #define OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS (1 << 1) |
67 | #define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0) | |
68 | ||
69 | #define OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0 0x0 | |
70 | #define OMAP_TLL_FSLSMODE_6PIN_PHY_DP_DM 0x1 | |
71 | #define OMAP_TLL_FSLSMODE_3PIN_PHY 0x2 | |
72 | #define OMAP_TLL_FSLSMODE_4PIN_PHY 0x3 | |
73 | #define OMAP_TLL_FSLSMODE_6PIN_TLL_DAT_SE0 0x4 | |
74 | #define OMAP_TLL_FSLSMODE_6PIN_TLL_DP_DM 0x5 | |
75 | #define OMAP_TLL_FSLSMODE_3PIN_TLL 0x6 | |
76 | #define OMAP_TLL_FSLSMODE_4PIN_TLL 0x7 | |
77 | #define OMAP_TLL_FSLSMODE_2PIN_TLL_DAT_SE0 0xA | |
78 | #define OMAP_TLL_FSLSMODE_2PIN_DAT_DP_DM 0xB | |
79 | ||
80 | #define OMAP_TLL_ULPI_FUNCTION_CTRL(num) (0x804 + 0x100 * num) | |
81 | #define OMAP_TLL_ULPI_INTERFACE_CTRL(num) (0x807 + 0x100 * num) | |
82 | #define OMAP_TLL_ULPI_OTG_CTRL(num) (0x80A + 0x100 * num) | |
83 | #define OMAP_TLL_ULPI_INT_EN_RISE(num) (0x80D + 0x100 * num) | |
84 | #define OMAP_TLL_ULPI_INT_EN_FALL(num) (0x810 + 0x100 * num) | |
85 | #define OMAP_TLL_ULPI_INT_STATUS(num) (0x813 + 0x100 * num) | |
86 | #define OMAP_TLL_ULPI_INT_LATCH(num) (0x814 + 0x100 * num) | |
87 | #define OMAP_TLL_ULPI_DEBUG(num) (0x815 + 0x100 * num) | |
88 | #define OMAP_TLL_ULPI_SCRATCH_REGISTER(num) (0x816 + 0x100 * num) | |
89 | ||
90 | #define OMAP_REV2_TLL_CHANNEL_COUNT 2 | |
91 | #define OMAP_TLL_CHANNEL_COUNT 3 | |
92 | #define OMAP_TLL_CHANNEL_1_EN_MASK (1 << 0) | |
93 | #define OMAP_TLL_CHANNEL_2_EN_MASK (1 << 1) | |
94 | #define OMAP_TLL_CHANNEL_3_EN_MASK (1 << 2) | |
95 | ||
96 | /* Values of USBTLL_REVISION - Note: these are not given in the TRM */ | |
97 | #define OMAP_USBTLL_REV1 0x00000015 /* OMAP3 */ | |
98 | #define OMAP_USBTLL_REV2 0x00000018 /* OMAP 3630 */ | |
99 | #define OMAP_USBTLL_REV3 0x00000004 /* OMAP4 */ | |
300c2f8f | 100 | #define OMAP_USBTLL_REV4 0x00000006 /* OMAP5 */ |
16fa3dc7 KM |
101 | |
102 | #define is_ehci_tll_mode(x) (x == OMAP_EHCI_PORT_MODE_TLL) | |
103 | ||
32a51f2a RQ |
104 | /* only PHY and UNUSED modes don't need TLL */ |
105 | #define omap_usb_mode_needs_tll(x) ((x) != OMAP_USBHS_PORT_MODE_UNUSED &&\ | |
106 | (x) != OMAP_EHCI_PORT_MODE_PHY) | |
107 | ||
16fa3dc7 | 108 | struct usbtll_omap { |
7e0ff103 | 109 | int nch; /* num. of channels */ |
0bde3e9f | 110 | struct clk **ch_clk; |
9f4a3ece | 111 | void __iomem *base; |
16fa3dc7 KM |
112 | }; |
113 | ||
114 | /*-------------------------------------------------------------------------*/ | |
115 | ||
7ed86191 RQ |
116 | static const char usbtll_driver_name[] = USBTLL_DRIVER_NAME; |
117 | static struct device *tll_dev; | |
66751446 | 118 | static DEFINE_SPINLOCK(tll_lock); /* serialize access to tll_dev */ |
16fa3dc7 KM |
119 | |
120 | /*-------------------------------------------------------------------------*/ | |
121 | ||
122 | static inline void usbtll_write(void __iomem *base, u32 reg, u32 val) | |
123 | { | |
124 | __raw_writel(val, base + reg); | |
125 | } | |
126 | ||
127 | static inline u32 usbtll_read(void __iomem *base, u32 reg) | |
128 | { | |
129 | return __raw_readl(base + reg); | |
130 | } | |
131 | ||
132 | static inline void usbtll_writeb(void __iomem *base, u8 reg, u8 val) | |
133 | { | |
134 | __raw_writeb(val, base + reg); | |
135 | } | |
136 | ||
137 | static inline u8 usbtll_readb(void __iomem *base, u8 reg) | |
138 | { | |
139 | return __raw_readb(base + reg); | |
140 | } | |
141 | ||
142 | /*-------------------------------------------------------------------------*/ | |
143 | ||
144 | static bool is_ohci_port(enum usbhs_omap_port_mode pmode) | |
145 | { | |
146 | switch (pmode) { | |
147 | case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0: | |
148 | case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM: | |
149 | case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0: | |
150 | case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM: | |
151 | case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0: | |
152 | case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM: | |
153 | case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0: | |
154 | case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM: | |
155 | case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0: | |
156 | case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM: | |
157 | return true; | |
158 | ||
159 | default: | |
160 | return false; | |
161 | } | |
162 | } | |
163 | ||
164 | /* | |
165 | * convert the port-mode enum to a value we can use in the FSLSMODE | |
166 | * field of USBTLL_CHANNEL_CONF | |
167 | */ | |
168 | static unsigned ohci_omap3_fslsmode(enum usbhs_omap_port_mode mode) | |
169 | { | |
170 | switch (mode) { | |
171 | case OMAP_USBHS_PORT_MODE_UNUSED: | |
172 | case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0: | |
173 | return OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0; | |
174 | ||
175 | case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM: | |
176 | return OMAP_TLL_FSLSMODE_6PIN_PHY_DP_DM; | |
177 | ||
178 | case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0: | |
179 | return OMAP_TLL_FSLSMODE_3PIN_PHY; | |
180 | ||
181 | case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM: | |
182 | return OMAP_TLL_FSLSMODE_4PIN_PHY; | |
183 | ||
184 | case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0: | |
185 | return OMAP_TLL_FSLSMODE_6PIN_TLL_DAT_SE0; | |
186 | ||
187 | case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM: | |
188 | return OMAP_TLL_FSLSMODE_6PIN_TLL_DP_DM; | |
189 | ||
190 | case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0: | |
191 | return OMAP_TLL_FSLSMODE_3PIN_TLL; | |
192 | ||
193 | case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM: | |
194 | return OMAP_TLL_FSLSMODE_4PIN_TLL; | |
195 | ||
196 | case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0: | |
197 | return OMAP_TLL_FSLSMODE_2PIN_TLL_DAT_SE0; | |
198 | ||
199 | case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM: | |
200 | return OMAP_TLL_FSLSMODE_2PIN_DAT_DP_DM; | |
201 | default: | |
202 | pr_warn("Invalid port mode, using default\n"); | |
203 | return OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0; | |
204 | } | |
205 | } | |
206 | ||
207 | /** | |
208 | * usbtll_omap_probe - initialize TI-based HCDs | |
209 | * | |
210 | * Allocates basic resources for this USB host controller. | |
211 | */ | |
f791be49 | 212 | static int usbtll_omap_probe(struct platform_device *pdev) |
16fa3dc7 KM |
213 | { |
214 | struct device *dev = &pdev->dev; | |
16fa3dc7 KM |
215 | struct resource *res; |
216 | struct usbtll_omap *tll; | |
16fa3dc7 | 217 | int ret = 0; |
7e0ff103 | 218 | int i, ver; |
16fa3dc7 KM |
219 | |
220 | dev_dbg(dev, "starting TI HSUSB TLL Controller\n"); | |
221 | ||
1a7a8d70 | 222 | tll = devm_kzalloc(dev, sizeof(struct usbtll_omap), GFP_KERNEL); |
16fa3dc7 KM |
223 | if (!tll) { |
224 | dev_err(dev, "Memory allocation failed\n"); | |
1a7a8d70 | 225 | return -ENOMEM; |
16fa3dc7 KM |
226 | } |
227 | ||
16fa3dc7 | 228 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
9f4a3ece RQ |
229 | tll->base = devm_request_and_ioremap(dev, res); |
230 | if (!tll->base) { | |
1a7a8d70 RQ |
231 | ret = -EADDRNOTAVAIL; |
232 | dev_err(dev, "Resource request/ioremap failed:%d\n", ret); | |
0bde3e9f | 233 | return ret; |
16fa3dc7 KM |
234 | } |
235 | ||
236 | platform_set_drvdata(pdev, tll); | |
237 | pm_runtime_enable(dev); | |
238 | pm_runtime_get_sync(dev); | |
239 | ||
9f4a3ece | 240 | ver = usbtll_read(tll->base, OMAP_USBTLL_REVISION); |
16fa3dc7 KM |
241 | switch (ver) { |
242 | case OMAP_USBTLL_REV1: | |
300c2f8f | 243 | case OMAP_USBTLL_REV4: |
7e0ff103 | 244 | tll->nch = OMAP_TLL_CHANNEL_COUNT; |
16fa3dc7 | 245 | break; |
7e0ff103 | 246 | case OMAP_USBTLL_REV2: |
16fa3dc7 | 247 | case OMAP_USBTLL_REV3: |
7e0ff103 | 248 | tll->nch = OMAP_REV2_TLL_CHANNEL_COUNT; |
16fa3dc7 KM |
249 | break; |
250 | default: | |
7e0ff103 RQ |
251 | tll->nch = OMAP_TLL_CHANNEL_COUNT; |
252 | dev_dbg(dev, | |
253 | "USB TLL Rev : 0x%x not recognized, assuming %d channels\n", | |
254 | ver, tll->nch); | |
255 | break; | |
16fa3dc7 KM |
256 | } |
257 | ||
0bde3e9f RQ |
258 | tll->ch_clk = devm_kzalloc(dev, sizeof(struct clk * [tll->nch]), |
259 | GFP_KERNEL); | |
260 | if (!tll->ch_clk) { | |
261 | ret = -ENOMEM; | |
262 | dev_err(dev, "Couldn't allocate memory for channel clocks\n"); | |
263 | goto err_clk_alloc; | |
264 | } | |
265 | ||
266 | for (i = 0; i < tll->nch; i++) { | |
267 | char clkname[] = "usb_tll_hs_usb_chx_clk"; | |
268 | ||
269 | snprintf(clkname, sizeof(clkname), | |
270 | "usb_tll_hs_usb_ch%d_clk", i); | |
271 | tll->ch_clk[i] = clk_get(dev, clkname); | |
272 | ||
273 | if (IS_ERR(tll->ch_clk[i])) | |
274 | dev_dbg(dev, "can't get clock : %s\n", clkname); | |
275 | } | |
276 | ||
9f4a3ece RQ |
277 | pm_runtime_put_sync(dev); |
278 | /* only after this can omap_tll_enable/disable work */ | |
279 | spin_lock(&tll_lock); | |
280 | tll_dev = dev; | |
281 | spin_unlock(&tll_lock); | |
282 | ||
283 | return 0; | |
284 | ||
285 | err_clk_alloc: | |
286 | pm_runtime_put_sync(dev); | |
287 | pm_runtime_disable(dev); | |
288 | ||
289 | return ret; | |
290 | } | |
291 | ||
292 | /** | |
293 | * usbtll_omap_remove - shutdown processing for UHH & TLL HCDs | |
294 | * @pdev: USB Host Controller being removed | |
295 | * | |
296 | * Reverses the effect of usbtll_omap_probe(). | |
297 | */ | |
298 | static int usbtll_omap_remove(struct platform_device *pdev) | |
299 | { | |
300 | struct usbtll_omap *tll = platform_get_drvdata(pdev); | |
301 | int i; | |
302 | ||
303 | spin_lock(&tll_lock); | |
304 | tll_dev = NULL; | |
305 | spin_unlock(&tll_lock); | |
306 | ||
307 | for (i = 0; i < tll->nch; i++) | |
308 | if (!IS_ERR(tll->ch_clk[i])) | |
309 | clk_put(tll->ch_clk[i]); | |
310 | ||
311 | pm_runtime_disable(&pdev->dev); | |
312 | return 0; | |
313 | } | |
314 | ||
48130b8f RQ |
315 | static const struct of_device_id usbtll_omap_dt_ids[] = { |
316 | { .compatible = "ti,usbhs-tll" }, | |
317 | { } | |
318 | }; | |
319 | ||
320 | MODULE_DEVICE_TABLE(of, usbtll_omap_dt_ids); | |
321 | ||
9f4a3ece RQ |
322 | static struct platform_driver usbtll_omap_driver = { |
323 | .driver = { | |
324 | .name = (char *)usbtll_driver_name, | |
325 | .owner = THIS_MODULE, | |
48130b8f | 326 | .of_match_table = of_match_ptr(usbtll_omap_dt_ids), |
9f4a3ece RQ |
327 | }, |
328 | .probe = usbtll_omap_probe, | |
329 | .remove = usbtll_omap_remove, | |
330 | }; | |
331 | ||
332 | int omap_tll_init(struct usbhs_omap_platform_data *pdata) | |
333 | { | |
334 | int i; | |
335 | bool needs_tll; | |
336 | unsigned reg; | |
337 | struct usbtll_omap *tll; | |
338 | ||
339 | spin_lock(&tll_lock); | |
340 | ||
341 | if (!tll_dev) { | |
342 | spin_unlock(&tll_lock); | |
343 | return -ENODEV; | |
344 | } | |
345 | ||
346 | tll = dev_get_drvdata(tll_dev); | |
347 | ||
32a51f2a RQ |
348 | needs_tll = false; |
349 | for (i = 0; i < tll->nch; i++) | |
350 | needs_tll |= omap_usb_mode_needs_tll(pdata->port_mode[i]); | |
351 | ||
9f4a3ece RQ |
352 | pm_runtime_get_sync(tll_dev); |
353 | ||
32a51f2a | 354 | if (needs_tll) { |
9f4a3ece | 355 | void __iomem *base = tll->base; |
16fa3dc7 KM |
356 | |
357 | /* Program Common TLL register */ | |
358 | reg = usbtll_read(base, OMAP_TLL_SHARED_CONF); | |
359 | reg |= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON | |
360 | | OMAP_TLL_SHARED_CONF_USB_DIVRATION); | |
361 | reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN; | |
362 | reg &= ~OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN; | |
363 | ||
364 | usbtll_write(base, OMAP_TLL_SHARED_CONF, reg); | |
365 | ||
366 | /* Enable channels now */ | |
7e0ff103 | 367 | for (i = 0; i < tll->nch; i++) { |
16fa3dc7 KM |
368 | reg = usbtll_read(base, OMAP_TLL_CHANNEL_CONF(i)); |
369 | ||
370 | if (is_ohci_port(pdata->port_mode[i])) { | |
371 | reg |= ohci_omap3_fslsmode(pdata->port_mode[i]) | |
372 | << OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT; | |
373 | reg |= OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS; | |
374 | } else if (pdata->port_mode[i] == | |
375 | OMAP_EHCI_PORT_MODE_TLL) { | |
376 | /* | |
377 | * Disable AutoIdle, BitStuffing | |
378 | * and use SDR Mode | |
379 | */ | |
380 | reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE | |
381 | | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF | |
382 | | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE); | |
300c2f8f RQ |
383 | } else if (pdata->port_mode[i] == |
384 | OMAP_EHCI_PORT_MODE_HSIC) { | |
385 | /* | |
386 | * HSIC Mode requires UTMI port configurations | |
387 | */ | |
388 | reg |= OMAP_TLL_CHANNEL_CONF_DRVVBUS | |
389 | | OMAP_TLL_CHANNEL_CONF_CHRGVBUS | |
390 | | OMAP_TLL_CHANNEL_CONF_MODE_TRANSPARENT_UTMI | |
391 | | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF; | |
16fa3dc7 KM |
392 | } else { |
393 | continue; | |
394 | } | |
395 | reg |= OMAP_TLL_CHANNEL_CONF_CHANEN; | |
396 | usbtll_write(base, OMAP_TLL_CHANNEL_CONF(i), reg); | |
397 | ||
398 | usbtll_writeb(base, | |
399 | OMAP_TLL_ULPI_SCRATCH_REGISTER(i), | |
400 | 0xbe); | |
401 | } | |
402 | } | |
403 | ||
9f4a3ece RQ |
404 | pm_runtime_put_sync(tll_dev); |
405 | ||
66751446 | 406 | spin_unlock(&tll_lock); |
16fa3dc7 | 407 | |
1a7a8d70 | 408 | return 0; |
16fa3dc7 | 409 | } |
9f4a3ece | 410 | EXPORT_SYMBOL_GPL(omap_tll_init); |
16fa3dc7 | 411 | |
9f4a3ece | 412 | int omap_tll_enable(struct usbhs_omap_platform_data *pdata) |
16fa3dc7 | 413 | { |
0bde3e9f | 414 | int i; |
9f4a3ece | 415 | struct usbtll_omap *tll; |
0bde3e9f | 416 | |
66751446 | 417 | spin_lock(&tll_lock); |
16fa3dc7 | 418 | |
9f4a3ece RQ |
419 | if (!tll_dev) { |
420 | spin_unlock(&tll_lock); | |
421 | return -ENODEV; | |
422 | } | |
16fa3dc7 | 423 | |
9f4a3ece | 424 | tll = dev_get_drvdata(tll_dev); |
16fa3dc7 | 425 | |
9f4a3ece | 426 | pm_runtime_get_sync(tll_dev); |
16fa3dc7 | 427 | |
0bde3e9f | 428 | for (i = 0; i < tll->nch; i++) { |
32a51f2a | 429 | if (omap_usb_mode_needs_tll(pdata->port_mode[i])) { |
0bde3e9f | 430 | int r; |
16fa3dc7 | 431 | |
0bde3e9f RQ |
432 | if (IS_ERR(tll->ch_clk[i])) |
433 | continue; | |
434 | ||
435 | r = clk_enable(tll->ch_clk[i]); | |
436 | if (r) { | |
9f4a3ece | 437 | dev_err(tll_dev, |
0bde3e9f RQ |
438 | "Error enabling ch %d clock: %d\n", i, r); |
439 | } | |
440 | } | |
441 | } | |
16fa3dc7 | 442 | |
9f4a3ece RQ |
443 | spin_unlock(&tll_lock); |
444 | ||
16fa3dc7 KM |
445 | return 0; |
446 | } | |
9f4a3ece | 447 | EXPORT_SYMBOL_GPL(omap_tll_enable); |
16fa3dc7 | 448 | |
9f4a3ece | 449 | int omap_tll_disable(struct usbhs_omap_platform_data *pdata) |
16fa3dc7 | 450 | { |
0bde3e9f | 451 | int i; |
9f4a3ece RQ |
452 | struct usbtll_omap *tll; |
453 | ||
454 | spin_lock(&tll_lock); | |
455 | ||
456 | if (!tll_dev) { | |
457 | spin_unlock(&tll_lock); | |
458 | return -ENODEV; | |
459 | } | |
16fa3dc7 | 460 | |
9f4a3ece | 461 | tll = dev_get_drvdata(tll_dev); |
16fa3dc7 | 462 | |
0bde3e9f | 463 | for (i = 0; i < tll->nch; i++) { |
32a51f2a | 464 | if (omap_usb_mode_needs_tll(pdata->port_mode[i])) { |
0bde3e9f RQ |
465 | if (!IS_ERR(tll->ch_clk[i])) |
466 | clk_disable(tll->ch_clk[i]); | |
467 | } | |
468 | } | |
16fa3dc7 | 469 | |
9f4a3ece | 470 | pm_runtime_put_sync(tll_dev); |
66751446 RQ |
471 | |
472 | spin_unlock(&tll_lock); | |
473 | ||
9f4a3ece | 474 | return 0; |
16fa3dc7 KM |
475 | } |
476 | EXPORT_SYMBOL_GPL(omap_tll_disable); | |
477 | ||
478 | MODULE_AUTHOR("Keshava Munegowda <keshava_mgowda@ti.com>"); | |
48130b8f | 479 | MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>"); |
16fa3dc7 KM |
480 | MODULE_ALIAS("platform:" USBHS_DRIVER_NAME); |
481 | MODULE_LICENSE("GPL v2"); | |
482 | MODULE_DESCRIPTION("usb tll driver for TI OMAP EHCI and OHCI controllers"); | |
483 | ||
484 | static int __init omap_usbtll_drvinit(void) | |
485 | { | |
486 | return platform_driver_register(&usbtll_omap_driver); | |
487 | } | |
488 | ||
489 | /* | |
490 | * init before usbhs core driver; | |
491 | * The usbtll driver should be initialized before | |
492 | * the usbhs core driver probe function is called. | |
493 | */ | |
494 | fs_initcall(omap_usbtll_drvinit); | |
495 | ||
496 | static void __exit omap_usbtll_drvexit(void) | |
497 | { | |
498 | platform_driver_unregister(&usbtll_omap_driver); | |
499 | } | |
500 | module_exit(omap_usbtll_drvexit); |