Skip to content

Commit

Permalink
regulator: helpers: Export helper voltage listing
Browse files Browse the repository at this point in the history
Some drivers need to translate voltage values to selectors prior regulator
registration. Currently a regulator_desc based list_voltages helper is only
exported for regulators using the linear_ranges. Export similar helper also
for regulators using simple linear mapping.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Link: https://lore.kernel.org/r/1200ef7a50c84327ada019b85f6527b4fc9b5ce1.1617020713.git.matti.vaittinen@fi.rohmeurope.com
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Matti Vaittinen authored and Mark Brown committed Apr 2, 2021
1 parent 0d02ec6 commit e3baacf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
36 changes: 28 additions & 8 deletions drivers/regulator/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,33 @@ int regulator_map_voltage_pickable_linear_range(struct regulator_dev *rdev,
}
EXPORT_SYMBOL_GPL(regulator_map_voltage_pickable_linear_range);

/**
* regulator_desc_list_voltage_linear - List voltages with simple calculation
*
* @desc: Regulator desc for regulator which volatges are to be listed
* @selector: Selector to convert into a voltage
*
* Regulators with a simple linear mapping between voltages and
* selectors can set min_uV and uV_step in the regulator descriptor
* and then use this function prior regulator registration to list
* the voltages. This is useful when voltages need to be listed during
* device-tree parsing.
*/
int regulator_desc_list_voltage_linear(const struct regulator_desc *desc,
unsigned int selector)
{
if (selector >= desc->n_voltages)
return -EINVAL;

if (selector < desc->linear_min_sel)
return 0;

selector -= desc->linear_min_sel;

return desc->min_uV + (desc->uV_step * selector);
}
EXPORT_SYMBOL_GPL(regulator_desc_list_voltage_linear);

/**
* regulator_list_voltage_linear - List voltages with simple calculation
*
Expand All @@ -521,14 +548,7 @@ EXPORT_SYMBOL_GPL(regulator_map_voltage_pickable_linear_range);
int regulator_list_voltage_linear(struct regulator_dev *rdev,
unsigned int selector)
{
if (selector >= rdev->desc->n_voltages)
return -EINVAL;
if (selector < rdev->desc->linear_min_sel)
return 0;

selector -= rdev->desc->linear_min_sel;

return rdev->desc->min_uV + (rdev->desc->uV_step * selector);
return regulator_desc_list_voltage_linear(rdev->desc, selector);
}
EXPORT_SYMBOL_GPL(regulator_list_voltage_linear);

Expand Down
2 changes: 2 additions & 0 deletions include/linux/regulator/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,4 +543,6 @@ void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc,
unsigned int selector);

int regulator_desc_list_voltage_linear(const struct regulator_desc *desc,
unsigned int selector);
#endif

0 comments on commit e3baacf

Please sign in to comment.