aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorDmitry Torokhov <dtor@insightbb.com>2006-08-04 22:53:37 -0400
committerDmitry Torokhov <dtor@insightbb.com>2006-08-04 22:53:37 -0400
commit2ffc1ccad85e8c2e81a6a4beb390fb4ce143256b (patch)
tree9111af393f517213a24cbf88ae3ce4d4c0f1e535 /drivers/usb
parentc3c38fbd0cc8cc200a65b2ca7700e4dddedc13a0 (diff)
Input: ati_remote - use msec instead of jiffies
By using milliseconds instead of jiffies to calculate acceleration factor we make the code immune to changes in HZ. Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/input/ati_remote.c135
1 files changed, 77 insertions, 58 deletions
diff --git a/drivers/usb/input/ati_remote.c b/drivers/usb/input/ati_remote.c
index 5a56f6cb36a8..3719fcb04b8f 100644
--- a/drivers/usb/input/ati_remote.c
+++ b/drivers/usb/input/ati_remote.c
@@ -157,9 +157,6 @@ MODULE_DEVICE_TABLE(usb, ati_remote_table);
157static char init1[] = { 0x01, 0x00, 0x20, 0x14 }; 157static char init1[] = { 0x01, 0x00, 0x20, 0x14 };
158static char init2[] = { 0x01, 0x00, 0x20, 0x14, 0x20, 0x20, 0x20 }; 158static char init2[] = { 0x01, 0x00, 0x20, 0x14, 0x20, 0x20, 0x20 };
159 159
160/* Acceleration curve for directional control pad */
161static const char accel[] = { 1, 2, 4, 6, 9, 13, 20 };
162
163struct ati_remote { 160struct ati_remote {
164 struct input_dev *idev; 161 struct input_dev *idev;
165 struct usb_device *udev; 162 struct usb_device *udev;
@@ -417,6 +414,43 @@ static int ati_remote_event_lookup(int rem, unsigned char d1, unsigned char d2)
417} 414}
418 415
419/* 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 */
425static 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/*
420 * ati_remote_report_input 454 * ati_remote_report_input
421 */ 455 */
422static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs) 456static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs)
@@ -494,63 +528,48 @@ static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs)
494 ati_remote_tbl[index].code, 0); 528 ati_remote_tbl[index].code, 0);
495 input_sync(dev); 529 input_sync(dev);
496 530
497 return; 531 } else {
498 }
499 532
500 /* 533 /*
501 * 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
502 * acceleration factor applied to them. Without this acceleration, the 535 * acceleration factor applied to them. Without this acceleration, the
503 * control pad is mostly unusable. 536 * control pad is mostly unusable.
504 * 537 */
505 * If elapsed time since last event is > 1/4 second, user "stopped", 538 acc = ati_remote_compute_accel(ati_remote);
506 * so reset acceleration. Otherwise, user is probably holding the control
507 * pad down, so we increase acceleration, ramping up over two seconds to
508 * a maximum speed. The acceleration curve is #defined above.
509 */
510 if (time_after(jiffies, ati_remote->old_jiffies + (HZ >> 2))) {
511 acc = 1;
512 ati_remote->acc_jiffies = jiffies;
513 }
514 else if (time_before(jiffies, ati_remote->acc_jiffies + (HZ >> 3))) acc = accel[0];
515 else if (time_before(jiffies, ati_remote->acc_jiffies + (HZ >> 2))) acc = accel[1];
516 else if (time_before(jiffies, ati_remote->acc_jiffies + (HZ >> 1))) acc = accel[2];
517 else if (time_before(jiffies, ati_remote->acc_jiffies + HZ)) acc = accel[3];
518 else if (time_before(jiffies, ati_remote->acc_jiffies + HZ+(HZ>>1))) acc = accel[4];
519 else if (time_before(jiffies, ati_remote->acc_jiffies + (HZ << 1))) acc = accel[5];
520 else acc = accel[6];
521
522 input_regs(dev, regs);
523 switch (ati_remote_tbl[index].kind) {
524 case KIND_ACCEL:
525 input_event(dev, ati_remote_tbl[index].type,
526 ati_remote_tbl[index].code,
527 ati_remote_tbl[index].value * acc);
528 break;
529 case KIND_LU:
530 input_report_rel(dev, REL_X, -acc);
531 input_report_rel(dev, REL_Y, -acc);
532 break;
533 case KIND_RU:
534 input_report_rel(dev, REL_X, acc);
535 input_report_rel(dev, REL_Y, -acc);
536 break;
537 case KIND_LD:
538 input_report_rel(dev, REL_X, -acc);
539 input_report_rel(dev, REL_Y, acc);
540 break;
541 case KIND_RD:
542 input_report_rel(dev, REL_X, acc);
543 input_report_rel(dev, REL_Y, acc);
544 break;
545 default:
546 dev_dbg(&ati_remote->interface->dev, "ati_remote kind=%d\n",
547 ati_remote_tbl[index].kind);
548 }
549 input_sync(dev);
550 539
551 ati_remote->old_jiffies = jiffies; 540 input_regs(dev, regs);
552 ati_remote->old_data[0] = data[1]; 541 switch (ati_remote_tbl[index].kind) {
553 ati_remote->old_data[1] = data[2]; 542 case KIND_ACCEL:
543 input_event(dev, ati_remote_tbl[index].type,
544 ati_remote_tbl[index].code,
545 ati_remote_tbl[index].value * acc);
546 break;
547 case KIND_LU:
548 input_report_rel(dev, REL_X, -acc);
549 input_report_rel(dev, REL_Y, -acc);
550 break;
551 case KIND_RU:
552 input_report_rel(dev, REL_X, acc);
553 input_report_rel(dev, REL_Y, -acc);
554 break;
555 case KIND_LD:
556 input_report_rel(dev, REL_X, -acc);
557 input_report_rel(dev, REL_Y, acc);
558 break;
559 case KIND_RD:
560 input_report_rel(dev, REL_X, acc);
561 input_report_rel(dev, REL_Y, acc);
562 break;
563 default:
564 dev_dbg(&ati_remote->interface->dev, "ati_remote kind=%d\n",
565 ati_remote_tbl[index].kind);
566 }
567 input_sync(dev);
568
569 ati_remote->old_jiffies = jiffies;
570 ati_remote->old_data[0] = data[1];
571 ati_remote->old_data[1] = data[2];
572 }
554} 573}
555 574
556/* 575/*