summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2020-10-14 13:59:06 -0600
committerCommit Bot <commit-bot@chromium.org>2021-04-28 18:10:21 +0000
commitb0cf18ad002e0610326170fee4e522fcf90fe2ab (patch)
tree2d7cbbba604207a9071a84e5de7d214d53dafd77
parent9b1254b253c085a9cc70bfaf169b289bf8d9410f (diff)
downloadchrome-ec-b0cf18ad002e0610326170fee4e522fcf90fe2ab.tar.gz
TCPMv2: Report source capabilities in TYPEC_STATUS
Report the source capabilities for a port to the TYPEC_STATUS host command, and add decoding for the interesting fields here to ectool. BRANCH=servo BUG=b:167700356 TEST=on waddledoo, confirm source capability decoding from ectool matches that from TotalPhase for servo_v4 and a charger Signed-off-by: Jeremy Bettis <jbettis@google.com> Change-Id: I61f03d4646d31379d5d2b834a3ec5b1eac9042c2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2827324 Tested-by: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Brian Nemec <bnemec@chromium.org> Commit-Queue: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r--include/ec_commands.h77
-rw-r--r--include/usb_pd.h13
2 files changed, 79 insertions, 11 deletions
diff --git a/include/ec_commands.h b/include/ec_commands.h
index 5244533610..0137636e2c 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -5796,6 +5796,83 @@ struct ec_response_locate_chip {
*/
#define EC_CMD_REBOOT_AP_ON_G3 0x0127
+/*
+ * Decode helpers for Source and Sink Capability PDOs
+ *
+ * Note: The Power Delivery Specification should be considered the ultimate
+ * source of truth on the decoding of these PDOs
+ */
+#define PDO_TYPE_FIXED (0 << 30)
+#define PDO_TYPE_BATTERY (1 << 30)
+#define PDO_TYPE_VARIABLE (2 << 30)
+#define PDO_TYPE_AUGMENTED (3 << 30)
+#define PDO_TYPE_MASK (3 << 30)
+
+/*
+ * From Table 6-9 and Table 6-14 PD Rev 3.0 Ver 2.0
+ *
+ * <31:30> : Fixed Supply
+ * <29> : Dual-Role Power
+ * <28> : SNK/SRC dependent
+ * <27> : Unconstrained Power
+ * <26> : USB Communications Capable
+ * <25> : Dual-Role Data
+ * <24:20> : SNK/SRC dependent
+ * <19:10> : Voltage in 50mV Units
+ * <9:0> : Maximum Current in 10mA units
+ */
+#define PDO_FIXED_DUAL_ROLE BIT(29)
+#define PDO_FIXED_UNCONSTRAINED BIT(27)
+#define PDO_FIXED_COMM_CAP BIT(26)
+#define PDO_FIXED_DATA_SWAP BIT(25)
+#define PDO_FIXED_FRS_CURR_MASK GENMASK(24, 23) /* Sink Cap only */
+#define PDO_FIXED_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
+#define PDO_FIXED_CURRENT(p) ((p & 0x3FF) * 10)
+
+/*
+ * From Table 6-12 and Table 6-16 PD Rev 3.0 Ver 2.0
+ *
+ * <31:30> : Battery
+ * <29:20> : Maximum Voltage in 50mV units
+ * <19:10> : Minimum Voltage in 50mV units
+ * <9:0> : Maximum Allowable Power in 250mW units
+ */
+#define PDO_BATT_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
+#define PDO_BATT_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
+#define PDO_BATT_MAX_POWER(p) ((p & 0x3FF) * 250)
+
+/*
+ * From Table 6-11 and Table 6-15 PD Rev 3.0 Ver 2.0
+ *
+ * <31:30> : Variable Supply (non-Battery)
+ * <29:20> : Maximum Voltage in 50mV units
+ * <19:10> : Minimum Voltage in 50mV units
+ * <9:0> : Operational Current in 10mA units
+ */
+#define PDO_VAR_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
+#define PDO_VAR_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
+#define PDO_VAR_MAX_CURRENT(p) ((p & 0x3FF) * 10)
+
+/*
+ * From Table 6-13 and Table 6-17 PD Rev 3.0 Ver 2.0
+ *
+ * Note this type is reserved in PD 2.0, and only one type of APDO is
+ * supported as of the cited version.
+ *
+ * <31:30> : Augmented Power Data Object
+ * <29:28> : Programmable Power Supply
+ * <27> : PPS Power Limited
+ * <26:25> : Reserved
+ * <24:17> : Maximum Voltage in 100mV increments
+ * <16> : Reserved
+ * <15:8> : Minimum Voltage in 100mV increments
+ * <7> : Reserved
+ * <6:0> : Maximum Current in 50mA increments
+ */
+#define PDO_AUG_MAX_VOLTAGE(p) ((p >> 17 & 0xFF) * 100)
+#define PDO_AUG_MIN_VOLTAGE(p) ((p >> 8 & 0xFF) * 100)
+#define PDO_AUG_MAX_CURRENT(p) ((p & 0x7F) * 50)
+
/*****************************************************************************/
/* The command range 0x200-0x2FF is reserved for Rotor. */
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 00341042e2..7256a3853a 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -87,19 +87,10 @@ enum pd_rx_errors {
* if present, shall be sent in Minimum Voltage order; lowest to highest.
* 5. (PD3.0) The Augmented PDO is defined to allow extension beyond the 4 PDOs
* above by examining bits <29:28> to determine the additional PDO function.
+ *
+ * Note: Some bits and decode macros are defined in ec_commands.h
*/
-#define PDO_TYPE_FIXED (0 << 30)
-#define PDO_TYPE_BATTERY BIT(30)
-#define PDO_TYPE_VARIABLE (2 << 30)
-#define PDO_TYPE_AUGMENTED (3 << 30)
-#define PDO_TYPE_MASK (3 << 30)
-
-#define PDO_FIXED_DUAL_ROLE BIT(29) /* Dual role device */
#define PDO_FIXED_SUSPEND BIT(28) /* USB Suspend supported */
-#define PDO_FIXED_UNCONSTRAINED BIT(27) /* Unconstrained Power */
-#define PDO_FIXED_COMM_CAP BIT(26) /* USB Communications Capable */
-#define PDO_FIXED_DATA_SWAP BIT(25) /* Data role swap command supported */
-#define PDO_FIXED_FRS_CURR_MASK (3 << 23) /* [23..24] FRS current */
#define PDO_FIXED_FRS_CURR_NOT_SUPPORTED (0 << 23)
#define PDO_FIXED_FRS_CURR_DFLT_USB_POWER (1 << 23)
#define PDO_FIXED_FRS_CURR_1A5_AT_5V (2 << 23)