Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp434564pxb; Tue, 19 Oct 2021 06:02:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0E0j3qmS+c1m2PMehpDoEWop9RrCXVPB+9OB8vi8yXIpMMbw7D5UUmtrlCd7AtH5jXpSp X-Received: by 2002:a05:6a00:1a10:b0:44d:e6e2:94f9 with SMTP id g16-20020a056a001a1000b0044de6e294f9mr7766748pfv.54.1634648562565; Tue, 19 Oct 2021 06:02:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634648562; cv=none; d=google.com; s=arc-20160816; b=KuykFkm9CDAKf9ZYwbluv1JD7Oq17rt+CX+Oabtv1K+0RqEPAlX9MQFMUXsw8O+/re 8Buz0KVTZWtVuRt+KVVn668qbIkMBSwhdb7NArO6zNMwTCl0jzsicXLPIp+FdOG22td8 2TwcfVcu1YYdBbSd/2oFtS0+N2nX8OXDtATHYHj0ZumYHHMhYEV3q1LMgZK5407sLO+K omt6jCa6JH5LR4f+I87jJwf+6mSrclEjScWNRAsn5QxJ6Ethv6i5DHevCkQSVG5pJ/EE vqf1WYiEfXWCl09IR22Y0BwcCTc7a1X6XYm2onPBAJvMQlzecsq6nkvSJ4hmR0YCqAAc 9cJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=FKYyukUjYQcoakf1FClyDjpoueWSopxNcHu8tfk/XOM=; b=MeKEXRdC9741EBU8H7NbHdBuErpqTzF7VTtDUAGT34ElF5mG3Hv4lFLybspcMKHan9 WOUSZXJSN1yzYZHuzVj4cxrKdT4SEGjF2RM1SAwg1DJSlgbfYfrrn6BBbTQ+roskymeu xy7BcdLhgKMDwsTwkfSKSJ1d7OSGRsOiVigLOS0HHeBkls4SQ7evf6wBunWa0Fg3NVUS iawqnmCh6oKvhIzAbjza8zw/8/1MP0XXD7VJh2leQS8H7ymaKcIaanla5UrQb60neY7r WK17NPUuaMSLuhGn78P5VwQly2TuN01blg8M6K3xXxx03tUHy3emvRiu93seYFxBk1us WWYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@ext.kapsi.fi header.s=20161220 header.b=InAIHn7I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w2si8236559plq.368.2021.10.19.06.02.27; Tue, 19 Oct 2021 06:02:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@ext.kapsi.fi header.s=20161220 header.b=InAIHn7I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235739AbhJSNC7 (ORCPT + 99 others); Tue, 19 Oct 2021 09:02:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231616AbhJSNC6 (ORCPT ); Tue, 19 Oct 2021 09:02:58 -0400 Received: from mailserv1.kapsi.fi (mailserv1.kapsi.fi [IPv6:2001:67c:1be8::25:1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84CF3C06161C; Tue, 19 Oct 2021 06:00:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ext.kapsi.fi; s=20161220; h=Subject:Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date: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=FKYyukUjYQcoakf1FClyDjpoueWSopxNcHu8tfk/XOM=; b=InAIHn7I3VH09l8zIndRLCpwpo 6tBT7O8YzqjFhwiESdbFTczfW688QWBXEg98wybq0tGFZMsu+rDQAu+/iqSa+jS86UoZPVhYHzvU4 s7hx1iY9zIg0Q26G8xsXfVtMcMaj19nKSi/nB9SLEK5088bT5xHn8LbKTB78f3Q7og9R8w3IW6YXR /OZiiE0qHGqw+H0uP4Pto5D6ki2snGG4CMK+fDwRlBc7LIsXypDJv/77Z3KgZzT9njtX63EAnqWCH MPvWFLhJVzOmrpTdu+jmkxmizAssvK4NQgegdcHTrUFqHaMNV9RkyQ8pJXOBPDIknJKb9/qFwwYHb Sejmsf9A==; Received: from 153-106-191-90.dyn.estpak.ee ([90.191.106.153]:56952 helo=localdomain) by mailserv1.kapsi.fi with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1mcojM-0001sg-2X; Tue, 19 Oct 2021 16:00:37 +0300 Received: by localdomain (sSMTP sendmail emulation); Tue, 19 Oct 2021 16:00:35 +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, robh+dt@kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, drew@beagleboard.org, Mauri Sandberg Date: Tue, 19 Oct 2021 15:57:29 +0300 Message-Id: <20211019125731.4327-1-maukka@ext.kapsi.fi> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210325122832.119147-1-sandberg@mailfence.com> References: <20210325122832.119147-1-sandberg@mailfence.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 90.191.106.153 X-SA-Exim-Mail-From: maukka@ext.kapsi.fi X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mailserv1.kapsi.fi X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, TVD_RCVD_IP autolearn=ham autolearn_force=no version=3.4.2 Subject: [PATCH v6 0/2] gpio: gpio-cascade: add generic GPIO cascade X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on mailserv1.kapsi.fi) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello all, It's been a while and here comes the sixth version of the patches. What was done: - adjust module dependecies and what it selects in Kconfig - use managed device resource call when adding gpio chip - remove redundant code - cosmetic changes Thanks, Mauri rangediff v5 -> v6: 1: a1bb23f56378 ! 1: 87348f391671 dt-bindings: gpio-cascade: add documentation @@ Commit message the cascaded line. Signed-off-by: Mauri Sandberg + Reviewed-by: Rob Herring --- + v5 -> v6: + - added Reviewed-by tag by Rob v4 -> v5: - renamed gpio-mux-input -> gpio-cascade - changed vague term 'pin' to 'upstream line' 2: e0be9df088a9 ! 2: a8e608181bc7 gpio: gpio-cascade: add generic GPIO cascade @@ Metadata ## Commit message ## gpio: gpio-cascade: add generic GPIO cascade - Adds support for a building cascades of GPIO lines. That is, it allows + Adds support for building cascades of GPIO lines. That is, it allows setups when there is one upstream line and multiple cascaded lines, out of which one can be chosen at a time. The status of the upstream line - can be conveyd to the selected cascaded line or, vice versa, the status + can be conveyed to the selected cascaded line or, vice versa, the status of the cascaded line can be conveyed to the upstream line. - A gpio-mux is being used to select, which cascaded GPIO line is being + A multiplexer is being used to select, which cascaded GPIO line is being used at any given time. At the moment only input direction is supported. In future it should be @@ Commit message Signed-off-by: Mauri Sandberg --- + v5 -> v6: + - In Kconfig, remove dependency to OF_GPIO and select only MULTIPLEXER + - refactor code preferring one-liners + - clean up prints, removing them from success-path. + - don't explicitly set gpio_chip.of_node as it's done in the GPIO library + - use devm_gpiochip_add_data instead of gpiochip_add v4 -> v5: - renamed gpio-mux-input -> gpio-cascade. refactored code accordingly here and there and changed to use new bindings and compatible string @@ drivers/gpio/Kconfig: config GPIO_VIRTIO + +config GPIO_CASCADE + tristate "General GPIO cascade" -+ depends on OF_GPIO + select MULTIPLEXER -+ select MUX_GPIO + help + Say yes here to enable support for generic GPIO cascade. + @@ drivers/gpio/gpio-cascade.c (new) + +static int gpio_cascade_get_value(struct gpio_chip *gc, unsigned int offset) +{ -+ struct gpio_cascade *cas; ++ struct gpio_cascade *cas = chip_to_cascade(gc); + int ret; + -+ cas = chip_to_cascade(gc); + ret = mux_control_select(cas->mux_control, offset); + if (ret) + return ret; @@ drivers/gpio/gpio-cascade.c (new) + +static int gpio_cascade_probe(struct platform_device *pdev) +{ -+ struct device_node *np = pdev->dev.of_node; + struct device *dev = &pdev->dev; + struct gpio_cascade *cas; + struct mux_control *mc; @@ drivers/gpio/gpio-cascade.c (new) + struct gpio_chip *gc; + int err; + -+ cas = devm_kzalloc(dev, sizeof(struct gpio_cascade), GFP_KERNEL); -+ if (cas == NULL) ++ cas = devm_kzalloc(dev, sizeof(*cas), GFP_KERNEL); ++ if (!cas) + 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; -+ } ++ if (IS_ERR(mc)) ++ return dev_err_probe(dev, ++ PTR_ERR(mc), ++ "unable to get mux-control\n"); + + cas->mux_control = mc; + upstream = devm_gpiod_get(dev, "upstream", GPIOD_IN); + if (IS_ERR(upstream)) { -+ err = (int) PTR_ERR(upstream); -+ dev_err(dev, "unable to claim upstream GPIO line: %d\n", err); -+ return err; ++ dev_err(dev, "unable to claim upstream GPIO line\n"); ++ return -ENODEV; + } + + cas->upstream_line = upstream; @@ drivers/gpio/gpio-cascade.c (new) + gc->label = dev_name(cas->parent); + gc->parent = cas->parent; + gc->owner = THIS_MODULE; -+ gc->of_node = np; + -+ err = gpiochip_add(&cas->gpio_chip); ++ err = devm_gpiochip_add_data(dev, &cas->gpio_chip, NULL); + if (err) { -+ dev_err(dev, "unable to add gpio chip, err=%d\n", err); ++ dev_err(dev, "unable to add gpio chip\n"); + return err; + } + + platform_set_drvdata(pdev, cas); -+ dev_info(dev, "registered %u cascaded GPIO lines\n", gc->ngpio); + return 0; +} + +static const struct of_device_id gpio_cascade_id[] = { -+ { -+ .compatible = "gpio-cascade", -+ .data = NULL, -+ }, ++ { .compatible = "gpio-cascade" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, gpio_cascade_id); Mauri Sandberg (2): dt-bindings: gpio-cascade: add documentation gpio: gpio-cascade: add generic GPIO cascade .../bindings/gpio/gpio-cascade.yaml | 103 ++++++++++++++ drivers/gpio/Kconfig | 12 ++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-cascade.c | 129 ++++++++++++++++++ 4 files changed, 245 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-cascade.yaml create mode 100644 drivers/gpio/gpio-cascade.c base-commit: f4a20dfac88c06c9b529a41ff4cf9acba8f3fdff -- 2.25.1