2 * Broadcom specific AMBA
5 * Licensed under the GNU/GPL. See COPYING for details.
9 #include "bcma_private.h"
11 #include <linux/bcma/bcma.h>
12 #include <linux/bcma/bcma_regs.h>
13 #include <linux/pci.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/slab.h>
18 struct bcma_device_id_name
{
23 static const struct bcma_device_id_name bcma_arm_device_names
[] = {
24 { BCMA_CORE_ARM_1176
, "ARM 1176" },
25 { BCMA_CORE_ARM_7TDMI
, "ARM 7TDMI" },
26 { BCMA_CORE_ARM_CM3
, "ARM CM3" },
29 static const struct bcma_device_id_name bcma_bcm_device_names
[] = {
30 { BCMA_CORE_OOB_ROUTER
, "OOB Router" },
31 { BCMA_CORE_INVALID
, "Invalid" },
32 { BCMA_CORE_CHIPCOMMON
, "ChipCommon" },
33 { BCMA_CORE_ILINE20
, "ILine 20" },
34 { BCMA_CORE_SRAM
, "SRAM" },
35 { BCMA_CORE_SDRAM
, "SDRAM" },
36 { BCMA_CORE_PCI
, "PCI" },
37 { BCMA_CORE_ETHERNET
, "Fast Ethernet" },
38 { BCMA_CORE_V90
, "V90" },
39 { BCMA_CORE_USB11_HOSTDEV
, "USB 1.1 Hostdev" },
40 { BCMA_CORE_ADSL
, "ADSL" },
41 { BCMA_CORE_ILINE100
, "ILine 100" },
42 { BCMA_CORE_IPSEC
, "IPSEC" },
43 { BCMA_CORE_UTOPIA
, "UTOPIA" },
44 { BCMA_CORE_PCMCIA
, "PCMCIA" },
45 { BCMA_CORE_INTERNAL_MEM
, "Internal Memory" },
46 { BCMA_CORE_MEMC_SDRAM
, "MEMC SDRAM" },
47 { BCMA_CORE_OFDM
, "OFDM" },
48 { BCMA_CORE_EXTIF
, "EXTIF" },
49 { BCMA_CORE_80211
, "IEEE 802.11" },
50 { BCMA_CORE_PHY_A
, "PHY A" },
51 { BCMA_CORE_PHY_B
, "PHY B" },
52 { BCMA_CORE_PHY_G
, "PHY G" },
53 { BCMA_CORE_USB11_HOST
, "USB 1.1 Host" },
54 { BCMA_CORE_USB11_DEV
, "USB 1.1 Device" },
55 { BCMA_CORE_USB20_HOST
, "USB 2.0 Host" },
56 { BCMA_CORE_USB20_DEV
, "USB 2.0 Device" },
57 { BCMA_CORE_SDIO_HOST
, "SDIO Host" },
58 { BCMA_CORE_ROBOSWITCH
, "Roboswitch" },
59 { BCMA_CORE_PARA_ATA
, "PATA" },
60 { BCMA_CORE_SATA_XORDMA
, "SATA XOR-DMA" },
61 { BCMA_CORE_ETHERNET_GBIT
, "GBit Ethernet" },
62 { BCMA_CORE_PCIE
, "PCIe" },
63 { BCMA_CORE_PHY_N
, "PHY N" },
64 { BCMA_CORE_SRAM_CTL
, "SRAM Controller" },
65 { BCMA_CORE_MINI_MACPHY
, "Mini MACPHY" },
66 { BCMA_CORE_PHY_LP
, "PHY LP" },
67 { BCMA_CORE_PMU
, "PMU" },
68 { BCMA_CORE_PHY_SSN
, "PHY SSN" },
69 { BCMA_CORE_SDIO_DEV
, "SDIO Device" },
70 { BCMA_CORE_PHY_HT
, "PHY HT" },
71 { BCMA_CORE_MAC_GBIT
, "GBit MAC" },
72 { BCMA_CORE_DDR12_MEM_CTL
, "DDR1/DDR2 Memory Controller" },
73 { BCMA_CORE_PCIE_RC
, "PCIe Root Complex" },
74 { BCMA_CORE_OCP_OCP_BRIDGE
, "OCP to OCP Bridge" },
75 { BCMA_CORE_SHARED_COMMON
, "Common Shared" },
76 { BCMA_CORE_OCP_AHB_BRIDGE
, "OCP to AHB Bridge" },
77 { BCMA_CORE_SPI_HOST
, "SPI Host" },
78 { BCMA_CORE_I2S
, "I2S" },
79 { BCMA_CORE_SDR_DDR1_MEM_CTL
, "SDR/DDR1 Memory Controller" },
80 { BCMA_CORE_SHIM
, "SHIM" },
81 { BCMA_CORE_DEFAULT
, "Default" },
84 static const struct bcma_device_id_name bcma_mips_device_names
[] = {
85 { BCMA_CORE_MIPS
, "MIPS" },
86 { BCMA_CORE_MIPS_3302
, "MIPS 3302" },
87 { BCMA_CORE_MIPS_74K
, "MIPS 74K" },
90 static const char *bcma_device_name(const struct bcma_device_id
*id
)
92 const struct bcma_device_id_name
*names
;
95 /* search manufacturer specific names */
98 names
= bcma_arm_device_names
;
99 size
= ARRAY_SIZE(bcma_arm_device_names
);
102 names
= bcma_bcm_device_names
;
103 size
= ARRAY_SIZE(bcma_bcm_device_names
);
105 case BCMA_MANUF_MIPS
:
106 names
= bcma_mips_device_names
;
107 size
= ARRAY_SIZE(bcma_mips_device_names
);
113 for (i
= 0; i
< size
; i
++) {
114 if (names
[i
].id
== id
->id
)
115 return names
[i
].name
;
121 static u32
bcma_scan_read32(struct bcma_bus
*bus
, u8 current_coreidx
,
124 return readl(bus
->mmio
+ offset
);
127 static void bcma_scan_switch_core(struct bcma_bus
*bus
, u32 addr
)
129 if (bus
->hosttype
== BCMA_HOSTTYPE_PCI
)
130 pci_write_config_dword(bus
->host_pci
, BCMA_PCI_BAR0_WIN
,
134 static u32
bcma_erom_get_ent(struct bcma_bus
*bus
, u32
**eromptr
)
136 u32 ent
= readl(*eromptr
);
141 static void bcma_erom_push_ent(u32
**eromptr
)
146 static s32
bcma_erom_get_ci(struct bcma_bus
*bus
, u32
**eromptr
)
148 u32 ent
= bcma_erom_get_ent(bus
, eromptr
);
149 if (!(ent
& SCAN_ER_VALID
))
151 if ((ent
& SCAN_ER_TAG
) != SCAN_ER_TAG_CI
)
156 static bool bcma_erom_is_end(struct bcma_bus
*bus
, u32
**eromptr
)
158 u32 ent
= bcma_erom_get_ent(bus
, eromptr
);
159 bcma_erom_push_ent(eromptr
);
160 return (ent
== (SCAN_ER_TAG_END
| SCAN_ER_VALID
));
163 static bool bcma_erom_is_bridge(struct bcma_bus
*bus
, u32
**eromptr
)
165 u32 ent
= bcma_erom_get_ent(bus
, eromptr
);
166 bcma_erom_push_ent(eromptr
);
167 return (((ent
& SCAN_ER_VALID
)) &&
168 ((ent
& SCAN_ER_TAGX
) == SCAN_ER_TAG_ADDR
) &&
169 ((ent
& SCAN_ADDR_TYPE
) == SCAN_ADDR_TYPE_BRIDGE
));
172 static void bcma_erom_skip_component(struct bcma_bus
*bus
, u32
**eromptr
)
176 ent
= bcma_erom_get_ent(bus
, eromptr
);
177 if ((ent
& SCAN_ER_VALID
) &&
178 ((ent
& SCAN_ER_TAG
) == SCAN_ER_TAG_CI
))
180 if (ent
== (SCAN_ER_TAG_END
| SCAN_ER_VALID
))
183 bcma_erom_push_ent(eromptr
);
186 static s32
bcma_erom_get_mst_port(struct bcma_bus
*bus
, u32
**eromptr
)
188 u32 ent
= bcma_erom_get_ent(bus
, eromptr
);
189 if (!(ent
& SCAN_ER_VALID
))
191 if ((ent
& SCAN_ER_TAG
) != SCAN_ER_TAG_MP
)
196 static s32
bcma_erom_get_addr_desc(struct bcma_bus
*bus
, u32
**eromptr
,
199 u32 addrl
, addrh
, sizel
, sizeh
= 0;
202 u32 ent
= bcma_erom_get_ent(bus
, eromptr
);
203 if ((!(ent
& SCAN_ER_VALID
)) ||
204 ((ent
& SCAN_ER_TAGX
) != SCAN_ER_TAG_ADDR
) ||
205 ((ent
& SCAN_ADDR_TYPE
) != type
) ||
206 (((ent
& SCAN_ADDR_PORT
) >> SCAN_ADDR_PORT_SHIFT
) != port
)) {
207 bcma_erom_push_ent(eromptr
);
211 addrl
= ent
& SCAN_ADDR_ADDR
;
212 if (ent
& SCAN_ADDR_AG32
)
213 addrh
= bcma_erom_get_ent(bus
, eromptr
);
217 if ((ent
& SCAN_ADDR_SZ
) == SCAN_ADDR_SZ_SZD
) {
218 size
= bcma_erom_get_ent(bus
, eromptr
);
219 sizel
= size
& SCAN_SIZE_SZ
;
220 if (size
& SCAN_SIZE_SG32
)
221 sizeh
= bcma_erom_get_ent(bus
, eromptr
);
223 sizel
= SCAN_ADDR_SZ_BASE
<<
224 ((ent
& SCAN_ADDR_SZ
) >> SCAN_ADDR_SZ_SHIFT
);
229 static struct bcma_device
*bcma_find_core_by_index(struct bcma_bus
*bus
,
232 struct bcma_device
*core
;
234 list_for_each_entry(core
, &bus
->cores
, list
) {
235 if (core
->core_index
== index
)
241 static struct bcma_device
*bcma_find_core_reverse(struct bcma_bus
*bus
, u16 coreid
)
243 struct bcma_device
*core
;
245 list_for_each_entry_reverse(core
, &bus
->cores
, list
) {
246 if (core
->id
.id
== coreid
)
252 static int bcma_get_next_core(struct bcma_bus
*bus
, u32 __iomem
**eromptr
,
253 struct bcma_device_id
*match
, int core_num
,
254 struct bcma_device
*core
)
259 u8 ports
[2], wrappers
[2];
262 cia
= bcma_erom_get_ci(bus
, eromptr
);
264 bcma_erom_push_ent(eromptr
);
265 if (bcma_erom_is_end(bus
, eromptr
))
269 cib
= bcma_erom_get_ci(bus
, eromptr
);
274 core
->id
.class = (cia
& SCAN_CIA_CLASS
) >> SCAN_CIA_CLASS_SHIFT
;
275 core
->id
.id
= (cia
& SCAN_CIA_ID
) >> SCAN_CIA_ID_SHIFT
;
276 core
->id
.manuf
= (cia
& SCAN_CIA_MANUF
) >> SCAN_CIA_MANUF_SHIFT
;
277 ports
[0] = (cib
& SCAN_CIB_NMP
) >> SCAN_CIB_NMP_SHIFT
;
278 ports
[1] = (cib
& SCAN_CIB_NSP
) >> SCAN_CIB_NSP_SHIFT
;
279 wrappers
[0] = (cib
& SCAN_CIB_NMW
) >> SCAN_CIB_NMW_SHIFT
;
280 wrappers
[1] = (cib
& SCAN_CIB_NSW
) >> SCAN_CIB_NSW_SHIFT
;
281 core
->id
.rev
= (cib
& SCAN_CIB_REV
) >> SCAN_CIB_REV_SHIFT
;
283 if (((core
->id
.manuf
== BCMA_MANUF_ARM
) &&
284 (core
->id
.id
== 0xFFF)) ||
286 bcma_erom_skip_component(bus
, eromptr
);
290 /* check if component is a core at all */
291 if (wrappers
[0] + wrappers
[1] == 0) {
292 /* we could save addrl of the router
293 if (cid == BCMA_CORE_OOB_ROUTER)
295 bcma_erom_skip_component(bus
, eromptr
);
299 if (bcma_erom_is_bridge(bus
, eromptr
)) {
300 bcma_erom_skip_component(bus
, eromptr
);
304 if (bcma_find_core_by_index(bus
, core_num
)) {
305 bcma_erom_skip_component(bus
, eromptr
);
309 if (match
&& ((match
->manuf
!= BCMA_ANY_MANUF
&&
310 match
->manuf
!= core
->id
.manuf
) ||
311 (match
->id
!= BCMA_ANY_ID
&& match
->id
!= core
->id
.id
) ||
312 (match
->rev
!= BCMA_ANY_REV
&& match
->rev
!= core
->id
.rev
) ||
313 (match
->class != BCMA_ANY_CLASS
&& match
->class != core
->id
.class)
315 bcma_erom_skip_component(bus
, eromptr
);
319 /* get & parse master ports */
320 for (i
= 0; i
< ports
[0]; i
++) {
321 s32 mst_port_d
= bcma_erom_get_mst_port(bus
, eromptr
);
326 /* First Slave Address Descriptor should be port 0:
327 * the main register space for the core
329 tmp
= bcma_erom_get_addr_desc(bus
, eromptr
, SCAN_ADDR_TYPE_SLAVE
, 0);
331 /* Try again to see if it is a bridge */
332 tmp
= bcma_erom_get_addr_desc(bus
, eromptr
,
333 SCAN_ADDR_TYPE_BRIDGE
, 0);
337 pr_info("Bridge found\n");
343 /* get & parse slave ports */
344 for (i
= 0; i
< ports
[1]; i
++) {
346 tmp
= bcma_erom_get_addr_desc(bus
, eromptr
,
347 SCAN_ADDR_TYPE_SLAVE
, i
);
349 /* no more entries for port _i_ */
350 /* pr_debug("erom: slave port %d "
351 * "has %d descriptors\n", i, j); */
354 if (i
== 0 && j
== 0)
360 /* get & parse master wrappers */
361 for (i
= 0; i
< wrappers
[0]; i
++) {
363 tmp
= bcma_erom_get_addr_desc(bus
, eromptr
,
364 SCAN_ADDR_TYPE_MWRAP
, i
);
366 /* no more entries for port _i_ */
367 /* pr_debug("erom: master wrapper %d "
368 * "has %d descriptors\n", i, j); */
371 if (i
== 0 && j
== 0)
377 /* get & parse slave wrappers */
378 for (i
= 0; i
< wrappers
[1]; i
++) {
379 u8 hack
= (ports
[1] == 1) ? 0 : 1;
381 tmp
= bcma_erom_get_addr_desc(bus
, eromptr
,
382 SCAN_ADDR_TYPE_SWRAP
, i
+ hack
);
384 /* no more entries for port _i_ */
385 /* pr_debug("erom: master wrapper %d "
386 * has %d descriptors\n", i, j); */
389 if (wrappers
[0] == 0 && !i
&& !j
)
394 if (bus
->hosttype
== BCMA_HOSTTYPE_SOC
) {
395 core
->io_addr
= ioremap_nocache(core
->addr
, BCMA_CORE_SIZE
);
398 core
->io_wrap
= ioremap_nocache(core
->wrap
, BCMA_CORE_SIZE
);
399 if (!core
->io_wrap
) {
400 iounmap(core
->io_addr
);
407 void bcma_init_bus(struct bcma_bus
*bus
)
410 struct bcma_chipinfo
*chipinfo
= &(bus
->chipinfo
);
415 INIT_LIST_HEAD(&bus
->cores
);
418 bcma_scan_switch_core(bus
, BCMA_ADDR_BASE
);
420 tmp
= bcma_scan_read32(bus
, 0, BCMA_CC_ID
);
421 chipinfo
->id
= (tmp
& BCMA_CC_ID_ID
) >> BCMA_CC_ID_ID_SHIFT
;
422 chipinfo
->rev
= (tmp
& BCMA_CC_ID_REV
) >> BCMA_CC_ID_REV_SHIFT
;
423 chipinfo
->pkg
= (tmp
& BCMA_CC_ID_PKG
) >> BCMA_CC_ID_PKG_SHIFT
;
424 pr_info("Found chip with id 0x%04X, rev 0x%02X and package 0x%02X\n",
425 chipinfo
->id
, chipinfo
->rev
, chipinfo
->pkg
);
427 bus
->init_done
= true;
430 int bcma_bus_scan(struct bcma_bus
*bus
)
433 u32 __iomem
*eromptr
, *eromend
;
435 int err
, core_num
= 0;
439 erombase
= bcma_scan_read32(bus
, 0, BCMA_CC_EROM
);
440 if (bus
->hosttype
== BCMA_HOSTTYPE_SOC
) {
441 eromptr
= ioremap_nocache(erombase
, BCMA_CORE_SIZE
);
448 eromend
= eromptr
+ BCMA_CORE_SIZE
/ sizeof(u32
);
450 bcma_scan_switch_core(bus
, erombase
);
452 while (eromptr
< eromend
) {
453 struct bcma_device
*other_core
;
454 struct bcma_device
*core
= kzalloc(sizeof(*core
), GFP_KERNEL
);
457 INIT_LIST_HEAD(&core
->list
);
460 err
= bcma_get_next_core(bus
, &eromptr
, NULL
, core_num
, core
);
463 if (err
== -ENODEV
) {
466 } else if (err
== -ENXIO
) {
468 } else if (err
== -ESPIPE
) {
474 core
->core_index
= core_num
++;
476 other_core
= bcma_find_core_reverse(bus
, core
->id
.id
);
477 core
->core_unit
= (other_core
== NULL
) ? 0 : other_core
->core_unit
+ 1;
479 pr_info("Core %d found: %s "
480 "(manuf 0x%03X, id 0x%03X, rev 0x%02X, class 0x%X)\n",
481 core
->core_index
, bcma_device_name(&core
->id
),
482 core
->id
.manuf
, core
->id
.id
, core
->id
.rev
,
485 list_add(&core
->list
, &bus
->cores
);
488 if (bus
->hosttype
== BCMA_HOSTTYPE_SOC
)
494 int __init
bcma_bus_scan_early(struct bcma_bus
*bus
,
495 struct bcma_device_id
*match
,
496 struct bcma_device
*core
)
499 u32 __iomem
*eromptr
, *eromend
;
504 erombase
= bcma_scan_read32(bus
, 0, BCMA_CC_EROM
);
505 if (bus
->hosttype
== BCMA_HOSTTYPE_SOC
) {
506 eromptr
= ioremap_nocache(erombase
, BCMA_CORE_SIZE
);
513 eromend
= eromptr
+ BCMA_CORE_SIZE
/ sizeof(u32
);
515 bcma_scan_switch_core(bus
, erombase
);
517 while (eromptr
< eromend
) {
518 memset(core
, 0, sizeof(*core
));
519 INIT_LIST_HEAD(&core
->list
);
522 err
= bcma_get_next_core(bus
, &eromptr
, match
, core_num
, core
);
523 if (err
== -ENODEV
) {
526 } else if (err
== -ENXIO
)
528 else if (err
== -ESPIPE
)
533 core
->core_index
= core_num
++;
535 pr_info("Core %d found: %s "
536 "(manuf 0x%03X, id 0x%03X, rev 0x%02X, class 0x%X)\n",
537 core
->core_index
, bcma_device_name(&core
->id
),
538 core
->id
.manuf
, core
->id
.id
, core
->id
.rev
,
541 list_add(&core
->list
, &bus
->cores
);
546 if (bus
->hosttype
== BCMA_HOSTTYPE_SOC
)