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