[openwrt/openwrt] bcm53xx: backport NVMEM NVRAM driver
LEDE Commits
lede-commits at lists.infradead.org
Wed Mar 10 22:23:52 GMT 2021
rmilecki pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/01b1b375281b77233d65eb0ebda8e4e3a1bd2407
commit 01b1b375281b77233d65eb0ebda8e4e3a1bd2407
Author: Rafał Miłecki <rafal at milecki.pl>
AuthorDate: Wed Mar 10 23:22:18 2021 +0100
bcm53xx: backport NVMEM NVRAM driver
It supports NVRAM access described using DT binding. Right now NVRAM
data is exposed using /sys/bus/nvmem/ only.
Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
target/linux/bcm53xx/config-5.4 | 1 +
...01-dt-bindings-nvmem-add-Broadcom-s-NVRAM.patch | 56 ++++++++++
...nvram-new-driver-exposing-Broadcom-s-NVRA.patch | 124 +++++++++++++++++++++
3 files changed, 181 insertions(+)
diff --git a/target/linux/bcm53xx/config-5.4 b/target/linux/bcm53xx/config-5.4
index f0c54bbd8e..07a8f85aa0 100644
--- a/target/linux/bcm53xx/config-5.4
+++ b/target/linux/bcm53xx/config-5.4
@@ -271,6 +271,7 @@ CONFIG_NEED_DMA_MAP_STATE=y
CONFIG_NET_FLOW_LIMIT=y
CONFIG_NR_CPUS=2
CONFIG_NVMEM=y
+CONFIG_NVMEM_BRCM_NVRAM=y
CONFIG_NVMEM_SYSFS=y
CONFIG_OF=y
CONFIG_OF_ADDRESS=y
diff --git a/target/linux/bcm53xx/patches-5.4/080-v5.13-0001-dt-bindings-nvmem-add-Broadcom-s-NVRAM.patch b/target/linux/bcm53xx/patches-5.4/080-v5.13-0001-dt-bindings-nvmem-add-Broadcom-s-NVRAM.patch
new file mode 100644
index 0000000000..01e29aaad6
--- /dev/null
+++ b/target/linux/bcm53xx/patches-5.4/080-v5.13-0001-dt-bindings-nvmem-add-Broadcom-s-NVRAM.patch
@@ -0,0 +1,56 @@
+From c39edb9f9dcb6c8a0ba0ebf5df9e0ac93ab94b82 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal at milecki.pl>
+Date: Fri, 5 Mar 2021 19:32:35 +0100
+Subject: [PATCH] dt-bindings: nvmem: add Broadcom's NVRAM
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Broadcom's NVRAM structure contains device data and can be accessed
+using I/O mapping.
+
+Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
+Reviewed-by: Rob Herring <robh at kernel.org>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla at linaro.org>
+---
+ .../devicetree/bindings/nvmem/brcm,nvram.yaml | 34 +++++++++++++++++++
+ 1 file changed, 34 insertions(+)
+ create mode 100644 Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
+
+--- /dev/null
++++ b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
+@@ -0,0 +1,34 @@
++# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
++%YAML 1.2
++---
++$id: http://devicetree.org/schemas/nvmem/brcm,nvram.yaml#
++$schema: http://devicetree.org/meta-schemas/core.yaml#
++
++title: Broadcom's NVRAM
++
++description: |
++ Broadcom's NVRAM is a structure containing device specific environment
++ variables. It is used for storing device configuration, booting parameters
++ and calibration data.
++
++ NVRAM can be accessed on Broadcom BCM47xx MIPS and Northstar ARM Cortex-A9
++ devices usiong I/O mapped memory.
++
++maintainers:
++ - Rafał Miłecki <rafal at milecki.pl>
++
++allOf:
++ - $ref: "nvmem.yaml#"
++
++properties:
++ compatible:
++ const: brcm,nvram
++
++unevaluatedProperties: false
++
++examples:
++ - |
++ nvram at 1eff0000 {
++ compatible = "brcm,nvram";
++ reg = <0x1eff0000 0x10000>;
++ };
diff --git a/target/linux/bcm53xx/patches-5.4/080-v5.13-0002-nvmem-brcm_nvram-new-driver-exposing-Broadcom-s-NVRA.patch b/target/linux/bcm53xx/patches-5.4/080-v5.13-0002-nvmem-brcm_nvram-new-driver-exposing-Broadcom-s-NVRA.patch
new file mode 100644
index 0000000000..61def7a93d
--- /dev/null
+++ b/target/linux/bcm53xx/patches-5.4/080-v5.13-0002-nvmem-brcm_nvram-new-driver-exposing-Broadcom-s-NVRA.patch
@@ -0,0 +1,124 @@
+From b152bbeb0282bfcf6f91d0d5befd7582c1c3fc23 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal at milecki.pl>
+Date: Fri, 5 Mar 2021 19:32:36 +0100
+Subject: [PATCH] nvmem: brcm_nvram: new driver exposing Broadcom's NVRAM
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+This driver provides access to Broadcom's NVRAM.
+
+Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla at linaro.org>
+---
+ drivers/nvmem/Kconfig | 9 +++++
+ drivers/nvmem/Makefile | 2 +
+ drivers/nvmem/brcm_nvram.c | 78 ++++++++++++++++++++++++++++++++++++++
+ 3 files changed, 89 insertions(+)
+ create mode 100644 drivers/nvmem/brcm_nvram.c
+
+--- a/drivers/nvmem/Kconfig
++++ b/drivers/nvmem/Kconfig
+@@ -230,4 +230,13 @@ config NVMEM_ZYNQMP
+
+ If sure, say yes. If unsure, say no.
+
++
++config NVMEM_BRCM_NVRAM
++ tristate "Broadcom's NVRAM support"
++ depends on ARCH_BCM_5301X || COMPILE_TEST
++ depends on HAS_IOMEM
++ help
++ This driver provides support for Broadcom's NVRAM that can be accessed
++ using I/O mapping.
++
+ endif
+--- a/drivers/nvmem/Makefile
++++ b/drivers/nvmem/Makefile
+@@ -50,3 +50,5 @@ obj-$(CONFIG_SC27XX_EFUSE) += nvmem-sc27
+ nvmem-sc27xx-efuse-y := sc27xx-efuse.o
+ obj-$(CONFIG_NVMEM_ZYNQMP) += nvmem_zynqmp_nvmem.o
+ nvmem_zynqmp_nvmem-y := zynqmp_nvmem.o
++obj-$(CONFIG_NVMEM_BRCM_NVRAM) += nvmem_brcm_nvram.o
++nvmem_brcm_nvram-y := brcm_nvram.o
+--- /dev/null
++++ b/drivers/nvmem/brcm_nvram.c
+@@ -0,0 +1,78 @@
++// SPDX-License-Identifier: GPL-2.0-only
++/*
++ * Copyright (C) 2021 Rafał Miłecki <rafal at milecki.pl>
++ */
++
++#include <linux/io.h>
++#include <linux/mod_devicetable.h>
++#include <linux/module.h>
++#include <linux/nvmem-provider.h>
++#include <linux/platform_device.h>
++
++struct brcm_nvram {
++ struct device *dev;
++ void __iomem *base;
++};
++
++static int brcm_nvram_read(void *context, unsigned int offset, void *val,
++ size_t bytes)
++{
++ struct brcm_nvram *priv = context;
++ u8 *dst = val;
++
++ while (bytes--)
++ *dst++ = readb(priv->base + offset++);
++
++ return 0;
++}
++
++static int brcm_nvram_probe(struct platform_device *pdev)
++{
++ struct nvmem_config config = {
++ .name = "brcm-nvram",
++ .reg_read = brcm_nvram_read,
++ };
++ struct device *dev = &pdev->dev;
++ struct resource *res;
++ struct brcm_nvram *priv;
++
++ priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
++ if (!priv)
++ return -ENOMEM;
++ priv->dev = dev;
++
++ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
++ priv->base = devm_ioremap_resource(dev, res);
++ if (IS_ERR(priv->base))
++ return PTR_ERR(priv->base);
++
++ config.dev = dev;
++ config.priv = priv;
++ config.size = resource_size(res);
++
++ return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &config));
++}
++
++static const struct of_device_id brcm_nvram_of_match_table[] = {
++ { .compatible = "brcm,nvram", },
++ {},
++};
++
++static struct platform_driver brcm_nvram_driver = {
++ .probe = brcm_nvram_probe,
++ .driver = {
++ .name = "brcm_nvram",
++ .of_match_table = brcm_nvram_of_match_table,
++ },
++};
++
++static int __init brcm_nvram_init(void)
++{
++ return platform_driver_register(&brcm_nvram_driver);
++}
++
++subsys_initcall_sync(brcm_nvram_init);
++
++MODULE_AUTHOR("Rafał Miłecki");
++MODULE_LICENSE("GPL");
++MODULE_DEVICE_TABLE(of, brcm_nvram_of_match_table);
More information about the lede-commits
mailing list