linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Timur Tabi <timur@codeaurora.org>
To: andy.gross@linaro.org, david.brown@linaro.org,
	Linus Walleij <linus.walleij@linaro.org>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	linux-gpio@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Cc: timur@codeaurora.org
Subject: [PATCH 1/3] gliolib: request the gpio before querying its direction
Date: Thu, 27 Jul 2017 13:19:23 -0500	[thread overview]
Message-ID: <1501179565-26466-2-git-send-email-timur@codeaurora.org> (raw)
In-Reply-To: <1501179565-26466-1-git-send-email-timur@codeaurora.org>

Before querying a GPIO to determine its direction, the GPIO should be
formally requested.  This allows the GPIO driver to block access to
unavailable GPIOs, which makes it easier for some drivers to support
sparse GPIO maps.

Signed-off-by: Timur Tabi <timur@codeaurora.org>
---
 drivers/gpio/gpiolib.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 9568708..3b4e1e8 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1202,6 +1202,14 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data)
 		struct gpio_desc *desc = &gdev->descs[i];
 
 		desc->gdev = gdev;
+
+		if (chip->request) {
+			status = chip->request(chip, i);
+			if (status < 0)
+				/* The GPIO is unavailable, so skip it */
+				continue;
+		}
+
 		/*
 		 * REVISIT: most hardware initializes GPIOs as inputs
 		 * (often with pullups enabled) so power usage is
@@ -1227,6 +1235,9 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data)
 			 */
 			set_bit(FLAG_IS_OUT, &desc->flags);
 		}
+
+		if (chip->free)
+			chip->free(chip, i);
 	}
 
 #ifdef CONFIG_PINCTRL
-- 
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc.  Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.

  reply	other threads:[~2017-07-27 18:19 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-27 18:19 [PATCH 0/3][v3] pinctrl: qcom: add support for sparse GPIOs Timur Tabi
2017-07-27 18:19 ` Timur Tabi [this message]
2017-07-31 13:35   ` [PATCH 1/3] gliolib: request the gpio before querying its direction Linus Walleij
2017-08-21 21:23     ` Timur Tabi
2017-08-23  8:32       ` Linus Walleij
2017-08-23 23:28         ` Timur Tabi
2017-08-24 21:28           ` Linus Walleij
2017-08-24 22:00             ` Timur Tabi
2017-07-27 18:19 ` [PATCH 2/3] [v3] pinctrl: qcom: disable GPIO groups with no pins Timur Tabi
2017-07-31 13:36   ` Linus Walleij
2017-08-09 19:02     ` Timur Tabi
2017-08-16 18:10       ` Jiandi An
2017-08-16 18:32         ` Timur Tabi
2017-08-16 19:30           ` Jiandi An
2017-08-16 19:31           ` Jiandi An
2017-08-16 19:55             ` Timur Tabi
2017-07-27 18:19 ` [PATCH 3/3] [v2] pinctrl: qcom: qdf2xxx: add support for new ACPI HID QCOM8002 Timur Tabi
  -- strict thread matches above, loose matches on Subject: below --
2017-07-17 23:43 [PATCH 0/3][v2] pinctrl: qcom: add support for sparse GPIOs Timur Tabi
2017-07-17 23:43 ` [PATCH 1/3] gliolib: request the gpio before querying its direction Timur Tabi

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=1501179565-26466-2-git-send-email-timur@codeaurora.org \
    --to=timur@codeaurora.org \
    --cc=andy.gross@linaro.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=david.brown@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.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).