2022-09-09 18:19:11

by Sebastian Reichel

[permalink] [raw]
Subject: [PATCHv3 12/14] regulator: expose regmap_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.

Signed-off-by: Sebastian Reichel <[email protected]>
---
drivers/regulator/helpers.c | 20 +++++++++++++++++---
include/linux/regulator/driver.h | 2 ++
2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c
index ad2237a95572..eb1f18917d05 100644
--- a/drivers/regulator/helpers.c
+++ b/drivers/regulator/helpers.c
@@ -902,7 +902,20 @@ bool regulator_is_equal(struct regulator *reg1, struct regulator *reg2)
}
EXPORT_SYMBOL_GPL(regulator_is_equal);

-static int find_closest_bigger(unsigned int target, const unsigned int *table,
+/**
+ * regmap_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 regmap_find_closest_bigger(unsigned int target, const unsigned int *table,
unsigned int num_sel, unsigned int *sel)
{
unsigned int s, tmp, max, maxsel = 0;
@@ -933,6 +946,7 @@ static int find_closest_bigger(unsigned int target, const unsigned int *table,

return 0;
}
+EXPORT_SYMBOL_GPL(regmap_find_closest_bigger);

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

- ret = find_closest_bigger(ramp_delay, rdev->desc->ramp_delay_table,
- rdev->desc->n_ramp_values, &sel);
+ ret = regmap_find_closest_bigger(ramp_delay, rdev->desc->ramp_delay_table,
+ rdev->desc->n_ramp_values, &sel);

if (ret) {
dev_warn(rdev_get_dev(rdev),
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index f9a7461e72b8..9501dbec64da 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -757,6 +757,8 @@ int regulator_set_current_limit_regmap(struct regulator_dev *rdev,
int min_uA, int max_uA);
int regulator_get_current_limit_regmap(struct regulator_dev *rdev);
void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
+int regmap_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_sync_voltage_rdev(struct regulator_dev *rdev);

--
2.35.1


2022-09-10 17:21:19

by Matti Vaittinen

[permalink] [raw]
Subject: Re: [PATCHv3 12/14] regulator: expose regmap_find_closest_bigger

pe 9. syysk. 2022 klo 21.21 Sebastian Reichel
([email protected]) kirjoitti:
>
> 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.
>

I am always in favor of adding helpers to be used for common tasks. I
am not demanding this (so please ignore my comment if you feel so) but
I guess finding the "closest bigger" from a table is not ramp-delay or
even regulator specific. I believe something like this might live
under lib - if exported.

Anyways, and whatever it is worth:
Acked-by: Matti Vaittinen <matti.vaittinen@[email protected]>
for exporting such a helper. (Or please disregard the ack if acks are
reserved only for maintainers - It's just a sign that I think this is
a good idea [even if it could live in lib])

Yours
-- Matti
--

Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~

2022-09-19 14:23:18

by Sebastian Reichel

[permalink] [raw]
Subject: Re: [PATCHv3 12/14] regulator: expose regmap_find_closest_bigger

Hi,

On Sat, Sep 10, 2022 at 08:17:09PM +0300, Matti Vaittinen wrote:
> pe 9. syysk. 2022 klo 21.21 Sebastian Reichel
> ([email protected]) kirjoitti:
> >
> > 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.
> >
>
> I am always in favor of adding helpers to be used for common tasks. I
> am not demanding this (so please ignore my comment if you feel so) but
> I guess finding the "closest bigger" from a table is not ramp-delay or
> even regulator specific. I believe something like this might live
> under lib - if exported.

I'm bad with naming :) If you or Mark have a specific suggestion I
can change it accordingly.

> Anyways, and whatever it is worth:
> Acked-by: Matti Vaittinen <matti.vaittinen@[email protected]>
> for exporting such a helper. (Or please disregard the ack if acks are
> reserved only for maintainers - It's just a sign that I think this is
> a good idea [even if it could live in lib])

I usually use 'Reviewed-by: <...>' in that case. But your Acked
line is broken. Looks like you have split personality problem
between work and private mail account :)

-- Sebastian


Attachments:
(No filename) (1.27 kB)
signature.asc (849.00 B)
Download all attachments

2022-09-28 17:54:42

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCHv3 12/14] regulator: expose regmap_find_closest_bigger

On Fri, Sep 09, 2022 at 07:55:20PM +0200, Sebastian Reichel wrote:

> -static int find_closest_bigger(unsigned int target, const unsigned int *table,

> +int regmap_find_closest_bigger(unsigned int target, const unsigned int *table,
> unsigned int num_sel, unsigned int *sel)

So this will create a function in the regmap namespace in the regulator
code which doesn't seem to interact with regmaps in any way? I'm a bit
confused.


Attachments:
(No filename) (452.00 B)
signature.asc (499.00 B)
Download all attachments