59b2f9fa2c6707e40fd4006ad864ff3f81a19fb8
[openwrt/openwrt.git] /
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*
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
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".
11
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
18
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>
24 ---
25 drivers/nvmem/core.c | 32 +++++++++++++++++++++++++++++---
26 1 file changed, 29 insertions(+), 3 deletions(-)
27
28 --- a/drivers/nvmem/core.c
29 +++ b/drivers/nvmem/core.c
30 @@ -696,7 +696,7 @@ static int nvmem_validate_keepouts(struc
31 return 0;
32 }
33
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)
36 {
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
40 const __be32 *addr;
41 int len, ret;
42
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};
46
47 addr = of_get_property(child, "reg", &len);
48 @@ -742,6 +742,28 @@ static int nvmem_add_cells_from_of(struc
49 return 0;
50 }
51
52 +static int nvmem_add_cells_from_legacy_of(struct nvmem_device *nvmem)
53 +{
54 + return nvmem_add_cells_from_dt(nvmem, nvmem->dev.of_node);
55 +}
56 +
57 +static int nvmem_add_cells_from_fixed_layout(struct nvmem_device *nvmem)
58 +{
59 + struct device_node *layout_np;
60 + int err = 0;
61 +
62 + layout_np = of_nvmem_layout_get_container(nvmem);
63 + if (!layout_np)
64 + return 0;
65 +
66 + if (of_device_is_compatible(layout_np, "fixed-layout"))
67 + err = nvmem_add_cells_from_dt(nvmem, layout_np);
68 +
69 + of_node_put(layout_np);
70 +
71 + return err;
72 +}
73 +
74 int __nvmem_layout_register(struct nvmem_layout *layout, struct module *owner)
75 {
76 layout->owner = owner;
77 @@ -972,7 +994,7 @@ struct nvmem_device *nvmem_register(cons
78 if (rval)
79 goto err_remove_cells;
80
81 - rval = nvmem_add_cells_from_of(nvmem);
82 + rval = nvmem_add_cells_from_legacy_of(nvmem);
83 if (rval)
84 goto err_remove_cells;
85
86 @@ -982,6 +1004,10 @@ struct nvmem_device *nvmem_register(cons
87 if (rval)
88 goto err_remove_cells;
89
90 + rval = nvmem_add_cells_from_fixed_layout(nvmem);
91 + if (rval)
92 + goto err_remove_cells;
93 +
94 rval = nvmem_add_cells_from_layout(nvmem);
95 if (rval)
96 goto err_remove_cells;