16 #include <linux/module.h>
20 #include <linux/device.h>
26 #include <mach/hardware.h>
31 #include <mach/regs-clock.h>
35 #include <plat/clock.h>
40 static struct clk *armclk;
44 static inline int within_khz(
unsigned long a,
unsigned long b)
48 return (diff >= -1000 && diff <= 1000);
61 unsigned int hdiv, pdiv;
63 unsigned long hclk_max;
65 fclk = cfg->
freq.fclk;
66 armclk = cfg->
freq.armclk;
67 hclk_max = cfg->
max.hclk;
69 s3c_freq_dbg(
"%s: fclk is %lu, armclk %lu, max hclk %lu\n",
70 __func__, fclk, armclk, hclk_max);
78 if (armclk < fclk && armclk < hclk_max)
81 for (hdiv = 1; hdiv < 9; hdiv++) {
82 if (hdiv == 5 || hdiv == 7)
86 if (hclk <= hclk_max || within_khz(hclk, hclk_max))
90 s3c_freq_dbg(
"%s: hclk %lu, div %d\n", __func__, hclk, hdiv);
95 pdiv = (hclk > cfg->
max.pclk) ? 2 : 1;
97 if ((hclk / pdiv) > cfg->
max.pclk)
121 cfg->
freq.armclk = armclk;
125 cfg->
divs.h_divisor = hdiv;
126 cfg->
divs.p_divisor = pdiv;
134 #define CAMDIVN_HCLK_HALF (S3C2440_CAMDIVN_HCLK3_HALF | \
135 S3C2440_CAMDIVN_HCLK4_HALF)
146 unsigned long clkdiv, camdiv;
149 cfg->
divs.h_divisor, cfg->
divs.p_divisor);
154 clkdiv &= ~(S3C2440_CLKDIVN_HDIVN_MASK | S3C2440_CLKDIVN_PDIVN);
157 switch (cfg->
divs.h_divisor) {
159 clkdiv |= S3C2440_CLKDIVN_HDIVN_1;
163 clkdiv |= S3C2440_CLKDIVN_HDIVN_2;
167 camdiv |= S3C2440_CAMDIVN_HCLK3_HALF;
169 clkdiv |= S3C2440_CLKDIVN_HDIVN_3_6;
173 camdiv |= S3C2440_CAMDIVN_HCLK4_HALF;
175 clkdiv |= S3C2440_CLKDIVN_HDIVN_4_8;
182 if (cfg->
divs.p_divisor != cfg->
divs.h_divisor)
183 clkdiv |= S3C2440_CLKDIVN_PDIVN;
201 static int run_freq_for(
unsigned long max_hclk,
unsigned long fclk,
210 for (div = *divs; div > 0; div = *divs++) {
213 if (freq > max_hclk && div != 1)
217 index = s3c_cpufreq_addfreq(table, index, table_size, freq);
225 static int hclk_divs[] = { 1, 2, 3, 4, 6, 8, -1 };
236 ret = run_freq_for(cfg->
info->max.hclk,
264 .set_divs = s3c2440_cpufreq_setdivs,
266 .calc_freqtable = s3c2440_cpufreq_calctable,
273 static int s3c2440_cpufreq_add(
struct device *
dev,
281 if (IS_ERR(xtal) || IS_ERR(hclk) || IS_ERR(fclk) || IS_ERR(armclk)) {
290 .name =
"s3c2440_cpufreq",
292 .add_dev = s3c2440_cpufreq_add,
295 static int s3c2440_cpufreq_init(
void)
304 .name =
"s3c2442_cpufreq",
306 .add_dev = s3c2440_cpufreq_add,
309 static int s3c2442_cpufreq_init(
void)