aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/input/ati_remote.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/input/ati_remote.c')
-rw-r--r--drivers/usb/input/ati_remote.c42
1 files changed, 31 insertions, 11 deletions
diff --git a/drivers/usb/input/ati_remote.c b/drivers/usb/input/ati_remote.c
index b724e36f7b92..471aab206443 100644
--- a/drivers/usb/input/ati_remote.c
+++ b/drivers/usb/input/ati_remote.c
@@ -120,6 +120,7 @@
120 * behaviour. 120 * behaviour.
121 */ 121 */
122#define FILTER_TIME 60 /* msec */ 122#define FILTER_TIME 60 /* msec */
123#define REPEAT_DELAY 500 /* msec */
123 124
124static unsigned long channel_mask; 125static unsigned long channel_mask;
125module_param(channel_mask, ulong, 0644); 126module_param(channel_mask, ulong, 0644);
@@ -133,6 +134,10 @@ static int repeat_filter = FILTER_TIME;
133module_param(repeat_filter, int, 0644); 134module_param(repeat_filter, int, 0644);
134MODULE_PARM_DESC(repeat_filter, "Repeat filter time, default = 60 msec"); 135MODULE_PARM_DESC(repeat_filter, "Repeat filter time, default = 60 msec");
135 136
137static int repeat_delay = REPEAT_DELAY;
138module_param(repeat_delay, int, 0644);
139MODULE_PARM_DESC(repeat_delay, "Delay before sending repeats, default = 500 msec");
140
136#define dbginfo(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0) 141#define dbginfo(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0)
137#undef err 142#undef err
138#define err(format, arg...) printk(KERN_ERR format , ## arg) 143#define err(format, arg...) printk(KERN_ERR format , ## arg)
@@ -174,6 +179,8 @@ struct ati_remote {
174 unsigned char old_data[2]; /* Detect duplicate events */ 179 unsigned char old_data[2]; /* Detect duplicate events */
175 unsigned long old_jiffies; 180 unsigned long old_jiffies;
176 unsigned long acc_jiffies; /* handle acceleration */ 181 unsigned long acc_jiffies; /* handle acceleration */
182 unsigned long first_jiffies;
183
177 unsigned int repeat_count; 184 unsigned int repeat_count;
178 185
179 char name[NAME_BUFSIZE]; 186 char name[NAME_BUFSIZE];
@@ -318,7 +325,7 @@ static void ati_remote_dump(unsigned char *data, unsigned int len)
318 */ 325 */
319static int ati_remote_open(struct input_dev *inputdev) 326static int ati_remote_open(struct input_dev *inputdev)
320{ 327{
321 struct ati_remote *ati_remote = inputdev->private; 328 struct ati_remote *ati_remote = input_get_drvdata(inputdev);
322 329
323 /* On first open, submit the read urb which was set up previously. */ 330 /* On first open, submit the read urb which was set up previously. */
324 ati_remote->irq_urb->dev = ati_remote->udev; 331 ati_remote->irq_urb->dev = ati_remote->udev;
@@ -336,7 +343,7 @@ static int ati_remote_open(struct input_dev *inputdev)
336 */ 343 */
337static void ati_remote_close(struct input_dev *inputdev) 344static void ati_remote_close(struct input_dev *inputdev)
338{ 345{
339 struct ati_remote *ati_remote = inputdev->private; 346 struct ati_remote *ati_remote = input_get_drvdata(inputdev);
340 347
341 usb_kill_urb(ati_remote->irq_urb); 348 usb_kill_urb(ati_remote->irq_urb);
342} 349}
@@ -501,21 +508,31 @@ static void ati_remote_input_report(struct urb *urb)
501 } 508 }
502 509
503 if (ati_remote_tbl[index].kind == KIND_FILTERED) { 510 if (ati_remote_tbl[index].kind == KIND_FILTERED) {
511 unsigned long now = jiffies;
512
504 /* Filter duplicate events which happen "too close" together. */ 513 /* Filter duplicate events which happen "too close" together. */
505 if (ati_remote->old_data[0] == data[1] && 514 if (ati_remote->old_data[0] == data[1] &&
506 ati_remote->old_data[1] == data[2] && 515 ati_remote->old_data[1] == data[2] &&
507 time_before(jiffies, ati_remote->old_jiffies + msecs_to_jiffies(repeat_filter))) { 516 time_before(now, ati_remote->old_jiffies +
517 msecs_to_jiffies(repeat_filter))) {
508 ati_remote->repeat_count++; 518 ati_remote->repeat_count++;
509 } else { 519 } else {
510 ati_remote->repeat_count = 0; 520 ati_remote->repeat_count = 0;
521 ati_remote->first_jiffies = now;
511 } 522 }
512 523
513 ati_remote->old_data[0] = data[1]; 524 ati_remote->old_data[0] = data[1];
514 ati_remote->old_data[1] = data[2]; 525 ati_remote->old_data[1] = data[2];
515 ati_remote->old_jiffies = jiffies; 526 ati_remote->old_jiffies = now;
516 527
528 /* Ensure we skip at least the 4 first duplicate events (generated
529 * by a single keypress), and continue skipping until repeat_delay
530 * msecs have passed
531 */
517 if (ati_remote->repeat_count > 0 && 532 if (ati_remote->repeat_count > 0 &&
518 ati_remote->repeat_count < 5) 533 (ati_remote->repeat_count < 5 ||
534 time_before(now, ati_remote->first_jiffies +
535 msecs_to_jiffies(repeat_delay))))
519 return; 536 return;
520 537
521 538
@@ -653,7 +670,8 @@ static void ati_remote_input_init(struct ati_remote *ati_remote)
653 if (ati_remote_tbl[i].type == EV_KEY) 670 if (ati_remote_tbl[i].type == EV_KEY)
654 set_bit(ati_remote_tbl[i].code, idev->keybit); 671 set_bit(ati_remote_tbl[i].code, idev->keybit);
655 672
656 idev->private = ati_remote; 673 input_set_drvdata(idev, ati_remote);
674
657 idev->open = ati_remote_open; 675 idev->open = ati_remote_open;
658 idev->close = ati_remote_close; 676 idev->close = ati_remote_close;
659 677
@@ -661,7 +679,7 @@ static void ati_remote_input_init(struct ati_remote *ati_remote)
661 idev->phys = ati_remote->phys; 679 idev->phys = ati_remote->phys;
662 680
663 usb_to_input_id(ati_remote->udev, &idev->id); 681 usb_to_input_id(ati_remote->udev, &idev->id);
664 idev->cdev.dev = &ati_remote->udev->dev; 682 idev->dev.parent = &ati_remote->udev->dev;
665} 683}
666 684
667static int ati_remote_initialize(struct ati_remote *ati_remote) 685static int ati_remote_initialize(struct ati_remote *ati_remote)
@@ -772,15 +790,17 @@ static int ati_remote_probe(struct usb_interface *interface, const struct usb_de
772 goto fail3; 790 goto fail3;
773 791
774 /* Set up and register input device */ 792 /* Set up and register input device */
775 input_register_device(ati_remote->idev); 793 err = input_register_device(ati_remote->idev);
794 if (err)
795 goto fail3;
776 796
777 usb_set_intfdata(interface, ati_remote); 797 usb_set_intfdata(interface, ati_remote);
778 return 0; 798 return 0;
779 799
780fail3: usb_kill_urb(ati_remote->irq_urb); 800 fail3: usb_kill_urb(ati_remote->irq_urb);
781 usb_kill_urb(ati_remote->out_urb); 801 usb_kill_urb(ati_remote->out_urb);
782fail2: ati_remote_free_buffers(ati_remote); 802 fail2: ati_remote_free_buffers(ati_remote);
783fail1: input_free_device(input_dev); 803 fail1: input_free_device(input_dev);
784 kfree(ati_remote); 804 kfree(ati_remote);
785 return err; 805 return err;
786} 806}