summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2019-11-27 23:59:24 -0800
committerCommit Bot <commit-bot@chromium.org>2020-06-25 15:17:26 +0000
commit3f205275779439c30fd7710af402eca24e329350 (patch)
tree7e71dddccbe6488e1db28ab06f29be5822f520bb /include
parentd2b98d2da9463e9445877e88344523198fc39ffc (diff)
downloadchrome-ec-3f205275779439c30fd7710af402eca24e329350.tar.gz
usb_pd_policy: Make a lot of objects common
There is a board specific usb_pd_policy.c file that contains a lot of code for handling DisplayPort Alternate mode, Google Firmware Update Alternate mode, as well as some PD policy functions such as deciding to Accept or Reject a data role swap or a power role swap. Several boards simply copy/paste this code from project to project as a lot of this functionality is not actually board specific. This commit tries to refactor this by pulling the functions that are not mainly board specific into common code. The functions are made overridable such that boards that truly do require a different implementation may do so. Additionally, this consolidation changes the policy behaviour for some boards, but they should be for the better. Some examples include that data swaps are always allowed if we are a UFP (no system image requirement), power swaps are allowed to become a sink if we are no longer dual role (e.g. - in suspend), and DisplayPort Alternate Mode is not entered if the AP is off. In order to facilitate this refactor, a couple CONFIG_* options were introduced: - CONFIG_USB_PD_DP_HPD_GPIO /* HPD is sent to the GPU from the EC via a GPIO */ - CONFIG_USB_PD_CUSTOM_VDO /* * Define this if a board needs custom SNK and/or SRC PDOs. * * The default SRC PDO is a fixed 5V/1.5A with PDO_FIXED_FLAGS indicating * Dual-Role power, USB Communication Capable, and Dual-Role data. * * The default SNK PDOs are: * - Fixed 5V/500mA with the same PDO_FIXED_FLAGS * - Variable (non-battery) min 4.75V, max PD_MAX_VOLTAGE_MV, * operational current PD_MAX_CURRENT_MA, * - Battery min 4.75V, max PD_MAX_VOLTAGE_MV, operational power * PD_OPERATING_POWER_MW */ BUG=chromium:1021724,b:141458448 BRANCH=firmware-grunt-11031.B TEST=With other PD Policies patches, flash grunt and run faft_ec&pd Change-Id: I18fd7e22dc77fe1dc6c21c38cd7f1bc53cae86cb Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1949052 Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2213574 Tested-by: Dawid Niedźwiecki <dn@semihalf.com> Reviewed-by: Edward Hill <ecgh@chromium.org> Commit-Queue: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'include')
-rw-r--r--include/config.h17
-rw-r--r--include/usb_pd.h144
2 files changed, 149 insertions, 12 deletions
diff --git a/include/config.h b/include/config.h
index dd30f529d1..8d29a7c95a 100644
--- a/include/config.h
+++ b/include/config.h
@@ -3235,6 +3235,9 @@
/* Support for USB PD alternate mode of Downward Facing Port */
#undef CONFIG_USB_PD_ALT_MODE_DFP
+/* HPD is sent to the GPU from the EC via a GPIO */
+#undef CONFIG_USB_PD_DP_HPD_GPIO
+
/* Check if max voltage request is allowed before each request */
#undef CONFIG_USB_PD_CHECK_MAX_REQUEST_ALLOWED
@@ -3242,6 +3245,20 @@
#undef CONFIG_USB_PD_COMM_DISABLED
/*
+ * Define this if a board needs custom SNK and/or SRC PDOs.
+ *
+ * The default SRC PDO is a fixed 5V/1.5A with PDO_FIXED_FLAGS indicating
+ * Dual-Role power, USB Communication Capable, and Dual-Role data.
+ *
+ * The default SNK PDOs are:
+ * - Fixed 5V/500mA with the same PDO_FIXED_FLAGS
+ * - Variable (non-battery) min 4.75V, max PD_MAX_VOLTAGE_MV, operational
+ * current 3A
+ * - Battery min 4.75V, max PD_MAX_VOLTAGE_MV, operational power 15W
+ */
+#undef CONFIG_USB_PD_CUSTOM_PDO
+
+/*
* Do not enable PD communication in RO as a security measure.
* We don't want to allow communication to outside world until
* we jump to RW. This can by overridden with the removal of
diff --git a/include/usb_pd.h b/include/usb_pd.h
index ec8025f789..a419c30ceb 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -1135,7 +1135,7 @@ unsigned pd_get_max_voltage(void);
* @mv input voltage
* @return 1 if voltage supported, 0 if not
*/
-int pd_is_valid_input_voltage(int mv);
+__override_proto int pd_is_valid_input_voltage(int mv);
/**
* Request a new operating voltage.
@@ -1160,7 +1160,7 @@ int pd_board_check_request(uint32_t rdo, int pdo_cnt);
*
* param idx index of the new voltage in the source PDO table.
*/
-void pd_transition_voltage(int idx);
+__override_proto void pd_transition_voltage(int idx);
/**
* Go back to the default/safe state of the power supply
@@ -1233,8 +1233,9 @@ typedef uint32_t typec_current_t;
* @param max_ma Maximum current limit
* @param supply_voltage Voltage at which current limit is applied
*/
-void typec_set_input_current_limit(int port, typec_current_t max_ma,
- uint32_t supply_voltage);
+__override_proto void typec_set_input_current_limit(int port,
+ typec_current_t max_ma,
+ uint32_t supply_voltage);
/**
* Set the type-C current limit when sourcing current..
@@ -1249,7 +1250,7 @@ void typec_set_source_current_limit(int port, enum tcpc_rp_value rp);
*
* @return EC_SUCCESS if the board is good, <0 else.
*/
-int pd_board_checks(void);
+__override_proto int pd_board_checks(void);
/**
* Return if VBUS is detected on type-C port
@@ -1272,7 +1273,7 @@ void pd_vbus_low(int port);
* @param port USB-C port number
* @return True if power swap is allowed, False otherwise
*/
-int pd_check_power_swap(int port);
+__override_proto int pd_check_power_swap(int port);
/**
* Check if data swap is allowed.
@@ -1281,7 +1282,7 @@ int pd_check_power_swap(int port);
* @param data_role current data role
* @return True if data swap is allowed, False otherwise
*/
-int pd_check_data_swap(int port, int data_role);
+__override_proto int pd_check_data_swap(int port, int data_role);
/**
* Check if vconn swap is allowed.
@@ -1299,7 +1300,7 @@ int pd_check_vconn_swap(int port);
* @param pr_role Our power role
* @param flags PD flags
*/
-void pd_check_pr_role(int port, int pr_role, int flags);
+__override_proto void pd_check_pr_role(int port, int pr_role, int flags);
/**
* Check current data role for potential data swap
@@ -1308,7 +1309,7 @@ void pd_check_pr_role(int port, int pr_role, int flags);
* @param dr_role Our data role
* @param flags PD flags
*/
-void pd_check_dr_role(int port, int dr_role, int flags);
+__override_proto void pd_check_dr_role(int port, int dr_role, int flags);
/**
* Check if we should charge from this device. This is
@@ -1327,7 +1328,7 @@ int pd_charge_from_device(uint16_t vid, uint16_t pid);
* @param port USB-C port number
* @param data_role new data role
*/
-void pd_execute_data_swap(int port, int data_role);
+__override_proto void pd_execute_data_swap(int port, int data_role);
/**
* Get PD device info used for VDO_CMD_SEND_INFO / VDO_CMD_READ_INFO
@@ -1345,7 +1346,8 @@ void pd_get_info(uint32_t *info_data);
* @param rpayload pointer to the data to send back.
* @return if >0, number of VDOs to send back.
*/
-int pd_custom_vdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload);
+__override_proto int pd_custom_vdm(int port, int cnt, uint32_t *payload,
+ uint32_t **rpayload);
/**
* Handle Structured Vendor Defined Messages
@@ -1463,7 +1465,7 @@ void pd_send_vdm(int port, uint32_t vid, int cmd, const uint32_t *data,
int count);
/* Power Data Objects for the source and the sink */
-extern const uint32_t pd_src_pdo[];
+__override_proto extern const uint32_t pd_src_pdo[];
extern const int pd_src_pdo_cnt;
extern const uint32_t pd_src_pdo_max[];
extern const int pd_src_pdo_max_cnt;
@@ -1888,4 +1890,122 @@ static inline void pd_log_event(uint8_t type, uint8_t size_port,
static inline int pd_vdm_get_log_entry(uint32_t *payload) { return 0; }
#endif /* CONFIG_USB_PD_LOGGING */
+/* ----- SVDM handlers ----- */
+
+/* DisplayPort Alternate Mode */
+#ifdef CONFIG_USB_PD_ALT_MODE_DFP
+extern int dp_flags[CONFIG_USB_PD_PORT_COUNT];
+extern uint32_t dp_status[CONFIG_USB_PD_PORT_COUNT];
+#endif /* CONFIG_USB_PD_ALT_MODE_DFP */
+/**
+ * Configure the pins used for DisplayPort Alternate Mode into safe state.
+ *
+ * @param port The PD port number
+ */
+__override_proto void svdm_safe_dp_mode(int port);
+
+/**
+ * Enter DisplayPort Alternate Mode.
+ *
+ * The default implementation will only enter DP Alt Mode if the SoC is on.
+ * Also, it may notify the AP that the mode was entered.
+ *
+ * @param port The PD port number
+ * @param mode_caps Bitmask indicating DisplayPort mode capabilities
+ * @return 0 if mode is entered, -1 otherwise.
+ */
+__override_proto int svdm_enter_dp_mode(int port, uint32_t mode_caps);
+
+/**
+ * Construct a DP status response.
+ *
+ * @param port The PD port number
+ * @param payload Pointer to the PDO payload which is filled with the DPStatus
+ * information.
+ * @return number of VDOs
+ */
+__override_proto int svdm_dp_status(int port, uint32_t *payload);
+
+/**
+ * Configure the pins used for DisplayPort Alternate Mode.
+ *
+ * @param port The PD port number
+ * @payload payload Pointer to the PDO payload which is filled with the
+ * DPConfigure response message
+ * @return number of VDOs
+ */
+__override_proto int svdm_dp_config(int port, uint32_t *payload);
+
+/**
+ * Perform any other work required after configuring the pins for DP Alt Mode.
+ *
+ * Typically, this involves sending the HPD signal from either the EC or TCPC to
+ * the GPU.
+ * @param port The PD port number
+ */
+__override_proto void svdm_dp_post_config(int port);
+
+/**
+ * Called when a DisplayPort Attention command is received
+ *
+ * The default implementation will parse the Attention message and indicate the
+ * HPD level to the GPU.
+ *
+ * @param port The PD port number
+ * @param payload Pointer to the payload received from the attention command
+ * @return 0 for NAK, 1 for ACK
+ */
+__override_proto int svdm_dp_attention(int port, uint32_t *payload);
+
+/**
+ * Exit DisplayPort Alternate Mode.
+ *
+ * @param port The PD port number
+ */
+__override_proto void svdm_exit_dp_mode(int port);
+
+/* Google Firmware Update Alternate Mode */
+/**
+ * Enter Google Firmware Update (GFU) Mode.
+ *
+ * @param port The PD port number
+ * @param mode_caps Unused for GFU
+ * @return 0 to enter the mode, -1 otherwise
+ */
+__override_proto int svdm_enter_gfu_mode(int port, uint32_t mode_caps);
+
+/**
+ * Exit Google Firmware Update Mode.
+ *
+ * @param port The PD port number
+ */
+__override_proto void svdm_exit_gfu_mode(int port);
+
+/**
+ * Called after successful entry into GFU Mode
+ *
+ * The default implementation sends VDO_CMD_READ_INFO.
+ * @param port The PD port number
+ * @param payload Unused for GFU
+ * @return The number of VDOs
+ */
+__override_proto int svdm_gfu_status(int port, uint32_t *payload);
+
+/**
+ * Configure any pins needed for GFU Mode
+ *
+ * @param port The PD port number
+ * @param payload Unused for GFU
+ * @return The number of VDOs
+ */
+__override_proto int svdm_gfu_config(int port, uint32_t *payload);
+
+/**
+ * Called when an Attention Message is received
+ *
+ * @param port The PD port number
+ * @param payload Unusued for GFU
+ * @return The number of VDOs
+ */
+__override_proto int svdm_gfu_attention(int port, uint32_t *payload);
#endif /* __CROS_EC_USB_PD_H */