Message ID | 20170416153031.11531-1-hdegoede@redhat.com (mailing list archive) |
---|---|
State | Not Applicable, archived |
Headers | show |
On Sun, Apr 16, 2017 at 05:30:31PM +0200, Hans de Goede wrote: > It is sensible to assume that the hardware actually always has a > way of charging the battery so when power_supply_am_i_supplied does not > find any suppliers, that does not mean that there are none, but simply > that no power_supply-drivers are registered / bound for any suppliers for > the supply calling power_supply_am_i_supplied. > > At which point a fuel-gauge driver calling power_supply_am_i_supplied() > cannot determine whether the battery is being charged or not. > > 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, > which allows fuel-gauge drivers to return POWER_SUPPLY_STATUS_UNKNOWN > rather then POWER_SUPPLY_STATUS_DISCHARGING if there are no suppliers. > > Signed-off-by: Hans de Goede <hdegoede@redhat.com> > --- > Changes in v2: > -Improve commit message > Changes in v3: > -s/am_i_supplied_data/psy_am_i_supplied_data/ > --- > drivers/power/supply/power_supply_core.c | 20 +++++++++++++++----- > 1 file changed, 15 insertions(+), 5 deletions(-) > Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org> Best regards, Krzysztof
Hi, On Sun, Apr 16, 2017 at 05:30:31PM +0200, Hans de Goede wrote: > It is sensible to assume that the hardware actually always has a > way of charging the battery so when power_supply_am_i_supplied does not > find any suppliers, that does not mean that there are none, but simply > that no power_supply-drivers are registered / bound for any suppliers for > the supply calling power_supply_am_i_supplied. > > At which point a fuel-gauge driver calling power_supply_am_i_supplied() > cannot determine whether the battery is being charged or not. > > 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, > which allows fuel-gauge drivers to return POWER_SUPPLY_STATUS_UNKNOWN > rather then POWER_SUPPLY_STATUS_DISCHARGING if there are no suppliers. > > Signed-off-by: Hans de Goede <hdegoede@redhat.com> Thanks, queued. -- Sebastian
diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index 1e0960b..7ec7c7c 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 psy_am_i_supplied_data { + struct power_supply *psy; + unsigned int count; +}; + +static int __power_supply_am_i_supplied(struct device *dev, void *_data) { union power_supply_propval ret = {0,}; - struct power_supply *psy = data; struct power_supply *epsy = dev_get_drvdata(dev); + struct psy_am_i_supplied_data *data = _data; - if (__power_supply_is_supplied_by(epsy, psy)) + data->count++; + if (__power_supply_is_supplied_by(epsy, data->psy)) if (!epsy->desc->get_property(epsy, POWER_SUPPLY_PROP_ONLINE, &ret)) return ret.intval; @@ -296,12 +302,16 @@ static int __power_supply_am_i_supplied(struct device *dev, void *data) int power_supply_am_i_supplied(struct power_supply *psy) { + struct psy_am_i_supplied_data data = { psy, 0 }; int error; - error = class_for_each_device(power_supply_class, NULL, psy, + error = class_for_each_device(power_supply_class, NULL, &data, __power_supply_am_i_supplied); - dev_dbg(&psy->dev, "%s %d\n", __func__, error); + dev_dbg(&psy->dev, "%s count %u err %d\n", __func__, data.count, error); + + if (data.count == 0) + return -ENODEV; return error; }
It is sensible to assume that the hardware actually always has a way of charging the battery so when power_supply_am_i_supplied does not find any suppliers, that does not mean that there are none, but simply that no power_supply-drivers are registered / bound for any suppliers for the supply calling power_supply_am_i_supplied. At which point a fuel-gauge driver calling power_supply_am_i_supplied() cannot determine whether the battery is being charged or not. 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, which allows fuel-gauge drivers to return POWER_SUPPLY_STATUS_UNKNOWN rather then POWER_SUPPLY_STATUS_DISCHARGING if there are no suppliers. Signed-off-by: Hans de Goede <hdegoede@redhat.com> --- Changes in v2: -Improve commit message Changes in v3: -s/am_i_supplied_data/psy_am_i_supplied_data/ --- drivers/power/supply/power_supply_core.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)