2 * Broadcom specific AMBA
3 * Broadcom MIPS32 74K core driver
5 * Copyright 2009, Broadcom Corporation
6 * Copyright 2006, 2007, Michael Buesch <mb@bu3sch.de>
7 * Copyright 2010, Bernhard Loos <bernhardloos@googlemail.com>
8 * Copyright 2011, Hauke Mehrtens <hauke@hauke-m.de>
10 * Licensed under the GNU/GPL. See COPYING for details.
13 #include "bcma_private.h"
15 #include <linux/bcma/bcma.h>
17 #include <linux/serial.h>
18 #include <linux/serial_core.h>
19 #include <linux/serial_reg.h>
20 #include <linux/time.h>
22 #include <linux/bcm47xx_nvram.h>
26 BCMA_BOOT_DEV_UNK
= 0,
28 BCMA_BOOT_DEV_PARALLEL
,
33 /* The 47162a0 hangs when reading MIPS DMP registers registers */
34 static inline bool bcma_core_mips_bcm47162a0_quirk(struct bcma_device
*dev
)
36 return dev
->bus
->chipinfo
.id
== BCMA_CHIP_ID_BCM47162
&&
37 dev
->bus
->chipinfo
.rev
== 0 && dev
->id
.id
== BCMA_CORE_MIPS_74K
;
40 /* The 5357b0 hangs when reading USB20H DMP registers */
41 static inline bool bcma_core_mips_bcm5357b0_quirk(struct bcma_device
*dev
)
43 return (dev
->bus
->chipinfo
.id
== BCMA_CHIP_ID_BCM5357
||
44 dev
->bus
->chipinfo
.id
== BCMA_CHIP_ID_BCM4749
) &&
45 dev
->bus
->chipinfo
.pkg
== 11 &&
46 dev
->id
.id
== BCMA_CORE_USB20_HOST
;
49 static inline u32
mips_read32(struct bcma_drv_mips
*mcore
,
52 return bcma_read32(mcore
->core
, offset
);
55 static inline void mips_write32(struct bcma_drv_mips
*mcore
,
59 bcma_write32(mcore
->core
, offset
, value
);
62 static const u32 ipsflag_irq_mask
[] = {
64 BCMA_MIPS_IPSFLAG_IRQ1
,
65 BCMA_MIPS_IPSFLAG_IRQ2
,
66 BCMA_MIPS_IPSFLAG_IRQ3
,
67 BCMA_MIPS_IPSFLAG_IRQ4
,
70 static const u32 ipsflag_irq_shift
[] = {
72 BCMA_MIPS_IPSFLAG_IRQ1_SHIFT
,
73 BCMA_MIPS_IPSFLAG_IRQ2_SHIFT
,
74 BCMA_MIPS_IPSFLAG_IRQ3_SHIFT
,
75 BCMA_MIPS_IPSFLAG_IRQ4_SHIFT
,
78 static u32
bcma_core_mips_irqflag(struct bcma_device
*dev
)
82 if (bcma_core_mips_bcm47162a0_quirk(dev
))
83 return dev
->core_index
;
84 if (bcma_core_mips_bcm5357b0_quirk(dev
))
85 return dev
->core_index
;
86 flag
= bcma_aread32(dev
, BCMA_MIPS_OOBSELOUTA30
);
94 /* Get the MIPS IRQ assignment for a specified device.
95 * If unassigned, 0 is returned.
96 * If disabled, 5 is returned.
97 * If not supported, 6 is returned.
99 unsigned int bcma_core_mips_irq(struct bcma_device
*dev
)
101 struct bcma_device
*mdev
= dev
->bus
->drv_mips
.core
;
105 irqflag
= bcma_core_mips_irqflag(dev
);
109 for (irq
= 0; irq
<= 4; irq
++)
110 if (bcma_read32(mdev
, BCMA_MIPS_MIPS74K_INTMASK(irq
)) &
117 static void bcma_core_mips_set_irq(struct bcma_device
*dev
, unsigned int irq
)
119 unsigned int oldirq
= bcma_core_mips_irq(dev
);
120 struct bcma_bus
*bus
= dev
->bus
;
121 struct bcma_device
*mdev
= bus
->drv_mips
.core
;
124 irqflag
= bcma_core_mips_irqflag(dev
);
129 /* clear the old irq */
131 bcma_write32(mdev
, BCMA_MIPS_MIPS74K_INTMASK(0),
132 bcma_read32(mdev
, BCMA_MIPS_MIPS74K_INTMASK(0)) &
134 else if (oldirq
!= 5)
135 bcma_write32(mdev
, BCMA_MIPS_MIPS74K_INTMASK(oldirq
), 0);
137 /* assign the new one */
139 bcma_write32(mdev
, BCMA_MIPS_MIPS74K_INTMASK(0),
140 bcma_read32(mdev
, BCMA_MIPS_MIPS74K_INTMASK(0)) |
143 u32 irqinitmask
= bcma_read32(mdev
,
144 BCMA_MIPS_MIPS74K_INTMASK(irq
));
146 struct bcma_device
*core
;
148 /* backplane irq line is in use, find out who uses
149 * it and set user to irq 0
151 list_for_each_entry(core
, &bus
->cores
, list
) {
152 if ((1 << bcma_core_mips_irqflag(core
)) ==
154 bcma_core_mips_set_irq(core
, 0);
159 bcma_write32(mdev
, BCMA_MIPS_MIPS74K_INTMASK(irq
),
163 bcma_debug(bus
, "set_irq: core 0x%04x, irq %d => %d\n",
164 dev
->id
.id
, oldirq
<= 4 ? oldirq
+ 2 : 0, irq
+ 2);
167 static void bcma_core_mips_set_irq_name(struct bcma_bus
*bus
, unsigned int irq
,
170 struct bcma_device
*core
;
172 core
= bcma_find_core_unit(bus
, coreid
, unit
);
175 "Can not find core (id: 0x%x, unit %i) for IRQ configuration.\n",
180 bcma_core_mips_set_irq(core
, irq
);
183 static void bcma_core_mips_print_irq(struct bcma_device
*dev
, unsigned int irq
)
186 static const char *irq_name
[] = {"2(S)", "3", "4", "5", "6", "D", "I"};
188 char *ints
= interrupts
;
190 for (i
= 0; i
< ARRAY_SIZE(irq_name
); i
++)
191 ints
+= sprintf(ints
, " %s%c",
192 irq_name
[i
], i
== irq
? '*' : ' ');
194 bcma_debug(dev
->bus
, "core 0x%04x, irq:%s\n", dev
->id
.id
, interrupts
);
197 static void bcma_core_mips_dump_irq(struct bcma_bus
*bus
)
199 struct bcma_device
*core
;
201 list_for_each_entry(core
, &bus
->cores
, list
) {
202 bcma_core_mips_print_irq(core
, bcma_core_mips_irq(core
));
206 u32
bcma_cpu_clock(struct bcma_drv_mips
*mcore
)
208 struct bcma_bus
*bus
= mcore
->core
->bus
;
210 if (bus
->drv_cc
.capabilities
& BCMA_CC_CAP_PMU
)
211 return bcma_pmu_get_cpu_clock(&bus
->drv_cc
);
213 bcma_err(bus
, "No PMU available, need this to get the cpu clock\n");
216 EXPORT_SYMBOL(bcma_cpu_clock
);
218 static enum bcma_boot_dev
bcma_boot_dev(struct bcma_bus
*bus
)
220 struct bcma_drv_cc
*cc
= &bus
->drv_cc
;
221 u8 cc_rev
= cc
->core
->id
.rev
;
224 struct bcma_device
*core
;
226 core
= bcma_find_core(bus
, BCMA_CORE_NS_ROM
);
228 switch (bcma_aread32(core
, BCMA_IOST
) &
229 BCMA_NS_ROM_IOST_BOOT_DEV_MASK
) {
230 case BCMA_NS_ROM_IOST_BOOT_DEV_NOR
:
231 return BCMA_BOOT_DEV_SERIAL
;
232 case BCMA_NS_ROM_IOST_BOOT_DEV_NAND
:
233 return BCMA_BOOT_DEV_NAND
;
234 case BCMA_NS_ROM_IOST_BOOT_DEV_ROM
:
236 return BCMA_BOOT_DEV_ROM
;
241 if (cc
->status
& BCMA_CC_CHIPST_5357_NAND_BOOT
)
242 return BCMA_BOOT_DEV_NAND
;
243 else if (cc
->status
& BIT(5))
244 return BCMA_BOOT_DEV_ROM
;
247 if ((cc
->capabilities
& BCMA_CC_CAP_FLASHT
) ==
249 return BCMA_BOOT_DEV_PARALLEL
;
251 return BCMA_BOOT_DEV_SERIAL
;
254 return BCMA_BOOT_DEV_SERIAL
;
257 static void bcma_core_mips_nvram_init(struct bcma_drv_mips
*mcore
)
259 struct bcma_bus
*bus
= mcore
->core
->bus
;
260 enum bcma_boot_dev boot_dev
;
262 /* Determine flash type this SoC boots from */
263 boot_dev
= bcma_boot_dev(bus
);
265 case BCMA_BOOT_DEV_PARALLEL
:
266 case BCMA_BOOT_DEV_SERIAL
:
267 #ifdef CONFIG_BCM47XX
268 bcm47xx_nvram_init_from_mem(BCMA_SOC_FLASH2
,
272 case BCMA_BOOT_DEV_NAND
:
273 #ifdef CONFIG_BCM47XX
274 bcm47xx_nvram_init_from_mem(BCMA_SOC_FLASH1
,
283 void bcma_core_mips_early_init(struct bcma_drv_mips
*mcore
)
285 struct bcma_bus
*bus
= mcore
->core
->bus
;
287 if (mcore
->early_setup_done
)
290 bcma_chipco_serial_init(&bus
->drv_cc
);
291 bcma_core_mips_nvram_init(mcore
);
293 mcore
->early_setup_done
= true;
296 static void bcma_fix_i2s_irqflag(struct bcma_bus
*bus
)
298 struct bcma_device
*cpu
, *pcie
, *i2s
;
300 /* Fixup the interrupts in 4716/4748 for i2s core (2010 Broadcom SDK)
301 * (IRQ flags > 7 are ignored when setting the interrupt masks)
303 if (bus
->chipinfo
.id
!= BCMA_CHIP_ID_BCM4716
&&
304 bus
->chipinfo
.id
!= BCMA_CHIP_ID_BCM4748
)
307 cpu
= bcma_find_core(bus
, BCMA_CORE_MIPS_74K
);
308 pcie
= bcma_find_core(bus
, BCMA_CORE_PCIE
);
309 i2s
= bcma_find_core(bus
, BCMA_CORE_I2S
);
310 if (cpu
&& pcie
&& i2s
&&
311 bcma_aread32(cpu
, BCMA_MIPS_OOBSELINA74
) == 0x08060504 &&
312 bcma_aread32(pcie
, BCMA_MIPS_OOBSELINA74
) == 0x08060504 &&
313 bcma_aread32(i2s
, BCMA_MIPS_OOBSELOUTA30
) == 0x88) {
314 bcma_awrite32(cpu
, BCMA_MIPS_OOBSELINA74
, 0x07060504);
315 bcma_awrite32(pcie
, BCMA_MIPS_OOBSELINA74
, 0x07060504);
316 bcma_awrite32(i2s
, BCMA_MIPS_OOBSELOUTA30
, 0x87);
318 "Moved i2s interrupt to oob line 7 instead of 8\n");
322 void bcma_core_mips_init(struct bcma_drv_mips
*mcore
)
324 struct bcma_bus
*bus
;
325 struct bcma_device
*core
;
326 bus
= mcore
->core
->bus
;
328 if (mcore
->setup_done
)
331 bcma_debug(bus
, "Initializing MIPS core...\n");
333 bcma_core_mips_early_init(mcore
);
335 bcma_fix_i2s_irqflag(bus
);
337 switch (bus
->chipinfo
.id
) {
338 case BCMA_CHIP_ID_BCM4716
:
339 case BCMA_CHIP_ID_BCM4748
:
340 bcma_core_mips_set_irq_name(bus
, 1, BCMA_CORE_80211
, 0);
341 bcma_core_mips_set_irq_name(bus
, 2, BCMA_CORE_MAC_GBIT
, 0);
342 bcma_core_mips_set_irq_name(bus
, 3, BCMA_CORE_USB20_HOST
, 0);
343 bcma_core_mips_set_irq_name(bus
, 4, BCMA_CORE_PCIE
, 0);
344 bcma_core_mips_set_irq_name(bus
, 0, BCMA_CORE_CHIPCOMMON
, 0);
345 bcma_core_mips_set_irq_name(bus
, 0, BCMA_CORE_I2S
, 0);
347 case BCMA_CHIP_ID_BCM5356
:
348 case BCMA_CHIP_ID_BCM47162
:
349 case BCMA_CHIP_ID_BCM53572
:
350 bcma_core_mips_set_irq_name(bus
, 1, BCMA_CORE_80211
, 0);
351 bcma_core_mips_set_irq_name(bus
, 2, BCMA_CORE_MAC_GBIT
, 0);
352 bcma_core_mips_set_irq_name(bus
, 0, BCMA_CORE_CHIPCOMMON
, 0);
354 case BCMA_CHIP_ID_BCM5357
:
355 case BCMA_CHIP_ID_BCM4749
:
356 bcma_core_mips_set_irq_name(bus
, 1, BCMA_CORE_80211
, 0);
357 bcma_core_mips_set_irq_name(bus
, 2, BCMA_CORE_MAC_GBIT
, 0);
358 bcma_core_mips_set_irq_name(bus
, 3, BCMA_CORE_USB20_HOST
, 0);
359 bcma_core_mips_set_irq_name(bus
, 0, BCMA_CORE_CHIPCOMMON
, 0);
360 bcma_core_mips_set_irq_name(bus
, 0, BCMA_CORE_I2S
, 0);
362 case BCMA_CHIP_ID_BCM4706
:
363 bcma_core_mips_set_irq_name(bus
, 1, BCMA_CORE_PCIE
, 0);
364 bcma_core_mips_set_irq_name(bus
, 2, BCMA_CORE_4706_MAC_GBIT
,
366 bcma_core_mips_set_irq_name(bus
, 3, BCMA_CORE_PCIE
, 1);
367 bcma_core_mips_set_irq_name(bus
, 4, BCMA_CORE_USB20_HOST
, 0);
368 bcma_core_mips_set_irq_name(bus
, 0, BCMA_CORE_4706_CHIPCOMMON
,
372 list_for_each_entry(core
, &bus
->cores
, list
) {
373 core
->irq
= bcma_core_irq(core
, 0);
376 "Unknown device (0x%x) found, can not configure IRQs\n",
379 bcma_debug(bus
, "IRQ reconfiguration done\n");
380 bcma_core_mips_dump_irq(bus
);
382 mcore
->setup_done
= true;