diff options
| -rw-r--r-- | drivers/regulator/core.c | 62 |
1 files changed, 35 insertions, 27 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 1f9ff55b3620..f28c133693ad 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
| @@ -2348,6 +2348,40 @@ static int _regulator_is_enabled(struct regulator_dev *rdev) | |||
| 2348 | return rdev->desc->ops->is_enabled(rdev); | 2348 | return rdev->desc->ops->is_enabled(rdev); |
| 2349 | } | 2349 | } |
| 2350 | 2350 | ||
| 2351 | static int _regulator_list_voltage(struct regulator *regulator, | ||
| 2352 | unsigned selector, int lock) | ||
| 2353 | { | ||
| 2354 | struct regulator_dev *rdev = regulator->rdev; | ||
| 2355 | const struct regulator_ops *ops = rdev->desc->ops; | ||
| 2356 | int ret; | ||
| 2357 | |||
| 2358 | if (rdev->desc->fixed_uV && rdev->desc->n_voltages == 1 && !selector) | ||
| 2359 | return rdev->desc->fixed_uV; | ||
| 2360 | |||
| 2361 | if (ops->list_voltage) { | ||
| 2362 | if (selector >= rdev->desc->n_voltages) | ||
| 2363 | return -EINVAL; | ||
| 2364 | if (lock) | ||
| 2365 | mutex_lock(&rdev->mutex); | ||
| 2366 | ret = ops->list_voltage(rdev, selector); | ||
| 2367 | if (lock) | ||
| 2368 | mutex_unlock(&rdev->mutex); | ||
| 2369 | } else if (rdev->supply) { | ||
| 2370 | ret = _regulator_list_voltage(rdev->supply, selector, lock); | ||
| 2371 | } else { | ||
| 2372 | return -EINVAL; | ||
| 2373 | } | ||
| 2374 | |||
| 2375 | if (ret > 0) { | ||
| 2376 | if (ret < rdev->constraints->min_uV) | ||
| 2377 | ret = 0; | ||
| 2378 | else if (ret > rdev->constraints->max_uV) | ||
| 2379 | ret = 0; | ||
| 2380 | } | ||
| 2381 | |||
| 2382 | return ret; | ||
| 2383 | } | ||
| 2384 | |||
| 2351 | /** | 2385 | /** |
| 2352 | * regulator_is_enabled - is the regulator output enabled | 2386 | * regulator_is_enabled - is the regulator output enabled |
| 2353 | * @regulator: regulator source | 2387 | * @regulator: regulator source |
| @@ -2437,33 +2471,7 @@ EXPORT_SYMBOL_GPL(regulator_count_voltages); | |||
| 2437 | */ | 2471 | */ |
| 2438 | int regulator_list_voltage(struct regulator *regulator, unsigned selector) | 2472 | int regulator_list_voltage(struct regulator *regulator, unsigned selector) |
| 2439 | { | 2473 | { |
| 2440 | struct regulator_dev *rdev = regulator->rdev; | 2474 | return _regulator_list_voltage(regulator, selector, 1); |
| 2441 | const struct regulator_ops *ops = rdev->desc->ops; | ||
| 2442 | int ret; | ||
| 2443 | |||
| 2444 | if (rdev->desc->fixed_uV && rdev->desc->n_voltages == 1 && !selector) | ||
| 2445 | return rdev->desc->fixed_uV; | ||
| 2446 | |||
| 2447 | if (ops->list_voltage) { | ||
| 2448 | if (selector >= rdev->desc->n_voltages) | ||
| 2449 | return -EINVAL; | ||
| 2450 | mutex_lock(&rdev->mutex); | ||
| 2451 | ret = ops->list_voltage(rdev, selector); | ||
| 2452 | mutex_unlock(&rdev->mutex); | ||
| 2453 | } else if (rdev->supply) { | ||
| 2454 | ret = regulator_list_voltage(rdev->supply, selector); | ||
| 2455 | } else { | ||
| 2456 | return -EINVAL; | ||
| 2457 | } | ||
| 2458 | |||
| 2459 | if (ret > 0) { | ||
| 2460 | if (ret < rdev->constraints->min_uV) | ||
| 2461 | ret = 0; | ||
| 2462 | else if (ret > rdev->constraints->max_uV) | ||
| 2463 | ret = 0; | ||
| 2464 | } | ||
| 2465 | |||
| 2466 | return ret; | ||
| 2467 | } | 2475 | } |
| 2468 | EXPORT_SYMBOL_GPL(regulator_list_voltage); | 2476 | EXPORT_SYMBOL_GPL(regulator_list_voltage); |
| 2469 | 2477 | ||
