f22a8646c07a2d5719ee73975c090c38f978abc1
[openwrt/openwrt.git] / target / linux / bcm53xx / patches-3.18 / 111-bcm47xx-nvram-add-new-nvram-driver-with-dt-support.patch
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
5 support
6
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
15 the wifi devices.
16
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.
20
21 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
22 ---
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
39
40 --- /dev/null
41 +++ b/Documentation/devicetree/bindings/misc/bcm47xx-nvram.txt
42 @@ -0,0 +1,19 @@
43 +Broadcom bcm47xx/bcm53xx nvram access driver
44 +
45 +This driver provides access to the nvram for other drivers.
46 +
47 +Required properties:
48 +
49 +- compatible : brcm,bcm47xx-nvram
50 +
51 +- reg : iomem address range
52 +
53 +On NorthStar ARM SoCs the NAND flash is available at 0x1c000000 and the
54 +NOR flash is at 0x1e000000
55 +
56 +Example:
57 +
58 +nvram0: nvram@0 {
59 + compatible = "brcm,bcm47xx-nvram";
60 + reg = <0x1c000000 0x01000000>;
61 +};
62 --- a/arch/mips/bcm47xx/board.c
63 +++ b/arch/mips/bcm47xx/board.c
64 @@ -218,36 +218,36 @@ static __init const struct bcm47xx_board
65 const struct bcm47xx_board_type_list2 *e2;
66 const struct bcm47xx_board_type_list3 *e3;
67
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))
72 return &e1->board;
73 }
74 }
75
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))
80 return &e1->board;
81 }
82 }
83
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))
88 return &e1->board;
89 }
90 }
91
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))
96 return &e1->board;
97 }
98 }
99
100 - if (bcm47xx_nvram_getenv("hardware_version", buf1, sizeof(buf1)) >= 0 &&
101 - bcm47xx_nvram_getenv("boardtype", buf2, sizeof(buf2)) >= 0) {
102 + if (bcm47xx_nvram_getenv(NULL, "hardware_version", buf1, sizeof(buf1)) >= 0 &&
103 + bcm47xx_nvram_getenv(NULL, "boardtype", buf2, sizeof(buf2)) >= 0) {
104 for (e2 = bcm47xx_board_list_boot_hw; e2->value1; e2++) {
105 if (!strstarts(buf1, e2->value1) &&
106 !strcmp(buf2, e2->value2))
107 @@ -255,22 +255,22 @@ static __init const struct bcm47xx_board
108 }
109 }
110
111 - if (bcm47xx_nvram_getenv("productid", buf1, sizeof(buf1)) >= 0) {
112 + if (bcm47xx_nvram_getenv(NULL, "productid", buf1, sizeof(buf1)) >= 0) {
113 for (e1 = bcm47xx_board_list_productid; e1->value1; e1++) {
114 if (!strcmp(buf1, e1->value1))
115 return &e1->board;
116 }
117 }
118
119 - if (bcm47xx_nvram_getenv("ModelId", buf1, sizeof(buf1)) >= 0) {
120 + if (bcm47xx_nvram_getenv(NULL, "ModelId", buf1, sizeof(buf1)) >= 0) {
121 for (e1 = bcm47xx_board_list_ModelId; e1->value1; e1++) {
122 if (!strcmp(buf1, e1->value1))
123 return &e1->board;
124 }
125 }
126
127 - if (bcm47xx_nvram_getenv("melco_id", buf1, sizeof(buf1)) >= 0 ||
128 - bcm47xx_nvram_getenv("buf1falo_id", buf1, sizeof(buf1)) >= 0) {
129 + if (bcm47xx_nvram_getenv(NULL, "melco_id", buf1, sizeof(buf1)) >= 0 ||
130 + bcm47xx_nvram_getenv(NULL, "buf1falo_id", buf1, sizeof(buf1)) >= 0) {
131 /* buffalo hardware, check id for specific hardware matches */
132 for (e1 = bcm47xx_board_list_melco_id; e1->value1; e1++) {
133 if (!strcmp(buf1, e1->value1))
134 @@ -278,8 +278,8 @@ static __init const struct bcm47xx_board
135 }
136 }
137
138 - if (bcm47xx_nvram_getenv("boot_hw_model", buf1, sizeof(buf1)) >= 0 &&
139 - bcm47xx_nvram_getenv("boot_hw_ver", buf2, sizeof(buf2)) >= 0) {
140 + if (bcm47xx_nvram_getenv(NULL, "boot_hw_model", buf1, sizeof(buf1)) >= 0 &&
141 + bcm47xx_nvram_getenv(NULL, "boot_hw_ver", buf2, sizeof(buf2)) >= 0) {
142 for (e2 = bcm47xx_board_list_boot_hw; e2->value1; e2++) {
143 if (!strcmp(buf1, e2->value1) &&
144 !strcmp(buf2, e2->value2))
145 @@ -287,16 +287,16 @@ static __init const struct bcm47xx_board
146 }
147 }
148
149 - if (bcm47xx_nvram_getenv("board_id", buf1, sizeof(buf1)) >= 0) {
150 + if (bcm47xx_nvram_getenv(NULL, "board_id", buf1, sizeof(buf1)) >= 0) {
151 for (e1 = bcm47xx_board_list_board_id; e1->value1; e1++) {
152 if (!strcmp(buf1, e1->value1))
153 return &e1->board;
154 }
155 }
156
157 - if (bcm47xx_nvram_getenv("boardtype", buf1, sizeof(buf1)) >= 0 &&
158 - bcm47xx_nvram_getenv("boardnum", buf2, sizeof(buf2)) >= 0 &&
159 - bcm47xx_nvram_getenv("boardrev", buf3, sizeof(buf3)) >= 0) {
160 + if (bcm47xx_nvram_getenv(NULL, "boardtype", buf1, sizeof(buf1)) >= 0 &&
161 + bcm47xx_nvram_getenv(NULL, "boardnum", buf2, sizeof(buf2)) >= 0 &&
162 + bcm47xx_nvram_getenv(NULL, "boardrev", buf3, sizeof(buf3)) >= 0) {
163 for (e3 = bcm47xx_board_list_board; e3->value1; e3++) {
164 if (!strcmp(buf1, e3->value1) &&
165 !strcmp(buf2, e3->value2) &&
166 @@ -305,9 +305,9 @@ static __init const struct bcm47xx_board
167 }
168 }
169
170 - if (bcm47xx_nvram_getenv("boardtype", buf1, sizeof(buf1)) >= 0 &&
171 - bcm47xx_nvram_getenv("boardrev", buf2, sizeof(buf2)) >= 0 &&
172 - bcm47xx_nvram_getenv("boardnum", buf3, sizeof(buf3)) == -ENOENT) {
173 + if (bcm47xx_nvram_getenv(NULL, "boardtype", buf1, sizeof(buf1)) >= 0 &&
174 + bcm47xx_nvram_getenv(NULL, "boardrev", buf2, sizeof(buf2)) >= 0 &&
175 + bcm47xx_nvram_getenv(NULL, "boardnum", buf3, sizeof(buf3)) == -ENOENT) {
176 for (e2 = bcm47xx_board_list_board_type_rev; e2->value1; e2++) {
177 if (!strcmp(buf1, e2->value1) &&
178 !strcmp(buf2, e2->value2))
179 @@ -327,7 +327,7 @@ void __init bcm47xx_board_detect(void)
180 return;
181
182 /* check if the nvram is available */
183 - err = bcm47xx_nvram_getenv("boardtype", buf, sizeof(buf));
184 + err = bcm47xx_nvram_getenv(NULL, "boardtype", buf, sizeof(buf));
185
186 /* init of nvram failed, probably too early now */
187 if (err == -ENXIO) {
188 --- a/arch/mips/bcm47xx/nvram.c
189 +++ b/arch/mips/bcm47xx/nvram.c
190 @@ -158,7 +158,8 @@ static int nvram_init(void)
191 return -ENXIO;
192 }
193
194 -int bcm47xx_nvram_getenv(char *name, char *val, size_t val_len)
195 +int bcm47xx_nvram_getenv(const struct device *dev, const char *name, char *val,
196 + size_t val_len)
197 {
198 char *var, *value, *end, *eq;
199 int err;
200 @@ -190,7 +191,7 @@ int bcm47xx_nvram_getenv(char *name, cha
201 }
202 EXPORT_SYMBOL(bcm47xx_nvram_getenv);
203
204 -int bcm47xx_nvram_gpio_pin(const char *name)
205 +int bcm47xx_nvram_gpio_pin(const struct device *dev, const char *name)
206 {
207 int i, err;
208 char nvram_var[10];
209 @@ -200,7 +201,7 @@ int bcm47xx_nvram_gpio_pin(const char *n
210 err = snprintf(nvram_var, sizeof(nvram_var), "gpio%i", i);
211 if (err <= 0)
212 continue;
213 - err = bcm47xx_nvram_getenv(nvram_var, buf, sizeof(buf));
214 + err = bcm47xx_nvram_getenv(dev, nvram_var, buf, sizeof(buf));
215 if (err <= 0)
216 continue;
217 if (!strcmp(name, buf))
218 --- a/arch/mips/bcm47xx/setup.c
219 +++ b/arch/mips/bcm47xx/setup.c
220 @@ -132,7 +132,7 @@ static int bcm47xx_get_invariants(struct
221 memset(&iv->sprom, 0, sizeof(struct ssb_sprom));
222 bcm47xx_fill_sprom(&iv->sprom, NULL, false);
223
224 - if (bcm47xx_nvram_getenv("cardbus", buf, sizeof(buf)) >= 0)
225 + if (bcm47xx_nvram_getenv(NULL, "cardbus", buf, sizeof(buf)) >= 0)
226 iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10);
227
228 return 0;
229 @@ -155,7 +155,7 @@ static void __init bcm47xx_register_ssb(
230 panic("Failed to initialize SSB bus (err %d)", err);
231
232 mcore = &bcm47xx_bus.ssb.mipscore;
233 - if (bcm47xx_nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) {
234 + if (bcm47xx_nvram_getenv(NULL, "kernel_args", buf, sizeof(buf)) >= 0) {
235 if (strstr(buf, "console=ttyS1")) {
236 struct ssb_serial_port port;
237
238 --- a/arch/mips/bcm47xx/sprom.c
239 +++ b/arch/mips/bcm47xx/sprom.c
240 @@ -52,10 +52,10 @@ static int get_nvram_var(const char *pre
241
242 create_key(prefix, postfix, name, key, sizeof(key));
243
244 - err = bcm47xx_nvram_getenv(key, buf, len);
245 + err = bcm47xx_nvram_getenv(NULL, key, buf, len);
246 if (fallback && err == -ENOENT && prefix) {
247 create_key(NULL, postfix, name, key, sizeof(key));
248 - err = bcm47xx_nvram_getenv(key, buf, len);
249 + err = bcm47xx_nvram_getenv(NULL, key, buf, len);
250 }
251 return err;
252 }
253 --- a/arch/mips/bcm47xx/time.c
254 +++ b/arch/mips/bcm47xx/time.c
255 @@ -61,7 +61,7 @@ void __init plat_time_init(void)
256 }
257
258 if (chip_id == 0x5354) {
259 - len = bcm47xx_nvram_getenv("clkfreq", buf, sizeof(buf));
260 + len = bcm47xx_nvram_getenv(NULL, "clkfreq", buf, sizeof(buf));
261 if (len >= 0 && !strncmp(buf, "200", 4))
262 hz = 100000000;
263 }
264 --- a/drivers/misc/Kconfig
265 +++ b/drivers/misc/Kconfig
266 @@ -515,6 +515,11 @@ config VEXPRESS_SYSCFG
267 bus. System Configuration interface is one of the possible means
268 of generating transactions on this bus.
269
270 +config BCM47XX_NVRAM
271 + tristate "BCM47XX nvram driver"
272 + help
273 + This adds support for the brcm47xx nvram driver.
274 +
275 source "drivers/misc/c2port/Kconfig"
276 source "drivers/misc/eeprom/Kconfig"
277 source "drivers/misc/cb710/Kconfig"
278 --- a/drivers/misc/Makefile
279 +++ b/drivers/misc/Makefile
280 @@ -56,3 +56,4 @@ obj-$(CONFIG_GENWQE) += genwqe/
281 obj-$(CONFIG_ECHO) += echo/
282 obj-$(CONFIG_VEXPRESS_SYSCFG) += vexpress-syscfg.o
283 obj-$(CONFIG_CXL_BASE) += cxl/
284 +obj-$(CONFIG_BCM47XX_NVRAM) += bcm47xx-nvram.o
285 --- /dev/null
286 +++ b/drivers/misc/bcm47xx-nvram.c
287 @@ -0,0 +1,215 @@
288 +/*
289 + * BCM947xx nvram variable access
290 + *
291 + * Copyright (C) 2005 Broadcom Corporation
292 + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
293 + * Copyright (C) 2010-2014 Hauke Mehrtens <hauke@hauke-m.de>
294 + *
295 + * This program is free software; you can redistribute it and/or modify it
296 + * under the terms of the GNU General Public License as published by the
297 + * Free Software Foundation; either version 2 of the License, or (at your
298 + * option) any later version.
299 + */
300 +
301 +#include <linux/types.h>
302 +#include <linux/module.h>
303 +#include <linux/kernel.h>
304 +#include <linux/string.h>
305 +#include <linux/of_address.h>
306 +#include <linux/device.h>
307 +#include <linux/platform_device.h>
308 +#include <linux/io.h>
309 +#include <linux/bcm47xx_nvram.h>
310 +
311 +struct bcm47xx_nvram {
312 + size_t nvram_len;
313 + char *nvram_buf;
314 +};
315 +
316 +static const u32 nvram_sizes[] = {0x8000, 0xF000, 0x10000};
317 +
318 +static u32 find_nvram_size(void __iomem *end)
319 +{
320 + struct nvram_header __iomem *header;
321 + int i;
322 +
323 + for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) {
324 + header = (struct nvram_header __iomem *)(end - nvram_sizes[i]);
325 + if (__raw_readl(&header->magic) == NVRAM_HEADER)
326 + return nvram_sizes[i];
327 + }
328 +
329 + return 0;
330 +}
331 +
332 +/* Probe for NVRAM header */
333 +static int nvram_find_and_copy(struct device *dev, void __iomem *base,
334 + size_t len, char **nvram_buf,
335 + size_t *nvram_len)
336 +{
337 + struct nvram_header __iomem *header;
338 + int i;
339 + u32 off;
340 + u32 *dst;
341 + __le32 __iomem *src;
342 + u32 size;
343 +
344 + /* TODO: when nvram is on nand flash check for bad blocks first. */
345 + off = FLASH_MIN;
346 + while (off <= len) {
347 + /* Windowed flash access */
348 + size = find_nvram_size(base + off);
349 + if (size) {
350 + header = (struct nvram_header __iomem *)
351 + (base + off - size);
352 + goto found;
353 + }
354 + off += 0x10000;
355 + }
356 +
357 + /* Try embedded NVRAM at 4 KB and 1 KB as last resorts */
358 + header = (struct nvram_header __iomem *)(base + 4096);
359 + if (__raw_readl(&header->magic) == NVRAM_HEADER) {
360 + size = NVRAM_SPACE;
361 + goto found;
362 + }
363 +
364 + header = (struct nvram_header __iomem *)(base + 1024);
365 + if (__raw_readl(&header->magic) == NVRAM_HEADER) {
366 + size = NVRAM_SPACE;
367 + goto found;
368 + }
369 +
370 + *nvram_buf = NULL;
371 + *nvram_len = 0;
372 + pr_err("no nvram found\n");
373 + return -ENXIO;
374 +
375 +found:
376 + if (readl(&header->len) > size)
377 + pr_err("The nvram size accoridng to the header seems to be bigger than the partition on flash\n");
378 + *nvram_len = min_t(u32, readl(&header->len), size);
379 +
380 + *nvram_buf = devm_kzalloc(dev, *nvram_len, GFP_KERNEL);
381 + if (!*nvram_buf)
382 + return -ENOMEM;
383 +
384 + src = (__le32 __iomem *) header;
385 + dst = (u32 *) *nvram_buf;
386 + for (i = 0; i < sizeof(struct nvram_header); i += 4)
387 + *dst++ = __raw_readl(src++);
388 + for (; i < *nvram_len; i += 4)
389 + *dst++ = readl(src++);
390 +
391 + return 0;
392 +}
393 +
394 +int bcm47xx_nvram_getenv(const struct device *dev, const char *name, char *val,
395 + size_t val_len)
396 +{
397 + char *var, *value, *end, *eq;
398 + struct bcm47xx_nvram *nvram;
399 +
400 + if (!dev)
401 + return -ENODEV;
402 +
403 + nvram = dev_get_drvdata(dev);
404 +
405 + if (!name || !nvram || !nvram->nvram_len)
406 + return -EINVAL;
407 +
408 + /* Look for name=value and return value */
409 + var = nvram->nvram_buf + sizeof(struct nvram_header);
410 + end = nvram->nvram_buf + nvram->nvram_len - 2;
411 + end[0] = end[1] = '\0';
412 + for (; *var; var = value + strlen(value) + 1) {
413 + eq = strchr(var, '=');
414 + if (!eq)
415 + break;
416 + value = eq + 1;
417 + if ((eq - var) == strlen(name) &&
418 + strncmp(var, name, (eq - var)) == 0) {
419 + return snprintf(val, val_len, "%s", value);
420 + }
421 + }
422 + return -ENOENT;
423 +}
424 +EXPORT_SYMBOL(bcm47xx_nvram_getenv);
425 +
426 +int bcm47xx_nvram_gpio_pin(const struct device *dev, const char *name)
427 +{
428 + int i, err;
429 + char nvram_var[10];
430 + char buf[30];
431 +
432 + if (!dev)
433 + return -ENODEV;
434 +
435 + for (i = 0; i < 32; i++) {
436 + err = snprintf(nvram_var, sizeof(nvram_var), "gpio%i", i);
437 + if (err <= 0)
438 + continue;
439 + err = bcm47xx_nvram_getenv(dev, nvram_var, buf, sizeof(buf));
440 + if (err <= 0)
441 + continue;
442 + if (!strcmp(name, buf))
443 + return i;
444 + }
445 + return -ENOENT;
446 +}
447 +EXPORT_SYMBOL(bcm47xx_nvram_gpio_pin);
448 +
449 +static int bcm47xx_nvram_probe(struct platform_device *pdev)
450 +{
451 + struct device *dev = &pdev->dev;
452 + struct device_node *np = dev->of_node;
453 + struct bcm47xx_nvram *nvram;
454 + int err;
455 + struct resource flash_mem;
456 + void __iomem *mmio;
457 +
458 + /* Alloc */
459 + nvram = devm_kzalloc(dev, sizeof(*nvram), GFP_KERNEL);
460 + if (!nvram)
461 + return -ENOMEM;
462 +
463 + err = of_address_to_resource(np, 0, &flash_mem);
464 + if (err)
465 + return err;
466 +
467 + mmio = ioremap_nocache(flash_mem.start, resource_size(&flash_mem));
468 + if (!mmio)
469 + return -ENOMEM;
470 +
471 + err = nvram_find_and_copy(dev, mmio, resource_size(&flash_mem),
472 + &nvram->nvram_buf, &nvram->nvram_len);
473 + if (err)
474 + goto err_unmap_mmio;
475 +
476 + platform_set_drvdata(pdev, nvram);
477 +
478 +err_unmap_mmio:
479 + iounmap(mmio);
480 + return err;
481 +}
482 +
483 +static const struct of_device_id bcm47xx_nvram_of_match_table[] = {
484 + { .compatible = "brcm,bcm47xx-nvram", },
485 + {},
486 +};
487 +MODULE_DEVICE_TABLE(of, mvebu_pcie_of_match_table);
488 +
489 +static struct platform_driver bcm47xx_nvram_driver = {
490 + .driver = {
491 + .owner = THIS_MODULE,
492 + .name = "bcm47xx-nvram",
493 + .of_match_table = bcm47xx_nvram_of_match_table,
494 + /* driver unloading/unbinding currently not supported */
495 + .suppress_bind_attrs = true,
496 + },
497 + .probe = bcm47xx_nvram_probe,
498 +};
499 +module_platform_driver(bcm47xx_nvram_driver);
500 +
501 +MODULE_AUTHOR("Hauke Mehrtens <hauke@hauke-m.de>");
502 +MODULE_LICENSE("GPLv2");
503 --- a/drivers/net/ethernet/broadcom/b44.c
504 +++ b/drivers/net/ethernet/broadcom/b44.c
505 @@ -411,7 +411,7 @@ static void b44_wap54g10_workaround(stru
506 * see https://dev.openwrt.org/ticket/146
507 * check and reset bit "isolate"
508 */
509 - if (bcm47xx_nvram_getenv("boardnum", buf, sizeof(buf)) < 0)
510 + if (bcm47xx_nvram_getenv(NULL, "boardnum", buf, sizeof(buf)) < 0)
511 return;
512 if (simple_strtoul(buf, NULL, 0) == 2) {
513 err = __b44_readphy(bp, 0, MII_BMCR, &val);
514 --- a/drivers/net/ethernet/broadcom/bgmac.c
515 +++ b/drivers/net/ethernet/broadcom/bgmac.c
516 @@ -974,7 +974,8 @@ static void bgmac_chip_reset(struct bgma
517 BGMAC_CHIPCTL_1_IF_TYPE_MII;
518 char buf[4];
519
520 - if (bcm47xx_nvram_getenv("et_swtype", buf, sizeof(buf)) > 0) {
521 + if (bcm47xx_nvram_getenv(NULL, "et_swtype", buf,
522 + sizeof(buf)) > 0) {
523 if (kstrtou8(buf, 0, &et_swtype))
524 bgmac_err(bgmac, "Failed to parse et_swtype (%s)\n",
525 buf);
526 @@ -1534,7 +1535,7 @@ static int bgmac_probe(struct bcma_devic
527 }
528
529 bgmac->int_mask = BGMAC_IS_ERRMASK | BGMAC_IS_RX | BGMAC_IS_TX_MASK;
530 - if (bcm47xx_nvram_getenv("et0_no_txint", NULL, 0) == 0)
531 + if (bcm47xx_nvram_getenv(NULL, "et0_no_txint", NULL, 0) == 0)
532 bgmac->int_mask &= ~BGMAC_IS_TX_MASK;
533
534 /* TODO: reset the external phy. Specs are needed */
535 --- a/drivers/ssb/driver_chipcommon_pmu.c
536 +++ b/drivers/ssb/driver_chipcommon_pmu.c
537 @@ -319,7 +319,8 @@ static void ssb_pmu_pll_init(struct ssb_
538
539 if (bus->bustype == SSB_BUSTYPE_SSB) {
540 char buf[20];
541 - if (bcm47xx_nvram_getenv("xtalfreq", buf, sizeof(buf)) >= 0)
542 + if (bcm47xx_nvram_getenv(NULL, "xtalfreq", buf,
543 + sizeof(buf)) >= 0)
544 crystalfreq = simple_strtoul(buf, NULL, 0);
545 }
546
547 --- a/include/linux/bcm47xx_nvram.h
548 +++ b/include/linux/bcm47xx_nvram.h
549 @@ -15,9 +15,11 @@
550 #include <linux/types.h>
551 #include <linux/kernel.h>
552
553 +struct device;
554 +
555 struct nvram_header {
556 u32 magic;
557 - u32 len;
558 + __le32 len;
559 u32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
560 u32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */
561 u32 config_ncdl; /* ncdl values for memc */
562 @@ -33,18 +35,21 @@ struct nvram_header {
563 #define NVRAM_MAX_VALUE_LEN 255
564 #define NVRAM_MAX_PARAM_LEN 64
565
566 -#ifdef CONFIG_BCM47XX
567 -int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len);
568 +#if defined(CONFIG_BCM47XX) || defined(CONFIG_BCM47XX_NVRAM)
569 +int bcm47xx_nvram_getenv(const struct device *dev, const char *name, char *val,
570 + size_t val_len);
571
572 -int bcm47xx_nvram_gpio_pin(const char *name);
573 +int bcm47xx_nvram_gpio_pin(const struct device *dev, const char *name);
574 #else
575 -static inline int bcm47xx_nvram_getenv(const char *name, char *val,
576 +static inline int bcm47xx_nvram_getenv(const struct device *dev,
577 + const char *name, char *val,
578 size_t val_len)
579 {
580 return -ENXIO;
581 }
582
583 -static inline int bcm47xx_nvram_gpio_pin(const char *name)
584 +static inline int bcm47xx_nvram_gpio_pin(const struct device *dev,
585 + const char *name)
586 {
587 return -ENXIO;
588 }