summaryrefslogtreecommitdiff
path: root/common/usb_pd_dual_role.c
diff options
context:
space:
mode:
authorEric Yilun Lin <yllin@chromium.org>2021-05-14 15:36:41 +0800
committerCommit Bot <commit-bot@chromium.org>2021-09-01 02:11:16 +0000
commit61bbfcaa37ecec87a9cea89e0f8fc65ecbecd13e (patch)
treef37906b9bb648028e8613e6069fa515b07b1db6f /common/usb_pd_dual_role.c
parent272e74878f45d744dfebad5847f0f32ed5cbb137 (diff)
downloadchrome-ec-61bbfcaa37ecec87a9cea89e0f8fc65ecbecd13e.tar.gz
usbpd: support dynamic PDO selection
Support dynamic PDO selection CONFIG_USB_PD_DPS. This config controls the charging voltage and power according to the input power and battery configuration. DPS would continuously evaluate the system load and current charging voltage, and decide a new one by below: 1. If the PDO can fulfill system desired power. 2. If the PDO is efficient for the battery configuration. To detect if the system load cannot be fulfilled by the current PDO, it checks: 1. if the input current closes to the PDO current limit. 2. if the input power closes to the PDO maximum power. To detect if the system load can be fulfilled by a more efficient PDO, it checks: - if the voltage of a new PDO is closer to the battery voltage than the current PDO, and the power is able fulfill the system load. BUG=b:169532537 TEST=1. tested on asurada, the charging voltage is able to switch to different PDOs under different system loads 2. tested that the DPS is able to switch charge port (e.g. C1 12V -> C0 9V) based on the provided PDOs. BRANCH=asurada Change-Id: I7c7706b331dc0d4f8ac68569dc7ed852fc9308e3 Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2897064 Tested-by: Eric Yilun Lin <yllin@google.com> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Eric Yilun Lin <yllin@google.com>
Diffstat (limited to 'common/usb_pd_dual_role.c')
-rw-r--r--common/usb_pd_dual_role.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/common/usb_pd_dual_role.c b/common/usb_pd_dual_role.c
index ae8429262d..3981353101 100644
--- a/common/usb_pd_dual_role.c
+++ b/common/usb_pd_dual_role.c
@@ -7,6 +7,7 @@
#include "charge_manager.h"
#include "charge_state.h"
+#include "dps.h"
#include "system.h"
#include "usb_common.h"
#include "usb_pd.h"
@@ -21,6 +22,7 @@
*/
static unsigned int max_request_mv = PD_MAX_VOLTAGE_MV;
+/* TODO(b:169532537): deprecate CONFIG_USB_PD_PREFER_MV */
STATIC_IF_NOT(CONFIG_USB_PD_PREFER_MV)
struct pd_pref_config_t __maybe_unused pd_pref_config;
@@ -236,6 +238,10 @@ void pd_build_request(int32_t vpd_vdo, uint32_t *rdo, uint32_t *ma,
else
max_request_allowed = 1;
+ if (IS_ENABLED(CONFIG_USB_PD_DPS) && dps_is_enabled())
+ max_request_mv =
+ MIN(max_request_mv, dps_get_dynamic_voltage());
+
/*
* If currently charging on a different port, or we are not allowed to
* request the max voltage, then select vSafe5V
@@ -342,11 +348,15 @@ void pd_process_source_cap(int port, int cnt, uint32_t *src_caps)
if (IS_ENABLED(CONFIG_CHARGE_MANAGER)) {
uint32_t ma, mv, pdo, unused;
+ uint32_t max_mv = pd_get_max_voltage();
+
+ if (IS_ENABLED(CONFIG_USB_PD_DPS) && dps_is_enabled())
+ max_mv = MIN(max_mv, dps_get_dynamic_voltage());
/* Get max power info that we could request */
pd_find_pdo_index(pd_get_src_cap_cnt(port),
pd_get_src_caps(port),
- pd_get_max_voltage(), &pdo);
+ max_mv, &pdo);
pd_extract_pdo_power(pdo, &ma, &mv, &unused);
/* Set max. limit, but apply 500mA ceiling */