From patchwork Mon Jan 8 12:49:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10149373 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 13033602B3 for ; Mon, 8 Jan 2018 12:51:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DEE928332 for ; Mon, 8 Jan 2018 12:51:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00A2928633; Mon, 8 Jan 2018 12:51:18 +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 8515528332 for ; Mon, 8 Jan 2018 12:51:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932467AbeAHMvS (ORCPT ); Mon, 8 Jan 2018 07:51:18 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:45941 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932465AbeAHMvR (ORCPT ); Mon, 8 Jan 2018 07:51:17 -0500 Received: by mail-lf0-f68.google.com with SMTP id y71so11931454lfd.12 for ; Mon, 08 Jan 2018 04:51:16 -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=0y83lDsSUwSSWZmhNquK1DOCDPjSEMZkl9+NMnrihH0=; b=dq491gl06VYVmz/nhq9+TDY4IjsQue8RcrSD6kBxQc3xSntXgYKYqUMmsz6Dtt05TI iWoesCSUtbNlgpuwy4KW0SrGJsdQxs5RFx85hlrv+tLP8mwCazgGgWmFvJP5pUfKw0yL LAY+ftmuocggsJXnbh4yJwaOiaF5kKFMTN6fM= 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=0y83lDsSUwSSWZmhNquK1DOCDPjSEMZkl9+NMnrihH0=; b=LtA6hke7VMcEAYUbXgl+sreydw99cqCoOk/ha0KJPp0GWcyF7vloO9xEsCR3us1lFR Ts6qUAAYwQqKwX2aMqNJCW/m23+0+F2LohSZVgEriV+rcaqVW2k6ZU29FNpiEvHj9ZB1 uDelwk8UPopOFaLx8JPY6QzRTJXudjfRY8gL2Rybk72cJtRMeQjLUTNGPM8D2hVdo+Ck Of9QLfO1GR2zcJSJhfXbIa7DJQ1l6kv9xI1TspXsf+uGeUnHdP5nXZWX1Q7WKkpJ3PQH jEvD+LZfKSJGh4xmeTXn4mZD4dP5KNg9E1jkoDh0JA6VYAOigifjtjcrJ3H2yygNKZgu yA4Q== X-Gm-Message-State: AKGB3mKjmQat1hSRNCvH9L6k6Pc5oSObUG4RKg0yDbZm47v+g87z07Fz kxbkztu3YPmM5BiA2CE2PIVucnoJYO0= X-Google-Smtp-Source: ACJfBotyS6sFsbqRbttO33l/UqiciNWBqT6WqNpwNHTY4PWHGosrxtr2YI612dUARYrnP1QH7cDhTw== X-Received: by 10.46.16.1 with SMTP id j1mr6292432lje.139.1515415875655; Mon, 08 Jan 2018 04:51:15 -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 t11sm2317757ljd.53.2018.01.08.04.51.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Jan 2018 04:51:14 -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 v2] gpio: of: Support SPI nonstandard GPIO properties Date: Mon, 8 Jan 2018 13:49:09 +0100 Message-Id: <20180108124909.32334-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 --- I will merge this into the GPIO tree as a preparation for the next (v4.17) kernel cycle so that we avoid cross-tree dependencies. I estimate that it is too late to merge the bulk of the patches for v4.16, but this can go in. ChangeLog v1->v2: - Us if IS_ENABLED(CONFIG_SPI_MASTER) instead of #ifdef CONFIG_SPI_MASTER --- 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..3ae9876e8c44 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. + */ +#if IS_ENABLED(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;