1 // SPDX-License-Identifier: GPL-2.0
3 * Cadence USBSS and USBSSP DRD Driver - host side
5 * Copyright (C) 2018-2019 Cadence Design Systems.
6 * Copyright (C) 2017-2018 NXP
12 #include <linux/platform_device.h>
13 #include <linux/slab.h>
16 #include "host-export.h"
17 #include <linux/usb/hcd.h>
18 #include "../host/xhci.h"
19 #include "../host/xhci-plat.h"
21 #define XECP_PORT_CAP_REG 0x8000
22 #define XECP_AUX_CTRL_REG1 0x8120
24 #define CFG_RXDET_P3_EN BIT(15)
25 #define LPM_2_STB_SWITCH_EN BIT(25)
27 static void xhci_cdns3_plat_start(struct usb_hcd *hcd)
29 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
33 value = readl(&xhci->op_regs->command);
34 value |= CMD_PM_INDEX;
35 writel(value, &xhci->op_regs->command);
38 value = readl(hcd->regs + XECP_AUX_CTRL_REG1);
39 value |= CFG_RXDET_P3_EN;
40 writel(value, hcd->regs + XECP_AUX_CTRL_REG1);
42 value = readl(hcd->regs + XECP_PORT_CAP_REG);
43 value |= LPM_2_STB_SWITCH_EN;
44 writel(value, hcd->regs + XECP_PORT_CAP_REG);
48 static int xhci_cdns3_resume_quirk(struct usb_hcd *hcd)
50 xhci_cdns3_plat_start(hcd);
54 static const struct xhci_plat_priv xhci_plat_cdns3_xhci = {
55 .quirks = XHCI_SKIP_PHY_INIT | XHCI_AVOID_BEI,
56 .plat_start = xhci_cdns3_plat_start,
57 .resume_quirk = xhci_cdns3_resume_quirk,
60 static int __cdns_host_init(struct cdns *cdns)
62 struct platform_device *xhci;
66 cdns_drd_host_on(cdns);
68 xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO);
70 dev_err(cdns->dev, "couldn't allocate xHCI device\n");
74 xhci->dev.parent = cdns->dev;
75 cdns->host_dev = xhci;
77 ret = platform_device_add_resources(xhci, cdns->xhci_res,
78 CDNS_XHCI_RESOURCES_NUM);
80 dev_err(cdns->dev, "couldn't add resources to xHCI device\n");
84 cdns->xhci_plat_data = kmemdup(&xhci_plat_cdns3_xhci,
85 sizeof(struct xhci_plat_priv), GFP_KERNEL);
86 if (!cdns->xhci_plat_data) {
91 if (cdns->pdata && (cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW))
92 cdns->xhci_plat_data->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW;
94 ret = platform_device_add_data(xhci, cdns->xhci_plat_data,
95 sizeof(struct xhci_plat_priv));
99 ret = platform_device_add(xhci);
101 dev_err(cdns->dev, "failed to register xHCI device\n");
105 /* Glue needs to access xHCI region register for Power management */
106 hcd = platform_get_drvdata(xhci);
108 cdns->xhci_regs = hcd->regs;
113 kfree(cdns->xhci_plat_data);
115 platform_device_put(xhci);
119 static void cdns_host_exit(struct cdns *cdns)
121 kfree(cdns->xhci_plat_data);
122 platform_device_unregister(cdns->host_dev);
123 cdns->host_dev = NULL;
124 cdns_drd_host_off(cdns);
127 int cdns_host_init(struct cdns *cdns)
129 struct cdns_role_driver *rdrv;
131 rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL);
135 rdrv->start = __cdns_host_init;
136 rdrv->stop = cdns_host_exit;
137 rdrv->state = CDNS_ROLE_STATE_INACTIVE;
140 cdns->roles[USB_ROLE_HOST] = rdrv;