linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chen-Yu Tsai <wens@csie.org>
To: Linus Walleij <linus.walleij@linaro.org>,
	Johannes Berg <johannes@sipsolutions.net>,
	"John W. Linville" <linville@tuxdriver.com>,
	Maxime Ripard <maxime.ripard@free-electrons.com>
Cc: Chen-Yu Tsai <wens@csie.org>, Arnd Bergmann <arnd@arndb.de>,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Alexandre Courbot <gnurou@gmail.com>,
	Stephen Warren <swarren@wwwdotorg.org>,
	linux-gpio@vger.kernel.org, linux-wireless@vger.kernel.org,
	netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-sunxi@googlegroups.com
Subject: [PATCH 1/7] gpiolib: gpiolib-of: Implement device tree gpio-names based lookup
Date: Tue, 15 Apr 2014 14:41:35 +0800	[thread overview]
Message-ID: <1397544101-18135-2-git-send-email-wens@csie.org> (raw)
In-Reply-To: <1397544101-18135-1-git-send-email-wens@csie.org>

This patch provides of_get_gpiod_flags_by_name(), which looks up GPIO
phandles by name only, through gpios/gpio-names, and not by index.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/gpio/gpiolib-of.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of_gpio.h   |  3 +++
 2 files changed, 51 insertions(+)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 2024d45..5c586fa 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -97,6 +97,54 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
 EXPORT_SYMBOL(of_get_named_gpiod_flags);
 
 /**
+ * of_get_gpiod_flags_by_name() - Get a GPIO descriptor and flags by name
+ * @np:		device node to get GPIO from
+ * @name:	matching name of gpio phandle
+ * @flags:	a flags pointer to fill in
+ *
+ * Returns GPIO descriptor to use with Linux GPIO API, or one of the errno
+ * value on the error condition. If @flags is not NULL the function also fills
+ * in flags for the GPIO.
+ */
+struct gpio_desc *of_get_gpiod_flags_by_name(struct device_node *np,
+		const char *name, enum of_gpio_flags *flags)
+{
+	/* Return -EPROBE_DEFER to support probe() functions to be called
+	 * later when the GPIO actually becomes available
+	 */
+	struct gg_data gg_data = {
+		.flags = flags,
+		.out_gpio = ERR_PTR(-EPROBE_DEFER)
+	};
+	int index = 0;
+	int ret;
+
+	/* exit if no name given */
+	if (!name)
+		return ERR_PTR(-EINVAL);
+
+	/* .of_xlate might decide to not fill in the flags, so clear it. */
+	if (flags)
+		*flags = 0;
+
+	if (name)
+		index = of_property_match_string(np, "gpio-names", name);
+
+	ret = of_parse_phandle_with_args(np, "gpios", "#gpio-cells", index,
+					 &gg_data.gpiospec);
+
+	if (ret)
+		return ERR_PTR(ret);
+
+	gpiochip_find(&gg_data, of_gpiochip_find_and_xlate);
+
+	of_node_put(gg_data.gpiospec.np);
+
+	return gg_data.out_gpio;
+}
+EXPORT_SYMBOL(of_get_gpiod_flags_by_names);
+
+/**
  * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags
  * @gc:		pointer to the gpio_chip structure
  * @np:		device node of the GPIO chip
diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h
index f14123a..134331f 100644
--- a/include/linux/of_gpio.h
+++ b/include/linux/of_gpio.h
@@ -51,6 +51,9 @@ static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc)
 extern struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
 		const char *list_name, int index, enum of_gpio_flags *flags);
 
+extern struct gpio_desc *of_get_gpiod_flags_by_name(struct device_node *np,
+		const char *name, enum of_gpio_flags *flags);
+
 extern int of_mm_gpiochip_add(struct device_node *np,
 			      struct of_mm_gpio_chip *mm_gc);
 
-- 
1.9.1


  reply	other threads:[~2014-04-15  7:22 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-15  6:41 [PATCH 0/7] net: rfkill: gpio: Add device tree support Chen-Yu Tsai
2014-04-15  6:41 ` Chen-Yu Tsai [this message]
2014-04-15 14:20   ` [PATCH 1/7] gpiolib: gpiolib-of: Implement device tree gpio-names based lookup Maxime Ripard
2014-04-16  6:12     ` Alexandre Courbot
2014-04-16  7:06       ` Alexandre Courbot
2014-04-16  9:56         ` Chen-Yu Tsai
2014-04-22 15:02   ` Linus Walleij
2014-04-23  1:49     ` Alexandre Courbot
2014-04-28 16:19       ` [linux-sunxi] " Chen-Yu Tsai
2014-04-15  6:41 ` [PATCH 2/7] gpiolib: Support purely name based gpiod lookup in device trees Chen-Yu Tsai
2014-04-22 15:00   ` Linus Walleij
2014-04-22 15:18     ` Maxime Ripard
2014-04-23 13:55       ` Linus Walleij
2014-04-15  6:41 ` [PATCH 3/7] net: rfkill: gpio: use clk_prepare_enable/clk_disable_unprepare Chen-Yu Tsai
2014-04-15 14:26   ` Maxime Ripard
2014-04-15  6:41 ` [PATCH 4/7] net: rfkill: gpio: fix reversed clock enable state Chen-Yu Tsai
2014-04-15 14:27   ` Maxime Ripard
2014-04-15  6:41 ` [PATCH 5/7] net: rfkill: gpio: add device tree support Chen-Yu Tsai
2014-04-15 21:00   ` Stephen Warren
2014-04-15 21:01   ` Stephen Warren
2014-04-15  6:41 ` [PATCH 6/7] net: rfkill: gpio: add clock-frequency device tree property Chen-Yu Tsai
2014-04-15 14:44   ` Maxime Ripard
2014-04-15  6:41 ` [PATCH 7/7] ARM: sun7i: cubietruck: enable bluetooth module Chen-Yu Tsai
2014-04-15 14:42   ` Maxime Ripard
2014-04-15 16:06     ` [linux-sunxi] " Chen-Yu Tsai
2014-04-15 16:18       ` One Thousand Gnomes
2014-04-16  9:44       ` Maxime Ripard
2014-04-16 10:39         ` Chen-Yu Tsai
2014-04-18 17:47           ` maxime.ripard
     [not found]           ` <534E8102.4070404@redhat.com>
     [not found]             ` <534F862C.8010604@broadcom.com>
2014-04-18 17:49               ` maxime.ripard
2014-04-16 13:08         ` Hans de Goede
2014-04-22 15:06 ` [PATCH 0/7] net: rfkill: gpio: Add device tree support Johannes Berg

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=1397544101-18135-2-git-send-email-wens@csie.org \
    --to=wens@csie.org \
    --cc=arnd@arndb.de \
    --cc=devicetree@vger.kernel.org \
    --cc=gnurou@gmail.com \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=johannes@sipsolutions.net \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sunxi@googlegroups.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linville@tuxdriver.com \
    --cc=maxime.ripard@free-electrons.com \
    --cc=mika.westerberg@linux.intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=swarren@wwwdotorg.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).