1 From 9a920f4d8eed485f7b73e9b13dab0e49c64d3ff8 Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sat, 18 Jun 2011 14:30:55 +0200
4 Subject: [PATCH 03/14] bcma: add functions to scan cores needed on SoCs
6 The chip common and mips core have to be setup early in the boot
7 process to get the cpu clock.
8 bcma_bus_early_register() gets pointers to some space to store the core
9 data and searches for the chip common and mips core and initializes
10 chip common. After that was done and the kernel is out of early boot we
11 just have to run bcma_bus_register() and it will search for the other
12 cores, initialize and register them.
14 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
16 drivers/bcma/bcma_private.h | 7 ++
17 drivers/bcma/driver_chipcommon.c | 5 ++
18 drivers/bcma/driver_pci.c | 3 +
19 drivers/bcma/main.c | 45 +++++++++++++
20 drivers/bcma/scan.c | 95 +++++++++++++++++++++++++--
21 include/linux/bcma/bcma.h | 1 +
22 include/linux/bcma/bcma_driver_chipcommon.h | 1 +
23 7 files changed, 151 insertions(+), 6 deletions(-)
25 --- a/drivers/bcma/bcma_private.h
26 +++ b/drivers/bcma/bcma_private.h
27 @@ -15,9 +15,16 @@ struct bcma_bus;
29 int bcma_bus_register(struct bcma_bus *bus);
30 void bcma_bus_unregister(struct bcma_bus *bus);
31 +int __init bcma_bus_early_register(struct bcma_bus *bus,
32 + struct bcma_device *core_cc,
33 + struct bcma_device *core_mips);
36 int bcma_bus_scan(struct bcma_bus *bus);
37 +int __init bcma_bus_scan_early(struct bcma_bus *bus,
38 + struct bcma_device_id *match,
39 + struct bcma_device *core);
40 +void bcma_init_bus(struct bcma_bus *bus);
43 int bcma_sprom_get(struct bcma_bus *bus);
44 --- a/drivers/bcma/driver_chipcommon.c
45 +++ b/drivers/bcma/driver_chipcommon.c
46 @@ -23,6 +23,9 @@ static inline u32 bcma_cc_write32_masked
48 void bcma_core_chipcommon_init(struct bcma_drv_cc *cc)
53 if (cc->core->id.rev >= 11)
54 cc->status = bcma_cc_read32(cc, BCMA_CC_CHIPSTAT);
55 cc->capabilities = bcma_cc_read32(cc, BCMA_CC_CAP);
56 @@ -38,6 +41,8 @@ void bcma_core_chipcommon_init(struct bc
58 if (cc->capabilities & BCMA_CC_CAP_PCTL)
59 pr_err("Power control not implemented!\n");
61 + cc->setup_done = true;
64 /* Set chip watchdog reset timer to fire in 'ticks' backplane cycles */
65 --- a/drivers/bcma/driver_pci.c
66 +++ b/drivers/bcma/driver_pci.c
67 @@ -159,7 +159,10 @@ static void bcma_pcicore_serdes_workarou
69 void bcma_core_pci_init(struct bcma_drv_pci *pc)
73 bcma_pcicore_serdes_workaround(pc);
74 + pc->setup_done = true;
77 int bcma_core_pci_irq_ctl(struct bcma_drv_pci *pc, struct bcma_device *core,
78 --- a/drivers/bcma/main.c
79 +++ b/drivers/bcma/main.c
80 @@ -167,6 +167,51 @@ void bcma_bus_unregister(struct bcma_bus
81 bcma_unregister_cores(bus);
84 +int __init bcma_bus_early_register(struct bcma_bus *bus,
85 + struct bcma_device *core_cc,
86 + struct bcma_device *core_mips)
89 + struct bcma_device *core;
90 + struct bcma_device_id match;
94 + match.manuf = BCMA_MANUF_BCM;
95 + match.id = BCMA_CORE_CHIPCOMMON;
96 + match.class = BCMA_CL_SIM;
97 + match.rev = BCMA_ANY_REV;
99 + /* Scan for devices (cores) */
100 + err = bcma_bus_scan_early(bus, &match, core_cc);
102 + pr_err("Failed to scan for common core: %d\n", err);
106 + match.manuf = BCMA_MANUF_MIPS;
107 + match.id = BCMA_CORE_MIPS_74K;
108 + match.class = BCMA_CL_SIM;
109 + match.rev = BCMA_ANY_REV;
111 + err = bcma_bus_scan_early(bus, &match, core_mips);
113 + pr_err("Failed to scan for mips core: %d\n", err);
118 + core = bcma_find_core(bus, BCMA_CORE_CHIPCOMMON);
120 + bus->drv_cc.core = core;
121 + bcma_core_chipcommon_init(&bus->drv_cc);
124 + pr_info("Early bus registered\n");
129 int __bcma_driver_register(struct bcma_driver *drv, struct module *owner)
131 drv->drv.name = drv->name;
132 --- a/drivers/bcma/scan.c
133 +++ b/drivers/bcma/scan.c
134 @@ -200,7 +200,20 @@ static s32 bcma_erom_get_addr_desc(struc
138 +static struct bcma_device *bcma_find_core_by_index(struct bcma_bus *bus,
141 + struct bcma_device *core;
143 + list_for_each_entry(core, &bus->cores, list) {
144 + if (core->core_index == index)
150 static int bcma_get_next_core(struct bcma_bus *bus, u32 __iomem **eromptr,
151 + struct bcma_device_id *match, int core_num,
152 struct bcma_device *core)
155 @@ -251,6 +264,21 @@ static int bcma_get_next_core(struct bcm
159 + if (bcma_find_core_by_index(bus, core_num)) {
160 + bcma_erom_skip_component(bus, eromptr);
164 + if (match && ((match->manuf != BCMA_ANY_MANUF &&
165 + match->manuf != core->id.manuf) ||
166 + (match->id != BCMA_ANY_ID && match->id != core->id.id) ||
167 + (match->rev != BCMA_ANY_REV && match->rev != core->id.rev) ||
168 + (match->class != BCMA_ANY_CLASS && match->class != core->id.class)
170 + bcma_erom_skip_component(bus, eromptr);
174 /* get & parse master ports */
175 for (i = 0; i < ports[0]; i++) {
176 u32 mst_port_d = bcma_erom_get_mst_port(bus, eromptr);
177 @@ -312,10 +340,13 @@ static int bcma_get_next_core(struct bcm
181 -static void bcma_init_bus(struct bcma_bus *bus)
182 +void bcma_init_bus(struct bcma_bus *bus)
186 + if (bus->init_done)
189 INIT_LIST_HEAD(&bus->cores);
192 @@ -325,6 +356,7 @@ static void bcma_init_bus(struct bcma_bu
193 bus->chipinfo.id = (tmp & BCMA_CC_ID_ID) >> BCMA_CC_ID_ID_SHIFT;
194 bus->chipinfo.rev = (tmp & BCMA_CC_ID_REV) >> BCMA_CC_ID_REV_SHIFT;
195 bus->chipinfo.pkg = (tmp & BCMA_CC_ID_PKG) >> BCMA_CC_ID_PKG_SHIFT;
196 + bus->init_done = true;
199 int bcma_bus_scan(struct bcma_bus *bus)
200 @@ -332,7 +364,7 @@ int bcma_bus_scan(struct bcma_bus *bus)
202 u32 __iomem *eromptr, *eromend;
205 + int err, core_num = 0;
209 @@ -349,23 +381,74 @@ int bcma_bus_scan(struct bcma_bus *bus)
210 INIT_LIST_HEAD(&core->list);
213 - err = bcma_get_next_core(bus, &eromptr, core);
215 + err = bcma_get_next_core(bus, &eromptr, NULL, core_num, core);
216 + if (err == -ENODEV) {
219 + } else if (err == -ENXIO)
221 else if (err == -ESPIPE)
226 + core->core_index = core_num++;
229 pr_info("Core %d found: %s "
230 "(manuf 0x%03X, id 0x%03X, rev 0x%02X, class 0x%X)\n",
231 - bus->nr_cores, bcma_device_name(&core->id),
232 + core->core_index, bcma_device_name(&core->id),
233 core->id.manuf, core->id.id, core->id.rev,
236 - core->core_index = bus->nr_cores++;
237 list_add(&core->list, &bus->cores);
243 +int __init bcma_bus_scan_early(struct bcma_bus *bus,
244 + struct bcma_device_id *match,
245 + struct bcma_device *core)
248 + u32 __iomem *eromptr, *eromend;
250 + int err, core_num = 0;
252 + erombase = bcma_scan_read32(bus, 0, BCMA_CC_EROM);
253 + eromptr = bus->mmio;
254 + eromend = eromptr + BCMA_CORE_SIZE / sizeof(u32);
256 + bcma_scan_switch_core(bus, erombase);
258 + while (eromptr < eromend) {
259 + memset(core, 0, sizeof(*core));
260 + INIT_LIST_HEAD(&core->list);
263 + err = bcma_get_next_core(bus, &eromptr, match, core_num, core);
264 + if (err == -ENODEV) {
267 + } else if (err == -ENXIO)
269 + else if (err == -ESPIPE)
274 + core->core_index = core_num++;
276 + pr_info("Core %d found: %s "
277 + "(manuf 0x%03X, id 0x%03X, rev 0x%02X, class 0x%X)\n",
278 + core->core_index, bcma_device_name(&core->id),
279 + core->id.manuf, core->id.id, core->id.rev,
282 + list_add(&core->list, &bus->cores);
288 --- a/include/linux/bcma/bcma.h
289 +++ b/include/linux/bcma/bcma.h
290 @@ -185,6 +185,7 @@ struct bcma_bus {
291 struct bcma_device *mapped_core;
292 struct list_head cores;
296 struct bcma_drv_cc drv_cc;
297 struct bcma_drv_pci drv_pci;
298 --- a/include/linux/bcma/bcma_driver_chipcommon.h
299 +++ b/include/linux/bcma/bcma_driver_chipcommon.h
300 @@ -259,6 +259,7 @@ struct bcma_drv_cc {
303 u32 capabilities_ext;
305 /* Fast Powerup Delay constant */
306 u16 fast_pwrup_delay;
307 struct bcma_chipcommon_pmu pmu;