Skip to contentSkip to conversation

TypeC Connector Class driver improvements

PATCH Superseded Azhar Shaikh 2 participants 6 messages Jul 30, 2020 – Aug 3, 2020

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover TypeC Connector Class driver improvements

Changes in v2:
* Patch 1: "platform/chrome: cros_ec_typec: Send enum values to

            usb_role_switch_set_role()"

* Update the commit message to change 'USB_ROLE_HOST in case of UFP.' to 'USB_ROLE_HOST in case of DFP.'

* Patch 2: "platform/chrome: cros_ec_typec: Avoid setting usb role twice during disconnect"
* New patch added.

Azhar Shaikh (2):
platform/chrome: cros_ec_typec: Send enum values to
usb_role_switch_set_role()
platform/chrome: cros_ec_typec: Avoid setting usb role twice during
disconnect

 drivers/platform/chrome/cros_ec_typec.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/2 platform/chrome: cros_ec_typec: Send enum values to usb_role_switch_set_role()

usb_role_switch_set_role() has the second argument as enum for usb_role. Currently depending upon the data role i.e. UFP(0) or DFP(1) is sent. This eventually translates to USB_ROLE_NONE in case of UFP and USB_ROLE_DEVICE in case of DFP. Correct this by sending correct enum values as USB_ROLE_DEVICE in case of UFP and USB_ROLE_HOST in case of DFP.

Fixes 7e7def15fa4b ("platform/chrome: cros_ec_typec: Add USB mux control")
---
 drivers/platform/chrome/cros_ec_typec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/platform/chrome/cros_ec_typec.c +2 -1
index 3eae01f4c9f7..eb4713b7ae14 100644
@@ -590,7 +590,8 @@ static int cros_typec_port_update(struct cros_typec_data *typec, int port_num)
 		dev_warn(typec->dev, "Configure muxes failed, err = %d\n", ret);
 
 	return usb_role_switch_set_role(typec->ports[port_num]->role_sw,
-					!!(resp.role & PD_CTRL_RESP_ROLE_DATA));
+				       resp.role & PD_CTRL_RESP_ROLE_DATA
+				       ? USB_ROLE_HOST : USB_ROLE_DEVICE);
 }
 
 static int cros_typec_get_cmd_version(struct cros_typec_data *typec)
Signature · 1 line
2.17.1
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] platform/chrome: cros_ec_typec: Send enum values to usb_role_switch_set_role()

Quoted 7 lines · Azhar Shaikh

usb_role_switch_set_role() has the second argument as enum for usb_role. Currently depending upon the data role i.e. UFP(0) or DFP(1) is sent. This eventually translates to USB_ROLE_NONE in case of UFP and USB_ROLE_DEVICE in case of DFP. Correct this by sending correct enum values as USB_ROLE_DEVICE in case of UFP and USB_ROLE_HOST in case of DFP.

Quoted 5 lines
Fixes 7e7def15fa4b ("platform/chrome: cros_ec_typec: Add USB mux control")
Quoted 20 lines
---
 drivers/platform/chrome/cros_ec_typec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/platform/chrome/cros_ec_typec.c +2 -1
index 3eae01f4c9f7..eb4713b7ae14 100644
@@ -590,7 +590,8 @@ static int cros_typec_port_update(struct cros_typec_data *typec, int port_num)
 		dev_warn(typec->dev, "Configure muxes failed, err = %d\n", ret);
 
 	return usb_role_switch_set_role(typec->ports[port_num]->role_sw,
-					!!(resp.role & PD_CTRL_RESP_ROLE_DATA));
+				       resp.role & PD_CTRL_RESP_ROLE_DATA
+				       ? USB_ROLE_HOST : USB_ROLE_DEVICE);
 }
 
 static int cros_typec_get_cmd_version(struct cros_typec_data *typec)
Signature · 1 line
2.17.1
Signature · 1 line
heikki
#3 lore raw

PATCH 1/1 platform/chrome: cros_ec_typec: Avoid setting usb role twice during disconnect

In reply to Azhar Shaikh

On disconnect port partner is removed and usb role is set to NONE. But then in cros_typec_port_update() the role is set again. Avoid this by moving usb_role_switch_set_role() to cros_typec_configure_mux().

---
 drivers/platform/chrome/cros_ec_typec.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/platform/chrome/cros_ec_typec.c +7 -3
index eb4713b7ae14..df97431b2275 100644
@@ -515,6 +515,12 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
 	if (ret)
 		return ret;
 
+	ret = usb_role_switch_set_role(typec->ports[port_num]->role_sw,
+				       pd_ctrl->role & PD_CTRL_RESP_ROLE_DATA
+				       ? USB_ROLE_HOST : USB_ROLE_DEVICE);
+	if (ret)
+		return ret;
+
 	if (mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) {
 		ret = cros_typec_enable_tbt(typec, port_num, pd_ctrl);
 	} else if (mux_flags & USB_PD_MUX_DP_ENABLED) {
@@ -589,9 +595,7 @@ static int cros_typec_port_update(struct cros_typec_data *typec, int port_num)
 	if (ret)
 		dev_warn(typec->dev, "Configure muxes failed, err = %d\n", ret);
 
-	return usb_role_switch_set_role(typec->ports[port_num]->role_sw,
-				       resp.role & PD_CTRL_RESP_ROLE_DATA
-				       ? USB_ROLE_HOST : USB_ROLE_DEVICE);
+	return ret;
 }
 
 static int cros_typec_get_cmd_version(struct cros_typec_data *typec)
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#4 lore raw

Re: [PATCH] platform/chrome: cros_ec_typec: Avoid setting usb role twice during disconnect

Hi,

I guess this is was supposed to be PATCH v2 2/2, right?

Quoted 7 lines · Azhar Shaikh

On disconnect port partner is removed and usb role is set to NONE. But then in cros_typec_port_update() the role is set again. Avoid this by moving usb_role_switch_set_role() to cros_typec_configure_mux().

Quoted 34 lines
---
 drivers/platform/chrome/cros_ec_typec.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/platform/chrome/cros_ec_typec.c +7 -3
index eb4713b7ae14..df97431b2275 100644
@@ -515,6 +515,12 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
 	if (ret)
 		return ret;
 
+	ret = usb_role_switch_set_role(typec->ports[port_num]->role_sw,
+				       pd_ctrl->role & PD_CTRL_RESP_ROLE_DATA
+				       ? USB_ROLE_HOST : USB_ROLE_DEVICE);
+	if (ret)
+		return ret;
+
 	if (mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) {
 		ret = cros_typec_enable_tbt(typec, port_num, pd_ctrl);
 	} else if (mux_flags & USB_PD_MUX_DP_ENABLED) {
@@ -589,9 +595,7 @@ static int cros_typec_port_update(struct cros_typec_data *typec, int port_num)
 	if (ret)
 		dev_warn(typec->dev, "Configure muxes failed, err = %d\n", ret);
 
-	return usb_role_switch_set_role(typec->ports[port_num]->role_sw,
-				       resp.role & PD_CTRL_RESP_ROLE_DATA
-				       ? USB_ROLE_HOST : USB_ROLE_DEVICE);
+	return ret;
 }
 
 static int cros_typec_get_cmd_version(struct cros_typec_data *typec)
Signature · 1 line
2.17.1

thanks,

Signature · 1 line
heikki
#5 lore raw

RE: [PATCH] platform/chrome: cros_ec_typec: Avoid setting usb role twice during disconnect

Hi,

Quoted 12 lines

-----Original Message-----
From: Heikki Krogerus <[email protected]>
Sent: Friday, July 31, 2020 6:37 AM
To: Shaikh, Azhar <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; Patel, Utkarsh H <[email protected]>; Bowman, Casey G <[email protected]>; Mani, Rajmohan <[email protected]>
Subject: Re: [PATCH] platform/chrome: cros_ec_typec: Avoid setting usb role twice during disconnect

Quoted 4 lines

Hi,

I guess this is was supposed to be PATCH v2 2/2, right?

That is correct.

Quoted 57 lines · Azhar Shaikh
Quoted 7 lines

On disconnect port partner is removed and usb role is set to NONE. But then in cros_typec_port_update() the role is set again. Avoid this by moving usb_role_switch_set_role() to cros_typec_configure_mux().

drivers/platform/chrome/cros_ec_typec.c static int cros_typec_configure_mux(struct

Quoted 10 lines
---
 drivers/platform/chrome/cros_ec_typec.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/platform/chrome/cros_ec_typec.c +0 -0
index eb4713b7ae14..df97431b2275 100644
@@ -515,6 +515,12 @@ static int cros_typec_configure_mux(struct

cros_typec_data *typec, int port_num,

drivers/platform/chrome/cros_ec_typec.c static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,

Quoted 5 lines
drivers/platform/chrome/cros_ec_typec.c +2 -0
 	if (ret)
 		return ret;
 
+	ret = usb_role_switch_set_role(typec->ports[port_num]->role_sw,
+				       pd_ctrl->role &

PD_CTRL_RESP_ROLE_DATA

drivers/platform/chrome/cros_ec_typec.c static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,

Quoted 7 lines
drivers/platform/chrome/cros_ec_typec.c +4 -0
+				       ? USB_ROLE_HOST : USB_ROLE_DEVICE);
+	if (ret)
+		return ret;
+
 	if (mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) {
 		ret = cros_typec_enable_tbt(typec, port_num, pd_ctrl);
 	} else if (mux_flags & USB_PD_MUX_DP_ENABLED) { @@ -589,9

+595,7 @@

Quoted 1 line

static int cros_typec_port_update(struct cros_typec_data *typec, int

port_num)

drivers/platform/chrome/cros_ec_typec.c

Quoted 2 lines
drivers/platform/chrome/cros_ec_typec.c +0 -0
 	if (ret)
 		dev_warn(typec->dev, "Configure muxes failed, err = %d\n",

ret);

Quoted 11 lines
drivers/platform/chrome/cros_ec_typec.c +0 -1
-	return usb_role_switch_set_role(typec->ports[port_num]-

role_sw,

drivers/platform/chrome/cros_ec_typec.c +1 -3
-				       resp.role & PD_CTRL_RESP_ROLE_DATA
-				       ? USB_ROLE_HOST : USB_ROLE_DEVICE);
+	return ret;
 }
 
 static int cros_typec_get_cmd_version(struct cros_typec_data *typec)
--

2.17.1

thanks,

--
heikki