gpio: of: Break out OF-only code
[linux/fpc-iii.git] / drivers / nvmem / mtk-efuse.c
blob856d9c3fc38e41d23422aea236eeb8fd5f5d7bc1
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2015 MediaTek Inc.
4 * Author: Andrew-CT Chen <andrew-ct.chen@mediatek.com>
5 */
7 #include <linux/device.h>
8 #include <linux/module.h>
9 #include <linux/mod_devicetable.h>
10 #include <linux/io.h>
11 #include <linux/nvmem-provider.h>
12 #include <linux/platform_device.h>
14 struct mtk_efuse_priv {
15 void __iomem *base;
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 u32 *val = _val;
23 int i = 0, words = bytes / 4;
25 while (words--)
26 *val++ = readl(priv->base + reg + (i++ * 4));
28 return 0;
31 static int mtk_reg_write(void *context,
32 unsigned int reg, void *_val, size_t bytes)
34 struct mtk_efuse_priv *priv = context;
35 u32 *val = _val;
36 int i = 0, words = bytes / 4;
38 while (words--)
39 writel(*val++, priv->base + reg + (i++ * 4));
41 return 0;
44 static int mtk_efuse_probe(struct platform_device *pdev)
46 struct device *dev = &pdev->dev;
47 struct resource *res;
48 struct nvmem_device *nvmem;
49 struct nvmem_config econfig = {};
50 struct mtk_efuse_priv *priv;
52 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
53 if (!priv)
54 return -ENOMEM;
56 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
57 priv->base = devm_ioremap_resource(dev, res);
58 if (IS_ERR(priv->base))
59 return PTR_ERR(priv->base);
61 econfig.stride = 4;
62 econfig.word_size = 4;
63 econfig.reg_read = mtk_reg_read;
64 econfig.reg_write = mtk_reg_write;
65 econfig.size = resource_size(res);
66 econfig.priv = priv;
67 econfig.dev = dev;
68 nvmem = devm_nvmem_register(dev, &econfig);
70 return PTR_ERR_OR_ZERO(nvmem);
73 static const struct of_device_id mtk_efuse_of_match[] = {
74 { .compatible = "mediatek,mt8173-efuse",},
75 { .compatible = "mediatek,efuse",},
76 {/* sentinel */},
78 MODULE_DEVICE_TABLE(of, mtk_efuse_of_match);
80 static struct platform_driver mtk_efuse_driver = {
81 .probe = mtk_efuse_probe,
82 .driver = {
83 .name = "mediatek,efuse",
84 .of_match_table = mtk_efuse_of_match,
88 static int __init mtk_efuse_init(void)
90 int ret;
92 ret = platform_driver_register(&mtk_efuse_driver);
93 if (ret) {
94 pr_err("Failed to register efuse driver\n");
95 return ret;
98 return 0;
101 static void __exit mtk_efuse_exit(void)
103 return platform_driver_unregister(&mtk_efuse_driver);
106 subsys_initcall(mtk_efuse_init);
107 module_exit(mtk_efuse_exit);
109 MODULE_AUTHOR("Andrew-CT Chen <andrew-ct.chen@mediatek.com>");
110 MODULE_DESCRIPTION("Mediatek EFUSE driver");
111 MODULE_LICENSE("GPL v2");