linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Krzysztof Kozlowski <krzk@kernel.org>
Cc: Sebastian Reichel <sre@kernel.org>,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
	linux-pm@vger.kernel.org
Subject: Re: [PATCH 01/13] power: Make power_supply_am_i_supplied return -ENODEV if there are no suppliers
Date: Fri, 14 Apr 2017 16:07:22 +0200	[thread overview]
Message-ID: <67216acf-89da-033c-8214-7166e858a306@redhat.com> (raw)
In-Reply-To: <20170414135638.pbcjxvvf6a7gfizw@kozik-lap>

Hi,

On 14-04-17 15:56, Krzysztof Kozlowski wrote:
> On Fri, Apr 14, 2017 at 02:59:07PM +0200, Hans de Goede wrote:
>> Allow a caller of power_supply_am_i_supplied to differentiate between
>> there not being any suppliers, vs no suppliers being online by returning
>> -ENODEV if there are no suppliers matching supplied_to / supplied_from.
>>
>
> This is missing important piece of information - why you need to
> differentiate that? What is the difference for you between no supplies
> at all and not-being-supplied?

Thank you for the quick response.

I think it is sensible to assume that the hardware actually always has a
way of charging the battery so where you say "no supplies at all" in
reality what would be the case is : "no power_supply-drivers
registered / bound for any supplies at all". At which point we can not
determine in many fuel-gauge drivers (which are the only user of
power_supply_am_i_supplied) if we're charging or discharging.

Here is the code for the STATUS property I'm adding to the max17042
driver in a later commit in the set:

static int max17042_get_status(struct max17042_chip *chip, int *status)
{
         int ret, charge_full, charge_now;

         ret = power_supply_am_i_supplied(chip->battery);
         if (ret < 0) {
                 *status = POWER_SUPPLY_STATUS_UNKNOWN;
                 return 0;
         }
         if (ret == 0) {
                 *status = POWER_SUPPLY_STATUS_DISCHARGING;
                 return 0;
         }

	...
}

This is where the -ENODEV comes in to make it properly return
POWER_SUPPLY_STATUS_UNKNOWN instead of always returning
POWER_SUPPLY_STATUS_DISCHARGING even if that may be untrue.

Note that I've since found out that the only in tree user of the
max17042 driver is arch/arm/boot/dts/exynos4412-trats2.dts and
the last patch in my makes the max77693 charger driver properly
set supplied_to so that power_supply_am_i_supplied() will work
correctly for the max17047 / max77693 combo on that board, which
sort of renders this patch unnecessary. I still think this patch
is a good idea, but it can be dropped if other people disagree.

Regards,

Hans




>
>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>  drivers/power/supply/power_supply_core.c | 20 +++++++++++++++-----
>>  1 file changed, 15 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
>> index 1e0960b..13a39da 100644
>> --- a/drivers/power/supply/power_supply_core.c
>> +++ b/drivers/power/supply/power_supply_core.c
>> @@ -280,13 +280,19 @@ static inline int power_supply_check_supplies(struct power_supply *psy)
>>  }
>>  #endif
>>
>> -static int __power_supply_am_i_supplied(struct device *dev, void *data)
>> +struct am_i_supplied_data {
>
> How about a prefix, e.g.: "psy_am_i_supplied_data"?
>
> Best regards,
> Krzysztof
>

  reply	other threads:[~2017-04-14 14:07 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-14 12:59 [PATCH 01/13] power: Make power_supply_am_i_supplied return -ENODEV if there are no suppliers Hans de Goede
2017-04-14 12:59 ` [PATCH 02/13] power: max17042_battery: Use sign_extend32 instead of DIY code Hans de Goede
2017-04-14 15:29   ` Krzysztof Kozlowski
2017-04-14 12:59 ` [PATCH 03/13] power: max17047_battery: The temp alert values are 8-bit 2's complement Hans de Goede
2017-04-14 15:09   ` Krzysztof Kozlowski
2017-04-14 15:16     ` Hans de Goede
2017-04-14 15:26       ` Krzysztof Kozlowski
2017-04-14 15:36         ` Hans de Goede
2017-04-14 15:39           ` Krzysztof Kozlowski
2017-04-14 12:59 ` [PATCH 04/13] power: max17042_battery: Add default platform_data for x86 use Hans de Goede
2017-04-14 15:35   ` Krzysztof Kozlowski
2017-04-14 16:07   ` Krzysztof Kozlowski
2017-04-14 17:11     ` Hans de Goede
2017-04-14 12:59 ` [PATCH 05/13] power: max17042_battery: Change name in power_supply_desc to "main-battery" Hans de Goede
2017-04-14 15:37   ` Krzysztof Kozlowski
2017-04-14 12:59 ` [PATCH 06/13] power: max17042_battery: Add support for the STATUS property Hans de Goede
2017-04-14 16:11   ` Krzysztof Kozlowski
2017-04-14 17:19     ` Hans de Goede
2017-04-14 12:59 ` [PATCH 07/13] power: max17042_battery: Add external_power_changed callback Hans de Goede
2017-04-14 16:22   ` Krzysztof Kozlowski
2017-04-14 12:59 ` [PATCH 08/13] power: max17042_battery: Add support for the TECHNOLOGY attribute Hans de Goede
2017-04-14 16:26   ` Krzysztof Kozlowski
2017-04-14 18:06     ` Hans de Goede
2017-04-14 18:20       ` Krzysztof Kozlowski
2017-04-14 18:24         ` Hans de Goede
2017-04-14 12:59 ` [PATCH 09/13] power: max17042_battery: Add support for the VOLT_MIN property Hans de Goede
2017-04-14 16:29   ` Krzysztof Kozlowski
2017-04-14 12:59 ` [PATCH 10/13] power: max17042_battery: Add support for the CHARGE_FULL_DESIGN property Hans de Goede
2017-04-14 16:34   ` Krzysztof Kozlowski
2017-04-14 18:08     ` Hans de Goede
2017-04-14 12:59 ` [PATCH 11/13] power: max17042_battery: Add support for CHARGE_NOW property Hans de Goede
2017-04-14 16:42   ` Krzysztof Kozlowski
2017-04-14 12:59 ` [PATCH 12/13] power: max17042_battery: Add support for SCOPE property Hans de Goede
2017-04-14 16:43   ` Krzysztof Kozlowski
2017-04-14 12:59 ` [PATCH 13/13] power: max77693_charger: Add supplied_to info to power_supply_config Hans de Goede
2017-04-14 16:44   ` Krzysztof Kozlowski
2017-04-14 13:56 ` [PATCH 01/13] power: Make power_supply_am_i_supplied return -ENODEV if there are no suppliers Krzysztof Kozlowski
2017-04-14 14:07   ` Hans de Goede [this message]
2017-04-14 14:31     ` Krzysztof Kozlowski
2017-04-14 15:21       ` Hans de Goede

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=67216acf-89da-033c-8214-7166e858a306@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=b.zolnierkie@samsung.com \
    --cc=krzk@kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --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).