blob: 79fe32df5e96c99da07d763e0990e07ee0321260 [file] [log] [blame]
Maxime Bizone7300d02009-08-18 13:23:37 +01001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
7 * Copyright (C) 2009 Florian Fainelli <florian@openwrt.org>
8 */
9
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/cpu.h>
Kevin Cernekee602977b2010-10-16 14:22:30 -070013#include <asm/cpu.h>
Florian Fainelli2b5b9b72009-10-14 09:56:00 +020014#include <asm/cpu-info.h>
Kevin Cernekee602977b2010-10-16 14:22:30 -070015#include <asm/mipsregs.h>
Maxime Bizone7300d02009-08-18 13:23:37 +010016#include <bcm63xx_cpu.h>
17#include <bcm63xx_regs.h>
18#include <bcm63xx_io.h>
19#include <bcm63xx_irq.h>
20
21const unsigned long *bcm63xx_regs_base;
22EXPORT_SYMBOL(bcm63xx_regs_base);
23
24const int *bcm63xx_irqs;
25EXPORT_SYMBOL(bcm63xx_irqs);
26
27static u16 bcm63xx_cpu_id;
Jonas Gorski66054282013-03-21 14:03:15 +000028static u8 bcm63xx_cpu_rev;
Maxime Bizone7300d02009-08-18 13:23:37 +010029static unsigned int bcm63xx_cpu_freq;
30static unsigned int bcm63xx_memory_size;
31
Jonas Gorskie5766ae2012-07-24 16:33:12 +020032static const unsigned long bcm6328_regs_base[] = {
33 __GEN_CPU_REGS_TABLE(6328)
34};
35
36static const int bcm6328_irqs[] = {
37 __GEN_CPU_IRQ_TABLE(6328)
38};
39
Maxime Bizonec68c522011-11-04 19:09:29 +010040static const unsigned long bcm6338_regs_base[] = {
41 __GEN_CPU_REGS_TABLE(6338)
Maxime Bizone7300d02009-08-18 13:23:37 +010042};
43
Maxime Bizonec68c522011-11-04 19:09:29 +010044static const int bcm6338_irqs[] = {
45 __GEN_CPU_IRQ_TABLE(6338)
Maxime Bizone7300d02009-08-18 13:23:37 +010046};
47
Maxime Bizonec68c522011-11-04 19:09:29 +010048static const unsigned long bcm6345_regs_base[] = {
49 __GEN_CPU_REGS_TABLE(6345)
Maxime Bizone7300d02009-08-18 13:23:37 +010050};
51
Maxime Bizonec68c522011-11-04 19:09:29 +010052static const int bcm6345_irqs[] = {
53 __GEN_CPU_IRQ_TABLE(6345)
Maxime Bizone7300d02009-08-18 13:23:37 +010054};
55
Maxime Bizonec68c522011-11-04 19:09:29 +010056static const unsigned long bcm6348_regs_base[] = {
57 __GEN_CPU_REGS_TABLE(6348)
Maxime Bizone7300d02009-08-18 13:23:37 +010058};
59
Maxime Bizonec68c522011-11-04 19:09:29 +010060static const int bcm6348_irqs[] = {
61 __GEN_CPU_IRQ_TABLE(6348)
62
Maxime Bizone7300d02009-08-18 13:23:37 +010063};
64
Maxime Bizonec68c522011-11-04 19:09:29 +010065static const unsigned long bcm6358_regs_base[] = {
66 __GEN_CPU_REGS_TABLE(6358)
Maxime Bizone7300d02009-08-18 13:23:37 +010067};
68
Maxime Bizonec68c522011-11-04 19:09:29 +010069static const int bcm6358_irqs[] = {
70 __GEN_CPU_IRQ_TABLE(6358)
71
Maxime Bizone7300d02009-08-18 13:23:37 +010072};
73
Jonas Gorski2c8aaf72013-03-21 14:03:17 +000074static const unsigned long bcm6362_regs_base[] = {
75 __GEN_CPU_REGS_TABLE(6362)
76};
77
78static const int bcm6362_irqs[] = {
79 __GEN_CPU_IRQ_TABLE(6362)
80
81};
82
Maxime Bizon04712f32011-11-04 19:09:35 +010083static const unsigned long bcm6368_regs_base[] = {
84 __GEN_CPU_REGS_TABLE(6368)
85};
86
87static const int bcm6368_irqs[] = {
88 __GEN_CPU_IRQ_TABLE(6368)
89
90};
91
Maxime Bizone7300d02009-08-18 13:23:37 +010092u16 __bcm63xx_get_cpu_id(void)
93{
94 return bcm63xx_cpu_id;
95}
96
97EXPORT_SYMBOL(__bcm63xx_get_cpu_id);
98
Jonas Gorski66054282013-03-21 14:03:15 +000099u8 bcm63xx_get_cpu_rev(void)
Maxime Bizone7300d02009-08-18 13:23:37 +0100100{
101 return bcm63xx_cpu_rev;
102}
103
104EXPORT_SYMBOL(bcm63xx_get_cpu_rev);
105
106unsigned int bcm63xx_get_cpu_freq(void)
107{
108 return bcm63xx_cpu_freq;
109}
110
111unsigned int bcm63xx_get_memory_size(void)
112{
113 return bcm63xx_memory_size;
114}
115
116static unsigned int detect_cpu_clock(void)
117{
Maxime Bizon04712f32011-11-04 19:09:35 +0100118 switch (bcm63xx_get_cpu_id()) {
Jonas Gorskie5766ae2012-07-24 16:33:12 +0200119 case BCM6328_CPU_ID:
120 {
121 unsigned int tmp, mips_pll_fcvo;
122
123 tmp = bcm_misc_readl(MISC_STRAPBUS_6328_REG);
124 mips_pll_fcvo = (tmp & STRAPBUS_6328_FCVO_MASK)
125 >> STRAPBUS_6328_FCVO_SHIFT;
126
127 switch (mips_pll_fcvo) {
128 case 0x12:
129 case 0x14:
130 case 0x19:
131 return 160000000;
132 case 0x1c:
133 return 192000000;
134 case 0x13:
135 case 0x15:
136 return 200000000;
137 case 0x1a:
138 return 384000000;
139 case 0x16:
140 return 400000000;
141 default:
142 return 320000000;
143 }
144
145 }
Maxime Bizon04712f32011-11-04 19:09:35 +0100146 case BCM6338_CPU_ID:
147 /* BCM6338 has a fixed 240 Mhz frequency */
Maxime Bizone7300d02009-08-18 13:23:37 +0100148 return 240000000;
149
Maxime Bizon04712f32011-11-04 19:09:35 +0100150 case BCM6345_CPU_ID:
151 /* BCM6345 has a fixed 140Mhz frequency */
Maxime Bizone7300d02009-08-18 13:23:37 +0100152 return 140000000;
153
Maxime Bizon04712f32011-11-04 19:09:35 +0100154 case BCM6348_CPU_ID:
155 {
156 unsigned int tmp, n1, n2, m1;
157
Maxime Bizone7300d02009-08-18 13:23:37 +0100158 /* 16MHz * (N1 + 1) * (N2 + 2) / (M1_CPU + 1) */
159 tmp = bcm_perf_readl(PERF_MIPSPLLCTL_REG);
160 n1 = (tmp & MIPSPLLCTL_N1_MASK) >> MIPSPLLCTL_N1_SHIFT;
161 n2 = (tmp & MIPSPLLCTL_N2_MASK) >> MIPSPLLCTL_N2_SHIFT;
162 m1 = (tmp & MIPSPLLCTL_M1CPU_MASK) >> MIPSPLLCTL_M1CPU_SHIFT;
163 n1 += 1;
164 n2 += 2;
165 m1 += 1;
Maxime Bizon04712f32011-11-04 19:09:35 +0100166 return (16 * 1000000 * n1 * n2) / m1;
Maxime Bizone7300d02009-08-18 13:23:37 +0100167 }
168
Maxime Bizon04712f32011-11-04 19:09:35 +0100169 case BCM6358_CPU_ID:
170 {
171 unsigned int tmp, n1, n2, m1;
172
Maxime Bizone7300d02009-08-18 13:23:37 +0100173 /* 16MHz * N1 * N2 / M1_CPU */
174 tmp = bcm_ddr_readl(DDR_DMIPSPLLCFG_REG);
175 n1 = (tmp & DMIPSPLLCFG_N1_MASK) >> DMIPSPLLCFG_N1_SHIFT;
176 n2 = (tmp & DMIPSPLLCFG_N2_MASK) >> DMIPSPLLCFG_N2_SHIFT;
177 m1 = (tmp & DMIPSPLLCFG_M1_MASK) >> DMIPSPLLCFG_M1_SHIFT;
Maxime Bizon04712f32011-11-04 19:09:35 +0100178 return (16 * 1000000 * n1 * n2) / m1;
Maxime Bizone7300d02009-08-18 13:23:37 +0100179 }
180
Jonas Gorski2c8aaf72013-03-21 14:03:17 +0000181 case BCM6362_CPU_ID:
182 {
183 unsigned int tmp, mips_pll_fcvo;
184
185 tmp = bcm_misc_readl(MISC_STRAPBUS_6362_REG);
186 mips_pll_fcvo = (tmp & STRAPBUS_6362_FCVO_MASK)
187 >> STRAPBUS_6362_FCVO_SHIFT;
188 switch (mips_pll_fcvo) {
189 case 0x03:
190 case 0x0b:
191 case 0x13:
192 case 0x1b:
193 return 240000000;
194 case 0x04:
195 case 0x0c:
196 case 0x14:
197 case 0x1c:
198 return 160000000;
199 case 0x05:
200 case 0x0e:
201 case 0x16:
202 case 0x1e:
203 case 0x1f:
204 return 400000000;
205 case 0x06:
206 return 440000000;
207 case 0x07:
208 case 0x17:
209 return 384000000;
210 case 0x15:
211 case 0x1d:
212 return 200000000;
213 default:
214 return 320000000;
215 }
216 }
Maxime Bizon04712f32011-11-04 19:09:35 +0100217 case BCM6368_CPU_ID:
218 {
219 unsigned int tmp, p1, p2, ndiv, m1;
220
221 /* (64MHz / P1) * P2 * NDIV / M1_CPU */
222 tmp = bcm_ddr_readl(DDR_DMIPSPLLCFG_6368_REG);
223
224 p1 = (tmp & DMIPSPLLCFG_6368_P1_MASK) >>
225 DMIPSPLLCFG_6368_P1_SHIFT;
226
227 p2 = (tmp & DMIPSPLLCFG_6368_P2_MASK) >>
228 DMIPSPLLCFG_6368_P2_SHIFT;
229
230 ndiv = (tmp & DMIPSPLLCFG_6368_NDIV_MASK) >>
231 DMIPSPLLCFG_6368_NDIV_SHIFT;
232
233 tmp = bcm_ddr_readl(DDR_DMIPSPLLDIV_6368_REG);
234 m1 = (tmp & DMIPSPLLDIV_6368_MDIV_MASK) >>
235 DMIPSPLLDIV_6368_MDIV_SHIFT;
236
237 return (((64 * 1000000) / p1) * p2 * ndiv) / m1;
238 }
239
240 default:
241 BUG();
242 }
Maxime Bizone7300d02009-08-18 13:23:37 +0100243}
244
245/*
246 * attempt to detect the amount of memory installed
247 */
248static unsigned int detect_memory_size(void)
249{
250 unsigned int cols = 0, rows = 0, is_32bits = 0, banks = 0;
251 u32 val;
252
Jonas Gorski2c8aaf72013-03-21 14:03:17 +0000253 if (BCMCPU_IS_6328() || BCMCPU_IS_6362())
Jonas Gorskie5766ae2012-07-24 16:33:12 +0200254 return bcm_ddr_readl(DDR_CSEND_REG) << 24;
255
Florian Fainellid61fcfe2011-11-16 20:10:36 +0100256 if (BCMCPU_IS_6345()) {
257 val = bcm_sdram_readl(SDRAM_MBASE_REG);
258 return (val * 8 * 1024 * 1024);
259 }
Maxime Bizone7300d02009-08-18 13:23:37 +0100260
261 if (BCMCPU_IS_6338() || BCMCPU_IS_6348()) {
262 val = bcm_sdram_readl(SDRAM_CFG_REG);
263 rows = (val & SDRAM_CFG_ROW_MASK) >> SDRAM_CFG_ROW_SHIFT;
264 cols = (val & SDRAM_CFG_COL_MASK) >> SDRAM_CFG_COL_SHIFT;
265 is_32bits = (val & SDRAM_CFG_32B_MASK) ? 1 : 0;
266 banks = (val & SDRAM_CFG_BANK_MASK) ? 2 : 1;
267 }
268
Maxime Bizon04712f32011-11-04 19:09:35 +0100269 if (BCMCPU_IS_6358() || BCMCPU_IS_6368()) {
Maxime Bizone7300d02009-08-18 13:23:37 +0100270 val = bcm_memc_readl(MEMC_CFG_REG);
271 rows = (val & MEMC_CFG_ROW_MASK) >> MEMC_CFG_ROW_SHIFT;
272 cols = (val & MEMC_CFG_COL_MASK) >> MEMC_CFG_COL_SHIFT;
273 is_32bits = (val & MEMC_CFG_32B_MASK) ? 0 : 1;
274 banks = 2;
275 }
276
277 /* 0 => 11 address bits ... 2 => 13 address bits */
278 rows += 11;
279
280 /* 0 => 8 address bits ... 2 => 10 address bits */
281 cols += 8;
282
283 return 1 << (cols + rows + (is_32bits + 1) + banks);
284}
285
286void __init bcm63xx_cpu_init(void)
287{
Jonas Gorski13be7982013-03-21 14:03:16 +0000288 unsigned int tmp;
Maxime Bizone7300d02009-08-18 13:23:37 +0100289 struct cpuinfo_mips *c = &current_cpu_data;
Florian Fainelli2b5b9b72009-10-14 09:56:00 +0200290 unsigned int cpu = smp_processor_id();
Jonas Gorski13be7982013-03-21 14:03:16 +0000291 u32 chipid_reg;
Maxime Bizone7300d02009-08-18 13:23:37 +0100292
293 /* soc registers location depends on cpu type */
Jonas Gorski13be7982013-03-21 14:03:16 +0000294 chipid_reg = 0;
Maxime Bizone7300d02009-08-18 13:23:37 +0100295
296 switch (c->cputype) {
Kevin Cernekee602977b2010-10-16 14:22:30 -0700297 case CPU_BMIPS3300:
Jonas Gorski13be7982013-03-21 14:03:16 +0000298 if ((read_c0_prid() & 0xff00) != PRID_IMP_BMIPS3300_ALT)
Kevin Cernekee602977b2010-10-16 14:22:30 -0700299 __cpu_name[cpu] = "Broadcom BCM6338";
Jonas Gorski13be7982013-03-21 14:03:16 +0000300 /* fall-through */
Kevin Cernekee602977b2010-10-16 14:22:30 -0700301 case CPU_BMIPS32:
Jonas Gorski13be7982013-03-21 14:03:16 +0000302 chipid_reg = BCM_6345_PERF_BASE;
Maxime Bizone7300d02009-08-18 13:23:37 +0100303 break;
Kevin Cernekee602977b2010-10-16 14:22:30 -0700304 case CPU_BMIPS4350:
Jonas Gorski13be7982013-03-21 14:03:16 +0000305 if ((read_c0_prid() & 0xf0) == 0x10)
306 chipid_reg = BCM_6345_PERF_BASE;
307 else
308 chipid_reg = BCM_6368_PERF_BASE;
Maxime Bizone7300d02009-08-18 13:23:37 +0100309 break;
310 }
311
312 /*
313 * really early to panic, but delaying panic would not help since we
314 * will never get any working console
315 */
Jonas Gorski13be7982013-03-21 14:03:16 +0000316 if (!chipid_reg)
Maxime Bizone7300d02009-08-18 13:23:37 +0100317 panic("unsupported Broadcom CPU");
318
Jonas Gorski13be7982013-03-21 14:03:16 +0000319 /* read out CPU type */
320 tmp = bcm_readl(chipid_reg);
Maxime Bizone7300d02009-08-18 13:23:37 +0100321 bcm63xx_cpu_id = (tmp & REV_CHIPID_MASK) >> REV_CHIPID_SHIFT;
322 bcm63xx_cpu_rev = (tmp & REV_REVID_MASK) >> REV_REVID_SHIFT;
323
Jonas Gorski13be7982013-03-21 14:03:16 +0000324 switch (bcm63xx_cpu_id) {
325 case BCM6328_CPU_ID:
326 bcm63xx_regs_base = bcm6328_regs_base;
327 bcm63xx_irqs = bcm6328_irqs;
328 break;
329 case BCM6338_CPU_ID:
330 bcm63xx_regs_base = bcm6338_regs_base;
331 bcm63xx_irqs = bcm6338_irqs;
332 break;
333 case BCM6345_CPU_ID:
334 bcm63xx_regs_base = bcm6345_regs_base;
335 bcm63xx_irqs = bcm6345_irqs;
336 break;
337 case BCM6348_CPU_ID:
338 bcm63xx_regs_base = bcm6348_regs_base;
339 bcm63xx_irqs = bcm6348_irqs;
340 break;
341 case BCM6358_CPU_ID:
342 bcm63xx_regs_base = bcm6358_regs_base;
343 bcm63xx_irqs = bcm6358_irqs;
344 break;
Jonas Gorski2c8aaf72013-03-21 14:03:17 +0000345 case BCM6362_CPU_ID:
346 bcm63xx_regs_base = bcm6362_regs_base;
347 bcm63xx_irqs = bcm6362_irqs;
348 break;
Jonas Gorski13be7982013-03-21 14:03:16 +0000349 case BCM6368_CPU_ID:
350 bcm63xx_regs_base = bcm6368_regs_base;
351 bcm63xx_irqs = bcm6368_irqs;
352 break;
353 default:
354 panic("unsupported broadcom CPU %x", bcm63xx_cpu_id);
355 break;
356 }
Maxime Bizone7300d02009-08-18 13:23:37 +0100357
358 bcm63xx_cpu_freq = detect_cpu_clock();
359 bcm63xx_memory_size = detect_memory_size();
360
361 printk(KERN_INFO "Detected Broadcom 0x%04x CPU revision %02x\n",
362 bcm63xx_cpu_id, bcm63xx_cpu_rev);
363 printk(KERN_INFO "CPU frequency is %u MHz\n",
364 bcm63xx_cpu_freq / 1000000);
365 printk(KERN_INFO "%uMB of RAM installed\n",
366 bcm63xx_memory_size >> 20);
367}