From: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
To: Matti Vaittinen <mazziesaccount@gmail.com>,
Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Cc: Sebastian Reichel <sre@kernel.org>,
Rob Herring <robh+dt@kernel.org>,
Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>,
Lee Jones <lee.jones@linaro.org>,
Linus Walleij <linus.walleij@linaro.org>,
rostokus@gmail.com, fan.chen@mediatek.com,
linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-power@fi.rohmeurope.com
Subject: [RFC PATCH v3 3/9] power: supply: Support DT originated temperature-capacity tables
Date: Tue, 16 Nov 2021 14:25:53 +0200 [thread overview]
Message-ID: <6123f62ac44e6513a498d15034a4b6b22abe5f5b.1637061794.git.matti.vaittinen@fi.rohmeurope.com> (raw)
In-Reply-To: <cover.1637061794.git.matti.vaittinen@fi.rohmeurope.com>
[-- Attachment #1: Type: text/plain, Size: 5413 bytes --]
Support obtaining the "capacity degradation by temperature" - tables
from device-tree to batinfo.
Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
---
RFCv3:
- rename simple_gauge_temp_degr to power_supply_temp_degr
---
drivers/power/supply/power_supply_core.c | 53 ++++++++++++++++++++++++
include/linux/power_supply.h | 26 ++++++++++++
2 files changed, 79 insertions(+)
diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index 295672165836..1a21f692ab81 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -562,10 +562,12 @@ struct power_supply *devm_power_supply_get_by_phandle(struct device *dev,
EXPORT_SYMBOL_GPL(devm_power_supply_get_by_phandle);
#endif /* CONFIG_OF */
+#define POWER_SUPPLY_TEMP_DGRD_MAX_VALUES 100
int power_supply_get_battery_info(struct power_supply *psy,
struct power_supply_battery_info *info)
{
struct power_supply_resistance_temp_table *resist_table;
+ u32 *dgrd_table;
struct device_node *battery_np;
const char *value;
int err, len, index;
@@ -588,6 +590,8 @@ int power_supply_get_battery_info(struct power_supply *psy,
info->temp_max = INT_MAX;
info->factory_internal_resistance_uohm = -EINVAL;
info->resist_table = NULL;
+ info->temp_dgrd_values = 0;
+ info->temp_dgrd = NULL;
for (index = 0; index < POWER_SUPPLY_OCV_TEMP_MAX; index++) {
info->ocv_table[index] = NULL;
@@ -677,6 +681,55 @@ int power_supply_get_battery_info(struct power_supply *psy,
of_property_read_u32_index(battery_np, "operating-range-celsius",
1, &info->temp_max);
+ len = of_property_count_u32_elems(battery_np, "temp-degrade-table");
+ if (len == -EINVAL)
+ len = 0;
+ if (len < 0) {
+ err = len;
+ goto out_put_node;
+ }
+ /* table should consist of value pairs - maximum of 100 pairs */
+ if (len % 3 || len / 3 > POWER_SUPPLY_TEMP_DGRD_MAX_VALUES) {
+ dev_warn(&psy->dev,
+ "bad amount of temperature-capacity degrade values\n");
+ err = -EINVAL;
+ goto out_put_node;
+ }
+ info->temp_dgrd_values = len / 3;
+ if (info->temp_dgrd_values) {
+ info->temp_dgrd = devm_kcalloc(&psy->dev,
+ info->temp_dgrd_values,
+ sizeof(*info->temp_dgrd),
+ GFP_KERNEL);
+ if (!info->temp_dgrd) {
+ err = -ENOMEM;
+ goto out_put_node;
+ }
+ dgrd_table = kcalloc(len, sizeof(*dgrd_table), GFP_KERNEL);
+ if (!dgrd_table) {
+ err = -ENOMEM;
+ goto out_put_node;
+ }
+ err = of_property_read_u32_array(battery_np,
+ "temp-degrade-table",
+ dgrd_table, len);
+ if (err) {
+ dev_warn(&psy->dev,
+ "bad temperature - capacity degrade values %d\n", err);
+ kfree(dgrd_table);
+ info->temp_dgrd_values = 0;
+ goto out_put_node;
+ }
+ for (index = 0; index < info->temp_dgrd_values; index++) {
+ struct power_supply_temp_degr *d = &info->temp_dgrd[index];
+
+ d->temp_degrade_1C = dgrd_table[index * 3];
+ d->degrade_at_set = dgrd_table[index * 3 + 1];
+ d->temp_set_point = dgrd_table[index * 3 + 2];
+ }
+ kfree(dgrd_table);
+ }
+
len = of_property_count_u32_elems(battery_np, "ocv-capacity-celsius");
if (len < 0 && len != -EINVAL) {
err = len;
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index fa8cf434f7e3..fbc07d403f41 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -214,6 +214,30 @@ union power_supply_propval {
struct device_node;
struct power_supply;
+/**
+ * struct power_supply_temp_degr - impact of temperature to battery capacity
+ *
+ * Usually temperature impacts on battery capacity. For systems where it is
+ * sufficient to describe capacity change as a series of temperature ranges
+ * where the change is linear (Eg delta cap = temperature_change * constant +
+ * offset) can be described by this structure.
+ *
+ * Please note - in order to avoid unnecessary rounding errors the change
+ * of capacity (uAh) is per change of temperature degree C while the temperature
+ * range floor is in tenths of degree C
+ *
+ * @temp_set_point: Temperature where cap change is as given in
+ * degrade_at_set. Units are 0.1 degree C
+ * @degrade_at_set: Capacity difference (from ideal) at temp_set_point
+ * temperature
+ * @temp_degrade_1C: Capacity change / temperature change (uAh / degree C)
+ */
+struct power_supply_temp_degr {
+ int temp_set_point;
+ int degrade_at_set;
+ int temp_degrade_1C;
+};
+
/* Run-time specific power supply configuration */
struct power_supply_config {
struct device_node *of_node;
@@ -377,6 +401,8 @@ struct power_supply_battery_info {
int ocv_table_size[POWER_SUPPLY_OCV_TEMP_MAX];
struct power_supply_resistance_temp_table *resist_table;
int resist_table_size;
+ int temp_dgrd_values;
+ struct power_supply_temp_degr *temp_dgrd;
};
extern struct atomic_notifier_head power_supply_notifier;
--
2.31.1
--
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND
~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =]
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2021-11-16 12:26 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-16 12:24 [RFC PATCH v3 0/9] power: supply: Add some fuel-gauge logic Matti Vaittinen
2021-11-16 12:24 ` [RFC PATCH v3 1/9] dt-bindings: battery: Add temperature-capacity degradation table Matti Vaittinen
2021-11-16 14:02 ` Rob Herring
2021-11-18 1:57 ` Linus Walleij
2021-11-18 5:27 ` Vaittinen, Matti
2021-11-16 12:25 ` [RFC PATCH v3 2/9] power: supply: add cap2ocv batinfo helper Matti Vaittinen
2021-11-18 2:02 ` Linus Walleij
2021-11-18 5:30 ` Vaittinen, Matti
2021-11-16 12:25 ` Matti Vaittinen [this message]
2021-11-18 2:10 ` [RFC PATCH v3 3/9] power: supply: Support DT originated temperature-capacity tables Linus Walleij
2021-11-18 6:11 ` Vaittinen, Matti
2021-11-26 11:56 ` Vaittinen, Matti
2021-11-26 12:35 ` Matti Vaittinen
2021-11-27 0:55 ` Linus Walleij
2021-11-27 0:54 ` Linus Walleij
2021-11-28 8:51 ` Vaittinen, Matti
2021-11-30 1:34 ` Linus Walleij
2021-11-30 6:33 ` Vaittinen, Matti
2021-12-02 1:57 ` Linus Walleij
2021-12-02 6:29 ` Vaittinen, Matti
2021-12-05 0:30 ` Linus Walleij
2021-11-16 12:26 ` [RFC PATCH v3 4/9] power: supply: Add batinfo getters usable prior supply registration Matti Vaittinen
2021-11-19 1:42 ` Linus Walleij
2021-11-16 12:27 ` [RFC PATCH v3 5/9] power: supply: Add constant battery aging degradation to batinfo Matti Vaittinen
2021-11-16 12:27 ` [RFC PATCH v3 6/9] power: supply: Add batinfo functions for OCV to SOC with 0.1% accuracy Matti Vaittinen
2021-11-19 1:49 ` Linus Walleij
2021-11-19 8:11 ` Matti Vaittinen
2021-11-16 12:28 ` [RFC PATCH v3 7/9] power: supply: add simple-gauge for SOC estimation and CC correction Matti Vaittinen
2021-11-19 1:54 ` Linus Walleij
2021-11-16 12:29 ` [RFC PATCH v3 8/9] mfd: bd71828, bd71815 prepare for power-supply support Matti Vaittinen
2021-11-16 12:29 ` [RFC PATCH v3 9/9] power: supply: Add bd718(15/27/28/78) charger driver Matti Vaittinen
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=6123f62ac44e6513a498d15034a4b6b22abe5f5b.1637061794.git.matti.vaittinen@fi.rohmeurope.com \
--to=matti.vaittinen@fi.rohmeurope.com \
--cc=devicetree@vger.kernel.org \
--cc=fan.chen@mediatek.com \
--cc=lee.jones@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-power@fi.rohmeurope.com \
--cc=mazziesaccount@gmail.com \
--cc=robh+dt@kernel.org \
--cc=rostokus@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).