]> cvs.zerfleddert.de Git - ms2-fixes/blobdiff - debounce.c
zero is a valid delay
[ms2-fixes] / debounce.c
index e6398dcb9ab262a9e7113ef0ea2473001e2be0d1..852118f020e8a3449fe52c6e1252f7898c1b99c9 100644 (file)
@@ -5,10 +5,14 @@
 
 #define PREFIX "debounce: "
 
 
 #define PREFIX "debounce: "
 
-static int delay = 5;
+static int debounce_delay = 15;
 
 
-module_param(delay, int, S_IRUSR | S_IRGRP | S_IROTH);
-MODULE_PARM_DESC(delay, "debouncing delay (ms), default: 5");
+static int old_delay = 0;
+static unsigned old_flags = 0;
+static struct gpio_event_matrix_info *gpio_evmi = NULL;
+
+module_param(debounce_delay, int, S_IRUSR | S_IRGRP | S_IROTH);
+MODULE_PARM_DESC(debounce_delay, "debouncing delay (ms), default: 15");
 
 static int find_ms2_dev(struct device *dev, void *data)
 {
 
 static int find_ms2_dev(struct device *dev, void *data)
 {
@@ -24,7 +28,6 @@ static int __init debounce_init(void)
        struct device *event_dev = NULL;
        struct gpio_event_platform_data *gpio_epd;
        struct gpio_event_info *gpio_ei;
        struct device *event_dev = NULL;
        struct gpio_event_platform_data *gpio_epd;
        struct gpio_event_info *gpio_ei;
-       struct gpio_event_matrix_info *gpio_evmi;
 
        printk(KERN_INFO PREFIX "Searching for " GPIO_EVENT_DEV_NAME "...\n");
 
 
        printk(KERN_INFO PREFIX "Searching for " GPIO_EVENT_DEV_NAME "...\n");
 
@@ -46,24 +49,46 @@ static int __init debounce_init(void)
        printk(KERN_INFO PREFIX "debounce_delay: %u\n", gpio_evmi->debounce_delay.tv.nsec);
        printk(KERN_INFO PREFIX "flags: 0x%x\n", gpio_evmi->flags);
 
        printk(KERN_INFO PREFIX "debounce_delay: %u\n", gpio_evmi->debounce_delay.tv.nsec);
        printk(KERN_INFO PREFIX "flags: 0x%x\n", gpio_evmi->flags);
 
-       /* GPIOKPF_DEBOUNCE should already be set by GPIOKPF_REMOVE_PHANTOM_KEYS */
-       if (!(gpio_evmi->flags & GPIOKPF_DEBOUNCE)) {
-               printk(KERN_INFO PREFIX "Activating debounce\n");
-               gpio_evmi->flags |= GPIOKPF_DEBOUNCE;
-               printk(KERN_INFO PREFIX "flags: 0x%x\n", gpio_evmi->flags);
-       }
+       old_delay = gpio_evmi->debounce_delay.tv.nsec;
 
 
-       if (gpio_evmi->debounce_delay.tv.nsec != delay * NSEC_PER_MSEC) {
+       if (gpio_evmi->debounce_delay.tv.nsec != debounce_delay * NSEC_PER_MSEC) {
                printk(KERN_INFO PREFIX "Changing debounce_delay\n");
                printk(KERN_INFO PREFIX "Changing debounce_delay\n");
-               gpio_evmi->debounce_delay.tv.nsec = delay * NSEC_PER_MSEC;
+               gpio_evmi->debounce_delay.tv.nsec = debounce_delay * NSEC_PER_MSEC;
                printk(KERN_INFO PREFIX "debounce_delay: %u\n", gpio_evmi->debounce_delay.tv.nsec);
        }
 
                printk(KERN_INFO PREFIX "debounce_delay: %u\n", gpio_evmi->debounce_delay.tv.nsec);
        }
 
+       old_flags = gpio_evmi->flags;
+
+       if (gpio_evmi->debounce_delay.tv.nsec != 0) {
+               /* GPIOKPF_DEBOUNCE should already be set by GPIOKPF_REMOVE_PHANTOM_KEYS */
+               if (!(gpio_evmi->flags & GPIOKPF_DEBOUNCE)) {
+                       printk(KERN_INFO PREFIX "Activating debounce\n");
+                       gpio_evmi->flags |= GPIOKPF_DEBOUNCE;
+               }
+       } else {
+               /* Deactivating GPIOKPF_DEBOUNCE */
+               printk(KERN_INFO PREFIX "Deactivating debounce\n");
+               gpio_evmi->flags &= ~GPIOKPF_DEBOUNCE;
+       }
+       printk(KERN_INFO PREFIX "flags: 0x%x\n", gpio_evmi->flags);
+
        return 0;
 }
 
 static void __exit debounce_exit(void)
 {
        return 0;
 }
 
 static void __exit debounce_exit(void)
 {
+       if (gpio_evmi) {
+               if (gpio_evmi->debounce_delay.tv.nsec != old_delay) {
+                       printk(KERN_INFO PREFIX "Restoring debounce_delay\n");
+                       gpio_evmi->debounce_delay.tv.nsec = old_delay;
+                       printk(KERN_INFO PREFIX "debounce_delay: %u\n", gpio_evmi->debounce_delay.tv.nsec);
+               }
+               if (gpio_evmi->flags != old_flags) {
+                       printk(KERN_INFO PREFIX "Restoring flags\n");
+                       gpio_evmi->flags = old_flags;
+                       printk(KERN_INFO PREFIX "flags: 0x%x\n", gpio_evmi->flags);
+               }
+       }
 }
 
 module_init(debounce_init);
 }
 
 module_init(debounce_init);
Impressum, Datenschutz