From patchwork Mon Jan 1 13:37:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10138543 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 755DC60362 for ; Mon, 1 Jan 2018 13:38:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66D602851B for ; Mon, 1 Jan 2018 13:38:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B77628817; Mon, 1 Jan 2018 13:38:15 +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 F126A2851B for ; Mon, 1 Jan 2018 13:38:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751313AbeAANiO (ORCPT ); Mon, 1 Jan 2018 08:38:14 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:46923 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751111AbeAANiN (ORCPT ); Mon, 1 Jan 2018 08:38:13 -0500 Received: by mail-wm0-f68.google.com with SMTP id r78so57737345wme.5 for ; Mon, 01 Jan 2018 05:38:13 -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:in-reply-to:references; bh=6rv3JMunccWHz345u5Ibn6Yqby9vVCNEu1dkoB7d+/o=; b=WXsH9Pe5l//Ln+/c/efip27g3IOMt75f044Ot9fl0Vv0xDO8ztN5VgdbzSx0ho9N5R /UlwO63ZbWM7RsouqCx8YHAakpy6BmDKlwY//VGHQbi/5y2bKPJ8DRpR2qx0AoZWJUU9 C4vIS1v/82XfA+e/jF+qAtAJ+klMD89IoPX1A= 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:in-reply-to :references; bh=6rv3JMunccWHz345u5Ibn6Yqby9vVCNEu1dkoB7d+/o=; b=kMXUxTv5HS0I5ijeER1pHIVSLASr+K0wBc2TJ+PwFsvSE0AfoWLCoRcRb1kLnK33IO 1OXygKR6n1rO//l+ddFyQm++ke9H1Bol+eHUz6v2khXBkX1vpAr9b6focXp8bGHp78uO PMlzIdbMqpK9CzOebak2ioluWfAiokv0+CKgT0lUJUBwYIe5zt90Y/QZ8vZt0XyELpXD /AA0IRU6pQ2d50FfXprp/Kic4paZ6Gme3lMZHZHr5zKrE3tYBOmIu2Mvlr6YE96dYifw npofatDvno17DTejLYLnlOBothlvt80rD7in/NWNna9BTyeetlvlMvpOLt42DYAWwTMh SkPg== X-Gm-Message-State: AKGB3mIgEYm3j49oHg8ExznTemTNTGTmF5hn2QE2UTlWyZFecPCYljNl eHTO+O4U3CyN0nY1oK/SJz05FQ== X-Google-Smtp-Source: ACJfBoulUYDSgDsbfOxaxQreHIiPT4Cbb81YH+EXLtlWkNrC8c3KaMAryJGIRuPrg6Ni+hGIcrea4w== X-Received: by 10.28.31.131 with SMTP id f125mr31849644wmf.18.1514813892572; Mon, 01 Jan 2018 05:38:12 -0800 (PST) Received: from localhost.localdomain (catv-80-98-14-92.catv.broadband.hu. [80.98.14.92]) by smtp.gmail.com with ESMTPSA id d7sm53491267wrd.54.2018.01.01.05.38.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Jan 2018 05:38:11 -0800 (PST) From: Linus Walleij To: Mark Brown , linux-spi@vger.kernel.org Cc: Linus Walleij , Rob Herring Subject: [PATCH 1/5] gpio: of: Support SPI nonstandard GPIO properties Date: Mon, 1 Jan 2018 14:37:45 +0100 Message-Id: <20180101133749.29567-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180101133749.29567-1-linus.walleij@linaro.org> References: <20180101133749.29567-1-linus.walleij@linaro.org> 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 --- drivers/gpio/gpiolib-of.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index e0d59e61b52f..0f2d096c78a3 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -117,6 +117,37 @@ 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. + */ +#ifdef CONFIG_SPI_MASTER +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; + + /* 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; +} +#else +static struct gpio_desc *of_find_spi_gpio(struct device *dev, const char *con_id, + enum of_gpio_flags *of_flags) +{ + return ERR_PTR(-ENOENT); +} +#endif + struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, unsigned int idx, enum gpio_lookup_flags *flags) @@ -126,6 +157,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 +172,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;