2010-01-27 03:13:06 +00:00
|
|
|
/*
|
|
|
|
* OMAP2xxx DVFS virtual clock functions
|
|
|
|
*
|
2012-10-30 02:56:00 +00:00
|
|
|
* Copyright (C) 2005-2008, 2012 Texas Instruments, Inc.
|
2010-01-27 03:13:06 +00:00
|
|
|
* Copyright (C) 2004-2010 Nokia Corporation
|
|
|
|
*
|
|
|
|
* Contacts:
|
|
|
|
* Richard Woodruff <r-woodruff2@ti.com>
|
|
|
|
* Paul Walmsley
|
|
|
|
*
|
|
|
|
* Based on earlier work by Tuukka Tikkanen, Tony Lindgren,
|
|
|
|
* Gordon McNutt and RidgeRun, Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* XXX Some of this code should be replaceable by the upcoming OPP layer
|
|
|
|
* code. However, some notion of "rate set" is probably still necessary
|
|
|
|
* for OMAP2xxx at least. Rate sets should be generalized so they can be
|
|
|
|
* used for any OMAP chip, not just OMAP2xxx. In particular, Richard Woodruff
|
|
|
|
* has in the past expressed a preference to use rate sets for OPP changes,
|
|
|
|
* rather than dynamically recalculating the clock tree, so if someone wants
|
|
|
|
* this badly enough to write the code to handle it, we should support it
|
|
|
|
* as an option.
|
|
|
|
*/
|
|
|
|
#undef DEBUG
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/cpufreq.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2010-01-27 03:13:06 +00:00
|
|
|
|
2012-08-31 17:59:07 +00:00
|
|
|
#include "soc.h"
|
2010-01-27 03:13:06 +00:00
|
|
|
#include "clock.h"
|
|
|
|
#include "clock2xxx.h"
|
|
|
|
#include "opp2xxx.h"
|
2012-10-30 02:57:39 +00:00
|
|
|
#include "cm2xxx.h"
|
2010-01-27 03:13:06 +00:00
|
|
|
#include "cm-regbits-24xx.h"
|
2012-10-17 00:46:45 +00:00
|
|
|
#include "sdrc.h"
|
2012-10-29 20:54:06 +00:00
|
|
|
#include "sram.h"
|
2010-01-27 03:13:06 +00:00
|
|
|
|
|
|
|
const struct prcm_config *curr_prcm_set;
|
|
|
|
const struct prcm_config *rate_table;
|
|
|
|
|
2012-10-30 02:56:00 +00:00
|
|
|
/*
|
|
|
|
* sys_ck_rate: the rate of the external high-frequency clock
|
|
|
|
* oscillator on the board. Set by the SoC-specific clock init code.
|
|
|
|
* Once set during a boot, will not change.
|
|
|
|
*/
|
|
|
|
static unsigned long sys_ck_rate;
|
|
|
|
|
2010-01-27 03:13:06 +00: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.
|
|
|
|
*/
|
2012-04-27 10:29:32 +00:00
|
|
|
unsigned long omap2_table_mpu_recalc(struct clk_hw *clk,
|
|
|
|
unsigned long parent_rate)
|
2010-01-27 03:13:06 +00:00
|
|
|
{
|
|
|
|
return curr_prcm_set->mpu_speed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-04-27 10:29:32 +00:00
|
|
|
long omap2_round_to_table_rate(struct clk_hw *hw, unsigned long rate,
|
|
|
|
unsigned long *parent_rate)
|
2010-01-27 03:13:06 +00:00
|
|
|
{
|
|
|
|
const struct prcm_config *ptr;
|
2012-10-30 02:56:00 +00:00
|
|
|
long highest_rate;
|
2010-01-27 03:13:06 +00:00
|
|
|
|
|
|
|
highest_rate = -EINVAL;
|
|
|
|
|
|
|
|
for (ptr = rate_table; ptr->mpu_speed; ptr++) {
|
|
|
|
if (!(ptr->flags & cpu_mask))
|
|
|
|
continue;
|
2012-10-30 02:56:00 +00:00
|
|
|
if (ptr->xtal_speed != sys_ck_rate)
|
2010-01-27 03:13:06 +00: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 */
|
2012-04-27 10:29:32 +00:00
|
|
|
int omap2_select_table_rate(struct clk_hw *hw, unsigned long rate,
|
|
|
|
unsigned long parent_rate)
|
2010-01-27 03:13:06 +00:00
|
|
|
{
|
|
|
|
u32 cur_rate, done_rate, bypass = 0, tmp;
|
|
|
|
const struct prcm_config *prcm;
|
|
|
|
unsigned long found_speed = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
for (prcm = rate_table; prcm->mpu_speed; prcm++) {
|
|
|
|
if (!(prcm->flags & cpu_mask))
|
|
|
|
continue;
|
|
|
|
|
2012-10-30 02:56:00 +00:00
|
|
|
if (prcm->xtal_speed != sys_ck_rate)
|
2010-01-27 03:13:06 +00: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",
|
|
|
|
rate / 1000000);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
curr_prcm_set = prcm;
|
2012-10-30 02:55:53 +00:00
|
|
|
cur_rate = omap2xxx_clk_get_core_rate();
|
2010-01-27 03:13:06 +00:00
|
|
|
|
|
|
|
if (prcm->dpll_speed == cur_rate / 2) {
|
|
|
|
omap2xxx_sdrc_reprogram(CORE_CLK_SRC_DPLL, 1);
|
|
|
|
} else if (prcm->dpll_speed == cur_rate * 2) {
|
|
|
|
omap2xxx_sdrc_reprogram(CORE_CLK_SRC_DPLL_X2, 1);
|
|
|
|
} else if (prcm->dpll_speed != cur_rate) {
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
|
|
|
if (prcm->dpll_speed == prcm->xtal_speed)
|
|
|
|
bypass = 1;
|
|
|
|
|
|
|
|
if ((prcm->cm_clksel2_pll & OMAP24XX_CORE_CLK_SRC_MASK) ==
|
|
|
|
CORE_CLK_SRC_DPLL_X2)
|
|
|
|
done_rate = CORE_CLK_SRC_DPLL_X2;
|
|
|
|
else
|
|
|
|
done_rate = CORE_CLK_SRC_DPLL;
|
|
|
|
|
|
|
|
/* MPU divider */
|
2010-12-22 04:05:14 +00:00
|
|
|
omap2_cm_write_mod_reg(prcm->cm_clksel_mpu, MPU_MOD, CM_CLKSEL);
|
2010-01-27 03:13:06 +00:00
|
|
|
|
|
|
|
/* dsp + iva1 div(2420), iva2.1(2430) */
|
2010-12-22 04:05:14 +00:00
|
|
|
omap2_cm_write_mod_reg(prcm->cm_clksel_dsp,
|
2010-01-27 03:13:06 +00:00
|
|
|
OMAP24XX_DSP_MOD, CM_CLKSEL);
|
|
|
|
|
2010-12-22 04:05:14 +00:00
|
|
|
omap2_cm_write_mod_reg(prcm->cm_clksel_gfx, GFX_MOD, CM_CLKSEL);
|
2010-01-27 03:13:06 +00:00
|
|
|
|
|
|
|
/* Major subsystem dividers */
|
2010-12-22 04:05:14 +00:00
|
|
|
tmp = omap2_cm_read_mod_reg(CORE_MOD, CM_CLKSEL1) & OMAP24XX_CLKSEL_DSS2_MASK;
|
|
|
|
omap2_cm_write_mod_reg(prcm->cm_clksel1_core | tmp, CORE_MOD,
|
2010-01-27 03:13:06 +00:00
|
|
|
CM_CLKSEL1);
|
|
|
|
|
|
|
|
if (cpu_is_omap2430())
|
2010-12-22 04:05:14 +00:00
|
|
|
omap2_cm_write_mod_reg(prcm->cm_clksel_mdm,
|
2010-01-27 03:13:06 +00:00
|
|
|
OMAP2430_MDM_MOD, CM_CLKSEL);
|
|
|
|
|
|
|
|
/* x2 to enter omap2xxx_sdrc_init_params() */
|
|
|
|
omap2xxx_sdrc_reprogram(CORE_CLK_SRC_DPLL_X2, 1);
|
|
|
|
|
|
|
|
omap2_set_prcm(prcm->cm_clksel1_pll, prcm->base_sdrc_rfr,
|
|
|
|
bypass);
|
|
|
|
|
|
|
|
omap2xxx_sdrc_init_params(omap2xxx_sdrc_dll_is_unlocked());
|
|
|
|
omap2xxx_sdrc_reprogram(done_rate, 0);
|
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2012-10-30 02:56:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* omap2xxx_clkt_vps_check_bootloader_rate - determine which of the rate
|
|
|
|
* table sets matches the current CORE DPLL hardware rate
|
|
|
|
*
|
|
|
|
* Check the MPU rate set by bootloader. Sets the 'curr_prcm_set'
|
|
|
|
* global to point to the active rate set when found; otherwise, sets
|
|
|
|
* it to NULL. No return value;
|
|
|
|
*/
|
|
|
|
void omap2xxx_clkt_vps_check_bootloader_rates(void)
|
|
|
|
{
|
|
|
|
const struct prcm_config *prcm = NULL;
|
|
|
|
unsigned long rate;
|
|
|
|
|
|
|
|
rate = omap2xxx_clk_get_core_rate();
|
|
|
|
for (prcm = rate_table; prcm->mpu_speed; prcm++) {
|
|
|
|
if (!(prcm->flags & cpu_mask))
|
|
|
|
continue;
|
|
|
|
if (prcm->xtal_speed != sys_ck_rate)
|
|
|
|
continue;
|
|
|
|
if (prcm->dpll_speed <= rate)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
curr_prcm_set = prcm;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap2xxx_clkt_vps_late_init - store a copy of the sys_ck rate
|
|
|
|
*
|
|
|
|
* Store a copy of the sys_ck rate for later use by the OMAP2xxx DVFS
|
|
|
|
* code. (The sys_ck rate does not -- or rather, must not -- change
|
|
|
|
* during kernel runtime.) Must be called after we have a valid
|
|
|
|
* sys_ck rate, but before the virt_prcm_set clock rate is
|
|
|
|
* recalculated. No return value.
|
|
|
|
*/
|
|
|
|
void omap2xxx_clkt_vps_late_init(void)
|
|
|
|
{
|
|
|
|
struct clk *c;
|
|
|
|
|
|
|
|
c = clk_get(NULL, "sys_ck");
|
|
|
|
if (IS_ERR(c)) {
|
|
|
|
WARN(1, "could not locate sys_ck\n");
|
|
|
|
} else {
|
|
|
|
sys_ck_rate = clk_get_rate(c);
|
|
|
|
clk_put(c);
|
|
|
|
}
|
|
|
|
}
|