diff options
author | Jeff Garzik <jeff@garzik.org> | 2006-08-07 06:43:17 -0400 |
---|---|---|
committer | Jeff Garzik <jeff@garzik.org> | 2006-08-07 06:43:17 -0400 |
commit | 38ebb1e0ed214efe124534eba4a34e869a0d8da7 (patch) | |
tree | 3712611527654e81109d194d903401c86763e3f4 /drivers/usb/input/ati_remote.c | |
parent | 236a686b56428a8967a057a2396f9be74e2ee652 (diff) | |
parent | 9f737633e6ee54fc174282d49b2559bd2208391d (diff) |
Merge branch 'master' into upstream
Diffstat (limited to 'drivers/usb/input/ati_remote.c')
-rw-r--r-- | drivers/usb/input/ati_remote.c | 173 |
1 files changed, 99 insertions, 74 deletions
diff --git a/drivers/usb/input/ati_remote.c b/drivers/usb/input/ati_remote.c index df198cf76f52..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,18 +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 | */ | ||
156 | #define FILTER_TIME 60 /* msec */ | ||
157 | |||
158 | struct ati_remote { | 160 | struct ati_remote { |
159 | struct input_dev *idev; | 161 | struct input_dev *idev; |
160 | struct usb_device *udev; | 162 | struct usb_device *udev; |
@@ -412,6 +414,43 @@ static int ati_remote_event_lookup(int rem, unsigned char d1, unsigned char d2) | |||
412 | } | 414 | } |
413 | 415 | ||
414 | /* | 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 | /* | ||
415 | * ati_remote_report_input | 454 | * ati_remote_report_input |
416 | */ | 455 | */ |
417 | 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) |
@@ -464,9 +503,9 @@ static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs) | |||
464 | 503 | ||
465 | if (ati_remote_tbl[index].kind == KIND_FILTERED) { | 504 | if (ati_remote_tbl[index].kind == KIND_FILTERED) { |
466 | /* Filter duplicate events which happen "too close" together. */ | 505 | /* Filter duplicate events which happen "too close" together. */ |
467 | if ((ati_remote->old_data[0] == data[1]) && | 506 | if (ati_remote->old_data[0] == data[1] && |
468 | (ati_remote->old_data[1] == data[2]) && | 507 | ati_remote->old_data[1] == data[2] && |
469 | time_before(jiffies, ati_remote->old_jiffies + msecs_to_jiffies(FILTER_TIME))) { | 508 | time_before(jiffies, ati_remote->old_jiffies + msecs_to_jiffies(repeat_filter))) { |
470 | ati_remote->repeat_count++; | 509 | ati_remote->repeat_count++; |
471 | } else { | 510 | } else { |
472 | ati_remote->repeat_count = 0; | 511 | ati_remote->repeat_count = 0; |
@@ -476,75 +515,61 @@ static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs) | |||
476 | ati_remote->old_data[1] = data[2]; | 515 | ati_remote->old_data[1] = data[2]; |
477 | ati_remote->old_jiffies = jiffies; | 516 | ati_remote->old_jiffies = jiffies; |
478 | 517 | ||
479 | if ((ati_remote->repeat_count > 0) | 518 | if (ati_remote->repeat_count > 0 && |
480 | && (ati_remote->repeat_count < 5)) | 519 | ati_remote->repeat_count < 5) |
481 | return; | 520 | return; |
482 | 521 | ||
483 | 522 | ||
484 | input_regs(dev, regs); | 523 | input_regs(dev, regs); |
485 | input_event(dev, ati_remote_tbl[index].type, | 524 | input_event(dev, ati_remote_tbl[index].type, |
486 | ati_remote_tbl[index].code, 1); | 525 | ati_remote_tbl[index].code, 1); |
526 | input_sync(dev); | ||
487 | input_event(dev, ati_remote_tbl[index].type, | 527 | input_event(dev, ati_remote_tbl[index].type, |
488 | ati_remote_tbl[index].code, 0); | 528 | ati_remote_tbl[index].code, 0); |
489 | input_sync(dev); | 529 | input_sync(dev); |
490 | 530 | ||
491 | return; | 531 | } else { |
492 | } | ||
493 | 532 | ||
494 | /* | 533 | /* |
495 | * 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 |
496 | * acceleration factor applied to them. Without this acceleration, the | 535 | * acceleration factor applied to them. Without this acceleration, the |
497 | * control pad is mostly unusable. | 536 | * control pad is mostly unusable. |
498 | * | 537 | */ |
499 | * If elapsed time since last event is > 1/4 second, user "stopped", | 538 | acc = ati_remote_compute_accel(ati_remote); |
500 | * so reset acceleration. Otherwise, user is probably holding the control | 539 | |
501 | * pad down, so we increase acceleration, ramping up over two seconds to | 540 | input_regs(dev, regs); |
502 | * a maximum speed. The acceleration curve is #defined above. | 541 | switch (ati_remote_tbl[index].kind) { |
503 | */ | 542 | case KIND_ACCEL: |
504 | if (time_after(jiffies, ati_remote->old_jiffies + (HZ >> 2))) { | 543 | input_event(dev, ati_remote_tbl[index].type, |
505 | acc = 1; | 544 | ati_remote_tbl[index].code, |
506 | ati_remote->acc_jiffies = jiffies; | 545 | ati_remote_tbl[index].value * acc); |
507 | } | 546 | break; |
508 | else if (time_before(jiffies, ati_remote->acc_jiffies + (HZ >> 3))) acc = accel[0]; | 547 | case KIND_LU: |
509 | else if (time_before(jiffies, ati_remote->acc_jiffies + (HZ >> 2))) acc = accel[1]; | 548 | input_report_rel(dev, REL_X, -acc); |
510 | else if (time_before(jiffies, ati_remote->acc_jiffies + (HZ >> 1))) acc = accel[2]; | 549 | input_report_rel(dev, REL_Y, -acc); |
511 | else if (time_before(jiffies, ati_remote->acc_jiffies + HZ)) acc = accel[3]; | 550 | break; |
512 | else if (time_before(jiffies, ati_remote->acc_jiffies + HZ+(HZ>>1))) acc = accel[4]; | 551 | case KIND_RU: |
513 | else if (time_before(jiffies, ati_remote->acc_jiffies + (HZ << 1))) acc = accel[5]; | 552 | input_report_rel(dev, REL_X, acc); |
514 | else acc = accel[6]; | 553 | input_report_rel(dev, REL_Y, -acc); |
515 | 554 | break; | |
516 | input_regs(dev, regs); | 555 | case KIND_LD: |
517 | switch (ati_remote_tbl[index].kind) { | 556 | input_report_rel(dev, REL_X, -acc); |
518 | case KIND_ACCEL: | 557 | input_report_rel(dev, REL_Y, acc); |
519 | input_event(dev, ati_remote_tbl[index].type, | 558 | break; |
520 | ati_remote_tbl[index].code, | 559 | case KIND_RD: |
521 | ati_remote_tbl[index].value * acc); | 560 | input_report_rel(dev, REL_X, acc); |
522 | break; | 561 | input_report_rel(dev, REL_Y, acc); |
523 | case KIND_LU: | 562 | break; |
524 | input_report_rel(dev, REL_X, -acc); | 563 | default: |
525 | input_report_rel(dev, REL_Y, -acc); | 564 | dev_dbg(&ati_remote->interface->dev, "ati_remote kind=%d\n", |
526 | break; | 565 | ati_remote_tbl[index].kind); |
527 | case KIND_RU: | 566 | } |
528 | input_report_rel(dev, REL_X, acc); | 567 | input_sync(dev); |
529 | input_report_rel(dev, REL_Y, -acc); | ||
530 | break; | ||
531 | case KIND_LD: | ||
532 | input_report_rel(dev, REL_X, -acc); | ||
533 | input_report_rel(dev, REL_Y, acc); | ||
534 | break; | ||
535 | case KIND_RD: | ||
536 | input_report_rel(dev, REL_X, acc); | ||
537 | input_report_rel(dev, REL_Y, acc); | ||
538 | break; | ||
539 | default: | ||
540 | dev_dbg(&ati_remote->interface->dev, "ati_remote kind=%d\n", | ||
541 | ati_remote_tbl[index].kind); | ||
542 | } | ||
543 | input_sync(dev); | ||
544 | 568 | ||
545 | ati_remote->old_jiffies = jiffies; | 569 | ati_remote->old_jiffies = jiffies; |
546 | ati_remote->old_data[0] = data[1]; | 570 | ati_remote->old_data[0] = data[1]; |
547 | ati_remote->old_data[1] = data[2]; | 571 | ati_remote->old_data[1] = data[2]; |
572 | } | ||
548 | } | 573 | } |
549 | 574 | ||
550 | /* | 575 | /* |