From: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
To: Linus Walleij <linus.walleij@linaro.org>,
Timur Tabi <timur@codeaurora.org>,
swboyd@chromium.org, linux-gpio@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>
Cc: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Subject: [PATCH v2] gpiolib: Show correct direction from the beginning
Date: Fri, 21 Sep 2018 12:36:04 +0200 [thread overview]
Message-ID: <20180921103604.13361-2-ricardo.ribalda@gmail.com> (raw)
In-Reply-To: <20180921103604.13361-1-ricardo.ribalda@gmail.com>
Current code assumes that the direction is input if direction_input
function is set.
This might not be the case on GPIOs with programmable direction.
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
drivers/gpio/gpiolib.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 4b45de883ada..00c17f64d9ff 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1352,7 +1352,12 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
* it does, and in case chip->get_direction is not set, we may
* expose the wrong direction in sysfs.
*/
- desc->flags = !chip->direction_input ? (1 << FLAG_IS_OUT) : 0;
+ if (chip->get_direction && gpiochip_line_is_valid(chip, i))
+ desc->flags = !chip->get_direction(chip, i) ?
+ (1 << FLAG_IS_OUT) : 0;
+ else
+ desc->flags = !chip->direction_input ?
+ (1 << FLAG_IS_OUT) : 0;
}
#ifdef CONFIG_PINCTRL
--
2.18.0
next prev parent reply other threads:[~2018-09-21 10:36 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-21 10:36 [PATCH] gpiolib: Fix gpio_direction_* for single direction GPIOs Ricardo Ribalda Delgado
2018-09-21 10:36 ` Ricardo Ribalda Delgado [this message]
2018-09-21 12:25 ` [PATCH v2] gpiolib: Show correct direction from the beginning Timur Tabi
2018-09-27 6:51 ` Stephen Boyd
2018-09-27 12:19 ` Timur Tabi
2018-09-27 14:04 ` Jeffrey Hugo
2018-09-27 14:19 ` Timur Tabi
2018-09-27 14:34 ` Jeffrey Hugo
2018-09-28 19:14 ` Jeffrey Hugo
2018-09-28 19:22 ` Timur Tabi
2018-09-29 6:23 ` Ricardo Ribalda Delgado
2018-09-29 13:21 ` Timur Tabi
2018-09-29 13:25 ` Timur Tabi
[not found] ` <D3E6F4C4-E1C4-4D88-B118-878576BF5281@gmail.com>
2018-10-01 11:54 ` Linus Walleij
2018-10-01 13:36 ` Ricardo Ribalda Delgado
2018-10-01 14:27 ` Jeffrey Hugo
2018-10-01 21:20 ` Linus Walleij
2018-10-02 7:15 ` Ricardo Ribalda Delgado
2018-10-02 7:38 ` Linus Walleij
2018-10-02 12:26 ` Timur Tabi
2018-10-02 12:51 ` Linus Walleij
2018-09-25 7:36 ` [PATCH] gpiolib: Fix gpio_direction_* for single direction GPIOs 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=20180921103604.13361-2-ricardo.ribalda@gmail.com \
--to=ricardo.ribalda@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=swboyd@chromium.org \
--cc=timur@codeaurora.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).