14 #include <linux/kernel.h>
15 #include <linux/module.h>
20 #include <asm/div64.h>
26 #define AR71XX_BASE_FREQ 40000000
27 #define AR724X_BASE_FREQ 5000000
28 #define AR913X_BASE_FREQ 5000000
34 static struct clk ath79_ref_clk;
35 static struct clk ath79_cpu_clk;
36 static struct clk ath79_ddr_clk;
37 static struct clk ath79_ahb_clk;
38 static struct clk ath79_wdt_clk;
39 static struct clk ath79_uart_clk;
41 static void __init ar71xx_clocks_init(
void)
52 freq = div * ath79_ref_clk.rate;
55 ath79_cpu_clk.rate = freq /
div;
58 ath79_ddr_clk.rate = freq /
div;
61 ath79_ahb_clk.rate = ath79_cpu_clk.rate /
div;
63 ath79_wdt_clk.rate = ath79_ahb_clk.rate;
64 ath79_uart_clk.rate = ath79_ahb_clk.rate;
67 static void __init ar724x_clocks_init(
void)
77 freq = div * ath79_ref_clk.rate;
82 ath79_cpu_clk.rate =
freq;
85 ath79_ddr_clk.rate = freq /
div;
88 ath79_ahb_clk.rate = ath79_cpu_clk.rate /
div;
90 ath79_wdt_clk.rate = ath79_ahb_clk.rate;
91 ath79_uart_clk.rate = ath79_ahb_clk.rate;
94 static void __init ar913x_clocks_init(
void)
104 freq = div * ath79_ref_clk.rate;
106 ath79_cpu_clk.rate =
freq;
109 ath79_ddr_clk.rate = freq /
div;
112 ath79_ahb_clk.rate = ath79_cpu_clk.rate /
div;
114 ath79_wdt_clk.rate = ath79_ahb_clk.rate;
115 ath79_uart_clk.rate = ath79_ahb_clk.rate;
118 static void __init ar933x_clocks_init(
void)
127 ath79_ref_clk.rate = (40 * 1000 * 1000);
129 ath79_ref_clk.rate = (25 * 1000 * 1000);
133 ath79_cpu_clk.rate = ath79_ref_clk.rate;
134 ath79_ahb_clk.rate = ath79_ref_clk.rate;
135 ath79_ddr_clk.rate = ath79_ref_clk.rate;
141 freq = ath79_ref_clk.rate /
t;
156 ath79_cpu_clk.rate = freq /
t;
160 ath79_ddr_clk.rate = freq /
t;
164 ath79_ahb_clk.rate = freq /
t;
167 ath79_wdt_clk.rate = ath79_ref_clk.rate;
168 ath79_uart_clk.rate = ath79_ref_clk.rate;
177 t = ath79_ref_clk.rate;
182 t = ath79_ref_clk.rate;
184 do_div(t, ref_div * frac);
187 ret /= (1 << out_div);
191 static void __init ar934x_clocks_init(
void)
193 u32 pll, out_div, ref_div, nint, nfrac,
frac, clk_ctrl, postdiv;
202 ath79_ref_clk.rate = 40 * 1000 * 1000;
204 ath79_ref_clk.rate = 25 * 1000 * 1000;
230 cpu_pll = ar934x_get_pll_freq(ath79_ref_clk.rate, ref_div, nint,
231 nfrac, frac, out_div);
234 if (pll & AR934X_SRIF_DPLL2_LOCAL_PLL) {
257 ddr_pll = ar934x_get_pll_freq(ath79_ref_clk.rate, ref_div, nint,
258 nfrac, frac, out_div);
266 ath79_cpu_clk.rate = ath79_ref_clk.rate;
268 ath79_cpu_clk.rate = cpu_pll / (postdiv + 1);
270 ath79_cpu_clk.rate = ddr_pll / (postdiv + 1);
276 ath79_ddr_clk.rate = ath79_ref_clk.rate;
278 ath79_ddr_clk.rate = ddr_pll / (postdiv + 1);
280 ath79_ddr_clk.rate = cpu_pll / (postdiv + 1);
286 ath79_ahb_clk.rate = ath79_ref_clk.rate;
288 ath79_ahb_clk.rate = ddr_pll / (postdiv + 1);
290 ath79_ahb_clk.rate = cpu_pll / (postdiv + 1);
292 ath79_wdt_clk.rate = ath79_ref_clk.rate;
293 ath79_uart_clk.rate = ath79_ref_clk.rate;
301 ar71xx_clocks_init();
302 else if (soc_is_ar724x())
303 ar724x_clocks_init();
304 else if (soc_is_ar913x())
305 ar913x_clocks_init();
306 else if (soc_is_ar933x())
307 ar933x_clocks_init();
308 else if (soc_is_ar934x())
309 ar934x_clocks_init();
313 pr_info(
"Clocks: CPU:%lu.%03luMHz, DDR:%lu.%03luMHz, AHB:%lu.%03luMHz, "
315 ath79_cpu_clk.rate / 1000000,
316 (ath79_cpu_clk.rate / 1000) % 1000,
317 ath79_ddr_clk.rate / 1000000,
318 (ath79_ddr_clk.rate / 1000) % 1000,
319 ath79_ahb_clk.rate / 1000000,
320 (ath79_ahb_clk.rate / 1000) % 1000,
321 ath79_ref_clk.rate / 1000000,
322 (ath79_ref_clk.rate / 1000) % 1000);
331 return &ath79_ref_clk;
334 return &ath79_cpu_clk;
337 return &ath79_ddr_clk;
340 return &ath79_ahb_clk;
343 return &ath79_wdt_clk;
346 return &ath79_uart_clk;