diff mbox series

[11/16] power: supply: ab8500: Standardize termination current

Message ID 20211118021752.2262818-12-linus.walleij@linaro.org (mailing list archive)
State Not Applicable, archived
Headers show
Series AB8500 charger to use power_supply_battery_info | expand

Commit Message

Linus Walleij Nov. 18, 2021, 2:17 a.m. UTC
The AB8500 custom termination current can be replaced by the
corresponding struct power_supply_battery_info field.

Remove the struct member and amend the code to use the
standard property.

Add *_ua suffix for clarity and to make sure we have
changed all code sites using this member.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/power/supply/ab8500-bm.h       |  2 --
 drivers/power/supply/ab8500_bmdata.c   |  5 ++++-
 drivers/power/supply/ab8500_chargalg.c | 12 ++++++------
 3 files changed, 10 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/drivers/power/supply/ab8500-bm.h b/drivers/power/supply/ab8500-bm.h
index e6c5c9f5d4c5..949e6d9f13c7 100644
--- a/drivers/power/supply/ab8500-bm.h
+++ b/drivers/power/supply/ab8500-bm.h
@@ -374,7 +374,6 @@  struct ab8500_maxim_parameters {
  * struct ab8500_battery_type - different batteries supported
  * @resis_high:			battery upper resistance limit
  * @resis_low:			battery lower resistance limit
- * @termination_curr		battery charging termination current in mA
  * @recharge_cap		battery capacity limit that will trigger a new
  *				full charging cycle in the case where maintenan-
  *				-ce charging has been disabled
@@ -398,7 +397,6 @@  struct ab8500_maxim_parameters {
 struct ab8500_battery_type {
 	int resis_high;
 	int resis_low;
-	int termination_curr;
 	int recharge_cap;
 	int normal_cur_lvl;
 	int normal_vol_lvl;
diff --git a/drivers/power/supply/ab8500_bmdata.c b/drivers/power/supply/ab8500_bmdata.c
index 2532499afe5f..1e43c9f751e1 100644
--- a/drivers/power/supply/ab8500_bmdata.c
+++ b/drivers/power/supply/ab8500_bmdata.c
@@ -83,7 +83,6 @@  static const struct batres_vs_temp temp_to_batres_tbl_thermistor[] = {
 static struct ab8500_battery_type bat_type_thermistor_unknown = {
 	.resis_high = 0,
 	.resis_low = 0,
-	.termination_curr = 200,
 	.recharge_cap = 95,
 	.normal_cur_lvl = 400,
 	.normal_vol_lvl = 4100,
@@ -203,6 +202,10 @@  int ab8500_bm_of_probe(struct power_supply *psy,
 		bi->overvoltage_limit_uv = 4050000;
 	}
 
+	if (bi->charge_term_current_ua)
+		/* Charging stops when we drop below this current */
+		bi->charge_term_current_ua = 200000;
+
 	if (bi->factory_internal_resistance_uohm < 0)
 		bi->factory_internal_resistance_uohm = 300000;
 
diff --git a/drivers/power/supply/ab8500_chargalg.c b/drivers/power/supply/ab8500_chargalg.c
index dd9cad63e37e..49e7167d0362 100644
--- a/drivers/power/supply/ab8500_chargalg.c
+++ b/drivers/power/supply/ab8500_chargalg.c
@@ -87,7 +87,7 @@  struct ab8500_chargalg_current_step_status {
 struct ab8500_chargalg_battery_data {
 	int temp;
 	int volt_uv;
-	int avg_curr;
+	int avg_curr_ua;
 	int inst_curr;
 	int percent;
 };
@@ -795,9 +795,9 @@  static void ab8500_chargalg_end_of_charge(struct ab8500_chargalg *di)
 		!di->maintenance_chg && (di->batt_data.volt_uv >=
 		di->bm->bi.overvoltage_limit_uv ||
 		di->events.usb_cv_active || di->events.ac_cv_active) &&
-		di->batt_data.avg_curr <
-		di->bm->bat_type->termination_curr &&
-		di->batt_data.avg_curr > 0) {
+		di->batt_data.avg_curr_ua <
+		di->bm->bi.charge_term_current_ua &&
+		di->batt_data.avg_curr_ua > 0) {
 		if (++di->eoc_cnt >= EOC_COND_CNT) {
 			di->eoc_cnt = 0;
 			di->charge_status = POWER_SUPPLY_STATUS_FULL;
@@ -1237,7 +1237,7 @@  static int ab8500_chargalg_get_ext_psy_data(struct device *dev, void *data)
 		case POWER_SUPPLY_PROP_CURRENT_AVG:
 			switch (ext->desc->type) {
 			case POWER_SUPPLY_TYPE_BATTERY:
-				di->batt_data.avg_curr = ret.intval / 1000;
+				di->batt_data.avg_curr_ua = ret.intval;
 				break;
 			case POWER_SUPPLY_TYPE_USB:
 				if (ret.intval)
@@ -1398,7 +1398,7 @@  static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di)
 		"AC_online %d USB_online %d AC_CV %d USB_CV %d AC_I %d "
 		"USB_I %d AC_Vset %d AC_Iset %d USB_Vset %d USB_Iset %d\n",
 		di->batt_data.volt_uv,
-		di->batt_data.avg_curr,
+		di->batt_data.avg_curr_ua,
 		di->batt_data.inst_curr,
 		di->batt_data.temp,
 		di->batt_data.percent,