From: Liam Girdwood <lrg@slimlogic.co.uk>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: David Collins <collinsd@codeaurora.org>,
linux-kernel@vger.kernel.org,
patches@opensource.wolfsonmicro.com
Subject: Re: [PATCH] regulator: When constraining modes fall back to higher power modes
Date: Wed, 30 Mar 2011 00:29:24 +0100 [thread overview]
Message-ID: <1301441364.3402.41.camel@odin> (raw)
In-Reply-To: <1301434152-16393-1-git-send-email-broonie@opensource.wolfsonmicro.com>
On Wed, 2011-03-30 at 06:29 +0900, Mark Brown wrote:
> If a mode requested by a consumer is not allowed by constraints
> automatically fall back to a higher power mode if possible. This
> ensures that consumers get at least the output they requested while
> allowing machine drivers to transparently limit lower power modes
> if required.
>
> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
> ---
>
> I've not actually had a chance to test this but throwing it out there
> for comment and testing now; someone with an OMAP board can probably
> test fairly quickly as the OMAP HSMMC driver is using set_mode().
>
> drivers/regulator/core.c | 24 +++++++++++++++---------
> 1 files changed, 15 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index 3ffc697..a634946 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
> @@ -197,9 +197,9 @@ static int regulator_check_current_limit(struct regulator_dev *rdev,
> }
>
> /* operating mode constraint check */
> -static int regulator_check_mode(struct regulator_dev *rdev, int mode)
> +static int regulator_mode_constrain(struct regulator_dev *rdev, int *mode)
> {
> - switch (mode) {
> + switch (*mode) {
> case REGULATOR_MODE_FAST:
> case REGULATOR_MODE_NORMAL:
> case REGULATOR_MODE_IDLE:
> @@ -217,11 +217,17 @@ static int regulator_check_mode(struct regulator_dev *rdev, int mode)
> rdev_err(rdev, "operation not allowed\n");
> return -EPERM;
> }
> - if (!(rdev->constraints->valid_modes_mask & mode)) {
> - rdev_err(rdev, "invalid mode %x\n", mode);
> - return -EINVAL;
> +
> + /* The modes are bitmasks, the most power hungry modes having
> + * the lowest values. If the requested mode isn't supported
> + * try higher modes. */
> + while (*mode) {
> + if (rdev->constraints->valid_modes_mask & *mode)
> + return 0;
> + *mode /= 2;
> }
> - return 0;
> +
> + return -EINVAL;
> }
It's late and I'm wondering if it's cleaner here just to :-
if (mask & *mode)
return 0;
*mode = fls(mask);
if (*mode)
return 0;
return -EINVAL;
What do you think ?
Liam
next prev parent reply other threads:[~2011-03-29 23:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-29 21:29 [PATCH] regulator: When constraining modes fall back to higher power modes Mark Brown
2011-03-29 23:29 ` Liam Girdwood [this message]
2011-03-29 23:39 ` Mark Brown
2011-03-30 19:14 ` Liam Girdwood
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=1301441364.3402.41.camel@odin \
--to=lrg@slimlogic.co.uk \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=collinsd@codeaurora.org \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@opensource.wolfsonmicro.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