From: Thomas Antoine <t.antoine@uclouvain.be>
To: "André Draszik" <andre.draszik@linaro.org>,
"Sebastian Reichel" <sre@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Dimitri Fedrau" <dima.fedrau@gmail.com>,
"Catalin Marinas" <catalin.marinas@arm.com>,
"Will Deacon" <will@kernel.org>,
"Peter Griffin" <peter.griffin@linaro.org>,
"Alim Akhtar" <alim.akhtar@samsung.com>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-samsung-soc@vger.kernel.org
Subject: Re: [PATCH v2 1/4] power: supply: add support for max77759 fuel gauge
Date: Fri, 10 Jan 2025 17:56:24 +0100 [thread overview]
Message-ID: <7d8d2406-fd49-446d-82e9-e088eaa7a9d1@uclouvain.be> (raw)
In-Reply-To: <7178eb322fafaf0fbcdc4b91d9f9a65d996e4e6b.camel@linaro.org>
Hi,
Thanks for taking the time to test the system.
On 1/7/25 12:00, André Draszik wrote:
> Hi Thomas,
>
> Thanks for your patch!
>
> On Thu, 2025-01-02 at 12:15 +0100, Thomas Antoine via B4 Relay wrote:
>> From: Thomas Antoine <t.antoine@uclouvain.be>
>>
>> The interface of the Maxim max77759 fuel gauge has a lot of common with the
>> Maxim max1720x. The major difference is the lack of non-volatile memory
>> slave address. No slave is available at address 0xb of the i2c bus, which
>> is coherent with the following driver from google: line 5836 disables
>> non-volatile memory for m5 gauge.
>>
>> https://android.googlesource.com/kernel/google-modules/bms/+/1a68c36bef474573cc8629cc1d121eb6a81ab68c/max1720x_battery.c
>>
>> Other differences include the lack of V_BATT register to read the battery
>> level and a difference in the way to identify the chip (the same register
>> is used but not the same mask).
>
> It also seems the reported POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN is
> quite a bit off - on my Pixel 6, it reports ca. 1131mAh, but the downstream
> stack reports a more reasonable 4524mAh. Interestingly, this is an exact
> multiple of four.
>
> POWER_SUPPLY_PROP_CHARGE_FULL is off in a similar way, and I suspect that
> related properties like charge_avg, time_to_empty, time_to_full are
> reported incorrectly as well.
Indeed, now that I check the code, the current computation is wrong.
In the downstream kernel, reg_to_capacity_uah is used to translate the register
value. In the end, it computes the value as follows:
div_s64((s64) val * 500000, rsense) * lsb;
Link: https://android.googlesource.com/kernel/google-modules/bms/+/refs/heads/android-gs-raviole-5.10-android15/max1720x_battery.h#36
whereas the mainline driver does val * 500.
Based on what I saw, lsb should be 1 to 2 based on the value of the register
MAX_M5_TASKPERIOD.
Basically, if lsb is 1 and given the default rsense of the mainline driver,
the two functions will return the same.
From the datasheet of the max17201, capacity LSB is "5.0μVh/RSENSE".
So it seems that the current mainline driver is only right if rsense is equal
to 10mOhms.
The factor 4 that you see should thus come from
1. a factor 2 because we do 5.0μVh/10mOhm instead of 5.0μVh/5mOhm.
2. a factor 2 because we do not take into account lsb.
MAX_M5_TASKPERIOD is reg 0x3c which is not mentionned at all in the datasheet
of the max17201. I guess this might be another difference between the two
devices.
I think the best course of action is to correct the computation to take into
account rsense and to then multiply by lsb only for max77759.
This would make the behaviour of the max17201 follow the datasheet.
> [...]
>
>> @@ -483,14 +608,27 @@ static int max1720x_probe(struct i2c_client *client)
>> psy_cfg.drv_data = info;
>> psy_cfg.fwnode = dev_fwnode(dev);
>> i2c_set_clientdata(client, info);
>> - info->regmap = devm_regmap_init_i2c(client, &max1720x_regmap_cfg);
>> +
>> + data = device_get_match_data(dev);
>> + if (!data)
>> + return dev_err_probe(dev, ret, "Failed to get chip data\n");
> ^^^
> This should be -EINVAL.
Indeed, will fix.
Best regards,
Thomas
next prev parent reply other threads:[~2025-01-10 16:57 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-02 11:15 [PATCH v2 0/4] Google Pixel 6 (oriole): max77759 fuel gauge enablement and driver support Thomas Antoine via B4 Relay
2025-01-02 11:15 ` [PATCH v2 1/4] power: supply: add support for max77759 fuel gauge Thomas Antoine via B4 Relay
2025-01-06 15:16 ` Dimitri Fedrau
2025-01-10 16:01 ` Thomas Antoine
2025-01-07 11:00 ` André Draszik
2025-01-10 16:56 ` Thomas Antoine [this message]
2025-01-07 18:10 ` Christophe JAILLET
2025-01-10 15:46 ` Thomas Antoine
2025-01-08 9:49 ` Peter Griffin
2025-01-15 21:30 ` Sebastian Reichel
2025-04-07 11:29 ` André Draszik
2025-01-02 11:15 ` [PATCH v2 2/4] dt-bindings: power: supply: add max77759-fg flavor Thomas Antoine via B4 Relay
2025-01-02 16:08 ` Krzysztof Kozlowski
2025-01-03 16:16 ` Thomas Antoine
2025-01-04 9:23 ` Krzysztof Kozlowski
2025-01-02 11:15 ` [PATCH v2 3/4] arm64: defconfig: enable Maxim max1720x driver Thomas Antoine via B4 Relay
2025-01-07 11:12 ` André Draszik
2025-01-02 11:15 ` [PATCH v2 4/4] arm64: dts: exynos: gs101-oriole: enable Maxim max77759 fuel gauge Thomas Antoine via B4 Relay
2025-01-07 9:06 ` André Draszik
2025-01-10 15:42 ` Thomas Antoine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7d8d2406-fd49-446d-82e9-e088eaa7a9d1@uclouvain.be \
--to=t.antoine@uclouvain.be \
--cc=alim.akhtar@samsung.com \
--cc=andre.draszik@linaro.org \
--cc=catalin.marinas@arm.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dima.fedrau@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=peter.griffin@linaro.org \
--cc=robh@kernel.org \
--cc=sre@kernel.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox