diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2023-04-07 15:28:13 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-04-12 18:43:39 +0000 |
commit | 7bc2e12e1ee125bd124ef4de463cb2764e91e14c (patch) | |
tree | 019c47fbc93ad11bbffb1b6d7c668e1f623ce526 | |
parent | 405c611c07fac37ec12299b308437c44f66058c9 (diff) | |
download | chrome-ec-7bc2e12e1ee125bd124ef4de463cb2764e91e14c.tar.gz |
ISL9241: Fix ACProchot reg <-> mA conversion
This CL fixes expressions used to convert ACProchot register values
to/from the current.
There is no functionality change because the register happens to use
identical conversion. That is, 128 mA <-> 0x80, for example.
BUG=b:277280318
BRANCH=None
TEST=./twister --toolchain host -T zephyr/test/drivers -s drivers.isl9241
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Change-Id: I7c2d6c8b1819c5031306de4ea421193828359290
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4409985
Commit-Queue: Paul Fagerburg <pfagerburg@chromium.org>
Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
-rw-r--r-- | driver/charger/isl9241.c | 21 | ||||
-rw-r--r-- | driver/charger/isl9241.h | 13 | ||||
-rw-r--r-- | zephyr/test/drivers/isl9241/src/isl9241.c | 4 |
3 files changed, 19 insertions, 19 deletions
diff --git a/driver/charger/isl9241.c b/driver/charger/isl9241.c index 5f3566095c..266150f2eb 100644 --- a/driver/charger/isl9241.c +++ b/driver/charger/isl9241.c @@ -28,19 +28,6 @@ #error "ISL9241 is a NVDC charger, please enable CONFIG_CHARGER_NARROW_VDC." #endif -/* Sense resistor default values in milli Ohm */ -#define ISL9241_DEFAULT_RS1 20 /* Input current sense resistor */ -#define ISL9241_DEFAULT_RS2 10 /* Battery charge current sense resistor */ - -#define BOARD_RS1 CONFIG_CHARGER_SENSE_RESISTOR_AC -#define BOARD_RS2 CONFIG_CHARGER_SENSE_RESISTOR - -#define BC_REG_TO_CURRENT(REG) (((REG)*ISL9241_DEFAULT_RS2) / BOARD_RS2) -#define BC_CURRENT_TO_REG(CUR) (((CUR)*BOARD_RS2) / ISL9241_DEFAULT_RS2) - -#define AC_REG_TO_CURRENT(REG) (((REG)*ISL9241_DEFAULT_RS1) / BOARD_RS1) -#define AC_CURRENT_TO_REG(CUR) (((CUR)*BOARD_RS1) / ISL9241_DEFAULT_RS1) - /* Console output macros */ #define CPRINTS(format, args...) cprints(CC_CHARGER, "ISL9241 " format, ##args) @@ -491,10 +478,10 @@ int isl9241_set_ac_prochot(int chgnum, int ma) * This routine should ensure these bits are not set * before writing the register. */ - if (ma > AC_REG_TO_CURRENT(ISL9241_AC_PROCHOT_CURRENT_MAX)) - reg = ISL9241_AC_PROCHOT_CURRENT_MAX; - else if (ma < AC_REG_TO_CURRENT(ISL9241_AC_PROCHOT_CURRENT_MIN)) - reg = ISL9241_AC_PROCHOT_CURRENT_MIN; + if (ma > ISL9241_AC_PROCHOT_CURRENT_MAX) + reg = AC_CURRENT_TO_REG(ISL9241_AC_PROCHOT_CURRENT_MAX); + else if (ma < ISL9241_AC_PROCHOT_CURRENT_MIN) + reg = AC_CURRENT_TO_REG(ISL9241_AC_PROCHOT_CURRENT_MIN); else reg = AC_CURRENT_TO_REG(ma); diff --git a/driver/charger/isl9241.h b/driver/charger/isl9241.h index c3f843f380..b068d48faa 100644 --- a/driver/charger/isl9241.h +++ b/driver/charger/isl9241.h @@ -169,4 +169,17 @@ */ #define ISL9241_BYPASS_VSYS_TIMEOUT_MS 500 +/* Sense resistor default values in milli Ohm */ +#define ISL9241_DEFAULT_RS1 20 /* Input current sense resistor */ +#define ISL9241_DEFAULT_RS2 10 /* Battery charge current sense resistor */ + +#define BOARD_RS1 CONFIG_CHARGER_SENSE_RESISTOR_AC +#define BOARD_RS2 CONFIG_CHARGER_SENSE_RESISTOR + +#define BC_REG_TO_CURRENT(REG) (((REG)*ISL9241_DEFAULT_RS2) / BOARD_RS2) +#define BC_CURRENT_TO_REG(CUR) (((CUR)*BOARD_RS2) / ISL9241_DEFAULT_RS2) + +#define AC_REG_TO_CURRENT(REG) (((REG)*ISL9241_DEFAULT_RS1) / BOARD_RS1) +#define AC_CURRENT_TO_REG(CUR) (((CUR)*BOARD_RS1) / ISL9241_DEFAULT_RS1) + #endif /* __CROS_EC_ISL9241_H */ diff --git a/zephyr/test/drivers/isl9241/src/isl9241.c b/zephyr/test/drivers/isl9241/src/isl9241.c index d84d11a454..57f7169919 100644 --- a/zephyr/test/drivers/isl9241/src/isl9241.c +++ b/zephyr/test/drivers/isl9241/src/isl9241.c @@ -191,7 +191,7 @@ ZTEST_F(isl9241_driver, test_ac_prochot) ISL9241_REG_AC_PROCHOT)); zassert_equal(isl9241_emul_peek(fixture->isl9241_emul, ISL9241_REG_AC_PROCHOT), - ISL9241_AC_PROCHOT_CURRENT_MAX); + AC_CURRENT_TO_REG(ISL9241_AC_PROCHOT_CURRENT_MAX)); cur = (ISL9241_AC_PROCHOT_CURRENT_MIN - 100) * scale; printf("cur %d ", cur); @@ -200,7 +200,7 @@ ZTEST_F(isl9241_driver, test_ac_prochot) ISL9241_REG_AC_PROCHOT)); zassert_equal(isl9241_emul_peek(fixture->isl9241_emul, ISL9241_REG_AC_PROCHOT), - ISL9241_AC_PROCHOT_CURRENT_MIN); + AC_CURRENT_TO_REG(ISL9241_AC_PROCHOT_CURRENT_MIN)); } ZTEST_F(isl9241_driver, test_dc_prochot) |