blob: 8bd5133eafd19014f538c87786789db30de07ee2 [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;
28static u16 bcm63xx_cpu_rev;
29static unsigned int bcm63xx_cpu_freq;
30static unsigned int bcm63xx_memory_size;
31
Maxime Bizonec68c522011-11-04 19:09:29 +010032static const unsigned long bcm6338_regs_base[] = {
33 __GEN_CPU_REGS_TABLE(6338)
Maxime Bizone7300d02009-08-18 13:23:37 +010034};
35
Maxime Bizonec68c522011-11-04 19:09:29 +010036static const int bcm6338_irqs[] = {
37 __GEN_CPU_IRQ_TABLE(6338)
Maxime Bizone7300d02009-08-18 13:23:37 +010038};
39
Maxime Bizonec68c522011-11-04 19:09:29 +010040static const unsigned long bcm6345_regs_base[] = {
41 __GEN_CPU_REGS_TABLE(6345)
Maxime Bizone7300d02009-08-18 13:23:37 +010042};
43
Maxime Bizonec68c522011-11-04 19:09:29 +010044static const int bcm6345_irqs[] = {
45 __GEN_CPU_IRQ_TABLE(6345)
Maxime Bizone7300d02009-08-18 13:23:37 +010046};
47
Maxime Bizonec68c522011-11-04 19:09:29 +010048static const unsigned long bcm6348_regs_base[] = {
49 __GEN_CPU_REGS_TABLE(6348)
Maxime Bizone7300d02009-08-18 13:23:37 +010050};
51
Maxime Bizonec68c522011-11-04 19:09:29 +010052static const int bcm6348_irqs[] = {
53 __GEN_CPU_IRQ_TABLE(6348)
54
Maxime Bizone7300d02009-08-18 13:23:37 +010055};
56
Maxime Bizonec68c522011-11-04 19:09:29 +010057static const unsigned long bcm6358_regs_base[] = {
58 __GEN_CPU_REGS_TABLE(6358)
Maxime Bizone7300d02009-08-18 13:23:37 +010059};
60
Maxime Bizonec68c522011-11-04 19:09:29 +010061static const int bcm6358_irqs[] = {
62 __GEN_CPU_IRQ_TABLE(6358)
63
Maxime Bizone7300d02009-08-18 13:23:37 +010064};
65
66u16 __bcm63xx_get_cpu_id(void)
67{
68 return bcm63xx_cpu_id;
69}
70
71EXPORT_SYMBOL(__bcm63xx_get_cpu_id);
72
73u16 bcm63xx_get_cpu_rev(void)
74{
75 return bcm63xx_cpu_rev;
76}
77
78EXPORT_SYMBOL(bcm63xx_get_cpu_rev);
79
80unsigned int bcm63xx_get_cpu_freq(void)
81{
82 return bcm63xx_cpu_freq;
83}
84
85unsigned int bcm63xx_get_memory_size(void)
86{
87 return bcm63xx_memory_size;
88}
89
90static unsigned int detect_cpu_clock(void)
91{
92 unsigned int tmp, n1 = 0, n2 = 0, m1 = 0;
93
94 /* BCM6338 has a fixed 240 Mhz frequency */
95 if (BCMCPU_IS_6338())
96 return 240000000;
97
98 /* BCM6345 has a fixed 140Mhz frequency */
99 if (BCMCPU_IS_6345())
100 return 140000000;
101
102 /*
103 * frequency depends on PLL configuration:
104 */
105 if (BCMCPU_IS_6348()) {
106 /* 16MHz * (N1 + 1) * (N2 + 2) / (M1_CPU + 1) */
107 tmp = bcm_perf_readl(PERF_MIPSPLLCTL_REG);
108 n1 = (tmp & MIPSPLLCTL_N1_MASK) >> MIPSPLLCTL_N1_SHIFT;
109 n2 = (tmp & MIPSPLLCTL_N2_MASK) >> MIPSPLLCTL_N2_SHIFT;
110 m1 = (tmp & MIPSPLLCTL_M1CPU_MASK) >> MIPSPLLCTL_M1CPU_SHIFT;
111 n1 += 1;
112 n2 += 2;
113 m1 += 1;
114 }
115
116 if (BCMCPU_IS_6358()) {
117 /* 16MHz * N1 * N2 / M1_CPU */
118 tmp = bcm_ddr_readl(DDR_DMIPSPLLCFG_REG);
119 n1 = (tmp & DMIPSPLLCFG_N1_MASK) >> DMIPSPLLCFG_N1_SHIFT;
120 n2 = (tmp & DMIPSPLLCFG_N2_MASK) >> DMIPSPLLCFG_N2_SHIFT;
121 m1 = (tmp & DMIPSPLLCFG_M1_MASK) >> DMIPSPLLCFG_M1_SHIFT;
122 }
123
124 return (16 * 1000000 * n1 * n2) / m1;
125}
126
127/*
128 * attempt to detect the amount of memory installed
129 */
130static unsigned int detect_memory_size(void)
131{
132 unsigned int cols = 0, rows = 0, is_32bits = 0, banks = 0;
133 u32 val;
134
135 if (BCMCPU_IS_6345())
136 return (8 * 1024 * 1024);
137
138 if (BCMCPU_IS_6338() || BCMCPU_IS_6348()) {
139 val = bcm_sdram_readl(SDRAM_CFG_REG);
140 rows = (val & SDRAM_CFG_ROW_MASK) >> SDRAM_CFG_ROW_SHIFT;
141 cols = (val & SDRAM_CFG_COL_MASK) >> SDRAM_CFG_COL_SHIFT;
142 is_32bits = (val & SDRAM_CFG_32B_MASK) ? 1 : 0;
143 banks = (val & SDRAM_CFG_BANK_MASK) ? 2 : 1;
144 }
145
146 if (BCMCPU_IS_6358()) {
147 val = bcm_memc_readl(MEMC_CFG_REG);
148 rows = (val & MEMC_CFG_ROW_MASK) >> MEMC_CFG_ROW_SHIFT;
149 cols = (val & MEMC_CFG_COL_MASK) >> MEMC_CFG_COL_SHIFT;
150 is_32bits = (val & MEMC_CFG_32B_MASK) ? 0 : 1;
151 banks = 2;
152 }
153
154 /* 0 => 11 address bits ... 2 => 13 address bits */
155 rows += 11;
156
157 /* 0 => 8 address bits ... 2 => 10 address bits */
158 cols += 8;
159
160 return 1 << (cols + rows + (is_32bits + 1) + banks);
161}
162
163void __init bcm63xx_cpu_init(void)
164{
165 unsigned int tmp, expected_cpu_id;
166 struct cpuinfo_mips *c = &current_cpu_data;
Florian Fainelli2b5b9b72009-10-14 09:56:00 +0200167 unsigned int cpu = smp_processor_id();
Maxime Bizone7300d02009-08-18 13:23:37 +0100168
169 /* soc registers location depends on cpu type */
170 expected_cpu_id = 0;
171
172 switch (c->cputype) {
Kevin Cernekee602977b2010-10-16 14:22:30 -0700173 case CPU_BMIPS3300:
174 if ((read_c0_prid() & 0xff00) == PRID_IMP_BMIPS3300_ALT) {
175 expected_cpu_id = BCM6348_CPU_ID;
Maxime Bizonec68c522011-11-04 19:09:29 +0100176 bcm63xx_regs_base = bcm6348_regs_base;
177 bcm63xx_irqs = bcm6348_irqs;
Kevin Cernekee602977b2010-10-16 14:22:30 -0700178 } else {
179 __cpu_name[cpu] = "Broadcom BCM6338";
180 expected_cpu_id = BCM6338_CPU_ID;
Maxime Bizonec68c522011-11-04 19:09:29 +0100181 bcm63xx_regs_base = bcm6338_regs_base;
182 bcm63xx_irqs = bcm6338_irqs;
Kevin Cernekee602977b2010-10-16 14:22:30 -0700183 }
Maxime Bizone7300d02009-08-18 13:23:37 +0100184 break;
Kevin Cernekee602977b2010-10-16 14:22:30 -0700185 case CPU_BMIPS32:
Maxime Bizone7300d02009-08-18 13:23:37 +0100186 expected_cpu_id = BCM6345_CPU_ID;
Maxime Bizonec68c522011-11-04 19:09:29 +0100187 bcm63xx_regs_base = bcm6345_regs_base;
188 bcm63xx_irqs = bcm6345_irqs;
Maxime Bizone7300d02009-08-18 13:23:37 +0100189 break;
Kevin Cernekee602977b2010-10-16 14:22:30 -0700190 case CPU_BMIPS4350:
Maxime Bizone7300d02009-08-18 13:23:37 +0100191 expected_cpu_id = BCM6358_CPU_ID;
Maxime Bizonec68c522011-11-04 19:09:29 +0100192 bcm63xx_regs_base = bcm6358_regs_base;
193 bcm63xx_irqs = bcm6358_irqs;
Maxime Bizone7300d02009-08-18 13:23:37 +0100194 break;
195 }
196
197 /*
198 * really early to panic, but delaying panic would not help since we
199 * will never get any working console
200 */
201 if (!expected_cpu_id)
202 panic("unsupported Broadcom CPU");
203
204 /*
205 * bcm63xx_regs_base is set, we can access soc registers
206 */
207
208 /* double check CPU type */
209 tmp = bcm_perf_readl(PERF_REV_REG);
210 bcm63xx_cpu_id = (tmp & REV_CHIPID_MASK) >> REV_CHIPID_SHIFT;
211 bcm63xx_cpu_rev = (tmp & REV_REVID_MASK) >> REV_REVID_SHIFT;
212
213 if (bcm63xx_cpu_id != expected_cpu_id)
214 panic("bcm63xx CPU id mismatch");
215
216 bcm63xx_cpu_freq = detect_cpu_clock();
217 bcm63xx_memory_size = detect_memory_size();
218
219 printk(KERN_INFO "Detected Broadcom 0x%04x CPU revision %02x\n",
220 bcm63xx_cpu_id, bcm63xx_cpu_rev);
221 printk(KERN_INFO "CPU frequency is %u MHz\n",
222 bcm63xx_cpu_freq / 1000000);
223 printk(KERN_INFO "%uMB of RAM installed\n",
224 bcm63xx_memory_size >> 20);
225}