1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2015 MediaTek Inc.
4 * Author: Andrew-CT Chen <andrew-ct.chen@mediatek.com>
7 #include <linux/device.h>
8 #include <linux/module.h>
9 #include <linux/mod_devicetable.h>
11 #include <linux/nvmem-provider.h>
12 #include <linux/platform_device.h>
14 struct mtk_efuse_priv {
18 static int mtk_reg_read(void *context,
19 unsigned int reg, void *_val, size_t bytes)
21 struct mtk_efuse_priv *priv = context;
22 void __iomem *addr = priv->base + reg;
26 for (i = 0; i < bytes; i++, val++)
27 *val = readb(addr + i);
32 static int mtk_efuse_probe(struct platform_device *pdev)
34 struct device *dev = &pdev->dev;
36 struct nvmem_device *nvmem;
37 struct nvmem_config econfig = {};
38 struct mtk_efuse_priv *priv;
40 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
44 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
45 priv->base = devm_ioremap_resource(dev, res);
46 if (IS_ERR(priv->base))
47 return PTR_ERR(priv->base);
50 econfig.word_size = 1;
51 econfig.reg_read = mtk_reg_read;
52 econfig.size = resource_size(res);
55 nvmem = devm_nvmem_register(dev, &econfig);
57 return PTR_ERR_OR_ZERO(nvmem);
60 static const struct of_device_id mtk_efuse_of_match[] = {
61 { .compatible = "mediatek,mt8173-efuse",},
62 { .compatible = "mediatek,efuse",},
65 MODULE_DEVICE_TABLE(of, mtk_efuse_of_match);
67 static struct platform_driver mtk_efuse_driver = {
68 .probe = mtk_efuse_probe,
70 .name = "mediatek,efuse",
71 .of_match_table = mtk_efuse_of_match,
75 static int __init mtk_efuse_init(void)
79 ret = platform_driver_register(&mtk_efuse_driver);
81 pr_err("Failed to register efuse driver\n");
88 static void __exit mtk_efuse_exit(void)
90 return platform_driver_unregister(&mtk_efuse_driver);
93 subsys_initcall(mtk_efuse_init);
94 module_exit(mtk_efuse_exit);
96 MODULE_AUTHOR("Andrew-CT Chen <andrew-ct.chen@mediatek.com>");
97 MODULE_DESCRIPTION("Mediatek EFUSE driver");
98 MODULE_LICENSE("GPL v2");