From: Linus Walleij <linus.walleij@linaro.org>
To: linux-gpio@vger.kernel.org
Cc: Linus Walleij <linus.walleij@linaro.org>,
Anton Vorontsov <anton@enomsg.org>,
Lukas Wunner <lukas@wunner.de>
Subject: [PATCH v2] gpio-mmio: Use the new .get_multiple() callback
Date: Fri, 20 Oct 2017 00:33:43 +0200 [thread overview]
Message-ID: <20171019223343.13927-1-linus.walleij@linaro.org> (raw)
It is possible to read all lines of a generic MMIO GPIO chip
with a single register read so support this if we are in
native endianness.
Add an especially quirky callback to read multiple lines for
the variants that require you to read values from the
output registers if and only if the line is set as output.
We managed to do that with a maximum of two register reads,
and just one read if the requested lines are all input or all
output.
Cc: Anton Vorontsov <anton@enomsg.org>
Cc: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v1->v2:
- Only assign the functions for multiple get if we are in
native endianness. Else each bit needs to be processed
differently after read and it will be a mess. Likely
the old get functions are better in this case.
- Directly write into *bits in both functions.
---
drivers/gpio/gpio-mmio.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 47 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpio-mmio.c b/drivers/gpio/gpio-mmio.c
index f7da40e46c55..cdfe1192be1d 100644
--- a/drivers/gpio/gpio-mmio.c
+++ b/drivers/gpio/gpio-mmio.c
@@ -147,11 +147,49 @@ static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio)
return !!(gc->read_reg(gc->reg_dat) & pinmask);
}
+/*
+ * This only works if the bits in the GPIO register are in native endianness.
+ * We only assign it if we have that.
+ */
+static int bgpio_get_set_multiple(struct gpio_chip *gc, unsigned long *mask,
+ unsigned long *bits)
+{
+ unsigned long get_mask = 0;
+ unsigned long set_mask = 0;
+ int bit = 0;
+
+ while ((bit = find_next_bit(mask, gc->ngpio, bit)) != gc->ngpio) {
+ if (gc->bgpio_dir & BIT(bit))
+ set_mask |= BIT(bit);
+ else
+ get_mask |= BIT(bit);
+ }
+
+ if (set_mask)
+ *bits |= gc->read_reg(gc->reg_set) & set_mask;
+ if (get_mask)
+ *bits |= gc->read_reg(gc->reg_dat) & get_mask;
+
+ return 0;
+}
+
static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)
{
return !!(gc->read_reg(gc->reg_dat) & gc->pin2mask(gc, gpio));
}
+/*
+ * This only works if the bits in the GPIO register are in native endianness.
+ * We only assign it if we have that.
+ */
+static int bgpio_get_multiple(struct gpio_chip *gc, unsigned long *mask,
+ unsigned long *bits)
+{
+ *bits = gc->read_reg(gc->reg_dat) & *mask;
+
+ return 0;
+}
+
static void bgpio_set_none(struct gpio_chip *gc, unsigned int gpio, int val)
{
}
@@ -462,10 +500,17 @@ static int bgpio_setup_io(struct gpio_chip *gc,
}
if (!(flags & BGPIOF_UNREADABLE_REG_SET) &&
- (flags & BGPIOF_READ_OUTPUT_REG_SET))
+ (flags & BGPIOF_READ_OUTPUT_REG_SET)) {
gc->get = bgpio_get_set;
- else
+ /* If we are in native endianness we can use the quick multiple read */
+ if (!(flags & BGPIOF_BIG_ENDIAN_BYTE_ORDER))
+ gc->get_multiple = bgpio_get_set_multiple;
+ } else {
gc->get = bgpio_get;
+ /* If we are in native endianness we can use the quick multiple read */
+ if (!(flags & BGPIOF_BIG_ENDIAN_BYTE_ORDER))
+ gc->get_multiple = bgpio_get_multiple;
+ }
return 0;
}
--
2.13.6
reply other threads:[~2017-10-19 22:35 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20171019223343.13927-1-linus.walleij@linaro.org \
--to=linus.walleij@linaro.org \
--cc=anton@enomsg.org \
--cc=linux-gpio@vger.kernel.org \
--cc=lukas@wunner.de \
/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).