1 From 27f699e578b1a72df89dfa3bc42e093a01dc8d10 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Sun, 11 Jun 2023 15:03:29 +0100
4 Subject: [PATCH] nvmem: core: add support for fixed cells *layout*
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 This adds support for the "fixed-layout" NVMEM layout binding. It allows
10 defining NVMEM cells in a layout DT node named "nvmem-layout".
12 While NVMEM subsystem supports layout drivers it has been discussed that
13 "fixed-layout" may actually be supperted internally. It's because:
14 1. It's a very basic layout
15 2. It allows sharing code with legacy syntax parsing
16 3. It's safer for soc_device_match() due to -EPROBE_DEFER
17 4. This will make the syntax transition easier
19 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
20 Reviewed-by: Michael Walle <michael@walle.cc>
21 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
22 Message-ID: <20230611140330.154222-26-srinivas.kandagatla@linaro.org>
23 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
25 drivers/nvmem/core.c | 32 +++++++++++++++++++++++++++++---
26 1 file changed, 29 insertions(+), 3 deletions(-)
28 --- a/drivers/nvmem/core.c
29 +++ b/drivers/nvmem/core.c
30 @@ -696,7 +696,7 @@ static int nvmem_validate_keepouts(struc
34 -static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
35 +static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np)
37 struct nvmem_layout *layout = nvmem->layout;
38 struct device *dev = &nvmem->dev;
39 @@ -704,7 +704,7 @@ static int nvmem_add_cells_from_of(struc
43 - for_each_child_of_node(dev->of_node, child) {
44 + for_each_child_of_node(np, child) {
45 struct nvmem_cell_info info = {0};
47 addr = of_get_property(child, "reg", &len);
48 @@ -742,6 +742,28 @@ static int nvmem_add_cells_from_of(struc
52 +static int nvmem_add_cells_from_legacy_of(struct nvmem_device *nvmem)
54 + return nvmem_add_cells_from_dt(nvmem, nvmem->dev.of_node);
57 +static int nvmem_add_cells_from_fixed_layout(struct nvmem_device *nvmem)
59 + struct device_node *layout_np;
62 + layout_np = of_nvmem_layout_get_container(nvmem);
66 + if (of_device_is_compatible(layout_np, "fixed-layout"))
67 + err = nvmem_add_cells_from_dt(nvmem, layout_np);
69 + of_node_put(layout_np);
74 int __nvmem_layout_register(struct nvmem_layout *layout, struct module *owner)
76 layout->owner = owner;
77 @@ -972,7 +994,7 @@ struct nvmem_device *nvmem_register(cons
79 goto err_remove_cells;
81 - rval = nvmem_add_cells_from_of(nvmem);
82 + rval = nvmem_add_cells_from_legacy_of(nvmem);
84 goto err_remove_cells;
86 @@ -982,6 +1004,10 @@ struct nvmem_device *nvmem_register(cons
88 goto err_remove_cells;
90 + rval = nvmem_add_cells_from_fixed_layout(nvmem);
92 + goto err_remove_cells;
94 rval = nvmem_add_cells_from_layout(nvmem);
96 goto err_remove_cells;