summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--driver/charger/bq25710.c21
-rw-r--r--driver/charger/bq25710.h10
2 files changed, 17 insertions, 14 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, &reg);
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 */
diff --git a/driver/charger/bq25710.h b/driver/charger/bq25710.h
index 2c0e1ba876..25e6c1546d 100644
--- a/driver/charger/bq25710.h
+++ b/driver/charger/bq25710.h
@@ -63,8 +63,8 @@
#define BQ25710_CHARGE_STATUS_ICO_DONE BIT(14)
/* IIN_DPM Register */
-#define BQ25710_CHARGE_IIN_BIT_0FFSET 8
-#define BQ25710_CHARGE_MA_PER_STEP 50
+#define BQ25710_IIN_DPM_CURRENT_SHIFT 8
+#define BQ25710_IIN_DPM_CURRENT_STEP_MA 50
/* ADCOption Register */
#define BQ25710_ADC_OPTION_ADC_START BIT(14)
@@ -107,9 +107,9 @@
#define BQ25710_PROCHOT_PROFILE_VSYS BIT(2)
#define BQ25710_PROCHOT_IDCHG_VTH_MASK 0xFC00
-/* IIN_DPM Register */
-#define BQ25710_IIN_DPM_BIT_SHIFT 8
-#define BQ25710_IIN_DPM_STEP_MA 50
+/* IIN_HOST Register */
+#define BQ25710_IIN_HOST_CURRENT_SHIFT 8
+#define BQ25710_IIN_HOST_CURRENT_STEP_MA 50
#if defined(CONFIG_CHARGER_BQ25720)
/* Vmin Active Protection Register */