1 // SPDX-License-Identifier: GPL-2.0-only
3 * omap-usb-host.c - The USBHS core driver for OMAP EHCI & OHCI
5 * Copyright (C) 2011-2013 Texas Instruments Incorporated - https://www.ti.com
6 * Author: Keshava Munegowda <keshava_mgowda@ti.com>
7 * Author: Roger Quadros <rogerq@ti.com>
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/types.h>
12 #include <linux/slab.h>
13 #include <linux/delay.h>
14 #include <linux/clk.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/gpio.h>
17 #include <linux/platform_device.h>
18 #include <linux/platform_data/usb-omap.h>
19 #include <linux/pm_runtime.h>
21 #include <linux/of_platform.h>
22 #include <linux/err.h>
26 #define USBHS_DRIVER_NAME "usbhs_omap"
27 #define OMAP_EHCI_DEVICE "ehci-omap"
28 #define OMAP_OHCI_DEVICE "ohci-omap3"
30 /* OMAP USBHOST Register addresses */
32 /* UHH Register Set */
33 #define OMAP_UHH_REVISION (0x00)
34 #define OMAP_UHH_SYSCONFIG (0x10)
35 #define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12)
36 #define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8)
37 #define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3)
38 #define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2)
39 #define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1)
40 #define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0)
42 #define OMAP_UHH_SYSSTATUS (0x14)
43 #define OMAP_UHH_HOSTCONFIG (0x40)
44 #define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0)
45 #define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0)
46 #define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11)
47 #define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12)
48 #define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2)
49 #define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3)
50 #define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4)
51 #define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5)
52 #define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8)
53 #define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9)
54 #define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10)
55 #define OMAP4_UHH_HOSTCONFIG_APP_START_CLK (1 << 31)
57 /* OMAP4-specific defines */
58 #define OMAP4_UHH_SYSCONFIG_IDLEMODE_CLEAR (3 << 2)
59 #define OMAP4_UHH_SYSCONFIG_NOIDLE (1 << 2)
60 #define OMAP4_UHH_SYSCONFIG_STDBYMODE_CLEAR (3 << 4)
61 #define OMAP4_UHH_SYSCONFIG_NOSTDBY (1 << 4)
62 #define OMAP4_UHH_SYSCONFIG_SOFTRESET (1 << 0)
64 #define OMAP4_P1_MODE_CLEAR (3 << 16)
65 #define OMAP4_P1_MODE_TLL (1 << 16)
66 #define OMAP4_P1_MODE_HSIC (3 << 16)
67 #define OMAP4_P2_MODE_CLEAR (3 << 18)
68 #define OMAP4_P2_MODE_TLL (1 << 18)
69 #define OMAP4_P2_MODE_HSIC (3 << 18)
71 #define OMAP_UHH_DEBUG_CSR (0x44)
73 /* Values of UHH_REVISION - Note: these are not given in the TRM */
74 #define OMAP_USBHS_REV1 0x00000010 /* OMAP3 */
75 #define OMAP_USBHS_REV2 0x50700100 /* OMAP4 */
77 #define is_omap_usbhs_rev1(x) (x->usbhs_rev == OMAP_USBHS_REV1)
78 #define is_omap_usbhs_rev2(x) (x->usbhs_rev == OMAP_USBHS_REV2)
80 #define is_ehci_phy_mode(x) (x == OMAP_EHCI_PORT_MODE_PHY)
81 #define is_ehci_tll_mode(x) (x == OMAP_EHCI_PORT_MODE_TLL)
82 #define is_ehci_hsic_mode(x) (x == OMAP_EHCI_PORT_MODE_HSIC)
85 struct usbhs_hcd_omap {
87 struct clk **utmi_clk;
88 struct clk **hsic60m_clk;
89 struct clk **hsic480m_clk;
91 struct clk *xclk60mhsp1_ck;
92 struct clk *xclk60mhsp2_ck;
93 struct clk *utmi_p1_gfclk;
94 struct clk *utmi_p2_gfclk;
95 struct clk *init_60m_fclk;
96 struct clk *ehci_logic_fck;
98 void __iomem *uhh_base;
100 struct usbhs_omap_platform_data *pdata;
104 /*-------------------------------------------------------------------------*/
106 static const char usbhs_driver_name[] = USBHS_DRIVER_NAME;
107 static u64 usbhs_dmamask = DMA_BIT_MASK(32);
109 /*-------------------------------------------------------------------------*/
111 static inline void usbhs_write(void __iomem *base, u32 reg, u32 val)
113 writel_relaxed(val, base + reg);
116 static inline u32 usbhs_read(void __iomem *base, u32 reg)
118 return readl_relaxed(base + reg);
121 /*-------------------------------------------------------------------------*/
124 * Map 'enum usbhs_omap_port_mode' found in <linux/platform_data/usb-omap.h>
125 * to the device tree binding portN-mode found in
126 * 'Documentation/devicetree/bindings/mfd/omap-usb-host.txt'
128 static const char * const port_modes[] = {
129 [OMAP_USBHS_PORT_MODE_UNUSED] = "",
130 [OMAP_EHCI_PORT_MODE_PHY] = "ehci-phy",
131 [OMAP_EHCI_PORT_MODE_TLL] = "ehci-tll",
132 [OMAP_EHCI_PORT_MODE_HSIC] = "ehci-hsic",
133 [OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0] = "ohci-phy-6pin-datse0",
134 [OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM] = "ohci-phy-6pin-dpdm",
135 [OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0] = "ohci-phy-3pin-datse0",
136 [OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM] = "ohci-phy-4pin-dpdm",
137 [OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0] = "ohci-tll-6pin-datse0",
138 [OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM] = "ohci-tll-6pin-dpdm",
139 [OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0] = "ohci-tll-3pin-datse0",
140 [OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM] = "ohci-tll-4pin-dpdm",
141 [OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0] = "ohci-tll-2pin-datse0",
142 [OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM] = "ohci-tll-2pin-dpdm",
145 static struct platform_device *omap_usbhs_alloc_child(const char *name,
146 struct resource *res, int num_resources, void *pdata,
147 size_t pdata_size, struct device *dev)
149 struct platform_device *child;
152 child = platform_device_alloc(name, 0);
155 dev_err(dev, "platform_device_alloc %s failed\n", name);
159 ret = platform_device_add_resources(child, res, num_resources);
161 dev_err(dev, "platform_device_add_resources failed\n");
165 ret = platform_device_add_data(child, pdata, pdata_size);
167 dev_err(dev, "platform_device_add_data failed\n");
171 child->dev.dma_mask = &usbhs_dmamask;
172 dma_set_coherent_mask(&child->dev, DMA_BIT_MASK(32));
173 child->dev.parent = dev;
175 ret = platform_device_add(child);
177 dev_err(dev, "platform_device_add failed\n");
184 platform_device_put(child);
190 static int omap_usbhs_alloc_children(struct platform_device *pdev)
192 struct device *dev = &pdev->dev;
193 struct usbhs_omap_platform_data *pdata = dev_get_platdata(dev);
194 struct platform_device *ehci;
195 struct platform_device *ohci;
196 struct resource *res;
197 struct resource resources[2];
200 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ehci");
202 dev_err(dev, "EHCI get resource IORESOURCE_MEM failed\n");
208 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ehci-irq");
210 dev_err(dev, " EHCI get resource IORESOURCE_IRQ failed\n");
216 ehci = omap_usbhs_alloc_child(OMAP_EHCI_DEVICE, resources, 2, pdata,
217 sizeof(*pdata), dev);
220 dev_err(dev, "omap_usbhs_alloc_child failed\n");
225 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ohci");
227 dev_err(dev, "OHCI get resource IORESOURCE_MEM failed\n");
233 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ohci-irq");
235 dev_err(dev, "OHCI get resource IORESOURCE_IRQ failed\n");
241 ohci = omap_usbhs_alloc_child(OMAP_OHCI_DEVICE, resources, 2, pdata,
242 sizeof(*pdata), dev);
244 dev_err(dev, "omap_usbhs_alloc_child failed\n");
252 platform_device_unregister(ehci);
258 static bool is_ohci_port(enum usbhs_omap_port_mode pmode)
261 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
262 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
263 case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
264 case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
265 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
266 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
267 case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
268 case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
269 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
270 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
278 static int usbhs_runtime_resume(struct device *dev)
280 struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
281 struct usbhs_omap_platform_data *pdata = omap->pdata;
284 dev_dbg(dev, "usbhs_runtime_resume\n");
286 omap_tll_enable(pdata);
288 if (!IS_ERR(omap->ehci_logic_fck))
289 clk_prepare_enable(omap->ehci_logic_fck);
291 for (i = 0; i < omap->nports; i++) {
292 switch (pdata->port_mode[i]) {
293 case OMAP_EHCI_PORT_MODE_HSIC:
294 if (!IS_ERR(omap->hsic60m_clk[i])) {
295 r = clk_prepare_enable(omap->hsic60m_clk[i]);
298 "Can't enable port %d hsic60m clk:%d\n",
303 if (!IS_ERR(omap->hsic480m_clk[i])) {
304 r = clk_prepare_enable(omap->hsic480m_clk[i]);
307 "Can't enable port %d hsic480m clk:%d\n",
311 fallthrough; /* as HSIC mode needs utmi_clk */
313 case OMAP_EHCI_PORT_MODE_TLL:
314 if (!IS_ERR(omap->utmi_clk[i])) {
315 r = clk_prepare_enable(omap->utmi_clk[i]);
318 "Can't enable port %d clk : %d\n",
331 static int usbhs_runtime_suspend(struct device *dev)
333 struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
334 struct usbhs_omap_platform_data *pdata = omap->pdata;
337 dev_dbg(dev, "usbhs_runtime_suspend\n");
339 for (i = 0; i < omap->nports; i++) {
340 switch (pdata->port_mode[i]) {
341 case OMAP_EHCI_PORT_MODE_HSIC:
342 if (!IS_ERR(omap->hsic60m_clk[i]))
343 clk_disable_unprepare(omap->hsic60m_clk[i]);
345 if (!IS_ERR(omap->hsic480m_clk[i]))
346 clk_disable_unprepare(omap->hsic480m_clk[i]);
347 fallthrough; /* as utmi_clks were used in HSIC mode */
349 case OMAP_EHCI_PORT_MODE_TLL:
350 if (!IS_ERR(omap->utmi_clk[i]))
351 clk_disable_unprepare(omap->utmi_clk[i]);
358 if (!IS_ERR(omap->ehci_logic_fck))
359 clk_disable_unprepare(omap->ehci_logic_fck);
361 omap_tll_disable(pdata);
366 static unsigned omap_usbhs_rev1_hostconfig(struct usbhs_hcd_omap *omap,
369 struct usbhs_omap_platform_data *pdata = omap->pdata;
372 for (i = 0; i < omap->nports; i++) {
373 switch (pdata->port_mode[i]) {
374 case OMAP_USBHS_PORT_MODE_UNUSED:
375 reg &= ~(OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS << i);
377 case OMAP_EHCI_PORT_MODE_PHY:
378 if (pdata->single_ulpi_bypass)
382 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
384 reg &= ~(OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS
388 if (pdata->single_ulpi_bypass)
392 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
394 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS
400 if (pdata->single_ulpi_bypass) {
401 /* bypass ULPI only if none of the ports use PHY mode */
402 reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
404 for (i = 0; i < omap->nports; i++) {
405 if (is_ehci_phy_mode(pdata->port_mode[i])) {
406 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
415 static unsigned omap_usbhs_rev2_hostconfig(struct usbhs_hcd_omap *omap,
418 struct usbhs_omap_platform_data *pdata = omap->pdata;
421 for (i = 0; i < omap->nports; i++) {
422 /* Clear port mode fields for PHY mode */
423 reg &= ~(OMAP4_P1_MODE_CLEAR << 2 * i);
425 if (is_ehci_tll_mode(pdata->port_mode[i]) ||
426 (is_ohci_port(pdata->port_mode[i])))
427 reg |= OMAP4_P1_MODE_TLL << 2 * i;
428 else if (is_ehci_hsic_mode(pdata->port_mode[i]))
429 reg |= OMAP4_P1_MODE_HSIC << 2 * i;
435 static void omap_usbhs_init(struct device *dev)
437 struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
440 dev_dbg(dev, "starting TI HSUSB Controller\n");
442 pm_runtime_get_sync(dev);
444 reg = usbhs_read(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
445 /* setup ULPI bypass and burst configurations */
446 reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
447 | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
448 | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
449 reg |= OMAP4_UHH_HOSTCONFIG_APP_START_CLK;
450 reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
452 switch (omap->usbhs_rev) {
453 case OMAP_USBHS_REV1:
454 reg = omap_usbhs_rev1_hostconfig(omap, reg);
457 case OMAP_USBHS_REV2:
458 reg = omap_usbhs_rev2_hostconfig(omap, reg);
461 default: /* newer revisions */
462 reg = omap_usbhs_rev2_hostconfig(omap, reg);
466 usbhs_write(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
467 dev_dbg(dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
469 pm_runtime_put_sync(dev);
472 static int usbhs_omap_get_dt_pdata(struct device *dev,
473 struct usbhs_omap_platform_data *pdata)
476 struct device_node *node = dev->of_node;
478 ret = of_property_read_u32(node, "num-ports", &pdata->nports);
482 if (pdata->nports > OMAP3_HS_USB_PORTS) {
483 dev_warn(dev, "Too many num_ports <%d> in device tree. Max %d\n",
484 pdata->nports, OMAP3_HS_USB_PORTS);
489 for (i = 0; i < OMAP3_HS_USB_PORTS; i++) {
493 pdata->port_mode[i] = OMAP_USBHS_PORT_MODE_UNUSED;
495 snprintf(prop, sizeof(prop), "port%d-mode", i + 1);
496 ret = of_property_read_string(node, prop, &mode);
500 /* get 'enum usbhs_omap_port_mode' from port mode string */
501 ret = match_string(port_modes, ARRAY_SIZE(port_modes), mode);
503 dev_warn(dev, "Invalid port%d-mode \"%s\" in device tree\n",
508 dev_dbg(dev, "port%d-mode: %s -> %d\n", i, mode, ret);
509 pdata->port_mode[i] = ret;
513 pdata->single_ulpi_bypass = of_property_read_bool(node,
514 "single-ulpi-bypass");
519 static const struct of_device_id usbhs_child_match_table[] = {
520 { .compatible = "ti,ehci-omap", },
521 { .compatible = "ti,ohci-omap3", },
526 * usbhs_omap_probe - initialize TI-based HCDs
528 * Allocates basic resources for this USB host controller.
530 * @pdev: Pointer to this device's platform device structure
532 static int usbhs_omap_probe(struct platform_device *pdev)
534 struct device *dev = &pdev->dev;
535 struct usbhs_omap_platform_data *pdata = dev_get_platdata(dev);
536 struct usbhs_hcd_omap *omap;
542 /* For DT boot we populate platform data from OF node */
543 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
547 ret = usbhs_omap_get_dt_pdata(dev, pdata);
551 dev->platform_data = pdata;
555 dev_err(dev, "Missing platform data\n");
559 if (pdata->nports > OMAP3_HS_USB_PORTS) {
560 dev_info(dev, "Too many num_ports <%d> in platform_data. Max %d\n",
561 pdata->nports, OMAP3_HS_USB_PORTS);
565 omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL);
567 dev_err(dev, "Memory allocation failed\n");
571 omap->uhh_base = devm_platform_ioremap_resource(pdev, 0);
572 if (IS_ERR(omap->uhh_base))
573 return PTR_ERR(omap->uhh_base);
577 /* Initialize the TLL subsystem */
578 omap_tll_init(pdata);
580 pm_runtime_enable(dev);
582 platform_set_drvdata(pdev, omap);
583 pm_runtime_get_sync(dev);
585 omap->usbhs_rev = usbhs_read(omap->uhh_base, OMAP_UHH_REVISION);
587 /* we need to call runtime suspend before we update omap->nports
588 * to prevent unbalanced clk_disable()
590 pm_runtime_put_sync(dev);
593 * If platform data contains nports then use that
594 * else make out number of ports from USBHS revision
597 omap->nports = pdata->nports;
599 switch (omap->usbhs_rev) {
600 case OMAP_USBHS_REV1:
603 case OMAP_USBHS_REV2:
607 omap->nports = OMAP3_HS_USB_PORTS;
609 "USB HOST Rev:0x%x not recognized, assuming %d ports\n",
610 omap->usbhs_rev, omap->nports);
613 pdata->nports = omap->nports;
616 i = sizeof(struct clk *) * omap->nports;
617 omap->utmi_clk = devm_kzalloc(dev, i, GFP_KERNEL);
618 omap->hsic480m_clk = devm_kzalloc(dev, i, GFP_KERNEL);
619 omap->hsic60m_clk = devm_kzalloc(dev, i, GFP_KERNEL);
621 if (!omap->utmi_clk || !omap->hsic480m_clk || !omap->hsic60m_clk) {
622 dev_err(dev, "Memory allocation failed\n");
627 /* Set all clocks as invalid to begin with */
628 omap->ehci_logic_fck = ERR_PTR(-ENODEV);
629 omap->init_60m_fclk = ERR_PTR(-ENODEV);
630 omap->utmi_p1_gfclk = ERR_PTR(-ENODEV);
631 omap->utmi_p2_gfclk = ERR_PTR(-ENODEV);
632 omap->xclk60mhsp1_ck = ERR_PTR(-ENODEV);
633 omap->xclk60mhsp2_ck = ERR_PTR(-ENODEV);
635 for (i = 0; i < omap->nports; i++) {
636 omap->utmi_clk[i] = ERR_PTR(-ENODEV);
637 omap->hsic480m_clk[i] = ERR_PTR(-ENODEV);
638 omap->hsic60m_clk[i] = ERR_PTR(-ENODEV);
641 /* for OMAP3 i.e. USBHS REV1 */
642 if (omap->usbhs_rev == OMAP_USBHS_REV1) {
643 need_logic_fck = false;
644 for (i = 0; i < omap->nports; i++) {
645 if (is_ehci_phy_mode(pdata->port_mode[i]) ||
646 is_ehci_tll_mode(pdata->port_mode[i]) ||
647 is_ehci_hsic_mode(pdata->port_mode[i]))
649 need_logic_fck |= true;
652 if (need_logic_fck) {
653 omap->ehci_logic_fck = devm_clk_get(dev,
655 if (IS_ERR(omap->ehci_logic_fck)) {
656 ret = PTR_ERR(omap->ehci_logic_fck);
657 dev_err(dev, "usbhost_120m_fck failed:%d\n",
665 /* for OMAP4+ i.e. USBHS REV2+ */
666 omap->utmi_p1_gfclk = devm_clk_get(dev, "utmi_p1_gfclk");
667 if (IS_ERR(omap->utmi_p1_gfclk)) {
668 ret = PTR_ERR(omap->utmi_p1_gfclk);
669 dev_err(dev, "utmi_p1_gfclk failed error:%d\n", ret);
673 omap->utmi_p2_gfclk = devm_clk_get(dev, "utmi_p2_gfclk");
674 if (IS_ERR(omap->utmi_p2_gfclk)) {
675 ret = PTR_ERR(omap->utmi_p2_gfclk);
676 dev_err(dev, "utmi_p2_gfclk failed error:%d\n", ret);
680 omap->xclk60mhsp1_ck = devm_clk_get(dev, "refclk_60m_ext_p1");
681 if (IS_ERR(omap->xclk60mhsp1_ck)) {
682 ret = PTR_ERR(omap->xclk60mhsp1_ck);
683 dev_err(dev, "refclk_60m_ext_p1 failed error:%d\n", ret);
687 omap->xclk60mhsp2_ck = devm_clk_get(dev, "refclk_60m_ext_p2");
688 if (IS_ERR(omap->xclk60mhsp2_ck)) {
689 ret = PTR_ERR(omap->xclk60mhsp2_ck);
690 dev_err(dev, "refclk_60m_ext_p2 failed error:%d\n", ret);
694 omap->init_60m_fclk = devm_clk_get(dev, "refclk_60m_int");
695 if (IS_ERR(omap->init_60m_fclk)) {
696 ret = PTR_ERR(omap->init_60m_fclk);
697 dev_err(dev, "refclk_60m_int failed error:%d\n", ret);
701 for (i = 0; i < omap->nports; i++) {
704 /* clock names are indexed from 1*/
705 snprintf(clkname, sizeof(clkname),
706 "usb_host_hs_utmi_p%d_clk", i + 1);
708 /* If a clock is not found we won't bail out as not all
709 * platforms have all clocks and we can function without
712 omap->utmi_clk[i] = devm_clk_get(dev, clkname);
713 if (IS_ERR(omap->utmi_clk[i])) {
714 ret = PTR_ERR(omap->utmi_clk[i]);
715 dev_err(dev, "Failed to get clock : %s : %d\n",
720 snprintf(clkname, sizeof(clkname),
721 "usb_host_hs_hsic480m_p%d_clk", i + 1);
722 omap->hsic480m_clk[i] = devm_clk_get(dev, clkname);
723 if (IS_ERR(omap->hsic480m_clk[i])) {
724 ret = PTR_ERR(omap->hsic480m_clk[i]);
725 dev_err(dev, "Failed to get clock : %s : %d\n",
730 snprintf(clkname, sizeof(clkname),
731 "usb_host_hs_hsic60m_p%d_clk", i + 1);
732 omap->hsic60m_clk[i] = devm_clk_get(dev, clkname);
733 if (IS_ERR(omap->hsic60m_clk[i])) {
734 ret = PTR_ERR(omap->hsic60m_clk[i]);
735 dev_err(dev, "Failed to get clock : %s : %d\n",
741 if (is_ehci_phy_mode(pdata->port_mode[0])) {
742 ret = clk_set_parent(omap->utmi_p1_gfclk,
743 omap->xclk60mhsp1_ck);
745 dev_err(dev, "xclk60mhsp1_ck set parent failed: %d\n",
749 } else if (is_ehci_tll_mode(pdata->port_mode[0])) {
750 ret = clk_set_parent(omap->utmi_p1_gfclk,
751 omap->init_60m_fclk);
753 dev_err(dev, "P0 init_60m_fclk set parent failed: %d\n",
759 if (is_ehci_phy_mode(pdata->port_mode[1])) {
760 ret = clk_set_parent(omap->utmi_p2_gfclk,
761 omap->xclk60mhsp2_ck);
763 dev_err(dev, "xclk60mhsp2_ck set parent failed: %d\n",
767 } else if (is_ehci_tll_mode(pdata->port_mode[1])) {
768 ret = clk_set_parent(omap->utmi_p2_gfclk,
769 omap->init_60m_fclk);
771 dev_err(dev, "P1 init_60m_fclk set parent failed: %d\n",
778 omap_usbhs_init(dev);
781 ret = of_platform_populate(dev->of_node,
782 usbhs_child_match_table, NULL, dev);
785 dev_err(dev, "Failed to create DT children: %d\n", ret);
790 ret = omap_usbhs_alloc_children(pdev);
792 dev_err(dev, "omap_usbhs_alloc_children failed: %d\n",
801 pm_runtime_disable(dev);
806 static int usbhs_omap_remove_child(struct device *dev, void *data)
808 dev_info(dev, "unregistering\n");
809 platform_device_unregister(to_platform_device(dev));
814 * usbhs_omap_remove - shutdown processing for UHH & TLL HCDs
815 * @pdev: USB Host Controller being removed
817 * Reverses the effect of usbhs_omap_probe().
819 static int usbhs_omap_remove(struct platform_device *pdev)
821 pm_runtime_disable(&pdev->dev);
823 /* remove children */
824 device_for_each_child(&pdev->dev, NULL, usbhs_omap_remove_child);
828 static const struct dev_pm_ops usbhsomap_dev_pm_ops = {
829 .runtime_suspend = usbhs_runtime_suspend,
830 .runtime_resume = usbhs_runtime_resume,
833 static const struct of_device_id usbhs_omap_dt_ids[] = {
834 { .compatible = "ti,usbhs-host" },
838 MODULE_DEVICE_TABLE(of, usbhs_omap_dt_ids);
841 static struct platform_driver usbhs_omap_driver = {
843 .name = usbhs_driver_name,
844 .pm = &usbhsomap_dev_pm_ops,
845 .of_match_table = usbhs_omap_dt_ids,
847 .probe = usbhs_omap_probe,
848 .remove = usbhs_omap_remove,
851 MODULE_AUTHOR("Keshava Munegowda <keshava_mgowda@ti.com>");
852 MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>");
853 MODULE_ALIAS("platform:" USBHS_DRIVER_NAME);
854 MODULE_DESCRIPTION("usb host common core driver for omap EHCI and OHCI");
856 static int omap_usbhs_drvinit(void)
858 return platform_driver_register(&usbhs_omap_driver);
862 * init before ehci and ohci drivers;
863 * The usbhs core driver should be initialized much before
864 * the omap ehci and ohci probe functions are called.
865 * This usbhs core driver should be initialized after
868 fs_initcall_sync(omap_usbhs_drvinit);
870 static void omap_usbhs_drvexit(void)
872 platform_driver_unregister(&usbhs_omap_driver);
874 module_exit(omap_usbhs_drvexit);