aboutsummaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorPooja Katiyar <pooja.katiyar@intel.com>2024-06-24 14:33:59 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-06-27 16:10:19 +0200
commitfe1b01a82f9d2af8e792db539324607676d8f35f (patch)
treea60434185fdf6a58885e0b4b1ab9b076237e8487 /drivers
parentd58a7671078a67c46bee4dd56efca073b25f11bb (diff)
usb: typec: ucsi: UCSI2.0 Get Error Status changes
Add support for UCSI 2.0 Get Error Status command to add connector number field to the command structure. Connector number field is extracted from the previous UCSI command which has failed and is used to get the failure reason/Error using Get Error Status command. Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Signed-off-by: Pooja Katiyar <pooja.katiyar@intel.com> Link: https://lore.kernel.org/r/20240624213359.1270018-1-pooja.katiyar@intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/typec/ucsi/ucsi.c29
-rw-r--r--drivers/usb/typec/ucsi/ucsi.h3
2 files changed, 29 insertions, 3 deletions
diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index c80454778d91..59eaa49042f4 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -65,8 +65,9 @@ static int ucsi_acknowledge(struct ucsi *ucsi, bool conn_ack)
static int ucsi_exec_command(struct ucsi *ucsi, u64 command);
-static int ucsi_read_error(struct ucsi *ucsi)
+static int ucsi_read_error(struct ucsi *ucsi, u8 connector_num)
{
+ u64 command;
u16 error;
int ret;
@@ -75,7 +76,8 @@ static int ucsi_read_error(struct ucsi *ucsi)
if (ret)
return ret;
- ret = ucsi_exec_command(ucsi, UCSI_GET_ERROR_STATUS);
+ command = UCSI_GET_ERROR_STATUS | UCSI_CONNECTOR_NUMBER(connector_num);
+ ret = ucsi_exec_command(ucsi, command);
if (ret < 0)
return ret;
@@ -134,9 +136,30 @@ static int ucsi_read_error(struct ucsi *ucsi)
static int ucsi_exec_command(struct ucsi *ucsi, u64 cmd)
{
+ u8 connector_num;
u32 cci;
int ret;
+ if (ucsi->version > UCSI_VERSION_1_2) {
+ switch (UCSI_COMMAND(cmd)) {
+ case UCSI_GET_ALTERNATE_MODES:
+ connector_num = UCSI_GET_ALTMODE_GET_CONNECTOR_NUMBER(cmd);
+ break;
+ case UCSI_PPM_RESET:
+ case UCSI_CANCEL:
+ case UCSI_ACK_CC_CI:
+ case UCSI_SET_NOTIFICATION_ENABLE:
+ case UCSI_GET_CAPABILITY:
+ connector_num = 0;
+ break;
+ default:
+ connector_num = UCSI_DEFAULT_GET_CONNECTOR_NUMBER(cmd);
+ break;
+ }
+ } else {
+ connector_num = 0;
+ }
+
ret = ucsi->ops->sync_write(ucsi, UCSI_CONTROL, &cmd, sizeof(cmd));
if (ret)
return ret;
@@ -166,7 +189,7 @@ static int ucsi_exec_command(struct ucsi *ucsi, u64 cmd)
return -EIO;
}
- return ucsi_read_error(ucsi);
+ return ucsi_read_error(ucsi, connector_num);
}
if (cmd == UCSI_CANCEL && cci & UCSI_CCI_CANCEL_COMPLETE) {
diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
index 47a3a0ca2c15..fe95a80050d3 100644
--- a/drivers/usb/typec/ucsi/ucsi.h
+++ b/drivers/usb/typec/ucsi/ucsi.h
@@ -116,6 +116,9 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 num);
#define UCSI_CONNECTOR_NUMBER(_num_) ((u64)(_num_) << 16)
#define UCSI_COMMAND(_cmd_) ((_cmd_) & 0xff)
+#define UCSI_GET_ALTMODE_GET_CONNECTOR_NUMBER(_cmd_) (((_cmd_) >> 24) & GENMASK(6, 0))
+#define UCSI_DEFAULT_GET_CONNECTOR_NUMBER(_cmd_) (((_cmd_) >> 16) & GENMASK(6, 0))
+
/* CONNECTOR_RESET command bits */
#define UCSI_CONNECTOR_RESET_HARD BIT(23) /* Deprecated in v1.1 */