Message ID | 20170508151354.21711-1-hdegoede@redhat.com (mailing list archive) |
---|---|
State | Not Applicable, archived |
Headers | show |
Hi, On Mon, May 08, 2017 at 05:13:54PM +0200, Hans de Goede wrote: > 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> Thanks, queued. -- Sebastian > --- > drivers/power/supply/power_supply_core.c | 24 +++++++++++++++++++++++- > 1 file changed, 23 insertions(+), 1 deletion(-) > > diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c > index 7ec7c7c202bd..0c09144193a6 100644 > --- a/drivers/power/supply/power_supply_core.c > +++ b/drivers/power/supply/power_supply_core.c > @@ -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 > -- > 2.12.2 >
diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index 7ec7c7c202bd..0c09144193a6 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -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
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> --- drivers/power/supply/power_supply_core.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)