[PATCH 1/2] power_supply: allow control of attribute visibility

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Daniel Drake
Date: Monday, December 6, 2010 - 1:35 pm

A power supply driver could support a certain attribute that is not
available at runtime (e.g. because the specific host doesn't support
that functionality).

Add a mechanism for power supplies to be able to specify this.

Signed-off-by: Daniel Drake <dsd@laptop.org>
---
 drivers/power/power_supply_sysfs.c |    4 ++++
 include/linux/power_supply.h       |    2 ++
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
index cd1f907..8df9e4c 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -191,6 +191,10 @@ static mode_t power_supply_attr_is_visible(struct kobject *kobj,
 		int property = psy->properties[i];
 
 		if (property == attrno) {
+			if (psy->property_is_available &&
+			    !psy->property_is_available(psy, property))
+				return 0;
+
 			if (psy->property_is_writeable &&
 			    psy->property_is_writeable(psy, property) > 0)
 				mode |= S_IWUSR;
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 7d73256..b481458 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -152,6 +152,8 @@ struct power_supply {
 	int (*set_property)(struct power_supply *psy,
 			    enum power_supply_property psp,
 			    const union power_supply_propval *val);
+	bool (*property_is_available)(struct power_supply *psy,
+				      enum power_supply_property psp);
 	int (*property_is_writeable)(struct power_supply *psy,
 				     enum power_supply_property psp);
 	void (*external_power_changed)(struct power_supply *psy);
-- 
1.7.3.2

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 1/2] power_supply: allow control of attribute visib ..., Daniel Drake, (Mon Dec 6, 1:35 pm)