Commit | Line | Data |
---|---|---|
21677cfc JW |
1 | /* |
2 | * imon.c: input and display driver for SoundGraph iMON IR/VFD/LCD | |
3 | * | |
693508df | 4 | * Copyright(C) 2010 Jarod Wilson <jarod@wilsonet.com> |
21677cfc JW |
5 | * Portions based on the original lirc_imon driver, |
6 | * Copyright(C) 2004 Venky Raju(dev@venky.ws) | |
7 | * | |
8 | * Huge thanks to R. Geoff Newbury for invaluable debugging on the | |
9 | * 0xffdc iMON devices, and for sending me one to hack on, without | |
10 | * which the support for them wouldn't be nearly as good. Thanks | |
11 | * also to the numerous 0xffdc device owners that tested auto-config | |
12 | * support for me and provided debug dumps from their devices. | |
13 | * | |
14 | * imon is free software; you can redistribute it and/or modify | |
15 | * it under the terms of the GNU General Public License as published by | |
16 | * the Free Software Foundation; either version 2 of the License, or | |
17 | * (at your option) any later version. | |
18 | * | |
19 | * This program is distributed in the hope that it will be useful, | |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 | * GNU General Public License for more details. | |
23 | * | |
24 | * You should have received a copy of the GNU General Public License | |
25 | * along with this program; if not, write to the Free Software | |
26 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
27 | */ | |
28 | ||
e2302501 JP |
29 | #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ |
30 | ||
21677cfc JW |
31 | #include <linux/errno.h> |
32 | #include <linux/init.h> | |
33 | #include <linux/kernel.h> | |
34 | #include <linux/module.h> | |
35 | #include <linux/slab.h> | |
36 | #include <linux/uaccess.h> | |
47a09b08 | 37 | #include <linux/ratelimit.h> |
21677cfc JW |
38 | |
39 | #include <linux/input.h> | |
40 | #include <linux/usb.h> | |
41 | #include <linux/usb/input.h> | |
6bda9644 | 42 | #include <media/rc-core.h> |
21677cfc JW |
43 | |
44 | #include <linux/time.h> | |
45 | #include <linux/timer.h> | |
46 | ||
47 | #define MOD_AUTHOR "Jarod Wilson <jarod@wilsonet.com>" | |
48 | #define MOD_DESC "Driver for SoundGraph iMON MultiMedia IR/Display" | |
49 | #define MOD_NAME "imon" | |
8791d63a | 50 | #define MOD_VERSION "0.9.4" |
21677cfc JW |
51 | |
52 | #define DISPLAY_MINOR_BASE 144 | |
53 | #define DEVICE_NAME "lcd%d" | |
54 | ||
55 | #define BUF_CHUNK_SIZE 8 | |
56 | #define BUF_SIZE 128 | |
57 | ||
58 | #define BIT_DURATION 250 /* each bit received is 250us */ | |
59 | ||
60 | #define IMON_CLOCK_ENABLE_PACKETS 2 | |
21677cfc JW |
61 | |
62 | /*** P R O T O T Y P E S ***/ | |
63 | ||
64 | /* USB Callback prototypes */ | |
65 | static int imon_probe(struct usb_interface *interface, | |
66 | const struct usb_device_id *id); | |
67 | static void imon_disconnect(struct usb_interface *interface); | |
68 | static void usb_rx_callback_intf0(struct urb *urb); | |
69 | static void usb_rx_callback_intf1(struct urb *urb); | |
70 | static void usb_tx_callback(struct urb *urb); | |
71 | ||
72 | /* suspend/resume support */ | |
73 | static int imon_resume(struct usb_interface *intf); | |
74 | static int imon_suspend(struct usb_interface *intf, pm_message_t message); | |
75 | ||
76 | /* Display file_operations function prototypes */ | |
77 | static int display_open(struct inode *inode, struct file *file); | |
78 | static int display_close(struct inode *inode, struct file *file); | |
79 | ||
80 | /* VFD write operation */ | |
81 | static ssize_t vfd_write(struct file *file, const char *buf, | |
82 | size_t n_bytes, loff_t *pos); | |
83 | ||
84 | /* LCD file_operations override function prototypes */ | |
85 | static ssize_t lcd_write(struct file *file, const char *buf, | |
86 | size_t n_bytes, loff_t *pos); | |
87 | ||
88 | /*** G L O B A L S ***/ | |
89 | ||
90 | struct imon_context { | |
91 | struct device *dev; | |
21677cfc JW |
92 | /* Newer devices have two interfaces */ |
93 | struct usb_device *usbdev_intf0; | |
94 | struct usb_device *usbdev_intf1; | |
95 | ||
96 | bool display_supported; /* not all controllers do */ | |
97 | bool display_isopen; /* display port has been opened */ | |
bbe4690f | 98 | bool rf_device; /* true if iMON 2.4G LT/DT RF device */ |
21677cfc JW |
99 | bool rf_isassociating; /* RF remote associating */ |
100 | bool dev_present_intf0; /* USB device presence, interface 0 */ | |
101 | bool dev_present_intf1; /* USB device presence, interface 1 */ | |
102 | ||
103 | struct mutex lock; /* to lock this object */ | |
104 | wait_queue_head_t remove_ok; /* For unexpected USB disconnects */ | |
105 | ||
106 | struct usb_endpoint_descriptor *rx_endpoint_intf0; | |
107 | struct usb_endpoint_descriptor *rx_endpoint_intf1; | |
108 | struct usb_endpoint_descriptor *tx_endpoint; | |
109 | struct urb *rx_urb_intf0; | |
110 | struct urb *rx_urb_intf1; | |
111 | struct urb *tx_urb; | |
112 | bool tx_control; | |
113 | unsigned char usb_rx_buf[8]; | |
114 | unsigned char usb_tx_buf[8]; | |
115 | ||
116 | struct tx_t { | |
117 | unsigned char data_buf[35]; /* user data buffer */ | |
118 | struct completion finished; /* wait for write to finish */ | |
119 | bool busy; /* write in progress */ | |
120 | int status; /* status of tx completion */ | |
121 | } tx; | |
122 | ||
123 | u16 vendor; /* usb vendor ID */ | |
124 | u16 product; /* usb product ID */ | |
125 | ||
d8b4b582 | 126 | struct rc_dev *rdev; /* rc-core device for remote */ |
eaf2bcc9 | 127 | struct input_dev *idev; /* input device for panel & IR mouse */ |
21677cfc JW |
128 | struct input_dev *touch; /* input device for touchscreen */ |
129 | ||
693508df | 130 | spinlock_t kc_lock; /* make sure we get keycodes right */ |
21677cfc JW |
131 | u32 kc; /* current input keycode */ |
132 | u32 last_keycode; /* last reported input keycode */ | |
eaf2bcc9 DH |
133 | u32 rc_scancode; /* the computed remote scancode */ |
134 | u8 rc_toggle; /* the computed remote toggle bit */ | |
52b66144 | 135 | u64 rc_type; /* iMON or MCE (RC6) IR protocol? */ |
21677cfc JW |
136 | bool release_code; /* some keys send a release code */ |
137 | ||
138 | u8 display_type; /* store the display type */ | |
139 | bool pad_mouse; /* toggle kbd(0)/mouse(1) mode */ | |
140 | ||
eaf2bcc9 DH |
141 | char name_rdev[128]; /* rc input device name */ |
142 | char phys_rdev[64]; /* rc input device phys path */ | |
143 | ||
21677cfc JW |
144 | char name_idev[128]; /* input device name */ |
145 | char phys_idev[64]; /* input device phys path */ | |
21677cfc JW |
146 | |
147 | char name_touch[128]; /* touch screen name */ | |
148 | char phys_touch[64]; /* touch screen phys path */ | |
149 | struct timer_list ttimer; /* touch screen timer */ | |
150 | int touch_x; /* x coordinate on touchscreen */ | |
151 | int touch_y; /* y coordinate on touchscreen */ | |
152 | }; | |
153 | ||
154 | #define TOUCH_TIMEOUT (HZ/30) | |
21677cfc JW |
155 | |
156 | /* vfd character device file operations */ | |
157 | static const struct file_operations vfd_fops = { | |
158 | .owner = THIS_MODULE, | |
159 | .open = &display_open, | |
160 | .write = &vfd_write, | |
6038f373 AB |
161 | .release = &display_close, |
162 | .llseek = noop_llseek, | |
21677cfc JW |
163 | }; |
164 | ||
165 | /* lcd character device file operations */ | |
166 | static const struct file_operations lcd_fops = { | |
167 | .owner = THIS_MODULE, | |
168 | .open = &display_open, | |
169 | .write = &lcd_write, | |
6038f373 AB |
170 | .release = &display_close, |
171 | .llseek = noop_llseek, | |
21677cfc JW |
172 | }; |
173 | ||
174 | enum { | |
175 | IMON_DISPLAY_TYPE_AUTO = 0, | |
176 | IMON_DISPLAY_TYPE_VFD = 1, | |
177 | IMON_DISPLAY_TYPE_LCD = 2, | |
178 | IMON_DISPLAY_TYPE_VGA = 3, | |
179 | IMON_DISPLAY_TYPE_NONE = 4, | |
180 | }; | |
181 | ||
21677cfc JW |
182 | enum { |
183 | IMON_KEY_IMON = 0, | |
184 | IMON_KEY_MCE = 1, | |
185 | IMON_KEY_PANEL = 2, | |
186 | }; | |
187 | ||
188 | /* | |
189 | * USB Device ID for iMON USB Control Boards | |
190 | * | |
191 | * The Windows drivers contain 6 different inf files, more or less one for | |
192 | * each new device until the 0x0034-0x0046 devices, which all use the same | |
193 | * driver. Some of the devices in the 34-46 range haven't been definitively | |
194 | * identified yet. Early devices have either a TriGem Computer, Inc. or a | |
195 | * Samsung vendor ID (0x0aa8 and 0x04e8 respectively), while all later | |
196 | * devices use the SoundGraph vendor ID (0x15c2). This driver only supports | |
197 | * the ffdc and later devices, which do onboard decoding. | |
198 | */ | |
199 | static struct usb_device_id imon_usb_id_table[] = { | |
200 | /* | |
201 | * Several devices with this same device ID, all use iMON_PAD.inf | |
202 | * SoundGraph iMON PAD (IR & VFD) | |
203 | * SoundGraph iMON PAD (IR & LCD) | |
204 | * SoundGraph iMON Knob (IR only) | |
205 | */ | |
206 | { USB_DEVICE(0x15c2, 0xffdc) }, | |
207 | ||
208 | /* | |
209 | * Newer devices, all driven by the latest iMON Windows driver, full | |
210 | * list of device IDs extracted via 'strings Setup/data1.hdr |grep 15c2' | |
211 | * Need user input to fill in details on unknown devices. | |
212 | */ | |
213 | /* SoundGraph iMON OEM Touch LCD (IR & 7" VGA LCD) */ | |
214 | { USB_DEVICE(0x15c2, 0x0034) }, | |
215 | /* SoundGraph iMON OEM Touch LCD (IR & 4.3" VGA LCD) */ | |
216 | { USB_DEVICE(0x15c2, 0x0035) }, | |
217 | /* SoundGraph iMON OEM VFD (IR & VFD) */ | |
218 | { USB_DEVICE(0x15c2, 0x0036) }, | |
219 | /* device specifics unknown */ | |
220 | { USB_DEVICE(0x15c2, 0x0037) }, | |
221 | /* SoundGraph iMON OEM LCD (IR & LCD) */ | |
222 | { USB_DEVICE(0x15c2, 0x0038) }, | |
223 | /* SoundGraph iMON UltraBay (IR & LCD) */ | |
224 | { USB_DEVICE(0x15c2, 0x0039) }, | |
225 | /* device specifics unknown */ | |
226 | { USB_DEVICE(0x15c2, 0x003a) }, | |
227 | /* device specifics unknown */ | |
228 | { USB_DEVICE(0x15c2, 0x003b) }, | |
229 | /* SoundGraph iMON OEM Inside (IR only) */ | |
230 | { USB_DEVICE(0x15c2, 0x003c) }, | |
231 | /* device specifics unknown */ | |
232 | { USB_DEVICE(0x15c2, 0x003d) }, | |
233 | /* device specifics unknown */ | |
234 | { USB_DEVICE(0x15c2, 0x003e) }, | |
235 | /* device specifics unknown */ | |
236 | { USB_DEVICE(0x15c2, 0x003f) }, | |
237 | /* device specifics unknown */ | |
238 | { USB_DEVICE(0x15c2, 0x0040) }, | |
239 | /* SoundGraph iMON MINI (IR only) */ | |
240 | { USB_DEVICE(0x15c2, 0x0041) }, | |
241 | /* Antec Veris Multimedia Station EZ External (IR only) */ | |
242 | { USB_DEVICE(0x15c2, 0x0042) }, | |
243 | /* Antec Veris Multimedia Station Basic Internal (IR only) */ | |
244 | { USB_DEVICE(0x15c2, 0x0043) }, | |
245 | /* Antec Veris Multimedia Station Elite (IR & VFD) */ | |
246 | { USB_DEVICE(0x15c2, 0x0044) }, | |
247 | /* Antec Veris Multimedia Station Premiere (IR & LCD) */ | |
248 | { USB_DEVICE(0x15c2, 0x0045) }, | |
249 | /* device specifics unknown */ | |
250 | { USB_DEVICE(0x15c2, 0x0046) }, | |
251 | {} | |
252 | }; | |
253 | ||
254 | /* USB Device data */ | |
255 | static struct usb_driver imon_driver = { | |
256 | .name = MOD_NAME, | |
257 | .probe = imon_probe, | |
4c62e976 | 258 | .disconnect = imon_disconnect, |
21677cfc JW |
259 | .suspend = imon_suspend, |
260 | .resume = imon_resume, | |
261 | .id_table = imon_usb_id_table, | |
262 | }; | |
263 | ||
264 | static struct usb_class_driver imon_vfd_class = { | |
265 | .name = DEVICE_NAME, | |
266 | .fops = &vfd_fops, | |
267 | .minor_base = DISPLAY_MINOR_BASE, | |
268 | }; | |
269 | ||
270 | static struct usb_class_driver imon_lcd_class = { | |
271 | .name = DEVICE_NAME, | |
272 | .fops = &lcd_fops, | |
273 | .minor_base = DISPLAY_MINOR_BASE, | |
274 | }; | |
275 | ||
276 | /* imon receiver front panel/knob key table */ | |
277 | static const struct { | |
278 | u64 hw_code; | |
279 | u32 keycode; | |
280 | } imon_panel_key_table[] = { | |
53a5fd4d JW |
281 | { 0x000000000f00ffeell, KEY_MEDIA }, /* Go */ |
282 | { 0x000000001200ffeell, KEY_UP }, | |
283 | { 0x000000001300ffeell, KEY_DOWN }, | |
284 | { 0x000000001400ffeell, KEY_LEFT }, | |
285 | { 0x000000001500ffeell, KEY_RIGHT }, | |
286 | { 0x000000001600ffeell, KEY_ENTER }, | |
287 | { 0x000000001700ffeell, KEY_ESC }, | |
1f71baef MCC |
288 | { 0x000000001f00ffeell, KEY_AUDIO }, |
289 | { 0x000000002000ffeell, KEY_VIDEO }, | |
290 | { 0x000000002100ffeell, KEY_CAMERA }, | |
291 | { 0x000000002700ffeell, KEY_DVD }, | |
292 | { 0x000000002300ffeell, KEY_TV }, | |
53a5fd4d JW |
293 | { 0x000000002b00ffeell, KEY_EXIT }, |
294 | { 0x000000002c00ffeell, KEY_SELECT }, | |
295 | { 0x000000002d00ffeell, KEY_MENU }, | |
1f71baef MCC |
296 | { 0x000000000500ffeell, KEY_PREVIOUS }, |
297 | { 0x000000000700ffeell, KEY_REWIND }, | |
298 | { 0x000000000400ffeell, KEY_STOP }, | |
299 | { 0x000000003c00ffeell, KEY_PLAYPAUSE }, | |
300 | { 0x000000000800ffeell, KEY_FASTFORWARD }, | |
301 | { 0x000000000600ffeell, KEY_NEXT }, | |
302 | { 0x000000010000ffeell, KEY_RIGHT }, | |
303 | { 0x000001000000ffeell, KEY_LEFT }, | |
304 | { 0x000000003d00ffeell, KEY_SELECT }, | |
305 | { 0x000100000000ffeell, KEY_VOLUMEUP }, | |
306 | { 0x010000000000ffeell, KEY_VOLUMEDOWN }, | |
307 | { 0x000000000100ffeell, KEY_MUTE }, | |
04292fc0 JW |
308 | /* 0xffdc iMON MCE VFD */ |
309 | { 0x00010000ffffffeell, KEY_VOLUMEUP }, | |
310 | { 0x01000000ffffffeell, KEY_VOLUMEDOWN }, | |
443b3919 JW |
311 | { 0x00000001ffffffeell, KEY_MUTE }, |
312 | { 0x0000000fffffffeell, KEY_MEDIA }, | |
313 | { 0x00000012ffffffeell, KEY_UP }, | |
314 | { 0x00000013ffffffeell, KEY_DOWN }, | |
315 | { 0x00000014ffffffeell, KEY_LEFT }, | |
316 | { 0x00000015ffffffeell, KEY_RIGHT }, | |
317 | { 0x00000016ffffffeell, KEY_ENTER }, | |
318 | { 0x00000017ffffffeell, KEY_ESC }, | |
21677cfc | 319 | /* iMON Knob values */ |
1f71baef MCC |
320 | { 0x000100ffffffffeell, KEY_VOLUMEUP }, |
321 | { 0x010000ffffffffeell, KEY_VOLUMEDOWN }, | |
322 | { 0x000008ffffffffeell, KEY_MUTE }, | |
21677cfc JW |
323 | }; |
324 | ||
325 | /* to prevent races between open() and disconnect(), probing, etc */ | |
326 | static DEFINE_MUTEX(driver_lock); | |
327 | ||
328 | /* Module bookkeeping bits */ | |
329 | MODULE_AUTHOR(MOD_AUTHOR); | |
330 | MODULE_DESCRIPTION(MOD_DESC); | |
331 | MODULE_VERSION(MOD_VERSION); | |
332 | MODULE_LICENSE("GPL"); | |
333 | MODULE_DEVICE_TABLE(usb, imon_usb_id_table); | |
334 | ||
335 | static bool debug; | |
336 | module_param(debug, bool, S_IRUGO | S_IWUSR); | |
6aa209e4 | 337 | MODULE_PARM_DESC(debug, "Debug messages: 0=no, 1=yes (default: no)"); |
21677cfc JW |
338 | |
339 | /* lcd, vfd, vga or none? should be auto-detected, but can be overridden... */ | |
340 | static int display_type; | |
341 | module_param(display_type, int, S_IRUGO); | |
342 | MODULE_PARM_DESC(display_type, "Type of attached display. 0=autodetect, " | |
343 | "1=vfd, 2=lcd, 3=vga, 4=none (default: autodetect)"); | |
344 | ||
6718e8ad JW |
345 | static int pad_stabilize = 1; |
346 | module_param(pad_stabilize, int, S_IRUGO | S_IWUSR); | |
347 | MODULE_PARM_DESC(pad_stabilize, "Apply stabilization algorithm to iMON PAD " | |
348 | "presses in arrow key mode. 0=disable, 1=enable (default)."); | |
21677cfc JW |
349 | |
350 | /* | |
351 | * In certain use cases, mouse mode isn't really helpful, and could actually | |
352 | * cause confusion, so allow disabling it when the IR device is open. | |
353 | */ | |
354 | static bool nomouse; | |
355 | module_param(nomouse, bool, S_IRUGO | S_IWUSR); | |
356 | MODULE_PARM_DESC(nomouse, "Disable mouse input device mode when IR device is " | |
357 | "open. 0=don't disable, 1=disable. (default: don't disable)"); | |
358 | ||
359 | /* threshold at which a pad push registers as an arrow key in kbd mode */ | |
360 | static int pad_thresh; | |
361 | module_param(pad_thresh, int, S_IRUGO | S_IWUSR); | |
362 | MODULE_PARM_DESC(pad_thresh, "Threshold at which a pad push registers as an " | |
363 | "arrow key in kbd mode (default: 28)"); | |
364 | ||
365 | ||
366 | static void free_imon_context(struct imon_context *ictx) | |
367 | { | |
368 | struct device *dev = ictx->dev; | |
369 | ||
370 | usb_free_urb(ictx->tx_urb); | |
371 | usb_free_urb(ictx->rx_urb_intf0); | |
372 | usb_free_urb(ictx->rx_urb_intf1); | |
373 | kfree(ictx); | |
374 | ||
375 | dev_dbg(dev, "%s: iMON context freed\n", __func__); | |
376 | } | |
377 | ||
378 | /** | |
379 | * Called when the Display device (e.g. /dev/lcd0) | |
380 | * is opened by the application. | |
381 | */ | |
382 | static int display_open(struct inode *inode, struct file *file) | |
383 | { | |
384 | struct usb_interface *interface; | |
385 | struct imon_context *ictx = NULL; | |
386 | int subminor; | |
387 | int retval = 0; | |
388 | ||
389 | /* prevent races with disconnect */ | |
390 | mutex_lock(&driver_lock); | |
391 | ||
392 | subminor = iminor(inode); | |
393 | interface = usb_find_interface(&imon_driver, subminor); | |
394 | if (!interface) { | |
e2302501 | 395 | pr_err("could not find interface for minor %d\n", subminor); |
21677cfc JW |
396 | retval = -ENODEV; |
397 | goto exit; | |
398 | } | |
399 | ictx = usb_get_intfdata(interface); | |
400 | ||
401 | if (!ictx) { | |
e2302501 | 402 | pr_err("no context found for minor %d\n", subminor); |
21677cfc JW |
403 | retval = -ENODEV; |
404 | goto exit; | |
405 | } | |
406 | ||
407 | mutex_lock(&ictx->lock); | |
408 | ||
409 | if (!ictx->display_supported) { | |
e2302501 | 410 | pr_err("display not supported by device\n"); |
21677cfc JW |
411 | retval = -ENODEV; |
412 | } else if (ictx->display_isopen) { | |
e2302501 | 413 | pr_err("display port is already open\n"); |
21677cfc JW |
414 | retval = -EBUSY; |
415 | } else { | |
f789bf40 | 416 | ictx->display_isopen = true; |
21677cfc JW |
417 | file->private_data = ictx; |
418 | dev_dbg(ictx->dev, "display port opened\n"); | |
419 | } | |
420 | ||
421 | mutex_unlock(&ictx->lock); | |
422 | ||
423 | exit: | |
424 | mutex_unlock(&driver_lock); | |
425 | return retval; | |
426 | } | |
427 | ||
428 | /** | |
429 | * Called when the display device (e.g. /dev/lcd0) | |
430 | * is closed by the application. | |
431 | */ | |
432 | static int display_close(struct inode *inode, struct file *file) | |
433 | { | |
434 | struct imon_context *ictx = NULL; | |
435 | int retval = 0; | |
436 | ||
abf84383 | 437 | ictx = file->private_data; |
21677cfc JW |
438 | |
439 | if (!ictx) { | |
e2302501 | 440 | pr_err("no context for device\n"); |
21677cfc JW |
441 | return -ENODEV; |
442 | } | |
443 | ||
444 | mutex_lock(&ictx->lock); | |
445 | ||
446 | if (!ictx->display_supported) { | |
e2302501 | 447 | pr_err("display not supported by device\n"); |
21677cfc JW |
448 | retval = -ENODEV; |
449 | } else if (!ictx->display_isopen) { | |
e2302501 | 450 | pr_err("display is not open\n"); |
21677cfc JW |
451 | retval = -EIO; |
452 | } else { | |
f789bf40 | 453 | ictx->display_isopen = false; |
21677cfc | 454 | dev_dbg(ictx->dev, "display port closed\n"); |
21677cfc JW |
455 | } |
456 | ||
457 | mutex_unlock(&ictx->lock); | |
458 | return retval; | |
459 | } | |
460 | ||
461 | /** | |
23ef710e JW |
462 | * Sends a packet to the device -- this function must be called with |
463 | * ictx->lock held, or its unlock/lock sequence while waiting for tx | |
464 | * to complete can/will lead to a deadlock. | |
21677cfc JW |
465 | */ |
466 | static int send_packet(struct imon_context *ictx) | |
467 | { | |
468 | unsigned int pipe; | |
469 | unsigned long timeout; | |
470 | int interval = 0; | |
471 | int retval = 0; | |
472 | struct usb_ctrlrequest *control_req = NULL; | |
473 | ||
474 | /* Check if we need to use control or interrupt urb */ | |
475 | if (!ictx->tx_control) { | |
476 | pipe = usb_sndintpipe(ictx->usbdev_intf0, | |
477 | ictx->tx_endpoint->bEndpointAddress); | |
478 | interval = ictx->tx_endpoint->bInterval; | |
479 | ||
480 | usb_fill_int_urb(ictx->tx_urb, ictx->usbdev_intf0, pipe, | |
481 | ictx->usb_tx_buf, | |
482 | sizeof(ictx->usb_tx_buf), | |
483 | usb_tx_callback, ictx, interval); | |
484 | ||
485 | ictx->tx_urb->actual_length = 0; | |
486 | } else { | |
487 | /* fill request into kmalloc'ed space: */ | |
488 | control_req = kmalloc(sizeof(struct usb_ctrlrequest), | |
489 | GFP_KERNEL); | |
490 | if (control_req == NULL) | |
491 | return -ENOMEM; | |
492 | ||
493 | /* setup packet is '21 09 0200 0001 0008' */ | |
494 | control_req->bRequestType = 0x21; | |
495 | control_req->bRequest = 0x09; | |
496 | control_req->wValue = cpu_to_le16(0x0200); | |
497 | control_req->wIndex = cpu_to_le16(0x0001); | |
498 | control_req->wLength = cpu_to_le16(0x0008); | |
499 | ||
500 | /* control pipe is endpoint 0x00 */ | |
501 | pipe = usb_sndctrlpipe(ictx->usbdev_intf0, 0); | |
502 | ||
503 | /* build the control urb */ | |
504 | usb_fill_control_urb(ictx->tx_urb, ictx->usbdev_intf0, | |
505 | pipe, (unsigned char *)control_req, | |
506 | ictx->usb_tx_buf, | |
507 | sizeof(ictx->usb_tx_buf), | |
508 | usb_tx_callback, ictx); | |
509 | ictx->tx_urb->actual_length = 0; | |
510 | } | |
511 | ||
512 | init_completion(&ictx->tx.finished); | |
f789bf40 | 513 | ictx->tx.busy = true; |
21677cfc JW |
514 | smp_rmb(); /* ensure later readers know we're busy */ |
515 | ||
516 | retval = usb_submit_urb(ictx->tx_urb, GFP_KERNEL); | |
517 | if (retval) { | |
f789bf40 | 518 | ictx->tx.busy = false; |
21677cfc | 519 | smp_rmb(); /* ensure later readers know we're not busy */ |
47a09b08 | 520 | pr_err_ratelimited("error submitting urb(%d)\n", retval); |
21677cfc JW |
521 | } else { |
522 | /* Wait for transmission to complete (or abort) */ | |
523 | mutex_unlock(&ictx->lock); | |
524 | retval = wait_for_completion_interruptible( | |
525 | &ictx->tx.finished); | |
526 | if (retval) | |
47a09b08 | 527 | pr_err_ratelimited("task interrupted\n"); |
21677cfc JW |
528 | mutex_lock(&ictx->lock); |
529 | ||
530 | retval = ictx->tx.status; | |
531 | if (retval) | |
47a09b08 | 532 | pr_err_ratelimited("packet tx failed (%d)\n", retval); |
21677cfc JW |
533 | } |
534 | ||
535 | kfree(control_req); | |
536 | ||
537 | /* | |
538 | * Induce a mandatory 5ms delay before returning, as otherwise, | |
539 | * send_packet can get called so rapidly as to overwhelm the device, | |
540 | * particularly on faster systems and/or those with quirky usb. | |
541 | */ | |
542 | timeout = msecs_to_jiffies(5); | |
543 | set_current_state(TASK_UNINTERRUPTIBLE); | |
544 | schedule_timeout(timeout); | |
545 | ||
546 | return retval; | |
547 | } | |
548 | ||
549 | /** | |
550 | * Sends an associate packet to the iMON 2.4G. | |
551 | * | |
552 | * This might not be such a good idea, since it has an id collision with | |
553 | * some versions of the "IR & VFD" combo. The only way to determine if it | |
554 | * is an RF version is to look at the product description string. (Which | |
555 | * we currently do not fetch). | |
556 | */ | |
557 | static int send_associate_24g(struct imon_context *ictx) | |
558 | { | |
559 | int retval; | |
560 | const unsigned char packet[8] = { 0x01, 0x00, 0x00, 0x00, | |
561 | 0x00, 0x00, 0x00, 0x20 }; | |
562 | ||
563 | if (!ictx) { | |
e2302501 | 564 | pr_err("no context for device\n"); |
21677cfc JW |
565 | return -ENODEV; |
566 | } | |
567 | ||
568 | if (!ictx->dev_present_intf0) { | |
e2302501 | 569 | pr_err("no iMON device present\n"); |
21677cfc JW |
570 | return -ENODEV; |
571 | } | |
572 | ||
573 | memcpy(ictx->usb_tx_buf, packet, sizeof(packet)); | |
574 | retval = send_packet(ictx); | |
575 | ||
576 | return retval; | |
577 | } | |
578 | ||
579 | /** | |
580 | * Sends packets to setup and show clock on iMON display | |
581 | * | |
582 | * Arguments: year - last 2 digits of year, month - 1..12, | |
583 | * day - 1..31, dow - day of the week (0-Sun...6-Sat), | |
584 | * hour - 0..23, minute - 0..59, second - 0..59 | |
585 | */ | |
586 | static int send_set_imon_clock(struct imon_context *ictx, | |
587 | unsigned int year, unsigned int month, | |
588 | unsigned int day, unsigned int dow, | |
589 | unsigned int hour, unsigned int minute, | |
590 | unsigned int second) | |
591 | { | |
592 | unsigned char clock_enable_pkt[IMON_CLOCK_ENABLE_PACKETS][8]; | |
593 | int retval = 0; | |
594 | int i; | |
595 | ||
596 | if (!ictx) { | |
e2302501 | 597 | pr_err("no context for device\n"); |
21677cfc JW |
598 | return -ENODEV; |
599 | } | |
600 | ||
601 | switch (ictx->display_type) { | |
602 | case IMON_DISPLAY_TYPE_LCD: | |
603 | clock_enable_pkt[0][0] = 0x80; | |
604 | clock_enable_pkt[0][1] = year; | |
605 | clock_enable_pkt[0][2] = month-1; | |
606 | clock_enable_pkt[0][3] = day; | |
607 | clock_enable_pkt[0][4] = hour; | |
608 | clock_enable_pkt[0][5] = minute; | |
609 | clock_enable_pkt[0][6] = second; | |
610 | ||
611 | clock_enable_pkt[1][0] = 0x80; | |
612 | clock_enable_pkt[1][1] = 0; | |
613 | clock_enable_pkt[1][2] = 0; | |
614 | clock_enable_pkt[1][3] = 0; | |
615 | clock_enable_pkt[1][4] = 0; | |
616 | clock_enable_pkt[1][5] = 0; | |
617 | clock_enable_pkt[1][6] = 0; | |
618 | ||
619 | if (ictx->product == 0xffdc) { | |
620 | clock_enable_pkt[0][7] = 0x50; | |
621 | clock_enable_pkt[1][7] = 0x51; | |
622 | } else { | |
623 | clock_enable_pkt[0][7] = 0x88; | |
624 | clock_enable_pkt[1][7] = 0x8a; | |
625 | } | |
626 | ||
627 | break; | |
628 | ||
629 | case IMON_DISPLAY_TYPE_VFD: | |
630 | clock_enable_pkt[0][0] = year; | |
631 | clock_enable_pkt[0][1] = month-1; | |
632 | clock_enable_pkt[0][2] = day; | |
633 | clock_enable_pkt[0][3] = dow; | |
634 | clock_enable_pkt[0][4] = hour; | |
635 | clock_enable_pkt[0][5] = minute; | |
636 | clock_enable_pkt[0][6] = second; | |
637 | clock_enable_pkt[0][7] = 0x40; | |
638 | ||
639 | clock_enable_pkt[1][0] = 0; | |
640 | clock_enable_pkt[1][1] = 0; | |
641 | clock_enable_pkt[1][2] = 1; | |
642 | clock_enable_pkt[1][3] = 0; | |
643 | clock_enable_pkt[1][4] = 0; | |
644 | clock_enable_pkt[1][5] = 0; | |
645 | clock_enable_pkt[1][6] = 0; | |
646 | clock_enable_pkt[1][7] = 0x42; | |
647 | ||
648 | break; | |
649 | ||
650 | default: | |
651 | return -ENODEV; | |
652 | } | |
653 | ||
654 | for (i = 0; i < IMON_CLOCK_ENABLE_PACKETS; i++) { | |
655 | memcpy(ictx->usb_tx_buf, clock_enable_pkt[i], 8); | |
656 | retval = send_packet(ictx); | |
657 | if (retval) { | |
e2302501 | 658 | pr_err("send_packet failed for packet %d\n", i); |
21677cfc JW |
659 | break; |
660 | } | |
661 | } | |
662 | ||
663 | return retval; | |
664 | } | |
665 | ||
666 | /** | |
667 | * These are the sysfs functions to handle the association on the iMON 2.4G LT. | |
668 | */ | |
669 | static ssize_t show_associate_remote(struct device *d, | |
670 | struct device_attribute *attr, | |
671 | char *buf) | |
672 | { | |
673 | struct imon_context *ictx = dev_get_drvdata(d); | |
674 | ||
675 | if (!ictx) | |
676 | return -ENODEV; | |
677 | ||
678 | mutex_lock(&ictx->lock); | |
679 | if (ictx->rf_isassociating) | |
680 | strcpy(buf, "associating\n"); | |
681 | else | |
682 | strcpy(buf, "closed\n"); | |
683 | ||
684 | dev_info(d, "Visit http://www.lirc.org/html/imon-24g.html for " | |
685 | "instructions on how to associate your iMON 2.4G DT/LT " | |
686 | "remote\n"); | |
687 | mutex_unlock(&ictx->lock); | |
688 | return strlen(buf); | |
689 | } | |
690 | ||
691 | static ssize_t store_associate_remote(struct device *d, | |
692 | struct device_attribute *attr, | |
693 | const char *buf, size_t count) | |
694 | { | |
695 | struct imon_context *ictx; | |
696 | ||
697 | ictx = dev_get_drvdata(d); | |
698 | ||
699 | if (!ictx) | |
700 | return -ENODEV; | |
701 | ||
702 | mutex_lock(&ictx->lock); | |
f789bf40 | 703 | ictx->rf_isassociating = true; |
21677cfc JW |
704 | send_associate_24g(ictx); |
705 | mutex_unlock(&ictx->lock); | |
706 | ||
707 | return count; | |
708 | } | |
709 | ||
710 | /** | |
711 | * sysfs functions to control internal imon clock | |
712 | */ | |
713 | static ssize_t show_imon_clock(struct device *d, | |
714 | struct device_attribute *attr, char *buf) | |
715 | { | |
716 | struct imon_context *ictx = dev_get_drvdata(d); | |
717 | size_t len; | |
718 | ||
719 | if (!ictx) | |
720 | return -ENODEV; | |
721 | ||
722 | mutex_lock(&ictx->lock); | |
723 | ||
724 | if (!ictx->display_supported) { | |
725 | len = snprintf(buf, PAGE_SIZE, "Not supported."); | |
726 | } else { | |
727 | len = snprintf(buf, PAGE_SIZE, | |
728 | "To set the clock on your iMON display:\n" | |
729 | "# date \"+%%y %%m %%d %%w %%H %%M %%S\" > imon_clock\n" | |
730 | "%s", ictx->display_isopen ? | |
731 | "\nNOTE: imon device must be closed\n" : ""); | |
732 | } | |
733 | ||
734 | mutex_unlock(&ictx->lock); | |
735 | ||
736 | return len; | |
737 | } | |
738 | ||
739 | static ssize_t store_imon_clock(struct device *d, | |
740 | struct device_attribute *attr, | |
741 | const char *buf, size_t count) | |
742 | { | |
743 | struct imon_context *ictx = dev_get_drvdata(d); | |
744 | ssize_t retval; | |
745 | unsigned int year, month, day, dow, hour, minute, second; | |
746 | ||
747 | if (!ictx) | |
748 | return -ENODEV; | |
749 | ||
750 | mutex_lock(&ictx->lock); | |
751 | ||
752 | if (!ictx->display_supported) { | |
753 | retval = -ENODEV; | |
754 | goto exit; | |
755 | } else if (ictx->display_isopen) { | |
756 | retval = -EBUSY; | |
757 | goto exit; | |
758 | } | |
759 | ||
760 | if (sscanf(buf, "%u %u %u %u %u %u %u", &year, &month, &day, &dow, | |
761 | &hour, &minute, &second) != 7) { | |
762 | retval = -EINVAL; | |
763 | goto exit; | |
764 | } | |
765 | ||
766 | if ((month < 1 || month > 12) || | |
767 | (day < 1 || day > 31) || (dow > 6) || | |
768 | (hour > 23) || (minute > 59) || (second > 59)) { | |
769 | retval = -EINVAL; | |
770 | goto exit; | |
771 | } | |
772 | ||
773 | retval = send_set_imon_clock(ictx, year, month, day, dow, | |
774 | hour, minute, second); | |
775 | if (retval) | |
776 | goto exit; | |
777 | ||
778 | retval = count; | |
779 | exit: | |
780 | mutex_unlock(&ictx->lock); | |
781 | ||
782 | return retval; | |
783 | } | |
784 | ||
785 | ||
786 | static DEVICE_ATTR(imon_clock, S_IWUSR | S_IRUGO, show_imon_clock, | |
787 | store_imon_clock); | |
788 | ||
789 | static DEVICE_ATTR(associate_remote, S_IWUSR | S_IRUGO, show_associate_remote, | |
790 | store_associate_remote); | |
791 | ||
792 | static struct attribute *imon_display_sysfs_entries[] = { | |
793 | &dev_attr_imon_clock.attr, | |
794 | NULL | |
795 | }; | |
796 | ||
6aa209e4 | 797 | static struct attribute_group imon_display_attr_group = { |
21677cfc JW |
798 | .attrs = imon_display_sysfs_entries |
799 | }; | |
800 | ||
801 | static struct attribute *imon_rf_sysfs_entries[] = { | |
802 | &dev_attr_associate_remote.attr, | |
803 | NULL | |
804 | }; | |
805 | ||
6aa209e4 | 806 | static struct attribute_group imon_rf_attr_group = { |
21677cfc JW |
807 | .attrs = imon_rf_sysfs_entries |
808 | }; | |
809 | ||
810 | /** | |
811 | * Writes data to the VFD. The iMON VFD is 2x16 characters | |
812 | * and requires data in 5 consecutive USB interrupt packets, | |
813 | * each packet but the last carrying 7 bytes. | |
814 | * | |
815 | * I don't know if the VFD board supports features such as | |
816 | * scrolling, clearing rows, blanking, etc. so at | |
817 | * the caller must provide a full screen of data. If fewer | |
818 | * than 32 bytes are provided spaces will be appended to | |
819 | * generate a full screen. | |
820 | */ | |
821 | static ssize_t vfd_write(struct file *file, const char *buf, | |
822 | size_t n_bytes, loff_t *pos) | |
823 | { | |
824 | int i; | |
825 | int offset; | |
826 | int seq; | |
827 | int retval = 0; | |
828 | struct imon_context *ictx; | |
829 | const unsigned char vfd_packet6[] = { | |
830 | 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF }; | |
831 | ||
abf84383 | 832 | ictx = file->private_data; |
21677cfc | 833 | if (!ictx) { |
47a09b08 | 834 | pr_err_ratelimited("no context for device\n"); |
21677cfc JW |
835 | return -ENODEV; |
836 | } | |
837 | ||
838 | mutex_lock(&ictx->lock); | |
839 | ||
840 | if (!ictx->dev_present_intf0) { | |
47a09b08 | 841 | pr_err_ratelimited("no iMON device present\n"); |
21677cfc JW |
842 | retval = -ENODEV; |
843 | goto exit; | |
844 | } | |
845 | ||
846 | if (n_bytes <= 0 || n_bytes > 32) { | |
47a09b08 | 847 | pr_err_ratelimited("invalid payload size\n"); |
21677cfc JW |
848 | retval = -EINVAL; |
849 | goto exit; | |
850 | } | |
851 | ||
852 | if (copy_from_user(ictx->tx.data_buf, buf, n_bytes)) { | |
853 | retval = -EFAULT; | |
854 | goto exit; | |
855 | } | |
856 | ||
857 | /* Pad with spaces */ | |
858 | for (i = n_bytes; i < 32; ++i) | |
859 | ictx->tx.data_buf[i] = ' '; | |
860 | ||
861 | for (i = 32; i < 35; ++i) | |
862 | ictx->tx.data_buf[i] = 0xFF; | |
863 | ||
864 | offset = 0; | |
865 | seq = 0; | |
866 | ||
867 | do { | |
868 | memcpy(ictx->usb_tx_buf, ictx->tx.data_buf + offset, 7); | |
869 | ictx->usb_tx_buf[7] = (unsigned char) seq; | |
870 | ||
871 | retval = send_packet(ictx); | |
872 | if (retval) { | |
47a09b08 | 873 | pr_err_ratelimited("send packet #%d failed\n", seq / 2); |
21677cfc JW |
874 | goto exit; |
875 | } else { | |
876 | seq += 2; | |
877 | offset += 7; | |
878 | } | |
879 | ||
880 | } while (offset < 35); | |
881 | ||
882 | /* Send packet #6 */ | |
883 | memcpy(ictx->usb_tx_buf, &vfd_packet6, sizeof(vfd_packet6)); | |
884 | ictx->usb_tx_buf[7] = (unsigned char) seq; | |
885 | retval = send_packet(ictx); | |
886 | if (retval) | |
47a09b08 | 887 | pr_err_ratelimited("send packet #%d failed\n", seq / 2); |
21677cfc JW |
888 | |
889 | exit: | |
890 | mutex_unlock(&ictx->lock); | |
891 | ||
892 | return (!retval) ? n_bytes : retval; | |
893 | } | |
894 | ||
895 | /** | |
896 | * Writes data to the LCD. The iMON OEM LCD screen expects 8-byte | |
897 | * packets. We accept data as 16 hexadecimal digits, followed by a | |
898 | * newline (to make it easy to drive the device from a command-line | |
899 | * -- even though the actual binary data is a bit complicated). | |
900 | * | |
901 | * The device itself is not a "traditional" text-mode display. It's | |
902 | * actually a 16x96 pixel bitmap display. That means if you want to | |
903 | * display text, you've got to have your own "font" and translate the | |
904 | * text into bitmaps for display. This is really flexible (you can | |
905 | * display whatever diacritics you need, and so on), but it's also | |
906 | * a lot more complicated than most LCDs... | |
907 | */ | |
908 | static ssize_t lcd_write(struct file *file, const char *buf, | |
909 | size_t n_bytes, loff_t *pos) | |
910 | { | |
911 | int retval = 0; | |
912 | struct imon_context *ictx; | |
913 | ||
abf84383 | 914 | ictx = file->private_data; |
21677cfc | 915 | if (!ictx) { |
47a09b08 | 916 | pr_err_ratelimited("no context for device\n"); |
21677cfc JW |
917 | return -ENODEV; |
918 | } | |
919 | ||
920 | mutex_lock(&ictx->lock); | |
921 | ||
922 | if (!ictx->display_supported) { | |
47a09b08 | 923 | pr_err_ratelimited("no iMON display present\n"); |
21677cfc JW |
924 | retval = -ENODEV; |
925 | goto exit; | |
926 | } | |
927 | ||
928 | if (n_bytes != 8) { | |
47a09b08 JW |
929 | pr_err_ratelimited("invalid payload size: %d (expected 8)\n", |
930 | (int)n_bytes); | |
21677cfc JW |
931 | retval = -EINVAL; |
932 | goto exit; | |
933 | } | |
934 | ||
935 | if (copy_from_user(ictx->usb_tx_buf, buf, 8)) { | |
936 | retval = -EFAULT; | |
937 | goto exit; | |
938 | } | |
939 | ||
940 | retval = send_packet(ictx); | |
941 | if (retval) { | |
47a09b08 | 942 | pr_err_ratelimited("send packet failed!\n"); |
21677cfc JW |
943 | goto exit; |
944 | } else { | |
945 | dev_dbg(ictx->dev, "%s: write %d bytes to LCD\n", | |
946 | __func__, (int) n_bytes); | |
947 | } | |
948 | exit: | |
949 | mutex_unlock(&ictx->lock); | |
950 | return (!retval) ? n_bytes : retval; | |
951 | } | |
952 | ||
953 | /** | |
954 | * Callback function for USB core API: transmit data | |
955 | */ | |
956 | static void usb_tx_callback(struct urb *urb) | |
957 | { | |
958 | struct imon_context *ictx; | |
959 | ||
960 | if (!urb) | |
961 | return; | |
962 | ictx = (struct imon_context *)urb->context; | |
963 | if (!ictx) | |
964 | return; | |
965 | ||
966 | ictx->tx.status = urb->status; | |
967 | ||
968 | /* notify waiters that write has finished */ | |
f789bf40 | 969 | ictx->tx.busy = false; |
21677cfc JW |
970 | smp_rmb(); /* ensure later readers know we're not busy */ |
971 | complete(&ictx->tx.finished); | |
972 | } | |
973 | ||
21677cfc JW |
974 | /** |
975 | * report touchscreen input | |
976 | */ | |
977 | static void imon_touch_display_timeout(unsigned long data) | |
978 | { | |
979 | struct imon_context *ictx = (struct imon_context *)data; | |
980 | ||
f03900d6 | 981 | if (ictx->display_type != IMON_DISPLAY_TYPE_VGA) |
21677cfc JW |
982 | return; |
983 | ||
984 | input_report_abs(ictx->touch, ABS_X, ictx->touch_x); | |
985 | input_report_abs(ictx->touch, ABS_Y, ictx->touch_y); | |
986 | input_report_key(ictx->touch, BTN_TOUCH, 0x00); | |
987 | input_sync(ictx->touch); | |
988 | } | |
989 | ||
990 | /** | |
991 | * iMON IR receivers support two different signal sets -- those used by | |
992 | * the iMON remotes, and those used by the Windows MCE remotes (which is | |
993 | * really just RC-6), but only one or the other at a time, as the signals | |
994 | * are decoded onboard the receiver. | |
23ef710e JW |
995 | * |
996 | * This function gets called two different ways, one way is from | |
997 | * rc_register_device, for initial protocol selection/setup, and the other is | |
998 | * via a userspace-initiated protocol change request, either by direct sysfs | |
999 | * prodding or by something like ir-keytable. In the rc_register_device case, | |
1000 | * the imon context lock is already held, but when initiated from userspace, | |
1001 | * it is not, so we must acquire it prior to calling send_packet, which | |
1002 | * requires that the lock is held. | |
21677cfc | 1003 | */ |
c003ab1b | 1004 | static int imon_ir_change_protocol(struct rc_dev *rc, u64 *rc_type) |
21677cfc JW |
1005 | { |
1006 | int retval; | |
d8b4b582 | 1007 | struct imon_context *ictx = rc->priv; |
21677cfc | 1008 | struct device *dev = ictx->dev; |
23ef710e | 1009 | bool unlock = false; |
21677cfc JW |
1010 | unsigned char ir_proto_packet[] = { |
1011 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86 }; | |
1012 | ||
c003ab1b | 1013 | if (*rc_type && !(*rc_type & rc->allowed_protos)) |
21677cfc JW |
1014 | dev_warn(dev, "Looks like you're trying to use an IR protocol " |
1015 | "this device does not support\n"); | |
1016 | ||
c003ab1b | 1017 | if (*rc_type & RC_BIT_RC6_MCE) { |
21677cfc JW |
1018 | dev_dbg(dev, "Configuring IR receiver for MCE protocol\n"); |
1019 | ir_proto_packet[0] = 0x01; | |
c003ab1b DH |
1020 | *rc_type = RC_BIT_RC6_MCE; |
1021 | } else if (*rc_type & RC_BIT_OTHER) { | |
666a9ed8 | 1022 | dev_dbg(dev, "Configuring IR receiver for iMON protocol\n"); |
76f1ef42 | 1023 | if (!pad_stabilize) |
666a9ed8 | 1024 | dev_dbg(dev, "PAD stabilize functionality disabled\n"); |
21677cfc | 1025 | /* ir_proto_packet[0] = 0x00; // already the default */ |
c003ab1b DH |
1026 | *rc_type = RC_BIT_OTHER; |
1027 | } else { | |
6718e8ad | 1028 | dev_warn(dev, "Unsupported IR protocol specified, overriding " |
666a9ed8 | 1029 | "to iMON IR protocol\n"); |
76f1ef42 | 1030 | if (!pad_stabilize) |
666a9ed8 | 1031 | dev_dbg(dev, "PAD stabilize functionality disabled\n"); |
6718e8ad | 1032 | /* ir_proto_packet[0] = 0x00; // already the default */ |
c003ab1b | 1033 | *rc_type = RC_BIT_OTHER; |
21677cfc JW |
1034 | } |
1035 | ||
1036 | memcpy(ictx->usb_tx_buf, &ir_proto_packet, sizeof(ir_proto_packet)); | |
1037 | ||
23ef710e JW |
1038 | if (!mutex_is_locked(&ictx->lock)) { |
1039 | unlock = true; | |
1040 | mutex_lock(&ictx->lock); | |
1041 | } | |
1042 | ||
21677cfc | 1043 | retval = send_packet(ictx); |
6718e8ad JW |
1044 | if (retval) |
1045 | goto out; | |
1046 | ||
c003ab1b | 1047 | ictx->rc_type = *rc_type; |
76f1ef42 | 1048 | ictx->pad_mouse = false; |
6718e8ad JW |
1049 | |
1050 | out: | |
23ef710e JW |
1051 | if (unlock) |
1052 | mutex_unlock(&ictx->lock); | |
1053 | ||
6718e8ad | 1054 | return retval; |
21677cfc JW |
1055 | } |
1056 | ||
1057 | static inline int tv2int(const struct timeval *a, const struct timeval *b) | |
1058 | { | |
1059 | int usecs = 0; | |
1060 | int sec = 0; | |
1061 | ||
1062 | if (b->tv_usec > a->tv_usec) { | |
1063 | usecs = 1000000; | |
1064 | sec--; | |
1065 | } | |
1066 | ||
1067 | usecs += a->tv_usec - b->tv_usec; | |
1068 | ||
1069 | sec += a->tv_sec - b->tv_sec; | |
1070 | sec *= 1000; | |
1071 | usecs /= 1000; | |
1072 | sec += usecs; | |
1073 | ||
1074 | if (sec < 0) | |
1075 | sec = 1000; | |
1076 | ||
1077 | return sec; | |
1078 | } | |
1079 | ||
1080 | /** | |
1081 | * The directional pad behaves a bit differently, depending on whether this is | |
1082 | * one of the older ffdc devices or a newer device. Newer devices appear to | |
1083 | * have a higher resolution matrix for more precise mouse movement, but it | |
1084 | * makes things overly sensitive in keyboard mode, so we do some interesting | |
1085 | * contortions to make it less touchy. Older devices run through the same | |
1086 | * routine with shorter timeout and a smaller threshold. | |
1087 | */ | |
1088 | static int stabilize(int a, int b, u16 timeout, u16 threshold) | |
1089 | { | |
1090 | struct timeval ct; | |
1091 | static struct timeval prev_time = {0, 0}; | |
1092 | static struct timeval hit_time = {0, 0}; | |
1093 | static int x, y, prev_result, hits; | |
1094 | int result = 0; | |
1095 | int msec, msec_hit; | |
1096 | ||
1097 | do_gettimeofday(&ct); | |
1098 | msec = tv2int(&ct, &prev_time); | |
1099 | msec_hit = tv2int(&ct, &hit_time); | |
1100 | ||
1101 | if (msec > 100) { | |
1102 | x = 0; | |
1103 | y = 0; | |
1104 | hits = 0; | |
1105 | } | |
1106 | ||
1107 | x += a; | |
1108 | y += b; | |
1109 | ||
1110 | prev_time = ct; | |
1111 | ||
1112 | if (abs(x) > threshold || abs(y) > threshold) { | |
1113 | if (abs(y) > abs(x)) | |
1114 | result = (y > 0) ? 0x7F : 0x80; | |
1115 | else | |
1116 | result = (x > 0) ? 0x7F00 : 0x8000; | |
1117 | ||
1118 | x = 0; | |
1119 | y = 0; | |
1120 | ||
1121 | if (result == prev_result) { | |
1122 | hits++; | |
1123 | ||
1124 | if (hits > 3) { | |
1125 | switch (result) { | |
1126 | case 0x7F: | |
1127 | y = 17 * threshold / 30; | |
1128 | break; | |
1129 | case 0x80: | |
1130 | y -= 17 * threshold / 30; | |
1131 | break; | |
1132 | case 0x7F00: | |
1133 | x = 17 * threshold / 30; | |
1134 | break; | |
1135 | case 0x8000: | |
1136 | x -= 17 * threshold / 30; | |
1137 | break; | |
1138 | } | |
1139 | } | |
1140 | ||
1141 | if (hits == 2 && msec_hit < timeout) { | |
1142 | result = 0; | |
1143 | hits = 1; | |
1144 | } | |
1145 | } else { | |
1146 | prev_result = result; | |
1147 | hits = 1; | |
1148 | hit_time = ct; | |
1149 | } | |
1150 | } | |
1151 | ||
1152 | return result; | |
1153 | } | |
1154 | ||
eaf2bcc9 | 1155 | static u32 imon_remote_key_lookup(struct imon_context *ictx, u32 scancode) |
21677cfc | 1156 | { |
21677cfc JW |
1157 | u32 keycode; |
1158 | u32 release; | |
1159 | bool is_release_code = false; | |
1160 | ||
1161 | /* Look for the initial press of a button */ | |
ca86674b | 1162 | keycode = rc_g_keycode_from_table(ictx->rdev, scancode); |
eaf2bcc9 DH |
1163 | ictx->rc_toggle = 0x0; |
1164 | ictx->rc_scancode = scancode; | |
21677cfc JW |
1165 | |
1166 | /* Look for the release of a button */ | |
1167 | if (keycode == KEY_RESERVED) { | |
1168 | release = scancode & ~0x4000; | |
ca86674b | 1169 | keycode = rc_g_keycode_from_table(ictx->rdev, release); |
21677cfc JW |
1170 | if (keycode != KEY_RESERVED) |
1171 | is_release_code = true; | |
1172 | } | |
1173 | ||
1174 | ictx->release_code = is_release_code; | |
1175 | ||
1176 | return keycode; | |
1177 | } | |
1178 | ||
eaf2bcc9 | 1179 | static u32 imon_mce_key_lookup(struct imon_context *ictx, u32 scancode) |
21677cfc | 1180 | { |
21677cfc JW |
1181 | u32 keycode; |
1182 | ||
1183 | #define MCE_KEY_MASK 0x7000 | |
1184 | #define MCE_TOGGLE_BIT 0x8000 | |
1185 | ||
1186 | /* | |
1187 | * On some receivers, mce keys decode to 0x8000f04xx and 0x8000f84xx | |
1188 | * (the toggle bit flipping between alternating key presses), while | |
1189 | * on other receivers, we see 0x8000f74xx and 0x8000ff4xx. To keep | |
1190 | * the table trim, we always or in the bits to look up 0x8000ff4xx, | |
1191 | * but we can't or them into all codes, as some keys are decoded in | |
1192 | * a different way w/o the same use of the toggle bit... | |
1193 | */ | |
eaf2bcc9 | 1194 | if (scancode & 0x80000000) |
21677cfc JW |
1195 | scancode = scancode | MCE_KEY_MASK | MCE_TOGGLE_BIT; |
1196 | ||
eaf2bcc9 | 1197 | ictx->rc_scancode = scancode; |
ca86674b | 1198 | keycode = rc_g_keycode_from_table(ictx->rdev, scancode); |
eaf2bcc9 DH |
1199 | |
1200 | /* not used in mce mode, but make sure we know its false */ | |
1201 | ictx->release_code = false; | |
21677cfc JW |
1202 | |
1203 | return keycode; | |
1204 | } | |
1205 | ||
eaf2bcc9 | 1206 | static u32 imon_panel_key_lookup(u64 code) |
21677cfc JW |
1207 | { |
1208 | int i; | |
083e4721 | 1209 | u32 keycode = KEY_RESERVED; |
21677cfc | 1210 | |
083e4721 JW |
1211 | for (i = 0; i < ARRAY_SIZE(imon_panel_key_table); i++) { |
1212 | if (imon_panel_key_table[i].hw_code == (code | 0xffee)) { | |
1213 | keycode = imon_panel_key_table[i].keycode; | |
21677cfc | 1214 | break; |
083e4721 JW |
1215 | } |
1216 | } | |
21677cfc JW |
1217 | |
1218 | return keycode; | |
1219 | } | |
1220 | ||
1221 | static bool imon_mouse_event(struct imon_context *ictx, | |
1222 | unsigned char *buf, int len) | |
1223 | { | |
1224 | char rel_x = 0x00, rel_y = 0x00; | |
1225 | u8 right_shift = 1; | |
f789bf40 | 1226 | bool mouse_input = true; |
21677cfc | 1227 | int dir = 0; |
693508df JW |
1228 | unsigned long flags; |
1229 | ||
1230 | spin_lock_irqsave(&ictx->kc_lock, flags); | |
21677cfc JW |
1231 | |
1232 | /* newer iMON device PAD or mouse button */ | |
1233 | if (ictx->product != 0xffdc && (buf[0] & 0x01) && len == 5) { | |
1234 | rel_x = buf[2]; | |
1235 | rel_y = buf[3]; | |
1236 | right_shift = 1; | |
1237 | /* 0xffdc iMON PAD or mouse button input */ | |
1238 | } else if (ictx->product == 0xffdc && (buf[0] & 0x40) && | |
1239 | !((buf[1] & 0x01) || ((buf[1] >> 2) & 0x01))) { | |
1240 | rel_x = (buf[1] & 0x08) | (buf[1] & 0x10) >> 2 | | |
1241 | (buf[1] & 0x20) >> 4 | (buf[1] & 0x40) >> 6; | |
1242 | if (buf[0] & 0x02) | |
1243 | rel_x |= ~0x0f; | |
1244 | rel_x = rel_x + rel_x / 2; | |
1245 | rel_y = (buf[2] & 0x08) | (buf[2] & 0x10) >> 2 | | |
1246 | (buf[2] & 0x20) >> 4 | (buf[2] & 0x40) >> 6; | |
1247 | if (buf[0] & 0x01) | |
1248 | rel_y |= ~0x0f; | |
1249 | rel_y = rel_y + rel_y / 2; | |
1250 | right_shift = 2; | |
1251 | /* some ffdc devices decode mouse buttons differently... */ | |
1252 | } else if (ictx->product == 0xffdc && (buf[0] == 0x68)) { | |
1253 | right_shift = 2; | |
1254 | /* ch+/- buttons, which we use for an emulated scroll wheel */ | |
1255 | } else if (ictx->kc == KEY_CHANNELUP && (buf[2] & 0x40) != 0x40) { | |
1256 | dir = 1; | |
1257 | } else if (ictx->kc == KEY_CHANNELDOWN && (buf[2] & 0x40) != 0x40) { | |
1258 | dir = -1; | |
1259 | } else | |
f789bf40 | 1260 | mouse_input = false; |
21677cfc | 1261 | |
693508df JW |
1262 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
1263 | ||
21677cfc JW |
1264 | if (mouse_input) { |
1265 | dev_dbg(ictx->dev, "sending mouse data via input subsystem\n"); | |
1266 | ||
1267 | if (dir) { | |
1268 | input_report_rel(ictx->idev, REL_WHEEL, dir); | |
1269 | } else if (rel_x || rel_y) { | |
1270 | input_report_rel(ictx->idev, REL_X, rel_x); | |
1271 | input_report_rel(ictx->idev, REL_Y, rel_y); | |
1272 | } else { | |
1273 | input_report_key(ictx->idev, BTN_LEFT, buf[1] & 0x1); | |
1274 | input_report_key(ictx->idev, BTN_RIGHT, | |
1275 | buf[1] >> right_shift & 0x1); | |
1276 | } | |
1277 | input_sync(ictx->idev); | |
693508df | 1278 | spin_lock_irqsave(&ictx->kc_lock, flags); |
21677cfc | 1279 | ictx->last_keycode = ictx->kc; |
693508df | 1280 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
21677cfc JW |
1281 | } |
1282 | ||
1283 | return mouse_input; | |
1284 | } | |
1285 | ||
1286 | static void imon_touch_event(struct imon_context *ictx, unsigned char *buf) | |
1287 | { | |
1288 | mod_timer(&ictx->ttimer, jiffies + TOUCH_TIMEOUT); | |
1289 | ictx->touch_x = (buf[0] << 4) | (buf[1] >> 4); | |
1290 | ictx->touch_y = 0xfff - ((buf[2] << 4) | (buf[1] & 0xf)); | |
1291 | input_report_abs(ictx->touch, ABS_X, ictx->touch_x); | |
1292 | input_report_abs(ictx->touch, ABS_Y, ictx->touch_y); | |
1293 | input_report_key(ictx->touch, BTN_TOUCH, 0x01); | |
1294 | input_sync(ictx->touch); | |
1295 | } | |
1296 | ||
1297 | static void imon_pad_to_keys(struct imon_context *ictx, unsigned char *buf) | |
1298 | { | |
1299 | int dir = 0; | |
1300 | char rel_x = 0x00, rel_y = 0x00; | |
1301 | u16 timeout, threshold; | |
eaf2bcc9 | 1302 | u32 scancode = KEY_RESERVED; |
693508df | 1303 | unsigned long flags; |
21677cfc JW |
1304 | |
1305 | /* | |
1306 | * The imon directional pad functions more like a touchpad. Bytes 3 & 4 | |
1307 | * contain a position coordinate (x,y), with each component ranging | |
1308 | * from -14 to 14. We want to down-sample this to only 4 discrete values | |
1309 | * for up/down/left/right arrow keys. Also, when you get too close to | |
25985edc | 1310 | * diagonals, it has a tendency to jump back and forth, so lets try to |
21677cfc JW |
1311 | * ignore when they get too close. |
1312 | */ | |
1313 | if (ictx->product != 0xffdc) { | |
1314 | /* first, pad to 8 bytes so it conforms with everything else */ | |
1315 | buf[5] = buf[6] = buf[7] = 0; | |
1316 | timeout = 500; /* in msecs */ | |
1317 | /* (2*threshold) x (2*threshold) square */ | |
1318 | threshold = pad_thresh ? pad_thresh : 28; | |
1319 | rel_x = buf[2]; | |
1320 | rel_y = buf[3]; | |
1321 | ||
c003ab1b | 1322 | if (ictx->rc_type == RC_BIT_OTHER && pad_stabilize) { |
21677cfc JW |
1323 | if ((buf[1] == 0) && ((rel_x != 0) || (rel_y != 0))) { |
1324 | dir = stabilize((int)rel_x, (int)rel_y, | |
1325 | timeout, threshold); | |
1326 | if (!dir) { | |
693508df JW |
1327 | spin_lock_irqsave(&ictx->kc_lock, |
1328 | flags); | |
21677cfc | 1329 | ictx->kc = KEY_UNKNOWN; |
693508df JW |
1330 | spin_unlock_irqrestore(&ictx->kc_lock, |
1331 | flags); | |
21677cfc JW |
1332 | return; |
1333 | } | |
1334 | buf[2] = dir & 0xFF; | |
1335 | buf[3] = (dir >> 8) & 0xFF; | |
eaf2bcc9 | 1336 | scancode = be32_to_cpu(*((u32 *)buf)); |
21677cfc JW |
1337 | } |
1338 | } else { | |
eaf2bcc9 DH |
1339 | /* |
1340 | * Hack alert: instead of using keycodes, we have | |
1341 | * to use hard-coded scancodes here... | |
1342 | */ | |
21677cfc JW |
1343 | if (abs(rel_y) > abs(rel_x)) { |
1344 | buf[2] = (rel_y > 0) ? 0x7F : 0x80; | |
1345 | buf[3] = 0; | |
eaf2bcc9 DH |
1346 | if (rel_y > 0) |
1347 | scancode = 0x01007f00; /* KEY_DOWN */ | |
1348 | else | |
1349 | scancode = 0x01008000; /* KEY_UP */ | |
21677cfc JW |
1350 | } else { |
1351 | buf[2] = 0; | |
1352 | buf[3] = (rel_x > 0) ? 0x7F : 0x80; | |
eaf2bcc9 DH |
1353 | if (rel_x > 0) |
1354 | scancode = 0x0100007f; /* KEY_RIGHT */ | |
1355 | else | |
1356 | scancode = 0x01000080; /* KEY_LEFT */ | |
21677cfc JW |
1357 | } |
1358 | } | |
1359 | ||
1360 | /* | |
1361 | * Handle on-board decoded pad events for e.g. older VFD/iMON-Pad | |
1362 | * device (15c2:ffdc). The remote generates various codes from | |
1363 | * 0x68nnnnB7 to 0x6AnnnnB7, the left mouse button generates | |
1364 | * 0x688301b7 and the right one 0x688481b7. All other keys generate | |
1365 | * 0x2nnnnnnn. Position coordinate is encoded in buf[1] and buf[2] with | |
1366 | * reversed endianess. Extract direction from buffer, rotate endianess, | |
1367 | * adjust sign and feed the values into stabilize(). The resulting codes | |
1368 | * will be 0x01008000, 0x01007F00, which match the newer devices. | |
1369 | */ | |
1370 | } else { | |
1371 | timeout = 10; /* in msecs */ | |
1372 | /* (2*threshold) x (2*threshold) square */ | |
1373 | threshold = pad_thresh ? pad_thresh : 15; | |
1374 | ||
1375 | /* buf[1] is x */ | |
1376 | rel_x = (buf[1] & 0x08) | (buf[1] & 0x10) >> 2 | | |
1377 | (buf[1] & 0x20) >> 4 | (buf[1] & 0x40) >> 6; | |
1378 | if (buf[0] & 0x02) | |
1379 | rel_x |= ~0x10+1; | |
1380 | /* buf[2] is y */ | |
1381 | rel_y = (buf[2] & 0x08) | (buf[2] & 0x10) >> 2 | | |
1382 | (buf[2] & 0x20) >> 4 | (buf[2] & 0x40) >> 6; | |
1383 | if (buf[0] & 0x01) | |
1384 | rel_y |= ~0x10+1; | |
1385 | ||
1386 | buf[0] = 0x01; | |
1387 | buf[1] = buf[4] = buf[5] = buf[6] = buf[7] = 0; | |
1388 | ||
c003ab1b | 1389 | if (ictx->rc_type == RC_BIT_OTHER && pad_stabilize) { |
21677cfc JW |
1390 | dir = stabilize((int)rel_x, (int)rel_y, |
1391 | timeout, threshold); | |
1392 | if (!dir) { | |
693508df | 1393 | spin_lock_irqsave(&ictx->kc_lock, flags); |
21677cfc | 1394 | ictx->kc = KEY_UNKNOWN; |
693508df | 1395 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
21677cfc JW |
1396 | return; |
1397 | } | |
1398 | buf[2] = dir & 0xFF; | |
1399 | buf[3] = (dir >> 8) & 0xFF; | |
eaf2bcc9 | 1400 | scancode = be32_to_cpu(*((u32 *)buf)); |
21677cfc | 1401 | } else { |
eaf2bcc9 DH |
1402 | /* |
1403 | * Hack alert: instead of using keycodes, we have | |
1404 | * to use hard-coded scancodes here... | |
1405 | */ | |
21677cfc JW |
1406 | if (abs(rel_y) > abs(rel_x)) { |
1407 | buf[2] = (rel_y > 0) ? 0x7F : 0x80; | |
1408 | buf[3] = 0; | |
eaf2bcc9 DH |
1409 | if (rel_y > 0) |
1410 | scancode = 0x01007f00; /* KEY_DOWN */ | |
1411 | else | |
1412 | scancode = 0x01008000; /* KEY_UP */ | |
21677cfc JW |
1413 | } else { |
1414 | buf[2] = 0; | |
1415 | buf[3] = (rel_x > 0) ? 0x7F : 0x80; | |
eaf2bcc9 DH |
1416 | if (rel_x > 0) |
1417 | scancode = 0x0100007f; /* KEY_RIGHT */ | |
1418 | else | |
1419 | scancode = 0x01000080; /* KEY_LEFT */ | |
21677cfc JW |
1420 | } |
1421 | } | |
1422 | } | |
eaf2bcc9 | 1423 | |
693508df JW |
1424 | if (scancode) { |
1425 | spin_lock_irqsave(&ictx->kc_lock, flags); | |
eaf2bcc9 | 1426 | ictx->kc = imon_remote_key_lookup(ictx, scancode); |
693508df JW |
1427 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
1428 | } | |
21677cfc JW |
1429 | } |
1430 | ||
eaf2bcc9 DH |
1431 | /** |
1432 | * figure out if these is a press or a release. We don't actually | |
1433 | * care about repeats, as those will be auto-generated within the IR | |
1434 | * subsystem for repeating scancodes. | |
1435 | */ | |
21677cfc JW |
1436 | static int imon_parse_press_type(struct imon_context *ictx, |
1437 | unsigned char *buf, u8 ktype) | |
1438 | { | |
1439 | int press_type = 0; | |
693508df JW |
1440 | unsigned long flags; |
1441 | ||
1442 | spin_lock_irqsave(&ictx->kc_lock, flags); | |
21677cfc JW |
1443 | |
1444 | /* key release of 0x02XXXXXX key */ | |
1445 | if (ictx->kc == KEY_RESERVED && buf[0] == 0x02 && buf[3] == 0x00) | |
1446 | ictx->kc = ictx->last_keycode; | |
1447 | ||
1448 | /* mouse button release on (some) 0xffdc devices */ | |
1449 | else if (ictx->kc == KEY_RESERVED && buf[0] == 0x68 && buf[1] == 0x82 && | |
1450 | buf[2] == 0x81 && buf[3] == 0xb7) | |
1451 | ictx->kc = ictx->last_keycode; | |
1452 | ||
1453 | /* mouse button release on (some other) 0xffdc devices */ | |
1454 | else if (ictx->kc == KEY_RESERVED && buf[0] == 0x01 && buf[1] == 0x00 && | |
1455 | buf[2] == 0x81 && buf[3] == 0xb7) | |
1456 | ictx->kc = ictx->last_keycode; | |
1457 | ||
eaf2bcc9 | 1458 | /* mce-specific button handling, no keyup events */ |
21677cfc | 1459 | else if (ktype == IMON_KEY_MCE) { |
eaf2bcc9 DH |
1460 | ictx->rc_toggle = buf[2]; |
1461 | press_type = 1; | |
21677cfc JW |
1462 | |
1463 | /* incoherent or irrelevant data */ | |
1464 | } else if (ictx->kc == KEY_RESERVED) | |
1465 | press_type = -EINVAL; | |
1466 | ||
1467 | /* key release of 0xXXXXXXb7 key */ | |
1468 | else if (ictx->release_code) | |
1469 | press_type = 0; | |
1470 | ||
1471 | /* this is a button press */ | |
1472 | else | |
1473 | press_type = 1; | |
1474 | ||
693508df JW |
1475 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
1476 | ||
21677cfc JW |
1477 | return press_type; |
1478 | } | |
1479 | ||
1480 | /** | |
1481 | * Process the incoming packet | |
1482 | */ | |
1483 | static void imon_incoming_packet(struct imon_context *ictx, | |
1484 | struct urb *urb, int intf) | |
1485 | { | |
1486 | int len = urb->actual_length; | |
1487 | unsigned char *buf = urb->transfer_buffer; | |
1488 | struct device *dev = ictx->dev; | |
693508df | 1489 | unsigned long flags; |
21677cfc | 1490 | u32 kc; |
21677cfc | 1491 | int i; |
eaf2bcc9 | 1492 | u64 scancode; |
21677cfc JW |
1493 | int press_type = 0; |
1494 | int msec; | |
1495 | struct timeval t; | |
1496 | static struct timeval prev_time = { 0, 0 }; | |
eaf2bcc9 | 1497 | u8 ktype; |
21677cfc | 1498 | |
21677cfc | 1499 | /* filter out junk data on the older 0xffdc imon devices */ |
bbe4690f | 1500 | if ((buf[0] == 0xff) && (buf[1] == 0xff) && (buf[2] == 0xff)) |
21677cfc JW |
1501 | return; |
1502 | ||
1503 | /* Figure out what key was pressed */ | |
21677cfc | 1504 | if (len == 8 && buf[7] == 0xee) { |
eaf2bcc9 | 1505 | scancode = be64_to_cpu(*((u64 *)buf)); |
21677cfc | 1506 | ktype = IMON_KEY_PANEL; |
eaf2bcc9 | 1507 | kc = imon_panel_key_lookup(scancode); |
21677cfc | 1508 | } else { |
eaf2bcc9 | 1509 | scancode = be32_to_cpu(*((u32 *)buf)); |
c003ab1b | 1510 | if (ictx->rc_type == RC_BIT_RC6_MCE) { |
eaf2bcc9 | 1511 | ktype = IMON_KEY_IMON; |
21677cfc JW |
1512 | if (buf[0] == 0x80) |
1513 | ktype = IMON_KEY_MCE; | |
eaf2bcc9 DH |
1514 | kc = imon_mce_key_lookup(ictx, scancode); |
1515 | } else { | |
1516 | ktype = IMON_KEY_IMON; | |
1517 | kc = imon_remote_key_lookup(ictx, scancode); | |
1518 | } | |
21677cfc JW |
1519 | } |
1520 | ||
693508df | 1521 | spin_lock_irqsave(&ictx->kc_lock, flags); |
21677cfc JW |
1522 | /* keyboard/mouse mode toggle button */ |
1523 | if (kc == KEY_KEYBOARD && !ictx->release_code) { | |
1524 | ictx->last_keycode = kc; | |
1525 | if (!nomouse) { | |
1526 | ictx->pad_mouse = ~(ictx->pad_mouse) & 0x1; | |
1527 | dev_dbg(dev, "toggling to %s mode\n", | |
1528 | ictx->pad_mouse ? "mouse" : "keyboard"); | |
693508df | 1529 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
21677cfc JW |
1530 | return; |
1531 | } else { | |
76f1ef42 | 1532 | ictx->pad_mouse = false; |
21677cfc JW |
1533 | dev_dbg(dev, "mouse mode disabled, passing key value\n"); |
1534 | } | |
1535 | } | |
1536 | ||
1537 | ictx->kc = kc; | |
693508df | 1538 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
21677cfc JW |
1539 | |
1540 | /* send touchscreen events through input subsystem if touchpad data */ | |
1541 | if (ictx->display_type == IMON_DISPLAY_TYPE_VGA && len == 8 && | |
1542 | buf[7] == 0x86) { | |
1543 | imon_touch_event(ictx, buf); | |
eaf2bcc9 | 1544 | return; |
21677cfc JW |
1545 | |
1546 | /* look for mouse events with pad in mouse mode */ | |
1547 | } else if (ictx->pad_mouse) { | |
1548 | if (imon_mouse_event(ictx, buf, len)) | |
1549 | return; | |
1550 | } | |
1551 | ||
1552 | /* Now for some special handling to convert pad input to arrow keys */ | |
1553 | if (((len == 5) && (buf[0] == 0x01) && (buf[4] == 0x00)) || | |
1554 | ((len == 8) && (buf[0] & 0x40) && | |
1555 | !(buf[1] & 0x1 || buf[1] >> 2 & 0x1))) { | |
1556 | len = 8; | |
1557 | imon_pad_to_keys(ictx, buf); | |
21677cfc JW |
1558 | } |
1559 | ||
1560 | if (debug) { | |
1561 | printk(KERN_INFO "intf%d decoded packet: ", intf); | |
1562 | for (i = 0; i < len; ++i) | |
1563 | printk("%02x ", buf[i]); | |
1564 | printk("\n"); | |
1565 | } | |
1566 | ||
1567 | press_type = imon_parse_press_type(ictx, buf, ktype); | |
1568 | if (press_type < 0) | |
1569 | goto not_input_data; | |
1570 | ||
693508df | 1571 | spin_lock_irqsave(&ictx->kc_lock, flags); |
21677cfc JW |
1572 | if (ictx->kc == KEY_UNKNOWN) |
1573 | goto unknown_key; | |
693508df | 1574 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
21677cfc | 1575 | |
eaf2bcc9 DH |
1576 | if (ktype != IMON_KEY_PANEL) { |
1577 | if (press_type == 0) | |
ca86674b | 1578 | rc_keyup(ictx->rdev); |
eaf2bcc9 | 1579 | else { |
ca86674b | 1580 | rc_keydown(ictx->rdev, ictx->rc_scancode, ictx->rc_toggle); |
693508df | 1581 | spin_lock_irqsave(&ictx->kc_lock, flags); |
eaf2bcc9 | 1582 | ictx->last_keycode = ictx->kc; |
693508df | 1583 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
eaf2bcc9 DH |
1584 | } |
1585 | return; | |
1586 | } | |
21677cfc | 1587 | |
eaf2bcc9 | 1588 | /* Only panel type events left to process now */ |
693508df JW |
1589 | spin_lock_irqsave(&ictx->kc_lock, flags); |
1590 | ||
94215ccd | 1591 | do_gettimeofday(&t); |
eaf2bcc9 DH |
1592 | /* KEY_MUTE repeats from knob need to be suppressed */ |
1593 | if (ictx->kc == KEY_MUTE && ictx->kc == ictx->last_keycode) { | |
21677cfc | 1594 | msec = tv2int(&t, &prev_time); |
428cc763 | 1595 | if (msec < ictx->idev->rep[REP_DELAY]) { |
693508df | 1596 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
21677cfc | 1597 | return; |
693508df | 1598 | } |
21677cfc | 1599 | } |
94215ccd | 1600 | prev_time = t; |
693508df | 1601 | kc = ictx->kc; |
21677cfc | 1602 | |
693508df | 1603 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
21677cfc | 1604 | |
428cc763 JW |
1605 | input_report_key(ictx->idev, kc, press_type); |
1606 | input_sync(ictx->idev); | |
21677cfc | 1607 | |
eaf2bcc9 | 1608 | /* panel keys don't generate a release */ |
428cc763 JW |
1609 | input_report_key(ictx->idev, kc, 0); |
1610 | input_sync(ictx->idev); | |
21677cfc | 1611 | |
94215ccd | 1612 | spin_lock_irqsave(&ictx->kc_lock, flags); |
693508df | 1613 | ictx->last_keycode = kc; |
94215ccd | 1614 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
21677cfc JW |
1615 | |
1616 | return; | |
1617 | ||
1618 | unknown_key: | |
693508df | 1619 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
21677cfc | 1620 | dev_info(dev, "%s: unknown keypress, code 0x%llx\n", __func__, |
eaf2bcc9 | 1621 | (long long)scancode); |
21677cfc JW |
1622 | return; |
1623 | ||
1624 | not_input_data: | |
1625 | if (len != 8) { | |
1626 | dev_warn(dev, "imon %s: invalid incoming packet " | |
1627 | "size (len = %d, intf%d)\n", __func__, len, intf); | |
1628 | return; | |
1629 | } | |
1630 | ||
1631 | /* iMON 2.4G associate frame */ | |
1632 | if (buf[0] == 0x00 && | |
1633 | buf[2] == 0xFF && /* REFID */ | |
1634 | buf[3] == 0xFF && | |
1635 | buf[4] == 0xFF && | |
1636 | buf[5] == 0xFF && /* iMON 2.4G */ | |
1637 | ((buf[6] == 0x4E && buf[7] == 0xDF) || /* LT */ | |
1638 | (buf[6] == 0x5E && buf[7] == 0xDF))) { /* DT */ | |
1639 | dev_warn(dev, "%s: remote associated refid=%02X\n", | |
1640 | __func__, buf[1]); | |
f789bf40 | 1641 | ictx->rf_isassociating = false; |
21677cfc JW |
1642 | } |
1643 | } | |
1644 | ||
1645 | /** | |
1646 | * Callback function for USB core API: receive data | |
1647 | */ | |
1648 | static void usb_rx_callback_intf0(struct urb *urb) | |
1649 | { | |
1650 | struct imon_context *ictx; | |
1651 | int intfnum = 0; | |
1652 | ||
1653 | if (!urb) | |
1654 | return; | |
1655 | ||
1656 | ictx = (struct imon_context *)urb->context; | |
8791d63a | 1657 | if (!ictx) |
21677cfc JW |
1658 | return; |
1659 | ||
8791d63a JW |
1660 | /* |
1661 | * if we get a callback before we're done configuring the hardware, we | |
1662 | * can't yet process the data, as there's nowhere to send it, but we | |
1663 | * still need to submit a new rx URB to avoid wedging the hardware | |
1664 | */ | |
1665 | if (!ictx->dev_present_intf0) | |
1666 | goto out; | |
1667 | ||
21677cfc JW |
1668 | switch (urb->status) { |
1669 | case -ENOENT: /* usbcore unlink successful! */ | |
1670 | return; | |
1671 | ||
1672 | case -ESHUTDOWN: /* transport endpoint was shut down */ | |
1673 | break; | |
1674 | ||
1675 | case 0: | |
1676 | imon_incoming_packet(ictx, urb, intfnum); | |
1677 | break; | |
1678 | ||
1679 | default: | |
1680 | dev_warn(ictx->dev, "imon %s: status(%d): ignored\n", | |
1681 | __func__, urb->status); | |
1682 | break; | |
1683 | } | |
1684 | ||
8791d63a | 1685 | out: |
21677cfc JW |
1686 | usb_submit_urb(ictx->rx_urb_intf0, GFP_ATOMIC); |
1687 | } | |
1688 | ||
1689 | static void usb_rx_callback_intf1(struct urb *urb) | |
1690 | { | |
1691 | struct imon_context *ictx; | |
1692 | int intfnum = 1; | |
1693 | ||
1694 | if (!urb) | |
1695 | return; | |
1696 | ||
1697 | ictx = (struct imon_context *)urb->context; | |
8791d63a | 1698 | if (!ictx) |
21677cfc JW |
1699 | return; |
1700 | ||
8791d63a JW |
1701 | /* |
1702 | * if we get a callback before we're done configuring the hardware, we | |
1703 | * can't yet process the data, as there's nowhere to send it, but we | |
1704 | * still need to submit a new rx URB to avoid wedging the hardware | |
1705 | */ | |
1706 | if (!ictx->dev_present_intf1) | |
1707 | goto out; | |
1708 | ||
21677cfc JW |
1709 | switch (urb->status) { |
1710 | case -ENOENT: /* usbcore unlink successful! */ | |
1711 | return; | |
1712 | ||
1713 | case -ESHUTDOWN: /* transport endpoint was shut down */ | |
1714 | break; | |
1715 | ||
1716 | case 0: | |
1717 | imon_incoming_packet(ictx, urb, intfnum); | |
1718 | break; | |
1719 | ||
1720 | default: | |
1721 | dev_warn(ictx->dev, "imon %s: status(%d): ignored\n", | |
1722 | __func__, urb->status); | |
1723 | break; | |
1724 | } | |
1725 | ||
8791d63a | 1726 | out: |
21677cfc JW |
1727 | usb_submit_urb(ictx->rx_urb_intf1, GFP_ATOMIC); |
1728 | } | |
1729 | ||
04292fc0 JW |
1730 | /* |
1731 | * The 0x15c2:0xffdc device ID was used for umpteen different imon | |
1732 | * devices, and all of them constantly spew interrupts, even when there | |
1733 | * is no actual data to report. However, byte 6 of this buffer looks like | |
1734 | * its unique across device variants, so we're trying to key off that to | |
1735 | * figure out which display type (if any) and what IR protocol the device | |
1736 | * actually supports. These devices have their IR protocol hard-coded into | |
1737 | * their firmware, they can't be changed on the fly like the newer hardware. | |
1738 | */ | |
1739 | static void imon_get_ffdc_type(struct imon_context *ictx) | |
1740 | { | |
1741 | u8 ffdc_cfg_byte = ictx->usb_rx_buf[6]; | |
1742 | u8 detected_display_type = IMON_DISPLAY_TYPE_NONE; | |
c003ab1b | 1743 | u64 allowed_protos = RC_BIT_OTHER; |
04292fc0 JW |
1744 | |
1745 | switch (ffdc_cfg_byte) { | |
1746 | /* iMON Knob, no display, iMON IR + vol knob */ | |
1747 | case 0x21: | |
1748 | dev_info(ictx->dev, "0xffdc iMON Knob, iMON IR"); | |
1749 | ictx->display_supported = false; | |
1750 | break; | |
1751 | /* iMON 2.4G LT (usb stick), no display, iMON RF */ | |
1752 | case 0x4e: | |
1753 | dev_info(ictx->dev, "0xffdc iMON 2.4G LT, iMON RF"); | |
1754 | ictx->display_supported = false; | |
1755 | ictx->rf_device = true; | |
1756 | break; | |
1757 | /* iMON VFD, no IR (does have vol knob tho) */ | |
1758 | case 0x35: | |
1759 | dev_info(ictx->dev, "0xffdc iMON VFD + knob, no IR"); | |
1760 | detected_display_type = IMON_DISPLAY_TYPE_VFD; | |
1761 | break; | |
1762 | /* iMON VFD, iMON IR */ | |
1763 | case 0x24: | |
1764 | case 0x85: | |
1765 | dev_info(ictx->dev, "0xffdc iMON VFD, iMON IR"); | |
1766 | detected_display_type = IMON_DISPLAY_TYPE_VFD; | |
1767 | break; | |
1768 | /* iMON VFD, MCE IR */ | |
443b3919 | 1769 | case 0x46: |
842071c9 | 1770 | case 0x7e: |
04292fc0 JW |
1771 | case 0x9e: |
1772 | dev_info(ictx->dev, "0xffdc iMON VFD, MCE IR"); | |
1773 | detected_display_type = IMON_DISPLAY_TYPE_VFD; | |
c003ab1b | 1774 | allowed_protos = RC_BIT_RC6_MCE; |
04292fc0 JW |
1775 | break; |
1776 | /* iMON LCD, MCE IR */ | |
1777 | case 0x9f: | |
1778 | dev_info(ictx->dev, "0xffdc iMON LCD, MCE IR"); | |
1779 | detected_display_type = IMON_DISPLAY_TYPE_LCD; | |
c003ab1b | 1780 | allowed_protos = RC_BIT_RC6_MCE; |
04292fc0 JW |
1781 | break; |
1782 | default: | |
1783 | dev_info(ictx->dev, "Unknown 0xffdc device, " | |
1784 | "defaulting to VFD and iMON IR"); | |
1785 | detected_display_type = IMON_DISPLAY_TYPE_VFD; | |
372b4249 JW |
1786 | /* We don't know which one it is, allow user to set the |
1787 | * RC6 one from userspace if OTHER wasn't correct. */ | |
c003ab1b | 1788 | allowed_protos |= RC_BIT_RC6_MCE; |
04292fc0 JW |
1789 | break; |
1790 | } | |
1791 | ||
1792 | printk(KERN_CONT " (id 0x%02x)\n", ffdc_cfg_byte); | |
1793 | ||
1794 | ictx->display_type = detected_display_type; | |
52b66144 | 1795 | ictx->rc_type = allowed_protos; |
04292fc0 JW |
1796 | } |
1797 | ||
1798 | static void imon_set_display_type(struct imon_context *ictx) | |
1799 | { | |
1800 | u8 configured_display_type = IMON_DISPLAY_TYPE_VFD; | |
1801 | ||
1802 | /* | |
1803 | * Try to auto-detect the type of display if the user hasn't set | |
1804 | * it by hand via the display_type modparam. Default is VFD. | |
1805 | */ | |
1806 | ||
1807 | if (display_type == IMON_DISPLAY_TYPE_AUTO) { | |
1808 | switch (ictx->product) { | |
1809 | case 0xffdc: | |
1810 | /* set in imon_get_ffdc_type() */ | |
1811 | configured_display_type = ictx->display_type; | |
1812 | break; | |
1813 | case 0x0034: | |
1814 | case 0x0035: | |
1815 | configured_display_type = IMON_DISPLAY_TYPE_VGA; | |
1816 | break; | |
1817 | case 0x0038: | |
1818 | case 0x0039: | |
1819 | case 0x0045: | |
1820 | configured_display_type = IMON_DISPLAY_TYPE_LCD; | |
1821 | break; | |
1822 | case 0x003c: | |
1823 | case 0x0041: | |
1824 | case 0x0042: | |
1825 | case 0x0043: | |
1826 | configured_display_type = IMON_DISPLAY_TYPE_NONE; | |
1827 | ictx->display_supported = false; | |
1828 | break; | |
1829 | case 0x0036: | |
1830 | case 0x0044: | |
1831 | default: | |
1832 | configured_display_type = IMON_DISPLAY_TYPE_VFD; | |
1833 | break; | |
1834 | } | |
1835 | } else { | |
1836 | configured_display_type = display_type; | |
1837 | if (display_type == IMON_DISPLAY_TYPE_NONE) | |
1838 | ictx->display_supported = false; | |
1839 | else | |
1840 | ictx->display_supported = true; | |
1841 | dev_info(ictx->dev, "%s: overriding display type to %d via " | |
1842 | "modparam\n", __func__, display_type); | |
1843 | } | |
1844 | ||
1845 | ictx->display_type = configured_display_type; | |
1846 | } | |
1847 | ||
d8b4b582 | 1848 | static struct rc_dev *imon_init_rdev(struct imon_context *ictx) |
eaf2bcc9 | 1849 | { |
d8b4b582 | 1850 | struct rc_dev *rdev; |
eaf2bcc9 | 1851 | int ret; |
04292fc0 JW |
1852 | const unsigned char fp_packet[] = { 0x40, 0x00, 0x00, 0x00, |
1853 | 0x00, 0x00, 0x00, 0x88 }; | |
eaf2bcc9 | 1854 | |
d8b4b582 DH |
1855 | rdev = rc_allocate_device(); |
1856 | if (!rdev) { | |
eaf2bcc9 DH |
1857 | dev_err(ictx->dev, "remote control dev allocation failed\n"); |
1858 | goto out; | |
1859 | } | |
1860 | ||
1861 | snprintf(ictx->name_rdev, sizeof(ictx->name_rdev), | |
1862 | "iMON Remote (%04x:%04x)", ictx->vendor, ictx->product); | |
1863 | usb_make_path(ictx->usbdev_intf0, ictx->phys_rdev, | |
1864 | sizeof(ictx->phys_rdev)); | |
1865 | strlcat(ictx->phys_rdev, "/input0", sizeof(ictx->phys_rdev)); | |
1866 | ||
d8b4b582 DH |
1867 | rdev->input_name = ictx->name_rdev; |
1868 | rdev->input_phys = ictx->phys_rdev; | |
1869 | usb_to_input_id(ictx->usbdev_intf0, &rdev->input_id); | |
eaf2bcc9 | 1870 | rdev->dev.parent = ictx->dev; |
eaf2bcc9 | 1871 | |
d8b4b582 DH |
1872 | rdev->priv = ictx; |
1873 | rdev->driver_type = RC_DRIVER_SCANCODE; | |
c003ab1b | 1874 | rdev->allowed_protos = RC_BIT_OTHER | RC_BIT_RC6_MCE; /* iMON PAD or MCE */ |
d8b4b582 DH |
1875 | rdev->change_protocol = imon_ir_change_protocol; |
1876 | rdev->driver_name = MOD_NAME; | |
eaf2bcc9 | 1877 | |
04292fc0 JW |
1878 | /* Enable front-panel buttons and/or knobs */ |
1879 | memcpy(ictx->usb_tx_buf, &fp_packet, sizeof(fp_packet)); | |
1880 | ret = send_packet(ictx); | |
1881 | /* Not fatal, but warn about it */ | |
1882 | if (ret) | |
1883 | dev_info(ictx->dev, "panel buttons/knobs setup failed\n"); | |
1884 | ||
7d2edfc2 | 1885 | if (ictx->product == 0xffdc) { |
04292fc0 | 1886 | imon_get_ffdc_type(ictx); |
7d2edfc2 JW |
1887 | rdev->allowed_protos = ictx->rc_type; |
1888 | } | |
04292fc0 JW |
1889 | |
1890 | imon_set_display_type(ictx); | |
1891 | ||
c003ab1b | 1892 | if (ictx->rc_type == RC_BIT_RC6_MCE) |
7d2edfc2 JW |
1893 | rdev->map_name = RC_MAP_IMON_MCE; |
1894 | else | |
1895 | rdev->map_name = RC_MAP_IMON_PAD; | |
1896 | ||
d8b4b582 | 1897 | ret = rc_register_device(rdev); |
eaf2bcc9 DH |
1898 | if (ret < 0) { |
1899 | dev_err(ictx->dev, "remote input dev register failed\n"); | |
1900 | goto out; | |
1901 | } | |
1902 | ||
1903 | return rdev; | |
1904 | ||
1905 | out: | |
d8b4b582 | 1906 | rc_free_device(rdev); |
eaf2bcc9 DH |
1907 | return NULL; |
1908 | } | |
1909 | ||
21677cfc JW |
1910 | static struct input_dev *imon_init_idev(struct imon_context *ictx) |
1911 | { | |
1912 | struct input_dev *idev; | |
21677cfc | 1913 | int ret, i; |
21677cfc JW |
1914 | |
1915 | idev = input_allocate_device(); | |
1916 | if (!idev) { | |
eaf2bcc9 DH |
1917 | dev_err(ictx->dev, "input dev allocation failed\n"); |
1918 | goto out; | |
21677cfc JW |
1919 | } |
1920 | ||
21677cfc | 1921 | snprintf(ictx->name_idev, sizeof(ictx->name_idev), |
eaf2bcc9 DH |
1922 | "iMON Panel, Knob and Mouse(%04x:%04x)", |
1923 | ictx->vendor, ictx->product); | |
21677cfc JW |
1924 | idev->name = ictx->name_idev; |
1925 | ||
1926 | usb_make_path(ictx->usbdev_intf0, ictx->phys_idev, | |
1927 | sizeof(ictx->phys_idev)); | |
eaf2bcc9 | 1928 | strlcat(ictx->phys_idev, "/input1", sizeof(ictx->phys_idev)); |
21677cfc JW |
1929 | idev->phys = ictx->phys_idev; |
1930 | ||
db190fc1 | 1931 | idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | BIT_MASK(EV_REL); |
21677cfc JW |
1932 | |
1933 | idev->keybit[BIT_WORD(BTN_MOUSE)] = | |
1934 | BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT); | |
1935 | idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y) | | |
1936 | BIT_MASK(REL_WHEEL); | |
1937 | ||
1938 | /* panel and/or knob code support */ | |
1939 | for (i = 0; i < ARRAY_SIZE(imon_panel_key_table); i++) { | |
1940 | u32 kc = imon_panel_key_table[i].keycode; | |
1941 | __set_bit(kc, idev->keybit); | |
1942 | } | |
1943 | ||
21677cfc JW |
1944 | usb_to_input_id(ictx->usbdev_intf0, &idev->id); |
1945 | idev->dev.parent = ictx->dev; | |
eaf2bcc9 | 1946 | input_set_drvdata(idev, ictx); |
21677cfc | 1947 | |
eaf2bcc9 | 1948 | ret = input_register_device(idev); |
21677cfc | 1949 | if (ret < 0) { |
eaf2bcc9 DH |
1950 | dev_err(ictx->dev, "input dev register failed\n"); |
1951 | goto out; | |
21677cfc JW |
1952 | } |
1953 | ||
1954 | return idev; | |
1955 | ||
eaf2bcc9 | 1956 | out: |
21677cfc | 1957 | input_free_device(idev); |
21677cfc JW |
1958 | return NULL; |
1959 | } | |
1960 | ||
1961 | static struct input_dev *imon_init_touch(struct imon_context *ictx) | |
1962 | { | |
1963 | struct input_dev *touch; | |
1964 | int ret; | |
1965 | ||
1966 | touch = input_allocate_device(); | |
1967 | if (!touch) { | |
1968 | dev_err(ictx->dev, "touchscreen input dev allocation failed\n"); | |
1969 | goto touch_alloc_failed; | |
1970 | } | |
1971 | ||
1972 | snprintf(ictx->name_touch, sizeof(ictx->name_touch), | |
1973 | "iMON USB Touchscreen (%04x:%04x)", | |
1974 | ictx->vendor, ictx->product); | |
1975 | touch->name = ictx->name_touch; | |
1976 | ||
1977 | usb_make_path(ictx->usbdev_intf1, ictx->phys_touch, | |
1978 | sizeof(ictx->phys_touch)); | |
eaf2bcc9 | 1979 | strlcat(ictx->phys_touch, "/input2", sizeof(ictx->phys_touch)); |
21677cfc JW |
1980 | touch->phys = ictx->phys_touch; |
1981 | ||
1982 | touch->evbit[0] = | |
1983 | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); | |
1984 | touch->keybit[BIT_WORD(BTN_TOUCH)] = | |
1985 | BIT_MASK(BTN_TOUCH); | |
1986 | input_set_abs_params(touch, ABS_X, | |
1987 | 0x00, 0xfff, 0, 0); | |
1988 | input_set_abs_params(touch, ABS_Y, | |
1989 | 0x00, 0xfff, 0, 0); | |
1990 | ||
1991 | input_set_drvdata(touch, ictx); | |
1992 | ||
1993 | usb_to_input_id(ictx->usbdev_intf1, &touch->id); | |
1994 | touch->dev.parent = ictx->dev; | |
1995 | ret = input_register_device(touch); | |
1996 | if (ret < 0) { | |
1997 | dev_info(ictx->dev, "touchscreen input dev register failed\n"); | |
1998 | goto touch_register_failed; | |
1999 | } | |
2000 | ||
2001 | return touch; | |
2002 | ||
2003 | touch_register_failed: | |
aeb35ebc | 2004 | input_free_device(touch); |
21677cfc JW |
2005 | |
2006 | touch_alloc_failed: | |
2007 | return NULL; | |
2008 | } | |
2009 | ||
2010 | static bool imon_find_endpoints(struct imon_context *ictx, | |
2011 | struct usb_host_interface *iface_desc) | |
2012 | { | |
2013 | struct usb_endpoint_descriptor *ep; | |
2014 | struct usb_endpoint_descriptor *rx_endpoint = NULL; | |
2015 | struct usb_endpoint_descriptor *tx_endpoint = NULL; | |
2016 | int ifnum = iface_desc->desc.bInterfaceNumber; | |
2017 | int num_endpts = iface_desc->desc.bNumEndpoints; | |
2018 | int i, ep_dir, ep_type; | |
f789bf40 JW |
2019 | bool ir_ep_found = false; |
2020 | bool display_ep_found = false; | |
2021 | bool tx_control = false; | |
21677cfc JW |
2022 | |
2023 | /* | |
2024 | * Scan the endpoint list and set: | |
2025 | * first input endpoint = IR endpoint | |
2026 | * first output endpoint = display endpoint | |
2027 | */ | |
2028 | for (i = 0; i < num_endpts && !(ir_ep_found && display_ep_found); ++i) { | |
2029 | ep = &iface_desc->endpoint[i].desc; | |
2030 | ep_dir = ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK; | |
2031 | ep_type = ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; | |
2032 | ||
2033 | if (!ir_ep_found && ep_dir == USB_DIR_IN && | |
2034 | ep_type == USB_ENDPOINT_XFER_INT) { | |
2035 | ||
2036 | rx_endpoint = ep; | |
f789bf40 | 2037 | ir_ep_found = true; |
21677cfc JW |
2038 | dev_dbg(ictx->dev, "%s: found IR endpoint\n", __func__); |
2039 | ||
2040 | } else if (!display_ep_found && ep_dir == USB_DIR_OUT && | |
2041 | ep_type == USB_ENDPOINT_XFER_INT) { | |
2042 | tx_endpoint = ep; | |
f789bf40 | 2043 | display_ep_found = true; |
21677cfc JW |
2044 | dev_dbg(ictx->dev, "%s: found display endpoint\n", __func__); |
2045 | } | |
2046 | } | |
2047 | ||
2048 | if (ifnum == 0) { | |
2049 | ictx->rx_endpoint_intf0 = rx_endpoint; | |
2050 | /* | |
2051 | * tx is used to send characters to lcd/vfd, associate RF | |
2052 | * remotes, set IR protocol, and maybe more... | |
2053 | */ | |
2054 | ictx->tx_endpoint = tx_endpoint; | |
2055 | } else { | |
2056 | ictx->rx_endpoint_intf1 = rx_endpoint; | |
2057 | } | |
2058 | ||
2059 | /* | |
2060 | * If we didn't find a display endpoint, this is probably one of the | |
2061 | * newer iMON devices that use control urb instead of interrupt | |
2062 | */ | |
2063 | if (!display_ep_found) { | |
f789bf40 JW |
2064 | tx_control = true; |
2065 | display_ep_found = true; | |
21677cfc JW |
2066 | dev_dbg(ictx->dev, "%s: device uses control endpoint, not " |
2067 | "interface OUT endpoint\n", __func__); | |
2068 | } | |
2069 | ||
2070 | /* | |
2071 | * Some iMON receivers have no display. Unfortunately, it seems | |
2072 | * that SoundGraph recycles device IDs between devices both with | |
2073 | * and without... :\ | |
2074 | */ | |
2075 | if (ictx->display_type == IMON_DISPLAY_TYPE_NONE) { | |
f789bf40 | 2076 | display_ep_found = false; |
21677cfc JW |
2077 | dev_dbg(ictx->dev, "%s: device has no display\n", __func__); |
2078 | } | |
2079 | ||
2080 | /* | |
2081 | * iMON Touch devices have a VGA touchscreen, but no "display", as | |
2082 | * that refers to e.g. /dev/lcd0 (a character device LCD or VFD). | |
2083 | */ | |
2084 | if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) { | |
f789bf40 | 2085 | display_ep_found = false; |
21677cfc JW |
2086 | dev_dbg(ictx->dev, "%s: iMON Touch device found\n", __func__); |
2087 | } | |
2088 | ||
2089 | /* Input endpoint is mandatory */ | |
2090 | if (!ir_ep_found) | |
e2302501 | 2091 | pr_err("no valid input (IR) endpoint found\n"); |
21677cfc JW |
2092 | |
2093 | ictx->tx_control = tx_control; | |
2094 | ||
2095 | if (display_ep_found) | |
2096 | ictx->display_supported = true; | |
2097 | ||
2098 | return ir_ep_found; | |
2099 | ||
2100 | } | |
2101 | ||
2102 | static struct imon_context *imon_init_intf0(struct usb_interface *intf) | |
2103 | { | |
2104 | struct imon_context *ictx; | |
2105 | struct urb *rx_urb; | |
2106 | struct urb *tx_urb; | |
2107 | struct device *dev = &intf->dev; | |
2108 | struct usb_host_interface *iface_desc; | |
1f71baef | 2109 | int ret = -ENOMEM; |
21677cfc JW |
2110 | |
2111 | ictx = kzalloc(sizeof(struct imon_context), GFP_KERNEL); | |
2112 | if (!ictx) { | |
2113 | dev_err(dev, "%s: kzalloc failed for context", __func__); | |
2114 | goto exit; | |
2115 | } | |
2116 | rx_urb = usb_alloc_urb(0, GFP_KERNEL); | |
2117 | if (!rx_urb) { | |
2118 | dev_err(dev, "%s: usb_alloc_urb failed for IR urb", __func__); | |
2119 | goto rx_urb_alloc_failed; | |
2120 | } | |
2121 | tx_urb = usb_alloc_urb(0, GFP_KERNEL); | |
2122 | if (!tx_urb) { | |
2123 | dev_err(dev, "%s: usb_alloc_urb failed for display urb", | |
2124 | __func__); | |
2125 | goto tx_urb_alloc_failed; | |
2126 | } | |
2127 | ||
2128 | mutex_init(&ictx->lock); | |
693508df | 2129 | spin_lock_init(&ictx->kc_lock); |
21677cfc JW |
2130 | |
2131 | mutex_lock(&ictx->lock); | |
2132 | ||
2133 | ictx->dev = dev; | |
2134 | ictx->usbdev_intf0 = usb_get_dev(interface_to_usbdev(intf)); | |
21677cfc JW |
2135 | ictx->rx_urb_intf0 = rx_urb; |
2136 | ictx->tx_urb = tx_urb; | |
bbe4690f | 2137 | ictx->rf_device = false; |
21677cfc JW |
2138 | |
2139 | ictx->vendor = le16_to_cpu(ictx->usbdev_intf0->descriptor.idVendor); | |
2140 | ictx->product = le16_to_cpu(ictx->usbdev_intf0->descriptor.idProduct); | |
2141 | ||
1f71baef | 2142 | ret = -ENODEV; |
21677cfc | 2143 | iface_desc = intf->cur_altsetting; |
1f71baef | 2144 | if (!imon_find_endpoints(ictx, iface_desc)) { |
21677cfc | 2145 | goto find_endpoint_failed; |
1f71baef | 2146 | } |
21677cfc | 2147 | |
21677cfc JW |
2148 | usb_fill_int_urb(ictx->rx_urb_intf0, ictx->usbdev_intf0, |
2149 | usb_rcvintpipe(ictx->usbdev_intf0, | |
2150 | ictx->rx_endpoint_intf0->bEndpointAddress), | |
2151 | ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf), | |
2152 | usb_rx_callback_intf0, ictx, | |
2153 | ictx->rx_endpoint_intf0->bInterval); | |
2154 | ||
2155 | ret = usb_submit_urb(ictx->rx_urb_intf0, GFP_KERNEL); | |
2156 | if (ret) { | |
e2302501 | 2157 | pr_err("usb_submit_urb failed for intf0 (%d)\n", ret); |
21677cfc JW |
2158 | goto urb_submit_failed; |
2159 | } | |
2160 | ||
9ad77eb5 JW |
2161 | ictx->idev = imon_init_idev(ictx); |
2162 | if (!ictx->idev) { | |
2163 | dev_err(dev, "%s: input device setup failed\n", __func__); | |
2164 | goto idev_setup_failed; | |
2165 | } | |
2166 | ||
2167 | ictx->rdev = imon_init_rdev(ictx); | |
2168 | if (!ictx->rdev) { | |
2169 | dev_err(dev, "%s: rc device setup failed\n", __func__); | |
2170 | goto rdev_setup_failed; | |
2171 | } | |
2172 | ||
6f6b90c9 JW |
2173 | ictx->dev_present_intf0 = true; |
2174 | ||
23ef710e | 2175 | mutex_unlock(&ictx->lock); |
21677cfc JW |
2176 | return ictx; |
2177 | ||
eaf2bcc9 DH |
2178 | rdev_setup_failed: |
2179 | input_unregister_device(ictx->idev); | |
21677cfc | 2180 | idev_setup_failed: |
9ad77eb5 JW |
2181 | usb_kill_urb(ictx->rx_urb_intf0); |
2182 | urb_submit_failed: | |
21677cfc JW |
2183 | find_endpoint_failed: |
2184 | mutex_unlock(&ictx->lock); | |
2185 | usb_free_urb(tx_urb); | |
2186 | tx_urb_alloc_failed: | |
2187 | usb_free_urb(rx_urb); | |
2188 | rx_urb_alloc_failed: | |
2189 | kfree(ictx); | |
2190 | exit: | |
2191 | dev_err(dev, "unable to initialize intf0, err %d\n", ret); | |
2192 | ||
2193 | return NULL; | |
2194 | } | |
2195 | ||
2196 | static struct imon_context *imon_init_intf1(struct usb_interface *intf, | |
2197 | struct imon_context *ictx) | |
2198 | { | |
2199 | struct urb *rx_urb; | |
2200 | struct usb_host_interface *iface_desc; | |
1f71baef | 2201 | int ret = -ENOMEM; |
21677cfc JW |
2202 | |
2203 | rx_urb = usb_alloc_urb(0, GFP_KERNEL); | |
2204 | if (!rx_urb) { | |
e2302501 | 2205 | pr_err("usb_alloc_urb failed for IR urb\n"); |
21677cfc JW |
2206 | goto rx_urb_alloc_failed; |
2207 | } | |
2208 | ||
2209 | mutex_lock(&ictx->lock); | |
2210 | ||
2211 | if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) { | |
2212 | init_timer(&ictx->ttimer); | |
2213 | ictx->ttimer.data = (unsigned long)ictx; | |
2214 | ictx->ttimer.function = imon_touch_display_timeout; | |
2215 | } | |
2216 | ||
2217 | ictx->usbdev_intf1 = usb_get_dev(interface_to_usbdev(intf)); | |
21677cfc JW |
2218 | ictx->rx_urb_intf1 = rx_urb; |
2219 | ||
1f71baef | 2220 | ret = -ENODEV; |
21677cfc JW |
2221 | iface_desc = intf->cur_altsetting; |
2222 | if (!imon_find_endpoints(ictx, iface_desc)) | |
2223 | goto find_endpoint_failed; | |
2224 | ||
2225 | if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) { | |
2226 | ictx->touch = imon_init_touch(ictx); | |
2227 | if (!ictx->touch) | |
2228 | goto touch_setup_failed; | |
2229 | } else | |
2230 | ictx->touch = NULL; | |
2231 | ||
2232 | usb_fill_int_urb(ictx->rx_urb_intf1, ictx->usbdev_intf1, | |
2233 | usb_rcvintpipe(ictx->usbdev_intf1, | |
2234 | ictx->rx_endpoint_intf1->bEndpointAddress), | |
2235 | ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf), | |
2236 | usb_rx_callback_intf1, ictx, | |
2237 | ictx->rx_endpoint_intf1->bInterval); | |
2238 | ||
2239 | ret = usb_submit_urb(ictx->rx_urb_intf1, GFP_KERNEL); | |
2240 | ||
2241 | if (ret) { | |
e2302501 | 2242 | pr_err("usb_submit_urb failed for intf1 (%d)\n", ret); |
21677cfc JW |
2243 | goto urb_submit_failed; |
2244 | } | |
2245 | ||
6f6b90c9 JW |
2246 | ictx->dev_present_intf1 = true; |
2247 | ||
23ef710e | 2248 | mutex_unlock(&ictx->lock); |
21677cfc JW |
2249 | return ictx; |
2250 | ||
2251 | urb_submit_failed: | |
20cd1959 | 2252 | if (ictx->touch) |
21677cfc | 2253 | input_unregister_device(ictx->touch); |
21677cfc JW |
2254 | touch_setup_failed: |
2255 | find_endpoint_failed: | |
2256 | mutex_unlock(&ictx->lock); | |
2257 | usb_free_urb(rx_urb); | |
2258 | rx_urb_alloc_failed: | |
8791d63a | 2259 | dev_err(ictx->dev, "unable to initialize intf1, err %d\n", ret); |
21677cfc JW |
2260 | |
2261 | return NULL; | |
2262 | } | |
2263 | ||
21677cfc JW |
2264 | static void imon_init_display(struct imon_context *ictx, |
2265 | struct usb_interface *intf) | |
2266 | { | |
2267 | int ret; | |
2268 | ||
2269 | dev_dbg(ictx->dev, "Registering iMON display with sysfs\n"); | |
2270 | ||
2271 | /* set up sysfs entry for built-in clock */ | |
6aa209e4 | 2272 | ret = sysfs_create_group(&intf->dev.kobj, &imon_display_attr_group); |
21677cfc JW |
2273 | if (ret) |
2274 | dev_err(ictx->dev, "Could not create display sysfs " | |
2275 | "entries(%d)", ret); | |
2276 | ||
2277 | if (ictx->display_type == IMON_DISPLAY_TYPE_LCD) | |
2278 | ret = usb_register_dev(intf, &imon_lcd_class); | |
2279 | else | |
2280 | ret = usb_register_dev(intf, &imon_vfd_class); | |
2281 | if (ret) | |
2282 | /* Not a fatal error, so ignore */ | |
2283 | dev_info(ictx->dev, "could not get a minor number for " | |
2284 | "display\n"); | |
2285 | ||
2286 | } | |
2287 | ||
2288 | /** | |
2289 | * Callback function for USB core API: Probe | |
2290 | */ | |
4c62e976 GKH |
2291 | static int imon_probe(struct usb_interface *interface, |
2292 | const struct usb_device_id *id) | |
21677cfc JW |
2293 | { |
2294 | struct usb_device *usbdev = NULL; | |
2295 | struct usb_host_interface *iface_desc = NULL; | |
2296 | struct usb_interface *first_if; | |
2297 | struct device *dev = &interface->dev; | |
76a2d21d | 2298 | int ifnum, sysfs_err; |
21677cfc JW |
2299 | int ret = 0; |
2300 | struct imon_context *ictx = NULL; | |
2301 | struct imon_context *first_if_ctx = NULL; | |
2302 | u16 vendor, product; | |
21677cfc | 2303 | |
21677cfc JW |
2304 | usbdev = usb_get_dev(interface_to_usbdev(interface)); |
2305 | iface_desc = interface->cur_altsetting; | |
2306 | ifnum = iface_desc->desc.bInterfaceNumber; | |
2307 | vendor = le16_to_cpu(usbdev->descriptor.idVendor); | |
2308 | product = le16_to_cpu(usbdev->descriptor.idProduct); | |
2309 | ||
2310 | dev_dbg(dev, "%s: found iMON device (%04x:%04x, intf%d)\n", | |
2311 | __func__, vendor, product, ifnum); | |
2312 | ||
2313 | /* prevent races probing devices w/multiple interfaces */ | |
2314 | mutex_lock(&driver_lock); | |
2315 | ||
2316 | first_if = usb_ifnum_to_if(usbdev, 0); | |
8350e155 | 2317 | first_if_ctx = usb_get_intfdata(first_if); |
21677cfc JW |
2318 | |
2319 | if (ifnum == 0) { | |
2320 | ictx = imon_init_intf0(interface); | |
2321 | if (!ictx) { | |
e2302501 | 2322 | pr_err("failed to initialize context!\n"); |
21677cfc JW |
2323 | ret = -ENODEV; |
2324 | goto fail; | |
2325 | } | |
2326 | ||
21677cfc JW |
2327 | } else { |
2328 | /* this is the secondary interface on the device */ | |
2329 | ictx = imon_init_intf1(interface, first_if_ctx); | |
2330 | if (!ictx) { | |
e2302501 | 2331 | pr_err("failed to attach to context!\n"); |
21677cfc JW |
2332 | ret = -ENODEV; |
2333 | goto fail; | |
2334 | } | |
2335 | ||
2336 | } | |
2337 | ||
2338 | usb_set_intfdata(interface, ictx); | |
2339 | ||
2340 | if (ifnum == 0) { | |
23ef710e JW |
2341 | mutex_lock(&ictx->lock); |
2342 | ||
bbe4690f JW |
2343 | if (product == 0xffdc && ictx->rf_device) { |
2344 | sysfs_err = sysfs_create_group(&interface->dev.kobj, | |
6aa209e4 | 2345 | &imon_rf_attr_group); |
bbe4690f | 2346 | if (sysfs_err) |
e2302501 JP |
2347 | pr_err("Could not create RF sysfs entries(%d)\n", |
2348 | sysfs_err); | |
bbe4690f JW |
2349 | } |
2350 | ||
21677cfc JW |
2351 | if (ictx->display_supported) |
2352 | imon_init_display(ictx, interface); | |
23ef710e JW |
2353 | |
2354 | mutex_unlock(&ictx->lock); | |
21677cfc JW |
2355 | } |
2356 | ||
21677cfc JW |
2357 | dev_info(dev, "iMON device (%04x:%04x, intf%d) on " |
2358 | "usb<%d:%d> initialized\n", vendor, product, ifnum, | |
2359 | usbdev->bus->busnum, usbdev->devnum); | |
2360 | ||
21677cfc JW |
2361 | mutex_unlock(&driver_lock); |
2362 | ||
2363 | return 0; | |
2364 | ||
2365 | fail: | |
2366 | mutex_unlock(&driver_lock); | |
2367 | dev_err(dev, "unable to register, err %d\n", ret); | |
2368 | ||
2369 | return ret; | |
2370 | } | |
2371 | ||
2372 | /** | |
2373 | * Callback function for USB core API: disconnect | |
2374 | */ | |
4c62e976 | 2375 | static void imon_disconnect(struct usb_interface *interface) |
21677cfc JW |
2376 | { |
2377 | struct imon_context *ictx; | |
2378 | struct device *dev; | |
2379 | int ifnum; | |
2380 | ||
2381 | /* prevent races with multi-interface device probing and display_open */ | |
2382 | mutex_lock(&driver_lock); | |
2383 | ||
2384 | ictx = usb_get_intfdata(interface); | |
2385 | dev = ictx->dev; | |
2386 | ifnum = interface->cur_altsetting->desc.bInterfaceNumber; | |
2387 | ||
21677cfc JW |
2388 | /* |
2389 | * sysfs_remove_group is safe to call even if sysfs_create_group | |
2390 | * hasn't been called | |
2391 | */ | |
6aa209e4 JW |
2392 | sysfs_remove_group(&interface->dev.kobj, &imon_display_attr_group); |
2393 | sysfs_remove_group(&interface->dev.kobj, &imon_rf_attr_group); | |
21677cfc JW |
2394 | |
2395 | usb_set_intfdata(interface, NULL); | |
2396 | ||
2397 | /* Abort ongoing write */ | |
2398 | if (ictx->tx.busy) { | |
2399 | usb_kill_urb(ictx->tx_urb); | |
2400 | complete_all(&ictx->tx.finished); | |
2401 | } | |
2402 | ||
2403 | if (ifnum == 0) { | |
f789bf40 | 2404 | ictx->dev_present_intf0 = false; |
21677cfc | 2405 | usb_kill_urb(ictx->rx_urb_intf0); |
eaf2bcc9 | 2406 | input_unregister_device(ictx->idev); |
d8b4b582 | 2407 | rc_unregister_device(ictx->rdev); |
21677cfc JW |
2408 | if (ictx->display_supported) { |
2409 | if (ictx->display_type == IMON_DISPLAY_TYPE_LCD) | |
2410 | usb_deregister_dev(interface, &imon_lcd_class); | |
76a2d21d | 2411 | else if (ictx->display_type == IMON_DISPLAY_TYPE_VFD) |
21677cfc JW |
2412 | usb_deregister_dev(interface, &imon_vfd_class); |
2413 | } | |
2414 | } else { | |
f789bf40 | 2415 | ictx->dev_present_intf1 = false; |
21677cfc | 2416 | usb_kill_urb(ictx->rx_urb_intf1); |
76a2d21d | 2417 | if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) { |
21677cfc | 2418 | input_unregister_device(ictx->touch); |
76a2d21d JW |
2419 | del_timer_sync(&ictx->ttimer); |
2420 | } | |
21677cfc JW |
2421 | } |
2422 | ||
76a2d21d JW |
2423 | if (!ictx->dev_present_intf0 && !ictx->dev_present_intf1) |
2424 | free_imon_context(ictx); | |
21677cfc JW |
2425 | |
2426 | mutex_unlock(&driver_lock); | |
2427 | ||
2428 | dev_dbg(dev, "%s: iMON device (intf%d) disconnected\n", | |
2429 | __func__, ifnum); | |
2430 | } | |
2431 | ||
2432 | static int imon_suspend(struct usb_interface *intf, pm_message_t message) | |
2433 | { | |
2434 | struct imon_context *ictx = usb_get_intfdata(intf); | |
2435 | int ifnum = intf->cur_altsetting->desc.bInterfaceNumber; | |
2436 | ||
2437 | if (ifnum == 0) | |
2438 | usb_kill_urb(ictx->rx_urb_intf0); | |
2439 | else | |
2440 | usb_kill_urb(ictx->rx_urb_intf1); | |
2441 | ||
2442 | return 0; | |
2443 | } | |
2444 | ||
2445 | static int imon_resume(struct usb_interface *intf) | |
2446 | { | |
2447 | int rc = 0; | |
2448 | struct imon_context *ictx = usb_get_intfdata(intf); | |
2449 | int ifnum = intf->cur_altsetting->desc.bInterfaceNumber; | |
2450 | ||
2451 | if (ifnum == 0) { | |
2452 | usb_fill_int_urb(ictx->rx_urb_intf0, ictx->usbdev_intf0, | |
2453 | usb_rcvintpipe(ictx->usbdev_intf0, | |
2454 | ictx->rx_endpoint_intf0->bEndpointAddress), | |
2455 | ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf), | |
2456 | usb_rx_callback_intf0, ictx, | |
2457 | ictx->rx_endpoint_intf0->bInterval); | |
2458 | ||
2459 | rc = usb_submit_urb(ictx->rx_urb_intf0, GFP_ATOMIC); | |
2460 | ||
2461 | } else { | |
2462 | usb_fill_int_urb(ictx->rx_urb_intf1, ictx->usbdev_intf1, | |
2463 | usb_rcvintpipe(ictx->usbdev_intf1, | |
2464 | ictx->rx_endpoint_intf1->bEndpointAddress), | |
2465 | ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf), | |
2466 | usb_rx_callback_intf1, ictx, | |
2467 | ictx->rx_endpoint_intf1->bInterval); | |
2468 | ||
2469 | rc = usb_submit_urb(ictx->rx_urb_intf1, GFP_ATOMIC); | |
2470 | } | |
2471 | ||
2472 | return rc; | |
2473 | } | |
2474 | ||
ecb3b2b3 | 2475 | module_usb_driver(imon_driver); |