Skip to content

Commit 431cb97

Browse files
srebroonie
authored andcommitted
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: Sebastian Reichel <sebastian.reichel@collabora.com> Link: https://lore.kernel.org/r/20230504173618.142075-11-sebastian.reichel@collabora.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 924764a commit 431cb97

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

drivers/regulator/helpers.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,21 @@ bool regulator_is_equal(struct regulator *reg1, struct regulator *reg2)
902902
}
903903
EXPORT_SYMBOL_GPL(regulator_is_equal);
904904

905-
static int find_closest_bigger(unsigned int target, const unsigned int *table,
906-
unsigned int num_sel, unsigned int *sel)
905+
/**
906+
* regulator_find_closest_bigger - helper to find offset in ramp delay table
907+
*
908+
* @target: targeted ramp_delay
909+
* @table: table with supported ramp delays
910+
* @num_sel: number of entries in the table
911+
* @sel: Pointer to store table offset
912+
*
913+
* This is the internal helper used by regulator_set_ramp_delay_regmap to
914+
* map ramp delay to register value. It should only be used directly if
915+
* regulator_set_ramp_delay_regmap cannot handle a specific device setup
916+
* (e.g. because the value is split over multiple registers).
917+
*/
918+
int regulator_find_closest_bigger(unsigned int target, const unsigned int *table,
919+
unsigned int num_sel, unsigned int *sel)
907920
{
908921
unsigned int s, tmp, max, maxsel = 0;
909922
bool found = false;
@@ -933,6 +946,7 @@ static int find_closest_bigger(unsigned int target, const unsigned int *table,
933946

934947
return 0;
935948
}
949+
EXPORT_SYMBOL_GPL(regulator_find_closest_bigger);
936950

937951
/**
938952
* 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)
951965
if (WARN_ON(!rdev->desc->n_ramp_values || !rdev->desc->ramp_delay_table))
952966
return -EINVAL;
953967

954-
ret = find_closest_bigger(ramp_delay, rdev->desc->ramp_delay_table,
955-
rdev->desc->n_ramp_values, &sel);
968+
ret = regulator_find_closest_bigger(ramp_delay, rdev->desc->ramp_delay_table,
969+
rdev->desc->n_ramp_values, &sel);
956970

957971
if (ret) {
958972
dev_warn(rdev_get_dev(rdev),

include/linux/regulator/driver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,8 @@ int regulator_set_current_limit_regmap(struct regulator_dev *rdev,
758758
int min_uA, int max_uA);
759759
int regulator_get_current_limit_regmap(struct regulator_dev *rdev);
760760
void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
761+
int regulator_find_closest_bigger(unsigned int target, const unsigned int *table,
762+
unsigned int num_sel, unsigned int *sel);
761763
int regulator_set_ramp_delay_regmap(struct regulator_dev *rdev, int ramp_delay);
762764
int regulator_sync_voltage_rdev(struct regulator_dev *rdev);
763765

0 commit comments

Comments
 (0)