From: Svyatoslav Ryhel <clamor95@gmail.com>
To: Iskren Chernev <me@iskren.info>,
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Matheus Castello <matheus@castello.eng.br>,
Sebastian Reichel <sre@kernel.org>,
Rob Herring <robh+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Russell King <linux@armlinux.org.uk>,
Alim Akhtar <alim.akhtar@samsung.com>,
Arnd Bergmann <arnd@arndb.de>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Svyatoslav Ryhel <clamor95@gmail.com>,
Claudiu Beznea <claudiu.beznea@microchip.com>,
Stefan Hansson <newbie13xd@gmail.com>
Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-samsung-soc@vger.kernel.org
Subject: [PATCH v3 3/4] power: max17040: get thermal data from adc if available
Date: Mon, 31 Jul 2023 10:36:12 +0300 [thread overview]
Message-ID: <20230731073613.10394-4-clamor95@gmail.com> (raw)
In-Reply-To: <20230731073613.10394-1-clamor95@gmail.com>
Since fuel gauge does not support thermal monitoring,
some vendors may couple this fuel gauge with thermal/adc
sensor to monitor battery cell exact temperature.
Add this feature by adding optional iio thermal channel.
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
drivers/power/supply/Kconfig | 2 +-
drivers/power/supply/max17040_battery.c | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
index c78be9f322e6..32600609865b 100644
--- a/drivers/power/supply/Kconfig
+++ b/drivers/power/supply/Kconfig
@@ -374,7 +374,7 @@ config AXP288_FUEL_GAUGE
config BATTERY_MAX17040
tristate "Maxim MAX17040/17041/17043 family Fuel Gauge"
- depends on I2C
+ depends on I2C && IIO
select REGMAP_I2C
help
Driver supports Maxim fuel-gauge systems for lithium-ion (Li+)
diff --git a/drivers/power/supply/max17040_battery.c b/drivers/power/supply/max17040_battery.c
index 3301e8a4b16c..54db20637c87 100644
--- a/drivers/power/supply/max17040_battery.c
+++ b/drivers/power/supply/max17040_battery.c
@@ -18,6 +18,7 @@
#include <linux/of_device.h>
#include <linux/regmap.h>
#include <linux/slab.h>
+#include <linux/iio/consumer.h>
#define MAX17040_VCELL 0x02
#define MAX17040_SOC 0x04
@@ -142,6 +143,7 @@ struct max17040_chip {
struct delayed_work work;
struct power_supply *battery;
struct chip_data data;
+ struct iio_channel *channel_temp;
/* battery capacity */
int soc;
@@ -404,6 +406,13 @@ static int max17040_get_property(struct power_supply *psy,
case POWER_SUPPLY_PROP_STATUS:
power_supply_get_property_from_supplier(psy, psp, val);
break;
+ case POWER_SUPPLY_PROP_TEMP:
+ if (!chip->channel_temp)
+ return -ENODATA;
+
+ iio_read_channel_processed_scale(chip->channel_temp,
+ &val->intval, 10);
+ break;
default:
return -EINVAL;
}
@@ -424,6 +433,7 @@ static enum power_supply_property max17040_battery_props[] = {
POWER_SUPPLY_PROP_CAPACITY,
POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN,
POWER_SUPPLY_PROP_STATUS,
+ POWER_SUPPLY_PROP_TEMP,
};
static const struct power_supply_desc max17040_battery_desc = {
@@ -469,6 +479,17 @@ static int max17040_probe(struct i2c_client *client)
i2c_set_clientdata(client, chip);
psy_cfg.drv_data = chip;
+ /* Switch to devm_iio_channel_get_optional when available */
+ chip->channel_temp = devm_iio_channel_get(&client->dev, "temp");
+ if (IS_ERR(chip->channel_temp)) {
+ ret = PTR_ERR(chip->channel_temp);
+ if (ret != -ENODEV)
+ return dev_err_probe(&client->dev, PTR_ERR(chip->channel_temp),
+ "failed to get temp\n");
+ else
+ chip->channel_temp = NULL;
+ }
+
chip->battery = devm_power_supply_register(&client->dev,
&max17040_battery_desc, &psy_cfg);
if (IS_ERR(chip->battery)) {
--
2.39.2
next prev parent reply other threads:[~2023-07-31 7:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-31 7:36 [PATCH v3 0/4] Add optional properties to MAX17040 Svyatoslav Ryhel
2023-07-31 7:36 ` [PATCH v3 1/4] dt-bindings: power: supply: maxim,max17040: update properties Svyatoslav Ryhel
2023-07-31 7:36 ` [PATCH v3 2/4] power: max17040: pass status property from supplier Svyatoslav Ryhel
2023-07-31 7:36 ` Svyatoslav Ryhel [this message]
2023-07-31 7:36 ` [PATCH v3 4/4] ARM: configs: s5pv210_defconfig: enable IIO required by MAX17040 Svyatoslav Ryhel
2023-08-05 22:42 ` Andi Shyti
2023-08-06 8:29 ` Krzysztof Kozlowski
2023-08-07 8:55 ` Andi Shyti
2023-08-07 13:51 ` Krzysztof Kozlowski
2023-09-11 11:39 ` (subset) " Krzysztof Kozlowski
2023-07-31 15:49 ` [PATCH v3 0/4] Add optional properties to MAX17040 Iskren Chernev
2023-09-14 15:42 ` (subset) " Sebastian Reichel
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=20230731073613.10394-4-clamor95@gmail.com \
--to=clamor95@gmail.com \
--cc=alim.akhtar@samsung.com \
--cc=arnd@arndb.de \
--cc=claudiu.beznea@microchip.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jernej.skrabec@gmail.com \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=m.szyprowski@samsung.com \
--cc=matheus@castello.eng.br \
--cc=me@iskren.info \
--cc=newbie13xd@gmail.com \
--cc=robh+dt@kernel.org \
--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).