devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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>,
	Andrew Morton
	<akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@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 v8 12/12] mux: support simplified bindings for single-user gpio mux
Date: Sun, 22 Jan 2017 13:30:02 +0000	[thread overview]
Message-ID: <33b29f7e-3e48-b85d-ccf9-93b1d67ac634@kernel.org> (raw)
In-Reply-To: <1484755035-25927-13-git-send-email-peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>

On 18/01/17 15:57, Peter Rosin wrote:
> Allow bindings for a GPIO controlled mux to be specified in the
> mux consumer node.
> 
> Signed-off-by: Peter Rosin <peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
Code is good as far as I am concerned. Only question is whether this
is worth the hassle given the normal bindings don't give that high
a burden in complexity!

I don't really care either way:)

> ---
>  drivers/mux/Kconfig    |  5 +----
>  drivers/mux/mux-core.c | 23 +++++++++++++++++++++--
>  drivers/mux/mux-gpio.c | 28 +++++++++++++++++++++-------
>  drivers/mux/mux-gpio.h | 13 +++++++++++++
>  4 files changed, 56 insertions(+), 13 deletions(-)
>  create mode 100644 drivers/mux/mux-gpio.h
> 
> diff --git a/drivers/mux/Kconfig b/drivers/mux/Kconfig
> index d13fcf98958e..cd161c228537 100644
> --- a/drivers/mux/Kconfig
> +++ b/drivers/mux/Kconfig
> @@ -29,7 +29,7 @@ config MUX_ADG792A
>  	  be called mux-adg792a.
>  
>  config MUX_GPIO
> -	tristate "GPIO-controlled Multiplexer"
> +	bool "GPIO-controlled Multiplexer"
>  	depends on OF && GPIOLIB
>  	help
>  	  GPIO-controlled Multiplexer controller.
> @@ -39,7 +39,4 @@ config MUX_GPIO
>  	  states. The GPIO pins can be connected (by the hardware) to several
>  	  multiplexers, which in that case will be operated in parallel.
>  
> -	  To compile the driver as a module, choose M here: the module will
> -	  be called mux-gpio.
> -
>  endif
> diff --git a/drivers/mux/mux-core.c b/drivers/mux/mux-core.c
> index 16a61253d164..0caafd6f5a77 100644
> --- a/drivers/mux/mux-core.c
> +++ b/drivers/mux/mux-core.c
> @@ -21,6 +21,8 @@
>  #include <linux/of_platform.h>
>  #include <linux/slab.h>
>  
> +#include "mux-gpio.h"
> +
>  static struct class mux_class = {
>  	.name = "mux",
>  	.owner = THIS_MODULE,
> @@ -314,9 +316,26 @@ struct mux_control *mux_control_get(struct device *dev, const char *mux_name)
>  	ret = of_parse_phandle_with_args(np,
>  					 "mux-controls", "#mux-control-cells",
>  					 index, &args);
> +
> +#ifdef CONFIG_MUX_GPIO
> +	if (ret == -ENOENT && !mux_name) {
> +		mux_chip = mux_gpio_alloc(dev);
> +		if (!IS_ERR(mux_chip)) {
> +			ret = devm_mux_chip_register(dev, mux_chip);
> +			if (ret < 0)
> +				return ERR_PTR(ret);
> +			get_device(&mux_chip->dev);
> +			return mux_chip->mux;
> +		}
> +
> +		ret = PTR_ERR(mux_chip);
> +	}
> +#endif
> +
>  	if (ret) {
> -		dev_err(dev, "%s: failed to get mux-control %s(%i)\n",
> -			np->full_name, mux_name ?: "", index);
> +		if (ret != -EPROBE_DEFER)
> +			dev_err(dev, "%s: failed to get mux-control %s(%i)\n",
> +				np->full_name, mux_name ?: "", index);
>  		return ERR_PTR(ret);
>  	}
>  
> diff --git a/drivers/mux/mux-gpio.c b/drivers/mux/mux-gpio.c
> index 48ca4d6b4fc7..2ab8735e3415 100644
> --- a/drivers/mux/mux-gpio.c
> +++ b/drivers/mux/mux-gpio.c
> @@ -18,6 +18,8 @@
>  #include <linux/platform_device.h>
>  #include <linux/property.h>
>  
> +#include "mux-gpio.h"
> +
>  struct mux_gpio {
>  	struct gpio_descs *gpios;
>  	int *val;
> @@ -48,24 +50,21 @@ static const struct of_device_id mux_gpio_dt_ids[] = {
>  };
>  MODULE_DEVICE_TABLE(of, mux_gpio_dt_ids);
>  
> -static int mux_gpio_probe(struct platform_device *pdev)
> +struct mux_chip *mux_gpio_alloc(struct device *dev)
>  {
> -	struct device *dev = &pdev->dev;
> -	struct device_node *np = dev->of_node;
>  	struct mux_chip *mux_chip;
>  	struct mux_gpio *mux_gpio;
>  	int pins;
> -	u32 idle_state;
>  	int ret;
>  
>  	pins = gpiod_count(dev, "mux");
>  	if (pins < 0)
> -		return pins;
> +		return ERR_PTR(pins);
>  
>  	mux_chip = devm_mux_chip_alloc(dev, 1, sizeof(*mux_gpio) +
>  				       pins * sizeof(*mux_gpio->val));
>  	if (!mux_chip)
> -		return -ENOMEM;
> +		return ERR_PTR(-ENOMEM);
>  
>  	mux_gpio = mux_chip_priv(mux_chip);
>  	mux_gpio->val = (int *)(mux_gpio + 1);
> @@ -76,11 +75,26 @@ static int mux_gpio_probe(struct platform_device *pdev)
>  		ret = PTR_ERR(mux_gpio->gpios);
>  		if (ret != -EPROBE_DEFER)
>  			dev_err(dev, "failed to get gpios\n");
> -		return ret;
> +		return ERR_PTR(ret);
>  	}
>  	WARN_ON(pins != mux_gpio->gpios->ndescs);
>  	mux_chip->mux->states = 1 << pins;
>  
> +	return mux_chip;
> +}
> +EXPORT_SYMBOL_GPL(mux_gpio_alloc);
> +
> +static int mux_gpio_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct mux_chip *mux_chip;
> +	u32 idle_state;
> +	int ret;
> +
> +	mux_chip = mux_gpio_alloc(dev);
> +	if (IS_ERR(mux_chip))
> +		return PTR_ERR(mux_chip);
> +
>  	ret = device_property_read_u32(dev, "idle-state", &idle_state);
>  	if (ret >= 0) {
>  		if (idle_state >= mux_chip->mux->states) {
> diff --git a/drivers/mux/mux-gpio.h b/drivers/mux/mux-gpio.h
> new file mode 100644
> index 000000000000..fe3e8d0173aa
> --- /dev/null
> +++ b/drivers/mux/mux-gpio.h
> @@ -0,0 +1,13 @@
> +/*
> + * GPIO-controlled multiplexer driver interface
> + *
> + * Copyright (C) 2017 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.
> + */
> +
> +struct mux_chip *mux_gpio_alloc(struct device *dev);
> 

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2017-01-22 13:30 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-18 15:57 [PATCH v8 00/12] mux controller abstraction and iio/i2c muxes Peter Rosin
2017-01-18 15:57 ` [PATCH v8 01/12] devres: trivial whitespace fix Peter Rosin
2017-01-18 15:57 ` [PATCH v8 02/12] dt-bindings: document devicetree bindings for mux-controllers and mux-gpio Peter Rosin
     [not found]   ` <1484755035-25927-3-git-send-email-peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2017-01-27 17:49     ` Rob Herring
2017-01-27 18:57       ` Peter Rosin
2017-01-18 15:57 ` [PATCH v8 03/12] mux: minimal mux subsystem and gpio-based mux controller Peter Rosin
2017-01-18 15:57 ` [PATCH v8 04/12] iio: inkern: api for manipulating ext_info of iio channels Peter Rosin
2017-01-18 15:57 ` [PATCH v8 05/12] dt-bindings: iio: io-channel-mux: document io-channel-mux bindings Peter Rosin
2017-01-27 19:12   ` Rob Herring
2017-01-18 15:57 ` [PATCH v8 06/12] iio: multiplexer: new iio category and iio-mux driver Peter Rosin
2017-01-18 15:57 ` [PATCH v8 07/12] dt-bindings: i2c: i2c-mux-simple: document i2c-mux-simple bindings Peter Rosin
2017-01-27 19:39   ` Rob Herring
2017-01-28 22:42     ` Peter Rosin
     [not found]       ` <835415bf-77af-6131-d018-d0bc7d8233b0-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2017-01-30 17:20         ` Rob Herring
     [not found]           ` <CAL_JsqLVrzm4BEv3kpOGRoaRq+cqvSm+A6weZfU8H8i9dc=tcA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-31  7:36             ` Peter Rosin
2017-02-02 16:08               ` Rob Herring
2017-02-03  8:25                 ` Peter Rosin
     [not found]                   ` <5dc05e28-45c7-1dfe-3cd2-53e55490b48a-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2017-02-06 21:22                     ` Rob Herring
     [not found] ` <1484755035-25927-1-git-send-email-peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2017-01-18 15:57   ` [PATCH v8 08/12] i2c: i2c-mux-simple: new driver Peter Rosin
2017-01-18 15:57 ` [PATCH v8 09/12] dt-bindings: mux-adg792a: document devicetree bindings for ADG792A/G mux Peter Rosin
2017-01-27 19:50   ` Rob Herring
2017-01-27 22:09     ` Peter Rosin
     [not found]       ` <383638ef-1bb2-224f-0fd0-4818395a2306-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2017-01-28 10:34         ` Peter Meerwald-Stadler
2017-01-28 11:40       ` Jonathan Cameron
2017-01-18 15:57 ` [PATCH v8 10/12] mux: adg792a: add mux controller driver for ADG792A/G Peter Rosin
2017-01-18 15:57 ` [PATCH v8 11/12] dt-bindings: simplified bindings for single-user gpio mux Peter Rosin
2017-01-18 15:57 ` [PATCH v8 12/12] mux: support " Peter Rosin
     [not found]   ` <1484755035-25927-13-git-send-email-peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2017-01-22 13:30     ` Jonathan Cameron [this message]
2017-01-23 10:24       ` Peter Rosin
2017-01-27 15:52         ` Rob Herring
2017-01-30  8:02           ` Peter Rosin

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=33b29f7e-3e48-b85d-ccf9-93b1d67ac634@kernel.org \
    --to=jic23-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
    --cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
    --cc=corbet-T1hC0tSOHrs@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@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).