]> git.zerfleddert.de Git - ms2-fixes/blobdiff - debounce.c
performance improvements
[ms2-fixes] / debounce.c
index 8e135205bb68bc39b719615324a418f0ec4c724d..845adad4cd2d174ac0d3f609f0898f0f05e4ee1f 100644 (file)
@@ -1,8 +1,64 @@
 #include <linux/module.h>
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/gpio_event.h>
+
+#define PREFIX "debounce: "
+
+static int debounce_delay = 10;
+
+module_param(debounce_delay, int, S_IRUSR | S_IRGRP | S_IROTH);
+MODULE_PARM_DESC(debounce_delay, "debouncing delay (ms), default: 10");
+
+static int find_ms2_dev(struct device *dev, void *data)
+{
+       if (!strncmp((char*)data, dev_name(dev), strlen((char*)data))) {
+               printk(KERN_INFO PREFIX "Found it\n");
+               return 1;
+       }
+       return 0;
+}
 
 static int __init debounce_init(void)
 {
-       printk(KERN_INFO "Hello Milestone2!\n");
+       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");
+
+       
+       event_dev = device_find_child(&platform_bus, GPIO_EVENT_DEV_NAME, find_ms2_dev);
+       if (event_dev == NULL)
+               return -ENODEV;
+
+       gpio_epd = (struct gpio_event_platform_data*)event_dev->platform_data;
+       printk(KERN_INFO PREFIX "And there is a %s connected...\n", gpio_epd->name);
+       if (strcmp(gpio_epd->name, "sholes-keypad"))
+               return -ENODEV;
+
+       gpio_ei = (struct gpio_event_info*)gpio_epd->info[0];
+       gpio_evmi = container_of(gpio_ei, struct gpio_event_matrix_info, info);
+
+       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);
+       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);
+       }
+
+       if (gpio_evmi->debounce_delay.tv.nsec != debounce_delay * NSEC_PER_MSEC) {
+               printk(KERN_INFO PREFIX "Changing debounce_delay\n");
+               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);
+       }
+
        return 0;
 }
 
Impressum, Datenschutz