All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rob Herring <robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
Cc: linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
	linus.walleij-0IS4wlFg1OjSUeElwK9/Pw@public.gmane.org,
	s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	dongas86-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Subject: Re: [PATCH V2 1/6] dt: add property iteration helpers
Date: Tue, 20 Mar 2012 15:03:10 -0500	[thread overview]
Message-ID: <4F68E27E.3000408@gmail.com> (raw)
In-Reply-To: <1332265479-1260-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>

On 03/20/2012 12:44 PM, Stephen Warren wrote:
> This patch adds macros of_property_for_each_u32() and
> of_property_for_each_string(), which iterate over an array of values
> within a device-tree property. Usage is for example:
> 
> struct property *prop;
> const __be32 *p;
> u32 u;
> of_property_for_each_u32(np, "propname", prop, p, u)
> 	printk("U32 value: %x\n", u);
> 
> struct property *prop;
> const char *s;
> of_property_for_each_string(np, "propname", prop, s)
> 	printk("String value: %s\n", s);
> 
> Based on work by Rob Herring <robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> 
> Signed-off-by: Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
> ---
> v2: Simplified the implementation per suggestion by Rob Herring.
> ---
>  include/linux/of_iter_prop.h |  101 ++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 101 insertions(+), 0 deletions(-)
>  create mode 100644 include/linux/of_iter_prop.h

I don't think this makes sense to be a new header as it's use is pretty
much the same as other property functions. I would un-inline the helper
functions to of/base.c and move the defines to of.h.

Rob

> diff --git a/include/linux/of_iter_prop.h b/include/linux/of_iter_prop.h
> new file mode 100644
> index 0000000..e3df23c
> --- /dev/null
> +++ b/include/linux/of_iter_prop.h
> @@ -0,0 +1,101 @@
> +/*
> + * Copyright (c) 2011-2012 NVIDIA CORPORATION. All rights reserved.
> + *
> + * Iterate over properties that store arrays.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
> + */
> +#ifndef __OF_ITER_PROP_H__
> +#define __OF_ITER_PROP_H__
> +
> +#include <linux/of.h>
> +
> +#ifdef CONFIG_OF
> +static inline const __be32 *of_prop_next_u32(struct property *prop,
> +					     const __be32 *cur, u32 *pu)
> +{
> +	const void *curv = cur;
> +
> +	if (!prop)
> +		return NULL;
> +
> +	if (!cur) {
> +		curv = prop->value;
> +		goto out_val;
> +	}
> +
> +	curv += sizeof(*cur);
> +	if (curv >= prop->value + prop->length)
> +		return NULL;
> +
> +out_val:
> +	*pu = be32_to_cpup(curv);
> +	return curv;
> +}
> +
> +/*
> + * struct property *prop;
> + * const __be32 *p;
> + * u32 u;
> + *
> + * of_property_for_each_u32(np, "propname", prop, p, u)
> + *         printk("U32 value: %x\n", u);
> + */
> +#define of_property_for_each_u32(np, propname, prop, p, u)	\
> +	for (prop = of_find_property(np, propname, NULL),	\
> +		p = of_prop_next_u32(prop, NULL, &u);		\
> +		p;						\
> +		p = of_prop_next_u32(prop, p, &u))
> +
> +static inline const char *of_prop_next_string(struct property *prop,
> +					      const char *cur)
> +{
> +	const void *curv = cur;
> +
> +	if (!prop)
> +		return NULL;
> +
> +	if (!cur)
> +		return prop->value;
> +
> +	curv += strlen(cur) + 1;
> +	if (curv >= prop->value + prop->length)
> +		return NULL;
> +
> +	return curv;
> +}
> +
> +/*
> + * struct property *prop;
> + * const char *s;
> + *
> + * of_property_for_each_string(np, "propname", prop, s)
> + *         printk("String value: %s\n", s);
> + */
> +#define of_property_for_each_string(np, propname, prop, s)	\
> +	for (prop = of_find_property(np, propname, NULL),	\
> +		s = of_prop_next_string(prop, NULL);		\
> +		s;						\
> +		s = of_prop_next_string(prop, s))
> +
> +#else
> +
> +#define of_property_for_each_u32(np, propname, prop, p, u) \
> +	while (0)
> +
> +#define of_property_for_each_string(np, propname, prop, s) \
> +	while (0)
> +
> +#endif /* CONFIG_OF */
> +
> +#endif /* __OF_ITER_PROP_H__ */

WARNING: multiple messages have this Message-ID (diff)
From: Rob Herring <robherring2@gmail.com>
To: Stephen Warren <swarren@wwwdotorg.org>
Cc: linus.walleij@linaro.org, devicetree-discuss@lists.ozlabs.org,
	linus.walleij@stericsson.com, s.hauer@pengutronix.de,
	linux-kernel@vger.kernel.org, rob.herring@calxeda.com,
	linux-tegra@vger.kernel.org, dongas86@gmail.com
Subject: Re: [PATCH V2 1/6] dt: add property iteration helpers
Date: Tue, 20 Mar 2012 15:03:10 -0500	[thread overview]
Message-ID: <4F68E27E.3000408@gmail.com> (raw)
In-Reply-To: <1332265479-1260-1-git-send-email-swarren@wwwdotorg.org>

On 03/20/2012 12:44 PM, Stephen Warren wrote:
> This patch adds macros of_property_for_each_u32() and
> of_property_for_each_string(), which iterate over an array of values
> within a device-tree property. Usage is for example:
> 
> struct property *prop;
> const __be32 *p;
> u32 u;
> of_property_for_each_u32(np, "propname", prop, p, u)
> 	printk("U32 value: %x\n", u);
> 
> struct property *prop;
> const char *s;
> of_property_for_each_string(np, "propname", prop, s)
> 	printk("String value: %s\n", s);
> 
> Based on work by Rob Herring <robherring2@gmail.com>
> 
> Signed-off-by: Stephen Warren <swarren@wwwdotorg.org>
> ---
> v2: Simplified the implementation per suggestion by Rob Herring.
> ---
>  include/linux/of_iter_prop.h |  101 ++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 101 insertions(+), 0 deletions(-)
>  create mode 100644 include/linux/of_iter_prop.h

I don't think this makes sense to be a new header as it's use is pretty
much the same as other property functions. I would un-inline the helper
functions to of/base.c and move the defines to of.h.

Rob

> diff --git a/include/linux/of_iter_prop.h b/include/linux/of_iter_prop.h
> new file mode 100644
> index 0000000..e3df23c
> --- /dev/null
> +++ b/include/linux/of_iter_prop.h
> @@ -0,0 +1,101 @@
> +/*
> + * Copyright (c) 2011-2012 NVIDIA CORPORATION. All rights reserved.
> + *
> + * Iterate over properties that store arrays.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
> + */
> +#ifndef __OF_ITER_PROP_H__
> +#define __OF_ITER_PROP_H__
> +
> +#include <linux/of.h>
> +
> +#ifdef CONFIG_OF
> +static inline const __be32 *of_prop_next_u32(struct property *prop,
> +					     const __be32 *cur, u32 *pu)
> +{
> +	const void *curv = cur;
> +
> +	if (!prop)
> +		return NULL;
> +
> +	if (!cur) {
> +		curv = prop->value;
> +		goto out_val;
> +	}
> +
> +	curv += sizeof(*cur);
> +	if (curv >= prop->value + prop->length)
> +		return NULL;
> +
> +out_val:
> +	*pu = be32_to_cpup(curv);
> +	return curv;
> +}
> +
> +/*
> + * struct property *prop;
> + * const __be32 *p;
> + * u32 u;
> + *
> + * of_property_for_each_u32(np, "propname", prop, p, u)
> + *         printk("U32 value: %x\n", u);
> + */
> +#define of_property_for_each_u32(np, propname, prop, p, u)	\
> +	for (prop = of_find_property(np, propname, NULL),	\
> +		p = of_prop_next_u32(prop, NULL, &u);		\
> +		p;						\
> +		p = of_prop_next_u32(prop, p, &u))
> +
> +static inline const char *of_prop_next_string(struct property *prop,
> +					      const char *cur)
> +{
> +	const void *curv = cur;
> +
> +	if (!prop)
> +		return NULL;
> +
> +	if (!cur)
> +		return prop->value;
> +
> +	curv += strlen(cur) + 1;
> +	if (curv >= prop->value + prop->length)
> +		return NULL;
> +
> +	return curv;
> +}
> +
> +/*
> + * struct property *prop;
> + * const char *s;
> + *
> + * of_property_for_each_string(np, "propname", prop, s)
> + *         printk("String value: %s\n", s);
> + */
> +#define of_property_for_each_string(np, propname, prop, s)	\
> +	for (prop = of_find_property(np, propname, NULL),	\
> +		s = of_prop_next_string(prop, NULL);		\
> +		s;						\
> +		s = of_prop_next_string(prop, s))
> +
> +#else
> +
> +#define of_property_for_each_u32(np, propname, prop, p, u) \
> +	while (0)
> +
> +#define of_property_for_each_string(np, propname, prop, s) \
> +	while (0)
> +
> +#endif /* CONFIG_OF */
> +
> +#endif /* __OF_ITER_PROP_H__ */


  parent reply	other threads:[~2012-03-20 20:03 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-20 17:44 [PATCH V2 1/6] dt: add property iteration helpers Stephen Warren
2012-03-20 17:44 ` Stephen Warren
2012-03-20 17:44 ` [PATCH V2 2/6] dt: pinctrl: Document device tree binding Stephen Warren
2012-03-20 19:50   ` Simon Glass
     [not found]   ` <1332265479-1260-2-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-03-21  5:37     ` Dong Aisheng
2012-03-21  5:37       ` Dong Aisheng
2012-03-20 17:44 ` [PATCH V2 3/6] pinctrl: core device tree mapping table parsing support Stephen Warren
     [not found]   ` <1332265479-1260-3-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-03-21  7:31     ` Dong Aisheng
2012-03-21  7:31       ` Dong Aisheng
2012-03-21  7:31       ` Dong Aisheng
     [not found]       ` <20120321073116.GE3191-Fb7DQEYuewWctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2012-03-21 15:48         ` Stephen Warren
2012-03-21 15:48           ` Stephen Warren
     [not found]           ` <4F69F844.3060102-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-03-21 17:25             ` Stephen Warren
2012-03-21 17:25               ` Stephen Warren
     [not found]               ` <4F6A0F05.90104-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-03-22  5:49                 ` Dong Aisheng
2012-03-22  5:49                   ` Dong Aisheng
2012-03-22  3:39             ` Dong Aisheng
2012-03-22  3:39               ` Dong Aisheng
2012-03-20 17:44 ` [PATCH V2 4/6] dt: Move Tegra20 pin mux binding into new pinctrl directory Stephen Warren
2012-03-20 17:44 ` [PATCH V2 5/6] dt: Document Tegra20/30 pinctrl binding Stephen Warren
     [not found]   ` <1332265479-1260-5-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-03-21  9:19     ` Dong Aisheng
2012-03-21  9:19       ` Dong Aisheng
     [not found]       ` <20120321091919.GA18592-Fb7DQEYuewWctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2012-03-21 15:57         ` Stephen Warren
2012-03-21 15:57           ` Stephen Warren
     [not found]           ` <4F69FA5A.9020504-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-03-22  4:00             ` Dong Aisheng
2012-03-22  4:00               ` Dong Aisheng
     [not found]               ` <20120322040024.GB840-Fb7DQEYuewWctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2012-03-22 15:45                 ` Stephen Warren
2012-03-22 15:45                   ` Stephen Warren
     [not found]                   ` <4F6B491B.8040506-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-03-23  4:51                     ` Dong Aisheng
2012-03-23  4:51                       ` Dong Aisheng
2012-03-20 17:44 ` [PATCH V2 6/6] pinctrl: tegra: Add complete device tree support Stephen Warren
     [not found]   ` <1332265479-1260-6-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-03-21  9:35     ` Dong Aisheng
2012-03-21  9:35       ` Dong Aisheng
2012-03-21 16:07       ` Stephen Warren
2012-03-21 16:07         ` Stephen Warren
     [not found]         ` <4F69FCBF.3050708-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-03-22  4:07           ` Dong Aisheng
2012-03-22  4:07             ` Dong Aisheng
     [not found]             ` <20120322040730.GC840-Fb7DQEYuewWctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2012-03-22 17:22               ` Stephen Warren
2012-03-22 17:22                 ` Stephen Warren
2012-04-01 17:29     ` Linus Walleij
2012-04-01 17:29       ` Linus Walleij
     [not found]       ` <CACRpkdav8x-Td-fH1Ree83GhNR8r7aA1dBsTQo2eU3nwwam21Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-04-02 15:34         ` Stephen Warren
2012-04-02 15:34           ` Stephen Warren
     [not found]           ` <4F79C6F7.4070701-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-04-03 21:06             ` Linus Walleij
2012-04-03 21:06               ` Linus Walleij
     [not found] ` <1332265479-1260-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-03-20 20:03   ` Rob Herring [this message]
2012-03-20 20:03     ` [PATCH V2 1/6] dt: add property iteration helpers Rob Herring

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=4F68E27E.3000408@gmail.com \
    --to=robherring2-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
    --cc=dongas86-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=linus.walleij-0IS4wlFg1OjSUeElwK9/Pw@public.gmane.org \
    --cc=linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org \
    --cc=s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
    --cc=swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.