From f34bcdc53cf6a874ef67b4a93331261390bae013 Mon Sep 17 00:00:00 2001 From: Ting Shen Date: Tue, 21 Feb 2023 15:52:58 +0800 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4274111 Reviewed-by: Eric Yilun Lin Tested-by: Ting Shen Commit-Queue: Ting Shen --- common/charge_ramp.c | 8 ++++ zephyr/shim/src/CMakeLists.txt | 4 +- zephyr/test/drivers/default/CMakeLists.txt | 1 + zephyr/test/drivers/default/src/charge_ramp.c | 59 +++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 zephyr/test/drivers/default/src/charge_ramp.c 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 +#include + +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); -- cgit v1.2.1