mirror of https://github.com/hak5/openwrt-owl.git
bcm53xx: sprom: simplify reading NVRAM after last backports
Signed-off-by: Rafał Miłecki <zajec5@gmail.com> SVN-Revision: 45229owl
parent
bb0e931298
commit
91071e366c
|
@ -32,9 +32,6 @@
|
||||||
struct bcm47xx_sprom_fill {
|
struct bcm47xx_sprom_fill {
|
||||||
const char *prefix;
|
const char *prefix;
|
||||||
bool fallback;
|
bool fallback;
|
||||||
int (*getenv)(const struct bcm47xx_sprom_fill *fill, const char *name,
|
|
||||||
char *val, size_t val_len);
|
|
||||||
const void *priv;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void create_key(const char *prefix, const char *postfix,
|
static void create_key(const char *prefix, const char *postfix,
|
||||||
|
@ -59,10 +56,10 @@ static int get_nvram_var(const struct bcm47xx_sprom_fill *fill,
|
||||||
|
|
||||||
create_key(fill->prefix, postfix, name, key, sizeof(key));
|
create_key(fill->prefix, postfix, name, key, sizeof(key));
|
||||||
|
|
||||||
err = fill->getenv(fill, key, buf, len);
|
err = bcm47xx_nvram_getenv(key, buf, len);
|
||||||
if (fill->fallback && err == -ENOENT && fill->prefix) {
|
if (fill->fallback && err == -ENOENT && fill->prefix) {
|
||||||
create_key(NULL, postfix, name, key, sizeof(key));
|
create_key(NULL, postfix, name, key, sizeof(key));
|
||||||
err = fill->getenv(fill, key, buf, len);
|
err = bcm47xx_nvram_getenv(key, buf, len);
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -635,15 +632,6 @@ static void bcm47xx_sprom_fill(struct ssb_sprom *sprom,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bcm47xx_sprom_getenv(const struct bcm47xx_sprom_fill *fill,
|
|
||||||
const char *name, char *val, size_t val_len)
|
|
||||||
{
|
|
||||||
return bcm47xx_nvram_getenv(name, val, val_len);
|
|
||||||
};
|
|
||||||
|
|
||||||
/* FIXME: This should not be static, but some callback argument */
|
|
||||||
static struct platform_device *sprom_pdev = NULL;
|
|
||||||
|
|
||||||
static char prefix[20];
|
static char prefix[20];
|
||||||
|
|
||||||
static void bcm47xx_sprom_apply_prefix_alias(char *prefix, size_t prefix_size)
|
static void bcm47xx_sprom_apply_prefix_alias(char *prefix, size_t prefix_size)
|
||||||
|
@ -681,26 +669,8 @@ static void bcm47xx_sprom_apply_prefix_alias(char *prefix, size_t prefix_size)
|
||||||
*/
|
*/
|
||||||
static int bcm47xx_sprom_init(struct bcma_bus *bus, struct ssb_sprom *out)
|
static int bcm47xx_sprom_init(struct bcma_bus *bus, struct ssb_sprom *out)
|
||||||
{
|
{
|
||||||
struct platform_device *pdev = sprom_pdev;
|
|
||||||
struct device *dev = &pdev->dev;
|
|
||||||
struct device_node *np = dev->of_node;
|
|
||||||
const __be32 *handle;
|
|
||||||
struct device_node *nvram_node;
|
|
||||||
struct platform_device *nvram_dev;
|
|
||||||
struct bcm47xx_sprom_fill fill;
|
struct bcm47xx_sprom_fill fill;
|
||||||
|
|
||||||
handle = of_get_property(np, "nvram", NULL);
|
|
||||||
if (!handle)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
nvram_node = of_find_node_by_phandle(be32_to_cpup(handle));
|
|
||||||
if (!nvram_node)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
nvram_dev = of_find_device_by_node(nvram_node);
|
|
||||||
if (!nvram_dev)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
switch (bus->hosttype) {
|
switch (bus->hosttype) {
|
||||||
case BCMA_HOSTTYPE_PCI:
|
case BCMA_HOSTTYPE_PCI:
|
||||||
snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
|
snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
|
||||||
|
@ -710,7 +680,7 @@ static int bcm47xx_sprom_init(struct bcma_bus *bus, struct ssb_sprom *out)
|
||||||
fill.prefix = prefix;
|
fill.prefix = prefix;
|
||||||
break;
|
break;
|
||||||
case BCMA_HOSTTYPE_SOC:
|
case BCMA_HOSTTYPE_SOC:
|
||||||
fill.prefix = of_get_property(np, "prefix", NULL);
|
fill.prefix = NULL;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
pr_err("Unable to fill SPROM for given hosttype.\n");
|
pr_err("Unable to fill SPROM for given hosttype.\n");
|
||||||
|
@ -718,8 +688,6 @@ static int bcm47xx_sprom_init(struct bcma_bus *bus, struct ssb_sprom *out)
|
||||||
}
|
}
|
||||||
|
|
||||||
fill.fallback = false;
|
fill.fallback = false;
|
||||||
fill.getenv = bcm47xx_sprom_getenv;
|
|
||||||
fill.priv = nvram_dev;
|
|
||||||
|
|
||||||
bcm47xx_sprom_fill(out, &fill);
|
bcm47xx_sprom_fill(out, &fill);
|
||||||
|
|
||||||
|
@ -728,9 +696,6 @@ static int bcm47xx_sprom_init(struct bcma_bus *bus, struct ssb_sprom *out)
|
||||||
|
|
||||||
static int bcm47xx_sprom_probe(struct platform_device *pdev)
|
static int bcm47xx_sprom_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
/* This is the only way to make pdev accessible to the callback */
|
|
||||||
sprom_pdev = pdev;
|
|
||||||
|
|
||||||
return bcma_arch_register_fallback_sprom(&bcm47xx_sprom_init);
|
return bcma_arch_register_fallback_sprom(&bcm47xx_sprom_init);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue