2 * imon.c: input and display driver for SoundGraph iMON IR/VFD/LCD
4 * Copyright(C) 2010 Jarod Wilson <jarod@wilsonet.com>
5 * Portions based on the original lirc_imon driver,
6 * Copyright(C) 2004 Venky Raju(dev@venky.ws)
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.
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.
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.
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.
29 #include <linux/errno.h>
30 #include <linux/init.h>
31 #include <linux/kernel.h>
32 #include <linux/module.h>
33 #include <linux/slab.h>
34 #include <linux/uaccess.h>
36 #include <linux/input.h>
37 #include <linux/usb.h>
38 #include <linux/usb/input.h>
39 #include <media/ir-core.h>
41 #include <linux/time.h>
42 #include <linux/timer.h>
44 #define MOD_AUTHOR "Jarod Wilson <jarod@wilsonet.com>"
45 #define MOD_DESC "Driver for SoundGraph iMON MultiMedia IR/Display"
46 #define MOD_NAME "imon"
47 #define MOD_VERSION "0.9.2"
49 #define DISPLAY_MINOR_BASE 144
50 #define DEVICE_NAME "lcd%d"
52 #define BUF_CHUNK_SIZE 8
55 #define BIT_DURATION 250 /* each bit received is 250us */
57 #define IMON_CLOCK_ENABLE_PACKETS 2
59 /*** P R O T O T Y P E S ***/
61 /* USB Callback prototypes */
62 static int imon_probe(struct usb_interface *interface,
63 const struct usb_device_id *id);
64 static void imon_disconnect(struct usb_interface *interface);
65 static void usb_rx_callback_intf0(struct urb *urb);
66 static void usb_rx_callback_intf1(struct urb *urb);
67 static void usb_tx_callback(struct urb *urb);
69 /* suspend/resume support */
70 static int imon_resume(struct usb_interface *intf);
71 static int imon_suspend(struct usb_interface *intf, pm_message_t message);
73 /* Display file_operations function prototypes */
74 static int display_open(struct inode *inode, struct file *file);
75 static int display_close(struct inode *inode, struct file *file);
77 /* VFD write operation */
78 static ssize_t vfd_write(struct file *file, const char *buf,
79 size_t n_bytes, loff_t *pos);
81 /* LCD file_operations override function prototypes */
82 static ssize_t lcd_write(struct file *file, const char *buf,
83 size_t n_bytes, loff_t *pos);
85 /*** G L O B A L S ***/
89 struct ir_dev_props *props;
90 /* Newer devices have two interfaces */
91 struct usb_device *usbdev_intf0;
92 struct usb_device *usbdev_intf1;
94 bool display_supported; /* not all controllers do */
95 bool display_isopen; /* display port has been opened */
96 bool rf_device; /* true if iMON 2.4G LT/DT RF device */
97 bool rf_isassociating; /* RF remote associating */
98 bool dev_present_intf0; /* USB device presence, interface 0 */
99 bool dev_present_intf1; /* USB device presence, interface 1 */
101 struct mutex lock; /* to lock this object */
102 wait_queue_head_t remove_ok; /* For unexpected USB disconnects */
104 struct usb_endpoint_descriptor *rx_endpoint_intf0;
105 struct usb_endpoint_descriptor *rx_endpoint_intf1;
106 struct usb_endpoint_descriptor *tx_endpoint;
107 struct urb *rx_urb_intf0;
108 struct urb *rx_urb_intf1;
111 unsigned char usb_rx_buf[8];
112 unsigned char usb_tx_buf[8];
115 unsigned char data_buf[35]; /* user data buffer */
116 struct completion finished; /* wait for write to finish */
117 bool busy; /* write in progress */
118 int status; /* status of tx completion */
121 u16 vendor; /* usb vendor ID */
122 u16 product; /* usb product ID */
124 struct input_dev *rdev; /* input device for remote */
125 struct input_dev *idev; /* input device for panel & IR mouse */
126 struct input_dev *touch; /* input device for touchscreen */
128 spinlock_t kc_lock; /* make sure we get keycodes right */
129 u32 kc; /* current input keycode */
130 u32 last_keycode; /* last reported input keycode */
131 u32 rc_scancode; /* the computed remote scancode */
132 u8 rc_toggle; /* the computed remote toggle bit */
133 u64 ir_type; /* iMON or MCE (RC6) IR protocol? */
134 bool release_code; /* some keys send a release code */
136 u8 display_type; /* store the display type */
137 bool pad_mouse; /* toggle kbd(0)/mouse(1) mode */
139 char name_rdev[128]; /* rc input device name */
140 char phys_rdev[64]; /* rc input device phys path */
142 char name_idev[128]; /* input device name */
143 char phys_idev[64]; /* input device phys path */
145 char name_touch[128]; /* touch screen name */
146 char phys_touch[64]; /* touch screen phys path */
147 struct timer_list ttimer; /* touch screen timer */
148 int touch_x; /* x coordinate on touchscreen */
149 int touch_y; /* y coordinate on touchscreen */
152 #define TOUCH_TIMEOUT (HZ/30)
154 /* vfd character device file operations */
155 static const struct file_operations vfd_fops = {
156 .owner = THIS_MODULE,
157 .open = &display_open,
159 .release = &display_close
162 /* lcd character device file operations */
163 static const struct file_operations lcd_fops = {
164 .owner = THIS_MODULE,
165 .open = &display_open,
167 .release = &display_close
171 IMON_DISPLAY_TYPE_AUTO = 0,
172 IMON_DISPLAY_TYPE_VFD = 1,
173 IMON_DISPLAY_TYPE_LCD = 2,
174 IMON_DISPLAY_TYPE_VGA = 3,
175 IMON_DISPLAY_TYPE_NONE = 4,
185 * USB Device ID for iMON USB Control Boards
187 * The Windows drivers contain 6 different inf files, more or less one for
188 * each new device until the 0x0034-0x0046 devices, which all use the same
189 * driver. Some of the devices in the 34-46 range haven't been definitively
190 * identified yet. Early devices have either a TriGem Computer, Inc. or a
191 * Samsung vendor ID (0x0aa8 and 0x04e8 respectively), while all later
192 * devices use the SoundGraph vendor ID (0x15c2). This driver only supports
193 * the ffdc and later devices, which do onboard decoding.
195 static struct usb_device_id imon_usb_id_table[] = {
197 * Several devices with this same device ID, all use iMON_PAD.inf
198 * SoundGraph iMON PAD (IR & VFD)
199 * SoundGraph iMON PAD (IR & LCD)
200 * SoundGraph iMON Knob (IR only)
202 { USB_DEVICE(0x15c2, 0xffdc) },
205 * Newer devices, all driven by the latest iMON Windows driver, full
206 * list of device IDs extracted via 'strings Setup/data1.hdr |grep 15c2'
207 * Need user input to fill in details on unknown devices.
209 /* SoundGraph iMON OEM Touch LCD (IR & 7" VGA LCD) */
210 { USB_DEVICE(0x15c2, 0x0034) },
211 /* SoundGraph iMON OEM Touch LCD (IR & 4.3" VGA LCD) */
212 { USB_DEVICE(0x15c2, 0x0035) },
213 /* SoundGraph iMON OEM VFD (IR & VFD) */
214 { USB_DEVICE(0x15c2, 0x0036) },
215 /* device specifics unknown */
216 { USB_DEVICE(0x15c2, 0x0037) },
217 /* SoundGraph iMON OEM LCD (IR & LCD) */
218 { USB_DEVICE(0x15c2, 0x0038) },
219 /* SoundGraph iMON UltraBay (IR & LCD) */
220 { USB_DEVICE(0x15c2, 0x0039) },
221 /* device specifics unknown */
222 { USB_DEVICE(0x15c2, 0x003a) },
223 /* device specifics unknown */
224 { USB_DEVICE(0x15c2, 0x003b) },
225 /* SoundGraph iMON OEM Inside (IR only) */
226 { USB_DEVICE(0x15c2, 0x003c) },
227 /* device specifics unknown */
228 { USB_DEVICE(0x15c2, 0x003d) },
229 /* device specifics unknown */
230 { USB_DEVICE(0x15c2, 0x003e) },
231 /* device specifics unknown */
232 { USB_DEVICE(0x15c2, 0x003f) },
233 /* device specifics unknown */
234 { USB_DEVICE(0x15c2, 0x0040) },
235 /* SoundGraph iMON MINI (IR only) */
236 { USB_DEVICE(0x15c2, 0x0041) },
237 /* Antec Veris Multimedia Station EZ External (IR only) */
238 { USB_DEVICE(0x15c2, 0x0042) },
239 /* Antec Veris Multimedia Station Basic Internal (IR only) */
240 { USB_DEVICE(0x15c2, 0x0043) },
241 /* Antec Veris Multimedia Station Elite (IR & VFD) */
242 { USB_DEVICE(0x15c2, 0x0044) },
243 /* Antec Veris Multimedia Station Premiere (IR & LCD) */
244 { USB_DEVICE(0x15c2, 0x0045) },
245 /* device specifics unknown */
246 { USB_DEVICE(0x15c2, 0x0046) },
250 /* USB Device data */
251 static struct usb_driver imon_driver = {
254 .disconnect = imon_disconnect,
255 .suspend = imon_suspend,
256 .resume = imon_resume,
257 .id_table = imon_usb_id_table,
260 static struct usb_class_driver imon_vfd_class = {
263 .minor_base = DISPLAY_MINOR_BASE,
266 static struct usb_class_driver imon_lcd_class = {
269 .minor_base = DISPLAY_MINOR_BASE,
272 /* imon receiver front panel/knob key table */
273 static const struct {
276 } imon_panel_key_table[] = {
277 { 0x000000000f00ffeell, KEY_PROG1 }, /* Go */
278 { 0x000000001f00ffeell, KEY_AUDIO },
279 { 0x000000002000ffeell, KEY_VIDEO },
280 { 0x000000002100ffeell, KEY_CAMERA },
281 { 0x000000002700ffeell, KEY_DVD },
282 { 0x000000002300ffeell, KEY_TV },
283 { 0x000000000500ffeell, KEY_PREVIOUS },
284 { 0x000000000700ffeell, KEY_REWIND },
285 { 0x000000000400ffeell, KEY_STOP },
286 { 0x000000003c00ffeell, KEY_PLAYPAUSE },
287 { 0x000000000800ffeell, KEY_FASTFORWARD },
288 { 0x000000000600ffeell, KEY_NEXT },
289 { 0x000000010000ffeell, KEY_RIGHT },
290 { 0x000001000000ffeell, KEY_LEFT },
291 { 0x000000003d00ffeell, KEY_SELECT },
292 { 0x000100000000ffeell, KEY_VOLUMEUP },
293 { 0x010000000000ffeell, KEY_VOLUMEDOWN },
294 { 0x000000000100ffeell, KEY_MUTE },
295 /* iMON Knob values */
296 { 0x000100ffffffffeell, KEY_VOLUMEUP },
297 { 0x010000ffffffffeell, KEY_VOLUMEDOWN },
298 { 0x000008ffffffffeell, KEY_MUTE },
301 /* to prevent races between open() and disconnect(), probing, etc */
302 static DEFINE_MUTEX(driver_lock);
304 /* Module bookkeeping bits */
305 MODULE_AUTHOR(MOD_AUTHOR);
306 MODULE_DESCRIPTION(MOD_DESC);
307 MODULE_VERSION(MOD_VERSION);
308 MODULE_LICENSE("GPL");
309 MODULE_DEVICE_TABLE(usb, imon_usb_id_table);
312 module_param(debug, bool, S_IRUGO | S_IWUSR);
313 MODULE_PARM_DESC(debug, "Debug messages: 0=no, 1=yes(default: no)");
315 /* lcd, vfd, vga or none? should be auto-detected, but can be overridden... */
316 static int display_type;
317 module_param(display_type, int, S_IRUGO);
318 MODULE_PARM_DESC(display_type, "Type of attached display. 0=autodetect, "
319 "1=vfd, 2=lcd, 3=vga, 4=none (default: autodetect)");
321 static int pad_stabilize = 1;
322 module_param(pad_stabilize, int, S_IRUGO | S_IWUSR);
323 MODULE_PARM_DESC(pad_stabilize, "Apply stabilization algorithm to iMON PAD "
324 "presses in arrow key mode. 0=disable, 1=enable (default).");
327 * In certain use cases, mouse mode isn't really helpful, and could actually
328 * cause confusion, so allow disabling it when the IR device is open.
331 module_param(nomouse, bool, S_IRUGO | S_IWUSR);
332 MODULE_PARM_DESC(nomouse, "Disable mouse input device mode when IR device is "
333 "open. 0=don't disable, 1=disable. (default: don't disable)");
335 /* threshold at which a pad push registers as an arrow key in kbd mode */
336 static int pad_thresh;
337 module_param(pad_thresh, int, S_IRUGO | S_IWUSR);
338 MODULE_PARM_DESC(pad_thresh, "Threshold at which a pad push registers as an "
339 "arrow key in kbd mode (default: 28)");
342 static void free_imon_context(struct imon_context *ictx)
344 struct device *dev = ictx->dev;
346 usb_free_urb(ictx->tx_urb);
347 usb_free_urb(ictx->rx_urb_intf0);
348 usb_free_urb(ictx->rx_urb_intf1);
351 dev_dbg(dev, "%s: iMON context freed\n", __func__);
355 * Called when the Display device (e.g. /dev/lcd0)
356 * is opened by the application.
358 static int display_open(struct inode *inode, struct file *file)
360 struct usb_interface *interface;
361 struct imon_context *ictx = NULL;
365 /* prevent races with disconnect */
366 mutex_lock(&driver_lock);
368 subminor = iminor(inode);
369 interface = usb_find_interface(&imon_driver, subminor);
371 err("%s: could not find interface for minor %d",
376 ictx = usb_get_intfdata(interface);
379 err("%s: no context found for minor %d", __func__, subminor);
384 mutex_lock(&ictx->lock);
386 if (!ictx->display_supported) {
387 err("%s: display not supported by device", __func__);
389 } else if (ictx->display_isopen) {
390 err("%s: display port is already open", __func__);
393 ictx->display_isopen = true;
394 file->private_data = ictx;
395 dev_dbg(ictx->dev, "display port opened\n");
398 mutex_unlock(&ictx->lock);
401 mutex_unlock(&driver_lock);
406 * Called when the display device (e.g. /dev/lcd0)
407 * is closed by the application.
409 static int display_close(struct inode *inode, struct file *file)
411 struct imon_context *ictx = NULL;
414 ictx = file->private_data;
417 err("%s: no context for device", __func__);
421 mutex_lock(&ictx->lock);
423 if (!ictx->display_supported) {
424 err("%s: display not supported by device", __func__);
426 } else if (!ictx->display_isopen) {
427 err("%s: display is not open", __func__);
430 ictx->display_isopen = false;
431 dev_dbg(ictx->dev, "display port closed\n");
432 if (!ictx->dev_present_intf0) {
434 * Device disconnected before close and IR port is not
435 * open. If IR port is open, context will be deleted by
438 mutex_unlock(&ictx->lock);
439 free_imon_context(ictx);
444 mutex_unlock(&ictx->lock);
449 * Sends a packet to the device -- this function must be called
450 * with ictx->lock held.
452 static int send_packet(struct imon_context *ictx)
455 unsigned long timeout;
458 struct usb_ctrlrequest *control_req = NULL;
460 /* Check if we need to use control or interrupt urb */
461 if (!ictx->tx_control) {
462 pipe = usb_sndintpipe(ictx->usbdev_intf0,
463 ictx->tx_endpoint->bEndpointAddress);
464 interval = ictx->tx_endpoint->bInterval;
466 usb_fill_int_urb(ictx->tx_urb, ictx->usbdev_intf0, pipe,
468 sizeof(ictx->usb_tx_buf),
469 usb_tx_callback, ictx, interval);
471 ictx->tx_urb->actual_length = 0;
473 /* fill request into kmalloc'ed space: */
474 control_req = kmalloc(sizeof(struct usb_ctrlrequest),
476 if (control_req == NULL)
479 /* setup packet is '21 09 0200 0001 0008' */
480 control_req->bRequestType = 0x21;
481 control_req->bRequest = 0x09;
482 control_req->wValue = cpu_to_le16(0x0200);
483 control_req->wIndex = cpu_to_le16(0x0001);
484 control_req->wLength = cpu_to_le16(0x0008);
486 /* control pipe is endpoint 0x00 */
487 pipe = usb_sndctrlpipe(ictx->usbdev_intf0, 0);
489 /* build the control urb */
490 usb_fill_control_urb(ictx->tx_urb, ictx->usbdev_intf0,
491 pipe, (unsigned char *)control_req,
493 sizeof(ictx->usb_tx_buf),
494 usb_tx_callback, ictx);
495 ictx->tx_urb->actual_length = 0;
498 init_completion(&ictx->tx.finished);
499 ictx->tx.busy = true;
500 smp_rmb(); /* ensure later readers know we're busy */
502 retval = usb_submit_urb(ictx->tx_urb, GFP_KERNEL);
504 ictx->tx.busy = false;
505 smp_rmb(); /* ensure later readers know we're not busy */
506 err("%s: error submitting urb(%d)", __func__, retval);
508 /* Wait for transmission to complete (or abort) */
509 mutex_unlock(&ictx->lock);
510 retval = wait_for_completion_interruptible(
513 err("%s: task interrupted", __func__);
514 mutex_lock(&ictx->lock);
516 retval = ictx->tx.status;
518 err("%s: packet tx failed (%d)", __func__, retval);
524 * Induce a mandatory 5ms delay before returning, as otherwise,
525 * send_packet can get called so rapidly as to overwhelm the device,
526 * particularly on faster systems and/or those with quirky usb.
528 timeout = msecs_to_jiffies(5);
529 set_current_state(TASK_UNINTERRUPTIBLE);
530 schedule_timeout(timeout);
536 * Sends an associate packet to the iMON 2.4G.
538 * This might not be such a good idea, since it has an id collision with
539 * some versions of the "IR & VFD" combo. The only way to determine if it
540 * is an RF version is to look at the product description string. (Which
541 * we currently do not fetch).
543 static int send_associate_24g(struct imon_context *ictx)
546 const unsigned char packet[8] = { 0x01, 0x00, 0x00, 0x00,
547 0x00, 0x00, 0x00, 0x20 };
550 err("%s: no context for device", __func__);
554 if (!ictx->dev_present_intf0) {
555 err("%s: no iMON device present", __func__);
559 memcpy(ictx->usb_tx_buf, packet, sizeof(packet));
560 retval = send_packet(ictx);
566 * Sends packets to setup and show clock on iMON display
568 * Arguments: year - last 2 digits of year, month - 1..12,
569 * day - 1..31, dow - day of the week (0-Sun...6-Sat),
570 * hour - 0..23, minute - 0..59, second - 0..59
572 static int send_set_imon_clock(struct imon_context *ictx,
573 unsigned int year, unsigned int month,
574 unsigned int day, unsigned int dow,
575 unsigned int hour, unsigned int minute,
578 unsigned char clock_enable_pkt[IMON_CLOCK_ENABLE_PACKETS][8];
583 err("%s: no context for device", __func__);
587 switch (ictx->display_type) {
588 case IMON_DISPLAY_TYPE_LCD:
589 clock_enable_pkt[0][0] = 0x80;
590 clock_enable_pkt[0][1] = year;
591 clock_enable_pkt[0][2] = month-1;
592 clock_enable_pkt[0][3] = day;
593 clock_enable_pkt[0][4] = hour;
594 clock_enable_pkt[0][5] = minute;
595 clock_enable_pkt[0][6] = second;
597 clock_enable_pkt[1][0] = 0x80;
598 clock_enable_pkt[1][1] = 0;
599 clock_enable_pkt[1][2] = 0;
600 clock_enable_pkt[1][3] = 0;
601 clock_enable_pkt[1][4] = 0;
602 clock_enable_pkt[1][5] = 0;
603 clock_enable_pkt[1][6] = 0;
605 if (ictx->product == 0xffdc) {
606 clock_enable_pkt[0][7] = 0x50;
607 clock_enable_pkt[1][7] = 0x51;
609 clock_enable_pkt[0][7] = 0x88;
610 clock_enable_pkt[1][7] = 0x8a;
615 case IMON_DISPLAY_TYPE_VFD:
616 clock_enable_pkt[0][0] = year;
617 clock_enable_pkt[0][1] = month-1;
618 clock_enable_pkt[0][2] = day;
619 clock_enable_pkt[0][3] = dow;
620 clock_enable_pkt[0][4] = hour;
621 clock_enable_pkt[0][5] = minute;
622 clock_enable_pkt[0][6] = second;
623 clock_enable_pkt[0][7] = 0x40;
625 clock_enable_pkt[1][0] = 0;
626 clock_enable_pkt[1][1] = 0;
627 clock_enable_pkt[1][2] = 1;
628 clock_enable_pkt[1][3] = 0;
629 clock_enable_pkt[1][4] = 0;
630 clock_enable_pkt[1][5] = 0;
631 clock_enable_pkt[1][6] = 0;
632 clock_enable_pkt[1][7] = 0x42;
640 for (i = 0; i < IMON_CLOCK_ENABLE_PACKETS; i++) {
641 memcpy(ictx->usb_tx_buf, clock_enable_pkt[i], 8);
642 retval = send_packet(ictx);
644 err("%s: send_packet failed for packet %d",
654 * These are the sysfs functions to handle the association on the iMON 2.4G LT.
656 static ssize_t show_associate_remote(struct device *d,
657 struct device_attribute *attr,
660 struct imon_context *ictx = dev_get_drvdata(d);
665 mutex_lock(&ictx->lock);
666 if (ictx->rf_isassociating)
667 strcpy(buf, "associating\n");
669 strcpy(buf, "closed\n");
671 dev_info(d, "Visit http://www.lirc.org/html/imon-24g.html for "
672 "instructions on how to associate your iMON 2.4G DT/LT "
674 mutex_unlock(&ictx->lock);
678 static ssize_t store_associate_remote(struct device *d,
679 struct device_attribute *attr,
680 const char *buf, size_t count)
682 struct imon_context *ictx;
684 ictx = dev_get_drvdata(d);
689 mutex_lock(&ictx->lock);
690 ictx->rf_isassociating = true;
691 send_associate_24g(ictx);
692 mutex_unlock(&ictx->lock);
698 * sysfs functions to control internal imon clock
700 static ssize_t show_imon_clock(struct device *d,
701 struct device_attribute *attr, char *buf)
703 struct imon_context *ictx = dev_get_drvdata(d);
709 mutex_lock(&ictx->lock);
711 if (!ictx->display_supported) {
712 len = snprintf(buf, PAGE_SIZE, "Not supported.");
714 len = snprintf(buf, PAGE_SIZE,
715 "To set the clock on your iMON display:\n"
716 "# date \"+%%y %%m %%d %%w %%H %%M %%S\" > imon_clock\n"
717 "%s", ictx->display_isopen ?
718 "\nNOTE: imon device must be closed\n" : "");
721 mutex_unlock(&ictx->lock);
726 static ssize_t store_imon_clock(struct device *d,
727 struct device_attribute *attr,
728 const char *buf, size_t count)
730 struct imon_context *ictx = dev_get_drvdata(d);
732 unsigned int year, month, day, dow, hour, minute, second;
737 mutex_lock(&ictx->lock);
739 if (!ictx->display_supported) {
742 } else if (ictx->display_isopen) {
747 if (sscanf(buf, "%u %u %u %u %u %u %u", &year, &month, &day, &dow,
748 &hour, &minute, &second) != 7) {
753 if ((month < 1 || month > 12) ||
754 (day < 1 || day > 31) || (dow > 6) ||
755 (hour > 23) || (minute > 59) || (second > 59)) {
760 retval = send_set_imon_clock(ictx, year, month, day, dow,
761 hour, minute, second);
767 mutex_unlock(&ictx->lock);
773 static DEVICE_ATTR(imon_clock, S_IWUSR | S_IRUGO, show_imon_clock,
776 static DEVICE_ATTR(associate_remote, S_IWUSR | S_IRUGO, show_associate_remote,
777 store_associate_remote);
779 static struct attribute *imon_display_sysfs_entries[] = {
780 &dev_attr_imon_clock.attr,
784 static struct attribute_group imon_display_attribute_group = {
785 .attrs = imon_display_sysfs_entries
788 static struct attribute *imon_rf_sysfs_entries[] = {
789 &dev_attr_associate_remote.attr,
793 static struct attribute_group imon_rf_attribute_group = {
794 .attrs = imon_rf_sysfs_entries
798 * Writes data to the VFD. The iMON VFD is 2x16 characters
799 * and requires data in 5 consecutive USB interrupt packets,
800 * each packet but the last carrying 7 bytes.
802 * I don't know if the VFD board supports features such as
803 * scrolling, clearing rows, blanking, etc. so at
804 * the caller must provide a full screen of data. If fewer
805 * than 32 bytes are provided spaces will be appended to
806 * generate a full screen.
808 static ssize_t vfd_write(struct file *file, const char *buf,
809 size_t n_bytes, loff_t *pos)
815 struct imon_context *ictx;
816 const unsigned char vfd_packet6[] = {
817 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF };
819 ictx = file->private_data;
821 err("%s: no context for device", __func__);
825 mutex_lock(&ictx->lock);
827 if (!ictx->dev_present_intf0) {
828 err("%s: no iMON device present", __func__);
833 if (n_bytes <= 0 || n_bytes > 32) {
834 err("%s: invalid payload size", __func__);
839 if (copy_from_user(ictx->tx.data_buf, buf, n_bytes)) {
844 /* Pad with spaces */
845 for (i = n_bytes; i < 32; ++i)
846 ictx->tx.data_buf[i] = ' ';
848 for (i = 32; i < 35; ++i)
849 ictx->tx.data_buf[i] = 0xFF;
855 memcpy(ictx->usb_tx_buf, ictx->tx.data_buf + offset, 7);
856 ictx->usb_tx_buf[7] = (unsigned char) seq;
858 retval = send_packet(ictx);
860 err("%s: send packet failed for packet #%d",
868 } while (offset < 35);
871 memcpy(ictx->usb_tx_buf, &vfd_packet6, sizeof(vfd_packet6));
872 ictx->usb_tx_buf[7] = (unsigned char) seq;
873 retval = send_packet(ictx);
875 err("%s: send packet failed for packet #%d",
879 mutex_unlock(&ictx->lock);
881 return (!retval) ? n_bytes : retval;
885 * Writes data to the LCD. The iMON OEM LCD screen expects 8-byte
886 * packets. We accept data as 16 hexadecimal digits, followed by a
887 * newline (to make it easy to drive the device from a command-line
888 * -- even though the actual binary data is a bit complicated).
890 * The device itself is not a "traditional" text-mode display. It's
891 * actually a 16x96 pixel bitmap display. That means if you want to
892 * display text, you've got to have your own "font" and translate the
893 * text into bitmaps for display. This is really flexible (you can
894 * display whatever diacritics you need, and so on), but it's also
895 * a lot more complicated than most LCDs...
897 static ssize_t lcd_write(struct file *file, const char *buf,
898 size_t n_bytes, loff_t *pos)
901 struct imon_context *ictx;
903 ictx = file->private_data;
905 err("%s: no context for device", __func__);
909 mutex_lock(&ictx->lock);
911 if (!ictx->display_supported) {
912 err("%s: no iMON display present", __func__);
918 err("%s: invalid payload size: %d (expecting 8)",
919 __func__, (int) n_bytes);
924 if (copy_from_user(ictx->usb_tx_buf, buf, 8)) {
929 retval = send_packet(ictx);
931 err("%s: send packet failed!", __func__);
934 dev_dbg(ictx->dev, "%s: write %d bytes to LCD\n",
935 __func__, (int) n_bytes);
938 mutex_unlock(&ictx->lock);
939 return (!retval) ? n_bytes : retval;
943 * Callback function for USB core API: transmit data
945 static void usb_tx_callback(struct urb *urb)
947 struct imon_context *ictx;
951 ictx = (struct imon_context *)urb->context;
955 ictx->tx.status = urb->status;
957 /* notify waiters that write has finished */
958 ictx->tx.busy = false;
959 smp_rmb(); /* ensure later readers know we're not busy */
960 complete(&ictx->tx.finished);
964 * report touchscreen input
966 static void imon_touch_display_timeout(unsigned long data)
968 struct imon_context *ictx = (struct imon_context *)data;
970 if (ictx->display_type != IMON_DISPLAY_TYPE_VGA)
973 input_report_abs(ictx->touch, ABS_X, ictx->touch_x);
974 input_report_abs(ictx->touch, ABS_Y, ictx->touch_y);
975 input_report_key(ictx->touch, BTN_TOUCH, 0x00);
976 input_sync(ictx->touch);
980 * iMON IR receivers support two different signal sets -- those used by
981 * the iMON remotes, and those used by the Windows MCE remotes (which is
982 * really just RC-6), but only one or the other at a time, as the signals
983 * are decoded onboard the receiver.
985 int imon_ir_change_protocol(void *priv, u64 ir_type)
988 struct imon_context *ictx = priv;
989 struct device *dev = ictx->dev;
991 unsigned char ir_proto_packet[] = {
992 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86 };
994 if (ir_type && !(ir_type & ictx->props->allowed_protos))
995 dev_warn(dev, "Looks like you're trying to use an IR protocol "
996 "this device does not support\n");
1000 dev_dbg(dev, "Configuring IR receiver for MCE protocol\n");
1001 ir_proto_packet[0] = 0x01;
1004 case IR_TYPE_UNKNOWN:
1006 dev_dbg(dev, "Configuring IR receiver for iMON protocol\n");
1010 dev_dbg(dev, "PAD stabilize functionality disabled\n");
1013 /* ir_proto_packet[0] = 0x00; // already the default */
1014 ir_type = IR_TYPE_OTHER;
1017 dev_warn(dev, "Unsupported IR protocol specified, overriding "
1018 "to iMON IR protocol\n");
1022 dev_dbg(dev, "PAD stabilize functionality disabled\n");
1025 /* ir_proto_packet[0] = 0x00; // already the default */
1026 ir_type = IR_TYPE_OTHER;
1030 memcpy(ictx->usb_tx_buf, &ir_proto_packet, sizeof(ir_proto_packet));
1032 retval = send_packet(ictx);
1036 ictx->ir_type = ir_type;
1037 ictx->pad_mouse = pad_mouse;
1043 static inline int tv2int(const struct timeval *a, const struct timeval *b)
1048 if (b->tv_usec > a->tv_usec) {
1053 usecs += a->tv_usec - b->tv_usec;
1055 sec += a->tv_sec - b->tv_sec;
1067 * The directional pad behaves a bit differently, depending on whether this is
1068 * one of the older ffdc devices or a newer device. Newer devices appear to
1069 * have a higher resolution matrix for more precise mouse movement, but it
1070 * makes things overly sensitive in keyboard mode, so we do some interesting
1071 * contortions to make it less touchy. Older devices run through the same
1072 * routine with shorter timeout and a smaller threshold.
1074 static int stabilize(int a, int b, u16 timeout, u16 threshold)
1077 static struct timeval prev_time = {0, 0};
1078 static struct timeval hit_time = {0, 0};
1079 static int x, y, prev_result, hits;
1083 do_gettimeofday(&ct);
1084 msec = tv2int(&ct, &prev_time);
1085 msec_hit = tv2int(&ct, &hit_time);
1098 if (abs(x) > threshold || abs(y) > threshold) {
1099 if (abs(y) > abs(x))
1100 result = (y > 0) ? 0x7F : 0x80;
1102 result = (x > 0) ? 0x7F00 : 0x8000;
1107 if (result == prev_result) {
1113 y = 17 * threshold / 30;
1116 y -= 17 * threshold / 30;
1119 x = 17 * threshold / 30;
1122 x -= 17 * threshold / 30;
1127 if (hits == 2 && msec_hit < timeout) {
1132 prev_result = result;
1141 static u32 imon_remote_key_lookup(struct imon_context *ictx, u32 scancode)
1145 bool is_release_code = false;
1147 /* Look for the initial press of a button */
1148 keycode = ir_g_keycode_from_table(ictx->rdev, scancode);
1149 ictx->rc_toggle = 0x0;
1150 ictx->rc_scancode = scancode;
1152 /* Look for the release of a button */
1153 if (keycode == KEY_RESERVED) {
1154 release = scancode & ~0x4000;
1155 keycode = ir_g_keycode_from_table(ictx->rdev, release);
1156 if (keycode != KEY_RESERVED)
1157 is_release_code = true;
1160 ictx->release_code = is_release_code;
1165 static u32 imon_mce_key_lookup(struct imon_context *ictx, u32 scancode)
1169 #define MCE_KEY_MASK 0x7000
1170 #define MCE_TOGGLE_BIT 0x8000
1173 * On some receivers, mce keys decode to 0x8000f04xx and 0x8000f84xx
1174 * (the toggle bit flipping between alternating key presses), while
1175 * on other receivers, we see 0x8000f74xx and 0x8000ff4xx. To keep
1176 * the table trim, we always or in the bits to look up 0x8000ff4xx,
1177 * but we can't or them into all codes, as some keys are decoded in
1178 * a different way w/o the same use of the toggle bit...
1180 if (scancode & 0x80000000)
1181 scancode = scancode | MCE_KEY_MASK | MCE_TOGGLE_BIT;
1183 ictx->rc_scancode = scancode;
1184 keycode = ir_g_keycode_from_table(ictx->rdev, scancode);
1186 /* not used in mce mode, but make sure we know its false */
1187 ictx->release_code = false;
1192 static u32 imon_panel_key_lookup(u64 code)
1195 u32 keycode = KEY_RESERVED;
1197 for (i = 0; i < ARRAY_SIZE(imon_panel_key_table); i++) {
1198 if (imon_panel_key_table[i].hw_code == (code | 0xffee)) {
1199 keycode = imon_panel_key_table[i].keycode;
1207 static bool imon_mouse_event(struct imon_context *ictx,
1208 unsigned char *buf, int len)
1210 char rel_x = 0x00, rel_y = 0x00;
1212 bool mouse_input = true;
1214 unsigned long flags;
1216 spin_lock_irqsave(&ictx->kc_lock, flags);
1218 /* newer iMON device PAD or mouse button */
1219 if (ictx->product != 0xffdc && (buf[0] & 0x01) && len == 5) {
1223 /* 0xffdc iMON PAD or mouse button input */
1224 } else if (ictx->product == 0xffdc && (buf[0] & 0x40) &&
1225 !((buf[1] & 0x01) || ((buf[1] >> 2) & 0x01))) {
1226 rel_x = (buf[1] & 0x08) | (buf[1] & 0x10) >> 2 |
1227 (buf[1] & 0x20) >> 4 | (buf[1] & 0x40) >> 6;
1230 rel_x = rel_x + rel_x / 2;
1231 rel_y = (buf[2] & 0x08) | (buf[2] & 0x10) >> 2 |
1232 (buf[2] & 0x20) >> 4 | (buf[2] & 0x40) >> 6;
1235 rel_y = rel_y + rel_y / 2;
1237 /* some ffdc devices decode mouse buttons differently... */
1238 } else if (ictx->product == 0xffdc && (buf[0] == 0x68)) {
1240 /* ch+/- buttons, which we use for an emulated scroll wheel */
1241 } else if (ictx->kc == KEY_CHANNELUP && (buf[2] & 0x40) != 0x40) {
1243 } else if (ictx->kc == KEY_CHANNELDOWN && (buf[2] & 0x40) != 0x40) {
1246 mouse_input = false;
1248 spin_unlock_irqrestore(&ictx->kc_lock, flags);
1251 dev_dbg(ictx->dev, "sending mouse data via input subsystem\n");
1254 input_report_rel(ictx->idev, REL_WHEEL, dir);
1255 } else if (rel_x || rel_y) {
1256 input_report_rel(ictx->idev, REL_X, rel_x);
1257 input_report_rel(ictx->idev, REL_Y, rel_y);
1259 input_report_key(ictx->idev, BTN_LEFT, buf[1] & 0x1);
1260 input_report_key(ictx->idev, BTN_RIGHT,
1261 buf[1] >> right_shift & 0x1);
1263 input_sync(ictx->idev);
1264 spin_lock_irqsave(&ictx->kc_lock, flags);
1265 ictx->last_keycode = ictx->kc;
1266 spin_unlock_irqrestore(&ictx->kc_lock, flags);
1272 static void imon_touch_event(struct imon_context *ictx, unsigned char *buf)
1274 mod_timer(&ictx->ttimer, jiffies + TOUCH_TIMEOUT);
1275 ictx->touch_x = (buf[0] << 4) | (buf[1] >> 4);
1276 ictx->touch_y = 0xfff - ((buf[2] << 4) | (buf[1] & 0xf));
1277 input_report_abs(ictx->touch, ABS_X, ictx->touch_x);
1278 input_report_abs(ictx->touch, ABS_Y, ictx->touch_y);
1279 input_report_key(ictx->touch, BTN_TOUCH, 0x01);
1280 input_sync(ictx->touch);
1283 static void imon_pad_to_keys(struct imon_context *ictx, unsigned char *buf)
1286 char rel_x = 0x00, rel_y = 0x00;
1287 u16 timeout, threshold;
1288 u32 scancode = KEY_RESERVED;
1289 unsigned long flags;
1292 * The imon directional pad functions more like a touchpad. Bytes 3 & 4
1293 * contain a position coordinate (x,y), with each component ranging
1294 * from -14 to 14. We want to down-sample this to only 4 discrete values
1295 * for up/down/left/right arrow keys. Also, when you get too close to
1296 * diagonals, it has a tendancy to jump back and forth, so lets try to
1297 * ignore when they get too close.
1299 if (ictx->product != 0xffdc) {
1300 /* first, pad to 8 bytes so it conforms with everything else */
1301 buf[5] = buf[6] = buf[7] = 0;
1302 timeout = 500; /* in msecs */
1303 /* (2*threshold) x (2*threshold) square */
1304 threshold = pad_thresh ? pad_thresh : 28;
1308 if (ictx->ir_type == IR_TYPE_OTHER && pad_stabilize) {
1309 if ((buf[1] == 0) && ((rel_x != 0) || (rel_y != 0))) {
1310 dir = stabilize((int)rel_x, (int)rel_y,
1311 timeout, threshold);
1313 spin_lock_irqsave(&ictx->kc_lock,
1315 ictx->kc = KEY_UNKNOWN;
1316 spin_unlock_irqrestore(&ictx->kc_lock,
1320 buf[2] = dir & 0xFF;
1321 buf[3] = (dir >> 8) & 0xFF;
1322 scancode = be32_to_cpu(*((u32 *)buf));
1326 * Hack alert: instead of using keycodes, we have
1327 * to use hard-coded scancodes here...
1329 if (abs(rel_y) > abs(rel_x)) {
1330 buf[2] = (rel_y > 0) ? 0x7F : 0x80;
1333 scancode = 0x01007f00; /* KEY_DOWN */
1335 scancode = 0x01008000; /* KEY_UP */
1338 buf[3] = (rel_x > 0) ? 0x7F : 0x80;
1340 scancode = 0x0100007f; /* KEY_RIGHT */
1342 scancode = 0x01000080; /* KEY_LEFT */
1347 * Handle on-board decoded pad events for e.g. older VFD/iMON-Pad
1348 * device (15c2:ffdc). The remote generates various codes from
1349 * 0x68nnnnB7 to 0x6AnnnnB7, the left mouse button generates
1350 * 0x688301b7 and the right one 0x688481b7. All other keys generate
1351 * 0x2nnnnnnn. Position coordinate is encoded in buf[1] and buf[2] with
1352 * reversed endianess. Extract direction from buffer, rotate endianess,
1353 * adjust sign and feed the values into stabilize(). The resulting codes
1354 * will be 0x01008000, 0x01007F00, which match the newer devices.
1357 timeout = 10; /* in msecs */
1358 /* (2*threshold) x (2*threshold) square */
1359 threshold = pad_thresh ? pad_thresh : 15;
1362 rel_x = (buf[1] & 0x08) | (buf[1] & 0x10) >> 2 |
1363 (buf[1] & 0x20) >> 4 | (buf[1] & 0x40) >> 6;
1367 rel_y = (buf[2] & 0x08) | (buf[2] & 0x10) >> 2 |
1368 (buf[2] & 0x20) >> 4 | (buf[2] & 0x40) >> 6;
1373 buf[1] = buf[4] = buf[5] = buf[6] = buf[7] = 0;
1375 if (ictx->ir_type == IR_TYPE_OTHER && pad_stabilize) {
1376 dir = stabilize((int)rel_x, (int)rel_y,
1377 timeout, threshold);
1379 spin_lock_irqsave(&ictx->kc_lock, flags);
1380 ictx->kc = KEY_UNKNOWN;
1381 spin_unlock_irqrestore(&ictx->kc_lock, flags);
1384 buf[2] = dir & 0xFF;
1385 buf[3] = (dir >> 8) & 0xFF;
1386 scancode = be32_to_cpu(*((u32 *)buf));
1389 * Hack alert: instead of using keycodes, we have
1390 * to use hard-coded scancodes here...
1392 if (abs(rel_y) > abs(rel_x)) {
1393 buf[2] = (rel_y > 0) ? 0x7F : 0x80;
1396 scancode = 0x01007f00; /* KEY_DOWN */
1398 scancode = 0x01008000; /* KEY_UP */
1401 buf[3] = (rel_x > 0) ? 0x7F : 0x80;
1403 scancode = 0x0100007f; /* KEY_RIGHT */
1405 scancode = 0x01000080; /* KEY_LEFT */
1411 spin_lock_irqsave(&ictx->kc_lock, flags);
1412 ictx->kc = imon_remote_key_lookup(ictx, scancode);
1413 spin_unlock_irqrestore(&ictx->kc_lock, flags);
1418 * figure out if these is a press or a release. We don't actually
1419 * care about repeats, as those will be auto-generated within the IR
1420 * subsystem for repeating scancodes.
1422 static int imon_parse_press_type(struct imon_context *ictx,
1423 unsigned char *buf, u8 ktype)
1426 unsigned long flags;
1428 spin_lock_irqsave(&ictx->kc_lock, flags);
1430 /* key release of 0x02XXXXXX key */
1431 if (ictx->kc == KEY_RESERVED && buf[0] == 0x02 && buf[3] == 0x00)
1432 ictx->kc = ictx->last_keycode;
1434 /* mouse button release on (some) 0xffdc devices */
1435 else if (ictx->kc == KEY_RESERVED && buf[0] == 0x68 && buf[1] == 0x82 &&
1436 buf[2] == 0x81 && buf[3] == 0xb7)
1437 ictx->kc = ictx->last_keycode;
1439 /* mouse button release on (some other) 0xffdc devices */
1440 else if (ictx->kc == KEY_RESERVED && buf[0] == 0x01 && buf[1] == 0x00 &&
1441 buf[2] == 0x81 && buf[3] == 0xb7)
1442 ictx->kc = ictx->last_keycode;
1444 /* mce-specific button handling, no keyup events */
1445 else if (ktype == IMON_KEY_MCE) {
1446 ictx->rc_toggle = buf[2];
1449 /* incoherent or irrelevant data */
1450 } else if (ictx->kc == KEY_RESERVED)
1451 press_type = -EINVAL;
1453 /* key release of 0xXXXXXXb7 key */
1454 else if (ictx->release_code)
1457 /* this is a button press */
1461 spin_unlock_irqrestore(&ictx->kc_lock, flags);
1467 * Process the incoming packet
1469 static void imon_incoming_packet(struct imon_context *ictx,
1470 struct urb *urb, int intf)
1472 int len = urb->actual_length;
1473 unsigned char *buf = urb->transfer_buffer;
1474 struct device *dev = ictx->dev;
1475 unsigned long flags;
1477 bool norelease = false;
1480 struct input_dev *idev = NULL;
1481 struct ir_input_dev *irdev = NULL;
1485 static struct timeval prev_time = { 0, 0 };
1489 irdev = input_get_drvdata(idev);
1491 /* filter out junk data on the older 0xffdc imon devices */
1492 if ((buf[0] == 0xff) && (buf[1] == 0xff) && (buf[2] == 0xff))
1495 /* Figure out what key was pressed */
1496 if (len == 8 && buf[7] == 0xee) {
1497 scancode = be64_to_cpu(*((u64 *)buf));
1498 ktype = IMON_KEY_PANEL;
1499 kc = imon_panel_key_lookup(scancode);
1501 scancode = be32_to_cpu(*((u32 *)buf));
1502 if (ictx->ir_type == IR_TYPE_RC6) {
1503 ktype = IMON_KEY_IMON;
1505 ktype = IMON_KEY_MCE;
1506 kc = imon_mce_key_lookup(ictx, scancode);
1508 ktype = IMON_KEY_IMON;
1509 kc = imon_remote_key_lookup(ictx, scancode);
1513 spin_lock_irqsave(&ictx->kc_lock, flags);
1514 /* keyboard/mouse mode toggle button */
1515 if (kc == KEY_KEYBOARD && !ictx->release_code) {
1516 ictx->last_keycode = kc;
1518 ictx->pad_mouse = ~(ictx->pad_mouse) & 0x1;
1519 dev_dbg(dev, "toggling to %s mode\n",
1520 ictx->pad_mouse ? "mouse" : "keyboard");
1521 spin_unlock_irqrestore(&ictx->kc_lock, flags);
1524 ictx->pad_mouse = 0;
1525 dev_dbg(dev, "mouse mode disabled, passing key value\n");
1530 spin_unlock_irqrestore(&ictx->kc_lock, flags);
1532 /* send touchscreen events through input subsystem if touchpad data */
1533 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA && len == 8 &&
1535 imon_touch_event(ictx, buf);
1538 /* look for mouse events with pad in mouse mode */
1539 } else if (ictx->pad_mouse) {
1540 if (imon_mouse_event(ictx, buf, len))
1544 /* Now for some special handling to convert pad input to arrow keys */
1545 if (((len == 5) && (buf[0] == 0x01) && (buf[4] == 0x00)) ||
1546 ((len == 8) && (buf[0] & 0x40) &&
1547 !(buf[1] & 0x1 || buf[1] >> 2 & 0x1))) {
1549 imon_pad_to_keys(ictx, buf);
1554 printk(KERN_INFO "intf%d decoded packet: ", intf);
1555 for (i = 0; i < len; ++i)
1556 printk("%02x ", buf[i]);
1560 press_type = imon_parse_press_type(ictx, buf, ktype);
1562 goto not_input_data;
1564 spin_lock_irqsave(&ictx->kc_lock, flags);
1565 if (ictx->kc == KEY_UNKNOWN)
1567 spin_unlock_irqrestore(&ictx->kc_lock, flags);
1569 if (ktype != IMON_KEY_PANEL) {
1570 if (press_type == 0)
1573 ir_keydown(ictx->rdev, ictx->rc_scancode,
1575 spin_lock_irqsave(&ictx->kc_lock, flags);
1576 ictx->last_keycode = ictx->kc;
1577 spin_unlock_irqrestore(&ictx->kc_lock, flags);
1582 /* Only panel type events left to process now */
1583 spin_lock_irqsave(&ictx->kc_lock, flags);
1585 /* KEY_MUTE repeats from knob need to be suppressed */
1586 if (ictx->kc == KEY_MUTE && ictx->kc == ictx->last_keycode) {
1587 do_gettimeofday(&t);
1588 msec = tv2int(&t, &prev_time);
1590 if (msec < idev->rep[REP_DELAY]) {
1591 spin_unlock_irqrestore(&ictx->kc_lock, flags);
1597 spin_unlock_irqrestore(&ictx->kc_lock, flags);
1599 input_report_key(idev, kc, press_type);
1602 /* panel keys don't generate a release */
1603 input_report_key(idev, kc, 0);
1606 ictx->last_keycode = kc;
1611 spin_unlock_irqrestore(&ictx->kc_lock, flags);
1612 dev_info(dev, "%s: unknown keypress, code 0x%llx\n", __func__,
1613 (long long)scancode);
1618 dev_warn(dev, "imon %s: invalid incoming packet "
1619 "size (len = %d, intf%d)\n", __func__, len, intf);
1623 /* iMON 2.4G associate frame */
1624 if (buf[0] == 0x00 &&
1625 buf[2] == 0xFF && /* REFID */
1628 buf[5] == 0xFF && /* iMON 2.4G */
1629 ((buf[6] == 0x4E && buf[7] == 0xDF) || /* LT */
1630 (buf[6] == 0x5E && buf[7] == 0xDF))) { /* DT */
1631 dev_warn(dev, "%s: remote associated refid=%02X\n",
1633 ictx->rf_isassociating = false;
1638 * Callback function for USB core API: receive data
1640 static void usb_rx_callback_intf0(struct urb *urb)
1642 struct imon_context *ictx;
1648 ictx = (struct imon_context *)urb->context;
1652 switch (urb->status) {
1653 case -ENOENT: /* usbcore unlink successful! */
1656 case -ESHUTDOWN: /* transport endpoint was shut down */
1660 imon_incoming_packet(ictx, urb, intfnum);
1664 dev_warn(ictx->dev, "imon %s: status(%d): ignored\n",
1665 __func__, urb->status);
1669 usb_submit_urb(ictx->rx_urb_intf0, GFP_ATOMIC);
1672 static void usb_rx_callback_intf1(struct urb *urb)
1674 struct imon_context *ictx;
1680 ictx = (struct imon_context *)urb->context;
1684 switch (urb->status) {
1685 case -ENOENT: /* usbcore unlink successful! */
1688 case -ESHUTDOWN: /* transport endpoint was shut down */
1692 imon_incoming_packet(ictx, urb, intfnum);
1696 dev_warn(ictx->dev, "imon %s: status(%d): ignored\n",
1697 __func__, urb->status);
1701 usb_submit_urb(ictx->rx_urb_intf1, GFP_ATOMIC);
1704 static struct input_dev *imon_init_rdev(struct imon_context *ictx)
1706 struct input_dev *rdev;
1707 struct ir_dev_props *props;
1710 rdev = input_allocate_device();
1711 props = kzalloc(sizeof(*props), GFP_KERNEL);
1712 if (!rdev || !props) {
1713 dev_err(ictx->dev, "remote control dev allocation failed\n");
1717 snprintf(ictx->name_rdev, sizeof(ictx->name_rdev),
1718 "iMON Remote (%04x:%04x)", ictx->vendor, ictx->product);
1719 usb_make_path(ictx->usbdev_intf0, ictx->phys_rdev,
1720 sizeof(ictx->phys_rdev));
1721 strlcat(ictx->phys_rdev, "/input0", sizeof(ictx->phys_rdev));
1723 rdev->name = ictx->name_rdev;
1724 rdev->phys = ictx->phys_rdev;
1725 usb_to_input_id(ictx->usbdev_intf0, &rdev->id);
1726 rdev->dev.parent = ictx->dev;
1727 rdev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
1728 input_set_drvdata(rdev, ictx);
1731 props->driver_type = RC_DRIVER_SCANCODE;
1732 props->allowed_protos = IR_TYPE_OTHER | IR_TYPE_RC6; /* iMON PAD or MCE */
1733 props->change_protocol = imon_ir_change_protocol;
1734 ictx->props = props;
1736 ret = ir_input_register(rdev, RC_MAP_IMON_PAD, props, MOD_NAME);
1738 dev_err(ictx->dev, "remote input dev register failed\n");
1746 input_free_device(rdev);
1750 static struct input_dev *imon_init_idev(struct imon_context *ictx)
1752 struct input_dev *idev;
1755 idev = input_allocate_device();
1757 dev_err(ictx->dev, "input dev allocation failed\n");
1761 snprintf(ictx->name_idev, sizeof(ictx->name_idev),
1762 "iMON Panel, Knob and Mouse(%04x:%04x)",
1763 ictx->vendor, ictx->product);
1764 idev->name = ictx->name_idev;
1766 usb_make_path(ictx->usbdev_intf0, ictx->phys_idev,
1767 sizeof(ictx->phys_idev));
1768 strlcat(ictx->phys_idev, "/input1", sizeof(ictx->phys_idev));
1769 idev->phys = ictx->phys_idev;
1771 idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | BIT_MASK(EV_REL);
1773 idev->keybit[BIT_WORD(BTN_MOUSE)] =
1774 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
1775 idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y) |
1776 BIT_MASK(REL_WHEEL);
1778 /* panel and/or knob code support */
1779 for (i = 0; i < ARRAY_SIZE(imon_panel_key_table); i++) {
1780 u32 kc = imon_panel_key_table[i].keycode;
1781 __set_bit(kc, idev->keybit);
1784 usb_to_input_id(ictx->usbdev_intf0, &idev->id);
1785 idev->dev.parent = ictx->dev;
1786 input_set_drvdata(idev, ictx);
1788 ret = input_register_device(idev);
1790 dev_err(ictx->dev, "input dev register failed\n");
1797 input_free_device(idev);
1801 static struct input_dev *imon_init_touch(struct imon_context *ictx)
1803 struct input_dev *touch;
1806 touch = input_allocate_device();
1808 dev_err(ictx->dev, "touchscreen input dev allocation failed\n");
1809 goto touch_alloc_failed;
1812 snprintf(ictx->name_touch, sizeof(ictx->name_touch),
1813 "iMON USB Touchscreen (%04x:%04x)",
1814 ictx->vendor, ictx->product);
1815 touch->name = ictx->name_touch;
1817 usb_make_path(ictx->usbdev_intf1, ictx->phys_touch,
1818 sizeof(ictx->phys_touch));
1819 strlcat(ictx->phys_touch, "/input2", sizeof(ictx->phys_touch));
1820 touch->phys = ictx->phys_touch;
1823 BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
1824 touch->keybit[BIT_WORD(BTN_TOUCH)] =
1825 BIT_MASK(BTN_TOUCH);
1826 input_set_abs_params(touch, ABS_X,
1828 input_set_abs_params(touch, ABS_Y,
1831 input_set_drvdata(touch, ictx);
1833 usb_to_input_id(ictx->usbdev_intf1, &touch->id);
1834 touch->dev.parent = ictx->dev;
1835 ret = input_register_device(touch);
1837 dev_info(ictx->dev, "touchscreen input dev register failed\n");
1838 goto touch_register_failed;
1843 touch_register_failed:
1844 input_free_device(ictx->touch);
1850 static bool imon_find_endpoints(struct imon_context *ictx,
1851 struct usb_host_interface *iface_desc)
1853 struct usb_endpoint_descriptor *ep;
1854 struct usb_endpoint_descriptor *rx_endpoint = NULL;
1855 struct usb_endpoint_descriptor *tx_endpoint = NULL;
1856 int ifnum = iface_desc->desc.bInterfaceNumber;
1857 int num_endpts = iface_desc->desc.bNumEndpoints;
1858 int i, ep_dir, ep_type;
1859 bool ir_ep_found = false;
1860 bool display_ep_found = false;
1861 bool tx_control = false;
1864 * Scan the endpoint list and set:
1865 * first input endpoint = IR endpoint
1866 * first output endpoint = display endpoint
1868 for (i = 0; i < num_endpts && !(ir_ep_found && display_ep_found); ++i) {
1869 ep = &iface_desc->endpoint[i].desc;
1870 ep_dir = ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK;
1871 ep_type = ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
1873 if (!ir_ep_found && ep_dir == USB_DIR_IN &&
1874 ep_type == USB_ENDPOINT_XFER_INT) {
1878 dev_dbg(ictx->dev, "%s: found IR endpoint\n", __func__);
1880 } else if (!display_ep_found && ep_dir == USB_DIR_OUT &&
1881 ep_type == USB_ENDPOINT_XFER_INT) {
1883 display_ep_found = true;
1884 dev_dbg(ictx->dev, "%s: found display endpoint\n", __func__);
1889 ictx->rx_endpoint_intf0 = rx_endpoint;
1891 * tx is used to send characters to lcd/vfd, associate RF
1892 * remotes, set IR protocol, and maybe more...
1894 ictx->tx_endpoint = tx_endpoint;
1896 ictx->rx_endpoint_intf1 = rx_endpoint;
1900 * If we didn't find a display endpoint, this is probably one of the
1901 * newer iMON devices that use control urb instead of interrupt
1903 if (!display_ep_found) {
1905 display_ep_found = true;
1906 dev_dbg(ictx->dev, "%s: device uses control endpoint, not "
1907 "interface OUT endpoint\n", __func__);
1911 * Some iMON receivers have no display. Unfortunately, it seems
1912 * that SoundGraph recycles device IDs between devices both with
1915 if (ictx->display_type == IMON_DISPLAY_TYPE_NONE) {
1916 display_ep_found = false;
1917 dev_dbg(ictx->dev, "%s: device has no display\n", __func__);
1921 * iMON Touch devices have a VGA touchscreen, but no "display", as
1922 * that refers to e.g. /dev/lcd0 (a character device LCD or VFD).
1924 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) {
1925 display_ep_found = false;
1926 dev_dbg(ictx->dev, "%s: iMON Touch device found\n", __func__);
1929 /* Input endpoint is mandatory */
1931 err("%s: no valid input (IR) endpoint found.", __func__);
1933 ictx->tx_control = tx_control;
1935 if (display_ep_found)
1936 ictx->display_supported = true;
1942 static struct imon_context *imon_init_intf0(struct usb_interface *intf)
1944 struct imon_context *ictx;
1947 struct device *dev = &intf->dev;
1948 struct usb_host_interface *iface_desc;
1951 ictx = kzalloc(sizeof(struct imon_context), GFP_KERNEL);
1953 dev_err(dev, "%s: kzalloc failed for context", __func__);
1956 rx_urb = usb_alloc_urb(0, GFP_KERNEL);
1958 dev_err(dev, "%s: usb_alloc_urb failed for IR urb", __func__);
1959 goto rx_urb_alloc_failed;
1961 tx_urb = usb_alloc_urb(0, GFP_KERNEL);
1963 dev_err(dev, "%s: usb_alloc_urb failed for display urb",
1965 goto tx_urb_alloc_failed;
1968 mutex_init(&ictx->lock);
1969 spin_lock_init(&ictx->kc_lock);
1971 mutex_lock(&ictx->lock);
1974 ictx->usbdev_intf0 = usb_get_dev(interface_to_usbdev(intf));
1975 ictx->dev_present_intf0 = true;
1976 ictx->rx_urb_intf0 = rx_urb;
1977 ictx->tx_urb = tx_urb;
1978 ictx->rf_device = false;
1980 ictx->vendor = le16_to_cpu(ictx->usbdev_intf0->descriptor.idVendor);
1981 ictx->product = le16_to_cpu(ictx->usbdev_intf0->descriptor.idProduct);
1984 iface_desc = intf->cur_altsetting;
1985 if (!imon_find_endpoints(ictx, iface_desc)) {
1986 goto find_endpoint_failed;
1989 ictx->idev = imon_init_idev(ictx);
1991 dev_err(dev, "%s: input device setup failed\n", __func__);
1992 goto idev_setup_failed;
1995 ictx->rdev = imon_init_rdev(ictx);
1997 dev_err(dev, "%s: rc device setup failed\n", __func__);
1998 goto rdev_setup_failed;
2001 usb_fill_int_urb(ictx->rx_urb_intf0, ictx->usbdev_intf0,
2002 usb_rcvintpipe(ictx->usbdev_intf0,
2003 ictx->rx_endpoint_intf0->bEndpointAddress),
2004 ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf),
2005 usb_rx_callback_intf0, ictx,
2006 ictx->rx_endpoint_intf0->bInterval);
2008 ret = usb_submit_urb(ictx->rx_urb_intf0, GFP_KERNEL);
2010 err("%s: usb_submit_urb failed for intf0 (%d)",
2012 goto urb_submit_failed;
2018 ir_input_unregister(ictx->rdev);
2020 input_unregister_device(ictx->idev);
2022 find_endpoint_failed:
2023 mutex_unlock(&ictx->lock);
2024 usb_free_urb(tx_urb);
2025 tx_urb_alloc_failed:
2026 usb_free_urb(rx_urb);
2027 rx_urb_alloc_failed:
2030 dev_err(dev, "unable to initialize intf0, err %d\n", ret);
2035 static struct imon_context *imon_init_intf1(struct usb_interface *intf,
2036 struct imon_context *ictx)
2039 struct usb_host_interface *iface_desc;
2042 rx_urb = usb_alloc_urb(0, GFP_KERNEL);
2044 err("%s: usb_alloc_urb failed for IR urb", __func__);
2045 goto rx_urb_alloc_failed;
2048 mutex_lock(&ictx->lock);
2050 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) {
2051 init_timer(&ictx->ttimer);
2052 ictx->ttimer.data = (unsigned long)ictx;
2053 ictx->ttimer.function = imon_touch_display_timeout;
2056 ictx->usbdev_intf1 = usb_get_dev(interface_to_usbdev(intf));
2057 ictx->dev_present_intf1 = true;
2058 ictx->rx_urb_intf1 = rx_urb;
2061 iface_desc = intf->cur_altsetting;
2062 if (!imon_find_endpoints(ictx, iface_desc))
2063 goto find_endpoint_failed;
2065 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) {
2066 ictx->touch = imon_init_touch(ictx);
2068 goto touch_setup_failed;
2072 usb_fill_int_urb(ictx->rx_urb_intf1, ictx->usbdev_intf1,
2073 usb_rcvintpipe(ictx->usbdev_intf1,
2074 ictx->rx_endpoint_intf1->bEndpointAddress),
2075 ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf),
2076 usb_rx_callback_intf1, ictx,
2077 ictx->rx_endpoint_intf1->bInterval);
2079 ret = usb_submit_urb(ictx->rx_urb_intf1, GFP_KERNEL);
2082 err("%s: usb_submit_urb failed for intf1 (%d)",
2084 goto urb_submit_failed;
2091 input_unregister_device(ictx->touch);
2093 find_endpoint_failed:
2094 mutex_unlock(&ictx->lock);
2095 usb_free_urb(rx_urb);
2096 rx_urb_alloc_failed:
2097 dev_err(ictx->dev, "unable to initialize intf0, err %d\n", ret);
2103 * The 0x15c2:0xffdc device ID was used for umpteen different imon
2104 * devices, and all of them constantly spew interrupts, even when there
2105 * is no actual data to report. However, byte 6 of this buffer looks like
2106 * its unique across device variants, so we're trying to key off that to
2107 * figure out which display type (if any) and what IR protocol the device
2108 * actually supports. These devices have their IR protocol hard-coded into
2109 * their firmware, they can't be changed on the fly like the newer hardware.
2111 static void imon_get_ffdc_type(struct imon_context *ictx)
2113 u8 ffdc_cfg_byte = ictx->usb_rx_buf[6];
2114 u8 detected_display_type = IMON_DISPLAY_TYPE_NONE;
2115 u64 allowed_protos = IR_TYPE_OTHER;
2117 switch (ffdc_cfg_byte) {
2118 /* iMON Knob, no display, iMON IR + vol knob */
2120 dev_info(ictx->dev, "0xffdc iMON Knob, iMON IR");
2121 ictx->display_supported = false;
2123 /* iMON 2.4G LT (usb stick), no display, iMON RF */
2125 dev_info(ictx->dev, "0xffdc iMON 2.4G LT, iMON RF");
2126 ictx->display_supported = false;
2127 ictx->rf_device = true;
2129 /* iMON VFD, no IR (does have vol knob tho) */
2131 dev_info(ictx->dev, "0xffdc iMON VFD + knob, no IR");
2132 detected_display_type = IMON_DISPLAY_TYPE_VFD;
2134 /* iMON VFD, iMON IR */
2137 dev_info(ictx->dev, "0xffdc iMON VFD, iMON IR");
2138 detected_display_type = IMON_DISPLAY_TYPE_VFD;
2140 /* iMON LCD, MCE IR */
2143 dev_info(ictx->dev, "0xffdc iMON LCD, MCE IR");
2144 detected_display_type = IMON_DISPLAY_TYPE_LCD;
2145 allowed_protos = IR_TYPE_RC6;
2148 dev_info(ictx->dev, "Unknown 0xffdc device, "
2149 "defaulting to VFD and iMON IR");
2150 detected_display_type = IMON_DISPLAY_TYPE_VFD;
2154 printk(KERN_CONT " (id 0x%02x)\n", ffdc_cfg_byte);
2156 ictx->display_type = detected_display_type;
2157 ictx->props->allowed_protos = allowed_protos;
2158 ictx->ir_type = allowed_protos;
2161 static void imon_set_display_type(struct imon_context *ictx,
2162 struct usb_interface *intf)
2164 u8 configured_display_type = IMON_DISPLAY_TYPE_VFD;
2167 * Try to auto-detect the type of display if the user hasn't set
2168 * it by hand via the display_type modparam. Default is VFD.
2171 if (display_type == IMON_DISPLAY_TYPE_AUTO) {
2172 switch (ictx->product) {
2174 /* set in imon_get_ffdc_type() */
2175 configured_display_type = ictx->display_type;
2179 configured_display_type = IMON_DISPLAY_TYPE_VGA;
2184 configured_display_type = IMON_DISPLAY_TYPE_LCD;
2190 configured_display_type = IMON_DISPLAY_TYPE_NONE;
2191 ictx->display_supported = false;
2196 configured_display_type = IMON_DISPLAY_TYPE_VFD;
2200 configured_display_type = display_type;
2201 if (display_type == IMON_DISPLAY_TYPE_NONE)
2202 ictx->display_supported = false;
2204 ictx->display_supported = true;
2205 dev_info(ictx->dev, "%s: overriding display type to %d via "
2206 "modparam\n", __func__, display_type);
2209 ictx->display_type = configured_display_type;
2212 static void imon_init_display(struct imon_context *ictx,
2213 struct usb_interface *intf)
2217 dev_dbg(ictx->dev, "Registering iMON display with sysfs\n");
2219 /* set up sysfs entry for built-in clock */
2220 ret = sysfs_create_group(&intf->dev.kobj,
2221 &imon_display_attribute_group);
2223 dev_err(ictx->dev, "Could not create display sysfs "
2224 "entries(%d)", ret);
2226 if (ictx->display_type == IMON_DISPLAY_TYPE_LCD)
2227 ret = usb_register_dev(intf, &imon_lcd_class);
2229 ret = usb_register_dev(intf, &imon_vfd_class);
2231 /* Not a fatal error, so ignore */
2232 dev_info(ictx->dev, "could not get a minor number for "
2238 * Callback function for USB core API: Probe
2240 static int __devinit imon_probe(struct usb_interface *interface,
2241 const struct usb_device_id *id)
2243 struct usb_device *usbdev = NULL;
2244 struct usb_host_interface *iface_desc = NULL;
2245 struct usb_interface *first_if;
2246 struct device *dev = &interface->dev;
2247 int ifnum, code_length, sysfs_err;
2249 struct imon_context *ictx = NULL;
2250 struct imon_context *first_if_ctx = NULL;
2251 u16 vendor, product;
2252 const unsigned char fp_packet[] = { 0x40, 0x00, 0x00, 0x00,
2253 0x00, 0x00, 0x00, 0x88 };
2255 code_length = BUF_CHUNK_SIZE * 8;
2257 usbdev = usb_get_dev(interface_to_usbdev(interface));
2258 iface_desc = interface->cur_altsetting;
2259 ifnum = iface_desc->desc.bInterfaceNumber;
2260 vendor = le16_to_cpu(usbdev->descriptor.idVendor);
2261 product = le16_to_cpu(usbdev->descriptor.idProduct);
2263 dev_dbg(dev, "%s: found iMON device (%04x:%04x, intf%d)\n",
2264 __func__, vendor, product, ifnum);
2266 /* prevent races probing devices w/multiple interfaces */
2267 mutex_lock(&driver_lock);
2269 first_if = usb_ifnum_to_if(usbdev, 0);
2270 first_if_ctx = (struct imon_context *)usb_get_intfdata(first_if);
2273 ictx = imon_init_intf0(interface);
2275 err("%s: failed to initialize context!\n", __func__);
2281 /* this is the secondary interface on the device */
2282 ictx = imon_init_intf1(interface, first_if_ctx);
2284 err("%s: failed to attach to context!\n", __func__);
2291 usb_set_intfdata(interface, ictx);
2294 /* Enable front-panel buttons and/or knobs */
2295 memcpy(ictx->usb_tx_buf, &fp_packet, sizeof(fp_packet));
2296 ret = send_packet(ictx);
2297 /* Not fatal, but warn about it */
2299 dev_info(dev, "failed to enable panel buttons "
2302 if (product == 0xffdc)
2303 imon_get_ffdc_type(ictx);
2305 imon_set_display_type(ictx, interface);
2307 if (product == 0xffdc && ictx->rf_device) {
2308 sysfs_err = sysfs_create_group(&interface->dev.kobj,
2309 &imon_rf_attribute_group);
2311 err("%s: Could not create RF sysfs entries(%d)",
2312 __func__, sysfs_err);
2315 if (ictx->display_supported)
2316 imon_init_display(ictx, interface);
2319 /* set IR protocol/remote type */
2320 ret = imon_ir_change_protocol(ictx, ictx->ir_type);
2322 dev_warn(dev, "%s: failed to set IR protocol, falling back "
2323 "to standard iMON protocol mode\n", __func__);
2324 ictx->ir_type = IR_TYPE_OTHER;
2327 dev_info(dev, "iMON device (%04x:%04x, intf%d) on "
2328 "usb<%d:%d> initialized\n", vendor, product, ifnum,
2329 usbdev->bus->busnum, usbdev->devnum);
2331 mutex_unlock(&ictx->lock);
2332 mutex_unlock(&driver_lock);
2337 mutex_unlock(&driver_lock);
2338 dev_err(dev, "unable to register, err %d\n", ret);
2344 * Callback function for USB core API: disconnect
2346 static void __devexit imon_disconnect(struct usb_interface *interface)
2348 struct imon_context *ictx;
2352 /* prevent races with multi-interface device probing and display_open */
2353 mutex_lock(&driver_lock);
2355 ictx = usb_get_intfdata(interface);
2357 ifnum = interface->cur_altsetting->desc.bInterfaceNumber;
2359 mutex_lock(&ictx->lock);
2362 * sysfs_remove_group is safe to call even if sysfs_create_group
2363 * hasn't been called
2365 sysfs_remove_group(&interface->dev.kobj,
2366 &imon_display_attribute_group);
2367 sysfs_remove_group(&interface->dev.kobj,
2368 &imon_rf_attribute_group);
2370 usb_set_intfdata(interface, NULL);
2372 /* Abort ongoing write */
2373 if (ictx->tx.busy) {
2374 usb_kill_urb(ictx->tx_urb);
2375 complete_all(&ictx->tx.finished);
2379 ictx->dev_present_intf0 = false;
2380 usb_kill_urb(ictx->rx_urb_intf0);
2381 input_unregister_device(ictx->idev);
2382 ir_input_unregister(ictx->rdev);
2383 if (ictx->display_supported) {
2384 if (ictx->display_type == IMON_DISPLAY_TYPE_LCD)
2385 usb_deregister_dev(interface, &imon_lcd_class);
2387 usb_deregister_dev(interface, &imon_vfd_class);
2390 ictx->dev_present_intf1 = false;
2391 usb_kill_urb(ictx->rx_urb_intf1);
2392 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA)
2393 input_unregister_device(ictx->touch);
2396 if (!ictx->dev_present_intf0 && !ictx->dev_present_intf1) {
2397 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA)
2398 del_timer_sync(&ictx->ttimer);
2399 mutex_unlock(&ictx->lock);
2400 if (!ictx->display_isopen)
2401 free_imon_context(ictx);
2403 mutex_unlock(&ictx->lock);
2405 mutex_unlock(&driver_lock);
2407 dev_dbg(dev, "%s: iMON device (intf%d) disconnected\n",
2411 static int imon_suspend(struct usb_interface *intf, pm_message_t message)
2413 struct imon_context *ictx = usb_get_intfdata(intf);
2414 int ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
2417 usb_kill_urb(ictx->rx_urb_intf0);
2419 usb_kill_urb(ictx->rx_urb_intf1);
2424 static int imon_resume(struct usb_interface *intf)
2427 struct imon_context *ictx = usb_get_intfdata(intf);
2428 int ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
2431 usb_fill_int_urb(ictx->rx_urb_intf0, ictx->usbdev_intf0,
2432 usb_rcvintpipe(ictx->usbdev_intf0,
2433 ictx->rx_endpoint_intf0->bEndpointAddress),
2434 ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf),
2435 usb_rx_callback_intf0, ictx,
2436 ictx->rx_endpoint_intf0->bInterval);
2438 rc = usb_submit_urb(ictx->rx_urb_intf0, GFP_ATOMIC);
2441 usb_fill_int_urb(ictx->rx_urb_intf1, ictx->usbdev_intf1,
2442 usb_rcvintpipe(ictx->usbdev_intf1,
2443 ictx->rx_endpoint_intf1->bEndpointAddress),
2444 ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf),
2445 usb_rx_callback_intf1, ictx,
2446 ictx->rx_endpoint_intf1->bInterval);
2448 rc = usb_submit_urb(ictx->rx_urb_intf1, GFP_ATOMIC);
2454 static int __init imon_init(void)
2458 rc = usb_register(&imon_driver);
2460 err("%s: usb register failed(%d)", __func__, rc);
2467 static void __exit imon_exit(void)
2469 usb_deregister(&imon_driver);
2472 module_init(imon_init);
2473 module_exit(imon_exit);