Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / nvmem / meson-efuse.c
blobd7f9ac99a212f15ed266e9f18f4b49ad62cc255d
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Amlogic Meson GX eFuse Driver
5 * Copyright (c) 2016 Endless Computers, Inc.
6 * Author: Carlo Caione <carlo@endlessm.com>
7 */
9 #include <linux/clk.h>
10 #include <linux/module.h>
11 #include <linux/nvmem-provider.h>
12 #include <linux/of.h>
13 #include <linux/platform_device.h>
15 #include <linux/firmware/meson/meson_sm.h>
17 static int meson_efuse_read(void *context, unsigned int offset,
18 void *val, size_t bytes)
20 struct meson_sm_firmware *fw = context;
21 int ret;
23 ret = meson_sm_call_read(fw, (u8 *)val, bytes, SM_EFUSE_READ, offset,
24 bytes, 0, 0, 0);
26 return ret < 0 ? ret : 0;
29 static int meson_efuse_write(void *context, unsigned int offset,
30 void *val, size_t bytes)
32 struct meson_sm_firmware *fw = context;
33 int ret;
35 ret = meson_sm_call_write(fw, (u8 *)val, bytes, SM_EFUSE_WRITE, offset,
36 bytes, 0, 0, 0);
38 return ret < 0 ? ret : 0;
41 static const struct of_device_id meson_efuse_match[] = {
42 { .compatible = "amlogic,meson-gxbb-efuse", },
43 { /* sentinel */ },
45 MODULE_DEVICE_TABLE(of, meson_efuse_match);
47 static int meson_efuse_probe(struct platform_device *pdev)
49 struct device *dev = &pdev->dev;
50 struct meson_sm_firmware *fw;
51 struct nvmem_device *nvmem;
52 struct nvmem_config *econfig;
53 struct clk *clk;
54 unsigned int size;
55 struct device_node *sm_np __free(device_node) =
56 of_parse_phandle(pdev->dev.of_node, "secure-monitor", 0);
58 if (!sm_np) {
59 dev_err(&pdev->dev, "no secure-monitor node\n");
60 return -ENODEV;
63 fw = meson_sm_get(sm_np);
64 if (!fw)
65 return -EPROBE_DEFER;
67 clk = devm_clk_get_enabled(dev, NULL);
68 if (IS_ERR(clk))
69 return dev_err_probe(dev, PTR_ERR(clk), "failed to get efuse gate");
71 if (meson_sm_call(fw, SM_EFUSE_USER_MAX, &size, 0, 0, 0, 0, 0) < 0) {
72 dev_err(dev, "failed to get max user");
73 return -EINVAL;
76 econfig = devm_kzalloc(dev, sizeof(*econfig), GFP_KERNEL);
77 if (!econfig)
78 return -ENOMEM;
80 econfig->dev = dev;
81 econfig->name = dev_name(dev);
82 econfig->add_legacy_fixed_of_cells = true;
83 econfig->stride = 1;
84 econfig->word_size = 1;
85 econfig->reg_read = meson_efuse_read;
86 econfig->reg_write = meson_efuse_write;
87 econfig->size = size;
88 econfig->priv = fw;
90 nvmem = devm_nvmem_register(&pdev->dev, econfig);
92 return PTR_ERR_OR_ZERO(nvmem);
95 static struct platform_driver meson_efuse_driver = {
96 .probe = meson_efuse_probe,
97 .driver = {
98 .name = "meson-efuse",
99 .of_match_table = meson_efuse_match,
103 module_platform_driver(meson_efuse_driver);
105 MODULE_AUTHOR("Carlo Caione <carlo@endlessm.com>");
106 MODULE_DESCRIPTION("Amlogic Meson GX NVMEM driver");
107 MODULE_LICENSE("GPL v2");