public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Marek Vasut <marex@denx.de>, linux-pm@vger.kernel.org
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Sebastian Reichel <sebastian.reichel@collabora.com>
Subject: Re: [PATCH] power: supply: bq25890: Add support for setting IINLIM
Date: Mon, 1 Aug 2022 09:15:11 +0200	[thread overview]
Message-ID: <f12ca549-ceed-f2e2-ed86-bc2f42933939@redhat.com> (raw)
In-Reply-To: <b18944f4-4e87-dfd1-37af-568a8959c57c@denx.de>

Hi,

On 8/1/22 05:00, Marek Vasut wrote:
> On 7/31/22 11:52, Hans de Goede wrote:
> 
> [...]
> 
>>> +static int bq25890_power_supply_set_property(struct power_supply *psy,
>>> +                         enum power_supply_property psp,
>>> +                         const union power_supply_propval *val)
>>> +{
>>> +    struct bq25890_device *bq = power_supply_get_drvdata(psy);
>>> +    u32 lval;
>>> +
>>> +    switch (psp) {
>>> +    case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
>>> +        lval = clamp(val->intval, 100000, 3250000);
>>> +        lval = DIV_ROUND_UP(lval - 100000, 50000);
>>
>> I'm not sure DIV_ROUND_UP is the right thing to do here. This means
>> that when the user e.g. asks for 1040 mA the iinlim will get set to
>> 1050mA so more then which is being requested.
>>
>> IMHO it would be better to use rounding down, aka standard divide
>> behavior here.
>>
>> But even better would be to replace both lval = ... statements
>> with a single:
>>
>>     lval = bq25890_find_idx(val->intval, TBL_IINLIM);
>>
>> which takes care of all this for you and is also what is used
>> by bq25890_charger_external_power_changed() to set iinlim based
>> on charger-type-detection done by other chips on the board
>> (e.g. PMICs / usb-phys Type-C controllers).
> 
> Nice, fixed in v2, thanks.
> 
> There is one thing which I don't quite understand about this driver though -- shouldn't we implement .external_power_changed() callback and then somehow listen for which charger gets plugged in (like, USB standard one, or 1.5A one or 3A one, or even some adapter), and based on that tweak the IINLIM too ? Or is this more of a userspace kind of policy, so it should be up to userspace to write this sysfs entry as needed ?

There already is an external_power_changed() callback that is what
the bq25890_charger_external_power_changed() function I mentioned is... ?

Regards,

Hans


  reply	other threads:[~2022-08-01  7:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-30 18:06 [PATCH] power: supply: bq25890: Add support for setting IINLIM Marek Vasut
2022-07-31  9:52 ` Hans de Goede
2022-08-01  3:00   ` Marek Vasut
2022-08-01  7:15     ` Hans de Goede [this message]
2022-08-01 10:50       ` Marek Vasut

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=f12ca549-ceed-f2e2-ed86-bc2f42933939@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=marex@denx.de \
    --cc=sebastian.reichel@collabora.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