All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rafał Miłecki" <zajec5@gmail.com>
To: Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Miquel Raynal" <miquel.raynal@bootlin.com>,
	"Michael Walle" <michael@walle.cc>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Rafał Miłecki" <rafal@milecki.pl>
Subject: [PATCH V4 4/4] nvmem: layouts: add fixed cells layout
Date: Fri, 17 Mar 2023 14:26:20 +0100	[thread overview]
Message-ID: <20230317132620.31142-5-zajec5@gmail.com> (raw)
In-Reply-To: <20230317132620.31142-1-zajec5@gmail.com>

From: Rafał Miłecki <rafal@milecki.pl>

This adds a driver for the "fixed-layout" NVMEM layout binding. It
allows defining NVMEM cells in a layout DT node named "nvmem-layout".

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 drivers/nvmem/layouts/Kconfig  |  8 +++++++
 drivers/nvmem/layouts/Makefile |  1 +
 drivers/nvmem/layouts/fixed.c  | 41 ++++++++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+)
 create mode 100644 drivers/nvmem/layouts/fixed.c

diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig
index 7ff1ee1c1f05..2ebbde7b15b2 100644
--- a/drivers/nvmem/layouts/Kconfig
+++ b/drivers/nvmem/layouts/Kconfig
@@ -2,6 +2,14 @@
 
 menu "Layout Types"
 
+config NVMEM_LAYOUT_FIXED
+	tristate "Fixed cells layout support"
+	help
+	  Say Y here if you want to support layout with fixed cells (hardcoded
+	  offsets and sizes).
+
+	  If unsure, say N.
+
 config NVMEM_LAYOUT_SL28_VPD
 	tristate "Kontron sl28 VPD layout support"
 	select CRC8
diff --git a/drivers/nvmem/layouts/Makefile b/drivers/nvmem/layouts/Makefile
index 2974bd7d33ed..449dd893f968 100644
--- a/drivers/nvmem/layouts/Makefile
+++ b/drivers/nvmem/layouts/Makefile
@@ -3,5 +3,6 @@
 # Makefile for nvmem layouts.
 #
 
+obj-$(CONFIG_NVMEM_LAYOUT_FIXED) += fixed.o
 obj-$(CONFIG_NVMEM_LAYOUT_SL28_VPD) += sl28vpd.o
 obj-$(CONFIG_NVMEM_LAYOUT_ONIE_TLV) += onie-tlv.o
diff --git a/drivers/nvmem/layouts/fixed.c b/drivers/nvmem/layouts/fixed.c
new file mode 100644
index 000000000000..b8d2f141d272
--- /dev/null
+++ b/drivers/nvmem/layouts/fixed.c
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/module.h>
+#include <linux/nvmem-consumer.h>
+#include <linux/nvmem-provider.h>
+#include <linux/of.h>
+
+static int fixed_add_cells(struct device *dev, struct nvmem_device *nvmem,
+			   struct nvmem_layout *layout)
+{
+	struct device_node *layout_np;
+	int err;
+
+	layout_np = of_nvmem_layout_get_container(nvmem);
+	if (!layout_np)
+		return -ENOENT;
+
+	err = nvmem_add_cells_from_of(nvmem, layout_np);
+
+	of_node_put(layout_np);
+
+	return err;
+}
+
+static const struct of_device_id fixed_of_match_table[] = {
+	{ .compatible = "fixed-layout" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, fixed_of_match_table);
+
+struct nvmem_layout fixed_nvmem_layout = {
+	.name = "fixed-layout",
+	.of_match_table = fixed_of_match_table,
+	.add_cells = fixed_add_cells,
+};
+
+module_nvmem_layout_driver(fixed_nvmem_layout);
+
+MODULE_AUTHOR("Rafał Miłecki");
+MODULE_LICENSE("GPL");
+MODULE_DEVICE_TABLE(of, fixed_of_match_table);
-- 
2.34.1


  parent reply	other threads:[~2023-03-17 13:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-17 13:26 [PATCH V4 0/4] nvmem: add fixed cells layout Rafał Miłecki
2023-03-17 13:26 ` [PATCH V4 1/4] dt-bindings: nvmem: layouts: add fixed-layout Rafał Miłecki
2023-03-17 13:26 ` [PATCH V4 2/4] dt-bindings: nvmem: convert base example to use NVMEM fixed cells layout Rafał Miłecki
2023-03-17 13:26 ` [PATCH V4 3/4] nvmem: core: export nvmem_add_cells_from_of() Rafał Miłecki
2023-03-18  0:06   ` kernel test robot
2023-03-20  8:23   ` Michael Walle
2023-03-17 13:26 ` Rafał Miłecki [this message]
2023-03-17 15:54   ` [PATCH V4 4/4] nvmem: layouts: add fixed cells layout kernel test robot
2023-03-17 16:04     ` Rafał Miłecki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230317132620.31142-5-zajec5@gmail.com \
    --to=zajec5@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael@walle.cc \
    --cc=miquel.raynal@bootlin.com \
    --cc=rafal@milecki.pl \
    --cc=robh+dt@kernel.org \
    --cc=srinivas.kandagatla@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.