From: Sai Kumar Cholleti <skmr537@gmail.com>
To: bgolaszewski@baylibre.com, andriy.shevchenko@linux.intel.com,
linux-gpio@vger.kernel.org
Cc: mmcclain@noprivs.com, Sai Kumar Cholleti <skmr537@gmail.com>
Subject: [PATCH] gpio: exar set value handling for hw with gpio pull-up or pull-down
Date: Tue, 30 Jul 2024 19:16:10 +0530 [thread overview]
Message-ID: <20240730134610.80986-1-skmr537@gmail.com> (raw)
Setting gpio direction = high, sometimes results in gpio value = 0.
If a gpio is pulled high, the following construction results in the
value being 0 when the desired value is 1:
$ echo "high" > /sys/class/gpio/gpio336/direction
$ cat /sys/class/gpio/gpio336/value
0
Before the gpio direction is changed from input to output,
exar_set_value is set to 1, but since direction is input when
exar_set_value is called, _regmap_update_bits reads a 1 due to an
external pull-up. When force_write is not set (regmap_set_bits has
force_write = false), the value is not written. When the direction is
then changed, the gpio becomes an output with the value of 0 (the
hardware default).
regmap_write_bits sets force_write = true, so the value is always
written by exar_set_value and an external pull-up doesn't affect the
outcome of setting direction = high.
The same can happen when a gpio is pulled low, but the scenario is a
little more complicated.
$ echo high > /sys/class/gpio/gpio351/direction
$ cat /sys/class/gpio/gpio351/value
1
$ echo in > /sys/class/gpio/gpio351/direction
$ cat /sys/class/gpio/gpio351/value
0
$ echo low > /sys/class/gpio/gpio351/direction
$ cat /sys/class/gpio/gpio351/value
1
Signed-off-by: Sai Kumar Cholleti <skmr537@gmail.com>
---
drivers/gpio/gpio-exar.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/gpio/gpio-exar.c b/drivers/gpio/gpio-exar.c
index 482f678c893e..de5ce73159cb 100644
--- a/drivers/gpio/gpio-exar.c
+++ b/drivers/gpio/gpio-exar.c
@@ -99,11 +99,13 @@ static void exar_set_value(struct gpio_chip *chip, unsigned int offset,
struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip);
unsigned int addr = exar_offset_to_lvl_addr(exar_gpio, offset);
unsigned int bit = exar_offset_to_bit(exar_gpio, offset);
+ unsigned int bit_value = value ? BIT(bit) : 0;
- if (value)
- regmap_set_bits(exar_gpio->regmap, addr, BIT(bit));
- else
- regmap_clear_bits(exar_gpio->regmap, addr, BIT(bit));
+ /*
+ * regmap_write_bits forces value to be written when an external
+ * pull up/down might otherwise indicate value was already set
+ */
+ regmap_write_bits(exar_gpio->regmap, addr, BIT(bit), bit_value);
}
static int exar_direction_output(struct gpio_chip *chip, unsigned int offset,
--
2.34.1
next reply other threads:[~2024-07-30 13:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-30 13:46 Sai Kumar Cholleti [this message]
2024-08-01 15:18 ` [PATCH] gpio: exar set value handling for hw with gpio pull-up or pull-down Matthew McClain
2024-08-12 17:22 ` Andy Shevchenko
2024-08-13 15:07 ` Matthew McClain
2024-11-04 13:25 ` Andy Shevchenko
2024-11-04 15:47 ` [PATCH v2] gpio: exar: set value when external pull-up or pull-down is present Sai Kumar Cholleti
2024-11-04 18:56 ` Andy Shevchenko
2024-11-05 7:15 ` [PATCH v3] " Sai Kumar Cholleti
2024-11-05 14:39 ` Andy Shevchenko
2024-11-12 15:30 ` Andy Shevchenko
2024-11-18 11:00 ` Bartosz Golaszewski
2024-11-18 12:34 ` Andy Shevchenko
2024-11-19 13:50 ` sai kumar
2024-11-21 8:10 ` Bartosz Golaszewski
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=20240730134610.80986-1-skmr537@gmail.com \
--to=skmr537@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bgolaszewski@baylibre.com \
--cc=linux-gpio@vger.kernel.org \
--cc=mmcclain@noprivs.com \
/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.