Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 367533
b: refs/heads/master
c: 5e0848c
h: refs/heads/master
i:
  367531: 9a0c40e
v: v3
  • Loading branch information
Rhyland Klein authored and Anton Vorontsov committed Apr 17, 2013
1 parent 674f258 commit 352fe2e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: da1233364d51947d8c84a33e200fcfb177ee9f20
refs/heads/master: 5e0848c6026ab98f47e0e179f5c76875cd509d58
47 changes: 34 additions & 13 deletions trunk/drivers/power/power_supply_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,42 @@ EXPORT_SYMBOL_GPL(power_supply_class);

static struct device_type power_supply_dev_type;

static bool __power_supply_is_supplied_by(struct power_supply *supplier,
struct power_supply *supply)
{
int i;

if (!supply->supplied_from && !supplier->supplied_to)
return false;

/* Support both supplied_to and supplied_from modes */
if (supply->supplied_from) {
if (!supplier->name)
return false;
for (i = 0; i < supply->num_supplies; i++)
if (!strcmp(supplier->name, supply->supplied_from[i]))
return true;
} else {
if (!supply->name)
return false;
for (i = 0; i < supplier->num_supplicants; i++)
if (!strcmp(supplier->supplied_to[i], supply->name))
return true;
}

return false;
}

static int __power_supply_changed_work(struct device *dev, void *data)
{
struct power_supply *psy = (struct power_supply *)data;
struct power_supply *pst = dev_get_drvdata(dev);
int i;

for (i = 0; i < psy->num_supplicants; i++)
if (!strcmp(psy->supplied_to[i], pst->name)) {
if (pst->external_power_changed)
pst->external_power_changed(pst);
}
if (__power_supply_is_supplied_by(psy, pst)) {
if (pst->external_power_changed)
pst->external_power_changed(pst);
}

return 0;
}

Expand Down Expand Up @@ -68,17 +93,13 @@ static int __power_supply_am_i_supplied(struct device *dev, void *data)
union power_supply_propval ret = {0,};
struct power_supply *psy = (struct power_supply *)data;
struct power_supply *epsy = dev_get_drvdata(dev);
int i;

for (i = 0; i < epsy->num_supplicants; i++) {
if (!strcmp(epsy->supplied_to[i], psy->name)) {
if (epsy->get_property(epsy,
POWER_SUPPLY_PROP_ONLINE, &ret))
continue;
if (__power_supply_is_supplied_by(epsy, psy))
if (!epsy->get_property(epsy, POWER_SUPPLY_PROP_ONLINE, &ret)) {
if (ret.intval)
return ret.intval;
}
}

return 0;
}

Expand Down
3 changes: 3 additions & 0 deletions trunk/include/linux/power_supply.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ struct power_supply {
char **supplied_to;
size_t num_supplicants;

char **supplied_from;
size_t num_supplies;

int (*get_property)(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val);
Expand Down

0 comments on commit 352fe2e

Please sign in to comment.