blob: 446713dbee27aa2852079bf3370562a8a92fcc51 [file] [log] [blame]
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +05301/**
2 * omap-usb-tll.c - The USB TLL driver for OMAP EHCI & OHCI
3 *
Roger Quadros9f4a3ec2013-01-29 15:00:03 +02004 * Copyright (C) 2012-2013 Texas Instruments Incorporated - http://www.ti.com
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +05305 * Author: Keshava Munegowda <keshava_mgowda@ti.com>
Roger Quadros9f4a3ec2013-01-29 15:00:03 +02006 * Author: Roger Quadros <rogerq@ti.com>
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +05307 *
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>
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +053029#include <linux/pm_runtime.h>
Felipe Balbie8c4a7a2012-10-24 14:26:19 -070030#include <linux/platform_data/usb-omap.h>
Roger Quadros48130b82013-01-29 15:20:55 +020031#include <linux/of.h>
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +053032
Ben Dooks17ed4d22016-06-08 19:06:20 +010033#include "omap-usb.h"
34
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +053035#define USBTLL_DRIVER_NAME "usbhs_tll"
36
37/* TLL Register Set */
38#define OMAP_USBTLL_REVISION (0x00)
39#define OMAP_USBTLL_SYSCONFIG (0x10)
40#define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8)
41#define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3)
42#define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2)
43#define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1)
44#define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0)
45
46#define OMAP_USBTLL_SYSSTATUS (0x14)
47#define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0)
48
49#define OMAP_USBTLL_IRQSTATUS (0x18)
50#define OMAP_USBTLL_IRQENABLE (0x1C)
51
52#define OMAP_TLL_SHARED_CONF (0x30)
53#define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6)
54#define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5)
55#define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2)
56#define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1)
57#define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0)
58
59#define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num)
60#define OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT 24
Roger Quadros300c2f82012-11-08 16:10:41 +020061#define OMAP_TLL_CHANNEL_CONF_DRVVBUS (1 << 16)
62#define OMAP_TLL_CHANNEL_CONF_CHRGVBUS (1 << 15)
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +053063#define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11)
64#define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10)
65#define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9)
66#define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8)
Roger Quadros300c2f82012-11-08 16:10:41 +020067#define OMAP_TLL_CHANNEL_CONF_MODE_TRANSPARENT_UTMI (2 << 1)
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +053068#define OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS (1 << 1)
69#define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0)
70
71#define OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0 0x0
72#define OMAP_TLL_FSLSMODE_6PIN_PHY_DP_DM 0x1
73#define OMAP_TLL_FSLSMODE_3PIN_PHY 0x2
74#define OMAP_TLL_FSLSMODE_4PIN_PHY 0x3
75#define OMAP_TLL_FSLSMODE_6PIN_TLL_DAT_SE0 0x4
76#define OMAP_TLL_FSLSMODE_6PIN_TLL_DP_DM 0x5
77#define OMAP_TLL_FSLSMODE_3PIN_TLL 0x6
78#define OMAP_TLL_FSLSMODE_4PIN_TLL 0x7
79#define OMAP_TLL_FSLSMODE_2PIN_TLL_DAT_SE0 0xA
80#define OMAP_TLL_FSLSMODE_2PIN_DAT_DP_DM 0xB
81
82#define OMAP_TLL_ULPI_FUNCTION_CTRL(num) (0x804 + 0x100 * num)
83#define OMAP_TLL_ULPI_INTERFACE_CTRL(num) (0x807 + 0x100 * num)
84#define OMAP_TLL_ULPI_OTG_CTRL(num) (0x80A + 0x100 * num)
85#define OMAP_TLL_ULPI_INT_EN_RISE(num) (0x80D + 0x100 * num)
86#define OMAP_TLL_ULPI_INT_EN_FALL(num) (0x810 + 0x100 * num)
87#define OMAP_TLL_ULPI_INT_STATUS(num) (0x813 + 0x100 * num)
88#define OMAP_TLL_ULPI_INT_LATCH(num) (0x814 + 0x100 * num)
89#define OMAP_TLL_ULPI_DEBUG(num) (0x815 + 0x100 * num)
90#define OMAP_TLL_ULPI_SCRATCH_REGISTER(num) (0x816 + 0x100 * num)
91
92#define OMAP_REV2_TLL_CHANNEL_COUNT 2
93#define OMAP_TLL_CHANNEL_COUNT 3
94#define OMAP_TLL_CHANNEL_1_EN_MASK (1 << 0)
95#define OMAP_TLL_CHANNEL_2_EN_MASK (1 << 1)
96#define OMAP_TLL_CHANNEL_3_EN_MASK (1 << 2)
97
98/* Values of USBTLL_REVISION - Note: these are not given in the TRM */
99#define OMAP_USBTLL_REV1 0x00000015 /* OMAP3 */
100#define OMAP_USBTLL_REV2 0x00000018 /* OMAP 3630 */
101#define OMAP_USBTLL_REV3 0x00000004 /* OMAP4 */
Roger Quadros300c2f82012-11-08 16:10:41 +0200102#define OMAP_USBTLL_REV4 0x00000006 /* OMAP5 */
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530103
104#define is_ehci_tll_mode(x) (x == OMAP_EHCI_PORT_MODE_TLL)
105
Roger Quadros32a51f22012-11-08 14:40:45 +0200106/* only PHY and UNUSED modes don't need TLL */
107#define omap_usb_mode_needs_tll(x) ((x) != OMAP_USBHS_PORT_MODE_UNUSED &&\
108 (x) != OMAP_EHCI_PORT_MODE_PHY)
109
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530110struct usbtll_omap {
Ladislav Michl16c20042018-01-15 21:25:05 +0100111 void __iomem *base;
112 int nch; /* num. of channels */
113 struct clk *ch_clk[0]; /* must be the last member */
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530114};
115
116/*-------------------------------------------------------------------------*/
117
Roger Quadros7ed86192012-11-26 15:26:28 +0200118static const char usbtll_driver_name[] = USBTLL_DRIVER_NAME;
119static struct device *tll_dev;
Roger Quadros66751442012-11-26 16:56:26 +0200120static DEFINE_SPINLOCK(tll_lock); /* serialize access to tll_dev */
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530121
122/*-------------------------------------------------------------------------*/
123
124static inline void usbtll_write(void __iomem *base, u32 reg, u32 val)
125{
Victor Kamenskydd6eb262013-11-16 02:01:15 +0200126 writel_relaxed(val, base + reg);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530127}
128
129static inline u32 usbtll_read(void __iomem *base, u32 reg)
130{
Victor Kamenskydd6eb262013-11-16 02:01:15 +0200131 return readl_relaxed(base + reg);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530132}
133
Arnd Bergmann993dc732017-08-23 16:44:51 +0200134static inline void usbtll_writeb(void __iomem *base, u32 reg, u8 val)
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530135{
Victor Kamenskydd6eb262013-11-16 02:01:15 +0200136 writeb_relaxed(val, base + reg);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530137}
138
Arnd Bergmann993dc732017-08-23 16:44:51 +0200139static inline u8 usbtll_readb(void __iomem *base, u32 reg)
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530140{
Victor Kamenskydd6eb262013-11-16 02:01:15 +0200141 return readb_relaxed(base + reg);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530142}
143
144/*-------------------------------------------------------------------------*/
145
146static bool is_ohci_port(enum usbhs_omap_port_mode pmode)
147{
148 switch (pmode) {
149 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
150 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
151 case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
152 case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
153 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
154 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
155 case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
156 case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
157 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
158 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
159 return true;
160
161 default:
162 return false;
163 }
164}
165
166/*
167 * convert the port-mode enum to a value we can use in the FSLSMODE
168 * field of USBTLL_CHANNEL_CONF
169 */
170static unsigned ohci_omap3_fslsmode(enum usbhs_omap_port_mode mode)
171{
172 switch (mode) {
173 case OMAP_USBHS_PORT_MODE_UNUSED:
174 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
175 return OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0;
176
177 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
178 return OMAP_TLL_FSLSMODE_6PIN_PHY_DP_DM;
179
180 case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
181 return OMAP_TLL_FSLSMODE_3PIN_PHY;
182
183 case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
184 return OMAP_TLL_FSLSMODE_4PIN_PHY;
185
186 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
187 return OMAP_TLL_FSLSMODE_6PIN_TLL_DAT_SE0;
188
189 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
190 return OMAP_TLL_FSLSMODE_6PIN_TLL_DP_DM;
191
192 case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
193 return OMAP_TLL_FSLSMODE_3PIN_TLL;
194
195 case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
196 return OMAP_TLL_FSLSMODE_4PIN_TLL;
197
198 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
199 return OMAP_TLL_FSLSMODE_2PIN_TLL_DAT_SE0;
200
201 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
202 return OMAP_TLL_FSLSMODE_2PIN_DAT_DP_DM;
203 default:
204 pr_warn("Invalid port mode, using default\n");
205 return OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0;
206 }
207}
208
209/**
210 * usbtll_omap_probe - initialize TI-based HCDs
211 *
212 * Allocates basic resources for this USB host controller.
213 */
Bill Pembertonf791be42012-11-19 13:23:04 -0500214static int usbtll_omap_probe(struct platform_device *pdev)
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530215{
216 struct device *dev = &pdev->dev;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530217 struct resource *res;
218 struct usbtll_omap *tll;
Ladislav Michl16c20042018-01-15 21:25:05 +0100219 void __iomem *base;
220 int i, nch, ver;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530221
222 dev_dbg(dev, "starting TI HSUSB TLL Controller\n");
223
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530224 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Ladislav Michl16c20042018-01-15 21:25:05 +0100225 base = devm_ioremap_resource(dev, res);
226 if (IS_ERR(base))
227 return PTR_ERR(base);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530228
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530229 pm_runtime_enable(dev);
230 pm_runtime_get_sync(dev);
231
Ladislav Michl16c20042018-01-15 21:25:05 +0100232 ver = usbtll_read(base, OMAP_USBTLL_REVISION);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530233 switch (ver) {
234 case OMAP_USBTLL_REV1:
Roger Quadros300c2f82012-11-08 16:10:41 +0200235 case OMAP_USBTLL_REV4:
Ladislav Michl16c20042018-01-15 21:25:05 +0100236 nch = OMAP_TLL_CHANNEL_COUNT;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530237 break;
Roger Quadros7e0ff1032012-11-26 12:28:44 +0200238 case OMAP_USBTLL_REV2:
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530239 case OMAP_USBTLL_REV3:
Ladislav Michl16c20042018-01-15 21:25:05 +0100240 nch = OMAP_REV2_TLL_CHANNEL_COUNT;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530241 break;
242 default:
Ladislav Michl16c20042018-01-15 21:25:05 +0100243 nch = OMAP_TLL_CHANNEL_COUNT;
244 dev_dbg(dev, "rev 0x%x not recognized, assuming %d channels\n",
245 ver, nch);
Roger Quadros7e0ff1032012-11-26 12:28:44 +0200246 break;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530247 }
248
Ladislav Michl16c20042018-01-15 21:25:05 +0100249 tll = devm_kzalloc(dev, sizeof(*tll) + sizeof(tll->ch_clk[nch]),
250 GFP_KERNEL);
251 if (!tll) {
252 pm_runtime_put_sync(dev);
253 pm_runtime_disable(dev);
254 return -ENOMEM;
Roger Quadros0bde3e92012-11-08 13:07:09 +0200255 }
256
Ladislav Michl16c20042018-01-15 21:25:05 +0100257 tll->base = base;
258 tll->nch = nch;
259 platform_set_drvdata(pdev, tll);
260
261 for (i = 0; i < nch; i++) {
Roger Quadros0bde3e92012-11-08 13:07:09 +0200262 char clkname[] = "usb_tll_hs_usb_chx_clk";
263
264 snprintf(clkname, sizeof(clkname),
265 "usb_tll_hs_usb_ch%d_clk", i);
266 tll->ch_clk[i] = clk_get(dev, clkname);
267
268 if (IS_ERR(tll->ch_clk[i]))
269 dev_dbg(dev, "can't get clock : %s\n", clkname);
Roger Quadrosb49b9272016-05-09 11:28:37 +0300270 else
271 clk_prepare(tll->ch_clk[i]);
Roger Quadros0bde3e92012-11-08 13:07:09 +0200272 }
273
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200274 pm_runtime_put_sync(dev);
275 /* only after this can omap_tll_enable/disable work */
276 spin_lock(&tll_lock);
277 tll_dev = dev;
278 spin_unlock(&tll_lock);
279
280 return 0;
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200281}
282
283/**
284 * usbtll_omap_remove - shutdown processing for UHH & TLL HCDs
285 * @pdev: USB Host Controller being removed
286 *
287 * Reverses the effect of usbtll_omap_probe().
288 */
289static int usbtll_omap_remove(struct platform_device *pdev)
290{
291 struct usbtll_omap *tll = platform_get_drvdata(pdev);
292 int i;
293
294 spin_lock(&tll_lock);
295 tll_dev = NULL;
296 spin_unlock(&tll_lock);
297
Roger Quadrosb49b9272016-05-09 11:28:37 +0300298 for (i = 0; i < tll->nch; i++) {
299 if (!IS_ERR(tll->ch_clk[i])) {
300 clk_unprepare(tll->ch_clk[i]);
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200301 clk_put(tll->ch_clk[i]);
Roger Quadrosb49b9272016-05-09 11:28:37 +0300302 }
303 }
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200304
305 pm_runtime_disable(&pdev->dev);
306 return 0;
307}
308
Roger Quadros48130b82013-01-29 15:20:55 +0200309static const struct of_device_id usbtll_omap_dt_ids[] = {
310 { .compatible = "ti,usbhs-tll" },
311 { }
312};
313
314MODULE_DEVICE_TABLE(of, usbtll_omap_dt_ids);
315
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200316static struct platform_driver usbtll_omap_driver = {
317 .driver = {
318 .name = (char *)usbtll_driver_name,
Sachin Kamat0f54e1e2013-10-15 09:18:50 +0530319 .of_match_table = usbtll_omap_dt_ids,
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200320 },
321 .probe = usbtll_omap_probe,
322 .remove = usbtll_omap_remove,
323};
324
325int omap_tll_init(struct usbhs_omap_platform_data *pdata)
326{
327 int i;
328 bool needs_tll;
329 unsigned reg;
330 struct usbtll_omap *tll;
331
Roger Quadros76a07752014-01-08 12:45:33 +0530332 if (!tll_dev)
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200333 return -ENODEV;
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200334
Roger Quadros76a07752014-01-08 12:45:33 +0530335 pm_runtime_get_sync(tll_dev);
336
337 spin_lock(&tll_lock);
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200338 tll = dev_get_drvdata(tll_dev);
Roger Quadros32a51f22012-11-08 14:40:45 +0200339 needs_tll = false;
340 for (i = 0; i < tll->nch; i++)
341 needs_tll |= omap_usb_mode_needs_tll(pdata->port_mode[i]);
342
343 if (needs_tll) {
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200344 void __iomem *base = tll->base;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530345
346 /* Program Common TLL register */
347 reg = usbtll_read(base, OMAP_TLL_SHARED_CONF);
348 reg |= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON
349 | OMAP_TLL_SHARED_CONF_USB_DIVRATION);
350 reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN;
351 reg &= ~OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN;
352
353 usbtll_write(base, OMAP_TLL_SHARED_CONF, reg);
354
355 /* Enable channels now */
Roger Quadros7e0ff1032012-11-26 12:28:44 +0200356 for (i = 0; i < tll->nch; i++) {
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530357 reg = usbtll_read(base, OMAP_TLL_CHANNEL_CONF(i));
358
359 if (is_ohci_port(pdata->port_mode[i])) {
360 reg |= ohci_omap3_fslsmode(pdata->port_mode[i])
361 << OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT;
362 reg |= OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS;
363 } else if (pdata->port_mode[i] ==
364 OMAP_EHCI_PORT_MODE_TLL) {
365 /*
Tony Lindgren76d33412017-04-15 10:05:09 -0700366 * Disable UTMI AutoIdle, BitStuffing
367 * and use SDR Mode. Enable ULPI AutoIdle.
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530368 */
369 reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530370 | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE);
Tony Lindgren8b8a84c2017-04-15 10:05:08 -0700371 reg |= OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF;
Tony Lindgren76d33412017-04-15 10:05:09 -0700372 reg |= OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE;
Roger Quadros300c2f82012-11-08 16:10:41 +0200373 } else if (pdata->port_mode[i] ==
374 OMAP_EHCI_PORT_MODE_HSIC) {
375 /*
376 * HSIC Mode requires UTMI port configurations
377 */
378 reg |= OMAP_TLL_CHANNEL_CONF_DRVVBUS
379 | OMAP_TLL_CHANNEL_CONF_CHRGVBUS
380 | OMAP_TLL_CHANNEL_CONF_MODE_TRANSPARENT_UTMI
381 | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530382 } else {
383 continue;
384 }
385 reg |= OMAP_TLL_CHANNEL_CONF_CHANEN;
386 usbtll_write(base, OMAP_TLL_CHANNEL_CONF(i), reg);
387
388 usbtll_writeb(base,
389 OMAP_TLL_ULPI_SCRATCH_REGISTER(i),
390 0xbe);
391 }
392 }
393
Roger Quadros66751442012-11-26 16:56:26 +0200394 spin_unlock(&tll_lock);
Roger Quadros76a07752014-01-08 12:45:33 +0530395 pm_runtime_put_sync(tll_dev);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530396
Roger Quadros1a7a8d72012-11-26 12:56:37 +0200397 return 0;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530398}
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200399EXPORT_SYMBOL_GPL(omap_tll_init);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530400
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200401int omap_tll_enable(struct usbhs_omap_platform_data *pdata)
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530402{
Roger Quadros0bde3e92012-11-08 13:07:09 +0200403 int i;
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200404 struct usbtll_omap *tll;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530405
Roger Quadros76a07752014-01-08 12:45:33 +0530406 if (!tll_dev)
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200407 return -ENODEV;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530408
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200409 pm_runtime_get_sync(tll_dev);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530410
Roger Quadros76a07752014-01-08 12:45:33 +0530411 spin_lock(&tll_lock);
412 tll = dev_get_drvdata(tll_dev);
413
Roger Quadros0bde3e92012-11-08 13:07:09 +0200414 for (i = 0; i < tll->nch; i++) {
Roger Quadros32a51f22012-11-08 14:40:45 +0200415 if (omap_usb_mode_needs_tll(pdata->port_mode[i])) {
Roger Quadros0bde3e92012-11-08 13:07:09 +0200416 int r;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530417
Roger Quadros0bde3e92012-11-08 13:07:09 +0200418 if (IS_ERR(tll->ch_clk[i]))
419 continue;
420
Roger Quadrosb49b9272016-05-09 11:28:37 +0300421 r = clk_enable(tll->ch_clk[i]);
Roger Quadros0bde3e92012-11-08 13:07:09 +0200422 if (r) {
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200423 dev_err(tll_dev,
Roger Quadros0bde3e92012-11-08 13:07:09 +0200424 "Error enabling ch %d clock: %d\n", i, r);
425 }
426 }
427 }
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530428
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200429 spin_unlock(&tll_lock);
430
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530431 return 0;
432}
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200433EXPORT_SYMBOL_GPL(omap_tll_enable);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530434
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200435int omap_tll_disable(struct usbhs_omap_platform_data *pdata)
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530436{
Roger Quadros0bde3e92012-11-08 13:07:09 +0200437 int i;
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200438 struct usbtll_omap *tll;
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530439
Roger Quadros76a07752014-01-08 12:45:33 +0530440 if (!tll_dev)
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200441 return -ENODEV;
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200442
Roger Quadros76a07752014-01-08 12:45:33 +0530443 spin_lock(&tll_lock);
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200444 tll = dev_get_drvdata(tll_dev);
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530445
Roger Quadros0bde3e92012-11-08 13:07:09 +0200446 for (i = 0; i < tll->nch; i++) {
Roger Quadros32a51f22012-11-08 14:40:45 +0200447 if (omap_usb_mode_needs_tll(pdata->port_mode[i])) {
Roger Quadros0bde3e92012-11-08 13:07:09 +0200448 if (!IS_ERR(tll->ch_clk[i]))
Roger Quadrosb49b9272016-05-09 11:28:37 +0300449 clk_disable(tll->ch_clk[i]);
Roger Quadros0bde3e92012-11-08 13:07:09 +0200450 }
451 }
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530452
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200453 spin_unlock(&tll_lock);
Roger Quadros76a07752014-01-08 12:45:33 +0530454 pm_runtime_put_sync(tll_dev);
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200455
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530456 return 0;
457}
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530458EXPORT_SYMBOL_GPL(omap_tll_disable);
459
460MODULE_AUTHOR("Keshava Munegowda <keshava_mgowda@ti.com>");
Roger Quadros48130b82013-01-29 15:20:55 +0200461MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>");
Keshava Munegowda16fa3dc2012-07-16 19:01:08 +0530462MODULE_ALIAS("platform:" USBHS_DRIVER_NAME);
463MODULE_LICENSE("GPL v2");
464MODULE_DESCRIPTION("usb tll driver for TI OMAP EHCI and OHCI controllers");
465
466static int __init omap_usbtll_drvinit(void)
467{
468 return platform_driver_register(&usbtll_omap_driver);
469}
470
471/*
472 * init before usbhs core driver;
473 * The usbtll driver should be initialized before
474 * the usbhs core driver probe function is called.
475 */
476fs_initcall(omap_usbtll_drvinit);
477
478static void __exit omap_usbtll_drvexit(void)
479{
480 platform_driver_unregister(&usbtll_omap_driver);
481}
482module_exit(omap_usbtll_drvexit);