Message ID | 20230308084419.11934-5-clamor95@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp221742wrd; Wed, 8 Mar 2023 01:08:04 -0800 (PST) X-Google-Smtp-Source: AK7set+N40wQ0SK6wxYGliiP/mC1vIMfPeV50Vg7qUD7VM3NhUdK929DbyEuXLlNt2xfqHcdgzl5 X-Received: by 2002:a05:6a21:6d9f:b0:cd:a334:a531 with SMTP id wl31-20020a056a216d9f00b000cda334a531mr22558897pzb.62.1678266484227; Wed, 08 Mar 2023 01:08:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678266484; cv=none; d=google.com; s=arc-20160816; b=P6VjBlVVoBEmIivUzukjOMphHhiabkHrMSRRsUTq2iFNFQ1HaATWa82DH7PjyNLAhj Hy0GuErykY17whaoljcqYoX943tzJG0MVOJ2faQOv4eOE6D45qGlkAeFJfXiOW3VnEVa F5PbMGz6I/ZAEK4MKwD/wMlQ+jiLlJQTwbvReNRK2LlBtGPz5P09r/xtgs152V/c1JcQ gV35hWeeGCMkvh7E/nM/NN/S3KPQpC6HnkmMBmRpWOG3MV5iYTeGoQQhHF0qK5m52d2Q M1Frg0RIjFHDxuhyNZvkH8ZvKNzmcRf0ln6SFsCbYrKPBrQTSGKabJfKB+UqDUfR/fEQ LkYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bt0rP56ZVICJXZOyWcT1Og4PPdYTw7SSYjSP/fByF9w=; b=X4TkMWWXqerWKOUUwXpkDbCQStshFmrieHHSoJU6tzG6YPbBCFXG1ASUkQ77o/BN/K VfE74TaEMqz9zCLoUSOQGoVOWo8AGNp/UYziiHFqChahv5Y3yshTctSFV02ZRGYWeUE5 q2UWMY0wDFQcWBKD0zUiEtGgE/eOLAJVpHpTt0zZdQ8iwfYpzAPJ4aVXUEXyl511nl4U oXQZczZBqWakhoPf+DbEdHzvbCF40I+LMBSILPqYh9qrxxJ6SR8e8LbmEO7Lv/QX9LWS HHdzcDZcptBxuBhot8wlZd/XeAyZQ+mV7C03JxpPt+eKd7ZF3n7rlD8TOtODDUQcsVIj S1Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=q4jDMXjb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 190-20020a6302c7000000b005031231026fsi14394697pgc.543.2023.03.08.01.07.51; Wed, 08 Mar 2023 01:08:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=q4jDMXjb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230368AbjCHIoz (ORCPT <rfc822;toshivichauhan@gmail.com> + 99 others); Wed, 8 Mar 2023 03:44:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229851AbjCHIok (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 8 Mar 2023 03:44:40 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C6219F067; Wed, 8 Mar 2023 00:44:39 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id ec29so31767239edb.6; Wed, 08 Mar 2023 00:44:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678265077; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bt0rP56ZVICJXZOyWcT1Og4PPdYTw7SSYjSP/fByF9w=; b=q4jDMXjbnN11ZJAbkD1K3MPkAEmb7KJT9Syk3m40F8SthEU/wy5ivzobAFc7jLuLdn Sp+76WjLsufxK8FxW+bqXlr59Us4r3k3qqRIkdxMaeuKQkYHbOP8PfvTxFgns4CYHR3T w5SIXGD7hpHTE6oDLsSSMAn6oZj0pmOtcNboOUr2NAroAWYdDjgxGmd+KnI4WOj4zQyq uHj1w4Y8orQ9y6T28/gMEZAq3SBdZeEKijZ3Qiiv0Zmd4X+w3zb/xGgK8oKgvwz4/Z30 VYb6S2UubuL1DicrTTsXYmYCS7TF8kagHYV1DwC/KlxEbqdRb6BV9Og8RX0vBOIcKM1m bkvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678265077; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bt0rP56ZVICJXZOyWcT1Og4PPdYTw7SSYjSP/fByF9w=; b=i3eZLC4EyV1S1gd93D/47vKxE0Nffe5oNugDMOFDhIugtN2Ydsol+TjaDSzeuaOXHT w42nIMHRjQJU3PrKdeQzyXdbvaYLYJhuVWkKc/fUbHLykM42+ATVPHVbgOjXOykn01qv hVocWgKQXrAb6lBfF72Nur5bCZEdI7Ft31S0PJ9NxW2X09f19fLZDl+89WDvU4rj1/Zq VszEWhlikDnS5FSNoMQ1zrtQh+Gp3gFQRa6w1olNwrvdt/iWILHexMGyulvMm2ZtNO0B vyn8mdxQxTvGmp9UmiODY9MYx+uSsY4LciA94X5I5sYUbaYeDNw+k/KUEwF2ahH6KbUp fdEA== X-Gm-Message-State: AO0yUKXKQankySWoL82fhbLiu2jM++0Swe0MIge8CPvTbTLQzIhedcx/ 2WP87kugxTjUJ9HTIscFToE= X-Received: by 2002:a17:906:b1cc:b0:8b1:7684:dfab with SMTP id bv12-20020a170906b1cc00b008b17684dfabmr19005757ejb.38.1678265077771; Wed, 08 Mar 2023 00:44:37 -0800 (PST) Received: from xeon.. ([188.163.112.76]) by smtp.gmail.com with ESMTPSA id p8-20020a170906838800b008ee95ccfe06sm7163891ejx.119.2023.03.08.00.44.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Mar 2023 00:44:37 -0800 (PST) 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 Message-Id: <20230308084419.11934-5-clamor95@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230308084419.11934-1-clamor95@gmail.com> References: <20230308084419.11934-1-clamor95@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759789956788708793?= X-GMAIL-MSGID: =?utf-8?q?1759789956788708793?= |
Series |
Add optional properties to MAX17040
|
|
Commit Message
Svyatoslav Ryhel
March 8, 2023, 8:44 a.m. UTC
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(+)
Comments
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@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; 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. Best regards, Krzysztof
ср, 8 бер. 2023 р. о 11:08 Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> пише: > > 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@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; > > 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 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. > > Best regards, > Krzysztof >
On 08/03/2023 10:23, Svyatoslav Ryhel wrote: > ср, 8 бер. 2023 р. о 11:08 Krzysztof Kozlowski > <krzysztof.kozlowski@linaro.org> пише: >> >> 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@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; >> >> 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
Hi Svyatoslav, Thank you for the patch! Yet something to improve: [auto build test ERROR on sre-power-supply/for-next] [also build test ERROR on krzk-dt/for-next linus/master v6.3-rc1 next-20230308] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Svyatoslav-Ryhel/dt-bindings-power-supply-maxim-max17040-update-properties/20230308-164538 base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next patch link: https://lore.kernel.org/r/20230308084419.11934-5-clamor95%40gmail.com patch subject: [PATCH v1 4/4] power: max17040: get thermal data from adc if available config: xtensa-randconfig-r002-20230308 (https://download.01.org/0day-ci/archive/20230309/202303090802.G5XRtUbY-lkp@intel.com/config) compiler: xtensa-linux-gcc (GCC) 12.1.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/7b9bbf6f2b910ef4ffab18022223573e9094f007 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Svyatoslav-Ryhel/dt-bindings-power-supply-maxim-max17040-update-properties/20230308-164538 git checkout 7b9bbf6f2b910ef4ffab18022223573e9094f007 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=xtensa olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=xtensa SHELL=/bin/bash If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> | Link: https://lore.kernel.org/oe-kbuild-all/202303090802.G5XRtUbY-lkp@intel.com/ All errors (new ones prefixed by >>): arch/xtensa/kernel/entry.o: in function `fast_syscall_spill_registers': arch/xtensa/kernel/entry.S:1424:(.exception.text+0x1e3): dangerous relocation: windowed longcall crosses 1GB boundary; return may fail: make_task_dead xtensa-linux-ld: drivers/power/supply/max17040_battery.o: in function `max17040_stop_work': >> max17040_battery.c:(.text+0x60): undefined reference to `iio_read_channel_raw' xtensa-linux-ld: drivers/power/supply/max17040_battery.o: in function `max17040_get_property': max17040_battery.c:(.text+0x11e): undefined reference to `iio_read_channel_raw' >> xtensa-linux-ld: max17040_battery.c:(.text+0x170): undefined reference to `iio_channel_release' xtensa-linux-ld: drivers/power/supply/max17040_battery.o: in function `max17040_remove': >> max17040_battery.c:(.text+0x188): undefined reference to `iio_channel_release' >> xtensa-linux-ld: max17040_battery.c:(.text+0x260): undefined reference to `iio_channel_get' xtensa-linux-ld: drivers/power/supply/max17040_battery.o: in function `max17040_probe': >> max17040_battery.c:(.text+0x542): undefined reference to `iio_channel_get'
Hi Svyatoslav, Thank you for the patch! Yet something to improve: [auto build test ERROR on sre-power-supply/for-next] [also build test ERROR on krzk-dt/for-next linus/master v6.3-rc1 next-20230308] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Svyatoslav-Ryhel/dt-bindings-power-supply-maxim-max17040-update-properties/20230308-164538 base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next patch link: https://lore.kernel.org/r/20230308084419.11934-5-clamor95%40gmail.com patch subject: [PATCH v1 4/4] power: max17040: get thermal data from adc if available config: hexagon-randconfig-r035-20230308 (https://download.01.org/0day-ci/archive/20230309/202303090817.SuiCpxvy-lkp@intel.com/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 67409911353323ca5edf2049ef0df54132fa1ca7) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/7b9bbf6f2b910ef4ffab18022223573e9094f007 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Svyatoslav-Ryhel/dt-bindings-power-supply-maxim-max17040-update-properties/20230308-164538 git checkout 7b9bbf6f2b910ef4ffab18022223573e9094f007 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> | Link: https://lore.kernel.org/oe-kbuild-all/202303090817.SuiCpxvy-lkp@intel.com/ All errors (new ones prefixed by >>): >> ld.lld: error: undefined symbol: iio_channel_release >>> referenced by max17040_battery.c:586 (drivers/power/supply/max17040_battery.c:586) >>> drivers/power/supply/max17040_battery.o:(max17040_remove) in archive vmlinux.a >>> referenced by max17040_battery.c:586 (drivers/power/supply/max17040_battery.c:586) >>> drivers/power/supply/max17040_battery.o:(max17040_remove) in archive vmlinux.a -- >> ld.lld: error: undefined symbol: iio_channel_get >>> referenced by max17040_battery.c:572 (drivers/power/supply/max17040_battery.c:572) >>> drivers/power/supply/max17040_battery.o:(max17040_probe) in archive vmlinux.a >>> referenced by max17040_battery.c:572 (drivers/power/supply/max17040_battery.c:572) >>> drivers/power/supply/max17040_battery.o:(max17040_probe) in archive vmlinux.a -- >> ld.lld: error: undefined symbol: iio_read_channel_raw >>> referenced by max17040_battery.c:422 (drivers/power/supply/max17040_battery.c:422) >>> drivers/power/supply/max17040_battery.o:(max17040_get_property) in archive vmlinux.a >>> referenced by max17040_battery.c:422 (drivers/power/supply/max17040_battery.c:422) >>> drivers/power/supply/max17040_battery.o:(max17040_get_property) in archive vmlinux.a
Hi Svyatoslav, Thank you for the patch! Yet something to improve: [auto build test ERROR on sre-power-supply/for-next] [also build test ERROR on krzk-dt/for-next linus/master v6.3-rc1 next-20230308] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Svyatoslav-Ryhel/dt-bindings-power-supply-maxim-max17040-update-properties/20230308-164538 base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next patch link: https://lore.kernel.org/r/20230308084419.11934-5-clamor95%40gmail.com patch subject: [PATCH v1 4/4] power: max17040: get thermal data from adc if available config: csky-randconfig-r015-20230308 (https://download.01.org/0day-ci/archive/20230309/202303090836.dpbjGxDu-lkp@intel.com/config) compiler: csky-linux-gcc (GCC) 12.1.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/7b9bbf6f2b910ef4ffab18022223573e9094f007 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Svyatoslav-Ryhel/dt-bindings-power-supply-maxim-max17040-update-properties/20230308-164538 git checkout 7b9bbf6f2b910ef4ffab18022223573e9094f007 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=csky olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=csky SHELL=/bin/bash If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> | Link: https://lore.kernel.org/oe-kbuild-all/202303090836.dpbjGxDu-lkp@intel.com/ All errors (new ones prefixed by >>): csky-linux-ld: drivers/power/supply/max17040_battery.o: in function `max17040_get_property': >> drivers/power/supply/max17040_battery.c:422: undefined reference to `iio_read_channel_raw' csky-linux-ld: drivers/power/supply/max17040_battery.o: in function `max17040_remove': >> drivers/power/supply/max17040_battery.c:586: undefined reference to `iio_channel_release' >> csky-linux-ld: drivers/power/supply/max17040_battery.c:587: undefined reference to `iio_read_channel_raw' >> csky-linux-ld: drivers/power/supply/max17040_battery.c:587: undefined reference to `iio_channel_release' csky-linux-ld: drivers/power/supply/max17040_battery.o: in function `max17040_probe': >> drivers/power/supply/max17040_battery.c:572: undefined reference to `iio_channel_get' csky-linux-ld: drivers/power/supply/max17040_battery.o: in function `max17040_work': drivers/power/supply/max17040_battery.c:297: undefined reference to `iio_channel_get' pahole: .tmp_vmlinux.btf: Invalid argument .btf.vmlinux.bin.o: file not recognized: file format not recognized vim +422 drivers/power/supply/max17040_battery.c 386 387 static int max17040_get_property(struct power_supply *psy, 388 enum power_supply_property psp, 389 union power_supply_propval *val) 390 { 391 struct max17040_chip *chip = power_supply_get_drvdata(psy); 392 393 switch (psp) { 394 case POWER_SUPPLY_PROP_ONLINE: 395 case POWER_SUPPLY_PROP_PRESENT: 396 val->intval = max17040_get_online(chip); 397 break; 398 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 399 val->intval = max17040_get_vcell(chip); 400 break; 401 case POWER_SUPPLY_PROP_CAPACITY: 402 val->intval = max17040_get_soc(chip); 403 break; 404 case POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN: 405 val->intval = chip->low_soc_alert; 406 break; 407 408 case POWER_SUPPLY_PROP_STATUS: 409 case POWER_SUPPLY_PROP_HEALTH: 410 power_supply_get_property_from_supplier(psy, psp, val); 411 break; 412 case POWER_SUPPLY_PROP_TECHNOLOGY: 413 val->intval = chip->batt_info->technology; 414 break; 415 case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: 416 val->intval = chip->batt_info->energy_full_design_uwh; 417 break; 418 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: 419 val->intval = chip->batt_info->charge_full_design_uah; 420 break; 421 case POWER_SUPPLY_PROP_TEMP: > 422 iio_read_channel_raw(chip->channel_temp, 423 &val->intval); 424 val->intval *= 10; 425 break; 426 case POWER_SUPPLY_PROP_TEMP_MIN: 427 if (chip->batt_info->temp_min == INT_MIN) 428 return -ENODATA; 429 430 val->intval = chip->batt_info->temp_min * 10; 431 break; 432 case POWER_SUPPLY_PROP_TEMP_MAX: 433 if (chip->batt_info->temp_max == INT_MAX) 434 return -ENODATA; 435 436 val->intval = chip->batt_info->temp_max * 10; 437 break; 438 default: 439 return -EINVAL; 440 } 441 return 0; 442 } 443 444 static const struct regmap_config max17040_regmap = { 445 .reg_bits = 8, 446 .reg_stride = 2, 447 .val_bits = 16, 448 .val_format_endian = REGMAP_ENDIAN_BIG, 449 }; 450 451 static enum power_supply_property max17040_battery_props[] = { 452 POWER_SUPPLY_PROP_ONLINE, 453 POWER_SUPPLY_PROP_PRESENT, 454 POWER_SUPPLY_PROP_VOLTAGE_NOW, 455 POWER_SUPPLY_PROP_CAPACITY, 456 POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN, 457 POWER_SUPPLY_PROP_TECHNOLOGY, 458 POWER_SUPPLY_PROP_STATUS, 459 POWER_SUPPLY_PROP_HEALTH, 460 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, 461 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, 462 POWER_SUPPLY_PROP_TEMP, 463 POWER_SUPPLY_PROP_TEMP_MIN, 464 POWER_SUPPLY_PROP_TEMP_MAX, 465 }; 466 467 static const struct power_supply_desc max17040_battery_desc = { 468 .name = "battery", 469 .type = POWER_SUPPLY_TYPE_BATTERY, 470 .get_property = max17040_get_property, 471 .set_property = max17040_set_property, 472 .property_is_writeable = max17040_prop_writeable, 473 .properties = max17040_battery_props, 474 .num_properties = ARRAY_SIZE(max17040_battery_props), 475 }; 476 477 static int max17040_probe(struct i2c_client *client) 478 { 479 const struct i2c_device_id *id = i2c_client_get_device_id(client); 480 struct i2c_adapter *adapter = client->adapter; 481 struct power_supply_config psy_cfg = {}; 482 struct max17040_chip *chip; 483 enum chip_id chip_id; 484 bool enable_irq = false; 485 int ret; 486 487 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) 488 return -EIO; 489 490 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); 491 if (!chip) 492 return -ENOMEM; 493 494 chip->client = client; 495 chip->regmap = devm_regmap_init_i2c(client, &max17040_regmap); 496 if (IS_ERR(chip->regmap)) 497 return PTR_ERR(chip->regmap); 498 chip_id = (enum chip_id) id->driver_data; 499 if (client->dev.of_node) { 500 ret = max17040_get_of_data(chip); 501 if (ret) 502 return ret; 503 chip_id = (uintptr_t)of_device_get_match_data(&client->dev); 504 } 505 chip->data = max17040_family[chip_id]; 506 507 i2c_set_clientdata(client, chip); 508 psy_cfg.drv_data = chip; 509 510 chip->battery = devm_power_supply_register(&client->dev, 511 &max17040_battery_desc, &psy_cfg); 512 if (IS_ERR(chip->battery)) { 513 dev_err(&client->dev, "failed: power supply register\n"); 514 return PTR_ERR(chip->battery); 515 } 516 517 if (client->dev.of_node) { 518 if (power_supply_get_battery_info(chip->battery, &chip->batt_info)) 519 dev_warn(&client->dev, 520 "No monitored battery, some properties will be missing\n"); 521 } 522 523 ret = max17040_get_version(chip); 524 if (ret < 0) 525 return ret; 526 dev_dbg(&chip->client->dev, "MAX17040 Fuel-Gauge Ver 0x%x\n", ret); 527 528 if (chip_id == ID_MAX17040 || chip_id == ID_MAX17041) 529 max17040_reset(chip); 530 531 max17040_set_rcomp(chip, chip->rcomp); 532 533 /* check interrupt */ 534 if (client->irq && chip->data.has_low_soc_alert) { 535 ret = max17040_set_low_soc_alert(chip, chip->low_soc_alert); 536 if (ret) { 537 dev_err(&client->dev, 538 "Failed to set low SOC alert: err %d\n", ret); 539 return ret; 540 } 541 542 enable_irq = true; 543 } 544 545 if (client->irq && chip->data.has_soc_alert) { 546 ret = max17040_set_soc_alert(chip, 1); 547 if (ret) { 548 dev_err(&client->dev, 549 "Failed to set SOC alert: err %d\n", ret); 550 return ret; 551 } 552 enable_irq = true; 553 } else { 554 /* soc alerts negate the need for polling */ 555 INIT_DEFERRABLE_WORK(&chip->work, max17040_work); 556 ret = devm_add_action(&client->dev, max17040_stop_work, chip); 557 if (ret) 558 return ret; 559 max17040_queue_work(chip); 560 } 561 562 if (enable_irq) { 563 ret = max17040_enable_alert_irq(chip); 564 if (ret) { 565 client->irq = 0; 566 dev_warn(&client->dev, 567 "Failed to get IRQ err %d\n", ret); 568 } 569 } 570 571 if (of_property_read_bool(client->dev.of_node, "io-channels")) { > 572 chip->channel_temp = iio_channel_get(&client->dev, "temp"); 573 if (IS_ERR(chip->channel_temp)) 574 return dev_err_probe(&client->dev, PTR_ERR(chip->channel_temp), 575 "failed to get temp\n"); 576 }; 577 578 return 0; 579 } 580 581 static void max17040_remove(struct i2c_client *client) 582 { 583 struct max17040_chip *chip = i2c_get_clientdata(client); 584 585 if (chip->channel_temp) > 586 iio_channel_release(chip->channel_temp); > 587 } 588
Hi, On Wed, Mar 08, 2023 at 10:44:19AM +0200, 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@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; return iio_read_channel_processed_scale(chip->channel_temp, &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, You should only expose this, if chip->channel_temp is not NULL. Use devm_kmemdup() to copy the array into a private copy in chip and modify it on the fly. > 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")) { device_property_present() > + chip->channel_temp = iio_channel_get(&client->dev, "temp"); devm_iio_channel_get() > + if (IS_ERR(chip->channel_temp)) > + return dev_err_probe(&client->dev, PTR_ERR(chip->channel_temp), > + "failed to get temp\n"); > + }; Also this must be acquired before registering the power-supply device. -- Sebastian > + > 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 >
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);