1 // SPDX-License-Identifier: GPL-2.0-only
3 * Amlogic Meson GX eFuse Driver
5 * Copyright (c) 2016 Endless Computers, Inc.
6 * Author: Carlo Caione <carlo@endlessm.com>
10 #include <linux/module.h>
11 #include <linux/nvmem-provider.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
;
23 ret
= meson_sm_call_read(fw
, (u8
*)val
, bytes
, SM_EFUSE_READ
, offset
,
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
;
35 ret
= meson_sm_call_write(fw
, (u8
*)val
, bytes
, SM_EFUSE_WRITE
, offset
,
38 return ret
< 0 ? ret
: 0;
41 static const struct of_device_id meson_efuse_match
[] = {
42 { .compatible
= "amlogic,meson-gxbb-efuse", },
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
;
55 struct device_node
*sm_np
__free(device_node
) =
56 of_parse_phandle(pdev
->dev
.of_node
, "secure-monitor", 0);
59 dev_err(&pdev
->dev
, "no secure-monitor node\n");
63 fw
= meson_sm_get(sm_np
);
67 clk
= devm_clk_get_enabled(dev
, NULL
);
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");
76 econfig
= devm_kzalloc(dev
, sizeof(*econfig
), GFP_KERNEL
);
81 econfig
->name
= dev_name(dev
);
82 econfig
->add_legacy_fixed_of_cells
= true;
84 econfig
->word_size
= 1;
85 econfig
->reg_read
= meson_efuse_read
;
86 econfig
->reg_write
= meson_efuse_write
;
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
,
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");