2 * Copyright (c) 2015 MediaTek Inc.
3 * Author: Andrew-CT Chen <andrew-ct.chen@mediatek.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <linux/device.h>
16 #include <linux/module.h>
17 #include <linux/mod_devicetable.h>
19 #include <linux/nvmem-provider.h>
20 #include <linux/platform_device.h>
22 struct mtk_efuse_priv
{
26 static int mtk_reg_read(void *context
,
27 unsigned int reg
, void *_val
, size_t bytes
)
29 struct mtk_efuse_priv
*priv
= context
;
31 int i
= 0, words
= bytes
/ 4;
34 *val
++ = readl(priv
->base
+ reg
+ (i
++ * 4));
39 static int mtk_reg_write(void *context
,
40 unsigned int reg
, void *_val
, size_t bytes
)
42 struct mtk_efuse_priv
*priv
= context
;
44 int i
= 0, words
= bytes
/ 4;
47 writel(*val
++, priv
->base
+ reg
+ (i
++ * 4));
52 static int mtk_efuse_probe(struct platform_device
*pdev
)
54 struct device
*dev
= &pdev
->dev
;
56 struct nvmem_device
*nvmem
;
57 struct nvmem_config econfig
= {};
58 struct mtk_efuse_priv
*priv
;
60 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
64 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
65 priv
->base
= devm_ioremap_resource(dev
, res
);
66 if (IS_ERR(priv
->base
))
67 return PTR_ERR(priv
->base
);
70 econfig
.word_size
= 4;
71 econfig
.reg_read
= mtk_reg_read
;
72 econfig
.reg_write
= mtk_reg_write
;
73 econfig
.size
= resource_size(res
);
76 nvmem
= devm_nvmem_register(dev
, &econfig
);
78 return PTR_ERR_OR_ZERO(nvmem
);
81 static const struct of_device_id mtk_efuse_of_match
[] = {
82 { .compatible
= "mediatek,mt8173-efuse",},
83 { .compatible
= "mediatek,efuse",},
86 MODULE_DEVICE_TABLE(of
, mtk_efuse_of_match
);
88 static struct platform_driver mtk_efuse_driver
= {
89 .probe
= mtk_efuse_probe
,
91 .name
= "mediatek,efuse",
92 .of_match_table
= mtk_efuse_of_match
,
96 static int __init
mtk_efuse_init(void)
100 ret
= platform_driver_register(&mtk_efuse_driver
);
102 pr_err("Failed to register efuse driver\n");
109 static void __exit
mtk_efuse_exit(void)
111 return platform_driver_unregister(&mtk_efuse_driver
);
114 subsys_initcall(mtk_efuse_init
);
115 module_exit(mtk_efuse_exit
);
117 MODULE_AUTHOR("Andrew-CT Chen <andrew-ct.chen@mediatek.com>");
118 MODULE_DESCRIPTION("Mediatek EFUSE driver");
119 MODULE_LICENSE("GPL v2");