1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2010 John Crispin <john@phrozen.org>
5 * Copyright (C) 2013-2015 Lantiq Beteiligungs-GmbH & Co.KG
9 #include <linux/export.h>
10 #include <linux/clk.h>
14 #include <asm/div64.h>
16 #include <lantiq_soc.h>
20 static unsigned int ram_clocks
[] = {
21 CLOCK_167M
, CLOCK_133M
, CLOCK_111M
, CLOCK_83M
};
22 #define DDR_HZ ram_clocks[ltq_cgu_r32(CGU_SYS) & 0x3]
24 /* legacy xway clock */
27 /* vr9, ar10/grx390 clock */
28 #define CGU_SYS_XRX 0x0c
29 #define CGU_IF_CLK_AR10 0x24
31 unsigned long ltq_danube_fpi_hz(void)
33 unsigned long ddr_clock
= DDR_HZ
;
35 if (ltq_cgu_r32(CGU_SYS
) & 0x40)
36 return ddr_clock
>> 1;
40 unsigned long ltq_danube_cpu_hz(void)
42 switch (ltq_cgu_r32(CGU_SYS
) & 0xc) {
54 unsigned long ltq_danube_pp32_hz(void)
56 unsigned int clksys
= (ltq_cgu_r32(CGU_SYS
) >> 7) & 3;
77 unsigned long ltq_ar9_sys_hz(void)
79 if (((ltq_cgu_r32(CGU_SYS
) >> 3) & 0x3) == 0x2)
84 unsigned long ltq_ar9_fpi_hz(void)
86 unsigned long sys
= ltq_ar9_sys_hz();
88 if (ltq_cgu_r32(CGU_SYS
) & BIT(0))
94 unsigned long ltq_ar9_cpu_hz(void)
96 if (ltq_cgu_r32(CGU_SYS
) & BIT(2))
97 return ltq_ar9_fpi_hz();
99 return ltq_ar9_sys_hz();
102 unsigned long ltq_vr9_cpu_hz(void)
104 unsigned int cpu_sel
;
107 cpu_sel
= (ltq_cgu_r32(CGU_SYS_XRX
) >> 4) & 0xf;
124 clk
= CLOCK_196_608M
;
142 unsigned long ltq_vr9_fpi_hz(void)
144 unsigned int ocp_sel
, cpu_clk
;
147 cpu_clk
= ltq_vr9_cpu_hz();
148 ocp_sel
= ltq_cgu_r32(CGU_SYS_XRX
) & 0x3;
161 clk
= (cpu_clk
* 2) / 5;
175 unsigned long ltq_vr9_pp32_hz(void)
177 unsigned int clksys
= (ltq_cgu_r32(CGU_SYS
) >> 16) & 0x7;
198 unsigned long ltq_ar10_cpu_hz(void)
201 int cpu_fs
= (ltq_cgu_r32(CGU_SYS_XRX
) >> 8) & 0x1;
202 int freq_div
= (ltq_cgu_r32(CGU_SYS_XRX
) >> 4) & 0x7;
228 unsigned long ltq_ar10_fpi_hz(void)
230 int freq_fpi
= (ltq_cgu_r32(CGU_IF_CLK_AR10
) >> 25) & 0xf;
247 unsigned long ltq_ar10_pp32_hz(void)
249 unsigned int clksys
= (ltq_cgu_r32(CGU_SYS
) >> 16) & 0x7;
267 unsigned long ltq_grx390_cpu_hz(void)
270 int cpu_fs
= ((ltq_cgu_r32(CGU_SYS_XRX
) >> 9) & 0x3);
271 int freq_div
= ((ltq_cgu_r32(CGU_SYS_XRX
) >> 4) & 0x7);
300 unsigned long ltq_grx390_fpi_hz(void)
302 /* fpi clock is derived from ddr_clk */
304 int cpu_fs
= ((ltq_cgu_r32(CGU_SYS_XRX
) >> 9) & 0x3);
305 int freq_div
= ((ltq_cgu_r32(CGU_SYS_XRX
)) & 0x7);
331 unsigned long ltq_grx390_pp32_hz(void)
333 unsigned int clksys
= (ltq_cgu_r32(CGU_SYS
) >> 16) & 0x7;