]> git.zerfleddert.de Git - ms2-fixes/blame_incremental - debounce.c
add privacy policy
[ms2-fixes] / debounce.c
... / ...
CommitLineData
1#include <linux/module.h>
2#include <linux/device.h>
3#include <linux/platform_device.h>
4#include <linux/gpio_event.h>
5#include <linux/interrupt.h>
6#include <linux/irq.h>
7#include <mach/gpio.h>
8#include <linux/earlysuspend.h>
9#include <linux/wakelock.h>
10#include <plat/board-mapphone.h>
11
12#define PREFIX "debounce: "
13
14#define PADCONF_PULL_UP ( OMAP343X_PADCONF_OFF_WAKEUP_ENABLED | \
15 OMAP343X_PADCONF_INPUT_ENABLED | \
16 OMAP343X_PADCONF_PULL_UP | \
17 OMAP343X_PADCONF_PUD_ENABLED | \
18 OMAP343X_PADCONF_MUXMODE4 )
19
20#define PADCONF_PULL_DOWN ( OMAP343X_PADCONF_OFF_WAKEUP_ENABLED | \
21 OMAP343X_PADCONF_INPUT_ENABLED | \
22 OMAP343X_PADCONF_PULL_DOWN | \
23 OMAP343X_PADCONF_PUD_ENABLED | \
24 OMAP343X_PADCONF_MUXMODE4 )
25
26#define OMAP_CTRL_REGADDR(reg) (OMAP2_L4_IO_ADDRESS(OMAP343X_CTRL_BASE) + (reg))
27
28static unsigned old_flags = 0;
29static ktime_t old_debounce_delay;
30static ktime_t old_settle_time;
31static ktime_t old_poll_time;
32static int (*old_sw_fixup)(int index);
33static struct gpio_event_matrix_info *gpio_evmi = NULL;
34static int hw_debounce = 0;
35static int hw_debounce_time = 0;
36
37struct gpio_event {
38 struct gpio_event_input_devs *input_devs;
39 const struct gpio_event_platform_data *info;
40 struct early_suspend early_suspend;
41 void *state[0];
42};
43
44struct gpio_kp {
45 struct gpio_event_input_devs *input_devs;
46 struct gpio_event_matrix_info *keypad_info;
47 struct hrtimer timer;
48 struct wake_lock wake_lock;
49 int current_output;
50 unsigned int use_irq:1;
51 unsigned int key_state_changed:1;
52 unsigned int last_key_state_changed:1;
53 unsigned int some_keys_pressed:2;
54 unsigned long keys_pressed[0];
55};
56
57static struct gpio_kp *gpio_kp_state = NULL;
58
59static int find_ms2_dev(struct device *dev, void *data)
60{
61 if (!strncmp((char*)data, dev_name(dev), strlen((char*)data))) {
62 printk(KERN_INFO PREFIX "Found it\n");
63 return 1;
64 }
65 return 0;
66}
67
68/* hardware debounce: (time + 1) * 31us */
69static void hw_debounce_set(int enable, int time) {
70 int i;
71
72 if (gpio_evmi == NULL)
73 return;
74
75 for (i = 0; i < gpio_evmi->ninputs; i++) {
76 int gpio = gpio_evmi->input_gpios[i];
77
78 if ((time != -1) && (time != hw_debounce_time) && hw_debounce) {
79 printk(KERN_INFO PREFIX "Setting hardware debounce time for GPIO %d to %d (%dus)\n", gpio, time, (time+1)*31);
80 omap_set_gpio_debounce_time(gpio, time);
81 }
82
83 if ((enable != -1) && (enable != hw_debounce)) {
84 printk(KERN_INFO PREFIX "%sabling hardware debounce for GPIO %d\n", (enable?"En":"Dis"), gpio);
85 omap_set_gpio_debounce(gpio, enable);
86 }
87 }
88}
89
90static void set_irq_types(void) {
91 int err;
92 unsigned int irq;
93 unsigned long type;
94 int i;
95
96 if (gpio_evmi == NULL)
97 return;
98
99 switch (gpio_evmi->flags & (GPIOKPF_ACTIVE_HIGH|GPIOKPF_LEVEL_TRIGGERED_IRQ)) {
100 default:
101 type = IRQ_TYPE_EDGE_FALLING;
102 break;
103 case GPIOKPF_ACTIVE_HIGH:
104 type = IRQ_TYPE_EDGE_RISING;
105 break;
106 case GPIOKPF_LEVEL_TRIGGERED_IRQ:
107 type = IRQ_TYPE_LEVEL_LOW;
108 break;
109 case GPIOKPF_LEVEL_TRIGGERED_IRQ | GPIOKPF_ACTIVE_HIGH:
110 type = IRQ_TYPE_LEVEL_HIGH;
111 break;
112 }
113
114 printk(KERN_INFO PREFIX "Settinhg IRQ type to 0x%lx\n", type);
115
116 for (i = 0; i < gpio_evmi->ninputs; i++) {
117
118 err = irq = gpio_to_irq(gpio_evmi->input_gpios[i]);
119
120 if (err < 0)
121 return;
122
123 err = set_irq_type(irq, type);
124 }
125}
126
127static ssize_t show_debounce_delay(struct device *dev, struct device_attribute *attr, char *buf)
128{
129 if (!gpio_evmi)
130 return -ENODEV;
131
132 return snprintf(buf, PAGE_SIZE, "%ld\n", (gpio_evmi->debounce_delay.tv.nsec / NSEC_PER_MSEC));
133}
134
135static void set_debounce_delay(long delay)
136{
137 if (gpio_evmi->debounce_delay.tv.nsec != delay * NSEC_PER_MSEC) {
138 printk(KERN_INFO PREFIX "Changing debounce_delay\n");
139 gpio_evmi->debounce_delay.tv.nsec = delay * NSEC_PER_MSEC;
140 printk(KERN_INFO PREFIX "debounce_delay: %u\n", gpio_evmi->debounce_delay.tv.nsec);
141 }
142
143#if 0
144 if (gpio_evmi->debounce_delay.tv.nsec != 0) {
145 if (!(gpio_evmi->flags & GPIOKPF_DEBOUNCE)) {
146 printk(KERN_INFO PREFIX "Activating debounce\n");
147 gpio_evmi->flags |= GPIOKPF_DEBOUNCE;
148 }
149 } else {
150 if (gpio_evmi->flags & GPIOKPF_DEBOUNCE) {
151 printk(KERN_INFO PREFIX "Deactivating debounce\n");
152 gpio_evmi->flags &= ~GPIOKPF_DEBOUNCE;
153 }
154 }
155#endif
156}
157
158static ssize_t store_debounce_delay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
159{
160 long int delay;
161
162 if (!gpio_evmi)
163 return -ENODEV;
164
165 sscanf(buf, "%ld", &delay);
166 set_debounce_delay(delay);
167
168 return count;
169}
170
171static ssize_t show_settle_time(struct device *dev, struct device_attribute *attr, char *buf)
172{
173 if (!gpio_evmi)
174 return -ENODEV;
175
176 return snprintf(buf, PAGE_SIZE, "%ld\n", (gpio_evmi->settle_time.tv.nsec / NSEC_PER_USEC));
177}
178
179static ssize_t store_settle_time(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
180{
181 long int delay;
182
183 if (!gpio_evmi)
184 return -ENODEV;
185
186 sscanf(buf, "%ld", &delay);
187 gpio_evmi->settle_time.tv.nsec = delay * NSEC_PER_USEC;
188
189 return count;
190}
191
192static ssize_t show_poll_time(struct device *dev, struct device_attribute *attr, char *buf)
193{
194 if (!gpio_evmi)
195 return -ENODEV;
196
197 return snprintf(buf, PAGE_SIZE, "%ld\n", (gpio_evmi->poll_time.tv.nsec / NSEC_PER_MSEC));
198}
199
200static ssize_t store_poll_time(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
201{
202 long int delay;
203
204 if (!gpio_evmi)
205 return -ENODEV;
206
207 sscanf(buf, "%ld", &delay);
208 gpio_evmi->poll_time.tv.nsec = delay * NSEC_PER_MSEC;
209
210 return count;
211}
212
213static ssize_t show_flags(struct device *dev, struct device_attribute *attr, char *buf)
214{
215 if (!gpio_evmi)
216 return -ENODEV;
217
218 return snprintf(buf, PAGE_SIZE, "0x%x\n", gpio_evmi->flags);
219}
220
221static ssize_t store_flags(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
222{
223 unsigned flags;
224
225 if (!gpio_evmi)
226 return -ENODEV;
227
228 sscanf(buf, "0x%x", &flags);
229
230 printk(KERN_INFO PREFIX "flags: 0x%x\n", flags);
231
232 gpio_evmi->flags = flags;
233
234 return count;
235}
236
237static ssize_t show_debounce_flag(struct device *dev, struct device_attribute *attr, char *buf)
238{
239 if (!gpio_evmi)
240 return -ENODEV;
241
242 return snprintf(buf, PAGE_SIZE, "%u\n", (gpio_evmi->flags & GPIOKPF_DEBOUNCE) ? 1 : 0);
243}
244
245static ssize_t store_debounce_flag(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
246{
247 unsigned flag;
248
249 if (!gpio_evmi)
250 return -ENODEV;
251
252 sscanf(buf, "%u", &flag);
253
254 if (flag) {
255 gpio_evmi->flags |= GPIOKPF_DEBOUNCE;
256 } else {
257 gpio_evmi->flags &= ~GPIOKPF_DEBOUNCE;
258 }
259
260 return count;
261}
262
263static ssize_t show_remove_some_phantom_keys_flag(struct device *dev, struct device_attribute *attr, char *buf)
264{
265 if (!gpio_evmi)
266 return -ENODEV;
267
268 return snprintf(buf, PAGE_SIZE, "%u\n", (gpio_evmi->flags & GPIOKPF_REMOVE_SOME_PHANTOM_KEYS) ? 1 : 0);
269}
270
271static ssize_t store_remove_some_phantom_keys_flag(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
272{
273 unsigned flag;
274
275 if (!gpio_evmi)
276 return -ENODEV;
277
278 sscanf(buf, "%u", &flag);
279
280 if (flag) {
281 gpio_evmi->flags |= GPIOKPF_REMOVE_SOME_PHANTOM_KEYS;
282 } else {
283 gpio_evmi->flags &= ~GPIOKPF_REMOVE_SOME_PHANTOM_KEYS;
284 }
285
286 return count;
287}
288
289static ssize_t show_print_unmapped_keys_flag(struct device *dev, struct device_attribute *attr, char *buf)
290{
291 if (!gpio_evmi)
292 return -ENODEV;
293
294 return snprintf(buf, PAGE_SIZE, "%u\n", (gpio_evmi->flags & GPIOKPF_PRINT_UNMAPPED_KEYS) ? 1 : 0);
295}
296
297static ssize_t store_print_unmapped_keys_flag(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
298{
299 unsigned flag;
300
301 if (!gpio_evmi)
302 return -ENODEV;
303
304 sscanf(buf, "%u", &flag);
305
306 if (flag) {
307 gpio_evmi->flags |= GPIOKPF_PRINT_UNMAPPED_KEYS;
308 } else {
309 gpio_evmi->flags &= ~GPIOKPF_PRINT_UNMAPPED_KEYS;
310 }
311
312 return count;
313}
314
315static ssize_t show_print_mapped_keys_flag(struct device *dev, struct device_attribute *attr, char *buf)
316{
317 if (!gpio_evmi)
318 return -ENODEV;
319
320 return snprintf(buf, PAGE_SIZE, "%u\n", (gpio_evmi->flags & GPIOKPF_PRINT_MAPPED_KEYS) ? 1 : 0);
321}
322
323static ssize_t store_print_mapped_keys_flag(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
324{
325 unsigned flag;
326
327 if (!gpio_evmi)
328 return -ENODEV;
329
330 sscanf(buf, "%u", &flag);
331
332 if (flag) {
333 gpio_evmi->flags |= GPIOKPF_PRINT_MAPPED_KEYS;
334 } else {
335 gpio_evmi->flags &= ~GPIOKPF_PRINT_MAPPED_KEYS;
336 }
337
338 return count;
339}
340
341static ssize_t show_print_phantom_keys_flag(struct device *dev, struct device_attribute *attr, char *buf)
342{
343 if (!gpio_evmi)
344 return -ENODEV;
345
346 return snprintf(buf, PAGE_SIZE, "%u\n", (gpio_evmi->flags & GPIOKPF_PRINT_PHANTOM_KEYS) ? 1 : 0);
347}
348
349static ssize_t store_print_phantom_keys_flag(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
350{
351 unsigned flag;
352
353 if (!gpio_evmi)
354 return -ENODEV;
355
356 sscanf(buf, "%u", &flag);
357
358 if (flag) {
359 gpio_evmi->flags |= GPIOKPF_PRINT_PHANTOM_KEYS;
360 } else {
361 gpio_evmi->flags &= ~GPIOKPF_PRINT_PHANTOM_KEYS;
362 }
363
364 return count;
365}
366
367static ssize_t show_active_high_flag(struct device *dev, struct device_attribute *attr, char *buf)
368{
369 if (!gpio_evmi)
370 return -ENODEV;
371
372 return snprintf(buf, PAGE_SIZE, "%u\n", (gpio_evmi->flags & GPIOKPF_ACTIVE_HIGH) ? 1 : 0);
373}
374
375static ssize_t store_active_high_flag(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
376{
377 unsigned flag;
378 int i;
379
380 if (!gpio_evmi)
381 return -ENODEV;
382
383 sscanf(buf, "%u", &flag);
384
385 if (flag) {
386 gpio_evmi->flags |= GPIOKPF_ACTIVE_HIGH;
387 for (i = 0x7a; i <= 0x88; i += 2) {
388 __raw_writew(PADCONF_PULL_DOWN, OMAP_CTRL_REGADDR(i));
389 }
390 } else {
391 gpio_evmi->flags &= ~GPIOKPF_ACTIVE_HIGH;
392 for (i = 0x7a; i <= 0x88; i += 2) {
393 __raw_writew(PADCONF_PULL_UP, OMAP_CTRL_REGADDR(i));
394 }
395 }
396
397 set_irq_types();
398
399 return count;
400}
401
402static ssize_t show_level_triggered_irq_flag(struct device *dev, struct device_attribute *attr, char *buf)
403{
404 if (!gpio_evmi)
405 return -ENODEV;
406
407 return snprintf(buf, PAGE_SIZE, "%u\n", (gpio_evmi->flags & GPIOKPF_LEVEL_TRIGGERED_IRQ) ? 1 : 0);
408}
409
410static ssize_t store_level_triggered_irq_flag(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
411{
412 unsigned flag;
413
414 if (!gpio_evmi)
415 return -ENODEV;
416
417 sscanf(buf, "%u", &flag);
418
419 if (flag) {
420 gpio_evmi->flags |= GPIOKPF_LEVEL_TRIGGERED_IRQ;
421 } else {
422 gpio_evmi->flags &= ~GPIOKPF_LEVEL_TRIGGERED_IRQ;
423 }
424
425 set_irq_types();
426
427 return count;
428}
429
430static ssize_t show_drive_inactive_flag(struct device *dev, struct device_attribute *attr, char *buf)
431{
432 if (!gpio_evmi)
433 return -ENODEV;
434
435 return snprintf(buf, PAGE_SIZE, "%u\n", (gpio_evmi->flags & GPIOKPF_DRIVE_INACTIVE) ? 1 : 0);
436}
437
438static ssize_t store_drive_inactive_flag(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
439{
440 unsigned flag;
441
442 if (!gpio_evmi)
443 return -ENODEV;
444
445 sscanf(buf, "%u", &flag);
446
447 if (flag) {
448 gpio_evmi->flags |= GPIOKPF_DRIVE_INACTIVE;
449 } else {
450 gpio_evmi->flags &= ~GPIOKPF_DRIVE_INACTIVE;
451 }
452
453 return count;
454}
455
456static ssize_t show_hw_debounce(struct device *dev, struct device_attribute *attr, char *buf)
457{
458 return snprintf(buf, PAGE_SIZE, "%d\n", hw_debounce);
459}
460
461static ssize_t store_hw_debounce(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
462{
463 int enable;
464
465 sscanf(buf, "%d", &enable);
466
467 if (enable) {
468 hw_debounce_set(1, -1);
469 hw_debounce = 1;
470 }
471 else {
472 hw_debounce_set(-1, 0);
473 hw_debounce_set(0, -1);
474 hw_debounce = 0;
475 hw_debounce_time = 0;
476 }
477
478 return count;
479}
480
481static ssize_t show_hw_debounce_time(struct device *dev, struct device_attribute *attr, char *buf)
482{
483 return snprintf(buf, PAGE_SIZE, "%d\n", hw_debounce_time);
484}
485
486static ssize_t store_hw_debounce_time(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
487{
488 int time;
489
490 sscanf(buf, "%d", &time);
491
492 if ((time < 0) || (time > 0xff))
493 return count;
494
495 if (!hw_debounce)
496 return count;
497
498 hw_debounce_set(-1, time);
499 hw_debounce_time = time;
500
501 return count;
502}
503
504static DEVICE_ATTR(debounce_delay, (S_IRUGO | S_IWUGO), show_debounce_delay, store_debounce_delay);
505static DEVICE_ATTR(settle_time, (S_IRUGO | S_IWUGO), show_settle_time, store_settle_time);
506static DEVICE_ATTR(poll_time, (S_IRUGO | S_IWUGO), show_poll_time, store_poll_time);
507static DEVICE_ATTR(flags, (S_IRUGO), show_flags, store_flags);
508static DEVICE_ATTR(debounce_flag, (S_IRUGO | S_IWUGO), show_debounce_flag, store_debounce_flag);
509static DEVICE_ATTR(remove_some_phantom_keys_flag, (S_IRUGO | S_IWUGO), show_remove_some_phantom_keys_flag, store_remove_some_phantom_keys_flag);
510static DEVICE_ATTR(print_unmapped_keys_flag, (S_IRUGO | S_IWUGO), show_print_unmapped_keys_flag, store_print_unmapped_keys_flag);
511static DEVICE_ATTR(print_mapped_keys_flag, (S_IRUGO | S_IWUGO), show_print_mapped_keys_flag, store_print_mapped_keys_flag);
512static DEVICE_ATTR(print_phantom_keys_flag, (S_IRUGO | S_IWUGO), show_print_phantom_keys_flag, store_print_phantom_keys_flag);
513static DEVICE_ATTR(active_high_flag, (S_IRUGO | S_IWUGO), show_active_high_flag, store_active_high_flag);
514static DEVICE_ATTR(level_triggered_irq_flag, (S_IRUGO | S_IWUGO), show_level_triggered_irq_flag, store_level_triggered_irq_flag);
515static DEVICE_ATTR(drive_inactive_flag, (S_IRUGO | S_IWUGO), show_drive_inactive_flag, store_drive_inactive_flag);
516static DEVICE_ATTR(hw_debounce, (S_IRUGO | S_IWUGO), show_hw_debounce, store_hw_debounce);
517static DEVICE_ATTR(hw_debounce_time, (S_IRUGO | S_IWUGO), show_hw_debounce_time, store_hw_debounce_time);
518
519#if 0
520static int debounce_fixup(int index)
521{
522 int ret;
523
524 printk(KERN_INFO PREFIX "key_state_changed: %d, last_key_state_changed: %d, some_keys_pressed: %d\n",
525 gpio_kp_state->key_state_changed,
526 gpio_kp_state->last_key_state_changed,
527 gpio_kp_state->some_keys_pressed);
528
529 ret = old_sw_fixup(index);
530 if (!ret)
531 printk(KERN_INFO PREFIX "Index 0x%x ignored!\n", index);
532
533 return ret;
534}
535#endif
536
537static void debounce_release(struct device *dev)
538{
539}
540
541static struct device debounce_device = {
542 .init_name = "debounce",
543 .release = debounce_release,
544};
545
546static int __init debounce_init(void)
547{
548 struct device *event_dev = NULL;
549 struct platform_device *pdev = NULL;
550 struct gpio_event_platform_data *gpio_epd;
551 struct gpio_event_info *gpio_ei;
552 struct gpio_event *gpio_e;
553 int err = 0;
554 int i;
555
556 printk(KERN_INFO PREFIX "Searching for " GPIO_EVENT_DEV_NAME "...\n");
557
558 event_dev = device_find_child(&platform_bus, GPIO_EVENT_DEV_NAME, find_ms2_dev);
559 if (event_dev == NULL)
560 return -ENODEV;
561
562 pdev = container_of(event_dev, struct platform_device, dev);
563 if (pdev == NULL)
564 return -ENODEV;
565
566 gpio_epd = (struct gpio_event_platform_data*)event_dev->platform_data;
567 printk(KERN_INFO PREFIX "And there is a %s connected...\n", gpio_epd->name);
568 if (strcmp(gpio_epd->name, "sholes-keypad"))
569 return -ENODEV;
570
571 gpio_ei = (struct gpio_event_info*)gpio_epd->info[0];
572 gpio_evmi = container_of(gpio_ei, struct gpio_event_matrix_info, info);
573
574 gpio_e = platform_get_drvdata(pdev);
575 printk(KERN_INFO PREFIX "Number of states: %d\n", gpio_e->info->info_count);
576
577 /* Search for correct gpio_event state */
578 for (i = 0; i < gpio_e->info->info_count; i++) {
579 if (gpio_e->info->info[i]->func == gpio_ei->func) {
580 printk(KERN_INFO PREFIX "Keypad state: %d\n", i);
581 gpio_kp_state = gpio_e->state[i];
582 }
583 }
584
585 if (!gpio_kp_state) {
586 printk(KERN_ERR PREFIX "Can't determine correct keypad state!\n");
587 return -ENODEV;
588 }
589
590 printk(KERN_INFO PREFIX "kp_use_irq: %d\n", gpio_kp_state->use_irq);
591#if 0
592 gpio_kp_state->use_irq=0;
593 hrtimer_start(&(gpio_kp_state->timer), gpio_evmi->poll_time, HRTIMER_MODE_REL);
594 printk(KERN_INFO PREFIX "kp_use_irq: %d\n", gpio_kp_state->use_irq);
595#endif
596
597 err = device_register(&debounce_device);
598 if (err) {
599 return err;
600 }
601
602 err = device_create_file(&debounce_device, &dev_attr_debounce_delay);
603 err = device_create_file(&debounce_device, &dev_attr_settle_time);
604 err = device_create_file(&debounce_device, &dev_attr_poll_time);
605 err = device_create_file(&debounce_device, &dev_attr_flags);
606 err = device_create_file(&debounce_device, &dev_attr_debounce_flag);
607 err = device_create_file(&debounce_device, &dev_attr_remove_some_phantom_keys_flag);
608 err = device_create_file(&debounce_device, &dev_attr_print_unmapped_keys_flag);
609 err = device_create_file(&debounce_device, &dev_attr_print_mapped_keys_flag);
610 err = device_create_file(&debounce_device, &dev_attr_print_phantom_keys_flag);
611 err = device_create_file(&debounce_device, &dev_attr_active_high_flag);
612 err = device_create_file(&debounce_device, &dev_attr_level_triggered_irq_flag);
613 err = device_create_file(&debounce_device, &dev_attr_drive_inactive_flag);
614 err = device_create_file(&debounce_device, &dev_attr_hw_debounce);
615 err = device_create_file(&debounce_device, &dev_attr_hw_debounce_time);
616
617 printk(KERN_INFO PREFIX "settle_time: %u\n", gpio_evmi->settle_time.tv.nsec);
618 printk(KERN_INFO PREFIX "poll_time: %u\n", gpio_evmi->poll_time.tv.nsec);
619 printk(KERN_INFO PREFIX "debounce_delay: %u\n", gpio_evmi->debounce_delay.tv.nsec);
620 printk(KERN_INFO PREFIX "flags: 0x%x\n", gpio_evmi->flags);
621
622 old_debounce_delay = gpio_evmi->debounce_delay;
623 old_settle_time = gpio_evmi->settle_time;
624 old_poll_time = gpio_evmi->poll_time;
625 old_flags = gpio_evmi->flags;
626 old_sw_fixup = gpio_evmi->sw_fixup;
627
628#if 0
629 printk(KERN_INFO PREFIX "Registering fixup handler\n");
630 gpio_evmi->sw_fixup = debounce_fixup;
631#endif
632
633 return 0;
634}
635
636static void __exit debounce_exit(void)
637{
638 int i;
639
640 if (gpio_evmi) {
641 if (gpio_evmi->debounce_delay.tv.nsec != old_debounce_delay.tv.nsec) {
642 printk(KERN_INFO PREFIX "Restoring debounce_delay\n");
643 gpio_evmi->debounce_delay = old_debounce_delay;
644 printk(KERN_INFO PREFIX "debounce_delay: %u\n", gpio_evmi->debounce_delay.tv.nsec);
645 }
646 if (gpio_evmi->flags != old_flags) {
647 printk(KERN_INFO PREFIX "Restoring flags\n");
648 gpio_evmi->flags = old_flags;
649 printk(KERN_INFO PREFIX "flags: 0x%x\n", gpio_evmi->flags);
650 if (gpio_evmi->flags & GPIOKPF_ACTIVE_HIGH) {
651 for (i = 0x7a; i <= 0x88; i += 2) {
652 __raw_writew(PADCONF_PULL_DOWN, OMAP_CTRL_REGADDR(i));
653 }
654 } else {
655 for (i = 0x7a; i <= 0x88; i += 2) {
656 __raw_writew(PADCONF_PULL_UP, OMAP_CTRL_REGADDR(i));
657 }
658 }
659 set_irq_types();
660 }
661 gpio_evmi->settle_time = old_settle_time;
662 gpio_evmi->poll_time = old_poll_time;
663
664 if (gpio_evmi->sw_fixup != old_sw_fixup) {
665 printk(KERN_INFO PREFIX "Restoring fixup handler\n");
666 gpio_evmi->sw_fixup = old_sw_fixup;
667 }
668 }
669 hw_debounce_set(0, 0);
670 device_remove_file(&debounce_device, &dev_attr_debounce_delay);
671 device_remove_file(&debounce_device, &dev_attr_settle_time);
672 device_remove_file(&debounce_device, &dev_attr_poll_time);
673 device_remove_file(&debounce_device, &dev_attr_flags);
674 device_remove_file(&debounce_device, &dev_attr_debounce_flag);
675 device_remove_file(&debounce_device, &dev_attr_remove_some_phantom_keys_flag);
676 device_remove_file(&debounce_device, &dev_attr_print_unmapped_keys_flag);
677 device_remove_file(&debounce_device, &dev_attr_print_mapped_keys_flag);
678 device_remove_file(&debounce_device, &dev_attr_print_phantom_keys_flag);
679 device_remove_file(&debounce_device, &dev_attr_active_high_flag);
680 device_remove_file(&debounce_device, &dev_attr_level_triggered_irq_flag);
681 device_remove_file(&debounce_device, &dev_attr_drive_inactive_flag);
682 device_remove_file(&debounce_device, &dev_attr_hw_debounce);
683 device_remove_file(&debounce_device, &dev_attr_hw_debounce_time);
684 device_unregister(&debounce_device);
685}
686
687module_init(debounce_init);
688module_exit(debounce_exit);
689
690MODULE_LICENSE("GPL");
691MODULE_AUTHOR("Michael Gernoth <michael@gernoth.net>");
Impressum, Datenschutz