Re: [PATCH v1 4/4] power: max17040: get thermal data from adc if available

From: Krzysztof Kozlowski
Date: Wed Mar 08 2023 - 05:46:17 EST


On 08/03/2023 10:23, Svyatoslav Ryhel wrote:
> ср, 8 бер. 2023 р. о 11:08 Krzysztof Kozlowski
> <krzysztof.kozlowski@xxxxxxxxxx> пише:
>>
>> On 08/03/2023 09:44, Svyatoslav Ryhel wrote:
>>> 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@xxxxxxxxx>
>>> ---
>>> 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;
>>
>> I am not convinced this is needed at all. You basically chain two
>> subsystems only to report to user-space via power supply, but it is
>> already reported via IIO. I would understand it if you use the value for
>> something, e.g. control the charger. Here, it's just feeding different
>> user-space interface. Therefore:
>> 1. IO channels are not a hardware property of the fuel gauge,
>> 2. I have doubts this should be even exposed via power supply interface.
>>
>
> I can assure you that this is only the beginning of weird vendor solutions
> I have discovered. Nonetheless, max17040 has no battery temp property,
> this means in case I have a critical battery overheating, userspace
> will tell me nothing

Of course will tell you - via IIO.

> since instead of having direct battery temp property under power supply I have
> separate iio sensor, which may not even be monitored. It is always nice to have
> battery explosions.

Hm, ok, I defer this to Sebastian. What's the policy - who should report
battery temperature if the battery/FG itself does not have any sensor?

Best regards,
Krzysztof