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.2"
49 #define DISPLAY_MINOR_BASE 144
50 #define DEVICE_NAME "lcd%d"
52 #define BUF_CHUNK_SIZE 8
55 #define BIT_DURATION 250 /* each bit received is 250us */
57 #define IMON_CLOCK_ENABLE_PACKETS 2
59 /*** P R O T O T Y P E S ***/
61 /* USB Callback prototypes */
62 static int imon_probe(struct usb_interface
*interface
,
63 const struct usb_device_id
*id
);
64 static void imon_disconnect(struct usb_interface
*interface
);
65 static void usb_rx_callback_intf0(struct urb
*urb
);
66 static void usb_rx_callback_intf1(struct urb
*urb
);
67 static void usb_tx_callback(struct urb
*urb
);
69 /* suspend/resume support */
70 static int imon_resume(struct usb_interface
*intf
);
71 static int imon_suspend(struct usb_interface
*intf
, pm_message_t message
);
73 /* Display file_operations function prototypes */
74 static int display_open(struct inode
*inode
, struct file
*file
);
75 static int display_close(struct inode
*inode
, struct file
*file
);
77 /* VFD write operation */
78 static ssize_t
vfd_write(struct file
*file
, const char *buf
,
79 size_t n_bytes
, loff_t
*pos
);
81 /* LCD file_operations override function prototypes */
82 static ssize_t
lcd_write(struct file
*file
, const char *buf
,
83 size_t n_bytes
, loff_t
*pos
);
85 /*** G L O B A L S ***/
89 struct ir_dev_props
*props
;
90 /* Newer devices have two interfaces */
91 struct usb_device
*usbdev_intf0
;
92 struct usb_device
*usbdev_intf1
;
94 bool display_supported
; /* not all controllers do */
95 bool display_isopen
; /* display port has been opened */
96 bool rf_device
; /* true if iMON 2.4G LT/DT RF device */
97 bool rf_isassociating
; /* RF remote associating */
98 bool dev_present_intf0
; /* USB device presence, interface 0 */
99 bool dev_present_intf1
; /* USB device presence, interface 1 */
101 struct mutex lock
; /* to lock this object */
102 wait_queue_head_t remove_ok
; /* For unexpected USB disconnects */
104 struct usb_endpoint_descriptor
*rx_endpoint_intf0
;
105 struct usb_endpoint_descriptor
*rx_endpoint_intf1
;
106 struct usb_endpoint_descriptor
*tx_endpoint
;
107 struct urb
*rx_urb_intf0
;
108 struct urb
*rx_urb_intf1
;
111 unsigned char usb_rx_buf
[8];
112 unsigned char usb_tx_buf
[8];
115 unsigned char data_buf
[35]; /* user data buffer */
116 struct completion finished
; /* wait for write to finish */
117 bool busy
; /* write in progress */
118 int status
; /* status of tx completion */
121 u16 vendor
; /* usb vendor ID */
122 u16 product
; /* usb product ID */
124 struct input_dev
*rdev
; /* input device for remote */
125 struct input_dev
*idev
; /* input device for panel & IR mouse */
126 struct input_dev
*touch
; /* input device for touchscreen */
128 u32 kc
; /* current input keycode */
129 u32 last_keycode
; /* last reported input keycode */
130 u32 rc_scancode
; /* the computed remote scancode */
131 u8 rc_toggle
; /* the computed remote toggle bit */
132 u64 ir_type
; /* iMON or MCE (RC6) IR protocol? */
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_rdev
[128]; /* rc input device name */
139 char phys_rdev
[64]; /* rc input device phys path */
141 char name_idev
[128]; /* input device name */
142 char phys_idev
[64]; /* input device phys path */
144 char name_touch
[128]; /* touch screen name */
145 char phys_touch
[64]; /* touch screen phys path */
146 struct timer_list ttimer
; /* touch screen timer */
147 int touch_x
; /* x coordinate on touchscreen */
148 int touch_y
; /* y coordinate on touchscreen */
151 #define TOUCH_TIMEOUT (HZ/30)
153 /* vfd character device file operations */
154 static const struct file_operations vfd_fops
= {
155 .owner
= THIS_MODULE
,
156 .open
= &display_open
,
158 .release
= &display_close
161 /* lcd character device file operations */
162 static const struct file_operations lcd_fops
= {
163 .owner
= THIS_MODULE
,
164 .open
= &display_open
,
166 .release
= &display_close
170 IMON_DISPLAY_TYPE_AUTO
= 0,
171 IMON_DISPLAY_TYPE_VFD
= 1,
172 IMON_DISPLAY_TYPE_LCD
= 2,
173 IMON_DISPLAY_TYPE_VGA
= 3,
174 IMON_DISPLAY_TYPE_NONE
= 4,
184 * USB Device ID for iMON USB Control Boards
186 * The Windows drivers contain 6 different inf files, more or less one for
187 * each new device until the 0x0034-0x0046 devices, which all use the same
188 * driver. Some of the devices in the 34-46 range haven't been definitively
189 * identified yet. Early devices have either a TriGem Computer, Inc. or a
190 * Samsung vendor ID (0x0aa8 and 0x04e8 respectively), while all later
191 * devices use the SoundGraph vendor ID (0x15c2). This driver only supports
192 * the ffdc and later devices, which do onboard decoding.
194 static struct usb_device_id imon_usb_id_table
[] = {
196 * Several devices with this same device ID, all use iMON_PAD.inf
197 * SoundGraph iMON PAD (IR & VFD)
198 * SoundGraph iMON PAD (IR & LCD)
199 * SoundGraph iMON Knob (IR only)
201 { USB_DEVICE(0x15c2, 0xffdc) },
204 * Newer devices, all driven by the latest iMON Windows driver, full
205 * list of device IDs extracted via 'strings Setup/data1.hdr |grep 15c2'
206 * Need user input to fill in details on unknown devices.
208 /* SoundGraph iMON OEM Touch LCD (IR & 7" VGA LCD) */
209 { USB_DEVICE(0x15c2, 0x0034) },
210 /* SoundGraph iMON OEM Touch LCD (IR & 4.3" VGA LCD) */
211 { USB_DEVICE(0x15c2, 0x0035) },
212 /* SoundGraph iMON OEM VFD (IR & VFD) */
213 { USB_DEVICE(0x15c2, 0x0036) },
214 /* device specifics unknown */
215 { USB_DEVICE(0x15c2, 0x0037) },
216 /* SoundGraph iMON OEM LCD (IR & LCD) */
217 { USB_DEVICE(0x15c2, 0x0038) },
218 /* SoundGraph iMON UltraBay (IR & LCD) */
219 { USB_DEVICE(0x15c2, 0x0039) },
220 /* device specifics unknown */
221 { USB_DEVICE(0x15c2, 0x003a) },
222 /* device specifics unknown */
223 { USB_DEVICE(0x15c2, 0x003b) },
224 /* SoundGraph iMON OEM Inside (IR only) */
225 { USB_DEVICE(0x15c2, 0x003c) },
226 /* device specifics unknown */
227 { USB_DEVICE(0x15c2, 0x003d) },
228 /* device specifics unknown */
229 { USB_DEVICE(0x15c2, 0x003e) },
230 /* device specifics unknown */
231 { USB_DEVICE(0x15c2, 0x003f) },
232 /* device specifics unknown */
233 { USB_DEVICE(0x15c2, 0x0040) },
234 /* SoundGraph iMON MINI (IR only) */
235 { USB_DEVICE(0x15c2, 0x0041) },
236 /* Antec Veris Multimedia Station EZ External (IR only) */
237 { USB_DEVICE(0x15c2, 0x0042) },
238 /* Antec Veris Multimedia Station Basic Internal (IR only) */
239 { USB_DEVICE(0x15c2, 0x0043) },
240 /* Antec Veris Multimedia Station Elite (IR & VFD) */
241 { USB_DEVICE(0x15c2, 0x0044) },
242 /* Antec Veris Multimedia Station Premiere (IR & LCD) */
243 { USB_DEVICE(0x15c2, 0x0045) },
244 /* device specifics unknown */
245 { USB_DEVICE(0x15c2, 0x0046) },
249 /* USB Device data */
250 static struct usb_driver imon_driver
= {
253 .disconnect
= imon_disconnect
,
254 .suspend
= imon_suspend
,
255 .resume
= imon_resume
,
256 .id_table
= imon_usb_id_table
,
259 static struct usb_class_driver imon_vfd_class
= {
262 .minor_base
= DISPLAY_MINOR_BASE
,
265 static struct usb_class_driver imon_lcd_class
= {
268 .minor_base
= DISPLAY_MINOR_BASE
,
271 /* imon receiver front panel/knob key table */
272 static const struct {
275 } imon_panel_key_table
[] = {
276 { 0x000000000f00ffeell
, KEY_PROG1
}, /* Go */
277 { 0x000000001f00ffeell
, KEY_AUDIO
},
278 { 0x000000002000ffeell
, KEY_VIDEO
},
279 { 0x000000002100ffeell
, KEY_CAMERA
},
280 { 0x000000002700ffeell
, KEY_DVD
},
281 { 0x000000002300ffeell
, KEY_TV
},
282 { 0x000000000500ffeell
, KEY_PREVIOUS
},
283 { 0x000000000700ffeell
, KEY_REWIND
},
284 { 0x000000000400ffeell
, KEY_STOP
},
285 { 0x000000003c00ffeell
, KEY_PLAYPAUSE
},
286 { 0x000000000800ffeell
, KEY_FASTFORWARD
},
287 { 0x000000000600ffeell
, KEY_NEXT
},
288 { 0x000000010000ffeell
, KEY_RIGHT
},
289 { 0x000001000000ffeell
, KEY_LEFT
},
290 { 0x000000003d00ffeell
, KEY_SELECT
},
291 { 0x000100000000ffeell
, KEY_VOLUMEUP
},
292 { 0x010000000000ffeell
, KEY_VOLUMEDOWN
},
293 { 0x000000000100ffeell
, KEY_MUTE
},
294 /* iMON Knob values */
295 { 0x000100ffffffffeell
, KEY_VOLUMEUP
},
296 { 0x010000ffffffffeell
, KEY_VOLUMEDOWN
},
297 { 0x000008ffffffffeell
, KEY_MUTE
},
300 /* to prevent races between open() and disconnect(), probing, etc */
301 static DEFINE_MUTEX(driver_lock
);
303 /* Module bookkeeping bits */
304 MODULE_AUTHOR(MOD_AUTHOR
);
305 MODULE_DESCRIPTION(MOD_DESC
);
306 MODULE_VERSION(MOD_VERSION
);
307 MODULE_LICENSE("GPL");
308 MODULE_DEVICE_TABLE(usb
, imon_usb_id_table
);
311 module_param(debug
, bool, S_IRUGO
| S_IWUSR
);
312 MODULE_PARM_DESC(debug
, "Debug messages: 0=no, 1=yes(default: no)");
314 /* lcd, vfd, vga or none? should be auto-detected, but can be overridden... */
315 static int display_type
;
316 module_param(display_type
, int, S_IRUGO
);
317 MODULE_PARM_DESC(display_type
, "Type of attached display. 0=autodetect, "
318 "1=vfd, 2=lcd, 3=vga, 4=none (default: autodetect)");
320 static int pad_stabilize
= 1;
321 module_param(pad_stabilize
, int, S_IRUGO
| S_IWUSR
);
322 MODULE_PARM_DESC(pad_stabilize
, "Apply stabilization algorithm to iMON PAD "
323 "presses in arrow key mode. 0=disable, 1=enable (default).");
326 * In certain use cases, mouse mode isn't really helpful, and could actually
327 * cause confusion, so allow disabling it when the IR device is open.
330 module_param(nomouse
, bool, S_IRUGO
| S_IWUSR
);
331 MODULE_PARM_DESC(nomouse
, "Disable mouse input device mode when IR device is "
332 "open. 0=don't disable, 1=disable. (default: don't disable)");
334 /* threshold at which a pad push registers as an arrow key in kbd mode */
335 static int pad_thresh
;
336 module_param(pad_thresh
, int, S_IRUGO
| S_IWUSR
);
337 MODULE_PARM_DESC(pad_thresh
, "Threshold at which a pad push registers as an "
338 "arrow key in kbd mode (default: 28)");
341 static void free_imon_context(struct imon_context
*ictx
)
343 struct device
*dev
= ictx
->dev
;
345 usb_free_urb(ictx
->tx_urb
);
346 usb_free_urb(ictx
->rx_urb_intf0
);
347 usb_free_urb(ictx
->rx_urb_intf1
);
350 dev_dbg(dev
, "%s: iMON context freed\n", __func__
);
354 * Called when the Display device (e.g. /dev/lcd0)
355 * is opened by the application.
357 static int display_open(struct inode
*inode
, struct file
*file
)
359 struct usb_interface
*interface
;
360 struct imon_context
*ictx
= NULL
;
364 /* prevent races with disconnect */
365 mutex_lock(&driver_lock
);
367 subminor
= iminor(inode
);
368 interface
= usb_find_interface(&imon_driver
, subminor
);
370 err("%s: could not find interface for minor %d",
375 ictx
= usb_get_intfdata(interface
);
378 err("%s: no context found for minor %d", __func__
, subminor
);
383 mutex_lock(&ictx
->lock
);
385 if (!ictx
->display_supported
) {
386 err("%s: display not supported by device", __func__
);
388 } else if (ictx
->display_isopen
) {
389 err("%s: display port is already open", __func__
);
392 ictx
->display_isopen
= true;
393 file
->private_data
= ictx
;
394 dev_dbg(ictx
->dev
, "display port opened\n");
397 mutex_unlock(&ictx
->lock
);
400 mutex_unlock(&driver_lock
);
405 * Called when the display device (e.g. /dev/lcd0)
406 * is closed by the application.
408 static int display_close(struct inode
*inode
, struct file
*file
)
410 struct imon_context
*ictx
= NULL
;
413 ictx
= file
->private_data
;
416 err("%s: no context for device", __func__
);
420 mutex_lock(&ictx
->lock
);
422 if (!ictx
->display_supported
) {
423 err("%s: display not supported by device", __func__
);
425 } else if (!ictx
->display_isopen
) {
426 err("%s: display is not open", __func__
);
429 ictx
->display_isopen
= false;
430 dev_dbg(ictx
->dev
, "display port closed\n");
431 if (!ictx
->dev_present_intf0
) {
433 * Device disconnected before close and IR port is not
434 * open. If IR port is open, context will be deleted by
437 mutex_unlock(&ictx
->lock
);
438 free_imon_context(ictx
);
443 mutex_unlock(&ictx
->lock
);
448 * Sends a packet to the device -- this function must be called
449 * with ictx->lock held.
451 static int send_packet(struct imon_context
*ictx
)
454 unsigned long timeout
;
457 struct usb_ctrlrequest
*control_req
= NULL
;
459 /* Check if we need to use control or interrupt urb */
460 if (!ictx
->tx_control
) {
461 pipe
= usb_sndintpipe(ictx
->usbdev_intf0
,
462 ictx
->tx_endpoint
->bEndpointAddress
);
463 interval
= ictx
->tx_endpoint
->bInterval
;
465 usb_fill_int_urb(ictx
->tx_urb
, ictx
->usbdev_intf0
, pipe
,
467 sizeof(ictx
->usb_tx_buf
),
468 usb_tx_callback
, ictx
, interval
);
470 ictx
->tx_urb
->actual_length
= 0;
472 /* fill request into kmalloc'ed space: */
473 control_req
= kmalloc(sizeof(struct usb_ctrlrequest
),
475 if (control_req
== NULL
)
478 /* setup packet is '21 09 0200 0001 0008' */
479 control_req
->bRequestType
= 0x21;
480 control_req
->bRequest
= 0x09;
481 control_req
->wValue
= cpu_to_le16(0x0200);
482 control_req
->wIndex
= cpu_to_le16(0x0001);
483 control_req
->wLength
= cpu_to_le16(0x0008);
485 /* control pipe is endpoint 0x00 */
486 pipe
= usb_sndctrlpipe(ictx
->usbdev_intf0
, 0);
488 /* build the control urb */
489 usb_fill_control_urb(ictx
->tx_urb
, ictx
->usbdev_intf0
,
490 pipe
, (unsigned char *)control_req
,
492 sizeof(ictx
->usb_tx_buf
),
493 usb_tx_callback
, ictx
);
494 ictx
->tx_urb
->actual_length
= 0;
497 init_completion(&ictx
->tx
.finished
);
498 ictx
->tx
.busy
= true;
499 smp_rmb(); /* ensure later readers know we're busy */
501 retval
= usb_submit_urb(ictx
->tx_urb
, GFP_KERNEL
);
503 ictx
->tx
.busy
= false;
504 smp_rmb(); /* ensure later readers know we're not busy */
505 err("%s: error submitting urb(%d)", __func__
, retval
);
507 /* Wait for transmission to complete (or abort) */
508 mutex_unlock(&ictx
->lock
);
509 retval
= wait_for_completion_interruptible(
512 err("%s: task interrupted", __func__
);
513 mutex_lock(&ictx
->lock
);
515 retval
= ictx
->tx
.status
;
517 err("%s: packet tx failed (%d)", __func__
, retval
);
523 * Induce a mandatory 5ms delay before returning, as otherwise,
524 * send_packet can get called so rapidly as to overwhelm the device,
525 * particularly on faster systems and/or those with quirky usb.
527 timeout
= msecs_to_jiffies(5);
528 set_current_state(TASK_UNINTERRUPTIBLE
);
529 schedule_timeout(timeout
);
535 * Sends an associate packet to the iMON 2.4G.
537 * This might not be such a good idea, since it has an id collision with
538 * some versions of the "IR & VFD" combo. The only way to determine if it
539 * is an RF version is to look at the product description string. (Which
540 * we currently do not fetch).
542 static int send_associate_24g(struct imon_context
*ictx
)
545 const unsigned char packet
[8] = { 0x01, 0x00, 0x00, 0x00,
546 0x00, 0x00, 0x00, 0x20 };
549 err("%s: no context for device", __func__
);
553 if (!ictx
->dev_present_intf0
) {
554 err("%s: no iMON device present", __func__
);
558 memcpy(ictx
->usb_tx_buf
, packet
, sizeof(packet
));
559 retval
= send_packet(ictx
);
565 * Sends packets to setup and show clock on iMON display
567 * Arguments: year - last 2 digits of year, month - 1..12,
568 * day - 1..31, dow - day of the week (0-Sun...6-Sat),
569 * hour - 0..23, minute - 0..59, second - 0..59
571 static int send_set_imon_clock(struct imon_context
*ictx
,
572 unsigned int year
, unsigned int month
,
573 unsigned int day
, unsigned int dow
,
574 unsigned int hour
, unsigned int minute
,
577 unsigned char clock_enable_pkt
[IMON_CLOCK_ENABLE_PACKETS
][8];
582 err("%s: no context for device", __func__
);
586 switch (ictx
->display_type
) {
587 case IMON_DISPLAY_TYPE_LCD
:
588 clock_enable_pkt
[0][0] = 0x80;
589 clock_enable_pkt
[0][1] = year
;
590 clock_enable_pkt
[0][2] = month
-1;
591 clock_enable_pkt
[0][3] = day
;
592 clock_enable_pkt
[0][4] = hour
;
593 clock_enable_pkt
[0][5] = minute
;
594 clock_enable_pkt
[0][6] = second
;
596 clock_enable_pkt
[1][0] = 0x80;
597 clock_enable_pkt
[1][1] = 0;
598 clock_enable_pkt
[1][2] = 0;
599 clock_enable_pkt
[1][3] = 0;
600 clock_enable_pkt
[1][4] = 0;
601 clock_enable_pkt
[1][5] = 0;
602 clock_enable_pkt
[1][6] = 0;
604 if (ictx
->product
== 0xffdc) {
605 clock_enable_pkt
[0][7] = 0x50;
606 clock_enable_pkt
[1][7] = 0x51;
608 clock_enable_pkt
[0][7] = 0x88;
609 clock_enable_pkt
[1][7] = 0x8a;
614 case IMON_DISPLAY_TYPE_VFD
:
615 clock_enable_pkt
[0][0] = year
;
616 clock_enable_pkt
[0][1] = month
-1;
617 clock_enable_pkt
[0][2] = day
;
618 clock_enable_pkt
[0][3] = dow
;
619 clock_enable_pkt
[0][4] = hour
;
620 clock_enable_pkt
[0][5] = minute
;
621 clock_enable_pkt
[0][6] = second
;
622 clock_enable_pkt
[0][7] = 0x40;
624 clock_enable_pkt
[1][0] = 0;
625 clock_enable_pkt
[1][1] = 0;
626 clock_enable_pkt
[1][2] = 1;
627 clock_enable_pkt
[1][3] = 0;
628 clock_enable_pkt
[1][4] = 0;
629 clock_enable_pkt
[1][5] = 0;
630 clock_enable_pkt
[1][6] = 0;
631 clock_enable_pkt
[1][7] = 0x42;
639 for (i
= 0; i
< IMON_CLOCK_ENABLE_PACKETS
; i
++) {
640 memcpy(ictx
->usb_tx_buf
, clock_enable_pkt
[i
], 8);
641 retval
= send_packet(ictx
);
643 err("%s: send_packet failed for packet %d",
653 * These are the sysfs functions to handle the association on the iMON 2.4G LT.
655 static ssize_t
show_associate_remote(struct device
*d
,
656 struct device_attribute
*attr
,
659 struct imon_context
*ictx
= dev_get_drvdata(d
);
664 mutex_lock(&ictx
->lock
);
665 if (ictx
->rf_isassociating
)
666 strcpy(buf
, "associating\n");
668 strcpy(buf
, "closed\n");
670 dev_info(d
, "Visit http://www.lirc.org/html/imon-24g.html for "
671 "instructions on how to associate your iMON 2.4G DT/LT "
673 mutex_unlock(&ictx
->lock
);
677 static ssize_t
store_associate_remote(struct device
*d
,
678 struct device_attribute
*attr
,
679 const char *buf
, size_t count
)
681 struct imon_context
*ictx
;
683 ictx
= dev_get_drvdata(d
);
688 mutex_lock(&ictx
->lock
);
689 ictx
->rf_isassociating
= true;
690 send_associate_24g(ictx
);
691 mutex_unlock(&ictx
->lock
);
697 * sysfs functions to control internal imon clock
699 static ssize_t
show_imon_clock(struct device
*d
,
700 struct device_attribute
*attr
, char *buf
)
702 struct imon_context
*ictx
= dev_get_drvdata(d
);
708 mutex_lock(&ictx
->lock
);
710 if (!ictx
->display_supported
) {
711 len
= snprintf(buf
, PAGE_SIZE
, "Not supported.");
713 len
= snprintf(buf
, PAGE_SIZE
,
714 "To set the clock on your iMON display:\n"
715 "# date \"+%%y %%m %%d %%w %%H %%M %%S\" > imon_clock\n"
716 "%s", ictx
->display_isopen
?
717 "\nNOTE: imon device must be closed\n" : "");
720 mutex_unlock(&ictx
->lock
);
725 static ssize_t
store_imon_clock(struct device
*d
,
726 struct device_attribute
*attr
,
727 const char *buf
, size_t count
)
729 struct imon_context
*ictx
= dev_get_drvdata(d
);
731 unsigned int year
, month
, day
, dow
, hour
, minute
, second
;
736 mutex_lock(&ictx
->lock
);
738 if (!ictx
->display_supported
) {
741 } else if (ictx
->display_isopen
) {
746 if (sscanf(buf
, "%u %u %u %u %u %u %u", &year
, &month
, &day
, &dow
,
747 &hour
, &minute
, &second
) != 7) {
752 if ((month
< 1 || month
> 12) ||
753 (day
< 1 || day
> 31) || (dow
> 6) ||
754 (hour
> 23) || (minute
> 59) || (second
> 59)) {
759 retval
= send_set_imon_clock(ictx
, year
, month
, day
, dow
,
760 hour
, minute
, second
);
766 mutex_unlock(&ictx
->lock
);
772 static DEVICE_ATTR(imon_clock
, S_IWUSR
| S_IRUGO
, show_imon_clock
,
775 static DEVICE_ATTR(associate_remote
, S_IWUSR
| S_IRUGO
, show_associate_remote
,
776 store_associate_remote
);
778 static struct attribute
*imon_display_sysfs_entries
[] = {
779 &dev_attr_imon_clock
.attr
,
783 static struct attribute_group imon_display_attribute_group
= {
784 .attrs
= imon_display_sysfs_entries
787 static struct attribute
*imon_rf_sysfs_entries
[] = {
788 &dev_attr_associate_remote
.attr
,
792 static struct attribute_group imon_rf_attribute_group
= {
793 .attrs
= imon_rf_sysfs_entries
797 * Writes data to the VFD. The iMON VFD is 2x16 characters
798 * and requires data in 5 consecutive USB interrupt packets,
799 * each packet but the last carrying 7 bytes.
801 * I don't know if the VFD board supports features such as
802 * scrolling, clearing rows, blanking, etc. so at
803 * the caller must provide a full screen of data. If fewer
804 * than 32 bytes are provided spaces will be appended to
805 * generate a full screen.
807 static ssize_t
vfd_write(struct file
*file
, const char *buf
,
808 size_t n_bytes
, loff_t
*pos
)
814 struct imon_context
*ictx
;
815 const unsigned char vfd_packet6
[] = {
816 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF };
818 ictx
= file
->private_data
;
820 err("%s: no context for device", __func__
);
824 mutex_lock(&ictx
->lock
);
826 if (!ictx
->dev_present_intf0
) {
827 err("%s: no iMON device present", __func__
);
832 if (n_bytes
<= 0 || n_bytes
> 32) {
833 err("%s: invalid payload size", __func__
);
838 if (copy_from_user(ictx
->tx
.data_buf
, buf
, n_bytes
)) {
843 /* Pad with spaces */
844 for (i
= n_bytes
; i
< 32; ++i
)
845 ictx
->tx
.data_buf
[i
] = ' ';
847 for (i
= 32; i
< 35; ++i
)
848 ictx
->tx
.data_buf
[i
] = 0xFF;
854 memcpy(ictx
->usb_tx_buf
, ictx
->tx
.data_buf
+ offset
, 7);
855 ictx
->usb_tx_buf
[7] = (unsigned char) seq
;
857 retval
= send_packet(ictx
);
859 err("%s: send packet failed for packet #%d",
867 } while (offset
< 35);
870 memcpy(ictx
->usb_tx_buf
, &vfd_packet6
, sizeof(vfd_packet6
));
871 ictx
->usb_tx_buf
[7] = (unsigned char) seq
;
872 retval
= send_packet(ictx
);
874 err("%s: send packet failed for packet #%d",
878 mutex_unlock(&ictx
->lock
);
880 return (!retval
) ? n_bytes
: retval
;
884 * Writes data to the LCD. The iMON OEM LCD screen expects 8-byte
885 * packets. We accept data as 16 hexadecimal digits, followed by a
886 * newline (to make it easy to drive the device from a command-line
887 * -- even though the actual binary data is a bit complicated).
889 * The device itself is not a "traditional" text-mode display. It's
890 * actually a 16x96 pixel bitmap display. That means if you want to
891 * display text, you've got to have your own "font" and translate the
892 * text into bitmaps for display. This is really flexible (you can
893 * display whatever diacritics you need, and so on), but it's also
894 * a lot more complicated than most LCDs...
896 static ssize_t
lcd_write(struct file
*file
, const char *buf
,
897 size_t n_bytes
, loff_t
*pos
)
900 struct imon_context
*ictx
;
902 ictx
= file
->private_data
;
904 err("%s: no context for device", __func__
);
908 mutex_lock(&ictx
->lock
);
910 if (!ictx
->display_supported
) {
911 err("%s: no iMON display present", __func__
);
917 err("%s: invalid payload size: %d (expecting 8)",
918 __func__
, (int) n_bytes
);
923 if (copy_from_user(ictx
->usb_tx_buf
, buf
, 8)) {
928 retval
= send_packet(ictx
);
930 err("%s: send packet failed!", __func__
);
933 dev_dbg(ictx
->dev
, "%s: write %d bytes to LCD\n",
934 __func__
, (int) n_bytes
);
937 mutex_unlock(&ictx
->lock
);
938 return (!retval
) ? n_bytes
: retval
;
942 * Callback function for USB core API: transmit data
944 static void usb_tx_callback(struct urb
*urb
)
946 struct imon_context
*ictx
;
950 ictx
= (struct imon_context
*)urb
->context
;
954 ictx
->tx
.status
= urb
->status
;
956 /* notify waiters that write has finished */
957 ictx
->tx
.busy
= false;
958 smp_rmb(); /* ensure later readers know we're not busy */
959 complete(&ictx
->tx
.finished
);
963 * report touchscreen input
965 static void imon_touch_display_timeout(unsigned long data
)
967 struct imon_context
*ictx
= (struct imon_context
*)data
;
969 if (ictx
->display_type
!= IMON_DISPLAY_TYPE_VGA
)
972 input_report_abs(ictx
->touch
, ABS_X
, ictx
->touch_x
);
973 input_report_abs(ictx
->touch
, ABS_Y
, ictx
->touch_y
);
974 input_report_key(ictx
->touch
, BTN_TOUCH
, 0x00);
975 input_sync(ictx
->touch
);
979 * iMON IR receivers support two different signal sets -- those used by
980 * the iMON remotes, and those used by the Windows MCE remotes (which is
981 * really just RC-6), but only one or the other at a time, as the signals
982 * are decoded onboard the receiver.
984 int imon_ir_change_protocol(void *priv
, u64 ir_type
)
987 struct imon_context
*ictx
= priv
;
988 struct device
*dev
= ictx
->dev
;
990 unsigned char ir_proto_packet
[] = {
991 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86 };
993 if (ir_type
&& !(ir_type
& ictx
->props
->allowed_protos
))
994 dev_warn(dev
, "Looks like you're trying to use an IR protocol "
995 "this device does not support\n");
999 dev_dbg(dev
, "Configuring IR receiver for MCE protocol\n");
1000 ir_proto_packet
[0] = 0x01;
1003 case IR_TYPE_UNKNOWN
:
1005 dev_dbg(dev
, "Configuring IR receiver for iMON protocol\n");
1009 dev_dbg(dev
, "PAD stabilize functionality disabled\n");
1012 /* ir_proto_packet[0] = 0x00; // already the default */
1013 ir_type
= IR_TYPE_OTHER
;
1016 dev_warn(dev
, "Unsupported IR protocol specified, overriding "
1017 "to iMON IR protocol\n");
1021 dev_dbg(dev
, "PAD stabilize functionality disabled\n");
1024 /* ir_proto_packet[0] = 0x00; // already the default */
1025 ir_type
= IR_TYPE_OTHER
;
1029 memcpy(ictx
->usb_tx_buf
, &ir_proto_packet
, sizeof(ir_proto_packet
));
1031 retval
= send_packet(ictx
);
1035 ictx
->ir_type
= ir_type
;
1036 ictx
->pad_mouse
= pad_mouse
;
1042 static inline int tv2int(const struct timeval
*a
, const struct timeval
*b
)
1047 if (b
->tv_usec
> a
->tv_usec
) {
1052 usecs
+= a
->tv_usec
- b
->tv_usec
;
1054 sec
+= a
->tv_sec
- b
->tv_sec
;
1066 * The directional pad behaves a bit differently, depending on whether this is
1067 * one of the older ffdc devices or a newer device. Newer devices appear to
1068 * have a higher resolution matrix for more precise mouse movement, but it
1069 * makes things overly sensitive in keyboard mode, so we do some interesting
1070 * contortions to make it less touchy. Older devices run through the same
1071 * routine with shorter timeout and a smaller threshold.
1073 static int stabilize(int a
, int b
, u16 timeout
, u16 threshold
)
1076 static struct timeval prev_time
= {0, 0};
1077 static struct timeval hit_time
= {0, 0};
1078 static int x
, y
, prev_result
, hits
;
1082 do_gettimeofday(&ct
);
1083 msec
= tv2int(&ct
, &prev_time
);
1084 msec_hit
= tv2int(&ct
, &hit_time
);
1097 if (abs(x
) > threshold
|| abs(y
) > threshold
) {
1098 if (abs(y
) > abs(x
))
1099 result
= (y
> 0) ? 0x7F : 0x80;
1101 result
= (x
> 0) ? 0x7F00 : 0x8000;
1106 if (result
== prev_result
) {
1112 y
= 17 * threshold
/ 30;
1115 y
-= 17 * threshold
/ 30;
1118 x
= 17 * threshold
/ 30;
1121 x
-= 17 * threshold
/ 30;
1126 if (hits
== 2 && msec_hit
< timeout
) {
1131 prev_result
= result
;
1140 static u32
imon_remote_key_lookup(struct imon_context
*ictx
, u32 scancode
)
1144 bool is_release_code
= false;
1146 /* Look for the initial press of a button */
1147 keycode
= ir_g_keycode_from_table(ictx
->rdev
, scancode
);
1148 ictx
->rc_toggle
= 0x0;
1149 ictx
->rc_scancode
= scancode
;
1151 /* Look for the release of a button */
1152 if (keycode
== KEY_RESERVED
) {
1153 release
= scancode
& ~0x4000;
1154 keycode
= ir_g_keycode_from_table(ictx
->rdev
, release
);
1155 if (keycode
!= KEY_RESERVED
)
1156 is_release_code
= true;
1159 ictx
->release_code
= is_release_code
;
1164 static u32
imon_mce_key_lookup(struct imon_context
*ictx
, u32 scancode
)
1168 #define MCE_KEY_MASK 0x7000
1169 #define MCE_TOGGLE_BIT 0x8000
1172 * On some receivers, mce keys decode to 0x8000f04xx and 0x8000f84xx
1173 * (the toggle bit flipping between alternating key presses), while
1174 * on other receivers, we see 0x8000f74xx and 0x8000ff4xx. To keep
1175 * the table trim, we always or in the bits to look up 0x8000ff4xx,
1176 * but we can't or them into all codes, as some keys are decoded in
1177 * a different way w/o the same use of the toggle bit...
1179 if (scancode
& 0x80000000)
1180 scancode
= scancode
| MCE_KEY_MASK
| MCE_TOGGLE_BIT
;
1182 ictx
->rc_scancode
= scancode
;
1183 keycode
= ir_g_keycode_from_table(ictx
->rdev
, scancode
);
1185 /* not used in mce mode, but make sure we know its false */
1186 ictx
->release_code
= false;
1191 static u32
imon_panel_key_lookup(u64 code
)
1194 u32 keycode
= KEY_RESERVED
;
1196 for (i
= 0; i
< ARRAY_SIZE(imon_panel_key_table
); i
++) {
1197 if (imon_panel_key_table
[i
].hw_code
== (code
| 0xffee)) {
1198 keycode
= imon_panel_key_table
[i
].keycode
;
1206 static bool imon_mouse_event(struct imon_context
*ictx
,
1207 unsigned char *buf
, int len
)
1209 char rel_x
= 0x00, rel_y
= 0x00;
1211 bool mouse_input
= true;
1214 /* newer iMON device PAD or mouse button */
1215 if (ictx
->product
!= 0xffdc && (buf
[0] & 0x01) && len
== 5) {
1219 /* 0xffdc iMON PAD or mouse button input */
1220 } else if (ictx
->product
== 0xffdc && (buf
[0] & 0x40) &&
1221 !((buf
[1] & 0x01) || ((buf
[1] >> 2) & 0x01))) {
1222 rel_x
= (buf
[1] & 0x08) | (buf
[1] & 0x10) >> 2 |
1223 (buf
[1] & 0x20) >> 4 | (buf
[1] & 0x40) >> 6;
1226 rel_x
= rel_x
+ rel_x
/ 2;
1227 rel_y
= (buf
[2] & 0x08) | (buf
[2] & 0x10) >> 2 |
1228 (buf
[2] & 0x20) >> 4 | (buf
[2] & 0x40) >> 6;
1231 rel_y
= rel_y
+ rel_y
/ 2;
1233 /* some ffdc devices decode mouse buttons differently... */
1234 } else if (ictx
->product
== 0xffdc && (buf
[0] == 0x68)) {
1236 /* ch+/- buttons, which we use for an emulated scroll wheel */
1237 } else if (ictx
->kc
== KEY_CHANNELUP
&& (buf
[2] & 0x40) != 0x40) {
1239 } else if (ictx
->kc
== KEY_CHANNELDOWN
&& (buf
[2] & 0x40) != 0x40) {
1242 mouse_input
= false;
1245 dev_dbg(ictx
->dev
, "sending mouse data via input subsystem\n");
1248 input_report_rel(ictx
->idev
, REL_WHEEL
, dir
);
1249 } else if (rel_x
|| rel_y
) {
1250 input_report_rel(ictx
->idev
, REL_X
, rel_x
);
1251 input_report_rel(ictx
->idev
, REL_Y
, rel_y
);
1253 input_report_key(ictx
->idev
, BTN_LEFT
, buf
[1] & 0x1);
1254 input_report_key(ictx
->idev
, BTN_RIGHT
,
1255 buf
[1] >> right_shift
& 0x1);
1257 input_sync(ictx
->idev
);
1258 ictx
->last_keycode
= ictx
->kc
;
1264 static void imon_touch_event(struct imon_context
*ictx
, unsigned char *buf
)
1266 mod_timer(&ictx
->ttimer
, jiffies
+ TOUCH_TIMEOUT
);
1267 ictx
->touch_x
= (buf
[0] << 4) | (buf
[1] >> 4);
1268 ictx
->touch_y
= 0xfff - ((buf
[2] << 4) | (buf
[1] & 0xf));
1269 input_report_abs(ictx
->touch
, ABS_X
, ictx
->touch_x
);
1270 input_report_abs(ictx
->touch
, ABS_Y
, ictx
->touch_y
);
1271 input_report_key(ictx
->touch
, BTN_TOUCH
, 0x01);
1272 input_sync(ictx
->touch
);
1275 static void imon_pad_to_keys(struct imon_context
*ictx
, unsigned char *buf
)
1278 char rel_x
= 0x00, rel_y
= 0x00;
1279 u16 timeout
, threshold
;
1280 u32 scancode
= KEY_RESERVED
;
1283 * The imon directional pad functions more like a touchpad. Bytes 3 & 4
1284 * contain a position coordinate (x,y), with each component ranging
1285 * from -14 to 14. We want to down-sample this to only 4 discrete values
1286 * for up/down/left/right arrow keys. Also, when you get too close to
1287 * diagonals, it has a tendancy to jump back and forth, so lets try to
1288 * ignore when they get too close.
1290 if (ictx
->product
!= 0xffdc) {
1291 /* first, pad to 8 bytes so it conforms with everything else */
1292 buf
[5] = buf
[6] = buf
[7] = 0;
1293 timeout
= 500; /* in msecs */
1294 /* (2*threshold) x (2*threshold) square */
1295 threshold
= pad_thresh
? pad_thresh
: 28;
1299 if (ictx
->ir_type
== IR_TYPE_OTHER
&& pad_stabilize
) {
1300 if ((buf
[1] == 0) && ((rel_x
!= 0) || (rel_y
!= 0))) {
1301 dir
= stabilize((int)rel_x
, (int)rel_y
,
1302 timeout
, threshold
);
1304 ictx
->kc
= KEY_UNKNOWN
;
1307 buf
[2] = dir
& 0xFF;
1308 buf
[3] = (dir
>> 8) & 0xFF;
1309 scancode
= be32_to_cpu(*((u32
*)buf
));
1313 * Hack alert: instead of using keycodes, we have
1314 * to use hard-coded scancodes here...
1316 if (abs(rel_y
) > abs(rel_x
)) {
1317 buf
[2] = (rel_y
> 0) ? 0x7F : 0x80;
1320 scancode
= 0x01007f00; /* KEY_DOWN */
1322 scancode
= 0x01008000; /* KEY_UP */
1325 buf
[3] = (rel_x
> 0) ? 0x7F : 0x80;
1327 scancode
= 0x0100007f; /* KEY_RIGHT */
1329 scancode
= 0x01000080; /* KEY_LEFT */
1334 * Handle on-board decoded pad events for e.g. older VFD/iMON-Pad
1335 * device (15c2:ffdc). The remote generates various codes from
1336 * 0x68nnnnB7 to 0x6AnnnnB7, the left mouse button generates
1337 * 0x688301b7 and the right one 0x688481b7. All other keys generate
1338 * 0x2nnnnnnn. Position coordinate is encoded in buf[1] and buf[2] with
1339 * reversed endianess. Extract direction from buffer, rotate endianess,
1340 * adjust sign and feed the values into stabilize(). The resulting codes
1341 * will be 0x01008000, 0x01007F00, which match the newer devices.
1344 timeout
= 10; /* in msecs */
1345 /* (2*threshold) x (2*threshold) square */
1346 threshold
= pad_thresh
? pad_thresh
: 15;
1349 rel_x
= (buf
[1] & 0x08) | (buf
[1] & 0x10) >> 2 |
1350 (buf
[1] & 0x20) >> 4 | (buf
[1] & 0x40) >> 6;
1354 rel_y
= (buf
[2] & 0x08) | (buf
[2] & 0x10) >> 2 |
1355 (buf
[2] & 0x20) >> 4 | (buf
[2] & 0x40) >> 6;
1360 buf
[1] = buf
[4] = buf
[5] = buf
[6] = buf
[7] = 0;
1362 if (ictx
->ir_type
== IR_TYPE_OTHER
&& pad_stabilize
) {
1363 dir
= stabilize((int)rel_x
, (int)rel_y
,
1364 timeout
, threshold
);
1366 ictx
->kc
= KEY_UNKNOWN
;
1369 buf
[2] = dir
& 0xFF;
1370 buf
[3] = (dir
>> 8) & 0xFF;
1371 scancode
= be32_to_cpu(*((u32
*)buf
));
1374 * Hack alert: instead of using keycodes, we have
1375 * to use hard-coded scancodes here...
1377 if (abs(rel_y
) > abs(rel_x
)) {
1378 buf
[2] = (rel_y
> 0) ? 0x7F : 0x80;
1381 scancode
= 0x01007f00; /* KEY_DOWN */
1383 scancode
= 0x01008000; /* KEY_UP */
1386 buf
[3] = (rel_x
> 0) ? 0x7F : 0x80;
1388 scancode
= 0x0100007f; /* KEY_RIGHT */
1390 scancode
= 0x01000080; /* KEY_LEFT */
1396 ictx
->kc
= imon_remote_key_lookup(ictx
, scancode
);
1400 * figure out if these is a press or a release. We don't actually
1401 * care about repeats, as those will be auto-generated within the IR
1402 * subsystem for repeating scancodes.
1404 static int imon_parse_press_type(struct imon_context
*ictx
,
1405 unsigned char *buf
, u8 ktype
)
1409 /* key release of 0x02XXXXXX key */
1410 if (ictx
->kc
== KEY_RESERVED
&& buf
[0] == 0x02 && buf
[3] == 0x00)
1411 ictx
->kc
= ictx
->last_keycode
;
1413 /* mouse button release on (some) 0xffdc devices */
1414 else if (ictx
->kc
== KEY_RESERVED
&& buf
[0] == 0x68 && buf
[1] == 0x82 &&
1415 buf
[2] == 0x81 && buf
[3] == 0xb7)
1416 ictx
->kc
= ictx
->last_keycode
;
1418 /* mouse button release on (some other) 0xffdc devices */
1419 else if (ictx
->kc
== KEY_RESERVED
&& buf
[0] == 0x01 && buf
[1] == 0x00 &&
1420 buf
[2] == 0x81 && buf
[3] == 0xb7)
1421 ictx
->kc
= ictx
->last_keycode
;
1423 /* mce-specific button handling, no keyup events */
1424 else if (ktype
== IMON_KEY_MCE
) {
1425 ictx
->rc_toggle
= buf
[2];
1428 /* incoherent or irrelevant data */
1429 } else if (ictx
->kc
== KEY_RESERVED
)
1430 press_type
= -EINVAL
;
1432 /* key release of 0xXXXXXXb7 key */
1433 else if (ictx
->release_code
)
1436 /* this is a button press */
1444 * Process the incoming packet
1446 static void imon_incoming_packet(struct imon_context
*ictx
,
1447 struct urb
*urb
, int intf
)
1449 int len
= urb
->actual_length
;
1450 unsigned char *buf
= urb
->transfer_buffer
;
1451 struct device
*dev
= ictx
->dev
;
1453 bool norelease
= false;
1456 struct input_dev
*idev
= NULL
;
1457 struct ir_input_dev
*irdev
= NULL
;
1461 static struct timeval prev_time
= { 0, 0 };
1465 irdev
= input_get_drvdata(idev
);
1467 /* filter out junk data on the older 0xffdc imon devices */
1468 if ((buf
[0] == 0xff) && (buf
[1] == 0xff) && (buf
[2] == 0xff))
1471 /* Figure out what key was pressed */
1472 if (len
== 8 && buf
[7] == 0xee) {
1473 scancode
= be64_to_cpu(*((u64
*)buf
));
1474 ktype
= IMON_KEY_PANEL
;
1475 kc
= imon_panel_key_lookup(scancode
);
1477 scancode
= be32_to_cpu(*((u32
*)buf
));
1478 if (ictx
->ir_type
== IR_TYPE_RC6
) {
1479 ktype
= IMON_KEY_IMON
;
1481 ktype
= IMON_KEY_MCE
;
1482 kc
= imon_mce_key_lookup(ictx
, scancode
);
1484 ktype
= IMON_KEY_IMON
;
1485 kc
= imon_remote_key_lookup(ictx
, scancode
);
1489 /* keyboard/mouse mode toggle button */
1490 if (kc
== KEY_KEYBOARD
&& !ictx
->release_code
) {
1491 ictx
->last_keycode
= kc
;
1493 ictx
->pad_mouse
= ~(ictx
->pad_mouse
) & 0x1;
1494 dev_dbg(dev
, "toggling to %s mode\n",
1495 ictx
->pad_mouse
? "mouse" : "keyboard");
1498 ictx
->pad_mouse
= 0;
1499 dev_dbg(dev
, "mouse mode disabled, passing key value\n");
1505 /* send touchscreen events through input subsystem if touchpad data */
1506 if (ictx
->display_type
== IMON_DISPLAY_TYPE_VGA
&& len
== 8 &&
1508 imon_touch_event(ictx
, buf
);
1511 /* look for mouse events with pad in mouse mode */
1512 } else if (ictx
->pad_mouse
) {
1513 if (imon_mouse_event(ictx
, buf
, len
))
1517 /* Now for some special handling to convert pad input to arrow keys */
1518 if (((len
== 5) && (buf
[0] == 0x01) && (buf
[4] == 0x00)) ||
1519 ((len
== 8) && (buf
[0] & 0x40) &&
1520 !(buf
[1] & 0x1 || buf
[1] >> 2 & 0x1))) {
1522 imon_pad_to_keys(ictx
, buf
);
1527 printk(KERN_INFO
"intf%d decoded packet: ", intf
);
1528 for (i
= 0; i
< len
; ++i
)
1529 printk("%02x ", buf
[i
]);
1533 press_type
= imon_parse_press_type(ictx
, buf
, ktype
);
1535 goto not_input_data
;
1537 if (ictx
->kc
== KEY_UNKNOWN
)
1540 if (ktype
!= IMON_KEY_PANEL
) {
1541 if (press_type
== 0)
1544 ir_keydown(ictx
->rdev
, ictx
->rc_scancode
,
1546 ictx
->last_keycode
= ictx
->kc
;
1551 /* Only panel type events left to process now */
1552 /* KEY_MUTE repeats from knob need to be suppressed */
1553 if (ictx
->kc
== KEY_MUTE
&& ictx
->kc
== ictx
->last_keycode
) {
1554 do_gettimeofday(&t
);
1555 msec
= tv2int(&t
, &prev_time
);
1557 if (msec
< idev
->rep
[REP_DELAY
])
1561 input_report_key(idev
, ictx
->kc
, press_type
);
1564 /* panel keys don't generate a release */
1565 input_report_key(idev
, ictx
->kc
, 0);
1568 ictx
->last_keycode
= ictx
->kc
;
1573 dev_info(dev
, "%s: unknown keypress, code 0x%llx\n", __func__
,
1574 (long long)scancode
);
1579 dev_warn(dev
, "imon %s: invalid incoming packet "
1580 "size (len = %d, intf%d)\n", __func__
, len
, intf
);
1584 /* iMON 2.4G associate frame */
1585 if (buf
[0] == 0x00 &&
1586 buf
[2] == 0xFF && /* REFID */
1589 buf
[5] == 0xFF && /* iMON 2.4G */
1590 ((buf
[6] == 0x4E && buf
[7] == 0xDF) || /* LT */
1591 (buf
[6] == 0x5E && buf
[7] == 0xDF))) { /* DT */
1592 dev_warn(dev
, "%s: remote associated refid=%02X\n",
1594 ictx
->rf_isassociating
= false;
1599 * Callback function for USB core API: receive data
1601 static void usb_rx_callback_intf0(struct urb
*urb
)
1603 struct imon_context
*ictx
;
1609 ictx
= (struct imon_context
*)urb
->context
;
1613 switch (urb
->status
) {
1614 case -ENOENT
: /* usbcore unlink successful! */
1617 case -ESHUTDOWN
: /* transport endpoint was shut down */
1621 imon_incoming_packet(ictx
, urb
, intfnum
);
1625 dev_warn(ictx
->dev
, "imon %s: status(%d): ignored\n",
1626 __func__
, urb
->status
);
1630 usb_submit_urb(ictx
->rx_urb_intf0
, GFP_ATOMIC
);
1633 static void usb_rx_callback_intf1(struct urb
*urb
)
1635 struct imon_context
*ictx
;
1641 ictx
= (struct imon_context
*)urb
->context
;
1645 switch (urb
->status
) {
1646 case -ENOENT
: /* usbcore unlink successful! */
1649 case -ESHUTDOWN
: /* transport endpoint was shut down */
1653 imon_incoming_packet(ictx
, urb
, intfnum
);
1657 dev_warn(ictx
->dev
, "imon %s: status(%d): ignored\n",
1658 __func__
, urb
->status
);
1662 usb_submit_urb(ictx
->rx_urb_intf1
, GFP_ATOMIC
);
1665 static struct input_dev
*imon_init_rdev(struct imon_context
*ictx
)
1667 struct input_dev
*rdev
;
1668 struct ir_dev_props
*props
;
1671 rdev
= input_allocate_device();
1672 props
= kzalloc(sizeof(*props
), GFP_KERNEL
);
1673 if (!rdev
|| !props
) {
1674 dev_err(ictx
->dev
, "remote control dev allocation failed\n");
1678 snprintf(ictx
->name_rdev
, sizeof(ictx
->name_rdev
),
1679 "iMON Remote (%04x:%04x)", ictx
->vendor
, ictx
->product
);
1680 usb_make_path(ictx
->usbdev_intf0
, ictx
->phys_rdev
,
1681 sizeof(ictx
->phys_rdev
));
1682 strlcat(ictx
->phys_rdev
, "/input0", sizeof(ictx
->phys_rdev
));
1684 rdev
->name
= ictx
->name_rdev
;
1685 rdev
->phys
= ictx
->phys_rdev
;
1686 usb_to_input_id(ictx
->usbdev_intf0
, &rdev
->id
);
1687 rdev
->dev
.parent
= ictx
->dev
;
1688 rdev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_REP
);
1689 input_set_drvdata(rdev
, ictx
);
1692 props
->driver_type
= RC_DRIVER_SCANCODE
;
1693 props
->allowed_protos
= IR_TYPE_OTHER
| IR_TYPE_RC6
; /* iMON PAD or MCE */
1694 props
->change_protocol
= imon_ir_change_protocol
;
1695 ictx
->props
= props
;
1697 ret
= ir_input_register(rdev
, RC_MAP_IMON_PAD
, props
, MOD_NAME
);
1699 dev_err(ictx
->dev
, "remote input dev register failed\n");
1707 input_free_device(rdev
);
1711 static struct input_dev
*imon_init_idev(struct imon_context
*ictx
)
1713 struct input_dev
*idev
;
1716 idev
= input_allocate_device();
1718 dev_err(ictx
->dev
, "input dev allocation failed\n");
1722 snprintf(ictx
->name_idev
, sizeof(ictx
->name_idev
),
1723 "iMON Panel, Knob and Mouse(%04x:%04x)",
1724 ictx
->vendor
, ictx
->product
);
1725 idev
->name
= ictx
->name_idev
;
1727 usb_make_path(ictx
->usbdev_intf0
, ictx
->phys_idev
,
1728 sizeof(ictx
->phys_idev
));
1729 strlcat(ictx
->phys_idev
, "/input1", sizeof(ictx
->phys_idev
));
1730 idev
->phys
= ictx
->phys_idev
;
1732 idev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_REP
) | BIT_MASK(EV_REL
);
1734 idev
->keybit
[BIT_WORD(BTN_MOUSE
)] =
1735 BIT_MASK(BTN_LEFT
) | BIT_MASK(BTN_RIGHT
);
1736 idev
->relbit
[0] = BIT_MASK(REL_X
) | BIT_MASK(REL_Y
) |
1737 BIT_MASK(REL_WHEEL
);
1739 /* panel and/or knob code support */
1740 for (i
= 0; i
< ARRAY_SIZE(imon_panel_key_table
); i
++) {
1741 u32 kc
= imon_panel_key_table
[i
].keycode
;
1742 __set_bit(kc
, idev
->keybit
);
1745 usb_to_input_id(ictx
->usbdev_intf0
, &idev
->id
);
1746 idev
->dev
.parent
= ictx
->dev
;
1747 input_set_drvdata(idev
, ictx
);
1749 ret
= input_register_device(idev
);
1751 dev_err(ictx
->dev
, "input dev register failed\n");
1758 input_free_device(idev
);
1762 static struct input_dev
*imon_init_touch(struct imon_context
*ictx
)
1764 struct input_dev
*touch
;
1767 touch
= input_allocate_device();
1769 dev_err(ictx
->dev
, "touchscreen input dev allocation failed\n");
1770 goto touch_alloc_failed
;
1773 snprintf(ictx
->name_touch
, sizeof(ictx
->name_touch
),
1774 "iMON USB Touchscreen (%04x:%04x)",
1775 ictx
->vendor
, ictx
->product
);
1776 touch
->name
= ictx
->name_touch
;
1778 usb_make_path(ictx
->usbdev_intf1
, ictx
->phys_touch
,
1779 sizeof(ictx
->phys_touch
));
1780 strlcat(ictx
->phys_touch
, "/input2", sizeof(ictx
->phys_touch
));
1781 touch
->phys
= ictx
->phys_touch
;
1784 BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
1785 touch
->keybit
[BIT_WORD(BTN_TOUCH
)] =
1786 BIT_MASK(BTN_TOUCH
);
1787 input_set_abs_params(touch
, ABS_X
,
1789 input_set_abs_params(touch
, ABS_Y
,
1792 input_set_drvdata(touch
, ictx
);
1794 usb_to_input_id(ictx
->usbdev_intf1
, &touch
->id
);
1795 touch
->dev
.parent
= ictx
->dev
;
1796 ret
= input_register_device(touch
);
1798 dev_info(ictx
->dev
, "touchscreen input dev register failed\n");
1799 goto touch_register_failed
;
1804 touch_register_failed
:
1805 input_free_device(ictx
->touch
);
1811 static bool imon_find_endpoints(struct imon_context
*ictx
,
1812 struct usb_host_interface
*iface_desc
)
1814 struct usb_endpoint_descriptor
*ep
;
1815 struct usb_endpoint_descriptor
*rx_endpoint
= NULL
;
1816 struct usb_endpoint_descriptor
*tx_endpoint
= NULL
;
1817 int ifnum
= iface_desc
->desc
.bInterfaceNumber
;
1818 int num_endpts
= iface_desc
->desc
.bNumEndpoints
;
1819 int i
, ep_dir
, ep_type
;
1820 bool ir_ep_found
= false;
1821 bool display_ep_found
= false;
1822 bool tx_control
= false;
1825 * Scan the endpoint list and set:
1826 * first input endpoint = IR endpoint
1827 * first output endpoint = display endpoint
1829 for (i
= 0; i
< num_endpts
&& !(ir_ep_found
&& display_ep_found
); ++i
) {
1830 ep
= &iface_desc
->endpoint
[i
].desc
;
1831 ep_dir
= ep
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
;
1832 ep_type
= ep
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
;
1834 if (!ir_ep_found
&& ep_dir
== USB_DIR_IN
&&
1835 ep_type
== USB_ENDPOINT_XFER_INT
) {
1839 dev_dbg(ictx
->dev
, "%s: found IR endpoint\n", __func__
);
1841 } else if (!display_ep_found
&& ep_dir
== USB_DIR_OUT
&&
1842 ep_type
== USB_ENDPOINT_XFER_INT
) {
1844 display_ep_found
= true;
1845 dev_dbg(ictx
->dev
, "%s: found display endpoint\n", __func__
);
1850 ictx
->rx_endpoint_intf0
= rx_endpoint
;
1852 * tx is used to send characters to lcd/vfd, associate RF
1853 * remotes, set IR protocol, and maybe more...
1855 ictx
->tx_endpoint
= tx_endpoint
;
1857 ictx
->rx_endpoint_intf1
= rx_endpoint
;
1861 * If we didn't find a display endpoint, this is probably one of the
1862 * newer iMON devices that use control urb instead of interrupt
1864 if (!display_ep_found
) {
1866 display_ep_found
= true;
1867 dev_dbg(ictx
->dev
, "%s: device uses control endpoint, not "
1868 "interface OUT endpoint\n", __func__
);
1872 * Some iMON receivers have no display. Unfortunately, it seems
1873 * that SoundGraph recycles device IDs between devices both with
1876 if (ictx
->display_type
== IMON_DISPLAY_TYPE_NONE
) {
1877 display_ep_found
= false;
1878 dev_dbg(ictx
->dev
, "%s: device has no display\n", __func__
);
1882 * iMON Touch devices have a VGA touchscreen, but no "display", as
1883 * that refers to e.g. /dev/lcd0 (a character device LCD or VFD).
1885 if (ictx
->display_type
== IMON_DISPLAY_TYPE_VGA
) {
1886 display_ep_found
= false;
1887 dev_dbg(ictx
->dev
, "%s: iMON Touch device found\n", __func__
);
1890 /* Input endpoint is mandatory */
1892 err("%s: no valid input (IR) endpoint found.", __func__
);
1894 ictx
->tx_control
= tx_control
;
1896 if (display_ep_found
)
1897 ictx
->display_supported
= true;
1903 static struct imon_context
*imon_init_intf0(struct usb_interface
*intf
)
1905 struct imon_context
*ictx
;
1908 struct device
*dev
= &intf
->dev
;
1909 struct usb_host_interface
*iface_desc
;
1912 ictx
= kzalloc(sizeof(struct imon_context
), GFP_KERNEL
);
1914 dev_err(dev
, "%s: kzalloc failed for context", __func__
);
1917 rx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
1919 dev_err(dev
, "%s: usb_alloc_urb failed for IR urb", __func__
);
1920 goto rx_urb_alloc_failed
;
1922 tx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
1924 dev_err(dev
, "%s: usb_alloc_urb failed for display urb",
1926 goto tx_urb_alloc_failed
;
1929 mutex_init(&ictx
->lock
);
1931 mutex_lock(&ictx
->lock
);
1934 ictx
->usbdev_intf0
= usb_get_dev(interface_to_usbdev(intf
));
1935 ictx
->dev_present_intf0
= true;
1936 ictx
->rx_urb_intf0
= rx_urb
;
1937 ictx
->tx_urb
= tx_urb
;
1938 ictx
->rf_device
= false;
1940 ictx
->vendor
= le16_to_cpu(ictx
->usbdev_intf0
->descriptor
.idVendor
);
1941 ictx
->product
= le16_to_cpu(ictx
->usbdev_intf0
->descriptor
.idProduct
);
1944 iface_desc
= intf
->cur_altsetting
;
1945 if (!imon_find_endpoints(ictx
, iface_desc
)) {
1946 goto find_endpoint_failed
;
1949 ictx
->idev
= imon_init_idev(ictx
);
1951 dev_err(dev
, "%s: input device setup failed\n", __func__
);
1952 goto idev_setup_failed
;
1955 ictx
->rdev
= imon_init_rdev(ictx
);
1957 dev_err(dev
, "%s: rc device setup failed\n", __func__
);
1958 goto rdev_setup_failed
;
1961 usb_fill_int_urb(ictx
->rx_urb_intf0
, ictx
->usbdev_intf0
,
1962 usb_rcvintpipe(ictx
->usbdev_intf0
,
1963 ictx
->rx_endpoint_intf0
->bEndpointAddress
),
1964 ictx
->usb_rx_buf
, sizeof(ictx
->usb_rx_buf
),
1965 usb_rx_callback_intf0
, ictx
,
1966 ictx
->rx_endpoint_intf0
->bInterval
);
1968 ret
= usb_submit_urb(ictx
->rx_urb_intf0
, GFP_KERNEL
);
1970 err("%s: usb_submit_urb failed for intf0 (%d)",
1972 goto urb_submit_failed
;
1978 ir_input_unregister(ictx
->rdev
);
1980 input_unregister_device(ictx
->idev
);
1982 find_endpoint_failed
:
1983 mutex_unlock(&ictx
->lock
);
1984 usb_free_urb(tx_urb
);
1985 tx_urb_alloc_failed
:
1986 usb_free_urb(rx_urb
);
1987 rx_urb_alloc_failed
:
1990 dev_err(dev
, "unable to initialize intf0, err %d\n", ret
);
1995 static struct imon_context
*imon_init_intf1(struct usb_interface
*intf
,
1996 struct imon_context
*ictx
)
1999 struct usb_host_interface
*iface_desc
;
2002 rx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
2004 err("%s: usb_alloc_urb failed for IR urb", __func__
);
2005 goto rx_urb_alloc_failed
;
2008 mutex_lock(&ictx
->lock
);
2010 if (ictx
->display_type
== IMON_DISPLAY_TYPE_VGA
) {
2011 init_timer(&ictx
->ttimer
);
2012 ictx
->ttimer
.data
= (unsigned long)ictx
;
2013 ictx
->ttimer
.function
= imon_touch_display_timeout
;
2016 ictx
->usbdev_intf1
= usb_get_dev(interface_to_usbdev(intf
));
2017 ictx
->dev_present_intf1
= true;
2018 ictx
->rx_urb_intf1
= rx_urb
;
2021 iface_desc
= intf
->cur_altsetting
;
2022 if (!imon_find_endpoints(ictx
, iface_desc
))
2023 goto find_endpoint_failed
;
2025 if (ictx
->display_type
== IMON_DISPLAY_TYPE_VGA
) {
2026 ictx
->touch
= imon_init_touch(ictx
);
2028 goto touch_setup_failed
;
2032 usb_fill_int_urb(ictx
->rx_urb_intf1
, ictx
->usbdev_intf1
,
2033 usb_rcvintpipe(ictx
->usbdev_intf1
,
2034 ictx
->rx_endpoint_intf1
->bEndpointAddress
),
2035 ictx
->usb_rx_buf
, sizeof(ictx
->usb_rx_buf
),
2036 usb_rx_callback_intf1
, ictx
,
2037 ictx
->rx_endpoint_intf1
->bInterval
);
2039 ret
= usb_submit_urb(ictx
->rx_urb_intf1
, GFP_KERNEL
);
2042 err("%s: usb_submit_urb failed for intf1 (%d)",
2044 goto urb_submit_failed
;
2051 input_unregister_device(ictx
->touch
);
2053 find_endpoint_failed
:
2054 mutex_unlock(&ictx
->lock
);
2055 usb_free_urb(rx_urb
);
2056 rx_urb_alloc_failed
:
2057 dev_err(ictx
->dev
, "unable to initialize intf0, err %d\n", ret
);
2063 * The 0x15c2:0xffdc device ID was used for umpteen different imon
2064 * devices, and all of them constantly spew interrupts, even when there
2065 * is no actual data to report. However, byte 6 of this buffer looks like
2066 * its unique across device variants, so we're trying to key off that to
2067 * figure out which display type (if any) and what IR protocol the device
2068 * actually supports. These devices have their IR protocol hard-coded into
2069 * their firmware, they can't be changed on the fly like the newer hardware.
2071 static void imon_get_ffdc_type(struct imon_context
*ictx
)
2073 u8 ffdc_cfg_byte
= ictx
->usb_rx_buf
[6];
2074 u8 detected_display_type
= IMON_DISPLAY_TYPE_NONE
;
2075 u64 allowed_protos
= IR_TYPE_OTHER
;
2077 switch (ffdc_cfg_byte
) {
2078 /* iMON Knob, no display, iMON IR + vol knob */
2080 dev_info(ictx
->dev
, "0xffdc iMON Knob, iMON IR");
2081 ictx
->display_supported
= false;
2083 /* iMON 2.4G LT (usb stick), no display, iMON RF */
2085 dev_info(ictx
->dev
, "0xffdc iMON 2.4G LT, iMON RF");
2086 ictx
->display_supported
= false;
2087 ictx
->rf_device
= true;
2089 /* iMON VFD, no IR (does have vol knob tho) */
2091 dev_info(ictx
->dev
, "0xffdc iMON VFD + knob, no IR");
2092 detected_display_type
= IMON_DISPLAY_TYPE_VFD
;
2094 /* iMON VFD, iMON IR */
2097 dev_info(ictx
->dev
, "0xffdc iMON VFD, iMON IR");
2098 detected_display_type
= IMON_DISPLAY_TYPE_VFD
;
2100 /* iMON LCD, MCE IR */
2103 dev_info(ictx
->dev
, "0xffdc iMON LCD, MCE IR");
2104 detected_display_type
= IMON_DISPLAY_TYPE_LCD
;
2105 allowed_protos
= IR_TYPE_RC6
;
2108 dev_info(ictx
->dev
, "Unknown 0xffdc device, "
2109 "defaulting to VFD and iMON IR");
2110 detected_display_type
= IMON_DISPLAY_TYPE_VFD
;
2114 printk(KERN_CONT
" (id 0x%02x)\n", ffdc_cfg_byte
);
2116 ictx
->display_type
= detected_display_type
;
2117 ictx
->props
->allowed_protos
= allowed_protos
;
2118 ictx
->ir_type
= allowed_protos
;
2121 static void imon_set_display_type(struct imon_context
*ictx
,
2122 struct usb_interface
*intf
)
2124 u8 configured_display_type
= IMON_DISPLAY_TYPE_VFD
;
2127 * Try to auto-detect the type of display if the user hasn't set
2128 * it by hand via the display_type modparam. Default is VFD.
2131 if (display_type
== IMON_DISPLAY_TYPE_AUTO
) {
2132 switch (ictx
->product
) {
2134 /* set in imon_get_ffdc_type() */
2135 configured_display_type
= ictx
->display_type
;
2139 configured_display_type
= IMON_DISPLAY_TYPE_VGA
;
2144 configured_display_type
= IMON_DISPLAY_TYPE_LCD
;
2150 configured_display_type
= IMON_DISPLAY_TYPE_NONE
;
2151 ictx
->display_supported
= false;
2156 configured_display_type
= IMON_DISPLAY_TYPE_VFD
;
2160 configured_display_type
= display_type
;
2161 if (display_type
== IMON_DISPLAY_TYPE_NONE
)
2162 ictx
->display_supported
= false;
2164 ictx
->display_supported
= true;
2165 dev_info(ictx
->dev
, "%s: overriding display type to %d via "
2166 "modparam\n", __func__
, display_type
);
2169 ictx
->display_type
= configured_display_type
;
2172 static void imon_init_display(struct imon_context
*ictx
,
2173 struct usb_interface
*intf
)
2177 dev_dbg(ictx
->dev
, "Registering iMON display with sysfs\n");
2179 /* set up sysfs entry for built-in clock */
2180 ret
= sysfs_create_group(&intf
->dev
.kobj
,
2181 &imon_display_attribute_group
);
2183 dev_err(ictx
->dev
, "Could not create display sysfs "
2184 "entries(%d)", ret
);
2186 if (ictx
->display_type
== IMON_DISPLAY_TYPE_LCD
)
2187 ret
= usb_register_dev(intf
, &imon_lcd_class
);
2189 ret
= usb_register_dev(intf
, &imon_vfd_class
);
2191 /* Not a fatal error, so ignore */
2192 dev_info(ictx
->dev
, "could not get a minor number for "
2198 * Callback function for USB core API: Probe
2200 static int __devinit
imon_probe(struct usb_interface
*interface
,
2201 const struct usb_device_id
*id
)
2203 struct usb_device
*usbdev
= NULL
;
2204 struct usb_host_interface
*iface_desc
= NULL
;
2205 struct usb_interface
*first_if
;
2206 struct device
*dev
= &interface
->dev
;
2207 int ifnum
, code_length
, sysfs_err
;
2209 struct imon_context
*ictx
= NULL
;
2210 struct imon_context
*first_if_ctx
= NULL
;
2211 u16 vendor
, product
;
2212 const unsigned char fp_packet
[] = { 0x40, 0x00, 0x00, 0x00,
2213 0x00, 0x00, 0x00, 0x88 };
2215 code_length
= BUF_CHUNK_SIZE
* 8;
2217 usbdev
= usb_get_dev(interface_to_usbdev(interface
));
2218 iface_desc
= interface
->cur_altsetting
;
2219 ifnum
= iface_desc
->desc
.bInterfaceNumber
;
2220 vendor
= le16_to_cpu(usbdev
->descriptor
.idVendor
);
2221 product
= le16_to_cpu(usbdev
->descriptor
.idProduct
);
2223 dev_dbg(dev
, "%s: found iMON device (%04x:%04x, intf%d)\n",
2224 __func__
, vendor
, product
, ifnum
);
2226 /* prevent races probing devices w/multiple interfaces */
2227 mutex_lock(&driver_lock
);
2229 first_if
= usb_ifnum_to_if(usbdev
, 0);
2230 first_if_ctx
= (struct imon_context
*)usb_get_intfdata(first_if
);
2233 ictx
= imon_init_intf0(interface
);
2235 err("%s: failed to initialize context!\n", __func__
);
2241 /* this is the secondary interface on the device */
2242 ictx
= imon_init_intf1(interface
, first_if_ctx
);
2244 err("%s: failed to attach to context!\n", __func__
);
2251 usb_set_intfdata(interface
, ictx
);
2254 /* Enable front-panel buttons and/or knobs */
2255 memcpy(ictx
->usb_tx_buf
, &fp_packet
, sizeof(fp_packet
));
2256 ret
= send_packet(ictx
);
2257 /* Not fatal, but warn about it */
2259 dev_info(dev
, "failed to enable panel buttons "
2262 if (product
== 0xffdc)
2263 imon_get_ffdc_type(ictx
);
2265 imon_set_display_type(ictx
, interface
);
2267 if (product
== 0xffdc && ictx
->rf_device
) {
2268 sysfs_err
= sysfs_create_group(&interface
->dev
.kobj
,
2269 &imon_rf_attribute_group
);
2271 err("%s: Could not create RF sysfs entries(%d)",
2272 __func__
, sysfs_err
);
2275 if (ictx
->display_supported
)
2276 imon_init_display(ictx
, interface
);
2279 /* set IR protocol/remote type */
2280 ret
= imon_ir_change_protocol(ictx
, ictx
->ir_type
);
2282 dev_warn(dev
, "%s: failed to set IR protocol, falling back "
2283 "to standard iMON protocol mode\n", __func__
);
2284 ictx
->ir_type
= IR_TYPE_OTHER
;
2287 dev_info(dev
, "iMON device (%04x:%04x, intf%d) on "
2288 "usb<%d:%d> initialized\n", vendor
, product
, ifnum
,
2289 usbdev
->bus
->busnum
, usbdev
->devnum
);
2291 mutex_unlock(&ictx
->lock
);
2292 mutex_unlock(&driver_lock
);
2297 mutex_unlock(&driver_lock
);
2298 dev_err(dev
, "unable to register, err %d\n", ret
);
2304 * Callback function for USB core API: disconnect
2306 static void __devexit
imon_disconnect(struct usb_interface
*interface
)
2308 struct imon_context
*ictx
;
2312 /* prevent races with multi-interface device probing and display_open */
2313 mutex_lock(&driver_lock
);
2315 ictx
= usb_get_intfdata(interface
);
2317 ifnum
= interface
->cur_altsetting
->desc
.bInterfaceNumber
;
2319 mutex_lock(&ictx
->lock
);
2322 * sysfs_remove_group is safe to call even if sysfs_create_group
2323 * hasn't been called
2325 sysfs_remove_group(&interface
->dev
.kobj
,
2326 &imon_display_attribute_group
);
2327 sysfs_remove_group(&interface
->dev
.kobj
,
2328 &imon_rf_attribute_group
);
2330 usb_set_intfdata(interface
, NULL
);
2332 /* Abort ongoing write */
2333 if (ictx
->tx
.busy
) {
2334 usb_kill_urb(ictx
->tx_urb
);
2335 complete_all(&ictx
->tx
.finished
);
2339 ictx
->dev_present_intf0
= false;
2340 usb_kill_urb(ictx
->rx_urb_intf0
);
2341 input_unregister_device(ictx
->idev
);
2342 ir_input_unregister(ictx
->rdev
);
2343 if (ictx
->display_supported
) {
2344 if (ictx
->display_type
== IMON_DISPLAY_TYPE_LCD
)
2345 usb_deregister_dev(interface
, &imon_lcd_class
);
2347 usb_deregister_dev(interface
, &imon_vfd_class
);
2350 ictx
->dev_present_intf1
= false;
2351 usb_kill_urb(ictx
->rx_urb_intf1
);
2352 if (ictx
->display_type
== IMON_DISPLAY_TYPE_VGA
)
2353 input_unregister_device(ictx
->touch
);
2356 if (!ictx
->dev_present_intf0
&& !ictx
->dev_present_intf1
) {
2357 if (ictx
->display_type
== IMON_DISPLAY_TYPE_VGA
)
2358 del_timer_sync(&ictx
->ttimer
);
2359 mutex_unlock(&ictx
->lock
);
2360 if (!ictx
->display_isopen
)
2361 free_imon_context(ictx
);
2363 mutex_unlock(&ictx
->lock
);
2365 mutex_unlock(&driver_lock
);
2367 dev_dbg(dev
, "%s: iMON device (intf%d) disconnected\n",
2371 static int imon_suspend(struct usb_interface
*intf
, pm_message_t message
)
2373 struct imon_context
*ictx
= usb_get_intfdata(intf
);
2374 int ifnum
= intf
->cur_altsetting
->desc
.bInterfaceNumber
;
2377 usb_kill_urb(ictx
->rx_urb_intf0
);
2379 usb_kill_urb(ictx
->rx_urb_intf1
);
2384 static int imon_resume(struct usb_interface
*intf
)
2387 struct imon_context
*ictx
= usb_get_intfdata(intf
);
2388 int ifnum
= intf
->cur_altsetting
->desc
.bInterfaceNumber
;
2391 usb_fill_int_urb(ictx
->rx_urb_intf0
, ictx
->usbdev_intf0
,
2392 usb_rcvintpipe(ictx
->usbdev_intf0
,
2393 ictx
->rx_endpoint_intf0
->bEndpointAddress
),
2394 ictx
->usb_rx_buf
, sizeof(ictx
->usb_rx_buf
),
2395 usb_rx_callback_intf0
, ictx
,
2396 ictx
->rx_endpoint_intf0
->bInterval
);
2398 rc
= usb_submit_urb(ictx
->rx_urb_intf0
, GFP_ATOMIC
);
2401 usb_fill_int_urb(ictx
->rx_urb_intf1
, ictx
->usbdev_intf1
,
2402 usb_rcvintpipe(ictx
->usbdev_intf1
,
2403 ictx
->rx_endpoint_intf1
->bEndpointAddress
),
2404 ictx
->usb_rx_buf
, sizeof(ictx
->usb_rx_buf
),
2405 usb_rx_callback_intf1
, ictx
,
2406 ictx
->rx_endpoint_intf1
->bInterval
);
2408 rc
= usb_submit_urb(ictx
->rx_urb_intf1
, GFP_ATOMIC
);
2414 static int __init
imon_init(void)
2418 rc
= usb_register(&imon_driver
);
2420 err("%s: usb register failed(%d)", __func__
, rc
);
2427 static void __exit
imon_exit(void)
2429 usb_deregister(&imon_driver
);
2432 module_init(imon_init
);
2433 module_exit(imon_exit
);