-From 60a413ed5bc7917f1612df441240f458163b10c1 Mon Sep 17 00:00:00 2001
+From 71a6bff8656a1713615ffdd9139a83d65ba46c6d Mon Sep 17 00:00:00 2001
From: Hauke Mehrtens <hauke@hauke-m.de>
Date: Sat, 3 May 2014 22:54:59 +0200
-Subject: [PATCH 03/15] bcm47xx-nvram: add new nvram driver with dt support
+Subject: [PATCH 02/17] bcm47xx-nvram: add new broadcom nvram driver with dt
+ support
-This adds a new nvrm driver which uses device tree to provide nvram
-access to other drivers. You have to specify the memory ranges where
-the flash chip is mapped and this driver will search there for some
-nvram and parse it. Other drivers can use this driver to access the
+This adds a new driver which searches at a given memory range for a
+nvram like it is used on the bcm47xx and bcm53xx SoCs with ARM and MIPS
+CPUs. This driver provides acces to this nvram to other device in the
+device tree. You have to specify the memory ranges where the content of
+the flash chip is memory mapped and this driver will search there for
+some nvram and parse it. Other drivers can use this driver to access the
device nvram. The nvram is used to store board configurations like the
-mac address and also for configuration values in the vendor firmware.
+mac addresses, the switch configuration and the calibration data for
+the wifi devices.
+
+This was copied from arch/mips/bcm47xx/nvram.c and modified to interact
+with device tree. My plan is to make the MIPS bcm47xx also use this new
+driver some time later.
+
+Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
---
- arch/mips/bcm47xx/board.c | 36 +++---
- arch/mips/bcm47xx/nvram.c | 7 +-
- arch/mips/bcm47xx/setup.c | 4 +-
- arch/mips/bcm47xx/sprom.c | 4 +-
- arch/mips/bcm47xx/time.c | 2 +-
- drivers/misc/Kconfig | 5 +
- drivers/misc/Makefile | 1 +
- drivers/misc/bcm47xx-nvram.c | 211 ++++++++++++++++++++++++++++++++++
- drivers/net/ethernet/broadcom/b44.c | 2 +-
- drivers/net/ethernet/broadcom/bgmac.c | 4 +-
- drivers/ssb/driver_chipcommon_pmu.c | 2 +-
- include/linux/bcm47xx_nvram.h | 16 ++-
- 12 files changed, 259 insertions(+), 35 deletions(-)
+ .../devicetree/bindings/misc/bcm47xx-nvram.txt | 19 ++
+ arch/mips/bcm47xx/board.c | 40 ++--
+ arch/mips/bcm47xx/nvram.c | 7 +-
+ arch/mips/bcm47xx/setup.c | 4 +-
+ arch/mips/bcm47xx/sprom.c | 4 +-
+ arch/mips/bcm47xx/time.c | 2 +-
+ drivers/misc/Kconfig | 5 +
+ drivers/misc/Makefile | 1 +
+ drivers/misc/bcm47xx-nvram.c | 215 +++++++++++++++++++++
+ drivers/net/ethernet/broadcom/b44.c | 2 +-
+ drivers/net/ethernet/broadcom/bgmac.c | 5 +-
+ drivers/ssb/driver_chipcommon_pmu.c | 3 +-
+ include/linux/bcm47xx_nvram.h | 17 +-
+ 13 files changed, 286 insertions(+), 38 deletions(-)
+ create mode 100644 Documentation/devicetree/bindings/misc/bcm47xx-nvram.txt
create mode 100644 drivers/misc/bcm47xx-nvram.c
+--- /dev/null
++++ b/Documentation/devicetree/bindings/misc/bcm47xx-nvram.txt
+@@ -0,0 +1,19 @@
++Broadcom bcm47xx/bcm53xx nvram access driver
++
++This driver provides access to the nvram for other drivers.
++
++Required properties:
++
++- compatible : brcm,bcm47xx-nvram
++
++- reg : iomem address range
++
++On NorthStar ARM SoCs the NAND flash is available at 0x1c000000 and the
++NOR flash is at 0x1e000000
++
++Example:
++
++nvram0: nvram@0 {
++ compatible = "brcm,bcm47xx-nvram";
++ reg = <0x1c000000 0x01000000>;
++};
--- a/arch/mips/bcm47xx/board.c
+++ b/arch/mips/bcm47xx/board.c
@@ -196,50 +196,50 @@ static __init const struct bcm47xx_board
+obj-$(CONFIG_BCM47XX_NVRAM) += bcm47xx-nvram.o
--- /dev/null
+++ b/drivers/misc/bcm47xx-nvram.c
-@@ -0,0 +1,211 @@
+@@ -0,0 +1,215 @@
+/*
+ * BCM947xx nvram variable access
+ *
+
+static u32 find_nvram_size(void __iomem *end)
+{
-+ struct nvram_header *header;
++ struct nvram_header __iomem *header;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) {
-+ header = (struct nvram_header *)(end - nvram_sizes[i]);
-+ if (header->magic == NVRAM_HEADER)
++ header = (struct nvram_header __iomem *)(end - nvram_sizes[i]);
++ if (__raw_readl(&header->magic) == NVRAM_HEADER)
+ return nvram_sizes[i];
+ }
+
+ size_t len, char **nvram_buf,
+ size_t *nvram_len)
+{
-+ struct nvram_header *header;
++ struct nvram_header __iomem *header;
+ int i;
+ u32 off;
-+ u32 *src, *dst;
++ u32 *dst;
++ __le32 __iomem *src;
+ u32 size;
+
+ /* TODO: when nvram is on nand flash check for bad blocks first. */
+ /* Windowed flash access */
+ size = find_nvram_size(base + off);
+ if (size) {
-+ header = (struct nvram_header *)(base + off - size);
++ header = (struct nvram_header __iomem *)
++ (base + off - size);
+ goto found;
+ }
-+ off <<= 1;
++ off += 0x10000;
+ }
+
+ /* Try embedded NVRAM at 4 KB and 1 KB as last resorts */
-+ header = (struct nvram_header *)(base + 4096);
-+ if (header->magic == NVRAM_HEADER) {
++ header = (struct nvram_header __iomem *)(base + 4096);
++ if (__raw_readl(&header->magic) == NVRAM_HEADER) {
+ size = NVRAM_SPACE;
+ goto found;
+ }
+
-+ header = (struct nvram_header *)(base + 1024);
-+ if (header->magic == NVRAM_HEADER) {
++ header = (struct nvram_header __iomem *)(base + 1024);
++ if (__raw_readl(&header->magic) == NVRAM_HEADER) {
+ size = NVRAM_SPACE;
+ goto found;
+ }
+ return -ENXIO;
+
+found:
-+ if (header->len > size)
++ if (readl(&header->len) > size)
+ pr_err("The nvram size accoridng to the header seems to be bigger than the partition on flash\n");
-+ *nvram_len = min_t(u32, header->len, size);
++ *nvram_len = min_t(u32, readl(&header->len), size);
+
+ *nvram_buf = devm_kzalloc(dev, *nvram_len, GFP_KERNEL);
+ if (!*nvram_buf)
+ return -ENOMEM;
+
-+ src = (u32 *) header;
++ src = (__le32 __iomem *) header;
+ dst = (u32 *) *nvram_buf;
+ for (i = 0; i < sizeof(struct nvram_header); i += 4)
-+ *dst++ = *src++;
++ *dst++ = __raw_readl(src++);
+ for (; i < *nvram_len; i += 4)
-+ *dst++ = le32_to_cpu(*src++);
++ *dst++ = readl(src++);
+
+ return 0;
+}
+
-+int bcm47xx_nvram_getenv(const struct device *dev, const char *name, char *val, size_t val_len)
++int bcm47xx_nvram_getenv(const struct device *dev, const char *name, char *val,
++ size_t val_len)
+{
+ char *var, *value, *end, *eq;
+ struct bcm47xx_nvram *nvram;
+ if (!mmio)
+ return -ENOMEM;
+
-+ err = nvram_find_and_copy(dev, mmio, resource_size(&flash_mem), &nvram->nvram_buf, &nvram->nvram_len);
++ err = nvram_find_and_copy(dev, mmio, resource_size(&flash_mem),
++ &nvram->nvram_buf, &nvram->nvram_len);
+ if (err)
+ goto err_unmap_mmio;
+
err = __b44_readphy(bp, 0, MII_BMCR, &val);
--- a/drivers/net/ethernet/broadcom/bgmac.c
+++ b/drivers/net/ethernet/broadcom/bgmac.c
-@@ -974,7 +974,7 @@ static void bgmac_chip_reset(struct bgma
+@@ -974,7 +974,8 @@ static void bgmac_chip_reset(struct bgma
BGMAC_CHIPCTL_1_IF_TYPE_MII;
char buf[4];
- if (bcm47xx_nvram_getenv("et_swtype", buf, sizeof(buf)) > 0) {
-+ if (bcm47xx_nvram_getenv(NULL, "et_swtype", buf, sizeof(buf)) > 0) {
++ if (bcm47xx_nvram_getenv(NULL, "et_swtype", buf,
++ sizeof(buf)) > 0) {
if (kstrtou8(buf, 0, &et_swtype))
bgmac_err(bgmac, "Failed to parse et_swtype (%s)\n",
buf);
-@@ -1534,7 +1534,7 @@ static int bgmac_probe(struct bcma_devic
+@@ -1534,7 +1535,7 @@ static int bgmac_probe(struct bcma_devic
}
bgmac->int_mask = BGMAC_IS_ERRMASK | BGMAC_IS_RX | BGMAC_IS_TX_MASK;
/* TODO: reset the external phy. Specs are needed */
--- a/drivers/ssb/driver_chipcommon_pmu.c
+++ b/drivers/ssb/driver_chipcommon_pmu.c
-@@ -319,7 +319,7 @@ static void ssb_pmu_pll_init(struct ssb_
+@@ -319,7 +319,8 @@ static void ssb_pmu_pll_init(struct ssb_
if (bus->bustype == SSB_BUSTYPE_SSB) {
char buf[20];
- if (bcm47xx_nvram_getenv("xtalfreq", buf, sizeof(buf)) >= 0)
-+ if (bcm47xx_nvram_getenv(NULL, "xtalfreq", buf, sizeof(buf)) >= 0)
++ if (bcm47xx_nvram_getenv(NULL, "xtalfreq", buf,
++ sizeof(buf)) >= 0)
crystalfreq = simple_strtoul(buf, NULL, 0);
}
--- a/include/linux/bcm47xx_nvram.h
+++ b/include/linux/bcm47xx_nvram.h
-@@ -15,6 +15,8 @@
+@@ -15,9 +15,11 @@
#include <linux/types.h>
#include <linux/kernel.h>
+
struct nvram_header {
u32 magic;
- u32 len;
-@@ -33,17 +35,21 @@ struct nvram_header {
+- u32 len;
++ __le32 len;
+ u32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
+ u32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */
+ u32 config_ncdl; /* ncdl values for memc */
+@@ -33,18 +35,21 @@ struct nvram_header {
#define NVRAM_MAX_VALUE_LEN 255
#define NVRAM_MAX_PARAM_LEN 64
-int bcm47xx_nvram_gpio_pin(const char *name);
+int bcm47xx_nvram_gpio_pin(const struct device *dev, const char *name);
#else
--static inline int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len)
+-static inline int bcm47xx_nvram_getenv(const char *name, char *val,
+static inline int bcm47xx_nvram_getenv(const struct device *dev,
+ const char *name, char *val,
-+ size_t val_len)
+ size_t val_len)
{
return -ENXIO;
}
-From b113f9d3e140f18e63cbf3408b3dcde372242dc8 Mon Sep 17 00:00:00 2001
+From 4e0ab3269a6d260a41a3673157753147f5f71341 Mon Sep 17 00:00:00 2001
From: Hauke Mehrtens <hauke@hauke-m.de>
Date: Sun, 4 May 2014 13:19:20 +0200
-Subject: [PATCH 04/15] bcm53xx-sprom: add sprom driver
+Subject: [PATCH 03/17] bcm47xx-sprom: add Broadcom sprom parser driver
This driver needs an nvram driver and fetches the sprom values from the
-sprom and provides it to any other driver. The calibration data for the
+nvram and provides it to any other driver. The calibration data for the
wifi chip the mac address and some more board description data is
stores in the sprom.
+This is based on a copy of arch/mips/bcm47xx/sprom.c and my plan is to
+make the bcm47xx MIPS SoCs also use this driver some time later.
+
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
---
- drivers/misc/Kconfig | 5 +
- drivers/misc/Makefile | 1 +
- drivers/misc/bcm53xx-sprom.c | 625 +++++++++++++++++++++++++++++++++++++++++++
- 3 files changed, 631 insertions(+)
- create mode 100644 drivers/misc/bcm53xx-sprom.c
+ .../devicetree/bindings/misc/bcm47xx-sprom.txt | 16 +
+ drivers/misc/Kconfig | 11 +
+ drivers/misc/Makefile | 1 +
+ drivers/misc/bcm47xx-sprom.c | 690 +++++++++++++++++++++
+ 4 files changed, 718 insertions(+)
+ create mode 100644 Documentation/devicetree/bindings/misc/bcm47xx-sprom.txt
+ create mode 100644 drivers/misc/bcm47xx-sprom.c
+--- /dev/null
++++ b/Documentation/devicetree/bindings/misc/bcm47xx-sprom.txt
+@@ -0,0 +1,16 @@
++Broadcom bcm47xx/bcm53xx sprom converter
++
++This driver provbides an sprom based on a given nvram.
++
++Required properties:
++
++- compatible : brcm,bcm47xx-sprom
++
++- nvram : reference to a nvram driver, e.g. bcm47xx-nvram
++
++Example:
++
++sprom0: sprom@0 {
++ compatible = "brcm,bcm47xx-sprom";
++ nvram = <&nvram0>;
++};
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
-@@ -520,6 +520,11 @@ config BCM47XX_NVRAM
+@@ -520,6 +520,17 @@ config BCM47XX_NVRAM
help
This adds support for the brcm47xx nvram driver.
-+config BCM53XX_SPROM
-+ tristate "BCM53XX sprom driver"
++config BCM47XX_SPROM
++ tristate "BCM47XX sprom driver"
+ help
-+ This adds support for the brcm53xx sprom driver.
++ This driver parses the sprom from a given nvram which is found on
++ Broadcom bcm47xx and bcm53xx SoCs.
++
++ The sprom contains board configuration data like the
++ calibration data fro the wifi chips, the mac addresses used
++ by the board and many other board configuration data. This
++ driver will provide the sprom to bcma.
+
source "drivers/misc/c2port/Kconfig"
source "drivers/misc/eeprom/Kconfig"
obj-y += mic/
obj-$(CONFIG_GENWQE) += genwqe/
obj-$(CONFIG_BCM47XX_NVRAM) += bcm47xx-nvram.o
-+obj-$(CONFIG_BCM53XX_SPROM) += bcm53xx-sprom.o
++obj-$(CONFIG_BCM47XX_SPROM) += bcm47xx-sprom.o
--- /dev/null
-+++ b/drivers/misc/bcm53xx-sprom.c
-@@ -0,0 +1,625 @@
++++ b/drivers/misc/bcm47xx-sprom.c
+@@ -0,0 +1,690 @@
+/*
-+ * BCM947xx nvram variable access
++ * BCM47xx/BCM53xx nvram variable access
+ *
+ * Copyright (C) 2005 Broadcom Corporation
+ * Copyright (C) 2004 Florian Schirmer <jolt@tuxbox.org>
+#include <linux/io.h>
+#include <linux/ssb/ssb.h>
+#include <linux/bcm47xx_nvram.h>
++#include <linux/if_ether.h>
++#include <linux/etherdevice.h>
+
-+struct bcm53xx_sprom_fill {
++struct bcm47xx_sprom_fill {
+ const char *prefix;
+ bool fallback;
-+ int (*getenv)(const struct bcm53xx_sprom_fill *fill, const char *name, char *val, size_t val_len);
++ int (*getenv)(const struct bcm47xx_sprom_fill *fill, const char *name,
++ char *val, size_t val_len);
+ const void *priv;
+};
+
+ snprintf(buf, len, "%s", name);
+}
+
-+static int get_nvram_var(const struct bcm53xx_sprom_fill *fill, const char *postfix,
-+ const char *name, char *buf, int len)
++static int get_nvram_var(const struct bcm47xx_sprom_fill *fill,
++ const char *postfix, const char *name, char *buf,
++ int len)
+{
+ char key[40];
+ int err;
+}
+
+#define NVRAM_READ_VAL(type) \
-+static void nvram_read_ ## type (const struct bcm53xx_sprom_fill *fill, \
++static void nvram_read_ ## type (const struct bcm47xx_sprom_fill *fill, \
+ const char *postfix, const char *name, \
+ type *val, type allset) \
+{ \
+
+#undef NVRAM_READ_VAL
+
-+static void nvram_read_u32_2(const struct bcm53xx_sprom_fill *fill, const char *name,
-+ u16 *val_lo, u16 *val_hi)
++static void nvram_read_u32_2(const struct bcm47xx_sprom_fill *fill,
++ const char *name, u16 *val_lo, u16 *val_hi)
+{
+ char buf[100];
+ int err;
+ *val_hi = (val & 0xFFFF0000U) >> 16;
+}
+
-+static void nvram_read_leddc(const struct bcm53xx_sprom_fill *fill, const char *name,
-+ u8 *leddc_on_time, u8 *leddc_off_time)
++static void nvram_read_leddc(const struct bcm47xx_sprom_fill *fill,
++ const char *name, u8 *leddc_on_time,
++ u8 *leddc_off_time)
+{
+ char buf[100];
+ int err;
+ *leddc_off_time = (val >> 16) & 0xff;
+}
+
-+static void nvram_read_macaddr(const struct bcm53xx_sprom_fill *fill, const char *name,
-+ u8 val[6])
++static void nvram_read_macaddr(const struct bcm47xx_sprom_fill *fill,
++ const char *name, u8 val[6])
+{
+ char buf[100];
+ int err;
+ bcm47xx_nvram_parse_macaddr(buf, val);
+}
+
-+static void nvram_read_alpha2(const struct bcm53xx_sprom_fill *fill, const char *name,
-+ char val[2])
++static void nvram_read_alpha2(const struct bcm47xx_sprom_fill *fill,
++ const char *name, char val[2])
+{
+ char buf[10];
+ int err;
+ memcpy(val, buf, 2);
+}
+
-+static void bcm53xx_sprom_fill_r1234589(struct ssb_sprom *sprom,
-+ const struct bcm53xx_sprom_fill *fill)
++static void bcm47xx_sprom_fill_r1234589(struct ssb_sprom *sprom,
++ const struct bcm47xx_sprom_fill *fill)
+{
++ nvram_read_u16(fill, NULL, "devid", &sprom->dev_id, 0);
+ nvram_read_u8(fill, NULL, "ledbh0", &sprom->gpio0, 0xff);
+ nvram_read_u8(fill, NULL, "ledbh1", &sprom->gpio1, 0xff);
+ nvram_read_u8(fill, NULL, "ledbh2", &sprom->gpio2, 0xff);
+ nvram_read_alpha2(fill, "ccode", sprom->alpha2);
+}
+
-+static void bcm53xx_sprom_fill_r12389(struct ssb_sprom *sprom,
-+ const struct bcm53xx_sprom_fill *fill)
++static void bcm47xx_sprom_fill_r12389(struct ssb_sprom *sprom,
++ const struct bcm47xx_sprom_fill *fill)
+{
+ nvram_read_u16(fill, NULL, "pa0b0", &sprom->pa0b0, 0);
+ nvram_read_u16(fill, NULL, "pa0b1", &sprom->pa0b1, 0);
+ nvram_read_u8(fill, NULL, "pa1maxpwr", &sprom->maxpwr_a, 0);
+}
+
-+static void bcm53xx_sprom_fill_r1(struct ssb_sprom *sprom,
-+ const struct bcm53xx_sprom_fill *fill)
++static void bcm47xx_sprom_fill_r1(struct ssb_sprom *sprom,
++ const struct bcm47xx_sprom_fill *fill)
+{
+ nvram_read_u16(fill, NULL, "boardflags", &sprom->boardflags_lo, 0);
+ nvram_read_u8(fill, NULL, "cc", &sprom->country_code, 0);
+}
+
-+static void bcm53xx_sprom_fill_r2389(struct ssb_sprom *sprom,
-+ const struct bcm53xx_sprom_fill *fill)
++static void bcm47xx_sprom_fill_r2389(struct ssb_sprom *sprom,
++ const struct bcm47xx_sprom_fill *fill)
+{
+ nvram_read_u8(fill, NULL, "opo", &sprom->opo, 0);
+ nvram_read_u16(fill, NULL, "pa1lob0", &sprom->pa1lob0, 0);
+ nvram_read_u8(fill, NULL, "pa1himaxpwr", &sprom->maxpwr_ah, 0);
+}
+
-+static void bcm53xx_sprom_fill_r389(struct ssb_sprom *sprom,
-+ const struct bcm53xx_sprom_fill *fill)
++static void bcm47xx_sprom_fill_r389(struct ssb_sprom *sprom,
++ const struct bcm47xx_sprom_fill *fill)
+{
+ nvram_read_u8(fill, NULL, "bxa2g", &sprom->bxa2g, 0);
+ nvram_read_u8(fill, NULL, "rssisav2g", &sprom->rssisav2g, 0);
+ nvram_read_s8(fill, NULL, "rxpo5g", &sprom->rxpo5g, 0);
+}
+
-+static void bcm53xx_sprom_fill_r3(struct ssb_sprom *sprom,
-+ const struct bcm53xx_sprom_fill *fill)
++static void bcm47xx_sprom_fill_r3(struct ssb_sprom *sprom,
++ const struct bcm47xx_sprom_fill *fill)
+{
+ nvram_read_u8(fill, NULL, "regrev", &sprom->regrev, 0);
+ nvram_read_leddc(fill, "leddc", &sprom->leddc_on_time,
+ &sprom->leddc_off_time);
+}
+
-+static void bcm53xx_sprom_fill_r4589(struct ssb_sprom *sprom,
-+ const struct bcm53xx_sprom_fill *fill)
++static void bcm47xx_sprom_fill_r4589(struct ssb_sprom *sprom,
++ const struct bcm47xx_sprom_fill *fill)
+{
+ nvram_read_u8(fill, NULL, "regrev", &sprom->regrev, 0);
+ nvram_read_s8(fill, NULL, "ag2", &sprom->antenna_gain.a2, 0);
+ &sprom->leddc_off_time);
+}
+
-+static void bcm53xx_sprom_fill_r458(struct ssb_sprom *sprom,
-+ const struct bcm53xx_sprom_fill *fill)
++static void bcm47xx_sprom_fill_r458(struct ssb_sprom *sprom,
++ const struct bcm47xx_sprom_fill *fill)
+{
+ nvram_read_u16(fill, NULL, "cck2gpo", &sprom->cck2gpo, 0);
+ nvram_read_u32(fill, NULL, "ofdm2gpo", &sprom->ofdm2gpo, 0);
+ nvram_read_u16(fill, NULL, "mcs5ghpo7", &sprom->mcs5ghpo[7], 0);
+}
+
-+static void bcm53xx_sprom_fill_r45(struct ssb_sprom *sprom,
-+ const struct bcm53xx_sprom_fill *fill)
++static void bcm47xx_sprom_fill_r45(struct ssb_sprom *sprom,
++ const struct bcm47xx_sprom_fill *fill)
+{
+ nvram_read_u8(fill, NULL, "txpid2ga0", &sprom->txpid2g[0], 0);
+ nvram_read_u8(fill, NULL, "txpid2ga1", &sprom->txpid2g[1], 0);
+ nvram_read_u8(fill, NULL, "txpid5gha3", &sprom->txpid5gh[3], 0);
+}
+
-+static void bcm53xx_sprom_fill_r89(struct ssb_sprom *sprom,
-+ const struct bcm53xx_sprom_fill *fill)
++static void bcm47xx_sprom_fill_r89(struct ssb_sprom *sprom,
++ const struct bcm47xx_sprom_fill *fill)
+{
+ nvram_read_u8(fill, NULL, "tssipos2g", &sprom->fem.ghz2.tssipos, 0);
+ nvram_read_u8(fill, NULL, "extpagain2g", &sprom->fem.ghz2.extpa_gain, 0);
+ nvram_read_u8(fill, NULL, "pcieingress_war", &sprom->pcieingress_war, 0);
+}
+
-+static void bcm53xx_sprom_fill_r9(struct ssb_sprom *sprom,
-+ const struct bcm53xx_sprom_fill *fill)
++static void bcm47xx_sprom_fill_r9(struct ssb_sprom *sprom,
++ const struct bcm47xx_sprom_fill *fill)
+{
+ nvram_read_u16(fill, NULL, "cckbw202gpo", &sprom->cckbw202gpo, 0);
+ nvram_read_u16(fill, NULL, "cckbw20ul2gpo", &sprom->cckbw20ul2gpo, 0);
+ nvram_read_u8(fill, NULL, "sar5g", &sprom->sar5g, 0);
+}
+
-+static void bcm53xx_sprom_fill_path_r4589(struct ssb_sprom *sprom,
-+ const struct bcm53xx_sprom_fill *fill)
++static void bcm47xx_sprom_fill_path_r4589(struct ssb_sprom *sprom,
++ const struct bcm47xx_sprom_fill *fill)
+{
+ char postfix[2];
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(sprom->core_pwr_info); i++) {
+ struct ssb_sprom_core_pwr_info *pwr_info = &sprom->core_pwr_info[i];
++
+ snprintf(postfix, sizeof(postfix), "%i", i);
+ nvram_read_u8(fill, postfix, "maxp2ga", &pwr_info->maxpwr_2g, 0);
+ nvram_read_u8(fill, postfix, "itt2ga", &pwr_info->itssi_2g, 0);
+ }
+}
+
-+static void bcm53xx_sprom_fill_path_r45(struct ssb_sprom *sprom,
-+ const struct bcm53xx_sprom_fill *fill)
++static void bcm47xx_sprom_fill_path_r45(struct ssb_sprom *sprom,
++ const struct bcm47xx_sprom_fill *fill)
+{
+ char postfix[2];
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(sprom->core_pwr_info); i++) {
+ struct ssb_sprom_core_pwr_info *pwr_info = &sprom->core_pwr_info[i];
++
+ snprintf(postfix, sizeof(postfix), "%i", i);
+ nvram_read_u16(fill, postfix, "pa2gw3a", &pwr_info->pa_2g[3], 0);
+ nvram_read_u16(fill, postfix, "pa5gw3a", &pwr_info->pa_5g[3], 0);
+ }
+}
+
-+static void bcm53xx_sprom_fill_ethernet(struct ssb_sprom *sprom,
-+ const struct bcm53xx_sprom_fill *fill)
++static bool bcm47xx_is_valid_mac(u8 *mac)
++{
++ return mac && !(mac[0] == 0x00 && mac[1] == 0x90 && mac[2] == 0x4c);
++}
++
++static int bcm47xx_increase_mac_addr(u8 *mac, u8 num)
++{
++ u8 *oui = mac + ETH_ALEN/2 - 1;
++ u8 *p = mac + ETH_ALEN - 1;
++
++ do {
++ (*p) += num;
++ if (*p > num)
++ break;
++ p--;
++ num = 1;
++ } while (p != oui);
++
++ if (p == oui) {
++ pr_err("unable to fetch mac address\n");
++ return -ENOENT;
++ }
++ return 0;
++}
++
++/*
++ * This is a global counter because different instances of sprom will
++ * access the same nvram.
++ */
++static int mac_addr_used = 2;
++
++static void bcm47xx_sprom_fill_ethernet(struct ssb_sprom *sprom,
++ const struct bcm47xx_sprom_fill *fill)
+{
+ nvram_read_macaddr(fill, "et0macaddr", sprom->et0mac);
+ nvram_read_u8(fill, NULL, "et0mdcport", &sprom->et0mdcport, 0);
+
+ nvram_read_macaddr(fill, "macaddr", sprom->il0mac);
+ nvram_read_macaddr(fill, "il0macaddr", sprom->il0mac);
++
++ /*
++ * The address prefix 00:90:4C is used by Broadcom in their initial
++ * configuration. When a mac address with the prefix 00:90:4C is used
++ * all devices from the same series are sharing the same mac address.
++ * To prevent mac address collisions we replace them with a mac address
++ * based on the base address.
++ */
++ if (!bcm47xx_is_valid_mac(sprom->il0mac)) {
++ u8 mac[6];
++ struct bcm47xx_sprom_fill fill_no_prefix;
++
++ memcpy(&fill_no_prefix, fill, sizeof(fill_no_prefix));
++ fill_no_prefix.prefix = NULL;
++
++ nvram_read_macaddr(&fill_no_prefix, "et0macaddr", mac);
++ if (bcm47xx_is_valid_mac(mac)) {
++ int err = bcm47xx_increase_mac_addr(mac, mac_addr_used);
++
++ if (!err) {
++ ether_addr_copy(sprom->il0mac, mac);
++ mac_addr_used++;
++ }
++ }
++ }
+}
+
-+static void bcm53xx_sprom_fill_board_data(struct ssb_sprom *sprom,
-+ const struct bcm53xx_sprom_fill *fill)
++static void bcm47xx_sprom_fill_board_data(struct ssb_sprom *sprom,
++ const struct bcm47xx_sprom_fill *fill)
+{
+ nvram_read_u16(fill, NULL, "boardrev", &sprom->board_rev, 0);
+ nvram_read_u16(fill, NULL, "boardnum", &sprom->board_num, 0);
+ &sprom->boardflags2_hi);
+}
+
-+static void bcm53xx_sprom_fill(struct ssb_sprom *sprom,
-+ const struct bcm53xx_sprom_fill *fill)
++static void bcm47xx_sprom_fill(struct ssb_sprom *sprom,
++ const struct bcm47xx_sprom_fill *fill)
+{
-+ bcm53xx_sprom_fill_ethernet(sprom, fill);
-+ bcm53xx_sprom_fill_board_data(sprom, fill);
++ bcm47xx_sprom_fill_ethernet(sprom, fill);
++ bcm47xx_sprom_fill_board_data(sprom, fill);
+
+ nvram_read_u8(fill, NULL, "sromrev", &sprom->revision, 0);
+
+ switch (sprom->revision) {
+ case 1:
-+ bcm53xx_sprom_fill_r1234589(sprom, fill);
-+ bcm53xx_sprom_fill_r12389(sprom, fill);
-+ bcm53xx_sprom_fill_r1(sprom, fill);
++ bcm47xx_sprom_fill_r1234589(sprom, fill);
++ bcm47xx_sprom_fill_r12389(sprom, fill);
++ bcm47xx_sprom_fill_r1(sprom, fill);
+ break;
+ case 2:
-+ bcm53xx_sprom_fill_r1234589(sprom, fill);
-+ bcm53xx_sprom_fill_r12389(sprom, fill);
-+ bcm53xx_sprom_fill_r2389(sprom, fill);
++ bcm47xx_sprom_fill_r1234589(sprom, fill);
++ bcm47xx_sprom_fill_r12389(sprom, fill);
++ bcm47xx_sprom_fill_r2389(sprom, fill);
+ break;
+ case 3:
-+ bcm53xx_sprom_fill_r1234589(sprom, fill);
-+ bcm53xx_sprom_fill_r12389(sprom, fill);
-+ bcm53xx_sprom_fill_r2389(sprom, fill);
-+ bcm53xx_sprom_fill_r389(sprom, fill);
-+ bcm53xx_sprom_fill_r3(sprom, fill);
++ bcm47xx_sprom_fill_r1234589(sprom, fill);
++ bcm47xx_sprom_fill_r12389(sprom, fill);
++ bcm47xx_sprom_fill_r2389(sprom, fill);
++ bcm47xx_sprom_fill_r389(sprom, fill);
++ bcm47xx_sprom_fill_r3(sprom, fill);
+ break;
+ case 4:
+ case 5:
-+ bcm53xx_sprom_fill_r1234589(sprom, fill);
-+ bcm53xx_sprom_fill_r4589(sprom, fill);
-+ bcm53xx_sprom_fill_r458(sprom, fill);
-+ bcm53xx_sprom_fill_r45(sprom, fill);
-+ bcm53xx_sprom_fill_path_r4589(sprom, fill);
-+ bcm53xx_sprom_fill_path_r45(sprom, fill);
++ bcm47xx_sprom_fill_r1234589(sprom, fill);
++ bcm47xx_sprom_fill_r4589(sprom, fill);
++ bcm47xx_sprom_fill_r458(sprom, fill);
++ bcm47xx_sprom_fill_r45(sprom, fill);
++ bcm47xx_sprom_fill_path_r4589(sprom, fill);
++ bcm47xx_sprom_fill_path_r45(sprom, fill);
+ break;
+ case 8:
-+ bcm53xx_sprom_fill_r1234589(sprom, fill);
-+ bcm53xx_sprom_fill_r12389(sprom, fill);
-+ bcm53xx_sprom_fill_r2389(sprom, fill);
-+ bcm53xx_sprom_fill_r389(sprom, fill);
-+ bcm53xx_sprom_fill_r4589(sprom, fill);
-+ bcm53xx_sprom_fill_r458(sprom, fill);
-+ bcm53xx_sprom_fill_r89(sprom, fill);
-+ bcm53xx_sprom_fill_path_r4589(sprom, fill);
++ bcm47xx_sprom_fill_r1234589(sprom, fill);
++ bcm47xx_sprom_fill_r12389(sprom, fill);
++ bcm47xx_sprom_fill_r2389(sprom, fill);
++ bcm47xx_sprom_fill_r389(sprom, fill);
++ bcm47xx_sprom_fill_r4589(sprom, fill);
++ bcm47xx_sprom_fill_r458(sprom, fill);
++ bcm47xx_sprom_fill_r89(sprom, fill);
++ bcm47xx_sprom_fill_path_r4589(sprom, fill);
+ break;
+ case 9:
-+ bcm53xx_sprom_fill_r1234589(sprom, fill);
-+ bcm53xx_sprom_fill_r12389(sprom, fill);
-+ bcm53xx_sprom_fill_r2389(sprom, fill);
-+ bcm53xx_sprom_fill_r389(sprom, fill);
-+ bcm53xx_sprom_fill_r4589(sprom, fill);
-+ bcm53xx_sprom_fill_r89(sprom, fill);
-+ bcm53xx_sprom_fill_r9(sprom, fill);
-+ bcm53xx_sprom_fill_path_r4589(sprom, fill);
++ bcm47xx_sprom_fill_r1234589(sprom, fill);
++ bcm47xx_sprom_fill_r12389(sprom, fill);
++ bcm47xx_sprom_fill_r2389(sprom, fill);
++ bcm47xx_sprom_fill_r389(sprom, fill);
++ bcm47xx_sprom_fill_r4589(sprom, fill);
++ bcm47xx_sprom_fill_r89(sprom, fill);
++ bcm47xx_sprom_fill_r9(sprom, fill);
++ bcm47xx_sprom_fill_path_r4589(sprom, fill);
+ break;
+ default:
+ pr_warn("Unsupported SPROM revision %d detected. Will extract v1\n",
+ sprom->revision);
+ sprom->revision = 1;
-+ bcm53xx_sprom_fill_r1234589(sprom, fill);
-+ bcm53xx_sprom_fill_r12389(sprom, fill);
-+ bcm53xx_sprom_fill_r1(sprom, fill);
++ bcm47xx_sprom_fill_r1234589(sprom, fill);
++ bcm47xx_sprom_fill_r12389(sprom, fill);
++ bcm47xx_sprom_fill_r1(sprom, fill);
+ }
+}
+
-+static int bcm53xx_sprom_getenv(const struct bcm53xx_sprom_fill *fill,
++static int bcm47xx_sprom_getenv(const struct bcm47xx_sprom_fill *fill,
+ const char *name, char *val, size_t val_len)
+{
+ const struct platform_device *nvram_dev = fill->priv;
+ return bcm47xx_nvram_getenv(&nvram_dev->dev, name, val, val_len);
+};
+
-+static int bcm53xx_sprom_probe(struct platform_device *pdev)
++static int bcm47xx_sprom_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct device_node *np = dev->of_node;
+ struct ssb_sprom *sprom;
-+ const phandle *handle;
++ const __be32 *handle;
+ struct device_node *nvram_node;
+ struct platform_device *nvram_dev;
-+ struct bcm53xx_sprom_fill fill;
++ struct bcm47xx_sprom_fill fill;
+
+ /* Alloc */
+ sprom = devm_kzalloc(dev, sizeof(*sprom), GFP_KERNEL);
+ if (!nvram_dev)
+ return -ENOMEM;
+
-+ fill.prefix = NULL;
++ fill.prefix = of_get_property(np, "prefix", NULL);
++
+ fill.fallback = false;
-+ fill.getenv = bcm53xx_sprom_getenv;
++ fill.getenv = bcm47xx_sprom_getenv;
+ fill.priv = nvram_dev;
+
-+ bcm53xx_sprom_fill(sprom, &fill);
++ bcm47xx_sprom_fill(sprom, &fill);
+
+ platform_set_drvdata(pdev, sprom);
+
+ return 0;
+}
+
-+static const struct of_device_id bcm53xx_sprom_of_match_table[] = {
-+ { .compatible = "brcm,bcm53xx-sprom", },
++static const struct of_device_id bcm47xx_sprom_of_match_table[] = {
++ { .compatible = "brcm,bcm47xx-sprom", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, mvebu_pcie_of_match_table);
+
-+static struct platform_driver bcm53xx_sprom_driver = {
++static struct platform_driver bcm47xx_sprom_driver = {
+ .driver = {
+ .owner = THIS_MODULE,
-+ .name = "bcm53xx-sprom",
-+ .of_match_table = bcm53xx_sprom_of_match_table,
++ .name = "bcm47xx-sprom",
++ .of_match_table = bcm47xx_sprom_of_match_table,
+ /* driver unloading/unbinding currently not supported */
+ .suppress_bind_attrs = true,
+ },
-+ .probe = bcm53xx_sprom_probe,
++ .probe = bcm47xx_sprom_probe,
+};
-+module_platform_driver(bcm53xx_sprom_driver);
++module_platform_driver(bcm47xx_sprom_driver);
+
+MODULE_AUTHOR("Hauke Mehrtens <hauke@hauke-m.de>");
-+MODULE_LICENSE("GPLv2");
++MODULE_LICENSE("GPL v2");