From: Drew Fustini <drew@beagleboard.org>
To: Mauri Sandberg <sandberg@mailfence.com>
Cc: linux-gpio@vger.kernel.org, andy.shevchenko@gmail.com,
linus.walleij@linaro.org, bgolaszewski@baylibre.com,
geert+renesas@glider.be
Subject: Re: [RFC gpio/for-next 2/2] gpio: gpio-mux-input: add generic gpio input multiplexer
Date: Thu, 25 Mar 2021 23:59:44 -0700 [thread overview]
Message-ID: <20210326065944.GA834818@x1> (raw)
In-Reply-To: <20210325122832.119147-3-sandberg@mailfence.com>
On Thu, Mar 25, 2021 at 02:28:32PM +0200, Mauri Sandberg wrote:
> Suppport for a general GPIO multiplexer. To drive the multiplexer a
> mux-controller is needed. The output pin of the multiplexer is a GPIO
> pin
>
> Signed-off-by: Mauri Sandberg <sandberg@mailfence.com>
Thanks for posting the RFC so we can take a look at the code and discuss
how it works.
> ---
> drivers/gpio/Kconfig | 11 +++
> drivers/gpio/Makefile | 1 +
> drivers/gpio/gpio-mux-input.c | 143 ++++++++++++++++++++++++++++++++++
> 3 files changed, 155 insertions(+)
> create mode 100644 drivers/gpio/gpio-mux-input.c
>
> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> index c70f46e80a3b..41062d8f7d93 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -1641,4 +1641,15 @@ config GPIO_MOCKUP
>
> endmenu
>
> +comment "Other GPIO expanders"
> +
> +config GPIO_MUX_INPUT
> + tristate "General GPIO input multiplexer"
> + select MULTIPLEXER
> + select MUX_GPIO
> + depends on OF_GPIO
> + help
> + Say yes here to enable support for generic GPIO input multiplexer. This
> + needs a multiplexer controller to drive the select pins.
> +
> endif
> diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
> index 35e3b6026665..00f7576ce23f 100644
> --- a/drivers/gpio/Makefile
> +++ b/drivers/gpio/Makefile
> @@ -105,6 +105,7 @@ obj-$(CONFIG_GPIO_MPC8XXX) += gpio-mpc8xxx.o
> obj-$(CONFIG_GPIO_MSC313) += gpio-msc313.o
> obj-$(CONFIG_GPIO_MSIC) += gpio-msic.o
> obj-$(CONFIG_GPIO_MT7621) += gpio-mt7621.o
> +obj-$(CONFIG_GPIO_MUX_INPUT) += gpio-mux-input.o
> obj-$(CONFIG_GPIO_MVEBU) += gpio-mvebu.o
> obj-$(CONFIG_GPIO_MXC) += gpio-mxc.o
> obj-$(CONFIG_GPIO_MXS) += gpio-mxs.o
This does not apply to mainline. I've added it manually to my
drivers/gpio/Makefile but something to fix in v2.
> diff --git a/drivers/gpio/gpio-mux-input.c b/drivers/gpio/gpio-mux-input.c
> new file mode 100644
> index 000000000000..ec0c7acbab2f
> --- /dev/null
> +++ b/drivers/gpio/gpio-mux-input.c
> @@ -0,0 +1,143 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * A generic GPIO input multiplexer driver
> + *
> + * Copyright (C) 2021 Mauri Sandberg <sandberg@mailfence.com>
> + *
> + */
> +
> +#include <linux/module.h>
> +#include <linux/gpio/consumer.h>
> +#include <linux/gpio/driver.h>
> +#include <linux/slab.h>
> +#include <linux/platform_device.h>
> +#include <linux/mux/consumer.h>
> +
> +struct gpio_mux_input {
> + struct device *parent;
> + struct gpio_chip gpio_chip;
> + struct mux_control *mux_control;
> + struct gpio_desc *mux_pin;
> +};
> +
> +static struct gpio_mux_input *gpio_to_mux(struct gpio_chip *gc)
> +{
> + return container_of(gc, struct gpio_mux_input, gpio_chip);
> +}
> +
> +static int gpio_mux_input_direction_input(struct gpio_chip *gc,
> + unsigned int offset)
> +{
> + return 0;
> +}
> +
> +static int gpio_mux_input_direction_output(struct gpio_chip *gc,
> + unsigned int offset, int val)
> +{
> + return -EINVAL;
> +}
> +
> +static int gpio_mux_input_get_value(struct gpio_chip *gc, unsigned int offset)
> +{
> + struct gpio_mux_input *mux;
> + int ret;
> +
> + mux = gpio_to_mux(gc);
> + ret = mux_control_select(mux->mux_control, offset);
> + if (ret)
> + return ret;
> +
> + ret = gpiod_get_value(mux->mux_pin);
I'm not too familiar with how mux_control works but does there need to
be locking here?
Or is not possible for mux_pin to change to another offset before if
gpiod_get_value() if gpio_mux_input_get_value() runs concurrently?
> + mux_control_deselect(mux->mux_control);
> + return ret;
> +}
> +
> +static void gpio_mux_input_set_value(struct gpio_chip *gc,
> + unsigned int offset, int val)
> +{
> + /* not supported */
I'm not sure but maybe it is better not to define gc->set in the probe?
> +}
> +
> +static int gpio_mux_input_probe(struct platform_device *pdev)
> +{
> + struct device_node *np = pdev->dev.of_node;
> + struct gpio_mux_input *mux;
> + struct gpio_chip *gc;
> + struct mux_control *mc;
> + struct gpio_desc *pin;
> + int err;
> +
> + mux = kzalloc(sizeof(struct gpio_mux_input), GFP_KERNEL);
> + if (mux == NULL)
> + return -ENOMEM;
> +
> + mc = mux_control_get(&pdev->dev, NULL);
> + if (IS_ERR(mc)) {
> + err = (int) PTR_ERR(mc);
> + if (err != -EPROBE_DEFER)
> + dev_err(&pdev->dev, "unable to get mux-control: %d\n",
> + err);
> + goto err_free_mux;
> + }
> +
> + mux->mux_control = mc;
> + pin = gpiod_get(&pdev->dev, "pin", GPIOD_IN);
> + if (IS_ERR(pin)) {
> + err = (int) PTR_ERR(pin);
> + dev_err(&pdev->dev, "unable to claim pin GPIOs: %d\n", err);
> + goto err_free_mc;
> + }
> +
> + mux->mux_pin = pin;
> + mux->parent = &pdev->dev;
> +
> + gc = &mux->gpio_chip;
> + gc->direction_input = gpio_mux_input_direction_input;
> + gc->direction_output = gpio_mux_input_direction_output;
> + gc->get = gpio_mux_input_get_value;
> + gc->set = gpio_mux_input_set_value;
> + gc->can_sleep = 1;
> +
> + gc->base = -1;
> + gc->ngpio = mux_control_states(mc);
> + gc->label = dev_name(mux->parent);
> + gc->parent = mux->parent;
> + gc->owner = THIS_MODULE;
> + gc->of_node = np;
> +
> + err = gpiochip_add(&mux->gpio_chip);
> + if (err) {
> + dev_err(&pdev->dev, "unable to add gpio chip, err=%d\n", err);
> + goto err_free_pin;
> + }
> +
> + platform_set_drvdata(pdev, mux);
> + return 0;
> +
> +err_free_pin:
> + gpiod_put(pin);
> +err_free_mc:
> + mux_control_put(mc);
> +err_free_mux:
> + kfree(mux);
> + return err;
> +}
> +
> +static const struct of_device_id gpio_mux_input_id[] = {
> + {
> + .compatible = "gpio-mux-input",
> + .data = NULL,
> + },
> + { /* sentinel */ }
> +};
> +MODULE_DEVICE_TABLE(of, gpio_mux_input_id);
> +
> +static struct platform_driver gpio_mux_input_driver = {
> + .driver = {
> + .name = "gpio-mux-input",
> + .owner = THIS_MODULE,
> + .of_match_table = gpio_mux_input_id,
> + },
> + .probe = gpio_mux_input_probe,
> +};
> +module_platform_driver(gpio_mux_input_driver);
I believe you need to add:
MODULE_AUTHOR("...");
MODULE_DESCRIPTION("...");
MODULE_LICENSE("GPL");
My build failed with:
ERROR: modpost: missing MODULE_LICENSE() in drivers/gpio/gpio-mux-input.o
LZMA arch/arm/boot/compressed/piggy_data
make[1]: *** [scripts/Makefile.modpost:132: Module.symvers] Error 1
make[1]: *** Deleting file 'Module.symvers'
make: *** [Makefile:1442: modules] Error 2
make: *** Waiting for unfinished jobs....
AS arch/arm/boot/compressed/piggy.o
LD arch/arm/boot/compressed/vmlinux
OBJCOPY arch/arm/boot/zImage
Kernel: arch/arm/boot/zImage is ready
I added those lines and it compiled successfully.
-Drew
next prev parent reply other threads:[~2021-03-26 7:00 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-25 12:28 [RFC gpio/for-next 0/2] gpio: add generic gpio input multiplexer Mauri Sandberg
2021-03-25 12:28 ` [RFC gpio/for-next 1/2] dt-bindings: gpio-mux-input: add documentation Mauri Sandberg
2021-03-25 12:28 ` [RFC gpio/for-next 2/2] gpio: gpio-mux-input: add generic gpio input multiplexer Mauri Sandberg
2021-03-25 23:08 ` kernel test robot
2021-03-25 23:08 ` [PATCH] gpio: gpio-mux-input: fix platform_no_drv_owner.cocci warnings kernel test robot
2021-03-26 6:59 ` Drew Fustini [this message]
2021-03-26 10:32 ` [RFC gpio/for-next 2/2] gpio: gpio-mux-input: add generic gpio input multiplexer Mauri Sandberg
2021-03-26 10:49 ` Andy Shevchenko
2021-03-29 13:57 ` [RFC v2 0/2] gpio: " Mauri Sandberg
2021-03-29 13:57 ` [RFC v2 1/2] dt-bindings: gpio-mux-input: add documentation Mauri Sandberg
2021-03-29 13:57 ` [RFC v2 2/2] gpio: gpio-mux-input: add generic gpio input multiplexer Mauri Sandberg
2021-05-17 16:58 ` [PATCH v3 0/2] gpio: " Mauri Sandberg
2021-05-17 16:58 ` [PATCH v3 1/2] dt-bindings: gpio-mux-input: add documentation Mauri Sandberg
2021-05-17 16:58 ` [PATCH v3 2/2] gpio: gpio-mux-input: add generic gpio input multiplexer Mauri Sandberg
2021-05-17 22:13 ` [PATCH v3 0/2] gpio: " Drew Fustini
2021-05-28 0:23 ` Linus Walleij
2021-05-28 0:27 ` Drew Fustini
2021-05-24 21:25 ` Drew Fustini
2021-05-24 16:29 ` RESEND PATCH v3 Mauri Sandberg
2021-05-24 16:29 ` [PATCH v3 1/2] dt-bindings: gpio-mux-input: add documentation Mauri Sandberg
2021-05-24 16:29 ` [PATCH v3 2/2] gpio: gpio-mux-input: add generic gpio input multiplexer Mauri Sandberg
2021-05-24 21:29 ` RESEND PATCH v3 Drew Fustini
2021-05-30 16:13 ` [PATCH v4 0/2] gpio: add generic gpio input multiplexer Mauri Sandberg
2021-05-30 16:13 ` [PATCH v4 1/2] dt-bindings: gpio-mux-input: add documentation Mauri Sandberg
2021-06-01 10:10 ` Linus Walleij
2021-06-01 10:44 ` Linus Walleij
2021-06-02 9:31 ` Mauri Sandberg
2021-06-02 10:35 ` Linus Walleij
2021-06-02 11:21 ` Mauri Sandberg
2021-06-04 7:51 ` Linus Walleij
2021-06-01 13:32 ` Rob Herring
2021-06-02 11:36 ` Mauri Sandberg
2021-05-30 16:13 ` [PATCH v4 2/2] gpio: gpio-mux-input: add generic gpio input multiplexer Mauri Sandberg
2021-05-30 18:09 ` Andy Shevchenko
2021-05-30 19:02 ` Mauri Sandberg
2021-05-30 19:38 ` Andy Shevchenko
2021-05-31 10:19 ` Mauri Sandberg
2021-06-01 10:38 ` Linus Walleij
2021-06-21 17:20 ` [PATCH v5 0/2] gpio: add generic gpio cascade Mauri Sandberg
2021-06-21 17:20 ` [PATCH v5 1/2] dt-bindings: gpio-cascade: add documentation Mauri Sandberg
2021-06-24 18:30 ` Rob Herring
2021-06-21 17:20 ` [PATCH v5 2/2] gpio: gpio-cascade: add generic GPIO cascade Mauri Sandberg
2021-06-21 17:43 ` Andy Shevchenko
2021-06-21 18:31 ` Enrico Weigelt, metux IT consult
2021-10-15 12:56 ` Mauri Sandberg
2021-10-15 17:20 ` Andy Shevchenko
2021-10-19 12:57 ` [PATCH v6 0/2] " Mauri Sandberg
2021-10-19 12:57 ` [PATCH v6 1/2] dt-bindings: gpio-cascade: add documentation Mauri Sandberg
2021-10-19 12:57 ` [PATCH v6 2/2] gpio: gpio-cascade: add generic GPIO cascade Mauri Sandberg
2021-10-19 13:12 ` Andy Shevchenko
2021-10-19 20:08 ` [PATCH v7 0/2] " Mauri Sandberg
2021-10-19 20:08 ` [PATCH v7 1/2] dt-bindings: gpio-cascade: add documentation Mauri Sandberg
2021-10-24 22:18 ` Linus Walleij
2021-10-19 20:08 ` [PATCH v7 2/2] gpio: gpio-cascade: add generic GPIO cascade Mauri Sandberg
2021-10-24 22:17 ` Linus Walleij
2021-10-25 9:29 ` Andy Shevchenko
2021-10-26 19:15 ` [PATCH v8 0/2] " Mauri Sandberg
2021-10-26 19:15 ` [PATCH v8 1/2] dt-bindings: gpio-cascade: add documentation Mauri Sandberg
2021-10-26 19:15 ` [PATCH v8 2/2] gpio: gpio-cascade: add generic GPIO cascade Mauri Sandberg
2022-02-05 21:59 ` [RESEND v8 0/2] " Mauri Sandberg
2022-02-05 21:59 ` [RESEND v8 1/2] dt-bindings: gpio-cascade: add documentation Mauri Sandberg
2022-02-05 21:59 ` [RESEND v8 2/2] gpio: gpio-cascade: add generic GPIO cascade Mauri Sandberg
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=20210326065944.GA834818@x1 \
--to=drew@beagleboard.org \
--cc=andy.shevchenko@gmail.com \
--cc=bgolaszewski@baylibre.com \
--cc=geert+renesas@glider.be \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=sandberg@mailfence.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.