From patchwork Mon Jan 8 15:02:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10149721 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 11080602CA for ; Mon, 8 Jan 2018 15:04:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC95E28464 for ; Mon, 8 Jan 2018 15:04:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE62728A27; Mon, 8 Jan 2018 15:04:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13B2F28464 for ; Mon, 8 Jan 2018 15:04:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934055AbeAHPEc (ORCPT ); Mon, 8 Jan 2018 10:04:32 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:40784 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934054AbeAHPEa (ORCPT ); Mon, 8 Jan 2018 10:04:30 -0500 Received: by mail-lf0-f65.google.com with SMTP id u84so12424632lff.7 for ; Mon, 08 Jan 2018 07:04:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=qh/cE4WukJhnpoRUCa1JhrmTy5sTI8ZOKwSeis7EVcM=; b=dYFzOt5CBM428LdNwYIsuDbEIyM3UTxzZA/+AGbiUsUZMCaitSb4VNpZWAjFIF+NVI GKw7Pp1iSVV7hSC1AMMjvVwnKloGogMw9tWen+GpPe8VQ2qrrRLBr2zzLzWq849XOm81 We/GokQahG+dksVkvDTcao5ptsWiRz7O+emGs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=qh/cE4WukJhnpoRUCa1JhrmTy5sTI8ZOKwSeis7EVcM=; b=i8Z0a5II+C4uVSOhjc8Qz7R92hdUk/ZraJdP5MkRYSrbd1Isu6v4mxjGZbRIyaEaEi x2jPSylgNxwUMsNStX2dNIl5u4KYAC3Yl/Zh6qyU5FhQL2u7iCaDOEZtUPMQkwhwkLUw IQi/Z3IdYMBeIyDhyY6gDLvW1Vo5nploKiObDrmbBph2C54ZgbtjJgxBDDskrduSuTAL wBd63HHr5UtfhLjBKHYIgdrmDRtxU11L+W5EfqnDu6GWBie1zaO+CZ4+vpxtZte0nMTA BSK+YReOmivcDexa7AMEXAaXiD3dlND7cWYyYCbfK4qD87USiO3LqRyGPcaP5X3n8sAU GsFw== X-Gm-Message-State: AKGB3mKt4x5ldsrBL5Itj/nrwp+GyVDw+I7+t1wifEiNi2P+lXJdjDMh 0bLPGVeoJZghoI1yHBOr5VYlTQ== X-Google-Smtp-Source: ACJfBouKrekmXm/KTraswp5gVM8ZoPQjKt4sTSwGhGooGOT7/jVilZ246JG08HBuOhftXLNQ3z3dFw== X-Received: by 10.46.60.23 with SMTP id j23mr6687084lja.107.1515423869296; Mon, 08 Jan 2018 07:04:29 -0800 (PST) Received: from localhost.localdomain (c-cb7471d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.116.203]) by smtp.gmail.com with ESMTPSA id j34sm203870lfi.80.2018.01.08.07.04.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Jan 2018 07:04:27 -0800 (PST) From: Linus Walleij To: Mark Brown , linux-spi@vger.kernel.org Cc: linux-gpio@vger.kernel.org, Linus Walleij , Rob Herring Subject: [PATCH v3] gpio: of: Support SPI nonstandard GPIO properties Date: Mon, 8 Jan 2018 16:02:21 +0100 Message-Id: <20180108150221.14193-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Before it was clearly established that all GPIO properties in the device tree shall be named "foo-gpios" (with the deprecated variant "foo-gpio" for single lines) we unfortunately merged a few bindings which named the lines "gpio-foo" instead. This is most prominent in the GPIO SPI driver in Linux which names the lines "gpio-sck", "gpio-mosi" and "gpio-miso". As we want to switch the GPIO SPI driver to using descriptors, we need devm_gpiod_get() to return something reasonable when looking up these in the device tree. Put in a special #ifdef:ed kludge to do this special lookup only for the SPI case and gets compiled out if we're not enabling SPI. If we have more oddly defined legacy GPIOs like this, they can be handled in a similar manner. Cc: Rob Herring Signed-off-by: Linus Walleij Reviewed-by: Rob Herring --- ChangeLog v2->v3: - Put the if(!IS_ENABLED()) inside the SPI GPIO retrieveal function and rely on the compiler to stub out unused code. ChangeLog v1->v2: - Us if IS_ENABLED(CONFIG_SPI_MASTER) instead of #ifdef CONFIG_SPI_MASTER --- drivers/gpio/gpiolib-of.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index e0d59e61b52f..317e54f95035 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -117,6 +117,36 @@ int of_get_named_gpio_flags(struct device_node *np, const char *list_name, } EXPORT_SYMBOL(of_get_named_gpio_flags); +/* + * The SPI GPIO bindings happened before we managed to establish that GPIO + * properties should be named "foo-gpios" so we have this special kludge for + * them. + */ +static struct gpio_desc *of_find_spi_gpio(struct device *dev, const char *con_id, + enum of_gpio_flags *of_flags) +{ + char prop_name[32]; /* 32 is max size of property name */ + struct device_node *np = dev->of_node; + struct gpio_desc *desc; + + /* + * Hopefully the compiler stubs the rest of the function if this + * is false. + */ + if (!IS_ENABLED(CONFIG_SPI_MASTER)) + return ERR_PTR(-ENOENT); + + /* Allow this specifically for "spi-gpio" devices */ + if (!of_device_is_compatible(np, "spi-gpio") || !con_id) + return ERR_PTR(-ENOENT); + + /* Will be "gpio-sck", "gpio-mosi" or "gpio-miso" */ + snprintf(prop_name, sizeof(prop_name), "%s-%s", "gpio", con_id); + + desc = of_get_named_gpiod_flags(np, prop_name, 0, of_flags); + return desc; +} + struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, unsigned int idx, enum gpio_lookup_flags *flags) @@ -126,6 +156,7 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, struct gpio_desc *desc; unsigned int i; + /* Try GPIO property "foo-gpios" and "foo-gpio" */ for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) { if (con_id) snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id, @@ -140,6 +171,10 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, break; } + /* Special handling for SPI GPIOs if used */ + if (IS_ERR(desc)) + desc = of_find_spi_gpio(dev, con_id, &of_flags); + if (IS_ERR(desc)) return desc;