usb: cdns3: fixes for 5.4-rc
Subsystems (3)
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
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
@@ -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
PATCH 1/2 usb: cdns3: fix cdns3_core_init_role()
In reply to Roger QuadrosAt 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
@@ -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
Re: [PATCH 2/2] usb: cdns3: gadget: Fix full-speed mode
In reply to Roger QuadrosQuoted 14 lines · Roger Quadros
We need to disable USB3 PHY for full-speed mode else gadget mode is broken.
Signed-off-by Roger Quadros <[email protected]>Signed-off-by Sekhar Nori <[email protected]>--- drivers/usb/cdns3/gadget.c | 1 + 1 file changed, 1 insertion(+)drivers/usb/cdns3/gadget.c +0
-0
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
RE: [PATCH 1/2] usb: cdns3: fix cdns3_core_init_role()
In reply to Roger QuadrosHi 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.Signed-off-by Roger Quadros <[email protected]>Signed-off-by Sekhar Nori <[email protected]>---
drivers/usb/cdns3/core.c| 20 +++++++++++++++++++-1 file changed, 19 insertions(+), 1 deletion(-)drivers/usb/cdns3/core.c +0
-0@@ -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
-1goto 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
RE: [PATCH 2/2] usb: cdns3: gadget: Fix full-speed mode
In reply to Peter ChenQuoted 10 lines · Roger Quadros
Quoted 9 lines
We need to disable USB3 PHY for full-speed mode else gadget mode is broken.
Signed-off-by Roger Quadros <[email protected]>Signed-off-by Sekhar Nori <[email protected]>--- 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@@ -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);Reviewed-by Peter Chen <[email protected]>
Quoted 5 lines
--
Thanks,
Peter Chen
Regards,
Pawell
Re: [PATCH 1/2] usb: cdns3: fix cdns3_core_init_role()
In reply to Pawel LaszczakHi 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.Signed-off-by Roger Quadros <[email protected]>Signed-off-by Sekhar Nori <[email protected]>---
drivers/usb/cdns3/core.c| 20 +++++++++++++++++++-1 file changed, 19 insertions(+), 1 deletion(-)drivers/usb/cdns3/core.c +0
-0@@ -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_UNKNOWNis not possible in this place. Ifcdns->dr_modewill beUSB_DR_MODE_UNKNOWNthen driver returns-EINVAL
At which place? I could not find.
Quoted 31 lines
some line before after returning form
cdns3_drd_update_modeand 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;Reviewed-by Pawel Laszczak <[email protected]>Tested-by Pawel Laszczak <[email protected]>--
Regards,
Pawel
Signature · 4 lines
cheers, -roger Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
Pawel Laszczak
maintainerRE: [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.Signed-off-by Roger Quadros <[email protected]>Signed-off-by Sekhar Nori <[email protected]>---
drivers/usb/cdns3/core.c| 20 +++++++++++++++++++-1 file changed, 19 insertions(+), 1 deletion(-)drivers/usb/cdns3/core.c +0
-0@@ -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_UNKNOWNis not possible in this place. Ifcdns->dr_modewill beUSB_DR_MODE_UNKNOWNthen 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_modeand 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
-0return ret;Reviewed-by Pawel Laszczak <[email protected]>Tested-by Pawel Laszczak <[email protected]>--
Regards,
Pawel--
cheers,
-roger
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
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.Signed-off-by Roger Quadros <[email protected]>Signed-off-by Sekhar Nori <[email protected]>---
drivers/usb/cdns3/core.c| 20 +++++++++++++++++++-1 file changed, 19 insertions(+), 1 deletion(-)drivers/usb/cdns3/core.c +0
-0@@ -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_UNKNOWNis not possible in this place. Ifcdns->dr_modewill beUSB_DR_MODE_UNKNOWNthen driver returns-EINVALQuoted 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 calledcdns3_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_modewe have 2 first lines from this patchif (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_modeand 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
-0return ret;Reviewed-by Pawel Laszczak <[email protected]>Tested-by Pawel Laszczak <[email protected]>--
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