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