Skip to content

Commit cffc959

Browse files
AxelLinbroonie
authored andcommitted
regulator: core: Allow drivers to set voltage mapping table in regulator_desc
Some regulator hardware use table based mapping can set volt_table in regulator_desc and use regulator_list_voltage_table() for their list_voltage callback. Signed-off-by: Axel Lin <axel.lin@gmail.com> Acked-by: Liam Girdwood <lrg@ti.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
1 parent f8f5701 commit cffc959

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎drivers/regulator/core.c‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,31 @@ int regulator_list_voltage_linear(struct regulator_dev *rdev,
18821882
}
18831883
EXPORT_SYMBOL_GPL(regulator_list_voltage_linear);
18841884

1885+
/**
1886+
* regulator_list_voltage_table - List voltages with table based mapping
1887+
*
1888+
* @rdev: Regulator device
1889+
* @selector: Selector to convert into a voltage
1890+
*
1891+
* Regulators with table based mapping between voltages and
1892+
* selectors can set volt_table in the regulator descriptor
1893+
* and then use this function as their list_voltage() operation.
1894+
*/
1895+
int regulator_list_voltage_table(struct regulator_dev *rdev,
1896+
unsigned int selector)
1897+
{
1898+
if (!rdev->desc->volt_table) {
1899+
BUG_ON(!rdev->desc->volt_table);
1900+
return -EINVAL;
1901+
}
1902+
1903+
if (selector >= rdev->desc->n_voltages)
1904+
return -EINVAL;
1905+
1906+
return rdev->desc->volt_table[selector];
1907+
}
1908+
EXPORT_SYMBOL_GPL(regulator_list_voltage_table);
1909+
18851910
/**
18861911
* regulator_list_voltage - enumerate supported voltages
18871912
* @regulator: regulator source

‎include/linux/regulator/driver.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ enum regulator_type {
170170
*
171171
* @min_uV: Voltage given by the lowest selector (if linear mapping)
172172
* @uV_step: Voltage increase with each selector (if linear mapping)
173+
* @volt_table: Voltage mapping table (if table based mapping)
173174
*
174175
* @vsel_reg: Register for selector when using regulator_regmap_X_voltage_
175176
* @vsel_mask: Mask for register bitfield used for selector
@@ -189,6 +190,8 @@ struct regulator_desc {
189190
unsigned int min_uV;
190191
unsigned int uV_step;
191192

193+
const unsigned int *volt_table;
194+
192195
unsigned int vsel_reg;
193196
unsigned int vsel_mask;
194197
unsigned int enable_reg;
@@ -271,6 +274,8 @@ int regulator_mode_to_status(unsigned int);
271274

272275
int regulator_list_voltage_linear(struct regulator_dev *rdev,
273276
unsigned int selector);
277+
int regulator_list_voltage_table(struct regulator_dev *rdev,
278+
unsigned int selector);
274279
int regulator_map_voltage_linear(struct regulator_dev *rdev,
275280
int min_uV, int max_uV);
276281
int regulator_map_voltage_iterate(struct regulator_dev *rdev,

0 commit comments

Comments
 (0)