devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Rob Herring <robh+dt@kernel.org>
Cc: Michael Walle <michael@walle.cc>,
	Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
	Frank Rowand <frowand.list@gmail.com>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org
Subject: Re: [PATCH] of: property: special #nvmem-cell-cells handling
Date: Wed, 23 Nov 2022 13:24:40 +0100	[thread overview]
Message-ID: <20221123132440.7ec3f7f5@xps-13> (raw)
In-Reply-To: <CAL_Jsq+CT00AHOK8Nxe_kUa6F_OcgxW4BL10iWWwKCJNwbTsAw@mail.gmail.com>

Hi Rob, Michael,

robh+dt@kernel.org wrote on Tue, 22 Nov 2022 17:44:26 -0600:

> On Fri, Nov 18, 2022 at 4:03 PM Michael Walle <michael@walle.cc> wrote:
> >
> > Am 2022-11-18 22:52, schrieb Rob Herring:  
> > > On Fri, Nov 18, 2022 at 3:40 PM Michael Walle <michael@walle.cc> wrote:  
> > >>
> > >> Since recently, there is a new #nvmem-cell-cells. To be backwards
> > >> compatible this is optional. Therefore, we need special handling and
> > >> cannot use DEFINE_SIMPLE_PROP() anymore.
> > >>
> > >> Signed-off-by: Michael Walle <michael@walle.cc>
> > >> ---
> > >> This patch will be part of the following series:
> > >> https://lore.kernel.org/linux-arm-kernel/20221118185118.1190044-1-michael@walle.cc/
> > >>
> > >>  drivers/of/property.c | 17 ++++++++++++++++-
> > >>  1 file changed, 16 insertions(+), 1 deletion(-)
> > >>
> > >> diff --git a/drivers/of/property.c b/drivers/of/property.c
> > >> index 967f79b59016..93c0ea662336 100644
> > >> --- a/drivers/of/property.c
> > >> +++ b/drivers/of/property.c
> > >> @@ -1305,7 +1305,6 @@ DEFINE_SIMPLE_PROP(dmas, "dmas", "#dma-cells")
> > >>  DEFINE_SIMPLE_PROP(power_domains, "power-domains",
> > >> "#power-domain-cells")
> > >>  DEFINE_SIMPLE_PROP(hwlocks, "hwlocks", "#hwlock-cells")
> > >>  DEFINE_SIMPLE_PROP(extcon, "extcon", NULL)
> > >> -DEFINE_SIMPLE_PROP(nvmem_cells, "nvmem-cells", NULL)
> > >>  DEFINE_SIMPLE_PROP(phys, "phys", "#phy-cells")
> > >>  DEFINE_SIMPLE_PROP(wakeup_parent, "wakeup-parent", NULL)
> > >>  DEFINE_SIMPLE_PROP(pinctrl0, "pinctrl-0", NULL)
> > >> @@ -1381,6 +1380,22 @@ static struct device_node
> > >> *parse_interrupts(struct device_node *np,
> > >>         return of_irq_parse_one(np, index, &sup_args) ? NULL :
> > >> sup_args.np;
> > >>  }
> > >>
> > >> +static struct device_node *parse_nvmem_cells(struct device_node *np,
> > >> +                                            const char *prop_name,
> > >> int index)
> > >> +{
> > >> +       struct of_phandle_args sup_args;
> > >> +
> > >> +       if (strcmp(prop_name, "nvmem-cells"))
> > >> +               return NULL;
> > >> +
> > >> +       if (of_parse_phandle_with_optional_args(np, prop_name,
> > >> +                                               "#nvmem-cell-cells",
> > >> index,
> > >> +                                               &sup_args))
> > >> +               return NULL;
> > >> +
> > >> +       return sup_args.np;
> > >> +}  
> > >
> > > There's a couple of other cases like that (MSI IIRC), so can we
> > > generalize this to work in more than 1 case?  
> >
> > You mean addding a new DEFINE_SIMPLE_PROP_OPTIONAL_ARGS()?  
> 
> Actually, I think you can just do something like the below. I don't
> think we need to separately handle an optional #.*-cells and a
> required one. It's really just validation which we do already both
> with the tools and when the subsystems parse these bindings. Of
> course, if we need to handle cases other than 0 default cells, we'll
> have to restructure the define some to pass the default cells.
>
> diff --git a/drivers/of/property.c b/drivers/of/property.c
> index 967f79b59016..198f56633eb0 100644
> --- a/drivers/of/property.c
> +++ b/drivers/of/property.c
> @@ -1254,7 +1254,7 @@ static struct device_node
> *parse_suffix_prop_cells(struct device_node *np,
>         if (strcmp_suffix(prop_name, suffix))
>                 return NULL;
> 
> -       if (of_parse_phandle_with_args(np, prop_name, cells_name, index,
> +       if (__of_parse_phandle_with_args(np, prop_name, cells_name, 0, index,
>                                        &sup_args))
>                 return NULL;

Excellent, this small change aside with

	-DEFINE_SIMPLE_PROP(nvmem_cells, "nvmem-cells", NULL)
	+DEFINE_SIMPLE_PROP(nvmem_cells, "nvmem-cells", "#nvmem-cell-cells")

look much simpler and work perfectly.

Tested-by: Miquel Raynal <miquel.raynal@bootlin.com>

Thanks,
Miquèl

  reply	other threads:[~2022-11-23 12:24 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-18 18:51 [PATCH v3 00/18] nvmem: core: introduce NVMEM layouts Michael Walle
2022-11-18 18:51 ` [PATCH v3 01/18] net: add helper eth_addr_add() Michael Walle
2022-11-18 18:51 ` [PATCH v3 02/18] of: base: add of_parse_phandle_with_optional_args() Michael Walle
2022-11-18 21:31   ` Michael Walle
2022-11-18 21:40     ` [PATCH] of: property: special #nvmem-cell-cells handling Michael Walle
2022-11-18 21:52       ` Rob Herring
2022-11-18 22:03         ` Michael Walle
2022-11-22 23:44           ` Rob Herring
2022-11-23 12:24             ` Miquel Raynal [this message]
2022-11-18 18:51 ` [PATCH v3 03/18] nvmem: core: fix device node refcounting Michael Walle
2022-11-18 18:51 ` [PATCH v3 04/18] nvmem: core: add an index parameter to the cell Michael Walle
2022-11-18 18:51 ` [PATCH v3 05/18] nvmem: core: move struct nvmem_cell_info to nvmem-provider.h Michael Walle
2022-11-18 18:51 ` [PATCH v3 06/18] nvmem: core: drop the removal of the cells in nvmem_add_cells() Michael Walle
2022-11-21  7:56   ` Sascha Hauer
2022-11-18 18:51 ` [PATCH v3 07/18] nvmem: core: add nvmem_add_one_cell() Michael Walle
2022-11-18 18:51 ` [PATCH v3 08/18] nvmem: core: use nvmem_add_one_cell() in nvmem_add_cells_from_of() Michael Walle
2022-11-18 18:51 ` [PATCH v3 09/18] nvmem: core: introduce NVMEM layouts Michael Walle
2022-11-18 18:51 ` [PATCH v3 10/18] nvmem: core: add per-cell post processing Michael Walle
2022-11-18 18:51 ` [PATCH v3 11/18] nvmem: core: allow to modify a cell before adding it Michael Walle
2022-11-18 18:51 ` [PATCH v3 12/18] nvmem: imx-ocotp: replace global post processing with layouts Michael Walle
2022-11-18 18:51 ` [PATCH v3 13/18] nvmem: cell: drop global cell_post_process Michael Walle
2022-11-18 18:51 ` [PATCH v3 14/18] nvmem: core: provide own priv pointer in post process callback Michael Walle
2022-11-18 18:51 ` [PATCH v3 15/18] nvmem: layouts: add sl28vpd layout Michael Walle
2022-11-18 18:51 ` [PATCH v3 16/18] MAINTAINERS: add myself as sl28vpd nvmem layout driver Michael Walle
2022-11-18 18:51 ` [PATCH v3 17/18] nvmem: layouts: Add ONIE tlv " Michael Walle
2022-11-21  7:51   ` Sascha Hauer
2022-11-23  9:52     ` Michael Walle
2022-11-18 18:51 ` [PATCH v3 18/18] MAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer Michael Walle

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=20221123132440.7ec3f7f5@xps-13 \
    --to=miquel.raynal@bootlin.com \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael@walle.cc \
    --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).