diff options
author | Javier Martinez Canillas <javier.martinez@collabora.co.uk> | 2014-07-29 12:28:56 -0400 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-07-29 14:24:43 -0400 |
commit | 26988efe11b1dc44853035122927ced25578f302 (patch) | |
tree | 50cc6c35a8c9d853f27a2ca2c38704ee24c5c2e2 /drivers/regulator/core.c | |
parent | e303996e94b8705c85f3d78f3c094d05b0620c9d (diff) |
regulator: core: Allow to get voltage count and list from parent
Load switches are modeled as regulators but they just provide
the voltage of their parent input supply. So, the drivers for
these switches usually neither provide a .list_voltage handler
not set a .n_voltages count. But there is code in the kernel
that assumes that all regulators should be able to provide this
information (e.g: cpufreq and mmc subsystems).
If the voltage count and list are not available for a regulator
and it has a parent input supply, then use the parent values.
Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'drivers/regulator/core.c')
-rw-r--r-- | drivers/regulator/core.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 57fe446fabce..5299456d07ee 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -2182,7 +2182,13 @@ int regulator_count_voltages(struct regulator *regulator) | |||
2182 | { | 2182 | { |
2183 | struct regulator_dev *rdev = regulator->rdev; | 2183 | struct regulator_dev *rdev = regulator->rdev; |
2184 | 2184 | ||
2185 | return rdev->desc->n_voltages ? : -EINVAL; | 2185 | if (rdev->desc->n_voltages) |
2186 | return rdev->desc->n_voltages; | ||
2187 | |||
2188 | if (!rdev->supply) | ||
2189 | return -EINVAL; | ||
2190 | |||
2191 | return regulator_count_voltages(rdev->supply); | ||
2186 | } | 2192 | } |
2187 | EXPORT_SYMBOL_GPL(regulator_count_voltages); | 2193 | EXPORT_SYMBOL_GPL(regulator_count_voltages); |
2188 | 2194 | ||
@@ -2205,12 +2211,17 @@ int regulator_list_voltage(struct regulator *regulator, unsigned selector) | |||
2205 | if (rdev->desc->fixed_uV && rdev->desc->n_voltages == 1 && !selector) | 2211 | if (rdev->desc->fixed_uV && rdev->desc->n_voltages == 1 && !selector) |
2206 | return rdev->desc->fixed_uV; | 2212 | return rdev->desc->fixed_uV; |
2207 | 2213 | ||
2208 | if (!ops->list_voltage || selector >= rdev->desc->n_voltages) | 2214 | if (ops->list_voltage) { |
2215 | if (selector >= rdev->desc->n_voltages) | ||
2216 | return -EINVAL; | ||
2217 | mutex_lock(&rdev->mutex); | ||
2218 | ret = ops->list_voltage(rdev, selector); | ||
2219 | mutex_unlock(&rdev->mutex); | ||
2220 | } else if (rdev->supply) { | ||
2221 | ret = regulator_list_voltage(rdev->supply, selector); | ||
2222 | } else { | ||
2209 | return -EINVAL; | 2223 | return -EINVAL; |
2210 | 2224 | } | |
2211 | mutex_lock(&rdev->mutex); | ||
2212 | ret = ops->list_voltage(rdev, selector); | ||
2213 | mutex_unlock(&rdev->mutex); | ||
2214 | 2225 | ||
2215 | if (ret > 0) { | 2226 | if (ret > 0) { |
2216 | if (ret < rdev->constraints->min_uV) | 2227 | if (ret < rdev->constraints->min_uV) |