Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

nvmem: add new NXP QorIQ eFuse driver

Add SFP (Security Fuse Processor) read support for NXP (Freescale)
QorIQ series SOC's.

This patch adds support for the T1023 SOC using the SFP offset from
the existing T1023 device tree. In theory this should also work for
T1024, T1014 and T1013 which uses the same SFP base offset.

Signed-off-by: Richard Alpe <richard@bit42.se>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20230823132744.350618-13-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Richard Alpe and committed by
Greg Kroah-Hartman
0861110b aa1ed604

+92
+12
drivers/nvmem/Kconfig
··· 392 392 393 393 If sure, say yes. If unsure, say no. 394 394 395 + config NVMEM_QORIQ_EFUSE 396 + tristate "NXP QorIQ eFuse support" 397 + depends on PPC_85xx || COMPILE_TEST 398 + depends on HAS_IOMEM 399 + help 400 + This driver provides read support for the eFuses (SFP) on NXP QorIQ 401 + series SoC's. This includes secure boot settings, the globally unique 402 + NXP ID 'FUIDR' and the OEM unique ID 'OUIDR'. 403 + 404 + This driver can also be built as a module. If so, the module 405 + will be called nvmem_qoriq_efuse. 406 + 395 407 endif
+2
drivers/nvmem/Makefile
··· 77 77 nvmem-vf610-ocotp-y := vf610-ocotp.o 78 78 obj-$(CONFIG_NVMEM_ZYNQMP) += nvmem_zynqmp_nvmem.o 79 79 nvmem_zynqmp_nvmem-y := zynqmp_nvmem.o 80 + obj-$(CONFIG_NVMEM_QORIQ_EFUSE) += nvmem-qoriq-efuse.o 81 + nvmem-qoriq-efuse-y := qoriq-efuse.o
+78
drivers/nvmem/qoriq-efuse.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (C) 2023 Westermo Network Technologies AB 4 + */ 5 + 6 + #include <linux/device.h> 7 + #include <linux/io.h> 8 + #include <linux/module.h> 9 + #include <linux/mod_devicetable.h> 10 + #include <linux/nvmem-provider.h> 11 + #include <linux/platform_device.h> 12 + 13 + struct qoriq_efuse_priv { 14 + void __iomem *base; 15 + }; 16 + 17 + static int qoriq_efuse_read(void *context, unsigned int offset, void *val, 18 + size_t bytes) 19 + { 20 + struct qoriq_efuse_priv *priv = context; 21 + 22 + /* .stride = 4 so offset is guaranteed to be aligned */ 23 + __ioread32_copy(val, priv->base + offset, bytes / 4); 24 + 25 + /* Ignore trailing bytes (there shouldn't be any) */ 26 + 27 + return 0; 28 + } 29 + 30 + static int qoriq_efuse_probe(struct platform_device *pdev) 31 + { 32 + struct nvmem_config config = { 33 + .dev = &pdev->dev, 34 + .read_only = true, 35 + .reg_read = qoriq_efuse_read, 36 + .stride = sizeof(u32), 37 + .word_size = sizeof(u32), 38 + .name = "qoriq_efuse_read", 39 + .id = NVMEM_DEVID_AUTO, 40 + .root_only = true, 41 + }; 42 + struct qoriq_efuse_priv *priv; 43 + struct nvmem_device *nvmem; 44 + struct resource *res; 45 + 46 + priv = devm_kzalloc(config.dev, sizeof(*priv), GFP_KERNEL); 47 + if (!priv) 48 + return -ENOMEM; 49 + 50 + priv->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 51 + if (IS_ERR(priv->base)) 52 + return PTR_ERR(priv->base); 53 + 54 + config.size = resource_size(res); 55 + config.priv = priv; 56 + nvmem = devm_nvmem_register(config.dev, &config); 57 + 58 + return PTR_ERR_OR_ZERO(nvmem); 59 + } 60 + 61 + static const struct of_device_id qoriq_efuse_of_match[] = { 62 + { .compatible = "fsl,t1023-sfp", }, 63 + {/* sentinel */}, 64 + }; 65 + MODULE_DEVICE_TABLE(of, qoriq_efuse_of_match); 66 + 67 + static struct platform_driver qoriq_efuse_driver = { 68 + .probe = qoriq_efuse_probe, 69 + .driver = { 70 + .name = "qoriq-efuse", 71 + .of_match_table = qoriq_efuse_of_match, 72 + }, 73 + }; 74 + module_platform_driver(qoriq_efuse_driver); 75 + 76 + MODULE_AUTHOR("Richard Alpe <richard.alpe@bit42.se>"); 77 + MODULE_DESCRIPTION("NXP QorIQ Security Fuse Processor (SFP) Reader"); 78 + MODULE_LICENSE("GPL");