]> rtime.felk.cvut.cz Git - zynq/linux.git/commitdiff
nvmem: zynqmp: Added zynqmp nvmem firmware driver
authorNava kishore Manne <nava.manne@xilinx.com>
Tue, 17 Jan 2017 10:45:55 +0000 (16:15 +0530)
committerMichal Simek <michal.simek@xilinx.com>
Tue, 24 Jan 2017 15:40:03 +0000 (16:40 +0100)
This patch adds zynqmp nvmem firmware driver to access the
SoC revision information from the hardware register.

Signed-off-by: Nava kishore Manne <navam@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
drivers/nvmem/Kconfig
drivers/nvmem/Makefile
drivers/nvmem/zynqmp_nvmem.c [new file with mode: 0644]

index ba140eaee5c89f99f0836f43bdaf425c995616c8..1480e6a80b826e24a47bb2d01475b900b8893a12 100644 (file)
@@ -111,4 +111,13 @@ config MESON_EFUSE
          This driver can also be built as a module. If so, the module
          will be called nvmem_meson_efuse.
 
+config NVMEM_ZYNQMP
+       bool "Xilinx ZYNQMP SoC nvmem firmware support"
+       depends on ARCH_ZYNQMP
+       help
+         This is a driver to access hardware related data like soc revision,
+         IDCODE... etc.
+
+         If sure, say yes. If unsure, say no.
+
 endif
index 8f942a0cdaec8dabf5d15430fa1179d3ab535377..749e53047a5387ef8fa195fd57e11df63fd737e4 100644 (file)
@@ -24,3 +24,5 @@ obj-$(CONFIG_NVMEM_VF610_OCOTP)       += nvmem-vf610-ocotp.o
 nvmem-vf610-ocotp-y            := vf610-ocotp.o
 obj-$(CONFIG_MESON_EFUSE)      += nvmem_meson_efuse.o
 nvmem_meson_efuse-y            := meson-efuse.o
+obj-$(CONFIG_NVMEM_ZYNQMP)     += nvmem_zynqmp_nvmem.o
+nvmem_zynqmp_nvmem-y           := zynqmp_nvmem.o
diff --git a/drivers/nvmem/zynqmp_nvmem.c b/drivers/nvmem/zynqmp_nvmem.c
new file mode 100644 (file)
index 0000000..634e687
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2017 Xilinx, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/nvmem-provider.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/soc/xilinx/zynqmp/pm.h>
+
+#define SILICON_REVISION_MASK 0xF
+
+static int zynqmp_nvmem_read(void *context, unsigned int offset,
+                                       void *val, size_t bytes)
+{
+       int ret;
+       int idcode, version;
+
+       ret = zynqmp_pm_get_chipid(&idcode, &version);
+       if (ret < 0)
+               return ret;
+
+       pr_debug("Read chipid val %x %x\n", idcode, version);
+       *(int *)val = version & SILICON_REVISION_MASK;
+
+       return 0;
+}
+
+static struct nvmem_config econfig = {
+       .name = "zynqmp-nvmem",
+       .owner = THIS_MODULE,
+       .word_size = 4,
+       .size = 4,
+       .read_only = true,
+};
+
+static const struct of_device_id zynqmp_nvmem_match[] = {
+       { .compatible = "xlnx,zynqmp-nvmem-fw", },
+       { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, zynqmp_nvmem_match);
+
+static int zynqmp_nvmem_probe(struct platform_device *pdev)
+{
+       struct nvmem_device *nvmem;
+
+       econfig.dev = &pdev->dev;
+       econfig.reg_read = zynqmp_nvmem_read;
+
+       nvmem = nvmem_register(&econfig);
+       if (IS_ERR(nvmem))
+               return PTR_ERR(nvmem);
+
+       platform_set_drvdata(pdev, nvmem);
+
+       return 0;
+}
+
+static int zynqmp_nvmem_remove(struct platform_device *pdev)
+{
+       struct nvmem_device *nvmem = platform_get_drvdata(pdev);
+
+       return nvmem_unregister(nvmem);
+}
+
+static struct platform_driver zynqmp_nvmem_driver = {
+       .probe = zynqmp_nvmem_probe,
+       .remove = zynqmp_nvmem_remove,
+       .driver = {
+               .name = "zynqmp-nvmem",
+               .of_match_table = zynqmp_nvmem_match,
+       },
+};
+
+module_platform_driver(zynqmp_nvmem_driver);
+
+MODULE_AUTHOR("Michal Simek <michal.simek@xilinx.com>, Nava kishore Manne <navam@xilinx.com>");
+MODULE_DESCRIPTION("ZynqMP NVMEM driver");
+MODULE_LICENSE("GPL");