use module included in ROM (when available)
[ms2-fixes] / debounce.c
CommitLineData
b422e333 1#include <linux/module.h>
d1ff9643
MG
2#include <linux/device.h>
3#include <linux/platform_device.h>
4#include <linux/gpio_event.h>
f4286301
MG
5#include <linux/interrupt.h>
6#include <linux/irq.h>
62a453fc 7#include <mach/gpio.h>
e2cecc6a
MG
8#include <linux/earlysuspend.h>
9#include <linux/wakelock.h>
126529c5 10#include <plat/board-mapphone.h>
62a453fc 11
ab5ed215
MG
12#define PREFIX "debounce: "
13
126529c5
MG
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
a4838b14 28static unsigned old_flags = 0;
29bad272
MG
29static ktime_t old_debounce_delay;
30static ktime_t old_settle_time;
31static ktime_t old_poll_time;
e063f9d5 32static int (*old_sw_fixup)(int index);
1e65c113 33static struct gpio_event_matrix_info *gpio_evmi = NULL;
29bad272
MG
34static int hw_debounce = 0;
35static int hw_debounce_time = 0;
1e65c113 36
e2cecc6a
MG
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
ab5ed215 59static int find_ms2_dev(struct device *dev, void *data)
d1ff9643
MG
60{
61 if (!strncmp((char*)data, dev_name(dev), strlen((char*)data))) {
ab5ed215 62 printk(KERN_INFO PREFIX "Found it\n");
d1ff9643
MG
63 return 1;
64 }
65 return 0;
66}
b422e333 67
29bad272
MG
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
308fc1a5 78 if ((time != -1) && (time != hw_debounce_time) && hw_debounce) {
5df3a8e0 79 printk(KERN_INFO PREFIX "Setting hardware debounce time for GPIO %d to %d (%dus)\n", gpio, time, (time+1)*31);
29bad272
MG
80 omap_set_gpio_debounce_time(gpio, time);
81 }
308fc1a5
MG
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 }
29bad272
MG
87 }
88}
89
f4286301
MG
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}
29bad272 126
f7cb07b2
MG
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;
f7cb07b2
MG
140 printk(KERN_INFO PREFIX "debounce_delay: %u\n", gpio_evmi->debounce_delay.tv.nsec);
141 }
142
fc215caa 143#if 0
f7cb07b2
MG
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 }
fc215caa 155#endif
f7cb07b2
MG
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
fc215caa 168 return count;
f7cb07b2
MG
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
fc215caa 189 return count;
f7cb07b2
MG
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
fc215caa 210 return count;
f7cb07b2
MG
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);
fc215caa
MG
229
230 printk(KERN_INFO PREFIX "flags: 0x%x\n", flags);
231
f7cb07b2
MG
232 gpio_evmi->flags = flags;
233
fc215caa
MG
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);
f7cb07b2
MG
243}
244
fc215caa
MG
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
a2485674
MG
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;
126529c5 378 int i;
a2485674
MG
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;
126529c5
MG
387 for (i = 0x7a; i <= 0x88; i += 2) {
388 __raw_writew(PADCONF_PULL_DOWN, OMAP_CTRL_REGADDR(i));
389 }
a2485674
MG
390 } else {
391 gpio_evmi->flags &= ~GPIOKPF_ACTIVE_HIGH;
126529c5
MG
392 for (i = 0x7a; i <= 0x88; i += 2) {
393 __raw_writew(PADCONF_PULL_UP, OMAP_CTRL_REGADDR(i));
394 }
a2485674
MG
395 }
396
f4286301
MG
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
a2485674
MG
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
29bad272
MG
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 {
c0cd650e 472 hw_debounce_set(-1, 0);
29bad272
MG
473 hw_debounce_set(0, -1);
474 hw_debounce = 0;
c0cd650e 475 hw_debounce_time = 0;
29bad272
MG
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
8440ec7c
MG
495 if (!hw_debounce)
496 return count;
497
29bad272
MG
498 hw_debounce_set(-1, time);
499 hw_debounce_time = time;
500
501 return count;
502}
503
fc215caa
MG
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);
60fe4255 513static DEVICE_ATTR(active_high_flag, (S_IRUGO | S_IWUGO), show_active_high_flag, store_active_high_flag);
f4286301 514static DEVICE_ATTR(level_triggered_irq_flag, (S_IRUGO | S_IWUGO), show_level_triggered_irq_flag, store_level_triggered_irq_flag);
a2485674 515static DEVICE_ATTR(drive_inactive_flag, (S_IRUGO | S_IWUGO), show_drive_inactive_flag, store_drive_inactive_flag);
29bad272
MG
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);
f7cb07b2 518
e063f9d5
MG
519#if 0
520static int debounce_fixup(int index)
521{
522 int ret;
523
e2cecc6a
MG
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);
e063f9d5
MG
528
529 ret = old_sw_fixup(index);
530 if (!ret)
e2cecc6a 531 printk(KERN_INFO PREFIX "Index 0x%x ignored!\n", index);
e063f9d5
MG
532
533 return ret;
534}
535#endif
536
f7cb07b2
MG
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
b422e333
MG
546static int __init debounce_init(void)
547{
d1ff9643 548 struct device *event_dev = NULL;
e2cecc6a 549 struct platform_device *pdev = NULL;
d1ff9643
MG
550 struct gpio_event_platform_data *gpio_epd;
551 struct gpio_event_info *gpio_ei;
e2cecc6a 552 struct gpio_event *gpio_e;
f7cb07b2 553 int err = 0;
e2cecc6a 554 int i;
d1ff9643 555
ab5ed215 556 printk(KERN_INFO PREFIX "Searching for " GPIO_EVENT_DEV_NAME "...\n");
d1ff9643
MG
557
558 event_dev = device_find_child(&platform_bus, GPIO_EVENT_DEV_NAME, find_ms2_dev);
559 if (event_dev == NULL)
560 return -ENODEV;
e2cecc6a
MG
561
562 pdev = container_of(event_dev, struct platform_device, dev);
563 if (pdev == NULL)
564 return -ENODEV;
565
d1ff9643 566 gpio_epd = (struct gpio_event_platform_data*)event_dev->platform_data;
ab5ed215 567 printk(KERN_INFO PREFIX "And there is a %s connected...\n", gpio_epd->name);
d1ff9643
MG
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
e2cecc6a
MG
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
f7cb07b2
MG
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);
fc215caa
MG
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);
a2485674 611 err = device_create_file(&debounce_device, &dev_attr_active_high_flag);
f4286301 612 err = device_create_file(&debounce_device, &dev_attr_level_triggered_irq_flag);
a2485674 613 err = device_create_file(&debounce_device, &dev_attr_drive_inactive_flag);
29bad272
MG
614 err = device_create_file(&debounce_device, &dev_attr_hw_debounce);
615 err = device_create_file(&debounce_device, &dev_attr_hw_debounce_time);
f7cb07b2 616
ab5ed215
MG
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);
20bf1c9e 621
bb65757a
MG
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;
e063f9d5 626 old_sw_fixup = gpio_evmi->sw_fixup;
1e65c113 627
e063f9d5
MG
628#if 0
629 printk(KERN_INFO PREFIX "Registering fixup handler\n");
630 gpio_evmi->sw_fixup = debounce_fixup;
631#endif
a4838b14 632
b422e333
MG
633 return 0;
634}
635
636static void __exit debounce_exit(void)
637{
126529c5
MG
638 int i;
639
1e65c113 640 if (gpio_evmi) {
bb65757a 641 if (gpio_evmi->debounce_delay.tv.nsec != old_debounce_delay.tv.nsec) {
1e65c113 642 printk(KERN_INFO PREFIX "Restoring debounce_delay\n");
bb65757a 643 gpio_evmi->debounce_delay = old_debounce_delay;
1e65c113
MG
644 printk(KERN_INFO PREFIX "debounce_delay: %u\n", gpio_evmi->debounce_delay.tv.nsec);
645 }
a4838b14
MG
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);
126529c5
MG
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 }
f4286301 659 set_irq_types();
a4838b14 660 }
bb65757a
MG
661 gpio_evmi->settle_time = old_settle_time;
662 gpio_evmi->poll_time = old_poll_time;
e063f9d5
MG
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 }
1e65c113 668 }
29bad272 669 hw_debounce_set(0, 0);
f7cb07b2
MG
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);
fc215caa
MG
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);
a2485674 679 device_remove_file(&debounce_device, &dev_attr_active_high_flag);
f4286301 680 device_remove_file(&debounce_device, &dev_attr_level_triggered_irq_flag);
a2485674 681 device_remove_file(&debounce_device, &dev_attr_drive_inactive_flag);
29bad272
MG
682 device_remove_file(&debounce_device, &dev_attr_hw_debounce);
683 device_remove_file(&debounce_device, &dev_attr_hw_debounce_time);
f7cb07b2 684 device_unregister(&debounce_device);
b422e333
MG
685}
686
687module_init(debounce_init);
688module_exit(debounce_exit);
689
690MODULE_LICENSE("GPL");
691MODULE_AUTHOR("Michael Gernoth <michael@gernoth.net>");
Impressum, Datenschutz