Warning: That file was not part of the compilation database. It may have many parsing errors.

1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2019 Xilinx, Inc.
4 */
5
6#include <linux/module.h>
7#include <linux/nvmem-provider.h>
8#include <linux/of.h>
9#include <linux/platform_device.h>
10#include <linux/firmware/xlnx-zynqmp.h>
11
12#define SILICON_REVISION_MASK 0xF
13
14struct zynqmp_nvmem_data {
15 struct device *dev;
16 struct nvmem_device *nvmem;
17};
18
19static int zynqmp_nvmem_read(void *context, unsigned int offset,
20 void *val, size_t bytes)
21{
22 int ret;
23 int idcode, version;
24 struct zynqmp_nvmem_data *priv = context;
25
26 const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
27
28 if (!eemi_ops || !eemi_ops->get_chipid)
29 return -ENXIO;
30
31 ret = eemi_ops->get_chipid(&idcode, &version);
32 if (ret < 0)
33 return ret;
34
35 dev_dbg(priv->dev, "Read chipid val %x %x\n", idcode, version);
36 *(int *)val = version & SILICON_REVISION_MASK;
37
38 return 0;
39}
40
41static struct nvmem_config econfig = {
42 .name = "zynqmp-nvmem",
43 .owner = THIS_MODULE,
44 .word_size = 1,
45 .size = 1,
46 .read_only = true,
47};
48
49static const struct of_device_id zynqmp_nvmem_match[] = {
50 { .compatible = "xlnx,zynqmp-nvmem-fw", },
51 { /* sentinel */ },
52};
53MODULE_DEVICE_TABLE(of, zynqmp_nvmem_match);
54
55static int zynqmp_nvmem_probe(struct platform_device *pdev)
56{
57 struct device *dev = &pdev->dev;
58 struct zynqmp_nvmem_data *priv;
59
60 priv = devm_kzalloc(dev, sizeof(struct zynqmp_nvmem_data), GFP_KERNEL);
61 if (!priv)
62 return -ENOMEM;
63
64 priv->dev = dev;
65 econfig.dev = dev;
66 econfig.reg_read = zynqmp_nvmem_read;
67 econfig.priv = priv;
68
69 priv->nvmem = devm_nvmem_register(dev, &econfig);
70
71 return PTR_ERR_OR_ZERO(priv->nvmem);
72}
73
74static struct platform_driver zynqmp_nvmem_driver = {
75 .probe = zynqmp_nvmem_probe,
76 .driver = {
77 .name = "zynqmp-nvmem",
78 .of_match_table = zynqmp_nvmem_match,
79 },
80};
81
82module_platform_driver(zynqmp_nvmem_driver);
83
84MODULE_AUTHOR("Michal Simek <michal.simek@xilinx.com>, Nava kishore Manne <navam@xilinx.com>");
85MODULE_DESCRIPTION("ZynqMP NVMEM driver");
86MODULE_LICENSE("GPL");
87

Warning: That file was not part of the compilation database. It may have many parsing errors.