Commit df109e63 authored by Magnus Damm's avatar Magnus Damm Committed by Paul Mundt

sh: use shared frequency tables on sh7785

This patch converts the sh7785 clock code to make use
of clk_rate_table_build() and clk_rate_table_round().
The ->build_rate_table() callback is removed, the
table building is instead handled in ->recalc().
Signed-off-by: default avatarMagnus Damm <damm@igel.co.jp>
Signed-off-by: default avatarPaul Mundt <lethal@linux-sh.org>
parent c94a8574
...@@ -19,6 +19,12 @@ ...@@ -19,6 +19,12 @@
static unsigned int div2[] = { 1, 2, 4, 6, 8, 12, 16, 18, static unsigned int div2[] = { 1, 2, 4, 6, 8, 12, 16, 18,
24, 32, 36, 48 }; 24, 32, 36, 48 };
static struct clk_div_mult_table cpg_div = {
.divisors = div2,
.nr_divisors = ARRAY_SIZE(div2),
};
struct clk_priv { struct clk_priv {
unsigned int shift; unsigned int shift;
...@@ -52,82 +58,23 @@ FRQMR_CLK_DATA(ifc, 28, 0x000e); ...@@ -52,82 +58,23 @@ FRQMR_CLK_DATA(ifc, 28, 0x000e);
static unsigned long frqmr_recalc(struct clk *clk) static unsigned long frqmr_recalc(struct clk *clk)
{ {
struct clk_priv *data = clk->priv; struct clk_priv *data = clk->priv;
unsigned int idx; unsigned int idx = (__raw_readl(FRQMR1) >> data->shift) & 0x000f;
idx = (__raw_readl(FRQMR1) >> data->shift) & 0x000f; clk_rate_table_build(clk, data->freq_table, ARRAY_SIZE(div2),
&cpg_div, &data->div_bitmap);
return clk->parent->rate / div2[idx]; return data->freq_table[idx].frequency;
}
static void frqmr_build_rate_table(struct clk *clk)
{
struct clk_priv *data = clk->priv;
int i, entry;
for (i = entry = 0; i < ARRAY_SIZE(div2); i++) {
if ((data->div_bitmap & (1 << i)) == 0)
continue;
data->freq_table[entry].index = entry;
data->freq_table[entry].frequency =
clk->parent->rate / div2[i];
entry++;
}
if (entry == 0) {
pr_warning("clkfwk: failed to build frequency table "
"for \"%s\" clk!\n", clk->name);
return;
}
/* Termination entry */
data->freq_table[entry].index = entry;
data->freq_table[entry].frequency = CPUFREQ_TABLE_END;
} }
static long frqmr_round_rate(struct clk *clk, unsigned long rate) static long frqmr_round_rate(struct clk *clk, unsigned long rate)
{ {
struct clk_priv *data = clk->priv; struct clk_priv *data = clk->priv;
unsigned long rate_error, rate_error_prev = ~0UL;
unsigned long rate_best_fit = rate;
unsigned long highest, lowest;
int i;
highest = lowest = 0;
for (i = 0; data->freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {
unsigned long freq = data->freq_table[i].frequency;
if (freq == CPUFREQ_ENTRY_INVALID)
continue;
if (freq > highest)
highest = freq;
if (freq < lowest)
lowest = freq;
rate_error = abs(freq - rate);
if (rate_error < rate_error_prev) {
rate_best_fit = freq;
rate_error_prev = rate_error;
}
if (rate_error == 0)
break;
}
if (rate >= highest)
rate_best_fit = highest;
if (rate <= lowest)
rate_best_fit = lowest;
return rate_best_fit; return clk_rate_table_round(clk, data->freq_table, rate);
} }
static struct clk_ops frqmr_clk_ops = { static struct clk_ops frqmr_clk_ops = {
.recalc = frqmr_recalc, .recalc = frqmr_recalc,
.build_rate_table = frqmr_build_rate_table,
.round_rate = frqmr_round_rate, .round_rate = frqmr_round_rate,
}; };
......
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