Skip to content

Commit a027237

Browse files
haukelinvjw
authored andcommitted
bcma: add support for sprom not found on the device
On SoCs the sprom is stored in the nvram in a special partition on the flash chip. The nvram contains the sprom for the main bus, but sometimes also for a pci devices using bcma. This patch makes it possible for the arch code to register a function to fetch the needed sprom from the nvram and provide it to the bcma code. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent 1c9351c commit a027237

2 files changed

Lines changed: 75 additions & 8 deletions

File tree

‎drivers/bcma/sprom.c‎

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Broadcom specific AMBA
33
* SPROM reading
44
*
5+
* Copyright 2011, 2012, Hauke Mehrtens <hauke@hauke-m.de>
6+
*
57
* Licensed under the GNU/GPL. See COPYING for details.
68
*/
79

@@ -14,6 +16,45 @@
1416
#include <linux/dma-mapping.h>
1517
#include <linux/slab.h>
1618

19+
static int(*get_fallback_sprom)(struct bcma_bus *dev, struct ssb_sprom *out);
20+
21+
/**
22+
* bcma_arch_register_fallback_sprom - Registers a method providing a
23+
* fallback SPROM if no SPROM is found.
24+
*
25+
* @sprom_callback: The callback function.
26+
*
27+
* With this function the architecture implementation may register a
28+
* callback handler which fills the SPROM data structure. The fallback is
29+
* used for PCI based BCMA devices, where no valid SPROM can be found
30+
* in the shadow registers and to provide the SPROM for SoCs where BCMA is
31+
* to controll the system bus.
32+
*
33+
* This function is useful for weird architectures that have a half-assed
34+
* BCMA device hardwired to their PCI bus.
35+
*
36+
* This function is available for architecture code, only. So it is not
37+
* exported.
38+
*/
39+
int bcma_arch_register_fallback_sprom(int (*sprom_callback)(struct bcma_bus *bus,
40+
struct ssb_sprom *out))
41+
{
42+
if (get_fallback_sprom)
43+
return -EEXIST;
44+
get_fallback_sprom = sprom_callback;
45+
46+
return 0;
47+
}
48+
49+
static int bcma_fill_sprom_with_fallback(struct bcma_bus *bus,
50+
struct ssb_sprom *out)
51+
{
52+
if (!get_fallback_sprom)
53+
return -ENOENT;
54+
55+
return get_fallback_sprom(bus, out);
56+
}
57+
1758
/**************************************************
1859
* R/W ops.
1960
**************************************************/
@@ -246,23 +287,43 @@ static void bcma_sprom_extract_r8(struct bcma_bus *bus, const u16 *sprom)
246287
SSB_SROM8_FEM_ANTSWLUT_SHIFT);
247288
}
248289

290+
static bool bcma_is_sprom_available(struct bcma_bus *bus)
291+
{
292+
u32 sromctrl;
293+
294+
if (!(bus->drv_cc.capabilities & BCMA_CC_CAP_SPROM))
295+
return false;
296+
297+
if (bus->drv_cc.core->id.rev >= 32) {
298+
sromctrl = bcma_read32(bus->drv_cc.core, BCMA_CC_SROM_CONTROL);
299+
return sromctrl & BCMA_CC_SROM_CONTROL_PRESENT;
300+
}
301+
return true;
302+
}
303+
249304
int bcma_sprom_get(struct bcma_bus *bus)
250305
{
251306
u16 offset;
252307
u16 *sprom;
253-
u32 sromctrl;
254308
int err = 0;
255309

256310
if (!bus->drv_cc.core)
257311
return -EOPNOTSUPP;
258312

259-
if (!(bus->drv_cc.capabilities & BCMA_CC_CAP_SPROM))
260-
return -ENOENT;
261-
262-
if (bus->drv_cc.core->id.rev >= 32) {
263-
sromctrl = bcma_read32(bus->drv_cc.core, BCMA_CC_SROM_CONTROL);
264-
if (!(sromctrl & BCMA_CC_SROM_CONTROL_PRESENT))
265-
return -ENOENT;
313+
if (!bcma_is_sprom_available(bus)) {
314+
/*
315+
* Maybe there is no SPROM on the device?
316+
* Now we ask the arch code if there is some sprom
317+
* available for this device in some other storage.
318+
*/
319+
err = bcma_fill_sprom_with_fallback(bus, &bus->sprom);
320+
if (err) {
321+
pr_warn("Using fallback SPROM failed (err %d)\n", err);
322+
} else {
323+
pr_debug("Using SPROM revision %d provided by"
324+
" platform.\n", bus->sprom.revision);
325+
return 0;
326+
}
266327
}
267328

268329
sprom = kcalloc(SSB_SPROMSIZE_WORDS_R4, sizeof(u16),

‎include/linux/bcma/bcma.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ int __bcma_driver_register(struct bcma_driver *drv, struct module *owner);
176176

177177
extern void bcma_driver_unregister(struct bcma_driver *drv);
178178

179+
/* Set a fallback SPROM.
180+
* See kdoc at the function definition for complete documentation. */
181+
extern int bcma_arch_register_fallback_sprom(
182+
int (*sprom_callback)(struct bcma_bus *bus,
183+
struct ssb_sprom *out));
184+
179185
struct bcma_bus {
180186
/* The MMIO area. */
181187
void __iomem *mmio;

0 commit comments

Comments
 (0)