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>
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 int xhci_cdns3_suspend_quirk(struct usb_hcd *hcd);
28 static const struct xhci_plat_priv xhci_plat_cdns3_xhci = {
29 .quirks = XHCI_SKIP_PHY_INIT | XHCI_AVOID_BEI,
30 .suspend_quirk = xhci_cdns3_suspend_quirk,
33 static int __cdns_host_init(struct cdns *cdns)
35 struct platform_device *xhci;
39 cdns_drd_host_on(cdns);
41 xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO);
43 dev_err(cdns->dev, "couldn't allocate xHCI device\n");
47 xhci->dev.parent = cdns->dev;
48 cdns->host_dev = xhci;
50 ret = platform_device_add_resources(xhci, cdns->xhci_res,
51 CDNS_XHCI_RESOURCES_NUM);
53 dev_err(cdns->dev, "couldn't add resources to xHCI device\n");
57 cdns->xhci_plat_data = kmemdup(&xhci_plat_cdns3_xhci,
58 sizeof(struct xhci_plat_priv), GFP_KERNEL);
59 if (!cdns->xhci_plat_data) {
64 if (cdns->pdata && (cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW))
65 cdns->xhci_plat_data->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW;
67 ret = platform_device_add_data(xhci, cdns->xhci_plat_data,
68 sizeof(struct xhci_plat_priv));
72 ret = platform_device_add(xhci);
74 dev_err(cdns->dev, "failed to register xHCI device\n");
78 /* Glue needs to access xHCI region register for Power management */
79 hcd = platform_get_drvdata(xhci);
81 cdns->xhci_regs = hcd->regs;
86 kfree(cdns->xhci_plat_data);
88 platform_device_put(xhci);
92 static int xhci_cdns3_suspend_quirk(struct usb_hcd *hcd)
94 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
97 if (pm_runtime_status_suspended(hcd->self.controller))
100 /* set usbcmd.EU3S */
101 value = readl(&xhci->op_regs->command);
102 value |= CMD_PM_INDEX;
103 writel(value, &xhci->op_regs->command);
106 value = readl(hcd->regs + XECP_AUX_CTRL_REG1);
107 value |= CFG_RXDET_P3_EN;
108 writel(value, hcd->regs + XECP_AUX_CTRL_REG1);
110 value = readl(hcd->regs + XECP_PORT_CAP_REG);
111 value |= LPM_2_STB_SWITCH_EN;
112 writel(value, hcd->regs + XECP_PORT_CAP_REG);
118 static void cdns_host_exit(struct cdns *cdns)
120 kfree(cdns->xhci_plat_data);
121 platform_device_unregister(cdns->host_dev);
122 cdns->host_dev = NULL;
123 cdns_drd_host_off(cdns);
126 int cdns_host_init(struct cdns *cdns)
128 struct cdns_role_driver *rdrv;
130 rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL);
134 rdrv->start = __cdns_host_init;
135 rdrv->stop = cdns_host_exit;
136 rdrv->state = CDNS_ROLE_STATE_INACTIVE;
139 cdns->roles[USB_ROLE_HOST] = rdrv;