From: Linus Walleij <linus.walleij@linaro.org>
To: H Hartley Sweeten <hsweeten@visionengravers.com>,
Alexander Sverdlin <alexander.sverdlin@gmail.com>
Cc: linux-gpio@vger.kernel.org,
Linus Walleij <linus.walleij@linaro.org>,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH 07/11] gpio: ep93xx: Do not pingpong irq numbers
Date: Wed, 22 Aug 2018 22:41:07 +0200 [thread overview]
Message-ID: <20180822204111.9581-8-linus.walleij@linaro.org> (raw)
In-Reply-To: <20180822204111.9581-1-linus.walleij@linaro.org>
For setting debounce config we want to write an offset in
a per-gpiochip register, and we know which gpiochip we are
on. Instead of a roundtrip over the IRQ number, figure out
what port we are on for this GPIO chip, then index to the
right register and write the value.
This adds the ep93xx_gpio_port() that finds the port index
from a struct gpio_chip * that we can later exploit to
simplify more code.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
drivers/gpio/gpio-ep93xx.c | 35 +++++++++++++++++++++++------------
1 file changed, 23 insertions(+), 12 deletions(-)
diff --git a/drivers/gpio/gpio-ep93xx.c b/drivers/gpio/gpio-ep93xx.c
index ce7e88df9cc5..3b235b25c028 100644
--- a/drivers/gpio/gpio-ep93xx.c
+++ b/drivers/gpio/gpio-ep93xx.c
@@ -68,12 +68,29 @@ static void ep93xx_gpio_update_int_params(struct ep93xx_gpio *epg, unsigned port
epg->base + int_en_register_offset[port]);
}
-static void ep93xx_gpio_int_debounce(struct ep93xx_gpio *epg,
- unsigned int irq, bool enable)
+static int ep93xx_gpio_port(struct gpio_chip *gc)
{
- int line = irq_to_gpio(irq);
- int port = line >> 3;
- int port_mask = 1 << (line & 7);
+ struct ep93xx_gpio *epg = gpiochip_get_data(gc);
+ int port = 0;
+
+ while (gc != &epg->gc[port] && port < sizeof(epg->gc))
+ port++;
+
+ /* This should not happen but is there as a last safeguard */
+ if (gc != &epg->gc[port]) {
+ pr_crit("can't find the GPIO port\n");
+ return 0;
+ }
+
+ return port;
+}
+
+static void ep93xx_gpio_int_debounce(struct gpio_chip *gc,
+ unsigned int offset, bool enable)
+{
+ struct ep93xx_gpio *epg = gpiochip_get_data(gc);
+ int port = ep93xx_gpio_port(gc);
+ int port_mask = BIT(offset);
if (enable)
gpio_int_debounce[port] |= port_mask;
@@ -331,19 +348,13 @@ static struct ep93xx_gpio_bank ep93xx_gpio_banks[] = {
static int ep93xx_gpio_set_config(struct gpio_chip *gc, unsigned offset,
unsigned long config)
{
- struct ep93xx_gpio *epg = gpiochip_get_data(gc);
- int gpio = gc->base + offset;
- int irq = gpio_to_irq(gpio);
u32 debounce;
if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
return -ENOTSUPP;
- if (irq < 0)
- return -EINVAL;
-
debounce = pinconf_to_config_argument(config);
- ep93xx_gpio_int_debounce(epg, irq, debounce ? true : false);
+ ep93xx_gpio_int_debounce(gc, offset, debounce ? true : false);
return 0;
}
--
2.17.1
next prev parent reply other threads:[~2018-08-22 20:41 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-22 20:41 [PATCH 00/11] Reform EP93xx GPIO Linus Walleij
2018-08-22 20:41 ` [PATCH 01/11] ARM/gpio: ep93xx: build standalone Linus Walleij
2018-08-23 7:36 ` Arnd Bergmann
2018-08-29 7:03 ` Linus Walleij
2018-08-24 15:51 ` Olof Johansson
2018-08-22 20:41 ` [PATCH 02/11] gpio: ep93xx: Cut down variable names Linus Walleij
2018-08-29 5:56 ` Alexander Sverdlin
2018-08-22 20:41 ` [PATCH 03/11] gpio: ep93xx: Switch to SPDX license tag Linus Walleij
2018-08-22 20:41 ` [PATCH 04/11] gpio: ep93xx: Pass around struct gpio_chip Linus Walleij
2018-08-22 20:41 ` [PATCH 05/11] gpio: ep93xx: Rename has_debounce to has_irq Linus Walleij
2018-08-22 20:41 ` [PATCH 06/11] gpio: ep93xx: Properly call the chained IRQ handler Linus Walleij
2018-08-22 20:41 ` Linus Walleij [this message]
2018-08-22 20:41 ` [PATCH 08/11] gpio: ep93xx: Use the hwirq and port Linus Walleij
2018-08-22 20:41 ` [PATCH 09/11] gpio: ep93xx: Use for_each_set_bit() in IRQ handler Linus Walleij
2018-08-22 20:41 ` [PATCH 10/11] gpio: ep93xx: Cut gpio_to_irq() usage Linus Walleij
2018-08-22 20:41 ` [PATCH 11/11] gpio: ep93xx: Switch A and B to use GPIOLIB_IRQCHIP Linus Walleij
2018-08-29 6:18 ` [PATCH 00/11] Reform EP93xx GPIO Alexander Sverdlin
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=20180822204111.9581-8-linus.walleij@linaro.org \
--to=linus.walleij@linaro.org \
--cc=alexander.sverdlin@gmail.com \
--cc=hsweeten@visionengravers.com \
--cc=linux-arm-kernel@lists.infradead.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).