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 * 2009 Florian Fainelli <florian@openwrt.org>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/cpu.h>
13 #include <bcm63xx_cpu.h>
14 #include <bcm63xx_regs.h>
15 #include <bcm63xx_io.h>
16 #include <bcm63xx_irq.h>
18 const unsigned long *bcm63xx_regs_base
;
19 EXPORT_SYMBOL(bcm63xx_regs_base
);
21 const int *bcm63xx_irqs
;
22 EXPORT_SYMBOL(bcm63xx_irqs
);
24 const unsigned long *bcm63xx_regs_spi
;
25 EXPORT_SYMBOL(bcm63xx_regs_spi
);
27 static u16 bcm63xx_cpu_id
;
28 static u16 bcm63xx_cpu_rev
;
29 static unsigned int bcm63xx_cpu_freq
;
30 static unsigned int bcm63xx_memory_size
;
33 * 6338 register sets and irqs
36 static const unsigned long bcm96338_regs_base
[] = {
37 [RSET_PERF
] = BCM_6338_PERF_BASE
,
38 [RSET_TIMER
] = BCM_6338_TIMER_BASE
,
39 [RSET_WDT
] = BCM_6338_WDT_BASE
,
40 [RSET_UART0
] = BCM_6338_UART0_BASE
,
41 [RSET_GPIO
] = BCM_6338_GPIO_BASE
,
42 [RSET_SPI
] = BCM_6338_SPI_BASE
,
43 [RSET_MEMC
] = BCM_6338_MEMC_BASE
,
46 static const int bcm96338_irqs
[] = {
47 [IRQ_TIMER
] = BCM_6338_TIMER_IRQ
,
48 [IRQ_SPI
] = BCM_6338_SPI_IRQ
,
49 [IRQ_UART0
] = BCM_6338_UART0_IRQ
,
50 [IRQ_DSL
] = BCM_6338_DSL_IRQ
,
51 [IRQ_ENET0
] = BCM_6338_ENET0_IRQ
,
52 [IRQ_ENET_PHY
] = BCM_6338_ENET_PHY_IRQ
,
53 [IRQ_ENET0_RXDMA
] = BCM_6338_ENET0_RXDMA_IRQ
,
54 [IRQ_ENET0_TXDMA
] = BCM_6338_ENET0_TXDMA_IRQ
,
57 static const unsigned long bcm96338_regs_spi
[] = {
58 [SPI_CMD
] = SPI_BCM_6338_SPI_CMD
,
59 [SPI_INT_STATUS
] = SPI_BCM_6338_SPI_INT_STATUS
,
60 [SPI_INT_MASK_ST
] = SPI_BCM_6338_SPI_MASK_INT_ST
,
61 [SPI_INT_MASK
] = SPI_BCM_6338_SPI_INT_MASK
,
62 [SPI_ST
] = SPI_BCM_6338_SPI_ST
,
63 [SPI_CLK_CFG
] = SPI_BCM_6338_SPI_CLK_CFG
,
64 [SPI_FILL_BYTE
] = SPI_BCM_6338_SPI_FILL_BYTE
,
65 [SPI_MSG_TAIL
] = SPI_BCM_6338_SPI_MSG_TAIL
,
66 [SPI_RX_TAIL
] = SPI_BCM_6338_SPI_RX_TAIL
,
67 [SPI_MSG_CTL
] = SPI_BCM_6338_SPI_MSG_CTL
,
68 [SPI_MSG_DATA
] = SPI_BCM_6338_SPI_MSG_DATA
,
69 [SPI_RX_DATA
] = SPI_BCM_6338_SPI_RX_DATA
,
73 * 6348 register sets and irqs
75 static const unsigned long bcm96348_regs_base
[] = {
76 [RSET_DSL_LMEM
] = BCM_6348_DSL_LMEM_BASE
,
77 [RSET_PERF
] = BCM_6348_PERF_BASE
,
78 [RSET_TIMER
] = BCM_6348_TIMER_BASE
,
79 [RSET_WDT
] = BCM_6348_WDT_BASE
,
80 [RSET_UART0
] = BCM_6348_UART0_BASE
,
81 [RSET_GPIO
] = BCM_6348_GPIO_BASE
,
82 [RSET_SPI
] = BCM_6348_SPI_BASE
,
83 [RSET_OHCI0
] = BCM_6348_OHCI0_BASE
,
84 [RSET_OHCI_PRIV
] = BCM_6348_OHCI_PRIV_BASE
,
85 [RSET_USBH_PRIV
] = BCM_6348_USBH_PRIV_BASE
,
86 [RSET_MPI
] = BCM_6348_MPI_BASE
,
87 [RSET_PCMCIA
] = BCM_6348_PCMCIA_BASE
,
88 [RSET_SDRAM
] = BCM_6348_SDRAM_BASE
,
89 [RSET_DSL
] = BCM_6348_DSL_BASE
,
90 [RSET_ENET0
] = BCM_6348_ENET0_BASE
,
91 [RSET_ENET1
] = BCM_6348_ENET1_BASE
,
92 [RSET_ENETDMA
] = BCM_6348_ENETDMA_BASE
,
93 [RSET_MEMC
] = BCM_6348_MEMC_BASE
,
94 [RSET_DDR
] = BCM_6348_DDR_BASE
,
97 static const int bcm96348_irqs
[] = {
98 [IRQ_TIMER
] = BCM_6348_TIMER_IRQ
,
99 [IRQ_SPI
] = BCM_6348_SPI_IRQ
,
100 [IRQ_UART0
] = BCM_6348_UART0_IRQ
,
101 [IRQ_DSL
] = BCM_6348_DSL_IRQ
,
102 [IRQ_ENET0
] = BCM_6348_ENET0_IRQ
,
103 [IRQ_ENET1
] = BCM_6348_ENET1_IRQ
,
104 [IRQ_ENET_PHY
] = BCM_6348_ENET_PHY_IRQ
,
105 [IRQ_OHCI0
] = BCM_6348_OHCI0_IRQ
,
106 [IRQ_PCMCIA
] = BCM_6348_PCMCIA_IRQ
,
107 [IRQ_ENET0_RXDMA
] = BCM_6348_ENET0_RXDMA_IRQ
,
108 [IRQ_ENET0_TXDMA
] = BCM_6348_ENET0_TXDMA_IRQ
,
109 [IRQ_ENET1_RXDMA
] = BCM_6348_ENET1_RXDMA_IRQ
,
110 [IRQ_ENET1_TXDMA
] = BCM_6348_ENET1_TXDMA_IRQ
,
111 [IRQ_PCI
] = BCM_6348_PCI_IRQ
,
114 static const unsigned long bcm96348_regs_spi
[] = {
115 [SPI_CMD
] = SPI_BCM_6348_SPI_CMD
,
116 [SPI_INT_STATUS
] = SPI_BCM_6348_SPI_INT_STATUS
,
117 [SPI_INT_MASK_ST
] = SPI_BCM_6348_SPI_MASK_INT_ST
,
118 [SPI_INT_MASK
] = SPI_BCM_6348_SPI_INT_MASK
,
119 [SPI_ST
] = SPI_BCM_6348_SPI_ST
,
120 [SPI_CLK_CFG
] = SPI_BCM_6348_SPI_CLK_CFG
,
121 [SPI_FILL_BYTE
] = SPI_BCM_6348_SPI_FILL_BYTE
,
122 [SPI_MSG_TAIL
] = SPI_BCM_6348_SPI_MSG_TAIL
,
123 [SPI_RX_TAIL
] = SPI_BCM_6348_SPI_RX_TAIL
,
124 [SPI_MSG_CTL
] = SPI_BCM_6348_SPI_MSG_CTL
,
125 [SPI_MSG_DATA
] = SPI_BCM_6348_SPI_MSG_DATA
,
126 [SPI_RX_DATA
] = SPI_BCM_6348_SPI_RX_DATA
,
130 * 6358 register sets and irqs
132 static const unsigned long bcm96358_regs_base
[] = {
133 [RSET_DSL_LMEM
] = BCM_6358_DSL_LMEM_BASE
,
134 [RSET_PERF
] = BCM_6358_PERF_BASE
,
135 [RSET_TIMER
] = BCM_6358_TIMER_BASE
,
136 [RSET_WDT
] = BCM_6358_WDT_BASE
,
137 [RSET_UART0
] = BCM_6358_UART0_BASE
,
138 [RSET_GPIO
] = BCM_6358_GPIO_BASE
,
139 [RSET_SPI
] = BCM_6358_SPI_BASE
,
140 [RSET_OHCI0
] = BCM_6358_OHCI0_BASE
,
141 [RSET_EHCI0
] = BCM_6358_EHCI0_BASE
,
142 [RSET_OHCI_PRIV
] = BCM_6358_OHCI_PRIV_BASE
,
143 [RSET_USBH_PRIV
] = BCM_6358_USBH_PRIV_BASE
,
144 [RSET_MPI
] = BCM_6358_MPI_BASE
,
145 [RSET_PCMCIA
] = BCM_6358_PCMCIA_BASE
,
146 [RSET_SDRAM
] = BCM_6358_SDRAM_BASE
,
147 [RSET_DSL
] = BCM_6358_DSL_BASE
,
148 [RSET_ENET0
] = BCM_6358_ENET0_BASE
,
149 [RSET_ENET1
] = BCM_6358_ENET1_BASE
,
150 [RSET_ENETDMA
] = BCM_6358_ENETDMA_BASE
,
151 [RSET_MEMC
] = BCM_6358_MEMC_BASE
,
152 [RSET_DDR
] = BCM_6358_DDR_BASE
,
155 static const int bcm96358_irqs
[] = {
156 [IRQ_TIMER
] = BCM_6358_TIMER_IRQ
,
157 [IRQ_SPI
] = BCM_6358_SPI_IRQ
,
158 [IRQ_UART0
] = BCM_6358_UART0_IRQ
,
159 [IRQ_DSL
] = BCM_6358_DSL_IRQ
,
160 [IRQ_ENET0
] = BCM_6358_ENET0_IRQ
,
161 [IRQ_ENET1
] = BCM_6358_ENET1_IRQ
,
162 [IRQ_ENET_PHY
] = BCM_6358_ENET_PHY_IRQ
,
163 [IRQ_OHCI0
] = BCM_6358_OHCI0_IRQ
,
164 [IRQ_EHCI0
] = BCM_6358_EHCI0_IRQ
,
165 [IRQ_PCMCIA
] = BCM_6358_PCMCIA_IRQ
,
166 [IRQ_ENET0_RXDMA
] = BCM_6358_ENET0_RXDMA_IRQ
,
167 [IRQ_ENET0_TXDMA
] = BCM_6358_ENET0_TXDMA_IRQ
,
168 [IRQ_ENET1_RXDMA
] = BCM_6358_ENET1_RXDMA_IRQ
,
169 [IRQ_ENET1_TXDMA
] = BCM_6358_ENET1_TXDMA_IRQ
,
170 [IRQ_PCI
] = BCM_6358_PCI_IRQ
,
173 static const unsigned long bcm96358_regs_spi
[] = {
174 [SPI_CMD
] = SPI_BCM_6358_SPI_CMD
,
175 [SPI_INT_STATUS
] = SPI_BCM_6358_SPI_INT_STATUS
,
176 [SPI_INT_MASK_ST
] = SPI_BCM_6358_SPI_MASK_INT_ST
,
177 [SPI_INT_MASK
] = SPI_BCM_6358_SPI_INT_MASK
,
178 [SPI_ST
] = SPI_BCM_6358_SPI_STATUS
,
179 [SPI_CLK_CFG
] = SPI_BCM_6358_SPI_CLK_CFG
,
180 [SPI_FILL_BYTE
] = SPI_BCM_6358_SPI_FILL_BYTE
,
181 [SPI_MSG_TAIL
] = SPI_BCM_6358_SPI_MSG_TAIL
,
182 [SPI_RX_TAIL
] = SPI_BCM_6358_SPI_RX_TAIL
,
183 [SPI_MSG_CTL
] = SPI_BCM_6358_MSG_CTL
,
184 [SPI_MSG_DATA
] = SPI_BCM_6358_SPI_MSG_DATA
,
185 [SPI_RX_DATA
] = SPI_BCM_6358_SPI_RX_DATA
,
188 u16
__bcm63xx_get_cpu_id(void)
190 return bcm63xx_cpu_id
;
193 EXPORT_SYMBOL(__bcm63xx_get_cpu_id
);
195 u16
bcm63xx_get_cpu_rev(void)
197 return bcm63xx_cpu_rev
;
200 EXPORT_SYMBOL(bcm63xx_get_cpu_rev
);
202 unsigned int bcm63xx_get_cpu_freq(void)
204 return bcm63xx_cpu_freq
;
207 unsigned int bcm63xx_get_memory_size(void)
209 return bcm63xx_memory_size
;
212 static unsigned int detect_cpu_clock(void)
214 unsigned int tmp
, n1
= 0, n2
= 0, m1
= 0;
216 if (BCMCPU_IS_6338()) {
221 * frequency depends on PLL configuration:
223 if (BCMCPU_IS_6348()) {
224 /* 16MHz * (N1 + 1) * (N2 + 2) / (M1_CPU + 1) */
225 tmp
= bcm_perf_readl(PERF_MIPSPLLCTL_REG
);
226 n1
= (tmp
& MIPSPLLCTL_N1_MASK
) >> MIPSPLLCTL_N1_SHIFT
;
227 n2
= (tmp
& MIPSPLLCTL_N2_MASK
) >> MIPSPLLCTL_N2_SHIFT
;
228 m1
= (tmp
& MIPSPLLCTL_M1CPU_MASK
) >> MIPSPLLCTL_M1CPU_SHIFT
;
234 if (BCMCPU_IS_6358()) {
235 /* 16MHz * N1 * N2 / M1_CPU */
236 tmp
= bcm_ddr_readl(DDR_DMIPSPLLCFG_REG
);
237 n1
= (tmp
& DMIPSPLLCFG_N1_MASK
) >> DMIPSPLLCFG_N1_SHIFT
;
238 n2
= (tmp
& DMIPSPLLCFG_N2_MASK
) >> DMIPSPLLCFG_N2_SHIFT
;
239 m1
= (tmp
& DMIPSPLLCFG_M1_MASK
) >> DMIPSPLLCFG_M1_SHIFT
;
242 return (16 * 1000000 * n1
* n2
) / m1
;
246 * attempt to detect the amount of memory installed
248 static unsigned int detect_memory_size(void)
250 unsigned int cols
= 0, rows
= 0, is_32bits
= 0, banks
= 0;
253 if (BCMCPU_IS_6338() || BCMCPU_IS_6348()) {
254 val
= bcm_sdram_readl(SDRAM_CFG_REG
);
255 rows
= (val
& SDRAM_CFG_ROW_MASK
) >> SDRAM_CFG_ROW_SHIFT
;
256 cols
= (val
& SDRAM_CFG_COL_MASK
) >> SDRAM_CFG_COL_SHIFT
;
257 is_32bits
= (val
& SDRAM_CFG_32B_MASK
) ? 1 : 0;
258 banks
= (val
& SDRAM_CFG_BANK_MASK
) ? 2 : 1;
261 if (BCMCPU_IS_6358()) {
262 val
= bcm_memc_readl(MEMC_CFG_REG
);
263 rows
= (val
& MEMC_CFG_ROW_MASK
) >> MEMC_CFG_ROW_SHIFT
;
264 cols
= (val
& MEMC_CFG_COL_MASK
) >> MEMC_CFG_COL_SHIFT
;
265 is_32bits
= (val
& MEMC_CFG_32B_MASK
) ? 0 : 1;
269 /* 0 => 11 address bits ... 2 => 13 address bits */
272 /* 0 => 8 address bits ... 2 => 10 address bits */
275 return 1 << (cols
+ rows
+ (is_32bits
+ 1) + banks
);
278 void __init
bcm63xx_cpu_init(void)
280 unsigned int tmp
, expected_cpu_id
;
281 struct cpuinfo_mips
*c
= ¤t_cpu_data
;
283 /* soc registers location depends on cpu type */
286 switch (c
->cputype
) {
288 expected_cpu_id
= BCM6338_CPU_ID
;
289 bcm63xx_regs_base
= bcm96338_regs_base
;
290 bcm63xx_irqs
= bcm96338_irqs
;
291 bcm63xx_regs_spi
= bcm96338_regs_spi
;
294 expected_cpu_id
= BCM6348_CPU_ID
;
295 bcm63xx_regs_base
= bcm96348_regs_base
;
296 bcm63xx_irqs
= bcm96348_irqs
;
297 bcm63xx_regs_spi
= bcm96348_regs_spi
;
300 expected_cpu_id
= BCM6358_CPU_ID
;
301 bcm63xx_regs_base
= bcm96358_regs_base
;
302 bcm63xx_irqs
= bcm96358_irqs
;
303 bcm63xx_regs_spi
= bcm96358_regs_spi
;
307 /* really early to panic, but delaying panic would not help
308 * since we will never get any working console */
309 if (!expected_cpu_id
)
310 panic("unsupported Broadcom CPU");
313 * bcm63xx_regs_base is set, we can access soc registers
316 /* double check CPU type */
317 tmp
= bcm_perf_readl(PERF_REV_REG
);
318 bcm63xx_cpu_id
= (tmp
& REV_CHIPID_MASK
) >> REV_CHIPID_SHIFT
;
319 bcm63xx_cpu_rev
= (tmp
& REV_REVID_MASK
) >> REV_REVID_SHIFT
;
321 if (bcm63xx_cpu_id
!= expected_cpu_id
)
322 panic("bcm63xx CPU id mismatch");
324 bcm63xx_cpu_freq
= detect_cpu_clock();
325 bcm63xx_memory_size
= detect_memory_size();
327 printk(KERN_INFO
"Detected Broadcom 0x%04x CPU revision %02x\n",
328 bcm63xx_cpu_id
, bcm63xx_cpu_rev
);
329 printk(KERN_INFO
"CPU frequency is %u Hz\n",
331 printk(KERN_INFO
"%uMB of RAM installed\n",
332 bcm63xx_memory_size
>> 20);