1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2021 Rafał Miłecki <rafal@milecki.pl>
7 #include <linux/mod_devicetable.h>
8 #include <linux/module.h>
9 #include <linux/nvmem-provider.h>
10 #include <linux/platform_device.h>
17 static int brcm_nvram_read(void *context, unsigned int offset, void *val,
20 struct brcm_nvram *priv = context;
24 *dst++ = readb(priv->base + offset++);
29 static int brcm_nvram_probe(struct platform_device *pdev)
31 struct nvmem_config config = {
33 .reg_read = brcm_nvram_read,
35 struct device *dev = &pdev->dev;
37 struct brcm_nvram *priv;
39 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
44 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
45 priv->base = devm_ioremap_resource(dev, res);
46 if (IS_ERR(priv->base))
47 return PTR_ERR(priv->base);
51 config.size = resource_size(res);
53 return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &config));
56 static const struct of_device_id brcm_nvram_of_match_table[] = {
57 { .compatible = "brcm,nvram", },
61 static struct platform_driver brcm_nvram_driver = {
62 .probe = brcm_nvram_probe,
65 .of_match_table = brcm_nvram_of_match_table,
69 static int __init brcm_nvram_init(void)
71 return platform_driver_register(&brcm_nvram_driver);
74 subsys_initcall_sync(brcm_nvram_init);
76 MODULE_AUTHOR("Rafał Miłecki");
77 MODULE_LICENSE("GPL");
78 MODULE_DEVICE_TABLE(of, brcm_nvram_of_match_table);