devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alban <albeu@free.fr>
To: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Aban Bedel <albeu@free.fr>,
	linux-kernel@vger.kernel.org, Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	David Woodhouse <dwmw2@infradead.org>,
	Brian Norris <computersforpeace@gmail.com>,
	Boris Brezillon <boris.brezillon@free-electrons.com>,
	Marek Vasut <marek.vasut@gmail.com>,
	Richard Weinberger <richard@nod.at>,
	Cyrille Pitchen <cyrille.pitchen@wedev4u.fr>,
	devicetree@vger.kernel.org, linux-mtd@lists.infradead.org
Subject: Re: [PATCH v3 1/3] nvmem: Update the OF binding to use a subnode for the cells list
Date: Fri, 8 Jun 2018 19:07:17 +0200	[thread overview]
Message-ID: <20180608190717.55cb185c@tock> (raw)
In-Reply-To: <cd7a0085-66cd-308e-a950-cd0eb96db945@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 4499 bytes --]

On Fri, 8 Jun 2018 12:34:12 +0100
Srinivas Kandagatla <srinivas.kandagatla@linaro.org> wrote:

> >> Can you try this with your original subnode proposal:
> >> just pass the subnode node pointer in np of nvmem_config:
> >>  
> >> ------------------------->cut<------------------------------------  
> >> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> >> index b05aa8e81303..c9621632bbfb 100644
> >> --- a/drivers/nvmem/core.c
> >> +++ b/drivers/nvmem/core.c
> >> @@ -472,7 +472,11 @@ struct nvmem_device *nvmem_register(const struct
> >> nvmem_config *config)
> >>           nvmem->priv = config->priv;
> >>           nvmem->reg_read = config->reg_read;
> >>           nvmem->reg_write = config->reg_write;
> >> -       nvmem->dev.of_node = config->dev->of_node;
> >> +
> >> +       if (config->np)
> >> +               nvmem->dev.of_node = config->np;
> >> +       else
> >> +               nvmem->dev.of_node = config->dev->of_node;
> >>
> >>           if (config->id == -1 && config->name) {
> >>                   dev_set_name(&nvmem->dev, "%s", config->name);
> >> diff --git a/include/linux/nvmem-provider.h
> >> b/include/linux/nvmem-provider.h index f89598bc4e1c..743345ffe2c8
> >> 100644 --- a/include/linux/nvmem-provider.h
> >> +++ b/include/linux/nvmem-provider.h
> >> @@ -49,6 +49,7 @@ typedef int (*nvmem_reg_write_t)(void *priv,
> >> unsigned int offset,nvmem_device_get(
> >>     */
> >>    struct nvmem_config {
> >>           struct device           *dev;
> >> +       struct device_node      *np;
> >>           const char              *name;
> >>           int                     id;
> >>           struct module           *owner;
> >>  
> >> ------------------------->cut<------------------------------------  
> > 
> > That should work just fine to allow next to any kind of binding.
> > I'll do a new patch using this approach for the code side and leaving
> > the generic binding as it is.  
> Sure!!
> This will give more flexibility to other provider drivers!

I looked into this. It would work fine for the cells but not so nicely
for the nvmem device API. The phandle for the nvmem device would have
to reference the node passed here and not the real device. We would end
up with a DT like this:

flash@0 {
	compatible = "mtd";
	...
	nvmem_dev: nvmem-cells {
		compatible = "nvmem-cells";
		...
        };
};

other-device@10 {
	...
	nvmem = <&nvmem_dev>;
};

Now if there is no cell defined we have this empty child node that make
very little sense, it is just there to accommodate the nvmem API.

What I would suggest now is to just change the wording. We don't
deprecate the current binding, but we extend it to allow grouping the
cells in a child node if required. The code to support this is trivial,
(4 lines including error handling) so even if we expect very few
bindings to make use of it it is not going to be maintenance drag.
That would look like this:

diff --git a/Documentation/devicetree/bindings/nvmem/nvmem.txt b/Documentation/devicetree/bindings/nvmem/nvmem.txt
index fd06c09..085d042 100644
--- a/Documentation/devicetree/bindings/nvmem/nvmem.txt
+++ b/Documentation/devicetree/bindings/nvmem/nvmem.txt
@@ -19,7 +19,10 @@ Optional properties:
 
 = Data cells =
 These are the child nodes of the provider which contain data cell
-information like offset and size in nvmem provider.
+information like offset and size in nvmem provider. Alternatively the data
+cells can be grouped in a node that has a compatible property set to
+"nvmem-cells".
+
 
 Required properties:
 reg:   specifies the offset in byte within the storage device.
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 4e94a78..3e1369c 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -859,6 +859,14 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
        if (!nvmem_np)
                return ERR_PTR(-EINVAL);
 
+       /* bindings that already have anonymous child nodes can instead put
+        * their cells in a child node with an nvmem-cells compatible. */
+       if (of_device_is_compatible(nvmem_np, "nvmem-cells")) {
+               nvmem_np = of_get_next_parent(nvmem_np);
+               if (!nvmem_np)
+                       return ERR_PTR(-EINVAL);
+       }
+
        nvmem = __nvmem_device_get(nvmem_np, NULL, NULL);
        of_node_put(nvmem_np);
        if (IS_ERR(nvmem))

What about it?

Alban

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2018-06-08 17:07 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-24 23:24 [PATCH v3 0/3] mtd: Add support for reading MTD devices via the nvmem API Alban Bedel
2018-03-24 23:24 ` [PATCH v3 1/3] nvmem: Update the OF binding to use a subnode for the cells list Alban Bedel
2018-04-16 21:04   ` Rob Herring
2018-04-17 12:31     ` Alban
2018-04-17 12:54   ` Srinivas Kandagatla
2018-04-17 14:54     ` Alban
2018-04-17 15:44       ` Srinivas Kandagatla
2018-04-17 16:00         ` Alban
2018-04-18 11:41           ` Alban
2018-04-18 12:12             ` Srinivas Kandagatla
2018-04-18 12:32               ` Alban
2018-04-18 12:53                 ` Srinivas Kandagatla
2018-04-18 13:34                   ` Alban
2018-05-01 16:49                     ` Srinivas Kandagatla
2018-06-07 16:41                       ` Alban
2018-06-07 17:03                         ` Srinivas Kandagatla
2018-06-08 10:59                           ` Alban
2018-06-08 11:34                             ` Srinivas Kandagatla
2018-06-08 17:07                               ` Alban [this message]
2018-06-10 10:32                                 ` Srinivas Kandagatla
2018-06-10 11:36                                   ` Alban
2018-06-10 13:28                                     ` Srinivas Kandagatla
2018-03-24 23:24 ` [PATCH v3 2/3] doc: bindings: Add bindings documentation for mtd nvmem Alban Bedel
2018-04-16 21:08   ` Rob Herring
2018-04-17 12:44     ` Alban
2018-03-24 23:24 ` [PATCH v3 3/3] mtd: Add support for reading MTD devices via the nvmem API Alban Bedel
2019-04-18 13:36 ` Reading MAC addresses with NVMEM under MTD partition [Was: Re: [PATCH v3 1/3] nvmem: Update the OF binding to use a subnode for the cells list] Petr Štetiar

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=20180608190717.55cb185c@tock \
    --to=albeu@free.fr \
    --cc=boris.brezillon@free-electrons.com \
    --cc=computersforpeace@gmail.com \
    --cc=cyrille.pitchen@wedev4u.fr \
    --cc=devicetree@vger.kernel.org \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marek.vasut@gmail.com \
    --cc=mark.rutland@arm.com \
    --cc=richard@nod.at \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).