blob: 265f5e350e1c7614d83b7a65c2812091e0fb985b [file] [log] [blame]
Thomas Gleixner6b1baef2019-05-29 16:57:55 -07001// SPDX-License-Identifier: GPL-2.0-only
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +05302/**
3 * omap-usb-tll.c - The USB TLL driver for OMAP EHCI & OHCI
4 *
Roger Quadros9f4a3ec2013-01-29 15:00:03 +02005 * Copyright (C) 2012-2013 Texas Instruments Incorporated - http://www.ti.com
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +05306 * Author: Keshava Munegowda <keshava_mgowda@ti.com>
Roger Quadros9f4a3ec2013-01-29 15:00:03 +02007 * Author: Roger Quadros <rogerq@ti.com>
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +05308 */
9#include <linux/kernel.h>
10#include <linux/module.h>
11#include <linux/types.h>
12#include <linux/slab.h>
13#include <linux/spinlock.h>
14#include <linux/platform_device.h>
15#include <linux/clk.h>
16#include <linux/io.h>
17#include <linux/err.h>
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +053018#include <linux/pm_runtime.h>
Felipe Balbie8c4a7a2012-10-24 14:26:19 -070019#include <linux/platform_data/usb-omap.h>
Roger Quadros48130b82013-01-29 15:20:55 +020020#include <linux/of.h>
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +053021
Ben Dooks17ed4d22016-06-08 19:06:20 +010022#include "omap-usb.h"
23
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +053024#define USBTLL_DRIVER_NAME "usbhs_tll"
25
26/* TLL Register Set */
27#define OMAP_USBTLL_REVISION (0x00)
28#define OMAP_USBTLL_SYSCONFIG (0x10)
29#define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8)
30#define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3)
31#define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2)
32#define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1)
33#define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0)
34
35#define OMAP_USBTLL_SYSSTATUS (0x14)
36#define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0)
37
38#define OMAP_USBTLL_IRQSTATUS (0x18)
39#define OMAP_USBTLL_IRQENABLE (0x1C)
40
41#define OMAP_TLL_SHARED_CONF (0x30)
42#define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6)
43#define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5)
44#define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2)
45#define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1)
46#define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0)
47
48#define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num)
49#define OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT 24
Roger Quadros300c2f82012-11-08 16:10:41 +020050#define OMAP_TLL_CHANNEL_CONF_DRVVBUS (1 << 16)
51#define OMAP_TLL_CHANNEL_CONF_CHRGVBUS (1 << 15)
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +053052#define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11)
53#define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10)
54#define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9)
55#define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8)
Roger Quadros300c2f82012-11-08 16:10:41 +020056#define OMAP_TLL_CHANNEL_CONF_MODE_TRANSPARENT_UTMI (2 << 1)
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +053057#define OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS (1 << 1)
58#define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0)
59
60#define OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0 0x0
61#define OMAP_TLL_FSLSMODE_6PIN_PHY_DP_DM 0x1
62#define OMAP_TLL_FSLSMODE_3PIN_PHY 0x2
63#define OMAP_TLL_FSLSMODE_4PIN_PHY 0x3
64#define OMAP_TLL_FSLSMODE_6PIN_TLL_DAT_SE0 0x4
65#define OMAP_TLL_FSLSMODE_6PIN_TLL_DP_DM 0x5
66#define OMAP_TLL_FSLSMODE_3PIN_TLL 0x6
67#define OMAP_TLL_FSLSMODE_4PIN_TLL 0x7
68#define OMAP_TLL_FSLSMODE_2PIN_TLL_DAT_SE0 0xA
69#define OMAP_TLL_FSLSMODE_2PIN_DAT_DP_DM 0xB
70
71#define OMAP_TLL_ULPI_FUNCTION_CTRL(num) (0x804 + 0x100 * num)
72#define OMAP_TLL_ULPI_INTERFACE_CTRL(num) (0x807 + 0x100 * num)
73#define OMAP_TLL_ULPI_OTG_CTRL(num) (0x80A + 0x100 * num)
74#define OMAP_TLL_ULPI_INT_EN_RISE(num) (0x80D + 0x100 * num)
75#define OMAP_TLL_ULPI_INT_EN_FALL(num) (0x810 + 0x100 * num)
76#define OMAP_TLL_ULPI_INT_STATUS(num) (0x813 + 0x100 * num)
77#define OMAP_TLL_ULPI_INT_LATCH(num) (0x814 + 0x100 * num)
78#define OMAP_TLL_ULPI_DEBUG(num) (0x815 + 0x100 * num)
79#define OMAP_TLL_ULPI_SCRATCH_REGISTER(num) (0x816 + 0x100 * num)
80
81#define OMAP_REV2_TLL_CHANNEL_COUNT 2
82#define OMAP_TLL_CHANNEL_COUNT 3
83#define OMAP_TLL_CHANNEL_1_EN_MASK (1 << 0)
84#define OMAP_TLL_CHANNEL_2_EN_MASK (1 << 1)
85#define OMAP_TLL_CHANNEL_3_EN_MASK (1 << 2)
86
87/* Values of USBTLL_REVISION - Note: these are not given in the TRM */
88#define OMAP_USBTLL_REV1 0x00000015 /* OMAP3 */
89#define OMAP_USBTLL_REV2 0x00000018 /* OMAP 3630 */
90#define OMAP_USBTLL_REV3 0x00000004 /* OMAP4 */
Roger Quadros300c2f82012-11-08 16:10:41 +020091#define OMAP_USBTLL_REV4 0x00000006 /* OMAP5 */
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +053092
93#define is_ehci_tll_mode(x) (x == OMAP_EHCI_PORT_MODE_TLL)
94
Roger Quadros32a51f22012-11-08 14:40:45 +020095/* only PHY and UNUSED modes don't need TLL */
96#define omap_usb_mode_needs_tll(x) ((x) != OMAP_USBHS_PORT_MODE_UNUSED &&\
97 (x) != OMAP_EHCI_PORT_MODE_PHY)
98
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +053099struct usbtll_omap {
Ladislav Michl16c20042018-01-15 21:25:05 +0100100 void __iomem *base;
101 int nch; /* num. of channels */
102 struct clk *ch_clk[0]; /* must be the last member */
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530103};
104
105/*-------------------------------------------------------------------------*/
106
Roger Quadros7ed86192012-11-26 15:26:28 +0200107static const char usbtll_driver_name[] = USBTLL_DRIVER_NAME;
108static struct device *tll_dev;
Roger Quadros66751442012-11-26 16:56:26 +0200109static DEFINE_SPINLOCK(tll_lock); /* serialize access to tll_dev */
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530110
111/*-------------------------------------------------------------------------*/
112
113static inline void usbtll_write(void __iomem *base, u32 reg, u32 val)
114{
Victor Kamenskydd6eb262013-11-16 02:01:15 +0200115 writel_relaxed(val, base + reg);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530116}
117
118static inline u32 usbtll_read(void __iomem *base, u32 reg)
119{
Victor Kamenskydd6eb262013-11-16 02:01:15 +0200120 return readl_relaxed(base + reg);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530121}
122
Arnd Bergmann993dc732017-08-23 16:44:51 +0200123static inline void usbtll_writeb(void __iomem *base, u32 reg, u8 val)
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530124{
Victor Kamenskydd6eb262013-11-16 02:01:15 +0200125 writeb_relaxed(val, base + reg);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530126}
127
Arnd Bergmann993dc732017-08-23 16:44:51 +0200128static inline u8 usbtll_readb(void __iomem *base, u32 reg)
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530129{
Victor Kamenskydd6eb262013-11-16 02:01:15 +0200130 return readb_relaxed(base + reg);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530131}
132
133/*-------------------------------------------------------------------------*/
134
135static bool is_ohci_port(enum usbhs_omap_port_mode pmode)
136{
137 switch (pmode) {
138 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
139 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
140 case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
141 case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
142 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
143 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
144 case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
145 case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
146 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
147 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
148 return true;
149
150 default:
151 return false;
152 }
153}
154
155/*
156 * convert the port-mode enum to a value we can use in the FSLSMODE
157 * field of USBTLL_CHANNEL_CONF
158 */
159static unsigned ohci_omap3_fslsmode(enum usbhs_omap_port_mode mode)
160{
161 switch (mode) {
162 case OMAP_USBHS_PORT_MODE_UNUSED:
163 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
164 return OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0;
165
166 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
167 return OMAP_TLL_FSLSMODE_6PIN_PHY_DP_DM;
168
169 case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
170 return OMAP_TLL_FSLSMODE_3PIN_PHY;
171
172 case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
173 return OMAP_TLL_FSLSMODE_4PIN_PHY;
174
175 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
176 return OMAP_TLL_FSLSMODE_6PIN_TLL_DAT_SE0;
177
178 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
179 return OMAP_TLL_FSLSMODE_6PIN_TLL_DP_DM;
180
181 case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
182 return OMAP_TLL_FSLSMODE_3PIN_TLL;
183
184 case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
185 return OMAP_TLL_FSLSMODE_4PIN_TLL;
186
187 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
188 return OMAP_TLL_FSLSMODE_2PIN_TLL_DAT_SE0;
189
190 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
191 return OMAP_TLL_FSLSMODE_2PIN_DAT_DP_DM;
192 default:
193 pr_warn("Invalid port mode, using default\n");
194 return OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0;
195 }
196}
197
198/**
199 * usbtll_omap_probe - initialize TI-based HCDs
200 *
201 * Allocates basic resources for this USB host controller.
202 */
Bill Pembertonf791be42012-11-19 13:23:04 -0500203static int usbtll_omap_probe(struct platform_device *pdev)
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530204{
205 struct device *dev = &pdev->dev;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530206 struct resource *res;
207 struct usbtll_omap *tll;
Ladislav Michl16c20042018-01-15 21:25:05 +0100208 void __iomem *base;
209 int i, nch, ver;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530210
211 dev_dbg(dev, "starting TI HSUSB TLL Controller\n");
212
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530213 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Ladislav Michl16c20042018-01-15 21:25:05 +0100214 base = devm_ioremap_resource(dev, res);
215 if (IS_ERR(base))
216 return PTR_ERR(base);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530217
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530218 pm_runtime_enable(dev);
219 pm_runtime_get_sync(dev);
220
Ladislav Michl16c20042018-01-15 21:25:05 +0100221 ver = usbtll_read(base, OMAP_USBTLL_REVISION);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530222 switch (ver) {
223 case OMAP_USBTLL_REV1:
Roger Quadros300c2f82012-11-08 16:10:41 +0200224 case OMAP_USBTLL_REV4:
Ladislav Michl16c20042018-01-15 21:25:05 +0100225 nch = OMAP_TLL_CHANNEL_COUNT;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530226 break;
Roger Quadros7e0ff1032012-11-26 12:28:44 +0200227 case OMAP_USBTLL_REV2:
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530228 case OMAP_USBTLL_REV3:
Ladislav Michl16c20042018-01-15 21:25:05 +0100229 nch = OMAP_REV2_TLL_CHANNEL_COUNT;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530230 break;
231 default:
Ladislav Michl16c20042018-01-15 21:25:05 +0100232 nch = OMAP_TLL_CHANNEL_COUNT;
233 dev_dbg(dev, "rev 0x%x not recognized, assuming %d channels\n",
234 ver, nch);
Roger Quadros7e0ff1032012-11-26 12:28:44 +0200235 break;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530236 }
237
Ladislav Michl16c20042018-01-15 21:25:05 +0100238 tll = devm_kzalloc(dev, sizeof(*tll) + sizeof(tll->ch_clk[nch]),
239 GFP_KERNEL);
240 if (!tll) {
241 pm_runtime_put_sync(dev);
242 pm_runtime_disable(dev);
243 return -ENOMEM;
Roger Quadros0bde3e92012-11-08 13:07:09 +0200244 }
245
Ladislav Michl16c20042018-01-15 21:25:05 +0100246 tll->base = base;
247 tll->nch = nch;
248 platform_set_drvdata(pdev, tll);
249
250 for (i = 0; i < nch; i++) {
Roger Quadros0bde3e92012-11-08 13:07:09 +0200251 char clkname[] = "usb_tll_hs_usb_chx_clk";
252
253 snprintf(clkname, sizeof(clkname),
254 "usb_tll_hs_usb_ch%d_clk", i);
255 tll->ch_clk[i] = clk_get(dev, clkname);
256
257 if (IS_ERR(tll->ch_clk[i]))
258 dev_dbg(dev, "can't get clock : %s\n", clkname);
Roger Quadrosb49b9272016-05-09 11:28:37 +0300259 else
260 clk_prepare(tll->ch_clk[i]);
Roger Quadros0bde3e92012-11-08 13:07:09 +0200261 }
262
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200263 pm_runtime_put_sync(dev);
264 /* only after this can omap_tll_enable/disable work */
265 spin_lock(&tll_lock);
266 tll_dev = dev;
267 spin_unlock(&tll_lock);
268
269 return 0;
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200270}
271
272/**
273 * usbtll_omap_remove - shutdown processing for UHH & TLL HCDs
274 * @pdev: USB Host Controller being removed
275 *
276 * Reverses the effect of usbtll_omap_probe().
277 */
278static int usbtll_omap_remove(struct platform_device *pdev)
279{
280 struct usbtll_omap *tll = platform_get_drvdata(pdev);
281 int i;
282
283 spin_lock(&tll_lock);
284 tll_dev = NULL;
285 spin_unlock(&tll_lock);
286
Roger Quadrosb49b9272016-05-09 11:28:37 +0300287 for (i = 0; i < tll->nch; i++) {
288 if (!IS_ERR(tll->ch_clk[i])) {
289 clk_unprepare(tll->ch_clk[i]);
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200290 clk_put(tll->ch_clk[i]);
Roger Quadrosb49b9272016-05-09 11:28:37 +0300291 }
292 }
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200293
294 pm_runtime_disable(&pdev->dev);
295 return 0;
296}
297
Roger Quadros48130b82013-01-29 15:20:55 +0200298static const struct of_device_id usbtll_omap_dt_ids[] = {
299 { .compatible = "ti,usbhs-tll" },
300 { }
301};
302
303MODULE_DEVICE_TABLE(of, usbtll_omap_dt_ids);
304
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200305static struct platform_driver usbtll_omap_driver = {
306 .driver = {
307 .name = (char *)usbtll_driver_name,
Sachin Kamat0f54e1e2013-10-15 09:18:50 +0530308 .of_match_table = usbtll_omap_dt_ids,
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200309 },
310 .probe = usbtll_omap_probe,
311 .remove = usbtll_omap_remove,
312};
313
314int omap_tll_init(struct usbhs_omap_platform_data *pdata)
315{
316 int i;
317 bool needs_tll;
318 unsigned reg;
319 struct usbtll_omap *tll;
320
Roger Quadros76a07752014-01-08 12:45:33 +0530321 if (!tll_dev)
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200322 return -ENODEV;
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200323
Roger Quadros76a07752014-01-08 12:45:33 +0530324 pm_runtime_get_sync(tll_dev);
325
326 spin_lock(&tll_lock);
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200327 tll = dev_get_drvdata(tll_dev);
Roger Quadros32a51f22012-11-08 14:40:45 +0200328 needs_tll = false;
329 for (i = 0; i < tll->nch; i++)
330 needs_tll |= omap_usb_mode_needs_tll(pdata->port_mode[i]);
331
332 if (needs_tll) {
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200333 void __iomem *base = tll->base;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530334
335 /* Program Common TLL register */
336 reg = usbtll_read(base, OMAP_TLL_SHARED_CONF);
337 reg |= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON
338 | OMAP_TLL_SHARED_CONF_USB_DIVRATION);
339 reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN;
340 reg &= ~OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN;
341
342 usbtll_write(base, OMAP_TLL_SHARED_CONF, reg);
343
344 /* Enable channels now */
Roger Quadros7e0ff1032012-11-26 12:28:44 +0200345 for (i = 0; i < tll->nch; i++) {
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530346 reg = usbtll_read(base, OMAP_TLL_CHANNEL_CONF(i));
347
348 if (is_ohci_port(pdata->port_mode[i])) {
349 reg |= ohci_omap3_fslsmode(pdata->port_mode[i])
350 << OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT;
351 reg |= OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS;
352 } else if (pdata->port_mode[i] ==
353 OMAP_EHCI_PORT_MODE_TLL) {
354 /*
Tony Lindgren76d33412017-04-15 10:05:09 -0700355 * Disable UTMI AutoIdle, BitStuffing
356 * and use SDR Mode. Enable ULPI AutoIdle.
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530357 */
358 reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530359 | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE);
Tony Lindgren8b8a84c2017-04-15 10:05:08 -0700360 reg |= OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF;
Tony Lindgren76d33412017-04-15 10:05:09 -0700361 reg |= OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE;
Roger Quadros300c2f82012-11-08 16:10:41 +0200362 } else if (pdata->port_mode[i] ==
363 OMAP_EHCI_PORT_MODE_HSIC) {
364 /*
365 * HSIC Mode requires UTMI port configurations
366 */
367 reg |= OMAP_TLL_CHANNEL_CONF_DRVVBUS
368 | OMAP_TLL_CHANNEL_CONF_CHRGVBUS
369 | OMAP_TLL_CHANNEL_CONF_MODE_TRANSPARENT_UTMI
370 | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530371 } else {
372 continue;
373 }
374 reg |= OMAP_TLL_CHANNEL_CONF_CHANEN;
375 usbtll_write(base, OMAP_TLL_CHANNEL_CONF(i), reg);
376
377 usbtll_writeb(base,
378 OMAP_TLL_ULPI_SCRATCH_REGISTER(i),
379 0xbe);
380 }
381 }
382
Roger Quadros66751442012-11-26 16:56:26 +0200383 spin_unlock(&tll_lock);
Roger Quadros76a07752014-01-08 12:45:33 +0530384 pm_runtime_put_sync(tll_dev);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530385
Roger Quadros1a7a8d72012-11-26 12:56:37 +0200386 return 0;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530387}
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200388EXPORT_SYMBOL_GPL(omap_tll_init);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530389
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200390int omap_tll_enable(struct usbhs_omap_platform_data *pdata)
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530391{
Roger Quadros0bde3e92012-11-08 13:07:09 +0200392 int i;
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200393 struct usbtll_omap *tll;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530394
Roger Quadros76a07752014-01-08 12:45:33 +0530395 if (!tll_dev)
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200396 return -ENODEV;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530397
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200398 pm_runtime_get_sync(tll_dev);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530399
Roger Quadros76a07752014-01-08 12:45:33 +0530400 spin_lock(&tll_lock);
401 tll = dev_get_drvdata(tll_dev);
402
Roger Quadros0bde3e92012-11-08 13:07:09 +0200403 for (i = 0; i < tll->nch; i++) {
Roger Quadros32a51f22012-11-08 14:40:45 +0200404 if (omap_usb_mode_needs_tll(pdata->port_mode[i])) {
Roger Quadros0bde3e92012-11-08 13:07:09 +0200405 int r;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530406
Roger Quadros0bde3e92012-11-08 13:07:09 +0200407 if (IS_ERR(tll->ch_clk[i]))
408 continue;
409
Roger Quadrosb49b9272016-05-09 11:28:37 +0300410 r = clk_enable(tll->ch_clk[i]);
Roger Quadros0bde3e92012-11-08 13:07:09 +0200411 if (r) {
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200412 dev_err(tll_dev,
Roger Quadros0bde3e92012-11-08 13:07:09 +0200413 "Error enabling ch %d clock: %d\n", i, r);
414 }
415 }
416 }
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530417
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200418 spin_unlock(&tll_lock);
419
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530420 return 0;
421}
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200422EXPORT_SYMBOL_GPL(omap_tll_enable);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530423
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200424int omap_tll_disable(struct usbhs_omap_platform_data *pdata)
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530425{
Roger Quadros0bde3e92012-11-08 13:07:09 +0200426 int i;
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200427 struct usbtll_omap *tll;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530428
Roger Quadros76a07752014-01-08 12:45:33 +0530429 if (!tll_dev)
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200430 return -ENODEV;
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200431
Roger Quadros76a07752014-01-08 12:45:33 +0530432 spin_lock(&tll_lock);
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200433 tll = dev_get_drvdata(tll_dev);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530434
Roger Quadros0bde3e92012-11-08 13:07:09 +0200435 for (i = 0; i < tll->nch; i++) {
Roger Quadros32a51f22012-11-08 14:40:45 +0200436 if (omap_usb_mode_needs_tll(pdata->port_mode[i])) {
Roger Quadros0bde3e92012-11-08 13:07:09 +0200437 if (!IS_ERR(tll->ch_clk[i]))
Roger Quadrosb49b9272016-05-09 11:28:37 +0300438 clk_disable(tll->ch_clk[i]);
Roger Quadros0bde3e92012-11-08 13:07:09 +0200439 }
440 }
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530441
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200442 spin_unlock(&tll_lock);
Roger Quadros76a07752014-01-08 12:45:33 +0530443 pm_runtime_put_sync(tll_dev);
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200444
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530445 return 0;
446}
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530447EXPORT_SYMBOL_GPL(omap_tll_disable);
448
449MODULE_AUTHOR("Keshava Munegowda <keshava_mgowda@ti.com>");
Roger Quadros48130b82013-01-29 15:20:55 +0200450MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>");
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530451MODULE_LICENSE("GPL v2");
452MODULE_DESCRIPTION("usb tll driver for TI OMAP EHCI and OHCI controllers");
453
454static int __init omap_usbtll_drvinit(void)
455{
456 return platform_driver_register(&usbtll_omap_driver);
457}
458
459/*
460 * init before usbhs core driver;
461 * The usbtll driver should be initialized before
462 * the usbhs core driver probe function is called.
463 */
464fs_initcall(omap_usbtll_drvinit);
465
466static void __exit omap_usbtll_drvexit(void)
467{
468 platform_driver_unregister(&usbtll_omap_driver);
469}
470module_exit(omap_usbtll_drvexit);