aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/helpers.c
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2013-08-09 03:29:27 -0400
committerMark Brown <broonie@linaro.org>2013-08-09 06:45:02 -0400
commitd295f7670127eb241d81e96e003b380c77c2b254 (patch)
tree84f185451441d18e1f3e676bdb1edbc4b96cdc98 /drivers/regulator/helpers.c
parentc4a54b8d54218a75b94ab9947449e688869df00d (diff)
regulator: core: Move list_voltage_{linear,linear_range,table} to helpers.c
Move regulator_list_voltage_{linear,linear_range,table} helper functions to helpers.c. Signed-off-by: Axel Lin <axel.lin@ingics.com> Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'drivers/regulator/helpers.c')
-rw-r--r--drivers/regulator/helpers.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c
index d13cf8f7fb90..6e30df14714b 100644
--- a/drivers/regulator/helpers.c
+++ b/drivers/regulator/helpers.c
@@ -320,6 +320,92 @@ int regulator_map_voltage_linear_range(struct regulator_dev *rdev,
320EXPORT_SYMBOL_GPL(regulator_map_voltage_linear_range); 320EXPORT_SYMBOL_GPL(regulator_map_voltage_linear_range);
321 321
322/** 322/**
323 * regulator_list_voltage_linear - List voltages with simple calculation
324 *
325 * @rdev: Regulator device
326 * @selector: Selector to convert into a voltage
327 *
328 * Regulators with a simple linear mapping between voltages and
329 * selectors can set min_uV and uV_step in the regulator descriptor
330 * and then use this function as their list_voltage() operation,
331 */
332int regulator_list_voltage_linear(struct regulator_dev *rdev,
333 unsigned int selector)
334{
335 if (selector >= rdev->desc->n_voltages)
336 return -EINVAL;
337 if (selector < rdev->desc->linear_min_sel)
338 return 0;
339
340 selector -= rdev->desc->linear_min_sel;
341
342 return rdev->desc->min_uV + (rdev->desc->uV_step * selector);
343}
344EXPORT_SYMBOL_GPL(regulator_list_voltage_linear);
345
346/**
347 * regulator_list_voltage_linear_range - List voltages for linear ranges
348 *
349 * @rdev: Regulator device
350 * @selector: Selector to convert into a voltage
351 *
352 * Regulators with a series of simple linear mappings between voltages
353 * and selectors can set linear_ranges in the regulator descriptor and
354 * then use this function as their list_voltage() operation,
355 */
356int regulator_list_voltage_linear_range(struct regulator_dev *rdev,
357 unsigned int selector)
358{
359 const struct regulator_linear_range *range;
360 int i;
361
362 if (!rdev->desc->n_linear_ranges) {
363 BUG_ON(!rdev->desc->n_linear_ranges);
364 return -EINVAL;
365 }
366
367 for (i = 0; i < rdev->desc->n_linear_ranges; i++) {
368 range = &rdev->desc->linear_ranges[i];
369
370 if (!(selector >= range->min_sel &&
371 selector <= range->max_sel))
372 continue;
373
374 selector -= range->min_sel;
375
376 return range->min_uV + (range->uV_step * selector);
377 }
378
379 return -EINVAL;
380}
381EXPORT_SYMBOL_GPL(regulator_list_voltage_linear_range);
382
383/**
384 * regulator_list_voltage_table - List voltages with table based mapping
385 *
386 * @rdev: Regulator device
387 * @selector: Selector to convert into a voltage
388 *
389 * Regulators with table based mapping between voltages and
390 * selectors can set volt_table in the regulator descriptor
391 * and then use this function as their list_voltage() operation.
392 */
393int regulator_list_voltage_table(struct regulator_dev *rdev,
394 unsigned int selector)
395{
396 if (!rdev->desc->volt_table) {
397 BUG_ON(!rdev->desc->volt_table);
398 return -EINVAL;
399 }
400
401 if (selector >= rdev->desc->n_voltages)
402 return -EINVAL;
403
404 return rdev->desc->volt_table[selector];
405}
406EXPORT_SYMBOL_GPL(regulator_list_voltage_table);
407
408/**
323 * regulator_set_bypass_regmap - Default set_bypass() using regmap 409 * regulator_set_bypass_regmap - Default set_bypass() using regmap
324 * 410 *
325 * @rdev: device to operate on. 411 * @rdev: device to operate on.