0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075 #include <linux/kernel.h>
0076 #include <linux/errno.h>
0077 #include <linux/init.h>
0078 #include <linux/slab.h>
0079 #include <linux/module.h>
0080 #include <linux/mutex.h>
0081 #include <linux/usb/input.h>
0082 #include <linux/wait.h>
0083 #include <linux/jiffies.h>
0084 #include <media/rc-core.h>
0085
0086
0087
0088
0089
0090 #define ATI_REMOTE_VENDOR_ID 0x0bc7
0091 #define LOLA_REMOTE_PRODUCT_ID 0x0002
0092 #define LOLA2_REMOTE_PRODUCT_ID 0x0003
0093 #define ATI_REMOTE_PRODUCT_ID 0x0004
0094 #define NVIDIA_REMOTE_PRODUCT_ID 0x0005
0095 #define MEDION_REMOTE_PRODUCT_ID 0x0006
0096 #define FIREFLY_REMOTE_PRODUCT_ID 0x0008
0097
0098 #define DRIVER_VERSION "2.2.1"
0099 #define DRIVER_AUTHOR "Torrey Hoffman <thoffman@arnor.net>"
0100 #define DRIVER_DESC "ATI/X10 RF USB Remote Control"
0101
0102 #define NAME_BUFSIZE 80
0103 #define DATA_BUFSIZE 63
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113 #define FILTER_TIME 60
0114 #define REPEAT_DELAY 500
0115
0116 static unsigned long channel_mask;
0117 module_param(channel_mask, ulong, 0644);
0118 MODULE_PARM_DESC(channel_mask, "Bitmask of remote control channels to ignore");
0119
0120 static int debug;
0121 module_param(debug, int, 0644);
0122 MODULE_PARM_DESC(debug, "Enable extra debug messages and information");
0123
0124 static int repeat_filter = FILTER_TIME;
0125 module_param(repeat_filter, int, 0644);
0126 MODULE_PARM_DESC(repeat_filter, "Repeat filter time, default = 60 msec");
0127
0128 static int repeat_delay = REPEAT_DELAY;
0129 module_param(repeat_delay, int, 0644);
0130 MODULE_PARM_DESC(repeat_delay, "Delay before sending repeats, default = 500 msec");
0131
0132 static bool mouse = true;
0133 module_param(mouse, bool, 0444);
0134 MODULE_PARM_DESC(mouse, "Enable mouse device, default = yes");
0135
0136 #define dbginfo(dev, format, arg...) \
0137 do { if (debug) dev_info(dev , format , ## arg); } while (0)
0138
0139 struct ati_receiver_type {
0140
0141 const char *default_keymap;
0142 const char *(*get_default_keymap)(struct usb_interface *interface);
0143 };
0144
0145 static const char *get_medion_keymap(struct usb_interface *interface)
0146 {
0147 struct usb_device *udev = interface_to_usbdev(interface);
0148
0149
0150
0151
0152
0153
0154
0155 if (udev->manufacturer && udev->product) {
0156 if (udev->actconfig->desc.bmAttributes & USB_CONFIG_ATT_WAKEUP) {
0157
0158 if (!strcmp(udev->manufacturer, "X10 Wireless Technology Inc")
0159 && !strcmp(udev->product, "USB Receiver"))
0160 return RC_MAP_MEDION_X10_DIGITAINER;
0161
0162 if (!strcmp(udev->manufacturer, "X10 WTI")
0163 && !strcmp(udev->product, "RF receiver"))
0164 return RC_MAP_MEDION_X10_OR2X;
0165 } else {
0166
0167 if (!strcmp(udev->manufacturer, "X10 Wireless Technology Inc")
0168 && !strcmp(udev->product, "USB Receiver"))
0169 return RC_MAP_MEDION_X10;
0170 }
0171 }
0172
0173 dev_info(&interface->dev,
0174 "Unknown Medion X10 receiver, using default ati_remote Medion keymap\n");
0175
0176 return RC_MAP_MEDION_X10;
0177 }
0178
0179 static const struct ati_receiver_type type_ati = {
0180 .default_keymap = RC_MAP_ATI_X10
0181 };
0182 static const struct ati_receiver_type type_medion = {
0183 .get_default_keymap = get_medion_keymap
0184 };
0185 static const struct ati_receiver_type type_firefly = {
0186 .default_keymap = RC_MAP_SNAPSTREAM_FIREFLY
0187 };
0188
0189 static const struct usb_device_id ati_remote_table[] = {
0190 {
0191 USB_DEVICE(ATI_REMOTE_VENDOR_ID, LOLA_REMOTE_PRODUCT_ID),
0192 .driver_info = (unsigned long)&type_ati
0193 },
0194 {
0195 USB_DEVICE(ATI_REMOTE_VENDOR_ID, LOLA2_REMOTE_PRODUCT_ID),
0196 .driver_info = (unsigned long)&type_ati
0197 },
0198 {
0199 USB_DEVICE(ATI_REMOTE_VENDOR_ID, ATI_REMOTE_PRODUCT_ID),
0200 .driver_info = (unsigned long)&type_ati
0201 },
0202 {
0203 USB_DEVICE(ATI_REMOTE_VENDOR_ID, NVIDIA_REMOTE_PRODUCT_ID),
0204 .driver_info = (unsigned long)&type_ati
0205 },
0206 {
0207 USB_DEVICE(ATI_REMOTE_VENDOR_ID, MEDION_REMOTE_PRODUCT_ID),
0208 .driver_info = (unsigned long)&type_medion
0209 },
0210 {
0211 USB_DEVICE(ATI_REMOTE_VENDOR_ID, FIREFLY_REMOTE_PRODUCT_ID),
0212 .driver_info = (unsigned long)&type_firefly
0213 },
0214 {}
0215 };
0216
0217 MODULE_DEVICE_TABLE(usb, ati_remote_table);
0218
0219
0220 #define HI(a) ((unsigned char)((a) >> 8))
0221 #define LO(a) ((unsigned char)((a) & 0xff))
0222
0223 #define SEND_FLAG_IN_PROGRESS 1
0224 #define SEND_FLAG_COMPLETE 2
0225
0226
0227 static char init1[] = { 0x01, 0x00, 0x20, 0x14 };
0228 static char init2[] = { 0x01, 0x00, 0x20, 0x14, 0x20, 0x20, 0x20 };
0229
0230 struct ati_remote {
0231 struct input_dev *idev;
0232 struct rc_dev *rdev;
0233 struct usb_device *udev;
0234 struct usb_interface *interface;
0235
0236 struct urb *irq_urb;
0237 struct urb *out_urb;
0238 struct usb_endpoint_descriptor *endpoint_in;
0239 struct usb_endpoint_descriptor *endpoint_out;
0240 unsigned char *inbuf;
0241 unsigned char *outbuf;
0242 dma_addr_t inbuf_dma;
0243 dma_addr_t outbuf_dma;
0244
0245 unsigned char old_data;
0246 unsigned long old_jiffies;
0247 unsigned long acc_jiffies;
0248 unsigned long first_jiffies;
0249
0250 unsigned int repeat_count;
0251
0252 char rc_name[NAME_BUFSIZE];
0253 char rc_phys[NAME_BUFSIZE];
0254 char mouse_name[NAME_BUFSIZE];
0255 char mouse_phys[NAME_BUFSIZE];
0256
0257 wait_queue_head_t wait;
0258 int send_flags;
0259
0260 int users;
0261 struct mutex open_mutex;
0262 };
0263
0264
0265 #define KIND_END 0
0266 #define KIND_LITERAL 1
0267 #define KIND_FILTERED 2
0268 #define KIND_ACCEL 3
0269
0270
0271 static const struct {
0272 unsigned char kind;
0273 unsigned char data;
0274 unsigned short code;
0275 } ati_remote_tbl[] = {
0276
0277 {KIND_ACCEL, 0x70, 0xff00},
0278 {KIND_ACCEL, 0x71, 0x0100},
0279 {KIND_ACCEL, 0x72, 0x00ff},
0280 {KIND_ACCEL, 0x73, 0x0001},
0281
0282
0283 {KIND_ACCEL, 0x74, 0xffff},
0284 {KIND_ACCEL, 0x75, 0x01ff},
0285 {KIND_ACCEL, 0x77, 0xff01},
0286 {KIND_ACCEL, 0x76, 0x0101},
0287
0288
0289
0290 {KIND_LITERAL, 0x78, BTN_LEFT},
0291 {KIND_LITERAL, 0x79, BTN_LEFT},
0292 {KIND_LITERAL, 0x7c, BTN_RIGHT},
0293 {KIND_LITERAL, 0x7d, BTN_RIGHT},
0294
0295
0296
0297 {KIND_FILTERED, 0x7a, BTN_SIDE},
0298 {KIND_FILTERED, 0x7e, BTN_EXTRA},
0299
0300
0301 {KIND_END, 0x00, 0}
0302 };
0303
0304
0305
0306
0307 static void ati_remote_dump(struct device *dev, unsigned char *data,
0308 unsigned int len)
0309 {
0310 if (len == 1) {
0311 if (data[0] != (unsigned char)0xff && data[0] != 0x00)
0312 dev_warn(dev, "Weird byte 0x%02x\n", data[0]);
0313 } else if (len == 4)
0314 dev_warn(dev, "Weird key %*ph\n", 4, data);
0315 else
0316 dev_warn(dev, "Weird data, len=%d %*ph ...\n", len, 6, data);
0317 }
0318
0319
0320
0321
0322 static int ati_remote_open(struct ati_remote *ati_remote)
0323 {
0324 int err = 0;
0325
0326 mutex_lock(&ati_remote->open_mutex);
0327
0328 if (ati_remote->users++ != 0)
0329 goto out;
0330
0331
0332 ati_remote->irq_urb->dev = ati_remote->udev;
0333 if (usb_submit_urb(ati_remote->irq_urb, GFP_KERNEL)) {
0334 dev_err(&ati_remote->interface->dev,
0335 "%s: usb_submit_urb failed!\n", __func__);
0336 err = -EIO;
0337 }
0338
0339 out: mutex_unlock(&ati_remote->open_mutex);
0340 return err;
0341 }
0342
0343
0344
0345
0346 static void ati_remote_close(struct ati_remote *ati_remote)
0347 {
0348 mutex_lock(&ati_remote->open_mutex);
0349 if (--ati_remote->users == 0)
0350 usb_kill_urb(ati_remote->irq_urb);
0351 mutex_unlock(&ati_remote->open_mutex);
0352 }
0353
0354 static int ati_remote_input_open(struct input_dev *inputdev)
0355 {
0356 struct ati_remote *ati_remote = input_get_drvdata(inputdev);
0357 return ati_remote_open(ati_remote);
0358 }
0359
0360 static void ati_remote_input_close(struct input_dev *inputdev)
0361 {
0362 struct ati_remote *ati_remote = input_get_drvdata(inputdev);
0363 ati_remote_close(ati_remote);
0364 }
0365
0366 static int ati_remote_rc_open(struct rc_dev *rdev)
0367 {
0368 struct ati_remote *ati_remote = rdev->priv;
0369 return ati_remote_open(ati_remote);
0370 }
0371
0372 static void ati_remote_rc_close(struct rc_dev *rdev)
0373 {
0374 struct ati_remote *ati_remote = rdev->priv;
0375 ati_remote_close(ati_remote);
0376 }
0377
0378
0379
0380
0381 static void ati_remote_irq_out(struct urb *urb)
0382 {
0383 struct ati_remote *ati_remote = urb->context;
0384
0385 if (urb->status) {
0386 dev_dbg(&ati_remote->interface->dev, "%s: status %d\n",
0387 __func__, urb->status);
0388 return;
0389 }
0390
0391 ati_remote->send_flags |= SEND_FLAG_COMPLETE;
0392 wmb();
0393 wake_up(&ati_remote->wait);
0394 }
0395
0396
0397
0398
0399
0400
0401 static int ati_remote_sendpacket(struct ati_remote *ati_remote, u16 cmd,
0402 unsigned char *data)
0403 {
0404 int retval = 0;
0405
0406
0407 memcpy(ati_remote->out_urb->transfer_buffer + 1, data, LO(cmd));
0408 ((char *) ati_remote->out_urb->transfer_buffer)[0] = HI(cmd);
0409
0410 ati_remote->out_urb->transfer_buffer_length = LO(cmd) + 1;
0411 ati_remote->out_urb->dev = ati_remote->udev;
0412 ati_remote->send_flags = SEND_FLAG_IN_PROGRESS;
0413
0414 retval = usb_submit_urb(ati_remote->out_urb, GFP_ATOMIC);
0415 if (retval) {
0416 dev_dbg(&ati_remote->interface->dev,
0417 "sendpacket: usb_submit_urb failed: %d\n", retval);
0418 return retval;
0419 }
0420
0421 wait_event_timeout(ati_remote->wait,
0422 ((ati_remote->out_urb->status != -EINPROGRESS) ||
0423 (ati_remote->send_flags & SEND_FLAG_COMPLETE)),
0424 HZ);
0425 usb_kill_urb(ati_remote->out_urb);
0426
0427 return retval;
0428 }
0429
0430 struct accel_times {
0431 const char value;
0432 unsigned int msecs;
0433 };
0434
0435 static const struct accel_times accel[] = {
0436 { 1, 125 },
0437 { 2, 250 },
0438 { 4, 500 },
0439 { 6, 1000 },
0440 { 9, 1500 },
0441 { 13, 2000 },
0442 { 20, 0 },
0443 };
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453
0454 static int ati_remote_compute_accel(struct ati_remote *ati_remote)
0455 {
0456 unsigned long now = jiffies, reset_time;
0457 int i;
0458
0459 reset_time = msecs_to_jiffies(250);
0460
0461 if (time_after(now, ati_remote->old_jiffies + reset_time)) {
0462 ati_remote->acc_jiffies = now;
0463 return 1;
0464 }
0465 for (i = 0; i < ARRAY_SIZE(accel) - 1; i++) {
0466 unsigned long timeout = msecs_to_jiffies(accel[i].msecs);
0467
0468 if (time_before(now, ati_remote->acc_jiffies + timeout))
0469 return accel[i].value;
0470 }
0471 return accel[i].value;
0472 }
0473
0474
0475
0476
0477 static void ati_remote_input_report(struct urb *urb)
0478 {
0479 struct ati_remote *ati_remote = urb->context;
0480 unsigned char *data= ati_remote->inbuf;
0481 struct input_dev *dev = ati_remote->idev;
0482 int index = -1;
0483 int remote_num;
0484 unsigned char scancode;
0485 u32 wheel_keycode = KEY_RESERVED;
0486 int i;
0487
0488
0489
0490
0491
0492
0493
0494
0495
0496 if ( urb->actual_length != 4 || data[0] != 0x14 ||
0497 data[1] != (unsigned char)(data[2] + data[3] + 0xD5) ||
0498 (data[3] & 0x0f) != 0x00) {
0499 ati_remote_dump(&urb->dev->dev, data, urb->actual_length);
0500 return;
0501 }
0502
0503 if (data[1] != ((data[2] + data[3] + 0xd5) & 0xff)) {
0504 dbginfo(&ati_remote->interface->dev,
0505 "wrong checksum in input: %*ph\n", 4, data);
0506 return;
0507 }
0508
0509
0510
0511 remote_num = (data[3] >> 4) & 0x0f;
0512 if (channel_mask & (1 << (remote_num + 1))) {
0513 dbginfo(&ati_remote->interface->dev,
0514 "Masked input from channel 0x%02x: data %02x, mask= 0x%02lx\n",
0515 remote_num, data[2], channel_mask);
0516 return;
0517 }
0518
0519
0520
0521
0522
0523 scancode = data[2] & 0x7f;
0524
0525 dbginfo(&ati_remote->interface->dev,
0526 "channel 0x%02x; key data %02x, scancode %02x\n",
0527 remote_num, data[2], scancode);
0528
0529 if (scancode >= 0x70) {
0530
0531
0532
0533
0534
0535
0536 wheel_keycode = rc_g_keycode_from_table(ati_remote->rdev,
0537 scancode & 0x78);
0538
0539 if (wheel_keycode == KEY_RESERVED) {
0540
0541
0542
0543
0544
0545 for (i = 0; ati_remote_tbl[i].kind != KIND_END; i++) {
0546 if (scancode == ati_remote_tbl[i].data) {
0547 index = i;
0548 break;
0549 }
0550 }
0551 }
0552 }
0553
0554 if (index >= 0 && ati_remote_tbl[index].kind == KIND_LITERAL) {
0555
0556
0557
0558
0559 input_event(dev, EV_KEY, ati_remote_tbl[index].code,
0560 !(data[2] & 1));
0561
0562 ati_remote->old_jiffies = jiffies;
0563
0564 } else if (index < 0 || ati_remote_tbl[index].kind == KIND_FILTERED) {
0565 unsigned long now = jiffies;
0566
0567
0568 if (ati_remote->old_data == data[2] &&
0569 time_before(now, ati_remote->old_jiffies +
0570 msecs_to_jiffies(repeat_filter))) {
0571 ati_remote->repeat_count++;
0572 } else {
0573 ati_remote->repeat_count = 0;
0574 ati_remote->first_jiffies = now;
0575 }
0576
0577 ati_remote->old_jiffies = now;
0578
0579
0580
0581
0582
0583 if (ati_remote->repeat_count > 0 &&
0584 (ati_remote->repeat_count < 5 ||
0585 time_before(now, ati_remote->first_jiffies +
0586 msecs_to_jiffies(repeat_delay))))
0587 return;
0588
0589 if (index >= 0) {
0590 input_event(dev, EV_KEY, ati_remote_tbl[index].code, 1);
0591 input_event(dev, EV_KEY, ati_remote_tbl[index].code, 0);
0592 } else {
0593
0594 int count = 1;
0595
0596 if (wheel_keycode != KEY_RESERVED) {
0597
0598
0599
0600
0601
0602
0603 count = (scancode & 0x07) + 1;
0604 scancode &= 0x78;
0605 }
0606
0607 while (count--) {
0608
0609
0610
0611
0612
0613 rc_keydown_notimeout(ati_remote->rdev,
0614 RC_PROTO_OTHER,
0615 scancode, data[2]);
0616 rc_keyup(ati_remote->rdev);
0617 }
0618 goto nosync;
0619 }
0620
0621 } else if (ati_remote_tbl[index].kind == KIND_ACCEL) {
0622 signed char dx = ati_remote_tbl[index].code >> 8;
0623 signed char dy = ati_remote_tbl[index].code & 255;
0624
0625
0626
0627
0628
0629
0630 int acc = ati_remote_compute_accel(ati_remote);
0631 if (dx)
0632 input_report_rel(dev, REL_X, dx * acc);
0633 if (dy)
0634 input_report_rel(dev, REL_Y, dy * acc);
0635 ati_remote->old_jiffies = jiffies;
0636
0637 } else {
0638 dev_dbg(&ati_remote->interface->dev, "ati_remote kind=%d\n",
0639 ati_remote_tbl[index].kind);
0640 return;
0641 }
0642 input_sync(dev);
0643 nosync:
0644 ati_remote->old_data = data[2];
0645 }
0646
0647
0648
0649
0650 static void ati_remote_irq_in(struct urb *urb)
0651 {
0652 struct ati_remote *ati_remote = urb->context;
0653 int retval;
0654
0655 switch (urb->status) {
0656 case 0:
0657 ati_remote_input_report(urb);
0658 break;
0659 case -ECONNRESET:
0660 case -ENOENT:
0661 case -ESHUTDOWN:
0662 dev_dbg(&ati_remote->interface->dev,
0663 "%s: urb error status, unlink?\n",
0664 __func__);
0665 return;
0666 default:
0667 dev_dbg(&ati_remote->interface->dev,
0668 "%s: Nonzero urb status %d\n",
0669 __func__, urb->status);
0670 }
0671
0672 retval = usb_submit_urb(urb, GFP_ATOMIC);
0673 if (retval)
0674 dev_err(&ati_remote->interface->dev,
0675 "%s: usb_submit_urb()=%d\n",
0676 __func__, retval);
0677 }
0678
0679
0680
0681
0682 static int ati_remote_alloc_buffers(struct usb_device *udev,
0683 struct ati_remote *ati_remote)
0684 {
0685 ati_remote->inbuf = usb_alloc_coherent(udev, DATA_BUFSIZE, GFP_ATOMIC,
0686 &ati_remote->inbuf_dma);
0687 if (!ati_remote->inbuf)
0688 return -1;
0689
0690 ati_remote->outbuf = usb_alloc_coherent(udev, DATA_BUFSIZE, GFP_ATOMIC,
0691 &ati_remote->outbuf_dma);
0692 if (!ati_remote->outbuf)
0693 return -1;
0694
0695 ati_remote->irq_urb = usb_alloc_urb(0, GFP_KERNEL);
0696 if (!ati_remote->irq_urb)
0697 return -1;
0698
0699 ati_remote->out_urb = usb_alloc_urb(0, GFP_KERNEL);
0700 if (!ati_remote->out_urb)
0701 return -1;
0702
0703 return 0;
0704 }
0705
0706
0707
0708
0709 static void ati_remote_free_buffers(struct ati_remote *ati_remote)
0710 {
0711 usb_free_urb(ati_remote->irq_urb);
0712 usb_free_urb(ati_remote->out_urb);
0713
0714 usb_free_coherent(ati_remote->udev, DATA_BUFSIZE,
0715 ati_remote->inbuf, ati_remote->inbuf_dma);
0716
0717 usb_free_coherent(ati_remote->udev, DATA_BUFSIZE,
0718 ati_remote->outbuf, ati_remote->outbuf_dma);
0719 }
0720
0721 static void ati_remote_input_init(struct ati_remote *ati_remote)
0722 {
0723 struct input_dev *idev = ati_remote->idev;
0724 int i;
0725
0726 idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
0727 idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
0728 BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_SIDE) | BIT_MASK(BTN_EXTRA);
0729 idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
0730 for (i = 0; ati_remote_tbl[i].kind != KIND_END; i++)
0731 if (ati_remote_tbl[i].kind == KIND_LITERAL ||
0732 ati_remote_tbl[i].kind == KIND_FILTERED)
0733 __set_bit(ati_remote_tbl[i].code, idev->keybit);
0734
0735 input_set_drvdata(idev, ati_remote);
0736
0737 idev->open = ati_remote_input_open;
0738 idev->close = ati_remote_input_close;
0739
0740 idev->name = ati_remote->mouse_name;
0741 idev->phys = ati_remote->mouse_phys;
0742
0743 usb_to_input_id(ati_remote->udev, &idev->id);
0744 idev->dev.parent = &ati_remote->interface->dev;
0745 }
0746
0747 static void ati_remote_rc_init(struct ati_remote *ati_remote)
0748 {
0749 struct rc_dev *rdev = ati_remote->rdev;
0750
0751 rdev->priv = ati_remote;
0752 rdev->allowed_protocols = RC_PROTO_BIT_OTHER;
0753 rdev->driver_name = "ati_remote";
0754
0755 rdev->open = ati_remote_rc_open;
0756 rdev->close = ati_remote_rc_close;
0757
0758 rdev->device_name = ati_remote->rc_name;
0759 rdev->input_phys = ati_remote->rc_phys;
0760
0761 usb_to_input_id(ati_remote->udev, &rdev->input_id);
0762 rdev->dev.parent = &ati_remote->interface->dev;
0763 }
0764
0765 static int ati_remote_initialize(struct ati_remote *ati_remote)
0766 {
0767 struct usb_device *udev = ati_remote->udev;
0768 int pipe, maxp;
0769
0770 init_waitqueue_head(&ati_remote->wait);
0771
0772
0773 pipe = usb_rcvintpipe(udev, ati_remote->endpoint_in->bEndpointAddress);
0774 maxp = usb_maxpacket(udev, pipe);
0775 maxp = (maxp > DATA_BUFSIZE) ? DATA_BUFSIZE : maxp;
0776
0777 usb_fill_int_urb(ati_remote->irq_urb, udev, pipe, ati_remote->inbuf,
0778 maxp, ati_remote_irq_in, ati_remote,
0779 ati_remote->endpoint_in->bInterval);
0780 ati_remote->irq_urb->transfer_dma = ati_remote->inbuf_dma;
0781 ati_remote->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
0782
0783
0784 pipe = usb_sndintpipe(udev, ati_remote->endpoint_out->bEndpointAddress);
0785 maxp = usb_maxpacket(udev, pipe);
0786 maxp = (maxp > DATA_BUFSIZE) ? DATA_BUFSIZE : maxp;
0787
0788 usb_fill_int_urb(ati_remote->out_urb, udev, pipe, ati_remote->outbuf,
0789 maxp, ati_remote_irq_out, ati_remote,
0790 ati_remote->endpoint_out->bInterval);
0791 ati_remote->out_urb->transfer_dma = ati_remote->outbuf_dma;
0792 ati_remote->out_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
0793
0794
0795 if ((ati_remote_sendpacket(ati_remote, 0x8004, init1)) ||
0796 (ati_remote_sendpacket(ati_remote, 0x8007, init2))) {
0797 dev_err(&ati_remote->interface->dev,
0798 "Initializing ati_remote hardware failed.\n");
0799 return -EIO;
0800 }
0801
0802 return 0;
0803 }
0804
0805
0806
0807
0808 static int ati_remote_probe(struct usb_interface *interface,
0809 const struct usb_device_id *id)
0810 {
0811 struct usb_device *udev = interface_to_usbdev(interface);
0812 struct usb_host_interface *iface_host = interface->cur_altsetting;
0813 struct usb_endpoint_descriptor *endpoint_in, *endpoint_out;
0814 struct ati_receiver_type *type = (struct ati_receiver_type *)id->driver_info;
0815 struct ati_remote *ati_remote;
0816 struct input_dev *input_dev;
0817 struct device *device = &interface->dev;
0818 struct rc_dev *rc_dev;
0819 int err = -ENOMEM;
0820
0821 if (iface_host->desc.bNumEndpoints != 2) {
0822 dev_err(device, "%s: Unexpected desc.bNumEndpoints\n", __func__);
0823 return -ENODEV;
0824 }
0825
0826 endpoint_in = &iface_host->endpoint[0].desc;
0827 endpoint_out = &iface_host->endpoint[1].desc;
0828
0829 if (!usb_endpoint_is_int_in(endpoint_in)) {
0830 dev_err(device, "%s: Unexpected endpoint_in\n", __func__);
0831 return -ENODEV;
0832 }
0833 if (le16_to_cpu(endpoint_in->wMaxPacketSize) == 0) {
0834 dev_err(device, "%s: endpoint_in message size==0?\n", __func__);
0835 return -ENODEV;
0836 }
0837 if (!usb_endpoint_is_int_out(endpoint_out)) {
0838 dev_err(device, "%s: Unexpected endpoint_out\n", __func__);
0839 return -ENODEV;
0840 }
0841
0842 ati_remote = kzalloc(sizeof (struct ati_remote), GFP_KERNEL);
0843 rc_dev = rc_allocate_device(RC_DRIVER_SCANCODE);
0844 if (!ati_remote || !rc_dev)
0845 goto exit_free_dev_rdev;
0846
0847
0848 if (ati_remote_alloc_buffers(udev, ati_remote))
0849 goto exit_free_buffers;
0850
0851 ati_remote->endpoint_in = endpoint_in;
0852 ati_remote->endpoint_out = endpoint_out;
0853 ati_remote->udev = udev;
0854 ati_remote->rdev = rc_dev;
0855 ati_remote->interface = interface;
0856
0857 usb_make_path(udev, ati_remote->rc_phys, sizeof(ati_remote->rc_phys));
0858 strscpy(ati_remote->mouse_phys, ati_remote->rc_phys,
0859 sizeof(ati_remote->mouse_phys));
0860
0861 strlcat(ati_remote->rc_phys, "/input0", sizeof(ati_remote->rc_phys));
0862 strlcat(ati_remote->mouse_phys, "/input1", sizeof(ati_remote->mouse_phys));
0863
0864 snprintf(ati_remote->rc_name, sizeof(ati_remote->rc_name), "%s%s%s",
0865 udev->manufacturer ?: "",
0866 udev->manufacturer && udev->product ? " " : "",
0867 udev->product ?: "");
0868
0869 if (!strlen(ati_remote->rc_name))
0870 snprintf(ati_remote->rc_name, sizeof(ati_remote->rc_name),
0871 DRIVER_DESC "(%04x,%04x)",
0872 le16_to_cpu(ati_remote->udev->descriptor.idVendor),
0873 le16_to_cpu(ati_remote->udev->descriptor.idProduct));
0874
0875 snprintf(ati_remote->mouse_name, sizeof(ati_remote->mouse_name),
0876 "%s mouse", ati_remote->rc_name);
0877
0878 rc_dev->map_name = RC_MAP_ATI_X10;
0879
0880
0881 if (type) {
0882 if (type->default_keymap)
0883 rc_dev->map_name = type->default_keymap;
0884 else if (type->get_default_keymap)
0885 rc_dev->map_name = type->get_default_keymap(interface);
0886 }
0887
0888 ati_remote_rc_init(ati_remote);
0889 mutex_init(&ati_remote->open_mutex);
0890
0891
0892 err = ati_remote_initialize(ati_remote);
0893 if (err)
0894 goto exit_kill_urbs;
0895
0896
0897 err = rc_register_device(ati_remote->rdev);
0898 if (err)
0899 goto exit_kill_urbs;
0900
0901
0902 if (mouse) {
0903 input_dev = input_allocate_device();
0904 if (!input_dev) {
0905 err = -ENOMEM;
0906 goto exit_unregister_device;
0907 }
0908
0909 ati_remote->idev = input_dev;
0910 ati_remote_input_init(ati_remote);
0911 err = input_register_device(input_dev);
0912
0913 if (err)
0914 goto exit_free_input_device;
0915 }
0916
0917 usb_set_intfdata(interface, ati_remote);
0918 return 0;
0919
0920 exit_free_input_device:
0921 input_free_device(input_dev);
0922 exit_unregister_device:
0923 rc_unregister_device(rc_dev);
0924 rc_dev = NULL;
0925 exit_kill_urbs:
0926 usb_kill_urb(ati_remote->irq_urb);
0927 usb_kill_urb(ati_remote->out_urb);
0928 exit_free_buffers:
0929 ati_remote_free_buffers(ati_remote);
0930 exit_free_dev_rdev:
0931 rc_free_device(rc_dev);
0932 kfree(ati_remote);
0933 return err;
0934 }
0935
0936
0937
0938
0939 static void ati_remote_disconnect(struct usb_interface *interface)
0940 {
0941 struct ati_remote *ati_remote;
0942
0943 ati_remote = usb_get_intfdata(interface);
0944 usb_set_intfdata(interface, NULL);
0945 if (!ati_remote) {
0946 dev_warn(&interface->dev, "%s - null device?\n", __func__);
0947 return;
0948 }
0949
0950 usb_kill_urb(ati_remote->irq_urb);
0951 usb_kill_urb(ati_remote->out_urb);
0952 if (ati_remote->idev)
0953 input_unregister_device(ati_remote->idev);
0954 rc_unregister_device(ati_remote->rdev);
0955 ati_remote_free_buffers(ati_remote);
0956 kfree(ati_remote);
0957 }
0958
0959
0960 static struct usb_driver ati_remote_driver = {
0961 .name = "ati_remote",
0962 .probe = ati_remote_probe,
0963 .disconnect = ati_remote_disconnect,
0964 .id_table = ati_remote_table,
0965 };
0966
0967 module_usb_driver(ati_remote_driver);
0968
0969 MODULE_AUTHOR(DRIVER_AUTHOR);
0970 MODULE_DESCRIPTION(DRIVER_DESC);
0971 MODULE_LICENSE("GPL");