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
7 Add support for the Security Fuse Processor found on Layerscape SoCs.
8 This driver implements basic read access.
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>
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
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
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
32 + This driver provides support to read the eFuses on Freescale
33 + Layerscape SoC's. For example, the vendor provides a per part
36 + This driver can also be built as a module. If so, the module
37 + will be called layerscape-sfp.
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
49 +++ b/drivers/nvmem/layerscape-sfp.c
51 +// SPDX-License-Identifier: GPL-2.0-only
53 + * Layerscape SFP driver
55 + * Copyright (c) 2022 Michael Walle <michael@walle.cc>
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>
67 +#define LAYERSCAPE_SFP_OTP_OFFSET 0x0200
69 +struct layerscape_sfp_priv {
73 +struct layerscape_sfp_data {
77 +static int layerscape_sfp_read(void *context, unsigned int offset, void *val,
80 + struct layerscape_sfp_priv *priv = context;
82 + memcpy_fromio(val, priv->base + LAYERSCAPE_SFP_OTP_OFFSET + offset,
88 +static struct nvmem_config layerscape_sfp_nvmem_config = {
90 + .reg_read = layerscape_sfp_read,
93 +static int layerscape_sfp_probe(struct platform_device *pdev)
95 + const struct layerscape_sfp_data *data;
96 + struct layerscape_sfp_priv *priv;
97 + struct nvmem_device *nvmem;
99 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
103 + priv->base = devm_platform_ioremap_resource(pdev, 0);
104 + if (IS_ERR(priv->base))
105 + return PTR_ERR(priv->base);
107 + data = device_get_match_data(&pdev->dev);
109 + layerscape_sfp_nvmem_config.size = data->size;
110 + layerscape_sfp_nvmem_config.dev = &pdev->dev;
111 + layerscape_sfp_nvmem_config.priv = priv;
113 + nvmem = devm_nvmem_register(&pdev->dev, &layerscape_sfp_nvmem_config);
115 + return PTR_ERR_OR_ZERO(nvmem);
118 +static const struct layerscape_sfp_data ls1028a_data = {
122 +static const struct of_device_id layerscape_sfp_dt_ids[] = {
123 + { .compatible = "fsl,ls1028a-sfp", .data = &ls1028a_data },
126 +MODULE_DEVICE_TABLE(of, layerscape_sfp_dt_ids);
128 +static struct platform_driver layerscape_sfp_driver = {
129 + .probe = layerscape_sfp_probe,
131 + .name = "layerscape_sfp",
132 + .of_match_table = layerscape_sfp_dt_ids,
135 +module_platform_driver(layerscape_sfp_driver);
137 +MODULE_AUTHOR("Michael Walle <michael@walle.cc>");
138 +MODULE_DESCRIPTION("Layerscape Security Fuse Processor driver");
139 +MODULE_LICENSE("GPL");