89 #include <linux/kernel.h>
90 #include <linux/errno.h>
92 #include <linux/slab.h>
93 #include <linux/module.h>
96 #include <linux/wait.h>
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
112 #define DRIVER_VERSION "2.2.1"
114 #define DRIVER_DESC "ATI/X10 RF USB Remote Control"
116 #define NAME_BUFSIZE 80
117 #define DATA_BUFSIZE 63
127 #define FILTER_TIME 60
128 #define REPEAT_DELAY 500
130 static unsigned long channel_mask;
132 MODULE_PARM_DESC(channel_mask,
"Bitmask of remote control channels to ignore");
144 MODULE_PARM_DESC(repeat_delay,
"Delay before sending repeats, default = 500 msec");
146 static bool mouse =
true;
150 #define dbginfo(dev, format, arg...) \
151 do { if (debug) dev_info(dev , format , ## arg); } while (0)
153 #define err(format, arg...) printk(KERN_ERR format , ## arg)
163 struct usb_device *
udev = interface_to_usbdev(interface);
171 if (udev->manufacturer && udev->product) {
174 if (!
strcmp(udev->manufacturer,
"X10 Wireless Technology Inc")
175 && !
strcmp(udev->product,
"USB Receiver"))
178 if (!
strcmp(udev->manufacturer,
"X10 WTI")
179 && !
strcmp(udev->product,
"RF receiver"))
183 if (!
strcmp(udev->manufacturer,
"X10 Wireless Technology Inc")
184 && !
strcmp(udev->product,
"USB Receiver"))
190 "Unknown Medion X10 receiver, using default ati_remote Medion keymap\n");
199 .get_default_keymap = get_medion_keymap
208 .driver_info = (
unsigned long)&type_ati
212 .driver_info = (
unsigned long)&type_ati
216 .driver_info = (
unsigned long)&type_ati
220 .driver_info = (
unsigned long)&type_ati
224 .driver_info = (
unsigned long)&type_medion
228 .driver_info = (
unsigned long)&type_firefly
236 #define HI(a) ((unsigned char)((a) >> 8))
237 #define LO(a) ((unsigned char)((a) & 0xff))
239 #define SEND_FLAG_IN_PROGRESS 1
240 #define SEND_FLAG_COMPLETE 2
243 static char init1[] = { 0x01, 0x00, 0x20, 0x14 };
244 static char init2[] = { 0x01, 0x00, 0x20, 0x14, 0x20, 0x20, 0x20 };
282 #define KIND_LITERAL 1
283 #define KIND_FILTERED 2
291 static const struct {
297 } ati_remote_tbl[] = {
327 static void ati_remote_dump(
struct device *
dev,
unsigned char *
data,
331 if (data[0] != (
unsigned char)0xff && data[0] != 0x00)
332 dev_warn(dev,
"Weird byte 0x%02x\n", data[0]);
334 dev_warn(dev,
"Weird key %*ph\n", 4, data);
336 dev_warn(dev,
"Weird data, len=%d %*ph ...\n", len, 6, data);
348 if (ati_remote->
users++ != 0)
355 "%s: usb_submit_urb failed!\n", __func__);
366 static void ati_remote_close(
struct ati_remote *ati_remote)
369 if (--ati_remote->
users == 0)
374 static int ati_remote_input_open(
struct input_dev *inputdev)
376 struct ati_remote *ati_remote = input_get_drvdata(inputdev);
377 return ati_remote_open(ati_remote);
380 static void ati_remote_input_close(
struct input_dev *inputdev)
382 struct ati_remote *ati_remote = input_get_drvdata(inputdev);
383 ati_remote_close(ati_remote);
386 static int ati_remote_rc_open(
struct rc_dev *
rdev)
388 struct ati_remote *ati_remote = rdev->
priv;
389 return ati_remote_open(ati_remote);
392 static void ati_remote_rc_close(
struct rc_dev *
rdev)
394 struct ati_remote *ati_remote = rdev->
priv;
395 ati_remote_close(ati_remote);
401 static void ati_remote_irq_out(
struct urb *
urb)
403 struct ati_remote *ati_remote = urb->context;
407 __func__, urb->status);
421 static int ati_remote_sendpacket(
struct ati_remote *ati_remote,
u16 cmd,
428 ((
char *) ati_remote->
out_urb->transfer_buffer)[0] =
HI(cmd);
430 ati_remote->
out_urb->transfer_buffer_length =
LO(cmd) + 1;
437 "sendpacket: usb_submit_urb failed: %d\n", retval);
459 static int ati_remote_compute_accel(
struct ati_remote *ati_remote)
461 static const char accel[] = { 1, 2, 4, 6, 9, 13, 20 };
490 static void ati_remote_input_report(
struct urb *urb)
492 struct ati_remote *ati_remote = urb->context;
493 unsigned char *data= ati_remote->
inbuf;
494 struct input_dev *dev = ati_remote->
idev;
498 unsigned char scancode;
510 if ( (urb->actual_length != 4) || (data[0] != 0x14) ||
511 ((data[3] & 0x0f) != 0x00) ) {
512 ati_remote_dump(&urb->dev->dev, data, urb->actual_length);
516 if (data[1] != ((data[2] + data[3] + 0xd5) & 0xff)) {
518 "wrong checksum in input: %*ph\n", 4, data);
524 remote_num = (data[3] >> 4) & 0x0f;
525 if (channel_mask & (1 << (remote_num + 1))) {
527 "Masked input from channel 0x%02x: data %02x,%02x, "
529 remote_num, data[1], data[2], channel_mask);
537 scancode = data[2] & 0x7f;
540 "channel 0x%02x; key data %02x, scancode %02x\n",
541 remote_num, data[2], scancode);
543 if (scancode >= 0x70) {
559 for (i = 0; ati_remote_tbl[
i].kind !=
KIND_END; i++) {
560 if (scancode == ati_remote_tbl[i].data) {
570 ati_remote_tbl[index].
code,
571 ati_remote_tbl[index].
value);
582 if (ati_remote->
old_data == data[2] &&
615 count = (scancode & 0x07) + 1;
633 ati_remote_tbl[index].
code, 1);
636 ati_remote_tbl[index].
code, 0);
646 acc = ati_remote_compute_accel(ati_remote);
648 switch (ati_remote_tbl[index].
kind) {
651 ati_remote_tbl[index].
code,
652 ati_remote_tbl[index].
value * acc);
655 input_report_rel(dev,
REL_X, -acc);
656 input_report_rel(dev,
REL_Y, -acc);
659 input_report_rel(dev,
REL_X, acc);
660 input_report_rel(dev,
REL_Y, -acc);
663 input_report_rel(dev,
REL_X, -acc);
664 input_report_rel(dev,
REL_Y, acc);
667 input_report_rel(dev,
REL_X, acc);
668 input_report_rel(dev,
REL_Y, acc);
672 "ati_remote kind=%d\n",
673 ati_remote_tbl[index].kind);
685 static void ati_remote_irq_in(
struct urb *urb)
687 struct ati_remote *ati_remote = urb->context;
690 switch (urb->status) {
692 ati_remote_input_report(urb);
698 "%s: urb error status, unlink?\n",
703 "%s: Nonzero urb status %d\n",
704 __func__, urb->status);
710 "%s: usb_submit_urb()=%d\n",
717 static int ati_remote_alloc_buffers(
struct usb_device *
udev,
718 struct ati_remote *ati_remote)
722 if (!ati_remote->
inbuf)
744 static void ati_remote_free_buffers(
struct ati_remote *ati_remote)
756 static void ati_remote_input_init(
struct ati_remote *ati_remote)
758 struct input_dev *
idev = ati_remote->
idev;
765 for (i = 0; ati_remote_tbl[
i].kind !=
KIND_END; i++)
769 input_set_drvdata(idev, ati_remote);
771 idev->open = ati_remote_input_open;
772 idev->close = ati_remote_input_close;
777 usb_to_input_id(ati_remote->
udev, &idev->id);
778 idev->dev.parent = &ati_remote->
interface->dev;
781 static void ati_remote_rc_init(
struct ati_remote *ati_remote)
785 rdev->
priv = ati_remote;
790 rdev->
open = ati_remote_rc_open;
791 rdev->
close = ati_remote_rc_close;
800 static int ati_remote_initialize(
struct ati_remote *ati_remote)
802 struct usb_device *udev = ati_remote->
udev;
808 pipe = usb_rcvintpipe(udev, ati_remote->
endpoint_in->bEndpointAddress);
809 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
812 usb_fill_int_urb(ati_remote->
irq_urb, udev, pipe, ati_remote->
inbuf,
813 maxp, ati_remote_irq_in, ati_remote,
816 ati_remote->
irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
819 pipe = usb_sndintpipe(udev, ati_remote->
endpoint_out->bEndpointAddress);
820 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
823 usb_fill_int_urb(ati_remote->
out_urb, udev, pipe, ati_remote->
outbuf,
824 maxp, ati_remote_irq_out, ati_remote,
827 ati_remote->
out_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
830 if ((ati_remote_sendpacket(ati_remote, 0x8004, init1)) ||
831 (ati_remote_sendpacket(ati_remote, 0x8007, init2))) {
833 "Initializing ati_remote hardware failed.\n");
846 struct usb_device *udev = interface_to_usbdev(interface);
847 struct usb_host_interface *iface_host = interface->cur_altsetting;
850 struct ati_remote *ati_remote;
851 struct input_dev *input_dev;
855 if (iface_host->desc.bNumEndpoints != 2) {
856 err(
"%s: Unexpected desc.bNumEndpoints\n", __func__);
860 endpoint_in = &iface_host->endpoint[0].desc;
861 endpoint_out = &iface_host->endpoint[1].desc;
863 if (!usb_endpoint_is_int_in(endpoint_in)) {
864 err(
"%s: Unexpected endpoint_in\n", __func__);
868 err(
"%s: endpoint_in message size==0? \n", __func__);
872 ati_remote = kzalloc(
sizeof (
struct ati_remote),
GFP_KERNEL);
874 if (!ati_remote || !
rc_dev)
878 if (ati_remote_alloc_buffers(udev, ati_remote))
887 usb_make_path(udev, ati_remote->
rc_phys,
sizeof(ati_remote->
rc_phys));
894 if (udev->manufacturer)
900 "%s %s", ati_remote->
rc_name, udev->product);
909 "%s mouse", ati_remote->
rc_name);
921 ati_remote_rc_init(ati_remote);
925 err = ati_remote_initialize(ati_remote);
939 input_dev = input_allocate_device();
945 ati_remote->
idev = input_dev;
946 ati_remote_input_init(ati_remote);
947 err = input_register_device(input_dev);
953 usb_set_intfdata(interface, ati_remote);
956 fail5: input_free_device(input_dev);
961 fail2: ati_remote_free_buffers(ati_remote);
970 static void ati_remote_disconnect(
struct usb_interface *interface)
972 struct ati_remote *ati_remote;
974 ati_remote = usb_get_intfdata(interface);
975 usb_set_intfdata(interface,
NULL);
977 dev_warn(&interface->dev,
"%s - null device?\n", __func__);
983 if (ati_remote->
idev)
984 input_unregister_device(ati_remote->
idev);
986 ati_remote_free_buffers(ati_remote);
991 static struct usb_driver ati_remote_driver = {
992 .name =
"ati_remote",
993 .probe = ati_remote_probe,
994 .disconnect = ati_remote_disconnect,
995 .id_table = ati_remote_table,