Message ID | 20230730172648.71578-4-clamor95@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp1638750vqg; Sun, 30 Jul 2023 12:43:05 -0700 (PDT) X-Google-Smtp-Source: APBJJlEKmOPGJFpa7ackgk6ndAxvUfvLeP0B0Wcu65TuCAtTb6k+o3fXbXqFXXTqBqO2xzujFe2v X-Received: by 2002:a17:906:7a08:b0:988:9621:d85f with SMTP id d8-20020a1709067a0800b009889621d85fmr4875068ejo.58.1690746184978; Sun, 30 Jul 2023 12:43:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690746184; cv=none; d=google.com; s=arc-20160816; b=K7qRnYwJcVzG9GMXiwWiVvaksyRUUViXhN5AIxW+UbVNFNBLb/KdL87uVInOFztgnG 2YEEdKMymU8Ar76r2j2s24AmI7VUEG4BLT11pbKatkN8dA3eKaCnq7pmMPtKGH4ZOFnr AETu6KaViShtUNNl47/g/5an1kTRusLPNWRecSdvmDZQBszWQq61Fs9xTpCcNA8mDqqz FFwx1IyYoLK40u3pCeQEUz26Izo0AcAjJZRD+WmfF/Gx3BbzRUo9FbrQ+vA66kiLubI9 awvbCFC2Qtsy6MNoNg8OIJVfpbbhvasDfgCmX2hkGO9ZyIc/NeFZCBxLrW2iukXH7jCO vkLQ== 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=LCibpJFPe7+Y3gfoirmVHXZU0UMpLMY1bCCkwz1GdIg=; fh=6EttwLj8TkcYgYcXwCN3+c7mDFZsrHr1IQ/n7Iq5Tzc=; b=tTu0cfBK/WX0jGmLDhxFi4QMy68vNixX4ZIUbCH4O6E0Oz+56ZdZupX5sDJYw6+us3 9eHMxSc3d5TjJMnZEz0k2VcYmg4mQQUBMyKVhBNXw3+m9T6kNwWoUoqhYmPRSiOVjmU5 jV3rPRXsL5NmZWthZbhgYLkhsYpbTF5omLkzgJ7GwoDzW9rugMLdGeE61LE8b82IZS0l adwHqF7stpPx65ZHjEKizivv+XmZnfgvT2hVeJN038XC9XuB0ANur0XqkIUnKQHmrUny 584YGF1dqNMDfxbbhfIRO1GzP+1dt4bEd3REREivmSx6nuZBE7d4YqZYwcOAqOyPdO1g YHeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=YgmwaCdD; 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 f16-20020a056402005000b005222065ee63si2205635edu.384.2023.07.30.12.42.38; Sun, 30 Jul 2023 12:43:04 -0700 (PDT) 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=20221208 header.b=YgmwaCdD; 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 S229764AbjG3R10 (ORCPT <rfc822;dengxinlin2429@gmail.com> + 99 others); Sun, 30 Jul 2023 13:27:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229770AbjG3R1S (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 30 Jul 2023 13:27:18 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB606126; Sun, 30 Jul 2023 10:27:16 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-4fe3678010eso300339e87.3; Sun, 30 Jul 2023 10:27:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690738035; x=1691342835; 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=LCibpJFPe7+Y3gfoirmVHXZU0UMpLMY1bCCkwz1GdIg=; b=YgmwaCdDVaqwRxcXmX09BtBu0LLUNDGymwZpoaNhyj7UZwjxpun3w6hwdoNJ6GC3hh WvAPKYtQ18hKzsPmLBthILLnaH/79BQby+MQGy+Rltjowbtc1ULuWvkc/vybzXBJ6Ub+ BALb2E38Fj1VOaZapw7REBlB4sOCFojR/lTUJVH4UurbU1Dl932pgv6yRO2ahT0IYmBB s4K3foqxAE3eSITBiepmcpeGPi3LPTIf9/4UusROAhXPWWtjENErbBFSAyVZ6B4z1IcC mTO6R07nhUqpDfHD3J9+mIWa3m367vJfVhifUy7nJMR1ebymxXrVQwXQhYcObGcPZOeb yReQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690738035; x=1691342835; 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=LCibpJFPe7+Y3gfoirmVHXZU0UMpLMY1bCCkwz1GdIg=; b=INtvGNuI/6WWYSS6qNlKT5ee0x/8k8PFxQ94p0rAzXjt44uMO3dlcFmL3I9+03ofLw dbhdxYvRJM8iFFHisIPGrZevxmvCIUHodV2h4VrzqaQ0mUWNTnj1NRvcS4BJX9ODwtha uXf+RVL+qVo//zCciIT0x/+7cACAdVFLMPkQGH4wV2N+l2z3/kecUKpUWvuTVyjQH9yj /THSS8BkwjuchFeYrSAHLVHcsYBB54437rYOTIE/RF4XYQaJc0D7MxKMbhjhUqZP1xMN eiSUlQpZ5yGycEhSBDwl1WFcbDCkLiZD6NngAPnvk+h2v7W5L+Yb78nXyyPtIvmvM7xu LV9A== X-Gm-Message-State: ABy/qLY95bct0TaVfrXecbFGlpghD/5F1hm2H1PLw3QAeIYyFT+Bupbw mNdocrAaWpV+YxzWkSZK4TvT7SWnePFn2A== X-Received: by 2002:a05:6512:1286:b0:4f8:5c90:f8a4 with SMTP id u6-20020a056512128600b004f85c90f8a4mr5626799lfs.33.1690738034935; Sun, 30 Jul 2023 10:27:14 -0700 (PDT) Received: from xeon.. ([188.163.112.48]) by smtp.gmail.com with ESMTPSA id x6-20020ac24886000000b004f8555f7aa1sm1737117lfc.52.2023.07.30.10.27.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jul 2023 10:27:14 -0700 (PDT) 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>, Svyatoslav Ryhel <clamor95@gmail.com> Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] power: max17040: get thermal data from adc if available Date: Sun, 30 Jul 2023 20:26:48 +0300 Message-Id: <20230730172648.71578-4-clamor95@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230730172648.71578-1-clamor95@gmail.com> References: <20230730172648.71578-1-clamor95@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 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_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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: INBOX X-GMAIL-THRID: 1772875871874137305 X-GMAIL-MSGID: 1772875871874137305 |
Series |
Add optional properties to MAX17040
|
|
Commit Message
Svyatoslav Ryhel
July 30, 2023, 5:26 p.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 | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
Comments
Hi Svyatoslav, kernel test robot noticed the following build errors: [auto build test ERROR on krzk-dt/for-next] [also build test ERROR on linus/master v6.5-rc3 next-20230728] [cannot apply to sre-power-supply/for-next] [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/20230731-012920 base: https://git.kernel.org/pub/scm/linux/kernel/git/krzk/linux-dt.git for-next patch link: https://lore.kernel.org/r/20230730172648.71578-4-clamor95%40gmail.com patch subject: [PATCH v2 3/3] power: max17040: get thermal data from adc if available config: s390-randconfig-r044-20230731 (https://download.01.org/0day-ci/archive/20230731/202307310322.iEuhtMME-lkp@intel.com/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a) reproduce: (https://download.01.org/0day-ci/archive/20230731/202307310322.iEuhtMME-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202307310322.iEuhtMME-lkp@intel.com/ All errors (new ones prefixed by >>): s390x-linux-ld: drivers/power/supply/max17040_battery.o: in function `max17040_probe': >> drivers/power/supply/max17040_battery.c:483: undefined reference to `devm_iio_channel_get' s390x-linux-ld: drivers/power/supply/max17040_battery.o: in function `max17040_get_property': >> drivers/power/supply/max17040_battery.c:413: undefined reference to `iio_read_channel_processed_scale' vim +483 drivers/power/supply/max17040_battery.c 385 386 static int max17040_get_property(struct power_supply *psy, 387 enum power_supply_property psp, 388 union power_supply_propval *val) 389 { 390 struct max17040_chip *chip = power_supply_get_drvdata(psy); 391 392 switch (psp) { 393 case POWER_SUPPLY_PROP_ONLINE: 394 case POWER_SUPPLY_PROP_PRESENT: 395 val->intval = max17040_get_online(chip); 396 break; 397 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 398 val->intval = max17040_get_vcell(chip); 399 break; 400 case POWER_SUPPLY_PROP_CAPACITY: 401 val->intval = max17040_get_soc(chip); 402 break; 403 case POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN: 404 val->intval = chip->low_soc_alert; 405 break; 406 case POWER_SUPPLY_PROP_STATUS: 407 power_supply_get_property_from_supplier(psy, psp, val); 408 break; 409 case POWER_SUPPLY_PROP_TEMP: 410 if (!chip->channel_temp) 411 return -ENODATA; 412 > 413 iio_read_channel_processed_scale(chip->channel_temp, 414 &val->intval, 10); 415 break; 416 default: 417 return -EINVAL; 418 } 419 return 0; 420 } 421 422 static const struct regmap_config max17040_regmap = { 423 .reg_bits = 8, 424 .reg_stride = 2, 425 .val_bits = 16, 426 .val_format_endian = REGMAP_ENDIAN_BIG, 427 }; 428 429 static enum power_supply_property max17040_battery_props[] = { 430 POWER_SUPPLY_PROP_ONLINE, 431 POWER_SUPPLY_PROP_PRESENT, 432 POWER_SUPPLY_PROP_VOLTAGE_NOW, 433 POWER_SUPPLY_PROP_CAPACITY, 434 POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN, 435 POWER_SUPPLY_PROP_STATUS, 436 POWER_SUPPLY_PROP_TEMP, 437 }; 438 439 static const struct power_supply_desc max17040_battery_desc = { 440 .name = "battery", 441 .type = POWER_SUPPLY_TYPE_BATTERY, 442 .get_property = max17040_get_property, 443 .set_property = max17040_set_property, 444 .property_is_writeable = max17040_prop_writeable, 445 .properties = max17040_battery_props, 446 .num_properties = ARRAY_SIZE(max17040_battery_props), 447 }; 448 449 static int max17040_probe(struct i2c_client *client) 450 { 451 const struct i2c_device_id *id = i2c_client_get_device_id(client); 452 struct i2c_adapter *adapter = client->adapter; 453 struct power_supply_config psy_cfg = {}; 454 struct max17040_chip *chip; 455 enum chip_id chip_id; 456 bool enable_irq = false; 457 int ret; 458 459 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) 460 return -EIO; 461 462 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); 463 if (!chip) 464 return -ENOMEM; 465 466 chip->client = client; 467 chip->regmap = devm_regmap_init_i2c(client, &max17040_regmap); 468 if (IS_ERR(chip->regmap)) 469 return PTR_ERR(chip->regmap); 470 chip_id = (enum chip_id) id->driver_data; 471 if (client->dev.of_node) { 472 ret = max17040_get_of_data(chip); 473 if (ret) 474 return ret; 475 chip_id = (uintptr_t)of_device_get_match_data(&client->dev); 476 } 477 chip->data = max17040_family[chip_id]; 478 479 i2c_set_clientdata(client, chip); 480 psy_cfg.drv_data = chip; 481 482 /* Switch to devm_iio_channel_get_optional when available */ > 483 chip->channel_temp = devm_iio_channel_get(&client->dev, "temp"); 484 if (IS_ERR(chip->channel_temp)) { 485 ret = PTR_ERR(chip->channel_temp); 486 if (ret != -ENODEV) 487 return dev_err_probe(&client->dev, PTR_ERR(chip->channel_temp), 488 "failed to get temp\n"); 489 else 490 chip->channel_temp = NULL; 491 } 492 493 chip->battery = devm_power_supply_register(&client->dev, 494 &max17040_battery_desc, &psy_cfg); 495 if (IS_ERR(chip->battery)) { 496 dev_err(&client->dev, "failed: power supply register\n"); 497 return PTR_ERR(chip->battery); 498 } 499 500 ret = max17040_get_version(chip); 501 if (ret < 0) 502 return ret; 503 dev_dbg(&chip->client->dev, "MAX17040 Fuel-Gauge Ver 0x%x\n", ret); 504 505 if (chip_id == ID_MAX17040 || chip_id == ID_MAX17041) 506 max17040_reset(chip); 507 508 max17040_set_rcomp(chip, chip->rcomp); 509 510 /* check interrupt */ 511 if (client->irq && chip->data.has_low_soc_alert) { 512 ret = max17040_set_low_soc_alert(chip, chip->low_soc_alert); 513 if (ret) { 514 dev_err(&client->dev, 515 "Failed to set low SOC alert: err %d\n", ret); 516 return ret; 517 } 518 519 enable_irq = true; 520 } 521 522 if (client->irq && chip->data.has_soc_alert) { 523 ret = max17040_set_soc_alert(chip, 1); 524 if (ret) { 525 dev_err(&client->dev, 526 "Failed to set SOC alert: err %d\n", ret); 527 return ret; 528 } 529 enable_irq = true; 530 } else { 531 /* soc alerts negate the need for polling */ 532 INIT_DEFERRABLE_WORK(&chip->work, max17040_work); 533 ret = devm_add_action(&client->dev, max17040_stop_work, chip); 534 if (ret) 535 return ret; 536 max17040_queue_work(chip); 537 } 538 539 if (enable_irq) { 540 ret = max17040_enable_alert_irq(chip); 541 if (ret) { 542 client->irq = 0; 543 dev_warn(&client->dev, 544 "Failed to get IRQ err %d\n", ret); 545 } 546 } 547 548 return 0; 549 } 550
Hi Svyatoslav, kernel test robot noticed the following build errors: [auto build test ERROR on krzk-dt/for-next] [also build test ERROR on linus/master v6.5-rc3 next-20230728] [cannot apply to sre-power-supply/for-next] [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/20230731-012920 base: https://git.kernel.org/pub/scm/linux/kernel/git/krzk/linux-dt.git for-next patch link: https://lore.kernel.org/r/20230730172648.71578-4-clamor95%40gmail.com patch subject: [PATCH v2 3/3] power: max17040: get thermal data from adc if available config: x86_64-buildonly-randconfig-r001-20230731 (https://download.01.org/0day-ci/archive/20230731/202307310308.FDG6br3Y-lkp@intel.com/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce: (https://download.01.org/0day-ci/archive/20230731/202307310308.FDG6br3Y-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202307310308.FDG6br3Y-lkp@intel.com/ All errors (new ones prefixed by >>): ld: vmlinux.o: in function `max17040_get_property': >> max17040_battery.c:(.text+0x1cb3dd0): undefined reference to `iio_read_channel_processed_scale' ld: vmlinux.o: in function `max17040_probe': >> max17040_battery.c:(.text+0x1cb40f5): undefined reference to `devm_iio_channel_get'
Hi Svyatoslav, kernel test robot noticed the following build errors: [auto build test ERROR on krzk-dt/for-next] [also build test ERROR on linus/master v6.5-rc3 next-20230728] [cannot apply to sre-power-supply/for-next] [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/20230731-012920 base: https://git.kernel.org/pub/scm/linux/kernel/git/krzk/linux-dt.git for-next patch link: https://lore.kernel.org/r/20230730172648.71578-4-clamor95%40gmail.com patch subject: [PATCH v2 3/3] power: max17040: get thermal data from adc if available config: i386-randconfig-i013-20230731 (https://download.01.org/0day-ci/archive/20230731/202307310455.Om3VuGqo-lkp@intel.com/config) compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07) reproduce: (https://download.01.org/0day-ci/archive/20230731/202307310455.Om3VuGqo-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202307310455.Om3VuGqo-lkp@intel.com/ All errors (new ones prefixed by >>): >> ld.lld: error: undefined symbol: devm_iio_channel_get >>> referenced by max17040_battery.c:483 (drivers/power/supply/max17040_battery.c:483) >>> drivers/power/supply/max17040_battery.o:(max17040_probe) in archive vmlinux.a -- >> ld.lld: error: undefined symbol: iio_read_channel_processed_scale >>> referenced by max17040_battery.c:413 (drivers/power/supply/max17040_battery.c:413) >>> drivers/power/supply/max17040_battery.o:(max17040_get_property) in archive vmlinux.a
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)) {