All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: Sebastian Reichel <sre@kernel.org>, Marcus Cooper <codekipper@gmail.com>
Cc: linux-pm@vger.kernel.org,
	Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>,
	Linus Walleij <linus.walleij@linaro.org>
Subject: [PATCH 2/6] power: supply: ab8500: Standardize alert mode charging
Date: Thu,  3 Feb 2022 18:16:29 +0100	[thread overview]
Message-ID: <20220203171633.183828-3-linus.walleij@linaro.org> (raw)
In-Reply-To: <20220203171633.183828-1-linus.walleij@linaro.org>

The AB8500 code is using a special current and voltage setting
when the battery is in "alert mode", i.e. when it is starting
to go outside normal operating conditions so it is too
cold or too hot. This makes sense as a way for the charging
algorithm to deal with hostile environments.

Add the needed members to the struct power_supply_battery_info,
and switch the AB8500 charging code over to using this.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/power/supply/ab8500-bm.h         |  4 ----
 drivers/power/supply/ab8500_bmdata.c     |  9 +++++++--
 drivers/power/supply/ab8500_chargalg.c   |  4 ++--
 drivers/power/supply/power_supply_core.c |  2 ++
 include/linux/power_supply.h             | 10 ++++++++++
 5 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/drivers/power/supply/ab8500-bm.h b/drivers/power/supply/ab8500-bm.h
index 4d74d21cf1eb..91ef9d4a5222 100644
--- a/drivers/power/supply/ab8500-bm.h
+++ b/drivers/power/supply/ab8500-bm.h
@@ -331,14 +331,10 @@ struct ab8500_maxim_parameters {
  * struct ab8500_battery_type - different batteries supported
  * @resis_high:			battery upper resistance limit
  * @resis_low:			battery lower resistance limit
- * @low_high_cur_lvl:		charger current in temp low/high state in mA
- * @low_high_vol_lvl:		charger voltage in temp low/high state in mV'
  */
 struct ab8500_battery_type {
 	int resis_high;
 	int resis_low;
-	int low_high_cur_lvl;
-	int low_high_vol_lvl;
 };
 
 /**
diff --git a/drivers/power/supply/ab8500_bmdata.c b/drivers/power/supply/ab8500_bmdata.c
index c104afe83b4b..c878dc6e4197 100644
--- a/drivers/power/supply/ab8500_bmdata.c
+++ b/drivers/power/supply/ab8500_bmdata.c
@@ -77,8 +77,6 @@ struct power_supply_maintenance_charge_table maint_charge_table[] = {
 static struct ab8500_battery_type bat_type_thermistor_unknown = {
 	.resis_high = 0,
 	.resis_low = 0,
-	.low_high_cur_lvl = 300,
-	.low_high_vol_lvl = 4000,
 };
 
 static const struct ab8500_bm_capacity_levels cap_levels = {
@@ -192,6 +190,13 @@ int ab8500_bm_of_probe(struct power_supply *psy,
 		bi->maintenance_charge_size = ARRAY_SIZE(maint_charge_table);
 	}
 
+	if (bi->alert_temp_charge_current_ua < 0 ||
+	    bi->alert_temp_charge_voltage_uv < 0)
+	{
+		bi->alert_temp_charge_current_ua = 300000;
+		bi->alert_temp_charge_voltage_uv = 4000000;
+	}
+
 	/*
 	 * Internal resistance and factory resistance are tightly coupled
 	 * so both MUST be defined or we fall back to defaults.
diff --git a/drivers/power/supply/ab8500_chargalg.c b/drivers/power/supply/ab8500_chargalg.c
index 6054996b6260..01fd2ef6e6b5 100644
--- a/drivers/power/supply/ab8500_chargalg.c
+++ b/drivers/power/supply/ab8500_chargalg.c
@@ -1511,8 +1511,8 @@ static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di)
 
 	case STATE_TEMP_LOWHIGH_INIT:
 		ab8500_chargalg_start_charging(di,
-			di->bm->bat_type->low_high_vol_lvl,
-			di->bm->bat_type->low_high_cur_lvl);
+			bi->alert_temp_charge_voltage_uv,
+			bi->alert_temp_charge_current_ua);
 		ab8500_chargalg_stop_maintenance_timer(di);
 		di->charge_status = POWER_SUPPLY_STATUS_CHARGING;
 		ab8500_chargalg_state_to(di, STATE_TEMP_LOWHIGH);
diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index 6568939e4518..01f9898ab548 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -591,6 +591,8 @@ int power_supply_get_battery_info(struct power_supply *psy,
 	info->charge_restart_voltage_uv      = -EINVAL;
 	info->overvoltage_limit_uv           = -EINVAL;
 	info->maintenance_charge             = NULL;
+	info->alert_temp_charge_current_ua   = -EINVAL;
+	info->alert_temp_charge_voltage_uv   = -EINVAL;
 	info->temp_ambient_alert_min         = INT_MIN;
 	info->temp_ambient_alert_max         = INT_MAX;
 	info->temp_alert_min                 = INT_MIN;
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index b998fc4c87ae..5a059c013c12 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -443,6 +443,14 @@ struct power_supply_maintenance_charge_table {
  *   after the main CC/CV charging phase is complete.
  * @maintenance_charge_size: the number of maintenance charging settings in
  *   maintenance_charge.
+ * @alert_temp_charge_current_ua: The charging current to use if the battery
+ *   enters alert temperatures. I.e. if the internal temperature is between
+ *   temp_alert_min and temp_min or temp_alert_max and temp_max. No matter
+ *   the charging phase, this and alert_temp_charge_voltage_uv will be
+ *   applied under alert temperature conditions, usually lowering the charging
+ *   current as an evasive manouver.
+ * @alert_temp_charge_voltage_uv: Same as alert_temp_charge_current_ua, but
+ *   for the charging voltage.
  * @factory_internal_resistance_uohm: the internal resistance of the battery
  *   at fabrication time, expressed in microohms. This resistance will vary
  *   depending on the lifetime and charge of the battery, so this is just a
@@ -594,6 +602,8 @@ struct power_supply_battery_info {
 	int constant_charge_voltage_max_uv;
 	struct power_supply_maintenance_charge_table *maintenance_charge;
 	int maintenance_charge_size;
+	int alert_temp_charge_current_ua;
+	int alert_temp_charge_voltage_uv;
 	int factory_internal_resistance_uohm;
 	int ocv_temp[POWER_SUPPLY_OCV_TEMP_MAX];
 	int temp_ambient_alert_min;
-- 
2.34.1


  parent reply	other threads:[~2022-02-03 17:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-03 17:16 [PATCH 0/6] AB8500 charging, the final steps Linus Walleij
2022-02-03 17:16 ` [PATCH 1/6] power: supply: ab8500: Standardize maintenance charging Linus Walleij
2022-02-07 11:15   ` Vaittinen, Matti
2022-02-12 23:21     ` Linus Walleij
2022-02-16  6:28       ` Vaittinen, Matti
2022-02-03 17:16 ` Linus Walleij [this message]
2022-02-04 14:49   ` [PATCH 2/6] power: supply: ab8500: Standardize alert mode charging Vaittinen, Matti
2022-02-13  0:01     ` Linus Walleij
2022-02-03 17:16 ` [PATCH 3/6] power: supply: ab8500: Standardize BTI resistance Linus Walleij
2022-02-03 17:16 ` [PATCH 4/6] power: supply: Support VBAT-to-Ri lookup tables Linus Walleij
2022-02-03 17:16 ` [PATCH 5/6] power: supply: ab8500_fg: Use VBAT-to-Ri if possible Linus Walleij
2022-02-03 17:16 ` [PATCH 6/6] power: supply: Static data for Samsung batteries Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220203171633.183828-3-linus.walleij@linaro.org \
    --to=linus.walleij@linaro.org \
    --cc=codekipper@gmail.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=sre@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.