From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
To: "David Heidelberg" <david@ixit.cz>,
"Sebastian Reichel" <sre@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Casey Connolly" <casey.connolly@linaro.org>,
"Casey Connolly" <casey@connolly.tech>,
"Joel Selvaraj" <foss@joelselvaraj.com>,
"Yassine Oudjana" <y.oudjana@protonmail.com>,
"Bjorn Andersson" <andersson@kernel.org>,
"Konrad Dybcio" <konradybcio@kernel.org>,
"Alexander Martinz" <amartinz@shiftphones.com>,
"Barnabás Czémán" <barnabas.czeman@mainlining.org>,
"Richard Acayan" <mailingradian@gmail.com>,
"Alexey Minnekhanov" <alexeymin@postmarketos.org>
Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
phone-devel@vger.kernel.org
Subject: Re: [PATCH RFC 2/8] power: supply: Add driver for Qualcomm PMI8998 fuel gauge
Date: Thu, 18 Dec 2025 15:59:54 +0100 [thread overview]
Message-ID: <acc02791-1828-4578-8a8f-ef3d6824cdbf@oss.qualcomm.com> (raw)
In-Reply-To: <d84c25d7-62c7-433d-9978-dd6b20f5681c@ixit.cz>
On 12/12/25 4:22 PM, David Heidelberg wrote:
> On 27/11/2025 16:28, Konrad Dybcio wrote:
>> On 11/24/25 10:53 PM, David Heidelberg via B4 Relay wrote:
>>> From: Joel Selvaraj <foss@joelselvaraj.com>
>>>
>>> Ths driver supports the fuel gauge hardware available on PMICs known as
>>> 3rd generation fuel gauge hardware available on PMI8998.
>>>
> [...]
>
>> Downstream checks if the address is > 0xBA which is what you want
>> at least for pmi8998
>
> My downstream [1] checks this value.
https://github.com/LineageOS/android_kernel_xiaomi_sdm845/blob/lineage-22.2/drivers/power/supply/qcom/fg-util.c#L434
I can quite surely tell you "> 0xBA" is the correct condition to check
for.. both my work laptop and a downstream clone on my SSD concur that
>
> [1] https://github.com/LineageOS/android_kernel_xiaomi_sdm845/blob/lineage-22.2/drivers/power/supply/qcom/qpnp-fg.c#L760>
>> You can de-abbreviate this to 'secure_access' (not to be confused
>> with 'secondary' or so). There's a locking mechanism which needs a
>> 0xa5 byte written to the base+0xd0 register (applies to all FG
>> peripherals with the 'last non-secure register' value possibly
>> varying).
>>
>> [...]
>>
>>> + u8 sec_addr_val = 0xa5;
>>> + int ret;
>>> +
>>> + if (((chip->base + addr) & 0xff00) == 0)
>>
>> The 'fuel gauge' consists of:
>>
>> FG_BATT_SOC @ 0x4000 (state of charge monitor)
>> FG_BATT_INFO @ 0x4100 ("general fg minus SoC")
>> FG_BCL @ 0x4200 (battery current limiter)
>> FG_LMH @ 0x4300 (limits management hardware)
>> FG_MEM_IF @ 0x4400 (DMA engine)
>> RRADC @ 0x4500 (today handled by its own driver)
>>
>> and a couple other peripherals that Linux doesn't need to worry about
>>
>> Each one of them should have its own 'reg' entry (which is assumed
>> to be 0x100-long), which will let you skip such interesting checks
>> and rely on the regmap framework disallowing address spillover (or
>> you can just then make the addr argument a u8)
>
> Sounds good.
>
>>
>> It would be good to keep in mind their relationship and think about how
>> to model them together. I don't think they must all necessarily be part
>> of a single big "fg" dt node, particularly the LMH/BCL part seems to be
>> rather self-contained
>
> Would you recommend some readings to prepare for this task?
>
> I see the FG_BATT* + FG_MEM_IF seems to be pretty relying on each other, so I assume I need to take good care of that relation, when spliting pieces up.
It may be that a single "fuel-gauge@" device node may make the most
sense to represent all three of batt_soc, batt_info and mem_if.
You'll unfortunately find out whether this is a good idea as you
write/port the drivers. Downstream has some hacks around plumbing
various PMIC peripherals with just function exports between drivers,
so don't read too hard into that, just try to understand what each
piece/function is doing and how that fits into the power_supply
framework.
I'm a little unsure about bcl and lmh.. but downstream keeps them in
a single node and it doesn't seem to be that bad of an idea. There's some
LMH support today in the kernel.. but not for the PMIC peripheral. That
said, the downstream driver seems to just make the same secure calls
anyway (which may be incomplete for some platforms, I don't remember the
details: <20230113031401.2336157-3-konrad.dybcio@linaro.org>)
Konrad
next prev parent reply other threads:[~2025-12-18 15:00 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-24 21:53 [PATCH RFC 0/8] Qualcomm 3rd gen fuel gauge support David Heidelberg via B4 Relay
2025-11-24 21:53 ` [PATCH RFC 1/8] dt-bindings: power: supply: Add schema for Qualcomm pmi8998 fuel gauge David Heidelberg via B4 Relay
2025-11-27 10:32 ` Konrad Dybcio
2025-11-24 21:53 ` [PATCH RFC 2/8] power: supply: Add driver for Qualcomm PMI8998 " David Heidelberg via B4 Relay
2025-11-25 23:13 ` Dmitry Baryshkov
2025-11-26 16:35 ` Joel Selvaraj
2025-11-29 1:36 ` Dmitry Baryshkov
2025-11-27 15:28 ` Konrad Dybcio
2025-12-12 15:22 ` David Heidelberg
2025-12-18 14:59 ` Konrad Dybcio [this message]
2025-11-24 21:53 ` [PATCH RFC 3/8] arm64: dts: qcom: pmi8998: Add " David Heidelberg via B4 Relay
2025-11-25 23:16 ` Dmitry Baryshkov
2025-11-27 17:53 ` Casey Connolly
2025-11-29 2:09 ` Richard Acayan
2025-11-24 21:53 ` [PATCH RFC 4/8] arm64: dts: qcom: pm660: " David Heidelberg via B4 Relay
2025-11-25 23:17 ` Dmitry Baryshkov
2025-11-24 21:53 ` [PATCH RFC 5/8] arm64: dts: qcom: sdm845-xiaomi-beryllium: Enable " David Heidelberg via B4 Relay
2025-11-25 23:48 ` Dmitry Baryshkov
2025-11-24 21:53 ` [PATCH RFC 6/8] arm64: dts: qcom: sdm845-shift-axolotl: " David Heidelberg via B4 Relay
2025-11-25 23:48 ` Dmitry Baryshkov
2025-11-24 21:53 ` [PATCH RFC 7/8] arm64: dts: qcom: sdm660-xiaomi-lavender: Enable support for battery David Heidelberg via B4 Relay
2025-11-25 23:50 ` Dmitry Baryshkov
2025-11-24 21:53 ` [PATCH RFC 8/8] arm64: dts: qcom: sdm670-google-sargo: Enable fuel gauge David Heidelberg via B4 Relay
2025-11-25 23:50 ` Dmitry Baryshkov
2025-11-25 18:09 ` [PATCH RFC 0/8] Qualcomm 3rd gen fuel gauge support Rob Herring
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=acc02791-1828-4578-8a8f-ef3d6824cdbf@oss.qualcomm.com \
--to=konrad.dybcio@oss.qualcomm.com \
--cc=alexeymin@postmarketos.org \
--cc=amartinz@shiftphones.com \
--cc=andersson@kernel.org \
--cc=barnabas.czeman@mainlining.org \
--cc=casey.connolly@linaro.org \
--cc=casey@connolly.tech \
--cc=conor+dt@kernel.org \
--cc=david@ixit.cz \
--cc=devicetree@vger.kernel.org \
--cc=foss@joelselvaraj.com \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mailingradian@gmail.com \
--cc=phone-devel@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sre@kernel.org \
--cc=y.oudjana@protonmail.com \
/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