linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 01/14] power: Make power_supply_am_i_supplied return -ENODEV if there are no suppliers
@ 2017-04-14 18:32 Hans de Goede
  2017-04-14 18:32 ` [PATCH v2 02/14] power: max17042_battery: Use sign_extend32 instead of DIY code Hans de Goede
                   ` (13 more replies)
  0 siblings, 14 replies; 36+ messages in thread
From: Hans de Goede @ 2017-04-14 18:32 UTC (permalink / raw)
  To: Sebastian Reichel, Krzysztof Kozlowski, Bartlomiej Zolnierkiewicz
  Cc: Hans de Goede, linux-pm

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
---
 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 {
+	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 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 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;
 }
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2017-05-01 15:50 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-14 18:32 [PATCH v2 01/14] power: Make power_supply_am_i_supplied return -ENODEV if there are no suppliers Hans de Goede
2017-04-14 18:32 ` [PATCH v2 02/14] power: max17042_battery: Use sign_extend32 instead of DIY code Hans de Goede
2017-05-01 11:36   ` Sebastian Reichel
2017-04-14 18:32 ` [PATCH v2 03/14] power: max17047_battery: The temp alert values are 8-bit 2's complement Hans de Goede
2017-05-01 11:37   ` Sebastian Reichel
2017-04-14 18:32 ` [PATCH v2 04/14] power: max17042_battery: Add default platform_data fallback data Hans de Goede
2017-04-15 10:31   ` Krzysztof Kozlowski
2017-05-01 11:37   ` Sebastian Reichel
2017-04-14 18:32 ` [PATCH v2 05/14] power: max17042_battery: Change name in power_supply_desc to "main-battery" Hans de Goede
2017-05-01 12:22   ` Sebastian Reichel
2017-05-01 15:11     ` Hans de Goede
2017-05-01 15:50       ` Sebastian Reichel
2017-04-14 18:32 ` [PATCH v2 06/14] power: max17042_battery: Add support for the STATUS property Hans de Goede
2017-04-15 10:32   ` Krzysztof Kozlowski
2017-05-01 11:38   ` Sebastian Reichel
2017-04-14 18:32 ` [PATCH v2 07/14] power: max17042_battery: Add external_power_changed callback Hans de Goede
2017-05-01 11:38   ` Sebastian Reichel
2017-04-14 18:32 ` [PATCH v2 08/14] power: max17042_battery: Add support for the TECHNOLOGY attribute Hans de Goede
2017-04-15 10:33   ` Krzysztof Kozlowski
2017-05-01 11:39   ` Sebastian Reichel
2017-04-14 18:32 ` [PATCH v2 09/14] power: max17042_battery: Add support for the VOLT_MIN property Hans de Goede
2017-05-01 11:39   ` Sebastian Reichel
2017-04-14 18:32 ` [PATCH v2 10/14] power: max17042_battery: mAh readings depend on r_sns value Hans de Goede
2017-04-15 10:38   ` Krzysztof Kozlowski
2017-05-01 11:39   ` Sebastian Reichel
2017-04-14 18:32 ` [PATCH v2 11/14] power: max17042_battery: Add support for the CHARGE_FULL_DESIGN property Hans de Goede
2017-04-15 10:38   ` Krzysztof Kozlowski
2017-05-01 11:40   ` Sebastian Reichel
2017-04-14 18:32 ` [PATCH v2 12/14] power: max17042_battery: Add support for the CHARGE_NOW property Hans de Goede
2017-04-15 10:39   ` Krzysztof Kozlowski
2017-05-01 11:40   ` Sebastian Reichel
2017-04-14 18:32 ` [PATCH v2 13/14] power: max17042_battery: Add support for the SCOPE property Hans de Goede
2017-05-01 11:41   ` Sebastian Reichel
2017-04-14 18:32 ` [PATCH v2 14/14] power: max77693_charger: Add supplied_to info to power_supply_config Hans de Goede
2017-05-01 12:19   ` Sebastian Reichel
2017-04-15 10:30 ` [PATCH v2 01/14] power: Make power_supply_am_i_supplied return -ENODEV if there are no suppliers Krzysztof Kozlowski

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).