Skip to content

Commit

Permalink
[ARM] omap: arrange for clock recalc methods to return the rate
Browse files Browse the repository at this point in the history
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: Russell King <rmk+kernel@arm.linux.org.uk>
  • Loading branch information
Russell King authored and Russell King committed Feb 14, 2009
1 parent 883992b commit 8b9dbc1
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 68 deletions.
32 changes: 12 additions & 20 deletions arch/arm/mach-omap1/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,27 +156,25 @@ __u32 arm_idlect1_mask;
* 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);
if (val & clk->enable_bit)
clk->rate = 48000000;
else
clk->rate = 12000000;
return val & clk->enable_bit ? 48000000 : 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);

div = (div >> 17) & 0x7;
div++;
clk->rate = clk->parent->rate / div;

return clk->parent->rate / div;
}

static int omap1_clk_enable_dsp_domain(struct clk *clk)
Expand Down Expand Up @@ -344,19 +342,15 @@ static int calc_dsor_exp(struct clk *clk, unsigned long rate)
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 */
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; /* No change, quick exit */
clk->rate = clk->parent->rate / dsor;
return 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;

Expand All @@ -371,9 +365,7 @@ static void omap1_ckctl_recalc_dsp_domain(struct clk * clk)
dsor = 1 << (3 & (__raw_readw(DSP_CKCTL) >> clk->rate_offset));
omap1_clk_disable(&api_ck.clk);

if (unlikely(clk->rate == clk->parent->rate / dsor))
return; /* No change, quick exit */
clk->rate = clk->parent->rate / dsor;
return clk->parent->rate / dsor;
}

/* MPU virtual clock functions */
Expand Down
10 changes: 5 additions & 5 deletions arch/arm/mach-omap1/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
#ifndef __ARCH_ARM_MACH_OMAP1_CLOCK_H
#define __ARCH_ARM_MACH_OMAP1_CLOCK_H

static void omap1_ckctl_recalc(struct clk * clk);
static void omap1_watchdog_recalc(struct clk * clk);
static unsigned long omap1_ckctl_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 void omap1_sossi_recalc(struct clk *clk);
static void omap1_ckctl_recalc_dsp_domain(struct clk * clk);
static unsigned long omap1_sossi_recalc(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_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 long omap1_round_ext_clk_rate(struct clk * clk, unsigned long rate);
static void omap1_init_ext_clk(struct clk * clk);
Expand Down
17 changes: 9 additions & 8 deletions arch/arm/mach-omap2/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ u32 omap2_get_dpll_rate(struct clk *clk)
* Used for clocks that have the same value as the parent clock,
* 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);

clk->rate = clk->parent->rate / clk->fixed_div;
return clk->parent->rate / clk->fixed_div;
}

/**
Expand Down Expand Up @@ -449,21 +449,22 @@ int omap2_clk_enable(struct clk *clk)
* Used for clocks that are part of CLKSEL_xyz governed clocks.
* 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;

pr_debug("clock: recalc'ing clksel clk %s\n", clk->name);

div = omap2_clksel_get_divisor(clk);
if (div == 0)
return;
return clk->rate;

if (clk->rate == (clk->parent->rate / div))
return;
clk->rate = clk->parent->rate / div;
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;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions arch/arm/mach-omap2/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ void omap2_clk_disable_unused(struct clk *clk);
#define omap2_clk_disable_unused NULL
#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_clksel_parent(struct clk *clk);
u32 omap2_clksel_get_divisor(struct clk *clk);
u32 omap2_clksel_round_rate_div(struct clk *clk, unsigned long target_rate,
u32 *new_div);
u32 omap2_clksel_to_divisor(struct clk *clk, u32 field_val);
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);
int omap2_clksel_set_rate(struct clk *clk, unsigned long rate);
u32 omap2_get_dpll_rate(struct clk *clk);
Expand Down
20 changes: 10 additions & 10 deletions arch/arm/mach-omap2/clock24xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
*/
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;
}

/*
Expand Down Expand Up @@ -647,14 +647,14 @@ static u32 omap2_get_sysclkdiv(void)
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();
}

/*
Expand Down Expand Up @@ -707,9 +707,9 @@ int __init omap2_clk_init(void)

clk_init(&omap2_clk_functions);

omap2_osc_clk_recalc(&osc_ck);
osc_ck.rate = omap2_osc_clk_recalc(&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);

for (c = omap24xx_clks; c < omap24xx_clks + ARRAY_SIZE(omap24xx_clks); c++)
Expand Down
10 changes: 5 additions & 5 deletions arch/arm/mach-omap2/clock24xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
#include "cm-regbits-24xx.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 long omap2_round_to_table_rate(struct clk *clk, unsigned long rate);
static void omap2_sys_clk_recalc(struct clk *clk);
static void omap2_osc_clk_recalc(struct clk *clk);
static void omap2_sys_clk_recalc(struct clk *clk);
static void omap2_dpllcore_recalc(struct clk *clk);
static unsigned long omap2_sys_clk_recalc(struct clk *clk);
static unsigned long omap2_osc_clk_recalc(struct clk *clk);
static unsigned long omap2_sys_clk_recalc(struct clk *clk);
static unsigned long omap2_dpllcore_recalc(struct clk *clk);
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.
Expand Down
12 changes: 7 additions & 5 deletions arch/arm/mach-omap2/clock34xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ static struct omap_clk omap34xx_clks[] = {
*
* 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 */
Expand Down Expand Up @@ -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
* 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;
unsigned long rate;
u32 v;
struct clk *pclk;

Expand All @@ -808,9 +809,10 @@ static void omap3_clkoutx2_recalc(struct clk *clk)
v = __raw_readl(dd->control_reg) & dd->enable_mask;
v >>= __ffs(dd->enable_mask);
if (v != DPLL_LOCKED)
clk->rate = clk->parent->rate;
rate = clk->parent->rate;
else
clk->rate = clk->parent->rate * 2;
rate = clk->parent->rate * 2;
return rate;
}

/* Common clock code */
Expand Down
4 changes: 2 additions & 2 deletions arch/arm/mach-omap2/clock34xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include "prm.h"
#include "prm-regbits-34xx.h"

static void omap3_dpll_recalc(struct clk *clk);
static void omap3_clkoutx2_recalc(struct clk *clk);
static unsigned long omap3_dpll_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_deny_idle(struct clk *clk);
static u32 omap3_dpll_autoidle_read(struct clk *clk);
Expand Down
15 changes: 6 additions & 9 deletions arch/arm/plat-omap/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ int clk_set_rate(struct clk *clk, unsigned long rate)
ret = arch_clock->clk_set_rate(clk, rate);
if (ret == 0) {
if (clk->recalc)
clk->recalc(clk);
clk->rate = clk->recalc(clk);
propagate_rate(clk);
}
spin_unlock_irqrestore(&clockfw_lock, flags);
Expand All @@ -148,7 +148,7 @@ int clk_set_parent(struct clk *clk, struct clk *parent)
ret = arch_clock->clk_set_parent(clk, parent);
if (ret == 0) {
if (clk->recalc)
clk->recalc(clk);
clk->rate = clk->recalc(clk);
propagate_rate(clk);
}
spin_unlock_irqrestore(&clockfw_lock, flags);
Expand Down Expand Up @@ -188,12 +188,9 @@ static int __init omap_clk_setup(char *str)
__setup("mpurate=", omap_clk_setup);

/* 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->rate = clk->parent->rate;
return clk->parent->rate;
}

void clk_reparent(struct clk *child, struct clk *parent)
Expand All @@ -214,7 +211,7 @@ void propagate_rate(struct clk * tclk)

list_for_each_entry(clkp, &tclk->children, sibling) {
if (clkp->recalc)
clkp->recalc(clkp);
clkp->rate = clkp->recalc(clkp);
propagate_rate(clkp);
}
}
Expand All @@ -234,7 +231,7 @@ void recalculate_root_clocks(void)

list_for_each_entry(clkp, &root_clks, sibling) {
if (clkp->recalc)
clkp->recalc(clkp);
clkp->rate = clkp->recalc(clkp);
propagate_rate(clkp);
}
}
Expand Down
4 changes: 2 additions & 2 deletions arch/arm/plat-omap/include/mach/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct clk {
unsigned long rate;
__u32 flags;
void __iomem *enable_reg;
void (*recalc)(struct clk *);
unsigned long (*recalc)(struct clk *);
int (*set_rate)(struct clk *, unsigned long);
long (*round_rate)(struct clk *, unsigned long);
void (*init)(struct clk *);
Expand Down Expand Up @@ -123,7 +123,7 @@ extern void clk_reparent(struct clk *child, struct clk *parent);
extern void clk_unregister(struct clk *clk);
extern void propagate_rate(struct clk *clk);
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);
#ifdef CONFIG_CPU_FREQ
extern void clk_init_cpufreq_table(struct cpufreq_frequency_table **table);
Expand Down

0 comments on commit 8b9dbc1

Please sign in to comment.