Skip to content

Commit

Permalink
power: supply: core: Add support for supplied-from device-property
Browse files Browse the repository at this point in the history
On devicetree using platforms the devicetree can provide info on which
power-supplies supply another power-supply through phandles.

This commit adds support for providing this info on non devicetree
platforms through the platform code setting a supplied-from
device-property on the power-supplies parent device.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
  • Loading branch information
Hans de Goede authored and Sebastian Reichel committed May 15, 2017
1 parent a463182 commit 58a36bb
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion drivers/power/supply/power_supply_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,30 @@ static int power_supply_check_supplies(struct power_supply *psy)
return power_supply_populate_supplied_from(psy);
}
#else
static inline int power_supply_check_supplies(struct power_supply *psy)
static int power_supply_check_supplies(struct power_supply *psy)
{
int nval, ret;

if (!psy->dev.parent)
return 0;

nval = device_property_read_string_array(psy->dev.parent,
"supplied-from", NULL, 0);
if (nval <= 0)
return 0;

psy->supplied_from = devm_kmalloc_array(&psy->dev, nval,
sizeof(char *), GFP_KERNEL);
if (!psy->supplied_from)
return -ENOMEM;

ret = device_property_read_string_array(psy->dev.parent,
"supplied-from", (const char **)psy->supplied_from, nval);
if (ret < 0)
return ret;

psy->num_supplies = nval;

return 0;
}
#endif
Expand Down

0 comments on commit 58a36bb

Please sign in to comment.