summaryrefslogtreecommitdiff
path: root/include
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 /include
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 'include')
-rw-r--r--include/config.h9
-rw-r--r--include/dps.h71
2 files changed, 80 insertions, 0 deletions
diff --git a/include/config.h b/include/config.h
index 1366d86662..f157047273 100644
--- a/include/config.h
+++ b/include/config.h
@@ -4115,6 +4115,15 @@
#undef CONFIG_USB_PD_TCPMV2
/*
+ * Enable dynamic PDO selection.
+ *
+ * DPS picks a power efficient voltage regarding to the battery configuration
+ * and the system loading. It monitors PIn (Power In), so VBUS/IBUS ADC
+ * should be supported on the platform.
+ */
+#undef CONFIG_USB_PD_DPS
+
+/*
* Device Types for TCPMv2.
*
* Exactly one must be defined when CONFIG_USB_PD_TCPMV2 is defined.
diff --git a/include/dps.h b/include/dps.h
new file mode 100644
index 0000000000..151c6b3f09
--- /dev/null
+++ b/include/dps.h
@@ -0,0 +1,71 @@
+/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef __CROS_EC_DPS__H
+#define __CROS_EC_DPS__H
+
+#include <stdbool.h>
+
+#include "common.h"
+
+/* Dynamic PDO Selection config. */
+struct dps_config_t {
+ /* (0, 100) coeff for transition to a lower power PDO*/
+ uint32_t k_less_pwr;
+ /* (0, 100) coeff for transition to a higher power PDO*/
+ uint32_t k_more_pwr;
+ /* Number for how many the same consecutive sample to transist */
+ uint32_t k_sample;
+ /* Number for moving average window for the power and the current. */
+ uint32_t k_window;
+ /* Power stabilized time after a new contract in us */
+ uint32_t t_stable;
+ /* Next power evaluation time interval in us */
+ uint32_t t_check;
+ /*
+ * If the current voltage is more efficient than the previous voltage
+ *
+ * @param curr_mv: current PDO voltage
+ * @param prev_mv: previous PDO voltage
+ * @param batt_mv: battery desired voltage
+ * @param batt_mw: current battery power
+ * @param input_mw: current adapter input power
+ * @return true is curr_mv is more efficient otherwise false
+ */
+ bool (*is_more_efficient)(int curr_mv, int prev_mv, int batt_mv,
+ int batt_mw, int input_mw);
+};
+
+/*
+ * Get voltage in the current system load
+ *
+ * @return a voltage(mV) that the adapter supports to charge at the given port.
+ */
+int dps_get_dynamic_voltage(void);
+
+/*
+ * Get DPS charge port
+ *
+ * @return the DPS charge port, or CHARGE_PORT_NONE if unavailable.
+ */
+int dps_get_charge_port(void);
+
+/*
+ * Check if DPS is enabled.
+ *
+ * @return true if enabled, false otherwise.
+ */
+bool dps_is_enabled(void);
+
+/*
+ * Update DPS stablized timeout
+ *
+ * This is called at the exit of PE_SNK_TRANSITION_SINK
+ *
+ * @param port: the port for timer reset.
+ */
+void dps_update_stabilized_time(int port);
+
+#endif /* __CROS_EC_DPS__H */