diff options
author | Andrew-CT Chen <andrew-ct.chen@mediatek.com> | 2015-12-07 05:58:11 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-02-08 02:04:57 -0500 |
commit | 4c7e4fe3776693ee4554ca1b3a2c728c1f8f361a (patch) | |
tree | fdb824ce6e3b0f4c9635907b472fda635e622458 | |
parent | b3c9f95dec595d31cb79cceaf7ca85da21012eef (diff) |
nvmem: mediatek: Add Mediatek EFUSE driver
Add Mediatek EFUSE driver to access hardware data like
thermal sensor calibration or HDMI impedance.
Signed-off-by: Andrew-CT Chen <andrew-ct.chen@mediatek.com>
Reviewed-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/nvmem/Kconfig | 11 | ||||
-rw-r--r-- | drivers/nvmem/Makefile | 2 | ||||
-rw-r--r-- | drivers/nvmem/mtk-efuse.c | 89 |
3 files changed, 102 insertions, 0 deletions
diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 6ff1b5051ae1..5bd18cc1a69c 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig | |||
@@ -45,6 +45,17 @@ config NVMEM_MXS_OCOTP | |||
45 | This driver can also be built as a module. If so, the module | 45 | This driver can also be built as a module. If so, the module |
46 | will be called nvmem-mxs-ocotp. | 46 | will be called nvmem-mxs-ocotp. |
47 | 47 | ||
48 | config MTK_EFUSE | ||
49 | tristate "Mediatek SoCs EFUSE support" | ||
50 | depends on ARCH_MEDIATEK || COMPILE_TEST | ||
51 | select REGMAP_MMIO | ||
52 | help | ||
53 | This is a driver to access hardware related data like sensor | ||
54 | calibration, HDMI impedance etc. | ||
55 | |||
56 | This driver can also be built as a module. If so, the module | ||
57 | will be called efuse-mtk. | ||
58 | |||
48 | config QCOM_QFPROM | 59 | config QCOM_QFPROM |
49 | tristate "QCOM QFPROM Support" | 60 | tristate "QCOM QFPROM Support" |
50 | depends on ARCH_QCOM || COMPILE_TEST | 61 | depends on ARCH_QCOM || COMPILE_TEST |
diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index c14a55644c5f..45ab1ae08fa9 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile | |||
@@ -12,6 +12,8 @@ obj-$(CONFIG_NVMEM_LPC18XX_EEPROM) += nvmem_lpc18xx_eeprom.o | |||
12 | nvmem_lpc18xx_eeprom-y := lpc18xx_eeprom.o | 12 | nvmem_lpc18xx_eeprom-y := lpc18xx_eeprom.o |
13 | obj-$(CONFIG_NVMEM_MXS_OCOTP) += nvmem-mxs-ocotp.o | 13 | obj-$(CONFIG_NVMEM_MXS_OCOTP) += nvmem-mxs-ocotp.o |
14 | nvmem-mxs-ocotp-y := mxs-ocotp.o | 14 | nvmem-mxs-ocotp-y := mxs-ocotp.o |
15 | obj-$(CONFIG_MTK_EFUSE) += nvmem_mtk-efuse.o | ||
16 | nvmem_mtk-efuse-y := mtk-efuse.o | ||
15 | obj-$(CONFIG_QCOM_QFPROM) += nvmem_qfprom.o | 17 | obj-$(CONFIG_QCOM_QFPROM) += nvmem_qfprom.o |
16 | nvmem_qfprom-y := qfprom.o | 18 | nvmem_qfprom-y := qfprom.o |
17 | obj-$(CONFIG_ROCKCHIP_EFUSE) += nvmem_rockchip_efuse.o | 19 | obj-$(CONFIG_ROCKCHIP_EFUSE) += nvmem_rockchip_efuse.o |
diff --git a/drivers/nvmem/mtk-efuse.c b/drivers/nvmem/mtk-efuse.c new file mode 100644 index 000000000000..7b35f5b630cd --- /dev/null +++ b/drivers/nvmem/mtk-efuse.c | |||
@@ -0,0 +1,89 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2015 MediaTek Inc. | ||
3 | * Author: Andrew-CT Chen <andrew-ct.chen@mediatek.com> | ||
4 | * | ||
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. | ||
8 | * | ||
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. | ||
13 | */ | ||
14 | |||
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> | ||
20 | |||
21 | static struct regmap_config mtk_regmap_config = { | ||
22 | .reg_bits = 32, | ||
23 | .val_bits = 32, | ||
24 | .reg_stride = 4, | ||
25 | }; | ||
26 | |||
27 | static int mtk_efuse_probe(struct platform_device *pdev) | ||
28 | { | ||
29 | struct device *dev = &pdev->dev; | ||
30 | struct resource *res; | ||
31 | struct nvmem_device *nvmem; | ||
32 | struct nvmem_config *econfig; | ||
33 | struct regmap *regmap; | ||
34 | void __iomem *base; | ||
35 | |||
36 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
37 | base = devm_ioremap_resource(dev, res); | ||
38 | if (IS_ERR(base)) | ||
39 | return PTR_ERR(base); | ||
40 | |||
41 | econfig = devm_kzalloc(dev, sizeof(*econfig), GFP_KERNEL); | ||
42 | if (!econfig) | ||
43 | return -ENOMEM; | ||
44 | |||
45 | mtk_regmap_config.max_register = resource_size(res) - 1; | ||
46 | |||
47 | regmap = devm_regmap_init_mmio(dev, base, &mtk_regmap_config); | ||
48 | if (IS_ERR(regmap)) { | ||
49 | dev_err(dev, "regmap init failed\n"); | ||
50 | return PTR_ERR(regmap); | ||
51 | } | ||
52 | |||
53 | econfig->dev = dev; | ||
54 | econfig->owner = THIS_MODULE; | ||
55 | nvmem = nvmem_register(econfig); | ||
56 | if (IS_ERR(nvmem)) | ||
57 | return PTR_ERR(nvmem); | ||
58 | |||
59 | platform_set_drvdata(pdev, nvmem); | ||
60 | |||
61 | return 0; | ||
62 | } | ||
63 | |||
64 | static int mtk_efuse_remove(struct platform_device *pdev) | ||
65 | { | ||
66 | struct nvmem_device *nvmem = platform_get_drvdata(pdev); | ||
67 | |||
68 | return nvmem_unregister(nvmem); | ||
69 | } | ||
70 | |||
71 | static const struct of_device_id mtk_efuse_of_match[] = { | ||
72 | { .compatible = "mediatek,mt8173-efuse",}, | ||
73 | { .compatible = "mediatek,efuse",}, | ||
74 | {/* sentinel */}, | ||
75 | }; | ||
76 | MODULE_DEVICE_TABLE(of, mtk_efuse_of_match); | ||
77 | |||
78 | static struct platform_driver mtk_efuse_driver = { | ||
79 | .probe = mtk_efuse_probe, | ||
80 | .remove = mtk_efuse_remove, | ||
81 | .driver = { | ||
82 | .name = "mediatek,efuse", | ||
83 | .of_match_table = mtk_efuse_of_match, | ||
84 | }, | ||
85 | }; | ||
86 | module_platform_driver(mtk_efuse_driver); | ||
87 | MODULE_AUTHOR("Andrew-CT Chen <andrew-ct.chen@mediatek.com>"); | ||
88 | MODULE_DESCRIPTION("Mediatek EFUSE driver"); | ||
89 | MODULE_LICENSE("GPL v2"); | ||