2022-03-17 19:35:54

by Rajat Khandelwal

[permalink] [raw]
Subject: RE: [PATCH] "Active" sysfs attribute of typeC class should reflect the current state of active mode.

+Abhijeet

-----Original Message-----
From: Khandelwal, Rajat <[email protected]>
Sent: Thursday, March 17, 2022 7:58 PM
To: [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Khandelwal, Rajat <[email protected]>; Regupathy, Rajaram <[email protected]>
Subject: [PATCH] "Active" sysfs attribute of typeC class should reflect the current state of active mode.

The "active" attribute of typeC class doesn't reflect the current status of active mode. For eg., if the device is in DP alt mode, the corresponding active sysfs attribute doesn't reflect the output to be "yes". It still displays "no". Same goes for TBT alt mode.
As an eg, cat /sys/bus/typec/devices/port0-partner.1/active --> displays "no"! port0-partner.1 is the partner SVID created for TBT mode. On entering TBT mode, the active sysfs attribute should display "yes", but it displays "no". This patch fixes this.

Signed-off-by: Rajat-Khandelwal <[email protected]>
---
drivers/platform/chrome/cros_ec_typec.c | 41 +++++++++++++++++++++++--
1 file changed, 39 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 5de0bfb0bc4d..798c58c75a7c 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -32,6 +32,12 @@ enum {
CROS_EC_ALTMODE_MAX,
};

+/* Supported alt modes and their SVIDs. */ enum {
+ CROS_EC_ALTMODE_DP_SVID = 0xff01,
+ CROS_EC_ALTMODE_TBT_SVID = 0x8087,
+};
+
/* Container for altmode pointer nodes. */ struct cros_typec_altmode_node {
struct typec_altmode *amode;
@@ -396,6 +402,7 @@ static int cros_typec_enable_tbt(struct cros_typec_data *typec, {
struct cros_typec_port *port = typec->ports[port_num];
struct typec_thunderbolt_data data;
+ struct cros_typec_altmode_node *node, *n;
int ret;

if (typec->pd_ctrl_ver < 2) {
@@ -438,7 +445,14 @@ static int cros_typec_enable_tbt(struct cros_typec_data *typec,
port->state.data = &data;
port->state.mode = TYPEC_TBT_MODE;

- return typec_mux_set(port->mux, &port->state);
+ ret = typec_mux_set(port->mux, &port->state);
+
+ list_for_each_entry_safe(node, n, &port->partner_mode_list, list) {
+ if (node->amode->svid == CROS_EC_ALTMODE_TBT_SVID && !ret)
+ typec_altmode_update_active(node->amode, true);
+ }
+
+ return ret;
}

/* Spoof the VDOs that were likely communicated by the partner. */ @@ -448,6 +462,7 @@ static int cros_typec_enable_dp(struct cros_typec_data *typec, {
struct cros_typec_port *port = typec->ports[port_num];
struct typec_displayport_data dp_data;
+ struct cros_typec_altmode_node *node, *n;
int ret;

if (typec->pd_ctrl_ver < 2) {
@@ -480,7 +495,14 @@ static int cros_typec_enable_dp(struct cros_typec_data *typec,
port->state.data = &dp_data;
port->state.mode = TYPEC_MODAL_STATE(ffs(pd_ctrl->dp_mode));

- return typec_mux_set(port->mux, &port->state);
+ ret = typec_mux_set(port->mux, &port->state);
+
+ list_for_each_entry_safe(node, n, &port->partner_mode_list, list) {
+ if (node->amode->svid == CROS_EC_ALTMODE_DP_SVID && !ret)
+ typec_altmode_update_active(node->amode, true);
+ }
+
+ return ret;
}

static int cros_typec_enable_usb4(struct cros_typec_data *typec, @@ -518,8 +540,23 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
struct cros_typec_port *port = typec->ports[port_num];
struct ec_params_usb_pd_mux_ack mux_ack;
enum typec_orientation orientation;
+ struct cros_typec_altmode_node *node, *n;
int ret;

+ if (mux_flags != USB_PD_MUX_DP_ENABLED && mux_flags != USB_PD_MUX_HPD_IRQ &&
+ mux_flags != USB_PD_MUX_HPD_LVL) {
+ list_for_each_entry_safe(node, n, &port->partner_mode_list, list) {
+ if (node->amode->svid == CROS_EC_ALTMODE_DP_SVID)
+ typec_altmode_update_active(node->amode, false);
+ }
+ }
+
+ if (mux_flags != USB_PD_MUX_TBT_COMPAT_ENABLED) {
+ list_for_each_entry_safe(node, n, &port->partner_mode_list, list) {
+ if (node->amode->svid == CROS_EC_ALTMODE_TBT_SVID)
+ typec_altmode_update_active(node->amode, false);
+ }
+ }
+
if (mux_flags == USB_PD_MUX_NONE) {
ret = cros_typec_usb_disconnect_state(port);
goto mux_ack;
--
2.17.1