diff options
author | Jayachandran C <jchandra@broadcom.com> | 2014-04-29 10:37:52 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2014-05-30 10:50:13 -0400 |
commit | edf3ed5e69bcf3f60087099eccab34be0ebcf60a (patch) | |
tree | f4d3dcf8ab5338fa76430b0c36c6dfcfdb6522c7 /arch/mips | |
parent | c065909e47aea3575e51304e7411b46df22b20ca (diff) |
MIPS: Netlogic: Update XLP9XX/2XX core freq calculation
Calculate XLP 9XX and 2XX core frequency from the per-core PLL. This
should give the correct value for all board configurations.
Signed-off-by: Jayachandran C <jchandra@broadcom.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/6870/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips')
-rw-r--r-- | arch/mips/include/asm/netlogic/xlp-hal/sys.h | 8 | ||||
-rw-r--r-- | arch/mips/netlogic/xlp/nlm_hal.c | 83 |
2 files changed, 73 insertions, 18 deletions
diff --git a/arch/mips/include/asm/netlogic/xlp-hal/sys.h b/arch/mips/include/asm/netlogic/xlp-hal/sys.h index bcb136d224e6..bc7bddf25be9 100644 --- a/arch/mips/include/asm/netlogic/xlp-hal/sys.h +++ b/arch/mips/include/asm/netlogic/xlp-hal/sys.h | |||
@@ -118,6 +118,10 @@ | |||
118 | #define SYS_SCRTCH3 0x4c | 118 | #define SYS_SCRTCH3 0x4c |
119 | 119 | ||
120 | /* PLL registers XLP2XX */ | 120 | /* PLL registers XLP2XX */ |
121 | #define SYS_CPU_PLL_CTRL0(core) (0x1c0 + (core * 4)) | ||
122 | #define SYS_CPU_PLL_CTRL1(core) (0x1c1 + (core * 4)) | ||
123 | #define SYS_CPU_PLL_CTRL2(core) (0x1c2 + (core * 4)) | ||
124 | #define SYS_CPU_PLL_CTRL3(core) (0x1c3 + (core * 4)) | ||
121 | #define SYS_PLL_CTRL0 0x240 | 125 | #define SYS_PLL_CTRL0 0x240 |
122 | #define SYS_PLL_CTRL1 0x241 | 126 | #define SYS_PLL_CTRL1 0x241 |
123 | #define SYS_PLL_CTRL2 0x242 | 127 | #define SYS_PLL_CTRL2 0x242 |
@@ -148,6 +152,10 @@ | |||
148 | #define SYS_PLL_MEM_STAT 0x2a4 | 152 | #define SYS_PLL_MEM_STAT 0x2a4 |
149 | 153 | ||
150 | /* PLL registers XLP9XX */ | 154 | /* PLL registers XLP9XX */ |
155 | #define SYS_9XX_CPU_PLL_CTRL0(core) (0xc0 + (core * 4)) | ||
156 | #define SYS_9XX_CPU_PLL_CTRL1(core) (0xc1 + (core * 4)) | ||
157 | #define SYS_9XX_CPU_PLL_CTRL2(core) (0xc2 + (core * 4)) | ||
158 | #define SYS_9XX_CPU_PLL_CTRL3(core) (0xc3 + (core * 4)) | ||
151 | #define SYS_9XX_DMC_PLL_CTRL0 0x140 | 159 | #define SYS_9XX_DMC_PLL_CTRL0 0x140 |
152 | #define SYS_9XX_DMC_PLL_CTRL1 0x141 | 160 | #define SYS_9XX_DMC_PLL_CTRL1 0x141 |
153 | #define SYS_9XX_DMC_PLL_CTRL2 0x142 | 161 | #define SYS_9XX_DMC_PLL_CTRL2 0x142 |
diff --git a/arch/mips/netlogic/xlp/nlm_hal.c b/arch/mips/netlogic/xlp/nlm_hal.c index 59f1303b69d7..bc24beb3a426 100644 --- a/arch/mips/netlogic/xlp/nlm_hal.c +++ b/arch/mips/netlogic/xlp/nlm_hal.c | |||
@@ -206,34 +206,81 @@ int nlm_irq_to_irt(int irq) | |||
206 | return xlp_irq_to_irt(irq); | 206 | return xlp_irq_to_irt(irq); |
207 | } | 207 | } |
208 | 208 | ||
209 | unsigned int nlm_get_core_frequency(int node, int core) | 209 | static unsigned int nlm_xlp2_get_core_frequency(int node, int core) |
210 | { | ||
211 | unsigned int pll_post_div, ctrl_val0, ctrl_val1, denom; | ||
212 | uint64_t num, sysbase, clockbase; | ||
213 | |||
214 | if (cpu_is_xlp9xx()) { | ||
215 | clockbase = nlm_get_clock_regbase(node); | ||
216 | ctrl_val0 = nlm_read_sys_reg(clockbase, | ||
217 | SYS_9XX_CPU_PLL_CTRL0(core)); | ||
218 | ctrl_val1 = nlm_read_sys_reg(clockbase, | ||
219 | SYS_9XX_CPU_PLL_CTRL1(core)); | ||
220 | } else { | ||
221 | sysbase = nlm_get_node(node)->sysbase; | ||
222 | ctrl_val0 = nlm_read_sys_reg(sysbase, | ||
223 | SYS_CPU_PLL_CTRL0(core)); | ||
224 | ctrl_val1 = nlm_read_sys_reg(sysbase, | ||
225 | SYS_CPU_PLL_CTRL1(core)); | ||
226 | } | ||
227 | |||
228 | /* Find PLL post divider value */ | ||
229 | switch ((ctrl_val0 >> 24) & 0x7) { | ||
230 | case 1: | ||
231 | pll_post_div = 2; | ||
232 | break; | ||
233 | case 3: | ||
234 | pll_post_div = 4; | ||
235 | break; | ||
236 | case 7: | ||
237 | pll_post_div = 8; | ||
238 | break; | ||
239 | case 6: | ||
240 | pll_post_div = 16; | ||
241 | break; | ||
242 | case 0: | ||
243 | default: | ||
244 | pll_post_div = 1; | ||
245 | break; | ||
246 | } | ||
247 | |||
248 | num = 1000000ULL * (400 * 3 + 100 * (ctrl_val1 & 0x3f)); | ||
249 | denom = 3 * pll_post_div; | ||
250 | do_div(num, denom); | ||
251 | |||
252 | return (unsigned int)num; | ||
253 | } | ||
254 | |||
255 | static unsigned int nlm_xlp_get_core_frequency(int node, int core) | ||
210 | { | 256 | { |
211 | unsigned int pll_divf, pll_divr, dfs_div, ext_div; | 257 | unsigned int pll_divf, pll_divr, dfs_div, ext_div; |
212 | unsigned int rstval, dfsval, denom; | 258 | unsigned int rstval, dfsval, denom; |
213 | uint64_t num, sysbase; | 259 | uint64_t num, sysbase; |
214 | 260 | ||
215 | sysbase = nlm_get_node(node)->sysbase; | 261 | sysbase = nlm_get_node(node)->sysbase; |
216 | if (cpu_is_xlp9xx()) | 262 | rstval = nlm_read_sys_reg(sysbase, SYS_POWER_ON_RESET_CFG); |
217 | rstval = nlm_read_sys_reg(sysbase, SYS_9XX_POWER_ON_RESET_CFG); | 263 | dfsval = nlm_read_sys_reg(sysbase, SYS_CORE_DFS_DIV_VALUE); |
218 | else | 264 | pll_divf = ((rstval >> 10) & 0x7f) + 1; |
219 | rstval = nlm_read_sys_reg(sysbase, SYS_POWER_ON_RESET_CFG); | 265 | pll_divr = ((rstval >> 8) & 0x3) + 1; |
220 | if (cpu_is_xlpii()) { | 266 | ext_div = ((rstval >> 30) & 0x3) + 1; |
221 | num = 1000000ULL * (400 * 3 + 100 * (rstval >> 26)); | 267 | dfs_div = ((dfsval >> (core * 4)) & 0xf) + 1; |
222 | denom = 3; | 268 | |
223 | } else { | 269 | num = 800000000ULL * pll_divf; |
224 | dfsval = nlm_read_sys_reg(sysbase, SYS_CORE_DFS_DIV_VALUE); | 270 | denom = 3 * pll_divr * ext_div * dfs_div; |
225 | pll_divf = ((rstval >> 10) & 0x7f) + 1; | ||
226 | pll_divr = ((rstval >> 8) & 0x3) + 1; | ||
227 | ext_div = ((rstval >> 30) & 0x3) + 1; | ||
228 | dfs_div = ((dfsval >> (core * 4)) & 0xf) + 1; | ||
229 | |||
230 | num = 800000000ULL * pll_divf; | ||
231 | denom = 3 * pll_divr * ext_div * dfs_div; | ||
232 | } | ||
233 | do_div(num, denom); | 271 | do_div(num, denom); |
272 | |||
234 | return (unsigned int)num; | 273 | return (unsigned int)num; |
235 | } | 274 | } |
236 | 275 | ||
276 | unsigned int nlm_get_core_frequency(int node, int core) | ||
277 | { | ||
278 | if (cpu_is_xlpii()) | ||
279 | return nlm_xlp2_get_core_frequency(node, core); | ||
280 | else | ||
281 | return nlm_xlp_get_core_frequency(node, core); | ||
282 | } | ||
283 | |||
237 | /* | 284 | /* |
238 | * Calculate PIC frequency from PLL registers. | 285 | * Calculate PIC frequency from PLL registers. |
239 | * freq_out = (ref_freq/2 * (6 + ctrl2[7:0]) + ctrl2[20:8]/2^13) / | 286 | * freq_out = (ref_freq/2 * (6 + ctrl2[7:0]) + ctrl2[20:8]/2^13) / |