kernel: update nvmem subsystem to the latest upstream
[openwrt/openwrt.git] / target / linux / generic / backport-5.15 / 804-v5.18-0007-nvmem-add-driver-for-Layerscape-SFP-Security-Fuse-Pr.patch
1 From f78451012b9e159afdba31c3eb69f223a9f42adc Mon Sep 17 00:00:00 2001
2 From: Michael Walle <michael@walle.cc>
3 Date: Sun, 20 Feb 2022 15:15:23 +0000
4 Subject: [PATCH] nvmem: add driver for Layerscape SFP (Security Fuse
5 Processor)
6
7 Add support for the Security Fuse Processor found on Layerscape SoCs.
8 This driver implements basic read access.
9
10 Signed-off-by: Michael Walle <michael@walle.cc>
11 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
12 Link: https://lore.kernel.org/r/20220220151527.17216-10-srinivas.kandagatla@linaro.org
13 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
14 ---
15 drivers/nvmem/Kconfig | 12 +++++
16 drivers/nvmem/Makefile | 2 +
17 drivers/nvmem/layerscape-sfp.c | 89 ++++++++++++++++++++++++++++++++++
18 3 files changed, 103 insertions(+)
19 create mode 100644 drivers/nvmem/layerscape-sfp.c
20
21 --- a/drivers/nvmem/Kconfig
22 +++ b/drivers/nvmem/Kconfig
23 @@ -300,4 +300,16 @@ config NVMEM_BRCM_NVRAM
24 This driver provides support for Broadcom's NVRAM that can be accessed
25 using I/O mapping.
26
27 +config NVMEM_LAYERSCAPE_SFP
28 + tristate "Layerscape SFP (Security Fuse Processor) support"
29 + depends on ARCH_LAYERSCAPE || COMPILE_TEST
30 + depends on HAS_IOMEM
31 + help
32 + This driver provides support to read the eFuses on Freescale
33 + Layerscape SoC's. For example, the vendor provides a per part
34 + unique ID there.
35 +
36 + This driver can also be built as a module. If so, the module
37 + will be called layerscape-sfp.
38 +
39 endif
40 --- a/drivers/nvmem/Makefile
41 +++ b/drivers/nvmem/Makefile
42 @@ -61,3 +61,5 @@ obj-$(CONFIG_NVMEM_RMEM) += nvmem-rmem.
43 nvmem-rmem-y := rmem.o
44 obj-$(CONFIG_NVMEM_BRCM_NVRAM) += nvmem_brcm_nvram.o
45 nvmem_brcm_nvram-y := brcm_nvram.o
46 +obj-$(CONFIG_NVMEM_LAYERSCAPE_SFP) += nvmem-layerscape-sfp.o
47 +nvmem-layerscape-sfp-y := layerscape-sfp.o
48 --- /dev/null
49 +++ b/drivers/nvmem/layerscape-sfp.c
50 @@ -0,0 +1,89 @@
51 +// SPDX-License-Identifier: GPL-2.0-only
52 +/*
53 + * Layerscape SFP driver
54 + *
55 + * Copyright (c) 2022 Michael Walle <michael@walle.cc>
56 + *
57 + */
58 +
59 +#include <linux/device.h>
60 +#include <linux/io.h>
61 +#include <linux/mod_devicetable.h>
62 +#include <linux/module.h>
63 +#include <linux/nvmem-provider.h>
64 +#include <linux/platform_device.h>
65 +#include <linux/property.h>
66 +
67 +#define LAYERSCAPE_SFP_OTP_OFFSET 0x0200
68 +
69 +struct layerscape_sfp_priv {
70 + void __iomem *base;
71 +};
72 +
73 +struct layerscape_sfp_data {
74 + int size;
75 +};
76 +
77 +static int layerscape_sfp_read(void *context, unsigned int offset, void *val,
78 + size_t bytes)
79 +{
80 + struct layerscape_sfp_priv *priv = context;
81 +
82 + memcpy_fromio(val, priv->base + LAYERSCAPE_SFP_OTP_OFFSET + offset,
83 + bytes);
84 +
85 + return 0;
86 +}
87 +
88 +static struct nvmem_config layerscape_sfp_nvmem_config = {
89 + .name = "fsl-sfp",
90 + .reg_read = layerscape_sfp_read,
91 +};
92 +
93 +static int layerscape_sfp_probe(struct platform_device *pdev)
94 +{
95 + const struct layerscape_sfp_data *data;
96 + struct layerscape_sfp_priv *priv;
97 + struct nvmem_device *nvmem;
98 +
99 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
100 + if (!priv)
101 + return -ENOMEM;
102 +
103 + priv->base = devm_platform_ioremap_resource(pdev, 0);
104 + if (IS_ERR(priv->base))
105 + return PTR_ERR(priv->base);
106 +
107 + data = device_get_match_data(&pdev->dev);
108 +
109 + layerscape_sfp_nvmem_config.size = data->size;
110 + layerscape_sfp_nvmem_config.dev = &pdev->dev;
111 + layerscape_sfp_nvmem_config.priv = priv;
112 +
113 + nvmem = devm_nvmem_register(&pdev->dev, &layerscape_sfp_nvmem_config);
114 +
115 + return PTR_ERR_OR_ZERO(nvmem);
116 +}
117 +
118 +static const struct layerscape_sfp_data ls1028a_data = {
119 + .size = 0x88,
120 +};
121 +
122 +static const struct of_device_id layerscape_sfp_dt_ids[] = {
123 + { .compatible = "fsl,ls1028a-sfp", .data = &ls1028a_data },
124 + {},
125 +};
126 +MODULE_DEVICE_TABLE(of, layerscape_sfp_dt_ids);
127 +
128 +static struct platform_driver layerscape_sfp_driver = {
129 + .probe = layerscape_sfp_probe,
130 + .driver = {
131 + .name = "layerscape_sfp",
132 + .of_match_table = layerscape_sfp_dt_ids,
133 + },
134 +};
135 +module_platform_driver(layerscape_sfp_driver);
136 +
137 +MODULE_AUTHOR("Michael Walle <michael@walle.cc>");
138 +MODULE_DESCRIPTION("Layerscape Security Fuse Processor driver");
139 +MODULE_LICENSE("GPL");