Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 0be3870

Browse files
jthiesatgooglegregkh
authored andcommitted
usb: typec: ucsi: Check capabilities before cable and identity discovery
Check the UCSI_CAP_GET_PD_MESSAGE bit before sending GET_PD_MESSAGE to discover partner and cable identity, check UCSI_CAP_CABLE_DETAILS before sending GET_CABLE_PROPERTY to discover the cable and check UCSI_CAP_ALT_MODE_DETAILS before registering the a cable plug. Additionally, move 8 bits from reserved_1 to features in the ucsi_capability struct. This makes the field 16 bits, still 8 short of the 24 bits allocated for it in UCSI v3.0, but it will not overflow because UCSI only defines 14 bits in bmOptionalFeatures. Fixes: 38ca416 ("usb: typec: ucsi: Register cables based on GET_CABLE_PROPERTY") Link: https://lore.kernel.org/linux-usb/44e8142f-d9b3-487b-83fe-39deadddb492@linaro.org Suggested-by: Neil Armstrong <neil.armstrong@linaro.org> Signed-off-by: Jameson Thies <jthies@google.com> Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8550-QRD Reviewed-by: Benson Leung <bleung@chromium.org> Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Link: https://lore.kernel.org/r/20240315171836.343830-2-jthies@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3de4f99 commit 0be3870

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

drivers/usb/typec/ucsi/ucsi.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,17 +1137,21 @@ static int ucsi_check_cable(struct ucsi_connector *con)
11371137
if (ret < 0)
11381138
return ret;
11391139

1140-
ret = ucsi_get_cable_identity(con);
1141-
if (ret < 0)
1142-
return ret;
1140+
if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE) {
1141+
ret = ucsi_get_cable_identity(con);
1142+
if (ret < 0)
1143+
return ret;
1144+
}
11431145

1144-
ret = ucsi_register_plug(con);
1145-
if (ret < 0)
1146-
return ret;
1146+
if (con->ucsi->cap.features & UCSI_CAP_ALT_MODE_DETAILS) {
1147+
ret = ucsi_register_plug(con);
1148+
if (ret < 0)
1149+
return ret;
11471150

1148-
ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
1149-
if (ret < 0)
1150-
return ret;
1151+
ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
1152+
if (ret < 0)
1153+
return ret;
1154+
}
11511155

11521156
return 0;
11531157
}
@@ -1193,8 +1197,10 @@ static void ucsi_handle_connector_change(struct work_struct *work)
11931197
ucsi_register_partner(con);
11941198
ucsi_partner_task(con, ucsi_check_connection, 1, HZ);
11951199
ucsi_partner_task(con, ucsi_check_connector_capability, 1, HZ);
1196-
ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ);
1197-
ucsi_partner_task(con, ucsi_check_cable, 1, HZ);
1200+
if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE)
1201+
ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ);
1202+
if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS)
1203+
ucsi_partner_task(con, ucsi_check_cable, 1, HZ);
11981204

11991205
if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) ==
12001206
UCSI_CONSTAT_PWR_OPMODE_PD)
@@ -1627,8 +1633,10 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
16271633
ucsi_register_partner(con);
16281634
ucsi_pwr_opmode_change(con);
16291635
ucsi_port_psy_changed(con);
1630-
ucsi_get_partner_identity(con);
1631-
ucsi_check_cable(con);
1636+
if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE)
1637+
ucsi_get_partner_identity(con);
1638+
if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS)
1639+
ucsi_check_cable(con);
16321640
}
16331641

16341642
/* Only notify USB controller if partner supports USB data */

drivers/usb/typec/ucsi/ucsi.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ struct ucsi_capability {
206206
#define UCSI_CAP_ATTR_POWER_OTHER BIT(10)
207207
#define UCSI_CAP_ATTR_POWER_VBUS BIT(14)
208208
u8 num_connectors;
209-
u8 features;
209+
u16 features;
210210
#define UCSI_CAP_SET_UOM BIT(0)
211211
#define UCSI_CAP_SET_PDM BIT(1)
212212
#define UCSI_CAP_ALT_MODE_DETAILS BIT(2)
@@ -215,7 +215,8 @@ struct ucsi_capability {
215215
#define UCSI_CAP_CABLE_DETAILS BIT(5)
216216
#define UCSI_CAP_EXT_SUPPLY_NOTIFICATIONS BIT(6)
217217
#define UCSI_CAP_PD_RESET BIT(7)
218-
u16 reserved_1;
218+
#define UCSI_CAP_GET_PD_MESSAGE BIT(8)
219+
u8 reserved_1;
219220
u8 num_alt_modes;
220221
u8 reserved_2;
221222
u16 bc_version;

0 commit comments

Comments
 (0)