diff options
author | Rafał Miłecki <rafal@milecki.pl> | 2022-09-14 14:20:38 +0200 |
---|---|---|
committer | Rafał Miłecki <rafal@milecki.pl> | 2022-09-14 14:21:57 +0200 |
commit | 2f50c53f1772f24e4687e960e21c5b392fb522f0 (patch) | |
tree | 7d5d7b3bbd8c4202fb9ce06ead8fb2cc88fb6632 /target/linux/bcm53xx | |
parent | 9cec4a0ea45b241cc54c5bc172510b843f19229e (diff) | |
download | upstream-2f50c53f1772f24e4687e960e21c5b392fb522f0.tar.gz upstream-2f50c53f1772f24e4687e960e21c5b392fb522f0.tar.bz2 upstream-2f50c53f1772f24e4687e960e21c5b392fb522f0.zip |
bcm53xx: update NVMEM driver for NVRAM
Include support for NVMEM cells.
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Diffstat (limited to 'target/linux/bcm53xx')
6 files changed, 378 insertions, 10 deletions
diff --git a/target/linux/bcm53xx/patches-5.10/081-v5.18-nvmem-brcm_nvram-parse-NVRAM-content-into-NVMEM-cell.patch b/target/linux/bcm53xx/patches-5.10/081-v5.18-nvmem-brcm_nvram-parse-NVRAM-content-into-NVMEM-cell.patch new file mode 100644 index 0000000000..99781b3a7b --- /dev/null +++ b/target/linux/bcm53xx/patches-5.10/081-v5.18-nvmem-brcm_nvram-parse-NVRAM-content-into-NVMEM-cell.patch @@ -0,0 +1,146 @@ +From 6e977eaa8280e957b87904b536661550f2a6b3e8 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl> +Date: Fri, 25 Feb 2022 17:58:20 +0000 +Subject: [PATCH] nvmem: brcm_nvram: parse NVRAM content into NVMEM cells +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +NVRAM consist of header and NUL separated key-value pairs. Parse it and +create NVMEM cell for every key-value entry. + +Signed-off-by: Rafał Miłecki <rafal@milecki.pl> +Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> +Link: https://lore.kernel.org/r/20220225175822.8293-3-srinivas.kandagatla@linaro.org +Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> +--- + drivers/nvmem/brcm_nvram.c | 90 ++++++++++++++++++++++++++++++++++++++ + 1 file changed, 90 insertions(+) + +--- a/drivers/nvmem/brcm_nvram.c ++++ b/drivers/nvmem/brcm_nvram.c +@@ -6,12 +6,26 @@ + #include <linux/io.h> + #include <linux/mod_devicetable.h> + #include <linux/module.h> ++#include <linux/nvmem-consumer.h> + #include <linux/nvmem-provider.h> + #include <linux/platform_device.h> ++#include <linux/slab.h> ++ ++#define NVRAM_MAGIC "FLSH" + + struct brcm_nvram { + struct device *dev; + void __iomem *base; ++ struct nvmem_cell_info *cells; ++ int ncells; ++}; ++ ++struct brcm_nvram_header { ++ char magic[4]; ++ __le32 len; ++ __le32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */ ++ __le32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */ ++ __le32 config_ncdl; /* ncdl values for memc */ + }; + + static int brcm_nvram_read(void *context, unsigned int offset, void *val, +@@ -26,6 +40,75 @@ static int brcm_nvram_read(void *context + return 0; + } + ++static int brcm_nvram_add_cells(struct brcm_nvram *priv, uint8_t *data, ++ size_t len) ++{ ++ struct device *dev = priv->dev; ++ char *var, *value, *eq; ++ int idx; ++ ++ priv->ncells = 0; ++ for (var = data + sizeof(struct brcm_nvram_header); ++ var < (char *)data + len && *var; ++ var += strlen(var) + 1) { ++ priv->ncells++; ++ } ++ ++ priv->cells = devm_kcalloc(dev, priv->ncells, sizeof(*priv->cells), GFP_KERNEL); ++ if (!priv->cells) ++ return -ENOMEM; ++ ++ for (var = data + sizeof(struct brcm_nvram_header), idx = 0; ++ var < (char *)data + len && *var; ++ var = value + strlen(value) + 1, idx++) { ++ eq = strchr(var, '='); ++ if (!eq) ++ break; ++ *eq = '\0'; ++ value = eq + 1; ++ ++ priv->cells[idx].name = devm_kstrdup(dev, var, GFP_KERNEL); ++ if (!priv->cells[idx].name) ++ return -ENOMEM; ++ priv->cells[idx].offset = value - (char *)data; ++ priv->cells[idx].bytes = strlen(value); ++ } ++ ++ return 0; ++} ++ ++static int brcm_nvram_parse(struct brcm_nvram *priv) ++{ ++ struct device *dev = priv->dev; ++ struct brcm_nvram_header header; ++ uint8_t *data; ++ size_t len; ++ int err; ++ ++ memcpy_fromio(&header, priv->base, sizeof(header)); ++ ++ if (memcmp(header.magic, NVRAM_MAGIC, 4)) { ++ dev_err(dev, "Invalid NVRAM magic\n"); ++ return -EINVAL; ++ } ++ ++ len = le32_to_cpu(header.len); ++ ++ data = kcalloc(1, len, GFP_KERNEL); ++ memcpy_fromio(data, priv->base, len); ++ data[len - 1] = '\0'; ++ ++ err = brcm_nvram_add_cells(priv, data, len); ++ if (err) { ++ dev_err(dev, "Failed to add cells: %d\n", err); ++ return err; ++ } ++ ++ kfree(data); ++ ++ return 0; ++} ++ + static int brcm_nvram_probe(struct platform_device *pdev) + { + struct nvmem_config config = { +@@ -35,6 +118,7 @@ static int brcm_nvram_probe(struct platf + struct device *dev = &pdev->dev; + struct resource *res; + struct brcm_nvram *priv; ++ int err; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) +@@ -46,7 +130,13 @@ static int brcm_nvram_probe(struct platf + if (IS_ERR(priv->base)) + return PTR_ERR(priv->base); + ++ err = brcm_nvram_parse(priv); ++ if (err) ++ return err; ++ + config.dev = dev; ++ config.cells = priv->cells; ++ config.ncells = priv->ncells; + config.priv = priv; + config.size = resource_size(res); + diff --git a/target/linux/bcm53xx/patches-5.10/082-v5.19-nvmem-brcm_nvram-find-Device-Tree-nodes-for-NVMEM-ce.patch b/target/linux/bcm53xx/patches-5.10/082-v5.19-nvmem-brcm_nvram-find-Device-Tree-nodes-for-NVMEM-ce.patch new file mode 100644 index 0000000000..a9eacd9419 --- /dev/null +++ b/target/linux/bcm53xx/patches-5.10/082-v5.19-nvmem-brcm_nvram-find-Device-Tree-nodes-for-NVMEM-ce.patch @@ -0,0 +1,38 @@ +From 207775f7e17b8fd0426a2ac4a5b81e4e1d71849e Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl> +Date: Fri, 29 Apr 2022 17:26:47 +0100 +Subject: [PATCH] nvmem: brcm_nvram: find Device Tree nodes for NVMEM cells +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +DT binding for Broadcom's NVRAM supports specifying NVMEM cells as NVMEM +device (provider) subnodes. Look for such subnodes when collecing NVMEM +cells. This allows NVMEM consumers to use NVRAM variables. + +Signed-off-by: Rafał Miłecki <rafal@milecki.pl> +Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> +Link: https://lore.kernel.org/r/20220429162701.2222-3-srinivas.kandagatla@linaro.org +Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> +--- + drivers/nvmem/brcm_nvram.c | 2 ++ + 1 file changed, 2 insertions(+) + +--- a/drivers/nvmem/brcm_nvram.c ++++ b/drivers/nvmem/brcm_nvram.c +@@ -8,6 +8,7 @@ + #include <linux/module.h> + #include <linux/nvmem-consumer.h> + #include <linux/nvmem-provider.h> ++#include <linux/of.h> + #include <linux/platform_device.h> + #include <linux/slab.h> + +@@ -72,6 +73,7 @@ static int brcm_nvram_add_cells(struct b + return -ENOMEM; + priv->cells[idx].offset = value - (char *)data; + priv->cells[idx].bytes = strlen(value); ++ priv->cells[idx].np = of_get_child_by_name(dev->of_node, priv->cells[idx].name); + } + + return 0; diff --git a/target/linux/bcm53xx/patches-5.10/800-0002-nvmem-brcm_nvram-provide-NVMEM-content-to-the-NVRAM-.patch b/target/linux/bcm53xx/patches-5.10/800-0002-nvmem-brcm_nvram-provide-NVMEM-content-to-the-NVRAM-.patch index cf5952ad5f..ecc5f3974e 100644 --- a/target/linux/bcm53xx/patches-5.10/800-0002-nvmem-brcm_nvram-provide-NVMEM-content-to-the-NVRAM-.patch +++ b/target/linux/bcm53xx/patches-5.10/800-0002-nvmem-brcm_nvram-provide-NVMEM-content-to-the-NVRAM-.patch @@ -20,12 +20,12 @@ Signed-off-by: Rafał Miłecki <rafal@milecki.pl> #include <linux/io.h> #include <linux/mod_devicetable.h> #include <linux/module.h> -@@ -46,6 +47,8 @@ static int brcm_nvram_probe(struct platf - if (IS_ERR(priv->base)) - return PTR_ERR(priv->base); +@@ -136,6 +137,8 @@ static int brcm_nvram_probe(struct platf + if (err) + return err; + bcm47xx_nvram_init_from_iomem(priv->base, resource_size(res)); + config.dev = dev; - config.priv = priv; - config.size = resource_size(res); + config.cells = priv->cells; + config.ncells = priv->ncells; diff --git a/target/linux/bcm53xx/patches-5.15/080-v5.18-nvmem-brcm_nvram-parse-NVRAM-content-into-NVMEM-cell.patch b/target/linux/bcm53xx/patches-5.15/080-v5.18-nvmem-brcm_nvram-parse-NVRAM-content-into-NVMEM-cell.patch new file mode 100644 index 0000000000..99781b3a7b --- /dev/null +++ b/target/linux/bcm53xx/patches-5.15/080-v5.18-nvmem-brcm_nvram-parse-NVRAM-content-into-NVMEM-cell.patch @@ -0,0 +1,146 @@ +From 6e977eaa8280e957b87904b536661550f2a6b3e8 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl> +Date: Fri, 25 Feb 2022 17:58:20 +0000 +Subject: [PATCH] nvmem: brcm_nvram: parse NVRAM content into NVMEM cells +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +NVRAM consist of header and NUL separated key-value pairs. Parse it and +create NVMEM cell for every key-value entry. + +Signed-off-by: Rafał Miłecki <rafal@milecki.pl> +Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> +Link: https://lore.kernel.org/r/20220225175822.8293-3-srinivas.kandagatla@linaro.org +Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> +--- + drivers/nvmem/brcm_nvram.c | 90 ++++++++++++++++++++++++++++++++++++++ + 1 file changed, 90 insertions(+) + +--- a/drivers/nvmem/brcm_nvram.c ++++ b/drivers/nvmem/brcm_nvram.c +@@ -6,12 +6,26 @@ + #include <linux/io.h> + #include <linux/mod_devicetable.h> + #include <linux/module.h> ++#include <linux/nvmem-consumer.h> + #include <linux/nvmem-provider.h> + #include <linux/platform_device.h> ++#include <linux/slab.h> ++ ++#define NVRAM_MAGIC "FLSH" + + struct brcm_nvram { + struct device *dev; + void __iomem *base; ++ struct nvmem_cell_info *cells; ++ int ncells; ++}; ++ ++struct brcm_nvram_header { ++ char magic[4]; ++ __le32 len; ++ __le32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */ ++ __le32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */ ++ __le32 config_ncdl; /* ncdl values for memc */ + }; + + static int brcm_nvram_read(void *context, unsigned int offset, void *val, +@@ -26,6 +40,75 @@ static int brcm_nvram_read(void *context + return 0; + } + ++static int brcm_nvram_add_cells(struct brcm_nvram *priv, uint8_t *data, ++ size_t len) ++{ ++ struct device *dev = priv->dev; ++ char *var, *value, *eq; ++ int idx; ++ ++ priv->ncells = 0; ++ for (var = data + sizeof(struct brcm_nvram_header); ++ var < (char *)data + len && *var; ++ var += strlen(var) + 1) { ++ priv->ncells++; ++ } ++ ++ priv->cells = devm_kcalloc(dev, priv->ncells, sizeof(*priv->cells), GFP_KERNEL); ++ if (!priv->cells) ++ return -ENOMEM; ++ ++ for (var = data + sizeof(struct brcm_nvram_header), idx = 0; ++ var < (char *)data + len && *var; ++ var = value + strlen(value) + 1, idx++) { ++ eq = strchr(var, '='); ++ if (!eq) ++ break; ++ *eq = '\0'; ++ value = eq + 1; ++ ++ priv->cells[idx].name = devm_kstrdup(dev, var, GFP_KERNEL); ++ if (!priv->cells[idx].name) ++ return -ENOMEM; ++ priv->cells[idx].offset = value - (char *)data; ++ priv->cells[idx].bytes = strlen(value); ++ } ++ ++ return 0; ++} ++ ++static int brcm_nvram_parse(struct brcm_nvram *priv) ++{ ++ struct device *dev = priv->dev; ++ struct brcm_nvram_header header; ++ uint8_t *data; ++ size_t len; ++ int err; ++ ++ memcpy_fromio(&header, priv->base, sizeof(header)); ++ ++ if (memcmp(header.magic, NVRAM_MAGIC, 4)) { ++ dev_err(dev, "Invalid NVRAM magic\n"); ++ return -EINVAL; ++ } ++ ++ len = le32_to_cpu(header.len); ++ ++ data = kcalloc(1, len, GFP_KERNEL); ++ memcpy_fromio(data, priv->base, len); ++ data[len - 1] = '\0'; ++ ++ err = brcm_nvram_add_cells(priv, data, len); ++ if (err) { ++ dev_err(dev, "Failed to add cells: %d\n", err); ++ return err; ++ } ++ ++ kfree(data); ++ ++ return 0; ++} ++ + static int brcm_nvram_probe(struct platform_device *pdev) + { + struct nvmem_config config = { +@@ -35,6 +118,7 @@ static int brcm_nvram_probe(struct platf + struct device *dev = &pdev->dev; + struct resource *res; + struct brcm_nvram *priv; ++ int err; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) +@@ -46,7 +130,13 @@ static int brcm_nvram_probe(struct platf + if (IS_ERR(priv->base)) + return PTR_ERR(priv->base); + ++ err = brcm_nvram_parse(priv); ++ if (err) ++ return err; ++ + config.dev = dev; ++ config.cells = priv->cells; ++ config.ncells = priv->ncells; + config.priv = priv; + config.size = resource_size(res); + diff --git a/target/linux/bcm53xx/patches-5.15/081-v5.19-nvmem-brcm_nvram-find-Device-Tree-nodes-for-NVMEM-ce.patch b/target/linux/bcm53xx/patches-5.15/081-v5.19-nvmem-brcm_nvram-find-Device-Tree-nodes-for-NVMEM-ce.patch new file mode 100644 index 0000000000..a9eacd9419 --- /dev/null +++ b/target/linux/bcm53xx/patches-5.15/081-v5.19-nvmem-brcm_nvram-find-Device-Tree-nodes-for-NVMEM-ce.patch @@ -0,0 +1,38 @@ +From 207775f7e17b8fd0426a2ac4a5b81e4e1d71849e Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl> +Date: Fri, 29 Apr 2022 17:26:47 +0100 +Subject: [PATCH] nvmem: brcm_nvram: find Device Tree nodes for NVMEM cells +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +DT binding for Broadcom's NVRAM supports specifying NVMEM cells as NVMEM +device (provider) subnodes. Look for such subnodes when collecing NVMEM +cells. This allows NVMEM consumers to use NVRAM variables. + +Signed-off-by: Rafał Miłecki <rafal@milecki.pl> +Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> +Link: https://lore.kernel.org/r/20220429162701.2222-3-srinivas.kandagatla@linaro.org +Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> +--- + drivers/nvmem/brcm_nvram.c | 2 ++ + 1 file changed, 2 insertions(+) + +--- a/drivers/nvmem/brcm_nvram.c ++++ b/drivers/nvmem/brcm_nvram.c +@@ -8,6 +8,7 @@ + #include <linux/module.h> + #include <linux/nvmem-consumer.h> + #include <linux/nvmem-provider.h> ++#include <linux/of.h> + #include <linux/platform_device.h> + #include <linux/slab.h> + +@@ -72,6 +73,7 @@ static int brcm_nvram_add_cells(struct b + return -ENOMEM; + priv->cells[idx].offset = value - (char *)data; + priv->cells[idx].bytes = strlen(value); ++ priv->cells[idx].np = of_get_child_by_name(dev->of_node, priv->cells[idx].name); + } + + return 0; diff --git a/target/linux/bcm53xx/patches-5.15/800-0002-nvmem-brcm_nvram-provide-NVMEM-content-to-the-NVRAM-.patch b/target/linux/bcm53xx/patches-5.15/800-0002-nvmem-brcm_nvram-provide-NVMEM-content-to-the-NVRAM-.patch index cf5952ad5f..ecc5f3974e 100644 --- a/target/linux/bcm53xx/patches-5.15/800-0002-nvmem-brcm_nvram-provide-NVMEM-content-to-the-NVRAM-.patch +++ b/target/linux/bcm53xx/patches-5.15/800-0002-nvmem-brcm_nvram-provide-NVMEM-content-to-the-NVRAM-.patch @@ -20,12 +20,12 @@ Signed-off-by: Rafał Miłecki <rafal@milecki.pl> #include <linux/io.h> #include <linux/mod_devicetable.h> #include <linux/module.h> -@@ -46,6 +47,8 @@ static int brcm_nvram_probe(struct platf - if (IS_ERR(priv->base)) - return PTR_ERR(priv->base); +@@ -136,6 +137,8 @@ static int brcm_nvram_probe(struct platf + if (err) + return err; + bcm47xx_nvram_init_from_iomem(priv->base, resource_size(res)); + config.dev = dev; - config.priv = priv; - config.size = resource_size(res); + config.cells = priv->cells; + config.ncells = priv->ncells; |