123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986 |
- #include <linux/kernel.h>
- #include <linux/errno.h>
- #include <linux/init.h>
- #include <linux/slab.h>
- #include <linux/module.h>
- #include <linux/mutex.h>
- #include <linux/usb/input.h>
- #include <linux/wait.h>
- #include <linux/jiffies.h>
- #include <media/rc-core.h>
- #define ATI_REMOTE_VENDOR_ID 0x0bc7
- #define LOLA_REMOTE_PRODUCT_ID 0x0002
- #define LOLA2_REMOTE_PRODUCT_ID 0x0003
- #define ATI_REMOTE_PRODUCT_ID 0x0004
- #define NVIDIA_REMOTE_PRODUCT_ID 0x0005
- #define MEDION_REMOTE_PRODUCT_ID 0x0006
- #define FIREFLY_REMOTE_PRODUCT_ID 0x0008
- #define DRIVER_VERSION "2.2.1"
- #define DRIVER_AUTHOR "Torrey Hoffman <thoffman@arnor.net>"
- #define DRIVER_DESC "ATI/X10 RF USB Remote Control"
- #define NAME_BUFSIZE 80
- #define DATA_BUFSIZE 63
- #define FILTER_TIME 60
- #define REPEAT_DELAY 500
- static unsigned long channel_mask;
- module_param(channel_mask, ulong, 0644);
- MODULE_PARM_DESC(channel_mask, "Bitmask of remote control channels to ignore");
- static int debug;
- module_param(debug, int, 0644);
- MODULE_PARM_DESC(debug, "Enable extra debug messages and information");
- static int repeat_filter = FILTER_TIME;
- module_param(repeat_filter, int, 0644);
- MODULE_PARM_DESC(repeat_filter, "Repeat filter time, default = 60 msec");
- static int repeat_delay = REPEAT_DELAY;
- module_param(repeat_delay, int, 0644);
- MODULE_PARM_DESC(repeat_delay, "Delay before sending repeats, default = 500 msec");
- static bool mouse = true;
- module_param(mouse, bool, 0444);
- MODULE_PARM_DESC(mouse, "Enable mouse device, default = yes");
- #define dbginfo(dev, format, arg...) \
- do { if (debug) dev_info(dev , format , ## arg); } while (0)
- #undef err
- #define err(format, arg...) printk(KERN_ERR format , ## arg)
- struct ati_receiver_type {
-
- const char *default_keymap;
- const char *(*get_default_keymap)(struct usb_interface *interface);
- };
- static const char *get_medion_keymap(struct usb_interface *interface)
- {
- struct usb_device *udev = interface_to_usbdev(interface);
-
- if (udev->manufacturer && udev->product) {
- if (udev->actconfig->desc.bmAttributes & USB_CONFIG_ATT_WAKEUP) {
- if (!strcmp(udev->manufacturer, "X10 Wireless Technology Inc")
- && !strcmp(udev->product, "USB Receiver"))
- return RC_MAP_MEDION_X10_DIGITAINER;
- if (!strcmp(udev->manufacturer, "X10 WTI")
- && !strcmp(udev->product, "RF receiver"))
- return RC_MAP_MEDION_X10_OR2X;
- } else {
- if (!strcmp(udev->manufacturer, "X10 Wireless Technology Inc")
- && !strcmp(udev->product, "USB Receiver"))
- return RC_MAP_MEDION_X10;
- }
- }
- dev_info(&interface->dev,
- "Unknown Medion X10 receiver, using default ati_remote Medion keymap\n");
- return RC_MAP_MEDION_X10;
- }
- static const struct ati_receiver_type type_ati = {
- .default_keymap = RC_MAP_ATI_X10
- };
- static const struct ati_receiver_type type_medion = {
- .get_default_keymap = get_medion_keymap
- };
- static const struct ati_receiver_type type_firefly = {
- .default_keymap = RC_MAP_SNAPSTREAM_FIREFLY
- };
- static struct usb_device_id ati_remote_table[] = {
- {
- USB_DEVICE(ATI_REMOTE_VENDOR_ID, LOLA_REMOTE_PRODUCT_ID),
- .driver_info = (unsigned long)&type_ati
- },
- {
- USB_DEVICE(ATI_REMOTE_VENDOR_ID, LOLA2_REMOTE_PRODUCT_ID),
- .driver_info = (unsigned long)&type_ati
- },
- {
- USB_DEVICE(ATI_REMOTE_VENDOR_ID, ATI_REMOTE_PRODUCT_ID),
- .driver_info = (unsigned long)&type_ati
- },
- {
- USB_DEVICE(ATI_REMOTE_VENDOR_ID, NVIDIA_REMOTE_PRODUCT_ID),
- .driver_info = (unsigned long)&type_ati
- },
- {
- USB_DEVICE(ATI_REMOTE_VENDOR_ID, MEDION_REMOTE_PRODUCT_ID),
- .driver_info = (unsigned long)&type_medion
- },
- {
- USB_DEVICE(ATI_REMOTE_VENDOR_ID, FIREFLY_REMOTE_PRODUCT_ID),
- .driver_info = (unsigned long)&type_firefly
- },
- {}
- };
- MODULE_DEVICE_TABLE(usb, ati_remote_table);
- #define HI(a) ((unsigned char)((a) >> 8))
- #define LO(a) ((unsigned char)((a) & 0xff))
- #define SEND_FLAG_IN_PROGRESS 1
- #define SEND_FLAG_COMPLETE 2
- static char init1[] = { 0x01, 0x00, 0x20, 0x14 };
- static char init2[] = { 0x01, 0x00, 0x20, 0x14, 0x20, 0x20, 0x20 };
- struct ati_remote {
- struct input_dev *idev;
- struct rc_dev *rdev;
- struct usb_device *udev;
- struct usb_interface *interface;
- struct urb *irq_urb;
- struct urb *out_urb;
- struct usb_endpoint_descriptor *endpoint_in;
- struct usb_endpoint_descriptor *endpoint_out;
- unsigned char *inbuf;
- unsigned char *outbuf;
- dma_addr_t inbuf_dma;
- dma_addr_t outbuf_dma;
- unsigned char old_data;
- unsigned long old_jiffies;
- unsigned long acc_jiffies;
- unsigned long first_jiffies;
- unsigned int repeat_count;
- char rc_name[NAME_BUFSIZE];
- char rc_phys[NAME_BUFSIZE];
- char mouse_name[NAME_BUFSIZE];
- char mouse_phys[NAME_BUFSIZE];
- wait_queue_head_t wait;
- int send_flags;
- int users;
- struct mutex open_mutex;
- };
- #define KIND_END 0
- #define KIND_LITERAL 1
- #define KIND_FILTERED 2
- #define KIND_ACCEL 3
- static const struct {
- unsigned char kind;
- unsigned char data;
- unsigned short code;
- } ati_remote_tbl[] = {
-
- {KIND_ACCEL, 0x70, 0xff00},
- {KIND_ACCEL, 0x71, 0x0100},
- {KIND_ACCEL, 0x72, 0x00ff},
- {KIND_ACCEL, 0x73, 0x0001},
-
- {KIND_ACCEL, 0x74, 0xffff},
- {KIND_ACCEL, 0x75, 0x01ff},
- {KIND_ACCEL, 0x77, 0xff01},
- {KIND_ACCEL, 0x76, 0x0101},
-
- {KIND_LITERAL, 0x78, BTN_LEFT},
- {KIND_LITERAL, 0x79, BTN_LEFT},
- {KIND_LITERAL, 0x7c, BTN_RIGHT},
- {KIND_LITERAL, 0x7d, BTN_RIGHT},
-
- {KIND_FILTERED, 0x7a, BTN_SIDE},
- {KIND_FILTERED, 0x7e, BTN_EXTRA},
-
- {KIND_END, 0x00, 0}
- };
- static void ati_remote_dump(struct device *dev, unsigned char *data,
- unsigned int len)
- {
- if (len == 1) {
- if (data[0] != (unsigned char)0xff && data[0] != 0x00)
- dev_warn(dev, "Weird byte 0x%02x\n", data[0]);
- } else if (len == 4)
- dev_warn(dev, "Weird key %*ph\n", 4, data);
- else
- dev_warn(dev, "Weird data, len=%d %*ph ...\n", len, 6, data);
- }
- static int ati_remote_open(struct ati_remote *ati_remote)
- {
- int err = 0;
- mutex_lock(&ati_remote->open_mutex);
- if (ati_remote->users++ != 0)
- goto out;
-
- ati_remote->irq_urb->dev = ati_remote->udev;
- if (usb_submit_urb(ati_remote->irq_urb, GFP_KERNEL)) {
- dev_err(&ati_remote->interface->dev,
- "%s: usb_submit_urb failed!\n", __func__);
- err = -EIO;
- }
- out: mutex_unlock(&ati_remote->open_mutex);
- return err;
- }
- static void ati_remote_close(struct ati_remote *ati_remote)
- {
- mutex_lock(&ati_remote->open_mutex);
- if (--ati_remote->users == 0)
- usb_kill_urb(ati_remote->irq_urb);
- mutex_unlock(&ati_remote->open_mutex);
- }
- static int ati_remote_input_open(struct input_dev *inputdev)
- {
- struct ati_remote *ati_remote = input_get_drvdata(inputdev);
- return ati_remote_open(ati_remote);
- }
- static void ati_remote_input_close(struct input_dev *inputdev)
- {
- struct ati_remote *ati_remote = input_get_drvdata(inputdev);
- ati_remote_close(ati_remote);
- }
- static int ati_remote_rc_open(struct rc_dev *rdev)
- {
- struct ati_remote *ati_remote = rdev->priv;
- return ati_remote_open(ati_remote);
- }
- static void ati_remote_rc_close(struct rc_dev *rdev)
- {
- struct ati_remote *ati_remote = rdev->priv;
- ati_remote_close(ati_remote);
- }
- static void ati_remote_irq_out(struct urb *urb)
- {
- struct ati_remote *ati_remote = urb->context;
- if (urb->status) {
- dev_dbg(&ati_remote->interface->dev, "%s: status %d\n",
- __func__, urb->status);
- return;
- }
- ati_remote->send_flags |= SEND_FLAG_COMPLETE;
- wmb();
- wake_up(&ati_remote->wait);
- }
- static int ati_remote_sendpacket(struct ati_remote *ati_remote, u16 cmd,
- unsigned char *data)
- {
- int retval = 0;
-
- memcpy(ati_remote->out_urb->transfer_buffer + 1, data, LO(cmd));
- ((char *) ati_remote->out_urb->transfer_buffer)[0] = HI(cmd);
- ati_remote->out_urb->transfer_buffer_length = LO(cmd) + 1;
- ati_remote->out_urb->dev = ati_remote->udev;
- ati_remote->send_flags = SEND_FLAG_IN_PROGRESS;
- retval = usb_submit_urb(ati_remote->out_urb, GFP_ATOMIC);
- if (retval) {
- dev_dbg(&ati_remote->interface->dev,
- "sendpacket: usb_submit_urb failed: %d\n", retval);
- return retval;
- }
- wait_event_timeout(ati_remote->wait,
- ((ati_remote->out_urb->status != -EINPROGRESS) ||
- (ati_remote->send_flags & SEND_FLAG_COMPLETE)),
- HZ);
- usb_kill_urb(ati_remote->out_urb);
- return retval;
- }
- struct accel_times {
- const char value;
- unsigned int msecs;
- };
- static const struct accel_times accel[] = {
- { 1, 125 },
- { 2, 250 },
- { 4, 500 },
- { 6, 1000 },
- { 9, 1500 },
- { 13, 2000 },
- { 20, 0 },
- };
- static int ati_remote_compute_accel(struct ati_remote *ati_remote)
- {
- unsigned long now = jiffies, reset_time;
- int i;
- reset_time = msecs_to_jiffies(250);
- if (time_after(now, ati_remote->old_jiffies + reset_time)) {
- ati_remote->acc_jiffies = now;
- return 1;
- }
- for (i = 0; i < ARRAY_SIZE(accel) - 1; i++) {
- unsigned long timeout = msecs_to_jiffies(accel[i].msecs);
- if (time_before(now, ati_remote->acc_jiffies + timeout))
- return accel[i].value;
- }
- return accel[i].value;
- }
- static void ati_remote_input_report(struct urb *urb)
- {
- struct ati_remote *ati_remote = urb->context;
- unsigned char *data= ati_remote->inbuf;
- struct input_dev *dev = ati_remote->idev;
- int index = -1;
- int remote_num;
- unsigned char scancode;
- u32 wheel_keycode = KEY_RESERVED;
- int i;
-
-
- if ( urb->actual_length != 4 || data[0] != 0x14 ||
- data[1] != (unsigned char)(data[2] + data[3] + 0xD5) ||
- (data[3] & 0x0f) != 0x00) {
- ati_remote_dump(&urb->dev->dev, data, urb->actual_length);
- return;
- }
- if (data[1] != ((data[2] + data[3] + 0xd5) & 0xff)) {
- dbginfo(&ati_remote->interface->dev,
- "wrong checksum in input: %*ph\n", 4, data);
- return;
- }
-
-
- remote_num = (data[3] >> 4) & 0x0f;
- if (channel_mask & (1 << (remote_num + 1))) {
- dbginfo(&ati_remote->interface->dev,
- "Masked input from channel 0x%02x: data %02x, "
- "mask= 0x%02lx\n",
- remote_num, data[2], channel_mask);
- return;
- }
-
- scancode = data[2] & 0x7f;
- dbginfo(&ati_remote->interface->dev,
- "channel 0x%02x; key data %02x, scancode %02x\n",
- remote_num, data[2], scancode);
- if (scancode >= 0x70) {
-
- wheel_keycode = rc_g_keycode_from_table(ati_remote->rdev,
- scancode & 0x78);
- if (wheel_keycode == KEY_RESERVED) {
-
-
- for (i = 0; ati_remote_tbl[i].kind != KIND_END; i++) {
- if (scancode == ati_remote_tbl[i].data) {
- index = i;
- break;
- }
- }
- }
- }
- if (index >= 0 && ati_remote_tbl[index].kind == KIND_LITERAL) {
-
- input_event(dev, EV_KEY, ati_remote_tbl[index].code,
- !(data[2] & 1));
- ati_remote->old_jiffies = jiffies;
- } else if (index < 0 || ati_remote_tbl[index].kind == KIND_FILTERED) {
- unsigned long now = jiffies;
-
- if (ati_remote->old_data == data[2] &&
- time_before(now, ati_remote->old_jiffies +
- msecs_to_jiffies(repeat_filter))) {
- ati_remote->repeat_count++;
- } else {
- ati_remote->repeat_count = 0;
- ati_remote->first_jiffies = now;
- }
- ati_remote->old_jiffies = now;
-
- if (ati_remote->repeat_count > 0 &&
- (ati_remote->repeat_count < 5 ||
- time_before(now, ati_remote->first_jiffies +
- msecs_to_jiffies(repeat_delay))))
- return;
- if (index >= 0) {
- input_event(dev, EV_KEY, ati_remote_tbl[index].code, 1);
- input_event(dev, EV_KEY, ati_remote_tbl[index].code, 0);
- } else {
-
- int count = 1;
- if (wheel_keycode != KEY_RESERVED) {
-
- count = (scancode & 0x07) + 1;
- scancode &= 0x78;
- }
- while (count--) {
-
- rc_keydown_notimeout(ati_remote->rdev, RC_TYPE_OTHER,
- scancode, data[2]);
- rc_keyup(ati_remote->rdev);
- }
- goto nosync;
- }
- } else if (ati_remote_tbl[index].kind == KIND_ACCEL) {
- signed char dx = ati_remote_tbl[index].code >> 8;
- signed char dy = ati_remote_tbl[index].code & 255;
-
- int acc = ati_remote_compute_accel(ati_remote);
- if (dx)
- input_report_rel(dev, REL_X, dx * acc);
- if (dy)
- input_report_rel(dev, REL_Y, dy * acc);
- ati_remote->old_jiffies = jiffies;
- } else {
- dev_dbg(&ati_remote->interface->dev, "ati_remote kind=%d\n",
- ati_remote_tbl[index].kind);
- return;
- }
- input_sync(dev);
- nosync:
- ati_remote->old_data = data[2];
- }
- static void ati_remote_irq_in(struct urb *urb)
- {
- struct ati_remote *ati_remote = urb->context;
- int retval;
- switch (urb->status) {
- case 0:
- ati_remote_input_report(urb);
- break;
- case -ECONNRESET:
- case -ENOENT:
- case -ESHUTDOWN:
- dev_dbg(&ati_remote->interface->dev,
- "%s: urb error status, unlink?\n",
- __func__);
- return;
- default:
- dev_dbg(&ati_remote->interface->dev,
- "%s: Nonzero urb status %d\n",
- __func__, urb->status);
- }
- retval = usb_submit_urb(urb, GFP_ATOMIC);
- if (retval)
- dev_err(&ati_remote->interface->dev,
- "%s: usb_submit_urb()=%d\n",
- __func__, retval);
- }
- static int ati_remote_alloc_buffers(struct usb_device *udev,
- struct ati_remote *ati_remote)
- {
- ati_remote->inbuf = usb_alloc_coherent(udev, DATA_BUFSIZE, GFP_ATOMIC,
- &ati_remote->inbuf_dma);
- if (!ati_remote->inbuf)
- return -1;
- ati_remote->outbuf = usb_alloc_coherent(udev, DATA_BUFSIZE, GFP_ATOMIC,
- &ati_remote->outbuf_dma);
- if (!ati_remote->outbuf)
- return -1;
- ati_remote->irq_urb = usb_alloc_urb(0, GFP_KERNEL);
- if (!ati_remote->irq_urb)
- return -1;
- ati_remote->out_urb = usb_alloc_urb(0, GFP_KERNEL);
- if (!ati_remote->out_urb)
- return -1;
- return 0;
- }
- static void ati_remote_free_buffers(struct ati_remote *ati_remote)
- {
- usb_free_urb(ati_remote->irq_urb);
- usb_free_urb(ati_remote->out_urb);
- usb_free_coherent(ati_remote->udev, DATA_BUFSIZE,
- ati_remote->inbuf, ati_remote->inbuf_dma);
- usb_free_coherent(ati_remote->udev, DATA_BUFSIZE,
- ati_remote->outbuf, ati_remote->outbuf_dma);
- }
- static void ati_remote_input_init(struct ati_remote *ati_remote)
- {
- struct input_dev *idev = ati_remote->idev;
- int i;
- idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
- idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
- BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_SIDE) | BIT_MASK(BTN_EXTRA);
- idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
- for (i = 0; ati_remote_tbl[i].kind != KIND_END; i++)
- if (ati_remote_tbl[i].kind == KIND_LITERAL ||
- ati_remote_tbl[i].kind == KIND_FILTERED)
- __set_bit(ati_remote_tbl[i].code, idev->keybit);
- input_set_drvdata(idev, ati_remote);
- idev->open = ati_remote_input_open;
- idev->close = ati_remote_input_close;
- idev->name = ati_remote->mouse_name;
- idev->phys = ati_remote->mouse_phys;
- usb_to_input_id(ati_remote->udev, &idev->id);
- idev->dev.parent = &ati_remote->interface->dev;
- }
- static void ati_remote_rc_init(struct ati_remote *ati_remote)
- {
- struct rc_dev *rdev = ati_remote->rdev;
- rdev->priv = ati_remote;
- rdev->driver_type = RC_DRIVER_SCANCODE;
- rdev->allowed_protocols = RC_BIT_OTHER;
- rdev->driver_name = "ati_remote";
- rdev->open = ati_remote_rc_open;
- rdev->close = ati_remote_rc_close;
- rdev->input_name = ati_remote->rc_name;
- rdev->input_phys = ati_remote->rc_phys;
- usb_to_input_id(ati_remote->udev, &rdev->input_id);
- rdev->dev.parent = &ati_remote->interface->dev;
- }
- static int ati_remote_initialize(struct ati_remote *ati_remote)
- {
- struct usb_device *udev = ati_remote->udev;
- int pipe, maxp;
- init_waitqueue_head(&ati_remote->wait);
-
- pipe = usb_rcvintpipe(udev, ati_remote->endpoint_in->bEndpointAddress);
- maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
- maxp = (maxp > DATA_BUFSIZE) ? DATA_BUFSIZE : maxp;
- usb_fill_int_urb(ati_remote->irq_urb, udev, pipe, ati_remote->inbuf,
- maxp, ati_remote_irq_in, ati_remote,
- ati_remote->endpoint_in->bInterval);
- ati_remote->irq_urb->transfer_dma = ati_remote->inbuf_dma;
- ati_remote->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
-
- pipe = usb_sndintpipe(udev, ati_remote->endpoint_out->bEndpointAddress);
- maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
- maxp = (maxp > DATA_BUFSIZE) ? DATA_BUFSIZE : maxp;
- usb_fill_int_urb(ati_remote->out_urb, udev, pipe, ati_remote->outbuf,
- maxp, ati_remote_irq_out, ati_remote,
- ati_remote->endpoint_out->bInterval);
- ati_remote->out_urb->transfer_dma = ati_remote->outbuf_dma;
- ati_remote->out_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
-
- if ((ati_remote_sendpacket(ati_remote, 0x8004, init1)) ||
- (ati_remote_sendpacket(ati_remote, 0x8007, init2))) {
- dev_err(&ati_remote->interface->dev,
- "Initializing ati_remote hardware failed.\n");
- return -EIO;
- }
- return 0;
- }
- static int ati_remote_probe(struct usb_interface *interface,
- const struct usb_device_id *id)
- {
- struct usb_device *udev = interface_to_usbdev(interface);
- struct usb_host_interface *iface_host = interface->cur_altsetting;
- struct usb_endpoint_descriptor *endpoint_in, *endpoint_out;
- struct ati_receiver_type *type = (struct ati_receiver_type *)id->driver_info;
- struct ati_remote *ati_remote;
- struct input_dev *input_dev;
- struct rc_dev *rc_dev;
- int err = -ENOMEM;
- if (iface_host->desc.bNumEndpoints != 2) {
- err("%s: Unexpected desc.bNumEndpoints\n", __func__);
- return -ENODEV;
- }
- endpoint_in = &iface_host->endpoint[0].desc;
- endpoint_out = &iface_host->endpoint[1].desc;
- if (!usb_endpoint_is_int_in(endpoint_in)) {
- err("%s: Unexpected endpoint_in\n", __func__);
- return -ENODEV;
- }
- if (le16_to_cpu(endpoint_in->wMaxPacketSize) == 0) {
- err("%s: endpoint_in message size==0? \n", __func__);
- return -ENODEV;
- }
- ati_remote = kzalloc(sizeof (struct ati_remote), GFP_KERNEL);
- rc_dev = rc_allocate_device();
- if (!ati_remote || !rc_dev)
- goto exit_free_dev_rdev;
-
- if (ati_remote_alloc_buffers(udev, ati_remote))
- goto exit_free_buffers;
- ati_remote->endpoint_in = endpoint_in;
- ati_remote->endpoint_out = endpoint_out;
- ati_remote->udev = udev;
- ati_remote->rdev = rc_dev;
- ati_remote->interface = interface;
- usb_make_path(udev, ati_remote->rc_phys, sizeof(ati_remote->rc_phys));
- strlcpy(ati_remote->mouse_phys, ati_remote->rc_phys,
- sizeof(ati_remote->mouse_phys));
- strlcat(ati_remote->rc_phys, "/input0", sizeof(ati_remote->rc_phys));
- strlcat(ati_remote->mouse_phys, "/input1", sizeof(ati_remote->mouse_phys));
- snprintf(ati_remote->rc_name, sizeof(ati_remote->rc_name), "%s%s%s",
- udev->manufacturer ?: "",
- udev->manufacturer && udev->product ? " " : "",
- udev->product ?: "");
- if (!strlen(ati_remote->rc_name))
- snprintf(ati_remote->rc_name, sizeof(ati_remote->rc_name),
- DRIVER_DESC "(%04x,%04x)",
- le16_to_cpu(ati_remote->udev->descriptor.idVendor),
- le16_to_cpu(ati_remote->udev->descriptor.idProduct));
- snprintf(ati_remote->mouse_name, sizeof(ati_remote->mouse_name),
- "%s mouse", ati_remote->rc_name);
- rc_dev->map_name = RC_MAP_ATI_X10;
-
- if (type) {
- if (type->default_keymap)
- rc_dev->map_name = type->default_keymap;
- else if (type->get_default_keymap)
- rc_dev->map_name = type->get_default_keymap(interface);
- }
- ati_remote_rc_init(ati_remote);
- mutex_init(&ati_remote->open_mutex);
-
- err = ati_remote_initialize(ati_remote);
- if (err)
- goto exit_kill_urbs;
-
- err = rc_register_device(ati_remote->rdev);
- if (err)
- goto exit_kill_urbs;
-
- ati_remote->rdev->input_dev->rep[REP_DELAY] = repeat_delay;
-
- if (mouse) {
- input_dev = input_allocate_device();
- if (!input_dev) {
- err = -ENOMEM;
- goto exit_unregister_device;
- }
- ati_remote->idev = input_dev;
- ati_remote_input_init(ati_remote);
- err = input_register_device(input_dev);
- if (err)
- goto exit_free_input_device;
- }
- usb_set_intfdata(interface, ati_remote);
- return 0;
- exit_free_input_device:
- input_free_device(input_dev);
- exit_unregister_device:
- rc_unregister_device(rc_dev);
- rc_dev = NULL;
- exit_kill_urbs:
- usb_kill_urb(ati_remote->irq_urb);
- usb_kill_urb(ati_remote->out_urb);
- exit_free_buffers:
- ati_remote_free_buffers(ati_remote);
- exit_free_dev_rdev:
- rc_free_device(rc_dev);
- kfree(ati_remote);
- return err;
- }
- static void ati_remote_disconnect(struct usb_interface *interface)
- {
- struct ati_remote *ati_remote;
- ati_remote = usb_get_intfdata(interface);
- usb_set_intfdata(interface, NULL);
- if (!ati_remote) {
- dev_warn(&interface->dev, "%s - null device?\n", __func__);
- return;
- }
- usb_kill_urb(ati_remote->irq_urb);
- usb_kill_urb(ati_remote->out_urb);
- if (ati_remote->idev)
- input_unregister_device(ati_remote->idev);
- rc_unregister_device(ati_remote->rdev);
- ati_remote_free_buffers(ati_remote);
- kfree(ati_remote);
- }
- static struct usb_driver ati_remote_driver = {
- .name = "ati_remote",
- .probe = ati_remote_probe,
- .disconnect = ati_remote_disconnect,
- .id_table = ati_remote_table,
- };
- module_usb_driver(ati_remote_driver);
- MODULE_AUTHOR(DRIVER_AUTHOR);
- MODULE_DESCRIPTION(DRIVER_DESC);
- MODULE_LICENSE("GPL");
|