forked from Minki/linux
power_supply: Add core support for supplied_from
This patch adds support for supplies to register a list of char *'s which represent the list of supplies which supply them. This is the opposite as the supplied_to list. This change maintains support for supplied_to until all drivers which make use of it already are converted. Signed-off-by: Rhyland Klein <rklein@nvidia.com> Reviewed-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Anton Vorontsov <anton@enomsg.org>
This commit is contained in:
parent
da1233364d
commit
5e0848c602
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user