1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89#include <linux/kernel.h>
90#include <linux/errno.h>
91#include <linux/init.h>
92#include <linux/slab.h>
93#include <linux/module.h>
94#include <linux/mutex.h>
95#include <linux/usb/input.h>
96#include <linux/wait.h>
97#include <linux/jiffies.h>
98#include <media/rc-core.h>
99
100
101
102
103
104#define ATI_REMOTE_VENDOR_ID 0x0bc7
105#define LOLA_REMOTE_PRODUCT_ID 0x0002
106#define LOLA2_REMOTE_PRODUCT_ID 0x0003
107#define ATI_REMOTE_PRODUCT_ID 0x0004
108#define NVIDIA_REMOTE_PRODUCT_ID 0x0005
109#define MEDION_REMOTE_PRODUCT_ID 0x0006
110#define FIREFLY_REMOTE_PRODUCT_ID 0x0008
111
112#define DRIVER_VERSION "2.2.1"
113#define DRIVER_AUTHOR "Torrey Hoffman <thoffman@arnor.net>"
114#define DRIVER_DESC "ATI/X10 RF USB Remote Control"
115
116#define NAME_BUFSIZE 80
117#define DATA_BUFSIZE 63
118
119
120
121
122
123
124
125
126
127#define FILTER_TIME 60
128#define REPEAT_DELAY 500
129
130static unsigned long channel_mask;
131module_param(channel_mask, ulong, 0644);
132MODULE_PARM_DESC(channel_mask, "Bitmask of remote control channels to ignore");
133
134static int debug;
135module_param(debug, int, 0644);
136MODULE_PARM_DESC(debug, "Enable extra debug messages and information");
137
138static int repeat_filter = FILTER_TIME;
139module_param(repeat_filter, int, 0644);
140MODULE_PARM_DESC(repeat_filter, "Repeat filter time, default = 60 msec");
141
142static int repeat_delay = REPEAT_DELAY;
143module_param(repeat_delay, int, 0644);
144MODULE_PARM_DESC(repeat_delay, "Delay before sending repeats, default = 500 msec");
145
146static bool mouse = true;
147module_param(mouse, bool, 0444);
148MODULE_PARM_DESC(mouse, "Enable mouse device, default = yes");
149
150#define dbginfo(dev, format, arg...) \
151 do { if (debug) dev_info(dev , format , ## arg); } while (0)
152#undef err
153#define err(format, arg...) printk(KERN_ERR format , ## arg)
154
155struct ati_receiver_type {
156
157 const char *default_keymap;
158 const char *(*get_default_keymap)(struct usb_interface *interface);
159};
160
161static const char *get_medion_keymap(struct usb_interface *interface)
162{
163 struct usb_device *udev = interface_to_usbdev(interface);
164
165
166
167
168
169
170
171 if (udev->manufacturer && udev->product) {
172 if (udev->actconfig->desc.bmAttributes & USB_CONFIG_ATT_WAKEUP) {
173
174 if (!strcmp(udev->manufacturer, "X10 Wireless Technology Inc")
175 && !strcmp(udev->product, "USB Receiver"))
176 return RC_MAP_MEDION_X10_DIGITAINER;
177
178 if (!strcmp(udev->manufacturer, "X10 WTI")
179 && !strcmp(udev->product, "RF receiver"))
180 return RC_MAP_MEDION_X10_OR2X;
181 } else {
182
183 if (!strcmp(udev->manufacturer, "X10 Wireless Technology Inc")
184 && !strcmp(udev->product, "USB Receiver"))
185 return RC_MAP_MEDION_X10;
186 }
187 }
188
189 dev_info(&interface->dev,
190 "Unknown Medion X10 receiver, using default ati_remote Medion keymap\n");
191
192 return RC_MAP_MEDION_X10;
193}
194
195static const struct ati_receiver_type type_ati = {
196 .default_keymap = RC_MAP_ATI_X10
197};
198static const struct ati_receiver_type type_medion = {
199 .get_default_keymap = get_medion_keymap
200};
201static const struct ati_receiver_type type_firefly = {
202 .default_keymap = RC_MAP_SNAPSTREAM_FIREFLY
203};
204
205static struct usb_device_id ati_remote_table[] = {
206 {
207 USB_DEVICE(ATI_REMOTE_VENDOR_ID, LOLA_REMOTE_PRODUCT_ID),
208 .driver_info = (unsigned long)&type_ati
209 },
210 {
211 USB_DEVICE(ATI_REMOTE_VENDOR_ID, LOLA2_REMOTE_PRODUCT_ID),
212 .driver_info = (unsigned long)&type_ati
213 },
214 {
215 USB_DEVICE(ATI_REMOTE_VENDOR_ID, ATI_REMOTE_PRODUCT_ID),
216 .driver_info = (unsigned long)&type_ati
217 },
218 {
219 USB_DEVICE(ATI_REMOTE_VENDOR_ID, NVIDIA_REMOTE_PRODUCT_ID),
220 .driver_info = (unsigned long)&type_ati
221 },
222 {
223 USB_DEVICE(ATI_REMOTE_VENDOR_ID, MEDION_REMOTE_PRODUCT_ID),
224 .driver_info = (unsigned long)&type_medion
225 },
226 {
227 USB_DEVICE(ATI_REMOTE_VENDOR_ID, FIREFLY_REMOTE_PRODUCT_ID),
228 .driver_info = (unsigned long)&type_firefly
229 },
230 {}
231};
232
233MODULE_DEVICE_TABLE(usb, ati_remote_table);
234
235
236#define HI(a) ((unsigned char)((a) >> 8))
237#define LO(a) ((unsigned char)((a) & 0xff))
238
239#define SEND_FLAG_IN_PROGRESS 1
240#define SEND_FLAG_COMPLETE 2
241
242
243static char init1[] = { 0x01, 0x00, 0x20, 0x14 };
244static char init2[] = { 0x01, 0x00, 0x20, 0x14, 0x20, 0x20, 0x20 };
245
246struct ati_remote {
247 struct input_dev *idev;
248 struct rc_dev *rdev;
249 struct usb_device *udev;
250 struct usb_interface *interface;
251
252 struct urb *irq_urb;
253 struct urb *out_urb;
254 struct usb_endpoint_descriptor *endpoint_in;
255 struct usb_endpoint_descriptor *endpoint_out;
256 unsigned char *inbuf;
257 unsigned char *outbuf;
258 dma_addr_t inbuf_dma;
259 dma_addr_t outbuf_dma;
260
261 unsigned char old_data;
262 unsigned long old_jiffies;
263 unsigned long acc_jiffies;
264 unsigned long first_jiffies;
265
266 unsigned int repeat_count;
267
268 char rc_name[NAME_BUFSIZE];
269 char rc_phys[NAME_BUFSIZE];
270 char mouse_name[NAME_BUFSIZE];
271 char mouse_phys[NAME_BUFSIZE];
272
273 wait_queue_head_t wait;
274 int send_flags;
275
276 int users;
277 struct mutex open_mutex;
278};
279
280
281#define KIND_END 0
282#define KIND_LITERAL 1
283#define KIND_FILTERED 2
284#define KIND_ACCEL 3
285
286
287static const struct {
288 unsigned char kind;
289 unsigned char data;
290 unsigned short code;
291} ati_remote_tbl[] = {
292
293 {KIND_ACCEL, 0x70, 0xff00},
294 {KIND_ACCEL, 0x71, 0x0100},
295 {KIND_ACCEL, 0x72, 0x00ff},
296 {KIND_ACCEL, 0x73, 0x0001},
297
298
299 {KIND_ACCEL, 0x74, 0xffff},
300 {KIND_ACCEL, 0x75, 0x01ff},
301 {KIND_ACCEL, 0x77, 0xff01},
302 {KIND_ACCEL, 0x76, 0x0101},
303
304
305
306 {KIND_LITERAL, 0x78, BTN_LEFT},
307 {KIND_LITERAL, 0x79, BTN_LEFT},
308 {KIND_LITERAL, 0x7c, BTN_RIGHT},
309 {KIND_LITERAL, 0x7d, BTN_RIGHT},
310
311
312
313 {KIND_FILTERED, 0x7a, BTN_SIDE},
314 {KIND_FILTERED, 0x7e, BTN_EXTRA},
315
316
317 {KIND_END, 0x00, 0}
318};
319
320
321
322
323static void ati_remote_dump(struct device *dev, unsigned char *data,
324 unsigned int len)
325{
326 if (len == 1) {
327 if (data[0] != (unsigned char)0xff && data[0] != 0x00)
328 dev_warn(dev, "Weird byte 0x%02x\n", data[0]);
329 } else if (len == 4)
330 dev_warn(dev, "Weird key %*ph\n", 4, data);
331 else
332 dev_warn(dev, "Weird data, len=%d %*ph ...\n", len, 6, data);
333}
334
335
336
337
338static int ati_remote_open(struct ati_remote *ati_remote)
339{
340 int err = 0;
341
342 mutex_lock(&ati_remote->open_mutex);
343
344 if (ati_remote->users++ != 0)
345 goto out;
346
347
348 ati_remote->irq_urb->dev = ati_remote->udev;
349 if (usb_submit_urb(ati_remote->irq_urb, GFP_KERNEL)) {
350 dev_err(&ati_remote->interface->dev,
351 "%s: usb_submit_urb failed!\n", __func__);
352 err = -EIO;
353 }
354
355out: mutex_unlock(&ati_remote->open_mutex);
356 return err;
357}
358
359
360
361
362static void ati_remote_close(struct ati_remote *ati_remote)
363{
364 mutex_lock(&ati_remote->open_mutex);
365 if (--ati_remote->users == 0)
366 usb_kill_urb(ati_remote->irq_urb);
367 mutex_unlock(&ati_remote->open_mutex);
368}
369
370static int ati_remote_input_open(struct input_dev *inputdev)
371{
372 struct ati_remote *ati_remote = input_get_drvdata(inputdev);
373 return ati_remote_open(ati_remote);
374}
375
376static void ati_remote_input_close(struct input_dev *inputdev)
377{
378 struct ati_remote *ati_remote = input_get_drvdata(inputdev);
379 ati_remote_close(ati_remote);
380}
381
382static int ati_remote_rc_open(struct rc_dev *rdev)
383{
384 struct ati_remote *ati_remote = rdev->priv;
385 return ati_remote_open(ati_remote);
386}
387
388static void ati_remote_rc_close(struct rc_dev *rdev)
389{
390 struct ati_remote *ati_remote = rdev->priv;
391 ati_remote_close(ati_remote);
392}
393
394
395
396
397static void ati_remote_irq_out(struct urb *urb)
398{
399 struct ati_remote *ati_remote = urb->context;
400
401 if (urb->status) {
402 dev_dbg(&ati_remote->interface->dev, "%s: status %d\n",
403 __func__, urb->status);
404 return;
405 }
406
407 ati_remote->send_flags |= SEND_FLAG_COMPLETE;
408 wmb();
409 wake_up(&ati_remote->wait);
410}
411
412
413
414
415
416
417static int ati_remote_sendpacket(struct ati_remote *ati_remote, u16 cmd,
418 unsigned char *data)
419{
420 int retval = 0;
421
422
423 memcpy(ati_remote->out_urb->transfer_buffer + 1, data, LO(cmd));
424 ((char *) ati_remote->out_urb->transfer_buffer)[0] = HI(cmd);
425
426 ati_remote->out_urb->transfer_buffer_length = LO(cmd) + 1;
427 ati_remote->out_urb->dev = ati_remote->udev;
428 ati_remote->send_flags = SEND_FLAG_IN_PROGRESS;
429
430 retval = usb_submit_urb(ati_remote->out_urb, GFP_ATOMIC);
431 if (retval) {
432 dev_dbg(&ati_remote->interface->dev,
433 "sendpacket: usb_submit_urb failed: %d\n", retval);
434 return retval;
435 }
436
437 wait_event_timeout(ati_remote->wait,
438 ((ati_remote->out_urb->status != -EINPROGRESS) ||
439 (ati_remote->send_flags & SEND_FLAG_COMPLETE)),
440 HZ);
441 usb_kill_urb(ati_remote->out_urb);
442
443 return retval;
444}
445
446struct accel_times {
447 const char value;
448 unsigned int msecs;
449};
450
451static const struct accel_times accel[] = {
452 { 1, 125 },
453 { 2, 250 },
454 { 4, 500 },
455 { 6, 1000 },
456 { 9, 1500 },
457 { 13, 2000 },
458 { 20, 0 },
459};
460
461
462
463
464
465
466
467
468
469
470static int ati_remote_compute_accel(struct ati_remote *ati_remote)
471{
472 unsigned long now = jiffies, reset_time;
473 int i;
474
475 reset_time = msecs_to_jiffies(250);
476
477 if (time_after(now, ati_remote->old_jiffies + reset_time)) {
478 ati_remote->acc_jiffies = now;
479 return 1;
480 }
481 for (i = 0; i < ARRAY_SIZE(accel) - 1; i++) {
482 unsigned long timeout = msecs_to_jiffies(accel[i].msecs);
483
484 if (time_before(now, ati_remote->acc_jiffies + timeout))
485 return accel[i].value;
486 }
487 return accel[i].value;
488}
489
490
491
492
493static void ati_remote_input_report(struct urb *urb)
494{
495 struct ati_remote *ati_remote = urb->context;
496 unsigned char *data= ati_remote->inbuf;
497 struct input_dev *dev = ati_remote->idev;
498 int index = -1;
499 int remote_num;
500 unsigned char scancode;
501 u32 wheel_keycode = KEY_RESERVED;
502 int i;
503
504
505
506
507
508
509
510
511
512 if ( urb->actual_length != 4 || data[0] != 0x14 ||
513 data[1] != (unsigned char)(data[2] + data[3] + 0xD5) ||
514 (data[3] & 0x0f) != 0x00) {
515 ati_remote_dump(&urb->dev->dev, data, urb->actual_length);
516 return;
517 }
518
519 if (data[1] != ((data[2] + data[3] + 0xd5) & 0xff)) {
520 dbginfo(&ati_remote->interface->dev,
521 "wrong checksum in input: %*ph\n", 4, data);
522 return;
523 }
524
525
526
527 remote_num = (data[3] >> 4) & 0x0f;
528 if (channel_mask & (1 << (remote_num + 1))) {
529 dbginfo(&ati_remote->interface->dev,
530 "Masked input from channel 0x%02x: data %02x, mask= 0x%02lx\n",
531 remote_num, data[2], channel_mask);
532 return;
533 }
534
535
536
537
538
539 scancode = data[2] & 0x7f;
540
541 dbginfo(&ati_remote->interface->dev,
542 "channel 0x%02x; key data %02x, scancode %02x\n",
543 remote_num, data[2], scancode);
544
545 if (scancode >= 0x70) {
546
547
548
549
550
551
552 wheel_keycode = rc_g_keycode_from_table(ati_remote->rdev,
553 scancode & 0x78);
554
555 if (wheel_keycode == KEY_RESERVED) {
556
557
558
559
560
561 for (i = 0; ati_remote_tbl[i].kind != KIND_END; i++) {
562 if (scancode == ati_remote_tbl[i].data) {
563 index = i;
564 break;
565 }
566 }
567 }
568 }
569
570 if (index >= 0 && ati_remote_tbl[index].kind == KIND_LITERAL) {
571
572
573
574
575 input_event(dev, EV_KEY, ati_remote_tbl[index].code,
576 !(data[2] & 1));
577
578 ati_remote->old_jiffies = jiffies;
579
580 } else if (index < 0 || ati_remote_tbl[index].kind == KIND_FILTERED) {
581 unsigned long now = jiffies;
582
583
584 if (ati_remote->old_data == data[2] &&
585 time_before(now, ati_remote->old_jiffies +
586 msecs_to_jiffies(repeat_filter))) {
587 ati_remote->repeat_count++;
588 } else {
589 ati_remote->repeat_count = 0;
590 ati_remote->first_jiffies = now;
591 }
592
593 ati_remote->old_jiffies = now;
594
595
596
597
598
599 if (ati_remote->repeat_count > 0 &&
600 (ati_remote->repeat_count < 5 ||
601 time_before(now, ati_remote->first_jiffies +
602 msecs_to_jiffies(repeat_delay))))
603 return;
604
605 if (index >= 0) {
606 input_event(dev, EV_KEY, ati_remote_tbl[index].code, 1);
607 input_event(dev, EV_KEY, ati_remote_tbl[index].code, 0);
608 } else {
609
610 int count = 1;
611
612 if (wheel_keycode != KEY_RESERVED) {
613
614
615
616
617
618
619 count = (scancode & 0x07) + 1;
620 scancode &= 0x78;
621 }
622
623 while (count--) {
624
625
626
627
628
629 rc_keydown_notimeout(ati_remote->rdev, RC_TYPE_OTHER,
630 scancode, data[2]);
631 rc_keyup(ati_remote->rdev);
632 }
633 goto nosync;
634 }
635
636 } else if (ati_remote_tbl[index].kind == KIND_ACCEL) {
637 signed char dx = ati_remote_tbl[index].code >> 8;
638 signed char dy = ati_remote_tbl[index].code & 255;
639
640
641
642
643
644
645 int acc = ati_remote_compute_accel(ati_remote);
646 if (dx)
647 input_report_rel(dev, REL_X, dx * acc);
648 if (dy)
649 input_report_rel(dev, REL_Y, dy * acc);
650 ati_remote->old_jiffies = jiffies;
651
652 } else {
653 dev_dbg(&ati_remote->interface->dev, "ati_remote kind=%d\n",
654 ati_remote_tbl[index].kind);
655 return;
656 }
657 input_sync(dev);
658nosync:
659 ati_remote->old_data = data[2];
660}
661
662
663
664
665static void ati_remote_irq_in(struct urb *urb)
666{
667 struct ati_remote *ati_remote = urb->context;
668 int retval;
669
670 switch (urb->status) {
671 case 0:
672 ati_remote_input_report(urb);
673 break;
674 case -ECONNRESET:
675 case -ENOENT:
676 case -ESHUTDOWN:
677 dev_dbg(&ati_remote->interface->dev,
678 "%s: urb error status, unlink?\n",
679 __func__);
680 return;
681 default:
682 dev_dbg(&ati_remote->interface->dev,
683 "%s: Nonzero urb status %d\n",
684 __func__, urb->status);
685 }
686
687 retval = usb_submit_urb(urb, GFP_ATOMIC);
688 if (retval)
689 dev_err(&ati_remote->interface->dev,
690 "%s: usb_submit_urb()=%d\n",
691 __func__, retval);
692}
693
694
695
696
697static int ati_remote_alloc_buffers(struct usb_device *udev,
698 struct ati_remote *ati_remote)
699{
700 ati_remote->inbuf = usb_alloc_coherent(udev, DATA_BUFSIZE, GFP_ATOMIC,
701 &ati_remote->inbuf_dma);
702 if (!ati_remote->inbuf)
703 return -1;
704
705 ati_remote->outbuf = usb_alloc_coherent(udev, DATA_BUFSIZE, GFP_ATOMIC,
706 &ati_remote->outbuf_dma);
707 if (!ati_remote->outbuf)
708 return -1;
709
710 ati_remote->irq_urb = usb_alloc_urb(0, GFP_KERNEL);
711 if (!ati_remote->irq_urb)
712 return -1;
713
714 ati_remote->out_urb = usb_alloc_urb(0, GFP_KERNEL);
715 if (!ati_remote->out_urb)
716 return -1;
717
718 return 0;
719}
720
721
722
723
724static void ati_remote_free_buffers(struct ati_remote *ati_remote)
725{
726 usb_free_urb(ati_remote->irq_urb);
727 usb_free_urb(ati_remote->out_urb);
728
729 usb_free_coherent(ati_remote->udev, DATA_BUFSIZE,
730 ati_remote->inbuf, ati_remote->inbuf_dma);
731
732 usb_free_coherent(ati_remote->udev, DATA_BUFSIZE,
733 ati_remote->outbuf, ati_remote->outbuf_dma);
734}
735
736static void ati_remote_input_init(struct ati_remote *ati_remote)
737{
738 struct input_dev *idev = ati_remote->idev;
739 int i;
740
741 idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
742 idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
743 BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_SIDE) | BIT_MASK(BTN_EXTRA);
744 idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
745 for (i = 0; ati_remote_tbl[i].kind != KIND_END; i++)
746 if (ati_remote_tbl[i].kind == KIND_LITERAL ||
747 ati_remote_tbl[i].kind == KIND_FILTERED)
748 __set_bit(ati_remote_tbl[i].code, idev->keybit);
749
750 input_set_drvdata(idev, ati_remote);
751
752 idev->open = ati_remote_input_open;
753 idev->close = ati_remote_input_close;
754
755 idev->name = ati_remote->mouse_name;
756 idev->phys = ati_remote->mouse_phys;
757
758 usb_to_input_id(ati_remote->udev, &idev->id);
759 idev->dev.parent = &ati_remote->interface->dev;
760}
761
762static void ati_remote_rc_init(struct ati_remote *ati_remote)
763{
764 struct rc_dev *rdev = ati_remote->rdev;
765
766 rdev->priv = ati_remote;
767 rdev->driver_type = RC_DRIVER_SCANCODE;
768 rdev->allowed_protocols = RC_BIT_OTHER;
769 rdev->driver_name = "ati_remote";
770
771 rdev->open = ati_remote_rc_open;
772 rdev->close = ati_remote_rc_close;
773
774 rdev->input_name = ati_remote->rc_name;
775 rdev->input_phys = ati_remote->rc_phys;
776
777 usb_to_input_id(ati_remote->udev, &rdev->input_id);
778 rdev->dev.parent = &ati_remote->interface->dev;
779}
780
781static int ati_remote_initialize(struct ati_remote *ati_remote)
782{
783 struct usb_device *udev = ati_remote->udev;
784 int pipe, maxp;
785
786 init_waitqueue_head(&ati_remote->wait);
787
788
789 pipe = usb_rcvintpipe(udev, ati_remote->endpoint_in->bEndpointAddress);
790 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
791 maxp = (maxp > DATA_BUFSIZE) ? DATA_BUFSIZE : maxp;
792
793 usb_fill_int_urb(ati_remote->irq_urb, udev, pipe, ati_remote->inbuf,
794 maxp, ati_remote_irq_in, ati_remote,
795 ati_remote->endpoint_in->bInterval);
796 ati_remote->irq_urb->transfer_dma = ati_remote->inbuf_dma;
797 ati_remote->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
798
799
800 pipe = usb_sndintpipe(udev, ati_remote->endpoint_out->bEndpointAddress);
801 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
802 maxp = (maxp > DATA_BUFSIZE) ? DATA_BUFSIZE : maxp;
803
804 usb_fill_int_urb(ati_remote->out_urb, udev, pipe, ati_remote->outbuf,
805 maxp, ati_remote_irq_out, ati_remote,
806 ati_remote->endpoint_out->bInterval);
807 ati_remote->out_urb->transfer_dma = ati_remote->outbuf_dma;
808 ati_remote->out_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
809
810
811 if ((ati_remote_sendpacket(ati_remote, 0x8004, init1)) ||
812 (ati_remote_sendpacket(ati_remote, 0x8007, init2))) {
813 dev_err(&ati_remote->interface->dev,
814 "Initializing ati_remote hardware failed.\n");
815 return -EIO;
816 }
817
818 return 0;
819}
820
821
822
823
824static int ati_remote_probe(struct usb_interface *interface,
825 const struct usb_device_id *id)
826{
827 struct usb_device *udev = interface_to_usbdev(interface);
828 struct usb_host_interface *iface_host = interface->cur_altsetting;
829 struct usb_endpoint_descriptor *endpoint_in, *endpoint_out;
830 struct ati_receiver_type *type = (struct ati_receiver_type *)id->driver_info;
831 struct ati_remote *ati_remote;
832 struct input_dev *input_dev;
833 struct rc_dev *rc_dev;
834 int err = -ENOMEM;
835
836 if (iface_host->desc.bNumEndpoints != 2) {
837 err("%s: Unexpected desc.bNumEndpoints\n", __func__);
838 return -ENODEV;
839 }
840
841 endpoint_in = &iface_host->endpoint[0].desc;
842 endpoint_out = &iface_host->endpoint[1].desc;
843
844 if (!usb_endpoint_is_int_in(endpoint_in)) {
845 err("%s: Unexpected endpoint_in\n", __func__);
846 return -ENODEV;
847 }
848 if (le16_to_cpu(endpoint_in->wMaxPacketSize) == 0) {
849 err("%s: endpoint_in message size==0? \n", __func__);
850 return -ENODEV;
851 }
852
853 ati_remote = kzalloc(sizeof (struct ati_remote), GFP_KERNEL);
854 rc_dev = rc_allocate_device();
855 if (!ati_remote || !rc_dev)
856 goto exit_free_dev_rdev;
857
858
859 if (ati_remote_alloc_buffers(udev, ati_remote))
860 goto exit_free_buffers;
861
862 ati_remote->endpoint_in = endpoint_in;
863 ati_remote->endpoint_out = endpoint_out;
864 ati_remote->udev = udev;
865 ati_remote->rdev = rc_dev;
866 ati_remote->interface = interface;
867
868 usb_make_path(udev, ati_remote->rc_phys, sizeof(ati_remote->rc_phys));
869 strlcpy(ati_remote->mouse_phys, ati_remote->rc_phys,
870 sizeof(ati_remote->mouse_phys));
871
872 strlcat(ati_remote->rc_phys, "/input0", sizeof(ati_remote->rc_phys));
873 strlcat(ati_remote->mouse_phys, "/input1", sizeof(ati_remote->mouse_phys));
874
875 snprintf(ati_remote->rc_name, sizeof(ati_remote->rc_name), "%s%s%s",
876 udev->manufacturer ?: "",
877 udev->manufacturer && udev->product ? " " : "",
878 udev->product ?: "");
879
880 if (!strlen(ati_remote->rc_name))
881 snprintf(ati_remote->rc_name, sizeof(ati_remote->rc_name),
882 DRIVER_DESC "(%04x,%04x)",
883 le16_to_cpu(ati_remote->udev->descriptor.idVendor),
884 le16_to_cpu(ati_remote->udev->descriptor.idProduct));
885
886 snprintf(ati_remote->mouse_name, sizeof(ati_remote->mouse_name),
887 "%s mouse", ati_remote->rc_name);
888
889 rc_dev->map_name = RC_MAP_ATI_X10;
890
891
892 if (type) {
893 if (type->default_keymap)
894 rc_dev->map_name = type->default_keymap;
895 else if (type->get_default_keymap)
896 rc_dev->map_name = type->get_default_keymap(interface);
897 }
898
899 ati_remote_rc_init(ati_remote);
900 mutex_init(&ati_remote->open_mutex);
901
902
903 err = ati_remote_initialize(ati_remote);
904 if (err)
905 goto exit_kill_urbs;
906
907
908 err = rc_register_device(ati_remote->rdev);
909 if (err)
910 goto exit_kill_urbs;
911
912
913 ati_remote->rdev->input_dev->rep[REP_DELAY] = repeat_delay;
914
915
916 if (mouse) {
917 input_dev = input_allocate_device();
918 if (!input_dev) {
919 err = -ENOMEM;
920 goto exit_unregister_device;
921 }
922
923 ati_remote->idev = input_dev;
924 ati_remote_input_init(ati_remote);
925 err = input_register_device(input_dev);
926
927 if (err)
928 goto exit_free_input_device;
929 }
930
931 usb_set_intfdata(interface, ati_remote);
932 return 0;
933
934 exit_free_input_device:
935 input_free_device(input_dev);
936 exit_unregister_device:
937 rc_unregister_device(rc_dev);
938 rc_dev = NULL;
939 exit_kill_urbs:
940 usb_kill_urb(ati_remote->irq_urb);
941 usb_kill_urb(ati_remote->out_urb);
942 exit_free_buffers:
943 ati_remote_free_buffers(ati_remote);
944 exit_free_dev_rdev:
945 rc_free_device(rc_dev);
946 kfree(ati_remote);
947 return err;
948}
949
950
951
952
953static void ati_remote_disconnect(struct usb_interface *interface)
954{
955 struct ati_remote *ati_remote;
956
957 ati_remote = usb_get_intfdata(interface);
958 usb_set_intfdata(interface, NULL);
959 if (!ati_remote) {
960 dev_warn(&interface->dev, "%s - null device?\n", __func__);
961 return;
962 }
963
964 usb_kill_urb(ati_remote->irq_urb);
965 usb_kill_urb(ati_remote->out_urb);
966 if (ati_remote->idev)
967 input_unregister_device(ati_remote->idev);
968 rc_unregister_device(ati_remote->rdev);
969 ati_remote_free_buffers(ati_remote);
970 kfree(ati_remote);
971}
972
973
974static struct usb_driver ati_remote_driver = {
975 .name = "ati_remote",
976 .probe = ati_remote_probe,
977 .disconnect = ati_remote_disconnect,
978 .id_table = ati_remote_table,
979};
980
981module_usb_driver(ati_remote_driver);
982
983MODULE_AUTHOR(DRIVER_AUTHOR);
984MODULE_DESCRIPTION(DRIVER_DESC);
985MODULE_LICENSE("GPL");
986