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
;
22 return meson_sm_call_read(fw
, (u8
*)val
, bytes
, SM_EFUSE_READ
, offset
,
26 static int meson_efuse_write(void *context
, unsigned int offset
,
27 void *val
, size_t bytes
)
29 struct meson_sm_firmware
*fw
= context
;
31 return meson_sm_call_write(fw
, (u8
*)val
, bytes
, SM_EFUSE_WRITE
, offset
,
35 static const struct of_device_id meson_efuse_match
[] = {
36 { .compatible
= "amlogic,meson-gxbb-efuse", },
39 MODULE_DEVICE_TABLE(of
, meson_efuse_match
);
41 static int meson_efuse_probe(struct platform_device
*pdev
)
43 struct device
*dev
= &pdev
->dev
;
44 struct meson_sm_firmware
*fw
;
45 struct device_node
*sm_np
;
46 struct nvmem_device
*nvmem
;
47 struct nvmem_config
*econfig
;
52 sm_np
= of_parse_phandle(pdev
->dev
.of_node
, "secure-monitor", 0);
54 dev_err(&pdev
->dev
, "no secure-monitor node\n");
58 fw
= meson_sm_get(sm_np
);
63 clk
= devm_clk_get(dev
, NULL
);
66 if (ret
!= -EPROBE_DEFER
)
67 dev_err(dev
, "failed to get efuse gate");
71 ret
= clk_prepare_enable(clk
);
73 dev_err(dev
, "failed to enable gate");
77 ret
= devm_add_action_or_reset(dev
,
78 (void(*)(void *))clk_disable_unprepare
,
81 dev_err(dev
, "failed to add disable callback");
85 if (meson_sm_call(fw
, SM_EFUSE_USER_MAX
, &size
, 0, 0, 0, 0, 0) < 0) {
86 dev_err(dev
, "failed to get max user");
90 econfig
= devm_kzalloc(dev
, sizeof(*econfig
), GFP_KERNEL
);
95 econfig
->name
= dev_name(dev
);
97 econfig
->word_size
= 1;
98 econfig
->reg_read
= meson_efuse_read
;
99 econfig
->reg_write
= meson_efuse_write
;
100 econfig
->size
= size
;
103 nvmem
= devm_nvmem_register(&pdev
->dev
, econfig
);
105 return PTR_ERR_OR_ZERO(nvmem
);
108 static struct platform_driver meson_efuse_driver
= {
109 .probe
= meson_efuse_probe
,
111 .name
= "meson-efuse",
112 .of_match_table
= meson_efuse_match
,
116 module_platform_driver(meson_efuse_driver
);
118 MODULE_AUTHOR("Carlo Caione <carlo@endlessm.com>");
119 MODULE_DESCRIPTION("Amlogic Meson GX NVMEM driver");
120 MODULE_LICENSE("GPL v2");