b7c041f60df4b5fd83ad1116f80ad78eecb9eccb
[openwrt.git] / target / linux / brcm63xx / files / arch / mips / bcm63xx / cpu.c
1 /*
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 */
8
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/cpu.h>
12 #include <bcm63xx_cpu.h>
13 #include <bcm63xx_regs.h>
14 #include <bcm63xx_io.h>
15 #include <bcm63xx_irq.h>
16
17 const unsigned long *bcm63xx_regs_base;
18 EXPORT_SYMBOL(bcm63xx_regs_base);
19
20 const int *bcm63xx_irqs;
21 EXPORT_SYMBOL(bcm63xx_irqs);
22
23 static u16 bcm63xx_cpu_id;
24 static u16 bcm63xx_cpu_rev;
25 static unsigned int bcm63xx_cpu_freq;
26 static unsigned int bcm63xx_memory_size;
27
28 /*
29 * 6338 register sets and irqs
30 */
31
32 static const unsigned long bcm96338_regs_base[] = {
33 [RSET_PERF] = BCM_6338_PERF_BASE,
34 [RSET_TIMER] = BCM_6338_TIMER_BASE,
35 [RSET_WDT] = BCM_6338_WDT_BASE,
36 [RSET_UART0] = BCM_6338_UART0_BASE,
37 [RSET_GPIO] = BCM_6338_GPIO_BASE,
38 [RSET_SPI] = BCM_6338_SPI_BASE,
39 };
40
41 static const int bcm96338_irqs[] = {
42 [IRQ_TIMER] = BCM_6338_TIMER_IRQ,
43 [IRQ_UART0] = BCM_6338_UART0_IRQ,
44 [IRQ_DSL] = BCM_6338_DSL_IRQ,
45 [IRQ_ENET0] = BCM_6338_ENET0_IRQ,
46 [IRQ_ENET_PHY] = BCM_6338_ENET_PHY_IRQ,
47 [IRQ_ENET0_RXDMA] = BCM_6338_ENET0_RXDMA_IRQ,
48 [IRQ_ENET0_TXDMA] = BCM_6338_ENET0_TXDMA_IRQ,
49 };
50
51 /*
52 * 6348 register sets and irqs
53 */
54 static const unsigned long bcm96348_regs_base[] = {
55 [RSET_DSL_LMEM] = BCM_6348_DSL_LMEM_BASE,
56 [RSET_PERF] = BCM_6348_PERF_BASE,
57 [RSET_TIMER] = BCM_6348_TIMER_BASE,
58 [RSET_WDT] = BCM_6348_WDT_BASE,
59 [RSET_UART0] = BCM_6348_UART0_BASE,
60 [RSET_GPIO] = BCM_6348_GPIO_BASE,
61 [RSET_SPI] = BCM_6348_SPI_BASE,
62 [RSET_OHCI0] = BCM_6348_OHCI0_BASE,
63 [RSET_OHCI_PRIV] = BCM_6348_OHCI_PRIV_BASE,
64 [RSET_USBH_PRIV] = BCM_6348_USBH_PRIV_BASE,
65 [RSET_MPI] = BCM_6348_MPI_BASE,
66 [RSET_PCMCIA] = BCM_6348_PCMCIA_BASE,
67 [RSET_SDRAM] = BCM_6348_SDRAM_BASE,
68 [RSET_DSL] = BCM_6348_DSL_BASE,
69 [RSET_ENET0] = BCM_6348_ENET0_BASE,
70 [RSET_ENET1] = BCM_6348_ENET1_BASE,
71 [RSET_ENETDMA] = BCM_6348_ENETDMA_BASE,
72 [RSET_MEMC] = BCM_6348_MEMC_BASE,
73 [RSET_DDR] = BCM_6348_DDR_BASE,
74 };
75
76 static const int bcm96348_irqs[] = {
77 [IRQ_TIMER] = BCM_6348_TIMER_IRQ,
78 [IRQ_UART0] = BCM_6348_UART0_IRQ,
79 [IRQ_DSL] = BCM_6348_DSL_IRQ,
80 [IRQ_ENET0] = BCM_6348_ENET0_IRQ,
81 [IRQ_ENET1] = BCM_6348_ENET1_IRQ,
82 [IRQ_ENET_PHY] = BCM_6348_ENET_PHY_IRQ,
83 [IRQ_OHCI0] = BCM_6348_OHCI0_IRQ,
84 [IRQ_PCMCIA] = BCM_6348_PCMCIA_IRQ,
85 [IRQ_ENET0_RXDMA] = BCM_6348_ENET0_RXDMA_IRQ,
86 [IRQ_ENET0_TXDMA] = BCM_6348_ENET0_TXDMA_IRQ,
87 [IRQ_ENET1_RXDMA] = BCM_6348_ENET1_RXDMA_IRQ,
88 [IRQ_ENET1_TXDMA] = BCM_6348_ENET1_TXDMA_IRQ,
89 [IRQ_PCI] = BCM_6348_PCI_IRQ,
90 };
91
92 /*
93 * 6358 register sets and irqs
94 */
95 static const unsigned long bcm96358_regs_base[] = {
96 [RSET_DSL_LMEM] = BCM_6358_DSL_LMEM_BASE,
97 [RSET_PERF] = BCM_6358_PERF_BASE,
98 [RSET_TIMER] = BCM_6358_TIMER_BASE,
99 [RSET_WDT] = BCM_6358_WDT_BASE,
100 [RSET_UART0] = BCM_6358_UART0_BASE,
101 [RSET_GPIO] = BCM_6358_GPIO_BASE,
102 [RSET_SPI] = BCM_6358_SPI_BASE,
103 [RSET_OHCI0] = BCM_6358_OHCI0_BASE,
104 [RSET_EHCI0] = BCM_6358_EHCI0_BASE,
105 [RSET_OHCI_PRIV] = BCM_6358_OHCI_PRIV_BASE,
106 [RSET_USBH_PRIV] = BCM_6358_USBH_PRIV_BASE,
107 [RSET_MPI] = BCM_6358_MPI_BASE,
108 [RSET_PCMCIA] = BCM_6358_PCMCIA_BASE,
109 [RSET_SDRAM] = BCM_6358_SDRAM_BASE,
110 [RSET_DSL] = BCM_6358_DSL_BASE,
111 [RSET_ENET0] = BCM_6358_ENET0_BASE,
112 [RSET_ENET1] = BCM_6358_ENET1_BASE,
113 [RSET_ENETDMA] = BCM_6358_ENETDMA_BASE,
114 [RSET_MEMC] = BCM_6358_MEMC_BASE,
115 [RSET_DDR] = BCM_6358_DDR_BASE,
116 };
117
118 static const int bcm96358_irqs[] = {
119 [IRQ_TIMER] = BCM_6358_TIMER_IRQ,
120 [IRQ_UART0] = BCM_6358_UART0_IRQ,
121 [IRQ_DSL] = BCM_6358_DSL_IRQ,
122 [IRQ_ENET0] = BCM_6358_ENET0_IRQ,
123 [IRQ_ENET1] = BCM_6358_ENET1_IRQ,
124 [IRQ_ENET_PHY] = BCM_6358_ENET_PHY_IRQ,
125 [IRQ_OHCI0] = BCM_6358_OHCI0_IRQ,
126 [IRQ_EHCI0] = BCM_6358_EHCI0_IRQ,
127 [IRQ_PCMCIA] = BCM_6358_PCMCIA_IRQ,
128 [IRQ_ENET0_RXDMA] = BCM_6358_ENET0_RXDMA_IRQ,
129 [IRQ_ENET0_TXDMA] = BCM_6358_ENET0_TXDMA_IRQ,
130 [IRQ_ENET1_RXDMA] = BCM_6358_ENET1_RXDMA_IRQ,
131 [IRQ_ENET1_TXDMA] = BCM_6358_ENET1_TXDMA_IRQ,
132 [IRQ_PCI] = BCM_6358_PCI_IRQ,
133 };
134
135 u16 __bcm63xx_get_cpu_id(void)
136 {
137 return bcm63xx_cpu_id;
138 }
139
140 EXPORT_SYMBOL(__bcm63xx_get_cpu_id);
141
142 u16 bcm63xx_get_cpu_rev(void)
143 {
144 return bcm63xx_cpu_rev;
145 }
146
147 EXPORT_SYMBOL(bcm63xx_get_cpu_rev);
148
149 unsigned int bcm63xx_get_cpu_freq(void)
150 {
151 return bcm63xx_cpu_freq;
152 }
153
154 unsigned int bcm63xx_get_memory_size(void)
155 {
156 return bcm63xx_memory_size;
157 }
158
159 static unsigned int detect_cpu_clock(void)
160 {
161 unsigned int tmp, n1 = 0, n2 = 0, m1 = 0;
162
163 if (BCMCPU_IS_6338()) {
164 return 240000000;
165 }
166
167 /*
168 * frequency depends on PLL configuration:
169 */
170 if (BCMCPU_IS_6348()) {
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;
176 n1 += 1;
177 n2 += 2;
178 m1 += 1;
179 }
180
181 if (BCMCPU_IS_6358()) {
182 /* 16MHz * N1 * N2 / M1_CPU */
183 tmp = bcm_ddr_readl(DDR_DMIPSPLLCFG_REG);
184 n1 = (tmp & DMIPSPLLCFG_N1_MASK) >> DMIPSPLLCFG_N1_SHIFT;
185 n2 = (tmp & DMIPSPLLCFG_N2_MASK) >> DMIPSPLLCFG_N2_SHIFT;
186 m1 = (tmp & DMIPSPLLCFG_M1_MASK) >> DMIPSPLLCFG_M1_SHIFT;
187 }
188
189 return (16 * 1000000 * n1 * n2) / m1;
190 }
191
192 /*
193 * attempt to detect the amount of memory installed
194 */
195 static unsigned int detect_memory_size(void)
196 {
197 unsigned int cols = 0, rows = 0, is_32bits = 0, banks = 0;
198 u32 val;
199
200 if (BCMCPU_IS_6338() || BCMCPU_IS_6348()) {
201 val = bcm_sdram_readl(SDRAM_CFG_REG);
202 rows = (val & SDRAM_CFG_ROW_MASK) >> SDRAM_CFG_ROW_SHIFT;
203 cols = (val & SDRAM_CFG_COL_MASK) >> SDRAM_CFG_COL_SHIFT;
204 is_32bits = (val & SDRAM_CFG_32B_MASK) ? 1 : 0;
205 banks = (val & SDRAM_CFG_BANK_MASK) ? 2 : 1;
206 }
207
208 if (BCMCPU_IS_6358()) {
209 val = bcm_memc_readl(MEMC_CFG_REG);
210 rows = (val & MEMC_CFG_ROW_MASK) >> MEMC_CFG_ROW_SHIFT;
211 cols = (val & MEMC_CFG_COL_MASK) >> MEMC_CFG_COL_SHIFT;
212 is_32bits = (val & MEMC_CFG_32B_MASK) ? 0 : 1;
213 banks = 2;
214 }
215
216 /* 0 => 11 address bits ... 2 => 13 address bits */
217 rows += 11;
218
219 /* 0 => 8 address bits ... 2 => 10 address bits */
220 cols += 8;
221
222 return 1 << (cols + rows + (is_32bits + 1) + banks);
223 }
224
225 void __init bcm63xx_cpu_init(void)
226 {
227 unsigned int tmp, expected_cpu_id;
228 struct cpuinfo_mips *c = &current_cpu_data;
229
230 /* soc registers location depends on cpu type */
231 expected_cpu_id = 0;
232
233 switch (c->cputype) {
234 case CPU_BCM6338:
235 expected_cpu_id = BCM6338_CPU_ID;
236 bcm63xx_regs_base = bcm96338_regs_base;
237 bcm63xx_irqs = bcm96338_irqs;
238 break;
239 case CPU_BCM6348:
240 expected_cpu_id = BCM6348_CPU_ID;
241 bcm63xx_regs_base = bcm96348_regs_base;
242 bcm63xx_irqs = bcm96348_irqs;
243 break;
244 case CPU_BCM6358:
245 expected_cpu_id = BCM6358_CPU_ID;
246 bcm63xx_regs_base = bcm96358_regs_base;
247 bcm63xx_irqs = bcm96358_irqs;
248 break;
249 }
250
251 /* really early to panic, but delaying panic would not help
252 * since we will never get any working console */
253 if (!expected_cpu_id)
254 panic("unsupported Broadcom CPU");
255
256 /*
257 * bcm63xx_regs_base is set, we can access soc registers
258 */
259
260 /* double check CPU type */
261 tmp = bcm_perf_readl(PERF_REV_REG);
262 bcm63xx_cpu_id = (tmp & REV_CHIPID_MASK) >> REV_CHIPID_SHIFT;
263 bcm63xx_cpu_rev = (tmp & REV_REVID_MASK) >> REV_REVID_SHIFT;
264
265 if (bcm63xx_cpu_id != expected_cpu_id)
266 panic("bcm63xx CPU id mismatch");
267
268 bcm63xx_cpu_freq = detect_cpu_clock();
269 bcm63xx_memory_size = detect_memory_size();
270
271 printk(KERN_INFO "Detected Broadcom 0x%04x CPU revision %02x\n",
272 bcm63xx_cpu_id, bcm63xx_cpu_rev);
273 printk(KERN_INFO "CPU frequency is %u MHz\n",
274 bcm63xx_cpu_freq);
275 printk(KERN_INFO "%uMB of RAM installed\n",
276 bcm63xx_memory_size >> 20);
277 }
This page took 0.04954 seconds and 3 git commands to generate.