5889e619106af1483235872504a550b5a14be7c1
[openwrt/staging/noltari.git] / target / linux / generic / backport-5.10 / 804-v5.14-0001-nvmem-core-allow-specifying-of_node.patch
1 From 1333a6779501f4cc662ff5c8b36b0a22f3a7ddc6 Mon Sep 17 00:00:00 2001
2 From: Michael Walle <michael@walle.cc>
3 Date: Sat, 24 Apr 2021 13:06:04 +0200
4 Subject: [PATCH] nvmem: core: allow specifying of_node
5
6 Until now, the of_node of the parent device is used. Some devices
7 provide more than just the nvmem provider. To avoid name space clashes,
8 add a way to allow specifying the nvmem cells in subnodes. Consider the
9 following example:
10
11 flash@0 {
12 compatible = "jedec,spi-nor";
13
14 partitions {
15 compatible = "fixed-partitions";
16 #address-cells = <1>;
17 #size-cells = <1>;
18
19 partition@0 {
20 reg = <0x000000 0x010000>;
21 };
22 };
23
24 otp {
25 compatible = "user-otp";
26 #address-cells = <1>;
27 #size-cells = <1>;
28
29 serial-number@0 {
30 reg = <0x0 0x8>;
31 };
32 };
33 };
34
35 There the nvmem provider might be the MTD partition or the OTP region of
36 the flash.
37
38 Add a new config->of_node parameter, which if set, will be used instead
39 of the parent's of_node.
40
41 Signed-off-by: Michael Walle <michael@walle.cc>
42 Acked-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
43 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
44 Link: https://lore.kernel.org/linux-mtd/20210424110608.15748-2-michael@walle.cc
45 ---
46 drivers/nvmem/core.c | 4 +++-
47 include/linux/nvmem-provider.h | 2 ++
48 2 files changed, 5 insertions(+), 1 deletion(-)
49
50 --- a/drivers/nvmem/core.c
51 +++ b/drivers/nvmem/core.c
52 @@ -795,7 +795,9 @@ struct nvmem_device *nvmem_register(cons
53 nvmem->reg_write = config->reg_write;
54 nvmem->keepout = config->keepout;
55 nvmem->nkeepout = config->nkeepout;
56 - if (!config->no_of_node)
57 + if (config->of_node)
58 + nvmem->dev.of_node = config->of_node;
59 + else if (!config->no_of_node)
60 nvmem->dev.of_node = config->dev->of_node;
61
62 switch (config->id) {
63 --- a/include/linux/nvmem-provider.h
64 +++ b/include/linux/nvmem-provider.h
65 @@ -57,6 +57,7 @@ struct nvmem_keepout {
66 * @type: Type of the nvmem storage
67 * @read_only: Device is read-only.
68 * @root_only: Device is accessibly to root only.
69 + * @of_node: If given, this will be used instead of the parent's of_node.
70 * @no_of_node: Device should not use the parent's of_node even if it's !NULL.
71 * @reg_read: Callback to read data.
72 * @reg_write: Callback to write data.
73 @@ -87,6 +88,7 @@ struct nvmem_config {
74 enum nvmem_type type;
75 bool read_only;
76 bool root_only;
77 + struct device_node *of_node;
78 bool ignore_wp;
79 bool no_of_node;
80 nvmem_reg_read_t reg_read;