1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2023 Westermo Network Technologies AB
6 #include <linux/device.h>
8 #include <linux/module.h>
9 #include <linux/mod_devicetable.h>
10 #include <linux/nvmem-provider.h>
11 #include <linux/platform_device.h>
13 struct qoriq_efuse_priv {
17 static int qoriq_efuse_read(void *context, unsigned int offset, void *val,
20 struct qoriq_efuse_priv *priv = context;
22 /* .stride = 4 so offset is guaranteed to be aligned */
23 __ioread32_copy(val, priv->base + offset, bytes / 4);
25 /* Ignore trailing bytes (there shouldn't be any) */
30 static int qoriq_efuse_probe(struct platform_device *pdev)
32 struct nvmem_config config = {
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,
42 struct qoriq_efuse_priv *priv;
43 struct nvmem_device *nvmem;
46 priv = devm_kzalloc(config.dev, sizeof(*priv), GFP_KERNEL);
50 priv->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
51 if (IS_ERR(priv->base))
52 return PTR_ERR(priv->base);
54 config.size = resource_size(res);
56 nvmem = devm_nvmem_register(config.dev, &config);
58 return PTR_ERR_OR_ZERO(nvmem);
61 static const struct of_device_id qoriq_efuse_of_match[] = {
62 { .compatible = "fsl,t1023-sfp", },
65 MODULE_DEVICE_TABLE(of, qoriq_efuse_of_match);
67 static struct platform_driver qoriq_efuse_driver = {
68 .probe = qoriq_efuse_probe,
70 .name = "qoriq-efuse",
71 .of_match_table = qoriq_efuse_of_match,
74 module_platform_driver(qoriq_efuse_driver);
76 MODULE_AUTHOR("Richard Alpe <richard.alpe@bit42.se>");
77 MODULE_DESCRIPTION("NXP QorIQ Security Fuse Processor (SFP) Reader");
78 MODULE_LICENSE("GPL");