blob: 8a256dfe6ddf7f013e849a939fbd8062e0549a0d [file] [log] [blame]
Keshava Munegowda17cdd292011-03-01 20:08:17 +05301/**
2 * omap-usb-host.c - The USBHS core driver for OMAP EHCI & OHCI
3 *
4 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com
5 * Author: Keshava Munegowda <keshava_mgowda@ti.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 of
9 * the License as published by the Free Software Foundation.
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, see <http://www.gnu.org/licenses/>.
18 */
19#include <linux/kernel.h>
Ming Lei417e2062011-08-19 16:57:54 +080020#include <linux/module.h>
Keshava Munegowda17cdd292011-03-01 20:08:17 +053021#include <linux/types.h>
22#include <linux/slab.h>
23#include <linux/delay.h>
Keshava Munegowda17cdd292011-03-01 20:08:17 +053024#include <linux/clk.h>
25#include <linux/dma-mapping.h>
26#include <linux/spinlock.h>
Russ Dillc05995c2012-06-14 09:24:21 -070027#include <linux/gpio.h>
Russ Dill13176a82012-04-22 01:48:18 -070028#include <plat/cpu.h>
Keshava Munegowda17cdd292011-03-01 20:08:17 +053029#include <plat/usb.h>
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +053030#include <linux/pm_runtime.h>
Keshava Munegowda17cdd292011-03-01 20:08:17 +053031
Keshava Munegowdaa6d3a662011-10-11 13:21:51 +053032#define USBHS_DRIVER_NAME "usbhs_omap"
Keshava Munegowda17cdd292011-03-01 20:08:17 +053033#define OMAP_EHCI_DEVICE "ehci-omap"
34#define OMAP_OHCI_DEVICE "ohci-omap3"
35
36/* OMAP USBHOST Register addresses */
37
38/* TLL Register Set */
39#define OMAP_USBTLL_REVISION (0x00)
40#define OMAP_USBTLL_SYSCONFIG (0x10)
41#define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8)
42#define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3)
43#define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2)
44#define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1)
45#define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0)
46
47#define OMAP_USBTLL_SYSSTATUS (0x14)
48#define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0)
49
50#define OMAP_USBTLL_IRQSTATUS (0x18)
51#define OMAP_USBTLL_IRQENABLE (0x1C)
52
53#define OMAP_TLL_SHARED_CONF (0x30)
54#define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6)
55#define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5)
56#define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2)
57#define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1)
58#define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0)
59
60#define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num)
61#define OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT 24
62#define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11)
63#define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10)
64#define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9)
65#define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8)
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_TLL_CHANNEL_COUNT 3
91#define OMAP_TLL_CHANNEL_1_EN_MASK (1 << 0)
92#define OMAP_TLL_CHANNEL_2_EN_MASK (1 << 1)
93#define OMAP_TLL_CHANNEL_3_EN_MASK (1 << 2)
94
95/* UHH Register Set */
96#define OMAP_UHH_REVISION (0x00)
97#define OMAP_UHH_SYSCONFIG (0x10)
98#define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12)
99#define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8)
100#define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3)
101#define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2)
102#define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1)
103#define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0)
104
105#define OMAP_UHH_SYSSTATUS (0x14)
106#define OMAP_UHH_HOSTCONFIG (0x40)
107#define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0)
108#define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0)
109#define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11)
110#define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12)
111#define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2)
112#define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3)
113#define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4)
114#define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5)
115#define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8)
116#define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9)
117#define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10)
118#define OMAP4_UHH_HOSTCONFIG_APP_START_CLK (1 << 31)
119
120/* OMAP4-specific defines */
121#define OMAP4_UHH_SYSCONFIG_IDLEMODE_CLEAR (3 << 2)
122#define OMAP4_UHH_SYSCONFIG_NOIDLE (1 << 2)
123#define OMAP4_UHH_SYSCONFIG_STDBYMODE_CLEAR (3 << 4)
124#define OMAP4_UHH_SYSCONFIG_NOSTDBY (1 << 4)
125#define OMAP4_UHH_SYSCONFIG_SOFTRESET (1 << 0)
126
127#define OMAP4_P1_MODE_CLEAR (3 << 16)
128#define OMAP4_P1_MODE_TLL (1 << 16)
129#define OMAP4_P1_MODE_HSIC (3 << 16)
130#define OMAP4_P2_MODE_CLEAR (3 << 18)
131#define OMAP4_P2_MODE_TLL (1 << 18)
132#define OMAP4_P2_MODE_HSIC (3 << 18)
133
134#define OMAP_REV2_TLL_CHANNEL_COUNT 2
135
136#define OMAP_UHH_DEBUG_CSR (0x44)
137
138/* Values of UHH_REVISION - Note: these are not given in the TRM */
139#define OMAP_USBHS_REV1 0x00000010 /* OMAP3 */
140#define OMAP_USBHS_REV2 0x50700100 /* OMAP4 */
141
142#define is_omap_usbhs_rev1(x) (x->usbhs_rev == OMAP_USBHS_REV1)
143#define is_omap_usbhs_rev2(x) (x->usbhs_rev == OMAP_USBHS_REV2)
144
145#define is_ehci_phy_mode(x) (x == OMAP_EHCI_PORT_MODE_PHY)
146#define is_ehci_tll_mode(x) (x == OMAP_EHCI_PORT_MODE_TLL)
147#define is_ehci_hsic_mode(x) (x == OMAP_EHCI_PORT_MODE_HSIC)
148
149
150struct usbhs_hcd_omap {
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530151 struct clk *xclk60mhsp1_ck;
152 struct clk *xclk60mhsp2_ck;
153 struct clk *utmi_p1_fck;
154 struct clk *usbhost_p1_fck;
155 struct clk *usbtll_p1_fck;
156 struct clk *utmi_p2_fck;
157 struct clk *usbhost_p2_fck;
158 struct clk *usbtll_p2_fck;
159 struct clk *init_60m_fclk;
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530160 struct clk *ehci_logic_fck;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530161
162 void __iomem *uhh_base;
163 void __iomem *tll_base;
164
165 struct usbhs_omap_platform_data platdata;
166
167 u32 usbhs_rev;
168 spinlock_t lock;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530169};
170/*-------------------------------------------------------------------------*/
171
172const char usbhs_driver_name[] = USBHS_DRIVER_NAME;
Govindraj.Rcbb8c222012-02-15 12:27:50 +0530173static u64 usbhs_dmamask = DMA_BIT_MASK(32);
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530174
175/*-------------------------------------------------------------------------*/
176
177static inline void usbhs_write(void __iomem *base, u32 reg, u32 val)
178{
179 __raw_writel(val, base + reg);
180}
181
182static inline u32 usbhs_read(void __iomem *base, u32 reg)
183{
184 return __raw_readl(base + reg);
185}
186
187static inline void usbhs_writeb(void __iomem *base, u8 reg, u8 val)
188{
189 __raw_writeb(val, base + reg);
190}
191
192static inline u8 usbhs_readb(void __iomem *base, u8 reg)
193{
194 return __raw_readb(base + reg);
195}
196
197/*-------------------------------------------------------------------------*/
198
199static struct platform_device *omap_usbhs_alloc_child(const char *name,
200 struct resource *res, int num_resources, void *pdata,
201 size_t pdata_size, struct device *dev)
202{
203 struct platform_device *child;
204 int ret;
205
206 child = platform_device_alloc(name, 0);
207
208 if (!child) {
209 dev_err(dev, "platform_device_alloc %s failed\n", name);
210 goto err_end;
211 }
212
213 ret = platform_device_add_resources(child, res, num_resources);
214 if (ret) {
215 dev_err(dev, "platform_device_add_resources failed\n");
216 goto err_alloc;
217 }
218
219 ret = platform_device_add_data(child, pdata, pdata_size);
220 if (ret) {
221 dev_err(dev, "platform_device_add_data failed\n");
222 goto err_alloc;
223 }
224
225 child->dev.dma_mask = &usbhs_dmamask;
Govindraj.Rcbb8c222012-02-15 12:27:50 +0530226 dma_set_coherent_mask(&child->dev, DMA_BIT_MASK(32));
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530227 child->dev.parent = dev;
228
229 ret = platform_device_add(child);
230 if (ret) {
231 dev_err(dev, "platform_device_add failed\n");
232 goto err_alloc;
233 }
234
235 return child;
236
237err_alloc:
238 platform_device_put(child);
239
240err_end:
241 return NULL;
242}
243
244static int omap_usbhs_alloc_children(struct platform_device *pdev)
245{
246 struct device *dev = &pdev->dev;
247 struct usbhs_hcd_omap *omap;
248 struct ehci_hcd_omap_platform_data *ehci_data;
249 struct ohci_hcd_omap_platform_data *ohci_data;
250 struct platform_device *ehci;
251 struct platform_device *ohci;
252 struct resource *res;
253 struct resource resources[2];
254 int ret;
255
256 omap = platform_get_drvdata(pdev);
257 ehci_data = omap->platdata.ehci_data;
258 ohci_data = omap->platdata.ohci_data;
259
260 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ehci");
261 if (!res) {
262 dev_err(dev, "EHCI get resource IORESOURCE_MEM failed\n");
263 ret = -ENODEV;
264 goto err_end;
265 }
266 resources[0] = *res;
267
268 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ehci-irq");
269 if (!res) {
270 dev_err(dev, " EHCI get resource IORESOURCE_IRQ failed\n");
271 ret = -ENODEV;
272 goto err_end;
273 }
274 resources[1] = *res;
275
276 ehci = omap_usbhs_alloc_child(OMAP_EHCI_DEVICE, resources, 2, ehci_data,
277 sizeof(*ehci_data), dev);
278
279 if (!ehci) {
280 dev_err(dev, "omap_usbhs_alloc_child failed\n");
Axel Lind9107742011-05-14 14:15:36 +0800281 ret = -ENOMEM;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530282 goto err_end;
283 }
284
285 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ohci");
286 if (!res) {
287 dev_err(dev, "OHCI get resource IORESOURCE_MEM failed\n");
288 ret = -ENODEV;
289 goto err_ehci;
290 }
291 resources[0] = *res;
292
293 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ohci-irq");
294 if (!res) {
295 dev_err(dev, "OHCI get resource IORESOURCE_IRQ failed\n");
296 ret = -ENODEV;
297 goto err_ehci;
298 }
299 resources[1] = *res;
300
301 ohci = omap_usbhs_alloc_child(OMAP_OHCI_DEVICE, resources, 2, ohci_data,
302 sizeof(*ohci_data), dev);
303 if (!ohci) {
304 dev_err(dev, "omap_usbhs_alloc_child failed\n");
Axel Lind9107742011-05-14 14:15:36 +0800305 ret = -ENOMEM;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530306 goto err_ehci;
307 }
308
309 return 0;
310
311err_ehci:
Axel Lind9107742011-05-14 14:15:36 +0800312 platform_device_unregister(ehci);
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530313
314err_end:
315 return ret;
316}
317
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530318static bool is_ohci_port(enum usbhs_omap_port_mode pmode)
319{
320 switch (pmode) {
321 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
322 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
323 case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
324 case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
325 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
326 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
327 case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
328 case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
329 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
330 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
331 return true;
332
333 default:
334 return false;
335 }
336}
337
338/*
339 * convert the port-mode enum to a value we can use in the FSLSMODE
340 * field of USBTLL_CHANNEL_CONF
341 */
342static unsigned ohci_omap3_fslsmode(enum usbhs_omap_port_mode mode)
343{
344 switch (mode) {
345 case OMAP_USBHS_PORT_MODE_UNUSED:
346 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
347 return OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0;
348
349 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
350 return OMAP_TLL_FSLSMODE_6PIN_PHY_DP_DM;
351
352 case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
353 return OMAP_TLL_FSLSMODE_3PIN_PHY;
354
355 case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
356 return OMAP_TLL_FSLSMODE_4PIN_PHY;
357
358 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
359 return OMAP_TLL_FSLSMODE_6PIN_TLL_DAT_SE0;
360
361 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
362 return OMAP_TLL_FSLSMODE_6PIN_TLL_DP_DM;
363
364 case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
365 return OMAP_TLL_FSLSMODE_3PIN_TLL;
366
367 case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
368 return OMAP_TLL_FSLSMODE_4PIN_TLL;
369
370 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
371 return OMAP_TLL_FSLSMODE_2PIN_TLL_DAT_SE0;
372
373 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
374 return OMAP_TLL_FSLSMODE_2PIN_DAT_DP_DM;
375 default:
376 pr_warning("Invalid port mode, using default\n");
377 return OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0;
378 }
379}
380
381static void usbhs_omap_tll_init(struct device *dev, u8 tll_channel_count)
382{
383 struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
384 struct usbhs_omap_platform_data *pdata = dev->platform_data;
385 unsigned reg;
386 int i;
387
388 /* Program Common TLL register */
389 reg = usbhs_read(omap->tll_base, OMAP_TLL_SHARED_CONF);
390 reg |= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON
391 | OMAP_TLL_SHARED_CONF_USB_DIVRATION);
392 reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN;
393 reg &= ~OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN;
394
395 usbhs_write(omap->tll_base, OMAP_TLL_SHARED_CONF, reg);
396
397 /* Enable channels now */
398 for (i = 0; i < tll_channel_count; i++) {
399 reg = usbhs_read(omap->tll_base,
400 OMAP_TLL_CHANNEL_CONF(i));
401
402 if (is_ohci_port(pdata->port_mode[i])) {
403 reg |= ohci_omap3_fslsmode(pdata->port_mode[i])
404 << OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT;
405 reg |= OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS;
406 } else if (pdata->port_mode[i] == OMAP_EHCI_PORT_MODE_TLL) {
407
408 /* Disable AutoIdle, BitStuffing and use SDR Mode */
409 reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE
410 | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
411 | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE);
412
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530413 } else
414 continue;
415
416 reg |= OMAP_TLL_CHANNEL_CONF_CHANEN;
417 usbhs_write(omap->tll_base,
418 OMAP_TLL_CHANNEL_CONF(i), reg);
419
420 usbhs_writeb(omap->tll_base,
421 OMAP_TLL_ULPI_SCRATCH_REGISTER(i), 0xbe);
422 }
423}
424
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530425static int usbhs_runtime_resume(struct device *dev)
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530426{
427 struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
428 struct usbhs_omap_platform_data *pdata = &omap->platdata;
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530429 unsigned long flags;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530430
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530431 dev_dbg(dev, "usbhs_runtime_resume\n");
432
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530433 if (!pdata) {
434 dev_dbg(dev, "missing platform_data\n");
Axel Lind11536e2011-04-21 19:52:41 +0530435 return -ENODEV;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530436 }
437
Keshava Munegowda4dc2cce2012-07-16 19:01:09 +0530438 omap_tll_enable();
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530439 spin_lock_irqsave(&omap->lock, flags);
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530440
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530441 if (omap->ehci_logic_fck && !IS_ERR(omap->ehci_logic_fck))
442 clk_enable(omap->ehci_logic_fck);
443
444 if (is_ehci_tll_mode(pdata->port_mode[0])) {
445 clk_enable(omap->usbhost_p1_fck);
446 clk_enable(omap->usbtll_p1_fck);
447 }
448 if (is_ehci_tll_mode(pdata->port_mode[1])) {
449 clk_enable(omap->usbhost_p2_fck);
450 clk_enable(omap->usbtll_p2_fck);
451 }
452 clk_enable(omap->utmi_p1_fck);
453 clk_enable(omap->utmi_p2_fck);
454
455 spin_unlock_irqrestore(&omap->lock, flags);
456
457 return 0;
458}
459
460static int usbhs_runtime_suspend(struct device *dev)
461{
462 struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
463 struct usbhs_omap_platform_data *pdata = &omap->platdata;
464 unsigned long flags;
465
466 dev_dbg(dev, "usbhs_runtime_suspend\n");
467
468 if (!pdata) {
469 dev_dbg(dev, "missing platform_data\n");
470 return -ENODEV;
471 }
472
473 spin_lock_irqsave(&omap->lock, flags);
474
475 if (is_ehci_tll_mode(pdata->port_mode[0])) {
476 clk_disable(omap->usbhost_p1_fck);
477 clk_disable(omap->usbtll_p1_fck);
478 }
479 if (is_ehci_tll_mode(pdata->port_mode[1])) {
480 clk_disable(omap->usbhost_p2_fck);
481 clk_disable(omap->usbtll_p2_fck);
482 }
483 clk_disable(omap->utmi_p2_fck);
484 clk_disable(omap->utmi_p1_fck);
485
486 if (omap->ehci_logic_fck && !IS_ERR(omap->ehci_logic_fck))
487 clk_disable(omap->ehci_logic_fck);
488
489 spin_unlock_irqrestore(&omap->lock, flags);
Keshava Munegowda4dc2cce2012-07-16 19:01:09 +0530490 omap_tll_disable();
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530491
492 return 0;
493}
494
495static void omap_usbhs_init(struct device *dev)
496{
497 struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
498 struct usbhs_omap_platform_data *pdata = &omap->platdata;
499 unsigned long flags;
500 unsigned reg;
501
502 dev_dbg(dev, "starting TI HSUSB Controller\n");
503
504 pm_runtime_get_sync(dev);
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530505
Russ Dillc05995c2012-06-14 09:24:21 -0700506 if (pdata->ehci_data->phy_reset) {
507 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0]))
508 gpio_request_one(pdata->ehci_data->reset_gpio_port[0],
509 GPIOF_OUT_INIT_LOW, "USB1 PHY reset");
510
511 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1]))
512 gpio_request_one(pdata->ehci_data->reset_gpio_port[1],
513 GPIOF_OUT_INIT_LOW, "USB2 PHY reset");
514
515 /* Hold the PHY in RESET for enough time till DIR is high */
516 udelay(10);
517 }
518
519 spin_lock_irqsave(&omap->lock, flags);
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530520 omap->usbhs_rev = usbhs_read(omap->uhh_base, OMAP_UHH_REVISION);
521 dev_dbg(dev, "OMAP UHH_REVISION 0x%x\n", omap->usbhs_rev);
522
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530523 reg = usbhs_read(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
524 /* setup ULPI bypass and burst configurations */
525 reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
526 | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
527 | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
528 reg |= OMAP4_UHH_HOSTCONFIG_APP_START_CLK;
529 reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
530
531 if (is_omap_usbhs_rev1(omap)) {
532 if (pdata->port_mode[0] == OMAP_USBHS_PORT_MODE_UNUSED)
533 reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
534 if (pdata->port_mode[1] == OMAP_USBHS_PORT_MODE_UNUSED)
535 reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
536 if (pdata->port_mode[2] == OMAP_USBHS_PORT_MODE_UNUSED)
537 reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
538
539 /* Bypass the TLL module for PHY mode operation */
540 if (cpu_is_omap3430() && (omap_rev() <= OMAP3430_REV_ES2_1)) {
541 dev_dbg(dev, "OMAP3 ES version <= ES2.1\n");
542 if (is_ehci_phy_mode(pdata->port_mode[0]) ||
543 is_ehci_phy_mode(pdata->port_mode[1]) ||
544 is_ehci_phy_mode(pdata->port_mode[2]))
545 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
546 else
547 reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
548 } else {
549 dev_dbg(dev, "OMAP3 ES version > ES2.1\n");
550 if (is_ehci_phy_mode(pdata->port_mode[0]))
551 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
552 else
553 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
554 if (is_ehci_phy_mode(pdata->port_mode[1]))
555 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
556 else
557 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
558 if (is_ehci_phy_mode(pdata->port_mode[2]))
559 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
560 else
561 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
562 }
563 } else if (is_omap_usbhs_rev2(omap)) {
564 /* Clear port mode fields for PHY mode*/
565 reg &= ~OMAP4_P1_MODE_CLEAR;
566 reg &= ~OMAP4_P2_MODE_CLEAR;
567
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530568 if (is_ehci_tll_mode(pdata->port_mode[0]) ||
569 (is_ohci_port(pdata->port_mode[0])))
570 reg |= OMAP4_P1_MODE_TLL;
571 else if (is_ehci_hsic_mode(pdata->port_mode[0]))
572 reg |= OMAP4_P1_MODE_HSIC;
573
574 if (is_ehci_tll_mode(pdata->port_mode[1]) ||
575 (is_ohci_port(pdata->port_mode[1])))
576 reg |= OMAP4_P2_MODE_TLL;
577 else if (is_ehci_hsic_mode(pdata->port_mode[1]))
578 reg |= OMAP4_P2_MODE_HSIC;
579 }
580
581 usbhs_write(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
582 dev_dbg(dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
583
584 if (is_ehci_tll_mode(pdata->port_mode[0]) ||
585 is_ehci_tll_mode(pdata->port_mode[1]) ||
586 is_ehci_tll_mode(pdata->port_mode[2]) ||
587 (is_ohci_port(pdata->port_mode[0])) ||
588 (is_ohci_port(pdata->port_mode[1])) ||
589 (is_ohci_port(pdata->port_mode[2]))) {
590
591 /* Enable UTMI mode for required TLL channels */
592 if (is_omap_usbhs_rev2(omap))
593 usbhs_omap_tll_init(dev, OMAP_REV2_TLL_CHANNEL_COUNT);
594 else
595 usbhs_omap_tll_init(dev, OMAP_TLL_CHANNEL_COUNT);
596 }
597
Axel Lind11536e2011-04-21 19:52:41 +0530598 spin_unlock_irqrestore(&omap->lock, flags);
Russ Dillc05995c2012-06-14 09:24:21 -0700599
600 if (pdata->ehci_data->phy_reset) {
601 /* Hold the PHY in RESET for enough time till
602 * PHY is settled and ready
603 */
604 udelay(10);
605
606 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0]))
607 gpio_set_value_cansleep
608 (pdata->ehci_data->reset_gpio_port[0], 1);
609
610 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1]))
611 gpio_set_value_cansleep
612 (pdata->ehci_data->reset_gpio_port[1], 1);
613 }
614
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530615 pm_runtime_put_sync(dev);
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530616}
617
Russ Dillc05995c2012-06-14 09:24:21 -0700618static void omap_usbhs_deinit(struct device *dev)
619{
620 struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
621 struct usbhs_omap_platform_data *pdata = &omap->platdata;
622
623 if (pdata->ehci_data->phy_reset) {
624 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0]))
625 gpio_free(pdata->ehci_data->reset_gpio_port[0]);
626
627 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1]))
628 gpio_free(pdata->ehci_data->reset_gpio_port[1]);
629 }
630}
631
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530632
633/**
634 * usbhs_omap_probe - initialize TI-based HCDs
635 *
636 * Allocates basic resources for this USB host controller.
637 */
638static int __devinit usbhs_omap_probe(struct platform_device *pdev)
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530639{
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530640 struct device *dev = &pdev->dev;
641 struct usbhs_omap_platform_data *pdata = dev->platform_data;
642 struct usbhs_hcd_omap *omap;
643 struct resource *res;
644 int ret = 0;
645 int i;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530646
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530647 if (!pdata) {
648 dev_err(dev, "Missing platform data\n");
649 ret = -ENOMEM;
650 goto end_probe;
651 }
652
653 omap = kzalloc(sizeof(*omap), GFP_KERNEL);
654 if (!omap) {
655 dev_err(dev, "Memory allocation failed\n");
656 ret = -ENOMEM;
657 goto end_probe;
658 }
659
660 spin_lock_init(&omap->lock);
661
662 for (i = 0; i < OMAP3_HS_USB_PORTS; i++)
663 omap->platdata.port_mode[i] = pdata->port_mode[i];
664
665 omap->platdata.ehci_data = pdata->ehci_data;
666 omap->platdata.ohci_data = pdata->ohci_data;
667
668 pm_runtime_enable(dev);
669
670
671 for (i = 0; i < OMAP3_HS_USB_PORTS; i++)
672 if (is_ehci_phy_mode(i) || is_ehci_tll_mode(i) ||
673 is_ehci_hsic_mode(i)) {
674 omap->ehci_logic_fck = clk_get(dev, "ehci_logic_fck");
675 if (IS_ERR(omap->ehci_logic_fck)) {
676 ret = PTR_ERR(omap->ehci_logic_fck);
677 dev_warn(dev, "ehci_logic_fck failed:%d\n",
678 ret);
679 }
680 break;
681 }
682
683 omap->utmi_p1_fck = clk_get(dev, "utmi_p1_gfclk");
684 if (IS_ERR(omap->utmi_p1_fck)) {
685 ret = PTR_ERR(omap->utmi_p1_fck);
686 dev_err(dev, "utmi_p1_gfclk failed error:%d\n", ret);
687 goto err_end;
688 }
689
690 omap->xclk60mhsp1_ck = clk_get(dev, "xclk60mhsp1_ck");
691 if (IS_ERR(omap->xclk60mhsp1_ck)) {
692 ret = PTR_ERR(omap->xclk60mhsp1_ck);
693 dev_err(dev, "xclk60mhsp1_ck failed error:%d\n", ret);
694 goto err_utmi_p1_fck;
695 }
696
697 omap->utmi_p2_fck = clk_get(dev, "utmi_p2_gfclk");
698 if (IS_ERR(omap->utmi_p2_fck)) {
699 ret = PTR_ERR(omap->utmi_p2_fck);
700 dev_err(dev, "utmi_p2_gfclk failed error:%d\n", ret);
701 goto err_xclk60mhsp1_ck;
702 }
703
704 omap->xclk60mhsp2_ck = clk_get(dev, "xclk60mhsp2_ck");
705 if (IS_ERR(omap->xclk60mhsp2_ck)) {
706 ret = PTR_ERR(omap->xclk60mhsp2_ck);
707 dev_err(dev, "xclk60mhsp2_ck failed error:%d\n", ret);
708 goto err_utmi_p2_fck;
709 }
710
711 omap->usbhost_p1_fck = clk_get(dev, "usb_host_hs_utmi_p1_clk");
712 if (IS_ERR(omap->usbhost_p1_fck)) {
713 ret = PTR_ERR(omap->usbhost_p1_fck);
714 dev_err(dev, "usbhost_p1_fck failed error:%d\n", ret);
715 goto err_xclk60mhsp2_ck;
716 }
717
718 omap->usbtll_p1_fck = clk_get(dev, "usb_tll_hs_usb_ch0_clk");
719 if (IS_ERR(omap->usbtll_p1_fck)) {
720 ret = PTR_ERR(omap->usbtll_p1_fck);
721 dev_err(dev, "usbtll_p1_fck failed error:%d\n", ret);
722 goto err_usbhost_p1_fck;
723 }
724
725 omap->usbhost_p2_fck = clk_get(dev, "usb_host_hs_utmi_p2_clk");
726 if (IS_ERR(omap->usbhost_p2_fck)) {
727 ret = PTR_ERR(omap->usbhost_p2_fck);
728 dev_err(dev, "usbhost_p2_fck failed error:%d\n", ret);
729 goto err_usbtll_p1_fck;
730 }
731
732 omap->usbtll_p2_fck = clk_get(dev, "usb_tll_hs_usb_ch1_clk");
733 if (IS_ERR(omap->usbtll_p2_fck)) {
734 ret = PTR_ERR(omap->usbtll_p2_fck);
735 dev_err(dev, "usbtll_p2_fck failed error:%d\n", ret);
736 goto err_usbhost_p2_fck;
737 }
738
739 omap->init_60m_fclk = clk_get(dev, "init_60m_fclk");
740 if (IS_ERR(omap->init_60m_fclk)) {
741 ret = PTR_ERR(omap->init_60m_fclk);
742 dev_err(dev, "init_60m_fclk failed error:%d\n", ret);
743 goto err_usbtll_p2_fck;
744 }
745
746 if (is_ehci_phy_mode(pdata->port_mode[0])) {
747 /* for OMAP3 , the clk set paretn fails */
748 ret = clk_set_parent(omap->utmi_p1_fck,
749 omap->xclk60mhsp1_ck);
750 if (ret != 0)
751 dev_err(dev, "xclk60mhsp1_ck set parent"
752 "failed error:%d\n", ret);
753 } else if (is_ehci_tll_mode(pdata->port_mode[0])) {
754 ret = clk_set_parent(omap->utmi_p1_fck,
755 omap->init_60m_fclk);
756 if (ret != 0)
757 dev_err(dev, "init_60m_fclk set parent"
758 "failed error:%d\n", ret);
759 }
760
761 if (is_ehci_phy_mode(pdata->port_mode[1])) {
762 ret = clk_set_parent(omap->utmi_p2_fck,
763 omap->xclk60mhsp2_ck);
764 if (ret != 0)
765 dev_err(dev, "xclk60mhsp2_ck set parent"
766 "failed error:%d\n", ret);
767 } else if (is_ehci_tll_mode(pdata->port_mode[1])) {
768 ret = clk_set_parent(omap->utmi_p2_fck,
769 omap->init_60m_fclk);
770 if (ret != 0)
771 dev_err(dev, "init_60m_fclk set parent"
772 "failed error:%d\n", ret);
773 }
774
775 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "uhh");
776 if (!res) {
777 dev_err(dev, "UHH EHCI get resource failed\n");
778 ret = -ENODEV;
779 goto err_init_60m_fclk;
780 }
781
782 omap->uhh_base = ioremap(res->start, resource_size(res));
783 if (!omap->uhh_base) {
784 dev_err(dev, "UHH ioremap failed\n");
785 ret = -ENOMEM;
786 goto err_init_60m_fclk;
787 }
788
789 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tll");
790 if (!res) {
791 dev_err(dev, "UHH EHCI get resource failed\n");
792 ret = -ENODEV;
793 goto err_tll;
794 }
795
796 omap->tll_base = ioremap(res->start, resource_size(res));
797 if (!omap->tll_base) {
798 dev_err(dev, "TLL ioremap failed\n");
799 ret = -ENOMEM;
800 goto err_tll;
801 }
802
803 platform_set_drvdata(pdev, omap);
804
Govindraj.Rf0447a62012-02-15 15:53:34 +0530805 omap_usbhs_init(dev);
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530806 ret = omap_usbhs_alloc_children(pdev);
807 if (ret) {
808 dev_err(dev, "omap_usbhs_alloc_children failed\n");
809 goto err_alloc;
810 }
811
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530812 goto end_probe;
813
814err_alloc:
Russ Dillc05995c2012-06-14 09:24:21 -0700815 omap_usbhs_deinit(&pdev->dev);
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530816 iounmap(omap->tll_base);
817
818err_tll:
819 iounmap(omap->uhh_base);
820
821err_init_60m_fclk:
822 clk_put(omap->init_60m_fclk);
823
824err_usbtll_p2_fck:
825 clk_put(omap->usbtll_p2_fck);
826
827err_usbhost_p2_fck:
828 clk_put(omap->usbhost_p2_fck);
829
830err_usbtll_p1_fck:
831 clk_put(omap->usbtll_p1_fck);
832
833err_usbhost_p1_fck:
834 clk_put(omap->usbhost_p1_fck);
835
836err_xclk60mhsp2_ck:
837 clk_put(omap->xclk60mhsp2_ck);
838
839err_utmi_p2_fck:
840 clk_put(omap->utmi_p2_fck);
841
842err_xclk60mhsp1_ck:
843 clk_put(omap->xclk60mhsp1_ck);
844
845err_utmi_p1_fck:
846 clk_put(omap->utmi_p1_fck);
847
848err_end:
849 clk_put(omap->ehci_logic_fck);
850 pm_runtime_disable(dev);
851 kfree(omap);
852
853end_probe:
854 return ret;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530855}
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530856
857/**
858 * usbhs_omap_remove - shutdown processing for UHH & TLL HCDs
859 * @pdev: USB Host Controller being removed
860 *
861 * Reverses the effect of usbhs_omap_probe().
862 */
863static int __devexit usbhs_omap_remove(struct platform_device *pdev)
864{
865 struct usbhs_hcd_omap *omap = platform_get_drvdata(pdev);
866
Russ Dillc05995c2012-06-14 09:24:21 -0700867 omap_usbhs_deinit(&pdev->dev);
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530868 iounmap(omap->tll_base);
869 iounmap(omap->uhh_base);
870 clk_put(omap->init_60m_fclk);
871 clk_put(omap->usbtll_p2_fck);
872 clk_put(omap->usbhost_p2_fck);
873 clk_put(omap->usbtll_p1_fck);
874 clk_put(omap->usbhost_p1_fck);
875 clk_put(omap->xclk60mhsp2_ck);
876 clk_put(omap->utmi_p2_fck);
877 clk_put(omap->xclk60mhsp1_ck);
878 clk_put(omap->utmi_p1_fck);
879 clk_put(omap->ehci_logic_fck);
880 pm_runtime_disable(&pdev->dev);
881 kfree(omap);
882
883 return 0;
884}
885
886static const struct dev_pm_ops usbhsomap_dev_pm_ops = {
887 .runtime_suspend = usbhs_runtime_suspend,
888 .runtime_resume = usbhs_runtime_resume,
889};
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530890
891static struct platform_driver usbhs_omap_driver = {
892 .driver = {
893 .name = (char *)usbhs_driver_name,
894 .owner = THIS_MODULE,
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530895 .pm = &usbhsomap_dev_pm_ops,
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530896 },
897 .remove = __exit_p(usbhs_omap_remove),
898};
899
900MODULE_AUTHOR("Keshava Munegowda <keshava_mgowda@ti.com>");
901MODULE_ALIAS("platform:" USBHS_DRIVER_NAME);
902MODULE_LICENSE("GPL v2");
903MODULE_DESCRIPTION("usb host common core driver for omap EHCI and OHCI");
904
905static int __init omap_usbhs_drvinit(void)
906{
907 return platform_driver_probe(&usbhs_omap_driver, usbhs_omap_probe);
908}
909
910/*
911 * init before ehci and ohci drivers;
912 * The usbhs core driver should be initialized much before
913 * the omap ehci and ohci probe functions are called.
Keshava Munegowda4dc2cce2012-07-16 19:01:09 +0530914 * This usbhs core driver should be initialized after
915 * usb tll driver
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530916 */
Keshava Munegowda4dc2cce2012-07-16 19:01:09 +0530917fs_initcall_sync(omap_usbhs_drvinit);
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530918
919static void __exit omap_usbhs_drvexit(void)
920{
921 platform_driver_unregister(&usbhs_omap_driver);
922}
923module_exit(omap_usbhs_drvexit);