aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlo Caione <carlo@endlessm.com>2016-08-27 09:43:46 -0400
committerKevin Hilman <khilman@baylibre.com>2016-09-01 17:24:21 -0400
commitad855eae6caf0d1dd17bce5bcd8e07759adc9903 (patch)
tree7f2ae4062d852b80d1a5a8d0c0367ee23ba5a83e
parent2c4ddb215521d5dfb30f72123ef966ac6bdd16d7 (diff)
nvmem: amlogic: Add Amlogic Meson EFUSE driver
Add Amlogic EFUSE driver to access hardware data like ethernet address, serial number or IDs. Acked-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Signed-off-by: Carlo Caione <carlo@endlessm.com> Signed-off-by: Kevin Hilman <khilman@baylibre.com>
-rw-r--r--drivers/nvmem/Kconfig10
-rw-r--r--drivers/nvmem/Makefile2
-rw-r--r--drivers/nvmem/meson-efuse.c93
3 files changed, 105 insertions, 0 deletions
diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index f550c4596a7a..ba140eaee5c8 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -101,4 +101,14 @@ config NVMEM_VF610_OCOTP
101 This driver can also be build as a module. If so, the module will 101 This driver can also be build as a module. If so, the module will
102 be called nvmem-vf610-ocotp. 102 be called nvmem-vf610-ocotp.
103 103
104config MESON_EFUSE
105 tristate "Amlogic eFuse Support"
106 depends on (ARCH_MESON || COMPILE_TEST) && MESON_SM
107 help
108 This is a driver to retrieve specific values from the eFuse found on
109 the Amlogic Meson SoCs.
110
111 This driver can also be built as a module. If so, the module
112 will be called nvmem_meson_efuse.
113
104endif 114endif
diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
index 45ab1ae08fa9..8f942a0cdaec 100644
--- a/drivers/nvmem/Makefile
+++ b/drivers/nvmem/Makefile
@@ -22,3 +22,5 @@ obj-$(CONFIG_NVMEM_SUNXI_SID) += nvmem_sunxi_sid.o
22nvmem_sunxi_sid-y := sunxi_sid.o 22nvmem_sunxi_sid-y := sunxi_sid.o
23obj-$(CONFIG_NVMEM_VF610_OCOTP) += nvmem-vf610-ocotp.o 23obj-$(CONFIG_NVMEM_VF610_OCOTP) += nvmem-vf610-ocotp.o
24nvmem-vf610-ocotp-y := vf610-ocotp.o 24nvmem-vf610-ocotp-y := vf610-ocotp.o
25obj-$(CONFIG_MESON_EFUSE) += nvmem_meson_efuse.o
26nvmem_meson_efuse-y := meson-efuse.o
diff --git a/drivers/nvmem/meson-efuse.c b/drivers/nvmem/meson-efuse.c
new file mode 100644
index 000000000000..f207c3b10482
--- /dev/null
+++ b/drivers/nvmem/meson-efuse.c
@@ -0,0 +1,93 @@
1/*
2 * Amlogic eFuse Driver
3 *
4 * Copyright (c) 2016 Endless Computers, Inc.
5 * Author: Carlo Caione <carlo@endlessm.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 */
16
17#include <linux/module.h>
18#include <linux/nvmem-provider.h>
19#include <linux/of.h>
20#include <linux/platform_device.h>
21
22#include <linux/firmware/meson/meson_sm.h>
23
24static int meson_efuse_read(void *context, unsigned int offset,
25 void *val, size_t bytes)
26{
27 u8 *buf = val;
28 int ret;
29
30 ret = meson_sm_call_read(buf, SM_EFUSE_READ, offset,
31 bytes, 0, 0, 0);
32 if (ret < 0)
33 return ret;
34
35 return 0;
36}
37
38static struct nvmem_config econfig = {
39 .name = "meson-efuse",
40 .owner = THIS_MODULE,
41 .stride = 1,
42 .word_size = 1,
43 .read_only = true,
44};
45
46static const struct of_device_id meson_efuse_match[] = {
47 { .compatible = "amlogic,meson-gxbb-efuse", },
48 { /* sentinel */ },
49};
50MODULE_DEVICE_TABLE(of, meson_efuse_match);
51
52static int meson_efuse_probe(struct platform_device *pdev)
53{
54 struct nvmem_device *nvmem;
55 unsigned int size;
56
57 if (meson_sm_call(SM_EFUSE_USER_MAX, &size, 0, 0, 0, 0, 0) < 0)
58 return -EINVAL;
59
60 econfig.dev = &pdev->dev;
61 econfig.reg_read = meson_efuse_read;
62 econfig.size = size;
63
64 nvmem = nvmem_register(&econfig);
65 if (IS_ERR(nvmem))
66 return PTR_ERR(nvmem);
67
68 platform_set_drvdata(pdev, nvmem);
69
70 return 0;
71}
72
73static int meson_efuse_remove(struct platform_device *pdev)
74{
75 struct nvmem_device *nvmem = platform_get_drvdata(pdev);
76
77 return nvmem_unregister(nvmem);
78}
79
80static struct platform_driver meson_efuse_driver = {
81 .probe = meson_efuse_probe,
82 .remove = meson_efuse_remove,
83 .driver = {
84 .name = "meson-efuse",
85 .of_match_table = meson_efuse_match,
86 },
87};
88
89module_platform_driver(meson_efuse_driver);
90
91MODULE_AUTHOR("Carlo Caione <carlo@endlessm.com>");
92MODULE_DESCRIPTION("Amlogic Meson NVMEM driver");
93MODULE_LICENSE("GPL v2");