From: Peter Rosin <peda@axentia.se>
To: <linux-kernel@vger.kernel.org>
Cc: Peter Rosin <peda@axentia.se>, Wolfram Sang <wsa@the-dreams.de>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Jonathan Cameron <jic23@kernel.org>,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
Jonathan Corbet <corbet@lwn.net>,
Andrew Morton <akpm@linux-foundation.org>,
<linux-i2c@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-iio@vger.kernel.org>, <linux-doc@vger.kernel.org>
Subject: [PATCH v8 12/12] mux: support simplified bindings for single-user gpio mux
Date: Wed, 18 Jan 2017 16:57:15 +0100 [thread overview]
Message-ID: <1484755035-25927-13-git-send-email-peda@axentia.se> (raw)
In-Reply-To: <1484755035-25927-1-git-send-email-peda@axentia.se>
Allow bindings for a GPIO controlled mux to be specified in the
mux consumer node.
Signed-off-by: Peter Rosin <peda@axentia.se>
---
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@axentia.se>
+ *
+ * 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);
--
2.1.4
next prev parent reply other threads:[~2017-01-18 16:04 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
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
2017-01-30 17:20 ` Rob Herring
2017-01-31 7:36 ` Peter Rosin
2017-02-02 16:08 ` Rob Herring
2017-02-03 8:25 ` Peter Rosin
2017-02-06 21:22 ` Rob Herring
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
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 ` Peter Rosin [this message]
2017-01-22 13:30 ` [PATCH v8 12/12] mux: support " Jonathan Cameron
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=1484755035-25927-13-git-send-email-peda@axentia.se \
--to=peda@axentia.se \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-doc@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=pmeerw@pmeerw.net \
--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
all inboxes | Powered by JetHome®