/* * 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.
*/
staticstruct clk *spear1340_cpu_get_possible_parent(unsignedlong newfreq)
{ struct clk *sys_pclk; int pclk; /* * In SPEAr1340, cpu clk's parent sys clk can take input from * following sources
*/ staticconstchar * const 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 */ elseif (newfreq > 300000000 && newfreq <= 500000000)
pclk = 3; /* src is pll3_clk */ elseif (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.
*/ staticint spear1340_set_cpu_rate(struct clk *sys_pclk, unsignedlong 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;
}
ret = clk_set_parent(sys_clk, sys_pclk); if (ret) {
pr_err("Failed to set sys clk parent\n"); return ret;
}
return 0;
}
staticint spear_cpufreq_target(struct cpufreq_policy *policy, unsignedint index)
{ long newfreq; struct clk *srcclk; int ret, mult = 1;
if (of_machine_is_compatible("st,spear1340")) { /* * SPEAr1340 is special in the sense that due to the possibility * of multiple clock sources for cpu clk's parent we can have * different clock source for different frequency of cpu clk. * Hence we need to choose one from amongst these possible clock * sources.
*/
srcclk = spear1340_cpu_get_possible_parent(newfreq); if (IS_ERR(srcclk)) {
pr_err("Failed to get src clk\n"); return PTR_ERR(srcclk);
}
/* SPEAr1340: src clk is always 2 * intended cpu clk */
mult = 2;
} else { /* * src clock to be altered is ancestor of cpu clock. Hence we * can directly work on cpu clk
*/
srcclk = spear_cpufreq.clk;
}
newfreq = clk_round_rate(srcclk, newfreq * mult); if (newfreq <= 0) {
pr_err("clk_round_rate failed for cpu src clock\n"); return newfreq;
}
if (mult == 2)
ret = spear1340_set_cpu_rate(srcclk, newfreq); else
ret = clk_set_rate(spear_cpufreq.clk, newfreq);
if (ret)
pr_err("CPU Freq: cpu clk_set_rate failed: %d\n", ret);
spear_cpufreq.clk = clk_get(NULL, "cpu_clk"); if (IS_ERR(spear_cpufreq.clk)) {
pr_err("Unable to get CPU clock\n");
ret = PTR_ERR(spear_cpufreq.clk); goto out_put_mem;
}
ret = cpufreq_register_driver(&spear_cpufreq_driver); if (!ret) return 0;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.