lkml.org 
[lkml]   [2018]   [Aug]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC/PATCH] regulator: Support regulators where voltage ranges are selectable
On Wed, Aug 22, 2018 at 02:05:07PM +0300, Matti Vaittinen wrote:
> For example ROHM BD71837 and ROHM BD71847 Power management ICs have
> regulators which provide multiple linear ranges. Ranges can be
> selected by individual non contagious bit in vsel register. Add
> regmap helper functions for selecting ranges.
>
> Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
[Snip...]
>
> +static int regulator_range_selector_to_index(struct regulator_dev *rdev,
> + unsigned int rval)
> +{
> + int i;
> +
> + if (!rdev->desc->linear_range_selectors)
> + return -EINVAL;
> +
> + rval &= rdev->desc->vsel_range_mask;
> +
> + for (i = 0; i < rdev->desc->n_linear_ranges; i++) {
> + if (rdev->desc->linear_range_selectors[i] == rval)
> + return i;
> + }
> + return -EINVAL;
> +}
> +
> +/**
> + * regulator_get_voltage_sel_pickable_regmap - pickable range get_voltage_sel
> + *
> + * @rdev: regulator to operate on
> + *
> + * Regulators that use regmap for their register I/O and use pickable
> + * ranges can set the vsel_reg, vsel_mask, vsel_range_reg and vsel_range_mask
> + * fields in their descriptor and then use this as their get_voltage_vsel
> + * operation, saving some code.
> + */
> +int regulator_get_voltage_sel_pickable_regmap(struct regulator_dev *rdev)
> +{
> + unsigned int r_val;
> + unsigned int range;
> + unsigned int val;
> + int ret, i;
> + unsigned int voltages_in_range = 0;
> +
> + if (!rdev->desc->linear_ranges)
> + return -EINVAL;
> +
> + ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val);
> + if (ret != 0)
> + return ret;
> +
> + ret = regmap_read(rdev->regmap, rdev->desc->vsel_range_reg, &r_val);
> + if (ret != 0)
> + return ret;
> +
> + val &= rdev->desc->vsel_mask;
> + val >>= ffs(rdev->desc->vsel_mask) - 1;
> +
> + range = regulator_range_selector_to_index(rdev, r_val);
> + if (range < 0)
> + return -EINVAL;

Got buildbot warning for checking whether unsigned int is negative.
I'll fix this one.

Other than that - I have BD71847 support almost finished - should I
send this change as part of that patch set as these helpers would be
used by the BD71847 patch series?

Br,
Matti Vaittinen

\
 
 \ /
  Last update: 2018-08-27 14:19    [W:0.037 / U:0.716 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site