From: Krzysztof Kozlowski <krzk@kernel.org>
To: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>,
Hans de Goede <hdegoede@redhat.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Sebastian Reichel <sre@kernel.org>,
linux-pm@vger.kernel.org
Cc: Purism Kernel Team <kernel@puri.sm>,
Rob Herring <robh@kernel.org>,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH 2/4] power: supply: max17042_battery: use ModelCfg refresh on max17055
Date: Wed, 23 Mar 2022 10:47:04 +0100 [thread overview]
Message-ID: <e6d014ca-4568-20f2-0254-e8fe51f30e5d@kernel.org> (raw)
In-Reply-To: <2957015.e9J7NaK4W3@pliszka>
On 20/03/2022 21:44, Sebastian Krzyszkowiak wrote:
> On niedziela, 20 marca 2022 13:18:49 CET Krzysztof Kozlowski wrote:
>> On 18/03/2022 20:58, Sebastian Krzyszkowiak wrote:
>>> On piątek, 18 marca 2022 09:22:16 CET Krzysztof Kozlowski wrote:
>>>> On 18/03/2022 01:10, Sebastian Krzyszkowiak wrote:
>>>>> Unlike other models, max17055 doesn't require cell characterization
>>>>> data and operates on smaller amount of input variables (DesignCap,
>>>>> VEmpty, IChgTerm and ModelCfg). Input data can already be filled in
>>>>> by max17042_override_por_values, however model refresh bit has to be
>>>>> set after adjusting input variables in order to make them apply.
>>>>>
>>>>> Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
>>>>> ---
>>>>>
>>>>> drivers/power/supply/max17042_battery.c | 73 +++++++++++++++----------
>>>>> include/linux/power/max17042_battery.h | 3 +
>>>>> 2 files changed, 48 insertions(+), 28 deletions(-)
>>>>>
>>>>> diff --git a/drivers/power/supply/max17042_battery.c
>>>>> b/drivers/power/supply/max17042_battery.c index
>>>>> c019d6c52363..c39250349a1d 100644
>>>>> --- a/drivers/power/supply/max17042_battery.c
>>>>> +++ b/drivers/power/supply/max17042_battery.c
>>>>> @@ -806,6 +806,13 @@ static inline void
>>>>> max17042_override_por_values(struct max17042_chip *chip)>
>>>>>
>>>>> (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17055)) {
>>>>>
>>>>> max17042_override_por(map, MAX17047_V_empty, config-
>>>>
>>>> vempty);
>>>>
>>>>> }
>>>>>
>>>>> +
>>>>> + if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17055) {
>>>>> + max17042_override_por(map, MAX17055_ModelCfg, config-
>>>>
>>>> model_cfg);
>>>>
>>>>> + // VChg is 1 by default, so allow it to be set to 0
>>>>
>>>> Consistent comment, so /* */
>>>>
>>>> I actually do not understand fully the comment and the code. You write
>>>> entire model_cfg to MAX17055_ModelCfg and then immediately do it again,
>>>> but with smaller mask. Why?
>>>
>>> That's because VChg is 1 on POR, and max17042_override_por doesn't do
>>> anything when value equals 0 - which means that if the whole
>>> config->model_cfg is 0, VChg won't get unset (which is needed for 4.2V
>>> batteries).
>>>
>>> This could actually be replaced with a single regmap_write.
>>
>> I got it now. But if config->model_cfg is 0, should VChg be unset?
>
> That's a good question.
>
> max17042_override_por doesn't override the register value when the given value
> equals zero in order to not override POR defaults with unset platform data.
> This way one can set only the registers that they want to change in `config`
> and the rest are untouched. This, however, only works if we assume that zero
> means "don't touch", which isn't the case for ModelCfg.
>
> On the Librem 5, we need to unset VChg bit because our battery is only being
> charged up to 4.2V. Allowing to unset this bit only without having to touch
> the rest of the register was the motivation behind the current version of this
> patch, however, thinking about it now I can see that it fails to do that in
> the opposite case - when the DT contains a simple-battery with maximum voltage
> higher than 4.25V, VChg will be set in config->model_cfg causing the whole
> register to be overwritten.
This is actually nice description which could be put into a comment there.
>
> So, I see two possible solutions:
>
> 1) move VChg handling to a separate variable in struct max17042_config_data.
> This way model_cfg can stay zero when there's no need to touch the rest of the
> register. This minimizes changes over current code.
>
> 2) remove max17042_override_por_values in its current shape altogether and
> make it only deal with the values that are actually being set by the driver
> (and only extend it in the future as it gains more ability). Currently most of
> this function is only usable with platform data - is there actually any user
> of max17042 that would need to configure the gauge without DT in the mainline
> kernel? My quick search didn't find any. Do we need or want to keep platform
> data support at all?
>
> I'm leaning towards option 2, as it seems to me that currently this driver is
> being cluttered quite a lot by what's essentially a dead code. Adding new
> parameters to read from DT for POR initialization (which is necessary for
> other models than MAX17055) should be rather easy, but trying to fit them into
> current platform_data-oriented code may be not.
I am in for removal of platform data.
Best regards,
Krzysztof
next prev parent reply other threads:[~2022-03-23 9:47 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-18 0:10 [PATCH 0/4] MAX17055 model configuration via DT Sebastian Krzyszkowiak
2022-03-18 0:10 ` [PATCH 1/4] power: supply: max17042_battery: Add unit conversion macros Sebastian Krzyszkowiak
2022-03-18 8:16 ` Krzysztof Kozlowski
2022-03-18 9:00 ` Hans de Goede
2022-03-18 9:06 ` Krzysztof Kozlowski
2022-03-18 9:51 ` Hans de Goede
2022-03-18 20:06 ` Sebastian Krzyszkowiak
2022-03-19 13:47 ` Hans de Goede
2022-03-18 8:59 ` Hans de Goede
2022-03-18 0:10 ` [PATCH 2/4] power: supply: max17042_battery: use ModelCfg refresh on max17055 Sebastian Krzyszkowiak
2022-03-18 8:22 ` Krzysztof Kozlowski
2022-03-18 19:58 ` Sebastian Krzyszkowiak
2022-03-20 12:18 ` Krzysztof Kozlowski
2022-03-20 20:44 ` Sebastian Krzyszkowiak
2022-03-23 9:47 ` Krzysztof Kozlowski [this message]
2022-03-18 9:04 ` Hans de Goede
2022-03-18 0:10 ` [PATCH 3/4] dt-bindings: power: supply: max17042: Add monitored-battery phandle Sebastian Krzyszkowiak
2022-03-18 8:23 ` Krzysztof Kozlowski
2022-03-18 0:10 ` [PATCH 4/4] power: supply: max17042_battery: read battery properties from device tree Sebastian Krzyszkowiak
2022-03-18 8:40 ` Krzysztof Kozlowski
2022-03-20 21:24 ` Sebastian Krzyszkowiak
2022-03-23 9:48 ` Krzysztof Kozlowski
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=e6d014ca-4568-20f2-0254-e8fe51f30e5d@kernel.org \
--to=krzk@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=hdegoede@redhat.com \
--cc=kernel@puri.sm \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=robh@kernel.org \
--cc=sebastian.krzyszkowiak@puri.sm \
--cc=sre@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;
as well as URLs for NNTP newsgroup(s).