Useful for getting regulators that are not correctly associated with a device. Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx> --- drivers/regulator/core.c | 30 +++++++++++++++++++++++++++++- include/regulator.h | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 4ca035ae94..f0de7a52e3 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -327,6 +327,34 @@ struct regulator *regulator_get(struct device_d *dev, const char *supply) return r; } +static struct regulator_internal *regulator_by_name(const char *name) +{ + struct regulator_internal *ri; + + list_for_each_entry(ri, ®ulator_list, list) + if (ri->name && !strcmp(ri->name, name)) + return ri; + + return NULL; +} + +struct regulator *regulator_get_name(const char *name) +{ + struct regulator_internal *ri; + struct regulator *r; + + ri = regulator_by_name(name); + if (!ri) + return ERR_PTR(-ENODEV); + + r = xzalloc(sizeof(*r)); + r->ri = ri; + + list_add_tail(&r->list, &ri->consumer_list); + + return r; +} + /* * regulator_enable - enable a regulator. * @r: the regulator to enable @@ -379,7 +407,7 @@ static void regulator_print_one(struct regulator_internal *ri) printf(" consumers:\n"); list_for_each_entry(r, &ri->consumer_list, list) - printf(" %s\n", dev_name(r->dev)); + printf(" %s\n", r->dev ? dev_name(r->dev) : "none"); } } diff --git a/include/regulator.h b/include/regulator.h index 156acb82f8..a445c5c3d1 100644 --- a/include/regulator.h +++ b/include/regulator.h @@ -116,6 +116,7 @@ void regulators_print(void); #ifdef CONFIG_REGULATOR struct regulator *regulator_get(struct device_d *, const char *); +struct regulator *regulator_get_name(const char *name); int regulator_enable(struct regulator *); int regulator_disable(struct regulator *); int regulator_is_enabled_regmap(struct regulator_dev *); -- 2.24.0 _______________________________________________ barebox mailing list barebox@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/barebox