All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
To: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Linus Walleij
	<linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
	Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Subject: [PATCH 1/5] gpio: of: Support SPI nonstandard GPIO properties
Date: Mon,  1 Jan 2018 14:37:45 +0100	[thread overview]
Message-ID: <20180101133749.29567-2-linus.walleij@linaro.org> (raw)
In-Reply-To: <20180101133749.29567-1-linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.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 <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Signed-off-by: Linus Walleij <linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
---
 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;
 
-- 
2.14.3

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2018-01-01 13:37 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-01 13:37 [PATCH 0/5] Rewrite GPIO SPI to use descriptors Linus Walleij
     [not found] ` <20180101133749.29567-1-linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2018-01-01 13:37   ` Linus Walleij [this message]
     [not found]     ` <20180101133749.29567-2-linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2018-01-03 15:04       ` [PATCH 1/5] gpio: of: Support SPI nonstandard GPIO properties Mark Brown
2018-01-03 15:23       ` Rob Herring
     [not found]         ` <CAL_JsqLH4pqptAkpw2CHPRe=6dR3k1iBPM8g7yMFUHnYmm7L9w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-01-04 20:24           ` Linus Walleij
     [not found]             ` <CACRpkdZ9yGm9K4iF=jR8bjzZR6cU7vEV8tNz6i7DfcE=Jhp2yw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-01-05 10:21               ` Andy Shevchenko
2018-01-01 13:37   ` [PATCH 2/5] spi: spi-gpio: Rewrite to use GPIO descriptors Linus Walleij
     [not found]     ` <20180101133749.29567-3-linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2018-01-03 15:55       ` Mark Brown
2018-01-05  7:34       ` Olof Johansson
2018-01-05 10:33       ` Andy Shevchenko
2018-01-01 13:37   ` [PATCH 3/5] spi: spi-gpio: Augment device tree bindings Linus Walleij
     [not found]     ` <20180101133749.29567-4-linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2018-02-14 16:28       ` Applied "spi: spi-gpio: Augment device tree bindings" to the spi tree Mark Brown
2018-01-01 13:37   ` [PATCH 4/5] spi: spi-gpio: Make optional chipselect handling more explicit Linus Walleij
     [not found]     ` <20180101133749.29567-5-linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2018-01-03  8:21       ` Geert Uytterhoeven
     [not found]         ` <CAMuHMdV5tdm0diunWg2BXxgVsG0FqwTgXXXBD+p9nbOEXcd59Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-01-03  8:58           ` Linus Walleij
     [not found]             ` <CACRpkdZaLKUs+9BP_Tp8bhdCur+CHaTK1RsS=i2na4Edqz1VGw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-01-03  9:17               ` Geert Uytterhoeven
     [not found]                 ` <CAMuHMdVeTQOxRMJaohGFtw6LUtwQb6H46rsrf1fRFno9KBQXXA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-01-03  9:40                   ` Linus Walleij
     [not found]                     ` <CACRpkdaEyKcWPY543CZz0grepAhVijefh_+FCsPd3g+83hv2Fg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-01-03 16:05                       ` Mark Brown
2018-01-01 13:37   ` [PATCH 5/5] spi: spi-gpio: Delete references to non-GENERIC_BITBANG Linus Walleij
     [not found]     ` <20180101133749.29567-6-linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2018-01-03 16:10       ` Mark Brown
2018-01-02  8:15   ` [PATCH 0/5] Rewrite GPIO SPI to use descriptors Linus Walleij
2018-01-02 18:42   ` Trent Piepho
     [not found]     ` <1514918569.26695.151.camel-cgc2CodaaHDQT0dZR+AlfA@public.gmane.org>
2018-01-02 23:17       ` Linus Walleij
     [not found]         ` <CACRpkdYRJ=jR4B2Ko2P1axwGMKob2vHkY2h8cMc9t9Qi7n52sQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-01-03 16:24           ` Mark Brown
     [not found]             ` <20180103162449.GG28713-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2018-01-06 23:18               ` Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180101133749.29567-2-linus.walleij@linaro.org \
    --to=linus.walleij-qsej5fyqhm4dnm+yrofe0a@public.gmane.org \
    --cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.