1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * USB ATI Remote support
5 * Copyright (c) 2011, 2012 Anssi Hannula <anssi.hannula@iki.fi>
6 * Version 2.2.0 Copyright (c) 2004 Torrey Hoffman <thoffman@arnor.net>
7 * Version 2.1.1 Copyright (c) 2002 Vladimir Dergachev
9 * This 2.2.0 version is a rewrite / cleanup of the 2.1.1 driver, including
10 * porting to the 2.6 kernel interfaces, along with other modification
11 * to better match the style of the existing usb/input drivers. However, the
12 * protocol and hardware handling is essentially unchanged from 2.1.1.
14 * The 2.1.1 driver was derived from the usbati_remote and usbkbd drivers by
19 * Feb 2004: Torrey Hoffman <thoffman@arnor.net>
21 * Jun 2004: Torrey Hoffman <thoffman@arnor.net>
23 * Added key repeat support contributed by:
24 * Vincent Vanackere <vanackere@lif.univ-mrs.fr>
25 * Added support for the "Lola" remote contributed by:
26 * Seth Cohn <sethcohn@yahoo.com>
28 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
30 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
32 * Hardware & software notes
34 * These remote controls are distributed by ATI as part of their
35 * "All-In-Wonder" video card packages. The receiver self-identifies as a
36 * "USB Receiver" with manufacturer "X10 Wireless Technology Inc".
38 * The "Lola" remote is available from X10. See:
39 * http://www.x10.com/products/lola_sg1.htm
40 * The Lola is similar to the ATI remote but has no mouse support, and slightly
43 * It is possible to use multiple receivers and remotes on multiple computers
44 * simultaneously by configuring them to use specific channels.
46 * The RF protocol used by the remote supports 16 distinct channels, 1 to 16.
47 * Actually, it may even support more, at least in some revisions of the
50 * Each remote can be configured to transmit on one channel as follows:
51 * - Press and hold the "hand icon" button.
52 * - When the red LED starts to blink, let go of the "hand icon" button.
53 * - When it stops blinking, input the channel code as two digits, from 01
54 * to 16, and press the hand icon again.
56 * The timing can be a little tricky. Try loading the module with debug=1
57 * to have the kernel print out messages about the remote control number
58 * and mask. Note: debugging prints remote numbers as zero-based hexadecimal.
60 * The driver has a "channel_mask" parameter. This bitmask specifies which
61 * channels will be ignored by the module. To mask out channels, just add
62 * all the 2^channel_number values together.
64 * For instance, set channel_mask = 2^4 = 16 (binary 10000) to make ati_remote
65 * ignore signals coming from remote controls transmitting on channel 4, but
66 * accept all other channels.
68 * Or, set channel_mask = 65533, (0xFFFD), and all channels except 1 will be
71 * The default is 0 (respond to all channels). Bit 0 and bits 17-32 of this
72 * parameter are unused.
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>
87 * Module and Version Information, Module Parameters
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
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"
102 #define NAME_BUFSIZE 80 /* size of product name, path buffers */
103 #define DATA_BUFSIZE 63 /* size of URB data buffers */
106 * Duplicate event filtering time.
107 * Sequential, identical KIND_FILTERED inputs with less than
108 * FILTER_TIME milliseconds between them are considered as repeat
109 * events. The hardware generates 5 events for the first keypress
110 * and we have to take this into account for an accurate repeat
113 #define FILTER_TIME 60 /* msec */
114 #define REPEAT_DELAY 500 /* msec */
116 static unsigned long channel_mask
;
117 module_param(channel_mask
, ulong
, 0644);
118 MODULE_PARM_DESC(channel_mask
, "Bitmask of remote control channels to ignore");
121 module_param(debug
, int, 0644);
122 MODULE_PARM_DESC(debug
, "Enable extra debug messages and information");
124 static int repeat_filter
= FILTER_TIME
;
125 module_param(repeat_filter
, int, 0644);
126 MODULE_PARM_DESC(repeat_filter
, "Repeat filter time, default = 60 msec");
128 static int repeat_delay
= REPEAT_DELAY
;
129 module_param(repeat_delay
, int, 0644);
130 MODULE_PARM_DESC(repeat_delay
, "Delay before sending repeats, default = 500 msec");
132 static bool mouse
= true;
133 module_param(mouse
, bool, 0444);
134 MODULE_PARM_DESC(mouse
, "Enable mouse device, default = yes");
136 #define dbginfo(dev, format, arg...) \
137 do { if (debug) dev_info(dev , format , ## arg); } while (0)
139 struct ati_receiver_type
{
140 /* either default_keymap or get_default_keymap should be set */
141 const char *default_keymap
;
142 const char *(*get_default_keymap
)(struct usb_interface
*interface
);
145 static const char *get_medion_keymap(struct usb_interface
*interface
)
147 struct usb_device
*udev
= interface_to_usbdev(interface
);
150 * There are many different Medion remotes shipped with a receiver
151 * with the same usb id, but the receivers have subtle differences
152 * in the USB descriptors allowing us to detect them.
155 if (udev
->manufacturer
&& udev
->product
) {
156 if (udev
->actconfig
->desc
.bmAttributes
& USB_CONFIG_ATT_WAKEUP
) {
158 if (!strcmp(udev
->manufacturer
, "X10 Wireless Technology Inc")
159 && !strcmp(udev
->product
, "USB Receiver"))
160 return RC_MAP_MEDION_X10_DIGITAINER
;
162 if (!strcmp(udev
->manufacturer
, "X10 WTI")
163 && !strcmp(udev
->product
, "RF receiver"))
164 return RC_MAP_MEDION_X10_OR2X
;
167 if (!strcmp(udev
->manufacturer
, "X10 Wireless Technology Inc")
168 && !strcmp(udev
->product
, "USB Receiver"))
169 return RC_MAP_MEDION_X10
;
173 dev_info(&interface
->dev
,
174 "Unknown Medion X10 receiver, using default ati_remote Medion keymap\n");
176 return RC_MAP_MEDION_X10
;
179 static const struct ati_receiver_type type_ati
= {
180 .default_keymap
= RC_MAP_ATI_X10
182 static const struct ati_receiver_type type_medion
= {
183 .get_default_keymap
= get_medion_keymap
185 static const struct ati_receiver_type type_firefly
= {
186 .default_keymap
= RC_MAP_SNAPSTREAM_FIREFLY
189 static const struct usb_device_id ati_remote_table
[] = {
191 USB_DEVICE(ATI_REMOTE_VENDOR_ID
, LOLA_REMOTE_PRODUCT_ID
),
192 .driver_info
= (unsigned long)&type_ati
195 USB_DEVICE(ATI_REMOTE_VENDOR_ID
, LOLA2_REMOTE_PRODUCT_ID
),
196 .driver_info
= (unsigned long)&type_ati
199 USB_DEVICE(ATI_REMOTE_VENDOR_ID
, ATI_REMOTE_PRODUCT_ID
),
200 .driver_info
= (unsigned long)&type_ati
203 USB_DEVICE(ATI_REMOTE_VENDOR_ID
, NVIDIA_REMOTE_PRODUCT_ID
),
204 .driver_info
= (unsigned long)&type_ati
207 USB_DEVICE(ATI_REMOTE_VENDOR_ID
, MEDION_REMOTE_PRODUCT_ID
),
208 .driver_info
= (unsigned long)&type_medion
211 USB_DEVICE(ATI_REMOTE_VENDOR_ID
, FIREFLY_REMOTE_PRODUCT_ID
),
212 .driver_info
= (unsigned long)&type_firefly
214 {} /* Terminating entry */
217 MODULE_DEVICE_TABLE(usb
, ati_remote_table
);
219 /* Get hi and low bytes of a 16-bits int */
220 #define HI(a) ((unsigned char)((a) >> 8))
221 #define LO(a) ((unsigned char)((a) & 0xff))
223 #define SEND_FLAG_IN_PROGRESS 1
224 #define SEND_FLAG_COMPLETE 2
226 /* Device initialization strings */
227 static char init1
[] = { 0x01, 0x00, 0x20, 0x14 };
228 static char init2
[] = { 0x01, 0x00, 0x20, 0x14, 0x20, 0x20, 0x20 };
231 struct input_dev
*idev
;
233 struct usb_device
*udev
;
234 struct usb_interface
*interface
;
238 struct usb_endpoint_descriptor
*endpoint_in
;
239 struct usb_endpoint_descriptor
*endpoint_out
;
240 unsigned char *inbuf
;
241 unsigned char *outbuf
;
242 dma_addr_t inbuf_dma
;
243 dma_addr_t outbuf_dma
;
245 unsigned char old_data
; /* Detect duplicate events */
246 unsigned long old_jiffies
;
247 unsigned long acc_jiffies
; /* handle acceleration */
248 unsigned long first_jiffies
;
250 unsigned int repeat_count
;
252 char rc_name
[NAME_BUFSIZE
];
253 char rc_phys
[NAME_BUFSIZE
];
254 char mouse_name
[NAME_BUFSIZE
+ 6];
255 char mouse_phys
[NAME_BUFSIZE
];
257 wait_queue_head_t wait
;
260 int users
; /* 0-2, users are rc and input */
261 struct mutex open_mutex
;
264 /* "Kinds" of messages sent from the hardware to the driver. */
266 #define KIND_LITERAL 1 /* Simply pass to input system as EV_KEY */
267 #define KIND_FILTERED 2 /* Add artificial key-up events, drop keyrepeats */
268 #define KIND_ACCEL 3 /* Translate to EV_REL mouse-move events */
270 /* Translation table from hardware messages to input events. */
271 static const struct {
273 unsigned char data
; /* Raw key code from remote */
274 unsigned short code
; /* Input layer translation */
275 } ati_remote_tbl
[] = {
276 /* Directional control pad axes. Code is xxyy */
277 {KIND_ACCEL
, 0x70, 0xff00}, /* left */
278 {KIND_ACCEL
, 0x71, 0x0100}, /* right */
279 {KIND_ACCEL
, 0x72, 0x00ff}, /* up */
280 {KIND_ACCEL
, 0x73, 0x0001}, /* down */
282 /* Directional control pad diagonals */
283 {KIND_ACCEL
, 0x74, 0xffff}, /* left up */
284 {KIND_ACCEL
, 0x75, 0x01ff}, /* right up */
285 {KIND_ACCEL
, 0x77, 0xff01}, /* left down */
286 {KIND_ACCEL
, 0x76, 0x0101}, /* right down */
288 /* "Mouse button" buttons. The code below uses the fact that the
289 * lsbit of the raw code is a down/up indicator. */
290 {KIND_LITERAL
, 0x78, BTN_LEFT
}, /* left btn down */
291 {KIND_LITERAL
, 0x79, BTN_LEFT
}, /* left btn up */
292 {KIND_LITERAL
, 0x7c, BTN_RIGHT
},/* right btn down */
293 {KIND_LITERAL
, 0x7d, BTN_RIGHT
},/* right btn up */
295 /* Artificial "double-click" events are generated by the hardware.
296 * They are mapped to the "side" and "extra" mouse buttons here. */
297 {KIND_FILTERED
, 0x7a, BTN_SIDE
}, /* left dblclick */
298 {KIND_FILTERED
, 0x7e, BTN_EXTRA
},/* right dblclick */
300 /* Non-mouse events are handled by rc-core */
305 * ati_remote_dump_input
307 static void ati_remote_dump(struct device
*dev
, unsigned char *data
,
311 if (data
[0] != (unsigned char)0xff && data
[0] != 0x00)
312 dev_warn(dev
, "Weird byte 0x%02x\n", data
[0]);
314 dev_warn(dev
, "Weird key %4ph\n", data
);
316 dev_warn(dev
, "Weird data, len=%d %6ph ...\n", len
, data
);
322 static int ati_remote_open(struct ati_remote
*ati_remote
)
326 mutex_lock(&ati_remote
->open_mutex
);
328 if (ati_remote
->users
++ != 0)
329 goto out
; /* one was already active */
331 /* On first open, submit the read urb which was set up previously. */
332 ati_remote
->irq_urb
->dev
= ati_remote
->udev
;
333 if (usb_submit_urb(ati_remote
->irq_urb
, GFP_KERNEL
)) {
334 dev_err(&ati_remote
->interface
->dev
,
335 "%s: usb_submit_urb failed!\n", __func__
);
339 out
: mutex_unlock(&ati_remote
->open_mutex
);
346 static void ati_remote_close(struct ati_remote
*ati_remote
)
348 mutex_lock(&ati_remote
->open_mutex
);
349 if (--ati_remote
->users
== 0)
350 usb_kill_urb(ati_remote
->irq_urb
);
351 mutex_unlock(&ati_remote
->open_mutex
);
354 static int ati_remote_input_open(struct input_dev
*inputdev
)
356 struct ati_remote
*ati_remote
= input_get_drvdata(inputdev
);
357 return ati_remote_open(ati_remote
);
360 static void ati_remote_input_close(struct input_dev
*inputdev
)
362 struct ati_remote
*ati_remote
= input_get_drvdata(inputdev
);
363 ati_remote_close(ati_remote
);
366 static int ati_remote_rc_open(struct rc_dev
*rdev
)
368 struct ati_remote
*ati_remote
= rdev
->priv
;
369 return ati_remote_open(ati_remote
);
372 static void ati_remote_rc_close(struct rc_dev
*rdev
)
374 struct ati_remote
*ati_remote
= rdev
->priv
;
375 ati_remote_close(ati_remote
);
381 static void ati_remote_irq_out(struct urb
*urb
)
383 struct ati_remote
*ati_remote
= urb
->context
;
386 dev_dbg(&ati_remote
->interface
->dev
, "%s: status %d\n",
387 __func__
, urb
->status
);
391 ati_remote
->send_flags
|= SEND_FLAG_COMPLETE
;
393 wake_up(&ati_remote
->wait
);
397 * ati_remote_sendpacket
399 * Used to send device initialization strings
401 static int ati_remote_sendpacket(struct ati_remote
*ati_remote
, u16 cmd
,
407 memcpy(ati_remote
->out_urb
->transfer_buffer
+ 1, data
, LO(cmd
));
408 ((char *) ati_remote
->out_urb
->transfer_buffer
)[0] = HI(cmd
);
410 ati_remote
->out_urb
->transfer_buffer_length
= LO(cmd
) + 1;
411 ati_remote
->out_urb
->dev
= ati_remote
->udev
;
412 ati_remote
->send_flags
= SEND_FLAG_IN_PROGRESS
;
414 retval
= usb_submit_urb(ati_remote
->out_urb
, GFP_ATOMIC
);
416 dev_dbg(&ati_remote
->interface
->dev
,
417 "sendpacket: usb_submit_urb failed: %d\n", retval
);
421 wait_event_timeout(ati_remote
->wait
,
422 ((ati_remote
->out_urb
->status
!= -EINPROGRESS
) ||
423 (ati_remote
->send_flags
& SEND_FLAG_COMPLETE
)),
425 usb_kill_urb(ati_remote
->out_urb
);
435 static const struct accel_times accel
[] = {
446 * ati_remote_compute_accel
448 * Implements acceleration curve for directional control pad
449 * If elapsed time since last event is > 1/4 second, user "stopped",
450 * so reset acceleration. Otherwise, user is probably holding the control
451 * pad down, so we increase acceleration, ramping up over two seconds to
454 static int ati_remote_compute_accel(struct ati_remote
*ati_remote
)
456 unsigned long now
= jiffies
, reset_time
;
459 reset_time
= msecs_to_jiffies(250);
461 if (time_after(now
, ati_remote
->old_jiffies
+ reset_time
)) {
462 ati_remote
->acc_jiffies
= now
;
465 for (i
= 0; i
< ARRAY_SIZE(accel
) - 1; i
++) {
466 unsigned long timeout
= msecs_to_jiffies(accel
[i
].msecs
);
468 if (time_before(now
, ati_remote
->acc_jiffies
+ timeout
))
469 return accel
[i
].value
;
471 return accel
[i
].value
;
475 * ati_remote_report_input
477 static void ati_remote_input_report(struct urb
*urb
)
479 struct ati_remote
*ati_remote
= urb
->context
;
480 unsigned char *data
= ati_remote
->inbuf
;
481 struct input_dev
*dev
= ati_remote
->idev
;
484 unsigned char scancode
;
485 u32 wheel_keycode
= KEY_RESERVED
;
490 * data[1] = data[2] + data[3] + 0xd5 (a checksum byte)
491 * data[2] = the key code (with toggle bit in MSB with some models)
492 * data[3] = channel << 4 (the low 4 bits must be zero)
495 /* Deal with strange looking inputs */
496 if ( urb
->actual_length
!= 4 || data
[0] != 0x14 ||
497 data
[1] != (unsigned char)(data
[2] + data
[3] + 0xD5) ||
498 (data
[3] & 0x0f) != 0x00) {
499 ati_remote_dump(&urb
->dev
->dev
, data
, urb
->actual_length
);
503 if (data
[1] != ((data
[2] + data
[3] + 0xd5) & 0xff)) {
504 dbginfo(&ati_remote
->interface
->dev
,
505 "wrong checksum in input: %4ph\n", data
);
509 /* Mask unwanted remote channels. */
510 /* note: remote_num is 0-based, channel 1 on remote == 0 here */
511 remote_num
= (data
[3] >> 4) & 0x0f;
512 if (channel_mask
& (1 << (remote_num
+ 1))) {
513 dbginfo(&ati_remote
->interface
->dev
,
514 "Masked input from channel 0x%02x: data %02x, mask= 0x%02lx\n",
515 remote_num
, data
[2], channel_mask
);
520 * MSB is a toggle code, though only used by some devices
521 * (e.g. SnapStream Firefly)
523 scancode
= data
[2] & 0x7f;
525 dbginfo(&ati_remote
->interface
->dev
,
526 "channel 0x%02x; key data %02x, scancode %02x\n",
527 remote_num
, data
[2], scancode
);
529 if (scancode
>= 0x70) {
531 * This is either a mouse or scrollwheel event, depending on
533 * Get the keycode assigned to scancode 0x78/0x70. If it is
534 * set, assume this is a scrollwheel up/down event.
536 wheel_keycode
= rc_g_keycode_from_table(ati_remote
->rdev
,
539 if (wheel_keycode
== KEY_RESERVED
) {
540 /* scrollwheel was not mapped, assume mouse */
542 /* Look up event code index in the mouse translation
545 for (i
= 0; ati_remote_tbl
[i
].kind
!= KIND_END
; i
++) {
546 if (scancode
== ati_remote_tbl
[i
].data
) {
554 if (index
>= 0 && ati_remote_tbl
[index
].kind
== KIND_LITERAL
) {
556 * The lsbit of the raw key code is a down/up flag.
557 * Invert it to match the input layer's conventions.
559 input_event(dev
, EV_KEY
, ati_remote_tbl
[index
].code
,
562 ati_remote
->old_jiffies
= jiffies
;
564 } else if (index
< 0 || ati_remote_tbl
[index
].kind
== KIND_FILTERED
) {
565 unsigned long now
= jiffies
;
567 /* Filter duplicate events which happen "too close" together. */
568 if (ati_remote
->old_data
== data
[2] &&
569 time_before(now
, ati_remote
->old_jiffies
+
570 msecs_to_jiffies(repeat_filter
))) {
571 ati_remote
->repeat_count
++;
573 ati_remote
->repeat_count
= 0;
574 ati_remote
->first_jiffies
= now
;
577 ati_remote
->old_jiffies
= now
;
579 /* Ensure we skip at least the 4 first duplicate events
580 * (generated by a single keypress), and continue skipping
581 * until repeat_delay msecs have passed.
583 if (ati_remote
->repeat_count
> 0 &&
584 (ati_remote
->repeat_count
< 5 ||
585 time_before(now
, ati_remote
->first_jiffies
+
586 msecs_to_jiffies(repeat_delay
))))
590 input_event(dev
, EV_KEY
, ati_remote_tbl
[index
].code
, 1);
591 input_event(dev
, EV_KEY
, ati_remote_tbl
[index
].code
, 0);
593 /* Not a mouse event, hand it to rc-core. */
596 if (wheel_keycode
!= KEY_RESERVED
) {
598 * This is a scrollwheel event, send the
599 * scroll up (0x78) / down (0x70) scancode
600 * repeatedly as many times as indicated by
601 * rest of the scancode.
603 count
= (scancode
& 0x07) + 1;
609 * We don't use the rc-core repeat handling yet as
610 * it would cause ghost repeats which would be a
611 * regression for this driver.
613 rc_keydown_notimeout(ati_remote
->rdev
,
616 rc_keyup(ati_remote
->rdev
);
621 } else if (ati_remote_tbl
[index
].kind
== KIND_ACCEL
) {
622 signed char dx
= ati_remote_tbl
[index
].code
>> 8;
623 signed char dy
= ati_remote_tbl
[index
].code
& 255;
626 * Other event kinds are from the directional control pad, and
627 * have an acceleration factor applied to them. Without this
628 * acceleration, the control pad is mostly unusable.
630 int acc
= ati_remote_compute_accel(ati_remote
);
632 input_report_rel(dev
, REL_X
, dx
* acc
);
634 input_report_rel(dev
, REL_Y
, dy
* acc
);
635 ati_remote
->old_jiffies
= jiffies
;
638 dev_dbg(&ati_remote
->interface
->dev
, "ati_remote kind=%d\n",
639 ati_remote_tbl
[index
].kind
);
644 ati_remote
->old_data
= data
[2];
650 static void ati_remote_irq_in(struct urb
*urb
)
652 struct ati_remote
*ati_remote
= urb
->context
;
655 switch (urb
->status
) {
656 case 0: /* success */
657 ati_remote_input_report(urb
);
659 case -ECONNRESET
: /* unlink */
662 dev_dbg(&ati_remote
->interface
->dev
,
663 "%s: urb error status, unlink?\n",
667 dev_dbg(&ati_remote
->interface
->dev
,
668 "%s: Nonzero urb status %d\n",
669 __func__
, urb
->status
);
672 retval
= usb_submit_urb(urb
, GFP_ATOMIC
);
674 dev_err(&ati_remote
->interface
->dev
,
675 "%s: usb_submit_urb()=%d\n",
680 * ati_remote_alloc_buffers
682 static int ati_remote_alloc_buffers(struct usb_device
*udev
,
683 struct ati_remote
*ati_remote
)
685 ati_remote
->inbuf
= usb_alloc_coherent(udev
, DATA_BUFSIZE
, GFP_ATOMIC
,
686 &ati_remote
->inbuf_dma
);
687 if (!ati_remote
->inbuf
)
690 ati_remote
->outbuf
= usb_alloc_coherent(udev
, DATA_BUFSIZE
, GFP_ATOMIC
,
691 &ati_remote
->outbuf_dma
);
692 if (!ati_remote
->outbuf
)
695 ati_remote
->irq_urb
= usb_alloc_urb(0, GFP_KERNEL
);
696 if (!ati_remote
->irq_urb
)
699 ati_remote
->out_urb
= usb_alloc_urb(0, GFP_KERNEL
);
700 if (!ati_remote
->out_urb
)
707 * ati_remote_free_buffers
709 static void ati_remote_free_buffers(struct ati_remote
*ati_remote
)
711 usb_free_urb(ati_remote
->irq_urb
);
712 usb_free_urb(ati_remote
->out_urb
);
714 usb_free_coherent(ati_remote
->udev
, DATA_BUFSIZE
,
715 ati_remote
->inbuf
, ati_remote
->inbuf_dma
);
717 usb_free_coherent(ati_remote
->udev
, DATA_BUFSIZE
,
718 ati_remote
->outbuf
, ati_remote
->outbuf_dma
);
721 static void ati_remote_input_init(struct ati_remote
*ati_remote
)
723 struct input_dev
*idev
= ati_remote
->idev
;
726 idev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_REL
);
727 idev
->keybit
[BIT_WORD(BTN_MOUSE
)] = BIT_MASK(BTN_LEFT
) |
728 BIT_MASK(BTN_RIGHT
) | BIT_MASK(BTN_SIDE
) | BIT_MASK(BTN_EXTRA
);
729 idev
->relbit
[0] = BIT_MASK(REL_X
) | BIT_MASK(REL_Y
);
730 for (i
= 0; ati_remote_tbl
[i
].kind
!= KIND_END
; i
++)
731 if (ati_remote_tbl
[i
].kind
== KIND_LITERAL
||
732 ati_remote_tbl
[i
].kind
== KIND_FILTERED
)
733 __set_bit(ati_remote_tbl
[i
].code
, idev
->keybit
);
735 input_set_drvdata(idev
, ati_remote
);
737 idev
->open
= ati_remote_input_open
;
738 idev
->close
= ati_remote_input_close
;
740 idev
->name
= ati_remote
->mouse_name
;
741 idev
->phys
= ati_remote
->mouse_phys
;
743 usb_to_input_id(ati_remote
->udev
, &idev
->id
);
744 idev
->dev
.parent
= &ati_remote
->interface
->dev
;
747 static void ati_remote_rc_init(struct ati_remote
*ati_remote
)
749 struct rc_dev
*rdev
= ati_remote
->rdev
;
751 rdev
->priv
= ati_remote
;
752 rdev
->allowed_protocols
= RC_PROTO_BIT_OTHER
;
753 rdev
->driver_name
= "ati_remote";
755 rdev
->open
= ati_remote_rc_open
;
756 rdev
->close
= ati_remote_rc_close
;
758 rdev
->device_name
= ati_remote
->rc_name
;
759 rdev
->input_phys
= ati_remote
->rc_phys
;
761 usb_to_input_id(ati_remote
->udev
, &rdev
->input_id
);
762 rdev
->dev
.parent
= &ati_remote
->interface
->dev
;
765 static int ati_remote_initialize(struct ati_remote
*ati_remote
)
767 struct usb_device
*udev
= ati_remote
->udev
;
770 init_waitqueue_head(&ati_remote
->wait
);
773 pipe
= usb_rcvintpipe(udev
, ati_remote
->endpoint_in
->bEndpointAddress
);
774 maxp
= usb_maxpacket(udev
, pipe
);
775 maxp
= (maxp
> DATA_BUFSIZE
) ? DATA_BUFSIZE
: maxp
;
777 usb_fill_int_urb(ati_remote
->irq_urb
, udev
, pipe
, ati_remote
->inbuf
,
778 maxp
, ati_remote_irq_in
, ati_remote
,
779 ati_remote
->endpoint_in
->bInterval
);
780 ati_remote
->irq_urb
->transfer_dma
= ati_remote
->inbuf_dma
;
781 ati_remote
->irq_urb
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
784 pipe
= usb_sndintpipe(udev
, ati_remote
->endpoint_out
->bEndpointAddress
);
785 maxp
= usb_maxpacket(udev
, pipe
);
786 maxp
= (maxp
> DATA_BUFSIZE
) ? DATA_BUFSIZE
: maxp
;
788 usb_fill_int_urb(ati_remote
->out_urb
, udev
, pipe
, ati_remote
->outbuf
,
789 maxp
, ati_remote_irq_out
, ati_remote
,
790 ati_remote
->endpoint_out
->bInterval
);
791 ati_remote
->out_urb
->transfer_dma
= ati_remote
->outbuf_dma
;
792 ati_remote
->out_urb
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
794 /* send initialization strings */
795 if ((ati_remote_sendpacket(ati_remote
, 0x8004, init1
)) ||
796 (ati_remote_sendpacket(ati_remote
, 0x8007, init2
))) {
797 dev_err(&ati_remote
->interface
->dev
,
798 "Initializing ati_remote hardware failed.\n");
808 static int ati_remote_probe(struct usb_interface
*interface
,
809 const struct usb_device_id
*id
)
811 struct usb_device
*udev
= interface_to_usbdev(interface
);
812 struct usb_host_interface
*iface_host
= interface
->cur_altsetting
;
813 struct usb_endpoint_descriptor
*endpoint_in
, *endpoint_out
;
814 struct ati_receiver_type
*type
= (struct ati_receiver_type
*)id
->driver_info
;
815 struct ati_remote
*ati_remote
;
816 struct input_dev
*input_dev
;
817 struct device
*device
= &interface
->dev
;
818 struct rc_dev
*rc_dev
;
821 if (iface_host
->desc
.bNumEndpoints
!= 2) {
822 dev_err(device
, "%s: Unexpected desc.bNumEndpoints\n", __func__
);
826 endpoint_in
= &iface_host
->endpoint
[0].desc
;
827 endpoint_out
= &iface_host
->endpoint
[1].desc
;
829 if (!usb_endpoint_is_int_in(endpoint_in
)) {
830 dev_err(device
, "%s: Unexpected endpoint_in\n", __func__
);
833 if (le16_to_cpu(endpoint_in
->wMaxPacketSize
) == 0) {
834 dev_err(device
, "%s: endpoint_in message size==0?\n", __func__
);
837 if (!usb_endpoint_is_int_out(endpoint_out
)) {
838 dev_err(device
, "%s: Unexpected endpoint_out\n", __func__
);
842 ati_remote
= kzalloc(sizeof (struct ati_remote
), GFP_KERNEL
);
843 rc_dev
= rc_allocate_device(RC_DRIVER_SCANCODE
);
844 if (!ati_remote
|| !rc_dev
)
845 goto exit_free_dev_rdev
;
847 /* Allocate URB buffers, URBs */
848 if (ati_remote_alloc_buffers(udev
, ati_remote
))
849 goto exit_free_buffers
;
851 ati_remote
->endpoint_in
= endpoint_in
;
852 ati_remote
->endpoint_out
= endpoint_out
;
853 ati_remote
->udev
= udev
;
854 ati_remote
->rdev
= rc_dev
;
855 ati_remote
->interface
= interface
;
857 usb_make_path(udev
, ati_remote
->rc_phys
, sizeof(ati_remote
->rc_phys
));
858 strscpy(ati_remote
->mouse_phys
, ati_remote
->rc_phys
,
859 sizeof(ati_remote
->mouse_phys
));
861 strlcat(ati_remote
->rc_phys
, "/input0", sizeof(ati_remote
->rc_phys
));
862 strlcat(ati_remote
->mouse_phys
, "/input1", sizeof(ati_remote
->mouse_phys
));
864 snprintf(ati_remote
->rc_name
, sizeof(ati_remote
->rc_name
), "%s%s%s",
865 udev
->manufacturer
?: "",
866 udev
->manufacturer
&& udev
->product
? " " : "",
867 udev
->product
?: "");
869 if (!strlen(ati_remote
->rc_name
))
870 snprintf(ati_remote
->rc_name
, sizeof(ati_remote
->rc_name
),
871 DRIVER_DESC
"(%04x,%04x)",
872 le16_to_cpu(ati_remote
->udev
->descriptor
.idVendor
),
873 le16_to_cpu(ati_remote
->udev
->descriptor
.idProduct
));
875 snprintf(ati_remote
->mouse_name
, sizeof(ati_remote
->mouse_name
),
876 "%s mouse", ati_remote
->rc_name
);
878 rc_dev
->map_name
= RC_MAP_ATI_X10
; /* default map */
880 /* set default keymap according to receiver model */
882 if (type
->default_keymap
)
883 rc_dev
->map_name
= type
->default_keymap
;
884 else if (type
->get_default_keymap
)
885 rc_dev
->map_name
= type
->get_default_keymap(interface
);
888 ati_remote_rc_init(ati_remote
);
889 mutex_init(&ati_remote
->open_mutex
);
891 /* Device Hardware Initialization - fills in ati_remote->idev from udev. */
892 err
= ati_remote_initialize(ati_remote
);
896 /* Set up and register rc device */
897 err
= rc_register_device(ati_remote
->rdev
);
901 /* Set up and register mouse input device */
903 input_dev
= input_allocate_device();
906 goto exit_unregister_device
;
909 ati_remote
->idev
= input_dev
;
910 ati_remote_input_init(ati_remote
);
911 err
= input_register_device(input_dev
);
914 goto exit_free_input_device
;
917 usb_set_intfdata(interface
, ati_remote
);
920 exit_free_input_device
:
921 input_free_device(input_dev
);
922 exit_unregister_device
:
923 rc_unregister_device(rc_dev
);
926 usb_kill_urb(ati_remote
->irq_urb
);
927 usb_kill_urb(ati_remote
->out_urb
);
929 ati_remote_free_buffers(ati_remote
);
931 rc_free_device(rc_dev
);
937 * ati_remote_disconnect
939 static void ati_remote_disconnect(struct usb_interface
*interface
)
941 struct ati_remote
*ati_remote
;
943 ati_remote
= usb_get_intfdata(interface
);
944 usb_set_intfdata(interface
, NULL
);
946 dev_warn(&interface
->dev
, "%s - null device?\n", __func__
);
950 usb_kill_urb(ati_remote
->irq_urb
);
951 usb_kill_urb(ati_remote
->out_urb
);
952 if (ati_remote
->idev
)
953 input_unregister_device(ati_remote
->idev
);
954 rc_unregister_device(ati_remote
->rdev
);
955 ati_remote_free_buffers(ati_remote
);
959 /* usb specific object to register with the usb subsystem */
960 static struct usb_driver ati_remote_driver
= {
961 .name
= "ati_remote",
962 .probe
= ati_remote_probe
,
963 .disconnect
= ati_remote_disconnect
,
964 .id_table
= ati_remote_table
,
967 module_usb_driver(ati_remote_driver
);
969 MODULE_AUTHOR(DRIVER_AUTHOR
);
970 MODULE_DESCRIPTION(DRIVER_DESC
);
971 MODULE_LICENSE("GPL");