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 #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
31 #include <linux/errno.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/module.h>
35 #include <linux/slab.h>
36 #include <linux/uaccess.h>
38 #include <linux/input.h>
39 #include <linux/usb.h>
40 #include <linux/usb/input.h>
41 #include <media/ir-core.h>
43 #include <linux/time.h>
44 #include <linux/timer.h>
46 #define MOD_AUTHOR "Jarod Wilson <jarod@wilsonet.com>"
47 #define MOD_DESC "Driver for SoundGraph iMON MultiMedia IR/Display"
48 #define MOD_NAME "imon"
49 #define MOD_VERSION "0.9.2"
51 #define DISPLAY_MINOR_BASE 144
52 #define DEVICE_NAME "lcd%d"
54 #define BUF_CHUNK_SIZE 8
57 #define BIT_DURATION 250 /* each bit received is 250us */
59 #define IMON_CLOCK_ENABLE_PACKETS 2
61 /*** P R O T O T Y P E S ***/
63 /* USB Callback prototypes */
64 static int imon_probe(struct usb_interface *interface,
65 const struct usb_device_id *id);
66 static void imon_disconnect(struct usb_interface *interface);
67 static void usb_rx_callback_intf0(struct urb *urb);
68 static void usb_rx_callback_intf1(struct urb *urb);
69 static void usb_tx_callback(struct urb *urb);
71 /* suspend/resume support */
72 static int imon_resume(struct usb_interface *intf);
73 static int imon_suspend(struct usb_interface *intf, pm_message_t message);
75 /* Display file_operations function prototypes */
76 static int display_open(struct inode *inode, struct file *file);
77 static int display_close(struct inode *inode, struct file *file);
79 /* VFD write operation */
80 static ssize_t vfd_write(struct file *file, const char *buf,
81 size_t n_bytes, loff_t *pos);
83 /* LCD file_operations override function prototypes */
84 static ssize_t lcd_write(struct file *file, const char *buf,
85 size_t n_bytes, loff_t *pos);
87 /*** G L O B A L S ***/
91 struct ir_dev_props *props;
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_device; /* true if iMON 2.4G LT/DT RF device */
99 bool rf_isassociating; /* RF remote associating */
100 bool dev_present_intf0; /* USB device presence, interface 0 */
101 bool dev_present_intf1; /* USB device presence, interface 1 */
103 struct mutex lock; /* to lock this object */
104 wait_queue_head_t remove_ok; /* For unexpected USB disconnects */
106 struct usb_endpoint_descriptor *rx_endpoint_intf0;
107 struct usb_endpoint_descriptor *rx_endpoint_intf1;
108 struct usb_endpoint_descriptor *tx_endpoint;
109 struct urb *rx_urb_intf0;
110 struct urb *rx_urb_intf1;
113 unsigned char usb_rx_buf[8];
114 unsigned char usb_tx_buf[8];
117 unsigned char data_buf[35]; /* user data buffer */
118 struct completion finished; /* wait for write to finish */
119 bool busy; /* write in progress */
120 int status; /* status of tx completion */
123 u16 vendor; /* usb vendor ID */
124 u16 product; /* usb product ID */
126 struct input_dev *rdev; /* input device for remote */
127 struct input_dev *idev; /* input device for panel & IR mouse */
128 struct input_dev *touch; /* input device for touchscreen */
130 spinlock_t kc_lock; /* make sure we get keycodes right */
131 u32 kc; /* current input keycode */
132 u32 last_keycode; /* last reported input keycode */
133 u32 rc_scancode; /* the computed remote scancode */
134 u8 rc_toggle; /* the computed remote toggle bit */
135 u64 ir_type; /* iMON or MCE (RC6) IR protocol? */
136 bool release_code; /* some keys send a release code */
138 u8 display_type; /* store the display type */
139 bool pad_mouse; /* toggle kbd(0)/mouse(1) mode */
141 char name_rdev[128]; /* rc input device name */
142 char phys_rdev[64]; /* rc input device phys path */
144 char name_idev[128]; /* input device name */
145 char phys_idev[64]; /* input device phys path */
147 char name_touch[128]; /* touch screen name */
148 char phys_touch[64]; /* touch screen phys path */
149 struct timer_list ttimer; /* touch screen timer */
150 int touch_x; /* x coordinate on touchscreen */
151 int touch_y; /* y coordinate on touchscreen */
154 #define TOUCH_TIMEOUT (HZ/30)
156 /* vfd character device file operations */
157 static const struct file_operations vfd_fops = {
158 .owner = THIS_MODULE,
159 .open = &display_open,
161 .release = &display_close
164 /* lcd character device file operations */
165 static const struct file_operations lcd_fops = {
166 .owner = THIS_MODULE,
167 .open = &display_open,
169 .release = &display_close
173 IMON_DISPLAY_TYPE_AUTO = 0,
174 IMON_DISPLAY_TYPE_VFD = 1,
175 IMON_DISPLAY_TYPE_LCD = 2,
176 IMON_DISPLAY_TYPE_VGA = 3,
177 IMON_DISPLAY_TYPE_NONE = 4,
187 * USB Device ID for iMON USB Control Boards
189 * The Windows drivers contain 6 different inf files, more or less one for
190 * each new device until the 0x0034-0x0046 devices, which all use the same
191 * driver. Some of the devices in the 34-46 range haven't been definitively
192 * identified yet. Early devices have either a TriGem Computer, Inc. or a
193 * Samsung vendor ID (0x0aa8 and 0x04e8 respectively), while all later
194 * devices use the SoundGraph vendor ID (0x15c2). This driver only supports
195 * the ffdc and later devices, which do onboard decoding.
197 static struct usb_device_id imon_usb_id_table[] = {
199 * Several devices with this same device ID, all use iMON_PAD.inf
200 * SoundGraph iMON PAD (IR & VFD)
201 * SoundGraph iMON PAD (IR & LCD)
202 * SoundGraph iMON Knob (IR only)
204 { USB_DEVICE(0x15c2, 0xffdc) },
207 * Newer devices, all driven by the latest iMON Windows driver, full
208 * list of device IDs extracted via 'strings Setup/data1.hdr |grep 15c2'
209 * Need user input to fill in details on unknown devices.
211 /* SoundGraph iMON OEM Touch LCD (IR & 7" VGA LCD) */
212 { USB_DEVICE(0x15c2, 0x0034) },
213 /* SoundGraph iMON OEM Touch LCD (IR & 4.3" VGA LCD) */
214 { USB_DEVICE(0x15c2, 0x0035) },
215 /* SoundGraph iMON OEM VFD (IR & VFD) */
216 { USB_DEVICE(0x15c2, 0x0036) },
217 /* device specifics unknown */
218 { USB_DEVICE(0x15c2, 0x0037) },
219 /* SoundGraph iMON OEM LCD (IR & LCD) */
220 { USB_DEVICE(0x15c2, 0x0038) },
221 /* SoundGraph iMON UltraBay (IR & LCD) */
222 { USB_DEVICE(0x15c2, 0x0039) },
223 /* device specifics unknown */
224 { USB_DEVICE(0x15c2, 0x003a) },
225 /* device specifics unknown */
226 { USB_DEVICE(0x15c2, 0x003b) },
227 /* SoundGraph iMON OEM Inside (IR only) */
228 { USB_DEVICE(0x15c2, 0x003c) },
229 /* device specifics unknown */
230 { USB_DEVICE(0x15c2, 0x003d) },
231 /* device specifics unknown */
232 { USB_DEVICE(0x15c2, 0x003e) },
233 /* device specifics unknown */
234 { USB_DEVICE(0x15c2, 0x003f) },
235 /* device specifics unknown */
236 { USB_DEVICE(0x15c2, 0x0040) },
237 /* SoundGraph iMON MINI (IR only) */
238 { USB_DEVICE(0x15c2, 0x0041) },
239 /* Antec Veris Multimedia Station EZ External (IR only) */
240 { USB_DEVICE(0x15c2, 0x0042) },
241 /* Antec Veris Multimedia Station Basic Internal (IR only) */
242 { USB_DEVICE(0x15c2, 0x0043) },
243 /* Antec Veris Multimedia Station Elite (IR & VFD) */
244 { USB_DEVICE(0x15c2, 0x0044) },
245 /* Antec Veris Multimedia Station Premiere (IR & LCD) */
246 { USB_DEVICE(0x15c2, 0x0045) },
247 /* device specifics unknown */
248 { USB_DEVICE(0x15c2, 0x0046) },
252 /* USB Device data */
253 static struct usb_driver imon_driver = {
256 .disconnect = imon_disconnect,
257 .suspend = imon_suspend,
258 .resume = imon_resume,
259 .id_table = imon_usb_id_table,
262 static struct usb_class_driver imon_vfd_class = {
265 .minor_base = DISPLAY_MINOR_BASE,
268 static struct usb_class_driver imon_lcd_class = {
271 .minor_base = DISPLAY_MINOR_BASE,
274 /* imon receiver front panel/knob key table */
275 static const struct {
278 } imon_panel_key_table[] = {
279 { 0x000000000f00ffeell, KEY_PROG1 }, /* Go */
280 { 0x000000001f00ffeell, KEY_AUDIO },
281 { 0x000000002000ffeell, KEY_VIDEO },
282 { 0x000000002100ffeell, KEY_CAMERA },
283 { 0x000000002700ffeell, KEY_DVD },
284 { 0x000000002300ffeell, KEY_TV },
285 { 0x000000000500ffeell, KEY_PREVIOUS },
286 { 0x000000000700ffeell, KEY_REWIND },
287 { 0x000000000400ffeell, KEY_STOP },
288 { 0x000000003c00ffeell, KEY_PLAYPAUSE },
289 { 0x000000000800ffeell, KEY_FASTFORWARD },
290 { 0x000000000600ffeell, KEY_NEXT },
291 { 0x000000010000ffeell, KEY_RIGHT },
292 { 0x000001000000ffeell, KEY_LEFT },
293 { 0x000000003d00ffeell, KEY_SELECT },
294 { 0x000100000000ffeell, KEY_VOLUMEUP },
295 { 0x010000000000ffeell, KEY_VOLUMEDOWN },
296 { 0x000000000100ffeell, KEY_MUTE },
297 /* 0xffdc iMON MCE VFD */
298 { 0x00010000ffffffeell, KEY_VOLUMEUP },
299 { 0x01000000ffffffeell, KEY_VOLUMEDOWN },
300 /* iMON Knob values */
301 { 0x000100ffffffffeell, KEY_VOLUMEUP },
302 { 0x010000ffffffffeell, KEY_VOLUMEDOWN },
303 { 0x000008ffffffffeell, KEY_MUTE },
306 /* to prevent races between open() and disconnect(), probing, etc */
307 static DEFINE_MUTEX(driver_lock);
309 /* Module bookkeeping bits */
310 MODULE_AUTHOR(MOD_AUTHOR);
311 MODULE_DESCRIPTION(MOD_DESC);
312 MODULE_VERSION(MOD_VERSION);
313 MODULE_LICENSE("GPL");
314 MODULE_DEVICE_TABLE(usb, imon_usb_id_table);
317 module_param(debug, bool, S_IRUGO | S_IWUSR);
318 MODULE_PARM_DESC(debug, "Debug messages: 0=no, 1=yes(default: no)");
320 /* lcd, vfd, vga or none? should be auto-detected, but can be overridden... */
321 static int display_type;
322 module_param(display_type, int, S_IRUGO);
323 MODULE_PARM_DESC(display_type, "Type of attached display. 0=autodetect, "
324 "1=vfd, 2=lcd, 3=vga, 4=none (default: autodetect)");
326 static int pad_stabilize = 1;
327 module_param(pad_stabilize, int, S_IRUGO | S_IWUSR);
328 MODULE_PARM_DESC(pad_stabilize, "Apply stabilization algorithm to iMON PAD "
329 "presses in arrow key mode. 0=disable, 1=enable (default).");
332 * In certain use cases, mouse mode isn't really helpful, and could actually
333 * cause confusion, so allow disabling it when the IR device is open.
336 module_param(nomouse, bool, S_IRUGO | S_IWUSR);
337 MODULE_PARM_DESC(nomouse, "Disable mouse input device mode when IR device is "
338 "open. 0=don't disable, 1=disable. (default: don't disable)");
340 /* threshold at which a pad push registers as an arrow key in kbd mode */
341 static int pad_thresh;
342 module_param(pad_thresh, int, S_IRUGO | S_IWUSR);
343 MODULE_PARM_DESC(pad_thresh, "Threshold at which a pad push registers as an "
344 "arrow key in kbd mode (default: 28)");
347 static void free_imon_context(struct imon_context *ictx)
349 struct device *dev = ictx->dev;
351 usb_free_urb(ictx->tx_urb);
352 usb_free_urb(ictx->rx_urb_intf0);
353 usb_free_urb(ictx->rx_urb_intf1);
356 dev_dbg(dev, "%s: iMON context freed\n", __func__);
360 * Called when the Display device (e.g. /dev/lcd0)
361 * is opened by the application.
363 static int display_open(struct inode *inode, struct file *file)
365 struct usb_interface *interface;
366 struct imon_context *ictx = NULL;
370 /* prevent races with disconnect */
371 mutex_lock(&driver_lock);
373 subminor = iminor(inode);
374 interface = usb_find_interface(&imon_driver, subminor);
376 pr_err("could not find interface for minor %d\n", subminor);
380 ictx = usb_get_intfdata(interface);
383 pr_err("no context found for minor %d\n", subminor);
388 mutex_lock(&ictx->lock);
390 if (!ictx->display_supported) {
391 pr_err("display not supported by device\n");
393 } else if (ictx->display_isopen) {
394 pr_err("display port is already open\n");
397 ictx->display_isopen = true;
398 file->private_data = ictx;
399 dev_dbg(ictx->dev, "display port opened\n");
402 mutex_unlock(&ictx->lock);
405 mutex_unlock(&driver_lock);
410 * Called when the display device (e.g. /dev/lcd0)
411 * is closed by the application.
413 static int display_close(struct inode *inode, struct file *file)
415 struct imon_context *ictx = NULL;
418 ictx = file->private_data;
421 pr_err("no context for device\n");
425 mutex_lock(&ictx->lock);
427 if (!ictx->display_supported) {
428 pr_err("display not supported by device\n");
430 } else if (!ictx->display_isopen) {
431 pr_err("display is not open\n");
434 ictx->display_isopen = false;
435 dev_dbg(ictx->dev, "display port closed\n");
436 if (!ictx->dev_present_intf0) {
438 * Device disconnected before close and IR port is not
439 * open. If IR port is open, context will be deleted by
442 mutex_unlock(&ictx->lock);
443 free_imon_context(ictx);
448 mutex_unlock(&ictx->lock);
453 * Sends a packet to the device -- this function must be called
454 * with ictx->lock held.
456 static int send_packet(struct imon_context *ictx)
459 unsigned long timeout;
462 struct usb_ctrlrequest *control_req = NULL;
464 /* Check if we need to use control or interrupt urb */
465 if (!ictx->tx_control) {
466 pipe = usb_sndintpipe(ictx->usbdev_intf0,
467 ictx->tx_endpoint->bEndpointAddress);
468 interval = ictx->tx_endpoint->bInterval;
470 usb_fill_int_urb(ictx->tx_urb, ictx->usbdev_intf0, pipe,
472 sizeof(ictx->usb_tx_buf),
473 usb_tx_callback, ictx, interval);
475 ictx->tx_urb->actual_length = 0;
477 /* fill request into kmalloc'ed space: */
478 control_req = kmalloc(sizeof(struct usb_ctrlrequest),
480 if (control_req == NULL)
483 /* setup packet is '21 09 0200 0001 0008' */
484 control_req->bRequestType = 0x21;
485 control_req->bRequest = 0x09;
486 control_req->wValue = cpu_to_le16(0x0200);
487 control_req->wIndex = cpu_to_le16(0x0001);
488 control_req->wLength = cpu_to_le16(0x0008);
490 /* control pipe is endpoint 0x00 */
491 pipe = usb_sndctrlpipe(ictx->usbdev_intf0, 0);
493 /* build the control urb */
494 usb_fill_control_urb(ictx->tx_urb, ictx->usbdev_intf0,
495 pipe, (unsigned char *)control_req,
497 sizeof(ictx->usb_tx_buf),
498 usb_tx_callback, ictx);
499 ictx->tx_urb->actual_length = 0;
502 init_completion(&ictx->tx.finished);
503 ictx->tx.busy = true;
504 smp_rmb(); /* ensure later readers know we're busy */
506 retval = usb_submit_urb(ictx->tx_urb, GFP_KERNEL);
508 ictx->tx.busy = false;
509 smp_rmb(); /* ensure later readers know we're not busy */
510 pr_err("error submitting urb(%d)\n", retval);
512 /* Wait for transmission to complete (or abort) */
513 mutex_unlock(&ictx->lock);
514 retval = wait_for_completion_interruptible(
517 pr_err("task interrupted\n");
518 mutex_lock(&ictx->lock);
520 retval = ictx->tx.status;
522 pr_err("packet tx failed (%d)\n", retval);
528 * Induce a mandatory 5ms delay before returning, as otherwise,
529 * send_packet can get called so rapidly as to overwhelm the device,
530 * particularly on faster systems and/or those with quirky usb.
532 timeout = msecs_to_jiffies(5);
533 set_current_state(TASK_UNINTERRUPTIBLE);
534 schedule_timeout(timeout);
540 * Sends an associate packet to the iMON 2.4G.
542 * This might not be such a good idea, since it has an id collision with
543 * some versions of the "IR & VFD" combo. The only way to determine if it
544 * is an RF version is to look at the product description string. (Which
545 * we currently do not fetch).
547 static int send_associate_24g(struct imon_context *ictx)
550 const unsigned char packet[8] = { 0x01, 0x00, 0x00, 0x00,
551 0x00, 0x00, 0x00, 0x20 };
554 pr_err("no context for device\n");
558 if (!ictx->dev_present_intf0) {
559 pr_err("no iMON device present\n");
563 memcpy(ictx->usb_tx_buf, packet, sizeof(packet));
564 retval = send_packet(ictx);
570 * Sends packets to setup and show clock on iMON display
572 * Arguments: year - last 2 digits of year, month - 1..12,
573 * day - 1..31, dow - day of the week (0-Sun...6-Sat),
574 * hour - 0..23, minute - 0..59, second - 0..59
576 static int send_set_imon_clock(struct imon_context *ictx,
577 unsigned int year, unsigned int month,
578 unsigned int day, unsigned int dow,
579 unsigned int hour, unsigned int minute,
582 unsigned char clock_enable_pkt[IMON_CLOCK_ENABLE_PACKETS][8];
587 pr_err("no context for device\n");
591 switch (ictx->display_type) {
592 case IMON_DISPLAY_TYPE_LCD:
593 clock_enable_pkt[0][0] = 0x80;
594 clock_enable_pkt[0][1] = year;
595 clock_enable_pkt[0][2] = month-1;
596 clock_enable_pkt[0][3] = day;
597 clock_enable_pkt[0][4] = hour;
598 clock_enable_pkt[0][5] = minute;
599 clock_enable_pkt[0][6] = second;
601 clock_enable_pkt[1][0] = 0x80;
602 clock_enable_pkt[1][1] = 0;
603 clock_enable_pkt[1][2] = 0;
604 clock_enable_pkt[1][3] = 0;
605 clock_enable_pkt[1][4] = 0;
606 clock_enable_pkt[1][5] = 0;
607 clock_enable_pkt[1][6] = 0;
609 if (ictx->product == 0xffdc) {
610 clock_enable_pkt[0][7] = 0x50;
611 clock_enable_pkt[1][7] = 0x51;
613 clock_enable_pkt[0][7] = 0x88;
614 clock_enable_pkt[1][7] = 0x8a;
619 case IMON_DISPLAY_TYPE_VFD:
620 clock_enable_pkt[0][0] = year;
621 clock_enable_pkt[0][1] = month-1;
622 clock_enable_pkt[0][2] = day;
623 clock_enable_pkt[0][3] = dow;
624 clock_enable_pkt[0][4] = hour;
625 clock_enable_pkt[0][5] = minute;
626 clock_enable_pkt[0][6] = second;
627 clock_enable_pkt[0][7] = 0x40;
629 clock_enable_pkt[1][0] = 0;
630 clock_enable_pkt[1][1] = 0;
631 clock_enable_pkt[1][2] = 1;
632 clock_enable_pkt[1][3] = 0;
633 clock_enable_pkt[1][4] = 0;
634 clock_enable_pkt[1][5] = 0;
635 clock_enable_pkt[1][6] = 0;
636 clock_enable_pkt[1][7] = 0x42;
644 for (i = 0; i < IMON_CLOCK_ENABLE_PACKETS; i++) {
645 memcpy(ictx->usb_tx_buf, clock_enable_pkt[i], 8);
646 retval = send_packet(ictx);
648 pr_err("send_packet failed for packet %d\n", i);
657 * These are the sysfs functions to handle the association on the iMON 2.4G LT.
659 static ssize_t show_associate_remote(struct device *d,
660 struct device_attribute *attr,
663 struct imon_context *ictx = dev_get_drvdata(d);
668 mutex_lock(&ictx->lock);
669 if (ictx->rf_isassociating)
670 strcpy(buf, "associating\n");
672 strcpy(buf, "closed\n");
674 dev_info(d, "Visit http://www.lirc.org/html/imon-24g.html for "
675 "instructions on how to associate your iMON 2.4G DT/LT "
677 mutex_unlock(&ictx->lock);
681 static ssize_t store_associate_remote(struct device *d,
682 struct device_attribute *attr,
683 const char *buf, size_t count)
685 struct imon_context *ictx;
687 ictx = dev_get_drvdata(d);
692 mutex_lock(&ictx->lock);
693 ictx->rf_isassociating = true;
694 send_associate_24g(ictx);
695 mutex_unlock(&ictx->lock);
701 * sysfs functions to control internal imon clock
703 static ssize_t show_imon_clock(struct device *d,
704 struct device_attribute *attr, char *buf)
706 struct imon_context *ictx = dev_get_drvdata(d);
712 mutex_lock(&ictx->lock);
714 if (!ictx->display_supported) {
715 len = snprintf(buf, PAGE_SIZE, "Not supported.");
717 len = snprintf(buf, PAGE_SIZE,
718 "To set the clock on your iMON display:\n"
719 "# date \"+%%y %%m %%d %%w %%H %%M %%S\" > imon_clock\n"
720 "%s", ictx->display_isopen ?
721 "\nNOTE: imon device must be closed\n" : "");
724 mutex_unlock(&ictx->lock);
729 static ssize_t store_imon_clock(struct device *d,
730 struct device_attribute *attr,
731 const char *buf, size_t count)
733 struct imon_context *ictx = dev_get_drvdata(d);
735 unsigned int year, month, day, dow, hour, minute, second;
740 mutex_lock(&ictx->lock);
742 if (!ictx->display_supported) {
745 } else if (ictx->display_isopen) {
750 if (sscanf(buf, "%u %u %u %u %u %u %u", &year, &month, &day, &dow,
751 &hour, &minute, &second) != 7) {
756 if ((month < 1 || month > 12) ||
757 (day < 1 || day > 31) || (dow > 6) ||
758 (hour > 23) || (minute > 59) || (second > 59)) {
763 retval = send_set_imon_clock(ictx, year, month, day, dow,
764 hour, minute, second);
770 mutex_unlock(&ictx->lock);
776 static DEVICE_ATTR(imon_clock, S_IWUSR | S_IRUGO, show_imon_clock,
779 static DEVICE_ATTR(associate_remote, S_IWUSR | S_IRUGO, show_associate_remote,
780 store_associate_remote);
782 static struct attribute *imon_display_sysfs_entries[] = {
783 &dev_attr_imon_clock.attr,
787 static struct attribute_group imon_display_attribute_group = {
788 .attrs = imon_display_sysfs_entries
791 static struct attribute *imon_rf_sysfs_entries[] = {
792 &dev_attr_associate_remote.attr,
796 static struct attribute_group imon_rf_attribute_group = {
797 .attrs = imon_rf_sysfs_entries
801 * Writes data to the VFD. The iMON VFD is 2x16 characters
802 * and requires data in 5 consecutive USB interrupt packets,
803 * each packet but the last carrying 7 bytes.
805 * I don't know if the VFD board supports features such as
806 * scrolling, clearing rows, blanking, etc. so at
807 * the caller must provide a full screen of data. If fewer
808 * than 32 bytes are provided spaces will be appended to
809 * generate a full screen.
811 static ssize_t vfd_write(struct file *file, const char *buf,
812 size_t n_bytes, loff_t *pos)
818 struct imon_context *ictx;
819 const unsigned char vfd_packet6[] = {
820 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF };
822 ictx = file->private_data;
824 pr_err("no context for device\n");
828 mutex_lock(&ictx->lock);
830 if (!ictx->dev_present_intf0) {
831 pr_err("no iMON device present\n");
836 if (n_bytes <= 0 || n_bytes > 32) {
837 pr_err("invalid payload size\n");
842 if (copy_from_user(ictx->tx.data_buf, buf, n_bytes)) {
847 /* Pad with spaces */
848 for (i = n_bytes; i < 32; ++i)
849 ictx->tx.data_buf[i] = ' ';
851 for (i = 32; i < 35; ++i)
852 ictx->tx.data_buf[i] = 0xFF;
858 memcpy(ictx->usb_tx_buf, ictx->tx.data_buf + offset, 7);
859 ictx->usb_tx_buf[7] = (unsigned char) seq;
861 retval = send_packet(ictx);
863 pr_err("send packet failed for packet #%d\n", seq / 2);
870 } while (offset < 35);
873 memcpy(ictx->usb_tx_buf, &vfd_packet6, sizeof(vfd_packet6));
874 ictx->usb_tx_buf[7] = (unsigned char) seq;
875 retval = send_packet(ictx);
877 pr_err("send packet failed for packet #%d\n", seq / 2);
880 mutex_unlock(&ictx->lock);
882 return (!retval) ? n_bytes : retval;
886 * Writes data to the LCD. The iMON OEM LCD screen expects 8-byte
887 * packets. We accept data as 16 hexadecimal digits, followed by a
888 * newline (to make it easy to drive the device from a command-line
889 * -- even though the actual binary data is a bit complicated).
891 * The device itself is not a "traditional" text-mode display. It's
892 * actually a 16x96 pixel bitmap display. That means if you want to
893 * display text, you've got to have your own "font" and translate the
894 * text into bitmaps for display. This is really flexible (you can
895 * display whatever diacritics you need, and so on), but it's also
896 * a lot more complicated than most LCDs...
898 static ssize_t lcd_write(struct file *file, const char *buf,
899 size_t n_bytes, loff_t *pos)
902 struct imon_context *ictx;
904 ictx = file->private_data;
906 pr_err("no context for device\n");
910 mutex_lock(&ictx->lock);
912 if (!ictx->display_supported) {
913 pr_err("no iMON display present\n");
919 pr_err("invalid payload size: %d (expected 8)\n", (int)n_bytes);
924 if (copy_from_user(ictx->usb_tx_buf, buf, 8)) {
929 retval = send_packet(ictx);
931 pr_err("send packet failed!\n");
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);
1705 * The 0x15c2:0xffdc device ID was used for umpteen different imon
1706 * devices, and all of them constantly spew interrupts, even when there
1707 * is no actual data to report. However, byte 6 of this buffer looks like
1708 * its unique across device variants, so we're trying to key off that to
1709 * figure out which display type (if any) and what IR protocol the device
1710 * actually supports. These devices have their IR protocol hard-coded into
1711 * their firmware, they can't be changed on the fly like the newer hardware.
1713 static void imon_get_ffdc_type(struct imon_context *ictx)
1715 u8 ffdc_cfg_byte = ictx->usb_rx_buf[6];
1716 u8 detected_display_type = IMON_DISPLAY_TYPE_NONE;
1717 u64 allowed_protos = IR_TYPE_OTHER;
1719 switch (ffdc_cfg_byte) {
1720 /* iMON Knob, no display, iMON IR + vol knob */
1722 dev_info(ictx->dev, "0xffdc iMON Knob, iMON IR");
1723 ictx->display_supported = false;
1725 /* iMON 2.4G LT (usb stick), no display, iMON RF */
1727 dev_info(ictx->dev, "0xffdc iMON 2.4G LT, iMON RF");
1728 ictx->display_supported = false;
1729 ictx->rf_device = true;
1731 /* iMON VFD, no IR (does have vol knob tho) */
1733 dev_info(ictx->dev, "0xffdc iMON VFD + knob, no IR");
1734 detected_display_type = IMON_DISPLAY_TYPE_VFD;
1736 /* iMON VFD, iMON IR */
1739 dev_info(ictx->dev, "0xffdc iMON VFD, iMON IR");
1740 detected_display_type = IMON_DISPLAY_TYPE_VFD;
1742 /* iMON VFD, MCE IR */
1744 dev_info(ictx->dev, "0xffdc iMON VFD, MCE IR");
1745 detected_display_type = IMON_DISPLAY_TYPE_VFD;
1746 allowed_protos = IR_TYPE_RC6;
1748 /* iMON LCD, MCE IR */
1750 dev_info(ictx->dev, "0xffdc iMON LCD, MCE IR");
1751 detected_display_type = IMON_DISPLAY_TYPE_LCD;
1752 allowed_protos = IR_TYPE_RC6;
1755 dev_info(ictx->dev, "Unknown 0xffdc device, "
1756 "defaulting to VFD and iMON IR");
1757 detected_display_type = IMON_DISPLAY_TYPE_VFD;
1761 printk(KERN_CONT " (id 0x%02x)\n", ffdc_cfg_byte);
1763 ictx->display_type = detected_display_type;
1764 ictx->props->allowed_protos = allowed_protos;
1765 ictx->ir_type = allowed_protos;
1768 static void imon_set_display_type(struct imon_context *ictx)
1770 u8 configured_display_type = IMON_DISPLAY_TYPE_VFD;
1773 * Try to auto-detect the type of display if the user hasn't set
1774 * it by hand via the display_type modparam. Default is VFD.
1777 if (display_type == IMON_DISPLAY_TYPE_AUTO) {
1778 switch (ictx->product) {
1780 /* set in imon_get_ffdc_type() */
1781 configured_display_type = ictx->display_type;
1785 configured_display_type = IMON_DISPLAY_TYPE_VGA;
1790 configured_display_type = IMON_DISPLAY_TYPE_LCD;
1796 configured_display_type = IMON_DISPLAY_TYPE_NONE;
1797 ictx->display_supported = false;
1802 configured_display_type = IMON_DISPLAY_TYPE_VFD;
1806 configured_display_type = display_type;
1807 if (display_type == IMON_DISPLAY_TYPE_NONE)
1808 ictx->display_supported = false;
1810 ictx->display_supported = true;
1811 dev_info(ictx->dev, "%s: overriding display type to %d via "
1812 "modparam\n", __func__, display_type);
1815 ictx->display_type = configured_display_type;
1818 static struct input_dev *imon_init_rdev(struct imon_context *ictx)
1820 struct input_dev *rdev;
1821 struct ir_dev_props *props;
1823 char *ir_codes = NULL;
1824 const unsigned char fp_packet[] = { 0x40, 0x00, 0x00, 0x00,
1825 0x00, 0x00, 0x00, 0x88 };
1827 rdev = input_allocate_device();
1828 props = kzalloc(sizeof(*props), GFP_KERNEL);
1829 if (!rdev || !props) {
1830 dev_err(ictx->dev, "remote control dev allocation failed\n");
1834 snprintf(ictx->name_rdev, sizeof(ictx->name_rdev),
1835 "iMON Remote (%04x:%04x)", ictx->vendor, ictx->product);
1836 usb_make_path(ictx->usbdev_intf0, ictx->phys_rdev,
1837 sizeof(ictx->phys_rdev));
1838 strlcat(ictx->phys_rdev, "/input0", sizeof(ictx->phys_rdev));
1840 rdev->name = ictx->name_rdev;
1841 rdev->phys = ictx->phys_rdev;
1842 usb_to_input_id(ictx->usbdev_intf0, &rdev->id);
1843 rdev->dev.parent = ictx->dev;
1844 rdev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
1845 input_set_drvdata(rdev, ictx);
1848 props->driver_type = RC_DRIVER_SCANCODE;
1849 props->allowed_protos = IR_TYPE_OTHER | IR_TYPE_RC6; /* iMON PAD or MCE */
1850 props->change_protocol = imon_ir_change_protocol;
1851 ictx->props = props;
1853 /* Enable front-panel buttons and/or knobs */
1854 memcpy(ictx->usb_tx_buf, &fp_packet, sizeof(fp_packet));
1855 ret = send_packet(ictx);
1856 /* Not fatal, but warn about it */
1858 dev_info(ictx->dev, "panel buttons/knobs setup failed\n");
1860 if (ictx->product == 0xffdc)
1861 imon_get_ffdc_type(ictx);
1863 imon_set_display_type(ictx);
1865 if (ictx->ir_type == IR_TYPE_RC6)
1866 ir_codes = RC_MAP_IMON_MCE;
1868 ir_codes = RC_MAP_IMON_PAD;
1870 ret = ir_input_register(rdev, ir_codes, props, MOD_NAME);
1872 dev_err(ictx->dev, "remote input dev register failed\n");
1880 input_free_device(rdev);
1884 static struct input_dev *imon_init_idev(struct imon_context *ictx)
1886 struct input_dev *idev;
1889 idev = input_allocate_device();
1891 dev_err(ictx->dev, "input dev allocation failed\n");
1895 snprintf(ictx->name_idev, sizeof(ictx->name_idev),
1896 "iMON Panel, Knob and Mouse(%04x:%04x)",
1897 ictx->vendor, ictx->product);
1898 idev->name = ictx->name_idev;
1900 usb_make_path(ictx->usbdev_intf0, ictx->phys_idev,
1901 sizeof(ictx->phys_idev));
1902 strlcat(ictx->phys_idev, "/input1", sizeof(ictx->phys_idev));
1903 idev->phys = ictx->phys_idev;
1905 idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | BIT_MASK(EV_REL);
1907 idev->keybit[BIT_WORD(BTN_MOUSE)] =
1908 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
1909 idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y) |
1910 BIT_MASK(REL_WHEEL);
1912 /* panel and/or knob code support */
1913 for (i = 0; i < ARRAY_SIZE(imon_panel_key_table); i++) {
1914 u32 kc = imon_panel_key_table[i].keycode;
1915 __set_bit(kc, idev->keybit);
1918 usb_to_input_id(ictx->usbdev_intf0, &idev->id);
1919 idev->dev.parent = ictx->dev;
1920 input_set_drvdata(idev, ictx);
1922 ret = input_register_device(idev);
1924 dev_err(ictx->dev, "input dev register failed\n");
1931 input_free_device(idev);
1935 static struct input_dev *imon_init_touch(struct imon_context *ictx)
1937 struct input_dev *touch;
1940 touch = input_allocate_device();
1942 dev_err(ictx->dev, "touchscreen input dev allocation failed\n");
1943 goto touch_alloc_failed;
1946 snprintf(ictx->name_touch, sizeof(ictx->name_touch),
1947 "iMON USB Touchscreen (%04x:%04x)",
1948 ictx->vendor, ictx->product);
1949 touch->name = ictx->name_touch;
1951 usb_make_path(ictx->usbdev_intf1, ictx->phys_touch,
1952 sizeof(ictx->phys_touch));
1953 strlcat(ictx->phys_touch, "/input2", sizeof(ictx->phys_touch));
1954 touch->phys = ictx->phys_touch;
1957 BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
1958 touch->keybit[BIT_WORD(BTN_TOUCH)] =
1959 BIT_MASK(BTN_TOUCH);
1960 input_set_abs_params(touch, ABS_X,
1962 input_set_abs_params(touch, ABS_Y,
1965 input_set_drvdata(touch, ictx);
1967 usb_to_input_id(ictx->usbdev_intf1, &touch->id);
1968 touch->dev.parent = ictx->dev;
1969 ret = input_register_device(touch);
1971 dev_info(ictx->dev, "touchscreen input dev register failed\n");
1972 goto touch_register_failed;
1977 touch_register_failed:
1978 input_free_device(ictx->touch);
1984 static bool imon_find_endpoints(struct imon_context *ictx,
1985 struct usb_host_interface *iface_desc)
1987 struct usb_endpoint_descriptor *ep;
1988 struct usb_endpoint_descriptor *rx_endpoint = NULL;
1989 struct usb_endpoint_descriptor *tx_endpoint = NULL;
1990 int ifnum = iface_desc->desc.bInterfaceNumber;
1991 int num_endpts = iface_desc->desc.bNumEndpoints;
1992 int i, ep_dir, ep_type;
1993 bool ir_ep_found = false;
1994 bool display_ep_found = false;
1995 bool tx_control = false;
1998 * Scan the endpoint list and set:
1999 * first input endpoint = IR endpoint
2000 * first output endpoint = display endpoint
2002 for (i = 0; i < num_endpts && !(ir_ep_found && display_ep_found); ++i) {
2003 ep = &iface_desc->endpoint[i].desc;
2004 ep_dir = ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK;
2005 ep_type = ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
2007 if (!ir_ep_found && ep_dir == USB_DIR_IN &&
2008 ep_type == USB_ENDPOINT_XFER_INT) {
2012 dev_dbg(ictx->dev, "%s: found IR endpoint\n", __func__);
2014 } else if (!display_ep_found && ep_dir == USB_DIR_OUT &&
2015 ep_type == USB_ENDPOINT_XFER_INT) {
2017 display_ep_found = true;
2018 dev_dbg(ictx->dev, "%s: found display endpoint\n", __func__);
2023 ictx->rx_endpoint_intf0 = rx_endpoint;
2025 * tx is used to send characters to lcd/vfd, associate RF
2026 * remotes, set IR protocol, and maybe more...
2028 ictx->tx_endpoint = tx_endpoint;
2030 ictx->rx_endpoint_intf1 = rx_endpoint;
2034 * If we didn't find a display endpoint, this is probably one of the
2035 * newer iMON devices that use control urb instead of interrupt
2037 if (!display_ep_found) {
2039 display_ep_found = true;
2040 dev_dbg(ictx->dev, "%s: device uses control endpoint, not "
2041 "interface OUT endpoint\n", __func__);
2045 * Some iMON receivers have no display. Unfortunately, it seems
2046 * that SoundGraph recycles device IDs between devices both with
2049 if (ictx->display_type == IMON_DISPLAY_TYPE_NONE) {
2050 display_ep_found = false;
2051 dev_dbg(ictx->dev, "%s: device has no display\n", __func__);
2055 * iMON Touch devices have a VGA touchscreen, but no "display", as
2056 * that refers to e.g. /dev/lcd0 (a character device LCD or VFD).
2058 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) {
2059 display_ep_found = false;
2060 dev_dbg(ictx->dev, "%s: iMON Touch device found\n", __func__);
2063 /* Input endpoint is mandatory */
2065 pr_err("no valid input (IR) endpoint found\n");
2067 ictx->tx_control = tx_control;
2069 if (display_ep_found)
2070 ictx->display_supported = true;
2076 static struct imon_context *imon_init_intf0(struct usb_interface *intf)
2078 struct imon_context *ictx;
2081 struct device *dev = &intf->dev;
2082 struct usb_host_interface *iface_desc;
2085 ictx = kzalloc(sizeof(struct imon_context), GFP_KERNEL);
2087 dev_err(dev, "%s: kzalloc failed for context", __func__);
2090 rx_urb = usb_alloc_urb(0, GFP_KERNEL);
2092 dev_err(dev, "%s: usb_alloc_urb failed for IR urb", __func__);
2093 goto rx_urb_alloc_failed;
2095 tx_urb = usb_alloc_urb(0, GFP_KERNEL);
2097 dev_err(dev, "%s: usb_alloc_urb failed for display urb",
2099 goto tx_urb_alloc_failed;
2102 mutex_init(&ictx->lock);
2103 spin_lock_init(&ictx->kc_lock);
2105 mutex_lock(&ictx->lock);
2108 ictx->usbdev_intf0 = usb_get_dev(interface_to_usbdev(intf));
2109 ictx->dev_present_intf0 = true;
2110 ictx->rx_urb_intf0 = rx_urb;
2111 ictx->tx_urb = tx_urb;
2112 ictx->rf_device = false;
2114 ictx->vendor = le16_to_cpu(ictx->usbdev_intf0->descriptor.idVendor);
2115 ictx->product = le16_to_cpu(ictx->usbdev_intf0->descriptor.idProduct);
2118 iface_desc = intf->cur_altsetting;
2119 if (!imon_find_endpoints(ictx, iface_desc)) {
2120 goto find_endpoint_failed;
2123 ictx->idev = imon_init_idev(ictx);
2125 dev_err(dev, "%s: input device setup failed\n", __func__);
2126 goto idev_setup_failed;
2129 ictx->rdev = imon_init_rdev(ictx);
2131 dev_err(dev, "%s: rc device setup failed\n", __func__);
2132 goto rdev_setup_failed;
2135 usb_fill_int_urb(ictx->rx_urb_intf0, ictx->usbdev_intf0,
2136 usb_rcvintpipe(ictx->usbdev_intf0,
2137 ictx->rx_endpoint_intf0->bEndpointAddress),
2138 ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf),
2139 usb_rx_callback_intf0, ictx,
2140 ictx->rx_endpoint_intf0->bInterval);
2142 ret = usb_submit_urb(ictx->rx_urb_intf0, GFP_KERNEL);
2144 pr_err("usb_submit_urb failed for intf0 (%d)\n", ret);
2145 goto urb_submit_failed;
2151 ir_input_unregister(ictx->rdev);
2153 input_unregister_device(ictx->idev);
2155 find_endpoint_failed:
2156 mutex_unlock(&ictx->lock);
2157 usb_free_urb(tx_urb);
2158 tx_urb_alloc_failed:
2159 usb_free_urb(rx_urb);
2160 rx_urb_alloc_failed:
2163 dev_err(dev, "unable to initialize intf0, err %d\n", ret);
2168 static struct imon_context *imon_init_intf1(struct usb_interface *intf,
2169 struct imon_context *ictx)
2172 struct usb_host_interface *iface_desc;
2175 rx_urb = usb_alloc_urb(0, GFP_KERNEL);
2177 pr_err("usb_alloc_urb failed for IR urb\n");
2178 goto rx_urb_alloc_failed;
2181 mutex_lock(&ictx->lock);
2183 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) {
2184 init_timer(&ictx->ttimer);
2185 ictx->ttimer.data = (unsigned long)ictx;
2186 ictx->ttimer.function = imon_touch_display_timeout;
2189 ictx->usbdev_intf1 = usb_get_dev(interface_to_usbdev(intf));
2190 ictx->dev_present_intf1 = true;
2191 ictx->rx_urb_intf1 = rx_urb;
2194 iface_desc = intf->cur_altsetting;
2195 if (!imon_find_endpoints(ictx, iface_desc))
2196 goto find_endpoint_failed;
2198 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) {
2199 ictx->touch = imon_init_touch(ictx);
2201 goto touch_setup_failed;
2205 usb_fill_int_urb(ictx->rx_urb_intf1, ictx->usbdev_intf1,
2206 usb_rcvintpipe(ictx->usbdev_intf1,
2207 ictx->rx_endpoint_intf1->bEndpointAddress),
2208 ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf),
2209 usb_rx_callback_intf1, ictx,
2210 ictx->rx_endpoint_intf1->bInterval);
2212 ret = usb_submit_urb(ictx->rx_urb_intf1, GFP_KERNEL);
2215 pr_err("usb_submit_urb failed for intf1 (%d)\n", ret);
2216 goto urb_submit_failed;
2223 input_unregister_device(ictx->touch);
2225 find_endpoint_failed:
2226 mutex_unlock(&ictx->lock);
2227 usb_free_urb(rx_urb);
2228 rx_urb_alloc_failed:
2229 dev_err(ictx->dev, "unable to initialize intf0, err %d\n", ret);
2234 static void imon_init_display(struct imon_context *ictx,
2235 struct usb_interface *intf)
2239 dev_dbg(ictx->dev, "Registering iMON display with sysfs\n");
2241 /* set up sysfs entry for built-in clock */
2242 ret = sysfs_create_group(&intf->dev.kobj,
2243 &imon_display_attribute_group);
2245 dev_err(ictx->dev, "Could not create display sysfs "
2246 "entries(%d)", ret);
2248 if (ictx->display_type == IMON_DISPLAY_TYPE_LCD)
2249 ret = usb_register_dev(intf, &imon_lcd_class);
2251 ret = usb_register_dev(intf, &imon_vfd_class);
2253 /* Not a fatal error, so ignore */
2254 dev_info(ictx->dev, "could not get a minor number for "
2260 * Callback function for USB core API: Probe
2262 static int __devinit imon_probe(struct usb_interface *interface,
2263 const struct usb_device_id *id)
2265 struct usb_device *usbdev = NULL;
2266 struct usb_host_interface *iface_desc = NULL;
2267 struct usb_interface *first_if;
2268 struct device *dev = &interface->dev;
2269 int ifnum, code_length, sysfs_err;
2271 struct imon_context *ictx = NULL;
2272 struct imon_context *first_if_ctx = NULL;
2273 u16 vendor, product;
2275 code_length = BUF_CHUNK_SIZE * 8;
2277 usbdev = usb_get_dev(interface_to_usbdev(interface));
2278 iface_desc = interface->cur_altsetting;
2279 ifnum = iface_desc->desc.bInterfaceNumber;
2280 vendor = le16_to_cpu(usbdev->descriptor.idVendor);
2281 product = le16_to_cpu(usbdev->descriptor.idProduct);
2283 dev_dbg(dev, "%s: found iMON device (%04x:%04x, intf%d)\n",
2284 __func__, vendor, product, ifnum);
2286 /* prevent races probing devices w/multiple interfaces */
2287 mutex_lock(&driver_lock);
2289 first_if = usb_ifnum_to_if(usbdev, 0);
2290 first_if_ctx = (struct imon_context *)usb_get_intfdata(first_if);
2293 ictx = imon_init_intf0(interface);
2295 pr_err("failed to initialize context!\n");
2301 /* this is the secondary interface on the device */
2302 ictx = imon_init_intf1(interface, first_if_ctx);
2304 pr_err("failed to attach to context!\n");
2311 usb_set_intfdata(interface, ictx);
2314 if (product == 0xffdc && ictx->rf_device) {
2315 sysfs_err = sysfs_create_group(&interface->dev.kobj,
2316 &imon_rf_attribute_group);
2318 pr_err("Could not create RF sysfs entries(%d)\n",
2322 if (ictx->display_supported)
2323 imon_init_display(ictx, interface);
2326 /* set IR protocol/remote type */
2327 ret = imon_ir_change_protocol(ictx, ictx->ir_type);
2329 dev_warn(dev, "%s: failed to set IR protocol, falling back "
2330 "to standard iMON protocol mode\n", __func__);
2331 ictx->ir_type = IR_TYPE_OTHER;
2334 dev_info(dev, "iMON device (%04x:%04x, intf%d) on "
2335 "usb<%d:%d> initialized\n", vendor, product, ifnum,
2336 usbdev->bus->busnum, usbdev->devnum);
2338 mutex_unlock(&ictx->lock);
2339 mutex_unlock(&driver_lock);
2344 mutex_unlock(&driver_lock);
2345 dev_err(dev, "unable to register, err %d\n", ret);
2351 * Callback function for USB core API: disconnect
2353 static void __devexit imon_disconnect(struct usb_interface *interface)
2355 struct imon_context *ictx;
2359 /* prevent races with multi-interface device probing and display_open */
2360 mutex_lock(&driver_lock);
2362 ictx = usb_get_intfdata(interface);
2364 ifnum = interface->cur_altsetting->desc.bInterfaceNumber;
2366 mutex_lock(&ictx->lock);
2369 * sysfs_remove_group is safe to call even if sysfs_create_group
2370 * hasn't been called
2372 sysfs_remove_group(&interface->dev.kobj,
2373 &imon_display_attribute_group);
2374 sysfs_remove_group(&interface->dev.kobj,
2375 &imon_rf_attribute_group);
2377 usb_set_intfdata(interface, NULL);
2379 /* Abort ongoing write */
2380 if (ictx->tx.busy) {
2381 usb_kill_urb(ictx->tx_urb);
2382 complete_all(&ictx->tx.finished);
2386 ictx->dev_present_intf0 = false;
2387 usb_kill_urb(ictx->rx_urb_intf0);
2388 input_unregister_device(ictx->idev);
2389 ir_input_unregister(ictx->rdev);
2390 if (ictx->display_supported) {
2391 if (ictx->display_type == IMON_DISPLAY_TYPE_LCD)
2392 usb_deregister_dev(interface, &imon_lcd_class);
2394 usb_deregister_dev(interface, &imon_vfd_class);
2397 ictx->dev_present_intf1 = false;
2398 usb_kill_urb(ictx->rx_urb_intf1);
2399 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA)
2400 input_unregister_device(ictx->touch);
2403 if (!ictx->dev_present_intf0 && !ictx->dev_present_intf1) {
2404 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA)
2405 del_timer_sync(&ictx->ttimer);
2406 mutex_unlock(&ictx->lock);
2407 if (!ictx->display_isopen)
2408 free_imon_context(ictx);
2410 mutex_unlock(&ictx->lock);
2412 mutex_unlock(&driver_lock);
2414 dev_dbg(dev, "%s: iMON device (intf%d) disconnected\n",
2418 static int imon_suspend(struct usb_interface *intf, pm_message_t message)
2420 struct imon_context *ictx = usb_get_intfdata(intf);
2421 int ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
2424 usb_kill_urb(ictx->rx_urb_intf0);
2426 usb_kill_urb(ictx->rx_urb_intf1);
2431 static int imon_resume(struct usb_interface *intf)
2434 struct imon_context *ictx = usb_get_intfdata(intf);
2435 int ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
2438 usb_fill_int_urb(ictx->rx_urb_intf0, ictx->usbdev_intf0,
2439 usb_rcvintpipe(ictx->usbdev_intf0,
2440 ictx->rx_endpoint_intf0->bEndpointAddress),
2441 ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf),
2442 usb_rx_callback_intf0, ictx,
2443 ictx->rx_endpoint_intf0->bInterval);
2445 rc = usb_submit_urb(ictx->rx_urb_intf0, GFP_ATOMIC);
2448 usb_fill_int_urb(ictx->rx_urb_intf1, ictx->usbdev_intf1,
2449 usb_rcvintpipe(ictx->usbdev_intf1,
2450 ictx->rx_endpoint_intf1->bEndpointAddress),
2451 ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf),
2452 usb_rx_callback_intf1, ictx,
2453 ictx->rx_endpoint_intf1->bInterval);
2455 rc = usb_submit_urb(ictx->rx_urb_intf1, GFP_ATOMIC);
2461 static int __init imon_init(void)
2465 rc = usb_register(&imon_driver);
2467 pr_err("usb register failed(%d)\n", rc);
2474 static void __exit imon_exit(void)
2476 usb_deregister(&imon_driver);
2479 module_init(imon_init);
2480 module_exit(imon_exit);