2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU General Public License version 2 as published
4 * by the Free Software Foundation.
6 * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
7 * Copyright (C) 2013-2015 Lantiq Beteiligungs-GmbH & Co.KG
11 #include <linux/export.h>
12 #include <linux/clk.h>
16 #include <asm/div64.h>
18 #include <lantiq_soc.h>
22 static unsigned int ram_clocks
[] = {
23 CLOCK_167M
, CLOCK_133M
, CLOCK_111M
, CLOCK_83M
};
24 #define DDR_HZ ram_clocks[ltq_cgu_r32(CGU_SYS) & 0x3]
26 /* legacy xway clock */
29 /* vr9, ar10/grx390 clock */
30 #define CGU_SYS_XRX 0x0c
31 #define CGU_IF_CLK_AR10 0x24
33 unsigned long ltq_danube_fpi_hz(void)
35 unsigned long ddr_clock
= DDR_HZ
;
37 if (ltq_cgu_r32(CGU_SYS
) & 0x40)
38 return ddr_clock
>> 1;
42 unsigned long ltq_danube_cpu_hz(void)
44 switch (ltq_cgu_r32(CGU_SYS
) & 0xc) {
56 unsigned long ltq_danube_pp32_hz(void)
58 unsigned int clksys
= (ltq_cgu_r32(CGU_SYS
) >> 7) & 3;
79 unsigned long ltq_ar9_sys_hz(void)
81 if (((ltq_cgu_r32(CGU_SYS
) >> 3) & 0x3) == 0x2)
86 unsigned long ltq_ar9_fpi_hz(void)
88 unsigned long sys
= ltq_ar9_sys_hz();
90 if (ltq_cgu_r32(CGU_SYS
) & BIT(0))
96 unsigned long ltq_ar9_cpu_hz(void)
98 if (ltq_cgu_r32(CGU_SYS
) & BIT(2))
99 return ltq_ar9_fpi_hz();
101 return ltq_ar9_sys_hz();
104 unsigned long ltq_vr9_cpu_hz(void)
106 unsigned int cpu_sel
;
109 cpu_sel
= (ltq_cgu_r32(CGU_SYS_XRX
) >> 4) & 0xf;
126 clk
= CLOCK_196_608M
;
144 unsigned long ltq_vr9_fpi_hz(void)
146 unsigned int ocp_sel
, cpu_clk
;
149 cpu_clk
= ltq_vr9_cpu_hz();
150 ocp_sel
= ltq_cgu_r32(CGU_SYS_XRX
) & 0x3;
163 clk
= (cpu_clk
* 2) / 5;
177 unsigned long ltq_vr9_pp32_hz(void)
179 unsigned int clksys
= (ltq_cgu_r32(CGU_SYS
) >> 16) & 0x7;
200 unsigned long ltq_ar10_cpu_hz(void)
203 int cpu_fs
= (ltq_cgu_r32(CGU_SYS_XRX
) >> 8) & 0x1;
204 int freq_div
= (ltq_cgu_r32(CGU_SYS_XRX
) >> 4) & 0x7;
230 unsigned long ltq_ar10_fpi_hz(void)
232 int freq_fpi
= (ltq_cgu_r32(CGU_IF_CLK_AR10
) >> 25) & 0xf;
249 unsigned long ltq_ar10_pp32_hz(void)
251 unsigned int clksys
= (ltq_cgu_r32(CGU_SYS
) >> 16) & 0x7;
269 unsigned long ltq_grx390_cpu_hz(void)
272 int cpu_fs
= ((ltq_cgu_r32(CGU_SYS_XRX
) >> 9) & 0x3);
273 int freq_div
= ((ltq_cgu_r32(CGU_SYS_XRX
) >> 4) & 0x7);
302 unsigned long ltq_grx390_fpi_hz(void)
304 /* fpi clock is derived from ddr_clk */
306 int cpu_fs
= ((ltq_cgu_r32(CGU_SYS_XRX
) >> 9) & 0x3);
307 int freq_div
= ((ltq_cgu_r32(CGU_SYS_XRX
)) & 0x7);
333 unsigned long ltq_grx390_pp32_hz(void)
335 unsigned int clksys
= (ltq_cgu_r32(CGU_SYS
) >> 16) & 0x7;