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
6 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
7 * Copyright (C) 2009 Florian Fainelli <florian@openwrt.org>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/cpu.h>
14 #include <asm/cpu-info.h>
15 #include <asm/mipsregs.h>
16 #include <bcm63xx_cpu.h>
17 #include <bcm63xx_regs.h>
18 #include <bcm63xx_io.h>
19 #include <bcm63xx_irq.h>
21 const unsigned long *bcm63xx_regs_base
;
22 EXPORT_SYMBOL(bcm63xx_regs_base
);
24 const int *bcm63xx_irqs
;
25 EXPORT_SYMBOL(bcm63xx_irqs
);
27 static u16 bcm63xx_cpu_id
;
28 static u8 bcm63xx_cpu_rev
;
29 static unsigned int bcm63xx_cpu_freq
;
30 static unsigned int bcm63xx_memory_size
;
32 static const unsigned long bcm3368_regs_base
[] = {
33 __GEN_CPU_REGS_TABLE(3368)
36 static const int bcm3368_irqs
[] = {
37 __GEN_CPU_IRQ_TABLE(3368)
40 static const unsigned long bcm6328_regs_base
[] = {
41 __GEN_CPU_REGS_TABLE(6328)
44 static const int bcm6328_irqs
[] = {
45 __GEN_CPU_IRQ_TABLE(6328)
48 static const unsigned long bcm6338_regs_base
[] = {
49 __GEN_CPU_REGS_TABLE(6338)
52 static const int bcm6338_irqs
[] = {
53 __GEN_CPU_IRQ_TABLE(6338)
56 static const unsigned long bcm6345_regs_base
[] = {
57 __GEN_CPU_REGS_TABLE(6345)
60 static const int bcm6345_irqs
[] = {
61 __GEN_CPU_IRQ_TABLE(6345)
64 static const unsigned long bcm6348_regs_base
[] = {
65 __GEN_CPU_REGS_TABLE(6348)
68 static const int bcm6348_irqs
[] = {
69 __GEN_CPU_IRQ_TABLE(6348)
73 static const unsigned long bcm6358_regs_base
[] = {
74 __GEN_CPU_REGS_TABLE(6358)
77 static const int bcm6358_irqs
[] = {
78 __GEN_CPU_IRQ_TABLE(6358)
82 static const unsigned long bcm6362_regs_base
[] = {
83 __GEN_CPU_REGS_TABLE(6362)
86 static const int bcm6362_irqs
[] = {
87 __GEN_CPU_IRQ_TABLE(6362)
91 static const unsigned long bcm6368_regs_base
[] = {
92 __GEN_CPU_REGS_TABLE(6368)
95 static const int bcm6368_irqs
[] = {
96 __GEN_CPU_IRQ_TABLE(6368)
100 u16
__bcm63xx_get_cpu_id(void)
102 return bcm63xx_cpu_id
;
105 EXPORT_SYMBOL(__bcm63xx_get_cpu_id
);
107 u8
bcm63xx_get_cpu_rev(void)
109 return bcm63xx_cpu_rev
;
112 EXPORT_SYMBOL(bcm63xx_get_cpu_rev
);
114 unsigned int bcm63xx_get_cpu_freq(void)
116 return bcm63xx_cpu_freq
;
119 unsigned int bcm63xx_get_memory_size(void)
121 return bcm63xx_memory_size
;
124 static unsigned int detect_cpu_clock(void)
126 u16 cpu_id
= bcm63xx_get_cpu_id();
134 unsigned int tmp
, mips_pll_fcvo
;
136 tmp
= bcm_misc_readl(MISC_STRAPBUS_6328_REG
);
137 mips_pll_fcvo
= (tmp
& STRAPBUS_6328_FCVO_MASK
)
138 >> STRAPBUS_6328_FCVO_SHIFT
;
140 switch (mips_pll_fcvo
) {
160 /* BCM6338 has a fixed 240 Mhz frequency */
164 /* BCM6345 has a fixed 140Mhz frequency */
169 unsigned int tmp
, n1
, n2
, m1
;
171 /* 16MHz * (N1 + 1) * (N2 + 2) / (M1_CPU + 1) */
172 tmp
= bcm_perf_readl(PERF_MIPSPLLCTL_REG
);
173 n1
= (tmp
& MIPSPLLCTL_N1_MASK
) >> MIPSPLLCTL_N1_SHIFT
;
174 n2
= (tmp
& MIPSPLLCTL_N2_MASK
) >> MIPSPLLCTL_N2_SHIFT
;
175 m1
= (tmp
& MIPSPLLCTL_M1CPU_MASK
) >> MIPSPLLCTL_M1CPU_SHIFT
;
179 return (16 * 1000000 * n1
* n2
) / m1
;
184 unsigned int tmp
, n1
, n2
, m1
;
186 /* 16MHz * N1 * N2 / M1_CPU */
187 tmp
= bcm_ddr_readl(DDR_DMIPSPLLCFG_REG
);
188 n1
= (tmp
& DMIPSPLLCFG_N1_MASK
) >> DMIPSPLLCFG_N1_SHIFT
;
189 n2
= (tmp
& DMIPSPLLCFG_N2_MASK
) >> DMIPSPLLCFG_N2_SHIFT
;
190 m1
= (tmp
& DMIPSPLLCFG_M1_MASK
) >> DMIPSPLLCFG_M1_SHIFT
;
191 return (16 * 1000000 * n1
* n2
) / m1
;
196 unsigned int tmp
, mips_pll_fcvo
;
198 tmp
= bcm_misc_readl(MISC_STRAPBUS_6362_REG
);
199 mips_pll_fcvo
= (tmp
& STRAPBUS_6362_FCVO_MASK
)
200 >> STRAPBUS_6362_FCVO_SHIFT
;
201 switch (mips_pll_fcvo
) {
232 unsigned int tmp
, p1
, p2
, ndiv
, m1
;
234 /* (64MHz / P1) * P2 * NDIV / M1_CPU */
235 tmp
= bcm_ddr_readl(DDR_DMIPSPLLCFG_6368_REG
);
237 p1
= (tmp
& DMIPSPLLCFG_6368_P1_MASK
) >>
238 DMIPSPLLCFG_6368_P1_SHIFT
;
240 p2
= (tmp
& DMIPSPLLCFG_6368_P2_MASK
) >>
241 DMIPSPLLCFG_6368_P2_SHIFT
;
243 ndiv
= (tmp
& DMIPSPLLCFG_6368_NDIV_MASK
) >>
244 DMIPSPLLCFG_6368_NDIV_SHIFT
;
246 tmp
= bcm_ddr_readl(DDR_DMIPSPLLDIV_6368_REG
);
247 m1
= (tmp
& DMIPSPLLDIV_6368_MDIV_MASK
) >>
248 DMIPSPLLDIV_6368_MDIV_SHIFT
;
250 return (((64 * 1000000) / p1
) * p2
* ndiv
) / m1
;
254 panic("Failed to detect clock for CPU with id=%04X\n", cpu_id
);
259 * attempt to detect the amount of memory installed
261 static unsigned int detect_memory_size(void)
263 unsigned int cols
= 0, rows
= 0, is_32bits
= 0, banks
= 0;
266 if (BCMCPU_IS_6328() || BCMCPU_IS_6362())
267 return bcm_ddr_readl(DDR_CSEND_REG
) << 24;
269 if (BCMCPU_IS_6345()) {
270 val
= bcm_sdram_readl(SDRAM_MBASE_REG
);
271 return (val
* 8 * 1024 * 1024);
274 if (BCMCPU_IS_6338() || BCMCPU_IS_6348()) {
275 val
= bcm_sdram_readl(SDRAM_CFG_REG
);
276 rows
= (val
& SDRAM_CFG_ROW_MASK
) >> SDRAM_CFG_ROW_SHIFT
;
277 cols
= (val
& SDRAM_CFG_COL_MASK
) >> SDRAM_CFG_COL_SHIFT
;
278 is_32bits
= (val
& SDRAM_CFG_32B_MASK
) ? 1 : 0;
279 banks
= (val
& SDRAM_CFG_BANK_MASK
) ? 2 : 1;
282 if (BCMCPU_IS_3368() || BCMCPU_IS_6358() || BCMCPU_IS_6368()) {
283 val
= bcm_memc_readl(MEMC_CFG_REG
);
284 rows
= (val
& MEMC_CFG_ROW_MASK
) >> MEMC_CFG_ROW_SHIFT
;
285 cols
= (val
& MEMC_CFG_COL_MASK
) >> MEMC_CFG_COL_SHIFT
;
286 is_32bits
= (val
& MEMC_CFG_32B_MASK
) ? 0 : 1;
290 /* 0 => 11 address bits ... 2 => 13 address bits */
293 /* 0 => 8 address bits ... 2 => 10 address bits */
296 return 1 << (cols
+ rows
+ (is_32bits
+ 1) + banks
);
299 void __init
bcm63xx_cpu_init(void)
302 struct cpuinfo_mips
*c
= ¤t_cpu_data
;
303 unsigned int cpu
= smp_processor_id();
306 /* soc registers location depends on cpu type */
309 switch (c
->cputype
) {
311 if ((read_c0_prid() & PRID_IMP_MASK
) != PRID_IMP_BMIPS3300_ALT
)
312 __cpu_name
[cpu
] = "Broadcom BCM6338";
315 chipid_reg
= BCM_6345_PERF_BASE
;
318 switch ((read_c0_prid() & PRID_REV_MASK
)) {
320 chipid_reg
= BCM_3368_PERF_BASE
;
323 chipid_reg
= BCM_6345_PERF_BASE
;
326 chipid_reg
= BCM_6368_PERF_BASE
;
333 * really early to panic, but delaying panic would not help since we
334 * will never get any working console
337 panic("unsupported Broadcom CPU");
339 /* read out CPU type */
340 tmp
= bcm_readl(chipid_reg
);
341 bcm63xx_cpu_id
= (tmp
& REV_CHIPID_MASK
) >> REV_CHIPID_SHIFT
;
342 bcm63xx_cpu_rev
= (tmp
& REV_REVID_MASK
) >> REV_REVID_SHIFT
;
344 switch (bcm63xx_cpu_id
) {
346 bcm63xx_regs_base
= bcm3368_regs_base
;
347 bcm63xx_irqs
= bcm3368_irqs
;
350 bcm63xx_regs_base
= bcm6328_regs_base
;
351 bcm63xx_irqs
= bcm6328_irqs
;
354 bcm63xx_regs_base
= bcm6338_regs_base
;
355 bcm63xx_irqs
= bcm6338_irqs
;
358 bcm63xx_regs_base
= bcm6345_regs_base
;
359 bcm63xx_irqs
= bcm6345_irqs
;
362 bcm63xx_regs_base
= bcm6348_regs_base
;
363 bcm63xx_irqs
= bcm6348_irqs
;
366 bcm63xx_regs_base
= bcm6358_regs_base
;
367 bcm63xx_irqs
= bcm6358_irqs
;
370 bcm63xx_regs_base
= bcm6362_regs_base
;
371 bcm63xx_irqs
= bcm6362_irqs
;
374 bcm63xx_regs_base
= bcm6368_regs_base
;
375 bcm63xx_irqs
= bcm6368_irqs
;
378 panic("unsupported broadcom CPU %x", bcm63xx_cpu_id
);
382 bcm63xx_cpu_freq
= detect_cpu_clock();
383 bcm63xx_memory_size
= detect_memory_size();
385 printk(KERN_INFO
"Detected Broadcom 0x%04x CPU revision %02x\n",
386 bcm63xx_cpu_id
, bcm63xx_cpu_rev
);
387 printk(KERN_INFO
"CPU frequency is %u MHz\n",
388 bcm63xx_cpu_freq
/ 1000000);
389 printk(KERN_INFO
"%uMB of RAM installed\n",
390 bcm63xx_memory_size
>> 20);