Commit 960bc368 authored by Paul Mundt's avatar Paul Mundt

sh: reinstate clock framework rate rounding.

This was killed off by a simplification patch previously that failed to
take the cpufreq use case in to account, so reinstate the old bounding
logic. The lowest rate bounding on the other hand was broken in that it
never actually got assigned a rate and the best fit rate was instead just
getting lucky based on the ordering of the rate table, fix this up so the
code actually does what it was intended to do originally.
Signed-off-by: default avatarPaul Mundt <lethal@linux-sh.org>
parent a8dc49b5
/* /*
* drivers/sh/clk.c - SuperH clock framework * drivers/sh/clk.c - SuperH clock framework
* *
* Copyright (C) 2005 - 2009 Paul Mundt * Copyright (C) 2005 - 2010 Paul Mundt
* *
* This clock framework is derived from the OMAP version by: * This clock framework is derived from the OMAP version by:
* *
...@@ -73,14 +73,23 @@ long clk_rate_table_round(struct clk *clk, ...@@ -73,14 +73,23 @@ long clk_rate_table_round(struct clk *clk,
{ {
unsigned long rate_error, rate_error_prev = ~0UL; unsigned long rate_error, rate_error_prev = ~0UL;
unsigned long rate_best_fit = rate; unsigned long rate_best_fit = rate;
unsigned long highest, lowest;
int i; int i;
highest = 0;
lowest = ~0UL;
for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++) { for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {
unsigned long freq = freq_table[i].frequency; unsigned long freq = freq_table[i].frequency;
if (freq == CPUFREQ_ENTRY_INVALID) if (freq == CPUFREQ_ENTRY_INVALID)
continue; continue;
if (freq > highest)
highest = freq;
if (freq < lowest)
lowest = freq;
rate_error = abs(freq - rate); rate_error = abs(freq - rate);
if (rate_error < rate_error_prev) { if (rate_error < rate_error_prev) {
rate_best_fit = freq; rate_best_fit = freq;
...@@ -91,6 +100,11 @@ long clk_rate_table_round(struct clk *clk, ...@@ -91,6 +100,11 @@ long clk_rate_table_round(struct clk *clk,
break; break;
} }
if (rate >= highest)
rate_best_fit = highest;
if (rate <= lowest)
rate_best_fit = lowest;
return rate_best_fit; return rate_best_fit;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment