Commit 0be3870f authored by Jameson Thies's avatar Jameson Thies Committed by Greg Kroah-Hartman
Browse files

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: 38ca4165 ("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: default avatarNeil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: default avatarJameson Thies <jthies@google.com>
Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8550-QRD
Reviewed-by: default avatarBenson Leung <bleung@chromium.org>
Reviewed-by: default avatarNeil Armstrong <neil.armstrong@linaro.org>
Reviewed-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20240315171836.343830-2-jthies@google.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 3de4f996
Loading
Loading
Loading
Loading
+21 −13
Original line number Diff line number Diff line
@@ -1137,10 +1137,13 @@ static int ucsi_check_cable(struct ucsi_connector *con)
	if (ret < 0)
		return ret;

	if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE) {
		ret = ucsi_get_cable_identity(con);
		if (ret < 0)
			return ret;
	}

	if (con->ucsi->cap.features & UCSI_CAP_ALT_MODE_DETAILS) {
		ret = ucsi_register_plug(con);
		if (ret < 0)
			return ret;
@@ -1148,6 +1151,7 @@ static int ucsi_check_cable(struct ucsi_connector *con)
		ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
		if (ret < 0)
			return ret;
	}

	return 0;
}
@@ -1193,7 +1197,9 @@ static void ucsi_handle_connector_change(struct work_struct *work)
			ucsi_register_partner(con);
			ucsi_partner_task(con, ucsi_check_connection, 1, HZ);
			ucsi_partner_task(con, ucsi_check_connector_capability, 1, HZ);
			if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE)
				ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ);
			if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS)
				ucsi_partner_task(con, ucsi_check_cable, 1, HZ);

			if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) ==
@@ -1627,7 +1633,9 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
		ucsi_register_partner(con);
		ucsi_pwr_opmode_change(con);
		ucsi_port_psy_changed(con);
		if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE)
			ucsi_get_partner_identity(con);
		if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS)
			ucsi_check_cable(con);
	}

+3 −2
Original line number Diff line number Diff line
@@ -206,7 +206,7 @@ struct ucsi_capability {
#define UCSI_CAP_ATTR_POWER_OTHER		BIT(10)
#define UCSI_CAP_ATTR_POWER_VBUS		BIT(14)
	u8 num_connectors;
	u8 features;
	u16 features;
#define UCSI_CAP_SET_UOM			BIT(0)
#define UCSI_CAP_SET_PDM			BIT(1)
#define UCSI_CAP_ALT_MODE_DETAILS		BIT(2)
@@ -215,7 +215,8 @@ struct ucsi_capability {
#define UCSI_CAP_CABLE_DETAILS			BIT(5)
#define UCSI_CAP_EXT_SUPPLY_NOTIFICATIONS	BIT(6)
#define UCSI_CAP_PD_RESET			BIT(7)
	u16 reserved_1;
#define UCSI_CAP_GET_PD_MESSAGE		BIT(8)
	u8 reserved_1;
	u8 num_alt_modes;
	u8 reserved_2;
	u16 bc_version;