summaryrefslogtreecommitdiffstats
path: root/drivers/regulator/core.c
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-02-08 20:18:24 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2021-02-10 10:14:29 +0100
commit6ee83ce08b24ed66dd24b7bc572a363ff95b4d6c (patch)
tree1e1f01b2ec20b8ff249eacac02926cc94b74aed6 /drivers/regulator/core.c
parentf38f34a2f41e5981f2995231d94688d31104befc (diff)
downloadbarebox-6ee83ce08b24ed66dd24b7bc572a363ff95b4d6c.tar.gz
barebox-6ee83ce08b24ed66dd24b7bc572a363ff95b4d6c.tar.xz
regulator: add regulator_get_voltage() to API
ADC drivers need to query their reference regulator's voltage to format their raw readings. Provide regulator_get_voltage() so ADC drivers need not hardcode a reference voltage. Regulator drivers that don't support this (i.e. nearly everything in-tree) will have the function return with -EINVAL. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/regulator/core.c')
-rw-r--r--drivers/regulator/core.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 6ea21a4609..7ced283c11 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -176,6 +176,9 @@ int of_regulator_register(struct regulator_dev *rd, struct device_node *node)
ri->node = node;
+ if (rd->desc->fixed_uV && rd->desc->n_voltages == 1)
+ ri->min_uv = ri->max_uv = rd->desc->fixed_uV;
+
of_property_read_u32(node, "regulator-enable-ramp-delay",
&ri->enable_time_us);
of_property_read_u32(node, "regulator-min-microvolt",
@@ -539,6 +542,30 @@ void regulator_bulk_free(int num_consumers,
}
EXPORT_SYMBOL_GPL(regulator_bulk_free);
+int regulator_get_voltage(struct regulator *regulator)
+{
+ struct regulator_dev *rdev = regulator->ri->rdev;
+ int sel, ret;
+
+ if (rdev->desc->ops->get_voltage_sel) {
+ sel = rdev->desc->ops->get_voltage_sel(rdev);
+ if (sel < 0)
+ return sel;
+ ret = rdev->desc->ops->list_voltage(rdev, sel);
+ } else if (rdev->desc->ops->get_voltage) {
+ ret = rdev->desc->ops->get_voltage(rdev);
+ } else if (rdev->desc->ops->list_voltage) {
+ ret = rdev->desc->ops->list_voltage(rdev, 0);
+ } else if (rdev->desc->fixed_uV && (rdev->desc->n_voltages == 1)) {
+ ret = rdev->desc->fixed_uV;
+ } else {
+ return -EINVAL;
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(regulator_get_voltage_rdev);
+
static void regulator_print_one(struct regulator_internal *ri)
{
struct regulator *r;