Skip to contentSkip to conversation

usb: cdns3: fixes for 5.4-rc

PATCH Superseded Roger Quadros 3 participants 9 messages Oct 7, 2019 – Oct 16, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover usb: cdns3: fixes for 5.4-rc

Hi,

Here are 2 fixes we found while testing the cdns3 driver on our platform.

The first one fixes a corner case where super-speed in host mode doesn't work if device was plugged before the cdns3 driver probes.

The second one fixes the case when gadget driver is limited to full-speed.

cheers,
-roger

Roger Quadros (2):
usb: cdns3: fix cdns3_core_init_role()
usb: cdns3: gadget: Fix full-speed mode

 drivers/usb/cdns3/core.c   | 20 +++++++++++++++++++-
 drivers/usb/cdns3/gadget.c |  1 +
 2 files changed, 20 insertions(+), 1 deletion(-)
Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
#6 lore raw

PATCH 2/2 usb: cdns3: gadget: Fix full-speed mode

We need to disable USB3 PHY for full-speed mode else gadget mode is broken.

---
 drivers/usb/cdns3/gadget.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/cdns3/gadget.c +1 -0
index 228cdc4ab886..157536753b8c 100644
@@ -2571,6 +2571,7 @@ static int cdns3_gadget_start(struct cdns3 *cdns)
 	switch (max_speed) {
 	case USB_SPEED_FULL:
 		writel(USB_CONF_SFORCE_FS, &priv_dev->regs->usb_conf);
+		writel(USB_CONF_USB3DIS, &priv_dev->regs->usb_conf);
 		break;
 	case USB_SPEED_HIGH:
 		writel(USB_CONF_USB3DIS, &priv_dev->regs->usb_conf);
Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
#1 lore raw

PATCH 1/2 usb: cdns3: fix cdns3_core_init_role()

In reply to Roger Quadros

At startup we should trigger the HW state machine
only if it is OTG mode. Otherwise we should just
start the respective role.

Initialize idle role by default. If we don't do this then cdns3_idle_role_stop() is not called when switching to host/device role and so lane switch mechanism doesn't work. This results to super-speed device not working in one orientation if it was plugged before driver probe.

---
 drivers/usb/cdns3/core.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/usb/cdns3/core.c +19 -1
index 06f1e105be4e..1109dc5a4c39 100644
@@ -160,10 +160,28 @@ static int cdns3_core_init_role(struct cdns3 *cdns)
 	if (ret)
 		goto err;
 
-	if (cdns->dr_mode != USB_DR_MODE_OTG) {
+	/* Initialize idle role to start with */
+	ret = cdns3_role_start(cdns, USB_ROLE_NONE);
+	if (ret)
+		goto err;
+
+	switch (cdns->dr_mode) {
+	case USB_DR_MODE_UNKNOWN:
+	case USB_DR_MODE_OTG:
 		ret = cdns3_hw_role_switch(cdns);
 		if (ret)
 			goto err;
+		break;
+	case USB_DR_MODE_PERIPHERAL:
+		ret = cdns3_role_start(cdns, USB_ROLE_DEVICE);
+		if (ret)
+			goto err;
+		break;
+	case USB_DR_MODE_HOST:
+		ret = cdns3_role_start(cdns, USB_ROLE_HOST);
+		if (ret)
+			goto err;
+		break;
 	}
 
 	return ret;
Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] usb: cdns3: gadget: Fix full-speed mode

In reply to Roger Quadros
Quoted 14 lines · Roger Quadros

We need to disable USB3 PHY for full-speed mode else gadget mode is broken.

---
 drivers/usb/cdns3/gadget.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/cdns3/gadget.c +0 -0
index 228cdc4ab886..157536753b8c 100644

drivers/usb/cdns3/gadget.c static int cdns3_gadget_start(struct cdns3 *cdns) · line 2577

Quoted 7 lines
drivers/usb/cdns3/gadget.c +1 -0
@@ -2571,6 +2571,7 @@ static int cdns3_gadget_start(struct cdns3 *cdns)
 	switch (max_speed) {
 	case USB_SPEED_FULL:
 		writel(USB_CONF_SFORCE_FS, &priv_dev->regs->usb_conf);
+		writel(USB_CONF_USB3DIS, &priv_dev->regs->usb_conf);
 		break;
 	case USB_SPEED_HIGH:
 		writel(USB_CONF_USB3DIS, &priv_dev->regs->usb_conf);
Signature · 2 lines
Thanks,
Peter Chen
maintainer Reviewed-by Tested-by on v1 1/2
#2 lore raw

RE: [PATCH 1/2] usb: cdns3: fix cdns3_core_init_role()

In reply to Roger Quadros

Hi Roger

Quoted 23 lines

At startup we should trigger the HW state machine
only if it is OTG mode. Otherwise we should just
start the respective role.

Initialize idle role by default. If we don't do this then cdns3_idle_role_stop() is not called when switching to host/device role and so lane switch mechanism doesn't work. This results to super-speed device not working in one orientation if it was plugged before driver probe.

---
drivers/usb/cdns3/core.c | 20 +++++++++++++++++++-

1 file changed, 19 insertions(+), 1 deletion(-)
drivers/usb/cdns3/core.c +0 -0
index 06f1e105be4e..1109dc5a4c39 100644
@@ -160,10 +160,28 @@ static int cdns3_core_init_role(struct cdns3 *cdns)
 	if (ret)

drivers/usb/cdns3/core.c static int cdns3_core_init_role(struct cdns3 *cdns) · line 169

Quoted 10 lines
drivers/usb/cdns3/core.c +7 -1
 		goto err;
 
-	if (cdns->dr_mode != USB_DR_MODE_OTG) {
+	/* Initialize idle role to start with */
+	ret = cdns3_role_start(cdns, USB_ROLE_NONE);
+	if (ret)
+		goto err;
+
+	switch (cdns->dr_mode) {
+	case USB_DR_MODE_UNKNOWN:

One note in this place. USB_DR_MODE_UNKNOWN is not possible in this place. If cdns->dr_mode will be USB_DR_MODE_UNKNOWN then driver returns -EINVAL some line before after returning form cdns3_drd_update_mode and in consequence it jump to err label.

Maybe for better readability it this condition should be treated here also as error.

Quoted 8 lines
drivers/usb/cdns3/core.c +5 -0
+	case USB_DR_MODE_OTG:
 		ret = cdns3_hw_role_switch(cdns);
 		if (ret)
 			goto err;
+		break;
+	case USB_DR_MODE_PERIPHERAL:
+		ret = cdns3_role_start(cdns, USB_ROLE_DEVICE);
+		if (ret)

drivers/usb/cdns3/core.c static int cdns3_core_init_role(struct cdns3 *cdns) · line 187

Quoted 10 lines
drivers/usb/cdns3/core.c +7 -0
+			goto err;
+		break;
+	case USB_DR_MODE_HOST:
+		ret = cdns3_role_start(cdns, USB_ROLE_HOST);
+		if (ret)
+			goto err;
+		break;
 	}
 
 	return ret;
Quoted 3 lines

--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

--
Regards,
Pawel

maintainer Reviewed-by
#8 lore raw

RE: [PATCH 2/2] usb: cdns3: gadget: Fix full-speed mode

In reply to Peter Chen
Quoted 10 lines · Roger Quadros
Quoted 9 lines

We need to disable USB3 PHY for full-speed mode else gadget mode is broken.

---
 drivers/usb/cdns3/gadget.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 14 lines

drivers/usb/cdns3/gadget.c static int cdns3_gadget_start(struct cdns3 *cdns) · line 2577

Quoted 12 lines
drivers/usb/cdns3/gadget.c +1 -0
index 228cdc4ab886..157536753b8c 100644
@@ -2571,6 +2571,7 @@ static int cdns3_gadget_start(struct cdns3 *cdns)
 	switch (max_speed) {
 	case USB_SPEED_FULL:
 		writel(USB_CONF_SFORCE_FS, &priv_dev->regs->usb_conf);
+		writel(USB_CONF_USB3DIS, &priv_dev->regs->usb_conf);
 		break;
 	case USB_SPEED_HIGH:
 		writel(USB_CONF_USB3DIS, &priv_dev->regs->usb_conf);
Quoted 5 lines

--

Thanks,
Peter Chen

Regards,
Pawell

#3 lore raw

Re: [PATCH 1/2] usb: cdns3: fix cdns3_core_init_role()

In reply to Pawel Laszczak

Hi Pawel,

Quoted 27 lines · Pawel Laszczak

Hi Roger

Quoted 25 lines

At startup we should trigger the HW state machine only if it is OTG mode. Otherwise we should just start the respective role.

Initialize idle role by default. If we don't do this then cdns3_idle_role_stop() is not called when switching to host/device role and so lane switch mechanism doesn't work. This results to super-speed device not working in one orientation if it was plugged before driver probe.

---
drivers/usb/cdns3/core.c | 20 +++++++++++++++++++-

1 file changed, 19 insertions(+), 1 deletion(-)
drivers/usb/cdns3/core.c +0 -0
index 06f1e105be4e..1109dc5a4c39 100644
@@ -160,10 +160,28 @@ static int cdns3_core_init_role(struct cdns3 *cdns)
 	if (ret)
 		goto err;
 
Quoted 11 lines

drivers/usb/cdns3/core.c static int cdns3_core_init_role(struct cdns3 *cdns) · line 169

Quoted 8 lines
drivers/usb/cdns3/core.c +7 -1
-	if (cdns->dr_mode != USB_DR_MODE_OTG) {
+	/* Initialize idle role to start with */
+	ret = cdns3_role_start(cdns, USB_ROLE_NONE);
+	if (ret)
+		goto err;
+
+	switch (cdns->dr_mode) {
+	case USB_DR_MODE_UNKNOWN:

One note in this place. USB_DR_MODE_UNKNOWN is not possible in this place. If cdns->dr_mode will be USB_DR_MODE_UNKNOWN then driver returns -EINVAL

At which place? I could not find.

Quoted 31 lines

some line before after returning form cdns3_drd_update_mode and in consequence it jump to err label.

Maybe for better readability it this condition should be treated here also as error.

Quoted 8 lines
drivers/usb/cdns3/core.c +5 -0
+	case USB_DR_MODE_OTG:
 		ret = cdns3_hw_role_switch(cdns);
 		if (ret)
 			goto err;
+		break;
+	case USB_DR_MODE_PERIPHERAL:
+		ret = cdns3_role_start(cdns, USB_ROLE_DEVICE);
+		if (ret)

drivers/usb/cdns3/core.c static int cdns3_core_init_role(struct cdns3 *cdns) · line 187

Quoted 10 lines
drivers/usb/cdns3/core.c +7 -0
+			goto err;
+		break;
+	case USB_DR_MODE_HOST:
+		ret = cdns3_role_start(cdns, USB_ROLE_HOST);
+		if (ret)
+			goto err;
+		break;
 	}
 
 	return ret;

--
Regards,
Pawel

Signature · 4 lines
cheers,
-roger
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
maintainer
#4 lore raw

RE: [PATCH 1/2] usb: cdns3: fix cdns3_core_init_role()

Quoted 44 lines

Hi Pawel,

Quoted 27 lines · Pawel Laszczak

Hi Roger

Quoted 25 lines

At startup we should trigger the HW state machine only if it is OTG mode. Otherwise we should just start the respective role.

Initialize idle role by default. If we don't do this then cdns3_idle_role_stop() is not called when switching to host/device role and so lane switch mechanism doesn't work. This results to super-speed device not working in one orientation if it was plugged before driver probe.

---
drivers/usb/cdns3/core.c | 20 +++++++++++++++++++-

1 file changed, 19 insertions(+), 1 deletion(-)
drivers/usb/cdns3/core.c +0 -0
index 06f1e105be4e..1109dc5a4c39 100644
@@ -160,10 +160,28 @@ static int cdns3_core_init_role(struct cdns3 *cdns)
 	if (ret)
 		goto err;
 
Quoted 11 lines

drivers/usb/cdns3/core.c static int cdns3_core_init_role(struct cdns3 *cdns) · line 169

Quoted 8 lines
drivers/usb/cdns3/core.c +7 -1
-	if (cdns->dr_mode != USB_DR_MODE_OTG) {
+	/* Initialize idle role to start with */
+	ret = cdns3_role_start(cdns, USB_ROLE_NONE);
+	if (ret)
+		goto err;
+
+	switch (cdns->dr_mode) {
+	case USB_DR_MODE_UNKNOWN:

One note in this place. USB_DR_MODE_UNKNOWN is not possible in this place. If cdns->dr_mode will be USB_DR_MODE_UNKNOWN then driver returns -EINVAL

Quoted 1 line

At which place? I could not find.

In this patch we can't see this line:
https://elixir.bootlin.com/linux/v5.4-rc2/source/drivers/usb/cdns3/core.c#L159
There is called cdns3_drd_update_mode(cdns);

int cdns3_drd_update_mode(struct cdns3 *cdns)

{
	int ret = 0;

	switch (cdns->dr_mode) {
	case USB_DR_MODE_PERIPHERAL:
		ret = cdns3_set_mode(cdns, USB_DR_MODE_PERIPHERAL);
		break;
	case USB_DR_MODE_HOST:
		ret = cdns3_set_mode(cdns, USB_DR_MODE_HOST);
		break;
	case USB_DR_MODE_OTG:
		ret = cdns3_init_otg_mode(cdns);
		break;
	default:
		dev_err(cdns->dev, "Unsupported mode of operation %d\n",
			cdns->dr_mode);
		return -EINVAL;
	}

	return ret;
}

After calling cdns3_drd_update_mode we have 2 first lines from this patch

	if (ret)
		goto err;

Pawel

Quoted 38 lines
Quoted 23 lines

some line before after returning form cdns3_drd_update_mode and in consequence it jump to err label.

Maybe for better readability it this condition should be treated here also as error.

Quoted 17 lines
drivers/usb/cdns3/core.c +12 -0
+	case USB_DR_MODE_OTG:
 		ret = cdns3_hw_role_switch(cdns);
 		if (ret)
 			goto err;
+		break;
+	case USB_DR_MODE_PERIPHERAL:
+		ret = cdns3_role_start(cdns, USB_ROLE_DEVICE);
+		if (ret)
+			goto err;
+		break;
+	case USB_DR_MODE_HOST:
+		ret = cdns3_role_start(cdns, USB_ROLE_HOST);
+		if (ret)
+			goto err;
+		break;
 	}
 
Quoted 9 lines

drivers/usb/cdns3/core.c static int cdns3_core_init_role(struct cdns3 *cdns) · line 187

Quoted 1 line
drivers/usb/cdns3/core.c +0 -0
 	return ret;

--
Regards,
Pawel

--
cheers,
-roger
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

#5 lore raw

Re: [PATCH 1/2] usb: cdns3: fix cdns3_core_init_role()

Quoted 73 lines · Pawel Laszczak
Quoted 44 lines

Hi Pawel,

Quoted 27 lines · Pawel Laszczak

Hi Roger

Quoted 25 lines

At startup we should trigger the HW state machine only if it is OTG mode. Otherwise we should just start the respective role.

Initialize idle role by default. If we don't do this then cdns3_idle_role_stop() is not called when switching to host/device role and so lane switch mechanism doesn't work. This results to super-speed device not working in one orientation if it was plugged before driver probe.

---
drivers/usb/cdns3/core.c | 20 +++++++++++++++++++-

1 file changed, 19 insertions(+), 1 deletion(-)
drivers/usb/cdns3/core.c +0 -0
index 06f1e105be4e..1109dc5a4c39 100644
@@ -160,10 +160,28 @@ static int cdns3_core_init_role(struct cdns3 *cdns)
 	if (ret)
 		goto err;
 
Quoted 11 lines

drivers/usb/cdns3/core.c static int cdns3_core_init_role(struct cdns3 *cdns) · line 169

Quoted 8 lines
drivers/usb/cdns3/core.c +7 -1
-	if (cdns->dr_mode != USB_DR_MODE_OTG) {
+	/* Initialize idle role to start with */
+	ret = cdns3_role_start(cdns, USB_ROLE_NONE);
+	if (ret)
+		goto err;
+
+	switch (cdns->dr_mode) {
+	case USB_DR_MODE_UNKNOWN:

One note in this place. USB_DR_MODE_UNKNOWN is not possible in this place. If cdns->dr_mode will be USB_DR_MODE_UNKNOWN then driver returns -EINVAL

Quoted 1 line

At which place? I could not find.

In this patch we can't see this line:
https://elixir.bootlin.com/linux/v5.4-rc2/source/drivers/usb/cdns3/core.c#L159
There is called cdns3_drd_update_mode(cdns);

int cdns3_drd_update_mode(struct cdns3 *cdns)

{
	int ret = 0;

	switch (cdns->dr_mode) {
	case USB_DR_MODE_PERIPHERAL:
		ret = cdns3_set_mode(cdns, USB_DR_MODE_PERIPHERAL);
		break;
	case USB_DR_MODE_HOST:
		ret = cdns3_set_mode(cdns, USB_DR_MODE_HOST);
		break;
	case USB_DR_MODE_OTG:
		ret = cdns3_init_otg_mode(cdns);
		break;
	default:
		dev_err(cdns->dev, "Unsupported mode of operation %d\n",
			cdns->dr_mode);
		return -EINVAL;
	}

	return ret;
}
Quoted 3 lines

After calling cdns3_drd_update_mode we have 2 first lines from this patch

	if (ret)
		goto err;

I see now. I will update this patch to error out if dr_mode is USB_DR_MODE_UNKNOWN. Thanks.

cheers,
-roger

Quoted 40 lines

Pawel

Quoted 38 lines
Quoted 23 lines

some line before after returning form cdns3_drd_update_mode and in consequence it jump to err label.

Maybe for better readability it this condition should be treated here also as error.

Quoted 17 lines
drivers/usb/cdns3/core.c +12 -0
+	case USB_DR_MODE_OTG:
 		ret = cdns3_hw_role_switch(cdns);
 		if (ret)
 			goto err;
+		break;
+	case USB_DR_MODE_PERIPHERAL:
+		ret = cdns3_role_start(cdns, USB_ROLE_DEVICE);
+		if (ret)
+			goto err;
+		break;
+	case USB_DR_MODE_HOST:
+		ret = cdns3_role_start(cdns, USB_ROLE_HOST);
+		if (ret)
+			goto err;
+		break;
 	}
 
Quoted 9 lines

drivers/usb/cdns3/core.c static int cdns3_core_init_role(struct cdns3 *cdns) · line 187

Quoted 1 line
drivers/usb/cdns3/core.c +0 -0
 	return ret;

--
Regards,
Pawel

--
cheers,
-roger
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki