2 * ehci-omap.c - driver for USBHOST on OMAP3/4 processors
4 * Bus Glue for the EHCI controllers in OMAP3/4
5 * Tested on several OMAP3 boards, and OMAP4 Pandaboard
7 * Copyright (C) 2007-2011 Texas Instruments, Inc.
8 * Author: Vikram Pandita <vikram.pandita@ti.com>
9 * Author: Anand Gadiyar <gadiyar@ti.com>
10 * Author: Keshava Munegowda <keshava_mgowda@ti.com>
12 * Copyright (C) 2009 Nokia Corporation
13 * Contact: Felipe Balbi <felipe.balbi@nokia.com>
15 * Based on "ehci-fsl.c" and "ehci-au1xxx.c" ehci glue layers
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 * TODO (last updated Feb 27, 2010):
34 * - add suspend/resume
35 * - add HSIC and TLL support
36 * - convert to use hwmod and runtime PM
39 #include <linux/platform_device.h>
40 #include <linux/slab.h>
41 #include <linux/usb/ulpi.h>
43 #include <linux/regulator/consumer.h>
44 #include <linux/pm_runtime.h>
45 #include <linux/gpio.h>
46 #include <linux/clk.h>
48 /* EHCI Register Set */
49 #define EHCI_INSNREG04 (0xA0)
50 #define EHCI_INSNREG04_DISABLE_UNSUSPEND (1 << 5)
51 #define EHCI_INSNREG05_ULPI (0xA4)
52 #define EHCI_INSNREG05_ULPI_CONTROL_SHIFT 31
53 #define EHCI_INSNREG05_ULPI_PORTSEL_SHIFT 24
54 #define EHCI_INSNREG05_ULPI_OPSEL_SHIFT 22
55 #define EHCI_INSNREG05_ULPI_REGADD_SHIFT 16
56 #define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8
57 #define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0
60 static struct clk
*utmi_p1_fck
;
61 static struct clk
*utmi_p2_fck
;
62 static struct clk
*xclk60mhsp1_ck
;
63 static struct clk
*xclk60mhsp2_ck
;
64 static struct clk
*usbhost_p1_fck
;
65 static struct clk
*usbhost_p2_fck
;
66 static struct clk
*init_60m_fclk
;
68 /*-------------------------------------------------------------------------*/
70 static const struct hc_driver ehci_omap_hc_driver
;
73 static inline void ehci_write(void __iomem
*base
, u32 reg
, u32 val
)
75 __raw_writel(val
, base
+ reg
);
78 static inline u32
ehci_read(void __iomem
*base
, u32 reg
)
80 return __raw_readl(base
+ reg
);
83 /* Erratum i693 workaround sequence */
84 static void omap_ehci_erratum_i693(struct ehci_hcd
*ehci
)
88 /* Switch to the internal 60 MHz clock */
89 ret
= clk_set_parent(utmi_p1_fck
, init_60m_fclk
);
91 ehci_err(ehci
, "init_60m_fclk set parent"
92 "failed error:%d\n", ret
);
94 ret
= clk_set_parent(utmi_p2_fck
, init_60m_fclk
);
96 ehci_err(ehci
, "init_60m_fclk set parent"
97 "failed error:%d\n", ret
);
99 clk_enable(usbhost_p1_fck
);
100 clk_enable(usbhost_p2_fck
);
102 /* Wait 1ms and switch back to the external clock */
104 ret
= clk_set_parent(utmi_p1_fck
, xclk60mhsp1_ck
);
106 ehci_err(ehci
, "xclk60mhsp1_ck set parent"
107 "failed error:%d\n", ret
);
109 ret
= clk_set_parent(utmi_p2_fck
, xclk60mhsp2_ck
);
111 ehci_err(ehci
, "xclk60mhsp2_ck set parent"
112 "failed error:%d\n", ret
);
114 clk_disable(usbhost_p1_fck
);
115 clk_disable(usbhost_p2_fck
);
118 static void omap_ehci_soft_phy_reset(struct platform_device
*pdev
, u8 port
)
120 struct usb_hcd
*hcd
= dev_get_drvdata(&pdev
->dev
);
121 unsigned long timeout
= jiffies
+ msecs_to_jiffies(1000);
124 reg
= ULPI_FUNC_CTRL_RESET
125 /* FUNCTION_CTRL_SET register */
126 | (ULPI_SET(ULPI_FUNC_CTRL
) << EHCI_INSNREG05_ULPI_REGADD_SHIFT
)
128 | (2 << EHCI_INSNREG05_ULPI_OPSEL_SHIFT
)
130 | ((port
+ 1) << EHCI_INSNREG05_ULPI_PORTSEL_SHIFT
)
131 /* start ULPI access*/
132 | (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT
);
134 ehci_write(hcd
->regs
, EHCI_INSNREG05_ULPI
, reg
);
136 /* Wait for ULPI access completion */
137 while ((ehci_read(hcd
->regs
, EHCI_INSNREG05_ULPI
)
138 & (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT
))) {
141 if (time_after(jiffies
, timeout
)) {
142 dev_dbg(&pdev
->dev
, "phy reset operation timed out\n");
148 static int omap_ehci_hub_control(
157 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
158 u32 __iomem
*status_reg
= &ehci
->regs
->port_status
[
159 (wIndex
& 0xff) - 1];
164 spin_lock_irqsave(&ehci
->lock
, flags
);
166 if (typeReq
== SetPortFeature
&& wValue
== USB_PORT_FEAT_SUSPEND
) {
167 temp
= ehci_readl(ehci
, status_reg
);
168 if ((temp
& PORT_PE
) == 0 || (temp
& PORT_RESET
) != 0) {
173 temp
&= ~PORT_WKCONN_E
;
174 temp
|= PORT_WKDISC_E
| PORT_WKOC_E
;
175 ehci_writel(ehci
, temp
| PORT_SUSPEND
, status_reg
);
177 omap_ehci_erratum_i693(ehci
);
179 set_bit((wIndex
& 0xff) - 1, &ehci
->suspended_ports
);
183 spin_unlock_irqrestore(&ehci
->lock
, flags
);
185 /* Handle the hub control events here */
186 return ehci_hub_control(hcd
, typeReq
, wValue
, wIndex
, buf
, wLength
);
188 spin_unlock_irqrestore(&ehci
->lock
, flags
);
192 static void disable_put_regulator(
193 struct ehci_hcd_omap_platform_data
*pdata
)
197 for (i
= 0 ; i
< OMAP3_HS_USB_PORTS
; i
++) {
198 if (pdata
->regulator
[i
]) {
199 regulator_disable(pdata
->regulator
[i
]);
200 regulator_put(pdata
->regulator
[i
]);
205 /* configure so an HC device and id are always provided */
206 /* always called with process context; sleeping is OK */
209 * ehci_hcd_omap_probe - initialize TI-based HCDs
211 * Allocates basic resources for this USB host controller, and
212 * then invokes the start() method for the HCD associated with it
213 * through the hotplug entry's driver_data.
215 static int ehci_hcd_omap_probe(struct platform_device
*pdev
)
217 struct device
*dev
= &pdev
->dev
;
218 struct ehci_hcd_omap_platform_data
*pdata
= dev
->platform_data
;
219 struct resource
*res
;
222 struct ehci_hcd
*omap_ehci
;
232 dev_err(dev
, "Missing parent device\n");
236 irq
= platform_get_irq_byname(pdev
, "ehci-irq");
238 dev_err(dev
, "EHCI irq failed\n");
242 res
= platform_get_resource_byname(pdev
,
243 IORESOURCE_MEM
, "ehci");
245 dev_err(dev
, "UHH EHCI get resource failed\n");
249 regs
= ioremap(res
->start
, resource_size(res
));
251 dev_err(dev
, "UHH EHCI ioremap failed\n");
255 hcd
= usb_create_hcd(&ehci_omap_hc_driver
, dev
,
258 dev_err(dev
, "failed to create hcd with err %d\n", ret
);
263 hcd
->rsrc_start
= res
->start
;
264 hcd
->rsrc_len
= resource_size(res
);
267 /* get ehci regulator and enable */
268 for (i
= 0 ; i
< OMAP3_HS_USB_PORTS
; i
++) {
269 if (pdata
->port_mode
[i
] != OMAP_EHCI_PORT_MODE_PHY
) {
270 pdata
->regulator
[i
] = NULL
;
273 snprintf(supply
, sizeof(supply
), "hsusb%d", i
);
274 pdata
->regulator
[i
] = regulator_get(dev
, supply
);
275 if (IS_ERR(pdata
->regulator
[i
])) {
276 pdata
->regulator
[i
] = NULL
;
278 "failed to get ehci port%d regulator\n", i
);
280 regulator_enable(pdata
->regulator
[i
]);
284 if (pdata
->phy_reset
) {
285 if (gpio_is_valid(pdata
->reset_gpio_port
[0]))
286 gpio_request_one(pdata
->reset_gpio_port
[0],
287 GPIOF_OUT_INIT_LOW
, "USB1 PHY reset");
289 if (gpio_is_valid(pdata
->reset_gpio_port
[1]))
290 gpio_request_one(pdata
->reset_gpio_port
[1],
291 GPIOF_OUT_INIT_LOW
, "USB2 PHY reset");
293 /* Hold the PHY in RESET for enough time till DIR is high */
297 pm_runtime_enable(dev
);
298 pm_runtime_get_sync(dev
);
301 * An undocumented "feature" in the OMAP3 EHCI controller,
302 * causes suspended ports to be taken out of suspend when
303 * the USBCMD.Run/Stop bit is cleared (for example when
304 * we do ehci_bus_suspend).
305 * This breaks suspend-resume if the root-hub is allowed
306 * to suspend. Writing 1 to this undocumented register bit
307 * disables this feature and restores normal behavior.
309 ehci_write(regs
, EHCI_INSNREG04
,
310 EHCI_INSNREG04_DISABLE_UNSUSPEND
);
312 /* Soft reset the PHY using PHY reset command over ULPI */
313 if (pdata
->port_mode
[0] == OMAP_EHCI_PORT_MODE_PHY
)
314 omap_ehci_soft_phy_reset(pdev
, 0);
315 if (pdata
->port_mode
[1] == OMAP_EHCI_PORT_MODE_PHY
)
316 omap_ehci_soft_phy_reset(pdev
, 1);
318 omap_ehci
= hcd_to_ehci(hcd
);
319 omap_ehci
->sbrn
= 0x20;
321 /* we know this is the memory we want, no need to ioremap again */
322 omap_ehci
->caps
= hcd
->regs
;
323 omap_ehci
->regs
= hcd
->regs
324 + HC_LENGTH(ehci
, readl(&omap_ehci
->caps
->hc_capbase
));
326 dbg_hcs_params(omap_ehci
, "reset");
327 dbg_hcc_params(omap_ehci
, "reset");
329 /* cache this readonly data; minimize chip reads */
330 omap_ehci
->hcs_params
= readl(&omap_ehci
->caps
->hcs_params
);
332 ehci_reset(omap_ehci
);
334 if (pdata
->phy_reset
) {
335 /* Hold the PHY in RESET for enough time till
336 * PHY is settled and ready
340 if (gpio_is_valid(pdata
->reset_gpio_port
[0]))
341 gpio_set_value_cansleep(pdata
->reset_gpio_port
[0], 1);
343 if (gpio_is_valid(pdata
->reset_gpio_port
[1]))
344 gpio_set_value_cansleep(pdata
->reset_gpio_port
[1], 1);
347 ret
= usb_add_hcd(hcd
, irq
, IRQF_SHARED
);
349 dev_err(dev
, "failed to add hcd with err %d\n", ret
);
353 /* root ports should always stay powered */
354 ehci_port_power(omap_ehci
, 1);
357 utmi_p1_fck
= clk_get(dev
, "utmi_p1_gfclk");
358 if (IS_ERR(utmi_p1_fck
)) {
359 ret
= PTR_ERR(utmi_p1_fck
);
360 dev_err(dev
, "utmi_p1_gfclk failed error:%d\n", ret
);
364 xclk60mhsp1_ck
= clk_get(dev
, "xclk60mhsp1_ck");
365 if (IS_ERR(xclk60mhsp1_ck
)) {
366 ret
= PTR_ERR(xclk60mhsp1_ck
);
367 dev_err(dev
, "xclk60mhsp1_ck failed error:%d\n", ret
);
368 goto err_utmi_p1_fck
;
371 utmi_p2_fck
= clk_get(dev
, "utmi_p2_gfclk");
372 if (IS_ERR(utmi_p2_fck
)) {
373 ret
= PTR_ERR(utmi_p2_fck
);
374 dev_err(dev
, "utmi_p2_gfclk failed error:%d\n", ret
);
375 goto err_xclk60mhsp1_ck
;
378 xclk60mhsp2_ck
= clk_get(dev
, "xclk60mhsp2_ck");
379 if (IS_ERR(xclk60mhsp2_ck
)) {
380 ret
= PTR_ERR(xclk60mhsp2_ck
);
381 dev_err(dev
, "xclk60mhsp2_ck failed error:%d\n", ret
);
382 goto err_utmi_p2_fck
;
385 usbhost_p1_fck
= clk_get(dev
, "usb_host_hs_utmi_p1_clk");
386 if (IS_ERR(usbhost_p1_fck
)) {
387 ret
= PTR_ERR(usbhost_p1_fck
);
388 dev_err(dev
, "usbhost_p1_fck failed error:%d\n", ret
);
389 goto err_xclk60mhsp2_ck
;
392 usbhost_p2_fck
= clk_get(dev
, "usb_host_hs_utmi_p2_clk");
393 if (IS_ERR(usbhost_p2_fck
)) {
394 ret
= PTR_ERR(usbhost_p2_fck
);
395 dev_err(dev
, "usbhost_p2_fck failed error:%d\n", ret
);
396 goto err_usbhost_p1_fck
;
399 init_60m_fclk
= clk_get(dev
, "init_60m_fclk");
400 if (IS_ERR(init_60m_fclk
)) {
401 ret
= PTR_ERR(init_60m_fclk
);
402 dev_err(dev
, "init_60m_fclk failed error:%d\n", ret
);
403 goto err_usbhost_p2_fck
;
409 clk_put(usbhost_p2_fck
);
412 clk_put(usbhost_p1_fck
);
415 clk_put(xclk60mhsp2_ck
);
418 clk_put(utmi_p2_fck
);
421 clk_put(xclk60mhsp1_ck
);
424 clk_put(utmi_p1_fck
);
427 disable_put_regulator(pdata
);
428 pm_runtime_put_sync(dev
);
437 * ehci_hcd_omap_remove - shutdown processing for EHCI HCDs
438 * @pdev: USB Host Controller being removed
440 * Reverses the effect of usb_ehci_hcd_omap_probe(), first invoking
441 * the HCD's stop() method. It is always called from a thread
442 * context, normally "rmmod", "apmd", or something similar.
444 static int ehci_hcd_omap_remove(struct platform_device
*pdev
)
446 struct device
*dev
= &pdev
->dev
;
447 struct usb_hcd
*hcd
= dev_get_drvdata(dev
);
448 struct ehci_hcd_omap_platform_data
*pdata
= dev
->platform_data
;
451 disable_put_regulator(dev
->platform_data
);
455 clk_put(utmi_p1_fck
);
456 clk_put(utmi_p2_fck
);
457 clk_put(xclk60mhsp1_ck
);
458 clk_put(xclk60mhsp2_ck
);
459 clk_put(usbhost_p1_fck
);
460 clk_put(usbhost_p2_fck
);
461 clk_put(init_60m_fclk
);
463 pm_runtime_put_sync(dev
);
464 pm_runtime_disable(dev
);
466 if (pdata
->phy_reset
) {
467 if (gpio_is_valid(pdata
->reset_gpio_port
[0]))
468 gpio_free(pdata
->reset_gpio_port
[0]);
470 if (gpio_is_valid(pdata
->reset_gpio_port
[1]))
471 gpio_free(pdata
->reset_gpio_port
[1]);
476 static void ehci_hcd_omap_shutdown(struct platform_device
*pdev
)
478 struct usb_hcd
*hcd
= dev_get_drvdata(&pdev
->dev
);
480 if (hcd
->driver
->shutdown
)
481 hcd
->driver
->shutdown(hcd
);
484 static struct platform_driver ehci_hcd_omap_driver
= {
485 .probe
= ehci_hcd_omap_probe
,
486 .remove
= ehci_hcd_omap_remove
,
487 .shutdown
= ehci_hcd_omap_shutdown
,
488 /*.suspend = ehci_hcd_omap_suspend, */
489 /*.resume = ehci_hcd_omap_resume, */
495 /*-------------------------------------------------------------------------*/
497 static const struct hc_driver ehci_omap_hc_driver
= {
498 .description
= hcd_name
,
499 .product_desc
= "OMAP-EHCI Host Controller",
500 .hcd_priv_size
= sizeof(struct ehci_hcd
),
503 * generic hardware linkage
506 .flags
= HCD_MEMORY
| HCD_USB2
,
509 * basic lifecycle operations
514 .shutdown
= ehci_shutdown
,
517 * managing i/o requests and associated device resources
519 .urb_enqueue
= ehci_urb_enqueue
,
520 .urb_dequeue
= ehci_urb_dequeue
,
521 .endpoint_disable
= ehci_endpoint_disable
,
522 .endpoint_reset
= ehci_endpoint_reset
,
527 .get_frame_number
= ehci_get_frame
,
532 .hub_status_data
= ehci_hub_status_data
,
533 .hub_control
= omap_ehci_hub_control
,
534 .bus_suspend
= ehci_bus_suspend
,
535 .bus_resume
= ehci_bus_resume
,
537 .clear_tt_buffer_complete
= ehci_clear_tt_buffer_complete
,
540 MODULE_ALIAS("platform:omap-ehci");
541 MODULE_AUTHOR("Texas Instruments, Inc.");
542 MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>");