From 9256eb74d075a68e00b2d63f3c1e3b890745858e Mon Sep 17 00:00:00 2001 From: Yuval Peress Date: Tue, 14 Sep 2021 00:36:49 -0600 Subject: zephyr: test: drivers: Use the LN9310 emulator Test the LN9310 init function for both 2S and 3S battery types. BRANCH=none BUG=b:184856083 TEST=zmake configure --test zephyr/test/drivers Signed-off-by: Yuval Peress Change-Id: I6c6804657377cab615f7af6661839b019ab88a8a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3159648 Commit-Queue: Yuval Peress Tested-by: Yuval Peress Reviewed-by: Jeremy Bettis --- zephyr/test/drivers/overlay.dts | 12 ++++++++++ zephyr/test/drivers/prj.conf | 1 + zephyr/test/drivers/src/ln9310.c | 48 ++++++++++++++++++++++++++++++++++++++++ zephyr/test/drivers/src/main.c | 2 ++ 4 files changed, 63 insertions(+) create mode 100644 zephyr/test/drivers/src/ln9310.c diff --git a/zephyr/test/drivers/overlay.dts b/zephyr/test/drivers/overlay.dts index 9ca18812b2..56027a7138 100644 --- a/zephyr/test/drivers/overlay.dts +++ b/zephyr/test/drivers/overlay.dts @@ -75,6 +75,11 @@ enum-name = "I2C_PORT_BATTERY"; label = "BATTERY"; }; + power { + i2c-port = <&i2c0>; + enum-name = "I2C_PORT_POWER"; + label = "POWER"; + }; charger { i2c-port = <&i2c0>; enum-name = "I2C_PORT_CHARGER"; @@ -483,4 +488,11 @@ error-on-ro-write; error-on-reserved-bit-write; }; + + ln9310: ln9310@80 { + compatible = "cros,ln9310-emul"; + status = "okay"; + reg = <0x80>; + label = "LN9310"; + }; }; diff --git a/zephyr/test/drivers/prj.conf b/zephyr/test/drivers/prj.conf index 4a6e981d7a..ff7f93b918 100644 --- a/zephyr/test/drivers/prj.conf +++ b/zephyr/test/drivers/prj.conf @@ -55,6 +55,7 @@ CONFIG_PLATFORM_EC_STEINHART_HART_3V0_22K6_47K_4050B=y CONFIG_PLATFORM_EC_STEINHART_HART_3V3_13K7_47K_4050B=y CONFIG_PLATFORM_EC_STEINHART_HART_3V3_30K9_47K_4050B=y CONFIG_PLATFORM_EC_STEINHART_HART_3V3_51K1_47K_4050B=y +CONFIG_PLATFORM_EC_SWITCHCAP_LN9310=y CONFIG_PLATFORM_EC_ACCEL_BMA255=y CONFIG_PLATFORM_EC_MOTIONSENSE=y CONFIG_PLATFORM_EC_ACCELGYRO_BMI160=y diff --git a/zephyr/test/drivers/src/ln9310.c b/zephyr/test/drivers/src/ln9310.c new file mode 100644 index 0000000000..d41625f98f --- /dev/null +++ b/zephyr/test/drivers/src/ln9310.c @@ -0,0 +1,48 @@ +/* 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. + */ + +#include +#include +#include "driver/ln9310.h" +#include "emul/emul_ln9310.h" + +void test_ln9310_2s_no_startup__passes_init(void) +{ + const struct emul *emulator = + emul_get_binding(DT_LABEL(DT_NODELABEL(ln9310))); + + zassert_not_null(emulator, NULL); + + ln9310_emul_set_context(emulator); + ln9310_emul_reset(emulator); + ln9310_emul_set_battery_cell_type(emulator, BATTERY_CELL_TYPE_2S); + ln9310_emul_set_version(emulator, LN9310_BC_STS_C_CHIP_REV_FIXED); + + zassert_ok(ln9310_init(), NULL); +} + +void test_ln9310_3s_no_startup__passes_init(void) +{ + const struct emul *emulator = + emul_get_binding(DT_LABEL(DT_NODELABEL(ln9310))); + + zassert_not_null(emulator, NULL); + + ln9310_emul_set_context(emulator); + ln9310_emul_reset(emulator); + ln9310_emul_set_battery_cell_type(emulator, BATTERY_CELL_TYPE_3S); + ln9310_emul_set_version(emulator, LN9310_BC_STS_C_CHIP_REV_FIXED); + + zassert_ok(ln9310_init(), NULL); +} + +void test_suite_ln9310(void) +{ + ztest_test_suite( + ln9310, + ztest_unit_test(test_ln9310_2s_no_startup__passes_init), + ztest_unit_test(test_ln9310_3s_no_startup__passes_init)); + ztest_run_test_suite(ln9310); +} diff --git a/zephyr/test/drivers/src/main.c b/zephyr/test/drivers/src/main.c index 3336baeda5..5237f74c2f 100644 --- a/zephyr/test/drivers/src/main.c +++ b/zephyr/test/drivers/src/main.c @@ -20,6 +20,7 @@ extern void test_suite_bmi160(void); extern void test_suite_tcs3400(void); extern void test_suite_espi(void); extern void test_suite_bb_retimer(void); +extern void test_suite_ln9310(void); void test_main(void) { @@ -41,4 +42,5 @@ void test_main(void) test_suite_tcs3400(); test_suite_espi(); test_suite_bb_retimer(); + test_suite_ln9310(); } -- cgit v1.2.1