From: Artur Weber <aweber.kernel@gmail.com>
To: Krzysztof Kozlowski <krzk@kernel.org>,
Chanwoo Choi <cw00.choi@samsung.com>
Cc: Sebastian Reichel <sre@kernel.org>, Rob Herring <robh@kernel.org>,
Conor Dooley <conor+dt@kernel.org>, Lee Jones <lee@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Alim Akhtar <alim.akhtar@samsung.com>,
linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-samsung-soc@vger.kernel.org,
~postmarketos/upstreaming@lists.sr.ht,
Henrik Grimler <henrik@grimler.se>,
Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de>,
Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Subject: Re: [PATCH RFC 06/11] power: supply: max77693: Set charge current limits during init
Date: Wed, 5 Jun 2024 16:43:48 +0200 [thread overview]
Message-ID: <9f88a533-cb99-4fa4-836d-9a8bd68992a2@gmail.com> (raw)
In-Reply-To: <311c13e0-2f14-4134-afb5-128bc82111e7@kernel.org>
On 31.05.2024 14:18, Krzysztof Kozlowski wrote:
> On 31/05/2024 13:55, Artur Weber wrote:
>> On 31.05.2024 11:47, Krzysztof Kozlowski wrote:
>>> On 30/05/2024 10:55, Artur Weber wrote:
>>>> There are two charger current limit registers:
>>>>
>>>> - Fast charge current limit (which controls current going from the
>>>> charger to the battery);
>>>> - CHGIN input current limit (which controls current going into the
>>>> charger through the cable, and is managed by the CHARGER regulator).
>>>>
>>>> Add functions for setting both of the values, and set them to a
>>>> safe default value of 500mA at initialization.
>>>>
>>>> The default value for the fast charge current limit can be modified
>>>> by setting the maxim,fast-charge-current-microamp DT property; the
>>>> CHGIN input current limit will be set up later in the charger detection
>>>> mechanism.
>>>>
>>>> Signed-off-by: Artur Weber <aweber.kernel@gmail.com>
>>>> ---
>>>> drivers/power/supply/max77693_charger.c | 45 +++++++++++++++++++++++++++++++++
>>>> 1 file changed, 45 insertions(+)
>>>>
>>>> diff --git a/drivers/power/supply/max77693_charger.c b/drivers/power/supply/max77693_charger.c
>>>> index 894c35b750b3..d59b1524b0a4 100644
>>>> --- a/drivers/power/supply/max77693_charger.c
>>>> +++ b/drivers/power/supply/max77693_charger.c
>>>> @@ -28,6 +28,7 @@ struct max77693_charger {
>>>> u32 min_system_volt;
>>>> u32 thermal_regulation_temp;
>>>> u32 batttery_overcurrent;
>>>> + u32 fast_charge_current;
>>>> u32 charge_input_threshold_volt;
>>>> };
>>>>
>>>> @@ -591,6 +592,35 @@ static int max77693_set_batttery_overcurrent(struct max77693_charger *chg,
>>>> CHG_CNFG_12_B2SOVRC_MASK, data);
>>>> }
>>>>
>>>> +static int max77693_set_input_current_limit(struct max77693_charger *chg,
>>>> + unsigned int uamp)
>>>> +{
>>>> + dev_dbg(chg->dev, "CHGIN input current limit: %u\n", uamp);
>>>
>>> That's quite useless debug. It duplicates
>>> max77693_set_fast_charge_current(). Just drop entire wrapper.
>>
>> It doesn't duplicate max77693_set_fast_charge_current, they modify two
>> separate registers. Quote from the commit message:
>
> But it is the same uamp value. Debug messages should not be per register
> write, because we are not debugging here registers...
>
>>
>>> There are two charger current limit registers:
>>>
>>> - Fast charge current limit (which controls current going from the
>>> charger to the battery);
>>> - CHGIN input current limit (which controls current going into the
>>> charger through the cable, and is managed by the CHARGER regulator).
>>
>> max77693_set_fast_charge_current sets up the "fast charge current"
>> register (in CNFG_02, CHG_CNFG_02_CC). The CHARGER regulators sets the
>> CHGIN input current (in CNFG_09, CHG_CNFG_09_CHGIN_ILIM).
>>
>> (Apparently the CHARGER regulator is supposed to handle the fast
>> charge current, but it does not; I wrote about this in the "CHARGER
>> regulator" section of the patchset description.)
>>
>>>> +
>>>> + return regulator_set_current_limit(chg->regu, (int)uamp, (int)uamp);
>>>> +}
>>>> +
>>>> +static int max77693_set_fast_charge_current(struct max77693_charger *chg,
>>>> + unsigned int uamp)
>>>> +{
>>>> + unsigned int data;
>>>> +
>>>> + data = (uamp / 1000) * 10 / 333; /* 0.1A/3 steps */
>>>> +
>>>> + if (data > CHG_CNFG_02_CC_MASK) {
>>>> + dev_err(chg->dev, "Wrong value for fast charge current\n");
>>>> + return -EINVAL;
>>>> + }
>>>> +
>>>> + data <<= CHG_CNFG_02_CC_SHIFT;
>>>> +
>>>> + dev_dbg(chg->dev, "Fast charge current: %u (0x%x)\n", uamp, data);
>>>> +
>>>> + return regmap_update_bits(chg->max77693->regmap,
>>>> + MAX77693_CHG_REG_CHG_CNFG_02,
>>>> + CHG_CNFG_02_CC_MASK, data);
>>>
>>> I am surprised that you set current limit via regulator but actual
>>> charging current value here. I think both should go to regulator in such
>>> case.
>>
>> As in, both fast charge current and input current should be set up by
>> the CHARGER regulator? Sure, sounds good to me.
Now that I look at it, there's one small problem with moving this to the
CHARGER regulator - the CHGIN input limit and the fast charge current
limit have different ranges for values; CHGIN input limit accepts values
from 60mA to 2.58A, whereas fast charge current accepts values from 0mA
to ~2.1A. (This also means the limits I described for the fast charge
current property in [PATCH 2/11] are wrong...)
Should we limit the CHARGER regulator to 2.1A (would require fixing
every DTS that defines the limits... though maybe they should be
hardcoded in the driver anyways?), or leave the limit as-is and cap the
fast charge current if the CHARGER current limit is set above 2.1A, or
something else entirely?
Best regards
Artur
next prev parent reply other threads:[~2024-06-05 14:43 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-30 8:55 [PATCH RFC 00/11] power: supply: max77693: Toggle charging/OTG based on extcon status Artur Weber
2024-05-30 8:55 ` [PATCH RFC 01/11] dt-bindings: power: supply: max77693: Add fast charge current property Artur Weber
2024-05-31 9:35 ` Krzysztof Kozlowski
2024-05-30 8:55 ` [PATCH RFC 02/11] dt-bindings: power: supply: max77693: Add maxim,usb-connector property Artur Weber
2024-05-31 9:15 ` Krzysztof Kozlowski
2024-05-30 8:55 ` [PATCH RFC 03/11] mfd: max77693: Add defines for charger current control Artur Weber
2024-05-31 9:14 ` Krzysztof Kozlowski
2024-05-30 8:55 ` [PATCH RFC 04/11] mfd: max77693: Add defines for OTG control Artur Weber
2024-05-31 9:36 ` Krzysztof Kozlowski
2024-05-30 8:55 ` [PATCH RFC 05/11] power: supply: max77693: Expose INPUT_CURRENT_LIMIT and CURRENT_MAX Artur Weber
2024-05-31 9:38 ` Krzysztof Kozlowski
2024-05-31 12:22 ` Artur Weber
2024-05-30 8:55 ` [PATCH RFC 06/11] power: supply: max77693: Set charge current limits during init Artur Weber
2024-05-31 9:47 ` Krzysztof Kozlowski
2024-05-31 11:55 ` Artur Weber
2024-05-31 12:18 ` Krzysztof Kozlowski
2024-06-05 14:43 ` Artur Weber [this message]
2024-05-30 8:55 ` [PATCH RFC 07/11] power: supply: max77693: Add USB extcon detection for enabling charging Artur Weber
2024-05-30 8:55 ` [PATCH RFC 08/11] power: supply: max77693: Add support for detecting and enabling OTG Artur Weber
2024-05-30 8:55 ` [PATCH RFC 09/11] power: supply: max77693: Set up charge/input current according to cable type Artur Weber
2024-05-30 8:56 ` [PATCH RFC 10/11] ARM: dts: samsung: exynos4212-tab3: Set fast charge current for MAX77693 Artur Weber
2024-05-30 8:56 ` [PATCH RFC 11/11] ARM: dts: samsung: exynos4212-tab3: Add USB connector node Artur Weber
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=9f88a533-cb99-4fa4-836d-9a8bd68992a2@gmail.com \
--to=aweber.kernel@gmail.com \
--cc=GNUtoo@cyberdimension.org \
--cc=alim.akhtar@samsung.com \
--cc=conor+dt@kernel.org \
--cc=cw00.choi@samsung.com \
--cc=devicetree@vger.kernel.org \
--cc=henrik@grimler.se \
--cc=krzk+dt@kernel.org \
--cc=krzk@kernel.org \
--cc=lee@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=robh@kernel.org \
--cc=sre@kernel.org \
--cc=wolfgit@wiedmeyer.de \
--cc=~postmarketos/upstreaming@lists.sr.ht \
/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