From nobody Thu Apr 9 13:31:47 2026 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63B0438553E for ; Fri, 27 Feb 2026 07:15:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772176518; cv=none; b=iIv7eE+lQMuMzth0/xXqpMtjUbDelJ0pJvjrYLQ28QstwfJxGq/rmra3LqiBc9LzgGBoNVo9TShyDyqNe7PrHZkADxrffLQb678NdDUEYB5IxeodgQFBG4bvc4gDzn9wtIgSN3L+qt7vFUR/AjUZf6NQCWR+Fr2XAZVZlquNS+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772176518; c=relaxed/simple; bh=aSX81ZyZDrEK62Qx+282skeF6cwlfyKFGDM/zj98kpI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LqGfxg6lL1zteUGBpemJSecC8DPEZZyKXmfL26t1braEKdRbWr2gQ2S4sWTJhRtbX5B2r7dyxBIGn6Qm+xR8nP4hWndhJ0gfSToDv2DgSn2Ao0kybP74YJkvPFWkg2bmK44nnvsABUwwBkylB0aMt00BXoDqrqm71dur2nnC7tE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=uSqFNPfp; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="uSqFNPfp" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-b886fc047d5so284943066b.3 for ; Thu, 26 Feb 2026 23:15:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1772176515; x=1772781315; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=6JgNbWns3UwEKgdueIS9H9aOU4yehTOts0vV7aSX/bI=; b=uSqFNPfplF/QefouVlA5AM+Q639C6kVQ81yCLxbS9NctbH/RH4juFR/8nogik3PdOV iQbVAGotM6U252OdMzyZeKrk8gAUkkRQUyBhRkPAhJ1P2whLslb1ueHKNLSu2OyyhKeU RbaO6HU/bIUqkRHJiX1h6KlfIlOouoYamKcU0DTD27aY2HIfFowwHHaoQImMX1Qt6+/Z APHO4bsajkxY0YNeuTuFb1UlcKk/AnDrnGnyNMDzwMfqO3idx6iLqxIwhwNjwWPI/Ckm 63QmPpZtX+3kZR5sUxp+cIBSFlkLtza0WXsBKCUMqlBio+8O/fMI9M4j2CazUgz28SG7 NvdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772176515; x=1772781315; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=6JgNbWns3UwEKgdueIS9H9aOU4yehTOts0vV7aSX/bI=; b=Zn5kxQDChnFNvVs6OQ28Yi2imNP67Z5xDGa9JmjQDvtEHYIyISkTF5EML3j/k6d+mh KcB3YcvieYe1486TIL/5L9GbKrlUrNvPUzht1EaYokTvss64eyjguD+Lxb9xlDF2TRNQ O783nbyddZu0BqPQ+9Ck4xZO5ZbByjFz/O+i012A3cIcR0mrUsDmgdkaxrfikVq7kOf3 tzjNo+9SOmGT92WeOCQt55ChMQMcWcrHHIsRJJvVQilLodZ74xZRK7DwK9HTZotBo/FA ttIzMzbFIV5fUe+TC8pYnS3/KqxqwLzxRdQQ9gdxb6F7cgDgyBRe8UO++mpN+t6jVWEF ZG6A== X-Forwarded-Encrypted: i=1; AJvYcCUozHwdbXwVCHlZTZvl24bXMR9eD2if1RXbfV+KBoiz2fO5Rbzjw04ftadOSlF5myoQReQatfGlUYUaWfw=@vger.kernel.org X-Gm-Message-State: AOJu0Yznpa1Au1mQKuQC+6zWTw3FtWxc/CEdosUxYZwgsM+f+FyBf5Ef Rg0ikymU2I4WaXLRv6eG2ujpMgIKaX3wPSiCaY8cKlP3AYt2CAhpzUjvdsW9Gk3xKfk= X-Gm-Gg: ATEYQzyAEk5wl8o3vYAckLOp3lugL62cJy47Jh4uwPDsDxVbt+QRlXLEuFdEb7Zy2Cc Vb+DaqwzUABSf/twh+/P/ZUE7Wg3dywoyueO2qJFk+rN35VeoY4T9lfzqMQyd6+/h2vYas3jVD8 qpArPPvLilk5eTT7BNLZrmcoo8LQgdumwlosfNgTAASvIU5xPmbT7/QwREQKv0fGU1k6+ZdpYwG PzGk1X/KTB1uOq4gNzAlouOnZjMGRE3L0Gf8zHoTqrsztJaIgdEVo5q3H+vqFdfWfZBBW11ukCk AbsWuVH1s+h9zJ+lCdJF43uQrOfWybIwYkWhdNFydFkY0gele66oe+akw//oxYOCfAnCBKSthwa qiAVxBtF9QwqCml//mAOP9VL92C8YeTTHsq3Fyy/1VYKtr02ckVrffBbS1lK5YweVyIBKIb97+W uKdLuuDttBbsQRUMcf1xtAEkG/80UzlMPeFKNmJkhwIMUS+XGWgdJyx5SByG2CK76O/6uHh4a09 uQwGAjG6MfF9/biSA== X-Received: by 2002:a17:907:1c93:b0:b88:64e9:899d with SMTP id a640c23a62f3a-b93764f4458mr110537166b.34.1772176514701; Thu, 26 Feb 2026 23:15:14 -0800 (PST) Received: from puffmais2.c.googlers.com (244.175.141.34.bc.googleusercontent.com. [34.141.175.244]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b935aeee867sm124205066b.66.2026.02.26.23.15.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 23:15:14 -0800 (PST) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Fri, 27 Feb 2026 07:15:15 +0000 Subject: [PATCH v2 10/11] power: supply: max17042: consider task period (max77759) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260227-max77759-fg-v2-10-e50be5f191f0@linaro.org> References: <20260227-max77759-fg-v2-0-e50be5f191f0@linaro.org> In-Reply-To: <20260227-max77759-fg-v2-0-e50be5f191f0@linaro.org> To: Hans de Goede , Krzysztof Kozlowski , Marek Szyprowski , Sebastian Krzyszkowiak , Purism Kernel Team , Sebastian Reichel , Rob Herring , Conor Dooley Cc: Peter Griffin , Tudor Ambarus , Juan Yescas , Amit Sunil Dhamne , kernel-team@android.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Andr=C3=A9_Draszik?= X-Mailer: b4 0.14.3 Several (register) values reported by the fuel gauge depend on its internal task period and it needs to be taken into account when calculating results. All relevant example formulas in the data sheet assume the default task period (of 5760) and final results need to be adjusted based on the task period in effect. Update the code as and where necessary. Signed-off-by: Andr=C3=A9 Draszik Reviewed-by: Peter Griffin --- While I do believe this should apply to all devices supported by this driver, given the register description in max17042_battery.h, I've made this change specific to max77759, as I have no way to confirm this works as expected on those. I've found a data sheet for max17047/max17050 online, which does describe the relevant register 0x3c as 'reserved', hence I'm a bit hesitant to enable this for all. v2: * update commit message subject prefix --- drivers/power/supply/max17042_battery.c | 20 ++++++++++++++++++++ include/linux/power/max17042_battery.h | 1 + 2 files changed, 21 insertions(+) diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply= /max17042_battery.c index 44626abdab34..89909b140cf9 100644 --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -61,6 +61,7 @@ struct max17042_chip { struct work_struct work; int init_complete; int irq; + int task_period; }; =20 static enum power_supply_property max17042_battery_props[] =3D { @@ -335,6 +336,8 @@ static int max17042_get_property(struct power_supply *p= sy, return ret; =20 data64 =3D data * 5000000ll; + data64 *=3D chip->task_period; + do_div(data64, MAX17042_DEFAULT_TASK_PERIOD); do_div(data64, chip->pdata->r_sns); val->intval =3D data64; break; @@ -344,6 +347,8 @@ static int max17042_get_property(struct power_supply *p= sy, return ret; =20 data64 =3D data * 5000000ll; + data64 *=3D chip->task_period; + do_div(data64, MAX17042_DEFAULT_TASK_PERIOD); do_div(data64, chip->pdata->r_sns); val->intval =3D data64; break; @@ -353,6 +358,8 @@ static int max17042_get_property(struct power_supply *p= sy, return ret; =20 data64 =3D data * 5000000ll; + data64 *=3D chip->task_period; + do_div(data64, MAX17042_DEFAULT_TASK_PERIOD); do_div(data64, chip->pdata->r_sns); val->intval =3D data64; break; @@ -362,6 +369,8 @@ static int max17042_get_property(struct power_supply *p= sy, return ret; =20 data64 =3D sign_extend64(data, 15) * 5000000ll; + data64 *=3D chip->task_period; + data64 =3D div_s64(data64, MAX17042_DEFAULT_TASK_PERIOD); val->intval =3D div_s64(data64, chip->pdata->r_sns); break; case POWER_SUPPLY_PROP_TEMP: @@ -1146,6 +1155,17 @@ static int max17042_probe(struct i2c_client *client,= struct device *dev, int irq regmap_write(chip->regmap, MAX17042_LearnCFG, 0x0007); } =20 + chip->task_period =3D MAX17042_DEFAULT_TASK_PERIOD; + if (chip->chip_type =3D=3D MAXIM_DEVICE_TYPE_MAX77759) { + ret =3D regmap_read(chip->regmap, MAX17042_TaskPeriod, &val); + if (ret) + return dev_err_probe(dev, ret, + "failed to read task period\n"); + chip->task_period =3D val; + } + dev_dbg(dev, "task period: %#.4x (%d)\n", chip->task_period, + chip->task_period); + chip->battery =3D devm_power_supply_register(dev, max17042_desc, &psy_cfg); if (IS_ERR(chip->battery)) diff --git a/include/linux/power/max17042_battery.h b/include/linux/power/m= ax17042_battery.h index 05097f08ea36..d5b08313cf11 100644 --- a/include/linux/power/max17042_battery.h +++ b/include/linux/power/max17042_battery.h @@ -17,6 +17,7 @@ #define MAX17042_DEFAULT_VMAX (4500) /* LiHV cell max */ #define MAX17042_DEFAULT_TEMP_MIN (0) /* For sys without temp sensor */ #define MAX17042_DEFAULT_TEMP_MAX (700) /* 70 degrees Celcius */ +#define MAX17042_DEFAULT_TASK_PERIOD (5760) =20 /* Consider RepCap which is less then 10 units below FullCAP full */ #define MAX17042_FULL_THRESHOLD 10 --=20 2.53.0.473.g4a7958ca14-goog