diff options
author | Paul Mackerras <paulus@samba.org> | 2006-08-08 03:09:11 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2006-08-08 03:09:11 -0400 |
commit | 32bc6e095d75233e7c87cc6fa0e07942b124d194 (patch) | |
tree | 8f83ef9a23d52d1305878b65dd98fc22b09b7f3e /drivers/usb/input/ati_remote.c | |
parent | 5cf13911b1e72707b6f0eb39b2d819ec6e343d76 (diff) | |
parent | 81b73dd92b97423b8f5324a59044da478c04f4c4 (diff) |
Merge branch 'merge'
Diffstat (limited to 'drivers/usb/input/ati_remote.c')
-rw-r--r-- | drivers/usb/input/ati_remote.c | 174 |
1 files changed, 99 insertions, 75 deletions
diff --git a/drivers/usb/input/ati_remote.c b/drivers/usb/input/ati_remote.c index 05d2d6012eb2..3719fcb04b8f 100644 --- a/drivers/usb/input/ati_remote.c +++ b/drivers/usb/input/ati_remote.c | |||
@@ -111,14 +111,28 @@ | |||
111 | #define NAME_BUFSIZE 80 /* size of product name, path buffers */ | 111 | #define NAME_BUFSIZE 80 /* size of product name, path buffers */ |
112 | #define DATA_BUFSIZE 63 /* size of URB data buffers */ | 112 | #define DATA_BUFSIZE 63 /* size of URB data buffers */ |
113 | 113 | ||
114 | /* | ||
115 | * Duplicate event filtering time. | ||
116 | * Sequential, identical KIND_FILTERED inputs with less than | ||
117 | * FILTER_TIME milliseconds between them are considered as repeat | ||
118 | * events. The hardware generates 5 events for the first keypress | ||
119 | * and we have to take this into account for an accurate repeat | ||
120 | * behaviour. | ||
121 | */ | ||
122 | #define FILTER_TIME 60 /* msec */ | ||
123 | |||
114 | static unsigned long channel_mask; | 124 | static unsigned long channel_mask; |
115 | module_param(channel_mask, ulong, 0444); | 125 | module_param(channel_mask, ulong, 0644); |
116 | MODULE_PARM_DESC(channel_mask, "Bitmask of remote control channels to ignore"); | 126 | MODULE_PARM_DESC(channel_mask, "Bitmask of remote control channels to ignore"); |
117 | 127 | ||
118 | static int debug; | 128 | static int debug; |
119 | module_param(debug, int, 0444); | 129 | module_param(debug, int, 0644); |
120 | MODULE_PARM_DESC(debug, "Enable extra debug messages and information"); | 130 | MODULE_PARM_DESC(debug, "Enable extra debug messages and information"); |
121 | 131 | ||
132 | static int repeat_filter = FILTER_TIME; | ||
133 | module_param(repeat_filter, int, 0644); | ||
134 | MODULE_PARM_DESC(repeat_filter, "Repeat filter time, default = 60 msec"); | ||
135 | |||
122 | #define dbginfo(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0) | 136 | #define dbginfo(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0) |
123 | #undef err | 137 | #undef err |
124 | #define err(format, arg...) printk(KERN_ERR format , ## arg) | 138 | #define err(format, arg...) printk(KERN_ERR format , ## arg) |
@@ -143,19 +157,6 @@ MODULE_DEVICE_TABLE(usb, ati_remote_table); | |||
143 | static char init1[] = { 0x01, 0x00, 0x20, 0x14 }; | 157 | static char init1[] = { 0x01, 0x00, 0x20, 0x14 }; |
144 | static char init2[] = { 0x01, 0x00, 0x20, 0x14, 0x20, 0x20, 0x20 }; | 158 | static char init2[] = { 0x01, 0x00, 0x20, 0x14, 0x20, 0x20, 0x20 }; |
145 | 159 | ||
146 | /* Acceleration curve for directional control pad */ | ||
147 | static const char accel[] = { 1, 2, 4, 6, 9, 13, 20 }; | ||
148 | |||
149 | /* Duplicate event filtering time. | ||
150 | * Sequential, identical KIND_FILTERED inputs with less than | ||
151 | * FILTER_TIME jiffies between them are considered as repeat | ||
152 | * events. The hardware generates 5 events for the first keypress | ||
153 | * and we have to take this into account for an accurate repeat | ||
154 | * behaviour. | ||
155 | * (HZ / 20) == 50 ms and works well for me. | ||
156 | */ | ||
157 | #define FILTER_TIME (HZ / 20) | ||
158 | |||
159 | struct ati_remote { | 160 | struct ati_remote { |
160 | struct input_dev *idev; | 161 | struct input_dev *idev; |
161 | struct usb_device *udev; | 162 | struct usb_device *udev; |
@@ -413,6 +414,43 @@ static int ati_remote_event_lookup(int rem, unsigned char d1, unsigned char d2) | |||
413 | } | 414 | } |
414 | 415 | ||
415 | /* | 416 | /* |
417 | * ati_remote_compute_accel | ||
418 | * | ||
419 | * Implements acceleration curve for directional control pad | ||
420 | * If elapsed time since last event is > 1/4 second, user "stopped", | ||
421 | * so reset acceleration. Otherwise, user is probably holding the control | ||
422 | * pad down, so we increase acceleration, ramping up over two seconds to | ||
423 | * a maximum speed. | ||
424 | */ | ||
425 | static int ati_remote_compute_accel(struct ati_remote *ati_remote) | ||
426 | { | ||
427 | static const char accel[] = { 1, 2, 4, 6, 9, 13, 20 }; | ||
428 | unsigned long now = jiffies; | ||
429 | int acc; | ||
430 | |||
431 | if (time_after(now, ati_remote->old_jiffies + msecs_to_jiffies(250))) { | ||
432 | acc = 1; | ||
433 | ati_remote->acc_jiffies = now; | ||
434 | } | ||
435 | else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(125))) | ||
436 | acc = accel[0]; | ||
437 | else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(250))) | ||
438 | acc = accel[1]; | ||
439 | else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(500))) | ||
440 | acc = accel[2]; | ||
441 | else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(1000))) | ||
442 | acc = accel[3]; | ||
443 | else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(1500))) | ||
444 | acc = accel[4]; | ||
445 | else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(2000))) | ||
446 | acc = accel[5]; | ||
447 | else | ||
448 | acc = accel[6]; | ||
449 | |||
450 | return acc; | ||
451 | } | ||
452 | |||
453 | /* | ||
416 | * ati_remote_report_input | 454 | * ati_remote_report_input |
417 | */ | 455 | */ |
418 | static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs) | 456 | static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs) |
@@ -465,9 +503,9 @@ static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs) | |||
465 | 503 | ||
466 | if (ati_remote_tbl[index].kind == KIND_FILTERED) { | 504 | if (ati_remote_tbl[index].kind == KIND_FILTERED) { |
467 | /* Filter duplicate events which happen "too close" together. */ | 505 | /* Filter duplicate events which happen "too close" together. */ |
468 | if ((ati_remote->old_data[0] == data[1]) && | 506 | if (ati_remote->old_data[0] == data[1] && |
469 | (ati_remote->old_data[1] == data[2]) && | 507 | ati_remote->old_data[1] == data[2] && |
470 | time_before(jiffies, ati_remote->old_jiffies + FILTER_TIME)) { | 508 | time_before(jiffies, ati_remote->old_jiffies + msecs_to_jiffies(repeat_filter))) { |
471 | ati_remote->repeat_count++; | 509 | ati_remote->repeat_count++; |
472 | } else { | 510 | } else { |
473 | ati_remote->repeat_count = 0; | 511 | ati_remote->repeat_count = 0; |
@@ -477,75 +515,61 @@ static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs) | |||
477 | ati_remote->old_data[1] = data[2]; | 515 | ati_remote->old_data[1] = data[2]; |
478 | ati_remote->old_jiffies = jiffies; | 516 | ati_remote->old_jiffies = jiffies; |
479 | 517 | ||
480 | if ((ati_remote->repeat_count > 0) | 518 | if (ati_remote->repeat_count > 0 && |
481 | && (ati_remote->repeat_count < 5)) | 519 | ati_remote->repeat_count < 5) |
482 | return; | 520 | return; |
483 | 521 | ||
484 | 522 | ||
485 | input_regs(dev, regs); | 523 | input_regs(dev, regs); |
486 | input_event(dev, ati_remote_tbl[index].type, | 524 | input_event(dev, ati_remote_tbl[index].type, |
487 | ati_remote_tbl[index].code, 1); | 525 | ati_remote_tbl[index].code, 1); |
526 | input_sync(dev); | ||
488 | input_event(dev, ati_remote_tbl[index].type, | 527 | input_event(dev, ati_remote_tbl[index].type, |
489 | ati_remote_tbl[index].code, 0); | 528 | ati_remote_tbl[index].code, 0); |
490 | input_sync(dev); | 529 | input_sync(dev); |
491 | 530 | ||
492 | return; | 531 | } else { |
493 | } | ||
494 | 532 | ||
495 | /* | 533 | /* |
496 | * Other event kinds are from the directional control pad, and have an | 534 | * Other event kinds are from the directional control pad, and have an |
497 | * acceleration factor applied to them. Without this acceleration, the | 535 | * acceleration factor applied to them. Without this acceleration, the |
498 | * control pad is mostly unusable. | 536 | * control pad is mostly unusable. |
499 | * | 537 | */ |
500 | * If elapsed time since last event is > 1/4 second, user "stopped", | 538 | acc = ati_remote_compute_accel(ati_remote); |
501 | * so reset acceleration. Otherwise, user is probably holding the control | 539 | |
502 | * pad down, so we increase acceleration, ramping up over two seconds to | 540 | input_regs(dev, regs); |
503 | * a maximum speed. The acceleration curve is #defined above. | 541 | switch (ati_remote_tbl[index].kind) { |
504 | */ | 542 | case KIND_ACCEL: |
505 | if (time_after(jiffies, ati_remote->old_jiffies + (HZ >> 2))) { | 543 | input_event(dev, ati_remote_tbl[index].type, |
506 | acc = 1; | 544 | ati_remote_tbl[index].code, |
507 | ati_remote->acc_jiffies = jiffies; | 545 | ati_remote_tbl[index].value * acc); |
508 | } | 546 | break; |
509 | else if (time_before(jiffies, ati_remote->acc_jiffies + (HZ >> 3))) acc = accel[0]; | 547 | case KIND_LU: |
510 | else if (time_before(jiffies, ati_remote->acc_jiffies + (HZ >> 2))) acc = accel[1]; | 548 | input_report_rel(dev, REL_X, -acc); |
511 | else if (time_before(jiffies, ati_remote->acc_jiffies + (HZ >> 1))) acc = accel[2]; | 549 | input_report_rel(dev, REL_Y, -acc); |
512 | else if (time_before(jiffies, ati_remote->acc_jiffies + HZ)) acc = accel[3]; | 550 | break; |
513 | else if (time_before(jiffies, ati_remote->acc_jiffies + HZ+(HZ>>1))) acc = accel[4]; | 551 | case KIND_RU: |
514 | else if (time_before(jiffies, ati_remote->acc_jiffies + (HZ << 1))) acc = accel[5]; | 552 | input_report_rel(dev, REL_X, acc); |
515 | else acc = accel[6]; | 553 | input_report_rel(dev, REL_Y, -acc); |
516 | 554 | break; | |
517 | input_regs(dev, regs); | 555 | case KIND_LD: |
518 | switch (ati_remote_tbl[index].kind) { | 556 | input_report_rel(dev, REL_X, -acc); |
519 | case KIND_ACCEL: | 557 | input_report_rel(dev, REL_Y, acc); |
520 | input_event(dev, ati_remote_tbl[index].type, | 558 | break; |
521 | ati_remote_tbl[index].code, | 559 | case KIND_RD: |
522 | ati_remote_tbl[index].value * acc); | 560 | input_report_rel(dev, REL_X, acc); |
523 | break; | 561 | input_report_rel(dev, REL_Y, acc); |
524 | case KIND_LU: | 562 | break; |
525 | input_report_rel(dev, REL_X, -acc); | 563 | default: |
526 | input_report_rel(dev, REL_Y, -acc); | 564 | dev_dbg(&ati_remote->interface->dev, "ati_remote kind=%d\n", |
527 | break; | 565 | ati_remote_tbl[index].kind); |
528 | case KIND_RU: | 566 | } |
529 | input_report_rel(dev, REL_X, acc); | 567 | input_sync(dev); |
530 | input_report_rel(dev, REL_Y, -acc); | ||
531 | break; | ||
532 | case KIND_LD: | ||
533 | input_report_rel(dev, REL_X, -acc); | ||
534 | input_report_rel(dev, REL_Y, acc); | ||
535 | break; | ||
536 | case KIND_RD: | ||
537 | input_report_rel(dev, REL_X, acc); | ||
538 | input_report_rel(dev, REL_Y, acc); | ||
539 | break; | ||
540 | default: | ||
541 | dev_dbg(&ati_remote->interface->dev, "ati_remote kind=%d\n", | ||
542 | ati_remote_tbl[index].kind); | ||
543 | } | ||
544 | input_sync(dev); | ||
545 | 568 | ||
546 | ati_remote->old_jiffies = jiffies; | 569 | ati_remote->old_jiffies = jiffies; |
547 | ati_remote->old_data[0] = data[1]; | 570 | ati_remote->old_data[0] = data[1]; |
548 | ati_remote->old_data[1] = data[2]; | 571 | ati_remote->old_data[1] = data[2]; |
572 | } | ||
549 | } | 573 | } |
550 | 574 | ||
551 | /* | 575 | /* |