mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lucas Stach <l.stach@pengutronix.de>
To: Liam Girdwood <lgirdwood@gmail.com>
Cc: Mark Brown <broonie@kernel.org>,
	linux-kernel@vger.kernel.org, kernel@pengutronix.de
Subject: Re: [PATCH] regulator: core: allow non-exact matches in regulator_set_voltage_time()
Date: Thu, 22 May 2014 10:34:08 +0200	[thread overview]
Message-ID: <1400747648.4913.5.camel@weser.hi.pengutronix.de> (raw)
In-Reply-To: <1400691239-21987-1-git-send-email-l.stach@pengutronix.de>

Am Mittwoch, den 21.05.2014, 18:53 +0200 schrieb Lucas Stach:
> Currently this function only provides a valid output if both
> old_uV and new_uV are exact voltages that can be provided by the
> regulator.
> This is almost impossible to achive as the consumer has
> no way to know the exact voltages provided by the regulator.
> Also it creates an unexpected twist in the API, as a user
> could possibly not use the same voltage parameters for
> set_voltage_time() as for set_voltage_time().
And one of the above set_voltage_time() should obviously just have been
a set_voltage().

> 
> This breaks the current cpufreq users of this function, as they
> stick in the raw voltages retrieved from their operating points,
> which may or may not match one of the regulator voltages.
> 
> To make this function behave as expected employ the same logic
> as used when calling set_voltage() and round the voltages to
> the closest matching voltage supported by the regulator.
> 
> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
> ---
>  drivers/regulator/core.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index 9a09f3cdbabb..29ab83f49da9 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
> @@ -2477,7 +2477,7 @@ int regulator_set_voltage_time(struct regulator *regulator,
>  	struct regulator_ops	*ops = rdev->desc->ops;
>  	int old_sel = -1;
>  	int new_sel = -1;
> -	int voltage;
> +	int voltage, best_match_old_uV = INT_MAX, best_match_new_uV = INT_MAX;
>  	int i;
>  
>  	/* Currently requires operations to do this */
> @@ -2486,16 +2486,19 @@ int regulator_set_voltage_time(struct regulator *regulator,
>  		return -EINVAL;
>  
>  	for (i = 0; i < rdev->desc->n_voltages; i++) {
> -		/* We only look for exact voltage matches here */
>  		voltage = regulator_list_voltage(regulator, i);
>  		if (voltage < 0)
>  			return -EINVAL;
>  		if (voltage == 0)
>  			continue;
> -		if (voltage == old_uV)
> +		if (voltage >= old_uV && voltage < best_match_old_uV) {
>  			old_sel = i;
> -		if (voltage == new_uV)
> +			best_match_old_uV = voltage;
> +		}
> +		if (voltage >= new_uV && voltage < best_match_new_uV) {
>  			new_sel = i;
> +			best_match_new_uV = voltage;
> +		}
>  	}
>  
>  	if (old_sel < 0 || new_sel < 0)

-- 
Pengutronix e.K.             | Lucas Stach                 |
Industrial Linux Solutions   | http://www.pengutronix.de/  |


  reply	other threads:[~2014-05-22  8:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-21 16:53 Lucas Stach
2014-05-22  8:34 ` Lucas Stach [this message]
2014-06-01 11:38 ` Mark Brown
2014-06-02 10:27   ` Lucas Stach
2014-06-02 12:15     ` 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=1400747648.4913.5.camel@weser.hi.pengutronix.de \
    --to=l.stach@pengutronix.de \
    --cc=broonie@kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®