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/nvmem-provider.h>
18 #include <linux/platform_device.h>
19 #include <linux/regmap.h>
21 static struct regmap_config mtk_regmap_config
= {
27 static int mtk_efuse_probe(struct platform_device
*pdev
)
29 struct device
*dev
= &pdev
->dev
;
31 struct nvmem_device
*nvmem
;
32 struct nvmem_config
*econfig
;
33 struct regmap
*regmap
;
36 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
37 base
= devm_ioremap_resource(dev
, res
);
41 econfig
= devm_kzalloc(dev
, sizeof(*econfig
), GFP_KERNEL
);
45 mtk_regmap_config
.max_register
= resource_size(res
) - 1;
47 regmap
= devm_regmap_init_mmio(dev
, base
, &mtk_regmap_config
);
49 dev_err(dev
, "regmap init failed\n");
50 return PTR_ERR(regmap
);
54 econfig
->owner
= THIS_MODULE
;
55 nvmem
= nvmem_register(econfig
);
57 return PTR_ERR(nvmem
);
59 platform_set_drvdata(pdev
, nvmem
);
64 static int mtk_efuse_remove(struct platform_device
*pdev
)
66 struct nvmem_device
*nvmem
= platform_get_drvdata(pdev
);
68 return nvmem_unregister(nvmem
);
71 static const struct of_device_id mtk_efuse_of_match
[] = {
72 { .compatible
= "mediatek,mt8173-efuse",},
73 { .compatible
= "mediatek,efuse",},
76 MODULE_DEVICE_TABLE(of
, mtk_efuse_of_match
);
78 static struct platform_driver mtk_efuse_driver
= {
79 .probe
= mtk_efuse_probe
,
80 .remove
= mtk_efuse_remove
,
82 .name
= "mediatek,efuse",
83 .of_match_table
= mtk_efuse_of_match
,
87 static int __init
mtk_efuse_init(void)
91 ret
= platform_driver_register(&mtk_efuse_driver
);
93 pr_err("Failed to register efuse driver\n");
100 static void __exit
mtk_efuse_exit(void)
102 return platform_driver_unregister(&mtk_efuse_driver
);
105 subsys_initcall(mtk_efuse_init
);
106 module_exit(mtk_efuse_exit
);
108 MODULE_AUTHOR("Andrew-CT Chen <andrew-ct.chen@mediatek.com>");
109 MODULE_DESCRIPTION("Mediatek EFUSE driver");
110 MODULE_LICENSE("GPL v2");