summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2021-02-01 14:54:38 -0700
committerCommit Bot <commit-bot@chromium.org>2021-02-09 17:17:05 +0000
commitb3493801225cb9aa6aa98783e8d50a50d41c1e05 (patch)
treed911088573b7ee5a0b0689fef35d0b00e7b465e1
parent86c1ed0487f3cb4a4942b1cbf745e304cc942016 (diff)
downloadchrome-ec-b3493801225cb9aa6aa98783e8d50a50d41c1e05.tar.gz
TCPMv2: Report correct source-out current in host command
The EC_CMD_USB_PD_POWER_INFO host command was still querying the older charge_manager source current tracking. Instead, when TCPMv2 is defined the DPM should be treated as the authority for source-out current. BRANCH=None BUG=b:177714628 TEST=on drawcia, connect hub requiring 3A and confirm that value is reported from "ectool usbpdpower" Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I65f4fb976f0ab90f4d20f6573c1002ed80ff9532 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2676081 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2681292 Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Commit-Queue: Abe Levkoy <alevkoy@chromium.org> Tested-by: Abe Levkoy <alevkoy@chromium.org>
-rw-r--r--common/charge_manager.c17
-rw-r--r--common/usbc/usb_pd_dpm.c13
-rw-r--r--include/usb_pd_dpm.h8
3 files changed, 33 insertions, 5 deletions
diff --git a/common/charge_manager.c b/common/charge_manager.c
index a6307fe318..e113179372 100644
--- a/common/charge_manager.c
+++ b/common/charge_manager.c
@@ -18,6 +18,7 @@
#include "tcpm/tcpm.h"
#include "timer.h"
#include "usb_pd.h"
+#include "usb_pd_dpm.h"
#include "usb_pd_tcpm.h"
#include "util.h"
@@ -108,7 +109,8 @@ static int override_port = OVERRIDE_OFF;
static int delayed_override_port = OVERRIDE_OFF;
static timestamp_t delayed_override_deadline;
-static uint8_t source_port_rp[CONFIG_USB_PD_PORT_MAX_COUNT];
+/* Source-out Rp values for TCPMv1 */
+__maybe_unused static uint8_t source_port_rp[CONFIG_USB_PD_PORT_MAX_COUNT];
#ifdef CONFIG_USB_PD_MAX_TOTAL_SOURCE_CURRENT
/* 3A on one port and 1.5A on the rest */
@@ -226,7 +228,7 @@ static void charge_manager_init(void)
charge_ceil[i][j] = CHARGE_CEIL_NONE;
if (!is_pd_port(i))
dualrole_capability[i] = CAP_DEDICATED;
- if (is_pd_port(i))
+ if (is_pd_port(i) && !IS_ENABLED(CONFIG_USB_PD_TCPMV2))
source_port_rp[i] = CONFIG_USB_PD_PULLUP;
}
}
@@ -269,7 +271,7 @@ static int charge_manager_is_seeded(void)
* @param port Charge port.
* @return Charge current (mA).
*/
-static int charge_manager_get_source_current(int port)
+__maybe_unused static int charge_manager_get_source_current(int port)
{
if (!is_pd_port(port))
return 0;
@@ -409,8 +411,13 @@ static void charge_manager_fill_power_info(int port,
r->meas.voltage_max = 0;
r->meas.voltage_now =
r->role == USB_PD_PORT_POWER_SOURCE ? 5000 : 0;
- r->meas.current_max =
- charge_manager_get_source_current(port);
+ /* TCPMv2 tracks source-out current in the DPM */
+ if (IS_ENABLED(CONFIG_USB_PD_TCPMV2))
+ r->meas.current_max =
+ dpm_get_source_current(port);
+ else
+ r->meas.current_max =
+ charge_manager_get_source_current(port);
r->max_power = 0;
} else {
r->type = USB_CHG_TYPE_NONE;
diff --git a/common/usbc/usb_pd_dpm.c b/common/usbc/usb_pd_dpm.c
index 9b42119bef..b1e6bad468 100644
--- a/common/usbc/usb_pd_dpm.c
+++ b/common/usbc/usb_pd_dpm.c
@@ -474,3 +474,16 @@ __overridable int dpm_get_source_pdo(const uint32_t **src_pdo, const int port)
*src_pdo = pd_src_pdo;
return pd_src_pdo_cnt;
}
+
+int dpm_get_source_current(const int port)
+{
+ if (pd_get_power_role(port) == PD_ROLE_SINK)
+ return 0;
+
+ if (max_current_claimed & BIT(port))
+ return 3000;
+ else if (CONFIG_USB_PD_PULLUP == TYPEC_RP_1A5)
+ return 1500;
+ else
+ return 500;
+}
diff --git a/include/usb_pd_dpm.h b/include/usb_pd_dpm.h
index d897c8ce84..d0e49a7383 100644
--- a/include/usb_pd_dpm.h
+++ b/include/usb_pd_dpm.h
@@ -84,4 +84,12 @@ void dpm_remove_sink(int port);
*/
int dpm_get_source_pdo(const uint32_t **src_pdo, const int port);
+/*
+ * Report offered source current for this port
+ *
+ * @param port USB-C port number
+ * @return Current offered, in mA
+ */
+int dpm_get_source_current(const int port);
+
#endif /* __CROS_EC_USB_DPM_H */