1 From b152bbeb0282bfcf6f91d0d5befd7582c1c3fc23 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Fri, 5 Mar 2021 19:32:36 +0100
4 Subject: [PATCH] nvmem: brcm_nvram: new driver exposing Broadcom's NVRAM
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 This driver provides access to Broadcom's NVRAM.
11 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
12 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
14 drivers/nvmem/Kconfig | 9 +++++
15 drivers/nvmem/Makefile | 2 +
16 drivers/nvmem/brcm_nvram.c | 78 ++++++++++++++++++++++++++++++++++++++
17 3 files changed, 89 insertions(+)
18 create mode 100644 drivers/nvmem/brcm_nvram.c
20 --- a/drivers/nvmem/Kconfig
21 +++ b/drivers/nvmem/Kconfig
22 @@ -230,4 +230,13 @@ config NVMEM_ZYNQMP
24 If sure, say yes. If unsure, say no.
27 +config NVMEM_BRCM_NVRAM
28 + tristate "Broadcom's NVRAM support"
29 + depends on ARCH_BCM_5301X || COMPILE_TEST
30 + depends on HAS_IOMEM
32 + This driver provides support for Broadcom's NVRAM that can be accessed
36 --- a/drivers/nvmem/Makefile
37 +++ b/drivers/nvmem/Makefile
38 @@ -50,3 +50,5 @@ obj-$(CONFIG_SC27XX_EFUSE) += nvmem-sc27
39 nvmem-sc27xx-efuse-y := sc27xx-efuse.o
40 obj-$(CONFIG_NVMEM_ZYNQMP) += nvmem_zynqmp_nvmem.o
41 nvmem_zynqmp_nvmem-y := zynqmp_nvmem.o
42 +obj-$(CONFIG_NVMEM_BRCM_NVRAM) += nvmem_brcm_nvram.o
43 +nvmem_brcm_nvram-y := brcm_nvram.o
45 +++ b/drivers/nvmem/brcm_nvram.c
47 +// SPDX-License-Identifier: GPL-2.0-only
49 + * Copyright (C) 2021 Rafał Miłecki <rafal@milecki.pl>
52 +#include <linux/io.h>
53 +#include <linux/mod_devicetable.h>
54 +#include <linux/module.h>
55 +#include <linux/nvmem-provider.h>
56 +#include <linux/platform_device.h>
63 +static int brcm_nvram_read(void *context, unsigned int offset, void *val,
66 + struct brcm_nvram *priv = context;
70 + *dst++ = readb(priv->base + offset++);
75 +static int brcm_nvram_probe(struct platform_device *pdev)
77 + struct nvmem_config config = {
78 + .name = "brcm-nvram",
79 + .reg_read = brcm_nvram_read,
81 + struct device *dev = &pdev->dev;
82 + struct resource *res;
83 + struct brcm_nvram *priv;
85 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
90 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
91 + priv->base = devm_ioremap_resource(dev, res);
92 + if (IS_ERR(priv->base))
93 + return PTR_ERR(priv->base);
97 + config.size = resource_size(res);
99 + return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &config));
102 +static const struct of_device_id brcm_nvram_of_match_table[] = {
103 + { .compatible = "brcm,nvram", },
107 +static struct platform_driver brcm_nvram_driver = {
108 + .probe = brcm_nvram_probe,
110 + .name = "brcm_nvram",
111 + .of_match_table = brcm_nvram_of_match_table,
115 +static int __init brcm_nvram_init(void)
117 + return platform_driver_register(&brcm_nvram_driver);
120 +subsys_initcall_sync(brcm_nvram_init);
122 +MODULE_AUTHOR("Rafał Miłecki");
123 +MODULE_LICENSE("GPL");
124 +MODULE_DEVICE_TABLE(of, brcm_nvram_of_match_table);