diff mbox

cpufreq: dbx500: Round to closest available freq

Message ID 1365599175-22361-1-git-send-email-ulf.hansson@stericsson.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ulf Hansson April 10, 2013, 1:06 p.m. UTC
From: Mats Fagerstrom <mats.fagerstrom@stericsson.com>

When reading the cpu speed, round it to the closest available
frequency from the table.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Mats Fagerstrom <mats.fagerstrom@stericsson.com>
---
 drivers/cpufreq/dbx500-cpufreq.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Linus Walleij April 11, 2013, 8:33 p.m. UTC | #1
On Wed, Apr 10, 2013 at 3:06 PM, Ulf Hansson <ulf.hansson@stericsson.com> wrote:

> From: Mats Fagerstrom <mats.fagerstrom@stericsson.com>
>
> When reading the cpu speed, round it to the closest available
> frequency from the table.
>
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> Signed-off-by: Mats Fagerstrom <mats.fagerstrom@stericsson.com>

(...)
> +       /* The value is rounded to closest frequency in the defined table. */
> +       while (freq_table[i + 1].frequency != CPUFREQ_TABLE_END) {
> +               if (freq < freq_table[i].frequency +
> +                  (freq_table[i + 1].frequency - freq_table[i].frequency) / 2)
>                         return freq_table[i].frequency;

Oh that works, clever.

Acked-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij
Rafael Wysocki April 11, 2013, 9:33 p.m. UTC | #2
On Thursday, April 11, 2013 10:33:07 PM Linus Walleij wrote:
> On Wed, Apr 10, 2013 at 3:06 PM, Ulf Hansson <ulf.hansson@stericsson.com> wrote:
> 
> > From: Mats Fagerstrom <mats.fagerstrom@stericsson.com>
> >
> > When reading the cpu speed, round it to the closest available
> > frequency from the table.
> >
> > Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> > Signed-off-by: Mats Fagerstrom <mats.fagerstrom@stericsson.com>
> 
> (...)
> > +       /* The value is rounded to closest frequency in the defined table. */
> > +       while (freq_table[i + 1].frequency != CPUFREQ_TABLE_END) {
> > +               if (freq < freq_table[i].frequency +
> > +                  (freq_table[i + 1].frequency - freq_table[i].frequency) / 2)
> >                         return freq_table[i].frequency;
> 
> Oh that works, clever.
> 
> Acked-by: Linus Walleij <linus.walleij@linaro.org>

Thanks, applied.

Rafael
Troy Kisky April 11, 2013, 9:52 p.m. UTC | #3
On 4/11/2013 2:33 PM, Rafael J. Wysocki wrote:
> On Thursday, April 11, 2013 10:33:07 PM Linus Walleij wrote:
>> On Wed, Apr 10, 2013 at 3:06 PM, Ulf Hansson <ulf.hansson@stericsson.com> wrote:
>>
>>> From: Mats Fagerstrom <mats.fagerstrom@stericsson.com>
>>>
>>> When reading the cpu speed, round it to the closest available
>>> frequency from the table.
>>>
>>> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
>>> Signed-off-by: Mats Fagerstrom <mats.fagerstrom@stericsson.com>
>> (...)
>>> +       /* The value is rounded to closest frequency in the defined table. */
>>> +       while (freq_table[i + 1].frequency != CPUFREQ_TABLE_END) {
>>> +               if (freq < freq_table[i].frequency +
>>> +                  (freq_table[i + 1].frequency - freq_table[i].frequency) / 2)

if (freq < (freq_table[i].frequency + freq_table[i + 1].frequency) / 2)

is easier to read.



>>>                          return freq_table[i].frequency;
>> Oh that works, clever.
>>
>> Acked-by: Linus Walleij <linus.walleij@linaro.org>
> Thanks, applied.
>
> Rafael
>
>
diff mbox

Patch

diff --git a/drivers/cpufreq/dbx500-cpufreq.c b/drivers/cpufreq/dbx500-cpufreq.c
index 15ed367..6ec6539 100644
--- a/drivers/cpufreq/dbx500-cpufreq.c
+++ b/drivers/cpufreq/dbx500-cpufreq.c
@@ -71,15 +71,15 @@  static unsigned int dbx500_cpufreq_getspeed(unsigned int cpu)
 	int i = 0;
 	unsigned long freq = clk_get_rate(armss_clk) / 1000;
 
-	while (freq_table[i].frequency != CPUFREQ_TABLE_END) {
-		if (freq <= freq_table[i].frequency)
+	/* The value is rounded to closest frequency in the defined table. */
+	while (freq_table[i + 1].frequency != CPUFREQ_TABLE_END) {
+		if (freq < freq_table[i].frequency +
+		   (freq_table[i + 1].frequency - freq_table[i].frequency) / 2)
 			return freq_table[i].frequency;
 		i++;
 	}
 
-	/* We could not find a corresponding frequency. */
-	pr_err("dbx500-cpufreq: Failed to find cpufreq speed\n");
-	return 0;
+	return freq_table[i].frequency;
 }
 
 static int __cpuinit dbx500_cpufreq_init(struct cpufreq_policy *policy)