[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250616133147.1835939-10-akuchynski@chromium.org>
Date: Mon, 16 Jun 2025 13:31:46 +0000
From: Andrei Kuchynski <akuchynski@...omium.org>
To: Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
Dmitry Baryshkov <lumag@...nel.org>,
Abhishek Pandit-Subedi <abhishekpandit@...omium.org>,
Jameson Thies <jthies@...gle.com>,
Benson Leung <bleung@...omium.org>,
Tzung-Bi Shih <tzungbi@...nel.org>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Guenter Roeck <groeck@...omium.org>,
Pooja Katiyar <pooja.katiyar@...el.com>,
Badhri Jagan Sridharan <badhri@...gle.com>,
RD Babiera <rdbabiera@...gle.com>,
linux-usb@...r.kernel.org,
linux-kernel@...r.kernel.org,
chrome-platform@...ts.linux.dev,
Andrei Kuchynski <akuchynski@...omium.org>
Subject: [PATCH 09/10] platform/chrome: cros_ec_typec: Propagate altmode entry result
In the `cros_typec_configure_mux` function, which concludes the DP/TBT
alternate mode entry, the error code should be reported back to the Type-C
mode selection logic. This ensures a detailed result is conveyed to user
space.
To inform partner drivers about the result, the VDM mechanism is used. For
DP altmode, the DP_CMD_STATUS_UPDATE message is utilized, as it is the
final one in the mode entry sequence. For TBT mode, the
TBT_CMD_STATUS_UPDATE message is sent.
Signed-off-by: Andrei Kuchynski <akuchynski@...omium.org>
---
drivers/platform/chrome/cros_ec_typec.c | 9 ++++++
drivers/platform/chrome/cros_typec_altmode.c | 32 ++++++++++++++++++--
drivers/platform/chrome/cros_typec_altmode.h | 6 ++++
include/linux/usb/typec_dp.h | 2 ++
4 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 3aed429fde03..a4f338771094 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -610,6 +610,7 @@ static int cros_typec_enable_dp(struct cros_typec_data *typec,
if (!ret)
ret = typec_mux_set(port->mux, &port->state);
+ dp_data.error = 0;
if (!ret)
ret = cros_typec_displayport_status_update(port->state.alt,
port->state.data);
@@ -699,8 +700,16 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
ret = cros_typec_enable_usb4(typec, port_num, pd_ctrl);
} else if (port->mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) {
ret = cros_typec_enable_tbt(typec, port_num, pd_ctrl);
+ cros_typec_tbt_status_update(
+ port->port_altmode[CROS_EC_ALTMODE_TBT], ret);
} else if (port->mux_flags & USB_PD_MUX_DP_ENABLED) {
ret = cros_typec_enable_dp(typec, port_num, pd_ctrl);
+ if (ret) {
+ struct typec_displayport_data dp_data = {.error = ret};
+
+ cros_typec_displayport_status_update(
+ port->port_altmode[CROS_EC_ALTMODE_DP], &dp_data);
+ }
} else if (port->mux_flags & USB_PD_MUX_SAFE_MODE) {
ret = cros_typec_usb_safe_state(port);
} else if (port->mux_flags & USB_PD_MUX_USB_ENABLED) {
diff --git a/drivers/platform/chrome/cros_typec_altmode.c b/drivers/platform/chrome/cros_typec_altmode.c
index 557340b53af0..7ee295cf0c02 100644
--- a/drivers/platform/chrome/cros_typec_altmode.c
+++ b/drivers/platform/chrome/cros_typec_altmode.c
@@ -28,6 +28,7 @@ struct cros_typec_altmode_data {
u16 sid;
u8 mode;
+ int error;
};
struct cros_typec_dp_data {
@@ -295,9 +296,16 @@ int cros_typec_displayport_status_update(struct typec_altmode *altmode,
dp_data->data = *data;
dp_data->pending_status_update = false;
- adata->header |= VDO_CMDT(CMDT_RSP_ACK);
- adata->vdo_data = &dp_data->data.status;
- adata->vdo_size = 2;
+ if (data->error) {
+ adata->header |= VDO_CMDT(CMDT_RSP_NAK);
+ adata->error = dp_data->data.error;
+ adata->vdo_data = &adata->error;
+ adata->vdo_size = 1;
+ } else {
+ adata->header |= VDO_CMDT(CMDT_RSP_ACK);
+ adata->vdo_data = &dp_data->data.status;
+ adata->vdo_size = 2;
+ }
schedule_work(&adata->work);
mutex_unlock(&adata->lock);
@@ -370,4 +378,22 @@ cros_typec_register_thunderbolt(struct cros_typec_port *port,
return alt;
}
+
+int cros_typec_tbt_status_update(struct typec_altmode *alt, int error)
+{
+ struct cros_typec_altmode_data *adata = typec_altmode_get_drvdata(alt);
+
+ mutex_lock(&adata->lock);
+
+ adata->header = VDO(adata->sid, 1, SVDM_VER_2_0, TBT_CMD_STATUS_UPDATE);
+ adata->header |= VDO_CMDT(error ? CMDT_RSP_NAK : CMDT_RSP_ACK);
+ adata->error = error;
+ adata->vdo_data = &adata->error;
+ adata->vdo_size = 1;
+ schedule_work(&adata->work);
+
+ mutex_unlock(&adata->lock);
+
+ return 0;
+}
#endif
diff --git a/drivers/platform/chrome/cros_typec_altmode.h b/drivers/platform/chrome/cros_typec_altmode.h
index 3f2aa95d065a..848a2b194b34 100644
--- a/drivers/platform/chrome/cros_typec_altmode.h
+++ b/drivers/platform/chrome/cros_typec_altmode.h
@@ -39,6 +39,7 @@ static inline int cros_typec_displayport_status_update(struct typec_altmode *alt
struct typec_altmode *
cros_typec_register_thunderbolt(struct cros_typec_port *port,
struct typec_altmode_desc *desc);
+int cros_typec_tbt_status_update(struct typec_altmode *alt, int error);
#else
static inline struct typec_altmode *
cros_typec_register_thunderbolt(struct cros_typec_port *port,
@@ -46,6 +47,11 @@ cros_typec_register_thunderbolt(struct cros_typec_port *port,
{
return typec_port_register_altmode(port->port, desc);
}
+static inline int cros_typec_tbt_status_update(struct typec_altmode *alt,
+ int error)
+{
+ return 0;
+}
#endif
#endif /* __CROS_TYPEC_ALTMODE_H__ */
diff --git a/include/linux/usb/typec_dp.h b/include/linux/usb/typec_dp.h
index f2da264d9c14..1679f7bb0c75 100644
--- a/include/linux/usb/typec_dp.h
+++ b/include/linux/usb/typec_dp.h
@@ -44,10 +44,12 @@ enum {
* commands: Status Update and Configure.
*
* @status will show for example the status of the HPD signal.
+ * @error will contain the error code, if applicable.
*/
struct typec_displayport_data {
u32 status;
u32 conf;
+ int error;
};
enum {
--
2.50.0.rc1.591.g9c95f17f64-goog
Powered by blists - more mailing lists