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: 123062 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp7868962qgn; Mon, 1 Jan 2018 05:38:15 -0800 (PST) X-Google-Smtp-Source: ACJfBos+S8JLpAR1JUe/iK36Br33kRQefT+HBT79wwi4PA6nF16X4/EBXZmFpquzaJS+g2JSnsXF X-Received: by 10.84.216.75 with SMTP id f11mr42820492plj.59.1514813895015; Mon, 01 Jan 2018 05:38:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514813895; cv=none; d=google.com; s=arc-20160816; b=lLd/bNgItQ4+39dehZiSNWnHzJ/GBrY9c2kkvBNlg2EwkR8chhEsY8IPCAd8qejPIp xHenDwEEVl/y8EJ2HXa6A9mZT0ganiRs24D3zFmDVty1W/4W/O2rB76kDG2Lm4QaljxY JzXEBa9RY8vkMG1wgdRRDED48DN7e/gWhdnV1djQlY7r64n67fnxq+/vFIJbB8YXSVXT NIsg/fMSCQwO4I8MxRokNVbVj96IoKxeeNee4ymt5f3jxum7b/F3CuT375l9FQR++1f5 cuiTvcz2ttIWi4jeOgmSJOy9JvXsDbb5I+wKOPhuzrEFI1R3/lcVLiiYzl4ib51y19Zu HKRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=oWurIUKWC9E1B4j8UJ89LduzMFW3HmrVyuDDYfhpbQM=; b=LjnXti28iwriCUXmTgXJ8XWoTjMaRutn+5ZbgUaMCf4Wve8PJPhphlINHM/AjyTaBP 8iylMAnTO6uQpplDj6eqlKfrkOW7GNiDOVD7hNHg2+WQlQH/oRbXixxIhFh1uW3m/WFo jO3tM9ufE7V+Iu+s0f2NnpWtzD4VCiSih7pvlNQ5I5AhFAc3UbwsG+WpiK1SSymUfQA+ SEkdaYo/s/CfKRVKm6fvMbOs52Yo++U1S6OwdDOkVqeIUc3UqVEbO/1odWyQxgHxTSrM OkFVO2eM8tPBSilv8nU6SvqR1R7rVJpqCEbpZI6f9XkyDAEFWkG4DllBlqa/dQLNY7FM Z2mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=WXsH9Pe5; spf=pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-spi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f13si8470380pga.543.2018.01.01.05.38.14; Mon, 01 Jan 2018 05:38:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=WXsH9Pe5; spf=pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-spi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751313AbeAANiO (ORCPT + 1 other); 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-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 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(+) -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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;