diff options
author | Caveh Jalali <caveh@chromium.org> | 2021-03-24 01:50:03 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-04-23 00:13:57 +0000 |
commit | a4336657562a25bf45e80296d31f0d6e86d6f97c (patch) | |
tree | ef1355721e60a0cabf8cc01302454fc58c95ef45 /driver/charger/bq25710.c | |
parent | 344ba538399931f83d5058a10c70be4ab9833c55 (diff) | |
download | chrome-ec-a4336657562a25bf45e80296d31f0d6e86d6f97c.tar.gz |
bq25710: Fix register field access macros
This cleans up the use of CURRENT_SHIFT and CURRENT_STEP_MA in related
macros. Also, in one case INPUT_RESISTOR_RATIO was not applied to
IIN_DPM - luckily, this ratio is 1 for all affected boards, so fixing
this has not functional impact.
BRANCH=none
BUG=b:185190976
TEST=ran util/compare_build.sh on affected boards
Change-Id: Ib3e8321d3d7ed69d33d7266077a67c5d2893182a
Signed-off-by: Caveh Jalali <caveh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2785269
Reviewed-by: Boris Mittelberg <bmbm@google.com>
Diffstat (limited to 'driver/charger/bq25710.c')
-rw-r--r-- | driver/charger/bq25710.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/driver/charger/bq25710.c b/driver/charger/bq25710.c index 994f4b418a..5169342c9c 100644 --- a/driver/charger/bq25710.c +++ b/driver/charger/bq25710.c @@ -44,8 +44,12 @@ #define INPUT_RESISTOR_RATIO \ ((CONFIG_CHARGER_SENSE_RESISTOR_AC) / DEFAULT_SENSE_RESISTOR) -#define REG_TO_INPUT_CURRENT(REG) ((REG + 1) * 50 / INPUT_RESISTOR_RATIO) -#define INPUT_CURRENT_TO_REG(CUR) (((CUR) * INPUT_RESISTOR_RATIO / 50) - 1) +#define IIN_DPM_REG_TO_CURRENT(REG) (((REG) + 1) * \ + BQ25710_IIN_DPM_CURRENT_STEP_MA / \ + INPUT_RESISTOR_RATIO) +#define IIN_HOST_CURRENT_TO_REG(CUR) (((CUR) * \ + INPUT_RESISTOR_RATIO / \ + BQ25710_IIN_HOST_CURRENT_STEP_MA) - 1) #define CHARGING_RESISTOR_RATIO \ ((CONFIG_CHARGER_SENSE_RESISTOR) / DEFAULT_SENSE_RESISTOR) @@ -412,10 +416,10 @@ static enum ec_error_list bq25710_discharge_on_ac(int chgnum, int enable) static enum ec_error_list bq25710_set_input_current_limit(int chgnum, int input_current) { - int num_steps = INPUT_CURRENT_TO_REG(input_current); + int num_steps = IIN_HOST_CURRENT_TO_REG(input_current); - return raw_write16(chgnum, BQ25710_REG_IIN_HOST, num_steps << - BQ25710_CHARGE_IIN_BIT_0FFSET); + return raw_write16(chgnum, BQ25710_REG_IIN_HOST, + num_steps << BQ25710_IIN_HOST_CURRENT_SHIFT); } static enum ec_error_list bq25710_get_input_current_limit(int chgnum, @@ -432,8 +436,8 @@ static enum ec_error_list bq25710_get_input_current_limit(int chgnum, rv = raw_read16(chgnum, BQ25710_REG_IIN_DPM, ®); if (!rv) *input_current = - REG_TO_INPUT_CURRENT((reg >> - BQ25710_CHARGE_IIN_BIT_0FFSET)); + IIN_DPM_REG_TO_CURRENT(reg >> + BQ25710_IIN_DPM_CURRENT_SHIFT); return rv; } @@ -618,8 +622,7 @@ static int bq25710_ramp_get_current_limit(int chgnum) return 0; } - return ((reg >> BQ25710_IIN_DPM_BIT_SHIFT) * BQ25710_IIN_DPM_STEP_MA + - BQ25710_IIN_DPM_STEP_MA); + return IIN_DPM_REG_TO_CURRENT(reg >> BQ25710_IIN_DPM_CURRENT_SHIFT); } #endif /* CONFIG_CHARGE_RAMP_HW */ |