From: Jonathan Cameron <jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Peter Rosin <peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>,
Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
Hartmut Knaack <knaack.h-Mmb7MZpHnFY@public.gmane.org>,
Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>,
Peter Meerwald-Stadler
<pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org>,
Jonathan Corbet <corbet-T1hC0tSOHrs@public.gmane.org>,
Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>,
Greg Kroah-Hartman
<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>,
linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v6 7/9] i2c: i2c-mux-simple: new driver
Date: Sun, 1 Jan 2017 10:31:26 +0000 [thread overview]
Message-ID: <5632f73d-2a22-a7c0-8270-83348c4e432a@kernel.org> (raw)
In-Reply-To: <1480493823-21462-8-git-send-email-peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
On 30/11/16 08:17, Peter Rosin wrote:
> This is a generic simple i2c mux that uses the generic multiplexer
> subsystem to do the muxing.
>
> The user can select if the mux is to be mux-locked and parent-locked
> as described in Documentation/i2c/i2c-topology.
>
> Signed-off-by: Peter Rosin <peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
Looks good to me though as I haven't really commented on it I'll give
an Ack rather than a reviewed by.
Acked-by: Jonathan Cameron <jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> ---
> drivers/i2c/muxes/Kconfig | 13 +++
> drivers/i2c/muxes/Makefile | 1 +
> drivers/i2c/muxes/i2c-mux-simple.c | 179 +++++++++++++++++++++++++++++++++++++
> 3 files changed, 193 insertions(+)
> create mode 100644 drivers/i2c/muxes/i2c-mux-simple.c
>
> diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig
> index 10b3d17ae3ea..565921e09a96 100644
> --- a/drivers/i2c/muxes/Kconfig
> +++ b/drivers/i2c/muxes/Kconfig
> @@ -73,6 +73,19 @@ config I2C_MUX_REG
> This driver can also be built as a module. If so, the module
> will be called i2c-mux-reg.
>
> +config I2C_MUX_SIMPLE
> + tristate "Simple I2C multiplexer"
> + select MULTIPLEXER
> + depends on OF
> + help
> + If you say yes to this option, support will be included for a
> + simple generic I2C multiplexer. This driver provides access to
> + I2C busses connected through a MUX, which is controlled
> + by a generic MUX controller.
> +
> + This driver can also be built as a module. If so, the module
> + will be called i2c-mux-simple.
> +
> config I2C_DEMUX_PINCTRL
> tristate "pinctrl-based I2C demultiplexer"
> depends on PINCTRL && OF
> diff --git a/drivers/i2c/muxes/Makefile b/drivers/i2c/muxes/Makefile
> index 9948fa45037f..6821d95c92a3 100644
> --- a/drivers/i2c/muxes/Makefile
> +++ b/drivers/i2c/muxes/Makefile
> @@ -11,5 +11,6 @@ obj-$(CONFIG_I2C_MUX_PCA9541) += i2c-mux-pca9541.o
> obj-$(CONFIG_I2C_MUX_PCA954x) += i2c-mux-pca954x.o
> obj-$(CONFIG_I2C_MUX_PINCTRL) += i2c-mux-pinctrl.o
> obj-$(CONFIG_I2C_MUX_REG) += i2c-mux-reg.o
> +obj-$(CONFIG_I2C_MUX_SIMPLE) += i2c-mux-simple.o
>
> ccflags-$(CONFIG_I2C_DEBUG_BUS) := -DDEBUG
> diff --git a/drivers/i2c/muxes/i2c-mux-simple.c b/drivers/i2c/muxes/i2c-mux-simple.c
> new file mode 100644
> index 000000000000..4a03493e1ad7
> --- /dev/null
> +++ b/drivers/i2c/muxes/i2c-mux-simple.c
> @@ -0,0 +1,179 @@
> +/*
> + * Generic simple I2C multiplexer
> + *
> + * Copyright (C) 2016 Axentia Technologies AB
> + *
> + * Author: Peter Rosin <peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +#include <linux/i2c.h>
> +#include <linux/i2c-mux.h>
> +#include <linux/module.h>
> +#include <linux/mux.h>
> +#include <linux/of_device.h>
> +#include <linux/platform_device.h>
> +
> +struct mux {
> + struct mux_control *control;
> +
> + bool do_not_deselect;
> +};
> +
> +static int i2c_mux_select(struct i2c_mux_core *muxc, u32 chan)
> +{
> + struct mux *mux = i2c_mux_priv(muxc);
> + int ret;
> +
> + ret = mux_control_select(mux->control, chan);
> + mux->do_not_deselect = ret < 0;
> +
> + return ret;
> +}
> +
> +static int i2c_mux_deselect(struct i2c_mux_core *muxc, u32 chan)
> +{
> + struct mux *mux = i2c_mux_priv(muxc);
> +
> + if (mux->do_not_deselect)
> + return 0;
> +
> + return mux_control_deselect(mux->control);
> +}
> +
> +static struct i2c_adapter *mux_parent_adapter(struct device *dev)
> +{
> + struct device_node *np = dev->of_node;
> + struct device_node *parent_np;
> + struct i2c_adapter *parent;
> +
> + parent_np = of_parse_phandle(np, "i2c-parent", 0);
> + if (!parent_np) {
> + dev_err(dev, "Cannot parse i2c-parent\n");
> + return ERR_PTR(-ENODEV);
> + }
> + parent = of_find_i2c_adapter_by_node(parent_np);
> + of_node_put(parent_np);
> + if (!parent)
> + return ERR_PTR(-EPROBE_DEFER);
> +
> + return parent;
> +}
> +
> +static const struct of_device_id i2c_mux_of_match[] = {
> + { .compatible = "i2c-mux-simple,parent-locked",
> + .data = (void *)0, },
> + { .compatible = "i2c-mux-simple,mux-locked",
> + .data = (void *)1, },
> + {},
> +};
> +MODULE_DEVICE_TABLE(of, i2c_mux_of_match);
> +
> +static int i2c_mux_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct device_node *np = dev->of_node;
> + struct device_node *child;
> + const struct of_device_id *match;
> + struct i2c_mux_core *muxc;
> + struct mux *mux;
> + struct i2c_adapter *parent;
> + int children;
> + int ret;
> +
> + if (!np)
> + return -ENODEV;
> +
> + mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL);
> + if (!mux)
> + return -ENOMEM;
> +
> + mux->control = devm_mux_control_get(dev, NULL);
> + if (IS_ERR(mux->control)) {
> + if (PTR_ERR(mux->control) != -EPROBE_DEFER)
> + dev_err(dev, "failed to get control-mux\n");
> + return PTR_ERR(mux->control);
> + }
> +
> + parent = mux_parent_adapter(dev);
> + if (IS_ERR(parent)) {
> + if (PTR_ERR(parent) != -EPROBE_DEFER)
> + dev_err(dev, "failed to get i2c-parent adapter\n");
> + return PTR_ERR(parent);
> + }
> +
> + children = of_get_child_count(np);
> +
> + muxc = i2c_mux_alloc(parent, dev, children, 0, 0,
> + i2c_mux_select, i2c_mux_deselect);
> + if (!muxc) {
> + ret = -ENOMEM;
> + goto err_parent;
> + }
> + muxc->priv = mux;
> +
> + platform_set_drvdata(pdev, muxc);
> +
> + match = of_match_device(of_match_ptr(i2c_mux_of_match), dev);
> + if (match)
> + muxc->mux_locked = !!of_device_get_match_data(dev);
> +
> + for_each_child_of_node(np, child) {
> + u32 chan;
> +
> + ret = of_property_read_u32(child, "reg", &chan);
> + if (ret < 0) {
> + dev_err(dev, "no reg property for node '%s'\n",
> + child->name);
> + goto err_children;
> + }
> +
> + if (chan >= mux->control->states) {
> + dev_err(dev, "invalid reg %u\n", chan);
> + ret = -EINVAL;
> + goto err_children;
> + }
> +
> + ret = i2c_mux_add_adapter(muxc, 0, chan, 0);
> + if (ret)
> + goto err_children;
> + }
> +
> + dev_info(dev, "%d-port mux on %s adapter\n", children, parent->name);
> +
> + return 0;
> +
> +err_children:
> + i2c_mux_del_adapters(muxc);
> +err_parent:
> + i2c_put_adapter(parent);
> +
> + return ret;
> +}
> +
> +static int i2c_mux_remove(struct platform_device *pdev)
> +{
> + struct i2c_mux_core *muxc = platform_get_drvdata(pdev);
> +
> + i2c_mux_del_adapters(muxc);
> + i2c_put_adapter(muxc->parent);
> +
> + return 0;
> +}
> +
> +static struct platform_driver i2c_mux_driver = {
> + .probe = i2c_mux_probe,
> + .remove = i2c_mux_remove,
> + .driver = {
> + .name = "i2c-mux-simple",
> + .of_match_table = i2c_mux_of_match,
> + },
> +};
> +module_platform_driver(i2c_mux_driver);
> +
> +MODULE_DESCRIPTION("Simple I2C multiplexer driver");
> +MODULE_AUTHOR("Peter Rosin <peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>");
> +MODULE_LICENSE("GPL v2");
>
next prev parent reply other threads:[~2017-01-01 10:31 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-30 8:16 [PATCH v6 0/9] mux controller abstraction and iio/i2c muxes Peter Rosin
2016-11-30 8:16 ` [PATCH v6 2/9] misc: minimal mux subsystem and gpio-based mux controller Peter Rosin
2016-12-31 16:19 ` Jonathan Cameron
2017-01-02 9:14 ` Peter Rosin
[not found] ` <7080f03c-0ee3-13b2-b242-21f80052e479-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2017-01-02 9:20 ` Jonathan Cameron
2016-11-30 8:16 ` [PATCH v6 3/9] iio: inkern: api for manipulating ext_info of iio channels Peter Rosin
[not found] ` <1480493823-21462-4-git-send-email-peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2016-12-31 15:51 ` Jonathan Cameron
2016-11-30 8:16 ` [PATCH v6 4/9] dt-bindings: iio: iio-mux: document iio-mux bindings Peter Rosin
2016-11-30 8:52 ` Peter Rosin
2016-11-30 8:57 ` Peter Rosin
2016-12-05 23:26 ` Rob Herring
2016-12-06 9:18 ` Peter Rosin
[not found] ` <ea58cfe1-88ed-f215-59df-e9ffba485eaa-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2016-12-10 18:21 ` Jonathan Cameron
[not found] ` <d2726499-4034-8d5d-4cff-61da86af5add-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2016-12-12 12:18 ` Peter Rosin
2016-12-31 16:01 ` Jonathan Cameron
2016-11-30 8:16 ` [PATCH v6 5/9] iio: multiplexer: new iio category and iio-mux driver Peter Rosin
2016-12-31 16:21 ` Jonathan Cameron
2016-11-30 8:17 ` [PATCH v6 6/9] dt-bindings: i2c: i2c-mux-simple: document i2c-mux-simple bindings Peter Rosin
[not found] ` <1480493823-21462-1-git-send-email-peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2016-11-30 8:16 ` [PATCH v6 1/9] dt-bindings: document devicetree bindings for mux-controllers and mux-gpio Peter Rosin
2016-12-31 16:10 ` Jonathan Cameron
2016-11-30 8:17 ` [PATCH v6 7/9] i2c: i2c-mux-simple: new driver Peter Rosin
[not found] ` <1480493823-21462-8-git-send-email-peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2017-01-01 10:31 ` Jonathan Cameron [this message]
2017-01-01 15:38 ` Andy Shevchenko
[not found] ` <CAHp75Vc2uYhaYJu_eU-uBq_PZrUgaoNt8sxpuRF8eEEs2kPUwg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-02 15:30 ` Peter Rosin
2016-11-30 8:17 ` [PATCH v6 8/9] dt-bindings: mux-adg792a: document devicetree bindings for ADG792A/G mux Peter Rosin
2017-01-01 11:00 ` Jonathan Cameron
2017-01-02 16:01 ` Peter Rosin
2017-01-02 18:05 ` Jonathan Cameron
2017-01-02 20:47 ` Peter Rosin
2017-01-02 21:13 ` Jonathan Cameron
[not found] ` <90A8A4B3-670B-4409-B7AB-47BF4B2ABDDA-tko9wxEg+fIOOJlXag/Snyp2UmYkHbXO@public.gmane.org>
2017-01-03 6:44 ` Peter Rosin
2016-11-30 8:17 ` [PATCH v6 9/9] misc: mux-adg792a: add mux controller driver for ADG792A/G Peter Rosin
2017-01-01 11:24 ` Jonathan Cameron
2017-01-02 11:00 ` Peter Rosin
2017-01-02 18:08 ` Jonathan Cameron
2017-01-01 11:28 ` [PATCH v6 0/9] mux controller abstraction and iio/i2c muxes Jonathan Cameron
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=5632f73d-2a22-a7c0-8270-83348c4e432a@kernel.org \
--to=jic23-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
--cc=arnd-r2nGTMty4D4@public.gmane.org \
--cc=corbet-T1hC0tSOHrs@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
--cc=knaack.h-Mmb7MZpHnFY@public.gmane.org \
--cc=lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org \
--cc=linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
--cc=peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org \
--cc=pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=wsa-z923LK4zBo2bacvFa/9K2g@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).