From patchwork Sun Jul 30 17:26:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Svyatoslav Ryhel X-Patchwork-Id: 128269 Return-Path: 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 + 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 ); 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 To: Iskren Chernev , Krzysztof Kozlowski , Marek Szyprowski , Matheus Castello , Sebastian Reichel , Rob Herring , Conor Dooley , Svyatoslav Ryhel 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 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772875871874137305 X-GMAIL-MSGID: 1772875871874137305 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/max17040_battery.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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)) {