Source
/*
* drivers/cpufreq/spear-cpufreq.c
*
* CPU Frequency Scaling for SPEAr platform
*
* Copyright (C) 2012 ST Microelectronics
* Deepak Sikri <deepak.sikri@st.com>
*
* This file is licensed under the terms of the GNU General Public
* License version 2. This program is licensed "as is" without any
* warranty of any kind, whether express or implied.
*/
/* SPEAr CPUFreq driver data structure */
static struct {
struct clk *clk;
unsigned int transition_latency;
struct cpufreq_frequency_table *freq_tbl;
u32 cnt;
} spear_cpufreq;
static struct clk *spear1340_cpu_get_possible_parent(unsigned long newfreq)
{
struct clk *sys_pclk;
int pclk;
/*
* In SPEAr1340, cpu clk's parent sys clk can take input from
* following sources
*/
const char *sys_clk_src[] = {
"sys_syn_clk",
"pll1_clk",
"pll2_clk",
"pll3_clk",
};
/*
* As sys clk can have multiple source with their own range
* limitation so we choose possible sources accordingly
*/
if (newfreq <= 300000000)
pclk = 0; /* src is sys_syn_clk */
else if (newfreq > 300000000 && newfreq <= 500000000)
pclk = 3; /* src is pll3_clk */
else if (newfreq == 600000000)
pclk = 1; /* src is pll1_clk */
else
return ERR_PTR(-EINVAL);
/* Get parent to sys clock */
sys_pclk = clk_get(NULL, sys_clk_src[pclk]);
if (IS_ERR(sys_pclk))
pr_err("Failed to get %s clock\n", sys_clk_src[pclk]);
return sys_pclk;
}
/*
* In SPEAr1340, we cannot use newfreq directly because we need to actually
* access a source clock (clk) which might not be ancestor of cpu at present.
* Hence in SPEAr1340 we would operate on source clock directly before switching
* cpu clock to it.
*/
static int spear1340_set_cpu_rate(struct clk *sys_pclk, unsigned long newfreq)
{
struct clk *sys_clk;
int ret = 0;
sys_clk = clk_get_parent(spear_cpufreq.clk);
if (IS_ERR(sys_clk)) {
pr_err("failed to get cpu's parent (sys) clock\n");
return PTR_ERR(sys_clk);
}
/* Set the rate of the source clock before changing the parent */
ret = clk_set_rate(sys_pclk, newfreq);
if (ret) {
pr_err("Failed to set sys clk rate to %lu\n", newfreq);
return ret;
}