ath79: add support for Huawei AP5030DN
[openwrt/openwrt.git] / target / linux / generic / backport-6.1 / 814-v6.6-0009-nvmem-add-new-NXP-QorIQ-eFuse-driver.patch
1 From c8efcf7a86ebf2ff48584d270b3070a7075bc345 Mon Sep 17 00:00:00 2001
2 From: Richard Alpe <richard@bit42.se>
3 Date: Mon, 10 Apr 2023 10:20:51 +0200
4 Subject: [PATCH] nvmem: add new NXP QorIQ eFuse driver
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Add SFP (Security Fuse Processor) read support for NXP (Freescale)
10 QorIQ series SOC's.
11
12 This patch adds support for the T1023 SOC using the SFP offset from
13 the existing T1023 device tree. In theory this should also work for
14 T1024, T1014 and T1013 which uses the same SFP base offset.
15
16 Signed-off-by: Richard Alpe <richard@bit42.se>
17 Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
18 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
19 ---
20 drivers/nvmem/Kconfig | 12 ++++++
21 drivers/nvmem/Makefile | 2 +
22 drivers/nvmem/qoriq-efuse.c | 78 +++++++++++++++++++++++++++++++++++++
23 3 files changed, 92 insertions(+)
24 create mode 100644 drivers/nvmem/qoriq-efuse.c
25
26 --- a/drivers/nvmem/Kconfig
27 +++ b/drivers/nvmem/Kconfig
28 @@ -392,4 +392,16 @@ config NVMEM_ZYNQMP
29
30 If sure, say yes. If unsure, say no.
31
32 +config NVMEM_QORIQ_EFUSE
33 + tristate "NXP QorIQ eFuse support"
34 + depends on PPC_85xx || COMPILE_TEST
35 + depends on HAS_IOMEM
36 + help
37 + This driver provides read support for the eFuses (SFP) on NXP QorIQ
38 + series SoC's. This includes secure boot settings, the globally unique
39 + NXP ID 'FUIDR' and the OEM unique ID 'OUIDR'.
40 +
41 + This driver can also be built as a module. If so, the module
42 + will be called nvmem_qoriq_efuse.
43 +
44 endif
45 --- a/drivers/nvmem/Makefile
46 +++ b/drivers/nvmem/Makefile
47 @@ -77,3 +77,5 @@ obj-$(CONFIG_NVMEM_VF610_OCOTP) += nvme
48 nvmem-vf610-ocotp-y := vf610-ocotp.o
49 obj-$(CONFIG_NVMEM_ZYNQMP) += nvmem_zynqmp_nvmem.o
50 nvmem_zynqmp_nvmem-y := zynqmp_nvmem.o
51 +obj-$(CONFIG_NVMEM_QORIQ_EFUSE) += nvmem-qoriq-efuse.o
52 +nvmem-qoriq-efuse-y := qoriq-efuse.o
53 --- /dev/null
54 +++ b/drivers/nvmem/qoriq-efuse.c
55 @@ -0,0 +1,78 @@
56 +// SPDX-License-Identifier: GPL-2.0
57 +/*
58 + * Copyright (C) 2023 Westermo Network Technologies AB
59 + */
60 +
61 +#include <linux/device.h>
62 +#include <linux/io.h>
63 +#include <linux/module.h>
64 +#include <linux/mod_devicetable.h>
65 +#include <linux/nvmem-provider.h>
66 +#include <linux/platform_device.h>
67 +
68 +struct qoriq_efuse_priv {
69 + void __iomem *base;
70 +};
71 +
72 +static int qoriq_efuse_read(void *context, unsigned int offset, void *val,
73 + size_t bytes)
74 +{
75 + struct qoriq_efuse_priv *priv = context;
76 +
77 + /* .stride = 4 so offset is guaranteed to be aligned */
78 + __ioread32_copy(val, priv->base + offset, bytes / 4);
79 +
80 + /* Ignore trailing bytes (there shouldn't be any) */
81 +
82 + return 0;
83 +}
84 +
85 +static int qoriq_efuse_probe(struct platform_device *pdev)
86 +{
87 + struct nvmem_config config = {
88 + .dev = &pdev->dev,
89 + .read_only = true,
90 + .reg_read = qoriq_efuse_read,
91 + .stride = sizeof(u32),
92 + .word_size = sizeof(u32),
93 + .name = "qoriq_efuse_read",
94 + .id = NVMEM_DEVID_AUTO,
95 + .root_only = true,
96 + };
97 + struct qoriq_efuse_priv *priv;
98 + struct nvmem_device *nvmem;
99 + struct resource *res;
100 +
101 + priv = devm_kzalloc(config.dev, sizeof(*priv), GFP_KERNEL);
102 + if (!priv)
103 + return -ENOMEM;
104 +
105 + priv->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
106 + if (IS_ERR(priv->base))
107 + return PTR_ERR(priv->base);
108 +
109 + config.size = resource_size(res);
110 + config.priv = priv;
111 + nvmem = devm_nvmem_register(config.dev, &config);
112 +
113 + return PTR_ERR_OR_ZERO(nvmem);
114 +}
115 +
116 +static const struct of_device_id qoriq_efuse_of_match[] = {
117 + { .compatible = "fsl,t1023-sfp", },
118 + {/* sentinel */},
119 +};
120 +MODULE_DEVICE_TABLE(of, qoriq_efuse_of_match);
121 +
122 +static struct platform_driver qoriq_efuse_driver = {
123 + .probe = qoriq_efuse_probe,
124 + .driver = {
125 + .name = "qoriq-efuse",
126 + .of_match_table = qoriq_efuse_of_match,
127 + },
128 +};
129 +module_platform_driver(qoriq_efuse_driver);
130 +
131 +MODULE_AUTHOR("Richard Alpe <richard.alpe@bit42.se>");
132 +MODULE_DESCRIPTION("NXP QorIQ Security Fuse Processor (SFP) Reader");
133 +MODULE_LICENSE("GPL");