Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

firmware/nvram: bcm47xx: support init from IO memory

Provide NVMEM content to the NVRAM driver from a simple
memory resource. This is necessary to use NVRAM in a memory-
mapped flash device. Patch taken from OpenWrts development
tree.

This patch makes it possible to use memory-mapped NVRAM
on the D-Link DWL-8610AP and the D-Link DIR-890L.

Cc: Hauke Mehrtens <hauke@hauke-m.de>
Cc: linux-mips@vger.kernel.org
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: bcm-kernel-feedback-list@broadcom.com
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
[Added an export for modules potentially using the init symbol]
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20221103082529.359084-1-linus.walleij@linaro.org
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>

authored by

Rafał Miłecki and committed by
Florian Fainelli
a5be5ce0 117bd98d

+27
+18
drivers/firmware/broadcom/bcm47xx_nvram.c
··· 110 110 return 0; 111 111 } 112 112 113 + int bcm47xx_nvram_init_from_iomem(void __iomem *nvram_start, size_t res_size) 114 + { 115 + if (nvram_len) { 116 + pr_warn("nvram already initialized\n"); 117 + return -EEXIST; 118 + } 119 + 120 + if (!bcm47xx_nvram_is_valid(nvram_start)) { 121 + pr_err("No valid NVRAM found\n"); 122 + return -ENOENT; 123 + } 124 + 125 + bcm47xx_nvram_copy(nvram_start, res_size); 126 + 127 + return 0; 128 + } 129 + EXPORT_SYMBOL_GPL(bcm47xx_nvram_init_from_iomem); 130 + 113 131 /* 114 132 * On bcm47xx we need access to the NVRAM very early, so we can't use mtd 115 133 * subsystem to access flash. We can't even use platform device / driver to
+3
drivers/nvmem/brcm_nvram.c
··· 3 3 * Copyright (C) 2021 Rafał Miłecki <rafal@milecki.pl> 4 4 */ 5 5 6 + #include <linux/bcm47xx_nvram.h> 6 7 #include <linux/io.h> 7 8 #include <linux/mod_devicetable.h> 8 9 #include <linux/module.h> ··· 136 135 err = brcm_nvram_parse(priv); 137 136 if (err) 138 137 return err; 138 + 139 + bcm47xx_nvram_init_from_iomem(priv->base, resource_size(res)); 139 140 140 141 config.dev = dev; 141 142 config.cells = priv->cells;
+6
include/linux/bcm47xx_nvram.h
··· 11 11 #include <linux/vmalloc.h> 12 12 13 13 #ifdef CONFIG_BCM47XX_NVRAM 14 + int bcm47xx_nvram_init_from_iomem(void __iomem *nvram_start, size_t res_size); 14 15 int bcm47xx_nvram_init_from_mem(u32 base, u32 lim); 15 16 int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len); 16 17 int bcm47xx_nvram_gpio_pin(const char *name); ··· 21 20 vfree(nvram); 22 21 }; 23 22 #else 23 + static inline int bcm47xx_nvram_init_from_iomem(void __iomem *nvram_start, 24 + size_t res_size) 25 + { 26 + return -ENOTSUPP; 27 + } 24 28 static inline int bcm47xx_nvram_init_from_mem(u32 base, u32 lim) 25 29 { 26 30 return -ENOTSUPP;