Skip to contentSkip to conversation

Add "scope" to power supplies

RFC PATCH In review Jeremy Fitzhardinge 3 participants 13 messages Dec 9, 2011 – Jan 4, 2012

Subsystems (3)
lore
Share & tools
lore
#1 lore raw

RFC PATCH v2 1/4 power_supply: add SCOPE attribute to power supplies

In reply to Jeremy Fitzhardinge

This adds a "scope" attribute to a power_supply, which indicates how much of the system it powers. It appears in sysfs as "scope" or in the uevent file as POWER_SUPPLY_SCOPE=. There are presently three possible values:
Unknown - unknown power topology
System - the power supply powers the whole system Device - it powers a specific device, or tree of devices

A power supply which doesn't have a "scope" attribute should be assumed to have "System" scope.

In general, usermode should assume that loss of all System-scoped power supplies will power off the whole system, but any single one is sufficient to power the system.

---
 drivers/power/power_supply_sysfs.c |    6 ++++++
 include/linux/power_supply.h       |    7 +++++++
 2 files changed, 13 insertions(+), 0 deletions(-)
drivers/power/power_supply_sysfs.c +6 -0
index e15d4c9..21178eb 100644
@@ -63,6 +63,9 @@ static ssize_t power_supply_show_property(struct device *dev,
 	static char *capacity_level_text[] = {
 		"Unknown", "Critical", "Low", "Normal", "High", "Full"
 	};
+	static char *scope_text[] = {
+		"Unknown", "System", "Device"
+	};
 	ssize_t ret = 0;
 	struct power_supply *psy = dev_get_drvdata(dev);
 	const ptrdiff_t off = attr - power_supply_attrs;
@@ -95,6 +98,8 @@ static ssize_t power_supply_show_property(struct device *dev,
 		return sprintf(buf, "%s\n", capacity_level_text[value.intval]);
 	else if (off == POWER_SUPPLY_PROP_TYPE)
 		return sprintf(buf, "%s\n", type_text[value.intval]);
+	else if (off == POWER_SUPPLY_PROP_SCOPE)
+		return sprintf(buf, "%s\n", scope_text[value.intval]);
 	else if (off >= POWER_SUPPLY_PROP_MODEL_NAME)
 		return sprintf(buf, "%s\n", value.strval);
 
@@ -167,6 +172,7 @@ static struct device_attribute power_supply_attrs[] = {
 	POWER_SUPPLY_ATTR(time_to_full_now),
 	POWER_SUPPLY_ATTR(time_to_full_avg),
 	POWER_SUPPLY_ATTR(type),
+	POWER_SUPPLY_ATTR(scope),
 	/* Properties of type `const char *' */
 	POWER_SUPPLY_ATTR(model_name),
 	POWER_SUPPLY_ATTR(manufacturer),
include/linux/power_supply.h +7 -0
index 204c18d..040a7b0 100644
@@ -74,6 +74,12 @@ enum {
 	POWER_SUPPLY_CAPACITY_LEVEL_FULL,
 };
 
+enum {
+	POWER_SUPPLY_SCOPE_UNKNOWN = 0,
+	POWER_SUPPLY_SCOPE_SYSTEM,
+	POWER_SUPPLY_SCOPE_DEVICE,
+};
+
 enum power_supply_property {
 	/* Properties of type `int' */
 	POWER_SUPPLY_PROP_STATUS = 0,
@@ -116,6 +122,7 @@ enum power_supply_property {
 	POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
 	POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
 	POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */
+	POWER_SUPPLY_PROP_SCOPE,
 	/* Properties of type `const char *' */
 	POWER_SUPPLY_PROP_MODEL_NAME,
 	POWER_SUPPLY_PROP_MANUFACTURER,
Signature · 1 line
1.7.7.3
#4 lore raw

RFC PATCH v2 4/4 power_supply: add "powers" links to self-powered HID devices

In reply to Jeremy Fitzhardinge

Make the relationship between the Wiimote and Wacom self-powered HID devices and their power supply explicit by adding a "powers" link.

---
 drivers/hid/hid-wacom.c   |    4 ++++
 drivers/hid/hid-wiimote.c |    2 ++
 2 files changed, 6 insertions(+), 0 deletions(-)
drivers/hid/hid-wacom.c +4 -0
index ad39777..3d28e49 100644
@@ -397,6 +397,8 @@ static int wacom_probe(struct hid_device *hdev,
 	wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY;
 	wdata->battery.use_for_apm = 0;
 
+	power_supply_powers(&wdata->battery, &hdev->dev);
+
 	ret = power_supply_register(&hdev->dev, &wdata->battery);
 	if (ret) {
 		hid_warn(hdev, "can't create sysfs battery attribute, err: %d\n",
@@ -411,6 +413,8 @@ static int wacom_probe(struct hid_device *hdev,
 	wdata->ac.type = POWER_SUPPLY_TYPE_MAINS;
 	wdata->ac.use_for_apm = 0;
 
+	power_supply_powers(&wdata->battery, &hdev->dev);
+
 	ret = power_supply_register(&hdev->dev, &wdata->ac);
 	if (ret) {
 		hid_warn(hdev,
drivers/hid/hid-wiimote.c +2 -0
index 98e4828..fc0b4db 100644
@@ -1263,6 +1263,8 @@ static int wiimote_hid_probe(struct hid_device *hdev,
 	wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY;
 	wdata->battery.use_for_apm = 0;
 
+	power_supply_powers(&wdata->battery, &hdev->dev);
+
 	ret = power_supply_register(&wdata->hdev->dev, &wdata->battery);
 	if (ret) {
 		hid_err(hdev, "Cannot register battery device\n");
Signature · 1 line
1.7.7.3
#3 lore raw

RFC PATCH v2 3/4 power_supply: add scope properties to some self-powered HID devices

In reply to Jeremy Fitzhardinge

The Wacom and Wiimote HID drivers register power supplies for themselves to indicate their battery levels. Make those power supplies device scope.

---
 drivers/hid/hid-wacom.c   |   12 ++++++++++--
 drivers/hid/hid-wiimote.c |    8 +++++++-
 2 files changed, 17 insertions(+), 3 deletions(-)
drivers/hid/hid-wacom.c +10 -2
index 17bb88f..ad39777 100644
@@ -47,12 +47,14 @@ static unsigned short batcap[8] = { 1, 15, 25, 35, 50, 70, 100, 0 };
 
 static enum power_supply_property wacom_battery_props[] = {
 	POWER_SUPPLY_PROP_PRESENT,
-	POWER_SUPPLY_PROP_CAPACITY
+	POWER_SUPPLY_PROP_CAPACITY,
+	POWER_SUPPLY_PROP_SCOPE,
 };
 
 static enum power_supply_property wacom_ac_props[] = {
 	POWER_SUPPLY_PROP_PRESENT,
-	POWER_SUPPLY_PROP_ONLINE
+	POWER_SUPPLY_PROP_ONLINE,
+	POWER_SUPPLY_PROP_SCOPE,
 };
 
 static int wacom_battery_get_property(struct power_supply *psy,
@@ -68,6 +70,9 @@ static int wacom_battery_get_property(struct power_supply *psy,
 	case POWER_SUPPLY_PROP_PRESENT:
 		val->intval = 1;
 		break;
+	case POWER_SUPPLY_PROP_SCOPE:
+		val->intval = POWER_SUPPLY_SCOPE_DEVICE;
+		break;
 	case POWER_SUPPLY_PROP_CAPACITY:
 		/* show 100% battery capacity when charging */
 		if (power_state == 0)
@@ -99,6 +104,9 @@ static int wacom_ac_get_property(struct power_supply *psy,
 		else
 			val->intval = 0;
 		break;
+	case POWER_SUPPLY_PROP_SCOPE:
+		val->intval = POWER_SUPPLY_SCOPE_DEVICE;
+		break;
 	default:
 		ret = -EINVAL;
 		break;
drivers/hid/hid-wiimote.c +7 -1
index 76739c0..98e4828 100644
@@ -136,7 +136,8 @@ static __u16 wiiproto_keymap[] = {
 };
 
 static enum power_supply_property wiimote_battery_props[] = {
-	POWER_SUPPLY_PROP_CAPACITY
+	POWER_SUPPLY_PROP_CAPACITY,
+	POWER_SUPPLY_PROP_SCOPE,
 };
 
 /* requires the state.lock spinlock to be held */
@@ -468,6 +469,11 @@ static int wiimote_battery_get_property(struct power_supply *psy,
 	int ret = 0, state;
 	unsigned long flags;
 
+	if (psp == POWER_SUPPLY_PROP_SCOPE) {
+		val->intval = POWER_SUPPLY_SCOPE_DEVICE;
+		return 0;
+	}
+
 	ret = wiimote_cmd_acquire(wdata);
 	if (ret)
 		return ret;
Signature · 1 line
1.7.7.3
#0 lore raw

v2 cover Add "scope" to power supplies

This series adds a "scope" attribute to power supplies, to indicate whether it powers the whole system ("System") or just some subset of the devices ("Device"). This allows upowerd to distinguish between system-wide power supplies and self-powered devices such as cordless mice.

This series also adds a "powers" link to power supplies, so that if they're scope=Device, they can specifically indicate which device tree they power.

Updates since last post:
- Add more complete documentation to scope and "powers" links
- Remove unnecessary scopes on System power supplies
- Make HID battery supplies Device, and add "powers" pointers for them.

This can also be pulled from:
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git power-supply-scope

Jeremy Fitzhardinge (4):
power_supply: add SCOPE attribute to power supplies
power_supply: allow a power supply to explicitly point to powered
device
power_supply: add scope properties to some self-powered HID devices
power_supply: add "powers" links to self-powered HID devices

 drivers/hid/hid-wacom.c            |   16 ++++++++++++++--
 drivers/hid/hid-wiimote.c          |   10 +++++++++-
 drivers/power/power_supply_core.c  |    7 +++++++
 drivers/power/power_supply_sysfs.c |    6 ++++++
 include/linux/power_supply.h       |    8 ++++++++
 5 files changed, 44 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.7.3
#2 lore raw

RFC PATCH v2 2/4 power_supply: allow a power supply to explicitly point to powered device

If a power supply has a scope of "Device", then allow the power supply to indicate what device it actually powers. This is represented in the power supply's sysfs directory as a symlink named "powers", which points to the sysfs directory of the powered device.

If the device has children, then the sub-devices are also powered by the same power supply.

---
 drivers/power/power_supply_core.c |    7 +++++++
 include/linux/power_supply.h      |    1 +
 2 files changed, 8 insertions(+), 0 deletions(-)
drivers/power/power_supply_core.c +7 -0
index 329b46b..b10c121 100644
@@ -147,6 +147,12 @@ struct power_supply *power_supply_get_by_name(char *name)
 }
 EXPORT_SYMBOL_GPL(power_supply_get_by_name);
 
+int power_supply_powers(struct power_supply *psy, struct device *dev)
+{
+	return sysfs_create_link_nowarn(&psy->dev->kobj, &dev->kobj, "powers");
+}
+EXPORT_SYMBOL_GPL(power_supply_powers);
+
 static void power_supply_dev_release(struct device *dev)
 {
 	pr_debug("device: '%s': %s\n", dev_name(dev), __func__);
@@ -202,6 +208,7 @@ EXPORT_SYMBOL_GPL(power_supply_register);
 void power_supply_unregister(struct power_supply *psy)
 {
 	cancel_work_sync(&psy->changed_work);
+	sysfs_remove_link(&psy->dev->kobj, "powers");
 	power_supply_remove_triggers(psy);
 	device_unregister(psy->dev);
 }
include/linux/power_supply.h +1 -0
index 040a7b0..2e3c827 100644
@@ -218,6 +218,7 @@ static inline int power_supply_is_system_supplied(void) { return -ENOSYS; }
 extern int power_supply_register(struct device *parent,
 				 struct power_supply *psy);
 extern void power_supply_unregister(struct power_supply *psy);
+extern int power_supply_powers(struct power_supply *psy, struct device *dev);
 
 /* For APM emulation, think legacy userspace. */
 extern struct class *power_supply_class;
Signature · 1 line
1.7.7.3
#5 lore raw
In reply to Jeremy Fitzhardinge
Quoted 26 lines · Jeremy Fitzhardinge

This series adds a "scope" attribute to power supplies, to indicate whether it powers the whole system ("System") or just some subset of the devices ("Device"). This allows upowerd to distinguish between system-wide power supplies and self-powered devices such as cordless mice.

This series also adds a "powers" link to power supplies, so that if they're scope=Device, they can specifically indicate which device tree they power.

Updates since last post:
- Add more complete documentation to scope and "powers" links
- Remove unnecessary scopes on System power supplies
- Make HID battery supplies Device, and add "powers" pointers for them.

This can also be pulled from:
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git power-supply-scope

Jeremy Fitzhardinge (4):
power_supply: add SCOPE attribute to power supplies
power_supply: allow a power supply to explicitly point to powered
device
power_supply: add scope properties to some self-powered HID devices
power_supply: add "powers" links to self-powered HID devices

Quoted 6 lines
 drivers/hid/hid-wacom.c            |   16 ++++++++++++++--
 drivers/hid/hid-wiimote.c          |   10 +++++++++-
 drivers/power/power_supply_core.c  |    7 +++++++
 drivers/power/power_supply_sysfs.c |    6 ++++++
 include/linux/power_supply.h       |    8 ++++++++
 5 files changed, 44 insertions(+), 3 deletions(-)

Anton, in case you are going to take this patchset, I think it makes sense to take it through your tree. In that case, please add

to the two patches touching drivers/hid/. Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
#6 lore raw
In reply to Jeremy Fitzhardinge

Ping?

Quoted 33 lines · Jeremy Fitzhardinge

This series adds a "scope" attribute to power supplies, to indicate whether it powers the whole system ("System") or just some subset of the devices ("Device"). This allows upowerd to distinguish between system-wide power supplies and self-powered devices such as cordless mice.

This series also adds a "powers" link to power supplies, so that if they're scope=Device, they can specifically indicate which device tree they power.

Updates since last post:
- Add more complete documentation to scope and "powers" links
- Remove unnecessary scopes on System power supplies
- Make HID battery supplies Device, and add "powers" pointers for them.

This can also be pulled from:
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git power-supply-scope

Jeremy Fitzhardinge (4):
power_supply: add SCOPE attribute to power supplies
power_supply: allow a power supply to explicitly point to powered
device
power_supply: add scope properties to some self-powered HID devices
power_supply: add "powers" links to self-powered HID devices

 drivers/hid/hid-wacom.c            |   16 ++++++++++++++--
 drivers/hid/hid-wiimote.c          |   10 +++++++++-
 drivers/power/power_supply_core.c  |    7 +++++++
 drivers/power/power_supply_sysfs.c |    6 ++++++
 include/linux/power_supply.h       |    8 ++++++++
 5 files changed, 44 insertions(+), 3 deletions(-)
#7 lore raw
Quoted 1 line · Jeremy Fitzhardinge

Ping?

Anton, if you are not going to take this patchset for whatever reason, but are fine with the changes, feel free to just provide Ack for the patches touching drivers/power, and I'll take them through hid tree.

Thanks.

Quoted 36 lines · Jeremy Fitzhardinge
Quoted 33 lines

This series adds a "scope" attribute to power supplies, to indicate whether it powers the whole system ("System") or just some subset of the devices ("Device"). This allows upowerd to distinguish between system-wide power supplies and self-powered devices such as cordless mice.

This series also adds a "powers" link to power supplies, so that if they're scope=Device, they can specifically indicate which device tree they power.

Updates since last post:
- Add more complete documentation to scope and "powers" links
- Remove unnecessary scopes on System power supplies
- Make HID battery supplies Device, and add "powers" pointers for them.

This can also be pulled from:
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git power-supply-scope

Jeremy Fitzhardinge (4):
power_supply: add SCOPE attribute to power supplies
power_supply: allow a power supply to explicitly point to powered
device
power_supply: add scope properties to some self-powered HID devices
power_supply: add "powers" links to self-powered HID devices

 drivers/hid/hid-wacom.c            |   16 ++++++++++++++--
 drivers/hid/hid-wiimote.c          |   10 +++++++++-
 drivers/power/power_supply_core.c  |    7 +++++++
 drivers/power/power_supply_sysfs.c |    6 ++++++
 include/linux/power_supply.h       |    8 ++++++++
 5 files changed, 44 insertions(+), 3 deletions(-)
Signature · 2 lines
Jiri Kosina
SUSE Labs
#8 lore raw
Quoted 5 lines · Jiri Kosina
Quoted 1 line

Ping?

Anton, if you are not going to take this patchset for whatever reason, but are fine with the changes, feel free to just provide Ack for the patches touching drivers/power, and I'll take them through hid tree.

Anton, hello?

Quoted 34 lines
Quoted 34 lines · Jeremy Fitzhardinge
Quoted 33 lines

This series adds a "scope" attribute to power supplies, to indicate whether it powers the whole system ("System") or just some subset of the devices ("Device"). This allows upowerd to distinguish between system-wide power supplies and self-powered devices such as cordless mice.

This series also adds a "powers" link to power supplies, so that if they're scope=Device, they can specifically indicate which device tree they power.

Updates since last post:
- Add more complete documentation to scope and "powers" links
- Remove unnecessary scopes on System power supplies
- Make HID battery supplies Device, and add "powers" pointers for them.

This can also be pulled from:
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git power-supply-scope

Jeremy Fitzhardinge (4):
power_supply: add SCOPE attribute to power supplies
power_supply: allow a power supply to explicitly point to powered
device
power_supply: add scope properties to some self-powered HID devices
power_supply: add "powers" links to self-powered HID devices

 drivers/hid/hid-wacom.c            |   16 ++++++++++++++--
 drivers/hid/hid-wiimote.c          |   10 +++++++++-
 drivers/power/power_supply_core.c  |    7 +++++++
 drivers/power/power_supply_sysfs.c |    6 ++++++
 include/linux/power_supply.h       |    8 ++++++++
 5 files changed, 44 insertions(+), 3 deletions(-)
Signature · 2 lines
Jiri Kosina
SUSE Labs
#9 lore raw
In reply to Jeremy Fitzhardinge
Quoted 26 lines · Jeremy Fitzhardinge

This series adds a "scope" attribute to power supplies, to indicate whether it powers the whole system ("System") or just some subset of the devices ("Device"). This allows upowerd to distinguish between system-wide power supplies and self-powered devices such as cordless mice.

This series also adds a "powers" link to power supplies, so that if they're scope=Device, they can specifically indicate which device tree they power.

Updates since last post:
- Add more complete documentation to scope and "powers" links
- Remove unnecessary scopes on System power supplies
- Make HID battery supplies Device, and add "powers" pointers for them.

This can also be pulled from:
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git power-supply-scope

Jeremy Fitzhardinge (4):
power_supply: add SCOPE attribute to power supplies
power_supply: allow a power supply to explicitly point to powered
device
power_supply: add scope properties to some self-powered HID devices
power_supply: add "powers" links to self-powered HID devices

Quoted 6 lines
 drivers/hid/hid-wacom.c            |   16 ++++++++++++++--
 drivers/hid/hid-wiimote.c          |   10 +++++++++-
 drivers/power/power_supply_core.c  |    7 +++++++
 drivers/power/power_supply_sysfs.c |    6 ++++++
 include/linux/power_supply.h       |    8 ++++++++
 5 files changed, 44 insertions(+), 3 deletions(-)

Pulled into battery-2.6.git, thank you!

Signature · 2 lines
Anton Vorontsov
Email: [email protected]
Acked-by
#10 lore raw
Quoted 26 lines · Anton Vorontsov
Quoted 26 lines

This series adds a "scope" attribute to power supplies, to indicate whether it powers the whole system ("System") or just some subset of the devices ("Device"). This allows upowerd to distinguish between system-wide power supplies and self-powered devices such as cordless mice.

This series also adds a "powers" link to power supplies, so that if they're scope=Device, they can specifically indicate which device tree they power.

Updates since last post:
- Add more complete documentation to scope and "powers" links
- Remove unnecessary scopes on System power supplies
- Make HID battery supplies Device, and add "powers" pointers for them.

This can also be pulled from:
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git power-supply-scope

Jeremy Fitzhardinge (4):
power_supply: add SCOPE attribute to power supplies
power_supply: allow a power supply to explicitly point to powered
device
power_supply: add scope properties to some self-powered HID devices
power_supply: add "powers" links to self-powered HID devices

Quoted 8 lines
Quoted 6 lines
 drivers/hid/hid-wacom.c            |   16 ++++++++++++++--
 drivers/hid/hid-wiimote.c          |   10 +++++++++-
 drivers/power/power_supply_core.c  |    7 +++++++
 drivers/power/power_supply_sysfs.c |    6 ++++++
 include/linux/power_supply.h       |    8 ++++++++
 5 files changed, 44 insertions(+), 3 deletions(-)

Pulled into battery-2.6.git, thank you!

Thanks. Looking at the tree ... in case you are going to rebase the branch, please add

or at least

to patches touching drivers/hid. Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
#11 lore raw

On Wed, Jan 04, 2012 at 01:48:40PM +0100, Jiri Kosina wrote:
[...]

Quoted 5 lines
Quoted 1 line

Pulled into battery-2.6.git, thank you!

Thanks. Looking at the tree ... in case you are going to rebase the branch, please add

Quoted 7 lines

or at least

to patches touching drivers/hid. Thanks,

Yeah, since I just pulled that tree, I didn't have a chance to insert your Ack. But if I ever rebase the tree, I'll add it.

In any case, I'll mention your ack when I send a pull request to Linus.

Thanks!

Signature · 2 lines
Anton Vorontsov
Email: [email protected]