blob: 7b3f31cc63d250c5bc080533f3ee22339185a37d [file] [log] [blame]
Jarod Wilson21677cf2010-04-16 18:29:02 -03001/*
2 * imon.c: input and display driver for SoundGraph iMON IR/VFD/LCD
3 *
Jarod Wilson693508d2010-09-15 15:56:03 -03004 * Copyright(C) 2010 Jarod Wilson <jarod@wilsonet.com>
Jarod Wilson21677cf2010-04-16 18:29:02 -03005 * Portions based on the original lirc_imon driver,
6 * Copyright(C) 2004 Venky Raju(dev@venky.ws)
7 *
8 * Huge thanks to R. Geoff Newbury for invaluable debugging on the
9 * 0xffdc iMON devices, and for sending me one to hack on, without
10 * which the support for them wouldn't be nearly as good. Thanks
11 * also to the numerous 0xffdc device owners that tested auto-config
12 * support for me and provided debug dumps from their devices.
13 *
14 * imon is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
Jarod Wilson21677cf2010-04-16 18:29:02 -030023 */
24
Joe Perchese2302502010-06-20 04:20:46 -030025#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
26
Jarod Wilson21677cf2010-04-16 18:29:02 -030027#include <linux/errno.h>
28#include <linux/init.h>
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/slab.h>
32#include <linux/uaccess.h>
Jarod Wilson47a09b02011-07-14 14:20:46 -030033#include <linux/ratelimit.h>
Jarod Wilson21677cf2010-04-16 18:29:02 -030034
35#include <linux/input.h>
36#include <linux/usb.h>
37#include <linux/usb/input.h>
Mauro Carvalho Chehab6bda9642010-11-17 13:28:38 -030038#include <media/rc-core.h>
Jarod Wilson21677cf2010-04-16 18:29:02 -030039
40#include <linux/time.h>
41#include <linux/timer.h>
42
43#define MOD_AUTHOR "Jarod Wilson <jarod@wilsonet.com>"
44#define MOD_DESC "Driver for SoundGraph iMON MultiMedia IR/Display"
45#define MOD_NAME "imon"
Jarod Wilson8791d632012-01-26 12:04:11 -030046#define MOD_VERSION "0.9.4"
Jarod Wilson21677cf2010-04-16 18:29:02 -030047
48#define DISPLAY_MINOR_BASE 144
49#define DEVICE_NAME "lcd%d"
50
51#define BUF_CHUNK_SIZE 8
52#define BUF_SIZE 128
53
54#define BIT_DURATION 250 /* each bit received is 250us */
55
56#define IMON_CLOCK_ENABLE_PACKETS 2
Jarod Wilson21677cf2010-04-16 18:29:02 -030057
58/*** P R O T O T Y P E S ***/
59
60/* USB Callback prototypes */
61static int imon_probe(struct usb_interface *interface,
62 const struct usb_device_id *id);
63static void imon_disconnect(struct usb_interface *interface);
64static void usb_rx_callback_intf0(struct urb *urb);
65static void usb_rx_callback_intf1(struct urb *urb);
66static void usb_tx_callback(struct urb *urb);
67
68/* suspend/resume support */
69static int imon_resume(struct usb_interface *intf);
70static int imon_suspend(struct usb_interface *intf, pm_message_t message);
71
72/* Display file_operations function prototypes */
73static int display_open(struct inode *inode, struct file *file);
74static int display_close(struct inode *inode, struct file *file);
75
76/* VFD write operation */
David Härdemand6740d82014-04-03 20:34:53 -030077static ssize_t vfd_write(struct file *file, const char __user *buf,
Jarod Wilson21677cf2010-04-16 18:29:02 -030078 size_t n_bytes, loff_t *pos);
79
80/* LCD file_operations override function prototypes */
David Härdemand6740d82014-04-03 20:34:53 -030081static ssize_t lcd_write(struct file *file, const char __user *buf,
Jarod Wilson21677cf2010-04-16 18:29:02 -030082 size_t n_bytes, loff_t *pos);
83
84/*** G L O B A L S ***/
85
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -030086struct imon_panel_key_table {
87 u64 hw_code;
88 u32 keycode;
89};
90
91struct imon_usb_dev_descr {
92 __u16 flags;
93#define IMON_NO_FLAGS 0
94#define IMON_NEED_20MS_PKT_DELAY 1
Sean Youngf41003a2016-12-20 12:18:06 -020095#define IMON_IR_RAW 2
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -030096 struct imon_panel_key_table key_table[];
97};
98
Jarod Wilson21677cf2010-04-16 18:29:02 -030099struct imon_context {
100 struct device *dev;
Jarod Wilson21677cf2010-04-16 18:29:02 -0300101 /* Newer devices have two interfaces */
102 struct usb_device *usbdev_intf0;
103 struct usb_device *usbdev_intf1;
104
105 bool display_supported; /* not all controllers do */
106 bool display_isopen; /* display port has been opened */
Jarod Wilsonbbe46902010-05-24 12:02:05 -0300107 bool rf_device; /* true if iMON 2.4G LT/DT RF device */
Jarod Wilson21677cf2010-04-16 18:29:02 -0300108 bool rf_isassociating; /* RF remote associating */
109 bool dev_present_intf0; /* USB device presence, interface 0 */
110 bool dev_present_intf1; /* USB device presence, interface 1 */
111
112 struct mutex lock; /* to lock this object */
113 wait_queue_head_t remove_ok; /* For unexpected USB disconnects */
114
115 struct usb_endpoint_descriptor *rx_endpoint_intf0;
116 struct usb_endpoint_descriptor *rx_endpoint_intf1;
117 struct usb_endpoint_descriptor *tx_endpoint;
118 struct urb *rx_urb_intf0;
119 struct urb *rx_urb_intf1;
120 struct urb *tx_urb;
121 bool tx_control;
122 unsigned char usb_rx_buf[8];
123 unsigned char usb_tx_buf[8];
Kevin Baradon26ccbec2013-02-18 14:42:47 -0300124 unsigned int send_packet_delay;
Jarod Wilson21677cf2010-04-16 18:29:02 -0300125
Sean Youngf41003a2016-12-20 12:18:06 -0200126 struct rx_data {
127 int count; /* length of 0 or 1 sequence */
128 int prev_bit; /* logic level of sequence */
129 int initial_space; /* initial space flag */
130 } rx;
131
Jarod Wilson21677cf2010-04-16 18:29:02 -0300132 struct tx_t {
133 unsigned char data_buf[35]; /* user data buffer */
134 struct completion finished; /* wait for write to finish */
135 bool busy; /* write in progress */
136 int status; /* status of tx completion */
137 } tx;
138
139 u16 vendor; /* usb vendor ID */
140 u16 product; /* usb product ID */
141
David Härdemand8b4b582010-10-29 16:08:23 -0300142 struct rc_dev *rdev; /* rc-core device for remote */
David Härdemaneaf2bcc2010-09-15 15:42:07 -0300143 struct input_dev *idev; /* input device for panel & IR mouse */
Jarod Wilson21677cf2010-04-16 18:29:02 -0300144 struct input_dev *touch; /* input device for touchscreen */
145
Jarod Wilson693508d2010-09-15 15:56:03 -0300146 spinlock_t kc_lock; /* make sure we get keycodes right */
Jarod Wilson21677cf2010-04-16 18:29:02 -0300147 u32 kc; /* current input keycode */
148 u32 last_keycode; /* last reported input keycode */
David Härdemaneaf2bcc2010-09-15 15:42:07 -0300149 u32 rc_scancode; /* the computed remote scancode */
150 u8 rc_toggle; /* the computed remote toggle bit */
Sean Young6d741bf2017-08-07 16:20:58 -0400151 u64 rc_proto; /* iMON or MCE (RC6) IR protocol? */
Jarod Wilson21677cf2010-04-16 18:29:02 -0300152 bool release_code; /* some keys send a release code */
153
154 u8 display_type; /* store the display type */
155 bool pad_mouse; /* toggle kbd(0)/mouse(1) mode */
156
David Härdemaneaf2bcc2010-09-15 15:42:07 -0300157 char name_rdev[128]; /* rc input device name */
158 char phys_rdev[64]; /* rc input device phys path */
159
Jarod Wilson21677cf2010-04-16 18:29:02 -0300160 char name_idev[128]; /* input device name */
161 char phys_idev[64]; /* input device phys path */
Jarod Wilson21677cf2010-04-16 18:29:02 -0300162
163 char name_touch[128]; /* touch screen name */
164 char phys_touch[64]; /* touch screen phys path */
165 struct timer_list ttimer; /* touch screen timer */
166 int touch_x; /* x coordinate on touchscreen */
167 int touch_y; /* y coordinate on touchscreen */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300168 struct imon_usb_dev_descr *dev_descr; /* device description with key
169 table for front panels */
Jarod Wilson21677cf2010-04-16 18:29:02 -0300170};
171
172#define TOUCH_TIMEOUT (HZ/30)
Jarod Wilson21677cf2010-04-16 18:29:02 -0300173
174/* vfd character device file operations */
175static const struct file_operations vfd_fops = {
176 .owner = THIS_MODULE,
177 .open = &display_open,
178 .write = &vfd_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200179 .release = &display_close,
180 .llseek = noop_llseek,
Jarod Wilson21677cf2010-04-16 18:29:02 -0300181};
182
183/* lcd character device file operations */
184static const struct file_operations lcd_fops = {
185 .owner = THIS_MODULE,
186 .open = &display_open,
187 .write = &lcd_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200188 .release = &display_close,
189 .llseek = noop_llseek,
Jarod Wilson21677cf2010-04-16 18:29:02 -0300190};
191
192enum {
193 IMON_DISPLAY_TYPE_AUTO = 0,
194 IMON_DISPLAY_TYPE_VFD = 1,
195 IMON_DISPLAY_TYPE_LCD = 2,
196 IMON_DISPLAY_TYPE_VGA = 3,
197 IMON_DISPLAY_TYPE_NONE = 4,
198};
199
200enum {
Jarod Wilson21677cf2010-04-16 18:29:02 -0300201 IMON_KEY_IMON = 0,
202 IMON_KEY_MCE = 1,
203 IMON_KEY_PANEL = 2,
204};
205
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300206static struct usb_class_driver imon_vfd_class = {
207 .name = DEVICE_NAME,
208 .fops = &vfd_fops,
209 .minor_base = DISPLAY_MINOR_BASE,
210};
211
212static struct usb_class_driver imon_lcd_class = {
213 .name = DEVICE_NAME,
214 .fops = &lcd_fops,
215 .minor_base = DISPLAY_MINOR_BASE,
216};
217
218/* imon receiver front panel/knob key table */
219static const struct imon_usb_dev_descr imon_default_table = {
220 .flags = IMON_NO_FLAGS,
221 .key_table = {
222 { 0x000000000f00ffeell, KEY_MEDIA }, /* Go */
223 { 0x000000001200ffeell, KEY_UP },
224 { 0x000000001300ffeell, KEY_DOWN },
225 { 0x000000001400ffeell, KEY_LEFT },
226 { 0x000000001500ffeell, KEY_RIGHT },
227 { 0x000000001600ffeell, KEY_ENTER },
228 { 0x000000001700ffeell, KEY_ESC },
229 { 0x000000001f00ffeell, KEY_AUDIO },
230 { 0x000000002000ffeell, KEY_VIDEO },
231 { 0x000000002100ffeell, KEY_CAMERA },
232 { 0x000000002700ffeell, KEY_DVD },
233 { 0x000000002300ffeell, KEY_TV },
234 { 0x000000002b00ffeell, KEY_EXIT },
235 { 0x000000002c00ffeell, KEY_SELECT },
236 { 0x000000002d00ffeell, KEY_MENU },
237 { 0x000000000500ffeell, KEY_PREVIOUS },
238 { 0x000000000700ffeell, KEY_REWIND },
239 { 0x000000000400ffeell, KEY_STOP },
240 { 0x000000003c00ffeell, KEY_PLAYPAUSE },
241 { 0x000000000800ffeell, KEY_FASTFORWARD },
242 { 0x000000000600ffeell, KEY_NEXT },
243 { 0x000000010000ffeell, KEY_RIGHT },
244 { 0x000001000000ffeell, KEY_LEFT },
245 { 0x000000003d00ffeell, KEY_SELECT },
246 { 0x000100000000ffeell, KEY_VOLUMEUP },
247 { 0x010000000000ffeell, KEY_VOLUMEDOWN },
248 { 0x000000000100ffeell, KEY_MUTE },
249 /* 0xffdc iMON MCE VFD */
250 { 0x00010000ffffffeell, KEY_VOLUMEUP },
251 { 0x01000000ffffffeell, KEY_VOLUMEDOWN },
252 { 0x00000001ffffffeell, KEY_MUTE },
253 { 0x0000000fffffffeell, KEY_MEDIA },
254 { 0x00000012ffffffeell, KEY_UP },
255 { 0x00000013ffffffeell, KEY_DOWN },
256 { 0x00000014ffffffeell, KEY_LEFT },
257 { 0x00000015ffffffeell, KEY_RIGHT },
258 { 0x00000016ffffffeell, KEY_ENTER },
259 { 0x00000017ffffffeell, KEY_ESC },
260 /* iMON Knob values */
261 { 0x000100ffffffffeell, KEY_VOLUMEUP },
262 { 0x010000ffffffffeell, KEY_VOLUMEDOWN },
263 { 0x000008ffffffffeell, KEY_MUTE },
264 { 0, KEY_RESERVED },
265 }
266};
267
268static const struct imon_usb_dev_descr imon_OEM_VFD = {
269 .flags = IMON_NEED_20MS_PKT_DELAY,
270 .key_table = {
271 { 0x000000000f00ffeell, KEY_MEDIA }, /* Go */
272 { 0x000000001200ffeell, KEY_UP },
273 { 0x000000001300ffeell, KEY_DOWN },
274 { 0x000000001400ffeell, KEY_LEFT },
275 { 0x000000001500ffeell, KEY_RIGHT },
276 { 0x000000001600ffeell, KEY_ENTER },
277 { 0x000000001700ffeell, KEY_ESC },
278 { 0x000000001f00ffeell, KEY_AUDIO },
279 { 0x000000002b00ffeell, KEY_EXIT },
280 { 0x000000002c00ffeell, KEY_SELECT },
281 { 0x000000002d00ffeell, KEY_MENU },
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 /* 0xffdc iMON MCE VFD */
295 { 0x00010000ffffffeell, KEY_VOLUMEUP },
296 { 0x01000000ffffffeell, KEY_VOLUMEDOWN },
297 { 0x00000001ffffffeell, KEY_MUTE },
298 { 0x0000000fffffffeell, KEY_MEDIA },
299 { 0x00000012ffffffeell, KEY_UP },
300 { 0x00000013ffffffeell, KEY_DOWN },
301 { 0x00000014ffffffeell, KEY_LEFT },
302 { 0x00000015ffffffeell, KEY_RIGHT },
303 { 0x00000016ffffffeell, KEY_ENTER },
304 { 0x00000017ffffffeell, KEY_ESC },
305 /* iMON Knob values */
306 { 0x000100ffffffffeell, KEY_VOLUMEUP },
307 { 0x010000ffffffffeell, KEY_VOLUMEDOWN },
308 { 0x000008ffffffffeell, KEY_MUTE },
309 { 0, KEY_RESERVED },
310 }
Kevin Baradon26ccbec2013-02-18 14:42:47 -0300311};
312
Ulrich Eckhardt7b5fc072014-07-26 14:59:07 -0300313/* imon receiver front panel/knob key table for DH102*/
314static const struct imon_usb_dev_descr imon_DH102 = {
315 .flags = IMON_NO_FLAGS,
316 .key_table = {
317 { 0x000100000000ffeell, KEY_VOLUMEUP },
318 { 0x010000000000ffeell, KEY_VOLUMEDOWN },
319 { 0x000000010000ffeell, KEY_MUTE },
320 { 0x0000000f0000ffeell, KEY_MEDIA },
321 { 0x000000120000ffeell, KEY_UP },
322 { 0x000000130000ffeell, KEY_DOWN },
323 { 0x000000140000ffeell, KEY_LEFT },
324 { 0x000000150000ffeell, KEY_RIGHT },
325 { 0x000000160000ffeell, KEY_ENTER },
326 { 0x000000170000ffeell, KEY_ESC },
327 { 0x0000002b0000ffeell, KEY_EXIT },
328 { 0x0000002c0000ffeell, KEY_SELECT },
329 { 0x0000002d0000ffeell, KEY_MENU },
330 { 0, KEY_RESERVED }
331 }
332};
333
Sean Youngf41003a2016-12-20 12:18:06 -0200334static const struct imon_usb_dev_descr imon_ir_raw = {
335 .flags = IMON_IR_RAW,
336};
337
Jarod Wilson21677cf2010-04-16 18:29:02 -0300338/*
339 * USB Device ID for iMON USB Control Boards
340 *
341 * The Windows drivers contain 6 different inf files, more or less one for
342 * each new device until the 0x0034-0x0046 devices, which all use the same
343 * driver. Some of the devices in the 34-46 range haven't been definitively
344 * identified yet. Early devices have either a TriGem Computer, Inc. or a
345 * Samsung vendor ID (0x0aa8 and 0x04e8 respectively), while all later
346 * devices use the SoundGraph vendor ID (0x15c2). This driver only supports
347 * the ffdc and later devices, which do onboard decoding.
348 */
349static struct usb_device_id imon_usb_id_table[] = {
350 /*
351 * Several devices with this same device ID, all use iMON_PAD.inf
352 * SoundGraph iMON PAD (IR & VFD)
353 * SoundGraph iMON PAD (IR & LCD)
354 * SoundGraph iMON Knob (IR only)
355 */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300356 { USB_DEVICE(0x15c2, 0xffdc),
357 .driver_info = (unsigned long)&imon_default_table },
Jarod Wilson21677cf2010-04-16 18:29:02 -0300358
359 /*
360 * Newer devices, all driven by the latest iMON Windows driver, full
361 * list of device IDs extracted via 'strings Setup/data1.hdr |grep 15c2'
362 * Need user input to fill in details on unknown devices.
363 */
364 /* SoundGraph iMON OEM Touch LCD (IR & 7" VGA LCD) */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300365 { USB_DEVICE(0x15c2, 0x0034),
Ulrich Eckhardt7b5fc072014-07-26 14:59:07 -0300366 .driver_info = (unsigned long)&imon_DH102 },
Jarod Wilson21677cf2010-04-16 18:29:02 -0300367 /* SoundGraph iMON OEM Touch LCD (IR & 4.3" VGA LCD) */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300368 { USB_DEVICE(0x15c2, 0x0035),
369 .driver_info = (unsigned long)&imon_default_table},
Jarod Wilson21677cf2010-04-16 18:29:02 -0300370 /* SoundGraph iMON OEM VFD (IR & VFD) */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300371 { USB_DEVICE(0x15c2, 0x0036),
372 .driver_info = (unsigned long)&imon_OEM_VFD },
Jarod Wilson21677cf2010-04-16 18:29:02 -0300373 /* device specifics unknown */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300374 { USB_DEVICE(0x15c2, 0x0037),
375 .driver_info = (unsigned long)&imon_default_table},
Jarod Wilson21677cf2010-04-16 18:29:02 -0300376 /* SoundGraph iMON OEM LCD (IR & LCD) */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300377 { USB_DEVICE(0x15c2, 0x0038),
378 .driver_info = (unsigned long)&imon_default_table},
Jarod Wilson21677cf2010-04-16 18:29:02 -0300379 /* SoundGraph iMON UltraBay (IR & LCD) */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300380 { USB_DEVICE(0x15c2, 0x0039),
381 .driver_info = (unsigned long)&imon_default_table},
Jarod Wilson21677cf2010-04-16 18:29:02 -0300382 /* device specifics unknown */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300383 { USB_DEVICE(0x15c2, 0x003a),
384 .driver_info = (unsigned long)&imon_default_table},
Jarod Wilson21677cf2010-04-16 18:29:02 -0300385 /* device specifics unknown */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300386 { USB_DEVICE(0x15c2, 0x003b),
387 .driver_info = (unsigned long)&imon_default_table},
Jarod Wilson21677cf2010-04-16 18:29:02 -0300388 /* SoundGraph iMON OEM Inside (IR only) */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300389 { USB_DEVICE(0x15c2, 0x003c),
390 .driver_info = (unsigned long)&imon_default_table},
Jarod Wilson21677cf2010-04-16 18:29:02 -0300391 /* device specifics unknown */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300392 { USB_DEVICE(0x15c2, 0x003d),
393 .driver_info = (unsigned long)&imon_default_table},
Jarod Wilson21677cf2010-04-16 18:29:02 -0300394 /* device specifics unknown */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300395 { USB_DEVICE(0x15c2, 0x003e),
396 .driver_info = (unsigned long)&imon_default_table},
Jarod Wilson21677cf2010-04-16 18:29:02 -0300397 /* device specifics unknown */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300398 { USB_DEVICE(0x15c2, 0x003f),
399 .driver_info = (unsigned long)&imon_default_table},
Jarod Wilson21677cf2010-04-16 18:29:02 -0300400 /* device specifics unknown */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300401 { USB_DEVICE(0x15c2, 0x0040),
402 .driver_info = (unsigned long)&imon_default_table},
Jarod Wilson21677cf2010-04-16 18:29:02 -0300403 /* SoundGraph iMON MINI (IR only) */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300404 { USB_DEVICE(0x15c2, 0x0041),
405 .driver_info = (unsigned long)&imon_default_table},
Jarod Wilson21677cf2010-04-16 18:29:02 -0300406 /* Antec Veris Multimedia Station EZ External (IR only) */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300407 { USB_DEVICE(0x15c2, 0x0042),
408 .driver_info = (unsigned long)&imon_default_table},
Jarod Wilson21677cf2010-04-16 18:29:02 -0300409 /* Antec Veris Multimedia Station Basic Internal (IR only) */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300410 { USB_DEVICE(0x15c2, 0x0043),
411 .driver_info = (unsigned long)&imon_default_table},
Jarod Wilson21677cf2010-04-16 18:29:02 -0300412 /* Antec Veris Multimedia Station Elite (IR & VFD) */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300413 { USB_DEVICE(0x15c2, 0x0044),
414 .driver_info = (unsigned long)&imon_default_table},
Jarod Wilson21677cf2010-04-16 18:29:02 -0300415 /* Antec Veris Multimedia Station Premiere (IR & LCD) */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300416 { USB_DEVICE(0x15c2, 0x0045),
417 .driver_info = (unsigned long)&imon_default_table},
Jarod Wilson21677cf2010-04-16 18:29:02 -0300418 /* device specifics unknown */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -0300419 { USB_DEVICE(0x15c2, 0x0046),
420 .driver_info = (unsigned long)&imon_default_table},
Sean Youngf41003a2016-12-20 12:18:06 -0200421 /* TriGem iMON (IR only) -- TG_iMON.inf */
422 { USB_DEVICE(0x0aa8, 0x8001),
423 .driver_info = (unsigned long)&imon_ir_raw},
424 /* SoundGraph iMON (IR only) -- sg_imon.inf */
425 { USB_DEVICE(0x04e8, 0xff30),
426 .driver_info = (unsigned long)&imon_ir_raw},
427 /* SoundGraph iMON VFD (IR & VFD) -- iMON_VFD.inf */
428 { USB_DEVICE(0x0aa8, 0xffda),
429 .driver_info = (unsigned long)&imon_ir_raw},
430 /* SoundGraph iMON SS (IR & VFD) -- iMON_SS.inf */
431 { USB_DEVICE(0x15c2, 0xffda),
432 .driver_info = (unsigned long)&imon_ir_raw},
Jarod Wilson21677cf2010-04-16 18:29:02 -0300433 {}
434};
435
436/* USB Device data */
437static struct usb_driver imon_driver = {
438 .name = MOD_NAME,
439 .probe = imon_probe,
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -0800440 .disconnect = imon_disconnect,
Jarod Wilson21677cf2010-04-16 18:29:02 -0300441 .suspend = imon_suspend,
442 .resume = imon_resume,
443 .id_table = imon_usb_id_table,
444};
445
Jarod Wilson21677cf2010-04-16 18:29:02 -0300446/* to prevent races between open() and disconnect(), probing, etc */
447static DEFINE_MUTEX(driver_lock);
448
449/* Module bookkeeping bits */
450MODULE_AUTHOR(MOD_AUTHOR);
451MODULE_DESCRIPTION(MOD_DESC);
452MODULE_VERSION(MOD_VERSION);
453MODULE_LICENSE("GPL");
454MODULE_DEVICE_TABLE(usb, imon_usb_id_table);
455
456static bool debug;
457module_param(debug, bool, S_IRUGO | S_IWUSR);
Jarod Wilson6aa209e2010-10-23 16:42:51 -0300458MODULE_PARM_DESC(debug, "Debug messages: 0=no, 1=yes (default: no)");
Jarod Wilson21677cf2010-04-16 18:29:02 -0300459
460/* lcd, vfd, vga or none? should be auto-detected, but can be overridden... */
461static int display_type;
462module_param(display_type, int, S_IRUGO);
Mauro Carvalho Chehab25ec5872016-10-18 17:44:25 -0200463MODULE_PARM_DESC(display_type, "Type of attached display. 0=autodetect, 1=vfd, 2=lcd, 3=vga, 4=none (default: autodetect)");
Jarod Wilson21677cf2010-04-16 18:29:02 -0300464
Jarod Wilson6718e8a2010-04-23 02:27:11 -0300465static int pad_stabilize = 1;
466module_param(pad_stabilize, int, S_IRUGO | S_IWUSR);
Mauro Carvalho Chehab25ec5872016-10-18 17:44:25 -0200467MODULE_PARM_DESC(pad_stabilize, "Apply stabilization algorithm to iMON PAD presses in arrow key mode. 0=disable, 1=enable (default).");
Jarod Wilson21677cf2010-04-16 18:29:02 -0300468
469/*
470 * In certain use cases, mouse mode isn't really helpful, and could actually
471 * cause confusion, so allow disabling it when the IR device is open.
472 */
473static bool nomouse;
474module_param(nomouse, bool, S_IRUGO | S_IWUSR);
Mauro Carvalho Chehab25ec5872016-10-18 17:44:25 -0200475MODULE_PARM_DESC(nomouse, "Disable mouse input device mode when IR device is open. 0=don't disable, 1=disable. (default: don't disable)");
Jarod Wilson21677cf2010-04-16 18:29:02 -0300476
477/* threshold at which a pad push registers as an arrow key in kbd mode */
478static int pad_thresh;
479module_param(pad_thresh, int, S_IRUGO | S_IWUSR);
Mauro Carvalho Chehab25ec5872016-10-18 17:44:25 -0200480MODULE_PARM_DESC(pad_thresh, "Threshold at which a pad push registers as an arrow key in kbd mode (default: 28)");
Jarod Wilson21677cf2010-04-16 18:29:02 -0300481
482
483static void free_imon_context(struct imon_context *ictx)
484{
485 struct device *dev = ictx->dev;
486
487 usb_free_urb(ictx->tx_urb);
488 usb_free_urb(ictx->rx_urb_intf0);
489 usb_free_urb(ictx->rx_urb_intf1);
490 kfree(ictx);
491
492 dev_dbg(dev, "%s: iMON context freed\n", __func__);
493}
494
495/**
496 * Called when the Display device (e.g. /dev/lcd0)
497 * is opened by the application.
498 */
499static int display_open(struct inode *inode, struct file *file)
500{
501 struct usb_interface *interface;
502 struct imon_context *ictx = NULL;
503 int subminor;
504 int retval = 0;
505
506 /* prevent races with disconnect */
507 mutex_lock(&driver_lock);
508
509 subminor = iminor(inode);
510 interface = usb_find_interface(&imon_driver, subminor);
511 if (!interface) {
Joe Perchese2302502010-06-20 04:20:46 -0300512 pr_err("could not find interface for minor %d\n", subminor);
Jarod Wilson21677cf2010-04-16 18:29:02 -0300513 retval = -ENODEV;
514 goto exit;
515 }
516 ictx = usb_get_intfdata(interface);
517
518 if (!ictx) {
Joe Perchese2302502010-06-20 04:20:46 -0300519 pr_err("no context found for minor %d\n", subminor);
Jarod Wilson21677cf2010-04-16 18:29:02 -0300520 retval = -ENODEV;
521 goto exit;
522 }
523
524 mutex_lock(&ictx->lock);
525
526 if (!ictx->display_supported) {
Joe Perchese2302502010-06-20 04:20:46 -0300527 pr_err("display not supported by device\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -0300528 retval = -ENODEV;
529 } else if (ictx->display_isopen) {
Joe Perchese2302502010-06-20 04:20:46 -0300530 pr_err("display port is already open\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -0300531 retval = -EBUSY;
532 } else {
Jarod Wilsonf789bf42010-05-24 12:00:31 -0300533 ictx->display_isopen = true;
Jarod Wilson21677cf2010-04-16 18:29:02 -0300534 file->private_data = ictx;
535 dev_dbg(ictx->dev, "display port opened\n");
536 }
537
538 mutex_unlock(&ictx->lock);
539
540exit:
541 mutex_unlock(&driver_lock);
542 return retval;
543}
544
545/**
546 * Called when the display device (e.g. /dev/lcd0)
547 * is closed by the application.
548 */
549static int display_close(struct inode *inode, struct file *file)
550{
551 struct imon_context *ictx = NULL;
552 int retval = 0;
553
Joe Perchesabf84382010-07-12 17:50:03 -0300554 ictx = file->private_data;
Jarod Wilson21677cf2010-04-16 18:29:02 -0300555
556 if (!ictx) {
Joe Perchese2302502010-06-20 04:20:46 -0300557 pr_err("no context for device\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -0300558 return -ENODEV;
559 }
560
561 mutex_lock(&ictx->lock);
562
563 if (!ictx->display_supported) {
Joe Perchese2302502010-06-20 04:20:46 -0300564 pr_err("display not supported by device\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -0300565 retval = -ENODEV;
566 } else if (!ictx->display_isopen) {
Joe Perchese2302502010-06-20 04:20:46 -0300567 pr_err("display is not open\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -0300568 retval = -EIO;
569 } else {
Jarod Wilsonf789bf42010-05-24 12:00:31 -0300570 ictx->display_isopen = false;
Jarod Wilson21677cf2010-04-16 18:29:02 -0300571 dev_dbg(ictx->dev, "display port closed\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -0300572 }
573
574 mutex_unlock(&ictx->lock);
575 return retval;
576}
577
578/**
Jarod Wilson23ef7102011-04-27 19:01:44 -0300579 * Sends a packet to the device -- this function must be called with
580 * ictx->lock held, or its unlock/lock sequence while waiting for tx
581 * to complete can/will lead to a deadlock.
Jarod Wilson21677cf2010-04-16 18:29:02 -0300582 */
583static int send_packet(struct imon_context *ictx)
584{
585 unsigned int pipe;
586 unsigned long timeout;
587 int interval = 0;
588 int retval = 0;
589 struct usb_ctrlrequest *control_req = NULL;
590
591 /* Check if we need to use control or interrupt urb */
592 if (!ictx->tx_control) {
593 pipe = usb_sndintpipe(ictx->usbdev_intf0,
594 ictx->tx_endpoint->bEndpointAddress);
595 interval = ictx->tx_endpoint->bInterval;
596
597 usb_fill_int_urb(ictx->tx_urb, ictx->usbdev_intf0, pipe,
598 ictx->usb_tx_buf,
599 sizeof(ictx->usb_tx_buf),
600 usb_tx_callback, ictx, interval);
601
602 ictx->tx_urb->actual_length = 0;
603 } else {
604 /* fill request into kmalloc'ed space: */
605 control_req = kmalloc(sizeof(struct usb_ctrlrequest),
606 GFP_KERNEL);
607 if (control_req == NULL)
608 return -ENOMEM;
609
610 /* setup packet is '21 09 0200 0001 0008' */
611 control_req->bRequestType = 0x21;
612 control_req->bRequest = 0x09;
613 control_req->wValue = cpu_to_le16(0x0200);
614 control_req->wIndex = cpu_to_le16(0x0001);
615 control_req->wLength = cpu_to_le16(0x0008);
616
617 /* control pipe is endpoint 0x00 */
618 pipe = usb_sndctrlpipe(ictx->usbdev_intf0, 0);
619
620 /* build the control urb */
621 usb_fill_control_urb(ictx->tx_urb, ictx->usbdev_intf0,
622 pipe, (unsigned char *)control_req,
623 ictx->usb_tx_buf,
624 sizeof(ictx->usb_tx_buf),
625 usb_tx_callback, ictx);
626 ictx->tx_urb->actual_length = 0;
627 }
628
Daniel Wagner7c073ff2016-09-16 08:18:21 -0300629 reinit_completion(&ictx->tx.finished);
Jarod Wilsonf789bf42010-05-24 12:00:31 -0300630 ictx->tx.busy = true;
Jarod Wilson21677cf2010-04-16 18:29:02 -0300631 smp_rmb(); /* ensure later readers know we're busy */
632
633 retval = usb_submit_urb(ictx->tx_urb, GFP_KERNEL);
634 if (retval) {
Jarod Wilsonf789bf42010-05-24 12:00:31 -0300635 ictx->tx.busy = false;
Jarod Wilson21677cf2010-04-16 18:29:02 -0300636 smp_rmb(); /* ensure later readers know we're not busy */
Jarod Wilson47a09b02011-07-14 14:20:46 -0300637 pr_err_ratelimited("error submitting urb(%d)\n", retval);
Jarod Wilson21677cf2010-04-16 18:29:02 -0300638 } else {
639 /* Wait for transmission to complete (or abort) */
640 mutex_unlock(&ictx->lock);
641 retval = wait_for_completion_interruptible(
642 &ictx->tx.finished);
Kevin Baradon5f3f2542013-04-22 16:09:46 -0300643 if (retval) {
644 usb_kill_urb(ictx->tx_urb);
Jarod Wilson47a09b02011-07-14 14:20:46 -0300645 pr_err_ratelimited("task interrupted\n");
Kevin Baradon5f3f2542013-04-22 16:09:46 -0300646 }
Jarod Wilson21677cf2010-04-16 18:29:02 -0300647 mutex_lock(&ictx->lock);
648
649 retval = ictx->tx.status;
650 if (retval)
Jarod Wilson47a09b02011-07-14 14:20:46 -0300651 pr_err_ratelimited("packet tx failed (%d)\n", retval);
Jarod Wilson21677cf2010-04-16 18:29:02 -0300652 }
653
654 kfree(control_req);
655
656 /*
Kevin Baradon26ccbec2013-02-18 14:42:47 -0300657 * Induce a mandatory delay before returning, as otherwise,
Jarod Wilson21677cf2010-04-16 18:29:02 -0300658 * send_packet can get called so rapidly as to overwhelm the device,
659 * particularly on faster systems and/or those with quirky usb.
660 */
Kevin Baradon26ccbec2013-02-18 14:42:47 -0300661 timeout = msecs_to_jiffies(ictx->send_packet_delay);
662 set_current_state(TASK_INTERRUPTIBLE);
Jarod Wilson21677cf2010-04-16 18:29:02 -0300663 schedule_timeout(timeout);
664
665 return retval;
666}
667
668/**
669 * Sends an associate packet to the iMON 2.4G.
670 *
671 * This might not be such a good idea, since it has an id collision with
672 * some versions of the "IR & VFD" combo. The only way to determine if it
673 * is an RF version is to look at the product description string. (Which
674 * we currently do not fetch).
675 */
676static int send_associate_24g(struct imon_context *ictx)
677{
678 int retval;
679 const unsigned char packet[8] = { 0x01, 0x00, 0x00, 0x00,
680 0x00, 0x00, 0x00, 0x20 };
681
682 if (!ictx) {
Joe Perchese2302502010-06-20 04:20:46 -0300683 pr_err("no context for device\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -0300684 return -ENODEV;
685 }
686
687 if (!ictx->dev_present_intf0) {
Joe Perchese2302502010-06-20 04:20:46 -0300688 pr_err("no iMON device present\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -0300689 return -ENODEV;
690 }
691
692 memcpy(ictx->usb_tx_buf, packet, sizeof(packet));
693 retval = send_packet(ictx);
694
695 return retval;
696}
697
698/**
699 * Sends packets to setup and show clock on iMON display
700 *
701 * Arguments: year - last 2 digits of year, month - 1..12,
702 * day - 1..31, dow - day of the week (0-Sun...6-Sat),
703 * hour - 0..23, minute - 0..59, second - 0..59
704 */
705static int send_set_imon_clock(struct imon_context *ictx,
706 unsigned int year, unsigned int month,
707 unsigned int day, unsigned int dow,
708 unsigned int hour, unsigned int minute,
709 unsigned int second)
710{
711 unsigned char clock_enable_pkt[IMON_CLOCK_ENABLE_PACKETS][8];
712 int retval = 0;
713 int i;
714
715 if (!ictx) {
Joe Perchese2302502010-06-20 04:20:46 -0300716 pr_err("no context for device\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -0300717 return -ENODEV;
718 }
719
720 switch (ictx->display_type) {
721 case IMON_DISPLAY_TYPE_LCD:
722 clock_enable_pkt[0][0] = 0x80;
723 clock_enable_pkt[0][1] = year;
724 clock_enable_pkt[0][2] = month-1;
725 clock_enable_pkt[0][3] = day;
726 clock_enable_pkt[0][4] = hour;
727 clock_enable_pkt[0][5] = minute;
728 clock_enable_pkt[0][6] = second;
729
730 clock_enable_pkt[1][0] = 0x80;
731 clock_enable_pkt[1][1] = 0;
732 clock_enable_pkt[1][2] = 0;
733 clock_enable_pkt[1][3] = 0;
734 clock_enable_pkt[1][4] = 0;
735 clock_enable_pkt[1][5] = 0;
736 clock_enable_pkt[1][6] = 0;
737
738 if (ictx->product == 0xffdc) {
739 clock_enable_pkt[0][7] = 0x50;
740 clock_enable_pkt[1][7] = 0x51;
741 } else {
742 clock_enable_pkt[0][7] = 0x88;
743 clock_enable_pkt[1][7] = 0x8a;
744 }
745
746 break;
747
748 case IMON_DISPLAY_TYPE_VFD:
749 clock_enable_pkt[0][0] = year;
750 clock_enable_pkt[0][1] = month-1;
751 clock_enable_pkt[0][2] = day;
752 clock_enable_pkt[0][3] = dow;
753 clock_enable_pkt[0][4] = hour;
754 clock_enable_pkt[0][5] = minute;
755 clock_enable_pkt[0][6] = second;
756 clock_enable_pkt[0][7] = 0x40;
757
758 clock_enable_pkt[1][0] = 0;
759 clock_enable_pkt[1][1] = 0;
760 clock_enable_pkt[1][2] = 1;
761 clock_enable_pkt[1][3] = 0;
762 clock_enable_pkt[1][4] = 0;
763 clock_enable_pkt[1][5] = 0;
764 clock_enable_pkt[1][6] = 0;
765 clock_enable_pkt[1][7] = 0x42;
766
767 break;
768
769 default:
770 return -ENODEV;
771 }
772
773 for (i = 0; i < IMON_CLOCK_ENABLE_PACKETS; i++) {
774 memcpy(ictx->usb_tx_buf, clock_enable_pkt[i], 8);
775 retval = send_packet(ictx);
776 if (retval) {
Joe Perchese2302502010-06-20 04:20:46 -0300777 pr_err("send_packet failed for packet %d\n", i);
Jarod Wilson21677cf2010-04-16 18:29:02 -0300778 break;
779 }
780 }
781
782 return retval;
783}
784
785/**
786 * These are the sysfs functions to handle the association on the iMON 2.4G LT.
787 */
788static ssize_t show_associate_remote(struct device *d,
789 struct device_attribute *attr,
790 char *buf)
791{
792 struct imon_context *ictx = dev_get_drvdata(d);
793
794 if (!ictx)
795 return -ENODEV;
796
797 mutex_lock(&ictx->lock);
798 if (ictx->rf_isassociating)
799 strcpy(buf, "associating\n");
800 else
801 strcpy(buf, "closed\n");
802
Mauro Carvalho Chehab25ec5872016-10-18 17:44:25 -0200803 dev_info(d, "Visit http://www.lirc.org/html/imon-24g.html for instructions on how to associate your iMON 2.4G DT/LT remote\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -0300804 mutex_unlock(&ictx->lock);
805 return strlen(buf);
806}
807
808static ssize_t store_associate_remote(struct device *d,
809 struct device_attribute *attr,
810 const char *buf, size_t count)
811{
812 struct imon_context *ictx;
813
814 ictx = dev_get_drvdata(d);
815
816 if (!ictx)
817 return -ENODEV;
818
819 mutex_lock(&ictx->lock);
Jarod Wilsonf789bf42010-05-24 12:00:31 -0300820 ictx->rf_isassociating = true;
Jarod Wilson21677cf2010-04-16 18:29:02 -0300821 send_associate_24g(ictx);
822 mutex_unlock(&ictx->lock);
823
824 return count;
825}
826
827/**
828 * sysfs functions to control internal imon clock
829 */
830static ssize_t show_imon_clock(struct device *d,
831 struct device_attribute *attr, char *buf)
832{
833 struct imon_context *ictx = dev_get_drvdata(d);
834 size_t len;
835
836 if (!ictx)
837 return -ENODEV;
838
839 mutex_lock(&ictx->lock);
840
841 if (!ictx->display_supported) {
842 len = snprintf(buf, PAGE_SIZE, "Not supported.");
843 } else {
844 len = snprintf(buf, PAGE_SIZE,
845 "To set the clock on your iMON display:\n"
846 "# date \"+%%y %%m %%d %%w %%H %%M %%S\" > imon_clock\n"
847 "%s", ictx->display_isopen ?
848 "\nNOTE: imon device must be closed\n" : "");
849 }
850
851 mutex_unlock(&ictx->lock);
852
853 return len;
854}
855
856static ssize_t store_imon_clock(struct device *d,
857 struct device_attribute *attr,
858 const char *buf, size_t count)
859{
860 struct imon_context *ictx = dev_get_drvdata(d);
861 ssize_t retval;
862 unsigned int year, month, day, dow, hour, minute, second;
863
864 if (!ictx)
865 return -ENODEV;
866
867 mutex_lock(&ictx->lock);
868
869 if (!ictx->display_supported) {
870 retval = -ENODEV;
871 goto exit;
872 } else if (ictx->display_isopen) {
873 retval = -EBUSY;
874 goto exit;
875 }
876
877 if (sscanf(buf, "%u %u %u %u %u %u %u", &year, &month, &day, &dow,
878 &hour, &minute, &second) != 7) {
879 retval = -EINVAL;
880 goto exit;
881 }
882
883 if ((month < 1 || month > 12) ||
884 (day < 1 || day > 31) || (dow > 6) ||
885 (hour > 23) || (minute > 59) || (second > 59)) {
886 retval = -EINVAL;
887 goto exit;
888 }
889
890 retval = send_set_imon_clock(ictx, year, month, day, dow,
891 hour, minute, second);
892 if (retval)
893 goto exit;
894
895 retval = count;
896exit:
897 mutex_unlock(&ictx->lock);
898
899 return retval;
900}
901
902
903static DEVICE_ATTR(imon_clock, S_IWUSR | S_IRUGO, show_imon_clock,
904 store_imon_clock);
905
906static DEVICE_ATTR(associate_remote, S_IWUSR | S_IRUGO, show_associate_remote,
907 store_associate_remote);
908
909static struct attribute *imon_display_sysfs_entries[] = {
910 &dev_attr_imon_clock.attr,
911 NULL
912};
913
Arvind Yadavd9a77b92017-07-07 04:15:12 -0400914static const struct attribute_group imon_display_attr_group = {
Jarod Wilson21677cf2010-04-16 18:29:02 -0300915 .attrs = imon_display_sysfs_entries
916};
917
918static struct attribute *imon_rf_sysfs_entries[] = {
919 &dev_attr_associate_remote.attr,
920 NULL
921};
922
Arvind Yadavd9a77b92017-07-07 04:15:12 -0400923static const struct attribute_group imon_rf_attr_group = {
Jarod Wilson21677cf2010-04-16 18:29:02 -0300924 .attrs = imon_rf_sysfs_entries
925};
926
927/**
928 * Writes data to the VFD. The iMON VFD is 2x16 characters
929 * and requires data in 5 consecutive USB interrupt packets,
930 * each packet but the last carrying 7 bytes.
931 *
932 * I don't know if the VFD board supports features such as
933 * scrolling, clearing rows, blanking, etc. so at
934 * the caller must provide a full screen of data. If fewer
935 * than 32 bytes are provided spaces will be appended to
936 * generate a full screen.
937 */
David Härdemand6740d82014-04-03 20:34:53 -0300938static ssize_t vfd_write(struct file *file, const char __user *buf,
Jarod Wilson21677cf2010-04-16 18:29:02 -0300939 size_t n_bytes, loff_t *pos)
940{
941 int i;
942 int offset;
943 int seq;
944 int retval = 0;
945 struct imon_context *ictx;
946 const unsigned char vfd_packet6[] = {
947 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF };
948
Joe Perchesabf84382010-07-12 17:50:03 -0300949 ictx = file->private_data;
Jarod Wilson21677cf2010-04-16 18:29:02 -0300950 if (!ictx) {
Jarod Wilson47a09b02011-07-14 14:20:46 -0300951 pr_err_ratelimited("no context for device\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -0300952 return -ENODEV;
953 }
954
955 mutex_lock(&ictx->lock);
956
957 if (!ictx->dev_present_intf0) {
Jarod Wilson47a09b02011-07-14 14:20:46 -0300958 pr_err_ratelimited("no iMON device present\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -0300959 retval = -ENODEV;
960 goto exit;
961 }
962
963 if (n_bytes <= 0 || n_bytes > 32) {
Jarod Wilson47a09b02011-07-14 14:20:46 -0300964 pr_err_ratelimited("invalid payload size\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -0300965 retval = -EINVAL;
966 goto exit;
967 }
968
969 if (copy_from_user(ictx->tx.data_buf, buf, n_bytes)) {
970 retval = -EFAULT;
971 goto exit;
972 }
973
974 /* Pad with spaces */
975 for (i = n_bytes; i < 32; ++i)
976 ictx->tx.data_buf[i] = ' ';
977
978 for (i = 32; i < 35; ++i)
979 ictx->tx.data_buf[i] = 0xFF;
980
981 offset = 0;
982 seq = 0;
983
984 do {
985 memcpy(ictx->usb_tx_buf, ictx->tx.data_buf + offset, 7);
986 ictx->usb_tx_buf[7] = (unsigned char) seq;
987
988 retval = send_packet(ictx);
989 if (retval) {
Jarod Wilson47a09b02011-07-14 14:20:46 -0300990 pr_err_ratelimited("send packet #%d failed\n", seq / 2);
Jarod Wilson21677cf2010-04-16 18:29:02 -0300991 goto exit;
992 } else {
993 seq += 2;
994 offset += 7;
995 }
996
997 } while (offset < 35);
998
999 /* Send packet #6 */
1000 memcpy(ictx->usb_tx_buf, &vfd_packet6, sizeof(vfd_packet6));
1001 ictx->usb_tx_buf[7] = (unsigned char) seq;
1002 retval = send_packet(ictx);
1003 if (retval)
Jarod Wilson47a09b02011-07-14 14:20:46 -03001004 pr_err_ratelimited("send packet #%d failed\n", seq / 2);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001005
1006exit:
1007 mutex_unlock(&ictx->lock);
1008
1009 return (!retval) ? n_bytes : retval;
1010}
1011
1012/**
1013 * Writes data to the LCD. The iMON OEM LCD screen expects 8-byte
1014 * packets. We accept data as 16 hexadecimal digits, followed by a
1015 * newline (to make it easy to drive the device from a command-line
1016 * -- even though the actual binary data is a bit complicated).
1017 *
1018 * The device itself is not a "traditional" text-mode display. It's
1019 * actually a 16x96 pixel bitmap display. That means if you want to
1020 * display text, you've got to have your own "font" and translate the
1021 * text into bitmaps for display. This is really flexible (you can
1022 * display whatever diacritics you need, and so on), but it's also
1023 * a lot more complicated than most LCDs...
1024 */
David Härdemand6740d82014-04-03 20:34:53 -03001025static ssize_t lcd_write(struct file *file, const char __user *buf,
Jarod Wilson21677cf2010-04-16 18:29:02 -03001026 size_t n_bytes, loff_t *pos)
1027{
1028 int retval = 0;
1029 struct imon_context *ictx;
1030
Joe Perchesabf84382010-07-12 17:50:03 -03001031 ictx = file->private_data;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001032 if (!ictx) {
Jarod Wilson47a09b02011-07-14 14:20:46 -03001033 pr_err_ratelimited("no context for device\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -03001034 return -ENODEV;
1035 }
1036
1037 mutex_lock(&ictx->lock);
1038
1039 if (!ictx->display_supported) {
Jarod Wilson47a09b02011-07-14 14:20:46 -03001040 pr_err_ratelimited("no iMON display present\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -03001041 retval = -ENODEV;
1042 goto exit;
1043 }
1044
1045 if (n_bytes != 8) {
Jarod Wilson47a09b02011-07-14 14:20:46 -03001046 pr_err_ratelimited("invalid payload size: %d (expected 8)\n",
1047 (int)n_bytes);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001048 retval = -EINVAL;
1049 goto exit;
1050 }
1051
1052 if (copy_from_user(ictx->usb_tx_buf, buf, 8)) {
1053 retval = -EFAULT;
1054 goto exit;
1055 }
1056
1057 retval = send_packet(ictx);
1058 if (retval) {
Jarod Wilson47a09b02011-07-14 14:20:46 -03001059 pr_err_ratelimited("send packet failed!\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -03001060 goto exit;
1061 } else {
1062 dev_dbg(ictx->dev, "%s: write %d bytes to LCD\n",
1063 __func__, (int) n_bytes);
1064 }
1065exit:
1066 mutex_unlock(&ictx->lock);
1067 return (!retval) ? n_bytes : retval;
1068}
1069
1070/**
1071 * Callback function for USB core API: transmit data
1072 */
1073static void usb_tx_callback(struct urb *urb)
1074{
1075 struct imon_context *ictx;
1076
1077 if (!urb)
1078 return;
1079 ictx = (struct imon_context *)urb->context;
1080 if (!ictx)
1081 return;
1082
1083 ictx->tx.status = urb->status;
1084
1085 /* notify waiters that write has finished */
Jarod Wilsonf789bf42010-05-24 12:00:31 -03001086 ictx->tx.busy = false;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001087 smp_rmb(); /* ensure later readers know we're not busy */
1088 complete(&ictx->tx.finished);
1089}
1090
1091/**
Jarod Wilson21677cf2010-04-16 18:29:02 -03001092 * report touchscreen input
1093 */
1094static void imon_touch_display_timeout(unsigned long data)
1095{
1096 struct imon_context *ictx = (struct imon_context *)data;
1097
Dan Carpenterf03900d2010-05-04 08:37:33 -03001098 if (ictx->display_type != IMON_DISPLAY_TYPE_VGA)
Jarod Wilson21677cf2010-04-16 18:29:02 -03001099 return;
1100
1101 input_report_abs(ictx->touch, ABS_X, ictx->touch_x);
1102 input_report_abs(ictx->touch, ABS_Y, ictx->touch_y);
1103 input_report_key(ictx->touch, BTN_TOUCH, 0x00);
1104 input_sync(ictx->touch);
1105}
1106
1107/**
1108 * iMON IR receivers support two different signal sets -- those used by
1109 * the iMON remotes, and those used by the Windows MCE remotes (which is
1110 * really just RC-6), but only one or the other at a time, as the signals
1111 * are decoded onboard the receiver.
Jarod Wilson23ef7102011-04-27 19:01:44 -03001112 *
1113 * This function gets called two different ways, one way is from
1114 * rc_register_device, for initial protocol selection/setup, and the other is
1115 * via a userspace-initiated protocol change request, either by direct sysfs
1116 * prodding or by something like ir-keytable. In the rc_register_device case,
1117 * the imon context lock is already held, but when initiated from userspace,
1118 * it is not, so we must acquire it prior to calling send_packet, which
1119 * requires that the lock is held.
Jarod Wilson21677cf2010-04-16 18:29:02 -03001120 */
Sean Young6d741bf2017-08-07 16:20:58 -04001121static int imon_ir_change_protocol(struct rc_dev *rc, u64 *rc_proto)
Jarod Wilson21677cf2010-04-16 18:29:02 -03001122{
1123 int retval;
David Härdemand8b4b582010-10-29 16:08:23 -03001124 struct imon_context *ictx = rc->priv;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001125 struct device *dev = ictx->dev;
Jarod Wilson23ef7102011-04-27 19:01:44 -03001126 bool unlock = false;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001127 unsigned char ir_proto_packet[] = {
1128 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86 };
1129
Sean Young6d741bf2017-08-07 16:20:58 -04001130 if (*rc_proto && !(*rc_proto & rc->allowed_protocols))
Mauro Carvalho Chehab25ec5872016-10-18 17:44:25 -02001131 dev_warn(dev, "Looks like you're trying to use an IR protocol this device does not support\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -03001132
Sean Young6d741bf2017-08-07 16:20:58 -04001133 if (*rc_proto & RC_PROTO_BIT_RC6_MCE) {
Jarod Wilson21677cf2010-04-16 18:29:02 -03001134 dev_dbg(dev, "Configuring IR receiver for MCE protocol\n");
1135 ir_proto_packet[0] = 0x01;
Sean Young6d741bf2017-08-07 16:20:58 -04001136 *rc_proto = RC_PROTO_BIT_RC6_MCE;
1137 } else if (*rc_proto & RC_PROTO_BIT_OTHER) {
Jarod Wilson666a9ed2010-04-28 14:37:29 -03001138 dev_dbg(dev, "Configuring IR receiver for iMON protocol\n");
Jarod Wilson76f1ef42011-01-06 16:59:35 -03001139 if (!pad_stabilize)
Jarod Wilson666a9ed2010-04-28 14:37:29 -03001140 dev_dbg(dev, "PAD stabilize functionality disabled\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -03001141 /* ir_proto_packet[0] = 0x00; // already the default */
Sean Young6d741bf2017-08-07 16:20:58 -04001142 *rc_proto = RC_PROTO_BIT_OTHER;
David Härdemanc003ab12012-10-11 19:11:54 -03001143 } else {
Mauro Carvalho Chehab25ec5872016-10-18 17:44:25 -02001144 dev_warn(dev, "Unsupported IR protocol specified, overriding to iMON IR protocol\n");
Jarod Wilson76f1ef42011-01-06 16:59:35 -03001145 if (!pad_stabilize)
Jarod Wilson666a9ed2010-04-28 14:37:29 -03001146 dev_dbg(dev, "PAD stabilize functionality disabled\n");
Jarod Wilson6718e8a2010-04-23 02:27:11 -03001147 /* ir_proto_packet[0] = 0x00; // already the default */
Sean Young6d741bf2017-08-07 16:20:58 -04001148 *rc_proto = RC_PROTO_BIT_OTHER;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001149 }
1150
1151 memcpy(ictx->usb_tx_buf, &ir_proto_packet, sizeof(ir_proto_packet));
1152
Jarod Wilson23ef7102011-04-27 19:01:44 -03001153 if (!mutex_is_locked(&ictx->lock)) {
1154 unlock = true;
1155 mutex_lock(&ictx->lock);
1156 }
1157
Jarod Wilson21677cf2010-04-16 18:29:02 -03001158 retval = send_packet(ictx);
Jarod Wilson6718e8a2010-04-23 02:27:11 -03001159 if (retval)
1160 goto out;
1161
Sean Young6d741bf2017-08-07 16:20:58 -04001162 ictx->rc_proto = *rc_proto;
Jarod Wilson76f1ef42011-01-06 16:59:35 -03001163 ictx->pad_mouse = false;
Jarod Wilson6718e8a2010-04-23 02:27:11 -03001164
1165out:
Jarod Wilson23ef7102011-04-27 19:01:44 -03001166 if (unlock)
1167 mutex_unlock(&ictx->lock);
1168
Jarod Wilson6718e8a2010-04-23 02:27:11 -03001169 return retval;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001170}
1171
1172static inline int tv2int(const struct timeval *a, const struct timeval *b)
1173{
1174 int usecs = 0;
1175 int sec = 0;
1176
1177 if (b->tv_usec > a->tv_usec) {
1178 usecs = 1000000;
1179 sec--;
1180 }
1181
1182 usecs += a->tv_usec - b->tv_usec;
1183
1184 sec += a->tv_sec - b->tv_sec;
1185 sec *= 1000;
1186 usecs /= 1000;
1187 sec += usecs;
1188
1189 if (sec < 0)
1190 sec = 1000;
1191
1192 return sec;
1193}
1194
1195/**
1196 * The directional pad behaves a bit differently, depending on whether this is
1197 * one of the older ffdc devices or a newer device. Newer devices appear to
1198 * have a higher resolution matrix for more precise mouse movement, but it
1199 * makes things overly sensitive in keyboard mode, so we do some interesting
1200 * contortions to make it less touchy. Older devices run through the same
1201 * routine with shorter timeout and a smaller threshold.
1202 */
1203static int stabilize(int a, int b, u16 timeout, u16 threshold)
1204{
1205 struct timeval ct;
1206 static struct timeval prev_time = {0, 0};
1207 static struct timeval hit_time = {0, 0};
1208 static int x, y, prev_result, hits;
1209 int result = 0;
1210 int msec, msec_hit;
1211
1212 do_gettimeofday(&ct);
1213 msec = tv2int(&ct, &prev_time);
1214 msec_hit = tv2int(&ct, &hit_time);
1215
1216 if (msec > 100) {
1217 x = 0;
1218 y = 0;
1219 hits = 0;
1220 }
1221
1222 x += a;
1223 y += b;
1224
1225 prev_time = ct;
1226
1227 if (abs(x) > threshold || abs(y) > threshold) {
1228 if (abs(y) > abs(x))
1229 result = (y > 0) ? 0x7F : 0x80;
1230 else
1231 result = (x > 0) ? 0x7F00 : 0x8000;
1232
1233 x = 0;
1234 y = 0;
1235
1236 if (result == prev_result) {
1237 hits++;
1238
1239 if (hits > 3) {
1240 switch (result) {
1241 case 0x7F:
1242 y = 17 * threshold / 30;
1243 break;
1244 case 0x80:
1245 y -= 17 * threshold / 30;
1246 break;
1247 case 0x7F00:
1248 x = 17 * threshold / 30;
1249 break;
1250 case 0x8000:
1251 x -= 17 * threshold / 30;
1252 break;
1253 }
1254 }
1255
1256 if (hits == 2 && msec_hit < timeout) {
1257 result = 0;
1258 hits = 1;
1259 }
1260 } else {
1261 prev_result = result;
1262 hits = 1;
1263 hit_time = ct;
1264 }
1265 }
1266
1267 return result;
1268}
1269
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001270static u32 imon_remote_key_lookup(struct imon_context *ictx, u32 scancode)
Jarod Wilson21677cf2010-04-16 18:29:02 -03001271{
Jarod Wilson21677cf2010-04-16 18:29:02 -03001272 u32 keycode;
1273 u32 release;
1274 bool is_release_code = false;
1275
1276 /* Look for the initial press of a button */
Mauro Carvalho Chehabca866742010-11-17 13:53:11 -03001277 keycode = rc_g_keycode_from_table(ictx->rdev, scancode);
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001278 ictx->rc_toggle = 0x0;
1279 ictx->rc_scancode = scancode;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001280
1281 /* Look for the release of a button */
1282 if (keycode == KEY_RESERVED) {
1283 release = scancode & ~0x4000;
Mauro Carvalho Chehabca866742010-11-17 13:53:11 -03001284 keycode = rc_g_keycode_from_table(ictx->rdev, release);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001285 if (keycode != KEY_RESERVED)
1286 is_release_code = true;
1287 }
1288
1289 ictx->release_code = is_release_code;
1290
1291 return keycode;
1292}
1293
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001294static u32 imon_mce_key_lookup(struct imon_context *ictx, u32 scancode)
Jarod Wilson21677cf2010-04-16 18:29:02 -03001295{
Jarod Wilson21677cf2010-04-16 18:29:02 -03001296 u32 keycode;
1297
1298#define MCE_KEY_MASK 0x7000
1299#define MCE_TOGGLE_BIT 0x8000
1300
1301 /*
1302 * On some receivers, mce keys decode to 0x8000f04xx and 0x8000f84xx
1303 * (the toggle bit flipping between alternating key presses), while
1304 * on other receivers, we see 0x8000f74xx and 0x8000ff4xx. To keep
1305 * the table trim, we always or in the bits to look up 0x8000ff4xx,
1306 * but we can't or them into all codes, as some keys are decoded in
1307 * a different way w/o the same use of the toggle bit...
1308 */
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001309 if (scancode & 0x80000000)
Jarod Wilson21677cf2010-04-16 18:29:02 -03001310 scancode = scancode | MCE_KEY_MASK | MCE_TOGGLE_BIT;
1311
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001312 ictx->rc_scancode = scancode;
Mauro Carvalho Chehabca866742010-11-17 13:53:11 -03001313 keycode = rc_g_keycode_from_table(ictx->rdev, scancode);
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001314
1315 /* not used in mce mode, but make sure we know its false */
1316 ictx->release_code = false;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001317
1318 return keycode;
1319}
1320
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -03001321static u32 imon_panel_key_lookup(struct imon_context *ictx, u64 code)
Jarod Wilson21677cf2010-04-16 18:29:02 -03001322{
1323 int i;
Jarod Wilson083e4722010-05-04 16:17:05 -03001324 u32 keycode = KEY_RESERVED;
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -03001325 struct imon_panel_key_table *key_table = ictx->dev_descr->key_table;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001326
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -03001327 for (i = 0; key_table[i].hw_code != 0; i++) {
1328 if (key_table[i].hw_code == (code | 0xffee)) {
1329 keycode = key_table[i].keycode;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001330 break;
Jarod Wilson083e4722010-05-04 16:17:05 -03001331 }
1332 }
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -03001333 ictx->release_code = false;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001334 return keycode;
1335}
1336
1337static bool imon_mouse_event(struct imon_context *ictx,
1338 unsigned char *buf, int len)
1339{
Alexandre Lissy24dec5d2012-09-02 15:35:20 -03001340 signed char rel_x = 0x00, rel_y = 0x00;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001341 u8 right_shift = 1;
Jarod Wilsonf789bf42010-05-24 12:00:31 -03001342 bool mouse_input = true;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001343 int dir = 0;
Jarod Wilson693508d2010-09-15 15:56:03 -03001344 unsigned long flags;
1345
1346 spin_lock_irqsave(&ictx->kc_lock, flags);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001347
1348 /* newer iMON device PAD or mouse button */
1349 if (ictx->product != 0xffdc && (buf[0] & 0x01) && len == 5) {
1350 rel_x = buf[2];
1351 rel_y = buf[3];
1352 right_shift = 1;
1353 /* 0xffdc iMON PAD or mouse button input */
1354 } else if (ictx->product == 0xffdc && (buf[0] & 0x40) &&
1355 !((buf[1] & 0x01) || ((buf[1] >> 2) & 0x01))) {
1356 rel_x = (buf[1] & 0x08) | (buf[1] & 0x10) >> 2 |
1357 (buf[1] & 0x20) >> 4 | (buf[1] & 0x40) >> 6;
1358 if (buf[0] & 0x02)
1359 rel_x |= ~0x0f;
1360 rel_x = rel_x + rel_x / 2;
1361 rel_y = (buf[2] & 0x08) | (buf[2] & 0x10) >> 2 |
1362 (buf[2] & 0x20) >> 4 | (buf[2] & 0x40) >> 6;
1363 if (buf[0] & 0x01)
1364 rel_y |= ~0x0f;
1365 rel_y = rel_y + rel_y / 2;
1366 right_shift = 2;
1367 /* some ffdc devices decode mouse buttons differently... */
1368 } else if (ictx->product == 0xffdc && (buf[0] == 0x68)) {
1369 right_shift = 2;
1370 /* ch+/- buttons, which we use for an emulated scroll wheel */
1371 } else if (ictx->kc == KEY_CHANNELUP && (buf[2] & 0x40) != 0x40) {
1372 dir = 1;
1373 } else if (ictx->kc == KEY_CHANNELDOWN && (buf[2] & 0x40) != 0x40) {
1374 dir = -1;
1375 } else
Jarod Wilsonf789bf42010-05-24 12:00:31 -03001376 mouse_input = false;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001377
Jarod Wilson693508d2010-09-15 15:56:03 -03001378 spin_unlock_irqrestore(&ictx->kc_lock, flags);
1379
Jarod Wilson21677cf2010-04-16 18:29:02 -03001380 if (mouse_input) {
1381 dev_dbg(ictx->dev, "sending mouse data via input subsystem\n");
1382
1383 if (dir) {
1384 input_report_rel(ictx->idev, REL_WHEEL, dir);
1385 } else if (rel_x || rel_y) {
1386 input_report_rel(ictx->idev, REL_X, rel_x);
1387 input_report_rel(ictx->idev, REL_Y, rel_y);
1388 } else {
1389 input_report_key(ictx->idev, BTN_LEFT, buf[1] & 0x1);
1390 input_report_key(ictx->idev, BTN_RIGHT,
1391 buf[1] >> right_shift & 0x1);
1392 }
1393 input_sync(ictx->idev);
Jarod Wilson693508d2010-09-15 15:56:03 -03001394 spin_lock_irqsave(&ictx->kc_lock, flags);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001395 ictx->last_keycode = ictx->kc;
Jarod Wilson693508d2010-09-15 15:56:03 -03001396 spin_unlock_irqrestore(&ictx->kc_lock, flags);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001397 }
1398
1399 return mouse_input;
1400}
1401
1402static void imon_touch_event(struct imon_context *ictx, unsigned char *buf)
1403{
1404 mod_timer(&ictx->ttimer, jiffies + TOUCH_TIMEOUT);
1405 ictx->touch_x = (buf[0] << 4) | (buf[1] >> 4);
1406 ictx->touch_y = 0xfff - ((buf[2] << 4) | (buf[1] & 0xf));
1407 input_report_abs(ictx->touch, ABS_X, ictx->touch_x);
1408 input_report_abs(ictx->touch, ABS_Y, ictx->touch_y);
1409 input_report_key(ictx->touch, BTN_TOUCH, 0x01);
1410 input_sync(ictx->touch);
1411}
1412
1413static void imon_pad_to_keys(struct imon_context *ictx, unsigned char *buf)
1414{
1415 int dir = 0;
Alexandre Lissy24dec5d2012-09-02 15:35:20 -03001416 signed char rel_x = 0x00, rel_y = 0x00;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001417 u16 timeout, threshold;
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001418 u32 scancode = KEY_RESERVED;
Jarod Wilson693508d2010-09-15 15:56:03 -03001419 unsigned long flags;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001420
1421 /*
1422 * The imon directional pad functions more like a touchpad. Bytes 3 & 4
1423 * contain a position coordinate (x,y), with each component ranging
1424 * from -14 to 14. We want to down-sample this to only 4 discrete values
1425 * for up/down/left/right arrow keys. Also, when you get too close to
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001426 * diagonals, it has a tendency to jump back and forth, so lets try to
Jarod Wilson21677cf2010-04-16 18:29:02 -03001427 * ignore when they get too close.
1428 */
1429 if (ictx->product != 0xffdc) {
1430 /* first, pad to 8 bytes so it conforms with everything else */
1431 buf[5] = buf[6] = buf[7] = 0;
1432 timeout = 500; /* in msecs */
1433 /* (2*threshold) x (2*threshold) square */
1434 threshold = pad_thresh ? pad_thresh : 28;
1435 rel_x = buf[2];
1436 rel_y = buf[3];
1437
Sean Young6d741bf2017-08-07 16:20:58 -04001438 if (ictx->rc_proto == RC_PROTO_BIT_OTHER && pad_stabilize) {
Jarod Wilson21677cf2010-04-16 18:29:02 -03001439 if ((buf[1] == 0) && ((rel_x != 0) || (rel_y != 0))) {
1440 dir = stabilize((int)rel_x, (int)rel_y,
1441 timeout, threshold);
1442 if (!dir) {
Jarod Wilson693508d2010-09-15 15:56:03 -03001443 spin_lock_irqsave(&ictx->kc_lock,
1444 flags);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001445 ictx->kc = KEY_UNKNOWN;
Jarod Wilson693508d2010-09-15 15:56:03 -03001446 spin_unlock_irqrestore(&ictx->kc_lock,
1447 flags);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001448 return;
1449 }
1450 buf[2] = dir & 0xFF;
1451 buf[3] = (dir >> 8) & 0xFF;
Hans Verkuild778d252014-08-20 19:34:33 -03001452 scancode = be32_to_cpu(*((__be32 *)buf));
Jarod Wilson21677cf2010-04-16 18:29:02 -03001453 }
1454 } else {
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001455 /*
1456 * Hack alert: instead of using keycodes, we have
1457 * to use hard-coded scancodes here...
1458 */
Jarod Wilson21677cf2010-04-16 18:29:02 -03001459 if (abs(rel_y) > abs(rel_x)) {
1460 buf[2] = (rel_y > 0) ? 0x7F : 0x80;
1461 buf[3] = 0;
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001462 if (rel_y > 0)
1463 scancode = 0x01007f00; /* KEY_DOWN */
1464 else
1465 scancode = 0x01008000; /* KEY_UP */
Jarod Wilson21677cf2010-04-16 18:29:02 -03001466 } else {
1467 buf[2] = 0;
1468 buf[3] = (rel_x > 0) ? 0x7F : 0x80;
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001469 if (rel_x > 0)
1470 scancode = 0x0100007f; /* KEY_RIGHT */
1471 else
1472 scancode = 0x01000080; /* KEY_LEFT */
Jarod Wilson21677cf2010-04-16 18:29:02 -03001473 }
1474 }
1475
1476 /*
1477 * Handle on-board decoded pad events for e.g. older VFD/iMON-Pad
1478 * device (15c2:ffdc). The remote generates various codes from
1479 * 0x68nnnnB7 to 0x6AnnnnB7, the left mouse button generates
1480 * 0x688301b7 and the right one 0x688481b7. All other keys generate
1481 * 0x2nnnnnnn. Position coordinate is encoded in buf[1] and buf[2] with
Jonathan McCrohan39c1cb22013-10-20 21:34:01 -03001482 * reversed endianness. Extract direction from buffer, rotate endianness,
Jarod Wilson21677cf2010-04-16 18:29:02 -03001483 * adjust sign and feed the values into stabilize(). The resulting codes
1484 * will be 0x01008000, 0x01007F00, which match the newer devices.
1485 */
1486 } else {
1487 timeout = 10; /* in msecs */
1488 /* (2*threshold) x (2*threshold) square */
1489 threshold = pad_thresh ? pad_thresh : 15;
1490
1491 /* buf[1] is x */
1492 rel_x = (buf[1] & 0x08) | (buf[1] & 0x10) >> 2 |
1493 (buf[1] & 0x20) >> 4 | (buf[1] & 0x40) >> 6;
1494 if (buf[0] & 0x02)
1495 rel_x |= ~0x10+1;
1496 /* buf[2] is y */
1497 rel_y = (buf[2] & 0x08) | (buf[2] & 0x10) >> 2 |
1498 (buf[2] & 0x20) >> 4 | (buf[2] & 0x40) >> 6;
1499 if (buf[0] & 0x01)
1500 rel_y |= ~0x10+1;
1501
1502 buf[0] = 0x01;
1503 buf[1] = buf[4] = buf[5] = buf[6] = buf[7] = 0;
1504
Sean Young6d741bf2017-08-07 16:20:58 -04001505 if (ictx->rc_proto == RC_PROTO_BIT_OTHER && pad_stabilize) {
Jarod Wilson21677cf2010-04-16 18:29:02 -03001506 dir = stabilize((int)rel_x, (int)rel_y,
1507 timeout, threshold);
1508 if (!dir) {
Jarod Wilson693508d2010-09-15 15:56:03 -03001509 spin_lock_irqsave(&ictx->kc_lock, flags);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001510 ictx->kc = KEY_UNKNOWN;
Jarod Wilson693508d2010-09-15 15:56:03 -03001511 spin_unlock_irqrestore(&ictx->kc_lock, flags);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001512 return;
1513 }
1514 buf[2] = dir & 0xFF;
1515 buf[3] = (dir >> 8) & 0xFF;
Hans Verkuild778d252014-08-20 19:34:33 -03001516 scancode = be32_to_cpu(*((__be32 *)buf));
Jarod Wilson21677cf2010-04-16 18:29:02 -03001517 } else {
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001518 /*
1519 * Hack alert: instead of using keycodes, we have
1520 * to use hard-coded scancodes here...
1521 */
Jarod Wilson21677cf2010-04-16 18:29:02 -03001522 if (abs(rel_y) > abs(rel_x)) {
1523 buf[2] = (rel_y > 0) ? 0x7F : 0x80;
1524 buf[3] = 0;
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001525 if (rel_y > 0)
1526 scancode = 0x01007f00; /* KEY_DOWN */
1527 else
1528 scancode = 0x01008000; /* KEY_UP */
Jarod Wilson21677cf2010-04-16 18:29:02 -03001529 } else {
1530 buf[2] = 0;
1531 buf[3] = (rel_x > 0) ? 0x7F : 0x80;
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001532 if (rel_x > 0)
1533 scancode = 0x0100007f; /* KEY_RIGHT */
1534 else
1535 scancode = 0x01000080; /* KEY_LEFT */
Jarod Wilson21677cf2010-04-16 18:29:02 -03001536 }
1537 }
1538 }
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001539
Jarod Wilson693508d2010-09-15 15:56:03 -03001540 if (scancode) {
1541 spin_lock_irqsave(&ictx->kc_lock, flags);
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001542 ictx->kc = imon_remote_key_lookup(ictx, scancode);
Jarod Wilson693508d2010-09-15 15:56:03 -03001543 spin_unlock_irqrestore(&ictx->kc_lock, flags);
1544 }
Jarod Wilson21677cf2010-04-16 18:29:02 -03001545}
1546
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001547/**
1548 * figure out if these is a press or a release. We don't actually
1549 * care about repeats, as those will be auto-generated within the IR
1550 * subsystem for repeating scancodes.
1551 */
Jarod Wilson21677cf2010-04-16 18:29:02 -03001552static int imon_parse_press_type(struct imon_context *ictx,
1553 unsigned char *buf, u8 ktype)
1554{
1555 int press_type = 0;
Jarod Wilson693508d2010-09-15 15:56:03 -03001556 unsigned long flags;
1557
1558 spin_lock_irqsave(&ictx->kc_lock, flags);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001559
1560 /* key release of 0x02XXXXXX key */
1561 if (ictx->kc == KEY_RESERVED && buf[0] == 0x02 && buf[3] == 0x00)
1562 ictx->kc = ictx->last_keycode;
1563
1564 /* mouse button release on (some) 0xffdc devices */
1565 else if (ictx->kc == KEY_RESERVED && buf[0] == 0x68 && buf[1] == 0x82 &&
1566 buf[2] == 0x81 && buf[3] == 0xb7)
1567 ictx->kc = ictx->last_keycode;
1568
1569 /* mouse button release on (some other) 0xffdc devices */
1570 else if (ictx->kc == KEY_RESERVED && buf[0] == 0x01 && buf[1] == 0x00 &&
1571 buf[2] == 0x81 && buf[3] == 0xb7)
1572 ictx->kc = ictx->last_keycode;
1573
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001574 /* mce-specific button handling, no keyup events */
Jarod Wilson21677cf2010-04-16 18:29:02 -03001575 else if (ktype == IMON_KEY_MCE) {
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001576 ictx->rc_toggle = buf[2];
1577 press_type = 1;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001578
1579 /* incoherent or irrelevant data */
1580 } else if (ictx->kc == KEY_RESERVED)
1581 press_type = -EINVAL;
1582
1583 /* key release of 0xXXXXXXb7 key */
1584 else if (ictx->release_code)
1585 press_type = 0;
1586
1587 /* this is a button press */
1588 else
1589 press_type = 1;
1590
Jarod Wilson693508d2010-09-15 15:56:03 -03001591 spin_unlock_irqrestore(&ictx->kc_lock, flags);
1592
Jarod Wilson21677cf2010-04-16 18:29:02 -03001593 return press_type;
1594}
1595
1596/**
1597 * Process the incoming packet
1598 */
Sean Youngf41003a2016-12-20 12:18:06 -02001599/**
1600 * Convert bit count to time duration (in us) and submit
1601 * the value to lirc_dev.
1602 */
1603static void submit_data(struct imon_context *context)
1604{
1605 DEFINE_IR_RAW_EVENT(ev);
1606
1607 ev.pulse = context->rx.prev_bit;
1608 ev.duration = US_TO_NS(context->rx.count * BIT_DURATION);
1609 ir_raw_event_store_with_filter(context->rdev, &ev);
1610}
1611
1612/**
1613 * Process the incoming packet
1614 */
1615static void imon_incoming_ir_raw(struct imon_context *context,
Jarod Wilson21677cf2010-04-16 18:29:02 -03001616 struct urb *urb, int intf)
1617{
1618 int len = urb->actual_length;
1619 unsigned char *buf = urb->transfer_buffer;
Sean Youngf41003a2016-12-20 12:18:06 -02001620 struct device *dev = context->dev;
1621 int octet, bit;
1622 unsigned char mask;
1623
1624 if (len != 8) {
1625 dev_warn(dev, "imon %s: invalid incoming packet size (len = %d, intf%d)\n",
1626 __func__, len, intf);
1627 return;
1628 }
1629
1630 if (debug)
1631 dev_info(dev, "raw packet: %*ph\n", len, buf);
1632 /*
1633 * Translate received data to pulse and space lengths.
1634 * Received data is active low, i.e. pulses are 0 and
1635 * spaces are 1.
1636 *
1637 * My original algorithm was essentially similar to
1638 * Changwoo Ryu's with the exception that he switched
1639 * the incoming bits to active high and also fed an
1640 * initial space to LIRC at the start of a new sequence
1641 * if the previous bit was a pulse.
1642 *
1643 * I've decided to adopt his algorithm.
1644 */
1645
1646 if (buf[7] == 1 && context->rx.initial_space) {
1647 /* LIRC requires a leading space */
1648 context->rx.prev_bit = 0;
1649 context->rx.count = 4;
1650 submit_data(context);
1651 context->rx.count = 0;
1652 }
1653
1654 for (octet = 0; octet < 5; ++octet) {
1655 mask = 0x80;
1656 for (bit = 0; bit < 8; ++bit) {
1657 int curr_bit = !(buf[octet] & mask);
1658
1659 if (curr_bit != context->rx.prev_bit) {
1660 if (context->rx.count) {
1661 submit_data(context);
1662 context->rx.count = 0;
1663 }
1664 context->rx.prev_bit = curr_bit;
1665 }
1666 ++context->rx.count;
1667 mask >>= 1;
1668 }
1669 }
1670
1671 if (buf[7] == 10) {
1672 if (context->rx.count) {
1673 submit_data(context);
1674 context->rx.count = 0;
1675 }
1676 context->rx.initial_space = context->rx.prev_bit;
1677 }
1678
1679 ir_raw_event_handle(context->rdev);
1680}
1681
1682static void imon_incoming_scancode(struct imon_context *ictx,
1683 struct urb *urb, int intf)
1684{
1685 int len = urb->actual_length;
1686 unsigned char *buf = urb->transfer_buffer;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001687 struct device *dev = ictx->dev;
Jarod Wilson693508d2010-09-15 15:56:03 -03001688 unsigned long flags;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001689 u32 kc;
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001690 u64 scancode;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001691 int press_type = 0;
1692 int msec;
1693 struct timeval t;
1694 static struct timeval prev_time = { 0, 0 };
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001695 u8 ktype;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001696
Jarod Wilson21677cf2010-04-16 18:29:02 -03001697 /* filter out junk data on the older 0xffdc imon devices */
Jarod Wilsonbbe46902010-05-24 12:02:05 -03001698 if ((buf[0] == 0xff) && (buf[1] == 0xff) && (buf[2] == 0xff))
Jarod Wilson21677cf2010-04-16 18:29:02 -03001699 return;
1700
1701 /* Figure out what key was pressed */
Jarod Wilson21677cf2010-04-16 18:29:02 -03001702 if (len == 8 && buf[7] == 0xee) {
Hans Verkuild778d252014-08-20 19:34:33 -03001703 scancode = be64_to_cpu(*((__be64 *)buf));
Jarod Wilson21677cf2010-04-16 18:29:02 -03001704 ktype = IMON_KEY_PANEL;
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -03001705 kc = imon_panel_key_lookup(ictx, scancode);
Ulrich Eckhardt6ddc2be2014-07-26 15:01:12 -03001706 ictx->release_code = false;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001707 } else {
Hans Verkuild778d252014-08-20 19:34:33 -03001708 scancode = be32_to_cpu(*((__be32 *)buf));
Sean Young6d741bf2017-08-07 16:20:58 -04001709 if (ictx->rc_proto == RC_PROTO_BIT_RC6_MCE) {
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001710 ktype = IMON_KEY_IMON;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001711 if (buf[0] == 0x80)
1712 ktype = IMON_KEY_MCE;
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001713 kc = imon_mce_key_lookup(ictx, scancode);
1714 } else {
1715 ktype = IMON_KEY_IMON;
1716 kc = imon_remote_key_lookup(ictx, scancode);
1717 }
Jarod Wilson21677cf2010-04-16 18:29:02 -03001718 }
1719
Jarod Wilson693508d2010-09-15 15:56:03 -03001720 spin_lock_irqsave(&ictx->kc_lock, flags);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001721 /* keyboard/mouse mode toggle button */
1722 if (kc == KEY_KEYBOARD && !ictx->release_code) {
1723 ictx->last_keycode = kc;
1724 if (!nomouse) {
Arnd Bergmannbd7e31b2017-05-11 08:46:44 -03001725 ictx->pad_mouse = !ictx->pad_mouse;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001726 dev_dbg(dev, "toggling to %s mode\n",
1727 ictx->pad_mouse ? "mouse" : "keyboard");
Jarod Wilson693508d2010-09-15 15:56:03 -03001728 spin_unlock_irqrestore(&ictx->kc_lock, flags);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001729 return;
1730 } else {
Jarod Wilson76f1ef42011-01-06 16:59:35 -03001731 ictx->pad_mouse = false;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001732 dev_dbg(dev, "mouse mode disabled, passing key value\n");
1733 }
1734 }
1735
1736 ictx->kc = kc;
Jarod Wilson693508d2010-09-15 15:56:03 -03001737 spin_unlock_irqrestore(&ictx->kc_lock, flags);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001738
1739 /* send touchscreen events through input subsystem if touchpad data */
1740 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA && len == 8 &&
1741 buf[7] == 0x86) {
1742 imon_touch_event(ictx, buf);
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001743 return;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001744
1745 /* look for mouse events with pad in mouse mode */
1746 } else if (ictx->pad_mouse) {
1747 if (imon_mouse_event(ictx, buf, len))
1748 return;
1749 }
1750
1751 /* Now for some special handling to convert pad input to arrow keys */
1752 if (((len == 5) && (buf[0] == 0x01) && (buf[4] == 0x00)) ||
1753 ((len == 8) && (buf[0] & 0x40) &&
1754 !(buf[1] & 0x1 || buf[1] >> 2 & 0x1))) {
1755 len = 8;
1756 imon_pad_to_keys(ictx, buf);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001757 }
1758
1759 if (debug) {
Mauro Carvalho Chehab832d40c2016-10-14 07:48:35 -03001760 printk(KERN_INFO "intf%d decoded packet: %*ph\n",
1761 intf, len, buf);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001762 }
1763
1764 press_type = imon_parse_press_type(ictx, buf, ktype);
1765 if (press_type < 0)
1766 goto not_input_data;
1767
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001768 if (ktype != IMON_KEY_PANEL) {
1769 if (press_type == 0)
Mauro Carvalho Chehabca866742010-11-17 13:53:11 -03001770 rc_keyup(ictx->rdev);
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001771 else {
Sean Young6d741bf2017-08-07 16:20:58 -04001772 if (ictx->rc_proto == RC_PROTO_BIT_RC6_MCE ||
1773 ictx->rc_proto == RC_PROTO_BIT_OTHER)
David Härdeman120703f2014-04-03 20:31:30 -03001774 rc_keydown(ictx->rdev,
Sean Young6d741bf2017-08-07 16:20:58 -04001775 ictx->rc_proto == RC_PROTO_BIT_RC6_MCE ? RC_PROTO_RC6_MCE : RC_PROTO_OTHER,
David Härdeman120703f2014-04-03 20:31:30 -03001776 ictx->rc_scancode, ictx->rc_toggle);
Jarod Wilson693508d2010-09-15 15:56:03 -03001777 spin_lock_irqsave(&ictx->kc_lock, flags);
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001778 ictx->last_keycode = ictx->kc;
Jarod Wilson693508d2010-09-15 15:56:03 -03001779 spin_unlock_irqrestore(&ictx->kc_lock, flags);
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001780 }
1781 return;
1782 }
1783
1784 /* Only panel type events left to process now */
Jarod Wilson693508d2010-09-15 15:56:03 -03001785 spin_lock_irqsave(&ictx->kc_lock, flags);
1786
Jarod Wilson94215cc2011-06-04 14:14:41 -03001787 do_gettimeofday(&t);
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001788 /* KEY_MUTE repeats from knob need to be suppressed */
1789 if (ictx->kc == KEY_MUTE && ictx->kc == ictx->last_keycode) {
Jarod Wilson21677cf2010-04-16 18:29:02 -03001790 msec = tv2int(&t, &prev_time);
Jarod Wilson428cc762010-10-23 16:42:20 -03001791 if (msec < ictx->idev->rep[REP_DELAY]) {
Jarod Wilson693508d2010-09-15 15:56:03 -03001792 spin_unlock_irqrestore(&ictx->kc_lock, flags);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001793 return;
Jarod Wilson693508d2010-09-15 15:56:03 -03001794 }
Jarod Wilson21677cf2010-04-16 18:29:02 -03001795 }
Jarod Wilson94215cc2011-06-04 14:14:41 -03001796 prev_time = t;
Jarod Wilson693508d2010-09-15 15:56:03 -03001797 kc = ictx->kc;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001798
Jarod Wilson693508d2010-09-15 15:56:03 -03001799 spin_unlock_irqrestore(&ictx->kc_lock, flags);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001800
Jarod Wilson428cc762010-10-23 16:42:20 -03001801 input_report_key(ictx->idev, kc, press_type);
1802 input_sync(ictx->idev);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001803
David Härdemaneaf2bcc2010-09-15 15:42:07 -03001804 /* panel keys don't generate a release */
Jarod Wilson428cc762010-10-23 16:42:20 -03001805 input_report_key(ictx->idev, kc, 0);
1806 input_sync(ictx->idev);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001807
Jarod Wilson94215cc2011-06-04 14:14:41 -03001808 spin_lock_irqsave(&ictx->kc_lock, flags);
Jarod Wilson693508d2010-09-15 15:56:03 -03001809 ictx->last_keycode = kc;
Jarod Wilson94215cc2011-06-04 14:14:41 -03001810 spin_unlock_irqrestore(&ictx->kc_lock, flags);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001811
1812 return;
1813
Jarod Wilson21677cf2010-04-16 18:29:02 -03001814not_input_data:
1815 if (len != 8) {
Mauro Carvalho Chehab25ec5872016-10-18 17:44:25 -02001816 dev_warn(dev, "imon %s: invalid incoming packet size (len = %d, intf%d)\n",
1817 __func__, len, intf);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001818 return;
1819 }
1820
1821 /* iMON 2.4G associate frame */
1822 if (buf[0] == 0x00 &&
1823 buf[2] == 0xFF && /* REFID */
1824 buf[3] == 0xFF &&
1825 buf[4] == 0xFF &&
1826 buf[5] == 0xFF && /* iMON 2.4G */
1827 ((buf[6] == 0x4E && buf[7] == 0xDF) || /* LT */
1828 (buf[6] == 0x5E && buf[7] == 0xDF))) { /* DT */
1829 dev_warn(dev, "%s: remote associated refid=%02X\n",
1830 __func__, buf[1]);
Jarod Wilsonf789bf42010-05-24 12:00:31 -03001831 ictx->rf_isassociating = false;
Jarod Wilson21677cf2010-04-16 18:29:02 -03001832 }
1833}
1834
1835/**
1836 * Callback function for USB core API: receive data
1837 */
1838static void usb_rx_callback_intf0(struct urb *urb)
1839{
1840 struct imon_context *ictx;
1841 int intfnum = 0;
1842
1843 if (!urb)
1844 return;
1845
1846 ictx = (struct imon_context *)urb->context;
Jarod Wilson8791d632012-01-26 12:04:11 -03001847 if (!ictx)
Jarod Wilson21677cf2010-04-16 18:29:02 -03001848 return;
1849
Jarod Wilson8791d632012-01-26 12:04:11 -03001850 /*
1851 * if we get a callback before we're done configuring the hardware, we
1852 * can't yet process the data, as there's nowhere to send it, but we
1853 * still need to submit a new rx URB to avoid wedging the hardware
1854 */
1855 if (!ictx->dev_present_intf0)
1856 goto out;
1857
Jarod Wilson21677cf2010-04-16 18:29:02 -03001858 switch (urb->status) {
1859 case -ENOENT: /* usbcore unlink successful! */
1860 return;
1861
1862 case -ESHUTDOWN: /* transport endpoint was shut down */
1863 break;
1864
1865 case 0:
Sean Youngf41003a2016-12-20 12:18:06 -02001866 if (ictx->rdev->driver_type == RC_DRIVER_IR_RAW)
1867 imon_incoming_ir_raw(ictx, urb, intfnum);
1868 else
1869 imon_incoming_scancode(ictx, urb, intfnum);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001870 break;
1871
1872 default:
1873 dev_warn(ictx->dev, "imon %s: status(%d): ignored\n",
1874 __func__, urb->status);
1875 break;
1876 }
1877
Jarod Wilson8791d632012-01-26 12:04:11 -03001878out:
Jarod Wilson21677cf2010-04-16 18:29:02 -03001879 usb_submit_urb(ictx->rx_urb_intf0, GFP_ATOMIC);
1880}
1881
1882static void usb_rx_callback_intf1(struct urb *urb)
1883{
1884 struct imon_context *ictx;
1885 int intfnum = 1;
1886
1887 if (!urb)
1888 return;
1889
1890 ictx = (struct imon_context *)urb->context;
Jarod Wilson8791d632012-01-26 12:04:11 -03001891 if (!ictx)
Jarod Wilson21677cf2010-04-16 18:29:02 -03001892 return;
1893
Jarod Wilson8791d632012-01-26 12:04:11 -03001894 /*
1895 * if we get a callback before we're done configuring the hardware, we
1896 * can't yet process the data, as there's nowhere to send it, but we
1897 * still need to submit a new rx URB to avoid wedging the hardware
1898 */
1899 if (!ictx->dev_present_intf1)
1900 goto out;
1901
Jarod Wilson21677cf2010-04-16 18:29:02 -03001902 switch (urb->status) {
1903 case -ENOENT: /* usbcore unlink successful! */
1904 return;
1905
1906 case -ESHUTDOWN: /* transport endpoint was shut down */
1907 break;
1908
1909 case 0:
Sean Youngf41003a2016-12-20 12:18:06 -02001910 if (ictx->rdev->driver_type == RC_DRIVER_IR_RAW)
1911 imon_incoming_ir_raw(ictx, urb, intfnum);
1912 else
1913 imon_incoming_scancode(ictx, urb, intfnum);
Jarod Wilson21677cf2010-04-16 18:29:02 -03001914 break;
1915
1916 default:
1917 dev_warn(ictx->dev, "imon %s: status(%d): ignored\n",
1918 __func__, urb->status);
1919 break;
1920 }
1921
Jarod Wilson8791d632012-01-26 12:04:11 -03001922out:
Jarod Wilson21677cf2010-04-16 18:29:02 -03001923 usb_submit_urb(ictx->rx_urb_intf1, GFP_ATOMIC);
1924}
1925
Jarod Wilson04292fc2010-09-15 00:28:41 -03001926/*
1927 * The 0x15c2:0xffdc device ID was used for umpteen different imon
1928 * devices, and all of them constantly spew interrupts, even when there
1929 * is no actual data to report. However, byte 6 of this buffer looks like
1930 * its unique across device variants, so we're trying to key off that to
1931 * figure out which display type (if any) and what IR protocol the device
1932 * actually supports. These devices have their IR protocol hard-coded into
1933 * their firmware, they can't be changed on the fly like the newer hardware.
1934 */
1935static void imon_get_ffdc_type(struct imon_context *ictx)
1936{
1937 u8 ffdc_cfg_byte = ictx->usb_rx_buf[6];
1938 u8 detected_display_type = IMON_DISPLAY_TYPE_NONE;
Sean Young6d741bf2017-08-07 16:20:58 -04001939 u64 allowed_protos = RC_PROTO_BIT_OTHER;
Jarod Wilson04292fc2010-09-15 00:28:41 -03001940
1941 switch (ffdc_cfg_byte) {
1942 /* iMON Knob, no display, iMON IR + vol knob */
1943 case 0x21:
1944 dev_info(ictx->dev, "0xffdc iMON Knob, iMON IR");
1945 ictx->display_supported = false;
1946 break;
1947 /* iMON 2.4G LT (usb stick), no display, iMON RF */
1948 case 0x4e:
1949 dev_info(ictx->dev, "0xffdc iMON 2.4G LT, iMON RF");
1950 ictx->display_supported = false;
1951 ictx->rf_device = true;
1952 break;
1953 /* iMON VFD, no IR (does have vol knob tho) */
1954 case 0x35:
1955 dev_info(ictx->dev, "0xffdc iMON VFD + knob, no IR");
1956 detected_display_type = IMON_DISPLAY_TYPE_VFD;
1957 break;
1958 /* iMON VFD, iMON IR */
1959 case 0x24:
1960 case 0x85:
1961 dev_info(ictx->dev, "0xffdc iMON VFD, iMON IR");
1962 detected_display_type = IMON_DISPLAY_TYPE_VFD;
1963 break;
1964 /* iMON VFD, MCE IR */
Jarod Wilson443b3912011-06-04 14:00:54 -03001965 case 0x46:
Jarod Wilson842071c2011-06-20 00:04:05 -03001966 case 0x7e:
Jarod Wilson04292fc2010-09-15 00:28:41 -03001967 case 0x9e:
1968 dev_info(ictx->dev, "0xffdc iMON VFD, MCE IR");
1969 detected_display_type = IMON_DISPLAY_TYPE_VFD;
Sean Young6d741bf2017-08-07 16:20:58 -04001970 allowed_protos = RC_PROTO_BIT_RC6_MCE;
Jarod Wilson04292fc2010-09-15 00:28:41 -03001971 break;
1972 /* iMON LCD, MCE IR */
1973 case 0x9f:
1974 dev_info(ictx->dev, "0xffdc iMON LCD, MCE IR");
1975 detected_display_type = IMON_DISPLAY_TYPE_LCD;
Sean Young6d741bf2017-08-07 16:20:58 -04001976 allowed_protos = RC_PROTO_BIT_RC6_MCE;
Jarod Wilson04292fc2010-09-15 00:28:41 -03001977 break;
1978 default:
Mauro Carvalho Chehab25ec5872016-10-18 17:44:25 -02001979 dev_info(ictx->dev, "Unknown 0xffdc device, defaulting to VFD and iMON IR");
Jarod Wilson04292fc2010-09-15 00:28:41 -03001980 detected_display_type = IMON_DISPLAY_TYPE_VFD;
Jarod Wilson372b4242011-06-20 00:07:13 -03001981 /* We don't know which one it is, allow user to set the
1982 * RC6 one from userspace if OTHER wasn't correct. */
Sean Young6d741bf2017-08-07 16:20:58 -04001983 allowed_protos |= RC_PROTO_BIT_RC6_MCE;
Jarod Wilson04292fc2010-09-15 00:28:41 -03001984 break;
1985 }
1986
1987 printk(KERN_CONT " (id 0x%02x)\n", ffdc_cfg_byte);
1988
1989 ictx->display_type = detected_display_type;
Sean Young6d741bf2017-08-07 16:20:58 -04001990 ictx->rc_proto = allowed_protos;
Jarod Wilson04292fc2010-09-15 00:28:41 -03001991}
1992
1993static void imon_set_display_type(struct imon_context *ictx)
1994{
1995 u8 configured_display_type = IMON_DISPLAY_TYPE_VFD;
1996
1997 /*
1998 * Try to auto-detect the type of display if the user hasn't set
1999 * it by hand via the display_type modparam. Default is VFD.
2000 */
2001
2002 if (display_type == IMON_DISPLAY_TYPE_AUTO) {
2003 switch (ictx->product) {
2004 case 0xffdc:
2005 /* set in imon_get_ffdc_type() */
2006 configured_display_type = ictx->display_type;
2007 break;
2008 case 0x0034:
2009 case 0x0035:
2010 configured_display_type = IMON_DISPLAY_TYPE_VGA;
2011 break;
2012 case 0x0038:
2013 case 0x0039:
2014 case 0x0045:
2015 configured_display_type = IMON_DISPLAY_TYPE_LCD;
2016 break;
2017 case 0x003c:
2018 case 0x0041:
2019 case 0x0042:
2020 case 0x0043:
Sean Youngf41003a2016-12-20 12:18:06 -02002021 case 0x8001:
2022 case 0xff30:
Jarod Wilson04292fc2010-09-15 00:28:41 -03002023 configured_display_type = IMON_DISPLAY_TYPE_NONE;
2024 ictx->display_supported = false;
2025 break;
2026 case 0x0036:
2027 case 0x0044:
Sean Youngf41003a2016-12-20 12:18:06 -02002028 case 0xffda:
Jarod Wilson04292fc2010-09-15 00:28:41 -03002029 default:
2030 configured_display_type = IMON_DISPLAY_TYPE_VFD;
2031 break;
2032 }
2033 } else {
2034 configured_display_type = display_type;
2035 if (display_type == IMON_DISPLAY_TYPE_NONE)
2036 ictx->display_supported = false;
2037 else
2038 ictx->display_supported = true;
Mauro Carvalho Chehab25ec5872016-10-18 17:44:25 -02002039 dev_info(ictx->dev, "%s: overriding display type to %d via modparam\n",
2040 __func__, display_type);
Jarod Wilson04292fc2010-09-15 00:28:41 -03002041 }
2042
2043 ictx->display_type = configured_display_type;
2044}
2045
David Härdemand8b4b582010-10-29 16:08:23 -03002046static struct rc_dev *imon_init_rdev(struct imon_context *ictx)
David Härdemaneaf2bcc2010-09-15 15:42:07 -03002047{
David Härdemand8b4b582010-10-29 16:08:23 -03002048 struct rc_dev *rdev;
David Härdemaneaf2bcc2010-09-15 15:42:07 -03002049 int ret;
Jarod Wilson04292fc2010-09-15 00:28:41 -03002050 const unsigned char fp_packet[] = { 0x40, 0x00, 0x00, 0x00,
2051 0x00, 0x00, 0x00, 0x88 };
David Härdemaneaf2bcc2010-09-15 15:42:07 -03002052
Sean Youngf41003a2016-12-20 12:18:06 -02002053 rdev = rc_allocate_device(ictx->dev_descr->flags & IMON_IR_RAW ?
2054 RC_DRIVER_IR_RAW : RC_DRIVER_SCANCODE);
David Härdemand8b4b582010-10-29 16:08:23 -03002055 if (!rdev) {
David Härdemaneaf2bcc2010-09-15 15:42:07 -03002056 dev_err(ictx->dev, "remote control dev allocation failed\n");
2057 goto out;
2058 }
2059
2060 snprintf(ictx->name_rdev, sizeof(ictx->name_rdev),
2061 "iMON Remote (%04x:%04x)", ictx->vendor, ictx->product);
2062 usb_make_path(ictx->usbdev_intf0, ictx->phys_rdev,
2063 sizeof(ictx->phys_rdev));
2064 strlcat(ictx->phys_rdev, "/input0", sizeof(ictx->phys_rdev));
2065
Sean Young518f4b22017-07-01 12:13:19 -04002066 rdev->device_name = ictx->name_rdev;
David Härdemand8b4b582010-10-29 16:08:23 -03002067 rdev->input_phys = ictx->phys_rdev;
2068 usb_to_input_id(ictx->usbdev_intf0, &rdev->input_id);
David Härdemaneaf2bcc2010-09-15 15:42:07 -03002069 rdev->dev.parent = ictx->dev;
David Härdemaneaf2bcc2010-09-15 15:42:07 -03002070
David Härdemand8b4b582010-10-29 16:08:23 -03002071 rdev->priv = ictx;
Sean Youngf41003a2016-12-20 12:18:06 -02002072 if (ictx->dev_descr->flags & IMON_IR_RAW)
Sean Young6d741bf2017-08-07 16:20:58 -04002073 rdev->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
Sean Youngf41003a2016-12-20 12:18:06 -02002074 else
2075 /* iMON PAD or MCE */
Sean Young6d741bf2017-08-07 16:20:58 -04002076 rdev->allowed_protocols = RC_PROTO_BIT_OTHER |
2077 RC_PROTO_BIT_RC6_MCE;
David Härdemand8b4b582010-10-29 16:08:23 -03002078 rdev->change_protocol = imon_ir_change_protocol;
2079 rdev->driver_name = MOD_NAME;
David Härdemaneaf2bcc2010-09-15 15:42:07 -03002080
Jarod Wilson04292fc2010-09-15 00:28:41 -03002081 /* Enable front-panel buttons and/or knobs */
2082 memcpy(ictx->usb_tx_buf, &fp_packet, sizeof(fp_packet));
2083 ret = send_packet(ictx);
2084 /* Not fatal, but warn about it */
2085 if (ret)
2086 dev_info(ictx->dev, "panel buttons/knobs setup failed\n");
2087
Jarod Wilson7d2edfc2011-01-06 16:57:14 -03002088 if (ictx->product == 0xffdc) {
Jarod Wilson04292fc2010-09-15 00:28:41 -03002089 imon_get_ffdc_type(ictx);
Sean Young6d741bf2017-08-07 16:20:58 -04002090 rdev->allowed_protocols = ictx->rc_proto;
Jarod Wilson7d2edfc2011-01-06 16:57:14 -03002091 }
Jarod Wilson04292fc2010-09-15 00:28:41 -03002092
2093 imon_set_display_type(ictx);
2094
Sean Young6d741bf2017-08-07 16:20:58 -04002095 if (ictx->rc_proto == RC_PROTO_BIT_RC6_MCE ||
Sean Youngf41003a2016-12-20 12:18:06 -02002096 ictx->dev_descr->flags & IMON_IR_RAW)
Jarod Wilson7d2edfc2011-01-06 16:57:14 -03002097 rdev->map_name = RC_MAP_IMON_MCE;
2098 else
2099 rdev->map_name = RC_MAP_IMON_PAD;
2100
David Härdemand8b4b582010-10-29 16:08:23 -03002101 ret = rc_register_device(rdev);
David Härdemaneaf2bcc2010-09-15 15:42:07 -03002102 if (ret < 0) {
2103 dev_err(ictx->dev, "remote input dev register failed\n");
2104 goto out;
2105 }
2106
2107 return rdev;
2108
2109out:
David Härdemand8b4b582010-10-29 16:08:23 -03002110 rc_free_device(rdev);
David Härdemaneaf2bcc2010-09-15 15:42:07 -03002111 return NULL;
2112}
2113
Jarod Wilson21677cf2010-04-16 18:29:02 -03002114static struct input_dev *imon_init_idev(struct imon_context *ictx)
2115{
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -03002116 struct imon_panel_key_table *key_table = ictx->dev_descr->key_table;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002117 struct input_dev *idev;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002118 int ret, i;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002119
2120 idev = input_allocate_device();
Joe Perchesda4a7332013-10-23 16:14:51 -03002121 if (!idev)
David Härdemaneaf2bcc2010-09-15 15:42:07 -03002122 goto out;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002123
Jarod Wilson21677cf2010-04-16 18:29:02 -03002124 snprintf(ictx->name_idev, sizeof(ictx->name_idev),
David Härdemaneaf2bcc2010-09-15 15:42:07 -03002125 "iMON Panel, Knob and Mouse(%04x:%04x)",
2126 ictx->vendor, ictx->product);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002127 idev->name = ictx->name_idev;
2128
2129 usb_make_path(ictx->usbdev_intf0, ictx->phys_idev,
2130 sizeof(ictx->phys_idev));
David Härdemaneaf2bcc2010-09-15 15:42:07 -03002131 strlcat(ictx->phys_idev, "/input1", sizeof(ictx->phys_idev));
Jarod Wilson21677cf2010-04-16 18:29:02 -03002132 idev->phys = ictx->phys_idev;
2133
Jarod Wilsondb190fc2010-04-30 16:06:12 -03002134 idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | BIT_MASK(EV_REL);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002135
2136 idev->keybit[BIT_WORD(BTN_MOUSE)] =
2137 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
2138 idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y) |
2139 BIT_MASK(REL_WHEEL);
2140
2141 /* panel and/or knob code support */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -03002142 for (i = 0; key_table[i].hw_code != 0; i++) {
2143 u32 kc = key_table[i].keycode;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002144 __set_bit(kc, idev->keybit);
2145 }
2146
Jarod Wilson21677cf2010-04-16 18:29:02 -03002147 usb_to_input_id(ictx->usbdev_intf0, &idev->id);
2148 idev->dev.parent = ictx->dev;
David Härdemaneaf2bcc2010-09-15 15:42:07 -03002149 input_set_drvdata(idev, ictx);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002150
David Härdemaneaf2bcc2010-09-15 15:42:07 -03002151 ret = input_register_device(idev);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002152 if (ret < 0) {
David Härdemaneaf2bcc2010-09-15 15:42:07 -03002153 dev_err(ictx->dev, "input dev register failed\n");
2154 goto out;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002155 }
2156
2157 return idev;
2158
David Härdemaneaf2bcc2010-09-15 15:42:07 -03002159out:
Jarod Wilson21677cf2010-04-16 18:29:02 -03002160 input_free_device(idev);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002161 return NULL;
2162}
2163
2164static struct input_dev *imon_init_touch(struct imon_context *ictx)
2165{
2166 struct input_dev *touch;
2167 int ret;
2168
2169 touch = input_allocate_device();
Joe Perchesda4a7332013-10-23 16:14:51 -03002170 if (!touch)
Jarod Wilson21677cf2010-04-16 18:29:02 -03002171 goto touch_alloc_failed;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002172
2173 snprintf(ictx->name_touch, sizeof(ictx->name_touch),
2174 "iMON USB Touchscreen (%04x:%04x)",
2175 ictx->vendor, ictx->product);
2176 touch->name = ictx->name_touch;
2177
2178 usb_make_path(ictx->usbdev_intf1, ictx->phys_touch,
2179 sizeof(ictx->phys_touch));
David Härdemaneaf2bcc2010-09-15 15:42:07 -03002180 strlcat(ictx->phys_touch, "/input2", sizeof(ictx->phys_touch));
Jarod Wilson21677cf2010-04-16 18:29:02 -03002181 touch->phys = ictx->phys_touch;
2182
2183 touch->evbit[0] =
2184 BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
2185 touch->keybit[BIT_WORD(BTN_TOUCH)] =
2186 BIT_MASK(BTN_TOUCH);
2187 input_set_abs_params(touch, ABS_X,
2188 0x00, 0xfff, 0, 0);
2189 input_set_abs_params(touch, ABS_Y,
2190 0x00, 0xfff, 0, 0);
2191
2192 input_set_drvdata(touch, ictx);
2193
2194 usb_to_input_id(ictx->usbdev_intf1, &touch->id);
2195 touch->dev.parent = ictx->dev;
2196 ret = input_register_device(touch);
2197 if (ret < 0) {
2198 dev_info(ictx->dev, "touchscreen input dev register failed\n");
2199 goto touch_register_failed;
2200 }
2201
2202 return touch;
2203
2204touch_register_failed:
Julia Lawallaeb35eb2011-05-20 15:31:59 -03002205 input_free_device(touch);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002206
2207touch_alloc_failed:
2208 return NULL;
2209}
2210
2211static bool imon_find_endpoints(struct imon_context *ictx,
2212 struct usb_host_interface *iface_desc)
2213{
2214 struct usb_endpoint_descriptor *ep;
2215 struct usb_endpoint_descriptor *rx_endpoint = NULL;
2216 struct usb_endpoint_descriptor *tx_endpoint = NULL;
2217 int ifnum = iface_desc->desc.bInterfaceNumber;
2218 int num_endpts = iface_desc->desc.bNumEndpoints;
2219 int i, ep_dir, ep_type;
Jarod Wilsonf789bf42010-05-24 12:00:31 -03002220 bool ir_ep_found = false;
2221 bool display_ep_found = false;
2222 bool tx_control = false;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002223
2224 /*
2225 * Scan the endpoint list and set:
2226 * first input endpoint = IR endpoint
2227 * first output endpoint = display endpoint
2228 */
2229 for (i = 0; i < num_endpts && !(ir_ep_found && display_ep_found); ++i) {
2230 ep = &iface_desc->endpoint[i].desc;
2231 ep_dir = ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK;
Himangi Saraogi9408d8f2014-08-15 13:18:53 -03002232 ep_type = usb_endpoint_type(ep);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002233
2234 if (!ir_ep_found && ep_dir == USB_DIR_IN &&
2235 ep_type == USB_ENDPOINT_XFER_INT) {
2236
2237 rx_endpoint = ep;
Jarod Wilsonf789bf42010-05-24 12:00:31 -03002238 ir_ep_found = true;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002239 dev_dbg(ictx->dev, "%s: found IR endpoint\n", __func__);
2240
2241 } else if (!display_ep_found && ep_dir == USB_DIR_OUT &&
2242 ep_type == USB_ENDPOINT_XFER_INT) {
2243 tx_endpoint = ep;
Jarod Wilsonf789bf42010-05-24 12:00:31 -03002244 display_ep_found = true;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002245 dev_dbg(ictx->dev, "%s: found display endpoint\n", __func__);
2246 }
2247 }
2248
2249 if (ifnum == 0) {
2250 ictx->rx_endpoint_intf0 = rx_endpoint;
2251 /*
2252 * tx is used to send characters to lcd/vfd, associate RF
2253 * remotes, set IR protocol, and maybe more...
2254 */
2255 ictx->tx_endpoint = tx_endpoint;
2256 } else {
2257 ictx->rx_endpoint_intf1 = rx_endpoint;
2258 }
2259
2260 /*
2261 * If we didn't find a display endpoint, this is probably one of the
2262 * newer iMON devices that use control urb instead of interrupt
2263 */
2264 if (!display_ep_found) {
Jarod Wilsonf789bf42010-05-24 12:00:31 -03002265 tx_control = true;
2266 display_ep_found = true;
Mauro Carvalho Chehab25ec5872016-10-18 17:44:25 -02002267 dev_dbg(ictx->dev, "%s: device uses control endpoint, not interface OUT endpoint\n",
2268 __func__);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002269 }
2270
2271 /*
2272 * Some iMON receivers have no display. Unfortunately, it seems
2273 * that SoundGraph recycles device IDs between devices both with
2274 * and without... :\
2275 */
2276 if (ictx->display_type == IMON_DISPLAY_TYPE_NONE) {
Jarod Wilsonf789bf42010-05-24 12:00:31 -03002277 display_ep_found = false;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002278 dev_dbg(ictx->dev, "%s: device has no display\n", __func__);
2279 }
2280
2281 /*
2282 * iMON Touch devices have a VGA touchscreen, but no "display", as
2283 * that refers to e.g. /dev/lcd0 (a character device LCD or VFD).
2284 */
2285 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) {
Jarod Wilsonf789bf42010-05-24 12:00:31 -03002286 display_ep_found = false;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002287 dev_dbg(ictx->dev, "%s: iMON Touch device found\n", __func__);
2288 }
2289
2290 /* Input endpoint is mandatory */
2291 if (!ir_ep_found)
Joe Perchese2302502010-06-20 04:20:46 -03002292 pr_err("no valid input (IR) endpoint found\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -03002293
2294 ictx->tx_control = tx_control;
2295
2296 if (display_ep_found)
2297 ictx->display_supported = true;
2298
2299 return ir_ep_found;
2300
2301}
2302
Kevin Baradonf7d141b2013-04-22 16:09:44 -03002303static struct imon_context *imon_init_intf0(struct usb_interface *intf,
2304 const struct usb_device_id *id)
Jarod Wilson21677cf2010-04-16 18:29:02 -03002305{
2306 struct imon_context *ictx;
2307 struct urb *rx_urb;
2308 struct urb *tx_urb;
2309 struct device *dev = &intf->dev;
2310 struct usb_host_interface *iface_desc;
Mauro Carvalho Chehab1f71bae2010-04-20 19:11:30 -03002311 int ret = -ENOMEM;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002312
2313 ictx = kzalloc(sizeof(struct imon_context), GFP_KERNEL);
2314 if (!ictx) {
2315 dev_err(dev, "%s: kzalloc failed for context", __func__);
2316 goto exit;
2317 }
2318 rx_urb = usb_alloc_urb(0, GFP_KERNEL);
Wolfram Sang15241912016-08-11 18:03:39 -03002319 if (!rx_urb)
Jarod Wilson21677cf2010-04-16 18:29:02 -03002320 goto rx_urb_alloc_failed;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002321 tx_urb = usb_alloc_urb(0, GFP_KERNEL);
Wolfram Sang15241912016-08-11 18:03:39 -03002322 if (!tx_urb)
Jarod Wilson21677cf2010-04-16 18:29:02 -03002323 goto tx_urb_alloc_failed;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002324
2325 mutex_init(&ictx->lock);
Jarod Wilson693508d2010-09-15 15:56:03 -03002326 spin_lock_init(&ictx->kc_lock);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002327
2328 mutex_lock(&ictx->lock);
2329
2330 ictx->dev = dev;
2331 ictx->usbdev_intf0 = usb_get_dev(interface_to_usbdev(intf));
Jarod Wilson21677cf2010-04-16 18:29:02 -03002332 ictx->rx_urb_intf0 = rx_urb;
2333 ictx->tx_urb = tx_urb;
Jarod Wilsonbbe46902010-05-24 12:02:05 -03002334 ictx->rf_device = false;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002335
Daniel Wagner7c073ff2016-09-16 08:18:21 -03002336 init_completion(&ictx->tx.finished);
2337
Jarod Wilson21677cf2010-04-16 18:29:02 -03002338 ictx->vendor = le16_to_cpu(ictx->usbdev_intf0->descriptor.idVendor);
2339 ictx->product = le16_to_cpu(ictx->usbdev_intf0->descriptor.idProduct);
2340
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -03002341 /* save drive info for later accessing the panel/knob key table */
2342 ictx->dev_descr = (struct imon_usb_dev_descr *)id->driver_info;
Kevin Baradonf7d141b2013-04-22 16:09:44 -03002343 /* default send_packet delay is 5ms but some devices need more */
Ulrich Eckhardt0d8053f2014-07-26 14:56:01 -03002344 ictx->send_packet_delay = ictx->dev_descr->flags &
2345 IMON_NEED_20MS_PKT_DELAY ? 20 : 5;
Kevin Baradonf7d141b2013-04-22 16:09:44 -03002346
Mauro Carvalho Chehab1f71bae2010-04-20 19:11:30 -03002347 ret = -ENODEV;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002348 iface_desc = intf->cur_altsetting;
Mauro Carvalho Chehab1f71bae2010-04-20 19:11:30 -03002349 if (!imon_find_endpoints(ictx, iface_desc)) {
Jarod Wilson21677cf2010-04-16 18:29:02 -03002350 goto find_endpoint_failed;
Mauro Carvalho Chehab1f71bae2010-04-20 19:11:30 -03002351 }
Jarod Wilson21677cf2010-04-16 18:29:02 -03002352
Jarod Wilson21677cf2010-04-16 18:29:02 -03002353 usb_fill_int_urb(ictx->rx_urb_intf0, ictx->usbdev_intf0,
2354 usb_rcvintpipe(ictx->usbdev_intf0,
2355 ictx->rx_endpoint_intf0->bEndpointAddress),
2356 ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf),
2357 usb_rx_callback_intf0, ictx,
2358 ictx->rx_endpoint_intf0->bInterval);
2359
2360 ret = usb_submit_urb(ictx->rx_urb_intf0, GFP_KERNEL);
2361 if (ret) {
Joe Perchese2302502010-06-20 04:20:46 -03002362 pr_err("usb_submit_urb failed for intf0 (%d)\n", ret);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002363 goto urb_submit_failed;
2364 }
2365
Jarod Wilson9ad77eb2011-01-06 16:59:34 -03002366 ictx->idev = imon_init_idev(ictx);
2367 if (!ictx->idev) {
2368 dev_err(dev, "%s: input device setup failed\n", __func__);
2369 goto idev_setup_failed;
2370 }
2371
2372 ictx->rdev = imon_init_rdev(ictx);
2373 if (!ictx->rdev) {
2374 dev_err(dev, "%s: rc device setup failed\n", __func__);
2375 goto rdev_setup_failed;
2376 }
2377
Jarod Wilson6f6b90c2011-07-19 12:12:47 -03002378 ictx->dev_present_intf0 = true;
2379
Jarod Wilson23ef7102011-04-27 19:01:44 -03002380 mutex_unlock(&ictx->lock);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002381 return ictx;
2382
David Härdemaneaf2bcc2010-09-15 15:42:07 -03002383rdev_setup_failed:
2384 input_unregister_device(ictx->idev);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002385idev_setup_failed:
Jarod Wilson9ad77eb2011-01-06 16:59:34 -03002386 usb_kill_urb(ictx->rx_urb_intf0);
2387urb_submit_failed:
Jarod Wilson21677cf2010-04-16 18:29:02 -03002388find_endpoint_failed:
Alexey Khoroshilove87cb472014-09-15 18:36:15 -03002389 usb_put_dev(ictx->usbdev_intf0);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002390 mutex_unlock(&ictx->lock);
2391 usb_free_urb(tx_urb);
2392tx_urb_alloc_failed:
2393 usb_free_urb(rx_urb);
2394rx_urb_alloc_failed:
2395 kfree(ictx);
2396exit:
2397 dev_err(dev, "unable to initialize intf0, err %d\n", ret);
2398
2399 return NULL;
2400}
2401
2402static struct imon_context *imon_init_intf1(struct usb_interface *intf,
2403 struct imon_context *ictx)
2404{
2405 struct urb *rx_urb;
2406 struct usb_host_interface *iface_desc;
Mauro Carvalho Chehab1f71bae2010-04-20 19:11:30 -03002407 int ret = -ENOMEM;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002408
2409 rx_urb = usb_alloc_urb(0, GFP_KERNEL);
Wolfram Sang15241912016-08-11 18:03:39 -03002410 if (!rx_urb)
Jarod Wilson21677cf2010-04-16 18:29:02 -03002411 goto rx_urb_alloc_failed;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002412
2413 mutex_lock(&ictx->lock);
2414
2415 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) {
Geliang Tangbd742c62017-04-08 22:34:08 -03002416 setup_timer(&ictx->ttimer, imon_touch_display_timeout,
2417 (unsigned long)ictx);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002418 }
2419
2420 ictx->usbdev_intf1 = usb_get_dev(interface_to_usbdev(intf));
Jarod Wilson21677cf2010-04-16 18:29:02 -03002421 ictx->rx_urb_intf1 = rx_urb;
2422
Mauro Carvalho Chehab1f71bae2010-04-20 19:11:30 -03002423 ret = -ENODEV;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002424 iface_desc = intf->cur_altsetting;
2425 if (!imon_find_endpoints(ictx, iface_desc))
2426 goto find_endpoint_failed;
2427
2428 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) {
2429 ictx->touch = imon_init_touch(ictx);
2430 if (!ictx->touch)
2431 goto touch_setup_failed;
2432 } else
2433 ictx->touch = NULL;
2434
2435 usb_fill_int_urb(ictx->rx_urb_intf1, ictx->usbdev_intf1,
2436 usb_rcvintpipe(ictx->usbdev_intf1,
2437 ictx->rx_endpoint_intf1->bEndpointAddress),
2438 ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf),
2439 usb_rx_callback_intf1, ictx,
2440 ictx->rx_endpoint_intf1->bInterval);
2441
2442 ret = usb_submit_urb(ictx->rx_urb_intf1, GFP_KERNEL);
2443
2444 if (ret) {
Joe Perchese2302502010-06-20 04:20:46 -03002445 pr_err("usb_submit_urb failed for intf1 (%d)\n", ret);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002446 goto urb_submit_failed;
2447 }
2448
Jarod Wilson6f6b90c2011-07-19 12:12:47 -03002449 ictx->dev_present_intf1 = true;
2450
Jarod Wilson23ef7102011-04-27 19:01:44 -03002451 mutex_unlock(&ictx->lock);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002452 return ictx;
2453
2454urb_submit_failed:
Jarod Wilson20cd1952010-07-26 11:11:36 -03002455 if (ictx->touch)
Jarod Wilson21677cf2010-04-16 18:29:02 -03002456 input_unregister_device(ictx->touch);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002457touch_setup_failed:
2458find_endpoint_failed:
Alexey Khoroshilove87cb472014-09-15 18:36:15 -03002459 usb_put_dev(ictx->usbdev_intf1);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002460 mutex_unlock(&ictx->lock);
2461 usb_free_urb(rx_urb);
2462rx_urb_alloc_failed:
Jarod Wilson8791d632012-01-26 12:04:11 -03002463 dev_err(ictx->dev, "unable to initialize intf1, err %d\n", ret);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002464
2465 return NULL;
2466}
2467
Jarod Wilson21677cf2010-04-16 18:29:02 -03002468static void imon_init_display(struct imon_context *ictx,
2469 struct usb_interface *intf)
2470{
2471 int ret;
2472
2473 dev_dbg(ictx->dev, "Registering iMON display with sysfs\n");
2474
2475 /* set up sysfs entry for built-in clock */
Jarod Wilson6aa209e2010-10-23 16:42:51 -03002476 ret = sysfs_create_group(&intf->dev.kobj, &imon_display_attr_group);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002477 if (ret)
Mauro Carvalho Chehab25ec5872016-10-18 17:44:25 -02002478 dev_err(ictx->dev, "Could not create display sysfs entries(%d)",
2479 ret);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002480
2481 if (ictx->display_type == IMON_DISPLAY_TYPE_LCD)
2482 ret = usb_register_dev(intf, &imon_lcd_class);
2483 else
2484 ret = usb_register_dev(intf, &imon_vfd_class);
2485 if (ret)
2486 /* Not a fatal error, so ignore */
Mauro Carvalho Chehab25ec5872016-10-18 17:44:25 -02002487 dev_info(ictx->dev, "could not get a minor number for display\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -03002488
2489}
2490
2491/**
2492 * Callback function for USB core API: Probe
2493 */
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08002494static int imon_probe(struct usb_interface *interface,
2495 const struct usb_device_id *id)
Jarod Wilson21677cf2010-04-16 18:29:02 -03002496{
2497 struct usb_device *usbdev = NULL;
2498 struct usb_host_interface *iface_desc = NULL;
2499 struct usb_interface *first_if;
2500 struct device *dev = &interface->dev;
Jarod Wilson76a2d212011-04-28 18:20:58 -03002501 int ifnum, sysfs_err;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002502 int ret = 0;
2503 struct imon_context *ictx = NULL;
2504 struct imon_context *first_if_ctx = NULL;
2505 u16 vendor, product;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002506
Jarod Wilson21677cf2010-04-16 18:29:02 -03002507 usbdev = usb_get_dev(interface_to_usbdev(interface));
2508 iface_desc = interface->cur_altsetting;
2509 ifnum = iface_desc->desc.bInterfaceNumber;
2510 vendor = le16_to_cpu(usbdev->descriptor.idVendor);
2511 product = le16_to_cpu(usbdev->descriptor.idProduct);
2512
2513 dev_dbg(dev, "%s: found iMON device (%04x:%04x, intf%d)\n",
2514 __func__, vendor, product, ifnum);
2515
2516 /* prevent races probing devices w/multiple interfaces */
2517 mutex_lock(&driver_lock);
2518
2519 first_if = usb_ifnum_to_if(usbdev, 0);
Joe Perches8350e152010-11-30 18:42:07 -03002520 first_if_ctx = usb_get_intfdata(first_if);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002521
2522 if (ifnum == 0) {
Kevin Baradonf7d141b2013-04-22 16:09:44 -03002523 ictx = imon_init_intf0(interface, id);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002524 if (!ictx) {
Joe Perchese2302502010-06-20 04:20:46 -03002525 pr_err("failed to initialize context!\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -03002526 ret = -ENODEV;
2527 goto fail;
2528 }
2529
Jarod Wilson21677cf2010-04-16 18:29:02 -03002530 } else {
Kevin Baradon7d54ba02013-04-22 16:09:45 -03002531 /* this is the secondary interface on the device */
2532
2533 /* fail early if first intf failed to register */
2534 if (!first_if_ctx) {
2535 ret = -ENODEV;
2536 goto fail;
2537 }
2538
Jarod Wilson21677cf2010-04-16 18:29:02 -03002539 ictx = imon_init_intf1(interface, first_if_ctx);
2540 if (!ictx) {
Joe Perchese2302502010-06-20 04:20:46 -03002541 pr_err("failed to attach to context!\n");
Jarod Wilson21677cf2010-04-16 18:29:02 -03002542 ret = -ENODEV;
2543 goto fail;
2544 }
2545
2546 }
2547
2548 usb_set_intfdata(interface, ictx);
2549
2550 if (ifnum == 0) {
Jarod Wilson23ef7102011-04-27 19:01:44 -03002551 mutex_lock(&ictx->lock);
2552
Jarod Wilsonbbe46902010-05-24 12:02:05 -03002553 if (product == 0xffdc && ictx->rf_device) {
2554 sysfs_err = sysfs_create_group(&interface->dev.kobj,
Jarod Wilson6aa209e2010-10-23 16:42:51 -03002555 &imon_rf_attr_group);
Jarod Wilsonbbe46902010-05-24 12:02:05 -03002556 if (sysfs_err)
Joe Perchese2302502010-06-20 04:20:46 -03002557 pr_err("Could not create RF sysfs entries(%d)\n",
2558 sysfs_err);
Jarod Wilsonbbe46902010-05-24 12:02:05 -03002559 }
2560
Jarod Wilson21677cf2010-04-16 18:29:02 -03002561 if (ictx->display_supported)
2562 imon_init_display(ictx, interface);
Jarod Wilson23ef7102011-04-27 19:01:44 -03002563
2564 mutex_unlock(&ictx->lock);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002565 }
2566
Mauro Carvalho Chehab25ec5872016-10-18 17:44:25 -02002567 dev_info(dev, "iMON device (%04x:%04x, intf%d) on usb<%d:%d> initialized\n",
2568 vendor, product, ifnum,
Jarod Wilson21677cf2010-04-16 18:29:02 -03002569 usbdev->bus->busnum, usbdev->devnum);
2570
Jarod Wilson21677cf2010-04-16 18:29:02 -03002571 mutex_unlock(&driver_lock);
Alexey Khoroshilove87cb472014-09-15 18:36:15 -03002572 usb_put_dev(usbdev);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002573
2574 return 0;
2575
2576fail:
2577 mutex_unlock(&driver_lock);
Alexey Khoroshilove87cb472014-09-15 18:36:15 -03002578 usb_put_dev(usbdev);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002579 dev_err(dev, "unable to register, err %d\n", ret);
2580
2581 return ret;
2582}
2583
2584/**
2585 * Callback function for USB core API: disconnect
2586 */
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08002587static void imon_disconnect(struct usb_interface *interface)
Jarod Wilson21677cf2010-04-16 18:29:02 -03002588{
2589 struct imon_context *ictx;
2590 struct device *dev;
2591 int ifnum;
2592
2593 /* prevent races with multi-interface device probing and display_open */
2594 mutex_lock(&driver_lock);
2595
2596 ictx = usb_get_intfdata(interface);
2597 dev = ictx->dev;
2598 ifnum = interface->cur_altsetting->desc.bInterfaceNumber;
2599
Jarod Wilson21677cf2010-04-16 18:29:02 -03002600 /*
2601 * sysfs_remove_group is safe to call even if sysfs_create_group
2602 * hasn't been called
2603 */
Jarod Wilson6aa209e2010-10-23 16:42:51 -03002604 sysfs_remove_group(&interface->dev.kobj, &imon_display_attr_group);
2605 sysfs_remove_group(&interface->dev.kobj, &imon_rf_attr_group);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002606
2607 usb_set_intfdata(interface, NULL);
2608
2609 /* Abort ongoing write */
2610 if (ictx->tx.busy) {
2611 usb_kill_urb(ictx->tx_urb);
Daniel Wagner7c073ff2016-09-16 08:18:21 -03002612 complete(&ictx->tx.finished);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002613 }
2614
2615 if (ifnum == 0) {
Jarod Wilsonf789bf42010-05-24 12:00:31 -03002616 ictx->dev_present_intf0 = false;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002617 usb_kill_urb(ictx->rx_urb_intf0);
Alexey Khoroshilove87cb472014-09-15 18:36:15 -03002618 usb_put_dev(ictx->usbdev_intf0);
David Härdemaneaf2bcc2010-09-15 15:42:07 -03002619 input_unregister_device(ictx->idev);
David Härdemand8b4b582010-10-29 16:08:23 -03002620 rc_unregister_device(ictx->rdev);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002621 if (ictx->display_supported) {
2622 if (ictx->display_type == IMON_DISPLAY_TYPE_LCD)
2623 usb_deregister_dev(interface, &imon_lcd_class);
Jarod Wilson76a2d212011-04-28 18:20:58 -03002624 else if (ictx->display_type == IMON_DISPLAY_TYPE_VFD)
Jarod Wilson21677cf2010-04-16 18:29:02 -03002625 usb_deregister_dev(interface, &imon_vfd_class);
2626 }
2627 } else {
Jarod Wilsonf789bf42010-05-24 12:00:31 -03002628 ictx->dev_present_intf1 = false;
Jarod Wilson21677cf2010-04-16 18:29:02 -03002629 usb_kill_urb(ictx->rx_urb_intf1);
Alexey Khoroshilove87cb472014-09-15 18:36:15 -03002630 usb_put_dev(ictx->usbdev_intf1);
Jarod Wilson76a2d212011-04-28 18:20:58 -03002631 if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) {
Jarod Wilson21677cf2010-04-16 18:29:02 -03002632 input_unregister_device(ictx->touch);
Jarod Wilson76a2d212011-04-28 18:20:58 -03002633 del_timer_sync(&ictx->ttimer);
2634 }
Jarod Wilson21677cf2010-04-16 18:29:02 -03002635 }
2636
Jarod Wilson76a2d212011-04-28 18:20:58 -03002637 if (!ictx->dev_present_intf0 && !ictx->dev_present_intf1)
2638 free_imon_context(ictx);
Jarod Wilson21677cf2010-04-16 18:29:02 -03002639
2640 mutex_unlock(&driver_lock);
2641
2642 dev_dbg(dev, "%s: iMON device (intf%d) disconnected\n",
2643 __func__, ifnum);
2644}
2645
2646static int imon_suspend(struct usb_interface *intf, pm_message_t message)
2647{
2648 struct imon_context *ictx = usb_get_intfdata(intf);
2649 int ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
2650
2651 if (ifnum == 0)
2652 usb_kill_urb(ictx->rx_urb_intf0);
2653 else
2654 usb_kill_urb(ictx->rx_urb_intf1);
2655
2656 return 0;
2657}
2658
2659static int imon_resume(struct usb_interface *intf)
2660{
2661 int rc = 0;
2662 struct imon_context *ictx = usb_get_intfdata(intf);
2663 int ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
2664
2665 if (ifnum == 0) {
2666 usb_fill_int_urb(ictx->rx_urb_intf0, ictx->usbdev_intf0,
2667 usb_rcvintpipe(ictx->usbdev_intf0,
2668 ictx->rx_endpoint_intf0->bEndpointAddress),
2669 ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf),
2670 usb_rx_callback_intf0, ictx,
2671 ictx->rx_endpoint_intf0->bInterval);
2672
2673 rc = usb_submit_urb(ictx->rx_urb_intf0, GFP_ATOMIC);
2674
2675 } else {
2676 usb_fill_int_urb(ictx->rx_urb_intf1, ictx->usbdev_intf1,
2677 usb_rcvintpipe(ictx->usbdev_intf1,
2678 ictx->rx_endpoint_intf1->bEndpointAddress),
2679 ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf),
2680 usb_rx_callback_intf1, ictx,
2681 ictx->rx_endpoint_intf1->bInterval);
2682
2683 rc = usb_submit_urb(ictx->rx_urb_intf1, GFP_ATOMIC);
2684 }
2685
2686 return rc;
2687}
2688
Greg Kroah-Hartmanecb3b2b2011-11-18 09:46:12 -08002689module_usb_driver(imon_driver);