From: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
To: lgirdwood@gmail.com, broonie@kernel.org, mazziesaccount@gmail.com
Cc: mikko.mutanen@fi.rohmeurope.com,
heikki.haikola@fi.rohmeurope.com, linux-kernel@vger.kernel.org
Subject: Re: [RFC/PATCH] regulator: Support regulators where voltage ranges are selectable
Date: Mon, 27 Aug 2018 15:19:10 +0300 [thread overview]
Message-ID: <20180827121910.GB2448@localhost.localdomain> (raw)
In-Reply-To: <20180822110507.GA6177@localhost.localdomain>
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
next prev parent reply other threads:[~2018-08-27 12:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-22 11:05 [RFC/PATCH] regulator: Support regulators where voltage ranges are selectable Matti Vaittinen
2018-08-27 12:19 ` Matti Vaittinen [this message]
2018-08-28 19:29 ` Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180827121910.GB2448@localhost.localdomain \
--to=matti.vaittinen@fi.rohmeurope.com \
--cc=broonie@kernel.org \
--cc=heikki.haikola@fi.rohmeurope.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mazziesaccount@gmail.com \
--cc=mikko.mutanen@fi.rohmeurope.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox