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
8 * Authors: Peter Chen <peter.chen@nxp.com>
9 * Pawel Laszczak <pawell@cadence.com>
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"
22 * The XECP_PORT_CAP_REG and XECP_AUX_CTRL_REG1 exist only
23 * in Cadence USB3 dual-role controller, so it can't be used
24 * with Cadence CDNSP dual-role controller.
26 #define XECP_PORT_CAP_REG 0x8000
27 #define XECP_AUX_CTRL_REG1 0x8120
29 #define CFG_RXDET_P3_EN BIT(15)
30 #define LPM_2_STB_SWITCH_EN BIT(25)
32 static void xhci_cdns3_plat_start(struct usb_hcd
*hcd
)
34 struct xhci_hcd
*xhci
= hcd_to_xhci(hcd
);
38 value
= readl(&xhci
->op_regs
->command
);
39 value
|= CMD_PM_INDEX
;
40 writel(value
, &xhci
->op_regs
->command
);
43 value
= readl(hcd
->regs
+ XECP_AUX_CTRL_REG1
);
44 value
|= CFG_RXDET_P3_EN
;
45 writel(value
, hcd
->regs
+ XECP_AUX_CTRL_REG1
);
47 value
= readl(hcd
->regs
+ XECP_PORT_CAP_REG
);
48 value
|= LPM_2_STB_SWITCH_EN
;
49 writel(value
, hcd
->regs
+ XECP_PORT_CAP_REG
);
53 static int xhci_cdns3_resume_quirk(struct usb_hcd
*hcd
)
55 xhci_cdns3_plat_start(hcd
);
59 static const struct xhci_plat_priv xhci_plat_cdns3_xhci
= {
60 .quirks
= XHCI_SKIP_PHY_INIT
| XHCI_AVOID_BEI
,
61 .plat_start
= xhci_cdns3_plat_start
,
62 .resume_quirk
= xhci_cdns3_resume_quirk
,
65 static const struct xhci_plat_priv xhci_plat_cdnsp_xhci
= {
66 .quirks
= XHCI_CDNS_SCTX_QUIRK
,
69 static int __cdns_host_init(struct cdns
*cdns
)
71 struct platform_device
*xhci
;
75 cdns_drd_host_on(cdns
);
77 xhci
= platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO
);
79 dev_err(cdns
->dev
, "couldn't allocate xHCI device\n");
83 xhci
->dev
.parent
= cdns
->dev
;
84 cdns
->host_dev
= xhci
;
86 ret
= platform_device_add_resources(xhci
, cdns
->xhci_res
,
87 CDNS_XHCI_RESOURCES_NUM
);
89 dev_err(cdns
->dev
, "couldn't add resources to xHCI device\n");
93 if (cdns
->version
< CDNSP_CONTROLLER_V2
)
94 cdns
->xhci_plat_data
= kmemdup(&xhci_plat_cdns3_xhci
,
95 sizeof(struct xhci_plat_priv
), GFP_KERNEL
);
97 cdns
->xhci_plat_data
= kmemdup(&xhci_plat_cdnsp_xhci
,
98 sizeof(struct xhci_plat_priv
), GFP_KERNEL
);
100 if (!cdns
->xhci_plat_data
) {
105 if (cdns
->pdata
&& (cdns
->pdata
->quirks
& CDNS3_DEFAULT_PM_RUNTIME_ALLOW
))
106 cdns
->xhci_plat_data
->quirks
|= XHCI_DEFAULT_PM_RUNTIME_ALLOW
;
108 ret
= platform_device_add_data(xhci
, cdns
->xhci_plat_data
,
109 sizeof(struct xhci_plat_priv
));
113 ret
= platform_device_add(xhci
);
115 dev_err(cdns
->dev
, "failed to register xHCI device\n");
119 /* Glue needs to access xHCI region register for Power management */
120 hcd
= platform_get_drvdata(xhci
);
122 cdns
->xhci_regs
= hcd
->regs
;
127 kfree(cdns
->xhci_plat_data
);
129 platform_device_put(xhci
);
133 static void cdns_host_exit(struct cdns
*cdns
)
135 kfree(cdns
->xhci_plat_data
);
136 platform_device_unregister(cdns
->host_dev
);
137 cdns
->host_dev
= NULL
;
138 cdns_drd_host_off(cdns
);
141 int cdns_host_init(struct cdns
*cdns
)
143 struct cdns_role_driver
*rdrv
;
145 rdrv
= devm_kzalloc(cdns
->dev
, sizeof(*rdrv
), GFP_KERNEL
);
149 rdrv
->start
= __cdns_host_init
;
150 rdrv
->stop
= cdns_host_exit
;
151 rdrv
->state
= CDNS_ROLE_STATE_INACTIVE
;
154 cdns
->roles
[USB_ROLE_HOST
] = rdrv
;