1 From 71a6bff8656a1713615ffdd9139a83d65ba46c6d Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sat, 3 May 2014 22:54:59 +0200
4 Subject: [PATCH 02/17] bcm47xx-nvram: add new broadcom nvram driver with dt
7 This adds a new driver which searches at a given memory range for a
8 nvram like it is used on the bcm47xx and bcm53xx SoCs with ARM and MIPS
9 CPUs. This driver provides acces to this nvram to other device in the
10 device tree. You have to specify the memory ranges where the content of
11 the flash chip is memory mapped and this driver will search there for
12 some nvram and parse it. Other drivers can use this driver to access the
13 device nvram. The nvram is used to store board configurations like the
14 mac addresses, the switch configuration and the calibration data for
17 This was copied from arch/mips/bcm47xx/nvram.c and modified to interact
18 with device tree. My plan is to make the MIPS bcm47xx also use this new
19 driver some time later.
21 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
23 .../devicetree/bindings/misc/bcm47xx-nvram.txt | 19 ++
24 arch/mips/bcm47xx/board.c | 40 ++--
25 arch/mips/bcm47xx/nvram.c | 7 +-
26 arch/mips/bcm47xx/setup.c | 4 +-
27 arch/mips/bcm47xx/sprom.c | 4 +-
28 arch/mips/bcm47xx/time.c | 2 +-
29 drivers/misc/Kconfig | 5 +
30 drivers/misc/Makefile | 1 +
31 drivers/misc/bcm47xx-nvram.c | 215 +++++++++++++++++++++
32 drivers/net/ethernet/broadcom/b44.c | 2 +-
33 drivers/net/ethernet/broadcom/bgmac.c | 5 +-
34 drivers/ssb/driver_chipcommon_pmu.c | 3 +-
35 include/linux/bcm47xx_nvram.h | 17 +-
36 13 files changed, 286 insertions(+), 38 deletions(-)
37 create mode 100644 Documentation/devicetree/bindings/misc/bcm47xx-nvram.txt
38 create mode 100644 drivers/misc/bcm47xx-nvram.c
41 +++ b/Documentation/devicetree/bindings/misc/bcm47xx-nvram.txt
43 +Broadcom bcm47xx/bcm53xx nvram access driver
45 +This driver provides access to the nvram for other drivers.
49 +- compatible : brcm,bcm47xx-nvram
51 +- reg : iomem address range
53 +On NorthStar ARM SoCs the NAND flash is available at 0x1c000000 and the
54 +NOR flash is at 0x1e000000
59 + compatible = "brcm,bcm47xx-nvram";
60 + reg = <0x1c000000 0x01000000>;
62 --- a/arch/mips/bcm47xx/board.c
63 +++ b/arch/mips/bcm47xx/board.c
64 @@ -196,50 +196,50 @@ static __init const struct bcm47xx_board
65 const struct bcm47xx_board_type_list2 *e2;
66 const struct bcm47xx_board_type_list3 *e3;
68 - if (bcm47xx_nvram_getenv("model_name", buf1, sizeof(buf1)) >= 0) {
69 + if (bcm47xx_nvram_getenv(NULL, "model_name", buf1, sizeof(buf1)) >= 0) {
70 for (e1 = bcm47xx_board_list_model_name; e1->value1; e1++) {
71 if (!strcmp(buf1, e1->value1))
76 - if (bcm47xx_nvram_getenv("model_no", buf1, sizeof(buf1)) >= 0) {
77 + if (bcm47xx_nvram_getenv(NULL, "model_no", buf1, sizeof(buf1)) >= 0) {
78 for (e1 = bcm47xx_board_list_model_no; e1->value1; e1++) {
79 if (strstarts(buf1, e1->value1))
84 - if (bcm47xx_nvram_getenv("machine_name", buf1, sizeof(buf1)) >= 0) {
85 + if (bcm47xx_nvram_getenv(NULL, "machine_name", buf1, sizeof(buf1)) >= 0) {
86 for (e1 = bcm47xx_board_list_machine_name; e1->value1; e1++) {
87 if (strstarts(buf1, e1->value1))
92 - if (bcm47xx_nvram_getenv("hardware_version", buf1, sizeof(buf1)) >= 0) {
93 + if (bcm47xx_nvram_getenv(NULL, "hardware_version", buf1, sizeof(buf1)) >= 0) {
94 for (e1 = bcm47xx_board_list_hardware_version; e1->value1; e1++) {
95 if (strstarts(buf1, e1->value1))
100 - if (bcm47xx_nvram_getenv("productid", buf1, sizeof(buf1)) >= 0) {
101 + if (bcm47xx_nvram_getenv(NULL, "productid", buf1, sizeof(buf1)) >= 0) {
102 for (e1 = bcm47xx_board_list_productid; e1->value1; e1++) {
103 if (!strcmp(buf1, e1->value1))
108 - if (bcm47xx_nvram_getenv("ModelId", buf1, sizeof(buf1)) >= 0) {
109 + if (bcm47xx_nvram_getenv(NULL, "ModelId", buf1, sizeof(buf1)) >= 0) {
110 for (e1 = bcm47xx_board_list_ModelId; e1->value1; e1++) {
111 if (!strcmp(buf1, e1->value1))
116 - if (bcm47xx_nvram_getenv("melco_id", buf1, sizeof(buf1)) >= 0 ||
117 - bcm47xx_nvram_getenv("buf1falo_id", buf1, sizeof(buf1)) >= 0) {
118 + if (bcm47xx_nvram_getenv(NULL, "melco_id", buf1, sizeof(buf1)) >= 0 ||
119 + bcm47xx_nvram_getenv(NULL, "buf1falo_id", buf1, sizeof(buf1)) >= 0) {
120 /* buffalo hardware, check id for specific hardware matches */
121 for (e1 = bcm47xx_board_list_melco_id; e1->value1; e1++) {
122 if (!strcmp(buf1, e1->value1))
123 @@ -247,8 +247,8 @@ static __init const struct bcm47xx_board
127 - if (bcm47xx_nvram_getenv("boot_hw_model", buf1, sizeof(buf1)) >= 0 &&
128 - bcm47xx_nvram_getenv("boot_hw_ver", buf2, sizeof(buf2)) >= 0) {
129 + if (bcm47xx_nvram_getenv(NULL, "boot_hw_model", buf1, sizeof(buf1)) >= 0 &&
130 + bcm47xx_nvram_getenv(NULL, "boot_hw_ver", buf2, sizeof(buf2)) >= 0) {
131 for (e2 = bcm47xx_board_list_boot_hw; e2->value1; e2++) {
132 if (!strcmp(buf1, e2->value1) &&
133 !strcmp(buf2, e2->value2))
134 @@ -256,16 +256,16 @@ static __init const struct bcm47xx_board
138 - if (bcm47xx_nvram_getenv("board_id", buf1, sizeof(buf1)) >= 0) {
139 + if (bcm47xx_nvram_getenv(NULL, "board_id", buf1, sizeof(buf1)) >= 0) {
140 for (e1 = bcm47xx_board_list_board_id; e1->value1; e1++) {
141 if (!strcmp(buf1, e1->value1))
146 - if (bcm47xx_nvram_getenv("boardtype", buf1, sizeof(buf1)) >= 0 &&
147 - bcm47xx_nvram_getenv("boardnum", buf2, sizeof(buf2)) >= 0 &&
148 - bcm47xx_nvram_getenv("boardrev", buf3, sizeof(buf3)) >= 0) {
149 + if (bcm47xx_nvram_getenv(NULL, "boardtype", buf1, sizeof(buf1)) >= 0 &&
150 + bcm47xx_nvram_getenv(NULL, "boardnum", buf2, sizeof(buf2)) >= 0 &&
151 + bcm47xx_nvram_getenv(NULL, "boardrev", buf3, sizeof(buf3)) >= 0) {
152 for (e3 = bcm47xx_board_list_board; e3->value1; e3++) {
153 if (!strcmp(buf1, e3->value1) &&
154 !strcmp(buf2, e3->value2) &&
155 @@ -286,7 +286,7 @@ void __init bcm47xx_board_detect(void)
158 /* check if the nvram is available */
159 - err = bcm47xx_nvram_getenv("boardtype", buf, sizeof(buf));
160 + err = bcm47xx_nvram_getenv(NULL, "boardtype", buf, sizeof(buf));
162 /* init of nvram failed, probably too early now */
164 --- a/arch/mips/bcm47xx/nvram.c
165 +++ b/arch/mips/bcm47xx/nvram.c
166 @@ -158,7 +158,8 @@ static int nvram_init(void)
170 -int bcm47xx_nvram_getenv(char *name, char *val, size_t val_len)
171 +int bcm47xx_nvram_getenv(const struct device *dev, const char *name, char *val,
174 char *var, *value, *end, *eq;
176 @@ -190,7 +191,7 @@ int bcm47xx_nvram_getenv(char *name, cha
178 EXPORT_SYMBOL(bcm47xx_nvram_getenv);
180 -int bcm47xx_nvram_gpio_pin(const char *name)
181 +int bcm47xx_nvram_gpio_pin(const struct device *dev, const char *name)
185 @@ -200,7 +201,7 @@ int bcm47xx_nvram_gpio_pin(const char *n
186 err = snprintf(nvram_var, sizeof(nvram_var), "gpio%i", i);
189 - err = bcm47xx_nvram_getenv(nvram_var, buf, sizeof(buf));
190 + err = bcm47xx_nvram_getenv(dev, nvram_var, buf, sizeof(buf));
193 if (!strcmp(name, buf))
194 --- a/arch/mips/bcm47xx/setup.c
195 +++ b/arch/mips/bcm47xx/setup.c
196 @@ -123,7 +123,7 @@ static int bcm47xx_get_invariants(struct
197 memset(&iv->sprom, 0, sizeof(struct ssb_sprom));
198 bcm47xx_fill_sprom(&iv->sprom, NULL, false);
200 - if (bcm47xx_nvram_getenv("cardbus", buf, sizeof(buf)) >= 0)
201 + if (bcm47xx_nvram_getenv(NULL, "cardbus", buf, sizeof(buf)) >= 0)
202 iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10);
205 @@ -146,7 +146,7 @@ static void __init bcm47xx_register_ssb(
206 panic("Failed to initialize SSB bus (err %d)", err);
208 mcore = &bcm47xx_bus.ssb.mipscore;
209 - if (bcm47xx_nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) {
210 + if (bcm47xx_nvram_getenv(NULL, "kernel_args", buf, sizeof(buf)) >= 0) {
211 if (strstr(buf, "console=ttyS1")) {
212 struct ssb_serial_port port;
214 --- a/arch/mips/bcm47xx/sprom.c
215 +++ b/arch/mips/bcm47xx/sprom.c
216 @@ -50,10 +50,10 @@ static int get_nvram_var(const char *pre
218 create_key(prefix, postfix, name, key, sizeof(key));
220 - err = bcm47xx_nvram_getenv(key, buf, len);
221 + err = bcm47xx_nvram_getenv(NULL, key, buf, len);
222 if (fallback && err == -ENOENT && prefix) {
223 create_key(NULL, postfix, name, key, sizeof(key));
224 - err = bcm47xx_nvram_getenv(key, buf, len);
225 + err = bcm47xx_nvram_getenv(NULL, key, buf, len);
229 --- a/arch/mips/bcm47xx/time.c
230 +++ b/arch/mips/bcm47xx/time.c
231 @@ -61,7 +61,7 @@ void __init plat_time_init(void)
234 if (chip_id == 0x5354) {
235 - len = bcm47xx_nvram_getenv("clkfreq", buf, sizeof(buf));
236 + len = bcm47xx_nvram_getenv(NULL, "clkfreq", buf, sizeof(buf));
237 if (len >= 0 && !strncmp(buf, "200", 4))
240 --- a/drivers/misc/Kconfig
241 +++ b/drivers/misc/Kconfig
242 @@ -515,6 +515,11 @@ config SRAM
243 the genalloc API. It is supposed to be used for small on-chip SRAM
244 areas found on many SoCs.
246 +config BCM47XX_NVRAM
247 + tristate "BCM47XX nvram driver"
249 + This adds support for the brcm47xx nvram driver.
251 source "drivers/misc/c2port/Kconfig"
252 source "drivers/misc/eeprom/Kconfig"
253 source "drivers/misc/cb710/Kconfig"
254 --- a/drivers/misc/Makefile
255 +++ b/drivers/misc/Makefile
256 @@ -54,3 +54,4 @@ obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lat
257 obj-$(CONFIG_SRAM) += sram.o
259 obj-$(CONFIG_GENWQE) += genwqe/
260 +obj-$(CONFIG_BCM47XX_NVRAM) += bcm47xx-nvram.o
261 --- a/drivers/net/ethernet/broadcom/b44.c
262 +++ b/drivers/net/ethernet/broadcom/b44.c
263 @@ -411,7 +411,7 @@ static void b44_wap54g10_workaround(stru
264 * see https://dev.openwrt.org/ticket/146
265 * check and reset bit "isolate"
267 - if (bcm47xx_nvram_getenv("boardnum", buf, sizeof(buf)) < 0)
268 + if (bcm47xx_nvram_getenv(NULL, "boardnum", buf, sizeof(buf)) < 0)
270 if (simple_strtoul(buf, NULL, 0) == 2) {
271 err = __b44_readphy(bp, 0, MII_BMCR, &val);
272 --- a/drivers/net/ethernet/broadcom/bgmac.c
273 +++ b/drivers/net/ethernet/broadcom/bgmac.c
274 @@ -974,7 +974,8 @@ static void bgmac_chip_reset(struct bgma
275 BGMAC_CHIPCTL_1_IF_TYPE_MII;
278 - if (bcm47xx_nvram_getenv("et_swtype", buf, sizeof(buf)) > 0) {
279 + if (bcm47xx_nvram_getenv(NULL, "et_swtype", buf,
280 + sizeof(buf)) > 0) {
281 if (kstrtou8(buf, 0, &et_swtype))
282 bgmac_err(bgmac, "Failed to parse et_swtype (%s)\n",
284 @@ -1534,7 +1535,7 @@ static int bgmac_probe(struct bcma_devic
287 bgmac->int_mask = BGMAC_IS_ERRMASK | BGMAC_IS_RX | BGMAC_IS_TX_MASK;
288 - if (bcm47xx_nvram_getenv("et0_no_txint", NULL, 0) == 0)
289 + if (bcm47xx_nvram_getenv(NULL, "et0_no_txint", NULL, 0) == 0)
290 bgmac->int_mask &= ~BGMAC_IS_TX_MASK;
292 /* TODO: reset the external phy. Specs are needed */
293 --- a/drivers/ssb/driver_chipcommon_pmu.c
294 +++ b/drivers/ssb/driver_chipcommon_pmu.c
295 @@ -319,7 +319,8 @@ static void ssb_pmu_pll_init(struct ssb_
297 if (bus->bustype == SSB_BUSTYPE_SSB) {
299 - if (bcm47xx_nvram_getenv("xtalfreq", buf, sizeof(buf)) >= 0)
300 + if (bcm47xx_nvram_getenv(NULL, "xtalfreq", buf,
302 crystalfreq = simple_strtoul(buf, NULL, 0);
305 --- a/include/linux/bcm47xx_nvram.h
306 +++ b/include/linux/bcm47xx_nvram.h
308 #include <linux/types.h>
309 #include <linux/kernel.h>
313 struct nvram_header {
317 u32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
318 u32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */
319 u32 config_ncdl; /* ncdl values for memc */
320 @@ -33,18 +35,21 @@ struct nvram_header {
321 #define NVRAM_MAX_VALUE_LEN 255
322 #define NVRAM_MAX_PARAM_LEN 64
324 -#ifdef CONFIG_BCM47XX
325 -int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len);
326 +#if defined(CONFIG_BCM47XX) || defined(CONFIG_BCM47XX_NVRAM)
327 +int bcm47xx_nvram_getenv(const struct device *dev, const char *name, char *val,
330 -int bcm47xx_nvram_gpio_pin(const char *name);
331 +int bcm47xx_nvram_gpio_pin(const struct device *dev, const char *name);
333 -static inline int bcm47xx_nvram_getenv(const char *name, char *val,
334 +static inline int bcm47xx_nvram_getenv(const struct device *dev,
335 + const char *name, char *val,
341 -static inline int bcm47xx_nvram_gpio_pin(const char *name)
342 +static inline int bcm47xx_nvram_gpio_pin(const struct device *dev,