[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200419002220.105338-1-hector.bujanda@digi.com>
Date: Sat, 18 Apr 2020 17:22:20 -0700
From: Hector Bujanda <hector.bujanda@...i.com>
To: unlisted-recipients:; (no To-header on input)
CC: Hector Bujanda <hector.bujanda@...i.com>,
Linus Walleij <linus.walleij@...aro.org>,
<linux-gpio@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: [PATCH] gpiolib: add GPIO_SET_DEBOUNCE_IOCTL
This allows calling gpiod_set_debounce function through char device ioctl.
Signed-off-by: Hector Bujanda <hector.bujanda@...i.com>
---
drivers/gpio/gpiolib.c | 12 ++++++++++++
include/uapi/linux/gpio.h | 12 ++++++++++++
2 files changed, 24 insertions(+)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 70f0dedca59f..c959c2962f15 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1073,6 +1073,18 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
if (copy_to_user(ip, &lineinfo, sizeof(lineinfo)))
return -EFAULT;
return 0;
+ } else if (cmd == GPIO_SET_DEBOUNCE_IOCTL) {
+ struct gpioline_debounce linedebounce;
+ struct gpio_desc *desc;
+
+ if (copy_from_user(&linedebounce, ip, sizeof(linedebounce)))
+ return -EFAULT;
+ if (linedebounce.line_offset >= gdev->ngpio)
+ return -EINVAL;
+
+ desc = &gdev->descs[linedebounce.line_offset];
+
+ return gpiod_set_debounce(desc, linedebounce.debounce_usec);
} else if (cmd == GPIO_GET_LINEHANDLE_IOCTL) {
return linehandle_create(gdev, ip);
} else if (cmd == GPIO_GET_LINEEVENT_IOCTL) {
diff --git a/include/uapi/linux/gpio.h b/include/uapi/linux/gpio.h
index 1bf6e6df084b..4b092990d4c8 100644
--- a/include/uapi/linux/gpio.h
+++ b/include/uapi/linux/gpio.h
@@ -53,6 +53,17 @@ struct gpioline_info {
char consumer[32];
};
+/**
+ * struct gpioline_debounce - GPIO line debounce
+ * @line_offset: the local offset on this GPIO device, fill this in when
+ * requesting the line information from the kernel
+ * @debounce_usec: debounce in uSeconds to set for this line
+ */
+struct gpioline_debounce {
+ __u32 line_offset;
+ __u32 debounce_usec;
+};
+
/* Maximum number of requested handles */
#define GPIOHANDLES_MAX 64
@@ -154,5 +165,6 @@ struct gpioevent_data {
#define GPIO_GET_LINEINFO_IOCTL _IOWR(0xB4, 0x02, struct gpioline_info)
#define GPIO_GET_LINEHANDLE_IOCTL _IOWR(0xB4, 0x03, struct gpiohandle_request)
#define GPIO_GET_LINEEVENT_IOCTL _IOWR(0xB4, 0x04, struct gpioevent_request)
+#define GPIO_SET_DEBOUNCE_IOCTL _IOW(0xB4, 0x05, struct gpioline_debounce)
#endif /* _UAPI_GPIO_H_ */
--
2.17.1
Powered by blists - more mailing lists