1 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
2 Date: Tue, 2 Mar 2021 08:33:13 +0100
3 Subject: [PATCH] firmware: bcm47xx_nvram: support platform device "brcm,nvram"
5 Add support for platform device providing mapping resource. This allows
6 reading NVRAM based on DT mapping binding. It's required for devices
7 that boot depending on NVRAM stored setup and provides early access to
10 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
12 drivers/firmware/broadcom/bcm47xx_nvram.c | 55 +++++++++++++++++++++++
13 1 file changed, 55 insertions(+)
15 --- a/drivers/firmware/broadcom/bcm47xx_nvram.c
16 +++ b/drivers/firmware/broadcom/bcm47xx_nvram.c
18 #include <linux/kernel.h>
19 #include <linux/string.h>
20 #include <linux/mtd/mtd.h>
21 +#include <linux/platform_device.h>
22 #include <linux/bcm47xx_nvram.h>
24 #define NVRAM_MAGIC 0x48534C46 /* 'FLSH' */
25 @@ -162,6 +163,60 @@ static int nvram_init(void)
29 +static int brcm_nvram_probe(struct platform_device *pdev)
31 + struct nvram_header __iomem *header;
32 + struct device *dev = &pdev->dev;
33 + struct resource *res;
37 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
39 + dev_err(dev, "Failed to get resource\n");
43 + mmio = ioremap(res->start, resource_size(res));
47 + header = (struct nvram_header *)mmio;
48 + copy_len = DIV_ROUND_UP(sizeof(*header) + header->len, 4);
49 + if (header->magic != NVRAM_MAGIC) {
50 + dev_err(dev, "No NVRAM found at %pR\n", res);
52 + } else if (copy_len > resource_size(res)) {
53 + dev_err(dev, "NVRAM size exceeds %pR\n", res);
55 + } else if (copy_len >= NVRAM_SPACE) {
56 + dev_err(dev, "NVRAM size exceeds buffer size %d\n", NVRAM_SPACE);
60 + __ioread32_copy(nvram_buf, mmio, copy_len);
61 + nvram_buf[NVRAM_SPACE - 1] = '\0';
68 +static const struct of_device_id brcm_nvram_of_match[] = {
69 + { .compatible = "brcm,nvram "},
73 +static struct platform_driver brcm_nvram_driver = {
75 + .name = "brcm_nvram",
76 + .of_match_table = brcm_nvram_of_match,
78 + .probe = brcm_nvram_probe,
81 +module_platform_driver(brcm_nvram_driver);
83 int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len)
85 char *var, *value, *end, *eq;