From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
To: Linus Walleij <linus.walleij@linaro.org>,
Alexandre Courbot <gnurou@gmail.com>,
Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: [PATCH 2/7] gpiolib: support monitoring mockup devices
Date: Wed, 25 Jan 2017 16:34:16 +0100 [thread overview]
Message-ID: <1485358461-24070-3-git-send-email-bgolaszewski@baylibre.com> (raw)
In-Reply-To: <1485358461-24070-1-git-send-email-bgolaszewski@baylibre.com>
Add a new flag to struct gpio_chip indicating that the chip doesn't
model a real device. When setting up the line event queue, check if
a device is a mockup chip and don't actually request the interrupt.
This way we can monitor mockup GPIOs.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
drivers/gpio/gpiolib.c | 27 +++++++++++++++++----------
include/linux/gpio/driver.h | 4 ++++
2 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 6722579..19b4b8b 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -735,6 +735,7 @@ static irqreturn_t lineevent_irq_thread(int irq, void *p)
static int lineevent_create(struct gpio_device *gdev, void __user *ip)
{
+ struct gpio_chip *chip = gdev->chip;
struct gpioevent_request eventreq;
struct lineevent_state *le;
struct gpio_desc *desc;
@@ -807,7 +808,8 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
goto out_free_desc;
le->irq = gpiod_to_irq(desc);
- if (le->irq <= 0) {
+ /* Mockup gpiochips don't have to support this. */
+ if (le->irq <= 0 && !chip->mockup) {
ret = -ENODEV;
goto out_free_desc;
}
@@ -823,15 +825,20 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
init_waitqueue_head(&le->wait);
mutex_init(&le->read_lock);
- /* Request a thread to read the events */
- ret = request_threaded_irq(le->irq,
- NULL,
- lineevent_irq_thread,
- irqflags,
- le->label,
- le);
- if (ret)
- goto out_free_desc;
+ if (!chip->mockup) {
+ /*
+ * Request a thread to read the events unless we're dealing
+ * with a mockup gpiochip.
+ */
+ ret = request_threaded_irq(le->irq,
+ NULL,
+ lineevent_irq_thread,
+ irqflags,
+ le->label,
+ le);
+ if (ret)
+ goto out_free_desc;
+ }
fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC);
if (fd < 0) {
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index e973fab..912eae1 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -82,6 +82,9 @@ enum single_ended_mode {
* implies that if the chip supports IRQs, these IRQs need to be threaded
* as the chip access may sleep when e.g. reading out the IRQ status
* registers.
+ * @mockup: if set, the flag signifies that this gpiochip does not model a
+ * real device; this can affect the way the chip is handled internally
+ * by gpiolib.
* @read_reg: reader function for generic GPIO
* @write_reg: writer function for generic GPIO
* @pin2mask: some generic GPIO controllers work with the big-endian bits
@@ -166,6 +169,7 @@ struct gpio_chip {
u16 ngpio;
const char *const *names;
bool can_sleep;
+ bool mockup;
#if IS_ENABLED(CONFIG_GPIO_GENERIC)
unsigned long (*read_reg)(void __iomem *reg);
--
2.9.3
next prev parent reply other threads:[~2017-01-25 15:34 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-25 15:34 [PATCH 0/7] gpio: mockup: extensions for testing purposes Bartosz Golaszewski
2017-01-25 15:34 ` [PATCH 1/7] gpiolib: clean up includes Bartosz Golaszewski
2017-01-31 13:20 ` Linus Walleij
2017-01-25 15:34 ` Bartosz Golaszewski [this message]
2017-01-31 13:23 ` [PATCH 2/7] gpiolib: support monitoring mockup devices Linus Walleij
2017-01-25 15:34 ` [PATCH 3/7] gpio: mockup: set the mockup flag in struct gpio_chip Bartosz Golaszewski
2017-01-25 15:34 ` [PATCH 4/7] gpiolib: allow injecting line events Bartosz Golaszewski
2017-01-31 13:24 ` Linus Walleij
2017-01-25 15:34 ` [PATCH 5/7] gpio: mockup: implement injecting events over debugfs Bartosz Golaszewski
2017-01-25 15:34 ` [PATCH 6/7] gpio: mockup: implement naming the GPIO lines Bartosz Golaszewski
2017-01-25 15:34 ` [PATCH 7/7] gpio: mockup: readability tweaks Bartosz Golaszewski
2017-01-31 13:28 ` [PATCH 0/7] gpio: mockup: extensions for testing purposes Linus Walleij
2017-01-31 14:05 ` Bartosz Golaszewski
2017-01-31 14:11 ` Lars-Peter Clausen
2017-01-31 14:21 ` 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=1485358461-24070-3-git-send-email-bgolaszewski@baylibre.com \
--to=bgolaszewski@baylibre.com \
--cc=bamvor.zhangjian@linaro.org \
--cc=gnurou@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@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).