From patchwork Mon May 17 16:58:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauri Sandberg X-Patchwork-Id: 440341 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34939C433ED for ; Mon, 17 May 2021 16:59:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0D76C61185 for ; Mon, 17 May 2021 16:59:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236000AbhEQRAj (ORCPT ); Mon, 17 May 2021 13:00:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236776AbhEQRAi (ORCPT ); Mon, 17 May 2021 13:00:38 -0400 Received: from mail.kapsi.fi (mail.kapsi.fi [IPv6:2001:67c:1be8::25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 224C0C061756 for ; Mon, 17 May 2021 09:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kapsi.fi; s=20161220; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=FNchyohTk64OPI3ZQ9BXTbaOFALE2D5YS8PQlfIT8Q4=; b=X4U46V3SddCapP1G/LJEqHZPcf oHPzbd+BJWrmyu2bsUcRYa/9tk5iBIEzkBDOAVkeUNRXvbK2uFmUK+PDClGDCM7Ofpdk4EaPRlYSq OOYVKwYFMFAjpL64tMQo1m6olEGNYOOCoPASAMPPfdmaCVFapTfXKgaJRgGCQ/QJdYONh/aG10c7C bkj7gGMvgQNjXsO1d1lTkYvQXz194uKhVekru6ZzEbTeVwf+0bwELBzp4r+5csfiHb/SyUldrxphI X9ULL6dk2zB+L+xtpaS9qO6LlzN/yBbLivu2I9Ox0S3E+1QxVbfZOWXLXvCHvl/ThGCJTwY0ts7Ed 7udJAE6A==; Received: from 164-105-191-90.dyn.estpak.ee ([90.191.105.164] helo=ubuntu) by mail.kapsi.fi with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1ligaL-0003AM-4G; Mon, 17 May 2021 19:59:18 +0300 Received: by ubuntu (sSMTP sendmail emulation); Mon, 17 May 2021 19:59:16 +0300 From: Mauri Sandberg To: sandberg@mailfence.com Cc: andy.shevchenko@gmail.com, bgolaszewski@baylibre.com, geert+renesas@glider.be, linus.walleij@linaro.org, linux-gpio@vger.kernel.org, drew@beagleboard.org Subject: [PATCH v3 1/2] dt-bindings: gpio-mux-input: add documentation Date: Mon, 17 May 2021 19:58:46 +0300 Message-Id: <20210517165847.206316-2-sandberg@mailfence.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210517165847.206316-1-sandberg@mailfence.com> References: <20210325122832.119147-1-sandberg@mailfence.com> <20210517165847.206316-1-sandberg@mailfence.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 90.191.105.164 X-SA-Exim-Mail-From: sandberg@mailfence.com X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add documentation for a general GPIO multiplexer. Signed-off-by: Mauri Sandberg --- v2 -> v3: added a complete example on dual 4-way multiplexer v1 -> v2: added a little bit more text in the binding documenation --- .../bindings/gpio/gpio-mux-input.yaml | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-mux-input.yaml diff --git a/Documentation/devicetree/bindings/gpio/gpio-mux-input.yaml b/Documentation/devicetree/bindings/gpio/gpio-mux-input.yaml new file mode 100644 index 000000000000..a7ff5d1fd6f3 --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/gpio-mux-input.yaml @@ -0,0 +1,75 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/gpio/gpio-mux-input.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Generic GPIO input multiplexer + +maintainers: + - Mauri Sandberg + +description: | + A generic GPIO based input multiplexer + + This driver uses a mux-controller to drive the multiplexer and has a single + output pin for reading the inputs to the mux. + + For GPIO consumer documentation see gpio.txt. + +properties: + compatible: + enum: + - gpio-mux-input + + gpio-controller: true + + '#gpio-cells': + const: 2 + + pin-gpios: + description: | + The GPIO pin used as the output from the multiplexer + +required: + - compatible + - gpio-controller + - "#gpio-cells" + - pin-gpios + +additionalProperties: false + +examples: + - | + #include + mux: mux-controller { + compatible = "gpio-mux"; + #mux-control-cells = <0>; + + mux-gpios = <&gpio 9 GPIO_ACTIVE_HIGH>, + <&gpio 11 GPIO_ACTIVE_HIGH>; + }; + + gpio2: key-mux1 { + compatible = "gpio-mux-input"; + mux-controls = <&mux>; + + gpio-controller; + #gpio-cells = <2>; + + // GPIOs used by this node, mux pin + pin-gpios = <&gpio 12 GPIO_ACTIVE_HIGH>; + }; + + gpio3: key-mux2 { + compatible = "gpio-mux-input"; + mux-controls = <&mux>; + + gpio-controller; + #gpio-cells = <2>; + + // GPIOs used by this node, mux pin + pin-gpios = <&gpio 14 GPIO_ACTIVE_HIGH>; + }; + +... From patchwork Mon May 17 16:58:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauri Sandberg X-Patchwork-Id: 441485 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAF4AC433ED for ; Mon, 17 May 2021 16:59:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90435611C2 for ; Mon, 17 May 2021 16:59:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237801AbhEQRAq (ORCPT ); Mon, 17 May 2021 13:00:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236776AbhEQRAq (ORCPT ); Mon, 17 May 2021 13:00:46 -0400 Received: from mail.kapsi.fi (mail.kapsi.fi [IPv6:2001:67c:1be8::25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 879DFC061573 for ; Mon, 17 May 2021 09:59:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kapsi.fi; s=20161220; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=o2Af4r6ondZLXI+wXQ/vPcbCdKAE02a1WwUiFgRTyC0=; b=f3sLJ2tL1QnabOxyMLsJ4GxT4A TUFDfAWhC5IftcucM6TrjDs5m5otgGOKNoV26OjEajgEEhbweqZWVrGQq5x6WIWNCKGBVGNfqOmVL AmXq0TLMUNr60fMTt1ZSAZBlXxscileftL8k2A+FTZq9xULb8iUPIbnrOBPEzJE/6Fj7APlVBsZVL 9k1xJfyGo5EhpXrN0ljYIzr5bHzdzJBC54mloadjzgf/UJdBYXL/ffTGj/BJ2RQxnxmBqf7a++gf/ NT908puK99Z6vgN6Rwt6GfEjuecxaWAaumX0ivduD609IUDVJYvxy1J4pAoLt5SevYfNGR8ZLa0GH juEda7yQ==; Received: from 164-105-191-90.dyn.estpak.ee ([90.191.105.164] helo=ubuntu) by mail.kapsi.fi with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1ligaO-0003BP-Av; Mon, 17 May 2021 19:59:21 +0300 Received: by ubuntu (sSMTP sendmail emulation); Mon, 17 May 2021 19:59:19 +0300 From: Mauri Sandberg To: sandberg@mailfence.com Cc: andy.shevchenko@gmail.com, bgolaszewski@baylibre.com, geert+renesas@glider.be, linus.walleij@linaro.org, linux-gpio@vger.kernel.org, drew@beagleboard.org, kernel test robot Subject: [PATCH v3 2/2] gpio: gpio-mux-input: add generic gpio input multiplexer Date: Mon, 17 May 2021 19:58:47 +0300 Message-Id: <20210517165847.206316-3-sandberg@mailfence.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210517165847.206316-1-sandberg@mailfence.com> References: <20210325122832.119147-1-sandberg@mailfence.com> <20210517165847.206316-1-sandberg@mailfence.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 90.191.105.164 X-SA-Exim-Mail-From: sandberg@mailfence.com X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Adds support for a generic GPIO multiplexer. To drive the multiplexer a mux-controller is needed. The output pin of the multiplexer is a GPIO pin. Reported-by: kernel test robot Signed-off-by: Mauri Sandberg --- v2 -> v3: - use managed device resources - update Kconfig description v1 -> v2: - removed .owner from platform_driver as per test bot's instruction - added MODULE_AUTHOR, MODULE_DESCRIPTION, MODULE_LICENSE - added gpio_mux_input_get_direction as it's recommended for all chips - removed because this is input only chip: gpio_mux_input_set_value - removed because they are not needed for input/output only chips: gpio_mux_input_direction_input gpio_mux_input_direction_output - fixed typo in an error message - added info message about successful registration - removed can_sleep flag as this does not sleep while getting GPIO value like I2C or SPI do - Updated description in Kconfig --- drivers/gpio/Kconfig | 16 +++++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-mux-input.c | 124 ++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 drivers/gpio/gpio-mux-input.c diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 1dd0ec6727fd..b7dd4ba59e6e 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1657,4 +1657,20 @@ config GPIO_MOCKUP endmenu +comment "Other GPIO expanders" + +config GPIO_MUX_INPUT + tristate "General GPIO input multiplexer" + depends on OF_GPIO + select MULTIPLEXER + select MUX_GPIO + help + Say yes here to enable support for generic GPIO input multiplexer. + + This driver uses a mux-controller to drive the multiplexer and has a + single output pin for reading the inputs to the mux. The driver can be + used in situations when GPIO pins are used to select what multiplexer + pin should be used for reading input and the output pin of the + multiplexer is connected to a GPIO input pin. + endif diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index d7c81e1611a4..ff2b530d8ef4 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -104,6 +104,7 @@ obj-$(CONFIG_GPIO_MPC5200) += gpio-mpc5200.o obj-$(CONFIG_GPIO_MPC8XXX) += gpio-mpc8xxx.o obj-$(CONFIG_GPIO_MSC313) += gpio-msc313.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 diff --git a/drivers/gpio/gpio-mux-input.c b/drivers/gpio/gpio-mux-input.c new file mode 100644 index 000000000000..3c41e6f47012 --- /dev/null +++ b/drivers/gpio/gpio-mux-input.c @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * A generic GPIO input multiplexer driver + * + * Copyright (C) 2021 Mauri Sandberg + * + */ + +#include +#include +#include +#include +#include +#include + +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_get_direction(struct gpio_chip *gc, + unsigned int offset) +{ + return GPIO_LINE_DIRECTION_IN; +} + +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); + mux_control_deselect(mux->mux_control); + return ret; +} + +static int gpio_mux_input_probe(struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + struct device *dev = &pdev->dev; + struct gpio_mux_input *mux; + struct mux_control *mc; + struct gpio_desc *pin; + struct gpio_chip *gc; + int err; + + mux = devm_kzalloc(dev, sizeof(struct gpio_mux_input), GFP_KERNEL); + if (mux == NULL) + return -ENOMEM; + + mc = devm_mux_control_get(dev, NULL); + if (IS_ERR(mc)) { + err = (int) PTR_ERR(mc); + if (err != -EPROBE_DEFER) + dev_err(dev, "unable to get mux-control: %d\n", err); + return err; + } + + mux->mux_control = mc; + pin = devm_gpiod_get(dev, "pin", GPIOD_IN); + if (IS_ERR(pin)) { + err = (int) PTR_ERR(pin); + dev_err(dev, "unable to claim output pin: %d\n", err); + return err; + } + + mux->mux_pin = pin; + mux->parent = dev; + + gc = &mux->gpio_chip; + gc->get = gpio_mux_input_get_value; + gc->get_direction = gpio_mux_input_get_direction; + + 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(dev, "unable to add gpio chip, err=%d\n", err); + return err; + } + + platform_set_drvdata(pdev, mux); + dev_info(dev, "registered %u input GPIOs\n", gc->ngpio); + return 0; +} + +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", + .of_match_table = gpio_mux_input_id, + }, + .probe = gpio_mux_input_probe, +}; +module_platform_driver(gpio_mux_input_driver); + +MODULE_AUTHOR("Mauri Sandberg "); +MODULE_DESCRIPTION("Generic GPIO input multiplexer"); +MODULE_LICENSE("GPL");