mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
power: max17040: get thermal data from adc if available
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> Reviewed-by: Iskren Chernev <me@iskren.info> Link: https://lore.kernel.org/r/20230731073613.10394-4-clamor95@gmail.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
committed by
Sebastian Reichel
parent
f4b782af61
commit
814755c48f
@@ -374,7 +374,7 @@ config AXP288_FUEL_GAUGE
|
|||||||
|
|
||||||
config BATTERY_MAX17040
|
config BATTERY_MAX17040
|
||||||
tristate "Maxim MAX17040/17041/17043 family Fuel Gauge"
|
tristate "Maxim MAX17040/17041/17043 family Fuel Gauge"
|
||||||
depends on I2C
|
depends on I2C && IIO
|
||||||
select REGMAP_I2C
|
select REGMAP_I2C
|
||||||
help
|
help
|
||||||
Driver supports Maxim fuel-gauge systems for lithium-ion (Li+)
|
Driver supports Maxim fuel-gauge systems for lithium-ion (Li+)
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <linux/of.h>
|
#include <linux/of.h>
|
||||||
#include <linux/regmap.h>
|
#include <linux/regmap.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
|
#include <linux/iio/consumer.h>
|
||||||
|
|
||||||
#define MAX17040_VCELL 0x02
|
#define MAX17040_VCELL 0x02
|
||||||
#define MAX17040_SOC 0x04
|
#define MAX17040_SOC 0x04
|
||||||
@@ -142,6 +143,7 @@ struct max17040_chip {
|
|||||||
struct delayed_work work;
|
struct delayed_work work;
|
||||||
struct power_supply *battery;
|
struct power_supply *battery;
|
||||||
struct chip_data data;
|
struct chip_data data;
|
||||||
|
struct iio_channel *channel_temp;
|
||||||
|
|
||||||
/* battery capacity */
|
/* battery capacity */
|
||||||
int soc;
|
int soc;
|
||||||
@@ -404,6 +406,13 @@ static int max17040_get_property(struct power_supply *psy,
|
|||||||
case POWER_SUPPLY_PROP_STATUS:
|
case POWER_SUPPLY_PROP_STATUS:
|
||||||
power_supply_get_property_from_supplier(psy, psp, val);
|
power_supply_get_property_from_supplier(psy, psp, val);
|
||||||
break;
|
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:
|
default:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@@ -424,6 +433,7 @@ static enum power_supply_property max17040_battery_props[] = {
|
|||||||
POWER_SUPPLY_PROP_CAPACITY,
|
POWER_SUPPLY_PROP_CAPACITY,
|
||||||
POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN,
|
POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN,
|
||||||
POWER_SUPPLY_PROP_STATUS,
|
POWER_SUPPLY_PROP_STATUS,
|
||||||
|
POWER_SUPPLY_PROP_TEMP,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct power_supply_desc max17040_battery_desc = {
|
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);
|
i2c_set_clientdata(client, chip);
|
||||||
psy_cfg.drv_data = 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,
|
chip->battery = devm_power_supply_register(&client->dev,
|
||||||
&max17040_battery_desc, &psy_cfg);
|
&max17040_battery_desc, &psy_cfg);
|
||||||
if (IS_ERR(chip->battery)) {
|
if (IS_ERR(chip->battery)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user