]>
git.zerfleddert.de Git - ms2-fixes/blob - debounce.c
9ae93f2283ed75259d37275d3013395d02947426
1 #include <linux/module.h>
2 #include <linux/device.h>
3 #include <linux/platform_device.h>
4 #include <linux/gpio_event.h>
6 #define PREFIX "debounce: "
10 module_param(delay
, int, S_IRUSR
| S_IRGRP
| S_IROTH
);
11 MODULE_PARM_DESC(delay
, "debouncing delay (ms), default: 10");
13 static int find_ms2_dev(struct device
*dev
, void *data
)
15 if (!strncmp((char*)data
, dev_name(dev
), strlen((char*)data
))) {
16 printk(KERN_INFO PREFIX
"Found it\n");
22 static int __init
debounce_init(void)
24 struct device
*event_dev
= NULL
;
25 struct gpio_event_platform_data
*gpio_epd
;
26 struct gpio_event_info
*gpio_ei
;
27 struct gpio_event_matrix_info
*gpio_evmi
;
29 printk(KERN_INFO PREFIX
"Searching for " GPIO_EVENT_DEV_NAME
"...\n");
32 event_dev
= device_find_child(&platform_bus
, GPIO_EVENT_DEV_NAME
, find_ms2_dev
);
33 if (event_dev
== NULL
)
36 gpio_epd
= (struct gpio_event_platform_data
*)event_dev
->platform_data
;
37 printk(KERN_INFO PREFIX
"And there is a %s connected...\n", gpio_epd
->name
);
38 if (strcmp(gpio_epd
->name
, "sholes-keypad"))
41 gpio_ei
= (struct gpio_event_info
*)gpio_epd
->info
[0];
42 gpio_evmi
= container_of(gpio_ei
, struct gpio_event_matrix_info
, info
);
44 printk(KERN_INFO PREFIX
"settle_time: %u\n", gpio_evmi
->settle_time
.tv
.nsec
);
45 printk(KERN_INFO PREFIX
"poll_time: %u\n", gpio_evmi
->poll_time
.tv
.nsec
);
46 printk(KERN_INFO PREFIX
"debounce_delay: %u\n", gpio_evmi
->debounce_delay
.tv
.nsec
);
47 printk(KERN_INFO PREFIX
"flags: 0x%x\n", gpio_evmi
->flags
);
49 /* GPIOKPF_DEBOUNCE should already be set by GPIOKPF_REMOVE_PHANTOM_KEYS */
50 if (!(gpio_evmi
->flags
& GPIOKPF_DEBOUNCE
)) {
51 printk(KERN_INFO PREFIX
"Activating debounce\n");
52 gpio_evmi
->flags
|= GPIOKPF_DEBOUNCE
;
53 printk(KERN_INFO PREFIX
"flags: 0x%x\n", gpio_evmi
->flags
);
56 if (gpio_evmi
->debounce_delay
.tv
.nsec
!= delay
* NSEC_PER_MSEC
) {
57 printk(KERN_INFO PREFIX
"Changing debounce_delay\n");
58 gpio_evmi
->debounce_delay
.tv
.nsec
= delay
* NSEC_PER_MSEC
;
59 printk(KERN_INFO PREFIX
"debounce_delay: %u\n", gpio_evmi
->debounce_delay
.tv
.nsec
);
65 static void __exit
debounce_exit(void)
69 module_init(debounce_init
);
70 module_exit(debounce_exit
);
72 MODULE_LICENSE("GPL");
73 MODULE_AUTHOR("Michael Gernoth <michael@gernoth.net>");