Merge tag 'riscv-for-linus-4.15-rc2_cleanups' of git://git.kernel.org/pub/scm/linux...
[linux/fpc-iii.git] / drivers / nvmem / meson-efuse.c
bloba43c68f909373a03c173ed1f52c79ec55e713aeb
1 /*
2 * Amlogic Meson GX eFuse Driver
4 * Copyright (c) 2016 Endless Computers, Inc.
5 * Author: Carlo Caione <carlo@endlessm.com>
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.
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.
17 #include <linux/module.h>
18 #include <linux/nvmem-provider.h>
19 #include <linux/of.h>
20 #include <linux/platform_device.h>
22 #include <linux/firmware/meson/meson_sm.h>
24 static int meson_efuse_read(void *context, unsigned int offset,
25 void *val, size_t bytes)
27 u8 *buf = val;
28 int ret;
30 ret = meson_sm_call_read(buf, bytes, SM_EFUSE_READ, offset,
31 bytes, 0, 0, 0);
32 if (ret < 0)
33 return ret;
35 return 0;
38 static struct nvmem_config econfig = {
39 .name = "meson-efuse",
40 .stride = 1,
41 .word_size = 1,
42 .read_only = true,
45 static const struct of_device_id meson_efuse_match[] = {
46 { .compatible = "amlogic,meson-gxbb-efuse", },
47 { /* sentinel */ },
49 MODULE_DEVICE_TABLE(of, meson_efuse_match);
51 static int meson_efuse_probe(struct platform_device *pdev)
53 struct nvmem_device *nvmem;
54 unsigned int size;
56 if (meson_sm_call(SM_EFUSE_USER_MAX, &size, 0, 0, 0, 0, 0) < 0)
57 return -EINVAL;
59 econfig.dev = &pdev->dev;
60 econfig.reg_read = meson_efuse_read;
61 econfig.size = size;
63 nvmem = nvmem_register(&econfig);
64 if (IS_ERR(nvmem))
65 return PTR_ERR(nvmem);
67 platform_set_drvdata(pdev, nvmem);
69 return 0;
72 static int meson_efuse_remove(struct platform_device *pdev)
74 struct nvmem_device *nvmem = platform_get_drvdata(pdev);
76 return nvmem_unregister(nvmem);
79 static struct platform_driver meson_efuse_driver = {
80 .probe = meson_efuse_probe,
81 .remove = meson_efuse_remove,
82 .driver = {
83 .name = "meson-efuse",
84 .of_match_table = meson_efuse_match,
88 module_platform_driver(meson_efuse_driver);
90 MODULE_AUTHOR("Carlo Caione <carlo@endlessm.com>");
91 MODULE_DESCRIPTION("Amlogic Meson GX NVMEM driver");
92 MODULE_LICENSE("GPL v2");