mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
To: Peter Rosin <peda@axentia.se>, <linux-kernel@vger.kernel.org>
Cc: Wolfram Sang <wsa@the-dreams.de>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Guenter Roeck <linux@roeck-us.net>,
	"David S. Miller" <davem@davemloft.net>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	<linux-i2c@vger.kernel.org>, <devicetree@vger.kernel.org>,
	Crestez Dan Leonard <leonard.crestez@intel.com>
Subject: Re: [PATCH v2 5/8] i2c: mux: add support for 'i2c-mux', 'i2c-arb' and 'i2c-gate' DT subnodes
Date: Mon, 15 Aug 2016 16:55:13 +0300	[thread overview]
Message-ID: <53bd470f-4243-c7fe-485a-3d8ec7cc034d@mentor.com> (raw)
In-Reply-To: <1471268431-5148-6-git-send-email-peda@axentia.se>

Hi Peter,

On 08/15/2016 04:40 PM, Peter Rosin wrote:
> Backwards compatibility is preserved; the subnodes are in practice
> optional.
>
> However, the mux core needs to know what subnode it should examine, so add
> a couple of new flags for i2c_mux_alloc for this purpose.
>
> The rule is that if the mux core finds a 'reg' property in the appropriate
> subnode, e.g. if 'reg' exists in the 'i2c-mux' subnode, then the mux core
> will assume that this is an old style entry and not an i2c-mux subnode
> (correspondingly for arbitrators and gates with 'i2c-arb' and 'i2c-gate').
>
> Signed-off-by: Peter Rosin <peda@axentia.se>
> ---
>  drivers/i2c/i2c-mux.c   | 44 ++++++++++++++++++++++++++++++++++++--------
>  include/linux/i2c-mux.h |  8 ++++++--
>  2 files changed, 42 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
> index 8eee98634cda..c1ae719d1a7a 100644
> --- a/drivers/i2c/i2c-mux.c
> +++ b/drivers/i2c/i2c-mux.c
> @@ -255,6 +255,10 @@ struct i2c_mux_core *i2c_mux_alloc(struct i2c_adapter *parent,
>  	muxc->dev = dev;
>  	if (flags & I2C_MUX_LOCKED)
>  		muxc->mux_locked = true;
> +	if (flags & I2C_MUX_ARBITRATOR)
> +		muxc->arbitrator = true;
> +	if (flags & I2C_MUX_GATE)
> +		muxc->gate = true;
>  	muxc->select = select;
>  	muxc->deselect = deselect;
>  	muxc->max_adapters = max_adapters;
> @@ -335,18 +339,42 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
>  	 * nothing if !CONFIG_OF.
>  	 */
>  	if (muxc->dev->of_node) {
> -		struct device_node *child;
> +		struct device_node *dev_node = muxc->dev->of_node;
> +		struct device_node *mux_node, *child = NULL;
>  		u32 reg;
>
> -		for_each_child_of_node(muxc->dev->of_node, child) {
> -			ret = of_property_read_u32(child, "reg", &reg);
> -			if (ret)
> -				continue;
> -			if (chan_id == reg) {
> -				priv->adap.dev.of_node = child;
> -				break;

missing of_node_put(child);

Also adding an empty line would be perfect.

> +		if (muxc->arbitrator)
> +			mux_node = of_get_child_by_name(dev_node, "i2c-arb");
> +		else if (muxc->gate)
> +			mux_node = of_get_child_by_name(dev_node, "i2c-gate");
> +		else
> +			mux_node = of_get_child_by_name(dev_node, "i2c-mux");
> +
> +		if (mux_node) {
> +			/* A "reg" property indicates an old-style DT entry */
> +			if (!of_property_read_u32(mux_node, "reg", &reg)) {
> +				of_node_put(mux_node);
> +				mux_node = NULL;
> +			}
> +		}
> +
> +		if (!mux_node)
> +			mux_node = of_node_get(dev_node);
> +		else if (muxc->arbitrator || muxc->gate)
> +			child = of_node_get(mux_node);
> +
> +		if (!child) {
> +			for_each_child_of_node(mux_node, child) {
> +				ret = of_property_read_u32(child, "reg", &reg);
> +				if (ret)
> +					continue;
> +				if (chan_id == reg)
> +					break;

missing of_node_put(child);

>  			}
>  		}
> +
> +		priv->adap.dev.of_node = child;
> +		of_node_put(mux_node);
>  	}
>
>  	/*
> diff --git a/include/linux/i2c-mux.h b/include/linux/i2c-mux.h
> index d4c1d12f900d..bd74d5706f3b 100644
> --- a/include/linux/i2c-mux.h
> +++ b/include/linux/i2c-mux.h
> @@ -32,7 +32,9 @@
>  struct i2c_mux_core {
>  	struct i2c_adapter *parent;
>  	struct device *dev;
> -	bool mux_locked;
> +	unsigned int mux_locked:1;
> +	unsigned int arbitrator:1;
> +	unsigned int gate:1;
>
>  	void *priv;
>
> @@ -51,7 +53,9 @@ struct i2c_mux_core *i2c_mux_alloc(struct i2c_adapter *parent,
>  				   int (*deselect)(struct i2c_mux_core *, u32));
>
>  /* flags for i2c_mux_alloc */
> -#define I2C_MUX_LOCKED BIT(0)
> +#define I2C_MUX_LOCKED     BIT(0)
> +#define I2C_MUX_ARBITRATOR BIT(1)
> +#define I2C_MUX_GATE       BIT(2)
>
>  static inline void *i2c_mux_priv(struct i2c_mux_core *muxc)
>  {
>

  reply	other threads:[~2016-08-15 13:55 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-15 13:40 [PATCH v2 0/8] devicetree cleanup for i2c muxes/arbs/gates Peter Rosin
2016-08-15 13:40 ` [PATCH v2 1/8] dt-bindings: i2c: add support for 'i2c-mux' subnode Peter Rosin
2016-08-15 13:40 ` [PATCH v2 2/8] dt-bindings: i2c: add support for 'i2c-arb' subnode Peter Rosin
2016-08-15 13:40 ` [PATCH v2 3/8] dt-bindings: i2c: add support for 'i2c-gate' subnode Peter Rosin
2016-08-16 13:57   ` Rob Herring
2016-08-25 16:15     ` Wolfram Sang
2016-08-15 13:40 ` [PATCH v2 4/8] dt-bindings: i2c: add bindings for nxp,pca9541 Peter Rosin
2016-08-15 13:40 ` [PATCH v2 5/8] i2c: mux: add support for 'i2c-mux', 'i2c-arb' and 'i2c-gate' DT subnodes Peter Rosin
2016-08-15 13:55   ` Vladimir Zapolskiy [this message]
2016-08-15 14:33     ` Peter Rosin
2016-08-15 13:40 ` [PATCH v2 6/8] i2c: mux: inform the i2c mux core about how it is used Peter Rosin
2016-08-25 16:19   ` Wolfram Sang
2016-08-25 16:22     ` Peter Rosin
2016-08-25 16:24       ` Wolfram Sang
2016-08-25 16:28         ` Peter Rosin
2016-08-25 16:38           ` Wolfram Sang
2016-08-15 13:40 ` [PATCH v2 7/8] i2c: pca9541: add device tree binding Peter Rosin
2016-08-15 13:40 ` [PATCH v2 8/8] i2c: pca954x: " Peter Rosin
2016-08-25 16:22 ` [PATCH v2 0/8] devicetree cleanup for i2c muxes/arbs/gates Wolfram Sang

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=53bd470f-4243-c7fe-485a-3d8ec7cc034d@mentor.com \
    --to=vladimir_zapolskiy@mentor.com \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=geert@linux-m68k.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=leonard.crestez@intel.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=mark.rutland@arm.com \
    --cc=mchehab@kernel.org \
    --cc=peda@axentia.se \
    --cc=robh+dt@kernel.org \
    --cc=wsa@the-dreams.de \
    /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

Powered by JetHome