net: DCB: Validate DCB_ATTR_DCB_BUFFER argument
[linux/fpc-iii.git] / drivers / nvmem / zynqmp_nvmem.c
blob5893543918c8dc1d570b0b8ce743536c8b5c95b0
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2019 Xilinx, Inc.
4 */
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>
12 #define SILICON_REVISION_MASK 0xF
14 struct zynqmp_nvmem_data {
15 struct device *dev;
16 struct nvmem_device *nvmem;
19 static const struct zynqmp_eemi_ops *eemi_ops;
21 static int zynqmp_nvmem_read(void *context, unsigned int offset,
22 void *val, size_t bytes)
24 int ret;
25 int idcode, version;
26 struct zynqmp_nvmem_data *priv = context;
28 if (!eemi_ops->get_chipid)
29 return -ENXIO;
31 ret = eemi_ops->get_chipid(&idcode, &version);
32 if (ret < 0)
33 return ret;
35 dev_dbg(priv->dev, "Read chipid val %x %x\n", idcode, version);
36 *(int *)val = version & SILICON_REVISION_MASK;
38 return 0;
41 static struct nvmem_config econfig = {
42 .name = "zynqmp-nvmem",
43 .owner = THIS_MODULE,
44 .word_size = 1,
45 .size = 1,
46 .read_only = true,
49 static const struct of_device_id zynqmp_nvmem_match[] = {
50 { .compatible = "xlnx,zynqmp-nvmem-fw", },
51 { /* sentinel */ },
53 MODULE_DEVICE_TABLE(of, zynqmp_nvmem_match);
55 static int zynqmp_nvmem_probe(struct platform_device *pdev)
57 struct device *dev = &pdev->dev;
58 struct zynqmp_nvmem_data *priv;
60 priv = devm_kzalloc(dev, sizeof(struct zynqmp_nvmem_data), GFP_KERNEL);
61 if (!priv)
62 return -ENOMEM;
64 eemi_ops = zynqmp_pm_get_eemi_ops();
65 if (IS_ERR(eemi_ops))
66 return PTR_ERR(eemi_ops);
68 priv->dev = dev;
69 econfig.dev = dev;
70 econfig.reg_read = zynqmp_nvmem_read;
71 econfig.priv = priv;
73 priv->nvmem = devm_nvmem_register(dev, &econfig);
75 return PTR_ERR_OR_ZERO(priv->nvmem);
78 static struct platform_driver zynqmp_nvmem_driver = {
79 .probe = zynqmp_nvmem_probe,
80 .driver = {
81 .name = "zynqmp-nvmem",
82 .of_match_table = zynqmp_nvmem_match,
86 module_platform_driver(zynqmp_nvmem_driver);
88 MODULE_AUTHOR("Michal Simek <michal.simek@xilinx.com>, Nava kishore Manne <navam@xilinx.com>");
89 MODULE_DESCRIPTION("ZynqMP NVMEM driver");
90 MODULE_LICENSE("GPL");