0001
0002
0003
0004
0005
0006
0007 #include <linux/device.h>
0008 #include <linux/module.h>
0009 #include <linux/mod_devicetable.h>
0010 #include <linux/io.h>
0011 #include <linux/nvmem-provider.h>
0012 #include <linux/platform_device.h>
0013
0014 struct mtk_efuse_priv {
0015 void __iomem *base;
0016 };
0017
0018 static int mtk_reg_read(void *context,
0019 unsigned int reg, void *_val, size_t bytes)
0020 {
0021 struct mtk_efuse_priv *priv = context;
0022 void __iomem *addr = priv->base + reg;
0023 u8 *val = _val;
0024 int i;
0025
0026 for (i = 0; i < bytes; i++, val++)
0027 *val = readb(addr + i);
0028
0029 return 0;
0030 }
0031
0032 static int mtk_efuse_probe(struct platform_device *pdev)
0033 {
0034 struct device *dev = &pdev->dev;
0035 struct resource *res;
0036 struct nvmem_device *nvmem;
0037 struct nvmem_config econfig = {};
0038 struct mtk_efuse_priv *priv;
0039
0040 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
0041 if (!priv)
0042 return -ENOMEM;
0043
0044 priv->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
0045 if (IS_ERR(priv->base))
0046 return PTR_ERR(priv->base);
0047
0048 econfig.stride = 1;
0049 econfig.word_size = 1;
0050 econfig.reg_read = mtk_reg_read;
0051 econfig.size = resource_size(res);
0052 econfig.priv = priv;
0053 econfig.dev = dev;
0054 nvmem = devm_nvmem_register(dev, &econfig);
0055
0056 return PTR_ERR_OR_ZERO(nvmem);
0057 }
0058
0059 static const struct of_device_id mtk_efuse_of_match[] = {
0060 { .compatible = "mediatek,mt8173-efuse",},
0061 { .compatible = "mediatek,efuse",},
0062 {},
0063 };
0064 MODULE_DEVICE_TABLE(of, mtk_efuse_of_match);
0065
0066 static struct platform_driver mtk_efuse_driver = {
0067 .probe = mtk_efuse_probe,
0068 .driver = {
0069 .name = "mediatek,efuse",
0070 .of_match_table = mtk_efuse_of_match,
0071 },
0072 };
0073
0074 static int __init mtk_efuse_init(void)
0075 {
0076 int ret;
0077
0078 ret = platform_driver_register(&mtk_efuse_driver);
0079 if (ret) {
0080 pr_err("Failed to register efuse driver\n");
0081 return ret;
0082 }
0083
0084 return 0;
0085 }
0086
0087 static void __exit mtk_efuse_exit(void)
0088 {
0089 return platform_driver_unregister(&mtk_efuse_driver);
0090 }
0091
0092 subsys_initcall(mtk_efuse_init);
0093 module_exit(mtk_efuse_exit);
0094
0095 MODULE_AUTHOR("Andrew-CT Chen <andrew-ct.chen@mediatek.com>");
0096 MODULE_DESCRIPTION("Mediatek EFUSE driver");
0097 MODULE_LICENSE("GPL v2");