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
17 #include <linux/module.h>
18 #include <linux/nvmem-provider.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
)
30 ret
= meson_sm_call_read(buf
, SM_EFUSE_READ
, offset
,
38 static struct nvmem_config econfig
= {
39 .name
= "meson-efuse",
46 static const struct of_device_id meson_efuse_match
[] = {
47 { .compatible
= "amlogic,meson-gxbb-efuse", },
50 MODULE_DEVICE_TABLE(of
, meson_efuse_match
);
52 static int meson_efuse_probe(struct platform_device
*pdev
)
54 struct nvmem_device
*nvmem
;
57 if (meson_sm_call(SM_EFUSE_USER_MAX
, &size
, 0, 0, 0, 0, 0) < 0)
60 econfig
.dev
= &pdev
->dev
;
61 econfig
.reg_read
= meson_efuse_read
;
64 nvmem
= nvmem_register(&econfig
);
66 return PTR_ERR(nvmem
);
68 platform_set_drvdata(pdev
, nvmem
);
73 static int meson_efuse_remove(struct platform_device
*pdev
)
75 struct nvmem_device
*nvmem
= platform_get_drvdata(pdev
);
77 return nvmem_unregister(nvmem
);
80 static struct platform_driver meson_efuse_driver
= {
81 .probe
= meson_efuse_probe
,
82 .remove
= meson_efuse_remove
,
84 .name
= "meson-efuse",
85 .of_match_table
= meson_efuse_match
,
89 module_platform_driver(meson_efuse_driver
);
91 MODULE_AUTHOR("Carlo Caione <carlo@endlessm.com>");
92 MODULE_DESCRIPTION("Amlogic Meson NVMEM driver");
93 MODULE_LICENSE("GPL v2");