public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] power:power_supply_syfs : Treat PROP_TYPE as a regular attribute first
@ 2013-08-14 23:09 Philippe De Swert
  2013-10-25 22:15 ` Anton Vorontsov
  0 siblings, 1 reply; 4+ messages in thread
From: Philippe De Swert @ 2013-08-14 23:09 UTC (permalink / raw)
  To: anton, dwmw2, linux-kernel; +Cc: Philippe De Swert

These days we often have USB powered devices. This means that often the
type is variable. Common examples are smartphones which can be charged
through a normal USB port on a PC/laptop, a dedicated charger, etc...
Often those chips also have support for other charger types like a
mains/DC charger. This means that often there are several psy structures
in the driver and makes it impossible to stick to just one type.

Userspace sometimes needs to behave differently based on the type of charger
connected to such devices. This goes from loading gadget drivers to get
enumerated on a PC/laptop to draw more power, to enabling special charging
functions for a dedicated charger. Or to just enable userspace to discriminate
between the two for charging indications/USB cable detection.

Moreover TYPE seems to be the right attribute to use as it has definitions
already for all the different USB charger types.This patch allows for using the 
regular get_property function with the TYPE property without breaking current 
functionality/way of working.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
---
 drivers/power/power_supply_sysfs.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
index 29178f7..a839c91 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -73,19 +73,20 @@ static ssize_t power_supply_show_property(struct device *dev,
 	const ptrdiff_t off = attr - power_supply_attrs;
 	union power_supply_propval value;
 
-	if (off == POWER_SUPPLY_PROP_TYPE)
-		value.intval = psy->type;
-	else
-		ret = psy->get_property(psy, off, &value);
+	ret = psy->get_property(psy, off, &value);
 
 	if (ret < 0) {
-		if (ret == -ENODATA)
-			dev_dbg(dev, "driver has no data for `%s' property\n",
-				attr->attr.name);
-		else if (ret != -ENODEV)
-			dev_err(dev, "driver failed to report `%s' property: %zd\n",
-				attr->attr.name, ret);
-		return ret;
+		if (off == POWER_SUPPLY_PROP_TYPE)
+			value.intval = psy->type;
+		else {
+			if (ret == -ENODATA)
+				dev_dbg(dev, "driver has no data for `%s' property\n",
+					attr->attr.name);
+			else if (ret != -ENODEV)
+				dev_err(dev, "driver failed to report `%s' property: %zd\n",
+					attr->attr.name, ret);
+			return ret;
+		}
 	}
 
 	if (off == POWER_SUPPLY_PROP_STATUS)
-- 
1.8.1.2


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

end of thread, other threads:[~2013-10-28  6:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-14 23:09 [PATCH] power:power_supply_syfs : Treat PROP_TYPE as a regular attribute first Philippe De Swert
2013-10-25 22:15 ` Anton Vorontsov
2013-10-25 23:01   ` Philippe De Swert
2013-10-28  6:35     ` Anton Vorontsov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox