summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorVijay Hiremath <vijay.p.hiremath@intel.com>2020-02-11 16:24:41 -0800
committerCommit Bot <commit-bot@chromium.org>2020-02-14 00:17:11 +0000
commiteb3344e698973f61559614f9b0aaa6c0282e9e11 (patch)
treea9f4c1b886c1c7bc016d514a0737dc992d8bcb1d /common
parent35bb4afa2a1d69b12f77e74c77dfa65cc350781a (diff)
downloadchrome-ec-eb3344e698973f61559614f9b0aaa6c0282e9e11.tar.gz
TCPMv1/v2: Reduce number of arguments of pd_build_request()
BUG=b:148528713 BRANCH=none TEST=Manually tested on Volteer 1. When only one charger connected: Able to negotiate to PD max. 2. When two chargers are connected (one on each port): Non charging port is rejected Swaps the charging port based on charger's priority Change-Id: Ib7fdc5d31bf36189a85f8cd3217bec78f83a9efe Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2051318 Reviewed-by: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/usb_pd_dual_role.c45
-rw-r--r--common/usb_pd_protocol.c33
-rw-r--r--common/usbc/usb_pe_drp_sm.c23
3 files changed, 40 insertions, 61 deletions
diff --git a/common/usb_pd_dual_role.c b/common/usb_pd_dual_role.c
index b2b6c25aae..ce90d95d3c 100644
--- a/common/usb_pd_dual_role.c
+++ b/common/usb_pd_dual_role.c
@@ -173,10 +173,8 @@ void pd_extract_pdo_power(uint32_t pdo, uint32_t *ma, uint32_t *mv)
*ma = MIN(max_ma, PD_MAX_CURRENT_MA);
}
-void pd_build_request(uint32_t src_cap_cnt, const uint32_t * const src_caps,
- int32_t vpd_vdo, uint32_t *rdo, uint32_t *ma,
- uint32_t *mv, enum pd_request_type req_type,
- uint32_t max_request_mv, int port)
+void pd_build_request(int32_t vpd_vdo, uint32_t *rdo, uint32_t *ma,
+ uint32_t *mv, int port)
{
uint32_t pdo;
int pdo_index, flags = 0;
@@ -186,15 +184,46 @@ void pd_build_request(uint32_t src_cap_cnt, const uint32_t * const src_caps,
int max_vbus;
int vpd_vbus_dcr;
int vpd_gnd_dcr;
+ uint32_t src_cap_cnt = pd_get_src_cap_cnt(port);
+ const uint32_t * const src_caps = pd_get_src_caps(port);
+ int charging_allowed;
+ int max_request_allowed;
+ uint32_t max_request_mv = pd_get_max_voltage();
- if (req_type == PD_REQUEST_VSAFE5V) {
- /* src cap 0 should be vSafe5V */
- pdo_index = 0;
- pdo = src_caps[0];
+ /*
+ * If this port is the current charge port, or if there isn't an active
+ * charge port, set this value to true. If CHARGE_PORT_NONE isn't
+ * considered, then there can be a race condition in PD negotiation and
+ * the charge manager which forces an incorrect request for
+ * vSafe5V. This can then lead to a brownout condition when the input
+ * current limit gets incorrectly set to 0.5A.
+ */
+ if (IS_ENABLED(CONFIG_CHARGE_MANAGER)) {
+ int chg_port = charge_manager_get_active_charge_port();
+
+ charging_allowed =
+ (chg_port == port || chg_port == CHARGE_PORT_NONE);
} else {
+ charging_allowed = 1;
+ }
+
+ if (IS_ENABLED(CONFIG_USB_PD_CHECK_MAX_REQUEST_ALLOWED))
+ max_request_allowed = pd_is_max_request_allowed();
+ else
+ max_request_allowed = 1;
+
+ /*
+ * If currently charging on a different port, or we are not allowed to
+ * request the max voltage, then select vSafe5V
+ */
+ if (charging_allowed && max_request_allowed) {
/* find pdo index for max voltage we can request */
pdo_index = pd_find_pdo_index(src_cap_cnt, src_caps,
max_request_mv, &pdo);
+ } else {
+ /* src cap 0 should be vSafe5V */
+ pdo_index = 0;
+ pdo = src_caps[0];
}
pd_extract_pdo_power(pdo, ma, mv);
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index 4f283fd386..9b0993b20f 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -1481,42 +1481,11 @@ static int pd_send_request_msg(int port, int always_send_request)
uint32_t rdo, curr_limit, supply_voltage;
int res;
-#ifdef CONFIG_CHARGE_MANAGER
- /*
- * If this port is the current charge port, or if there isn't an active
- * charge port, set this value to true. If CHARGE_PORT_NONE isn't
- * considered, then there can be a race condition in PD negotiation and
- * the charge manager which forces an incorrect request for
- * vSafe5V. This can then lead to a brownout condition when the input
- * current limit gets incorrectly set to 0.5A.
- */
- int charging_allowed = ((charge_manager_get_active_charge_port() ==
- port) ||
- (charge_manager_get_active_charge_port() ==
- CHARGE_PORT_NONE));
-#else
- const int charging_allowed = 1;
-#endif
-
-#ifdef CONFIG_USB_PD_CHECK_MAX_REQUEST_ALLOWED
- int max_request_allowed = pd_is_max_request_allowed();
-#else
- const int max_request_allowed = 1;
-#endif
-
/* Clear new power request */
pd[port].new_power_request = 0;
/* Build and send request RDO */
- /*
- * If currently charging on a different port, or we are not allowed to
- * request the max voltage, then select vSafe5V
- */
- pd_build_request(pd_get_src_cap_cnt(port), pd_get_src_caps(port), 0,
- &rdo, &curr_limit, &supply_voltage,
- charging_allowed && max_request_allowed ?
- PD_REQUEST_MAX : PD_REQUEST_VSAFE5V,
- pd_get_max_voltage(), port);
+ pd_build_request(0, &rdo, &curr_limit, &supply_voltage, port);
if (!always_send_request) {
/* Don't re-request the same voltage */
diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c
index 1581a26e41..5143bbd3a0 100644
--- a/common/usbc/usb_pe_drp_sm.c
+++ b/common/usbc/usb_pe_drp_sm.c
@@ -835,29 +835,10 @@ static void pe_send_request_msg(int port)
uint32_t rdo;
uint32_t curr_limit;
uint32_t supply_voltage;
- int charging;
- int max_request_allowed;
-
- if (IS_ENABLED(CONFIG_CHARGE_MANAGER))
- charging = (charge_manager_get_active_charge_port() == port);
- else
- charging = 1;
-
- if (IS_ENABLED(CONFIG_USB_PD_CHECK_MAX_REQUEST_ALLOWED))
- max_request_allowed = pd_is_max_request_allowed();
- else
- max_request_allowed = 1;
/* Build and send request RDO */
- /*
- * If this port is not actively charging or we are not allowed to
- * request the max voltage, then select vSafe5V
- */
- pd_build_request(pe[port].src_cap_cnt, pe[port].src_caps,
- pe[port].vpd_vdo, &rdo, &curr_limit,
- &supply_voltage, charging && max_request_allowed ?
- PD_REQUEST_MAX : PD_REQUEST_VSAFE5V,
- pd_get_max_voltage(), port);
+ pd_build_request(pe[port].vpd_vdo, &rdo, &curr_limit,
+ &supply_voltage, port);
CPRINTF("C%d Req [%d] %dmV %dmA", port, RDO_POS(rdo),
supply_voltage, curr_limit);