2 * imon.c: input and display driver for SoundGraph iMON IR/VFD/LCD
4 * Copyright(C) 2009 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.1"
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
58 #define IMON_KEY_RELEASE_OFFSET 1000
60 /*** P R O T O T Y P E S ***/
62 /* USB Callback prototypes */
63 static int imon_probe(struct usb_interface *interface,
64 const struct usb_device_id *id);
65 static void imon_disconnect(struct usb_interface *interface);
66 static void usb_rx_callback_intf0(struct urb *urb);
67 static void usb_rx_callback_intf1(struct urb *urb);
68 static void usb_tx_callback(struct urb *urb);
70 /* suspend/resume support */
71 static int imon_resume(struct usb_interface *intf);
72 static int imon_suspend(struct usb_interface *intf, pm_message_t message);
74 /* Display file_operations function prototypes */
75 static int display_open(struct inode *inode, struct file *file);
76 static int display_close(struct inode *inode, struct file *file);
78 /* VFD write operation */
79 static ssize_t vfd_write(struct file *file, const char *buf,
80 size_t n_bytes, loff_t *pos);
82 /* LCD file_operations override function prototypes */
83 static ssize_t lcd_write(struct file *file, const char *buf,
84 size_t n_bytes, loff_t *pos);
86 /*** G L O B A L S ***/
90 struct ir_dev_props *props;
91 struct ir_input_dev *ir;
92 /* Newer devices have two interfaces */
93 struct usb_device *usbdev_intf0;
94 struct usb_device *usbdev_intf1;
96 bool display_supported; /* not all controllers do */
97 bool display_isopen; /* display port has been opened */
98 bool rf_isassociating; /* RF remote associating */
99 bool dev_present_intf0; /* USB device presence, interface 0 */
100 bool dev_present_intf1; /* USB device presence, interface 1 */
102 struct mutex lock; /* to lock this object */
103 wait_queue_head_t remove_ok; /* For unexpected USB disconnects */
105 struct usb_endpoint_descriptor *rx_endpoint_intf0;
106 struct usb_endpoint_descriptor *rx_endpoint_intf1;
107 struct usb_endpoint_descriptor *tx_endpoint;
108 struct urb *rx_urb_intf0;
109 struct urb *rx_urb_intf1;
112 unsigned char usb_rx_buf[8];
113 unsigned char usb_tx_buf[8];
116 unsigned char data_buf[35]; /* user data buffer */
117 struct completion finished; /* wait for write to finish */
118 bool busy; /* write in progress */
119 int status; /* status of tx completion */
122 u16 vendor; /* usb vendor ID */
123 u16 product; /* usb product ID */
125 struct input_dev *idev; /* input device for remote */
126 struct input_dev *touch; /* input device for touchscreen */
128 u32 kc; /* current input keycode */
129 u32 last_keycode; /* last reported input keycode */
130 u8 ir_protocol; /* iMON or MCE (RC6) IR protocol? */
131 u8 ir_proto_mask; /* supported IR protocol mask */
132 u8 mce_toggle_bit; /* last mce toggle bit */
133 bool release_code; /* some keys send a release code */
135 u8 display_type; /* store the display type */
136 bool pad_mouse; /* toggle kbd(0)/mouse(1) mode */
138 char name_idev[128]; /* input device name */
139 char phys_idev[64]; /* input device phys path */
140 struct timer_list itimer; /* input device timer, need for rc6 */
142 char name_touch[128]; /* touch screen name */
143 char phys_touch[64]; /* touch screen phys path */
144 struct timer_list ttimer; /* touch screen timer */
145 int touch_x; /* x coordinate on touchscreen */
146 int touch_y; /* y coordinate on touchscreen */
149 #define TOUCH_TIMEOUT (HZ/30)
150 #define MCE_TIMEOUT_MS 200
152 /* vfd character device file operations */
153 static const struct file_operations vfd_fops = {
154 .owner = THIS_MODULE,
155 .open = &display_open,
157 .release = &display_close
160 /* lcd character device file operations */
161 static const struct file_operations lcd_fops = {
162 .owner = THIS_MODULE,
163 .open = &display_open,
165 .release = &display_close
169 IMON_DISPLAY_TYPE_AUTO = 0,
170 IMON_DISPLAY_TYPE_VFD = 1,
171 IMON_DISPLAY_TYPE_LCD = 2,
172 IMON_DISPLAY_TYPE_VGA = 3,
173 IMON_DISPLAY_TYPE_NONE = 4,
177 IMON_IR_PROTOCOL_AUTO = 0x0,
178 IMON_IR_PROTOCOL_MCE = 0x1,
179 IMON_IR_PROTOCOL_IMON = 0x2,
180 IMON_IR_PROTOCOL_IMON_NOPAD = 0x4,
184 IMON_IR_PROTO_MASK_NONE = 0x0,
185 IMON_IR_PROTO_MASK_MCE = IMON_IR_PROTOCOL_MCE,
186 IMON_IR_PROTO_MASK_IMON = IMON_IR_PROTOCOL_IMON |
187 IMON_IR_PROTOCOL_IMON_NOPAD,
197 * USB Device ID for iMON USB Control Boards
199 * The Windows drivers contain 6 different inf files, more or less one for
200 * each new device until the 0x0034-0x0046 devices, which all use the same
201 * driver. Some of the devices in the 34-46 range haven't been definitively
202 * identified yet. Early devices have either a TriGem Computer, Inc. or a
203 * Samsung vendor ID (0x0aa8 and 0x04e8 respectively), while all later
204 * devices use the SoundGraph vendor ID (0x15c2). This driver only supports
205 * the ffdc and later devices, which do onboard decoding.
207 static struct usb_device_id imon_usb_id_table[] = {
209 * Several devices with this same device ID, all use iMON_PAD.inf
210 * SoundGraph iMON PAD (IR & VFD)
211 * SoundGraph iMON PAD (IR & LCD)
212 * SoundGraph iMON Knob (IR only)
214 { USB_DEVICE(0x15c2, 0xffdc) },
217 * Newer devices, all driven by the latest iMON Windows driver, full
218 * list of device IDs extracted via 'strings Setup/data1.hdr |grep 15c2'
219 * Need user input to fill in details on unknown devices.
221 /* SoundGraph iMON OEM Touch LCD (IR & 7" VGA LCD) */
222 { USB_DEVICE(0x15c2, 0x0034) },
223 /* SoundGraph iMON OEM Touch LCD (IR & 4.3" VGA LCD) */
224 { USB_DEVICE(0x15c2, 0x0035) },
225 /* SoundGraph iMON OEM VFD (IR & VFD) */
226 { USB_DEVICE(0x15c2, 0x0036) },
227 /* device specifics unknown */
228 { USB_DEVICE(0x15c2, 0x0037) },
229 /* SoundGraph iMON OEM LCD (IR & LCD) */
230 { USB_DEVICE(0x15c2, 0x0038) },
231 /* SoundGraph iMON UltraBay (IR & LCD) */
232 { USB_DEVICE(0x15c2, 0x0039) },
233 /* device specifics unknown */
234 { USB_DEVICE(0x15c2, 0x003a) },
235 /* device specifics unknown */
236 { USB_DEVICE(0x15c2, 0x003b) },
237 /* SoundGraph iMON OEM Inside (IR only) */
238 { USB_DEVICE(0x15c2, 0x003c) },
239 /* device specifics unknown */
240 { USB_DEVICE(0x15c2, 0x003d) },
241 /* device specifics unknown */
242 { USB_DEVICE(0x15c2, 0x003e) },
243 /* device specifics unknown */
244 { USB_DEVICE(0x15c2, 0x003f) },
245 /* device specifics unknown */
246 { USB_DEVICE(0x15c2, 0x0040) },
247 /* SoundGraph iMON MINI (IR only) */
248 { USB_DEVICE(0x15c2, 0x0041) },
249 /* Antec Veris Multimedia Station EZ External (IR only) */
250 { USB_DEVICE(0x15c2, 0x0042) },
251 /* Antec Veris Multimedia Station Basic Internal (IR only) */
252 { USB_DEVICE(0x15c2, 0x0043) },
253 /* Antec Veris Multimedia Station Elite (IR & VFD) */
254 { USB_DEVICE(0x15c2, 0x0044) },
255 /* Antec Veris Multimedia Station Premiere (IR & LCD) */
256 { USB_DEVICE(0x15c2, 0x0045) },
257 /* device specifics unknown */
258 { USB_DEVICE(0x15c2, 0x0046) },
262 /* USB Device data */
263 static struct usb_driver imon_driver = {
266 .disconnect = imon_disconnect,
267 .suspend = imon_suspend,
268 .resume = imon_resume,
269 .id_table = imon_usb_id_table,
272 static struct usb_class_driver imon_vfd_class = {
275 .minor_base = DISPLAY_MINOR_BASE,
278 static struct usb_class_driver imon_lcd_class = {
281 .minor_base = DISPLAY_MINOR_BASE,
284 /* imon receiver front panel/knob key table */
285 static const struct {
288 } imon_panel_key_table[] = {
289 { 0x000000000f00ffeell, KEY_PROG1 }, /* Go */
290 { 0x000000001f00ffeell, KEY_AUDIO },
291 { 0x000000002000ffeell, KEY_VIDEO },
292 { 0x000000002100ffeell, KEY_CAMERA },
293 { 0x000000002700ffeell, KEY_DVD },
294 { 0x000000002300ffeell, KEY_TV },
295 { 0x000000000500ffeell, KEY_PREVIOUS },
296 { 0x000000000700ffeell, KEY_REWIND },
297 { 0x000000000400ffeell, KEY_STOP },
298 { 0x000000003c00ffeell, KEY_PLAYPAUSE },
299 { 0x000000000800ffeell, KEY_FASTFORWARD },
300 { 0x000000000600ffeell, KEY_NEXT },
301 { 0x000000010000ffeell, KEY_RIGHT },
302 { 0x000001000000ffeell, KEY_LEFT },
303 { 0x000000003d00ffeell, KEY_SELECT },
304 { 0x000100000000ffeell, KEY_VOLUMEUP },
305 { 0x010000000000ffeell, KEY_VOLUMEDOWN },
306 { 0x000000000100ffeell, KEY_MUTE },
307 /* iMON Knob values */
308 { 0x000100ffffffffeell, KEY_VOLUMEUP },
309 { 0x010000ffffffffeell, KEY_VOLUMEDOWN },
310 { 0x000008ffffffffeell, KEY_MUTE },
313 /* to prevent races between open() and disconnect(), probing, etc */
314 static DEFINE_MUTEX(driver_lock);
316 /* Module bookkeeping bits */
317 MODULE_AUTHOR(MOD_AUTHOR);
318 MODULE_DESCRIPTION(MOD_DESC);
319 MODULE_VERSION(MOD_VERSION);
320 MODULE_LICENSE("GPL");
321 MODULE_DEVICE_TABLE(usb, imon_usb_id_table);
324 module_param(debug, bool, S_IRUGO | S_IWUSR);
325 MODULE_PARM_DESC(debug, "Debug messages: 0=no, 1=yes(default: no)");
327 /* lcd, vfd, vga or none? should be auto-detected, but can be overridden... */
328 static int display_type;
329 module_param(display_type, int, S_IRUGO);
330 MODULE_PARM_DESC(display_type, "Type of attached display. 0=autodetect, "
331 "1=vfd, 2=lcd, 3=vga, 4=none (default: autodetect)");
333 /* IR protocol: native iMON, Windows MCE (RC-6), or iMON w/o PAD stabilize */
334 static int ir_protocol;
335 module_param(ir_protocol, int, S_IRUGO | S_IWUSR);
336 MODULE_PARM_DESC(ir_protocol, "Which IR protocol to use. 0=auto-detect, "
337 "1=Windows Media Center Ed. (RC-6), 2=iMON native, "
338 "4=iMON w/o PAD stabilize (default: auto-detect)");
341 * In certain use cases, mouse mode isn't really helpful, and could actually
342 * cause confusion, so allow disabling it when the IR device is open.
345 module_param(nomouse, bool, S_IRUGO | S_IWUSR);
346 MODULE_PARM_DESC(nomouse, "Disable mouse input device mode when IR device is "
347 "open. 0=don't disable, 1=disable. (default: don't disable)");
349 /* threshold at which a pad push registers as an arrow key in kbd mode */
350 static int pad_thresh;
351 module_param(pad_thresh, int, S_IRUGO | S_IWUSR);
352 MODULE_PARM_DESC(pad_thresh, "Threshold at which a pad push registers as an "
353 "arrow key in kbd mode (default: 28)");
356 static void free_imon_context(struct imon_context *ictx)
358 struct device *dev = ictx->dev;
360 usb_free_urb(ictx->tx_urb);
361 usb_free_urb(ictx->rx_urb_intf0);
362 usb_free_urb(ictx->rx_urb_intf1);
365 dev_dbg(dev, "%s: iMON context freed\n", __func__);
369 * Called when the Display device (e.g. /dev/lcd0)
370 * is opened by the application.
372 static int display_open(struct inode *inode, struct file *file)
374 struct usb_interface *interface;
375 struct imon_context *ictx = NULL;
379 /* prevent races with disconnect */
380 mutex_lock(&driver_lock);
382 subminor = iminor(inode);
383 interface = usb_find_interface(&imon_driver, subminor);
385 err("%s: could not find interface for minor %d",
390 ictx = usb_get_intfdata(interface);
393 err("%s: no context found for minor %d", __func__, subminor);
398 mutex_lock(&ictx->lock);
400 if (!ictx->display_supported) {
401 err("%s: display not supported by device", __func__);
403 } else if (ictx->display_isopen) {
404 err("%s: display port is already open", __func__);
407 ictx->display_isopen = 1;
408 file->private_data = ictx;
409 dev_dbg(ictx->dev, "display port opened\n");
412 mutex_unlock(&ictx->lock);
415 mutex_unlock(&driver_lock);
420 * Called when the display device (e.g. /dev/lcd0)
421 * is closed by the application.
423 static int display_close(struct inode *inode, struct file *file)
425 struct imon_context *ictx = NULL;
428 ictx = (struct imon_context *)file->private_data;
431 err("%s: no context for device", __func__);
435 mutex_lock(&ictx->lock);
437 if (!ictx->display_supported) {
438 err("%s: display not supported by device", __func__);
440 } else if (!ictx->display_isopen) {
441 err("%s: display is not open", __func__);
444 ictx->display_isopen = 0;
445 dev_dbg(ictx->dev, "display port closed\n");
446 if (!ictx->dev_present_intf0) {
448 * Device disconnected before close and IR port is not
449 * open. If IR port is open, context will be deleted by
452 mutex_unlock(&ictx->lock);
453 free_imon_context(ictx);
458 mutex_unlock(&ictx->lock);
463 * Sends a packet to the device -- this function must be called
464 * with ictx->lock held.
466 static int send_packet(struct imon_context *ictx)
469 unsigned long timeout;
472 struct usb_ctrlrequest *control_req = NULL;
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;
480 usb_fill_int_urb(ictx->tx_urb, ictx->usbdev_intf0, pipe,
482 sizeof(ictx->usb_tx_buf),
483 usb_tx_callback, ictx, interval);
485 ictx->tx_urb->actual_length = 0;
487 /* fill request into kmalloc'ed space: */
488 control_req = kmalloc(sizeof(struct usb_ctrlrequest),
490 if (control_req == NULL)
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);
500 /* control pipe is endpoint 0x00 */
501 pipe = usb_sndctrlpipe(ictx->usbdev_intf0, 0);
503 /* build the control urb */
504 usb_fill_control_urb(ictx->tx_urb, ictx->usbdev_intf0,
505 pipe, (unsigned char *)control_req,
507 sizeof(ictx->usb_tx_buf),
508 usb_tx_callback, ictx);
509 ictx->tx_urb->actual_length = 0;
512 init_completion(&ictx->tx.finished);
514 smp_rmb(); /* ensure later readers know we're busy */
516 retval = usb_submit_urb(ictx->tx_urb, GFP_KERNEL);
519 smp_rmb(); /* ensure later readers know we're not busy */
520 err("%s: error submitting urb(%d)", __func__, retval);
522 /* Wait for transmission to complete (or abort) */
523 mutex_unlock(&ictx->lock);
524 retval = wait_for_completion_interruptible(
527 err("%s: task interrupted", __func__);
528 mutex_lock(&ictx->lock);
530 retval = ictx->tx.status;
532 err("%s: packet tx failed (%d)", __func__, retval);
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.
542 timeout = msecs_to_jiffies(5);
543 set_current_state(TASK_UNINTERRUPTIBLE);
544 schedule_timeout(timeout);
550 * Sends an associate packet to the iMON 2.4G.
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).
557 static int send_associate_24g(struct imon_context *ictx)
560 const unsigned char packet[8] = { 0x01, 0x00, 0x00, 0x00,
561 0x00, 0x00, 0x00, 0x20 };
564 err("%s: no context for device", __func__);
568 if (!ictx->dev_present_intf0) {
569 err("%s: no iMON device present", __func__);
573 memcpy(ictx->usb_tx_buf, packet, sizeof(packet));
574 retval = send_packet(ictx);
580 * Sends packets to setup and show clock on iMON display
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
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,
592 unsigned char clock_enable_pkt[IMON_CLOCK_ENABLE_PACKETS][8];
597 err("%s: no context for device", __func__);
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;
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;
619 if (ictx->product == 0xffdc) {
620 clock_enable_pkt[0][7] = 0x50;
621 clock_enable_pkt[1][7] = 0x51;
623 clock_enable_pkt[0][7] = 0x88;
624 clock_enable_pkt[1][7] = 0x8a;
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;
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;
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);
658 err("%s: send_packet failed for packet %d",
668 * These are the sysfs functions to handle the association on the iMON 2.4G LT.
670 static ssize_t show_associate_remote(struct device *d,
671 struct device_attribute *attr,
674 struct imon_context *ictx = dev_get_drvdata(d);
679 mutex_lock(&ictx->lock);
680 if (ictx->rf_isassociating)
681 strcpy(buf, "associating\n");
683 strcpy(buf, "closed\n");
685 dev_info(d, "Visit http://www.lirc.org/html/imon-24g.html for "
686 "instructions on how to associate your iMON 2.4G DT/LT "
688 mutex_unlock(&ictx->lock);
692 static ssize_t store_associate_remote(struct device *d,
693 struct device_attribute *attr,
694 const char *buf, size_t count)
696 struct imon_context *ictx;
698 ictx = dev_get_drvdata(d);
703 mutex_lock(&ictx->lock);
704 ictx->rf_isassociating = 1;
705 send_associate_24g(ictx);
706 mutex_unlock(&ictx->lock);
712 * sysfs functions to control internal imon clock
714 static ssize_t show_imon_clock(struct device *d,
715 struct device_attribute *attr, char *buf)
717 struct imon_context *ictx = dev_get_drvdata(d);
723 mutex_lock(&ictx->lock);
725 if (!ictx->display_supported) {
726 len = snprintf(buf, PAGE_SIZE, "Not supported.");
728 len = snprintf(buf, PAGE_SIZE,
729 "To set the clock on your iMON display:\n"
730 "# date \"+%%y %%m %%d %%w %%H %%M %%S\" > imon_clock\n"
731 "%s", ictx->display_isopen ?
732 "\nNOTE: imon device must be closed\n" : "");
735 mutex_unlock(&ictx->lock);
740 static ssize_t store_imon_clock(struct device *d,
741 struct device_attribute *attr,
742 const char *buf, size_t count)
744 struct imon_context *ictx = dev_get_drvdata(d);
746 unsigned int year, month, day, dow, hour, minute, second;
751 mutex_lock(&ictx->lock);
753 if (!ictx->display_supported) {
756 } else if (ictx->display_isopen) {
761 if (sscanf(buf, "%u %u %u %u %u %u %u", &year, &month, &day, &dow,
762 &hour, &minute, &second) != 7) {
767 if ((month < 1 || month > 12) ||
768 (day < 1 || day > 31) || (dow > 6) ||
769 (hour > 23) || (minute > 59) || (second > 59)) {
774 retval = send_set_imon_clock(ictx, year, month, day, dow,
775 hour, minute, second);
781 mutex_unlock(&ictx->lock);
787 static DEVICE_ATTR(imon_clock, S_IWUSR | S_IRUGO, show_imon_clock,
790 static DEVICE_ATTR(associate_remote, S_IWUSR | S_IRUGO, show_associate_remote,
791 store_associate_remote);
793 static struct attribute *imon_display_sysfs_entries[] = {
794 &dev_attr_imon_clock.attr,
798 static struct attribute_group imon_display_attribute_group = {
799 .attrs = imon_display_sysfs_entries
802 static struct attribute *imon_rf_sysfs_entries[] = {
803 &dev_attr_associate_remote.attr,
807 static struct attribute_group imon_rf_attribute_group = {
808 .attrs = imon_rf_sysfs_entries
812 * Writes data to the VFD. The iMON VFD is 2x16 characters
813 * and requires data in 5 consecutive USB interrupt packets,
814 * each packet but the last carrying 7 bytes.
816 * I don't know if the VFD board supports features such as
817 * scrolling, clearing rows, blanking, etc. so at
818 * the caller must provide a full screen of data. If fewer
819 * than 32 bytes are provided spaces will be appended to
820 * generate a full screen.
822 static ssize_t vfd_write(struct file *file, const char *buf,
823 size_t n_bytes, loff_t *pos)
829 struct imon_context *ictx;
830 const unsigned char vfd_packet6[] = {
831 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF };
833 ictx = (struct imon_context *)file->private_data;
835 err("%s: no context for device", __func__);
839 mutex_lock(&ictx->lock);
841 if (!ictx->dev_present_intf0) {
842 err("%s: no iMON device present", __func__);
847 if (n_bytes <= 0 || n_bytes > 32) {
848 err("%s: invalid payload size", __func__);
853 if (copy_from_user(ictx->tx.data_buf, buf, n_bytes)) {
858 /* Pad with spaces */
859 for (i = n_bytes; i < 32; ++i)
860 ictx->tx.data_buf[i] = ' ';
862 for (i = 32; i < 35; ++i)
863 ictx->tx.data_buf[i] = 0xFF;
869 memcpy(ictx->usb_tx_buf, ictx->tx.data_buf + offset, 7);
870 ictx->usb_tx_buf[7] = (unsigned char) seq;
872 retval = send_packet(ictx);
874 err("%s: send packet failed for packet #%d",
882 } while (offset < 35);
885 memcpy(ictx->usb_tx_buf, &vfd_packet6, sizeof(vfd_packet6));
886 ictx->usb_tx_buf[7] = (unsigned char) seq;
887 retval = send_packet(ictx);
889 err("%s: send packet failed for packet #%d",
893 mutex_unlock(&ictx->lock);
895 return (!retval) ? n_bytes : retval;
899 * Writes data to the LCD. The iMON OEM LCD screen expects 8-byte
900 * packets. We accept data as 16 hexadecimal digits, followed by a
901 * newline (to make it easy to drive the device from a command-line
902 * -- even though the actual binary data is a bit complicated).
904 * The device itself is not a "traditional" text-mode display. It's
905 * actually a 16x96 pixel bitmap display. That means if you want to
906 * display text, you've got to have your own "font" and translate the
907 * text into bitmaps for display. This is really flexible (you can
908 * display whatever diacritics you need, and so on), but it's also
909 * a lot more complicated than most LCDs...
911 static ssize_t lcd_write(struct file *file, const char *buf,
912 size_t n_bytes, loff_t *pos)
915 struct imon_context *ictx;
917 ictx = (struct imon_context *)file->private_data;
919 err("%s: no context for device", __func__);
923 mutex_lock(&ictx->lock);
925 if (!ictx->display_supported) {
926 err("%s: no iMON display present", __func__);
932 err("%s: invalid payload size: %d (expecting 8)",
933 __func__, (int) n_bytes);
938 if (copy_from_user(ictx->usb_tx_buf, buf, 8)) {
943 retval = send_packet(ictx);
945 err("%s: send packet failed!", __func__);
948 dev_dbg(ictx->dev, "%s: write %d bytes to LCD\n",
949 __func__, (int) n_bytes);
952 mutex_unlock(&ictx->lock);
953 return (!retval) ? n_bytes : retval;
957 * Callback function for USB core API: transmit data
959 static void usb_tx_callback(struct urb *urb)
961 struct imon_context *ictx;
965 ictx = (struct imon_context *)urb->context;
969 ictx->tx.status = urb->status;
971 /* notify waiters that write has finished */
973 smp_rmb(); /* ensure later readers know we're not busy */
974 complete(&ictx->tx.finished);
978 * mce/rc6 keypresses have no distinct release code, use timer
980 static void imon_mce_timeout(unsigned long data)
982 struct imon_context *ictx = (struct imon_context *)data;
984 input_report_key(ictx->idev, ictx->last_keycode, 0);
985 input_sync(ictx->idev);
989 * report touchscreen input
991 static void imon_touch_display_timeout(unsigned long data)
993 struct imon_context *ictx = (struct imon_context *)data;
995 if (!ictx->display_type == IMON_DISPLAY_TYPE_VGA)
998 input_report_abs(ictx->touch, ABS_X, ictx->touch_x);
999 input_report_abs(ictx->touch, ABS_Y, ictx->touch_y);
1000 input_report_key(ictx->touch, BTN_TOUCH, 0x00);
1001 input_sync(ictx->touch);
1005 * iMON IR receivers support two different signal sets -- those used by
1006 * the iMON remotes, and those used by the Windows MCE remotes (which is
1007 * really just RC-6), but only one or the other at a time, as the signals
1008 * are decoded onboard the receiver.
1010 static void imon_set_ir_protocol(struct imon_context *ictx)
1013 struct device *dev = ictx->dev;
1014 unsigned char ir_proto_packet[] = {
1015 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86 };
1017 if (ir_protocol && !(ir_protocol & ictx->ir_proto_mask))
1018 dev_warn(dev, "Looks like you're trying to use an IR protocol "
1019 "this device does not support\n");
1021 switch (ir_protocol) {
1022 case IMON_IR_PROTOCOL_AUTO:
1023 if (ictx->product == 0xffdc) {
1024 if (ictx->ir_proto_mask & IMON_IR_PROTO_MASK_MCE) {
1025 ir_proto_packet[0] = 0x01;
1026 ictx->ir_protocol = IMON_IR_PROTOCOL_MCE;
1027 ictx->pad_mouse = 0;
1028 init_timer(&ictx->itimer);
1029 ictx->itimer.data = (unsigned long)ictx;
1030 ictx->itimer.function = imon_mce_timeout;
1032 ictx->ir_protocol = IMON_IR_PROTOCOL_IMON;
1033 ictx->pad_mouse = 1;
1037 case IMON_IR_PROTOCOL_MCE:
1038 dev_dbg(dev, "Configuring IR receiver for MCE protocol\n");
1039 ir_proto_packet[0] = 0x01;
1040 ictx->ir_protocol = IMON_IR_PROTOCOL_MCE;
1041 ictx->pad_mouse = 0;
1042 init_timer(&ictx->itimer);
1043 ictx->itimer.data = (unsigned long)ictx;
1044 ictx->itimer.function = imon_mce_timeout;
1046 case IMON_IR_PROTOCOL_IMON:
1047 dev_dbg(dev, "Configuring IR receiver for iMON protocol\n");
1048 /* ir_proto_packet[0] = 0x00; // already the default */
1049 ictx->ir_protocol = IMON_IR_PROTOCOL_IMON;
1050 ictx->pad_mouse = 1;
1052 case IMON_IR_PROTOCOL_IMON_NOPAD:
1053 dev_dbg(dev, "Configuring IR receiver for iMON protocol "
1054 "without PAD stabilize function enabled\n");
1055 /* ir_proto_packet[0] = 0x00; // already the default */
1056 ictx->ir_protocol = IMON_IR_PROTOCOL_IMON_NOPAD;
1057 ictx->pad_mouse = 0;
1060 dev_info(dev, "%s: unknown IR protocol specified, will "
1061 "just default to iMON protocol\n", __func__);
1062 ictx->ir_protocol = IMON_IR_PROTOCOL_IMON;
1063 ictx->pad_mouse = 1;
1067 memcpy(ictx->usb_tx_buf, &ir_proto_packet, sizeof(ir_proto_packet));
1069 retval = send_packet(ictx);
1071 dev_info(dev, "%s: failed to set IR protocol, falling back "
1072 "to standard iMON protocol mode\n", __func__);
1073 ir_protocol = IMON_IR_PROTOCOL_IMON;
1074 ictx->ir_protocol = IMON_IR_PROTOCOL_IMON;
1078 static inline int tv2int(const struct timeval *a, const struct timeval *b)
1083 if (b->tv_usec > a->tv_usec) {
1088 usecs += a->tv_usec - b->tv_usec;
1090 sec += a->tv_sec - b->tv_sec;
1102 * The directional pad behaves a bit differently, depending on whether this is
1103 * one of the older ffdc devices or a newer device. Newer devices appear to
1104 * have a higher resolution matrix for more precise mouse movement, but it
1105 * makes things overly sensitive in keyboard mode, so we do some interesting
1106 * contortions to make it less touchy. Older devices run through the same
1107 * routine with shorter timeout and a smaller threshold.
1109 static int stabilize(int a, int b, u16 timeout, u16 threshold)
1112 static struct timeval prev_time = {0, 0};
1113 static struct timeval hit_time = {0, 0};
1114 static int x, y, prev_result, hits;
1118 do_gettimeofday(&ct);
1119 msec = tv2int(&ct, &prev_time);
1120 msec_hit = tv2int(&ct, &hit_time);
1133 if (abs(x) > threshold || abs(y) > threshold) {
1134 if (abs(y) > abs(x))
1135 result = (y > 0) ? 0x7F : 0x80;
1137 result = (x > 0) ? 0x7F00 : 0x8000;
1142 if (result == prev_result) {
1148 y = 17 * threshold / 30;
1151 y -= 17 * threshold / 30;
1154 x = 17 * threshold / 30;
1157 x -= 17 * threshold / 30;
1162 if (hits == 2 && msec_hit < timeout) {
1167 prev_result = result;
1176 static u32 imon_remote_key_lookup(struct imon_context *ictx, u32 hw_code)
1178 u32 scancode = be32_to_cpu(hw_code);
1181 bool is_release_code = false;
1183 /* Look for the initial press of a button */
1184 keycode = ir_g_keycode_from_table(ictx->idev, scancode);
1186 /* Look for the release of a button */
1187 if (keycode == KEY_RESERVED) {
1188 release = scancode & ~0x4000;
1189 keycode = ir_g_keycode_from_table(ictx->idev, release);
1190 if (keycode != KEY_RESERVED)
1191 is_release_code = true;
1194 ictx->release_code = is_release_code;
1199 static u32 imon_mce_key_lookup(struct imon_context *ictx, u32 hw_code)
1201 u32 scancode = be32_to_cpu(hw_code);
1204 #define MCE_KEY_MASK 0x7000
1205 #define MCE_TOGGLE_BIT 0x8000
1208 * On some receivers, mce keys decode to 0x8000f04xx and 0x8000f84xx
1209 * (the toggle bit flipping between alternating key presses), while
1210 * on other receivers, we see 0x8000f74xx and 0x8000ff4xx. To keep
1211 * the table trim, we always or in the bits to look up 0x8000ff4xx,
1212 * but we can't or them into all codes, as some keys are decoded in
1213 * a different way w/o the same use of the toggle bit...
1215 if ((scancode >> 24) & 0x80)
1216 scancode = scancode | MCE_KEY_MASK | MCE_TOGGLE_BIT;
1218 keycode = ir_g_keycode_from_table(ictx->idev, scancode);
1223 static u32 imon_panel_key_lookup(u64 hw_code)
1226 u64 code = be64_to_cpu(hw_code);
1229 for (i = 0; i < ARRAY_SIZE(imon_panel_key_table); i++)
1230 if (imon_panel_key_table[i].hw_code == (code | 0xffee))
1233 keycode = imon_panel_key_table[i % IMON_KEY_RELEASE_OFFSET].keycode;
1238 static bool imon_mouse_event(struct imon_context *ictx,
1239 unsigned char *buf, int len)
1241 char rel_x = 0x00, rel_y = 0x00;
1243 bool mouse_input = 1;
1246 /* newer iMON device PAD or mouse button */
1247 if (ictx->product != 0xffdc && (buf[0] & 0x01) && len == 5) {
1251 /* 0xffdc iMON PAD or mouse button input */
1252 } else if (ictx->product == 0xffdc && (buf[0] & 0x40) &&
1253 !((buf[1] & 0x01) || ((buf[1] >> 2) & 0x01))) {
1254 rel_x = (buf[1] & 0x08) | (buf[1] & 0x10) >> 2 |
1255 (buf[1] & 0x20) >> 4 | (buf[1] & 0x40) >> 6;
1258 rel_x = rel_x + rel_x / 2;
1259 rel_y = (buf[2] & 0x08) | (buf[2] & 0x10) >> 2 |
1260 (buf[2] & 0x20) >> 4 | (buf[2] & 0x40) >> 6;
1263 rel_y = rel_y + rel_y / 2;
1265 /* some ffdc devices decode mouse buttons differently... */
1266 } else if (ictx->product == 0xffdc && (buf[0] == 0x68)) {
1268 /* ch+/- buttons, which we use for an emulated scroll wheel */
1269 } else if (ictx->kc == KEY_CHANNELUP && (buf[2] & 0x40) != 0x40) {
1271 } else if (ictx->kc == KEY_CHANNELDOWN && (buf[2] & 0x40) != 0x40) {
1277 dev_dbg(ictx->dev, "sending mouse data via input subsystem\n");
1280 input_report_rel(ictx->idev, REL_WHEEL, dir);
1281 } else if (rel_x || rel_y) {
1282 input_report_rel(ictx->idev, REL_X, rel_x);
1283 input_report_rel(ictx->idev, REL_Y, rel_y);
1285 input_report_key(ictx->idev, BTN_LEFT, buf[1] & 0x1);
1286 input_report_key(ictx->idev, BTN_RIGHT,
1287 buf[1] >> right_shift & 0x1);
1289 input_sync(ictx->idev);
1290 ictx->last_keycode = ictx->kc;
1296 static void imon_touch_event(struct imon_context *ictx, unsigned char *buf)
1298 mod_timer(&ictx->ttimer, jiffies + TOUCH_TIMEOUT);
1299 ictx->touch_x = (buf[0] << 4) | (buf[1] >> 4);
1300 ictx->touch_y = 0xfff - ((buf[2] << 4) | (buf[1] & 0xf));
1301 input_report_abs(ictx->touch, ABS_X, ictx->touch_x);
1302 input_report_abs(ictx->touch, ABS_Y, ictx->touch_y);
1303 input_report_key(ictx->touch, BTN_TOUCH, 0x01);
1304 input_sync(ictx->touch);
1307 static void imon_pad_to_keys(struct imon_context *ictx, unsigned char *buf)
1310 char rel_x = 0x00, rel_y = 0x00;
1311 u16 timeout, threshold;
1316 * The imon directional pad functions more like a touchpad. Bytes 3 & 4
1317 * contain a position coordinate (x,y), with each component ranging
1318 * from -14 to 14. We want to down-sample this to only 4 discrete values
1319 * for up/down/left/right arrow keys. Also, when you get too close to
1320 * diagonals, it has a tendancy to jump back and forth, so lets try to
1321 * ignore when they get too close.
1323 if (ictx->product != 0xffdc) {
1324 /* first, pad to 8 bytes so it conforms with everything else */
1325 buf[5] = buf[6] = buf[7] = 0;
1326 timeout = 500; /* in msecs */
1327 /* (2*threshold) x (2*threshold) square */
1328 threshold = pad_thresh ? pad_thresh : 28;
1332 if (ictx->ir_protocol == IMON_IR_PROTOCOL_IMON) {
1333 if ((buf[1] == 0) && ((rel_x != 0) || (rel_y != 0))) {
1334 dir = stabilize((int)rel_x, (int)rel_y,
1335 timeout, threshold);
1337 ictx->kc = KEY_UNKNOWN;
1340 buf[2] = dir & 0xFF;
1341 buf[3] = (dir >> 8) & 0xFF;
1342 memcpy(&temp_key, buf, sizeof(temp_key));
1343 remote_key = (u32) (le64_to_cpu(temp_key)
1345 ictx->kc = imon_remote_key_lookup(ictx,
1349 if (abs(rel_y) > abs(rel_x)) {
1350 buf[2] = (rel_y > 0) ? 0x7F : 0x80;
1352 ictx->kc = (rel_y > 0) ? KEY_DOWN : KEY_UP;
1355 buf[3] = (rel_x > 0) ? 0x7F : 0x80;
1356 ictx->kc = (rel_x > 0) ? KEY_RIGHT : KEY_LEFT;
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.
1371 timeout = 10; /* in msecs */
1372 /* (2*threshold) x (2*threshold) square */
1373 threshold = pad_thresh ? pad_thresh : 15;
1376 rel_x = (buf[1] & 0x08) | (buf[1] & 0x10) >> 2 |
1377 (buf[1] & 0x20) >> 4 | (buf[1] & 0x40) >> 6;
1381 rel_y = (buf[2] & 0x08) | (buf[2] & 0x10) >> 2 |
1382 (buf[2] & 0x20) >> 4 | (buf[2] & 0x40) >> 6;
1387 buf[1] = buf[4] = buf[5] = buf[6] = buf[7] = 0;
1389 if (ictx->ir_protocol == IMON_IR_PROTOCOL_IMON) {
1390 dir = stabilize((int)rel_x, (int)rel_y,
1391 timeout, threshold);
1393 ictx->kc = KEY_UNKNOWN;
1396 buf[2] = dir & 0xFF;
1397 buf[3] = (dir >> 8) & 0xFF;
1398 memcpy(&temp_key, buf, sizeof(temp_key));
1399 remote_key = (u32) (le64_to_cpu(temp_key) & 0xffffffff);
1400 ictx->kc = imon_remote_key_lookup(ictx, remote_key);
1402 if (abs(rel_y) > abs(rel_x)) {
1403 buf[2] = (rel_y > 0) ? 0x7F : 0x80;
1405 ictx->kc = (rel_y > 0) ? KEY_DOWN : KEY_UP;
1408 buf[3] = (rel_x > 0) ? 0x7F : 0x80;
1409 ictx->kc = (rel_x > 0) ? KEY_RIGHT : KEY_LEFT;
1415 static int imon_parse_press_type(struct imon_context *ictx,
1416 unsigned char *buf, u8 ktype)
1420 /* key release of 0x02XXXXXX key */
1421 if (ictx->kc == KEY_RESERVED && buf[0] == 0x02 && buf[3] == 0x00)
1422 ictx->kc = ictx->last_keycode;
1424 /* mouse button release on (some) 0xffdc devices */
1425 else if (ictx->kc == KEY_RESERVED && buf[0] == 0x68 && buf[1] == 0x82 &&
1426 buf[2] == 0x81 && buf[3] == 0xb7)
1427 ictx->kc = ictx->last_keycode;
1429 /* mouse button release on (some other) 0xffdc devices */
1430 else if (ictx->kc == KEY_RESERVED && buf[0] == 0x01 && buf[1] == 0x00 &&
1431 buf[2] == 0x81 && buf[3] == 0xb7)
1432 ictx->kc = ictx->last_keycode;
1434 /* mce-specific button handling */
1435 else if (ktype == IMON_KEY_MCE) {
1437 if (ictx->kc != ictx->last_keycode
1438 || buf[2] != ictx->mce_toggle_bit) {
1439 ictx->last_keycode = ictx->kc;
1440 ictx->mce_toggle_bit = buf[2];
1442 mod_timer(&ictx->itimer,
1443 jiffies + msecs_to_jiffies(MCE_TIMEOUT_MS));
1447 mod_timer(&ictx->itimer,
1448 jiffies + msecs_to_jiffies(MCE_TIMEOUT_MS));
1451 /* incoherent or irrelevant data */
1452 } else if (ictx->kc == KEY_RESERVED)
1453 press_type = -EINVAL;
1455 /* key release of 0xXXXXXXb7 key */
1456 else if (ictx->release_code)
1459 /* this is a button press */
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;
1481 struct input_dev *idev = NULL;
1485 static struct timeval prev_time = { 0, 0 };
1486 u8 ktype = IMON_KEY_IMON;
1490 /* filter out junk data on the older 0xffdc imon devices */
1491 if ((buf[0] == 0xff) && (buf[7] == 0xff))
1494 /* Figure out what key was pressed */
1495 memcpy(&temp_key, buf, sizeof(temp_key));
1496 if (len == 8 && buf[7] == 0xee) {
1497 ktype = IMON_KEY_PANEL;
1498 panel_key = le64_to_cpu(temp_key);
1499 kc = imon_panel_key_lookup(panel_key);
1501 remote_key = (u32) (le64_to_cpu(temp_key) & 0xffffffff);
1502 if (ictx->ir_protocol == IMON_IR_PROTOCOL_MCE) {
1504 ktype = IMON_KEY_MCE;
1505 kc = imon_mce_key_lookup(ictx, remote_key);
1507 kc = imon_remote_key_lookup(ictx, remote_key);
1510 /* keyboard/mouse mode toggle button */
1511 if (kc == KEY_KEYBOARD && !ictx->release_code) {
1512 ictx->last_keycode = kc;
1514 ictx->pad_mouse = ~(ictx->pad_mouse) & 0x1;
1515 dev_dbg(dev, "toggling to %s mode\n",
1516 ictx->pad_mouse ? "mouse" : "keyboard");
1519 ictx->pad_mouse = 0;
1520 dev_dbg(dev, "mouse mode disabled, passing key value\n");
1526 /* send touchscreen events through input subsystem if touchpad data */
1527 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA && len == 8 &&
1529 imon_touch_event(ictx, buf);
1531 /* look for mouse events with pad in mouse mode */
1532 } else if (ictx->pad_mouse) {
1533 if (imon_mouse_event(ictx, buf, len))
1537 /* Now for some special handling to convert pad input to arrow keys */
1538 if (((len == 5) && (buf[0] == 0x01) && (buf[4] == 0x00)) ||
1539 ((len == 8) && (buf[0] & 0x40) &&
1540 !(buf[1] & 0x1 || buf[1] >> 2 & 0x1))) {
1542 imon_pad_to_keys(ictx, buf);
1547 printk(KERN_INFO "intf%d decoded packet: ", intf);
1548 for (i = 0; i < len; ++i)
1549 printk("%02x ", buf[i]);
1553 press_type = imon_parse_press_type(ictx, buf, ktype);
1555 goto not_input_data;
1557 if (ictx->kc == KEY_UNKNOWN)
1560 /* KEY_MUTE repeats from MCE and knob need to be suppressed */
1561 if ((ictx->kc == KEY_MUTE && ictx->kc == ictx->last_keycode)
1562 && (buf[7] == 0xee || ktype == IMON_KEY_MCE)) {
1563 do_gettimeofday(&t);
1564 msec = tv2int(&t, &prev_time);
1570 input_report_key(idev, ictx->kc, press_type);
1573 /* panel keys and some remote keys don't generate a release */
1574 if (panel_key || norelease) {
1575 input_report_key(idev, ictx->kc, 0);
1579 ictx->last_keycode = ictx->kc;
1584 dev_info(dev, "%s: unknown keypress, code 0x%llx\n", __func__,
1585 (panel_key ? be64_to_cpu(panel_key) :
1586 be32_to_cpu(remote_key)));
1591 dev_warn(dev, "imon %s: invalid incoming packet "
1592 "size (len = %d, intf%d)\n", __func__, len, intf);
1596 /* iMON 2.4G associate frame */
1597 if (buf[0] == 0x00 &&
1598 buf[2] == 0xFF && /* REFID */
1601 buf[5] == 0xFF && /* iMON 2.4G */
1602 ((buf[6] == 0x4E && buf[7] == 0xDF) || /* LT */
1603 (buf[6] == 0x5E && buf[7] == 0xDF))) { /* DT */
1604 dev_warn(dev, "%s: remote associated refid=%02X\n",
1606 ictx->rf_isassociating = 0;
1611 * Callback function for USB core API: receive data
1613 static void usb_rx_callback_intf0(struct urb *urb)
1615 struct imon_context *ictx;
1621 ictx = (struct imon_context *)urb->context;
1625 switch (urb->status) {
1626 case -ENOENT: /* usbcore unlink successful! */
1629 case -ESHUTDOWN: /* transport endpoint was shut down */
1633 imon_incoming_packet(ictx, urb, intfnum);
1637 dev_warn(ictx->dev, "imon %s: status(%d): ignored\n",
1638 __func__, urb->status);
1642 usb_submit_urb(ictx->rx_urb_intf0, GFP_ATOMIC);
1645 static void usb_rx_callback_intf1(struct urb *urb)
1647 struct imon_context *ictx;
1653 ictx = (struct imon_context *)urb->context;
1657 switch (urb->status) {
1658 case -ENOENT: /* usbcore unlink successful! */
1661 case -ESHUTDOWN: /* transport endpoint was shut down */
1665 imon_incoming_packet(ictx, urb, intfnum);
1669 dev_warn(ictx->dev, "imon %s: status(%d): ignored\n",
1670 __func__, urb->status);
1674 usb_submit_urb(ictx->rx_urb_intf1, GFP_ATOMIC);
1677 static struct input_dev *imon_init_idev(struct imon_context *ictx)
1679 struct input_dev *idev;
1680 struct ir_dev_props *props;
1681 struct ir_input_dev *ir;
1683 char *ir_codes = NULL;
1685 if (ir_protocol == IMON_IR_PROTOCOL_MCE)
1686 ir_codes = RC_MAP_IMON_MCE;
1688 ir_codes = RC_MAP_IMON_PAD;
1690 idev = input_allocate_device();
1692 dev_err(ictx->dev, "remote input dev allocation failed\n");
1693 goto idev_alloc_failed;
1696 props = kzalloc(sizeof(struct ir_dev_props), GFP_KERNEL);
1698 dev_err(ictx->dev, "remote ir dev props allocation failed\n");
1699 goto props_alloc_failed;
1702 ir = kzalloc(sizeof(struct ir_input_dev), GFP_KERNEL);
1704 dev_err(ictx->dev, "remote ir input dev allocation failed\n");
1705 goto ir_dev_alloc_failed;
1708 snprintf(ictx->name_idev, sizeof(ictx->name_idev),
1709 "iMON Remote (%04x:%04x)", ictx->vendor, ictx->product);
1710 idev->name = ictx->name_idev;
1712 usb_make_path(ictx->usbdev_intf0, ictx->phys_idev,
1713 sizeof(ictx->phys_idev));
1714 strlcat(ictx->phys_idev, "/input0", sizeof(ictx->phys_idev));
1715 idev->phys = ictx->phys_idev;
1717 idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
1719 idev->keybit[BIT_WORD(BTN_MOUSE)] =
1720 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
1721 idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y) |
1722 BIT_MASK(REL_WHEEL);
1724 /* panel and/or knob code support */
1725 for (i = 0; i < ARRAY_SIZE(imon_panel_key_table); i++) {
1726 u32 kc = imon_panel_key_table[i].keycode;
1727 __set_bit(kc, idev->keybit);
1730 props->driver_type = RC_DRIVER_SCANCODE;
1731 props->allowed_protos = IR_TYPE_UNKNOWN;
1734 memcpy(&ir->dev, ictx->dev, sizeof(struct device));
1736 usb_to_input_id(ictx->usbdev_intf0, &idev->id);
1737 idev->dev.parent = ictx->dev;
1739 input_set_drvdata(idev, ir);
1741 ret = ir_input_register(idev, ir_codes, props, MOD_NAME);
1743 dev_err(ictx->dev, "remote input dev register failed\n");
1744 goto idev_register_failed;
1749 idev_register_failed:
1751 ir_dev_alloc_failed:
1754 input_free_device(idev);
1760 static struct input_dev *imon_init_touch(struct imon_context *ictx)
1762 struct input_dev *touch;
1765 touch = input_allocate_device();
1767 dev_err(ictx->dev, "touchscreen input dev allocation failed\n");
1768 goto touch_alloc_failed;
1771 snprintf(ictx->name_touch, sizeof(ictx->name_touch),
1772 "iMON USB Touchscreen (%04x:%04x)",
1773 ictx->vendor, ictx->product);
1774 touch->name = ictx->name_touch;
1776 usb_make_path(ictx->usbdev_intf1, ictx->phys_touch,
1777 sizeof(ictx->phys_touch));
1778 strlcat(ictx->phys_touch, "/input1", sizeof(ictx->phys_touch));
1779 touch->phys = ictx->phys_touch;
1782 BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
1783 touch->keybit[BIT_WORD(BTN_TOUCH)] =
1784 BIT_MASK(BTN_TOUCH);
1785 input_set_abs_params(touch, ABS_X,
1787 input_set_abs_params(touch, ABS_Y,
1790 input_set_drvdata(touch, ictx);
1792 usb_to_input_id(ictx->usbdev_intf1, &touch->id);
1793 touch->dev.parent = ictx->dev;
1794 ret = input_register_device(touch);
1796 dev_info(ictx->dev, "touchscreen input dev register failed\n");
1797 goto touch_register_failed;
1802 touch_register_failed:
1803 input_free_device(ictx->touch);
1804 mutex_unlock(&ictx->lock);
1810 static bool imon_find_endpoints(struct imon_context *ictx,
1811 struct usb_host_interface *iface_desc)
1813 struct usb_endpoint_descriptor *ep;
1814 struct usb_endpoint_descriptor *rx_endpoint = NULL;
1815 struct usb_endpoint_descriptor *tx_endpoint = NULL;
1816 int ifnum = iface_desc->desc.bInterfaceNumber;
1817 int num_endpts = iface_desc->desc.bNumEndpoints;
1818 int i, ep_dir, ep_type;
1819 bool ir_ep_found = 0;
1820 bool display_ep_found = 0;
1821 bool tx_control = 0;
1824 * Scan the endpoint list and set:
1825 * first input endpoint = IR endpoint
1826 * first output endpoint = display endpoint
1828 for (i = 0; i < num_endpts && !(ir_ep_found && display_ep_found); ++i) {
1829 ep = &iface_desc->endpoint[i].desc;
1830 ep_dir = ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK;
1831 ep_type = ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
1833 if (!ir_ep_found && ep_dir == USB_DIR_IN &&
1834 ep_type == USB_ENDPOINT_XFER_INT) {
1838 dev_dbg(ictx->dev, "%s: found IR endpoint\n", __func__);
1840 } else if (!display_ep_found && ep_dir == USB_DIR_OUT &&
1841 ep_type == USB_ENDPOINT_XFER_INT) {
1843 display_ep_found = 1;
1844 dev_dbg(ictx->dev, "%s: found display endpoint\n", __func__);
1849 ictx->rx_endpoint_intf0 = rx_endpoint;
1851 * tx is used to send characters to lcd/vfd, associate RF
1852 * remotes, set IR protocol, and maybe more...
1854 ictx->tx_endpoint = tx_endpoint;
1856 ictx->rx_endpoint_intf1 = rx_endpoint;
1860 * If we didn't find a display endpoint, this is probably one of the
1861 * newer iMON devices that use control urb instead of interrupt
1863 if (!display_ep_found) {
1865 display_ep_found = 1;
1866 dev_dbg(ictx->dev, "%s: device uses control endpoint, not "
1867 "interface OUT endpoint\n", __func__);
1871 * Some iMON receivers have no display. Unfortunately, it seems
1872 * that SoundGraph recycles device IDs between devices both with
1875 if (ictx->display_type == IMON_DISPLAY_TYPE_NONE) {
1876 display_ep_found = 0;
1877 dev_dbg(ictx->dev, "%s: device has no display\n", __func__);
1881 * iMON Touch devices have a VGA touchscreen, but no "display", as
1882 * that refers to e.g. /dev/lcd0 (a character device LCD or VFD).
1884 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) {
1885 display_ep_found = 0;
1886 dev_dbg(ictx->dev, "%s: iMON Touch device found\n", __func__);
1889 /* Input endpoint is mandatory */
1891 err("%s: no valid input (IR) endpoint found.", __func__);
1893 ictx->tx_control = tx_control;
1895 if (display_ep_found)
1896 ictx->display_supported = true;
1902 static struct imon_context *imon_init_intf0(struct usb_interface *intf)
1904 struct imon_context *ictx;
1907 struct device *dev = &intf->dev;
1908 struct usb_host_interface *iface_desc;
1911 ictx = kzalloc(sizeof(struct imon_context), GFP_KERNEL);
1913 dev_err(dev, "%s: kzalloc failed for context", __func__);
1916 rx_urb = usb_alloc_urb(0, GFP_KERNEL);
1918 dev_err(dev, "%s: usb_alloc_urb failed for IR urb", __func__);
1919 goto rx_urb_alloc_failed;
1921 tx_urb = usb_alloc_urb(0, GFP_KERNEL);
1923 dev_err(dev, "%s: usb_alloc_urb failed for display urb",
1925 goto tx_urb_alloc_failed;
1928 mutex_init(&ictx->lock);
1930 mutex_lock(&ictx->lock);
1933 ictx->usbdev_intf0 = usb_get_dev(interface_to_usbdev(intf));
1934 ictx->dev_present_intf0 = 1;
1935 ictx->rx_urb_intf0 = rx_urb;
1936 ictx->tx_urb = tx_urb;
1938 ictx->vendor = le16_to_cpu(ictx->usbdev_intf0->descriptor.idVendor);
1939 ictx->product = le16_to_cpu(ictx->usbdev_intf0->descriptor.idProduct);
1942 iface_desc = intf->cur_altsetting;
1943 if (!imon_find_endpoints(ictx, iface_desc)) {
1944 goto find_endpoint_failed;
1947 ictx->idev = imon_init_idev(ictx);
1949 dev_err(dev, "%s: input device setup failed\n", __func__);
1950 goto idev_setup_failed;
1953 usb_fill_int_urb(ictx->rx_urb_intf0, ictx->usbdev_intf0,
1954 usb_rcvintpipe(ictx->usbdev_intf0,
1955 ictx->rx_endpoint_intf0->bEndpointAddress),
1956 ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf),
1957 usb_rx_callback_intf0, ictx,
1958 ictx->rx_endpoint_intf0->bInterval);
1960 ret = usb_submit_urb(ictx->rx_urb_intf0, GFP_KERNEL);
1962 err("%s: usb_submit_urb failed for intf0 (%d)",
1964 goto urb_submit_failed;
1970 input_unregister_device(ictx->idev);
1971 input_free_device(ictx->idev);
1973 find_endpoint_failed:
1974 mutex_unlock(&ictx->lock);
1975 usb_free_urb(tx_urb);
1976 tx_urb_alloc_failed:
1977 usb_free_urb(rx_urb);
1978 rx_urb_alloc_failed:
1981 dev_err(dev, "unable to initialize intf0, err %d\n", ret);
1986 static struct imon_context *imon_init_intf1(struct usb_interface *intf,
1987 struct imon_context *ictx)
1990 struct usb_host_interface *iface_desc;
1993 rx_urb = usb_alloc_urb(0, GFP_KERNEL);
1995 err("%s: usb_alloc_urb failed for IR urb", __func__);
1996 goto rx_urb_alloc_failed;
1999 mutex_lock(&ictx->lock);
2001 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) {
2002 init_timer(&ictx->ttimer);
2003 ictx->ttimer.data = (unsigned long)ictx;
2004 ictx->ttimer.function = imon_touch_display_timeout;
2007 ictx->usbdev_intf1 = usb_get_dev(interface_to_usbdev(intf));
2008 ictx->dev_present_intf1 = 1;
2009 ictx->rx_urb_intf1 = rx_urb;
2012 iface_desc = intf->cur_altsetting;
2013 if (!imon_find_endpoints(ictx, iface_desc))
2014 goto find_endpoint_failed;
2016 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) {
2017 ictx->touch = imon_init_touch(ictx);
2019 goto touch_setup_failed;
2023 usb_fill_int_urb(ictx->rx_urb_intf1, ictx->usbdev_intf1,
2024 usb_rcvintpipe(ictx->usbdev_intf1,
2025 ictx->rx_endpoint_intf1->bEndpointAddress),
2026 ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf),
2027 usb_rx_callback_intf1, ictx,
2028 ictx->rx_endpoint_intf1->bInterval);
2030 ret = usb_submit_urb(ictx->rx_urb_intf1, GFP_KERNEL);
2033 err("%s: usb_submit_urb failed for intf1 (%d)",
2035 goto urb_submit_failed;
2042 input_unregister_device(ictx->touch);
2043 input_free_device(ictx->touch);
2046 find_endpoint_failed:
2047 mutex_unlock(&ictx->lock);
2048 usb_free_urb(rx_urb);
2049 rx_urb_alloc_failed:
2050 dev_err(ictx->dev, "unable to initialize intf0, err %d\n", ret);
2056 * The 0x15c2:0xffdc device ID was used for umpteen different imon
2057 * devices, and all of them constantly spew interrupts, even when there
2058 * is no actual data to report. However, byte 6 of this buffer looks like
2059 * its unique across device variants, so we're trying to key off that to
2060 * figure out which display type (if any) and what IR protocol the device
2061 * actually supports.
2063 static void imon_get_ffdc_type(struct imon_context *ictx)
2065 u8 ffdc_cfg_byte = ictx->usb_rx_buf[6];
2066 u8 detected_display_type = IMON_DISPLAY_TYPE_NONE;
2067 u8 ir_proto_mask = IMON_IR_PROTO_MASK_IMON;
2069 switch (ffdc_cfg_byte) {
2070 /* iMON Knob, no display, iMON IR + vol knob */
2072 dev_info(ictx->dev, "0xffdc iMON Knob, iMON IR");
2073 ictx->display_supported = false;
2075 /* iMON VFD, no IR (does have vol knob tho) */
2077 dev_info(ictx->dev, "0xffdc iMON VFD + knob, no IR");
2078 detected_display_type = IMON_DISPLAY_TYPE_VFD;
2079 ir_proto_mask = IMON_IR_PROTO_MASK_NONE;
2081 /* iMON VFD, iMON IR */
2084 dev_info(ictx->dev, "0xffdc iMON VFD, iMON IR");
2085 detected_display_type = IMON_DISPLAY_TYPE_VFD;
2087 /* iMON LCD, MCE IR */
2089 dev_info(ictx->dev, "0xffdc iMON LCD, MCE IR");
2090 detected_display_type = IMON_DISPLAY_TYPE_LCD;
2091 ir_proto_mask = IMON_IR_PROTO_MASK_MCE;
2094 dev_info(ictx->dev, "Unknown 0xffdc device, "
2095 "defaulting to VFD and iMON IR");
2096 detected_display_type = IMON_DISPLAY_TYPE_VFD;
2100 printk(" (id 0x%02x)\n", ffdc_cfg_byte);
2102 ictx->display_type = detected_display_type;
2103 ictx->ir_proto_mask = ir_proto_mask;
2106 static void imon_set_display_type(struct imon_context *ictx,
2107 struct usb_interface *intf)
2109 u8 configured_display_type = IMON_DISPLAY_TYPE_VFD;
2112 * Try to auto-detect the type of display if the user hasn't set
2113 * it by hand via the display_type modparam. Default is VFD.
2116 if (display_type == IMON_DISPLAY_TYPE_AUTO) {
2117 switch (ictx->product) {
2119 /* set in imon_get_ffdc_type() */
2120 configured_display_type = ictx->display_type;
2124 configured_display_type = IMON_DISPLAY_TYPE_VGA;
2129 configured_display_type = IMON_DISPLAY_TYPE_LCD;
2135 configured_display_type = IMON_DISPLAY_TYPE_NONE;
2136 ictx->display_supported = false;
2141 configured_display_type = IMON_DISPLAY_TYPE_VFD;
2145 configured_display_type = display_type;
2146 if (display_type == IMON_DISPLAY_TYPE_NONE)
2147 ictx->display_supported = false;
2149 ictx->display_supported = true;
2150 dev_info(ictx->dev, "%s: overriding display type to %d via "
2151 "modparam\n", __func__, display_type);
2154 ictx->display_type = configured_display_type;
2157 static void imon_init_display(struct imon_context *ictx,
2158 struct usb_interface *intf)
2162 dev_dbg(ictx->dev, "Registering iMON display with sysfs\n");
2164 /* set up sysfs entry for built-in clock */
2165 ret = sysfs_create_group(&intf->dev.kobj,
2166 &imon_display_attribute_group);
2168 dev_err(ictx->dev, "Could not create display sysfs "
2169 "entries(%d)", ret);
2171 if (ictx->display_type == IMON_DISPLAY_TYPE_LCD)
2172 ret = usb_register_dev(intf, &imon_lcd_class);
2174 ret = usb_register_dev(intf, &imon_vfd_class);
2176 /* Not a fatal error, so ignore */
2177 dev_info(ictx->dev, "could not get a minor number for "
2183 * Callback function for USB core API: Probe
2185 static int __devinit imon_probe(struct usb_interface *interface,
2186 const struct usb_device_id *id)
2188 struct usb_device *usbdev = NULL;
2189 struct usb_host_interface *iface_desc = NULL;
2190 struct usb_interface *first_if;
2191 struct device *dev = &interface->dev;
2192 int ifnum, code_length, sysfs_err;
2194 struct imon_context *ictx = NULL;
2195 struct imon_context *first_if_ctx = NULL;
2196 u16 vendor, product;
2197 const unsigned char fp_packet[] = { 0x40, 0x00, 0x00, 0x00,
2198 0x00, 0x00, 0x00, 0x88 };
2200 code_length = BUF_CHUNK_SIZE * 8;
2202 usbdev = usb_get_dev(interface_to_usbdev(interface));
2203 iface_desc = interface->cur_altsetting;
2204 ifnum = iface_desc->desc.bInterfaceNumber;
2205 vendor = le16_to_cpu(usbdev->descriptor.idVendor);
2206 product = le16_to_cpu(usbdev->descriptor.idProduct);
2208 dev_dbg(dev, "%s: found iMON device (%04x:%04x, intf%d)\n",
2209 __func__, vendor, product, ifnum);
2211 /* prevent races probing devices w/multiple interfaces */
2212 mutex_lock(&driver_lock);
2214 first_if = usb_ifnum_to_if(usbdev, 0);
2215 first_if_ctx = (struct imon_context *)usb_get_intfdata(first_if);
2218 ictx = imon_init_intf0(interface);
2220 err("%s: failed to initialize context!\n", __func__);
2225 if (product == 0xffdc) {
2226 /* RF products *also* use 0xffdc... sigh... */
2227 sysfs_err = sysfs_create_group(&interface->dev.kobj,
2228 &imon_rf_attribute_group);
2230 err("%s: Could not create RF sysfs entries(%d)",
2231 __func__, sysfs_err);
2235 /* this is the secondary interface on the device */
2236 ictx = imon_init_intf1(interface, first_if_ctx);
2238 err("%s: failed to attach to context!\n", __func__);
2245 usb_set_intfdata(interface, ictx);
2248 /* Enable front-panel buttons and/or knobs */
2249 memcpy(ictx->usb_tx_buf, &fp_packet, sizeof(fp_packet));
2250 ret = send_packet(ictx);
2251 /* Not fatal, but warn about it */
2253 dev_info(dev, "failed to enable panel buttons "
2256 if (product == 0xffdc)
2257 imon_get_ffdc_type(ictx);
2259 ictx->ir_proto_mask = IMON_IR_PROTO_MASK_MCE |
2260 IMON_IR_PROTO_MASK_IMON;
2262 imon_set_display_type(ictx, interface);
2264 if (ictx->display_supported)
2265 imon_init_display(ictx, interface);
2268 /* set IR protocol/remote type */
2269 imon_set_ir_protocol(ictx);
2271 dev_info(dev, "iMON device (%04x:%04x, intf%d) on "
2272 "usb<%d:%d> initialized\n", vendor, product, ifnum,
2273 usbdev->bus->busnum, usbdev->devnum);
2275 mutex_unlock(&ictx->lock);
2276 mutex_unlock(&driver_lock);
2281 mutex_unlock(&driver_lock);
2282 dev_err(dev, "unable to register, err %d\n", ret);
2288 * Callback function for USB core API: disconnect
2290 static void __devexit imon_disconnect(struct usb_interface *interface)
2292 struct imon_context *ictx;
2296 /* prevent races with multi-interface device probing and display_open */
2297 mutex_lock(&driver_lock);
2299 ictx = usb_get_intfdata(interface);
2301 ifnum = interface->cur_altsetting->desc.bInterfaceNumber;
2303 mutex_lock(&ictx->lock);
2306 * sysfs_remove_group is safe to call even if sysfs_create_group
2307 * hasn't been called
2309 sysfs_remove_group(&interface->dev.kobj,
2310 &imon_display_attribute_group);
2311 sysfs_remove_group(&interface->dev.kobj,
2312 &imon_rf_attribute_group);
2314 usb_set_intfdata(interface, NULL);
2316 /* Abort ongoing write */
2317 if (ictx->tx.busy) {
2318 usb_kill_urb(ictx->tx_urb);
2319 complete_all(&ictx->tx.finished);
2323 ictx->dev_present_intf0 = 0;
2324 usb_kill_urb(ictx->rx_urb_intf0);
2325 input_unregister_device(ictx->idev);
2326 if (ictx->display_supported) {
2327 if (ictx->display_type == IMON_DISPLAY_TYPE_LCD)
2328 usb_deregister_dev(interface, &imon_lcd_class);
2330 usb_deregister_dev(interface, &imon_vfd_class);
2333 ictx->dev_present_intf1 = 0;
2334 usb_kill_urb(ictx->rx_urb_intf1);
2335 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA)
2336 input_unregister_device(ictx->touch);
2339 if (!ictx->dev_present_intf0 && !ictx->dev_present_intf1) {
2340 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA)
2341 del_timer_sync(&ictx->ttimer);
2342 mutex_unlock(&ictx->lock);
2343 if (!ictx->display_isopen)
2344 free_imon_context(ictx);
2346 if (ictx->ir_protocol == IMON_IR_PROTOCOL_MCE)
2347 del_timer_sync(&ictx->itimer);
2348 mutex_unlock(&ictx->lock);
2351 mutex_unlock(&driver_lock);
2353 dev_dbg(dev, "%s: iMON device (intf%d) disconnected\n",
2357 static int imon_suspend(struct usb_interface *intf, pm_message_t message)
2359 struct imon_context *ictx = usb_get_intfdata(intf);
2360 int ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
2363 usb_kill_urb(ictx->rx_urb_intf0);
2365 usb_kill_urb(ictx->rx_urb_intf1);
2370 static int imon_resume(struct usb_interface *intf)
2373 struct imon_context *ictx = usb_get_intfdata(intf);
2374 int ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
2377 usb_fill_int_urb(ictx->rx_urb_intf0, ictx->usbdev_intf0,
2378 usb_rcvintpipe(ictx->usbdev_intf0,
2379 ictx->rx_endpoint_intf0->bEndpointAddress),
2380 ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf),
2381 usb_rx_callback_intf0, ictx,
2382 ictx->rx_endpoint_intf0->bInterval);
2384 rc = usb_submit_urb(ictx->rx_urb_intf0, GFP_ATOMIC);
2387 usb_fill_int_urb(ictx->rx_urb_intf1, ictx->usbdev_intf1,
2388 usb_rcvintpipe(ictx->usbdev_intf1,
2389 ictx->rx_endpoint_intf1->bEndpointAddress),
2390 ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf),
2391 usb_rx_callback_intf1, ictx,
2392 ictx->rx_endpoint_intf1->bInterval);
2394 rc = usb_submit_urb(ictx->rx_urb_intf1, GFP_ATOMIC);
2400 static int __init imon_init(void)
2404 rc = usb_register(&imon_driver);
2406 err("%s: usb register failed(%d)", __func__, rc);
2413 static void __exit imon_exit(void)
2415 usb_deregister(&imon_driver);
2418 module_init(imon_init);
2419 module_exit(imon_exit);