Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris...
[linux/fpc-iii.git] / arch / mips / lantiq / xway / clk.c
blob8750dc0a1bf678c5bd8500260816d6070b949aca
1 /*
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 */
9 #include <linux/io.h>
10 #include <linux/export.h>
11 #include <linux/clk.h>
13 #include <asm/time.h>
14 #include <asm/irq.h>
15 #include <asm/div64.h>
17 #include <lantiq_soc.h>
19 #include "../clk.h"
21 static unsigned int ram_clocks[] = {
22 CLOCK_167M, CLOCK_133M, CLOCK_111M, CLOCK_83M };
23 #define DDR_HZ ram_clocks[ltq_cgu_r32(CGU_SYS) & 0x3]
25 /* legacy xway clock */
26 #define CGU_SYS 0x10
28 /* vr9 clock */
29 #define CGU_SYS_VR9 0x0c
30 #define CGU_IF_CLK_VR9 0x24
32 unsigned long ltq_danube_fpi_hz(void)
34 unsigned long ddr_clock = DDR_HZ;
36 if (ltq_cgu_r32(CGU_SYS) & 0x40)
37 return ddr_clock >> 1;
38 return ddr_clock;
41 unsigned long ltq_danube_cpu_hz(void)
43 switch (ltq_cgu_r32(CGU_SYS) & 0xc) {
44 case 0:
45 return CLOCK_333M;
46 case 4:
47 return DDR_HZ;
48 case 8:
49 return DDR_HZ << 1;
50 default:
51 return DDR_HZ >> 1;
55 unsigned long ltq_danube_pp32_hz(void)
57 unsigned int clksys = (ltq_cgu_r32(CGU_SYS) >> 7) & 3;
58 unsigned long clk;
60 switch (clksys) {
61 case 1:
62 clk = CLOCK_240M;
63 break;
64 case 2:
65 clk = CLOCK_222M;
66 break;
67 case 3:
68 clk = CLOCK_133M;
69 break;
70 default:
71 clk = CLOCK_266M;
72 break;
75 return clk;
78 unsigned long ltq_ar9_sys_hz(void)
80 if (((ltq_cgu_r32(CGU_SYS) >> 3) & 0x3) == 0x2)
81 return CLOCK_393M;
82 return CLOCK_333M;
85 unsigned long ltq_ar9_fpi_hz(void)
87 unsigned long sys = ltq_ar9_sys_hz();
89 if (ltq_cgu_r32(CGU_SYS) & BIT(0))
90 return sys;
91 return sys >> 1;
94 unsigned long ltq_ar9_cpu_hz(void)
96 if (ltq_cgu_r32(CGU_SYS) & BIT(2))
97 return ltq_ar9_fpi_hz();
98 else
99 return ltq_ar9_sys_hz();
102 unsigned long ltq_vr9_cpu_hz(void)
104 unsigned int cpu_sel;
105 unsigned long clk;
107 cpu_sel = (ltq_cgu_r32(CGU_SYS_VR9) >> 4) & 0xf;
109 switch (cpu_sel) {
110 case 0:
111 clk = CLOCK_600M;
112 break;
113 case 1:
114 clk = CLOCK_500M;
115 break;
116 case 2:
117 clk = CLOCK_393M;
118 break;
119 case 3:
120 clk = CLOCK_333M;
121 break;
122 case 5:
123 case 6:
124 clk = CLOCK_196_608M;
125 break;
126 case 7:
127 clk = CLOCK_167M;
128 break;
129 case 4:
130 case 8:
131 case 9:
132 clk = CLOCK_125M;
133 break;
134 default:
135 clk = 0;
136 break;
139 return clk;
142 unsigned long ltq_vr9_fpi_hz(void)
144 unsigned int ocp_sel, cpu_clk;
145 unsigned long clk;
147 cpu_clk = ltq_vr9_cpu_hz();
148 ocp_sel = ltq_cgu_r32(CGU_SYS_VR9) & 0x3;
150 switch (ocp_sel) {
151 case 0:
152 /* OCP ratio 1 */
153 clk = cpu_clk;
154 break;
155 case 2:
156 /* OCP ratio 2 */
157 clk = cpu_clk / 2;
158 break;
159 case 3:
160 /* OCP ratio 2.5 */
161 clk = (cpu_clk * 2) / 5;
162 break;
163 case 4:
164 /* OCP ratio 3 */
165 clk = cpu_clk / 3;
166 break;
167 default:
168 clk = 0;
169 break;
172 return clk;
175 unsigned long ltq_vr9_pp32_hz(void)
177 unsigned int clksys = (ltq_cgu_r32(CGU_SYS) >> 16) & 3;
178 unsigned long clk;
180 switch (clksys) {
181 case 1:
182 clk = CLOCK_450M;
183 break;
184 case 2:
185 clk = CLOCK_300M;
186 break;
187 default:
188 clk = CLOCK_500M;
189 break;
192 return clk;