1 // SPDX-License-Identifier: GPL-2.0-only
3 * Apple SoC eFuse driver
5 * Copyright (C) The Asahi Linux Contributors
9 #include <linux/mod_devicetable.h>
10 #include <linux/module.h>
11 #include <linux/nvmem-provider.h>
12 #include <linux/platform_device.h>
14 struct apple_efuses_priv
{
18 static int apple_efuses_read(void *context
, unsigned int offset
, void *val
,
21 struct apple_efuses_priv
*priv
= context
;
24 while (bytes
>= sizeof(u32
)) {
25 *dst
++ = readl_relaxed(priv
->fuses
+ offset
);
27 offset
+= sizeof(u32
);
33 static int apple_efuses_probe(struct platform_device
*pdev
)
35 struct apple_efuses_priv
*priv
;
37 struct nvmem_config config
= {
39 .add_legacy_fixed_of_cells
= true,
41 .reg_read
= apple_efuses_read
,
42 .stride
= sizeof(u32
),
43 .word_size
= sizeof(u32
),
44 .name
= "apple_efuses_nvmem",
45 .id
= NVMEM_DEVID_AUTO
,
49 priv
= devm_kzalloc(config
.dev
, sizeof(*priv
), GFP_KERNEL
);
53 priv
->fuses
= devm_platform_get_and_ioremap_resource(pdev
, 0, &res
);
54 if (IS_ERR(priv
->fuses
))
55 return PTR_ERR(priv
->fuses
);
58 config
.size
= resource_size(res
);
60 return PTR_ERR_OR_ZERO(devm_nvmem_register(config
.dev
, &config
));
63 static const struct of_device_id apple_efuses_of_match
[] = {
64 { .compatible
= "apple,efuses", },
68 MODULE_DEVICE_TABLE(of
, apple_efuses_of_match
);
70 static struct platform_driver apple_efuses_driver
= {
72 .name
= "apple_efuses",
73 .of_match_table
= apple_efuses_of_match
,
75 .probe
= apple_efuses_probe
,
78 module_platform_driver(apple_efuses_driver
);
80 MODULE_AUTHOR("Sven Peter <sven@svenpeter.dev>");
81 MODULE_DESCRIPTION("Apple SoC eFuse driver");
82 MODULE_LICENSE("GPL");