summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTing Shen <phoenixshen@google.com>2023-02-21 15:52:58 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-02-24 08:56:12 +0000
commitf34bcdc53cf6a874ef67b4a93331261390bae013 (patch)
tree119fc9accd5ed08ec5a390b8e1182434ef044b54
parent9239f343bc9bf69aac3cf6438a4d34ba3e578a7e (diff)
downloadchrome-ec-f34bcdc53cf6a874ef67b4a93331261390bae013.tar.gz
zephyr: make bc1.2 optional
For devices that don't support bc1.2, the code should not depend on anything related to usb_charge module (e.g. bc12_ports) BUG=b:269989432 TEST=zmake build --all BRANCH=none Change-Id: I6be47485bbd606f93a581d1638b3402337233b7c Signed-off-by: Ting Shen <phoenixshen@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4274111 Reviewed-by: Eric Yilun Lin <yllin@google.com> Tested-by: Ting Shen <phoenixshen@chromium.org> Commit-Queue: Ting Shen <phoenixshen@chromium.org>
-rw-r--r--common/charge_ramp.c8
-rw-r--r--zephyr/shim/src/CMakeLists.txt4
-rw-r--r--zephyr/test/drivers/default/CMakeLists.txt1
-rw-r--r--zephyr/test/drivers/default/src/charge_ramp.c59
4 files changed, 71 insertions, 1 deletions
diff --git a/common/charge_ramp.c b/common/charge_ramp.c
index 2c84087e21..fcea02d1c7 100644
--- a/common/charge_ramp.c
+++ b/common/charge_ramp.c
@@ -44,8 +44,11 @@ test_mockable int chg_ramp_allowed(int port, int supplier)
/* default: fall through */
}
+#ifdef CONFIG_USB_CHARGER
/* Otherwise ask the BC1.2 detect module */
return usb_charger_ramp_allowed(port, supplier);
+#endif
+ return 0;
}
test_mockable int chg_ramp_max(int port, int supplier, int sup_curr)
@@ -53,6 +56,8 @@ test_mockable int chg_ramp_max(int port, int supplier, int sup_curr)
switch (supplier) {
case CHARGE_SUPPLIER_PD:
case CHARGE_SUPPLIER_TYPEC:
+ return 0;
+
case CHARGE_SUPPLIER_TYPEC_DTS:
/*
* We should not ramp DTS beyond what they advertise, otherwise
@@ -62,6 +67,9 @@ test_mockable int chg_ramp_max(int port, int supplier, int sup_curr)
/* default: fall through */
}
+#ifdef CONFIG_USB_CHARGER
/* Otherwise ask the BC1.2 detect module */
return usb_charger_ramp_max(port, supplier, sup_curr);
+#endif
+ return 0;
}
diff --git a/zephyr/shim/src/CMakeLists.txt b/zephyr/shim/src/CMakeLists.txt
index 5c77156ef5..8ab6c6b016 100644
--- a/zephyr/shim/src/CMakeLists.txt
+++ b/zephyr/shim/src/CMakeLists.txt
@@ -65,8 +65,10 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_TIMER hwtimer.c)
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_I2C i2c.c)
zephyr_library_sources_ifdef(CONFIG_SHIMMED_TASKS tasks.c)
zephyr_library_sources_ifdef(CONFIG_WATCHDOG watchdog.c)
-zephyr_library_sources_ifndef(CONFIG_PLATFORM_EC_BC12_SINGLE_DRIVER
+if (DEFINED CONFIG_PLATFORM_EC_USB_CHARGER)
+ zephyr_library_sources_ifndef(CONFIG_PLATFORM_EC_BC12_SINGLE_DRIVER
bc12.c)
+endif()
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_BC12_DETECT_PI3USB9201
bc12_pi3usb9201.c)
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USBC_PPC ppc.c)
diff --git a/zephyr/test/drivers/default/CMakeLists.txt b/zephyr/test/drivers/default/CMakeLists.txt
index 305c58be82..3bcb408f5e 100644
--- a/zephyr/test/drivers/default/CMakeLists.txt
+++ b/zephyr/test/drivers/default/CMakeLists.txt
@@ -6,6 +6,7 @@ target_sources(app PRIVATE
src/bmi160.c
src/bmi260.c
src/charge_manager.c
+ src/charge_ramp.c
src/charge_state_prevent_power_on.c
src/console.c
src/cros_cbi.c
diff --git a/zephyr/test/drivers/default/src/charge_ramp.c b/zephyr/test/drivers/default/src/charge_ramp.c
new file mode 100644
index 0000000000..3511b56001
--- /dev/null
+++ b/zephyr/test/drivers/default/src/charge_ramp.c
@@ -0,0 +1,59 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "charge_manager.h"
+#include "charge_ramp.h"
+#include "system.h"
+#include "system_fake.h"
+#include "test/drivers/test_mocks.h"
+
+#include <zephyr/fff.h>
+#include <zephyr/ztest.h>
+
+static void charge_ramp_before(void *state)
+{
+ ARG_UNUSED(state);
+ RESET_FAKE(system_is_locked);
+}
+
+static void charge_ramp_after(void *state)
+{
+ ARG_UNUSED(state);
+ RESET_FAKE(system_is_locked);
+}
+
+/* Test ramping logic.
+ *
+ * Not testing BC1.2 chargers because driver tests should cover them.
+ */
+ZTEST_USER(charge_ramp, test_ramp)
+{
+ zassert_equal(chg_ramp_allowed(0, CHARGE_SUPPLIER_PD), 0);
+ zassert_equal(chg_ramp_max(0, CHARGE_SUPPLIER_PD, 1234), 0);
+
+ zassert_equal(chg_ramp_allowed(0, CHARGE_SUPPLIER_TYPEC), 0);
+ zassert_equal(chg_ramp_max(0, CHARGE_SUPPLIER_TYPEC, 1234), 0);
+
+ zassert_equal(chg_ramp_allowed(0, CHARGE_SUPPLIER_TYPEC_DTS), 1);
+ zassert_equal(chg_ramp_max(0, CHARGE_SUPPLIER_TYPEC_DTS, 1234), 1234);
+}
+
+/* Disable ramping in locked RO */
+ZTEST_USER(charge_ramp, test_ramp_locked)
+{
+ enum ec_image old_image = system_get_shrspi_image_copy();
+
+ system_set_shrspi_image_copy(EC_IMAGE_RO);
+ zassert_false(system_is_in_rw());
+
+ system_is_locked_fake.return_val = 1;
+
+ zassert_equal(chg_ramp_allowed(0, CHARGE_SUPPLIER_TYPEC_DTS), 0);
+
+ system_set_shrspi_image_copy(old_image);
+}
+
+ZTEST_SUITE(charge_ramp, NULL, NULL, charge_ramp_before, charge_ramp_after,
+ NULL);