Commit 335e3eff authored by Abhishek Pandit-Subedi's avatar Abhishek Pandit-Subedi Committed by Greg Kroah-Hartman
Browse files

usb: typec: ucsi: Update connector cap and status

parent b3db266f
Loading
Loading
Loading
Loading
+52 −4
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@
#include <linux/usb/typec.h>
#include <linux/usb/pd.h>
#include <linux/usb/role.h>
#include <asm/unaligned.h>

/* -------------------------------------------------------------------------- */

@@ -35,6 +36,12 @@ struct dentry;
#define UCSI_BCD_GET_MINOR(_v_)		(((_v_) >> 4) & 0x0F)
#define UCSI_BCD_GET_SUBMINOR(_v_)	((_v_) & 0x0F)

/*
 * Per USB PD 3.2, Section 6.2.1.1.5, the spec revision is represented by 2 bits
 * 0b00 = 1.0, 0b01 = 2.0, 0b10 = 3.0, 0b11 = Reserved, Shall NOT be used.
 */
#define UCSI_SPEC_REVISION_TO_BCD(_v_)  (((_v_) + 1) << 8)

/* Command Status and Connector Change Indication (CCI) bits */
#define UCSI_CCI_CONNECTOR(_c_)		(((_c_) & GENMASK(7, 1)) >> 1)
#define UCSI_CCI_LENGTH(_c_)		(((_c_) & GENMASK(15, 8)) >> 8)
@@ -214,9 +221,29 @@ struct ucsi_connector_capability {
#define UCSI_CONCAP_OPMODE_USB2			BIT(5)
#define UCSI_CONCAP_OPMODE_USB3			BIT(6)
#define UCSI_CONCAP_OPMODE_ALT_MODE		BIT(7)
	u8 flags;
	u32 flags;
#define UCSI_CONCAP_FLAG_PROVIDER		BIT(0)
#define UCSI_CONCAP_FLAG_CONSUMER		BIT(1)
#define UCSI_CONCAP_FLAG_SWAP_TO_DFP		BIT(2)
#define UCSI_CONCAP_FLAG_SWAP_TO_UFP		BIT(3)
#define UCSI_CONCAP_FLAG_SWAP_TO_SRC		BIT(4)
#define UCSI_CONCAP_FLAG_SWAP_TO_SINK		BIT(5)
#define UCSI_CONCAP_FLAG_EX_OP_MODE(_f_) \
	(((_f_) & GENMASK(13, 6)) >> 6)
#define   UCSI_CONCAP_EX_OP_MODE_USB4_GEN2	BIT(0)
#define   UCSI_CONCAP_EX_OP_MODE_EPR_SRC	BIT(1)
#define   UCSI_CONCAP_EX_OP_MODE_EPR_SINK	BIT(2)
#define   UCSI_CONCAP_EX_OP_MODE_USB4_GEN3	BIT(3)
#define   UCSI_CONCAP_EX_OP_MODE_USB4_GEN4	BIT(4)
#define UCSI_CONCAP_FLAG_MISC_CAPS(_f_) \
	(((_f_) & GENMASK(17, 14)) >> 14)
#define   UCSI_CONCAP_MISC_CAP_FW_UPDATE	BIT(0)
#define   UCSI_CONCAP_MISC_CAP_SECURITY		BIT(1)
#define UCSI_CONCAP_FLAG_REV_CURR_PROT_SUPPORT	BIT(18)
#define UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV(_f_) \
	(((_f_) & GENMASK(20, 19)) >> 19)
#define UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV_AS_BCD(_f_) \
	UCSI_SPEC_REVISION_TO_BCD(UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV(_f_))
} __packed;

struct ucsi_altmode {
@@ -276,15 +303,36 @@ struct ucsi_connector_status {
#define   UCSI_CONSTAT_PARTNER_TYPE_DEBUG	5
#define   UCSI_CONSTAT_PARTNER_TYPE_AUDIO	6
	u32 request_data_obj;
	u8 pwr_status;
#define UCSI_CONSTAT_BC_STATUS(_p_)		((_p_) & GENMASK(2, 0))

	u8 pwr_status[3];
#define UCSI_CONSTAT_BC_STATUS(_p_)		((_p_[0]) & GENMASK(1, 0))
#define   UCSI_CONSTAT_BC_NOT_CHARGING		0
#define   UCSI_CONSTAT_BC_NOMINAL_CHARGING	1
#define   UCSI_CONSTAT_BC_SLOW_CHARGING		2
#define   UCSI_CONSTAT_BC_TRICKLE_CHARGING	3
#define UCSI_CONSTAT_PROVIDER_CAP_LIMIT(_p_)	(((_p_) & GENMASK(6, 3)) >> 3)
#define UCSI_CONSTAT_PROVIDER_CAP_LIMIT(_p_)	(((_p_[0]) & GENMASK(5, 2)) >> 2)
#define   UCSI_CONSTAT_CAP_PWR_LOWERED		0
#define   UCSI_CONSTAT_CAP_PWR_BUDGET_LIMIT	1
#define UCSI_CONSTAT_PROVIDER_PD_VERSION_OPER_MODE(_p_)	\
	((get_unaligned_le32(_p_) & GENMASK(21, 6)) >> 6)
#define UCSI_CONSTAT_ORIENTATION(_p_)		(((_p_[2]) & GENMASK(6, 6)) >> 6)
#define   UCSI_CONSTAT_ORIENTATION_DIRECT	0
#define   UCSI_CONSTAT_ORIENTATION_FLIPPED	1
#define UCSI_CONSTAT_SINK_PATH_STATUS(_p_)	(((_p_[2]) & GENMASK(7, 7)) >> 7)
#define   UCSI_CONSTAT_SINK_PATH_DISABLED	0
#define   UCSI_CONSTAT_SINK_PATH_ENABLED	1
	u8 pwr_readings[9];
#define UCSI_CONSTAT_REV_CURR_PROT_STATUS(_p_)	((_p_[0]) & 0x1)
#define UCSI_CONSTAT_PWR_READING_VALID(_p_)	(((_p_[0]) & GENMASK(1, 1)) >> 1)
#define UCSI_CONSTAT_CURRENT_SCALE(_p_)		(((_p_[0]) & GENMASK(4, 2)) >> 2)
#define UCSI_CONSTAT_PEAK_CURRENT(_p_) \
	((get_unaligned_le32(_p_) & GENMASK(20, 5)) >> 5)
#define UCSI_CONSTAT_AVG_CURRENT(_p_) \
	((get_unaligned_le32(&(_p_)[2]) & GENMASK(20, 5)) >> 5)
#define UCSI_CONSTAT_VOLTAGE_SCALE(_p_) \
	((get_unaligned_le16(&(_p_)[4]) & GENMASK(8, 5)) >> 5)
#define UCSI_CONSTAT_VOLTAGE_READING(_p_) \
	((get_unaligned_le32(&(_p_)[5]) & GENMASK(16, 1)) >> 1)
} __packed;

/* -------------------------------------------------------------------------- */