1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2019 Xilinx, Inc.
6 #include <linux/module.h>
7 #include <linux/nvmem-provider.h>
9 #include <linux/platform_device.h>
10 #include <linux/firmware/xlnx-zynqmp.h>
12 #define SILICON_REVISION_MASK 0xF
14 struct zynqmp_nvmem_data {
16 struct nvmem_device *nvmem;
19 static int zynqmp_nvmem_read(void *context, unsigned int offset,
20 void *val, size_t bytes)
24 struct zynqmp_nvmem_data *priv = context;
26 ret = zynqmp_pm_get_chipid(&idcode, &version);
30 dev_dbg(priv->dev, "Read chipid val %x %x\n", idcode, version);
31 *(int *)val = version & SILICON_REVISION_MASK;
36 static struct nvmem_config econfig = {
37 .name = "zynqmp-nvmem",
44 static const struct of_device_id zynqmp_nvmem_match[] = {
45 { .compatible = "xlnx,zynqmp-nvmem-fw", },
48 MODULE_DEVICE_TABLE(of, zynqmp_nvmem_match);
50 static int zynqmp_nvmem_probe(struct platform_device *pdev)
52 struct device *dev = &pdev->dev;
53 struct zynqmp_nvmem_data *priv;
55 priv = devm_kzalloc(dev, sizeof(struct zynqmp_nvmem_data), GFP_KERNEL);
61 econfig.reg_read = zynqmp_nvmem_read;
64 priv->nvmem = devm_nvmem_register(dev, &econfig);
66 return PTR_ERR_OR_ZERO(priv->nvmem);
69 static struct platform_driver zynqmp_nvmem_driver = {
70 .probe = zynqmp_nvmem_probe,
72 .name = "zynqmp-nvmem",
73 .of_match_table = zynqmp_nvmem_match,
77 module_platform_driver(zynqmp_nvmem_driver);
79 MODULE_AUTHOR("Michal Simek <michal.simek@xilinx.com>, Nava kishore Manne <navam@xilinx.com>");
80 MODULE_DESCRIPTION("ZynqMP NVMEM driver");
81 MODULE_LICENSE("GPL");