1 // SPDX-License-Identifier: GPL-2.0
3 * Cadence USBSS DRD Driver - host side
5 * Copyright (C) 2018-2019 Cadence Design Systems.
6 * Copyright (C) 2017-2018 NXP
12 #include <linux/platform_device.h>
15 #include "host-export.h"
16 #include <linux/usb/hcd.h>
17 #include "../host/xhci.h"
18 #include "../host/xhci-plat.h"
20 #define XECP_PORT_CAP_REG 0x8000
21 #define XECP_AUX_CTRL_REG1 0x8120
23 #define CFG_RXDET_P3_EN BIT(15)
24 #define LPM_2_STB_SWITCH_EN BIT(25)
26 static const struct xhci_plat_priv xhci_plat_cdns3_xhci = {
27 .quirks = XHCI_SKIP_PHY_INIT | XHCI_AVOID_BEI,
28 .suspend_quirk = xhci_cdns3_suspend_quirk,
31 static int __cdns3_host_init(struct cdns3 *cdns)
33 struct platform_device *xhci;
37 cdns3_drd_host_on(cdns);
39 xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO);
41 dev_err(cdns->dev, "couldn't allocate xHCI device\n");
45 xhci->dev.parent = cdns->dev;
46 cdns->host_dev = xhci;
48 ret = platform_device_add_resources(xhci, cdns->xhci_res,
49 CDNS3_XHCI_RESOURCES_NUM);
51 dev_err(cdns->dev, "couldn't add resources to xHCI device\n");
55 cdns->xhci_plat_data = kmemdup(&xhci_plat_cdns3_xhci,
56 sizeof(struct xhci_plat_priv), GFP_KERNEL);
57 if (!cdns->xhci_plat_data) {
62 if (cdns->pdata && (cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW))
63 cdns->xhci_plat_data->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW;
65 ret = platform_device_add_data(xhci, cdns->xhci_plat_data,
66 sizeof(struct xhci_plat_priv));
70 ret = platform_device_add(xhci);
72 dev_err(cdns->dev, "failed to register xHCI device\n");
76 /* Glue needs to access xHCI region register for Power management */
77 hcd = platform_get_drvdata(xhci);
79 cdns->xhci_regs = hcd->regs;
84 kfree(cdns->xhci_plat_data);
86 platform_device_put(xhci);
90 int xhci_cdns3_suspend_quirk(struct usb_hcd *hcd)
92 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
95 if (pm_runtime_status_suspended(hcd->self.controller))
99 value = readl(&xhci->op_regs->command);
100 value |= CMD_PM_INDEX;
101 writel(value, &xhci->op_regs->command);
104 value = readl(hcd->regs + XECP_AUX_CTRL_REG1);
105 value |= CFG_RXDET_P3_EN;
106 writel(value, hcd->regs + XECP_AUX_CTRL_REG1);
108 value = readl(hcd->regs + XECP_PORT_CAP_REG);
109 value |= LPM_2_STB_SWITCH_EN;
110 writel(value, hcd->regs + XECP_PORT_CAP_REG);
116 static void cdns3_host_exit(struct cdns3 *cdns)
118 kfree(cdns->xhci_plat_data);
119 platform_device_unregister(cdns->host_dev);
120 cdns->host_dev = NULL;
121 cdns3_drd_host_off(cdns);
124 int cdns3_host_init(struct cdns3 *cdns)
126 struct cdns3_role_driver *rdrv;
128 rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL);
132 rdrv->start = __cdns3_host_init;
133 rdrv->stop = cdns3_host_exit;
134 rdrv->state = CDNS3_ROLE_STATE_INACTIVE;
137 cdns->roles[USB_ROLE_HOST] = rdrv;