diff mbox series

[17/22] gpiolib: cdev: report edge detection in lineinfo

Message ID 20200623040107.22270-18-warthog618@gmail.com
State New
Headers show
Series [01/22] gpiolib: move gpiolib-sysfs function declarations into their own header | expand

Commit Message

Kent Gibson June 23, 2020, 4:01 a.m. UTC
Report the state of edge detection for a line in the gpioline_info_v2
returned by GPIO_GET_LINEINFO_V2_IOCTL, and indirectly for lines watched
by GPIO_GET_LINEINFO_WATCH_V2_IOCTL.

Signed-off-by: Kent Gibson <warthog618@gmail.com>

---
 drivers/gpio/gpiolib-cdev.c | 14 ++++++++++++++
 drivers/gpio/gpiolib.c      |  2 ++
 drivers/gpio/gpiolib.h      |  2 ++
 3 files changed, 18 insertions(+)
diff mbox series

Patch

diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index d4a22d78953f..7ba0929b2741 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -566,6 +566,12 @@  static void edge_detector_stop(struct edge_detector *edet)
 static int edge_detector_setup(struct edge_detector *edet,
 			       struct gpioline_config *lc)
 {
+	struct gpio_desc *desc = edge_detector_desc(edet);
+
+	if (lc->edge_detection & GPIOLINE_EDGE_RISING)
+		set_bit(FLAG_EDGE_RISING, &desc->flags);
+	if (lc->edge_detection & GPIOLINE_EDGE_FALLING)
+		set_bit(FLAG_EDGE_FALLING, &desc->flags);
 	if (lc->edge_detection)
 		return edge_detector_start(edet);
 	return 0;
@@ -1574,6 +1580,14 @@  static void gpio_desc_to_lineinfo(struct gpio_desc *desc,
 	}
 
 	lc->edge_detection = 0;
+	if (test_bit(FLAG_EDGE_RISING, &desc->flags)) {
+		lc->flags |= GPIOLINE_FLAG_V2_EDGE_DETECTION;
+		lc->edge_detection |= GPIOLINE_EDGE_RISING;
+	}
+	if (test_bit(FLAG_EDGE_FALLING, &desc->flags)) {
+		lc->flags |= GPIOLINE_FLAG_V2_EDGE_DETECTION;
+		lc->edge_detection |= GPIOLINE_EDGE_FALLING;
+	}
 
 	spin_unlock_irqrestore(&gpio_lock, flags);
 }
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 517c99ddf6c8..a5f2795e17b7 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2041,6 +2041,8 @@  static bool gpiod_free_commit(struct gpio_desc *desc)
 		clear_bit(FLAG_PULL_UP, &desc->flags);
 		clear_bit(FLAG_PULL_DOWN, &desc->flags);
 		clear_bit(FLAG_BIAS_DISABLE, &desc->flags);
+		clear_bit(FLAG_EDGE_RISING, &desc->flags);
+		clear_bit(FLAG_EDGE_FALLING, &desc->flags);
 		clear_bit(FLAG_IS_HOGGED, &desc->flags);
 #ifdef CONFIG_OF_DYNAMIC
 		desc->hog = NULL;
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index 2dee4e1e12dc..1dc6d2b191af 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -114,6 +114,8 @@  struct gpio_desc {
 #define FLAG_PULL_UP    13	/* GPIO has pull up enabled */
 #define FLAG_PULL_DOWN  14	/* GPIO has pull down enabled */
 #define FLAG_BIAS_DISABLE    15	/* GPIO has pull disabled */
+#define FLAG_EDGE_RISING     16	/* GPIO CDEV detects rising edge events */
+#define FLAG_EDGE_FALLING    17	/* GPIO CDEV detects falling edge events */
 
 	/* Connection label */
 	const char		*label;