13ee2d42293f91dd5a90efb83af8c473d9db2453
[openwrt/staging/thess.git] /
1 From a5be5ce0e25439fae3cd42e3d775979547926812 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Thu, 3 Nov 2022 09:25:29 +0100
4 Subject: [PATCH] firmware/nvram: bcm47xx: support init from IO memory
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Provide NVMEM content to the NVRAM driver from a simple
10 memory resource. This is necessary to use NVRAM in a memory-
11 mapped flash device. Patch taken from OpenWrts development
12 tree.
13
14 This patch makes it possible to use memory-mapped NVRAM
15 on the D-Link DWL-8610AP and the D-Link DIR-890L.
16
17 Cc: Hauke Mehrtens <hauke@hauke-m.de>
18 Cc: linux-mips@vger.kernel.org
19 Cc: Florian Fainelli <f.fainelli@gmail.com>
20 Cc: bcm-kernel-feedback-list@broadcom.com
21 Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
22 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
23 [Added an export for modules potentially using the init symbol]
24 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
25 Link: https://lore.kernel.org/r/20221103082529.359084-1-linus.walleij@linaro.org
26 Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
27 ---
28 drivers/firmware/broadcom/bcm47xx_nvram.c | 18 ++++++++++++++++++
29 drivers/nvmem/brcm_nvram.c | 3 +++
30 include/linux/bcm47xx_nvram.h | 6 ++++++
31 3 files changed, 27 insertions(+)
32
33 --- a/drivers/firmware/broadcom/bcm47xx_nvram.c
34 +++ b/drivers/firmware/broadcom/bcm47xx_nvram.c
35 @@ -110,6 +110,24 @@ found:
36 return 0;
37 }
38
39 +int bcm47xx_nvram_init_from_iomem(void __iomem *nvram_start, size_t res_size)
40 +{
41 + if (nvram_len) {
42 + pr_warn("nvram already initialized\n");
43 + return -EEXIST;
44 + }
45 +
46 + if (!bcm47xx_nvram_is_valid(nvram_start)) {
47 + pr_err("No valid NVRAM found\n");
48 + return -ENOENT;
49 + }
50 +
51 + bcm47xx_nvram_copy(nvram_start, res_size);
52 +
53 + return 0;
54 +}
55 +EXPORT_SYMBOL_GPL(bcm47xx_nvram_init_from_iomem);
56 +
57 /*
58 * On bcm47xx we need access to the NVRAM very early, so we can't use mtd
59 * subsystem to access flash. We can't even use platform device / driver to
60 --- a/drivers/nvmem/brcm_nvram.c
61 +++ b/drivers/nvmem/brcm_nvram.c
62 @@ -3,6 +3,7 @@
63 * Copyright (C) 2021 Rafał Miłecki <rafal@milecki.pl>
64 */
65
66 +#include <linux/bcm47xx_nvram.h>
67 #include <linux/io.h>
68 #include <linux/mod_devicetable.h>
69 #include <linux/module.h>
70 @@ -139,6 +140,8 @@ static int brcm_nvram_probe(struct platf
71 if (err)
72 return err;
73
74 + bcm47xx_nvram_init_from_iomem(priv->base, resource_size(res));
75 +
76 config.dev = dev;
77 config.cells = priv->cells;
78 config.ncells = priv->ncells;
79 --- a/include/linux/bcm47xx_nvram.h
80 +++ b/include/linux/bcm47xx_nvram.h
81 @@ -11,6 +11,7 @@
82 #include <linux/vmalloc.h>
83
84 #ifdef CONFIG_BCM47XX_NVRAM
85 +int bcm47xx_nvram_init_from_iomem(void __iomem *nvram_start, size_t res_size);
86 int bcm47xx_nvram_init_from_mem(u32 base, u32 lim);
87 int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len);
88 int bcm47xx_nvram_gpio_pin(const char *name);
89 @@ -20,6 +21,11 @@ static inline void bcm47xx_nvram_release
90 vfree(nvram);
91 };
92 #else
93 +static inline int bcm47xx_nvram_init_from_iomem(void __iomem *nvram_start,
94 + size_t res_size)
95 +{
96 + return -ENOTSUPP;
97 +}
98 static inline int bcm47xx_nvram_init_from_mem(u32 base, u32 lim)
99 {
100 return -ENOTSUPP;