Commit 982eee67 authored by Hauke Mehrtens's avatar Hauke Mehrtens Committed by John W. Linville

bcma: move parsing of EEPROM into own function.

Move the parsing of the EEPROM data in scan function for one core into
an own function. Now we are able to use it in some other scan function
as well.
Acked-by: default avatarRafał Miłecki <zajec5@gmail.com>
Signed-off-by: default avatarHauke Mehrtens <hauke@hauke-m.de>
Acked-by: default avatarRalf Baechle <ralf@linux-mips.org>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 581c9c4f
...@@ -200,56 +200,25 @@ static s32 bcma_erom_get_addr_desc(struct bcma_bus *bus, u32 **eromptr, ...@@ -200,56 +200,25 @@ static s32 bcma_erom_get_addr_desc(struct bcma_bus *bus, u32 **eromptr,
return addrl; return addrl;
} }
int bcma_bus_scan(struct bcma_bus *bus) static int bcma_get_next_core(struct bcma_bus *bus, u32 __iomem **eromptr,
struct bcma_device *core)
{ {
u32 erombase;
u32 __iomem *eromptr, *eromend;
s32 cia, cib;
u8 ports[2], wrappers[2];
s32 tmp; s32 tmp;
u8 i, j; u8 i, j;
s32 cia, cib;
int err; u8 ports[2], wrappers[2];
INIT_LIST_HEAD(&bus->cores);
bus->nr_cores = 0;
bcma_scan_switch_core(bus, BCMA_ADDR_BASE);
tmp = bcma_scan_read32(bus, 0, BCMA_CC_ID);
bus->chipinfo.id = (tmp & BCMA_CC_ID_ID) >> BCMA_CC_ID_ID_SHIFT;
bus->chipinfo.rev = (tmp & BCMA_CC_ID_REV) >> BCMA_CC_ID_REV_SHIFT;
bus->chipinfo.pkg = (tmp & BCMA_CC_ID_PKG) >> BCMA_CC_ID_PKG_SHIFT;
erombase = bcma_scan_read32(bus, 0, BCMA_CC_EROM);
eromptr = bus->mmio;
eromend = eromptr + BCMA_CORE_SIZE / sizeof(u32);
bcma_scan_switch_core(bus, erombase);
while (eromptr < eromend) {
struct bcma_device *core = kzalloc(sizeof(*core), GFP_KERNEL);
if (!core)
return -ENOMEM;
INIT_LIST_HEAD(&core->list);
core->bus = bus;
/* get CIs */ /* get CIs */
cia = bcma_erom_get_ci(bus, &eromptr); cia = bcma_erom_get_ci(bus, eromptr);
if (cia < 0) { if (cia < 0) {
bcma_erom_push_ent(&eromptr); bcma_erom_push_ent(eromptr);
if (bcma_erom_is_end(bus, &eromptr)) if (bcma_erom_is_end(bus, eromptr))
break; return -ESPIPE;
err= -EILSEQ; return -EILSEQ;
goto out;
}
cib = bcma_erom_get_ci(bus, &eromptr);
if (cib < 0) {
err= -EILSEQ;
goto out;
} }
cib = bcma_erom_get_ci(bus, eromptr);
if (cib < 0)
return -EILSEQ;
/* parse CIs */ /* parse CIs */
core->id.class = (cia & SCAN_CIA_CLASS) >> SCAN_CIA_CLASS_SHIFT; core->id.class = (cia & SCAN_CIA_CLASS) >> SCAN_CIA_CLASS_SHIFT;
...@@ -264,8 +233,8 @@ int bcma_bus_scan(struct bcma_bus *bus) ...@@ -264,8 +233,8 @@ int bcma_bus_scan(struct bcma_bus *bus)
if (((core->id.manuf == BCMA_MANUF_ARM) && if (((core->id.manuf == BCMA_MANUF_ARM) &&
(core->id.id == 0xFFF)) || (core->id.id == 0xFFF)) ||
(ports[1] == 0)) { (ports[1] == 0)) {
bcma_erom_skip_component(bus, &eromptr); bcma_erom_skip_component(bus, eromptr);
continue; return -ENXIO;
} }
/* check if component is a core at all */ /* check if component is a core at all */
...@@ -273,28 +242,26 @@ int bcma_bus_scan(struct bcma_bus *bus) ...@@ -273,28 +242,26 @@ int bcma_bus_scan(struct bcma_bus *bus)
/* we could save addrl of the router /* we could save addrl of the router
if (cid == BCMA_CORE_OOB_ROUTER) if (cid == BCMA_CORE_OOB_ROUTER)
*/ */
bcma_erom_skip_component(bus, &eromptr); bcma_erom_skip_component(bus, eromptr);
continue; return -ENXIO;
} }
if (bcma_erom_is_bridge(bus, &eromptr)) { if (bcma_erom_is_bridge(bus, eromptr)) {
bcma_erom_skip_component(bus, &eromptr); bcma_erom_skip_component(bus, eromptr);
continue; return -ENXIO;
} }
/* get & parse master ports */ /* get & parse master ports */
for (i = 0; i < ports[0]; i++) { for (i = 0; i < ports[0]; i++) {
u32 mst_port_d = bcma_erom_get_mst_port(bus, &eromptr); u32 mst_port_d = bcma_erom_get_mst_port(bus, eromptr);
if (mst_port_d < 0) { if (mst_port_d < 0)
err= -EILSEQ; return -EILSEQ;
goto out;
}
} }
/* get & parse slave ports */ /* get & parse slave ports */
for (i = 0; i < ports[1]; i++) { for (i = 0; i < ports[1]; i++) {
for (j = 0; ; j++) { for (j = 0; ; j++) {
tmp = bcma_erom_get_addr_desc(bus, &eromptr, tmp = bcma_erom_get_addr_desc(bus, eromptr,
SCAN_ADDR_TYPE_SLAVE, i); SCAN_ADDR_TYPE_SLAVE, i);
if (tmp < 0) { if (tmp < 0) {
/* no more entries for port _i_ */ /* no more entries for port _i_ */
...@@ -311,7 +278,7 @@ int bcma_bus_scan(struct bcma_bus *bus) ...@@ -311,7 +278,7 @@ int bcma_bus_scan(struct bcma_bus *bus)
/* get & parse master wrappers */ /* get & parse master wrappers */
for (i = 0; i < wrappers[0]; i++) { for (i = 0; i < wrappers[0]; i++) {
for (j = 0; ; j++) { for (j = 0; ; j++) {
tmp = bcma_erom_get_addr_desc(bus, &eromptr, tmp = bcma_erom_get_addr_desc(bus, eromptr,
SCAN_ADDR_TYPE_MWRAP, i); SCAN_ADDR_TYPE_MWRAP, i);
if (tmp < 0) { if (tmp < 0) {
/* no more entries for port _i_ */ /* no more entries for port _i_ */
...@@ -329,7 +296,7 @@ int bcma_bus_scan(struct bcma_bus *bus) ...@@ -329,7 +296,7 @@ int bcma_bus_scan(struct bcma_bus *bus)
for (i = 0; i < wrappers[1]; i++) { for (i = 0; i < wrappers[1]; i++) {
u8 hack = (ports[1] == 1) ? 0 : 1; u8 hack = (ports[1] == 1) ? 0 : 1;
for (j = 0; ; j++) { for (j = 0; ; j++) {
tmp = bcma_erom_get_addr_desc(bus, &eromptr, tmp = bcma_erom_get_addr_desc(bus, eromptr,
SCAN_ADDR_TYPE_SWRAP, i + hack); SCAN_ADDR_TYPE_SWRAP, i + hack);
if (tmp < 0) { if (tmp < 0) {
/* no more entries for port _i_ */ /* no more entries for port _i_ */
...@@ -342,6 +309,48 @@ int bcma_bus_scan(struct bcma_bus *bus) ...@@ -342,6 +309,48 @@ int bcma_bus_scan(struct bcma_bus *bus)
} }
} }
} }
return 0;
}
int bcma_bus_scan(struct bcma_bus *bus)
{
u32 erombase;
u32 __iomem *eromptr, *eromend;
s32 tmp;
int err;
INIT_LIST_HEAD(&bus->cores);
bus->nr_cores = 0;
bcma_scan_switch_core(bus, BCMA_ADDR_BASE);
tmp = bcma_scan_read32(bus, 0, BCMA_CC_ID);
bus->chipinfo.id = (tmp & BCMA_CC_ID_ID) >> BCMA_CC_ID_ID_SHIFT;
bus->chipinfo.rev = (tmp & BCMA_CC_ID_REV) >> BCMA_CC_ID_REV_SHIFT;
bus->chipinfo.pkg = (tmp & BCMA_CC_ID_PKG) >> BCMA_CC_ID_PKG_SHIFT;
erombase = bcma_scan_read32(bus, 0, BCMA_CC_EROM);
eromptr = bus->mmio;
eromend = eromptr + BCMA_CORE_SIZE / sizeof(u32);
bcma_scan_switch_core(bus, erombase);
while (eromptr < eromend) {
struct bcma_device *core = kzalloc(sizeof(*core), GFP_KERNEL);
if (!core)
return -ENOMEM;
INIT_LIST_HEAD(&core->list);
core->bus = bus;
err = bcma_get_next_core(bus, &eromptr, core);
if (err == -ENXIO)
continue;
else if (err == -ESPIPE)
break;
else if (err < 0)
return err;
pr_info("Core %d found: %s " pr_info("Core %d found: %s "
"(manuf 0x%03X, id 0x%03X, rev 0x%02X, class 0x%X)\n", "(manuf 0x%03X, id 0x%03X, rev 0x%02X, class 0x%X)\n",
...@@ -351,9 +360,6 @@ int bcma_bus_scan(struct bcma_bus *bus) ...@@ -351,9 +360,6 @@ int bcma_bus_scan(struct bcma_bus *bus)
core->core_index = bus->nr_cores++; core->core_index = bus->nr_cores++;
list_add(&core->list, &bus->cores); list_add(&core->list, &bus->cores);
continue;
out:
return err;
} }
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment