bcm53xx: add testing support for kernel 5.10
[openwrt/staging/ldir.git] / target / linux / bcm53xx / patches-5.10 / 080-v5.13-0002-nvmem-brcm_nvram-new-driver-exposing-Broadcom-s-NVRA.patch
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
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 This driver provides access to Broadcom's NVRAM.
10
11 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
12 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
13 ---
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
19
20 --- a/drivers/nvmem/Kconfig
21 +++ b/drivers/nvmem/Kconfig
22 @@ -270,4 +270,13 @@ config SPRD_EFUSE
23 This driver can also be built as a module. If so, the module
24 will be called nvmem-sprd-efuse.
25
26 +
27 +config NVMEM_BRCM_NVRAM
28 + tristate "Broadcom's NVRAM support"
29 + depends on ARCH_BCM_5301X || COMPILE_TEST
30 + depends on HAS_IOMEM
31 + help
32 + This driver provides support for Broadcom's NVRAM that can be accessed
33 + using I/O mapping.
34 +
35 endif
36 --- a/drivers/nvmem/Makefile
37 +++ b/drivers/nvmem/Makefile
38 @@ -55,3 +55,5 @@ obj-$(CONFIG_NVMEM_ZYNQMP) += nvmem_zynq
39 nvmem_zynqmp_nvmem-y := zynqmp_nvmem.o
40 obj-$(CONFIG_SPRD_EFUSE) += nvmem_sprd_efuse.o
41 nvmem_sprd_efuse-y := sprd-efuse.o
42 +obj-$(CONFIG_NVMEM_BRCM_NVRAM) += nvmem_brcm_nvram.o
43 +nvmem_brcm_nvram-y := brcm_nvram.o
44 --- /dev/null
45 +++ b/drivers/nvmem/brcm_nvram.c
46 @@ -0,0 +1,78 @@
47 +// SPDX-License-Identifier: GPL-2.0-only
48 +/*
49 + * Copyright (C) 2021 Rafał Miłecki <rafal@milecki.pl>
50 + */
51 +
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>
57 +
58 +struct brcm_nvram {
59 + struct device *dev;
60 + void __iomem *base;
61 +};
62 +
63 +static int brcm_nvram_read(void *context, unsigned int offset, void *val,
64 + size_t bytes)
65 +{
66 + struct brcm_nvram *priv = context;
67 + u8 *dst = val;
68 +
69 + while (bytes--)
70 + *dst++ = readb(priv->base + offset++);
71 +
72 + return 0;
73 +}
74 +
75 +static int brcm_nvram_probe(struct platform_device *pdev)
76 +{
77 + struct nvmem_config config = {
78 + .name = "brcm-nvram",
79 + .reg_read = brcm_nvram_read,
80 + };
81 + struct device *dev = &pdev->dev;
82 + struct resource *res;
83 + struct brcm_nvram *priv;
84 +
85 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
86 + if (!priv)
87 + return -ENOMEM;
88 + priv->dev = dev;
89 +
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);
94 +
95 + config.dev = dev;
96 + config.priv = priv;
97 + config.size = resource_size(res);
98 +
99 + return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &config));
100 +}
101 +
102 +static const struct of_device_id brcm_nvram_of_match_table[] = {
103 + { .compatible = "brcm,nvram", },
104 + {},
105 +};
106 +
107 +static struct platform_driver brcm_nvram_driver = {
108 + .probe = brcm_nvram_probe,
109 + .driver = {
110 + .name = "brcm_nvram",
111 + .of_match_table = brcm_nvram_of_match_table,
112 + },
113 +};
114 +
115 +static int __init brcm_nvram_init(void)
116 +{
117 + return platform_driver_register(&brcm_nvram_driver);
118 +}
119 +
120 +subsys_initcall_sync(brcm_nvram_init);
121 +
122 +MODULE_AUTHOR("Rafał Miłecki");
123 +MODULE_LICENSE("GPL");
124 +MODULE_DEVICE_TABLE(of, brcm_nvram_of_match_table);