Commit 431cb97b authored by Sebastian Reichel's avatar Sebastian Reichel Committed by Mark Brown

regulator: expose regulator_find_closest_bigger

Expose and document the table lookup logic used by
regulator_set_ramp_delay_regmap, so that it can be
reused for devices that cannot be configured via
regulator_set_ramp_delay_regmap.

Tested-by: Diederik de Haas <didi.debian@cknow.org> # Rock64, Quartz64 Model A + B
Tested-by: Vincent Legoll <vincent.legoll@gmail.com> # Pine64 QuartzPro64
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
Link: https://lore.kernel.org/r/20230504173618.142075-11-sebastian.reichel@collabora.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 924764aa
...@@ -902,8 +902,21 @@ bool regulator_is_equal(struct regulator *reg1, struct regulator *reg2) ...@@ -902,8 +902,21 @@ bool regulator_is_equal(struct regulator *reg1, struct regulator *reg2)
} }
EXPORT_SYMBOL_GPL(regulator_is_equal); EXPORT_SYMBOL_GPL(regulator_is_equal);
static int find_closest_bigger(unsigned int target, const unsigned int *table, /**
unsigned int num_sel, unsigned int *sel) * regulator_find_closest_bigger - helper to find offset in ramp delay table
*
* @target: targeted ramp_delay
* @table: table with supported ramp delays
* @num_sel: number of entries in the table
* @sel: Pointer to store table offset
*
* This is the internal helper used by regulator_set_ramp_delay_regmap to
* map ramp delay to register value. It should only be used directly if
* regulator_set_ramp_delay_regmap cannot handle a specific device setup
* (e.g. because the value is split over multiple registers).
*/
int regulator_find_closest_bigger(unsigned int target, const unsigned int *table,
unsigned int num_sel, unsigned int *sel)
{ {
unsigned int s, tmp, max, maxsel = 0; unsigned int s, tmp, max, maxsel = 0;
bool found = false; bool found = false;
...@@ -933,6 +946,7 @@ static int find_closest_bigger(unsigned int target, const unsigned int *table, ...@@ -933,6 +946,7 @@ static int find_closest_bigger(unsigned int target, const unsigned int *table,
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(regulator_find_closest_bigger);
/** /**
* regulator_set_ramp_delay_regmap - set_ramp_delay() helper * regulator_set_ramp_delay_regmap - set_ramp_delay() helper
...@@ -951,8 +965,8 @@ int regulator_set_ramp_delay_regmap(struct regulator_dev *rdev, int ramp_delay) ...@@ -951,8 +965,8 @@ int regulator_set_ramp_delay_regmap(struct regulator_dev *rdev, int ramp_delay)
if (WARN_ON(!rdev->desc->n_ramp_values || !rdev->desc->ramp_delay_table)) if (WARN_ON(!rdev->desc->n_ramp_values || !rdev->desc->ramp_delay_table))
return -EINVAL; return -EINVAL;
ret = find_closest_bigger(ramp_delay, rdev->desc->ramp_delay_table, ret = regulator_find_closest_bigger(ramp_delay, rdev->desc->ramp_delay_table,
rdev->desc->n_ramp_values, &sel); rdev->desc->n_ramp_values, &sel);
if (ret) { if (ret) {
dev_warn(rdev_get_dev(rdev), dev_warn(rdev_get_dev(rdev),
......
...@@ -758,6 +758,8 @@ int regulator_set_current_limit_regmap(struct regulator_dev *rdev, ...@@ -758,6 +758,8 @@ int regulator_set_current_limit_regmap(struct regulator_dev *rdev,
int min_uA, int max_uA); int min_uA, int max_uA);
int regulator_get_current_limit_regmap(struct regulator_dev *rdev); int regulator_get_current_limit_regmap(struct regulator_dev *rdev);
void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data); void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
int regulator_find_closest_bigger(unsigned int target, const unsigned int *table,
unsigned int num_sel, unsigned int *sel);
int regulator_set_ramp_delay_regmap(struct regulator_dev *rdev, int ramp_delay); int regulator_set_ramp_delay_regmap(struct regulator_dev *rdev, int ramp_delay);
int regulator_sync_voltage_rdev(struct regulator_dev *rdev); int regulator_sync_voltage_rdev(struct regulator_dev *rdev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment