diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2019-12-19 19:27:58 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2019-12-20 15:06:20 +0100 |
commit | ad2c5cb39faf64881ce392a410df4f01315439e9 (patch) | |
tree | 1efcf271a84f6b6fa8d93c5c633c44671f2cd0e0 /drivers/regulator | |
parent | afb73b61e1d9b215d450df32bbd4687ab914adae (diff) | |
download | barebox-ad2c5cb39faf64881ce392a410df4f01315439e9.tar.gz barebox-ad2c5cb39faf64881ce392a410df4f01315439e9.tar.xz |
regulator: add function to get regulator by its name
Useful for getting regulators that are not correctly associated with a
device.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/core.c | 30 |
1 files changed, 29 insertions, 1 deletions
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"); } } |