Commit 8b9dbc16 authored by Russell King's avatar Russell King Committed by Russell King

[ARM] omap: arrange for clock recalc methods to return the rate

linux-omap source commit 33d000c99ee393fe2042f93e8422f94976d276ce
introduces a way to "dry run" clock changes before they're committed.
However, this involves putting logic to handle this into each and
every recalc function, and unfortunately due to the caching, led to
some bugs.

Solve both of issues by making the recalc methods always return the
clock rate for the clock, which the caller decides what to do with.
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent 883992bd
...@@ -156,27 +156,25 @@ __u32 arm_idlect1_mask; ...@@ -156,27 +156,25 @@ __u32 arm_idlect1_mask;
* Omap1 specific clock functions * Omap1 specific clock functions
*-------------------------------------------------------------------------*/ *-------------------------------------------------------------------------*/
static void omap1_watchdog_recalc(struct clk * clk) static unsigned long omap1_watchdog_recalc(struct clk *clk)
{ {
clk->rate = clk->parent->rate / 14; return clk->parent->rate / 14;
} }
static void omap1_uart_recalc(struct clk * clk) static unsigned long omap1_uart_recalc(struct clk *clk)
{ {
unsigned int val = __raw_readl(clk->enable_reg); unsigned int val = __raw_readl(clk->enable_reg);
if (val & clk->enable_bit) return val & clk->enable_bit ? 48000000 : 12000000;
clk->rate = 48000000;
else
clk->rate = 12000000;
} }
static void omap1_sossi_recalc(struct clk *clk) static unsigned long omap1_sossi_recalc(struct clk *clk)
{ {
u32 div = omap_readl(MOD_CONF_CTRL_1); u32 div = omap_readl(MOD_CONF_CTRL_1);
div = (div >> 17) & 0x7; div = (div >> 17) & 0x7;
div++; div++;
clk->rate = clk->parent->rate / div;
return clk->parent->rate / div;
} }
static int omap1_clk_enable_dsp_domain(struct clk *clk) static int omap1_clk_enable_dsp_domain(struct clk *clk)
...@@ -344,19 +342,15 @@ static int calc_dsor_exp(struct clk *clk, unsigned long rate) ...@@ -344,19 +342,15 @@ static int calc_dsor_exp(struct clk *clk, unsigned long rate)
return dsor_exp; return dsor_exp;
} }
static void omap1_ckctl_recalc(struct clk * clk) static unsigned long omap1_ckctl_recalc(struct clk *clk)
{ {
int dsor;
/* Calculate divisor encoded as 2-bit exponent */ /* Calculate divisor encoded as 2-bit exponent */
dsor = 1 << (3 & (omap_readw(ARM_CKCTL) >> clk->rate_offset)); int dsor = 1 << (3 & (omap_readw(ARM_CKCTL) >> clk->rate_offset));
if (unlikely(clk->rate == clk->parent->rate / dsor)) return clk->parent->rate / dsor;
return; /* No change, quick exit */
clk->rate = clk->parent->rate / dsor;
} }
static void omap1_ckctl_recalc_dsp_domain(struct clk * clk) static unsigned long omap1_ckctl_recalc_dsp_domain(struct clk *clk)
{ {
int dsor; int dsor;
...@@ -371,9 +365,7 @@ static void omap1_ckctl_recalc_dsp_domain(struct clk * clk) ...@@ -371,9 +365,7 @@ static void omap1_ckctl_recalc_dsp_domain(struct clk * clk)
dsor = 1 << (3 & (__raw_readw(DSP_CKCTL) >> clk->rate_offset)); dsor = 1 << (3 & (__raw_readw(DSP_CKCTL) >> clk->rate_offset));
omap1_clk_disable(&api_ck.clk); omap1_clk_disable(&api_ck.clk);
if (unlikely(clk->rate == clk->parent->rate / dsor)) return clk->parent->rate / dsor;
return; /* No change, quick exit */
clk->rate = clk->parent->rate / dsor;
} }
/* MPU virtual clock functions */ /* MPU virtual clock functions */
......
...@@ -13,14 +13,14 @@ ...@@ -13,14 +13,14 @@
#ifndef __ARCH_ARM_MACH_OMAP1_CLOCK_H #ifndef __ARCH_ARM_MACH_OMAP1_CLOCK_H
#define __ARCH_ARM_MACH_OMAP1_CLOCK_H #define __ARCH_ARM_MACH_OMAP1_CLOCK_H
static void omap1_ckctl_recalc(struct clk * clk); static unsigned long omap1_ckctl_recalc(struct clk *clk);
static void omap1_watchdog_recalc(struct clk * clk); static unsigned long omap1_watchdog_recalc(struct clk *clk);
static int omap1_set_sossi_rate(struct clk *clk, unsigned long rate); static int omap1_set_sossi_rate(struct clk *clk, unsigned long rate);
static void omap1_sossi_recalc(struct clk *clk); static unsigned long omap1_sossi_recalc(struct clk *clk);
static void omap1_ckctl_recalc_dsp_domain(struct clk * clk); static unsigned long omap1_ckctl_recalc_dsp_domain(struct clk *clk);
static int omap1_clk_set_rate_dsp_domain(struct clk * clk, unsigned long rate); static int omap1_clk_set_rate_dsp_domain(struct clk * clk, unsigned long rate);
static int omap1_set_uart_rate(struct clk * clk, unsigned long rate); static int omap1_set_uart_rate(struct clk * clk, unsigned long rate);
static void omap1_uart_recalc(struct clk * clk); static unsigned long omap1_uart_recalc(struct clk *clk);
static int omap1_set_ext_clk_rate(struct clk * clk, unsigned long rate); static int omap1_set_ext_clk_rate(struct clk * clk, unsigned long rate);
static long omap1_round_ext_clk_rate(struct clk * clk, unsigned long rate); static long omap1_round_ext_clk_rate(struct clk * clk, unsigned long rate);
static void omap1_init_ext_clk(struct clk * clk); static void omap1_init_ext_clk(struct clk * clk);
......
...@@ -239,11 +239,11 @@ u32 omap2_get_dpll_rate(struct clk *clk) ...@@ -239,11 +239,11 @@ u32 omap2_get_dpll_rate(struct clk *clk)
* Used for clocks that have the same value as the parent clock, * Used for clocks that have the same value as the parent clock,
* divided by some factor * divided by some factor
*/ */
void omap2_fixed_divisor_recalc(struct clk *clk) unsigned long omap2_fixed_divisor_recalc(struct clk *clk)
{ {
WARN_ON(!clk->fixed_div); WARN_ON(!clk->fixed_div);
clk->rate = clk->parent->rate / clk->fixed_div; return clk->parent->rate / clk->fixed_div;
} }
/** /**
...@@ -449,21 +449,22 @@ int omap2_clk_enable(struct clk *clk) ...@@ -449,21 +449,22 @@ int omap2_clk_enable(struct clk *clk)
* Used for clocks that are part of CLKSEL_xyz governed clocks. * Used for clocks that are part of CLKSEL_xyz governed clocks.
* REVISIT: Maybe change to use clk->enable() functions like on omap1? * REVISIT: Maybe change to use clk->enable() functions like on omap1?
*/ */
void omap2_clksel_recalc(struct clk *clk) unsigned long omap2_clksel_recalc(struct clk *clk)
{ {
unsigned long rate;
u32 div = 0; u32 div = 0;
pr_debug("clock: recalc'ing clksel clk %s\n", clk->name); pr_debug("clock: recalc'ing clksel clk %s\n", clk->name);
div = omap2_clksel_get_divisor(clk); div = omap2_clksel_get_divisor(clk);
if (div == 0) if (div == 0)
return; return clk->rate;
if (clk->rate == (clk->parent->rate / div)) rate = clk->parent->rate / div;
return;
clk->rate = clk->parent->rate / div; pr_debug("clock: new clock rate is %ld (div %d)\n", rate, div);
pr_debug("clock: new clock rate is %ld (div %d)\n", clk->rate, div); return rate;
} }
/** /**
......
...@@ -36,7 +36,7 @@ void omap2_clk_disable_unused(struct clk *clk); ...@@ -36,7 +36,7 @@ void omap2_clk_disable_unused(struct clk *clk);
#define omap2_clk_disable_unused NULL #define omap2_clk_disable_unused NULL
#endif #endif
void omap2_clksel_recalc(struct clk *clk); unsigned long omap2_clksel_recalc(struct clk *clk);
void omap2_init_clk_clkdm(struct clk *clk); void omap2_init_clk_clkdm(struct clk *clk);
void omap2_init_clksel_parent(struct clk *clk); void omap2_init_clksel_parent(struct clk *clk);
u32 omap2_clksel_get_divisor(struct clk *clk); u32 omap2_clksel_get_divisor(struct clk *clk);
...@@ -44,7 +44,7 @@ u32 omap2_clksel_round_rate_div(struct clk *clk, unsigned long target_rate, ...@@ -44,7 +44,7 @@ u32 omap2_clksel_round_rate_div(struct clk *clk, unsigned long target_rate,
u32 *new_div); u32 *new_div);
u32 omap2_clksel_to_divisor(struct clk *clk, u32 field_val); u32 omap2_clksel_to_divisor(struct clk *clk, u32 field_val);
u32 omap2_divisor_to_clksel(struct clk *clk, u32 div); u32 omap2_divisor_to_clksel(struct clk *clk, u32 div);
void omap2_fixed_divisor_recalc(struct clk *clk); unsigned long omap2_fixed_divisor_recalc(struct clk *clk);
long omap2_clksel_round_rate(struct clk *clk, unsigned long target_rate); long omap2_clksel_round_rate(struct clk *clk, unsigned long target_rate);
int omap2_clksel_set_rate(struct clk *clk, unsigned long rate); int omap2_clksel_set_rate(struct clk *clk, unsigned long rate);
u32 omap2_get_dpll_rate(struct clk *clk); u32 omap2_get_dpll_rate(struct clk *clk);
......
...@@ -369,9 +369,9 @@ static long omap2_dpllcore_round_rate(unsigned long target_rate) ...@@ -369,9 +369,9 @@ static long omap2_dpllcore_round_rate(unsigned long target_rate)
} }
static void omap2_dpllcore_recalc(struct clk *clk) static unsigned long omap2_dpllcore_recalc(struct clk *clk)
{ {
clk->rate = omap2_get_dpll_rate_24xx(clk); return omap2_get_dpll_rate_24xx(clk);
} }
static int omap2_reprogram_dpllcore(struct clk *clk, unsigned long rate) static int omap2_reprogram_dpllcore(struct clk *clk, unsigned long rate)
...@@ -448,9 +448,9 @@ static int omap2_reprogram_dpllcore(struct clk *clk, unsigned long rate) ...@@ -448,9 +448,9 @@ static int omap2_reprogram_dpllcore(struct clk *clk, unsigned long rate)
* *
* Set virt_prcm_set's rate to the mpu_speed field of the current PRCM set. * Set virt_prcm_set's rate to the mpu_speed field of the current PRCM set.
*/ */
static void omap2_table_mpu_recalc(struct clk *clk) static unsigned long omap2_table_mpu_recalc(struct clk *clk)
{ {
clk->rate = curr_prcm_set->mpu_speed; return curr_prcm_set->mpu_speed;
} }
/* /*
...@@ -647,14 +647,14 @@ static u32 omap2_get_sysclkdiv(void) ...@@ -647,14 +647,14 @@ static u32 omap2_get_sysclkdiv(void)
return div; return div;
} }
static void omap2_osc_clk_recalc(struct clk *clk) static unsigned long omap2_osc_clk_recalc(struct clk *clk)
{ {
clk->rate = omap2_get_apll_clkin() * omap2_get_sysclkdiv(); return omap2_get_apll_clkin() * omap2_get_sysclkdiv();
} }
static void omap2_sys_clk_recalc(struct clk *clk) static unsigned long omap2_sys_clk_recalc(struct clk *clk)
{ {
clk->rate = clk->parent->rate / omap2_get_sysclkdiv(); return clk->parent->rate / omap2_get_sysclkdiv();
} }
/* /*
...@@ -707,9 +707,9 @@ int __init omap2_clk_init(void) ...@@ -707,9 +707,9 @@ int __init omap2_clk_init(void)
clk_init(&omap2_clk_functions); clk_init(&omap2_clk_functions);
omap2_osc_clk_recalc(&osc_ck); osc_ck.rate = omap2_osc_clk_recalc(&osc_ck);
propagate_rate(&osc_ck); propagate_rate(&osc_ck);
omap2_sys_clk_recalc(&sys_ck); sys_ck.rate = omap2_sys_clk_recalc(&sys_ck);
propagate_rate(&sys_ck); propagate_rate(&sys_ck);
for (c = omap24xx_clks; c < omap24xx_clks + ARRAY_SIZE(omap24xx_clks); c++) for (c = omap24xx_clks; c < omap24xx_clks + ARRAY_SIZE(omap24xx_clks); c++)
......
...@@ -24,13 +24,13 @@ ...@@ -24,13 +24,13 @@
#include "cm-regbits-24xx.h" #include "cm-regbits-24xx.h"
#include "sdrc.h" #include "sdrc.h"
static void omap2_table_mpu_recalc(struct clk *clk); static unsigned long omap2_table_mpu_recalc(struct clk *clk);
static int omap2_select_table_rate(struct clk *clk, unsigned long rate); static int omap2_select_table_rate(struct clk *clk, unsigned long rate);
static long omap2_round_to_table_rate(struct clk *clk, unsigned long rate); static long omap2_round_to_table_rate(struct clk *clk, unsigned long rate);
static void omap2_sys_clk_recalc(struct clk *clk); static unsigned long omap2_sys_clk_recalc(struct clk *clk);
static void omap2_osc_clk_recalc(struct clk *clk); static unsigned long omap2_osc_clk_recalc(struct clk *clk);
static void omap2_sys_clk_recalc(struct clk *clk); static unsigned long omap2_sys_clk_recalc(struct clk *clk);
static void omap2_dpllcore_recalc(struct clk *clk); static unsigned long omap2_dpllcore_recalc(struct clk *clk);
static int omap2_reprogram_dpllcore(struct clk *clk, unsigned long rate); static int omap2_reprogram_dpllcore(struct clk *clk, unsigned long rate);
/* Key dividers which make up a PRCM set. Ratio's for a PRCM are mandated. /* Key dividers which make up a PRCM set. Ratio's for a PRCM are mandated.
......
...@@ -289,9 +289,9 @@ static struct omap_clk omap34xx_clks[] = { ...@@ -289,9 +289,9 @@ static struct omap_clk omap34xx_clks[] = {
* *
* Recalculate and propagate the DPLL rate. * Recalculate and propagate the DPLL rate.
*/ */
static void omap3_dpll_recalc(struct clk *clk) static unsigned long omap3_dpll_recalc(struct clk *clk)
{ {
clk->rate = omap2_get_dpll_rate(clk); return omap2_get_dpll_rate(clk);
} }
/* _omap3_dpll_write_clken - write clken_bits arg to a DPLL's enable bits */ /* _omap3_dpll_write_clken - write clken_bits arg to a DPLL's enable bits */
...@@ -787,9 +787,10 @@ static void omap3_dpll_deny_idle(struct clk *clk) ...@@ -787,9 +787,10 @@ static void omap3_dpll_deny_idle(struct clk *clk)
* Using parent clock DPLL data, look up DPLL state. If locked, set our * Using parent clock DPLL data, look up DPLL state. If locked, set our
* rate to the dpll_clk * 2; otherwise, just use dpll_clk. * rate to the dpll_clk * 2; otherwise, just use dpll_clk.
*/ */
static void omap3_clkoutx2_recalc(struct clk *clk) static unsigned long omap3_clkoutx2_recalc(struct clk *clk)
{ {
const struct dpll_data *dd; const struct dpll_data *dd;
unsigned long rate;
u32 v; u32 v;
struct clk *pclk; struct clk *pclk;
...@@ -808,9 +809,10 @@ static void omap3_clkoutx2_recalc(struct clk *clk) ...@@ -808,9 +809,10 @@ static void omap3_clkoutx2_recalc(struct clk *clk)
v = __raw_readl(dd->control_reg) & dd->enable_mask; v = __raw_readl(dd->control_reg) & dd->enable_mask;
v >>= __ffs(dd->enable_mask); v >>= __ffs(dd->enable_mask);
if (v != DPLL_LOCKED) if (v != DPLL_LOCKED)
clk->rate = clk->parent->rate; rate = clk->parent->rate;
else else
clk->rate = clk->parent->rate * 2; rate = clk->parent->rate * 2;
return rate;
} }
/* Common clock code */ /* Common clock code */
......
...@@ -27,8 +27,8 @@ ...@@ -27,8 +27,8 @@
#include "prm.h" #include "prm.h"
#include "prm-regbits-34xx.h" #include "prm-regbits-34xx.h"
static void omap3_dpll_recalc(struct clk *clk); static unsigned long omap3_dpll_recalc(struct clk *clk);
static void omap3_clkoutx2_recalc(struct clk *clk); static unsigned long omap3_clkoutx2_recalc(struct clk *clk);
static void omap3_dpll_allow_idle(struct clk *clk); static void omap3_dpll_allow_idle(struct clk *clk);
static void omap3_dpll_deny_idle(struct clk *clk); static void omap3_dpll_deny_idle(struct clk *clk);
static u32 omap3_dpll_autoidle_read(struct clk *clk); static u32 omap3_dpll_autoidle_read(struct clk *clk);
......
...@@ -126,7 +126,7 @@ int clk_set_rate(struct clk *clk, unsigned long rate) ...@@ -126,7 +126,7 @@ int clk_set_rate(struct clk *clk, unsigned long rate)
ret = arch_clock->clk_set_rate(clk, rate); ret = arch_clock->clk_set_rate(clk, rate);
if (ret == 0) { if (ret == 0) {
if (clk->recalc) if (clk->recalc)
clk->recalc(clk); clk->rate = clk->recalc(clk);
propagate_rate(clk); propagate_rate(clk);
} }
spin_unlock_irqrestore(&clockfw_lock, flags); spin_unlock_irqrestore(&clockfw_lock, flags);
...@@ -148,7 +148,7 @@ int clk_set_parent(struct clk *clk, struct clk *parent) ...@@ -148,7 +148,7 @@ int clk_set_parent(struct clk *clk, struct clk *parent)
ret = arch_clock->clk_set_parent(clk, parent); ret = arch_clock->clk_set_parent(clk, parent);
if (ret == 0) { if (ret == 0) {
if (clk->recalc) if (clk->recalc)
clk->recalc(clk); clk->rate = clk->recalc(clk);
propagate_rate(clk); propagate_rate(clk);
} }
spin_unlock_irqrestore(&clockfw_lock, flags); spin_unlock_irqrestore(&clockfw_lock, flags);
...@@ -188,12 +188,9 @@ static int __init omap_clk_setup(char *str) ...@@ -188,12 +188,9 @@ static int __init omap_clk_setup(char *str)
__setup("mpurate=", omap_clk_setup); __setup("mpurate=", omap_clk_setup);
/* Used for clocks that always have same value as the parent clock */ /* Used for clocks that always have same value as the parent clock */
void followparent_recalc(struct clk *clk) unsigned long followparent_recalc(struct clk *clk)
{ {
if (clk == NULL || IS_ERR(clk)) return clk->parent->rate;
return;
clk->rate = clk->parent->rate;
} }
void clk_reparent(struct clk *child, struct clk *parent) void clk_reparent(struct clk *child, struct clk *parent)
...@@ -214,7 +211,7 @@ void propagate_rate(struct clk * tclk) ...@@ -214,7 +211,7 @@ void propagate_rate(struct clk * tclk)
list_for_each_entry(clkp, &tclk->children, sibling) { list_for_each_entry(clkp, &tclk->children, sibling) {
if (clkp->recalc) if (clkp->recalc)
clkp->recalc(clkp); clkp->rate = clkp->recalc(clkp);
propagate_rate(clkp); propagate_rate(clkp);
} }
} }
...@@ -234,7 +231,7 @@ void recalculate_root_clocks(void) ...@@ -234,7 +231,7 @@ void recalculate_root_clocks(void)
list_for_each_entry(clkp, &root_clks, sibling) { list_for_each_entry(clkp, &root_clks, sibling) {
if (clkp->recalc) if (clkp->recalc)
clkp->recalc(clkp); clkp->rate = clkp->recalc(clkp);
propagate_rate(clkp); propagate_rate(clkp);
} }
} }
......
...@@ -75,7 +75,7 @@ struct clk { ...@@ -75,7 +75,7 @@ struct clk {
unsigned long rate; unsigned long rate;
__u32 flags; __u32 flags;
void __iomem *enable_reg; void __iomem *enable_reg;
void (*recalc)(struct clk *); unsigned long (*recalc)(struct clk *);
int (*set_rate)(struct clk *, unsigned long); int (*set_rate)(struct clk *, unsigned long);
long (*round_rate)(struct clk *, unsigned long); long (*round_rate)(struct clk *, unsigned long);
void (*init)(struct clk *); void (*init)(struct clk *);
...@@ -123,7 +123,7 @@ extern void clk_reparent(struct clk *child, struct clk *parent); ...@@ -123,7 +123,7 @@ extern void clk_reparent(struct clk *child, struct clk *parent);
extern void clk_unregister(struct clk *clk); extern void clk_unregister(struct clk *clk);
extern void propagate_rate(struct clk *clk); extern void propagate_rate(struct clk *clk);
extern void recalculate_root_clocks(void); extern void recalculate_root_clocks(void);
extern void followparent_recalc(struct clk *clk); extern unsigned long followparent_recalc(struct clk *clk);
extern void clk_enable_init_clocks(void); extern void clk_enable_init_clocks(void);
#ifdef CONFIG_CPU_FREQ #ifdef CONFIG_CPU_FREQ
extern void clk_init_cpufreq_table(struct cpufreq_frequency_table **table); extern void clk_init_cpufreq_table(struct cpufreq_frequency_table **table);
......
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