Skip to content

Commit fe1b01a

Browse files
pakatiyargregkh
authored andcommitted
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 <[email protected]> Signed-off-by: Pooja Katiyar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d58a767 commit fe1b01a

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

drivers/usb/typec/ucsi/ucsi.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ static int ucsi_acknowledge(struct ucsi *ucsi, bool conn_ack)
6565

6666
static int ucsi_exec_command(struct ucsi *ucsi, u64 command);
6767

68-
static int ucsi_read_error(struct ucsi *ucsi)
68+
static int ucsi_read_error(struct ucsi *ucsi, u8 connector_num)
6969
{
70+
u64 command;
7071
u16 error;
7172
int ret;
7273

@@ -75,7 +76,8 @@ static int ucsi_read_error(struct ucsi *ucsi)
7576
if (ret)
7677
return ret;
7778

78-
ret = ucsi_exec_command(ucsi, UCSI_GET_ERROR_STATUS);
79+
command = UCSI_GET_ERROR_STATUS | UCSI_CONNECTOR_NUMBER(connector_num);
80+
ret = ucsi_exec_command(ucsi, command);
7981
if (ret < 0)
8082
return ret;
8183

@@ -134,9 +136,30 @@ static int ucsi_read_error(struct ucsi *ucsi)
134136

135137
static int ucsi_exec_command(struct ucsi *ucsi, u64 cmd)
136138
{
139+
u8 connector_num;
137140
u32 cci;
138141
int ret;
139142

143+
if (ucsi->version > UCSI_VERSION_1_2) {
144+
switch (UCSI_COMMAND(cmd)) {
145+
case UCSI_GET_ALTERNATE_MODES:
146+
connector_num = UCSI_GET_ALTMODE_GET_CONNECTOR_NUMBER(cmd);
147+
break;
148+
case UCSI_PPM_RESET:
149+
case UCSI_CANCEL:
150+
case UCSI_ACK_CC_CI:
151+
case UCSI_SET_NOTIFICATION_ENABLE:
152+
case UCSI_GET_CAPABILITY:
153+
connector_num = 0;
154+
break;
155+
default:
156+
connector_num = UCSI_DEFAULT_GET_CONNECTOR_NUMBER(cmd);
157+
break;
158+
}
159+
} else {
160+
connector_num = 0;
161+
}
162+
140163
ret = ucsi->ops->sync_write(ucsi, UCSI_CONTROL, &cmd, sizeof(cmd));
141164
if (ret)
142165
return ret;
@@ -166,7 +189,7 @@ static int ucsi_exec_command(struct ucsi *ucsi, u64 cmd)
166189

167190
return -EIO;
168191
}
169-
return ucsi_read_error(ucsi);
192+
return ucsi_read_error(ucsi, connector_num);
170193
}
171194

172195
if (cmd == UCSI_CANCEL && cci & UCSI_CCI_CANCEL_COMPLETE) {

drivers/usb/typec/ucsi/ucsi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 num);
116116
#define UCSI_CONNECTOR_NUMBER(_num_) ((u64)(_num_) << 16)
117117
#define UCSI_COMMAND(_cmd_) ((_cmd_) & 0xff)
118118

119+
#define UCSI_GET_ALTMODE_GET_CONNECTOR_NUMBER(_cmd_) (((_cmd_) >> 24) & GENMASK(6, 0))
120+
#define UCSI_DEFAULT_GET_CONNECTOR_NUMBER(_cmd_) (((_cmd_) >> 16) & GENMASK(6, 0))
121+
119122
/* CONNECTOR_RESET command bits */
120123
#define UCSI_CONNECTOR_RESET_HARD BIT(23) /* Deprecated in v1.1 */
121124

0 commit comments

Comments
 (0)