2005-11-10 22:26:52 +08:00
|
|
|
/*
|
|
|
|
* linux/arch/arm/mach-omap2/clock.c
|
|
|
|
*
|
2008-03-18 17:56:39 +08:00
|
|
|
* Copyright (C) 2005-2008 Texas Instruments, Inc.
|
|
|
|
* Copyright (C) 2004-2008 Nokia Corporation
|
2005-11-10 22:26:52 +08:00
|
|
|
*
|
2008-03-18 17:56:39 +08:00
|
|
|
* Contacts:
|
|
|
|
* Richard Woodruff <r-woodruff2@ti.com>
|
|
|
|
* Paul Walmsley
|
2005-11-10 22:26:52 +08:00
|
|
|
*
|
2008-03-18 17:56:39 +08:00
|
|
|
* Based on earlier work by Tuukka Tikkanen, Tony Lindgren,
|
|
|
|
* Gordon McNutt and RidgeRun, Inc.
|
2005-11-10 22:26:52 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
2008-03-18 16:35:15 +08:00
|
|
|
#undef DEBUG
|
|
|
|
|
2005-11-10 22:26:52 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/delay.h>
|
2006-01-08 00:15:52 +08:00
|
|
|
#include <linux/clk.h>
|
2008-03-18 16:35:15 +08:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/cpufreq.h>
|
2008-09-06 19:13:59 +08:00
|
|
|
#include <linux/bitops.h>
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2009-10-21 00:40:47 +08:00
|
|
|
#include <plat/clock.h>
|
|
|
|
#include <plat/sram.h>
|
|
|
|
#include <plat/prcm.h>
|
2009-12-09 07:18:47 +08:00
|
|
|
#include <plat/clkdev_omap.h>
|
2006-12-13 15:02:43 +08:00
|
|
|
#include <asm/div64.h>
|
2009-01-19 23:27:29 +08:00
|
|
|
#include <asm/clkdev.h>
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2009-10-21 00:40:47 +08:00
|
|
|
#include <plat/sdrc.h>
|
2008-03-18 16:35:15 +08:00
|
|
|
#include "clock.h"
|
2009-12-09 07:21:29 +08:00
|
|
|
#include "clock2xxx.h"
|
|
|
|
#include "opp2xxx.h"
|
2008-03-18 16:35:15 +08:00
|
|
|
#include "prm.h"
|
|
|
|
#include "prm-regbits-24xx.h"
|
|
|
|
#include "cm.h"
|
|
|
|
#include "cm-regbits-24xx.h"
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2009-01-19 23:27:29 +08:00
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
/* CM_CLKEN_PLL.EN_{54,96}M_PLL options (24XX) */
|
|
|
|
#define EN_APLL_STOPPED 0
|
|
|
|
#define EN_APLL_LOCKED 3
|
2006-09-25 17:41:50 +08:00
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
/* CM_CLKSEL1_PLL.APLLS_CLKIN options (24XX) */
|
|
|
|
#define APLLS_CLKIN_19_2MHZ 0
|
|
|
|
#define APLLS_CLKIN_13MHZ 2
|
|
|
|
#define APLLS_CLKIN_12MHZ 3
|
|
|
|
|
|
|
|
/* #define DOWN_VARIABLE_DPLL 1 */ /* Experimental */
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2009-12-09 07:21:29 +08:00
|
|
|
const struct prcm_config *curr_prcm_set;
|
|
|
|
const struct prcm_config *rate_table;
|
|
|
|
|
|
|
|
struct clk *vclk, *sclk, *dclk;
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2009-12-09 07:21:29 +08:00
|
|
|
void __iomem *prcm_clksrc_ctrl;
|
2009-05-26 02:26:42 +08:00
|
|
|
|
2005-11-10 22:26:52 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2008-03-18 16:35:15 +08:00
|
|
|
* Omap24xx specific clock functions
|
2005-11-10 22:26:52 +08:00
|
|
|
*-------------------------------------------------------------------------*/
|
|
|
|
|
2009-07-25 09:44:04 +08:00
|
|
|
/**
|
|
|
|
* omap2430_clk_i2chs_find_idlest - return CM_IDLEST info for 2430 I2CHS
|
|
|
|
* @clk: struct clk * being enabled
|
|
|
|
* @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
|
|
|
|
* @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
|
|
|
|
*
|
|
|
|
* OMAP2430 I2CHS CM_IDLEST bits are in CM_IDLEST1_CORE, but the
|
|
|
|
* CM_*CLKEN bits are in CM_{I,F}CLKEN2_CORE. This custom function
|
|
|
|
* passes back the correct CM_IDLEST register address for I2CHS
|
|
|
|
* modules. No return value.
|
|
|
|
*/
|
|
|
|
static void omap2430_clk_i2chs_find_idlest(struct clk *clk,
|
|
|
|
void __iomem **idlest_reg,
|
|
|
|
u8 *idlest_bit)
|
|
|
|
{
|
|
|
|
*idlest_reg = OMAP_CM_REGADDR(CORE_MOD, CM_IDLEST);
|
|
|
|
*idlest_bit = clk->enable_bit;
|
|
|
|
}
|
|
|
|
|
2009-12-09 07:21:29 +08:00
|
|
|
/* 2430 I2CHS has non-standard IDLEST register */
|
|
|
|
const struct clkops clkops_omap2430_i2chs_wait = {
|
|
|
|
.enable = omap2_dflt_clk_enable,
|
|
|
|
.disable = omap2_dflt_clk_disable,
|
|
|
|
.find_idlest = omap2430_clk_i2chs_find_idlest,
|
|
|
|
.find_companion = omap2_clk_dflt_find_companion,
|
|
|
|
};
|
2009-07-25 09:44:04 +08:00
|
|
|
|
[ARM] omap: add support for bypassing DPLLs
This roughly corresponds with OMAP commits: 7d06c48, 3241b19,
88b5d9b, 18a5500, 9c909ac, 5c6497b, 8b1f0bd, 2ac1da8.
For both OMAP2 and OMAP3, we note the reference and bypass clocks in
the DPLL data structure. Whenever we modify the DPLL rate, we first
ensure that both the reference and bypass clocks are enabled. Then,
we decide whether to use the reference and DPLL, or the bypass clock
if the desired rate is identical to the bypass rate, and program the
DPLL appropriately. Finally, we update the clock's parent, and then
disable the unused clocks.
This keeps the parents correctly balanced, and more importantly ensures
that the bypass clock is running whenever we reprogram the DPLL. This
is especially important because the procedure for reprogramming the DPLL
involves switching to the bypass clock.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2009-02-19 21:29:22 +08:00
|
|
|
/**
|
|
|
|
* omap2xxx_clk_get_core_rate - return the CORE_CLK rate
|
|
|
|
* @clk: pointer to the combined dpll_ck + core_ck (currently "dpll_ck")
|
|
|
|
*
|
|
|
|
* Returns the CORE_CLK rate. CORE_CLK can have one of three rate
|
|
|
|
* sources on OMAP2xxx: the DPLL CLKOUT rate, DPLL CLKOUTX2, or 32KHz
|
|
|
|
* (the latter is unusual). This currently should be called with
|
|
|
|
* struct clk *dpll_ck, which is a composite clock of dpll_ck and
|
|
|
|
* core_ck.
|
|
|
|
*/
|
2009-12-09 07:21:29 +08:00
|
|
|
unsigned long omap2xxx_clk_get_core_rate(struct clk *clk)
|
2008-03-18 17:56:39 +08:00
|
|
|
{
|
[ARM] omap: add support for bypassing DPLLs
This roughly corresponds with OMAP commits: 7d06c48, 3241b19,
88b5d9b, 18a5500, 9c909ac, 5c6497b, 8b1f0bd, 2ac1da8.
For both OMAP2 and OMAP3, we note the reference and bypass clocks in
the DPLL data structure. Whenever we modify the DPLL rate, we first
ensure that both the reference and bypass clocks are enabled. Then,
we decide whether to use the reference and DPLL, or the bypass clock
if the desired rate is identical to the bypass rate, and program the
DPLL appropriately. Finally, we update the clock's parent, and then
disable the unused clocks.
This keeps the parents correctly balanced, and more importantly ensures
that the bypass clock is running whenever we reprogram the DPLL. This
is especially important because the procedure for reprogramming the DPLL
involves switching to the bypass clock.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2009-02-19 21:29:22 +08:00
|
|
|
long long core_clk;
|
|
|
|
u32 v;
|
2008-03-18 17:56:39 +08:00
|
|
|
|
[ARM] omap: add support for bypassing DPLLs
This roughly corresponds with OMAP commits: 7d06c48, 3241b19,
88b5d9b, 18a5500, 9c909ac, 5c6497b, 8b1f0bd, 2ac1da8.
For both OMAP2 and OMAP3, we note the reference and bypass clocks in
the DPLL data structure. Whenever we modify the DPLL rate, we first
ensure that both the reference and bypass clocks are enabled. Then,
we decide whether to use the reference and DPLL, or the bypass clock
if the desired rate is identical to the bypass rate, and program the
DPLL appropriately. Finally, we update the clock's parent, and then
disable the unused clocks.
This keeps the parents correctly balanced, and more importantly ensures
that the bypass clock is running whenever we reprogram the DPLL. This
is especially important because the procedure for reprogramming the DPLL
involves switching to the bypass clock.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2009-02-19 21:29:22 +08:00
|
|
|
core_clk = omap2_get_dpll_rate(clk);
|
2008-03-18 17:56:39 +08:00
|
|
|
|
[ARM] omap: add support for bypassing DPLLs
This roughly corresponds with OMAP commits: 7d06c48, 3241b19,
88b5d9b, 18a5500, 9c909ac, 5c6497b, 8b1f0bd, 2ac1da8.
For both OMAP2 and OMAP3, we note the reference and bypass clocks in
the DPLL data structure. Whenever we modify the DPLL rate, we first
ensure that both the reference and bypass clocks are enabled. Then,
we decide whether to use the reference and DPLL, or the bypass clock
if the desired rate is identical to the bypass rate, and program the
DPLL appropriately. Finally, we update the clock's parent, and then
disable the unused clocks.
This keeps the parents correctly balanced, and more importantly ensures
that the bypass clock is running whenever we reprogram the DPLL. This
is especially important because the procedure for reprogramming the DPLL
involves switching to the bypass clock.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2009-02-19 21:29:22 +08:00
|
|
|
v = cm_read_mod_reg(PLL_MOD, CM_CLKSEL2);
|
|
|
|
v &= OMAP24XX_CORE_CLK_SRC_MASK;
|
|
|
|
|
|
|
|
if (v == CORE_CLK_SRC_32K)
|
|
|
|
core_clk = 32768;
|
|
|
|
else
|
|
|
|
core_clk *= v;
|
2008-03-18 17:56:39 +08:00
|
|
|
|
[ARM] omap: add support for bypassing DPLLs
This roughly corresponds with OMAP commits: 7d06c48, 3241b19,
88b5d9b, 18a5500, 9c909ac, 5c6497b, 8b1f0bd, 2ac1da8.
For both OMAP2 and OMAP3, we note the reference and bypass clocks in
the DPLL data structure. Whenever we modify the DPLL rate, we first
ensure that both the reference and bypass clocks are enabled. Then,
we decide whether to use the reference and DPLL, or the bypass clock
if the desired rate is identical to the bypass rate, and program the
DPLL appropriately. Finally, we update the clock's parent, and then
disable the unused clocks.
This keeps the parents correctly balanced, and more importantly ensures
that the bypass clock is running whenever we reprogram the DPLL. This
is especially important because the procedure for reprogramming the DPLL
involves switching to the bypass clock.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2009-02-19 21:29:22 +08:00
|
|
|
return core_clk;
|
2008-03-18 17:56:39 +08:00
|
|
|
}
|
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
static int omap2_enable_osc_ck(struct clk *clk)
|
|
|
|
{
|
|
|
|
u32 pcc;
|
|
|
|
|
2009-05-26 02:26:42 +08:00
|
|
|
pcc = __raw_readl(prcm_clksrc_ctrl);
|
2008-03-18 16:35:15 +08:00
|
|
|
|
2009-05-26 02:26:42 +08:00
|
|
|
__raw_writel(pcc & ~OMAP_AUTOEXTCLKMODE_MASK, prcm_clksrc_ctrl);
|
2008-03-18 16:35:15 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void omap2_disable_osc_ck(struct clk *clk)
|
|
|
|
{
|
|
|
|
u32 pcc;
|
|
|
|
|
2009-05-26 02:26:42 +08:00
|
|
|
pcc = __raw_readl(prcm_clksrc_ctrl);
|
2008-03-18 16:35:15 +08:00
|
|
|
|
2009-05-26 02:26:42 +08:00
|
|
|
__raw_writel(pcc | OMAP_AUTOEXTCLKMODE_MASK, prcm_clksrc_ctrl);
|
2008-03-18 16:35:15 +08:00
|
|
|
}
|
|
|
|
|
2009-12-09 07:21:29 +08:00
|
|
|
const struct clkops clkops_oscck = {
|
|
|
|
.enable = omap2_enable_osc_ck,
|
|
|
|
.disable = omap2_disable_osc_ck,
|
2008-11-04 22:02:46 +08:00
|
|
|
};
|
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
#ifdef OLD_CK
|
2005-11-10 22:26:52 +08:00
|
|
|
/* Recalculate SYST_CLK */
|
2009-12-09 07:21:29 +08:00
|
|
|
static void omap2_sys_clk_recalc(struct clk *clk)
|
2005-11-10 22:26:52 +08:00
|
|
|
{
|
|
|
|
u32 div = PRCM_CLKSRC_CTRL;
|
|
|
|
div &= (1 << 7) | (1 << 6); /* Test if ext clk divided by 1 or 2 */
|
|
|
|
div >>= clk->rate_offset;
|
|
|
|
clk->rate = (clk->parent->rate / div);
|
|
|
|
propagate_rate(clk);
|
|
|
|
}
|
2008-03-18 16:35:15 +08:00
|
|
|
#endif /* OLD_CK */
|
2005-11-10 22:26:52 +08:00
|
|
|
|
|
|
|
/* Enable an APLL if off */
|
2009-12-09 07:18:46 +08:00
|
|
|
static int omap2_clk_apll_enable(struct clk *clk, u32 status_mask)
|
2005-11-10 22:26:52 +08:00
|
|
|
{
|
2008-03-18 16:35:15 +08:00
|
|
|
u32 cval, apll_mask;
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
apll_mask = EN_APLL_LOCKED << clk->enable_bit;
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
cval = cm_read_mod_reg(PLL_MOD, CM_CLKEN);
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
if ((cval & apll_mask) == apll_mask)
|
|
|
|
return 0; /* apll already enabled */
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
cval &= ~apll_mask;
|
|
|
|
cval |= apll_mask;
|
|
|
|
cm_write_mod_reg(cval, PLL_MOD, CM_CLKEN);
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2009-12-09 07:18:46 +08:00
|
|
|
omap2_cm_wait_idlest(OMAP_CM_REGADDR(PLL_MOD, CM_IDLEST), status_mask,
|
2009-07-25 09:44:04 +08:00
|
|
|
clk->name);
|
2008-03-18 16:35:15 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* REVISIT: Should we return an error code if omap2_wait_clock_ready()
|
|
|
|
* fails?
|
|
|
|
*/
|
|
|
|
return 0;
|
2005-11-10 22:26:52 +08:00
|
|
|
}
|
|
|
|
|
2009-12-09 07:18:46 +08:00
|
|
|
static int omap2_clk_apll96_enable(struct clk *clk)
|
|
|
|
{
|
|
|
|
return omap2_clk_apll_enable(clk, OMAP24XX_ST_96M_APLL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int omap2_clk_apll54_enable(struct clk *clk)
|
|
|
|
{
|
|
|
|
return omap2_clk_apll_enable(clk, OMAP24XX_ST_54M_APLL);
|
|
|
|
}
|
|
|
|
|
2005-11-10 22:26:52 +08:00
|
|
|
/* Stop APLL */
|
2009-12-09 07:18:46 +08:00
|
|
|
static void omap2_clk_apll_disable(struct clk *clk)
|
2005-11-10 22:26:52 +08:00
|
|
|
{
|
|
|
|
u32 cval;
|
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
cval = cm_read_mod_reg(PLL_MOD, CM_CLKEN);
|
|
|
|
cval &= ~(EN_APLL_LOCKED << clk->enable_bit);
|
|
|
|
cm_write_mod_reg(cval, PLL_MOD, CM_CLKEN);
|
2005-11-10 22:26:52 +08:00
|
|
|
}
|
|
|
|
|
2009-12-09 07:21:29 +08:00
|
|
|
const struct clkops clkops_apll96 = {
|
|
|
|
.enable = omap2_clk_apll96_enable,
|
|
|
|
.disable = omap2_clk_apll_disable,
|
2009-12-09 07:18:46 +08:00
|
|
|
};
|
|
|
|
|
2009-12-09 07:21:29 +08:00
|
|
|
const struct clkops clkops_apll54 = {
|
|
|
|
.enable = omap2_clk_apll54_enable,
|
|
|
|
.disable = omap2_clk_apll_disable,
|
2008-11-04 22:02:46 +08:00
|
|
|
};
|
|
|
|
|
2005-11-10 22:26:52 +08:00
|
|
|
/*
|
|
|
|
* Uses the current prcm set to tell if a rate is valid.
|
|
|
|
* You can go slower, but not faster within a given rate set.
|
|
|
|
*/
|
2009-12-09 07:21:29 +08:00
|
|
|
long omap2_dpllcore_round_rate(unsigned long target_rate)
|
2005-11-10 22:26:52 +08:00
|
|
|
{
|
2008-03-18 16:35:15 +08:00
|
|
|
u32 high, low, core_clk_src;
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
core_clk_src = cm_read_mod_reg(PLL_MOD, CM_CLKSEL2);
|
|
|
|
core_clk_src &= OMAP24XX_CORE_CLK_SRC_MASK;
|
|
|
|
|
|
|
|
if (core_clk_src == CORE_CLK_SRC_DPLL) { /* DPLL clockout */
|
2005-11-10 22:26:52 +08:00
|
|
|
high = curr_prcm_set->dpll_speed * 2;
|
|
|
|
low = curr_prcm_set->dpll_speed;
|
|
|
|
} else { /* DPLL clockout x 2 */
|
|
|
|
high = curr_prcm_set->dpll_speed;
|
|
|
|
low = curr_prcm_set->dpll_speed / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DOWN_VARIABLE_DPLL
|
|
|
|
if (target_rate > high)
|
|
|
|
return high;
|
|
|
|
else
|
|
|
|
return target_rate;
|
|
|
|
#else
|
|
|
|
if (target_rate > low)
|
|
|
|
return high;
|
|
|
|
else
|
|
|
|
return low;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-12-09 07:21:29 +08:00
|
|
|
unsigned long omap2_dpllcore_recalc(struct clk *clk)
|
2008-03-18 16:35:15 +08:00
|
|
|
{
|
[ARM] omap: add support for bypassing DPLLs
This roughly corresponds with OMAP commits: 7d06c48, 3241b19,
88b5d9b, 18a5500, 9c909ac, 5c6497b, 8b1f0bd, 2ac1da8.
For both OMAP2 and OMAP3, we note the reference and bypass clocks in
the DPLL data structure. Whenever we modify the DPLL rate, we first
ensure that both the reference and bypass clocks are enabled. Then,
we decide whether to use the reference and DPLL, or the bypass clock
if the desired rate is identical to the bypass rate, and program the
DPLL appropriately. Finally, we update the clock's parent, and then
disable the unused clocks.
This keeps the parents correctly balanced, and more importantly ensures
that the bypass clock is running whenever we reprogram the DPLL. This
is especially important because the procedure for reprogramming the DPLL
involves switching to the bypass clock.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2009-02-19 21:29:22 +08:00
|
|
|
return omap2xxx_clk_get_core_rate(clk);
|
2008-03-18 16:35:15 +08:00
|
|
|
}
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2009-12-09 07:21:29 +08:00
|
|
|
int omap2_reprogram_dpllcore(struct clk *clk, unsigned long rate)
|
2005-11-10 22:26:52 +08:00
|
|
|
{
|
2008-03-18 16:35:15 +08:00
|
|
|
u32 cur_rate, low, mult, div, valid_rate, done_rate;
|
2005-11-10 22:26:52 +08:00
|
|
|
u32 bypass = 0;
|
|
|
|
struct prcm_config tmpset;
|
2008-03-18 16:35:15 +08:00
|
|
|
const struct dpll_data *dd;
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2009-12-09 07:21:29 +08:00
|
|
|
cur_rate = omap2xxx_clk_get_core_rate(dclk);
|
2008-03-18 16:35:15 +08:00
|
|
|
mult = cm_read_mod_reg(PLL_MOD, CM_CLKSEL2);
|
|
|
|
mult &= OMAP24XX_CORE_CLK_SRC_MASK;
|
2005-11-10 22:26:52 +08:00
|
|
|
|
|
|
|
if ((rate == (cur_rate / 2)) && (mult == 2)) {
|
2009-01-29 03:27:37 +08:00
|
|
|
omap2xxx_sdrc_reprogram(CORE_CLK_SRC_DPLL, 1);
|
2005-11-10 22:26:52 +08:00
|
|
|
} else if ((rate == (cur_rate * 2)) && (mult == 1)) {
|
2009-01-29 03:27:37 +08:00
|
|
|
omap2xxx_sdrc_reprogram(CORE_CLK_SRC_DPLL_X2, 1);
|
2005-11-10 22:26:52 +08:00
|
|
|
} else if (rate != cur_rate) {
|
ARM: OMAP2: Clock: New OMAP2/3 DPLL rate rounding algorithm
This patch adds a new rate rounding algorithm for DPLL clocks on the
OMAP2/3 architecture.
For a desired DPLL target rate, there may be several
multiplier/divider (M, N) values which will generate a sufficiently
close rate. Lower N values result in greater power economy. However,
lower N values can cause the difference between the rounded rate and
the target rate ("rate error") to be larger than it would be with a
higher N. This can cause downstream devices to run more slowly than
they otherwise would.
This DPLL rate rounding algorithm:
- attempts to find the lowest possible N (DPLL divider) to reach the
target_rate (since, according to Richard Woodruff <r-woodruff@ti.com>,
lower N values save more power than higher N values).
- allows developers to set an upper bound on the error between the
rounded rate and the desired target rate ("rate tolerance"), so an
appropriate balance between rate fidelity and power savings can be
set. This maximum rate error tolerance is set via
omap2_set_dpll_rate_tolerance().
- never returns a rounded rate higher than the target rate.
The rate rounding algorithm caches the last rounded M, N, and rate
computation to avoid rounding the rate twice for each clk_set_rate()
call. (This patch does not yet implement set_rate for DPLLs; that
follows in a future patch.)
The algorithm trades execution speed for rate accuracy. It will find
the (M, N) set that results in the least rate error, within a
specified rate tolerance. It does this by evaluating each divider
setting - on OMAP3, this involves 128 steps. Another approach to DPLL
rate rounding would be to bail out as soon as a valid rate is found
within the rate tolerance, which would trade rate accuracy for
execution speed. Alternate implementations welcome.
This code is not yet used by the OMAP24XX DPLL clock, since it
is currently defined as a composite clock, fusing the DPLL M,N and the
M2 output divider. This patch also renames the existing OMAP24xx DPLL
programming functions to highlight that they program both the DPLL and
the DPLL's output multiplier.
Signed-off-by: Paul Walmsley <paul@pwsan.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
2008-07-03 17:24:46 +08:00
|
|
|
valid_rate = omap2_dpllcore_round_rate(rate);
|
2005-11-10 22:26:52 +08:00
|
|
|
if (valid_rate != rate)
|
2009-01-29 03:35:31 +08:00
|
|
|
return -EINVAL;
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
if (mult == 1)
|
2005-11-10 22:26:52 +08:00
|
|
|
low = curr_prcm_set->dpll_speed;
|
|
|
|
else
|
|
|
|
low = curr_prcm_set->dpll_speed / 2;
|
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
dd = clk->dpll_data;
|
|
|
|
if (!dd)
|
2009-01-29 03:35:31 +08:00
|
|
|
return -EINVAL;
|
2008-03-18 16:35:15 +08:00
|
|
|
|
|
|
|
tmpset.cm_clksel1_pll = __raw_readl(dd->mult_div1_reg);
|
|
|
|
tmpset.cm_clksel1_pll &= ~(dd->mult_mask |
|
|
|
|
dd->div1_mask);
|
2005-11-10 22:26:52 +08:00
|
|
|
div = ((curr_prcm_set->xtal_speed / 1000000) - 1);
|
2008-03-18 16:35:15 +08:00
|
|
|
tmpset.cm_clksel2_pll = cm_read_mod_reg(PLL_MOD, CM_CLKSEL2);
|
|
|
|
tmpset.cm_clksel2_pll &= ~OMAP24XX_CORE_CLK_SRC_MASK;
|
2005-11-10 22:26:52 +08:00
|
|
|
if (rate > low) {
|
2008-03-18 16:35:15 +08:00
|
|
|
tmpset.cm_clksel2_pll |= CORE_CLK_SRC_DPLL_X2;
|
2005-11-10 22:26:52 +08:00
|
|
|
mult = ((rate / 2) / 1000000);
|
2008-03-18 16:35:15 +08:00
|
|
|
done_rate = CORE_CLK_SRC_DPLL_X2;
|
2005-11-10 22:26:52 +08:00
|
|
|
} else {
|
2008-03-18 16:35:15 +08:00
|
|
|
tmpset.cm_clksel2_pll |= CORE_CLK_SRC_DPLL;
|
2005-11-10 22:26:52 +08:00
|
|
|
mult = (rate / 1000000);
|
2008-03-18 16:35:15 +08:00
|
|
|
done_rate = CORE_CLK_SRC_DPLL;
|
2005-11-10 22:26:52 +08:00
|
|
|
}
|
2008-03-18 16:35:15 +08:00
|
|
|
tmpset.cm_clksel1_pll |= (div << __ffs(dd->mult_mask));
|
|
|
|
tmpset.cm_clksel1_pll |= (mult << __ffs(dd->div1_mask));
|
2005-11-10 22:26:52 +08:00
|
|
|
|
|
|
|
/* Worst case */
|
2008-03-18 16:35:15 +08:00
|
|
|
tmpset.base_sdrc_rfr = SDRC_RFR_CTRL_BYPASS;
|
2005-11-10 22:26:52 +08:00
|
|
|
|
|
|
|
if (rate == curr_prcm_set->xtal_speed) /* If asking for 1-1 */
|
|
|
|
bypass = 1;
|
|
|
|
|
2009-01-29 03:27:37 +08:00
|
|
|
/* For omap2xxx_sdrc_init_params() */
|
|
|
|
omap2xxx_sdrc_reprogram(CORE_CLK_SRC_DPLL_X2, 1);
|
2005-11-10 22:26:52 +08:00
|
|
|
|
|
|
|
/* Force dll lock mode */
|
|
|
|
omap2_set_prcm(tmpset.cm_clksel1_pll, tmpset.base_sdrc_rfr,
|
|
|
|
bypass);
|
|
|
|
|
|
|
|
/* Errata: ret dll entry state */
|
2009-01-29 03:27:37 +08:00
|
|
|
omap2xxx_sdrc_init_params(omap2xxx_sdrc_dll_is_unlocked());
|
|
|
|
omap2xxx_sdrc_reprogram(done_rate, 0);
|
2005-11-10 22:26:52 +08:00
|
|
|
}
|
|
|
|
|
2009-01-29 03:35:31 +08:00
|
|
|
return 0;
|
2005-11-10 22:26:52 +08:00
|
|
|
}
|
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
/**
|
|
|
|
* omap2_table_mpu_recalc - just return the MPU speed
|
|
|
|
* @clk: virt_prcm_set struct clk
|
|
|
|
*
|
|
|
|
* Set virt_prcm_set's rate to the mpu_speed field of the current PRCM set.
|
|
|
|
*/
|
2009-12-09 07:21:29 +08:00
|
|
|
unsigned long omap2_table_mpu_recalc(struct clk *clk)
|
2005-11-10 22:26:52 +08:00
|
|
|
{
|
2009-02-12 18:12:59 +08:00
|
|
|
return curr_prcm_set->mpu_speed;
|
2005-11-10 22:26:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look for a rate equal or less than the target rate given a configuration set.
|
|
|
|
*
|
|
|
|
* What's not entirely clear is "which" field represents the key field.
|
|
|
|
* Some might argue L3-DDR, others ARM, others IVA. This code is simple and
|
|
|
|
* just uses the ARM rates.
|
|
|
|
*/
|
2009-12-09 07:21:29 +08:00
|
|
|
long omap2_round_to_table_rate(struct clk *clk, unsigned long rate)
|
2005-11-10 22:26:52 +08:00
|
|
|
{
|
2009-12-09 07:21:29 +08:00
|
|
|
const struct prcm_config *ptr;
|
2005-11-10 22:26:52 +08:00
|
|
|
long highest_rate;
|
2009-12-09 07:21:29 +08:00
|
|
|
long sys_ck_rate;
|
|
|
|
|
|
|
|
sys_ck_rate = clk_get_rate(sclk);
|
2005-11-10 22:26:52 +08:00
|
|
|
|
|
|
|
highest_rate = -EINVAL;
|
|
|
|
|
|
|
|
for (ptr = rate_table; ptr->mpu_speed; ptr++) {
|
2008-03-18 16:35:15 +08:00
|
|
|
if (!(ptr->flags & cpu_mask))
|
|
|
|
continue;
|
2009-12-09 07:21:29 +08:00
|
|
|
if (ptr->xtal_speed != sys_ck_rate)
|
2005-11-10 22:26:52 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
highest_rate = ptr->mpu_speed;
|
|
|
|
|
|
|
|
/* Can check only after xtal frequency check */
|
|
|
|
if (ptr->mpu_speed <= rate)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return highest_rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets basic clocks based on the specified rate */
|
2009-12-09 07:21:29 +08:00
|
|
|
int omap2_select_table_rate(struct clk *clk, unsigned long rate)
|
2005-11-10 22:26:52 +08:00
|
|
|
{
|
2008-03-18 16:35:15 +08:00
|
|
|
u32 cur_rate, done_rate, bypass = 0, tmp;
|
2009-12-09 07:21:29 +08:00
|
|
|
const struct prcm_config *prcm;
|
2005-11-10 22:26:52 +08:00
|
|
|
unsigned long found_speed = 0;
|
2008-03-18 16:35:15 +08:00
|
|
|
unsigned long flags;
|
2009-12-09 07:21:29 +08:00
|
|
|
long sys_ck_rate;
|
|
|
|
|
|
|
|
sys_ck_rate = clk_get_rate(sclk);
|
2005-11-10 22:26:52 +08:00
|
|
|
|
|
|
|
for (prcm = rate_table; prcm->mpu_speed; prcm++) {
|
|
|
|
if (!(prcm->flags & cpu_mask))
|
|
|
|
continue;
|
|
|
|
|
2009-12-09 07:21:29 +08:00
|
|
|
if (prcm->xtal_speed != sys_ck_rate)
|
2005-11-10 22:26:52 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (prcm->mpu_speed <= rate) {
|
|
|
|
found_speed = prcm->mpu_speed;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found_speed) {
|
|
|
|
printk(KERN_INFO "Could not set MPU rate to %luMHz\n",
|
2008-03-18 17:56:39 +08:00
|
|
|
rate / 1000000);
|
2005-11-10 22:26:52 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
curr_prcm_set = prcm;
|
2009-12-09 07:21:29 +08:00
|
|
|
cur_rate = omap2xxx_clk_get_core_rate(dclk);
|
2005-11-10 22:26:52 +08:00
|
|
|
|
|
|
|
if (prcm->dpll_speed == cur_rate / 2) {
|
2009-01-29 03:27:37 +08:00
|
|
|
omap2xxx_sdrc_reprogram(CORE_CLK_SRC_DPLL, 1);
|
2005-11-10 22:26:52 +08:00
|
|
|
} else if (prcm->dpll_speed == cur_rate * 2) {
|
2009-01-29 03:27:37 +08:00
|
|
|
omap2xxx_sdrc_reprogram(CORE_CLK_SRC_DPLL_X2, 1);
|
2005-11-10 22:26:52 +08:00
|
|
|
} else if (prcm->dpll_speed != cur_rate) {
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
|
|
|
if (prcm->dpll_speed == prcm->xtal_speed)
|
|
|
|
bypass = 1;
|
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
if ((prcm->cm_clksel2_pll & OMAP24XX_CORE_CLK_SRC_MASK) ==
|
|
|
|
CORE_CLK_SRC_DPLL_X2)
|
|
|
|
done_rate = CORE_CLK_SRC_DPLL_X2;
|
2005-11-10 22:26:52 +08:00
|
|
|
else
|
2008-03-18 16:35:15 +08:00
|
|
|
done_rate = CORE_CLK_SRC_DPLL;
|
2005-11-10 22:26:52 +08:00
|
|
|
|
|
|
|
/* MPU divider */
|
2008-03-18 16:35:15 +08:00
|
|
|
cm_write_mod_reg(prcm->cm_clksel_mpu, MPU_MOD, CM_CLKSEL);
|
2005-11-10 22:26:52 +08:00
|
|
|
|
|
|
|
/* dsp + iva1 div(2420), iva2.1(2430) */
|
2008-03-18 16:35:15 +08:00
|
|
|
cm_write_mod_reg(prcm->cm_clksel_dsp,
|
|
|
|
OMAP24XX_DSP_MOD, CM_CLKSEL);
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
cm_write_mod_reg(prcm->cm_clksel_gfx, GFX_MOD, CM_CLKSEL);
|
2005-11-10 22:26:52 +08:00
|
|
|
|
|
|
|
/* Major subsystem dividers */
|
2008-03-18 16:35:15 +08:00
|
|
|
tmp = cm_read_mod_reg(CORE_MOD, CM_CLKSEL1) & OMAP24XX_CLKSEL_DSS2_MASK;
|
2009-01-28 10:12:50 +08:00
|
|
|
cm_write_mod_reg(prcm->cm_clksel1_core | tmp, CORE_MOD,
|
|
|
|
CM_CLKSEL1);
|
|
|
|
|
2005-11-10 22:26:52 +08:00
|
|
|
if (cpu_is_omap2430())
|
2008-03-18 16:35:15 +08:00
|
|
|
cm_write_mod_reg(prcm->cm_clksel_mdm,
|
|
|
|
OMAP2430_MDM_MOD, CM_CLKSEL);
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2009-01-29 03:27:37 +08:00
|
|
|
/* x2 to enter omap2xxx_sdrc_init_params() */
|
|
|
|
omap2xxx_sdrc_reprogram(CORE_CLK_SRC_DPLL_X2, 1);
|
2005-11-10 22:26:52 +08:00
|
|
|
|
|
|
|
omap2_set_prcm(prcm->cm_clksel1_pll, prcm->base_sdrc_rfr,
|
|
|
|
bypass);
|
|
|
|
|
2009-01-29 03:27:37 +08:00
|
|
|
omap2xxx_sdrc_init_params(omap2xxx_sdrc_dll_is_unlocked());
|
|
|
|
omap2xxx_sdrc_reprogram(done_rate, 0);
|
2005-11-10 22:26:52 +08:00
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-28 10:13:38 +08:00
|
|
|
#ifdef CONFIG_CPU_FREQ
|
|
|
|
/*
|
|
|
|
* Walk PRCM rate table and fillout cpufreq freq_table
|
|
|
|
*/
|
|
|
|
static struct cpufreq_frequency_table freq_table[ARRAY_SIZE(rate_table)];
|
|
|
|
|
|
|
|
void omap2_clk_init_cpufreq_table(struct cpufreq_frequency_table **table)
|
|
|
|
{
|
|
|
|
struct prcm_config *prcm;
|
2010-01-09 06:23:15 +08:00
|
|
|
long sys_ck_rate;
|
2009-01-28 10:13:38 +08:00
|
|
|
int i = 0;
|
|
|
|
|
2010-01-09 06:23:15 +08:00
|
|
|
sys_ck_rate = clk_get_rate(sclk);
|
|
|
|
|
2009-01-28 10:13:38 +08:00
|
|
|
for (prcm = rate_table; prcm->mpu_speed; prcm++) {
|
|
|
|
if (!(prcm->flags & cpu_mask))
|
|
|
|
continue;
|
2010-01-09 06:23:15 +08:00
|
|
|
if (prcm->xtal_speed != sys_ck_rate)
|
2009-01-28 10:13:38 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* don't put bypass rates in table */
|
|
|
|
if (prcm->dpll_speed == prcm->xtal_speed)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
freq_table[i].index = i;
|
|
|
|
freq_table[i].frequency = prcm->mpu_speed / 1000;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
printk(KERN_WARNING "%s: failed to initialize frequency "
|
|
|
|
"table\n", __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
freq_table[i].index = i;
|
|
|
|
freq_table[i].frequency = CPUFREQ_TABLE_END;
|
|
|
|
|
|
|
|
*table = &freq_table[0];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-12-09 07:18:47 +08:00
|
|
|
struct clk_functions omap2_clk_functions = {
|
2005-11-10 22:26:52 +08:00
|
|
|
.clk_enable = omap2_clk_enable,
|
|
|
|
.clk_disable = omap2_clk_disable,
|
|
|
|
.clk_round_rate = omap2_clk_round_rate,
|
|
|
|
.clk_set_rate = omap2_clk_set_rate,
|
|
|
|
.clk_set_parent = omap2_clk_set_parent,
|
2006-09-25 18:27:20 +08:00
|
|
|
.clk_disable_unused = omap2_clk_disable_unused,
|
2009-01-28 10:13:38 +08:00
|
|
|
#ifdef CONFIG_CPU_FREQ
|
|
|
|
.clk_init_cpufreq_table = omap2_clk_init_cpufreq_table,
|
|
|
|
#endif
|
2005-11-10 22:26:52 +08:00
|
|
|
};
|
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
static u32 omap2_get_apll_clkin(void)
|
2005-11-10 22:26:52 +08:00
|
|
|
{
|
2009-01-28 10:12:50 +08:00
|
|
|
u32 aplls, srate = 0;
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
aplls = cm_read_mod_reg(PLL_MOD, CM_CLKSEL1);
|
|
|
|
aplls &= OMAP24XX_APLLS_CLKIN_MASK;
|
|
|
|
aplls >>= OMAP24XX_APLLS_CLKIN_SHIFT;
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
if (aplls == APLLS_CLKIN_19_2MHZ)
|
2009-01-28 10:12:50 +08:00
|
|
|
srate = 19200000;
|
2008-03-18 16:35:15 +08:00
|
|
|
else if (aplls == APLLS_CLKIN_13MHZ)
|
2009-01-28 10:12:50 +08:00
|
|
|
srate = 13000000;
|
2008-03-18 16:35:15 +08:00
|
|
|
else if (aplls == APLLS_CLKIN_12MHZ)
|
2009-01-28 10:12:50 +08:00
|
|
|
srate = 12000000;
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2009-01-28 10:12:50 +08:00
|
|
|
return srate;
|
2008-03-18 16:35:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static u32 omap2_get_sysclkdiv(void)
|
|
|
|
{
|
|
|
|
u32 div;
|
|
|
|
|
2009-05-26 02:26:42 +08:00
|
|
|
div = __raw_readl(prcm_clksrc_ctrl);
|
2008-03-18 16:35:15 +08:00
|
|
|
div &= OMAP_SYSCLKDIV_MASK;
|
|
|
|
div >>= OMAP_SYSCLKDIV_SHIFT;
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
return div;
|
|
|
|
}
|
|
|
|
|
2009-12-09 07:21:29 +08:00
|
|
|
unsigned long omap2_osc_clk_recalc(struct clk *clk)
|
2008-03-18 16:35:15 +08:00
|
|
|
{
|
2009-02-12 18:12:59 +08:00
|
|
|
return omap2_get_apll_clkin() * omap2_get_sysclkdiv();
|
2008-03-18 16:35:15 +08:00
|
|
|
}
|
|
|
|
|
2009-12-09 07:21:29 +08:00
|
|
|
unsigned long omap2_sys_clk_recalc(struct clk *clk)
|
2008-03-18 16:35:15 +08:00
|
|
|
{
|
2009-02-12 18:12:59 +08:00
|
|
|
return clk->parent->rate / omap2_get_sysclkdiv();
|
2005-11-10 22:26:52 +08:00
|
|
|
}
|
|
|
|
|
2006-09-25 17:41:20 +08:00
|
|
|
/*
|
|
|
|
* Set clocks for bypass mode for reboot to work.
|
|
|
|
*/
|
|
|
|
void omap2_clk_prepare_for_reboot(void)
|
|
|
|
{
|
|
|
|
u32 rate;
|
|
|
|
|
|
|
|
if (vclk == NULL || sclk == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
rate = clk_get_rate(sclk);
|
|
|
|
clk_set_rate(vclk, rate);
|
|
|
|
}
|
|
|
|
|
2005-11-10 22:26:52 +08:00
|
|
|
/*
|
|
|
|
* Switch the MPU rate if specified on cmdline.
|
|
|
|
* We cannot do this early until cmdline is parsed.
|
|
|
|
*/
|
|
|
|
static int __init omap2_clk_arch_init(void)
|
|
|
|
{
|
2009-12-09 07:21:29 +08:00
|
|
|
struct clk *virt_prcm_set, *sys_ck, *dpll_ck, *mpu_ck;
|
|
|
|
unsigned long sys_ck_rate;
|
|
|
|
|
2005-11-10 22:26:52 +08:00
|
|
|
if (!mpurate)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2009-12-09 07:21:29 +08:00
|
|
|
virt_prcm_set = clk_get(NULL, "virt_prcm_set");
|
|
|
|
sys_ck = clk_get(NULL, "sys_ck");
|
|
|
|
dpll_ck = clk_get(NULL, "dpll_ck");
|
|
|
|
mpu_ck = clk_get(NULL, "mpu_ck");
|
|
|
|
|
|
|
|
if (clk_set_rate(virt_prcm_set, mpurate))
|
2005-11-10 22:26:52 +08:00
|
|
|
printk(KERN_ERR "Could not find matching MPU rate\n");
|
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
recalculate_root_clocks();
|
2005-11-10 22:26:52 +08:00
|
|
|
|
2009-12-09 07:21:29 +08:00
|
|
|
sys_ck_rate = clk_get_rate(sys_ck);
|
|
|
|
|
|
|
|
pr_info("Switched to new clocking rate (Crystal/DPLL/MPU): "
|
|
|
|
"%ld.%01ld/%ld/%ld MHz\n",
|
|
|
|
(sys_ck_rate / 1000000), (sys_ck_rate / 100000) % 10,
|
|
|
|
(clk_get_rate(dpll_ck) / 1000000),
|
|
|
|
(clk_get_rate(mpu_ck) / 1000000));
|
2005-11-10 22:26:52 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
arch_initcall(omap2_clk_arch_init);
|
|
|
|
|
|
|
|
|