From patchwork Mon Jul 31 07:36:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Svyatoslav Ryhel X-Patchwork-Id: 128402 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp1862462vqg; Mon, 31 Jul 2023 01:02:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlEkk088A2ao3CR9s0t9G1Dn4gRdPgUVb8ZRrRD7dYv4GQC63ATZZbTs+mwrr6zEVKBVnPra X-Received: by 2002:a17:906:cc13:b0:992:a90a:5d1f with SMTP id ml19-20020a170906cc1300b00992a90a5d1fmr5780185ejb.68.1690790543505; Mon, 31 Jul 2023 01:02:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690790543; cv=none; d=google.com; s=arc-20160816; b=oLrWEu1J7mVXQcHDTA3MNkF068igTumZJXIWwTMOqYts4rCd625pjLLwfLgrmgchCW eC9AIyQtRparQ7tFCHoKGrdO223IvV6HylV32VQ/pQ63p0pjFwyRxmCSIoIUz2dPWzVe N3eZmhRdIYq18nUfNVKTwiW1KM1emn0TpxvmxD6+FtccfuFkIH87trL53WU043ZwmBeW Q7dF8pSVGKONYDvmh45UG78YyrJkGTV75pWczxoBPmeQx5ksOOgWIAmfFR+sI67oSgSE USIVPrMQc4iLp5pPFya3N2MnAnVhKDzjZ1ij/D45/p8TRJkcry8OLDZFsBZnImlrFPgY XFLQ== 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=UDXgSylBUJtlqgXKl+eFyzEmuuOxDLbY4Ry7v67coaU=; fh=BYYxYocqtJiC/MlqHuXF0UZXhvoN/4a0Xtp0KZwYhQ0=; b=MozsnEmEe9JordJnkxsSn9yOm9Yyl5Tj+VbrCdQybbNg24LWUGobHqLFVvABY+Jn5W iNj0r++BP53H1/u1aeEqvN76dCb/W+1GwuA+6xQ+E5n/aLyTAZwFehBEAdoIHlcF5D17 QPxKX5tRHPuJHYd6ww1DzoAPVHsFd7OItsroXPGkWhwzxSb5rvU/rmpr3rs00D4AeePt lQcoCiN08lK4k3MeQPc3epknVDCSjYd/+OEURTyt8umThEipYkYmU5/5cUNrOx4fRAJr wc1z6uL8kgdRBAi0VWJnuxvtjiTUonnZ1GH6R/NDWAABa/v0TfCuNhXpXsl2qZJ6zC6R kcgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=M+YmC08C; 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 ga15-20020a170906b84f00b0098cee0f8cfesi7314000ejb.969.2023.07.31.01.01.58; Mon, 31 Jul 2023 01:02:23 -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=M+YmC08C; 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 S231389AbjGaHhH (ORCPT + 99 others); Mon, 31 Jul 2023 03:37:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231280AbjGaHgs (ORCPT ); Mon, 31 Jul 2023 03:36:48 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E0FF11B; Mon, 31 Jul 2023 00:36:47 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-4fe28f92d8eso2078000e87.1; Mon, 31 Jul 2023 00:36:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690789005; x=1691393805; 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=UDXgSylBUJtlqgXKl+eFyzEmuuOxDLbY4Ry7v67coaU=; b=M+YmC08CYkEd/jALSE78ke/tk19xg7gETYrI9RtT46ASu0nDcTimuCNCo4EEtrz6ov 5D8N2FpMJGBgFJpLZiRXgpSGMWDDgHLA3whI3hP4xZOBs/41HeeuN75/hdABoiCkKR/x ZAWGLeEp1XhiphGT2d57V3xw+M8ju0IMnoPT2GS14Upj9BIdgIMx8xzcvULpMHBQPImS wr3XXNhu3XkeS1loHJGEa0LVgTLe8QWJ6zHFjs0srBHlL4O/N2pVYN86lJoMrRDeY9Mr wXdjJokRabzgMz2UNV6GXyxN85LVMnK3jc2l2KmuiTpKmKeLBNqf3M6ym+km8ZucXBUy HPRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690789005; x=1691393805; 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=UDXgSylBUJtlqgXKl+eFyzEmuuOxDLbY4Ry7v67coaU=; b=I4QIoLOP9lN03ivUaRVQBFQr+AGufk8rPkl7UBZa2coWDpKK9CXzdXpuF/kUmFdeen o4zBDczotplCBguHLywWxPONw9lhKQZBRk8EW1RRIkp1r2oiCeH66vVBqg2e4+LdL80G C5Y+sxO3YdZaHNgLYEcjQlwGa5WmP9tTutkRy1sC/V5v1Kbhlylt7+oeldMxNBsQ9Vym g7QqOOPnLsBYyueNRQIqac+/4dbqIjGtv3tgaDXKHKf8eMTAcQe9mOxz1gQ8tNIsNXGo 4r6qT7aU1YLnG54j9isTWOx+1HgQNUdzr12L/o3z6Hrxwyz53lFJ4qmpjWTmNoBu4dJU lB/Q== X-Gm-Message-State: ABy/qLYyheoHQ9wJeba1Hng6GtXJx5dpio7pd56ctYGmYdOBNB81Od/Q k/s/WUXl7KohpPtbzPOQ3rg= X-Received: by 2002:ac2:58c8:0:b0:4f9:596d:c803 with SMTP id u8-20020ac258c8000000b004f9596dc803mr4878541lfo.53.1690789005107; Mon, 31 Jul 2023 00:36:45 -0700 (PDT) Received: from xeon.. ([188.163.112.48]) by smtp.gmail.com with ESMTPSA id m14-20020a056512014e00b004fe3229e584sm586898lfo.270.2023.07.31.00.36.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 00:36:44 -0700 (PDT) From: Svyatoslav Ryhel To: Iskren Chernev , Krzysztof Kozlowski , Marek Szyprowski , Matheus Castello , Sebastian Reichel , Rob Herring , Conor Dooley , Russell King , Alim Akhtar , Arnd Bergmann , Jernej Skrabec , Svyatoslav Ryhel , Claudiu Beznea , Stefan Hansson Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org Subject: [PATCH v3 3/4] power: max17040: get thermal data from adc if available Date: Mon, 31 Jul 2023 10:36:12 +0300 Message-Id: <20230731073613.10394-4-clamor95@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230731073613.10394-1-clamor95@gmail.com> References: <20230731073613.10394-1-clamor95@gmail.com> MIME-Version: 1.0 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_NONE,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772922385059527207 X-GMAIL-MSGID: 1772922385059527207 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 --- drivers/power/supply/Kconfig | 2 +- drivers/power/supply/max17040_battery.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig index c78be9f322e6..32600609865b 100644 --- a/drivers/power/supply/Kconfig +++ b/drivers/power/supply/Kconfig @@ -374,7 +374,7 @@ config AXP288_FUEL_GAUGE config BATTERY_MAX17040 tristate "Maxim MAX17040/17041/17043 family Fuel Gauge" - depends on I2C + depends on I2C && IIO select REGMAP_I2C help Driver supports Maxim fuel-gauge systems for lithium-ion (Li+) 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 #include #include +#include #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)) {