diff mbox series

[RFC,2/4] regulator: core: Add regulator_map_voltage_descend() API

Message ID 20240605074936.578687-3-prabhakar.mahadev-lad.rj@bp.renesas.com
State New
Headers show
Series Add SD/MMC support for Renesas RZ/V2H(P) SoC | expand

Commit Message

Lad, Prabhakar June 5, 2024, 7:49 a.m. UTC
From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Similarly to regulator_map_voltage_ascend() api add
regulator_map_voltage_descend() api and export it.

Drivers that have descendant voltage list can use this as their
map_voltage() operation.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
 drivers/regulator/helpers.c      | 31 +++++++++++++++++++++++++++++++
 include/linux/regulator/driver.h |  2 ++
 2 files changed, 33 insertions(+)

Comments

Geert Uytterhoeven June 20, 2024, 2:52 p.m. UTC | #1
Hi Prabhakar,

On Wed, Jun 5, 2024 at 9:49 AM Prabhakar <prabhakar.csengg@gmail.com> wrote:
> From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
>
> Similarly to regulator_map_voltage_ascend() api add
> regulator_map_voltage_descend() api and export it.
>
> Drivers that have descendant voltage list can use this as their
> map_voltage() operation.
>
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Thanks for your patch!

> --- a/drivers/regulator/helpers.c
> +++ b/drivers/regulator/helpers.c
> @@ -368,6 +368,37 @@ int regulator_map_voltage_ascend(struct regulator_dev *rdev,
>  }
>  EXPORT_SYMBOL_GPL(regulator_map_voltage_ascend);
>
> +/**
> + * regulator_map_voltage_descend - map_voltage() for descendant voltage list
> + *
> + * @rdev: Regulator to operate on
> + * @min_uV: Lower bound for voltage
> + * @max_uV: Upper bound for voltage
> + *
> + * Drivers that have descendant voltage list can use this as their
> + * map_voltage() operation.
> + */
> +int regulator_map_voltage_descend(struct regulator_dev *rdev,
> +                                 int min_uV, int max_uV)
> +{
> +       int i, ret;
> +
> +       for (i = rdev->desc->n_voltages - 1; i >= 0 ; i--) {
> +               ret = rdev->desc->ops->list_voltage(rdev, i);
> +               if (ret < 0)
> +                       continue;
> +
> +               if (ret > min_uV)

I know this patch is superseded, but shouldn't this be "<"?

> +                       break;
> +
> +               if (ret >= min_uV && ret <= max_uV)
> +                       return i;
> +       }
> +
> +       return -EINVAL;
> +}
> +EXPORT_SYMBOL_GPL(regulator_map_voltage_descend);
> +
>  /**
>   * regulator_map_voltage_linear - map_voltage() for simple linear mappings
>   *

Gr{oetje,eeting}s,

                        Geert
Lad, Prabhakar June 20, 2024, 3:48 p.m. UTC | #2
Hi Geert,

Thank you for the review.

On Thu, Jun 20, 2024 at 3:52 PM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>
> Hi Prabhakar,
>
> On Wed, Jun 5, 2024 at 9:49 AM Prabhakar <prabhakar.csengg@gmail.com> wrote:
> > From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> >
> > Similarly to regulator_map_voltage_ascend() api add
> > regulator_map_voltage_descend() api and export it.
> >
> > Drivers that have descendant voltage list can use this as their
> > map_voltage() operation.
> >
> > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
>
> Thanks for your patch!
>
> > --- a/drivers/regulator/helpers.c
> > +++ b/drivers/regulator/helpers.c
> > @@ -368,6 +368,37 @@ int regulator_map_voltage_ascend(struct regulator_dev *rdev,
> >  }
> >  EXPORT_SYMBOL_GPL(regulator_map_voltage_ascend);
> >
> > +/**
> > + * regulator_map_voltage_descend - map_voltage() for descendant voltage list
> > + *
> > + * @rdev: Regulator to operate on
> > + * @min_uV: Lower bound for voltage
> > + * @max_uV: Upper bound for voltage
> > + *
> > + * Drivers that have descendant voltage list can use this as their
> > + * map_voltage() operation.
> > + */
> > +int regulator_map_voltage_descend(struct regulator_dev *rdev,
> > +                                 int min_uV, int max_uV)
> > +{
> > +       int i, ret;
> > +
> > +       for (i = rdev->desc->n_voltages - 1; i >= 0 ; i--) {
> > +               ret = rdev->desc->ops->list_voltage(rdev, i);
> > +               if (ret < 0)
> > +                       continue;
> > +
> > +               if (ret > min_uV)
>
> I know this patch is superseded, but shouldn't this be "<"?
>
Agreed, thanks I missed that.

Cheers,
Prabhakar
diff mbox series

Patch

diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c
index 6e1ace660b8c..ac62d778e3c0 100644
--- a/drivers/regulator/helpers.c
+++ b/drivers/regulator/helpers.c
@@ -368,6 +368,37 @@  int regulator_map_voltage_ascend(struct regulator_dev *rdev,
 }
 EXPORT_SYMBOL_GPL(regulator_map_voltage_ascend);
 
+/**
+ * regulator_map_voltage_descend - map_voltage() for descendant voltage list
+ *
+ * @rdev: Regulator to operate on
+ * @min_uV: Lower bound for voltage
+ * @max_uV: Upper bound for voltage
+ *
+ * Drivers that have descendant voltage list can use this as their
+ * map_voltage() operation.
+ */
+int regulator_map_voltage_descend(struct regulator_dev *rdev,
+				  int min_uV, int max_uV)
+{
+	int i, ret;
+
+	for (i = rdev->desc->n_voltages - 1; i >= 0 ; i--) {
+		ret = rdev->desc->ops->list_voltage(rdev, i);
+		if (ret < 0)
+			continue;
+
+		if (ret > min_uV)
+			break;
+
+		if (ret >= min_uV && ret <= max_uV)
+			return i;
+	}
+
+	return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(regulator_map_voltage_descend);
+
 /**
  * regulator_map_voltage_linear - map_voltage() for simple linear mappings
  *
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index f230a472ccd3..6410c57ba85a 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -735,6 +735,8 @@  int regulator_map_voltage_iterate(struct regulator_dev *rdev,
 				  int min_uV, int max_uV);
 int regulator_map_voltage_ascend(struct regulator_dev *rdev,
 				  int min_uV, int max_uV);
+int regulator_map_voltage_descend(struct regulator_dev *rdev,
+				  int min_uV, int max_uV);
 int regulator_get_voltage_sel_pickable_regmap(struct regulator_dev *rdev);
 int regulator_set_voltage_sel_pickable_regmap(struct regulator_dev *rdev,
 						unsigned int sel);