]> git.zerfleddert.de Git - ms2-fixes/commitdiff
make hw_debounce user configurable
authorMichael Gernoth <michael@gernoth.net>
Sun, 21 Aug 2011 13:05:25 +0000 (15:05 +0200)
committerMichael Gernoth <michael@gernoth.net>
Sun, 21 Aug 2011 13:05:25 +0000 (15:05 +0200)
MS2Debounce/assets/debounce.ko
debounce.c

index f9753eb03f921f1a993a7832d39375e12bb31b02..9de2161224619a97a93ca0404ccb56685a2951f3 100644 (file)
Binary files a/MS2Debounce/assets/debounce.ko and b/MS2Debounce/assets/debounce.ko differ
index 5694d1286b780bd97005050e4f05eacff763933a..3176d4c2e6a8c9bbf8335ddf0a743cc78122c02c 100644 (file)
@@ -4,16 +4,15 @@
 #include <linux/gpio_event.h>
 #include <mach/gpio.h>
 
-/* hardware debounce: (value + 1) * 31us */
-#define GPIO_DEBOUNCE_TIME              0x1
-
 #define PREFIX "debounce: "
 
 static unsigned old_flags = 0;
-ktime_t old_debounce_delay;
-ktime_t old_settle_time;
-ktime_t old_poll_time;
+static ktime_t old_debounce_delay;
+static ktime_t old_settle_time;
+static ktime_t old_poll_time;
 static struct gpio_event_matrix_info *gpio_evmi = NULL;
+static int hw_debounce = 0;
+static int hw_debounce_time = 0;
 
 static int find_ms2_dev(struct device *dev, void *data)
 {
@@ -24,6 +23,29 @@ static int find_ms2_dev(struct device *dev, void *data)
        return 0;
 }
 
+/* hardware debounce: (time + 1) * 31us */
+static void hw_debounce_set(int enable, int time) {
+       int i;
+
+       if (gpio_evmi == NULL)
+               return;
+
+       for (i = 0; i < gpio_evmi->ninputs; i++) {
+               int gpio = gpio_evmi->input_gpios[i];
+
+               if (enable != -1) {
+                       printk(KERN_INFO PREFIX "%sabling hardware debounce for GPIO %d\n", (enable?"En":"Dis"), gpio);
+                       omap_set_gpio_debounce(gpio, enable);
+               }
+
+               if (time != -1) {
+                       printk(KERN_INFO PREFIX "Setting hardware debounce itime for GPIO %d to %d (%dus)\n", gpio, time, (time+1)*31);
+                       omap_set_gpio_debounce_time(gpio, time);
+               }
+       }
+}
+
+
 static ssize_t show_debounce_delay(struct device *dev, struct device_attribute *attr, char *buf)
 {
        if (!gpio_evmi) 
@@ -316,6 +338,49 @@ static ssize_t store_drive_inactive_flag(struct device *dev, struct device_attri
        return count;
 }
 
+static ssize_t show_hw_debounce(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       return snprintf(buf, PAGE_SIZE, "%d\n", hw_debounce);
+}
+
+static ssize_t store_hw_debounce(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+{
+       int enable;
+
+       sscanf(buf, "%d", &enable);
+
+       if (enable) {
+               hw_debounce_set(1, -1);
+               hw_debounce = 1;
+       }
+       else {
+               hw_debounce_set(0, -1);
+               hw_debounce = 0;
+       }
+
+       return count;
+}
+
+static ssize_t show_hw_debounce_time(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       return snprintf(buf, PAGE_SIZE, "%d\n", hw_debounce_time);
+}
+
+static ssize_t store_hw_debounce_time(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+{
+       int time;
+
+       sscanf(buf, "%d", &time);
+
+       if ((time < 0) || (time > 0xff))
+               return count;
+
+       hw_debounce_set(-1, time);
+       hw_debounce_time = time;
+
+       return count;
+}
+
 static DEVICE_ATTR(debounce_delay, (S_IRUGO | S_IWUGO), show_debounce_delay, store_debounce_delay);
 static DEVICE_ATTR(settle_time, (S_IRUGO | S_IWUGO), show_settle_time, store_settle_time);
 static DEVICE_ATTR(poll_time, (S_IRUGO | S_IWUGO), show_poll_time, store_poll_time);
@@ -327,6 +392,8 @@ static DEVICE_ATTR(print_mapped_keys_flag, (S_IRUGO | S_IWUGO), show_print_mappe
 static DEVICE_ATTR(print_phantom_keys_flag, (S_IRUGO | S_IWUGO), show_print_phantom_keys_flag, store_print_phantom_keys_flag);
 static DEVICE_ATTR(active_high_flag, (S_IRUGO), show_active_high_flag, store_active_high_flag);
 static DEVICE_ATTR(drive_inactive_flag, (S_IRUGO | S_IWUGO), show_drive_inactive_flag, store_drive_inactive_flag);
+static DEVICE_ATTR(hw_debounce, (S_IRUGO | S_IWUGO), show_hw_debounce, store_hw_debounce);
+static DEVICE_ATTR(hw_debounce_time, (S_IRUGO | S_IWUGO), show_hw_debounce_time, store_hw_debounce_time);
 
 static void debounce_release(struct device *dev)
 {
@@ -337,24 +404,6 @@ static struct device debounce_device = {
        .release = debounce_release,
 };
 
-static void hw_debounce_pin(int gpio, int enable) {
-       printk(KERN_INFO PREFIX "%sabling hardware debounce for GPIO %d\n", (enable?"En":"Dis"), gpio);
-       if (enable)
-               omap_set_gpio_debounce_time(gpio, GPIO_DEBOUNCE_TIME);
-       omap_set_gpio_debounce(gpio, enable);
-}
-
-static void hw_debounce(int enable) {
-       int i;
-
-       if (gpio_evmi == NULL)
-               return;
-
-       for (i = 0; i < gpio_evmi->ninputs; i++) {
-               hw_debounce_pin(gpio_evmi->input_gpios[i], enable);
-       }
-}
-
 static int __init debounce_init(void)
 {
        struct device *event_dev = NULL;
@@ -381,8 +430,6 @@ static int __init debounce_init(void)
                return err;
        }
 
-       hw_debounce(1);
-
        err = device_create_file(&debounce_device, &dev_attr_debounce_delay);
        err = device_create_file(&debounce_device, &dev_attr_settle_time);
        err = device_create_file(&debounce_device, &dev_attr_poll_time);
@@ -394,6 +441,8 @@ static int __init debounce_init(void)
        err = device_create_file(&debounce_device, &dev_attr_print_phantom_keys_flag);
        err = device_create_file(&debounce_device, &dev_attr_active_high_flag);
        err = device_create_file(&debounce_device, &dev_attr_drive_inactive_flag);
+       err = device_create_file(&debounce_device, &dev_attr_hw_debounce);
+       err = device_create_file(&debounce_device, &dev_attr_hw_debounce_time);
 
        printk(KERN_INFO PREFIX "settle_time: %u\n", gpio_evmi->settle_time.tv.nsec);
        printk(KERN_INFO PREFIX "poll_time: %u\n", gpio_evmi->poll_time.tv.nsec);
@@ -426,7 +475,7 @@ static void __exit debounce_exit(void)
                gpio_evmi->settle_time = old_settle_time;
                gpio_evmi->poll_time = old_poll_time;
        }
-       hw_debounce(0);
+       hw_debounce_set(0, 0);
        device_remove_file(&debounce_device, &dev_attr_debounce_delay);
        device_remove_file(&debounce_device, &dev_attr_settle_time);
        device_remove_file(&debounce_device, &dev_attr_poll_time);
@@ -438,6 +487,8 @@ static void __exit debounce_exit(void)
        device_remove_file(&debounce_device, &dev_attr_print_phantom_keys_flag);
        device_remove_file(&debounce_device, &dev_attr_active_high_flag);
        device_remove_file(&debounce_device, &dev_attr_drive_inactive_flag);
+       device_remove_file(&debounce_device, &dev_attr_hw_debounce);
+       device_remove_file(&debounce_device, &dev_attr_hw_debounce_time);
        device_unregister(&debounce_device);
 }
 
Impressum, Datenschutz