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 = {
40 .reg_read = apple_efuses_read,
41 .stride = sizeof(u32),
42 .word_size = sizeof(u32),
43 .name = "apple_efuses_nvmem",
44 .id = NVMEM_DEVID_AUTO,
48 priv = devm_kzalloc(config.dev, sizeof(*priv), GFP_KERNEL);
52 priv->fuses = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
53 if (IS_ERR(priv->fuses))
54 return PTR_ERR(priv->fuses);
57 config.size = resource_size(res);
59 return PTR_ERR_OR_ZERO(devm_nvmem_register(config.dev, &config));
62 static const struct of_device_id apple_efuses_of_match[] = {
63 { .compatible = "apple,efuses", },
67 MODULE_DEVICE_TABLE(of, apple_efuses_of_match);
69 static struct platform_driver apple_efuses_driver = {
71 .name = "apple_efuses",
72 .of_match_table = apple_efuses_of_match,
74 .probe = apple_efuses_probe,
77 module_platform_driver(apple_efuses_driver);
79 MODULE_AUTHOR("Sven Peter <sven@svenpeter.dev>");
80 MODULE_LICENSE("GPL");