Skip to content

Commit 22d91ce

Browse files
pawellcdnsgregkh
authored andcommitted
usb: cdnsp: Add support for device-only configuration
This patch introduces support for the Cadence USBSSP (cdnsp) controller in hardware configurations where the Dual-Role Device (DRD) register block is not implemented or is inaccessible. In such cases, the driver cannot rely on the DRD logic to manage roles and must operate exclusively in a fixed peripheral/host mode. The change in BAR indexing (from BAR 2 to BAR 1) is a direct consequence of the 32-bit addressing used in this specific DRD-disabled hardware layout, compared to the 64-bit addressing used in DRD-enabled configurations. Tested on a PCI platform with a hardware configuration that lacks DRD support. Platform-side changes are included to support the PCI glue layer's property injection to handle this specific layout. Acked-by: Peter Chen <peter.chen@kernel.org> Acked-by: Bjorn Helgaas <bhelgaas@google.com> Signed-off-by: Pawel Laszczak <pawell@cadence.com> Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202605141023.18vWXyw3-lkp@intel.com/ Link: Closes: https://lore.kernel.org/oe-kbuild-all/202605141023.18vWXyw3-lkp@intel.com/ Link: https://patch.msgid.link/20260521-no_drd_config_v9-v9-2-2512cef10104@cadence.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a82fb62 commit 22d91ce

5 files changed

Lines changed: 106 additions & 24 deletions

File tree

drivers/usb/cdns3/cdns3-plat.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ static int cdns3_plat_probe(struct platform_device *pdev)
8181
if (cdns->pdata && cdns->pdata->override_apb_timeout)
8282
cdns->override_apb_timeout = cdns->pdata->override_apb_timeout;
8383

84+
if (device_is_compatible(dev, "cdns,cdnsp")) {
85+
cdns->no_drd = true;
86+
cdns->version = CDNSP_CONTROLLER_V2;
87+
dev_dbg(dev, "No DRD support\n");
88+
}
89+
8490
platform_set_drvdata(pdev, cdns);
8591

8692
ret = platform_get_irq_byname(pdev, "host");
@@ -113,21 +119,22 @@ static int cdns3_plat_probe(struct platform_device *pdev)
113119

114120
cdns->dev_regs = regs;
115121

116-
cdns->otg_irq = platform_get_irq_byname(pdev, "otg");
117-
if (cdns->otg_irq < 0)
118-
return dev_err_probe(dev, cdns->otg_irq,
119-
"Failed to get otg IRQ\n");
120-
121-
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "otg");
122-
if (!res) {
123-
dev_err(dev, "couldn't get otg resource\n");
124-
return -ENXIO;
122+
if (!cdns->no_drd) {
123+
cdns->otg_irq = platform_get_irq_byname(pdev, "otg");
124+
if (cdns->otg_irq < 0)
125+
return dev_err_probe(dev, cdns->otg_irq,
126+
"Failed to get otg IRQ\n");
127+
128+
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "otg");
129+
if (!res) {
130+
dev_err(dev, "couldn't get otg resource\n");
131+
return -ENXIO;
132+
}
133+
cdns->otg_res = *res;
125134
}
126135

127136
cdns->phyrst_a_enable = device_property_read_bool(dev, "cdns,phyrst-a-enable");
128137

129-
cdns->otg_res = *res;
130-
131138
cdns->wakeup_irq = platform_get_irq_byname_optional(pdev, "wakeup");
132139
if (cdns->wakeup_irq == -EPROBE_DEFER)
133140
return cdns->wakeup_irq;
@@ -341,6 +348,7 @@ static const struct dev_pm_ops cdns3_pm_ops = {
341348
#ifdef CONFIG_OF
342349
static const struct of_device_id of_cdns3_match[] = {
343350
{ .compatible = "cdns,usb3" },
351+
{ .compatible = "cdns,cdnsp" },
344352
{ },
345353
};
346354
MODULE_DEVICE_TABLE(of, of_cdns3_match);

drivers/usb/cdns3/cdnsp-pci.c

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
struct cdnsp_wrap {
2121
struct platform_device *plat_dev;
22+
struct property_entry prop[3];
2223
struct resource dev_res[6];
2324
int devfn;
2425
};
@@ -29,17 +30,23 @@ struct cdnsp_wrap {
2930
#define RES_HOST_ID 3
3031
#define RES_DEV_ID 4
3132
#define RES_DRD_ID 5
32-
33+
/* DRD PCI configuration - 64-bit addressing */
34+
/* First PCI function */
3335
#define PCI_BAR_HOST 0
34-
#define PCI_BAR_OTG 0
3536
#define PCI_BAR_DEV 2
37+
/* Second PCI function */
38+
#define PCI_BAR_OTG 0
39+
/* Device only PCI configuration - 32-bit addressing */
40+
/* First PCI function */
41+
#define PCI_BAR_ONLY_DEV 1
3642

3743
#define PCI_DEV_FN_HOST_DEVICE 0
3844
#define PCI_DEV_FN_OTG 1
3945

4046
#define PCI_DRIVER_NAME "cdns-pci-usbssp"
4147
#define PLAT_DRIVER_NAME "cdns-usb3"
4248

49+
#define PCI_DEVICE_ID_CDNS_UDC_USBSSP 0x0400
4350
#define CHICKEN_APB_TIMEOUT_VALUE 0x1C20
4451

4552
static struct pci_dev *cdnsp_get_second_fun(struct pci_dev *pdev)
@@ -65,6 +72,7 @@ static int cdnsp_pci_probe(struct pci_dev *pdev,
6572
struct cdnsp_wrap *wrap;
6673
struct resource *res;
6774
struct pci_dev *func;
75+
bool no_drd = false;
6876
int ret = 0;
6977

7078
/*
@@ -75,11 +83,14 @@ static int cdnsp_pci_probe(struct pci_dev *pdev,
7583
pdev->devfn != PCI_DEV_FN_OTG))
7684
return -EINVAL;
7785

86+
if (pdev->device == PCI_DEVICE_ID_CDNS_UDC_USBSSP)
87+
no_drd = true;
88+
7889
func = cdnsp_get_second_fun(pdev);
79-
if (!func)
90+
if (!func && !no_drd)
8091
return -EINVAL;
8192

82-
if (func->class == PCI_CLASS_SERIAL_USB_XHCI ||
93+
if ((func && func->class == PCI_CLASS_SERIAL_USB_XHCI) ||
8394
pdev->class == PCI_CLASS_SERIAL_USB_XHCI) {
8495
ret = -EINVAL;
8596
goto put_pci;
@@ -93,7 +104,7 @@ static int cdnsp_pci_probe(struct pci_dev *pdev,
93104

94105
pci_set_master(pdev);
95106

96-
if (pci_is_enabled(func)) {
107+
if (func && pci_is_enabled(func)) {
97108
wrap = pci_get_drvdata(func);
98109
} else {
99110
wrap = kzalloc_obj(*wrap);
@@ -106,10 +117,12 @@ static int cdnsp_pci_probe(struct pci_dev *pdev,
106117
res = wrap->dev_res;
107118

108119
if (pdev->devfn == PCI_DEV_FN_HOST_DEVICE) {
120+
int bar_dev = no_drd ? PCI_BAR_ONLY_DEV : PCI_BAR_DEV;
121+
109122
/* Function 0: host(BAR_0) + device(BAR_2). */
110123
dev_dbg(&pdev->dev, "Initialize Device resources\n");
111-
res[RES_DEV_ID].start = pci_resource_start(pdev, PCI_BAR_DEV);
112-
res[RES_DEV_ID].end = pci_resource_end(pdev, PCI_BAR_DEV);
124+
res[RES_DEV_ID].start = pci_resource_start(pdev, bar_dev);
125+
res[RES_DEV_ID].end = pci_resource_end(pdev, bar_dev);
113126
res[RES_DEV_ID].name = "dev";
114127
res[RES_DEV_ID].flags = IORESOURCE_MEM;
115128
dev_dbg(&pdev->dev, "USBSSP-DEV physical base addr: %pa\n",
@@ -145,9 +158,21 @@ static int cdnsp_pci_probe(struct pci_dev *pdev,
145158
wrap->dev_res[RES_IRQ_OTG_ID].flags = IORESOURCE_IRQ;
146159
}
147160

148-
if (pci_is_enabled(func)) {
161+
if (no_drd || pci_is_enabled(func)) {
162+
u8 idx = 0;
163+
149164
/* set up platform device info */
150165
pdata.override_apb_timeout = CHICKEN_APB_TIMEOUT_VALUE;
166+
167+
if (no_drd) {
168+
wrap->prop[idx++] = PROPERTY_ENTRY_STRING("compatible",
169+
"cdns,cdnsp");
170+
wrap->prop[idx++] = PROPERTY_ENTRY_STRING("dr_mode", "peripheral");
171+
} else {
172+
wrap->prop[idx++] = PROPERTY_ENTRY_STRING("dr_mode", "otg");
173+
wrap->prop[idx++] = PROPERTY_ENTRY_BOOL("usb-role-switch");
174+
}
175+
151176
memset(&plat_info, 0, sizeof(plat_info));
152177
plat_info.parent = &pdev->dev;
153178
plat_info.fwnode = pdev->dev.fwnode;
@@ -158,6 +183,7 @@ static int cdnsp_pci_probe(struct pci_dev *pdev,
158183
plat_info.dma_mask = pdev->dma_mask;
159184
plat_info.data = &pdata;
160185
plat_info.size_data = sizeof(pdata);
186+
plat_info.properties = wrap->prop;
161187
wrap->devfn = pdev->devfn;
162188
/* register platform device */
163189
wrap->plat_dev = platform_device_register_full(&plat_info);
@@ -185,13 +211,17 @@ static void cdnsp_pci_remove(struct pci_dev *pdev)
185211
if (wrap->devfn == pdev->devfn)
186212
platform_device_unregister(wrap->plat_dev);
187213

188-
if (!pci_is_enabled(func))
214+
if (!func || !pci_is_enabled(func))
189215
kfree(wrap);
190216

191217
pci_dev_put(func);
192218
}
193219

194220
static const struct pci_device_id cdnsp_pci_ids[] = {
221+
{ PCI_DEVICE(PCI_VENDOR_ID_CDNS, PCI_DEVICE_ID_CDNS_UDC_USBSSP),
222+
.class = PCI_CLASS_SERIAL_USB_DEVICE },
223+
{ PCI_DEVICE(PCI_VENDOR_ID_CDNS, PCI_DEVICE_ID_CDNS_UDC_USBSSP),
224+
.class = PCI_CLASS_SERIAL_USB_CDNS },
195225
{ PCI_DEVICE(PCI_VENDOR_ID_CDNS, PCI_DEVICE_ID_CDNS_USBSSP),
196226
.class = PCI_CLASS_SERIAL_USB_DEVICE },
197227
{ PCI_DEVICE(PCI_VENDOR_ID_CDNS, PCI_DEVICE_ID_CDNS_USBSSP),

drivers/usb/cdns3/core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ static void cdns_role_stop(struct cdns *cdns)
7070
static void cdns_exit_roles(struct cdns *cdns)
7171
{
7272
cdns_role_stop(cdns);
73-
cdns_drd_exit(cdns);
73+
if (!cdns->no_drd)
74+
cdns_drd_exit(cdns);
7475
}
7576

7677
/**

drivers/usb/cdns3/core.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ struct cdns3_platform_data {
8484
* value in CHICKEN_BITS_3 will be preserved.
8585
* @gadget_init: pointer to gadget initialization function
8686
* @host_init: pointer to host initialization function
87+
* @no_drd: DRD register block is inaccessible. The controller is hardwired to
88+
* single role (host or device) or the logic for role switching is
89+
* missing.
8790
*/
8891
struct cdns {
8992
struct device *dev;
@@ -124,6 +127,7 @@ struct cdns {
124127
u32 override_apb_timeout;
125128
int (*gadget_init)(struct cdns *cdns);
126129
int (*host_init)(struct cdns *cdns);
130+
bool no_drd;
127131
};
128132

129133
int cdns_hw_role_switch(struct cdns *cdns);

drivers/usb/cdns3/drd.c

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ int cdns_get_id(struct cdns *cdns)
8787
{
8888
int id;
8989

90+
if (cdns->no_drd)
91+
return 0;
92+
9093
id = readl(&cdns->otg_regs->sts) & OTGSTS_ID_VALUE;
9194
dev_dbg(cdns->dev, "OTG ID: %d", id);
9295

@@ -107,7 +110,7 @@ void cdns_clear_vbus(struct cdns *cdns)
107110
{
108111
u32 reg;
109112

110-
if (cdns->version != CDNSP_CONTROLLER_V2)
113+
if (cdns->version != CDNSP_CONTROLLER_V2 || cdns->no_drd)
111114
return;
112115

113116
reg = readl(&cdns->otg_cdnsp_regs->override);
@@ -120,7 +123,7 @@ void cdns_set_vbus(struct cdns *cdns)
120123
{
121124
u32 reg;
122125

123-
if (cdns->version != CDNSP_CONTROLLER_V2)
126+
if (cdns->version != CDNSP_CONTROLLER_V2 || cdns->no_drd)
124127
return;
125128

126129
reg = readl(&cdns->otg_cdnsp_regs->override);
@@ -179,7 +182,10 @@ static void cdns_otg_enable_irq(struct cdns *cdns)
179182
int cdns_drd_host_on(struct cdns *cdns)
180183
{
181184
u32 val, ready_bit;
182-
int ret;
185+
int ret = 0;
186+
187+
if (cdns->no_drd)
188+
goto phy_set;
183189

184190
/* Enable host mode. */
185191
writel(OTGCMD_HOST_BUS_REQ | OTGCMD_OTG_DIS,
@@ -197,6 +203,7 @@ int cdns_drd_host_on(struct cdns *cdns)
197203
if (ret)
198204
dev_err(cdns->dev, "timeout waiting for xhci_ready\n");
199205

206+
phy_set:
200207
phy_set_mode(cdns->usb2_phy, PHY_MODE_USB_HOST);
201208
phy_set_mode(cdns->usb3_phy, PHY_MODE_USB_HOST);
202209
return ret;
@@ -210,6 +217,9 @@ void cdns_drd_host_off(struct cdns *cdns)
210217
{
211218
u32 val;
212219

220+
if (cdns->no_drd)
221+
goto phy_set;
222+
213223
writel(OTGCMD_HOST_BUS_DROP | OTGCMD_DEV_BUS_DROP |
214224
OTGCMD_DEV_POWER_OFF | OTGCMD_HOST_POWER_OFF,
215225
&cdns->otg_regs->cmd);
@@ -218,6 +228,8 @@ void cdns_drd_host_off(struct cdns *cdns)
218228
readl_poll_timeout_atomic(&cdns->otg_regs->state, val,
219229
!(val & OTGSTATE_HOST_STATE_MASK),
220230
1, 2000000);
231+
232+
phy_set:
221233
phy_set_mode(cdns->usb2_phy, PHY_MODE_INVALID);
222234
phy_set_mode(cdns->usb3_phy, PHY_MODE_INVALID);
223235
}
@@ -234,6 +246,9 @@ int cdns_drd_gadget_on(struct cdns *cdns)
234246
u32 ready_bit;
235247
int ret, val;
236248

249+
if (cdns->no_drd)
250+
goto phy_set;
251+
237252
/* switch OTG core */
238253
writel(OTGCMD_DEV_BUS_REQ | reg, &cdns->otg_regs->cmd);
239254

@@ -251,6 +266,7 @@ int cdns_drd_gadget_on(struct cdns *cdns)
251266
return ret;
252267
}
253268

269+
phy_set:
254270
phy_set_mode(cdns->usb2_phy, PHY_MODE_USB_DEVICE);
255271
phy_set_mode(cdns->usb3_phy, PHY_MODE_USB_DEVICE);
256272
return 0;
@@ -265,6 +281,9 @@ void cdns_drd_gadget_off(struct cdns *cdns)
265281
{
266282
u32 val;
267283

284+
if (cdns->no_drd)
285+
goto phy_set;
286+
268287
/*
269288
* Driver should wait at least 10us after disabling Device
270289
* before turning-off Device (DEV_BUS_DROP).
@@ -277,6 +296,8 @@ void cdns_drd_gadget_off(struct cdns *cdns)
277296
readl_poll_timeout_atomic(&cdns->otg_regs->state, val,
278297
!(val & OTGSTATE_DEV_STATE_MASK),
279298
1, 2000000);
299+
300+
phy_set:
280301
phy_set_mode(cdns->usb2_phy, PHY_MODE_INVALID);
281302
phy_set_mode(cdns->usb3_phy, PHY_MODE_INVALID);
282303
}
@@ -392,6 +413,18 @@ int cdns_drd_init(struct cdns *cdns)
392413
u32 state, reg;
393414
int ret;
394415

416+
if (cdns->no_drd) {
417+
cdns->dr_mode = usb_get_dr_mode(cdns->dev);
418+
419+
if (cdns->dr_mode != USB_DR_MODE_HOST &&
420+
cdns->dr_mode != USB_DR_MODE_PERIPHERAL) {
421+
dev_err(cdns->dev, "Incorrect dr_mode\n");
422+
return -EINVAL;
423+
}
424+
425+
return 0;
426+
}
427+
395428
regs = devm_ioremap_resource(cdns->dev, &cdns->otg_res);
396429
if (IS_ERR(regs))
397430
return PTR_ERR(regs);
@@ -492,6 +525,9 @@ int cdns_drd_init(struct cdns *cdns)
492525

493526
int cdns_drd_exit(struct cdns *cdns)
494527
{
528+
if (cdns->no_drd)
529+
return 0;
530+
495531
cdns_otg_disable_irq(cdns);
496532

497533
return 0;
@@ -500,6 +536,9 @@ int cdns_drd_exit(struct cdns *cdns)
500536
/* Indicate the cdns3 core was power lost before */
501537
bool cdns_power_is_lost(struct cdns *cdns)
502538
{
539+
if (cdns->no_drd)
540+
return false;
541+
503542
if (cdns->version == CDNS3_CONTROLLER_V0) {
504543
if (!(readl(&cdns->otg_v0_regs->simulate) & BIT(0)))
505544
return true;

0 commit comments

Comments
 (0)