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: 856786 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="dq491gl0"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zFZs31Wb1z9s7g for ; Mon, 8 Jan 2018 23:51:19 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932466AbeAHMvR (ORCPT ); Mon, 8 Jan 2018 07:51:17 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:38220 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932413AbeAHMvR (ORCPT ); Mon, 8 Jan 2018 07:51:17 -0500 Received: by mail-lf0-f65.google.com with SMTP id d19so3667805lfj.5 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=n7c4EpuFfAS1ksIj2ORhrh7UNHszdTJ8+kRfGLzoTg/IJq9vrpt9VoH9W9u+G6QlvW 69Xb4sXNnLId5Fkk7JXt9VSz/o4kLk53oBLu+KUes1CiDtKtVb4Lt8PNEe7PYy8t13HU M0SbYlN/SJBQnQSUw1ETiF6Aa1DGDdDA0/m+44LHame5gf29YjP63EdLqcaFN8B4o8FQ yTjl68oFfH4XG5KW97YG5uKd2QmVG+0wbv9ORDUG6oS4be69Gtn44oFIG51PruSn2cQu mTnNoK+vNxVhjQgc7RdF4/6fuvtFBYhnyYx+bPJuRvXrBWwr4GqrOlRYO+XL6dd+yKg1 GkZg== X-Gm-Message-State: AKGB3mKI3kqAHL533Up+bfrcZmuQlNKqK1U1rp0YnjKEjVLOb/TACnfI TTkQfYz51fBKFioSgD1SYP9yfw== 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-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@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 --- 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;