From: Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
To: Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
Cc: Grant Likely
<grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>,
Rob Herring <rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>,
Ben Dooks <ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org>,
Linus Walleij
<linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>,
David Daney <ddaney.cavm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: Re: [PATCH 1/2] i2c: mux: add device tree support
Date: Mon, 23 Apr 2012 13:15:07 +0200 [thread overview]
Message-ID: <20120423111507.GF19192@pengutronix.de> (raw)
In-Reply-To: <1334688545-8465-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 8045 bytes --]
On Tue, Apr 17, 2012 at 12:49:04PM -0600, Stephen Warren wrote:
> From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
>
> * Define core portions of the DT binding for I2C bus muxes.
> * Enhance i2c_add_mux_adapter():
> ** Add parameters required for DT support. Update all callers.
> ** Set the appropriate adap->dev.of_node for the child bus.
> ** Call of_i2c_register_devices() for the child bus.
>
> Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
David Daney (CCed) posted another variant [1]. Just looking at the
patches (and not really using them), I tend to like the approach using
<reg> better. But I am open for discussion, so I'd appreciate your
feedback.
Regards,
Wolfram
[1] http://lkml.org/lkml/2012/4/12/423
> ---
> Note: This series depends on the 3 patches I just sent that affect
> of_find_i2c_device_by_node and implement of_find_i2c_adapter_by_node.
> It might be useful to put this patch (and the others I sent) in
> a separate tree so it can be merged into any SoC trees that wish to use
> this new feature.
>
> Documentation/devicetree/bindings/i2c/i2cmux.txt | 45 ++++++++++++++++++++++
> drivers/i2c/i2c-mux.c | 23 +++++++++++-
> drivers/i2c/muxes/gpio-i2cmux.c | 5 +-
> drivers/i2c/muxes/pca9541.c | 4 +-
> drivers/i2c/muxes/pca954x.c | 4 +-
> include/linux/i2c-mux.h | 4 +-
> 6 files changed, 77 insertions(+), 8 deletions(-)
> create mode 100644 Documentation/devicetree/bindings/i2c/i2cmux.txt
>
> diff --git a/Documentation/devicetree/bindings/i2c/i2cmux.txt b/Documentation/devicetree/bindings/i2c/i2cmux.txt
> new file mode 100644
> index 0000000..1e4e2bc
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/i2c/i2cmux.txt
> @@ -0,0 +1,45 @@
> +Common I2C mux bindings
> +
> +An I2C mux is a device that connects a master I2C bus to one of a number of
> +child I2C busses, under programmatic control.
> +
> +Each I2C mux may define the set of child busses it supports in a different
> +way. Some devices may have a hard-coded set of child ports, whereas others may
> +support a varying set of child busses (especially when the bus mux is
> +implemented using GPIOs or pin muxing). Any bindings required to represent
> +this are the domain of the individual mux device.
> +
> +For each child bus, there shall be a node within the I2C mux's own node for
> +that bus. This node will contain all the I2C devices on that bus, just like
> +any other I2C bus. Each child bus shall be identified by some name. The set
> +of child bus names is defined by the individual I2C mux's bindings. Bus names
> +are used to construct the name of the bus's child node using the format
> +i2c-bus-%s. Each child bus node needs the usual #address-cells and #size-cells
> +properties.
> +
> +Example:
> +
> + i2cmux {
> + // properties here omitted from the example.
> +
> + i2c-bus-0 {
> + #address-cells = <1>;
> + #size-cells = <0>;
> +
> + eeprom {
> + compatible = "eeprom";
> + reg = <0x50>;
> + };
> + };
> +
> + i2c-bus-1 {
> + #address-cells = <1>;
> + #size-cells = <0>;
> +
> + eeprom {
> + compatible = "eeprom";
> + reg = <0x50>;
> + };
> + };
> + };
> +
> diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
> index d7a4833..8adeeec 100644
> --- a/drivers/i2c/i2c-mux.c
> +++ b/drivers/i2c/i2c-mux.c
> @@ -24,6 +24,7 @@
> #include <linux/slab.h>
> #include <linux/i2c.h>
> #include <linux/i2c-mux.h>
> +#include <linux/of_i2c.h>
>
> /* multiplexer per channel data */
> struct i2c_mux_priv {
> @@ -86,8 +87,10 @@ static u32 i2c_mux_functionality(struct i2c_adapter *adap)
> return parent->algo->functionality(parent);
> }
>
> -struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
> +struct i2c_adapter *i2c_add_mux_adapter(struct device *dev,
> + struct i2c_adapter *parent,
> void *mux_dev, u32 force_nr, u32 chan_id,
> + const char *chan_name,
> int (*select) (struct i2c_adapter *,
> void *, u32),
> int (*deselect) (struct i2c_adapter *,
> @@ -124,6 +127,22 @@ struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
> priv->adap.algo_data = priv;
> priv->adap.dev.parent = &parent->dev;
>
> + if (dev->of_node) {
> + const char *name;
> +
> + if (chan_name)
> + name = kasprintf(GFP_KERNEL, "i2c-bus-%s",
> + chan_name);
> + else
> + name = kasprintf(GFP_KERNEL, "i2c-bus-%d",
> + chan_id);
> +
> + priv->adap.dev.of_node = of_find_node_by_name(dev->of_node,
> + name);
> +
> + kfree(name);
> + }
> +
> if (force_nr) {
> priv->adap.nr = force_nr;
> ret = i2c_add_numbered_adapter(&priv->adap);
> @@ -141,6 +160,8 @@ struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
> dev_info(&parent->dev, "Added multiplexed i2c bus %d\n",
> i2c_adapter_id(&priv->adap));
>
> + of_i2c_register_devices(&priv->adap);
> +
> return &priv->adap;
> }
> EXPORT_SYMBOL_GPL(i2c_add_mux_adapter);
> diff --git a/drivers/i2c/muxes/gpio-i2cmux.c b/drivers/i2c/muxes/gpio-i2cmux.c
> index e5fa695..7284c70 100644
> --- a/drivers/i2c/muxes/gpio-i2cmux.c
> +++ b/drivers/i2c/muxes/gpio-i2cmux.c
> @@ -105,8 +105,9 @@ static int __devinit gpiomux_probe(struct platform_device *pdev)
> for (i = 0; i < pdata->n_values; i++) {
> u32 nr = pdata->base_nr ? (pdata->base_nr + i) : 0;
>
> - mux->adap[i] = i2c_add_mux_adapter(parent, mux, nr, i,
> - gpiomux_select, deselect);
> + mux->adap[i] = i2c_add_mux_adapter(&pdev->dev, parent, mux, nr,
> + i, NULL, gpiomux_select,
> + deselect);
> if (!mux->adap[i]) {
> ret = -ENODEV;
> dev_err(&pdev->dev, "Failed to add adapter %d\n", i);
> diff --git a/drivers/i2c/muxes/pca9541.c b/drivers/i2c/muxes/pca9541.c
> index e0df9b6..e1777fb 100644
> --- a/drivers/i2c/muxes/pca9541.c
> +++ b/drivers/i2c/muxes/pca9541.c
> @@ -353,8 +353,8 @@ static int pca9541_probe(struct i2c_client *client,
> force = 0;
> if (pdata)
> force = pdata->modes[0].adap_id;
> - data->mux_adap = i2c_add_mux_adapter(adap, client, force, 0,
> - pca9541_select_chan,
> + data->mux_adap = i2c_add_mux_adapter(&client->dev, adap, client, force,
> + 0, NULL, pca9541_select_chan,
> pca9541_release_chan);
>
> if (data->mux_adap == NULL) {
> diff --git a/drivers/i2c/muxes/pca954x.c b/drivers/i2c/muxes/pca954x.c
> index 0e37ef2..736a803 100644
> --- a/drivers/i2c/muxes/pca954x.c
> +++ b/drivers/i2c/muxes/pca954x.c
> @@ -226,8 +226,8 @@ static int pca954x_probe(struct i2c_client *client,
> }
>
> data->virt_adaps[num] =
> - i2c_add_mux_adapter(adap, client,
> - force, num, pca954x_select_chan,
> + i2c_add_mux_adapter(&client->dev, adap, client,
> + force, num, NULL, pca954x_select_chan,
> (pdata && pdata->modes[num].deselect_on_exit)
> ? pca954x_deselect_mux : NULL);
>
> diff --git a/include/linux/i2c-mux.h b/include/linux/i2c-mux.h
> index 747f0cd..43fb11a 100644
> --- a/include/linux/i2c-mux.h
> +++ b/include/linux/i2c-mux.h
> @@ -33,8 +33,10 @@
> * and deselect callback functions to perform hardware-specific
> * mux control.
> */
> -struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
> +struct i2c_adapter *i2c_add_mux_adapter(struct device *dev,
> + struct i2c_adapter *parent,
> void *mux_dev, u32 force_nr, u32 chan_id,
> + const char *chan_name,
> int (*select) (struct i2c_adapter *,
> void *mux_dev, u32 chan_id),
> int (*deselect) (struct i2c_adapter *,
> --
> 1.7.0.4
>
--
Pengutronix e.K. | Wolfram Sang |
Industrial Linux Solutions | http://www.pengutronix.de/ |
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
next prev parent reply other threads:[~2012-04-23 11:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-17 18:49 [PATCH 1/2] i2c: mux: add device tree support Stephen Warren
[not found] ` <1334688545-8465-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-04-17 18:49 ` [PATCH 2/2] i2c: Add generic I2C multiplexer using pinctrl API Stephen Warren
[not found] ` <1334688545-8465-2-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-04-17 19:50 ` Linus Walleij
2012-04-23 11:15 ` Wolfram Sang [this message]
[not found] ` <20120423111507.GF19192-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-04-23 16:13 ` [PATCH 1/2] i2c: mux: add device tree support Stephen Warren
[not found] ` <4F957F9F.7000309-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-04-23 17:00 ` Wolfram Sang
2012-04-23 17:11 ` David Daney
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=20120423111507.GF19192@pengutronix.de \
--to=w.sang-bicnvbalz9megne8c9+irq@public.gmane.org \
--cc=ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org \
--cc=ddaney.cavm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
--cc=grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org \
--cc=linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org \
--cc=swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org \
--cc=swarren-DDmLM1+adcrQT0dZR+AlfA@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 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).