Skip to contentSkip to conversation

usb: cdns3: core: get role switch node from firmware

PATCH In review Peter Chen 2 participants 10 messages Mar 31, 2020 – Apr 2, 2020

Subsystems (3)
lore
Share & tools
lore

Peter Chen

author
#0 lore raw

PATCH 1/4 usb: cdns3: core: get role switch node from firmware

After that, the role switch device (eg, Type-C device) could call cdns3_role_set to finish the role switch.

---
 drivers/usb/cdns3/core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/usb/cdns3/core.c +2 -0
index 4aafba20f450..704c679a0c5d 100644
@@ -528,6 +528,8 @@ static int cdns3_probe(struct platform_device *pdev)
 	sw_desc.get = cdns3_role_get;
 	sw_desc.allow_userspace_control = true;
 	sw_desc.driver_data = cdns;
+	if (device_property_read_bool(dev, "usb-role-switch"))
+		sw_desc.fwnode = dev->fwnode;
 
 	cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
 	if (IS_ERR(cdns->role_sw)) {
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 2/4 usb: cdns3: delete role_override

In short, we have three kinds of role switches:
- Based on SoC: ID and VBUS
- Based on external connnctor, eg, Type-C or GPIO Connector
- Based on user choices through sysfs

Since HW handling and usb-role-switch handling are at different places, we do not need role_override any more, and this flag could not judge external connector case well.

With role_override deleted, We use cdns3_hw_role_switch for the 1st use case, and usb-role-switch for the 2nd and 3rd cases.

---
 drivers/usb/cdns3/core.c | 37 -------------------------------------
 drivers/usb/cdns3/core.h |  2 --
 2 files changed, 39 deletions(-)
drivers/usb/cdns3/core.c +0 -37
index 704c679a0c5d..f57c66a9f87c 100644
@@ -291,10 +291,6 @@ int cdns3_hw_role_switch(struct cdns3 *cdns)
 	enum usb_role real_role, current_role;
 	int ret = 0;
 
-	/* Do nothing if role based on syfs. */
-	if (cdns->role_override)
-		return 0;
-
 	pm_runtime_get_sync(cdns->dev);
 
 	current_role = cdns->role;
@@ -353,39 +349,6 @@ static int cdns3_role_set(struct usb_role_switch *sw, enum usb_role role)
 
 	pm_runtime_get_sync(cdns->dev);
 
-	/*
-	 * FIXME: switch role framework should be extended to meet
-	 * requirements. Driver assumes that role can be controlled
-	 * by SW or HW. Temporary workaround is to use USB_ROLE_NONE to
-	 * switch from SW to HW control.
-	 *
-	 * For dr_mode == USB_DR_MODE_OTG:
-	 *	if user sets USB_ROLE_HOST or USB_ROLE_DEVICE then driver
-	 *	sets role_override flag and forces that role.
-	 *	if user sets USB_ROLE_NONE, driver clears role_override and lets
-	 *	HW state machine take over.
-	 *
-	 * For dr_mode != USB_DR_MODE_OTG:
-	 *	Assumptions:
-	 *	1. Restricted user control between NONE and dr_mode.
-	 *	2. Driver doesn't need to rely on role_override flag.
-	 *	3. Driver needs to ensure that HW state machine is never called
-	 *	   if dr_mode != USB_DR_MODE_OTG.
-	 */
-	if (role == USB_ROLE_NONE)
-		cdns->role_override = 0;
-	else
-		cdns->role_override = 1;
-
-	/*
-	 * HW state might have changed so driver need to trigger
-	 * HW state machine if dr_mode == USB_DR_MODE_OTG.
-	 */
-	if (!cdns->role_override && cdns->dr_mode == USB_DR_MODE_OTG) {
-		cdns3_hw_role_switch(cdns);
-		goto pm_put;
-	}
-
 	if (cdns->role == role)
 		goto pm_put;
 
drivers/usb/cdns3/core.h +0 -2
index 969eb94de204..1ad1f1fe61e9 100644
@@ -62,7 +62,6 @@ struct cdns3_role_driver {
  *           This field based on firmware setting, kernel configuration
  *           and hardware configuration.
  * @role_sw: pointer to role switch object.
- * @role_override: set 1 if role rely on SW.
  */
 struct cdns3 {
 	struct device			*dev;
@@ -90,7 +89,6 @@ struct cdns3 {
 	struct mutex			mutex;
 	enum usb_dr_mode		dr_mode;
 	struct usb_role_switch		*role_sw;
-	int				role_override;
 };
 
 int cdns3_hw_role_switch(struct cdns3 *cdns);
Signature · 1 line
2.17.1
author
#2 lore raw

PATCH 3/4 usb: cdns3: change "cdsn3" to"cdns3"

In reply to Peter Chen

And delete cdsn3_hw_role_state_machine declare which doesn't be needed.

---
 drivers/usb/cdns3/core.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/usb/cdns3/core.c +3 -5
index f57c66a9f87c..19bbb5b7e6b6 100644
@@ -82,8 +82,6 @@ static void cdns3_exit_roles(struct cdns3 *cdns)
 	cdns3_drd_exit(cdns);
 }
 
-static enum usb_role cdsn3_hw_role_state_machine(struct cdns3 *cdns);
-
 /**
  * cdns3_core_init_role - initialize role of operation
  * @cdns: Pointer to cdns3 structure
@@ -193,12 +191,12 @@ static int cdns3_core_init_role(struct cdns3 *cdns)
 }
 
 /**
- * cdsn3_hw_role_state_machine  - role switch state machine based on hw events.
+ * cdns3_hw_role_state_machine  - role switch state machine based on hw events.
  * @cdns: Pointer to controller structure.
  *
  * Returns next role to be entered based on hw events.
  */
-static enum usb_role cdsn3_hw_role_state_machine(struct cdns3 *cdns)
+static enum usb_role cdns3_hw_role_state_machine(struct cdns3 *cdns)
 {
 	enum usb_role role;
 	int id, vbus;
@@ -294,7 +292,7 @@ int cdns3_hw_role_switch(struct cdns3 *cdns)
 	pm_runtime_get_sync(cdns->dev);
 
 	current_role = cdns->role;
-	real_role = cdsn3_hw_role_state_machine(cdns);
+	real_role = cdns3_hw_role_state_machine(cdns);
 
 	/* Do nothing if nothing changed */
 	if (current_role == real_role)
Signature · 1 line
2.17.1
author
#3 lore raw

PATCH 4/4 usb: cdns3: change dev_info to dev_dbg for debug message

In reply to Peter Chen

During device mode initialization, lots of device information are printed to console, see below. Change them as debug message.

cdns-usb3 5b130000.cdns3: Initialized ep0 support:
cdns-usb3 5b130000.cdns3: Initialized ep1out support: BULK, INT ISO cdns-usb3 5b130000.cdns3: Initialized ep2out support: BULK, INT ISO cdns-usb3 5b130000.cdns3: Initialized ep3out support: BULK, INT ISO cdns-usb3 5b130000.cdns3: Initialized ep4out support: BULK, INT ISO cdns-usb3 5b130000.cdns3: Initialized ep5out support: BULK, INT ISO cdns-usb3 5b130000.cdns3: Initialized ep6out support: BULK, INT ISO cdns-usb3 5b130000.cdns3: Initialized ep7out support: BULK, INT ISO cdns-usb3 5b130000.cdns3: Initialized ep1in support: BULK, INT ISO cdns-usb3 5b130000.cdns3: Initialized ep2in support: BULK, INT ISO cdns-usb3 5b130000.cdns3: Initialized ep3in support: BULK, INT ISO cdns-usb3 5b130000.cdns3: Initialized ep4in support: BULK, INT ISO cdns-usb3 5b130000.cdns3: Initialized ep5in support: BULK, INT ISO cdns-usb3 5b130000.cdns3: Initialized ep6in support: BULK, INT ISO cdns-usb3 5b130000.cdns3: Initialized ep7in support: BULK, INT ISO

---
 drivers/usb/cdns3/drd.c    | 4 ++--
 drivers/usb/cdns3/gadget.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/usb/cdns3/drd.c +2 -2
index 16ad485f0b69..58089841ed52 100644
@@ -329,7 +329,7 @@ int cdns3_drd_init(struct cdns3 *cdns)
 		cdns->otg_v1_regs = NULL;
 		cdns->otg_regs = regs;
 		writel(1, &cdns->otg_v0_regs->simulate);
-		dev_info(cdns->dev, "DRD version v0 (%08x)\n",
+		dev_dbg(cdns->dev, "DRD version v0 (%08x)\n",
 			 readl(&cdns->otg_v0_regs->version));
 	} else {
 		cdns->otg_v0_regs = NULL;
@@ -337,7 +337,7 @@ int cdns3_drd_init(struct cdns3 *cdns)
 		cdns->otg_regs = (void *)&cdns->otg_v1_regs->cmd;
 		cdns->version  = CDNS3_CONTROLLER_V1;
 		writel(1, &cdns->otg_v1_regs->simulate);
-		dev_info(cdns->dev, "DRD version v1 (ID: %08x, rev: %08x)\n",
+		dev_dbg(cdns->dev, "DRD version v1 (ID: %08x, rev: %08x)\n",
 			 readl(&cdns->otg_v1_regs->did),
 			 readl(&cdns->otg_v1_regs->rid));
 	}
drivers/usb/cdns3/gadget.c +1 -1
index 3c05080a9ad5..2dab1da4a2bc 100644
@@ -2954,7 +2954,7 @@ static int cdns3_init_eps(struct cdns3_device *priv_dev)
 
 		priv_ep->flags = 0;
 
-		dev_info(priv_dev->dev, "Initialized  %s support: %s %s\n",
+		dev_dbg(priv_dev->dev, "Initialized  %s support: %s %s\n",
 			 priv_ep->name,
 			 priv_ep->endpoint.caps.type_bulk ? "BULK, INT" : "",
 			 priv_ep->endpoint.caps.type_iso ? "ISO" : "");
Signature · 1 line
2.17.1
#4 lore raw
In reply to Peter Chen

Hi Peter,

Quoted 4 lines · Peter Chen

After that, the role switch device (eg, Type-C device) could call cdns3_role_set to finish the role switch.

This does not apply on v5.6. What branch did you test this on?

cheers,
-roger

Quoted 18 lines
---
  drivers/usb/cdns3/core.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/usb/cdns3/core.c +2 -0
index 4aafba20f450..704c679a0c5d 100644
@@ -528,6 +528,8 @@ static int cdns3_probe(struct platform_device *pdev)
  	sw_desc.get = cdns3_role_get;
  	sw_desc.allow_userspace_control = true;
  	sw_desc.driver_data = cdns;
+	if (device_property_read_bool(dev, "usb-role-switch"))
+		sw_desc.fwnode = dev->fwnode;
 
  	cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
  	if (IS_ERR(cdns->role_sw)) {
Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
author
#5 lore raw
Quoted 11 lines · Peter Chen
Quoted 4 lines

After that, the role switch device (eg, Type-C device) could call cdns3_role_set to finish the role switch.

This does not apply on v5.6. What branch did you test this on?

Hi Roger,

I use 5.6-rc4. Which conflict you have met? Do you have below patch?

8708a9fa2938 usb: roles: Provide the switch drivers handle to the switch in the API

Peter

#6 lore raw
Quoted 9 lines · Peter Chen
Quoted 9 lines · Peter Chen
Quoted 4 lines

After that, the role switch device (eg, Type-C device) could call cdns3_role_set to finish the role switch.

Quoted 8 lines
Quoted 2 lines

This does not apply on v5.6. What branch did you test this on?

Hi Roger,

I use 5.6-rc4. Which conflict you have met? Do you have below patch?

8708a9fa2938 usb: roles: Provide the switch drivers handle to the switch in the API

Applying: usb: cdns3: core: get role switch node from firmware
error: patch failed: drivers/usb/cdns3/core.c:528
error: drivers/usb/cdns3/core.c: patch does not apply
Patch failed at 0001 usb: cdns3: core: get role switch node from firmware Use 'git am --show-current-patch' to see the failed patch When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".

cheers,
-roger

Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
author
#7 lore raw
Quoted 9 lines
Quoted 8 lines
Quoted 1 line

Hi Roger,

I use 5.6-rc4. Which conflict you have met? Do you have below patch?

8708a9fa2938 usb: roles: Provide the switch drivers handle to the switch in the API

Quoted 9 lines

Applying: usb: cdns3: core: get role switch node from firmware
error: patch failed: drivers/usb/cdns3/core.c:528
error: drivers/usb/cdns3/core.c: patch does not apply Patch failed at 0001 usb:
cdns3: core: get role switch node from firmware Use 'git am --show-current-patch' to see the failed patch When you have resolved this problem, run "git am -- continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

I just tried the latest Greg's usb-next, it could apply. Do you have the patch I mentioned? What's the conflict in source file?

Peter

#8 lore raw
Quoted 19 lines · Peter Chen
Quoted 9 lines
Quoted 8 lines
Quoted 1 line

Hi Roger,

I use 5.6-rc4. Which conflict you have met? Do you have below patch?

8708a9fa2938 usb: roles: Provide the switch drivers handle to the switch in the API

Quoted 9 lines

Applying: usb: cdns3: core: get role switch node from firmware
error: patch failed: drivers/usb/cdns3/core.c:528
error: drivers/usb/cdns3/core.c: patch does not apply Patch failed at 0001 usb:
cdns3: core: get role switch node from firmware Use 'git am --show-current-patch' to see the failed patch When you have resolved this problem, run "git am -- continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

Quoted 3 lines

I just tried the latest Greg's usb-next, it could apply. Do you have the patch I mentioned? What's the conflict in source file?

OK, it applies on usb-next. Thanks.

cheers,
-roger

Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
Reviewed-by on v1 1/4
#9 lore raw
In reply to Peter Chen
Quoted 4 lines · Peter Chen

After that, the role switch device (eg, Type-C device) could call cdns3_role_set to finish the role switch.

For this patch and all in the series

Quoted 18 lines
---
  drivers/usb/cdns3/core.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/usb/cdns3/core.c +2 -0
index 4aafba20f450..704c679a0c5d 100644
@@ -528,6 +528,8 @@ static int cdns3_probe(struct platform_device *pdev)
  	sw_desc.get = cdns3_role_get;
  	sw_desc.allow_userspace_control = true;
  	sw_desc.driver_data = cdns;
+	if (device_property_read_bool(dev, "usb-role-switch"))
+		sw_desc.fwnode = dev->fwnode;
 
  	cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
  	if (IS_ERR(cdns->role_sw)) {
Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki