blob: a3420585d942e2ea9b953852528bcc54f8cc881a [file] [log] [blame]
Rafał Miłecki8369ae32011-05-09 18:56:46 +02001/*
2 * Broadcom specific AMBA
3 * Bus scanning
4 *
5 * Licensed under the GNU/GPL. See COPYING for details.
6 */
7
8#include "scan.h"
9#include "bcma_private.h"
10
11#include <linux/bcma/bcma.h>
12#include <linux/bcma/bcma_regs.h>
13#include <linux/pci.h>
14#include <linux/io.h>
15#include <linux/dma-mapping.h>
16#include <linux/slab.h>
17
18struct bcma_device_id_name {
19 u16 id;
20 const char *name;
21};
Nathan Hintz82a7c2b2012-05-04 21:56:31 -070022
23static 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" },
27};
28
29static const struct bcma_device_id_name bcma_bcm_device_names[] = {
Rafał Miłecki8369ae32011-05-09 18:56:46 +020030 { BCMA_CORE_OOB_ROUTER, "OOB Router" },
Rafał Miłeckid2bb2b92012-06-25 22:12:20 +020031 { BCMA_CORE_4706_CHIPCOMMON, "BCM4706 ChipCommon" },
32 { BCMA_CORE_4706_SOC_RAM, "BCM4706 SOC RAM" },
33 { BCMA_CORE_4706_MAC_GBIT, "BCM4706 GBit MAC" },
34 { BCMA_CORE_AMEMC, "AMEMC (DDR)" },
35 { BCMA_CORE_ALTA, "ALTA (I2S)" },
36 { BCMA_CORE_4706_MAC_GBIT_COMMON, "BCM4706 GBit MAC Common" },
Rafał Miłecki8369ae32011-05-09 18:56:46 +020037 { BCMA_CORE_INVALID, "Invalid" },
38 { BCMA_CORE_CHIPCOMMON, "ChipCommon" },
39 { BCMA_CORE_ILINE20, "ILine 20" },
40 { BCMA_CORE_SRAM, "SRAM" },
41 { BCMA_CORE_SDRAM, "SDRAM" },
42 { BCMA_CORE_PCI, "PCI" },
Rafał Miłecki8369ae32011-05-09 18:56:46 +020043 { BCMA_CORE_ETHERNET, "Fast Ethernet" },
44 { BCMA_CORE_V90, "V90" },
45 { BCMA_CORE_USB11_HOSTDEV, "USB 1.1 Hostdev" },
46 { BCMA_CORE_ADSL, "ADSL" },
47 { BCMA_CORE_ILINE100, "ILine 100" },
48 { BCMA_CORE_IPSEC, "IPSEC" },
49 { BCMA_CORE_UTOPIA, "UTOPIA" },
50 { BCMA_CORE_PCMCIA, "PCMCIA" },
51 { BCMA_CORE_INTERNAL_MEM, "Internal Memory" },
52 { BCMA_CORE_MEMC_SDRAM, "MEMC SDRAM" },
53 { BCMA_CORE_OFDM, "OFDM" },
54 { BCMA_CORE_EXTIF, "EXTIF" },
55 { BCMA_CORE_80211, "IEEE 802.11" },
56 { BCMA_CORE_PHY_A, "PHY A" },
57 { BCMA_CORE_PHY_B, "PHY B" },
58 { BCMA_CORE_PHY_G, "PHY G" },
Rafał Miłecki8369ae32011-05-09 18:56:46 +020059 { BCMA_CORE_USB11_HOST, "USB 1.1 Host" },
60 { BCMA_CORE_USB11_DEV, "USB 1.1 Device" },
61 { BCMA_CORE_USB20_HOST, "USB 2.0 Host" },
62 { BCMA_CORE_USB20_DEV, "USB 2.0 Device" },
63 { BCMA_CORE_SDIO_HOST, "SDIO Host" },
64 { BCMA_CORE_ROBOSWITCH, "Roboswitch" },
65 { BCMA_CORE_PARA_ATA, "PATA" },
66 { BCMA_CORE_SATA_XORDMA, "SATA XOR-DMA" },
67 { BCMA_CORE_ETHERNET_GBIT, "GBit Ethernet" },
68 { BCMA_CORE_PCIE, "PCIe" },
69 { BCMA_CORE_PHY_N, "PHY N" },
70 { BCMA_CORE_SRAM_CTL, "SRAM Controller" },
71 { BCMA_CORE_MINI_MACPHY, "Mini MACPHY" },
Rafał Miłecki8369ae32011-05-09 18:56:46 +020072 { BCMA_CORE_PHY_LP, "PHY LP" },
73 { BCMA_CORE_PMU, "PMU" },
74 { BCMA_CORE_PHY_SSN, "PHY SSN" },
75 { BCMA_CORE_SDIO_DEV, "SDIO Device" },
Rafał Miłecki8369ae32011-05-09 18:56:46 +020076 { BCMA_CORE_PHY_HT, "PHY HT" },
Rafał Miłecki8369ae32011-05-09 18:56:46 +020077 { BCMA_CORE_MAC_GBIT, "GBit MAC" },
78 { BCMA_CORE_DDR12_MEM_CTL, "DDR1/DDR2 Memory Controller" },
79 { BCMA_CORE_PCIE_RC, "PCIe Root Complex" },
80 { BCMA_CORE_OCP_OCP_BRIDGE, "OCP to OCP Bridge" },
81 { BCMA_CORE_SHARED_COMMON, "Common Shared" },
82 { BCMA_CORE_OCP_AHB_BRIDGE, "OCP to AHB Bridge" },
83 { BCMA_CORE_SPI_HOST, "SPI Host" },
84 { BCMA_CORE_I2S, "I2S" },
85 { BCMA_CORE_SDR_DDR1_MEM_CTL, "SDR/DDR1 Memory Controller" },
86 { BCMA_CORE_SHIM, "SHIM" },
87 { BCMA_CORE_DEFAULT, "Default" },
88};
Rafał Miłecki8369ae32011-05-09 18:56:46 +020089
Nathan Hintz82a7c2b2012-05-04 21:56:31 -070090static const struct bcma_device_id_name bcma_mips_device_names[] = {
91 { BCMA_CORE_MIPS, "MIPS" },
92 { BCMA_CORE_MIPS_3302, "MIPS 3302" },
93 { BCMA_CORE_MIPS_74K, "MIPS 74K" },
94};
95
96static const char *bcma_device_name(const struct bcma_device_id *id)
97{
98 const struct bcma_device_id_name *names;
99 int size, i;
100
101 /* search manufacturer specific names */
102 switch (id->manuf) {
103 case BCMA_MANUF_ARM:
104 names = bcma_arm_device_names;
105 size = ARRAY_SIZE(bcma_arm_device_names);
106 break;
107 case BCMA_MANUF_BCM:
108 names = bcma_bcm_device_names;
109 size = ARRAY_SIZE(bcma_bcm_device_names);
110 break;
111 case BCMA_MANUF_MIPS:
112 names = bcma_mips_device_names;
113 size = ARRAY_SIZE(bcma_mips_device_names);
114 break;
115 default:
116 return "UNKNOWN";
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200117 }
Nathan Hintz82a7c2b2012-05-04 21:56:31 -0700118
119 for (i = 0; i < size; i++) {
120 if (names[i].id == id->id)
121 return names[i].name;
122 }
123
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200124 return "UNKNOWN";
125}
126
127static u32 bcma_scan_read32(struct bcma_bus *bus, u8 current_coreidx,
128 u16 offset)
129{
130 return readl(bus->mmio + offset);
131}
132
133static void bcma_scan_switch_core(struct bcma_bus *bus, u32 addr)
134{
135 if (bus->hosttype == BCMA_HOSTTYPE_PCI)
136 pci_write_config_dword(bus->host_pci, BCMA_PCI_BAR0_WIN,
137 addr);
138}
139
140static u32 bcma_erom_get_ent(struct bcma_bus *bus, u32 **eromptr)
141{
142 u32 ent = readl(*eromptr);
143 (*eromptr)++;
144 return ent;
145}
146
147static void bcma_erom_push_ent(u32 **eromptr)
148{
149 (*eromptr)--;
150}
151
152static s32 bcma_erom_get_ci(struct bcma_bus *bus, u32 **eromptr)
153{
154 u32 ent = bcma_erom_get_ent(bus, eromptr);
155 if (!(ent & SCAN_ER_VALID))
156 return -ENOENT;
157 if ((ent & SCAN_ER_TAG) != SCAN_ER_TAG_CI)
158 return -ENOENT;
159 return ent;
160}
161
162static bool bcma_erom_is_end(struct bcma_bus *bus, u32 **eromptr)
163{
164 u32 ent = bcma_erom_get_ent(bus, eromptr);
165 bcma_erom_push_ent(eromptr);
166 return (ent == (SCAN_ER_TAG_END | SCAN_ER_VALID));
167}
168
169static bool bcma_erom_is_bridge(struct bcma_bus *bus, u32 **eromptr)
170{
171 u32 ent = bcma_erom_get_ent(bus, eromptr);
172 bcma_erom_push_ent(eromptr);
173 return (((ent & SCAN_ER_VALID)) &&
174 ((ent & SCAN_ER_TAGX) == SCAN_ER_TAG_ADDR) &&
175 ((ent & SCAN_ADDR_TYPE) == SCAN_ADDR_TYPE_BRIDGE));
176}
177
178static void bcma_erom_skip_component(struct bcma_bus *bus, u32 **eromptr)
179{
180 u32 ent;
181 while (1) {
182 ent = bcma_erom_get_ent(bus, eromptr);
183 if ((ent & SCAN_ER_VALID) &&
184 ((ent & SCAN_ER_TAG) == SCAN_ER_TAG_CI))
185 break;
186 if (ent == (SCAN_ER_TAG_END | SCAN_ER_VALID))
187 break;
188 }
189 bcma_erom_push_ent(eromptr);
190}
191
192static s32 bcma_erom_get_mst_port(struct bcma_bus *bus, u32 **eromptr)
193{
194 u32 ent = bcma_erom_get_ent(bus, eromptr);
195 if (!(ent & SCAN_ER_VALID))
196 return -ENOENT;
197 if ((ent & SCAN_ER_TAG) != SCAN_ER_TAG_MP)
198 return -ENOENT;
199 return ent;
200}
201
202static s32 bcma_erom_get_addr_desc(struct bcma_bus *bus, u32 **eromptr,
203 u32 type, u8 port)
204{
205 u32 addrl, addrh, sizel, sizeh = 0;
206 u32 size;
207
208 u32 ent = bcma_erom_get_ent(bus, eromptr);
209 if ((!(ent & SCAN_ER_VALID)) ||
210 ((ent & SCAN_ER_TAGX) != SCAN_ER_TAG_ADDR) ||
211 ((ent & SCAN_ADDR_TYPE) != type) ||
212 (((ent & SCAN_ADDR_PORT) >> SCAN_ADDR_PORT_SHIFT) != port)) {
213 bcma_erom_push_ent(eromptr);
214 return -EINVAL;
215 }
216
217 addrl = ent & SCAN_ADDR_ADDR;
218 if (ent & SCAN_ADDR_AG32)
219 addrh = bcma_erom_get_ent(bus, eromptr);
220 else
221 addrh = 0;
222
223 if ((ent & SCAN_ADDR_SZ) == SCAN_ADDR_SZ_SZD) {
224 size = bcma_erom_get_ent(bus, eromptr);
225 sizel = size & SCAN_SIZE_SZ;
226 if (size & SCAN_SIZE_SG32)
227 sizeh = bcma_erom_get_ent(bus, eromptr);
228 } else
229 sizel = SCAN_ADDR_SZ_BASE <<
230 ((ent & SCAN_ADDR_SZ) >> SCAN_ADDR_SZ_SHIFT);
231
232 return addrl;
233}
234
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200235static struct bcma_device *bcma_find_core_by_index(struct bcma_bus *bus,
236 u16 index)
237{
238 struct bcma_device *core;
239
240 list_for_each_entry(core, &bus->cores, list) {
241 if (core->core_index == index)
242 return core;
243 }
244 return NULL;
245}
246
Hauke Mehrtens5f2d6172012-01-31 00:03:31 +0100247static struct bcma_device *bcma_find_core_reverse(struct bcma_bus *bus, u16 coreid)
248{
249 struct bcma_device *core;
250
251 list_for_each_entry_reverse(core, &bus->cores, list) {
252 if (core->id.id == coreid)
253 return core;
254 }
255 return NULL;
256}
257
Hauke Mehrtens982eee62011-07-23 01:20:05 +0200258static int bcma_get_next_core(struct bcma_bus *bus, u32 __iomem **eromptr,
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200259 struct bcma_device_id *match, int core_num,
Hauke Mehrtens982eee62011-07-23 01:20:05 +0200260 struct bcma_device *core)
261{
262 s32 tmp;
263 u8 i, j;
264 s32 cia, cib;
265 u8 ports[2], wrappers[2];
266
267 /* get CIs */
268 cia = bcma_erom_get_ci(bus, eromptr);
269 if (cia < 0) {
270 bcma_erom_push_ent(eromptr);
271 if (bcma_erom_is_end(bus, eromptr))
272 return -ESPIPE;
273 return -EILSEQ;
274 }
275 cib = bcma_erom_get_ci(bus, eromptr);
276 if (cib < 0)
277 return -EILSEQ;
278
279 /* parse CIs */
280 core->id.class = (cia & SCAN_CIA_CLASS) >> SCAN_CIA_CLASS_SHIFT;
281 core->id.id = (cia & SCAN_CIA_ID) >> SCAN_CIA_ID_SHIFT;
282 core->id.manuf = (cia & SCAN_CIA_MANUF) >> SCAN_CIA_MANUF_SHIFT;
283 ports[0] = (cib & SCAN_CIB_NMP) >> SCAN_CIB_NMP_SHIFT;
284 ports[1] = (cib & SCAN_CIB_NSP) >> SCAN_CIB_NSP_SHIFT;
285 wrappers[0] = (cib & SCAN_CIB_NMW) >> SCAN_CIB_NMW_SHIFT;
286 wrappers[1] = (cib & SCAN_CIB_NSW) >> SCAN_CIB_NSW_SHIFT;
287 core->id.rev = (cib & SCAN_CIB_REV) >> SCAN_CIB_REV_SHIFT;
288
289 if (((core->id.manuf == BCMA_MANUF_ARM) &&
290 (core->id.id == 0xFFF)) ||
291 (ports[1] == 0)) {
292 bcma_erom_skip_component(bus, eromptr);
293 return -ENXIO;
294 }
295
296 /* check if component is a core at all */
297 if (wrappers[0] + wrappers[1] == 0) {
298 /* we could save addrl of the router
299 if (cid == BCMA_CORE_OOB_ROUTER)
300 */
301 bcma_erom_skip_component(bus, eromptr);
302 return -ENXIO;
303 }
304
305 if (bcma_erom_is_bridge(bus, eromptr)) {
306 bcma_erom_skip_component(bus, eromptr);
307 return -ENXIO;
308 }
309
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200310 if (bcma_find_core_by_index(bus, core_num)) {
311 bcma_erom_skip_component(bus, eromptr);
312 return -ENODEV;
313 }
314
315 if (match && ((match->manuf != BCMA_ANY_MANUF &&
316 match->manuf != core->id.manuf) ||
317 (match->id != BCMA_ANY_ID && match->id != core->id.id) ||
318 (match->rev != BCMA_ANY_REV && match->rev != core->id.rev) ||
319 (match->class != BCMA_ANY_CLASS && match->class != core->id.class)
320 )) {
321 bcma_erom_skip_component(bus, eromptr);
322 return -ENODEV;
323 }
324
Hauke Mehrtens982eee62011-07-23 01:20:05 +0200325 /* get & parse master ports */
326 for (i = 0; i < ports[0]; i++) {
Dan Carpenter4e0d8cc2011-08-23 22:15:35 +0300327 s32 mst_port_d = bcma_erom_get_mst_port(bus, eromptr);
Hauke Mehrtens982eee62011-07-23 01:20:05 +0200328 if (mst_port_d < 0)
329 return -EILSEQ;
330 }
331
Hauke Mehrtense167d9f2012-03-15 23:49:56 +0100332 /* First Slave Address Descriptor should be port 0:
333 * the main register space for the core
334 */
335 tmp = bcma_erom_get_addr_desc(bus, eromptr, SCAN_ADDR_TYPE_SLAVE, 0);
336 if (tmp <= 0) {
337 /* Try again to see if it is a bridge */
338 tmp = bcma_erom_get_addr_desc(bus, eromptr,
339 SCAN_ADDR_TYPE_BRIDGE, 0);
340 if (tmp <= 0) {
341 return -EILSEQ;
342 } else {
343 pr_info("Bridge found\n");
344 return -ENXIO;
345 }
346 }
347 core->addr = tmp;
348
Hauke Mehrtens982eee62011-07-23 01:20:05 +0200349 /* get & parse slave ports */
350 for (i = 0; i < ports[1]; i++) {
351 for (j = 0; ; j++) {
352 tmp = bcma_erom_get_addr_desc(bus, eromptr,
353 SCAN_ADDR_TYPE_SLAVE, i);
354 if (tmp < 0) {
355 /* no more entries for port _i_ */
356 /* pr_debug("erom: slave port %d "
357 * "has %d descriptors\n", i, j); */
358 break;
359 } else {
360 if (i == 0 && j == 0)
Hauke Mehrtense167d9f2012-03-15 23:49:56 +0100361 core->addr1 = tmp;
Hauke Mehrtens982eee62011-07-23 01:20:05 +0200362 }
363 }
364 }
365
366 /* get & parse master wrappers */
367 for (i = 0; i < wrappers[0]; i++) {
368 for (j = 0; ; j++) {
369 tmp = bcma_erom_get_addr_desc(bus, eromptr,
370 SCAN_ADDR_TYPE_MWRAP, i);
371 if (tmp < 0) {
372 /* no more entries for port _i_ */
373 /* pr_debug("erom: master wrapper %d "
374 * "has %d descriptors\n", i, j); */
375 break;
376 } else {
377 if (i == 0 && j == 0)
378 core->wrap = tmp;
379 }
380 }
381 }
382
383 /* get & parse slave wrappers */
384 for (i = 0; i < wrappers[1]; i++) {
385 u8 hack = (ports[1] == 1) ? 0 : 1;
386 for (j = 0; ; j++) {
387 tmp = bcma_erom_get_addr_desc(bus, eromptr,
388 SCAN_ADDR_TYPE_SWRAP, i + hack);
389 if (tmp < 0) {
390 /* no more entries for port _i_ */
391 /* pr_debug("erom: master wrapper %d "
392 * has %d descriptors\n", i, j); */
393 break;
394 } else {
395 if (wrappers[0] == 0 && !i && !j)
396 core->wrap = tmp;
397 }
398 }
399 }
Hauke Mehrtensecd177c2011-07-23 01:20:08 +0200400 if (bus->hosttype == BCMA_HOSTTYPE_SOC) {
401 core->io_addr = ioremap_nocache(core->addr, BCMA_CORE_SIZE);
402 if (!core->io_addr)
403 return -ENOMEM;
404 core->io_wrap = ioremap_nocache(core->wrap, BCMA_CORE_SIZE);
405 if (!core->io_wrap) {
406 iounmap(core->io_addr);
407 return -ENOMEM;
408 }
409 }
Hauke Mehrtens982eee62011-07-23 01:20:05 +0200410 return 0;
411}
412
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200413void bcma_init_bus(struct bcma_bus *bus)
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200414{
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200415 s32 tmp;
Hauke Mehrtensf0d47242012-02-01 00:13:54 +0100416 struct bcma_chipinfo *chipinfo = &(bus->chipinfo);
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200417
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200418 if (bus->init_done)
419 return;
420
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200421 INIT_LIST_HEAD(&bus->cores);
422 bus->nr_cores = 0;
423
424 bcma_scan_switch_core(bus, BCMA_ADDR_BASE);
425
426 tmp = bcma_scan_read32(bus, 0, BCMA_CC_ID);
Hauke Mehrtensf0d47242012-02-01 00:13:54 +0100427 chipinfo->id = (tmp & BCMA_CC_ID_ID) >> BCMA_CC_ID_ID_SHIFT;
428 chipinfo->rev = (tmp & BCMA_CC_ID_REV) >> BCMA_CC_ID_REV_SHIFT;
429 chipinfo->pkg = (tmp & BCMA_CC_ID_PKG) >> BCMA_CC_ID_PKG_SHIFT;
430 pr_info("Found chip with id 0x%04X, rev 0x%02X and package 0x%02X\n",
431 chipinfo->id, chipinfo->rev, chipinfo->pkg);
432
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200433 bus->init_done = true;
Hauke Mehrtens67a5c292011-07-23 01:20:06 +0200434}
435
436int bcma_bus_scan(struct bcma_bus *bus)
437{
438 u32 erombase;
439 u32 __iomem *eromptr, *eromend;
440
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200441 int err, core_num = 0;
Hauke Mehrtens67a5c292011-07-23 01:20:06 +0200442
443 bcma_init_bus(bus);
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200444
445 erombase = bcma_scan_read32(bus, 0, BCMA_CC_EROM);
Hauke Mehrtensecd177c2011-07-23 01:20:08 +0200446 if (bus->hosttype == BCMA_HOSTTYPE_SOC) {
447 eromptr = ioremap_nocache(erombase, BCMA_CORE_SIZE);
448 if (!eromptr)
449 return -ENOMEM;
450 } else {
451 eromptr = bus->mmio;
452 }
453
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200454 eromend = eromptr + BCMA_CORE_SIZE / sizeof(u32);
455
456 bcma_scan_switch_core(bus, erombase);
457
458 while (eromptr < eromend) {
Hauke Mehrtens5f2d6172012-01-31 00:03:31 +0100459 struct bcma_device *other_core;
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200460 struct bcma_device *core = kzalloc(sizeof(*core), GFP_KERNEL);
461 if (!core)
462 return -ENOMEM;
463 INIT_LIST_HEAD(&core->list);
464 core->bus = bus;
465
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200466 err = bcma_get_next_core(bus, &eromptr, NULL, core_num, core);
Jesper Juhlf9721ed2012-01-29 21:34:04 +0100467 if (err < 0) {
468 kfree(core);
469 if (err == -ENODEV) {
470 core_num++;
471 continue;
472 } else if (err == -ENXIO) {
473 continue;
474 } else if (err == -ESPIPE) {
475 break;
476 }
Hauke Mehrtens982eee62011-07-23 01:20:05 +0200477 return err;
Jesper Juhlf9721ed2012-01-29 21:34:04 +0100478 }
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200479
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200480 core->core_index = core_num++;
481 bus->nr_cores++;
Hauke Mehrtens5f2d6172012-01-31 00:03:31 +0100482 other_core = bcma_find_core_reverse(bus, core->id.id);
483 core->core_unit = (other_core == NULL) ? 0 : other_core->core_unit + 1;
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200484
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200485 pr_info("Core %d found: %s "
486 "(manuf 0x%03X, id 0x%03X, rev 0x%02X, class 0x%X)\n",
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200487 core->core_index, bcma_device_name(&core->id),
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200488 core->id.manuf, core->id.id, core->id.rev,
489 core->id.class);
490
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200491 list_add(&core->list, &bus->cores);
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200492 }
493
Hauke Mehrtensecd177c2011-07-23 01:20:08 +0200494 if (bus->hosttype == BCMA_HOSTTYPE_SOC)
495 iounmap(eromptr);
496
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200497 return 0;
498}
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200499
500int __init bcma_bus_scan_early(struct bcma_bus *bus,
501 struct bcma_device_id *match,
502 struct bcma_device *core)
503{
504 u32 erombase;
505 u32 __iomem *eromptr, *eromend;
506
Hauke Mehrtensecd177c2011-07-23 01:20:08 +0200507 int err = -ENODEV;
508 int core_num = 0;
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200509
510 erombase = bcma_scan_read32(bus, 0, BCMA_CC_EROM);
Hauke Mehrtensecd177c2011-07-23 01:20:08 +0200511 if (bus->hosttype == BCMA_HOSTTYPE_SOC) {
512 eromptr = ioremap_nocache(erombase, BCMA_CORE_SIZE);
513 if (!eromptr)
514 return -ENOMEM;
515 } else {
516 eromptr = bus->mmio;
517 }
518
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200519 eromend = eromptr + BCMA_CORE_SIZE / sizeof(u32);
520
521 bcma_scan_switch_core(bus, erombase);
522
523 while (eromptr < eromend) {
524 memset(core, 0, sizeof(*core));
525 INIT_LIST_HEAD(&core->list);
526 core->bus = bus;
527
528 err = bcma_get_next_core(bus, &eromptr, match, core_num, core);
529 if (err == -ENODEV) {
530 core_num++;
531 continue;
532 } else if (err == -ENXIO)
533 continue;
534 else if (err == -ESPIPE)
535 break;
536 else if (err < 0)
537 return err;
538
539 core->core_index = core_num++;
540 bus->nr_cores++;
541 pr_info("Core %d found: %s "
542 "(manuf 0x%03X, id 0x%03X, rev 0x%02X, class 0x%X)\n",
543 core->core_index, bcma_device_name(&core->id),
544 core->id.manuf, core->id.id, core->id.rev,
545 core->id.class);
546
547 list_add(&core->list, &bus->cores);
Hauke Mehrtensecd177c2011-07-23 01:20:08 +0200548 err = 0;
549 break;
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200550 }
551
Hauke Mehrtensecd177c2011-07-23 01:20:08 +0200552 if (bus->hosttype == BCMA_HOSTTYPE_SOC)
553 iounmap(eromptr);
554
555 return err;
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200556}