15 #include <linux/module.h>
19 #include <linux/device.h>
28 #include <mach/regs-clock.h>
32 #include <plat/clock.h>
39 static struct clk *armclk;
45 unsigned int hdiv, pdiv, armdiv, dvs;
46 unsigned long hclk,
fclk, armclk, armdiv_clk;
47 unsigned long hclk_max;
49 fclk = cfg->
freq.fclk;
50 armclk = cfg->
freq.armclk;
51 hclk_max = cfg->
max.hclk;
56 if (hclk_max > armclk)
60 __func__, fclk, armclk, hclk_max);
62 __func__, cfg->
freq.fclk, cfg->
freq.armclk,
65 armdiv = fclk / armclk;
72 cfg->
divs.arm_divisor = armdiv;
73 armdiv_clk = fclk / armdiv;
75 hdiv = armdiv_clk / hclk_max;
79 cfg->
freq.hclk = hclk = armdiv_clk / hdiv;
82 cfg->
divs.dvs = dvs = armclk < armdiv_clk;
85 cfg->
freq.armclk = dvs ? hclk : armdiv_clk;
87 s3c_freq_dbg(
"%s: armclk %lu, hclk %lu, armdiv %d, hdiv %d, dvs %d\n",
88 __func__, armclk, hclk, armdiv, hdiv, cfg->
divs.dvs);
93 pdiv = (hclk > cfg->
max.pclk) ? 2 : 1;
95 if ((hclk / pdiv) > cfg->
max.pclk)
98 cfg->
freq.pclk = hclk / pdiv;
109 cfg->
divs.h_divisor = hdiv * armdiv;
110 cfg->
divs.p_divisor = pdiv * armdiv;
120 unsigned long clkdiv;
121 unsigned long olddiv;
127 clkdiv &= ~S3C2412_CLKDIVN_ARMDIVN;
128 clkdiv &= ~S3C2412_CLKDIVN_HDIVN_MASK;
129 clkdiv &= ~S3C2412_CLKDIVN_PDIVN;
131 if (cfg->
divs.arm_divisor == 2)
132 clkdiv |= S3C2412_CLKDIVN_ARMDIVN;
134 clkdiv |= ((cfg->
divs.h_divisor / cfg->
divs.arm_divisor) - 1);
136 if (cfg->
divs.p_divisor != cfg->
divs.h_divisor)
137 clkdiv |= S3C2412_CLKDIVN_PDIVN;
139 s3c_freq_dbg(
"%s: div %08lx => %08lx\n", __func__, olddiv, clkdiv);
158 refresh = (board->
refresh / 10);
159 refresh *= (cfg->
freq.hclk / 100);
160 refresh /= (1 * 1000 * 1000);
162 s3c_freq_dbg(
"%s: setting refresh 0x%08lx\n", __func__, refresh);
185 .set_divs = s3c2412_cpufreq_setdivs,
186 .calc_divs = s3c2412_cpufreq_calcdivs,
197 static int s3c2412_cpufreq_add(
struct device *
dev,
200 unsigned long fclk_rate;
215 if (fclk_rate > 200000000) {
217 "%s: fclk %ld MHz, assuming 266MHz capable part\n",
218 __func__, fclk_rate / 1000000);
219 s3c2412_cpufreq_info.
max.fclk = 266000000;
220 s3c2412_cpufreq_info.
max.hclk = 133000000;
221 s3c2412_cpufreq_info.
max.pclk = 66000000;
225 if (IS_ERR(armclk)) {
249 .name =
"s3c2412_cpufreq",
251 .add_dev = s3c2412_cpufreq_add,
254 static int s3c2412_cpufreq_init(
void)