mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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>,
	Svyatoslav Ryhel <clamor95@gmail.com>
Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v1 4/4] power: max17040: get thermal data from adc if available
Date: Wed,  8 Mar 2023 10:44:19 +0200	[thread overview]
Message-ID: <20230308084419.11934-5-clamor95@gmail.com> (raw)
In-Reply-To: <20230308084419.11934-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/max17040_battery.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/power/supply/max17040_battery.c b/drivers/power/supply/max17040_battery.c
index 6dfce7b1309e..8c743c26dc6e 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
@@ -143,6 +144,7 @@ struct max17040_chip {
 	struct power_supply		*battery;
 	struct power_supply_battery_info	*batt_info;
 	struct chip_data		data;
+	struct iio_channel		*channel_temp;
 
 	/* battery capacity */
 	int soc;
@@ -416,6 +418,11 @@ static int max17040_get_property(struct power_supply *psy,
 	case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
 		val->intval = chip->batt_info->charge_full_design_uah;
 		break;
+	case POWER_SUPPLY_PROP_TEMP:
+		iio_read_channel_raw(chip->channel_temp,
+				     &val->intval);
+		val->intval *= 10;
+		break;
 	case POWER_SUPPLY_PROP_TEMP_MIN:
 		if (chip->batt_info->temp_min == INT_MIN)
 			return -ENODATA;
@@ -452,6 +459,7 @@ static enum power_supply_property max17040_battery_props[] = {
 	POWER_SUPPLY_PROP_HEALTH,
 	POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
+	POWER_SUPPLY_PROP_TEMP,
 	POWER_SUPPLY_PROP_TEMP_MIN,
 	POWER_SUPPLY_PROP_TEMP_MAX,
 };
@@ -560,9 +568,24 @@ static int max17040_probe(struct i2c_client *client)
 		}
 	}
 
+	if (of_property_read_bool(client->dev.of_node, "io-channels")) {
+		chip->channel_temp = iio_channel_get(&client->dev, "temp");
+		if (IS_ERR(chip->channel_temp))
+			return dev_err_probe(&client->dev, PTR_ERR(chip->channel_temp),
+					     "failed to get temp\n");
+	};
+
 	return 0;
 }
 
+static void max17040_remove(struct i2c_client *client)
+{
+	struct max17040_chip *chip = i2c_get_clientdata(client);
+
+	if (chip->channel_temp)
+		iio_channel_release(chip->channel_temp);
+}
+
 #ifdef CONFIG_PM_SLEEP
 
 static int max17040_suspend(struct device *dev)
@@ -642,6 +665,7 @@ static struct i2c_driver max17040_i2c_driver = {
 		.pm	= MAX17040_PM_OPS,
 	},
 	.probe_new	= max17040_probe,
+	.remove		= max17040_remove,
 	.id_table	= max17040_id,
 };
 module_i2c_driver(max17040_i2c_driver);
-- 
2.37.2


  parent reply	other threads:[~2023-03-08  8:45 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-08  8:44 [PATCH v1 0/4] Add optional properties to MAX17040 Svyatoslav Ryhel
2023-03-08  8:44 ` [PATCH v1 1/4] dt-bindings: power: supply: maxim,max17040: update properties Svyatoslav Ryhel
2023-03-08  9:04   ` Krzysztof Kozlowski
2023-03-08  9:15     ` Svyatoslav Ryhel
2023-03-08 10:44       ` Krzysztof Kozlowski
2023-03-08 10:51         ` Svyatoslav Ryhel
2023-03-08 10:53           ` Krzysztof Kozlowski
2023-03-08 11:06             ` Svyatoslav Ryhel
2023-03-08 11:12               ` Krzysztof Kozlowski
2023-05-15 22:17   ` Sebastian Reichel
2023-03-08  8:44 ` [PATCH v1 2/4] power: max17040: add simple battery cell support Svyatoslav Ryhel
2023-05-15 22:21   ` Sebastian Reichel
2023-03-08  8:44 ` [PATCH v1 3/4] power: max17040: add passing props from supplier Svyatoslav Ryhel
2023-05-15 22:41   ` Sebastian Reichel
2023-03-08  8:44 ` Svyatoslav Ryhel [this message]
2023-03-08  9:08   ` [PATCH v1 4/4] power: max17040: get thermal data from adc if available Krzysztof Kozlowski
2023-03-08  9:23     ` Svyatoslav Ryhel
2023-03-08 10:46       ` Krzysztof Kozlowski
2023-03-09  0:24   ` kernel test robot
2023-03-09  0:24   ` kernel test robot
2023-03-09  0:45   ` kernel test robot
2023-05-15 22:39   ` 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=20230308084419.11934-5-clamor95@gmail.com \
    --to=clamor95@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=matheus@castello.eng.br \
    --cc=me@iskren.info \
    --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

all inboxes | Powered by JetHome®