From ab5ed21554f59f43f285465d50d0c63e86e6626e Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Fri, 20 May 2011 15:07:25 +0200 Subject: [PATCH] make the debounce_delay modifiable via the "delay" module parameter --- debounce.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/debounce.c b/debounce.c index 7489f8c..e6398dc 100644 --- a/debounce.c +++ b/debounce.c @@ -3,10 +3,17 @@ #include #include -int find_ms2_dev(struct device *dev, void *data) +#define PREFIX "debounce: " + +static int delay = 5; + +module_param(delay, int, S_IRUSR | S_IRGRP | S_IROTH); +MODULE_PARM_DESC(delay, "debouncing delay (ms), default: 5"); + +static int find_ms2_dev(struct device *dev, void *data) { if (!strncmp((char*)data, dev_name(dev), strlen((char*)data))) { - printk(KERN_INFO "Found it!\n"); + printk(KERN_INFO PREFIX "Found it\n"); return 1; } return 0; @@ -19,7 +26,7 @@ static int __init debounce_init(void) struct gpio_event_info *gpio_ei; struct gpio_event_matrix_info *gpio_evmi; - printk(KERN_INFO "Searching for " GPIO_EVENT_DEV_NAME "...\n"); + 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); @@ -27,25 +34,29 @@ static int __init debounce_init(void) return -ENODEV; gpio_epd = (struct gpio_event_platform_data*)event_dev->platform_data; - printk(KERN_INFO "And there is a %s connected...\n", gpio_epd->name); + 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 "settle_time: %u\n", gpio_evmi->settle_time.tv.nsec); - printk(KERN_INFO "poll_time: %u\n", gpio_evmi->poll_time.tv.nsec); - printk(KERN_INFO "debounce_delay: %u\n", gpio_evmi->debounce_delay.tv.nsec); - printk(KERN_INFO "flags: %x\n", gpio_evmi->flags); - if (!gpio_evmi->debounce_delay.tv.nsec) { - printk(KERN_INFO "Activating debounce!\n"); - gpio_evmi->debounce_delay.tv.nsec = 5 * NSEC_PER_MSEC; + 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 */ + /* 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 "debounce_delay: %u\n", gpio_evmi->debounce_delay.tv.nsec); - printk(KERN_INFO "flags: %x\n", gpio_evmi->flags); + printk(KERN_INFO PREFIX "flags: 0x%x\n", gpio_evmi->flags); + } + + if (gpio_evmi->debounce_delay.tv.nsec != delay * NSEC_PER_MSEC) { + printk(KERN_INFO PREFIX "Changing debounce_delay\n"); + gpio_evmi->debounce_delay.tv.nsec = delay * NSEC_PER_MSEC; + printk(KERN_INFO PREFIX "debounce_delay: %u\n", gpio_evmi->debounce_delay.tv.nsec); } return 0; -- 2.39.5