b7c041f60df4b5fd83ad1116f80ad78eecb9eccb
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>
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>
17 const unsigned long *bcm63xx_regs_base
;
18 EXPORT_SYMBOL(bcm63xx_regs_base
);
20 const int *bcm63xx_irqs
;
21 EXPORT_SYMBOL(bcm63xx_irqs
);
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
;
29 * 6338 register sets and irqs
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
,
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
,
52 * 6348 register sets and irqs
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
,
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
,
93 * 6358 register sets and irqs
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
,
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
,
135 u16
__bcm63xx_get_cpu_id(void)
137 return bcm63xx_cpu_id
;
140 EXPORT_SYMBOL(__bcm63xx_get_cpu_id
);
142 u16
bcm63xx_get_cpu_rev(void)
144 return bcm63xx_cpu_rev
;
147 EXPORT_SYMBOL(bcm63xx_get_cpu_rev
);
149 unsigned int bcm63xx_get_cpu_freq(void)
151 return bcm63xx_cpu_freq
;
154 unsigned int bcm63xx_get_memory_size(void)
156 return bcm63xx_memory_size
;
159 static unsigned int detect_cpu_clock(void)
161 unsigned int tmp
, n1
= 0, n2
= 0, m1
= 0;
163 if (BCMCPU_IS_6338()) {
168 * frequency depends on PLL configuration:
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
;
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
;
189 return (16 * 1000000 * n1
* n2
) / m1
;
193 * attempt to detect the amount of memory installed
195 static unsigned int detect_memory_size(void)
197 unsigned int cols
= 0, rows
= 0, is_32bits
= 0, banks
= 0;
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;
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;
216 /* 0 => 11 address bits ... 2 => 13 address bits */
219 /* 0 => 8 address bits ... 2 => 10 address bits */
222 return 1 << (cols
+ rows
+ (is_32bits
+ 1) + banks
);
225 void __init
bcm63xx_cpu_init(void)
227 unsigned int tmp
, expected_cpu_id
;
228 struct cpuinfo_mips
*c
= ¤t_cpu_data
;
230 /* soc registers location depends on cpu type */
233 switch (c
->cputype
) {
235 expected_cpu_id
= BCM6338_CPU_ID
;
236 bcm63xx_regs_base
= bcm96338_regs_base
;
237 bcm63xx_irqs
= bcm96338_irqs
;
240 expected_cpu_id
= BCM6348_CPU_ID
;
241 bcm63xx_regs_base
= bcm96348_regs_base
;
242 bcm63xx_irqs
= bcm96348_irqs
;
245 expected_cpu_id
= BCM6358_CPU_ID
;
246 bcm63xx_regs_base
= bcm96358_regs_base
;
247 bcm63xx_irqs
= bcm96358_irqs
;
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");
257 * bcm63xx_regs_base is set, we can access soc registers
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
;
265 if (bcm63xx_cpu_id
!= expected_cpu_id
)
266 panic("bcm63xx CPU id mismatch");
268 bcm63xx_cpu_freq
= detect_cpu_clock();
269 bcm63xx_memory_size
= detect_memory_size();
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",
275 printk(KERN_INFO
"%uMB of RAM installed\n",
276 bcm63xx_memory_size
>> 20);
This page took 0.04954 seconds and 3 git commands to generate.