linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 4/7] gpiolib: allow injecting line events
Date: Wed, 25 Jan 2017 16:34:18 +0100	[thread overview]
Message-ID: <1485358461-24070-5-git-send-email-bgolaszewski@baylibre.com> (raw)
In-Reply-To: <1485358461-24070-1-git-send-email-bgolaszewski@baylibre.com>

Implement a routine visible inside the drivers/gpio directory, that
allows to inject line events for testing/debugging purposes.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 drivers/gpio/gpiolib.c | 16 ++++++++++++++++
 drivers/gpio/gpiolib.h |  4 ++++
 2 files changed, 20 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 19b4b8b..8dde5f1 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -643,6 +643,7 @@ static int lineevent_release(struct inode *inode, struct file *filep)
 	struct gpio_device *gdev = le->gdev;
 
 	free_irq(le->irq, le);
+	le->desc->le = NULL;
 	gpiod_free(le->desc);
 	kfree(le->label);
 	kfree(le);
@@ -733,6 +734,20 @@ static irqreturn_t lineevent_irq_thread(int irq, void *p)
 	return IRQ_HANDLED;
 }
 
+void gpiod_inject_event(struct gpio_desc *desc)
+{
+	struct lineevent_state *le = desc->le;
+	unsigned long flags;
+
+	if (le) {
+		/* Act as if we were in interrupt context. */
+		local_irq_save(flags);
+		lineevent_irq_thread(-1 /* unused */, le);
+		local_irq_restore(flags);
+	}
+}
+EXPORT_SYMBOL(gpiod_inject_event);
+
 static int lineevent_create(struct gpio_device *gdev, void __user *ip)
 {
 	struct gpio_chip *chip = gdev->chip;
@@ -794,6 +809,7 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
 	if (ret)
 		goto out_free_desc;
 	le->desc = desc;
+	desc->le = le;
 	le->eflags = eflags;
 
 	if (lflags & GPIOHANDLE_REQUEST_ACTIVE_LOW)
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index 067e5e5..3c87222 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -23,6 +23,7 @@ enum of_gpio_flags;
 enum gpiod_flags;
 enum gpio_lookup_flags;
 struct acpi_device;
+struct lineevent_state;
 
 /**
  * struct gpio_device - internal state container for GPIO devices
@@ -196,12 +197,15 @@ struct gpio_desc {
 	const char		*label;
 	/* Name of the GPIO */
 	const char		*name;
+	/* Private: line event context for the GPIO */
+	struct lineevent_state  *le;
 };
 
 int gpiod_request(struct gpio_desc *desc, const char *label);
 void gpiod_free(struct gpio_desc *desc);
 int gpiod_hog(struct gpio_desc *desc, const char *name,
 		unsigned long lflags, enum gpiod_flags dflags);
+void gpiod_inject_event(struct gpio_desc *desc);
 
 /*
  * Return the GPIO number of the passed descriptor relative to its chip
-- 
2.9.3

  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 ` [PATCH 2/7] gpiolib: support monitoring mockup devices Bartosz Golaszewski
2017-01-31 13:23   ` 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 ` Bartosz Golaszewski [this message]
2017-01-31 13:24   ` [PATCH 4/7] gpiolib: allow injecting line events 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-5-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).