Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1 | /* |
| 2 | * imon.c: input and display driver for SoundGraph iMON IR/VFD/LCD |
| 3 | * |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 4 | * Copyright(C) 2010 Jarod Wilson <jarod@wilsonet.com> |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 5 | * 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 Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 23 | */ |
| 24 | |
Joe Perches | e230250 | 2010-06-20 04:20:46 -0300 | [diff] [blame] | 25 | #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ |
| 26 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 27 | #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 Wilson | 47a09b0 | 2011-07-14 14:20:46 -0300 | [diff] [blame] | 33 | #include <linux/ratelimit.h> |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 34 | |
| 35 | #include <linux/input.h> |
| 36 | #include <linux/usb.h> |
| 37 | #include <linux/usb/input.h> |
Mauro Carvalho Chehab | 6bda964 | 2010-11-17 13:28:38 -0300 | [diff] [blame] | 38 | #include <media/rc-core.h> |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 39 | |
| 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 Wilson | 8791d63 | 2012-01-26 12:04:11 -0300 | [diff] [blame] | 46 | #define MOD_VERSION "0.9.4" |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 47 | |
| 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 Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 57 | |
| 58 | /*** P R O T O T Y P E S ***/ |
| 59 | |
| 60 | /* USB Callback prototypes */ |
| 61 | static int imon_probe(struct usb_interface *interface, |
| 62 | const struct usb_device_id *id); |
| 63 | static void imon_disconnect(struct usb_interface *interface); |
| 64 | static void usb_rx_callback_intf0(struct urb *urb); |
| 65 | static void usb_rx_callback_intf1(struct urb *urb); |
| 66 | static void usb_tx_callback(struct urb *urb); |
| 67 | |
| 68 | /* suspend/resume support */ |
| 69 | static int imon_resume(struct usb_interface *intf); |
| 70 | static int imon_suspend(struct usb_interface *intf, pm_message_t message); |
| 71 | |
| 72 | /* Display file_operations function prototypes */ |
| 73 | static int display_open(struct inode *inode, struct file *file); |
| 74 | static int display_close(struct inode *inode, struct file *file); |
| 75 | |
| 76 | /* VFD write operation */ |
David Härdeman | d6740d8 | 2014-04-03 20:34:53 -0300 | [diff] [blame] | 77 | static ssize_t vfd_write(struct file *file, const char __user *buf, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 78 | size_t n_bytes, loff_t *pos); |
| 79 | |
| 80 | /* LCD file_operations override function prototypes */ |
David Härdeman | d6740d8 | 2014-04-03 20:34:53 -0300 | [diff] [blame] | 81 | static ssize_t lcd_write(struct file *file, const char __user *buf, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 82 | size_t n_bytes, loff_t *pos); |
| 83 | |
| 84 | /*** G L O B A L S ***/ |
| 85 | |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 86 | struct imon_panel_key_table { |
| 87 | u64 hw_code; |
| 88 | u32 keycode; |
| 89 | }; |
| 90 | |
| 91 | struct imon_usb_dev_descr { |
| 92 | __u16 flags; |
| 93 | #define IMON_NO_FLAGS 0 |
| 94 | #define IMON_NEED_20MS_PKT_DELAY 1 |
Sean Young | f41003a | 2016-12-20 12:18:06 -0200 | [diff] [blame] | 95 | #define IMON_IR_RAW 2 |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 96 | struct imon_panel_key_table key_table[]; |
| 97 | }; |
| 98 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 99 | struct imon_context { |
| 100 | struct device *dev; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 101 | /* 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 Wilson | bbe4690 | 2010-05-24 12:02:05 -0300 | [diff] [blame] | 107 | bool rf_device; /* true if iMON 2.4G LT/DT RF device */ |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 108 | 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 Baradon | 26ccbec | 2013-02-18 14:42:47 -0300 | [diff] [blame] | 124 | unsigned int send_packet_delay; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 125 | |
Sean Young | f41003a | 2016-12-20 12:18:06 -0200 | [diff] [blame] | 126 | 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 Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 132 | 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ärdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 142 | struct rc_dev *rdev; /* rc-core device for remote */ |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 143 | struct input_dev *idev; /* input device for panel & IR mouse */ |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 144 | struct input_dev *touch; /* input device for touchscreen */ |
| 145 | |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 146 | spinlock_t kc_lock; /* make sure we get keycodes right */ |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 147 | u32 kc; /* current input keycode */ |
| 148 | u32 last_keycode; /* last reported input keycode */ |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 149 | u32 rc_scancode; /* the computed remote scancode */ |
| 150 | u8 rc_toggle; /* the computed remote toggle bit */ |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 151 | u64 rc_proto; /* iMON or MCE (RC6) IR protocol? */ |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 152 | 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ärdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 157 | char name_rdev[128]; /* rc input device name */ |
| 158 | char phys_rdev[64]; /* rc input device phys path */ |
| 159 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 160 | char name_idev[128]; /* input device name */ |
| 161 | char phys_idev[64]; /* input device phys path */ |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 162 | |
| 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 Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 168 | struct imon_usb_dev_descr *dev_descr; /* device description with key |
| 169 | table for front panels */ |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | #define TOUCH_TIMEOUT (HZ/30) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 173 | |
| 174 | /* vfd character device file operations */ |
| 175 | static const struct file_operations vfd_fops = { |
| 176 | .owner = THIS_MODULE, |
| 177 | .open = &display_open, |
| 178 | .write = &vfd_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 179 | .release = &display_close, |
| 180 | .llseek = noop_llseek, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | /* lcd character device file operations */ |
| 184 | static const struct file_operations lcd_fops = { |
| 185 | .owner = THIS_MODULE, |
| 186 | .open = &display_open, |
| 187 | .write = &lcd_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 188 | .release = &display_close, |
| 189 | .llseek = noop_llseek, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 190 | }; |
| 191 | |
| 192 | enum { |
| 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 | |
| 200 | enum { |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 201 | IMON_KEY_IMON = 0, |
| 202 | IMON_KEY_MCE = 1, |
| 203 | IMON_KEY_PANEL = 2, |
| 204 | }; |
| 205 | |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 206 | static struct usb_class_driver imon_vfd_class = { |
| 207 | .name = DEVICE_NAME, |
| 208 | .fops = &vfd_fops, |
| 209 | .minor_base = DISPLAY_MINOR_BASE, |
| 210 | }; |
| 211 | |
| 212 | static 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 */ |
| 219 | static 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 | |
| 268 | static 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 Baradon | 26ccbec | 2013-02-18 14:42:47 -0300 | [diff] [blame] | 311 | }; |
| 312 | |
Ulrich Eckhardt | 7b5fc07 | 2014-07-26 14:59:07 -0300 | [diff] [blame] | 313 | /* imon receiver front panel/knob key table for DH102*/ |
| 314 | static 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 Young | f41003a | 2016-12-20 12:18:06 -0200 | [diff] [blame] | 334 | static const struct imon_usb_dev_descr imon_ir_raw = { |
| 335 | .flags = IMON_IR_RAW, |
| 336 | }; |
| 337 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 338 | /* |
| 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 | */ |
Arvind Yadav | 5fad16b | 2017-08-13 05:54:44 -0300 | [diff] [blame] | 349 | static const struct usb_device_id imon_usb_id_table[] = { |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 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 Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 356 | { USB_DEVICE(0x15c2, 0xffdc), |
| 357 | .driver_info = (unsigned long)&imon_default_table }, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 358 | |
| 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 Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 365 | { USB_DEVICE(0x15c2, 0x0034), |
Ulrich Eckhardt | 7b5fc07 | 2014-07-26 14:59:07 -0300 | [diff] [blame] | 366 | .driver_info = (unsigned long)&imon_DH102 }, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 367 | /* SoundGraph iMON OEM Touch LCD (IR & 4.3" VGA LCD) */ |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 368 | { USB_DEVICE(0x15c2, 0x0035), |
| 369 | .driver_info = (unsigned long)&imon_default_table}, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 370 | /* SoundGraph iMON OEM VFD (IR & VFD) */ |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 371 | { USB_DEVICE(0x15c2, 0x0036), |
| 372 | .driver_info = (unsigned long)&imon_OEM_VFD }, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 373 | /* device specifics unknown */ |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 374 | { USB_DEVICE(0x15c2, 0x0037), |
| 375 | .driver_info = (unsigned long)&imon_default_table}, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 376 | /* SoundGraph iMON OEM LCD (IR & LCD) */ |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 377 | { USB_DEVICE(0x15c2, 0x0038), |
| 378 | .driver_info = (unsigned long)&imon_default_table}, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 379 | /* SoundGraph iMON UltraBay (IR & LCD) */ |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 380 | { USB_DEVICE(0x15c2, 0x0039), |
| 381 | .driver_info = (unsigned long)&imon_default_table}, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 382 | /* device specifics unknown */ |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 383 | { USB_DEVICE(0x15c2, 0x003a), |
| 384 | .driver_info = (unsigned long)&imon_default_table}, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 385 | /* device specifics unknown */ |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 386 | { USB_DEVICE(0x15c2, 0x003b), |
| 387 | .driver_info = (unsigned long)&imon_default_table}, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 388 | /* SoundGraph iMON OEM Inside (IR only) */ |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 389 | { USB_DEVICE(0x15c2, 0x003c), |
| 390 | .driver_info = (unsigned long)&imon_default_table}, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 391 | /* device specifics unknown */ |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 392 | { USB_DEVICE(0x15c2, 0x003d), |
| 393 | .driver_info = (unsigned long)&imon_default_table}, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 394 | /* device specifics unknown */ |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 395 | { USB_DEVICE(0x15c2, 0x003e), |
| 396 | .driver_info = (unsigned long)&imon_default_table}, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 397 | /* device specifics unknown */ |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 398 | { USB_DEVICE(0x15c2, 0x003f), |
| 399 | .driver_info = (unsigned long)&imon_default_table}, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 400 | /* device specifics unknown */ |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 401 | { USB_DEVICE(0x15c2, 0x0040), |
| 402 | .driver_info = (unsigned long)&imon_default_table}, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 403 | /* SoundGraph iMON MINI (IR only) */ |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 404 | { USB_DEVICE(0x15c2, 0x0041), |
| 405 | .driver_info = (unsigned long)&imon_default_table}, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 406 | /* Antec Veris Multimedia Station EZ External (IR only) */ |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 407 | { USB_DEVICE(0x15c2, 0x0042), |
| 408 | .driver_info = (unsigned long)&imon_default_table}, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 409 | /* Antec Veris Multimedia Station Basic Internal (IR only) */ |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 410 | { USB_DEVICE(0x15c2, 0x0043), |
| 411 | .driver_info = (unsigned long)&imon_default_table}, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 412 | /* Antec Veris Multimedia Station Elite (IR & VFD) */ |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 413 | { USB_DEVICE(0x15c2, 0x0044), |
| 414 | .driver_info = (unsigned long)&imon_default_table}, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 415 | /* Antec Veris Multimedia Station Premiere (IR & LCD) */ |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 416 | { USB_DEVICE(0x15c2, 0x0045), |
| 417 | .driver_info = (unsigned long)&imon_default_table}, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 418 | /* device specifics unknown */ |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 419 | { USB_DEVICE(0x15c2, 0x0046), |
| 420 | .driver_info = (unsigned long)&imon_default_table}, |
Sean Young | f41003a | 2016-12-20 12:18:06 -0200 | [diff] [blame] | 421 | /* 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 Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 433 | {} |
| 434 | }; |
| 435 | |
| 436 | /* USB Device data */ |
| 437 | static struct usb_driver imon_driver = { |
| 438 | .name = MOD_NAME, |
| 439 | .probe = imon_probe, |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 440 | .disconnect = imon_disconnect, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 441 | .suspend = imon_suspend, |
| 442 | .resume = imon_resume, |
| 443 | .id_table = imon_usb_id_table, |
| 444 | }; |
| 445 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 446 | /* to prevent races between open() and disconnect(), probing, etc */ |
| 447 | static DEFINE_MUTEX(driver_lock); |
| 448 | |
| 449 | /* Module bookkeeping bits */ |
| 450 | MODULE_AUTHOR(MOD_AUTHOR); |
| 451 | MODULE_DESCRIPTION(MOD_DESC); |
| 452 | MODULE_VERSION(MOD_VERSION); |
| 453 | MODULE_LICENSE("GPL"); |
| 454 | MODULE_DEVICE_TABLE(usb, imon_usb_id_table); |
| 455 | |
| 456 | static bool debug; |
| 457 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
Jarod Wilson | 6aa209e | 2010-10-23 16:42:51 -0300 | [diff] [blame] | 458 | MODULE_PARM_DESC(debug, "Debug messages: 0=no, 1=yes (default: no)"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 459 | |
| 460 | /* lcd, vfd, vga or none? should be auto-detected, but can be overridden... */ |
| 461 | static int display_type; |
| 462 | module_param(display_type, int, S_IRUGO); |
Mauro Carvalho Chehab | 25ec587 | 2016-10-18 17:44:25 -0200 | [diff] [blame] | 463 | MODULE_PARM_DESC(display_type, "Type of attached display. 0=autodetect, 1=vfd, 2=lcd, 3=vga, 4=none (default: autodetect)"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 464 | |
Jarod Wilson | 6718e8ad | 2010-04-23 02:27:11 -0300 | [diff] [blame] | 465 | static int pad_stabilize = 1; |
| 466 | module_param(pad_stabilize, int, S_IRUGO | S_IWUSR); |
Mauro Carvalho Chehab | 25ec587 | 2016-10-18 17:44:25 -0200 | [diff] [blame] | 467 | MODULE_PARM_DESC(pad_stabilize, "Apply stabilization algorithm to iMON PAD presses in arrow key mode. 0=disable, 1=enable (default)."); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 468 | |
| 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 | */ |
| 473 | static bool nomouse; |
| 474 | module_param(nomouse, bool, S_IRUGO | S_IWUSR); |
Mauro Carvalho Chehab | 25ec587 | 2016-10-18 17:44:25 -0200 | [diff] [blame] | 475 | MODULE_PARM_DESC(nomouse, "Disable mouse input device mode when IR device is open. 0=don't disable, 1=disable. (default: don't disable)"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 476 | |
| 477 | /* threshold at which a pad push registers as an arrow key in kbd mode */ |
| 478 | static int pad_thresh; |
| 479 | module_param(pad_thresh, int, S_IRUGO | S_IWUSR); |
Mauro Carvalho Chehab | 25ec587 | 2016-10-18 17:44:25 -0200 | [diff] [blame] | 480 | MODULE_PARM_DESC(pad_thresh, "Threshold at which a pad push registers as an arrow key in kbd mode (default: 28)"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 481 | |
| 482 | |
| 483 | static 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 | |
Mauro Carvalho Chehab | 255940e | 2017-11-27 10:27:54 -0500 | [diff] [blame] | 495 | /* |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 496 | * Called when the Display device (e.g. /dev/lcd0) |
| 497 | * is opened by the application. |
| 498 | */ |
| 499 | static 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 Perches | e230250 | 2010-06-20 04:20:46 -0300 | [diff] [blame] | 512 | pr_err("could not find interface for minor %d\n", subminor); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 513 | retval = -ENODEV; |
| 514 | goto exit; |
| 515 | } |
| 516 | ictx = usb_get_intfdata(interface); |
| 517 | |
| 518 | if (!ictx) { |
Joe Perches | e230250 | 2010-06-20 04:20:46 -0300 | [diff] [blame] | 519 | pr_err("no context found for minor %d\n", subminor); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 520 | retval = -ENODEV; |
| 521 | goto exit; |
| 522 | } |
| 523 | |
| 524 | mutex_lock(&ictx->lock); |
| 525 | |
| 526 | if (!ictx->display_supported) { |
Joe Perches | e230250 | 2010-06-20 04:20:46 -0300 | [diff] [blame] | 527 | pr_err("display not supported by device\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 528 | retval = -ENODEV; |
| 529 | } else if (ictx->display_isopen) { |
Joe Perches | e230250 | 2010-06-20 04:20:46 -0300 | [diff] [blame] | 530 | pr_err("display port is already open\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 531 | retval = -EBUSY; |
| 532 | } else { |
Jarod Wilson | f789bf4 | 2010-05-24 12:00:31 -0300 | [diff] [blame] | 533 | ictx->display_isopen = true; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 534 | file->private_data = ictx; |
| 535 | dev_dbg(ictx->dev, "display port opened\n"); |
| 536 | } |
| 537 | |
| 538 | mutex_unlock(&ictx->lock); |
| 539 | |
| 540 | exit: |
| 541 | mutex_unlock(&driver_lock); |
| 542 | return retval; |
| 543 | } |
| 544 | |
Mauro Carvalho Chehab | 255940e | 2017-11-27 10:27:54 -0500 | [diff] [blame] | 545 | /* |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 546 | * Called when the display device (e.g. /dev/lcd0) |
| 547 | * is closed by the application. |
| 548 | */ |
| 549 | static int display_close(struct inode *inode, struct file *file) |
| 550 | { |
| 551 | struct imon_context *ictx = NULL; |
| 552 | int retval = 0; |
| 553 | |
Joe Perches | abf8438 | 2010-07-12 17:50:03 -0300 | [diff] [blame] | 554 | ictx = file->private_data; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 555 | |
| 556 | if (!ictx) { |
Joe Perches | e230250 | 2010-06-20 04:20:46 -0300 | [diff] [blame] | 557 | pr_err("no context for device\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 558 | return -ENODEV; |
| 559 | } |
| 560 | |
| 561 | mutex_lock(&ictx->lock); |
| 562 | |
| 563 | if (!ictx->display_supported) { |
Joe Perches | e230250 | 2010-06-20 04:20:46 -0300 | [diff] [blame] | 564 | pr_err("display not supported by device\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 565 | retval = -ENODEV; |
| 566 | } else if (!ictx->display_isopen) { |
Joe Perches | e230250 | 2010-06-20 04:20:46 -0300 | [diff] [blame] | 567 | pr_err("display is not open\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 568 | retval = -EIO; |
| 569 | } else { |
Jarod Wilson | f789bf4 | 2010-05-24 12:00:31 -0300 | [diff] [blame] | 570 | ictx->display_isopen = false; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 571 | dev_dbg(ictx->dev, "display port closed\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | mutex_unlock(&ictx->lock); |
| 575 | return retval; |
| 576 | } |
| 577 | |
Mauro Carvalho Chehab | 255940e | 2017-11-27 10:27:54 -0500 | [diff] [blame] | 578 | /* |
Jarod Wilson | 23ef710 | 2011-04-27 19:01:44 -0300 | [diff] [blame] | 579 | * 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 Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 582 | */ |
| 583 | static 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: */ |
Markus Elfring | a8c779e | 2017-08-29 07:45:59 -0300 | [diff] [blame] | 605 | control_req = kmalloc(sizeof(*control_req), GFP_KERNEL); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 606 | if (control_req == NULL) |
| 607 | return -ENOMEM; |
| 608 | |
| 609 | /* setup packet is '21 09 0200 0001 0008' */ |
| 610 | control_req->bRequestType = 0x21; |
| 611 | control_req->bRequest = 0x09; |
| 612 | control_req->wValue = cpu_to_le16(0x0200); |
| 613 | control_req->wIndex = cpu_to_le16(0x0001); |
| 614 | control_req->wLength = cpu_to_le16(0x0008); |
| 615 | |
| 616 | /* control pipe is endpoint 0x00 */ |
| 617 | pipe = usb_sndctrlpipe(ictx->usbdev_intf0, 0); |
| 618 | |
| 619 | /* build the control urb */ |
| 620 | usb_fill_control_urb(ictx->tx_urb, ictx->usbdev_intf0, |
| 621 | pipe, (unsigned char *)control_req, |
| 622 | ictx->usb_tx_buf, |
| 623 | sizeof(ictx->usb_tx_buf), |
| 624 | usb_tx_callback, ictx); |
| 625 | ictx->tx_urb->actual_length = 0; |
| 626 | } |
| 627 | |
Daniel Wagner | 7c073ff | 2016-09-16 08:18:21 -0300 | [diff] [blame] | 628 | reinit_completion(&ictx->tx.finished); |
Jarod Wilson | f789bf4 | 2010-05-24 12:00:31 -0300 | [diff] [blame] | 629 | ictx->tx.busy = true; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 630 | smp_rmb(); /* ensure later readers know we're busy */ |
| 631 | |
| 632 | retval = usb_submit_urb(ictx->tx_urb, GFP_KERNEL); |
| 633 | if (retval) { |
Jarod Wilson | f789bf4 | 2010-05-24 12:00:31 -0300 | [diff] [blame] | 634 | ictx->tx.busy = false; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 635 | smp_rmb(); /* ensure later readers know we're not busy */ |
Jarod Wilson | 47a09b0 | 2011-07-14 14:20:46 -0300 | [diff] [blame] | 636 | pr_err_ratelimited("error submitting urb(%d)\n", retval); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 637 | } else { |
| 638 | /* Wait for transmission to complete (or abort) */ |
| 639 | mutex_unlock(&ictx->lock); |
| 640 | retval = wait_for_completion_interruptible( |
| 641 | &ictx->tx.finished); |
Kevin Baradon | 5f3f254 | 2013-04-22 16:09:46 -0300 | [diff] [blame] | 642 | if (retval) { |
| 643 | usb_kill_urb(ictx->tx_urb); |
Jarod Wilson | 47a09b0 | 2011-07-14 14:20:46 -0300 | [diff] [blame] | 644 | pr_err_ratelimited("task interrupted\n"); |
Kevin Baradon | 5f3f254 | 2013-04-22 16:09:46 -0300 | [diff] [blame] | 645 | } |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 646 | mutex_lock(&ictx->lock); |
| 647 | |
| 648 | retval = ictx->tx.status; |
| 649 | if (retval) |
Jarod Wilson | 47a09b0 | 2011-07-14 14:20:46 -0300 | [diff] [blame] | 650 | pr_err_ratelimited("packet tx failed (%d)\n", retval); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | kfree(control_req); |
| 654 | |
| 655 | /* |
Kevin Baradon | 26ccbec | 2013-02-18 14:42:47 -0300 | [diff] [blame] | 656 | * Induce a mandatory delay before returning, as otherwise, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 657 | * send_packet can get called so rapidly as to overwhelm the device, |
| 658 | * particularly on faster systems and/or those with quirky usb. |
| 659 | */ |
Kevin Baradon | 26ccbec | 2013-02-18 14:42:47 -0300 | [diff] [blame] | 660 | timeout = msecs_to_jiffies(ictx->send_packet_delay); |
| 661 | set_current_state(TASK_INTERRUPTIBLE); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 662 | schedule_timeout(timeout); |
| 663 | |
| 664 | return retval; |
| 665 | } |
| 666 | |
Mauro Carvalho Chehab | 255940e | 2017-11-27 10:27:54 -0500 | [diff] [blame] | 667 | /* |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 668 | * Sends an associate packet to the iMON 2.4G. |
| 669 | * |
| 670 | * This might not be such a good idea, since it has an id collision with |
| 671 | * some versions of the "IR & VFD" combo. The only way to determine if it |
| 672 | * is an RF version is to look at the product description string. (Which |
| 673 | * we currently do not fetch). |
| 674 | */ |
| 675 | static int send_associate_24g(struct imon_context *ictx) |
| 676 | { |
| 677 | int retval; |
| 678 | const unsigned char packet[8] = { 0x01, 0x00, 0x00, 0x00, |
| 679 | 0x00, 0x00, 0x00, 0x20 }; |
| 680 | |
| 681 | if (!ictx) { |
Joe Perches | e230250 | 2010-06-20 04:20:46 -0300 | [diff] [blame] | 682 | pr_err("no context for device\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 683 | return -ENODEV; |
| 684 | } |
| 685 | |
| 686 | if (!ictx->dev_present_intf0) { |
Joe Perches | e230250 | 2010-06-20 04:20:46 -0300 | [diff] [blame] | 687 | pr_err("no iMON device present\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 688 | return -ENODEV; |
| 689 | } |
| 690 | |
| 691 | memcpy(ictx->usb_tx_buf, packet, sizeof(packet)); |
| 692 | retval = send_packet(ictx); |
| 693 | |
| 694 | return retval; |
| 695 | } |
| 696 | |
Mauro Carvalho Chehab | 255940e | 2017-11-27 10:27:54 -0500 | [diff] [blame] | 697 | /* |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 698 | * Sends packets to setup and show clock on iMON display |
| 699 | * |
| 700 | * Arguments: year - last 2 digits of year, month - 1..12, |
| 701 | * day - 1..31, dow - day of the week (0-Sun...6-Sat), |
| 702 | * hour - 0..23, minute - 0..59, second - 0..59 |
| 703 | */ |
| 704 | static int send_set_imon_clock(struct imon_context *ictx, |
| 705 | unsigned int year, unsigned int month, |
| 706 | unsigned int day, unsigned int dow, |
| 707 | unsigned int hour, unsigned int minute, |
| 708 | unsigned int second) |
| 709 | { |
| 710 | unsigned char clock_enable_pkt[IMON_CLOCK_ENABLE_PACKETS][8]; |
| 711 | int retval = 0; |
| 712 | int i; |
| 713 | |
| 714 | if (!ictx) { |
Joe Perches | e230250 | 2010-06-20 04:20:46 -0300 | [diff] [blame] | 715 | pr_err("no context for device\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 716 | return -ENODEV; |
| 717 | } |
| 718 | |
| 719 | switch (ictx->display_type) { |
| 720 | case IMON_DISPLAY_TYPE_LCD: |
| 721 | clock_enable_pkt[0][0] = 0x80; |
| 722 | clock_enable_pkt[0][1] = year; |
| 723 | clock_enable_pkt[0][2] = month-1; |
| 724 | clock_enable_pkt[0][3] = day; |
| 725 | clock_enable_pkt[0][4] = hour; |
| 726 | clock_enable_pkt[0][5] = minute; |
| 727 | clock_enable_pkt[0][6] = second; |
| 728 | |
| 729 | clock_enable_pkt[1][0] = 0x80; |
| 730 | clock_enable_pkt[1][1] = 0; |
| 731 | clock_enable_pkt[1][2] = 0; |
| 732 | clock_enable_pkt[1][3] = 0; |
| 733 | clock_enable_pkt[1][4] = 0; |
| 734 | clock_enable_pkt[1][5] = 0; |
| 735 | clock_enable_pkt[1][6] = 0; |
| 736 | |
| 737 | if (ictx->product == 0xffdc) { |
| 738 | clock_enable_pkt[0][7] = 0x50; |
| 739 | clock_enable_pkt[1][7] = 0x51; |
| 740 | } else { |
| 741 | clock_enable_pkt[0][7] = 0x88; |
| 742 | clock_enable_pkt[1][7] = 0x8a; |
| 743 | } |
| 744 | |
| 745 | break; |
| 746 | |
| 747 | case IMON_DISPLAY_TYPE_VFD: |
| 748 | clock_enable_pkt[0][0] = year; |
| 749 | clock_enable_pkt[0][1] = month-1; |
| 750 | clock_enable_pkt[0][2] = day; |
| 751 | clock_enable_pkt[0][3] = dow; |
| 752 | clock_enable_pkt[0][4] = hour; |
| 753 | clock_enable_pkt[0][5] = minute; |
| 754 | clock_enable_pkt[0][6] = second; |
| 755 | clock_enable_pkt[0][7] = 0x40; |
| 756 | |
| 757 | clock_enable_pkt[1][0] = 0; |
| 758 | clock_enable_pkt[1][1] = 0; |
| 759 | clock_enable_pkt[1][2] = 1; |
| 760 | clock_enable_pkt[1][3] = 0; |
| 761 | clock_enable_pkt[1][4] = 0; |
| 762 | clock_enable_pkt[1][5] = 0; |
| 763 | clock_enable_pkt[1][6] = 0; |
| 764 | clock_enable_pkt[1][7] = 0x42; |
| 765 | |
| 766 | break; |
| 767 | |
| 768 | default: |
| 769 | return -ENODEV; |
| 770 | } |
| 771 | |
| 772 | for (i = 0; i < IMON_CLOCK_ENABLE_PACKETS; i++) { |
| 773 | memcpy(ictx->usb_tx_buf, clock_enable_pkt[i], 8); |
| 774 | retval = send_packet(ictx); |
| 775 | if (retval) { |
Joe Perches | e230250 | 2010-06-20 04:20:46 -0300 | [diff] [blame] | 776 | pr_err("send_packet failed for packet %d\n", i); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 777 | break; |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | return retval; |
| 782 | } |
| 783 | |
Mauro Carvalho Chehab | 255940e | 2017-11-27 10:27:54 -0500 | [diff] [blame] | 784 | /* |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 785 | * These are the sysfs functions to handle the association on the iMON 2.4G LT. |
| 786 | */ |
| 787 | static ssize_t show_associate_remote(struct device *d, |
| 788 | struct device_attribute *attr, |
| 789 | char *buf) |
| 790 | { |
| 791 | struct imon_context *ictx = dev_get_drvdata(d); |
| 792 | |
| 793 | if (!ictx) |
| 794 | return -ENODEV; |
| 795 | |
| 796 | mutex_lock(&ictx->lock); |
| 797 | if (ictx->rf_isassociating) |
| 798 | strcpy(buf, "associating\n"); |
| 799 | else |
| 800 | strcpy(buf, "closed\n"); |
| 801 | |
Mauro Carvalho Chehab | 25ec587 | 2016-10-18 17:44:25 -0200 | [diff] [blame] | 802 | 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 Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 803 | mutex_unlock(&ictx->lock); |
| 804 | return strlen(buf); |
| 805 | } |
| 806 | |
| 807 | static ssize_t store_associate_remote(struct device *d, |
| 808 | struct device_attribute *attr, |
| 809 | const char *buf, size_t count) |
| 810 | { |
| 811 | struct imon_context *ictx; |
| 812 | |
| 813 | ictx = dev_get_drvdata(d); |
| 814 | |
| 815 | if (!ictx) |
| 816 | return -ENODEV; |
| 817 | |
| 818 | mutex_lock(&ictx->lock); |
Jarod Wilson | f789bf4 | 2010-05-24 12:00:31 -0300 | [diff] [blame] | 819 | ictx->rf_isassociating = true; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 820 | send_associate_24g(ictx); |
| 821 | mutex_unlock(&ictx->lock); |
| 822 | |
| 823 | return count; |
| 824 | } |
| 825 | |
Mauro Carvalho Chehab | 255940e | 2017-11-27 10:27:54 -0500 | [diff] [blame] | 826 | /* |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 827 | * sysfs functions to control internal imon clock |
| 828 | */ |
| 829 | static ssize_t show_imon_clock(struct device *d, |
| 830 | struct device_attribute *attr, char *buf) |
| 831 | { |
| 832 | struct imon_context *ictx = dev_get_drvdata(d); |
| 833 | size_t len; |
| 834 | |
| 835 | if (!ictx) |
| 836 | return -ENODEV; |
| 837 | |
| 838 | mutex_lock(&ictx->lock); |
| 839 | |
| 840 | if (!ictx->display_supported) { |
| 841 | len = snprintf(buf, PAGE_SIZE, "Not supported."); |
| 842 | } else { |
| 843 | len = snprintf(buf, PAGE_SIZE, |
| 844 | "To set the clock on your iMON display:\n" |
| 845 | "# date \"+%%y %%m %%d %%w %%H %%M %%S\" > imon_clock\n" |
| 846 | "%s", ictx->display_isopen ? |
| 847 | "\nNOTE: imon device must be closed\n" : ""); |
| 848 | } |
| 849 | |
| 850 | mutex_unlock(&ictx->lock); |
| 851 | |
| 852 | return len; |
| 853 | } |
| 854 | |
| 855 | static ssize_t store_imon_clock(struct device *d, |
| 856 | struct device_attribute *attr, |
| 857 | const char *buf, size_t count) |
| 858 | { |
| 859 | struct imon_context *ictx = dev_get_drvdata(d); |
| 860 | ssize_t retval; |
| 861 | unsigned int year, month, day, dow, hour, minute, second; |
| 862 | |
| 863 | if (!ictx) |
| 864 | return -ENODEV; |
| 865 | |
| 866 | mutex_lock(&ictx->lock); |
| 867 | |
| 868 | if (!ictx->display_supported) { |
| 869 | retval = -ENODEV; |
| 870 | goto exit; |
| 871 | } else if (ictx->display_isopen) { |
| 872 | retval = -EBUSY; |
| 873 | goto exit; |
| 874 | } |
| 875 | |
| 876 | if (sscanf(buf, "%u %u %u %u %u %u %u", &year, &month, &day, &dow, |
| 877 | &hour, &minute, &second) != 7) { |
| 878 | retval = -EINVAL; |
| 879 | goto exit; |
| 880 | } |
| 881 | |
| 882 | if ((month < 1 || month > 12) || |
| 883 | (day < 1 || day > 31) || (dow > 6) || |
| 884 | (hour > 23) || (minute > 59) || (second > 59)) { |
| 885 | retval = -EINVAL; |
| 886 | goto exit; |
| 887 | } |
| 888 | |
| 889 | retval = send_set_imon_clock(ictx, year, month, day, dow, |
| 890 | hour, minute, second); |
| 891 | if (retval) |
| 892 | goto exit; |
| 893 | |
| 894 | retval = count; |
| 895 | exit: |
| 896 | mutex_unlock(&ictx->lock); |
| 897 | |
| 898 | return retval; |
| 899 | } |
| 900 | |
| 901 | |
| 902 | static DEVICE_ATTR(imon_clock, S_IWUSR | S_IRUGO, show_imon_clock, |
| 903 | store_imon_clock); |
| 904 | |
| 905 | static DEVICE_ATTR(associate_remote, S_IWUSR | S_IRUGO, show_associate_remote, |
| 906 | store_associate_remote); |
| 907 | |
| 908 | static struct attribute *imon_display_sysfs_entries[] = { |
| 909 | &dev_attr_imon_clock.attr, |
| 910 | NULL |
| 911 | }; |
| 912 | |
Arvind Yadav | d9a77b9 | 2017-07-07 04:15:12 -0400 | [diff] [blame] | 913 | static const struct attribute_group imon_display_attr_group = { |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 914 | .attrs = imon_display_sysfs_entries |
| 915 | }; |
| 916 | |
| 917 | static struct attribute *imon_rf_sysfs_entries[] = { |
| 918 | &dev_attr_associate_remote.attr, |
| 919 | NULL |
| 920 | }; |
| 921 | |
Arvind Yadav | d9a77b9 | 2017-07-07 04:15:12 -0400 | [diff] [blame] | 922 | static const struct attribute_group imon_rf_attr_group = { |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 923 | .attrs = imon_rf_sysfs_entries |
| 924 | }; |
| 925 | |
Mauro Carvalho Chehab | 255940e | 2017-11-27 10:27:54 -0500 | [diff] [blame] | 926 | /* |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 927 | * Writes data to the VFD. The iMON VFD is 2x16 characters |
| 928 | * and requires data in 5 consecutive USB interrupt packets, |
| 929 | * each packet but the last carrying 7 bytes. |
| 930 | * |
| 931 | * I don't know if the VFD board supports features such as |
| 932 | * scrolling, clearing rows, blanking, etc. so at |
| 933 | * the caller must provide a full screen of data. If fewer |
| 934 | * than 32 bytes are provided spaces will be appended to |
| 935 | * generate a full screen. |
| 936 | */ |
David Härdeman | d6740d8 | 2014-04-03 20:34:53 -0300 | [diff] [blame] | 937 | static ssize_t vfd_write(struct file *file, const char __user *buf, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 938 | size_t n_bytes, loff_t *pos) |
| 939 | { |
| 940 | int i; |
| 941 | int offset; |
| 942 | int seq; |
| 943 | int retval = 0; |
| 944 | struct imon_context *ictx; |
Colin Ian King | c25895c | 2017-09-05 09:07:50 -0300 | [diff] [blame] | 945 | static const unsigned char vfd_packet6[] = { |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 946 | 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF }; |
| 947 | |
Joe Perches | abf8438 | 2010-07-12 17:50:03 -0300 | [diff] [blame] | 948 | ictx = file->private_data; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 949 | if (!ictx) { |
Jarod Wilson | 47a09b0 | 2011-07-14 14:20:46 -0300 | [diff] [blame] | 950 | pr_err_ratelimited("no context for device\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 951 | return -ENODEV; |
| 952 | } |
| 953 | |
| 954 | mutex_lock(&ictx->lock); |
| 955 | |
| 956 | if (!ictx->dev_present_intf0) { |
Jarod Wilson | 47a09b0 | 2011-07-14 14:20:46 -0300 | [diff] [blame] | 957 | pr_err_ratelimited("no iMON device present\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 958 | retval = -ENODEV; |
| 959 | goto exit; |
| 960 | } |
| 961 | |
| 962 | if (n_bytes <= 0 || n_bytes > 32) { |
Jarod Wilson | 47a09b0 | 2011-07-14 14:20:46 -0300 | [diff] [blame] | 963 | pr_err_ratelimited("invalid payload size\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 964 | retval = -EINVAL; |
| 965 | goto exit; |
| 966 | } |
| 967 | |
| 968 | if (copy_from_user(ictx->tx.data_buf, buf, n_bytes)) { |
| 969 | retval = -EFAULT; |
| 970 | goto exit; |
| 971 | } |
| 972 | |
| 973 | /* Pad with spaces */ |
| 974 | for (i = n_bytes; i < 32; ++i) |
| 975 | ictx->tx.data_buf[i] = ' '; |
| 976 | |
| 977 | for (i = 32; i < 35; ++i) |
| 978 | ictx->tx.data_buf[i] = 0xFF; |
| 979 | |
| 980 | offset = 0; |
| 981 | seq = 0; |
| 982 | |
| 983 | do { |
| 984 | memcpy(ictx->usb_tx_buf, ictx->tx.data_buf + offset, 7); |
| 985 | ictx->usb_tx_buf[7] = (unsigned char) seq; |
| 986 | |
| 987 | retval = send_packet(ictx); |
| 988 | if (retval) { |
Jarod Wilson | 47a09b0 | 2011-07-14 14:20:46 -0300 | [diff] [blame] | 989 | pr_err_ratelimited("send packet #%d failed\n", seq / 2); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 990 | goto exit; |
| 991 | } else { |
| 992 | seq += 2; |
| 993 | offset += 7; |
| 994 | } |
| 995 | |
| 996 | } while (offset < 35); |
| 997 | |
| 998 | /* Send packet #6 */ |
| 999 | memcpy(ictx->usb_tx_buf, &vfd_packet6, sizeof(vfd_packet6)); |
| 1000 | ictx->usb_tx_buf[7] = (unsigned char) seq; |
| 1001 | retval = send_packet(ictx); |
| 1002 | if (retval) |
Jarod Wilson | 47a09b0 | 2011-07-14 14:20:46 -0300 | [diff] [blame] | 1003 | pr_err_ratelimited("send packet #%d failed\n", seq / 2); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1004 | |
| 1005 | exit: |
| 1006 | mutex_unlock(&ictx->lock); |
| 1007 | |
| 1008 | return (!retval) ? n_bytes : retval; |
| 1009 | } |
| 1010 | |
Mauro Carvalho Chehab | 255940e | 2017-11-27 10:27:54 -0500 | [diff] [blame] | 1011 | /* |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1012 | * Writes data to the LCD. The iMON OEM LCD screen expects 8-byte |
| 1013 | * packets. We accept data as 16 hexadecimal digits, followed by a |
| 1014 | * newline (to make it easy to drive the device from a command-line |
| 1015 | * -- even though the actual binary data is a bit complicated). |
| 1016 | * |
| 1017 | * The device itself is not a "traditional" text-mode display. It's |
| 1018 | * actually a 16x96 pixel bitmap display. That means if you want to |
| 1019 | * display text, you've got to have your own "font" and translate the |
| 1020 | * text into bitmaps for display. This is really flexible (you can |
| 1021 | * display whatever diacritics you need, and so on), but it's also |
| 1022 | * a lot more complicated than most LCDs... |
| 1023 | */ |
David Härdeman | d6740d8 | 2014-04-03 20:34:53 -0300 | [diff] [blame] | 1024 | static ssize_t lcd_write(struct file *file, const char __user *buf, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1025 | size_t n_bytes, loff_t *pos) |
| 1026 | { |
| 1027 | int retval = 0; |
| 1028 | struct imon_context *ictx; |
| 1029 | |
Joe Perches | abf8438 | 2010-07-12 17:50:03 -0300 | [diff] [blame] | 1030 | ictx = file->private_data; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1031 | if (!ictx) { |
Jarod Wilson | 47a09b0 | 2011-07-14 14:20:46 -0300 | [diff] [blame] | 1032 | pr_err_ratelimited("no context for device\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1033 | return -ENODEV; |
| 1034 | } |
| 1035 | |
| 1036 | mutex_lock(&ictx->lock); |
| 1037 | |
| 1038 | if (!ictx->display_supported) { |
Jarod Wilson | 47a09b0 | 2011-07-14 14:20:46 -0300 | [diff] [blame] | 1039 | pr_err_ratelimited("no iMON display present\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1040 | retval = -ENODEV; |
| 1041 | goto exit; |
| 1042 | } |
| 1043 | |
| 1044 | if (n_bytes != 8) { |
Jarod Wilson | 47a09b0 | 2011-07-14 14:20:46 -0300 | [diff] [blame] | 1045 | pr_err_ratelimited("invalid payload size: %d (expected 8)\n", |
| 1046 | (int)n_bytes); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1047 | retval = -EINVAL; |
| 1048 | goto exit; |
| 1049 | } |
| 1050 | |
| 1051 | if (copy_from_user(ictx->usb_tx_buf, buf, 8)) { |
| 1052 | retval = -EFAULT; |
| 1053 | goto exit; |
| 1054 | } |
| 1055 | |
| 1056 | retval = send_packet(ictx); |
| 1057 | if (retval) { |
Jarod Wilson | 47a09b0 | 2011-07-14 14:20:46 -0300 | [diff] [blame] | 1058 | pr_err_ratelimited("send packet failed!\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1059 | goto exit; |
| 1060 | } else { |
| 1061 | dev_dbg(ictx->dev, "%s: write %d bytes to LCD\n", |
| 1062 | __func__, (int) n_bytes); |
| 1063 | } |
| 1064 | exit: |
| 1065 | mutex_unlock(&ictx->lock); |
| 1066 | return (!retval) ? n_bytes : retval; |
| 1067 | } |
| 1068 | |
Mauro Carvalho Chehab | 255940e | 2017-11-27 10:27:54 -0500 | [diff] [blame] | 1069 | /* |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1070 | * Callback function for USB core API: transmit data |
| 1071 | */ |
| 1072 | static void usb_tx_callback(struct urb *urb) |
| 1073 | { |
| 1074 | struct imon_context *ictx; |
| 1075 | |
| 1076 | if (!urb) |
| 1077 | return; |
| 1078 | ictx = (struct imon_context *)urb->context; |
| 1079 | if (!ictx) |
| 1080 | return; |
| 1081 | |
| 1082 | ictx->tx.status = urb->status; |
| 1083 | |
| 1084 | /* notify waiters that write has finished */ |
Jarod Wilson | f789bf4 | 2010-05-24 12:00:31 -0300 | [diff] [blame] | 1085 | ictx->tx.busy = false; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1086 | smp_rmb(); /* ensure later readers know we're not busy */ |
| 1087 | complete(&ictx->tx.finished); |
| 1088 | } |
| 1089 | |
Mauro Carvalho Chehab | 255940e | 2017-11-27 10:27:54 -0500 | [diff] [blame] | 1090 | /* |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1091 | * report touchscreen input |
| 1092 | */ |
Kees Cook | b17ec78 | 2017-10-24 11:23:14 -0400 | [diff] [blame] | 1093 | static void imon_touch_display_timeout(struct timer_list *t) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1094 | { |
Kees Cook | b17ec78 | 2017-10-24 11:23:14 -0400 | [diff] [blame] | 1095 | struct imon_context *ictx = from_timer(ictx, t, ttimer); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1096 | |
Dan Carpenter | f03900d | 2010-05-04 08:37:33 -0300 | [diff] [blame] | 1097 | if (ictx->display_type != IMON_DISPLAY_TYPE_VGA) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1098 | return; |
| 1099 | |
| 1100 | input_report_abs(ictx->touch, ABS_X, ictx->touch_x); |
| 1101 | input_report_abs(ictx->touch, ABS_Y, ictx->touch_y); |
| 1102 | input_report_key(ictx->touch, BTN_TOUCH, 0x00); |
| 1103 | input_sync(ictx->touch); |
| 1104 | } |
| 1105 | |
Mauro Carvalho Chehab | 255940e | 2017-11-27 10:27:54 -0500 | [diff] [blame] | 1106 | /* |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1107 | * iMON IR receivers support two different signal sets -- those used by |
| 1108 | * the iMON remotes, and those used by the Windows MCE remotes (which is |
| 1109 | * really just RC-6), but only one or the other at a time, as the signals |
| 1110 | * are decoded onboard the receiver. |
Jarod Wilson | 23ef710 | 2011-04-27 19:01:44 -0300 | [diff] [blame] | 1111 | * |
| 1112 | * This function gets called two different ways, one way is from |
| 1113 | * rc_register_device, for initial protocol selection/setup, and the other is |
| 1114 | * via a userspace-initiated protocol change request, either by direct sysfs |
| 1115 | * prodding or by something like ir-keytable. In the rc_register_device case, |
| 1116 | * the imon context lock is already held, but when initiated from userspace, |
| 1117 | * it is not, so we must acquire it prior to calling send_packet, which |
| 1118 | * requires that the lock is held. |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1119 | */ |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1120 | static int imon_ir_change_protocol(struct rc_dev *rc, u64 *rc_proto) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1121 | { |
| 1122 | int retval; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1123 | struct imon_context *ictx = rc->priv; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1124 | struct device *dev = ictx->dev; |
Jarod Wilson | 23ef710 | 2011-04-27 19:01:44 -0300 | [diff] [blame] | 1125 | bool unlock = false; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1126 | unsigned char ir_proto_packet[] = { |
| 1127 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86 }; |
| 1128 | |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1129 | if (*rc_proto && !(*rc_proto & rc->allowed_protocols)) |
Mauro Carvalho Chehab | 25ec587 | 2016-10-18 17:44:25 -0200 | [diff] [blame] | 1130 | dev_warn(dev, "Looks like you're trying to use an IR protocol this device does not support\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1131 | |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1132 | if (*rc_proto & RC_PROTO_BIT_RC6_MCE) { |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1133 | dev_dbg(dev, "Configuring IR receiver for MCE protocol\n"); |
| 1134 | ir_proto_packet[0] = 0x01; |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1135 | *rc_proto = RC_PROTO_BIT_RC6_MCE; |
| 1136 | } else if (*rc_proto & RC_PROTO_BIT_OTHER) { |
Jarod Wilson | 666a9ed | 2010-04-28 14:37:29 -0300 | [diff] [blame] | 1137 | dev_dbg(dev, "Configuring IR receiver for iMON protocol\n"); |
Jarod Wilson | 76f1ef4 | 2011-01-06 16:59:35 -0300 | [diff] [blame] | 1138 | if (!pad_stabilize) |
Jarod Wilson | 666a9ed | 2010-04-28 14:37:29 -0300 | [diff] [blame] | 1139 | dev_dbg(dev, "PAD stabilize functionality disabled\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1140 | /* ir_proto_packet[0] = 0x00; // already the default */ |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1141 | *rc_proto = RC_PROTO_BIT_OTHER; |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 1142 | } else { |
Mauro Carvalho Chehab | 25ec587 | 2016-10-18 17:44:25 -0200 | [diff] [blame] | 1143 | dev_warn(dev, "Unsupported IR protocol specified, overriding to iMON IR protocol\n"); |
Jarod Wilson | 76f1ef4 | 2011-01-06 16:59:35 -0300 | [diff] [blame] | 1144 | if (!pad_stabilize) |
Jarod Wilson | 666a9ed | 2010-04-28 14:37:29 -0300 | [diff] [blame] | 1145 | dev_dbg(dev, "PAD stabilize functionality disabled\n"); |
Jarod Wilson | 6718e8ad | 2010-04-23 02:27:11 -0300 | [diff] [blame] | 1146 | /* ir_proto_packet[0] = 0x00; // already the default */ |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1147 | *rc_proto = RC_PROTO_BIT_OTHER; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | memcpy(ictx->usb_tx_buf, &ir_proto_packet, sizeof(ir_proto_packet)); |
| 1151 | |
Jarod Wilson | 23ef710 | 2011-04-27 19:01:44 -0300 | [diff] [blame] | 1152 | if (!mutex_is_locked(&ictx->lock)) { |
| 1153 | unlock = true; |
| 1154 | mutex_lock(&ictx->lock); |
| 1155 | } |
| 1156 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1157 | retval = send_packet(ictx); |
Jarod Wilson | 6718e8ad | 2010-04-23 02:27:11 -0300 | [diff] [blame] | 1158 | if (retval) |
| 1159 | goto out; |
| 1160 | |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1161 | ictx->rc_proto = *rc_proto; |
Jarod Wilson | 76f1ef4 | 2011-01-06 16:59:35 -0300 | [diff] [blame] | 1162 | ictx->pad_mouse = false; |
Jarod Wilson | 6718e8ad | 2010-04-23 02:27:11 -0300 | [diff] [blame] | 1163 | |
| 1164 | out: |
Jarod Wilson | 23ef710 | 2011-04-27 19:01:44 -0300 | [diff] [blame] | 1165 | if (unlock) |
| 1166 | mutex_unlock(&ictx->lock); |
| 1167 | |
Jarod Wilson | 6718e8ad | 2010-04-23 02:27:11 -0300 | [diff] [blame] | 1168 | return retval; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | static inline int tv2int(const struct timeval *a, const struct timeval *b) |
| 1172 | { |
| 1173 | int usecs = 0; |
| 1174 | int sec = 0; |
| 1175 | |
| 1176 | if (b->tv_usec > a->tv_usec) { |
| 1177 | usecs = 1000000; |
| 1178 | sec--; |
| 1179 | } |
| 1180 | |
| 1181 | usecs += a->tv_usec - b->tv_usec; |
| 1182 | |
| 1183 | sec += a->tv_sec - b->tv_sec; |
| 1184 | sec *= 1000; |
| 1185 | usecs /= 1000; |
| 1186 | sec += usecs; |
| 1187 | |
| 1188 | if (sec < 0) |
| 1189 | sec = 1000; |
| 1190 | |
| 1191 | return sec; |
| 1192 | } |
| 1193 | |
Mauro Carvalho Chehab | 255940e | 2017-11-27 10:27:54 -0500 | [diff] [blame] | 1194 | /* |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1195 | * The directional pad behaves a bit differently, depending on whether this is |
| 1196 | * one of the older ffdc devices or a newer device. Newer devices appear to |
| 1197 | * have a higher resolution matrix for more precise mouse movement, but it |
| 1198 | * makes things overly sensitive in keyboard mode, so we do some interesting |
| 1199 | * contortions to make it less touchy. Older devices run through the same |
| 1200 | * routine with shorter timeout and a smaller threshold. |
| 1201 | */ |
| 1202 | static int stabilize(int a, int b, u16 timeout, u16 threshold) |
| 1203 | { |
| 1204 | struct timeval ct; |
| 1205 | static struct timeval prev_time = {0, 0}; |
| 1206 | static struct timeval hit_time = {0, 0}; |
| 1207 | static int x, y, prev_result, hits; |
| 1208 | int result = 0; |
| 1209 | int msec, msec_hit; |
| 1210 | |
| 1211 | do_gettimeofday(&ct); |
| 1212 | msec = tv2int(&ct, &prev_time); |
| 1213 | msec_hit = tv2int(&ct, &hit_time); |
| 1214 | |
| 1215 | if (msec > 100) { |
| 1216 | x = 0; |
| 1217 | y = 0; |
| 1218 | hits = 0; |
| 1219 | } |
| 1220 | |
| 1221 | x += a; |
| 1222 | y += b; |
| 1223 | |
| 1224 | prev_time = ct; |
| 1225 | |
| 1226 | if (abs(x) > threshold || abs(y) > threshold) { |
| 1227 | if (abs(y) > abs(x)) |
| 1228 | result = (y > 0) ? 0x7F : 0x80; |
| 1229 | else |
| 1230 | result = (x > 0) ? 0x7F00 : 0x8000; |
| 1231 | |
| 1232 | x = 0; |
| 1233 | y = 0; |
| 1234 | |
| 1235 | if (result == prev_result) { |
| 1236 | hits++; |
| 1237 | |
| 1238 | if (hits > 3) { |
| 1239 | switch (result) { |
| 1240 | case 0x7F: |
| 1241 | y = 17 * threshold / 30; |
| 1242 | break; |
| 1243 | case 0x80: |
| 1244 | y -= 17 * threshold / 30; |
| 1245 | break; |
| 1246 | case 0x7F00: |
| 1247 | x = 17 * threshold / 30; |
| 1248 | break; |
| 1249 | case 0x8000: |
| 1250 | x -= 17 * threshold / 30; |
| 1251 | break; |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | if (hits == 2 && msec_hit < timeout) { |
| 1256 | result = 0; |
| 1257 | hits = 1; |
| 1258 | } |
| 1259 | } else { |
| 1260 | prev_result = result; |
| 1261 | hits = 1; |
| 1262 | hit_time = ct; |
| 1263 | } |
| 1264 | } |
| 1265 | |
| 1266 | return result; |
| 1267 | } |
| 1268 | |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1269 | static u32 imon_remote_key_lookup(struct imon_context *ictx, u32 scancode) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1270 | { |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1271 | u32 keycode; |
| 1272 | u32 release; |
| 1273 | bool is_release_code = false; |
| 1274 | |
| 1275 | /* Look for the initial press of a button */ |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 1276 | keycode = rc_g_keycode_from_table(ictx->rdev, scancode); |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1277 | ictx->rc_toggle = 0x0; |
| 1278 | ictx->rc_scancode = scancode; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1279 | |
| 1280 | /* Look for the release of a button */ |
| 1281 | if (keycode == KEY_RESERVED) { |
| 1282 | release = scancode & ~0x4000; |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 1283 | keycode = rc_g_keycode_from_table(ictx->rdev, release); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1284 | if (keycode != KEY_RESERVED) |
| 1285 | is_release_code = true; |
| 1286 | } |
| 1287 | |
| 1288 | ictx->release_code = is_release_code; |
| 1289 | |
| 1290 | return keycode; |
| 1291 | } |
| 1292 | |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1293 | static u32 imon_mce_key_lookup(struct imon_context *ictx, u32 scancode) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1294 | { |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1295 | u32 keycode; |
| 1296 | |
| 1297 | #define MCE_KEY_MASK 0x7000 |
| 1298 | #define MCE_TOGGLE_BIT 0x8000 |
| 1299 | |
| 1300 | /* |
| 1301 | * On some receivers, mce keys decode to 0x8000f04xx and 0x8000f84xx |
| 1302 | * (the toggle bit flipping between alternating key presses), while |
| 1303 | * on other receivers, we see 0x8000f74xx and 0x8000ff4xx. To keep |
| 1304 | * the table trim, we always or in the bits to look up 0x8000ff4xx, |
| 1305 | * but we can't or them into all codes, as some keys are decoded in |
| 1306 | * a different way w/o the same use of the toggle bit... |
| 1307 | */ |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1308 | if (scancode & 0x80000000) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1309 | scancode = scancode | MCE_KEY_MASK | MCE_TOGGLE_BIT; |
| 1310 | |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1311 | ictx->rc_scancode = scancode; |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 1312 | keycode = rc_g_keycode_from_table(ictx->rdev, scancode); |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1313 | |
| 1314 | /* not used in mce mode, but make sure we know its false */ |
| 1315 | ictx->release_code = false; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1316 | |
| 1317 | return keycode; |
| 1318 | } |
| 1319 | |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 1320 | static u32 imon_panel_key_lookup(struct imon_context *ictx, u64 code) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1321 | { |
| 1322 | int i; |
Jarod Wilson | 083e472 | 2010-05-04 16:17:05 -0300 | [diff] [blame] | 1323 | u32 keycode = KEY_RESERVED; |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 1324 | struct imon_panel_key_table *key_table = ictx->dev_descr->key_table; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1325 | |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 1326 | for (i = 0; key_table[i].hw_code != 0; i++) { |
| 1327 | if (key_table[i].hw_code == (code | 0xffee)) { |
| 1328 | keycode = key_table[i].keycode; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1329 | break; |
Jarod Wilson | 083e472 | 2010-05-04 16:17:05 -0300 | [diff] [blame] | 1330 | } |
| 1331 | } |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 1332 | ictx->release_code = false; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1333 | return keycode; |
| 1334 | } |
| 1335 | |
| 1336 | static bool imon_mouse_event(struct imon_context *ictx, |
| 1337 | unsigned char *buf, int len) |
| 1338 | { |
Alexandre Lissy | 24dec5d | 2012-09-02 15:35:20 -0300 | [diff] [blame] | 1339 | signed char rel_x = 0x00, rel_y = 0x00; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1340 | u8 right_shift = 1; |
Jarod Wilson | f789bf4 | 2010-05-24 12:00:31 -0300 | [diff] [blame] | 1341 | bool mouse_input = true; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1342 | int dir = 0; |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1343 | unsigned long flags; |
| 1344 | |
| 1345 | spin_lock_irqsave(&ictx->kc_lock, flags); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1346 | |
| 1347 | /* newer iMON device PAD or mouse button */ |
| 1348 | if (ictx->product != 0xffdc && (buf[0] & 0x01) && len == 5) { |
| 1349 | rel_x = buf[2]; |
| 1350 | rel_y = buf[3]; |
| 1351 | right_shift = 1; |
| 1352 | /* 0xffdc iMON PAD or mouse button input */ |
| 1353 | } else if (ictx->product == 0xffdc && (buf[0] & 0x40) && |
| 1354 | !((buf[1] & 0x01) || ((buf[1] >> 2) & 0x01))) { |
| 1355 | rel_x = (buf[1] & 0x08) | (buf[1] & 0x10) >> 2 | |
| 1356 | (buf[1] & 0x20) >> 4 | (buf[1] & 0x40) >> 6; |
| 1357 | if (buf[0] & 0x02) |
| 1358 | rel_x |= ~0x0f; |
| 1359 | rel_x = rel_x + rel_x / 2; |
| 1360 | rel_y = (buf[2] & 0x08) | (buf[2] & 0x10) >> 2 | |
| 1361 | (buf[2] & 0x20) >> 4 | (buf[2] & 0x40) >> 6; |
| 1362 | if (buf[0] & 0x01) |
| 1363 | rel_y |= ~0x0f; |
| 1364 | rel_y = rel_y + rel_y / 2; |
| 1365 | right_shift = 2; |
| 1366 | /* some ffdc devices decode mouse buttons differently... */ |
| 1367 | } else if (ictx->product == 0xffdc && (buf[0] == 0x68)) { |
| 1368 | right_shift = 2; |
| 1369 | /* ch+/- buttons, which we use for an emulated scroll wheel */ |
| 1370 | } else if (ictx->kc == KEY_CHANNELUP && (buf[2] & 0x40) != 0x40) { |
| 1371 | dir = 1; |
| 1372 | } else if (ictx->kc == KEY_CHANNELDOWN && (buf[2] & 0x40) != 0x40) { |
| 1373 | dir = -1; |
| 1374 | } else |
Jarod Wilson | f789bf4 | 2010-05-24 12:00:31 -0300 | [diff] [blame] | 1375 | mouse_input = false; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1376 | |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1377 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
| 1378 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1379 | if (mouse_input) { |
| 1380 | dev_dbg(ictx->dev, "sending mouse data via input subsystem\n"); |
| 1381 | |
| 1382 | if (dir) { |
| 1383 | input_report_rel(ictx->idev, REL_WHEEL, dir); |
| 1384 | } else if (rel_x || rel_y) { |
| 1385 | input_report_rel(ictx->idev, REL_X, rel_x); |
| 1386 | input_report_rel(ictx->idev, REL_Y, rel_y); |
| 1387 | } else { |
| 1388 | input_report_key(ictx->idev, BTN_LEFT, buf[1] & 0x1); |
| 1389 | input_report_key(ictx->idev, BTN_RIGHT, |
| 1390 | buf[1] >> right_shift & 0x1); |
| 1391 | } |
| 1392 | input_sync(ictx->idev); |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1393 | spin_lock_irqsave(&ictx->kc_lock, flags); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1394 | ictx->last_keycode = ictx->kc; |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1395 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | return mouse_input; |
| 1399 | } |
| 1400 | |
| 1401 | static void imon_touch_event(struct imon_context *ictx, unsigned char *buf) |
| 1402 | { |
| 1403 | mod_timer(&ictx->ttimer, jiffies + TOUCH_TIMEOUT); |
| 1404 | ictx->touch_x = (buf[0] << 4) | (buf[1] >> 4); |
| 1405 | ictx->touch_y = 0xfff - ((buf[2] << 4) | (buf[1] & 0xf)); |
| 1406 | input_report_abs(ictx->touch, ABS_X, ictx->touch_x); |
| 1407 | input_report_abs(ictx->touch, ABS_Y, ictx->touch_y); |
| 1408 | input_report_key(ictx->touch, BTN_TOUCH, 0x01); |
| 1409 | input_sync(ictx->touch); |
| 1410 | } |
| 1411 | |
| 1412 | static void imon_pad_to_keys(struct imon_context *ictx, unsigned char *buf) |
| 1413 | { |
| 1414 | int dir = 0; |
Alexandre Lissy | 24dec5d | 2012-09-02 15:35:20 -0300 | [diff] [blame] | 1415 | signed char rel_x = 0x00, rel_y = 0x00; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1416 | u16 timeout, threshold; |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1417 | u32 scancode = KEY_RESERVED; |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1418 | unsigned long flags; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1419 | |
| 1420 | /* |
| 1421 | * The imon directional pad functions more like a touchpad. Bytes 3 & 4 |
| 1422 | * contain a position coordinate (x,y), with each component ranging |
| 1423 | * from -14 to 14. We want to down-sample this to only 4 discrete values |
| 1424 | * for up/down/left/right arrow keys. Also, when you get too close to |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1425 | * diagonals, it has a tendency to jump back and forth, so lets try to |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1426 | * ignore when they get too close. |
| 1427 | */ |
| 1428 | if (ictx->product != 0xffdc) { |
| 1429 | /* first, pad to 8 bytes so it conforms with everything else */ |
| 1430 | buf[5] = buf[6] = buf[7] = 0; |
| 1431 | timeout = 500; /* in msecs */ |
| 1432 | /* (2*threshold) x (2*threshold) square */ |
| 1433 | threshold = pad_thresh ? pad_thresh : 28; |
| 1434 | rel_x = buf[2]; |
| 1435 | rel_y = buf[3]; |
| 1436 | |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1437 | if (ictx->rc_proto == RC_PROTO_BIT_OTHER && pad_stabilize) { |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1438 | if ((buf[1] == 0) && ((rel_x != 0) || (rel_y != 0))) { |
| 1439 | dir = stabilize((int)rel_x, (int)rel_y, |
| 1440 | timeout, threshold); |
| 1441 | if (!dir) { |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1442 | spin_lock_irqsave(&ictx->kc_lock, |
| 1443 | flags); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1444 | ictx->kc = KEY_UNKNOWN; |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1445 | spin_unlock_irqrestore(&ictx->kc_lock, |
| 1446 | flags); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1447 | return; |
| 1448 | } |
| 1449 | buf[2] = dir & 0xFF; |
| 1450 | buf[3] = (dir >> 8) & 0xFF; |
Hans Verkuil | d778d25 | 2014-08-20 19:34:33 -0300 | [diff] [blame] | 1451 | scancode = be32_to_cpu(*((__be32 *)buf)); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1452 | } |
| 1453 | } else { |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1454 | /* |
| 1455 | * Hack alert: instead of using keycodes, we have |
| 1456 | * to use hard-coded scancodes here... |
| 1457 | */ |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1458 | if (abs(rel_y) > abs(rel_x)) { |
| 1459 | buf[2] = (rel_y > 0) ? 0x7F : 0x80; |
| 1460 | buf[3] = 0; |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1461 | if (rel_y > 0) |
| 1462 | scancode = 0x01007f00; /* KEY_DOWN */ |
| 1463 | else |
| 1464 | scancode = 0x01008000; /* KEY_UP */ |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1465 | } else { |
| 1466 | buf[2] = 0; |
| 1467 | buf[3] = (rel_x > 0) ? 0x7F : 0x80; |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1468 | if (rel_x > 0) |
| 1469 | scancode = 0x0100007f; /* KEY_RIGHT */ |
| 1470 | else |
| 1471 | scancode = 0x01000080; /* KEY_LEFT */ |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1472 | } |
| 1473 | } |
| 1474 | |
| 1475 | /* |
| 1476 | * Handle on-board decoded pad events for e.g. older VFD/iMON-Pad |
| 1477 | * device (15c2:ffdc). The remote generates various codes from |
| 1478 | * 0x68nnnnB7 to 0x6AnnnnB7, the left mouse button generates |
| 1479 | * 0x688301b7 and the right one 0x688481b7. All other keys generate |
| 1480 | * 0x2nnnnnnn. Position coordinate is encoded in buf[1] and buf[2] with |
Jonathan McCrohan | 39c1cb2 | 2013-10-20 21:34:01 -0300 | [diff] [blame] | 1481 | * reversed endianness. Extract direction from buffer, rotate endianness, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1482 | * adjust sign and feed the values into stabilize(). The resulting codes |
| 1483 | * will be 0x01008000, 0x01007F00, which match the newer devices. |
| 1484 | */ |
| 1485 | } else { |
| 1486 | timeout = 10; /* in msecs */ |
| 1487 | /* (2*threshold) x (2*threshold) square */ |
| 1488 | threshold = pad_thresh ? pad_thresh : 15; |
| 1489 | |
| 1490 | /* buf[1] is x */ |
| 1491 | rel_x = (buf[1] & 0x08) | (buf[1] & 0x10) >> 2 | |
| 1492 | (buf[1] & 0x20) >> 4 | (buf[1] & 0x40) >> 6; |
| 1493 | if (buf[0] & 0x02) |
| 1494 | rel_x |= ~0x10+1; |
| 1495 | /* buf[2] is y */ |
| 1496 | rel_y = (buf[2] & 0x08) | (buf[2] & 0x10) >> 2 | |
| 1497 | (buf[2] & 0x20) >> 4 | (buf[2] & 0x40) >> 6; |
| 1498 | if (buf[0] & 0x01) |
| 1499 | rel_y |= ~0x10+1; |
| 1500 | |
| 1501 | buf[0] = 0x01; |
| 1502 | buf[1] = buf[4] = buf[5] = buf[6] = buf[7] = 0; |
| 1503 | |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1504 | if (ictx->rc_proto == RC_PROTO_BIT_OTHER && pad_stabilize) { |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1505 | dir = stabilize((int)rel_x, (int)rel_y, |
| 1506 | timeout, threshold); |
| 1507 | if (!dir) { |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1508 | spin_lock_irqsave(&ictx->kc_lock, flags); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1509 | ictx->kc = KEY_UNKNOWN; |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1510 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1511 | return; |
| 1512 | } |
| 1513 | buf[2] = dir & 0xFF; |
| 1514 | buf[3] = (dir >> 8) & 0xFF; |
Hans Verkuil | d778d25 | 2014-08-20 19:34:33 -0300 | [diff] [blame] | 1515 | scancode = be32_to_cpu(*((__be32 *)buf)); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1516 | } else { |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1517 | /* |
| 1518 | * Hack alert: instead of using keycodes, we have |
| 1519 | * to use hard-coded scancodes here... |
| 1520 | */ |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1521 | if (abs(rel_y) > abs(rel_x)) { |
| 1522 | buf[2] = (rel_y > 0) ? 0x7F : 0x80; |
| 1523 | buf[3] = 0; |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1524 | if (rel_y > 0) |
| 1525 | scancode = 0x01007f00; /* KEY_DOWN */ |
| 1526 | else |
| 1527 | scancode = 0x01008000; /* KEY_UP */ |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1528 | } else { |
| 1529 | buf[2] = 0; |
| 1530 | buf[3] = (rel_x > 0) ? 0x7F : 0x80; |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1531 | if (rel_x > 0) |
| 1532 | scancode = 0x0100007f; /* KEY_RIGHT */ |
| 1533 | else |
| 1534 | scancode = 0x01000080; /* KEY_LEFT */ |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1535 | } |
| 1536 | } |
| 1537 | } |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1538 | |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1539 | if (scancode) { |
| 1540 | spin_lock_irqsave(&ictx->kc_lock, flags); |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1541 | ictx->kc = imon_remote_key_lookup(ictx, scancode); |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1542 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
| 1543 | } |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1544 | } |
| 1545 | |
Mauro Carvalho Chehab | 255940e | 2017-11-27 10:27:54 -0500 | [diff] [blame] | 1546 | /* |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1547 | * figure out if these is a press or a release. We don't actually |
| 1548 | * care about repeats, as those will be auto-generated within the IR |
| 1549 | * subsystem for repeating scancodes. |
| 1550 | */ |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1551 | static int imon_parse_press_type(struct imon_context *ictx, |
| 1552 | unsigned char *buf, u8 ktype) |
| 1553 | { |
| 1554 | int press_type = 0; |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1555 | unsigned long flags; |
| 1556 | |
| 1557 | spin_lock_irqsave(&ictx->kc_lock, flags); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1558 | |
| 1559 | /* key release of 0x02XXXXXX key */ |
| 1560 | if (ictx->kc == KEY_RESERVED && buf[0] == 0x02 && buf[3] == 0x00) |
| 1561 | ictx->kc = ictx->last_keycode; |
| 1562 | |
| 1563 | /* mouse button release on (some) 0xffdc devices */ |
| 1564 | else if (ictx->kc == KEY_RESERVED && buf[0] == 0x68 && buf[1] == 0x82 && |
| 1565 | buf[2] == 0x81 && buf[3] == 0xb7) |
| 1566 | ictx->kc = ictx->last_keycode; |
| 1567 | |
| 1568 | /* mouse button release on (some other) 0xffdc devices */ |
| 1569 | else if (ictx->kc == KEY_RESERVED && buf[0] == 0x01 && buf[1] == 0x00 && |
| 1570 | buf[2] == 0x81 && buf[3] == 0xb7) |
| 1571 | ictx->kc = ictx->last_keycode; |
| 1572 | |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1573 | /* mce-specific button handling, no keyup events */ |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1574 | else if (ktype == IMON_KEY_MCE) { |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1575 | ictx->rc_toggle = buf[2]; |
| 1576 | press_type = 1; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1577 | |
| 1578 | /* incoherent or irrelevant data */ |
| 1579 | } else if (ictx->kc == KEY_RESERVED) |
| 1580 | press_type = -EINVAL; |
| 1581 | |
| 1582 | /* key release of 0xXXXXXXb7 key */ |
| 1583 | else if (ictx->release_code) |
| 1584 | press_type = 0; |
| 1585 | |
| 1586 | /* this is a button press */ |
| 1587 | else |
| 1588 | press_type = 1; |
| 1589 | |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1590 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
| 1591 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1592 | return press_type; |
| 1593 | } |
| 1594 | |
Mauro Carvalho Chehab | 255940e | 2017-11-27 10:27:54 -0500 | [diff] [blame] | 1595 | /* |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1596 | * Process the incoming packet |
| 1597 | */ |
Mauro Carvalho Chehab | 255940e | 2017-11-27 10:27:54 -0500 | [diff] [blame] | 1598 | /* |
Sean Young | f41003a | 2016-12-20 12:18:06 -0200 | [diff] [blame] | 1599 | * Convert bit count to time duration (in us) and submit |
| 1600 | * the value to lirc_dev. |
| 1601 | */ |
| 1602 | static void submit_data(struct imon_context *context) |
| 1603 | { |
| 1604 | DEFINE_IR_RAW_EVENT(ev); |
| 1605 | |
| 1606 | ev.pulse = context->rx.prev_bit; |
| 1607 | ev.duration = US_TO_NS(context->rx.count * BIT_DURATION); |
| 1608 | ir_raw_event_store_with_filter(context->rdev, &ev); |
| 1609 | } |
| 1610 | |
Mauro Carvalho Chehab | 255940e | 2017-11-27 10:27:54 -0500 | [diff] [blame] | 1611 | /* |
Sean Young | f41003a | 2016-12-20 12:18:06 -0200 | [diff] [blame] | 1612 | * Process the incoming packet |
| 1613 | */ |
| 1614 | static void imon_incoming_ir_raw(struct imon_context *context, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1615 | struct urb *urb, int intf) |
| 1616 | { |
| 1617 | int len = urb->actual_length; |
| 1618 | unsigned char *buf = urb->transfer_buffer; |
Sean Young | f41003a | 2016-12-20 12:18:06 -0200 | [diff] [blame] | 1619 | struct device *dev = context->dev; |
| 1620 | int octet, bit; |
| 1621 | unsigned char mask; |
| 1622 | |
| 1623 | if (len != 8) { |
| 1624 | dev_warn(dev, "imon %s: invalid incoming packet size (len = %d, intf%d)\n", |
| 1625 | __func__, len, intf); |
| 1626 | return; |
| 1627 | } |
| 1628 | |
| 1629 | if (debug) |
| 1630 | dev_info(dev, "raw packet: %*ph\n", len, buf); |
| 1631 | /* |
| 1632 | * Translate received data to pulse and space lengths. |
| 1633 | * Received data is active low, i.e. pulses are 0 and |
| 1634 | * spaces are 1. |
| 1635 | * |
| 1636 | * My original algorithm was essentially similar to |
| 1637 | * Changwoo Ryu's with the exception that he switched |
| 1638 | * the incoming bits to active high and also fed an |
| 1639 | * initial space to LIRC at the start of a new sequence |
| 1640 | * if the previous bit was a pulse. |
| 1641 | * |
| 1642 | * I've decided to adopt his algorithm. |
| 1643 | */ |
| 1644 | |
| 1645 | if (buf[7] == 1 && context->rx.initial_space) { |
| 1646 | /* LIRC requires a leading space */ |
| 1647 | context->rx.prev_bit = 0; |
| 1648 | context->rx.count = 4; |
| 1649 | submit_data(context); |
| 1650 | context->rx.count = 0; |
| 1651 | } |
| 1652 | |
| 1653 | for (octet = 0; octet < 5; ++octet) { |
| 1654 | mask = 0x80; |
| 1655 | for (bit = 0; bit < 8; ++bit) { |
| 1656 | int curr_bit = !(buf[octet] & mask); |
| 1657 | |
| 1658 | if (curr_bit != context->rx.prev_bit) { |
| 1659 | if (context->rx.count) { |
| 1660 | submit_data(context); |
| 1661 | context->rx.count = 0; |
| 1662 | } |
| 1663 | context->rx.prev_bit = curr_bit; |
| 1664 | } |
| 1665 | ++context->rx.count; |
| 1666 | mask >>= 1; |
| 1667 | } |
| 1668 | } |
| 1669 | |
| 1670 | if (buf[7] == 10) { |
| 1671 | if (context->rx.count) { |
| 1672 | submit_data(context); |
| 1673 | context->rx.count = 0; |
| 1674 | } |
| 1675 | context->rx.initial_space = context->rx.prev_bit; |
| 1676 | } |
| 1677 | |
| 1678 | ir_raw_event_handle(context->rdev); |
| 1679 | } |
| 1680 | |
| 1681 | static void imon_incoming_scancode(struct imon_context *ictx, |
| 1682 | struct urb *urb, int intf) |
| 1683 | { |
| 1684 | int len = urb->actual_length; |
| 1685 | unsigned char *buf = urb->transfer_buffer; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1686 | struct device *dev = ictx->dev; |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1687 | unsigned long flags; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1688 | u32 kc; |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1689 | u64 scancode; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1690 | int press_type = 0; |
| 1691 | int msec; |
| 1692 | struct timeval t; |
| 1693 | static struct timeval prev_time = { 0, 0 }; |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1694 | u8 ktype; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1695 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1696 | /* filter out junk data on the older 0xffdc imon devices */ |
Jarod Wilson | bbe4690 | 2010-05-24 12:02:05 -0300 | [diff] [blame] | 1697 | if ((buf[0] == 0xff) && (buf[1] == 0xff) && (buf[2] == 0xff)) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1698 | return; |
| 1699 | |
| 1700 | /* Figure out what key was pressed */ |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1701 | if (len == 8 && buf[7] == 0xee) { |
Hans Verkuil | d778d25 | 2014-08-20 19:34:33 -0300 | [diff] [blame] | 1702 | scancode = be64_to_cpu(*((__be64 *)buf)); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1703 | ktype = IMON_KEY_PANEL; |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 1704 | kc = imon_panel_key_lookup(ictx, scancode); |
Ulrich Eckhardt | 6ddc2be | 2014-07-26 15:01:12 -0300 | [diff] [blame] | 1705 | ictx->release_code = false; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1706 | } else { |
Hans Verkuil | d778d25 | 2014-08-20 19:34:33 -0300 | [diff] [blame] | 1707 | scancode = be32_to_cpu(*((__be32 *)buf)); |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1708 | if (ictx->rc_proto == RC_PROTO_BIT_RC6_MCE) { |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1709 | ktype = IMON_KEY_IMON; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1710 | if (buf[0] == 0x80) |
| 1711 | ktype = IMON_KEY_MCE; |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1712 | kc = imon_mce_key_lookup(ictx, scancode); |
| 1713 | } else { |
| 1714 | ktype = IMON_KEY_IMON; |
| 1715 | kc = imon_remote_key_lookup(ictx, scancode); |
| 1716 | } |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1717 | } |
| 1718 | |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1719 | spin_lock_irqsave(&ictx->kc_lock, flags); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1720 | /* keyboard/mouse mode toggle button */ |
| 1721 | if (kc == KEY_KEYBOARD && !ictx->release_code) { |
| 1722 | ictx->last_keycode = kc; |
| 1723 | if (!nomouse) { |
Arnd Bergmann | bd7e31b | 2017-05-11 08:46:44 -0300 | [diff] [blame] | 1724 | ictx->pad_mouse = !ictx->pad_mouse; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1725 | dev_dbg(dev, "toggling to %s mode\n", |
| 1726 | ictx->pad_mouse ? "mouse" : "keyboard"); |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1727 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1728 | return; |
| 1729 | } else { |
Jarod Wilson | 76f1ef4 | 2011-01-06 16:59:35 -0300 | [diff] [blame] | 1730 | ictx->pad_mouse = false; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1731 | dev_dbg(dev, "mouse mode disabled, passing key value\n"); |
| 1732 | } |
| 1733 | } |
| 1734 | |
| 1735 | ictx->kc = kc; |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1736 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1737 | |
| 1738 | /* send touchscreen events through input subsystem if touchpad data */ |
| 1739 | if (ictx->display_type == IMON_DISPLAY_TYPE_VGA && len == 8 && |
| 1740 | buf[7] == 0x86) { |
| 1741 | imon_touch_event(ictx, buf); |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1742 | return; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1743 | |
| 1744 | /* look for mouse events with pad in mouse mode */ |
| 1745 | } else if (ictx->pad_mouse) { |
| 1746 | if (imon_mouse_event(ictx, buf, len)) |
| 1747 | return; |
| 1748 | } |
| 1749 | |
| 1750 | /* Now for some special handling to convert pad input to arrow keys */ |
| 1751 | if (((len == 5) && (buf[0] == 0x01) && (buf[4] == 0x00)) || |
| 1752 | ((len == 8) && (buf[0] & 0x40) && |
| 1753 | !(buf[1] & 0x1 || buf[1] >> 2 & 0x1))) { |
| 1754 | len = 8; |
| 1755 | imon_pad_to_keys(ictx, buf); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | if (debug) { |
Mauro Carvalho Chehab | 832d40c | 2016-10-14 07:48:35 -0300 | [diff] [blame] | 1759 | printk(KERN_INFO "intf%d decoded packet: %*ph\n", |
| 1760 | intf, len, buf); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | press_type = imon_parse_press_type(ictx, buf, ktype); |
| 1764 | if (press_type < 0) |
| 1765 | goto not_input_data; |
| 1766 | |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1767 | if (ktype != IMON_KEY_PANEL) { |
| 1768 | if (press_type == 0) |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 1769 | rc_keyup(ictx->rdev); |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1770 | else { |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1771 | if (ictx->rc_proto == RC_PROTO_BIT_RC6_MCE || |
| 1772 | ictx->rc_proto == RC_PROTO_BIT_OTHER) |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 1773 | rc_keydown(ictx->rdev, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1774 | ictx->rc_proto == RC_PROTO_BIT_RC6_MCE ? RC_PROTO_RC6_MCE : RC_PROTO_OTHER, |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 1775 | ictx->rc_scancode, ictx->rc_toggle); |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1776 | spin_lock_irqsave(&ictx->kc_lock, flags); |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1777 | ictx->last_keycode = ictx->kc; |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1778 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1779 | } |
| 1780 | return; |
| 1781 | } |
| 1782 | |
| 1783 | /* Only panel type events left to process now */ |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1784 | spin_lock_irqsave(&ictx->kc_lock, flags); |
| 1785 | |
Jarod Wilson | 94215cc | 2011-06-04 14:14:41 -0300 | [diff] [blame] | 1786 | do_gettimeofday(&t); |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1787 | /* KEY_MUTE repeats from knob need to be suppressed */ |
| 1788 | if (ictx->kc == KEY_MUTE && ictx->kc == ictx->last_keycode) { |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1789 | msec = tv2int(&t, &prev_time); |
Jarod Wilson | 428cc76 | 2010-10-23 16:42:20 -0300 | [diff] [blame] | 1790 | if (msec < ictx->idev->rep[REP_DELAY]) { |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1791 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1792 | return; |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1793 | } |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1794 | } |
Jarod Wilson | 94215cc | 2011-06-04 14:14:41 -0300 | [diff] [blame] | 1795 | prev_time = t; |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1796 | kc = ictx->kc; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1797 | |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1798 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1799 | |
Jarod Wilson | 428cc76 | 2010-10-23 16:42:20 -0300 | [diff] [blame] | 1800 | input_report_key(ictx->idev, kc, press_type); |
| 1801 | input_sync(ictx->idev); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1802 | |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 1803 | /* panel keys don't generate a release */ |
Jarod Wilson | 428cc76 | 2010-10-23 16:42:20 -0300 | [diff] [blame] | 1804 | input_report_key(ictx->idev, kc, 0); |
| 1805 | input_sync(ictx->idev); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1806 | |
Jarod Wilson | 94215cc | 2011-06-04 14:14:41 -0300 | [diff] [blame] | 1807 | spin_lock_irqsave(&ictx->kc_lock, flags); |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 1808 | ictx->last_keycode = kc; |
Jarod Wilson | 94215cc | 2011-06-04 14:14:41 -0300 | [diff] [blame] | 1809 | spin_unlock_irqrestore(&ictx->kc_lock, flags); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1810 | |
| 1811 | return; |
| 1812 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1813 | not_input_data: |
| 1814 | if (len != 8) { |
Mauro Carvalho Chehab | 25ec587 | 2016-10-18 17:44:25 -0200 | [diff] [blame] | 1815 | dev_warn(dev, "imon %s: invalid incoming packet size (len = %d, intf%d)\n", |
| 1816 | __func__, len, intf); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1817 | return; |
| 1818 | } |
| 1819 | |
| 1820 | /* iMON 2.4G associate frame */ |
| 1821 | if (buf[0] == 0x00 && |
| 1822 | buf[2] == 0xFF && /* REFID */ |
| 1823 | buf[3] == 0xFF && |
| 1824 | buf[4] == 0xFF && |
| 1825 | buf[5] == 0xFF && /* iMON 2.4G */ |
| 1826 | ((buf[6] == 0x4E && buf[7] == 0xDF) || /* LT */ |
| 1827 | (buf[6] == 0x5E && buf[7] == 0xDF))) { /* DT */ |
| 1828 | dev_warn(dev, "%s: remote associated refid=%02X\n", |
| 1829 | __func__, buf[1]); |
Jarod Wilson | f789bf4 | 2010-05-24 12:00:31 -0300 | [diff] [blame] | 1830 | ictx->rf_isassociating = false; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1831 | } |
| 1832 | } |
| 1833 | |
Mauro Carvalho Chehab | 255940e | 2017-11-27 10:27:54 -0500 | [diff] [blame] | 1834 | /* |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1835 | * Callback function for USB core API: receive data |
| 1836 | */ |
| 1837 | static void usb_rx_callback_intf0(struct urb *urb) |
| 1838 | { |
| 1839 | struct imon_context *ictx; |
| 1840 | int intfnum = 0; |
| 1841 | |
| 1842 | if (!urb) |
| 1843 | return; |
| 1844 | |
| 1845 | ictx = (struct imon_context *)urb->context; |
Jarod Wilson | 8791d63 | 2012-01-26 12:04:11 -0300 | [diff] [blame] | 1846 | if (!ictx) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1847 | return; |
| 1848 | |
Jarod Wilson | 8791d63 | 2012-01-26 12:04:11 -0300 | [diff] [blame] | 1849 | /* |
| 1850 | * if we get a callback before we're done configuring the hardware, we |
| 1851 | * can't yet process the data, as there's nowhere to send it, but we |
| 1852 | * still need to submit a new rx URB to avoid wedging the hardware |
| 1853 | */ |
| 1854 | if (!ictx->dev_present_intf0) |
| 1855 | goto out; |
| 1856 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1857 | switch (urb->status) { |
| 1858 | case -ENOENT: /* usbcore unlink successful! */ |
| 1859 | return; |
| 1860 | |
| 1861 | case -ESHUTDOWN: /* transport endpoint was shut down */ |
| 1862 | break; |
| 1863 | |
| 1864 | case 0: |
Sean Young | f41003a | 2016-12-20 12:18:06 -0200 | [diff] [blame] | 1865 | if (ictx->rdev->driver_type == RC_DRIVER_IR_RAW) |
| 1866 | imon_incoming_ir_raw(ictx, urb, intfnum); |
| 1867 | else |
| 1868 | imon_incoming_scancode(ictx, urb, intfnum); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1869 | break; |
| 1870 | |
| 1871 | default: |
| 1872 | dev_warn(ictx->dev, "imon %s: status(%d): ignored\n", |
| 1873 | __func__, urb->status); |
| 1874 | break; |
| 1875 | } |
| 1876 | |
Jarod Wilson | 8791d63 | 2012-01-26 12:04:11 -0300 | [diff] [blame] | 1877 | out: |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1878 | usb_submit_urb(ictx->rx_urb_intf0, GFP_ATOMIC); |
| 1879 | } |
| 1880 | |
| 1881 | static void usb_rx_callback_intf1(struct urb *urb) |
| 1882 | { |
| 1883 | struct imon_context *ictx; |
| 1884 | int intfnum = 1; |
| 1885 | |
| 1886 | if (!urb) |
| 1887 | return; |
| 1888 | |
| 1889 | ictx = (struct imon_context *)urb->context; |
Jarod Wilson | 8791d63 | 2012-01-26 12:04:11 -0300 | [diff] [blame] | 1890 | if (!ictx) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1891 | return; |
| 1892 | |
Jarod Wilson | 8791d63 | 2012-01-26 12:04:11 -0300 | [diff] [blame] | 1893 | /* |
| 1894 | * if we get a callback before we're done configuring the hardware, we |
| 1895 | * can't yet process the data, as there's nowhere to send it, but we |
| 1896 | * still need to submit a new rx URB to avoid wedging the hardware |
| 1897 | */ |
| 1898 | if (!ictx->dev_present_intf1) |
| 1899 | goto out; |
| 1900 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1901 | switch (urb->status) { |
| 1902 | case -ENOENT: /* usbcore unlink successful! */ |
| 1903 | return; |
| 1904 | |
| 1905 | case -ESHUTDOWN: /* transport endpoint was shut down */ |
| 1906 | break; |
| 1907 | |
| 1908 | case 0: |
Sean Young | f41003a | 2016-12-20 12:18:06 -0200 | [diff] [blame] | 1909 | if (ictx->rdev->driver_type == RC_DRIVER_IR_RAW) |
| 1910 | imon_incoming_ir_raw(ictx, urb, intfnum); |
| 1911 | else |
| 1912 | imon_incoming_scancode(ictx, urb, intfnum); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1913 | break; |
| 1914 | |
| 1915 | default: |
| 1916 | dev_warn(ictx->dev, "imon %s: status(%d): ignored\n", |
| 1917 | __func__, urb->status); |
| 1918 | break; |
| 1919 | } |
| 1920 | |
Jarod Wilson | 8791d63 | 2012-01-26 12:04:11 -0300 | [diff] [blame] | 1921 | out: |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 1922 | usb_submit_urb(ictx->rx_urb_intf1, GFP_ATOMIC); |
| 1923 | } |
| 1924 | |
Jarod Wilson | 04292fc | 2010-09-15 00:28:41 -0300 | [diff] [blame] | 1925 | /* |
| 1926 | * The 0x15c2:0xffdc device ID was used for umpteen different imon |
| 1927 | * devices, and all of them constantly spew interrupts, even when there |
| 1928 | * is no actual data to report. However, byte 6 of this buffer looks like |
| 1929 | * its unique across device variants, so we're trying to key off that to |
| 1930 | * figure out which display type (if any) and what IR protocol the device |
| 1931 | * actually supports. These devices have their IR protocol hard-coded into |
| 1932 | * their firmware, they can't be changed on the fly like the newer hardware. |
| 1933 | */ |
| 1934 | static void imon_get_ffdc_type(struct imon_context *ictx) |
| 1935 | { |
| 1936 | u8 ffdc_cfg_byte = ictx->usb_rx_buf[6]; |
| 1937 | u8 detected_display_type = IMON_DISPLAY_TYPE_NONE; |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1938 | u64 allowed_protos = RC_PROTO_BIT_OTHER; |
Jarod Wilson | 04292fc | 2010-09-15 00:28:41 -0300 | [diff] [blame] | 1939 | |
| 1940 | switch (ffdc_cfg_byte) { |
| 1941 | /* iMON Knob, no display, iMON IR + vol knob */ |
| 1942 | case 0x21: |
| 1943 | dev_info(ictx->dev, "0xffdc iMON Knob, iMON IR"); |
| 1944 | ictx->display_supported = false; |
| 1945 | break; |
| 1946 | /* iMON 2.4G LT (usb stick), no display, iMON RF */ |
| 1947 | case 0x4e: |
| 1948 | dev_info(ictx->dev, "0xffdc iMON 2.4G LT, iMON RF"); |
| 1949 | ictx->display_supported = false; |
| 1950 | ictx->rf_device = true; |
| 1951 | break; |
| 1952 | /* iMON VFD, no IR (does have vol knob tho) */ |
| 1953 | case 0x35: |
| 1954 | dev_info(ictx->dev, "0xffdc iMON VFD + knob, no IR"); |
| 1955 | detected_display_type = IMON_DISPLAY_TYPE_VFD; |
| 1956 | break; |
| 1957 | /* iMON VFD, iMON IR */ |
| 1958 | case 0x24: |
| 1959 | case 0x85: |
| 1960 | dev_info(ictx->dev, "0xffdc iMON VFD, iMON IR"); |
| 1961 | detected_display_type = IMON_DISPLAY_TYPE_VFD; |
| 1962 | break; |
| 1963 | /* iMON VFD, MCE IR */ |
Jarod Wilson | 443b391 | 2011-06-04 14:00:54 -0300 | [diff] [blame] | 1964 | case 0x46: |
Jarod Wilson | 842071c | 2011-06-20 00:04:05 -0300 | [diff] [blame] | 1965 | case 0x7e: |
Jarod Wilson | 04292fc | 2010-09-15 00:28:41 -0300 | [diff] [blame] | 1966 | case 0x9e: |
| 1967 | dev_info(ictx->dev, "0xffdc iMON VFD, MCE IR"); |
| 1968 | detected_display_type = IMON_DISPLAY_TYPE_VFD; |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1969 | allowed_protos = RC_PROTO_BIT_RC6_MCE; |
Jarod Wilson | 04292fc | 2010-09-15 00:28:41 -0300 | [diff] [blame] | 1970 | break; |
| 1971 | /* iMON LCD, MCE IR */ |
| 1972 | case 0x9f: |
| 1973 | dev_info(ictx->dev, "0xffdc iMON LCD, MCE IR"); |
| 1974 | detected_display_type = IMON_DISPLAY_TYPE_LCD; |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1975 | allowed_protos = RC_PROTO_BIT_RC6_MCE; |
Jarod Wilson | 04292fc | 2010-09-15 00:28:41 -0300 | [diff] [blame] | 1976 | break; |
| 1977 | default: |
Mauro Carvalho Chehab | 25ec587 | 2016-10-18 17:44:25 -0200 | [diff] [blame] | 1978 | dev_info(ictx->dev, "Unknown 0xffdc device, defaulting to VFD and iMON IR"); |
Jarod Wilson | 04292fc | 2010-09-15 00:28:41 -0300 | [diff] [blame] | 1979 | detected_display_type = IMON_DISPLAY_TYPE_VFD; |
Jarod Wilson | 372b424 | 2011-06-20 00:07:13 -0300 | [diff] [blame] | 1980 | /* We don't know which one it is, allow user to set the |
| 1981 | * RC6 one from userspace if OTHER wasn't correct. */ |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1982 | allowed_protos |= RC_PROTO_BIT_RC6_MCE; |
Jarod Wilson | 04292fc | 2010-09-15 00:28:41 -0300 | [diff] [blame] | 1983 | break; |
| 1984 | } |
| 1985 | |
| 1986 | printk(KERN_CONT " (id 0x%02x)\n", ffdc_cfg_byte); |
| 1987 | |
| 1988 | ictx->display_type = detected_display_type; |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1989 | ictx->rc_proto = allowed_protos; |
Jarod Wilson | 04292fc | 2010-09-15 00:28:41 -0300 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | static void imon_set_display_type(struct imon_context *ictx) |
| 1993 | { |
| 1994 | u8 configured_display_type = IMON_DISPLAY_TYPE_VFD; |
| 1995 | |
| 1996 | /* |
| 1997 | * Try to auto-detect the type of display if the user hasn't set |
| 1998 | * it by hand via the display_type modparam. Default is VFD. |
| 1999 | */ |
| 2000 | |
| 2001 | if (display_type == IMON_DISPLAY_TYPE_AUTO) { |
| 2002 | switch (ictx->product) { |
| 2003 | case 0xffdc: |
| 2004 | /* set in imon_get_ffdc_type() */ |
| 2005 | configured_display_type = ictx->display_type; |
| 2006 | break; |
| 2007 | case 0x0034: |
| 2008 | case 0x0035: |
| 2009 | configured_display_type = IMON_DISPLAY_TYPE_VGA; |
| 2010 | break; |
| 2011 | case 0x0038: |
| 2012 | case 0x0039: |
| 2013 | case 0x0045: |
| 2014 | configured_display_type = IMON_DISPLAY_TYPE_LCD; |
| 2015 | break; |
| 2016 | case 0x003c: |
| 2017 | case 0x0041: |
| 2018 | case 0x0042: |
| 2019 | case 0x0043: |
Sean Young | f41003a | 2016-12-20 12:18:06 -0200 | [diff] [blame] | 2020 | case 0x8001: |
| 2021 | case 0xff30: |
Jarod Wilson | 04292fc | 2010-09-15 00:28:41 -0300 | [diff] [blame] | 2022 | configured_display_type = IMON_DISPLAY_TYPE_NONE; |
| 2023 | ictx->display_supported = false; |
| 2024 | break; |
| 2025 | case 0x0036: |
| 2026 | case 0x0044: |
Sean Young | f41003a | 2016-12-20 12:18:06 -0200 | [diff] [blame] | 2027 | case 0xffda: |
Jarod Wilson | 04292fc | 2010-09-15 00:28:41 -0300 | [diff] [blame] | 2028 | default: |
| 2029 | configured_display_type = IMON_DISPLAY_TYPE_VFD; |
| 2030 | break; |
| 2031 | } |
| 2032 | } else { |
| 2033 | configured_display_type = display_type; |
| 2034 | if (display_type == IMON_DISPLAY_TYPE_NONE) |
| 2035 | ictx->display_supported = false; |
| 2036 | else |
| 2037 | ictx->display_supported = true; |
Mauro Carvalho Chehab | 25ec587 | 2016-10-18 17:44:25 -0200 | [diff] [blame] | 2038 | dev_info(ictx->dev, "%s: overriding display type to %d via modparam\n", |
| 2039 | __func__, display_type); |
Jarod Wilson | 04292fc | 2010-09-15 00:28:41 -0300 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | ictx->display_type = configured_display_type; |
| 2043 | } |
| 2044 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 2045 | static struct rc_dev *imon_init_rdev(struct imon_context *ictx) |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 2046 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 2047 | struct rc_dev *rdev; |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 2048 | int ret; |
Colin Ian King | c25895c | 2017-09-05 09:07:50 -0300 | [diff] [blame] | 2049 | static const unsigned char fp_packet[] = { |
| 2050 | 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88 }; |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 2051 | |
Sean Young | f41003a | 2016-12-20 12:18:06 -0200 | [diff] [blame] | 2052 | rdev = rc_allocate_device(ictx->dev_descr->flags & IMON_IR_RAW ? |
| 2053 | RC_DRIVER_IR_RAW : RC_DRIVER_SCANCODE); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 2054 | if (!rdev) { |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 2055 | dev_err(ictx->dev, "remote control dev allocation failed\n"); |
| 2056 | goto out; |
| 2057 | } |
| 2058 | |
| 2059 | snprintf(ictx->name_rdev, sizeof(ictx->name_rdev), |
| 2060 | "iMON Remote (%04x:%04x)", ictx->vendor, ictx->product); |
| 2061 | usb_make_path(ictx->usbdev_intf0, ictx->phys_rdev, |
| 2062 | sizeof(ictx->phys_rdev)); |
| 2063 | strlcat(ictx->phys_rdev, "/input0", sizeof(ictx->phys_rdev)); |
| 2064 | |
Sean Young | 518f4b2 | 2017-07-01 12:13:19 -0400 | [diff] [blame] | 2065 | rdev->device_name = ictx->name_rdev; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 2066 | rdev->input_phys = ictx->phys_rdev; |
| 2067 | usb_to_input_id(ictx->usbdev_intf0, &rdev->input_id); |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 2068 | rdev->dev.parent = ictx->dev; |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 2069 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 2070 | rdev->priv = ictx; |
Sean Young | f41003a | 2016-12-20 12:18:06 -0200 | [diff] [blame] | 2071 | if (ictx->dev_descr->flags & IMON_IR_RAW) |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 2072 | rdev->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER; |
Sean Young | f41003a | 2016-12-20 12:18:06 -0200 | [diff] [blame] | 2073 | else |
| 2074 | /* iMON PAD or MCE */ |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 2075 | rdev->allowed_protocols = RC_PROTO_BIT_OTHER | |
| 2076 | RC_PROTO_BIT_RC6_MCE; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 2077 | rdev->change_protocol = imon_ir_change_protocol; |
| 2078 | rdev->driver_name = MOD_NAME; |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 2079 | |
Jarod Wilson | 04292fc | 2010-09-15 00:28:41 -0300 | [diff] [blame] | 2080 | /* Enable front-panel buttons and/or knobs */ |
| 2081 | memcpy(ictx->usb_tx_buf, &fp_packet, sizeof(fp_packet)); |
| 2082 | ret = send_packet(ictx); |
| 2083 | /* Not fatal, but warn about it */ |
| 2084 | if (ret) |
| 2085 | dev_info(ictx->dev, "panel buttons/knobs setup failed\n"); |
| 2086 | |
Jarod Wilson | 7d2edfc | 2011-01-06 16:57:14 -0300 | [diff] [blame] | 2087 | if (ictx->product == 0xffdc) { |
Jarod Wilson | 04292fc | 2010-09-15 00:28:41 -0300 | [diff] [blame] | 2088 | imon_get_ffdc_type(ictx); |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 2089 | rdev->allowed_protocols = ictx->rc_proto; |
Jarod Wilson | 7d2edfc | 2011-01-06 16:57:14 -0300 | [diff] [blame] | 2090 | } |
Jarod Wilson | 04292fc | 2010-09-15 00:28:41 -0300 | [diff] [blame] | 2091 | |
| 2092 | imon_set_display_type(ictx); |
| 2093 | |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 2094 | if (ictx->rc_proto == RC_PROTO_BIT_RC6_MCE || |
Sean Young | f41003a | 2016-12-20 12:18:06 -0200 | [diff] [blame] | 2095 | ictx->dev_descr->flags & IMON_IR_RAW) |
Jarod Wilson | 7d2edfc | 2011-01-06 16:57:14 -0300 | [diff] [blame] | 2096 | rdev->map_name = RC_MAP_IMON_MCE; |
| 2097 | else |
| 2098 | rdev->map_name = RC_MAP_IMON_PAD; |
| 2099 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 2100 | ret = rc_register_device(rdev); |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 2101 | if (ret < 0) { |
| 2102 | dev_err(ictx->dev, "remote input dev register failed\n"); |
| 2103 | goto out; |
| 2104 | } |
| 2105 | |
| 2106 | return rdev; |
| 2107 | |
| 2108 | out: |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 2109 | rc_free_device(rdev); |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 2110 | return NULL; |
| 2111 | } |
| 2112 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2113 | static struct input_dev *imon_init_idev(struct imon_context *ictx) |
| 2114 | { |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 2115 | struct imon_panel_key_table *key_table = ictx->dev_descr->key_table; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2116 | struct input_dev *idev; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2117 | int ret, i; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2118 | |
| 2119 | idev = input_allocate_device(); |
Joe Perches | da4a733 | 2013-10-23 16:14:51 -0300 | [diff] [blame] | 2120 | if (!idev) |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 2121 | goto out; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2122 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2123 | snprintf(ictx->name_idev, sizeof(ictx->name_idev), |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 2124 | "iMON Panel, Knob and Mouse(%04x:%04x)", |
| 2125 | ictx->vendor, ictx->product); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2126 | idev->name = ictx->name_idev; |
| 2127 | |
| 2128 | usb_make_path(ictx->usbdev_intf0, ictx->phys_idev, |
| 2129 | sizeof(ictx->phys_idev)); |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 2130 | strlcat(ictx->phys_idev, "/input1", sizeof(ictx->phys_idev)); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2131 | idev->phys = ictx->phys_idev; |
| 2132 | |
Jarod Wilson | db190fc | 2010-04-30 16:06:12 -0300 | [diff] [blame] | 2133 | idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | BIT_MASK(EV_REL); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2134 | |
| 2135 | idev->keybit[BIT_WORD(BTN_MOUSE)] = |
| 2136 | BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT); |
| 2137 | idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y) | |
| 2138 | BIT_MASK(REL_WHEEL); |
| 2139 | |
| 2140 | /* panel and/or knob code support */ |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 2141 | for (i = 0; key_table[i].hw_code != 0; i++) { |
| 2142 | u32 kc = key_table[i].keycode; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2143 | __set_bit(kc, idev->keybit); |
| 2144 | } |
| 2145 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2146 | usb_to_input_id(ictx->usbdev_intf0, &idev->id); |
| 2147 | idev->dev.parent = ictx->dev; |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 2148 | input_set_drvdata(idev, ictx); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2149 | |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 2150 | ret = input_register_device(idev); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2151 | if (ret < 0) { |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 2152 | dev_err(ictx->dev, "input dev register failed\n"); |
| 2153 | goto out; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | return idev; |
| 2157 | |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 2158 | out: |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2159 | input_free_device(idev); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2160 | return NULL; |
| 2161 | } |
| 2162 | |
| 2163 | static struct input_dev *imon_init_touch(struct imon_context *ictx) |
| 2164 | { |
| 2165 | struct input_dev *touch; |
| 2166 | int ret; |
| 2167 | |
| 2168 | touch = input_allocate_device(); |
Joe Perches | da4a733 | 2013-10-23 16:14:51 -0300 | [diff] [blame] | 2169 | if (!touch) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2170 | goto touch_alloc_failed; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2171 | |
| 2172 | snprintf(ictx->name_touch, sizeof(ictx->name_touch), |
| 2173 | "iMON USB Touchscreen (%04x:%04x)", |
| 2174 | ictx->vendor, ictx->product); |
| 2175 | touch->name = ictx->name_touch; |
| 2176 | |
| 2177 | usb_make_path(ictx->usbdev_intf1, ictx->phys_touch, |
| 2178 | sizeof(ictx->phys_touch)); |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 2179 | strlcat(ictx->phys_touch, "/input2", sizeof(ictx->phys_touch)); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2180 | touch->phys = ictx->phys_touch; |
| 2181 | |
| 2182 | touch->evbit[0] = |
| 2183 | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
| 2184 | touch->keybit[BIT_WORD(BTN_TOUCH)] = |
| 2185 | BIT_MASK(BTN_TOUCH); |
| 2186 | input_set_abs_params(touch, ABS_X, |
| 2187 | 0x00, 0xfff, 0, 0); |
| 2188 | input_set_abs_params(touch, ABS_Y, |
| 2189 | 0x00, 0xfff, 0, 0); |
| 2190 | |
| 2191 | input_set_drvdata(touch, ictx); |
| 2192 | |
| 2193 | usb_to_input_id(ictx->usbdev_intf1, &touch->id); |
| 2194 | touch->dev.parent = ictx->dev; |
| 2195 | ret = input_register_device(touch); |
| 2196 | if (ret < 0) { |
| 2197 | dev_info(ictx->dev, "touchscreen input dev register failed\n"); |
| 2198 | goto touch_register_failed; |
| 2199 | } |
| 2200 | |
| 2201 | return touch; |
| 2202 | |
| 2203 | touch_register_failed: |
Julia Lawall | aeb35eb | 2011-05-20 15:31:59 -0300 | [diff] [blame] | 2204 | input_free_device(touch); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2205 | |
| 2206 | touch_alloc_failed: |
| 2207 | return NULL; |
| 2208 | } |
| 2209 | |
| 2210 | static bool imon_find_endpoints(struct imon_context *ictx, |
| 2211 | struct usb_host_interface *iface_desc) |
| 2212 | { |
| 2213 | struct usb_endpoint_descriptor *ep; |
| 2214 | struct usb_endpoint_descriptor *rx_endpoint = NULL; |
| 2215 | struct usb_endpoint_descriptor *tx_endpoint = NULL; |
| 2216 | int ifnum = iface_desc->desc.bInterfaceNumber; |
| 2217 | int num_endpts = iface_desc->desc.bNumEndpoints; |
| 2218 | int i, ep_dir, ep_type; |
Jarod Wilson | f789bf4 | 2010-05-24 12:00:31 -0300 | [diff] [blame] | 2219 | bool ir_ep_found = false; |
| 2220 | bool display_ep_found = false; |
| 2221 | bool tx_control = false; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2222 | |
| 2223 | /* |
| 2224 | * Scan the endpoint list and set: |
| 2225 | * first input endpoint = IR endpoint |
| 2226 | * first output endpoint = display endpoint |
| 2227 | */ |
| 2228 | for (i = 0; i < num_endpts && !(ir_ep_found && display_ep_found); ++i) { |
| 2229 | ep = &iface_desc->endpoint[i].desc; |
| 2230 | ep_dir = ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK; |
Himangi Saraogi | 9408d8f | 2014-08-15 13:18:53 -0300 | [diff] [blame] | 2231 | ep_type = usb_endpoint_type(ep); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2232 | |
| 2233 | if (!ir_ep_found && ep_dir == USB_DIR_IN && |
| 2234 | ep_type == USB_ENDPOINT_XFER_INT) { |
| 2235 | |
| 2236 | rx_endpoint = ep; |
Jarod Wilson | f789bf4 | 2010-05-24 12:00:31 -0300 | [diff] [blame] | 2237 | ir_ep_found = true; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2238 | dev_dbg(ictx->dev, "%s: found IR endpoint\n", __func__); |
| 2239 | |
| 2240 | } else if (!display_ep_found && ep_dir == USB_DIR_OUT && |
| 2241 | ep_type == USB_ENDPOINT_XFER_INT) { |
| 2242 | tx_endpoint = ep; |
Jarod Wilson | f789bf4 | 2010-05-24 12:00:31 -0300 | [diff] [blame] | 2243 | display_ep_found = true; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2244 | dev_dbg(ictx->dev, "%s: found display endpoint\n", __func__); |
| 2245 | } |
| 2246 | } |
| 2247 | |
| 2248 | if (ifnum == 0) { |
| 2249 | ictx->rx_endpoint_intf0 = rx_endpoint; |
| 2250 | /* |
| 2251 | * tx is used to send characters to lcd/vfd, associate RF |
| 2252 | * remotes, set IR protocol, and maybe more... |
| 2253 | */ |
| 2254 | ictx->tx_endpoint = tx_endpoint; |
| 2255 | } else { |
| 2256 | ictx->rx_endpoint_intf1 = rx_endpoint; |
| 2257 | } |
| 2258 | |
| 2259 | /* |
| 2260 | * If we didn't find a display endpoint, this is probably one of the |
| 2261 | * newer iMON devices that use control urb instead of interrupt |
| 2262 | */ |
| 2263 | if (!display_ep_found) { |
Jarod Wilson | f789bf4 | 2010-05-24 12:00:31 -0300 | [diff] [blame] | 2264 | tx_control = true; |
| 2265 | display_ep_found = true; |
Mauro Carvalho Chehab | 25ec587 | 2016-10-18 17:44:25 -0200 | [diff] [blame] | 2266 | dev_dbg(ictx->dev, "%s: device uses control endpoint, not interface OUT endpoint\n", |
| 2267 | __func__); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2268 | } |
| 2269 | |
| 2270 | /* |
| 2271 | * Some iMON receivers have no display. Unfortunately, it seems |
| 2272 | * that SoundGraph recycles device IDs between devices both with |
| 2273 | * and without... :\ |
| 2274 | */ |
| 2275 | if (ictx->display_type == IMON_DISPLAY_TYPE_NONE) { |
Jarod Wilson | f789bf4 | 2010-05-24 12:00:31 -0300 | [diff] [blame] | 2276 | display_ep_found = false; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2277 | dev_dbg(ictx->dev, "%s: device has no display\n", __func__); |
| 2278 | } |
| 2279 | |
| 2280 | /* |
| 2281 | * iMON Touch devices have a VGA touchscreen, but no "display", as |
| 2282 | * that refers to e.g. /dev/lcd0 (a character device LCD or VFD). |
| 2283 | */ |
| 2284 | if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) { |
Jarod Wilson | f789bf4 | 2010-05-24 12:00:31 -0300 | [diff] [blame] | 2285 | display_ep_found = false; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2286 | dev_dbg(ictx->dev, "%s: iMON Touch device found\n", __func__); |
| 2287 | } |
| 2288 | |
| 2289 | /* Input endpoint is mandatory */ |
| 2290 | if (!ir_ep_found) |
Joe Perches | e230250 | 2010-06-20 04:20:46 -0300 | [diff] [blame] | 2291 | pr_err("no valid input (IR) endpoint found\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2292 | |
| 2293 | ictx->tx_control = tx_control; |
| 2294 | |
| 2295 | if (display_ep_found) |
| 2296 | ictx->display_supported = true; |
| 2297 | |
| 2298 | return ir_ep_found; |
| 2299 | |
| 2300 | } |
| 2301 | |
Kevin Baradon | f7d141b | 2013-04-22 16:09:44 -0300 | [diff] [blame] | 2302 | static struct imon_context *imon_init_intf0(struct usb_interface *intf, |
| 2303 | const struct usb_device_id *id) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2304 | { |
| 2305 | struct imon_context *ictx; |
| 2306 | struct urb *rx_urb; |
| 2307 | struct urb *tx_urb; |
| 2308 | struct device *dev = &intf->dev; |
| 2309 | struct usb_host_interface *iface_desc; |
Mauro Carvalho Chehab | 1f71bae | 2010-04-20 19:11:30 -0300 | [diff] [blame] | 2310 | int ret = -ENOMEM; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2311 | |
Markus Elfring | a8c779e | 2017-08-29 07:45:59 -0300 | [diff] [blame] | 2312 | ictx = kzalloc(sizeof(*ictx), GFP_KERNEL); |
Markus Elfring | 3e70b25 | 2017-08-29 07:40:07 -0300 | [diff] [blame] | 2313 | if (!ictx) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2314 | goto exit; |
Markus Elfring | 3e70b25 | 2017-08-29 07:40:07 -0300 | [diff] [blame] | 2315 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2316 | rx_urb = usb_alloc_urb(0, GFP_KERNEL); |
Wolfram Sang | 1524191 | 2016-08-11 18:03:39 -0300 | [diff] [blame] | 2317 | if (!rx_urb) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2318 | goto rx_urb_alloc_failed; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2319 | tx_urb = usb_alloc_urb(0, GFP_KERNEL); |
Wolfram Sang | 1524191 | 2016-08-11 18:03:39 -0300 | [diff] [blame] | 2320 | if (!tx_urb) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2321 | goto tx_urb_alloc_failed; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2322 | |
| 2323 | mutex_init(&ictx->lock); |
Jarod Wilson | 693508d | 2010-09-15 15:56:03 -0300 | [diff] [blame] | 2324 | spin_lock_init(&ictx->kc_lock); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2325 | |
| 2326 | mutex_lock(&ictx->lock); |
| 2327 | |
| 2328 | ictx->dev = dev; |
| 2329 | ictx->usbdev_intf0 = usb_get_dev(interface_to_usbdev(intf)); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2330 | ictx->rx_urb_intf0 = rx_urb; |
| 2331 | ictx->tx_urb = tx_urb; |
Jarod Wilson | bbe4690 | 2010-05-24 12:02:05 -0300 | [diff] [blame] | 2332 | ictx->rf_device = false; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2333 | |
Daniel Wagner | 7c073ff | 2016-09-16 08:18:21 -0300 | [diff] [blame] | 2334 | init_completion(&ictx->tx.finished); |
| 2335 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2336 | ictx->vendor = le16_to_cpu(ictx->usbdev_intf0->descriptor.idVendor); |
| 2337 | ictx->product = le16_to_cpu(ictx->usbdev_intf0->descriptor.idProduct); |
| 2338 | |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 2339 | /* save drive info for later accessing the panel/knob key table */ |
| 2340 | ictx->dev_descr = (struct imon_usb_dev_descr *)id->driver_info; |
Kevin Baradon | f7d141b | 2013-04-22 16:09:44 -0300 | [diff] [blame] | 2341 | /* default send_packet delay is 5ms but some devices need more */ |
Ulrich Eckhardt | 0d8053f | 2014-07-26 14:56:01 -0300 | [diff] [blame] | 2342 | ictx->send_packet_delay = ictx->dev_descr->flags & |
| 2343 | IMON_NEED_20MS_PKT_DELAY ? 20 : 5; |
Kevin Baradon | f7d141b | 2013-04-22 16:09:44 -0300 | [diff] [blame] | 2344 | |
Mauro Carvalho Chehab | 1f71bae | 2010-04-20 19:11:30 -0300 | [diff] [blame] | 2345 | ret = -ENODEV; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2346 | iface_desc = intf->cur_altsetting; |
Mauro Carvalho Chehab | 1f71bae | 2010-04-20 19:11:30 -0300 | [diff] [blame] | 2347 | if (!imon_find_endpoints(ictx, iface_desc)) { |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2348 | goto find_endpoint_failed; |
Mauro Carvalho Chehab | 1f71bae | 2010-04-20 19:11:30 -0300 | [diff] [blame] | 2349 | } |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2350 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2351 | usb_fill_int_urb(ictx->rx_urb_intf0, ictx->usbdev_intf0, |
| 2352 | usb_rcvintpipe(ictx->usbdev_intf0, |
| 2353 | ictx->rx_endpoint_intf0->bEndpointAddress), |
| 2354 | ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf), |
| 2355 | usb_rx_callback_intf0, ictx, |
| 2356 | ictx->rx_endpoint_intf0->bInterval); |
| 2357 | |
| 2358 | ret = usb_submit_urb(ictx->rx_urb_intf0, GFP_KERNEL); |
| 2359 | if (ret) { |
Joe Perches | e230250 | 2010-06-20 04:20:46 -0300 | [diff] [blame] | 2360 | pr_err("usb_submit_urb failed for intf0 (%d)\n", ret); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2361 | goto urb_submit_failed; |
| 2362 | } |
| 2363 | |
Jarod Wilson | 9ad77eb | 2011-01-06 16:59:34 -0300 | [diff] [blame] | 2364 | ictx->idev = imon_init_idev(ictx); |
| 2365 | if (!ictx->idev) { |
| 2366 | dev_err(dev, "%s: input device setup failed\n", __func__); |
| 2367 | goto idev_setup_failed; |
| 2368 | } |
| 2369 | |
| 2370 | ictx->rdev = imon_init_rdev(ictx); |
| 2371 | if (!ictx->rdev) { |
| 2372 | dev_err(dev, "%s: rc device setup failed\n", __func__); |
| 2373 | goto rdev_setup_failed; |
| 2374 | } |
| 2375 | |
Jarod Wilson | 6f6b90c | 2011-07-19 12:12:47 -0300 | [diff] [blame] | 2376 | ictx->dev_present_intf0 = true; |
| 2377 | |
Jarod Wilson | 23ef710 | 2011-04-27 19:01:44 -0300 | [diff] [blame] | 2378 | mutex_unlock(&ictx->lock); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2379 | return ictx; |
| 2380 | |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 2381 | rdev_setup_failed: |
| 2382 | input_unregister_device(ictx->idev); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2383 | idev_setup_failed: |
Jarod Wilson | 9ad77eb | 2011-01-06 16:59:34 -0300 | [diff] [blame] | 2384 | usb_kill_urb(ictx->rx_urb_intf0); |
| 2385 | urb_submit_failed: |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2386 | find_endpoint_failed: |
Alexey Khoroshilov | e87cb47 | 2014-09-15 18:36:15 -0300 | [diff] [blame] | 2387 | usb_put_dev(ictx->usbdev_intf0); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2388 | mutex_unlock(&ictx->lock); |
| 2389 | usb_free_urb(tx_urb); |
| 2390 | tx_urb_alloc_failed: |
| 2391 | usb_free_urb(rx_urb); |
| 2392 | rx_urb_alloc_failed: |
| 2393 | kfree(ictx); |
| 2394 | exit: |
| 2395 | dev_err(dev, "unable to initialize intf0, err %d\n", ret); |
| 2396 | |
| 2397 | return NULL; |
| 2398 | } |
| 2399 | |
| 2400 | static struct imon_context *imon_init_intf1(struct usb_interface *intf, |
| 2401 | struct imon_context *ictx) |
| 2402 | { |
| 2403 | struct urb *rx_urb; |
| 2404 | struct usb_host_interface *iface_desc; |
Mauro Carvalho Chehab | 1f71bae | 2010-04-20 19:11:30 -0300 | [diff] [blame] | 2405 | int ret = -ENOMEM; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2406 | |
| 2407 | rx_urb = usb_alloc_urb(0, GFP_KERNEL); |
Wolfram Sang | 1524191 | 2016-08-11 18:03:39 -0300 | [diff] [blame] | 2408 | if (!rx_urb) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2409 | goto rx_urb_alloc_failed; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2410 | |
| 2411 | mutex_lock(&ictx->lock); |
| 2412 | |
| 2413 | if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) { |
Kees Cook | b17ec78 | 2017-10-24 11:23:14 -0400 | [diff] [blame] | 2414 | timer_setup(&ictx->ttimer, imon_touch_display_timeout, 0); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2415 | } |
| 2416 | |
| 2417 | ictx->usbdev_intf1 = usb_get_dev(interface_to_usbdev(intf)); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2418 | ictx->rx_urb_intf1 = rx_urb; |
| 2419 | |
Mauro Carvalho Chehab | 1f71bae | 2010-04-20 19:11:30 -0300 | [diff] [blame] | 2420 | ret = -ENODEV; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2421 | iface_desc = intf->cur_altsetting; |
| 2422 | if (!imon_find_endpoints(ictx, iface_desc)) |
| 2423 | goto find_endpoint_failed; |
| 2424 | |
| 2425 | if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) { |
| 2426 | ictx->touch = imon_init_touch(ictx); |
| 2427 | if (!ictx->touch) |
| 2428 | goto touch_setup_failed; |
| 2429 | } else |
| 2430 | ictx->touch = NULL; |
| 2431 | |
| 2432 | usb_fill_int_urb(ictx->rx_urb_intf1, ictx->usbdev_intf1, |
| 2433 | usb_rcvintpipe(ictx->usbdev_intf1, |
| 2434 | ictx->rx_endpoint_intf1->bEndpointAddress), |
| 2435 | ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf), |
| 2436 | usb_rx_callback_intf1, ictx, |
| 2437 | ictx->rx_endpoint_intf1->bInterval); |
| 2438 | |
| 2439 | ret = usb_submit_urb(ictx->rx_urb_intf1, GFP_KERNEL); |
| 2440 | |
| 2441 | if (ret) { |
Joe Perches | e230250 | 2010-06-20 04:20:46 -0300 | [diff] [blame] | 2442 | pr_err("usb_submit_urb failed for intf1 (%d)\n", ret); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2443 | goto urb_submit_failed; |
| 2444 | } |
| 2445 | |
Jarod Wilson | 6f6b90c | 2011-07-19 12:12:47 -0300 | [diff] [blame] | 2446 | ictx->dev_present_intf1 = true; |
| 2447 | |
Jarod Wilson | 23ef710 | 2011-04-27 19:01:44 -0300 | [diff] [blame] | 2448 | mutex_unlock(&ictx->lock); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2449 | return ictx; |
| 2450 | |
| 2451 | urb_submit_failed: |
Jarod Wilson | 20cd195 | 2010-07-26 11:11:36 -0300 | [diff] [blame] | 2452 | if (ictx->touch) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2453 | input_unregister_device(ictx->touch); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2454 | touch_setup_failed: |
| 2455 | find_endpoint_failed: |
Alexey Khoroshilov | e87cb47 | 2014-09-15 18:36:15 -0300 | [diff] [blame] | 2456 | usb_put_dev(ictx->usbdev_intf1); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2457 | mutex_unlock(&ictx->lock); |
| 2458 | usb_free_urb(rx_urb); |
| 2459 | rx_urb_alloc_failed: |
Jarod Wilson | 8791d63 | 2012-01-26 12:04:11 -0300 | [diff] [blame] | 2460 | dev_err(ictx->dev, "unable to initialize intf1, err %d\n", ret); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2461 | |
| 2462 | return NULL; |
| 2463 | } |
| 2464 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2465 | static void imon_init_display(struct imon_context *ictx, |
| 2466 | struct usb_interface *intf) |
| 2467 | { |
| 2468 | int ret; |
| 2469 | |
| 2470 | dev_dbg(ictx->dev, "Registering iMON display with sysfs\n"); |
| 2471 | |
| 2472 | /* set up sysfs entry for built-in clock */ |
Jarod Wilson | 6aa209e | 2010-10-23 16:42:51 -0300 | [diff] [blame] | 2473 | ret = sysfs_create_group(&intf->dev.kobj, &imon_display_attr_group); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2474 | if (ret) |
Mauro Carvalho Chehab | 25ec587 | 2016-10-18 17:44:25 -0200 | [diff] [blame] | 2475 | dev_err(ictx->dev, "Could not create display sysfs entries(%d)", |
| 2476 | ret); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2477 | |
| 2478 | if (ictx->display_type == IMON_DISPLAY_TYPE_LCD) |
| 2479 | ret = usb_register_dev(intf, &imon_lcd_class); |
| 2480 | else |
| 2481 | ret = usb_register_dev(intf, &imon_vfd_class); |
| 2482 | if (ret) |
| 2483 | /* Not a fatal error, so ignore */ |
Mauro Carvalho Chehab | 25ec587 | 2016-10-18 17:44:25 -0200 | [diff] [blame] | 2484 | dev_info(ictx->dev, "could not get a minor number for display\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2485 | |
| 2486 | } |
| 2487 | |
Mauro Carvalho Chehab | 255940e | 2017-11-27 10:27:54 -0500 | [diff] [blame] | 2488 | /* |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2489 | * Callback function for USB core API: Probe |
| 2490 | */ |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 2491 | static int imon_probe(struct usb_interface *interface, |
| 2492 | const struct usb_device_id *id) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2493 | { |
| 2494 | struct usb_device *usbdev = NULL; |
| 2495 | struct usb_host_interface *iface_desc = NULL; |
| 2496 | struct usb_interface *first_if; |
| 2497 | struct device *dev = &interface->dev; |
Jarod Wilson | 76a2d21 | 2011-04-28 18:20:58 -0300 | [diff] [blame] | 2498 | int ifnum, sysfs_err; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2499 | int ret = 0; |
| 2500 | struct imon_context *ictx = NULL; |
| 2501 | struct imon_context *first_if_ctx = NULL; |
| 2502 | u16 vendor, product; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2503 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2504 | usbdev = usb_get_dev(interface_to_usbdev(interface)); |
| 2505 | iface_desc = interface->cur_altsetting; |
| 2506 | ifnum = iface_desc->desc.bInterfaceNumber; |
| 2507 | vendor = le16_to_cpu(usbdev->descriptor.idVendor); |
| 2508 | product = le16_to_cpu(usbdev->descriptor.idProduct); |
| 2509 | |
| 2510 | dev_dbg(dev, "%s: found iMON device (%04x:%04x, intf%d)\n", |
| 2511 | __func__, vendor, product, ifnum); |
| 2512 | |
| 2513 | /* prevent races probing devices w/multiple interfaces */ |
| 2514 | mutex_lock(&driver_lock); |
| 2515 | |
| 2516 | first_if = usb_ifnum_to_if(usbdev, 0); |
Arvind Yadav | 58fd55e | 2017-10-09 20:14:48 +0200 | [diff] [blame] | 2517 | if (!first_if) { |
| 2518 | ret = -ENODEV; |
| 2519 | goto fail; |
| 2520 | } |
| 2521 | |
Joe Perches | 8350e15 | 2010-11-30 18:42:07 -0300 | [diff] [blame] | 2522 | first_if_ctx = usb_get_intfdata(first_if); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2523 | |
| 2524 | if (ifnum == 0) { |
Kevin Baradon | f7d141b | 2013-04-22 16:09:44 -0300 | [diff] [blame] | 2525 | ictx = imon_init_intf0(interface, id); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2526 | if (!ictx) { |
Joe Perches | e230250 | 2010-06-20 04:20:46 -0300 | [diff] [blame] | 2527 | pr_err("failed to initialize context!\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2528 | ret = -ENODEV; |
| 2529 | goto fail; |
| 2530 | } |
| 2531 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2532 | } else { |
Kevin Baradon | 7d54ba0 | 2013-04-22 16:09:45 -0300 | [diff] [blame] | 2533 | /* this is the secondary interface on the device */ |
| 2534 | |
| 2535 | /* fail early if first intf failed to register */ |
| 2536 | if (!first_if_ctx) { |
| 2537 | ret = -ENODEV; |
| 2538 | goto fail; |
| 2539 | } |
| 2540 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2541 | ictx = imon_init_intf1(interface, first_if_ctx); |
| 2542 | if (!ictx) { |
Joe Perches | e230250 | 2010-06-20 04:20:46 -0300 | [diff] [blame] | 2543 | pr_err("failed to attach to context!\n"); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2544 | ret = -ENODEV; |
| 2545 | goto fail; |
| 2546 | } |
| 2547 | |
| 2548 | } |
| 2549 | |
| 2550 | usb_set_intfdata(interface, ictx); |
| 2551 | |
| 2552 | if (ifnum == 0) { |
Jarod Wilson | 23ef710 | 2011-04-27 19:01:44 -0300 | [diff] [blame] | 2553 | mutex_lock(&ictx->lock); |
| 2554 | |
Jarod Wilson | bbe4690 | 2010-05-24 12:02:05 -0300 | [diff] [blame] | 2555 | if (product == 0xffdc && ictx->rf_device) { |
| 2556 | sysfs_err = sysfs_create_group(&interface->dev.kobj, |
Jarod Wilson | 6aa209e | 2010-10-23 16:42:51 -0300 | [diff] [blame] | 2557 | &imon_rf_attr_group); |
Jarod Wilson | bbe4690 | 2010-05-24 12:02:05 -0300 | [diff] [blame] | 2558 | if (sysfs_err) |
Joe Perches | e230250 | 2010-06-20 04:20:46 -0300 | [diff] [blame] | 2559 | pr_err("Could not create RF sysfs entries(%d)\n", |
| 2560 | sysfs_err); |
Jarod Wilson | bbe4690 | 2010-05-24 12:02:05 -0300 | [diff] [blame] | 2561 | } |
| 2562 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2563 | if (ictx->display_supported) |
| 2564 | imon_init_display(ictx, interface); |
Jarod Wilson | 23ef710 | 2011-04-27 19:01:44 -0300 | [diff] [blame] | 2565 | |
| 2566 | mutex_unlock(&ictx->lock); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2567 | } |
| 2568 | |
Mauro Carvalho Chehab | 25ec587 | 2016-10-18 17:44:25 -0200 | [diff] [blame] | 2569 | dev_info(dev, "iMON device (%04x:%04x, intf%d) on usb<%d:%d> initialized\n", |
| 2570 | vendor, product, ifnum, |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2571 | usbdev->bus->busnum, usbdev->devnum); |
| 2572 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2573 | mutex_unlock(&driver_lock); |
Alexey Khoroshilov | e87cb47 | 2014-09-15 18:36:15 -0300 | [diff] [blame] | 2574 | usb_put_dev(usbdev); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2575 | |
| 2576 | return 0; |
| 2577 | |
| 2578 | fail: |
| 2579 | mutex_unlock(&driver_lock); |
Alexey Khoroshilov | e87cb47 | 2014-09-15 18:36:15 -0300 | [diff] [blame] | 2580 | usb_put_dev(usbdev); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2581 | dev_err(dev, "unable to register, err %d\n", ret); |
| 2582 | |
| 2583 | return ret; |
| 2584 | } |
| 2585 | |
Mauro Carvalho Chehab | 255940e | 2017-11-27 10:27:54 -0500 | [diff] [blame] | 2586 | /* |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2587 | * Callback function for USB core API: disconnect |
| 2588 | */ |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 2589 | static void imon_disconnect(struct usb_interface *interface) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2590 | { |
| 2591 | struct imon_context *ictx; |
| 2592 | struct device *dev; |
| 2593 | int ifnum; |
| 2594 | |
| 2595 | /* prevent races with multi-interface device probing and display_open */ |
| 2596 | mutex_lock(&driver_lock); |
| 2597 | |
| 2598 | ictx = usb_get_intfdata(interface); |
| 2599 | dev = ictx->dev; |
| 2600 | ifnum = interface->cur_altsetting->desc.bInterfaceNumber; |
| 2601 | |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2602 | /* |
| 2603 | * sysfs_remove_group is safe to call even if sysfs_create_group |
| 2604 | * hasn't been called |
| 2605 | */ |
Jarod Wilson | 6aa209e | 2010-10-23 16:42:51 -0300 | [diff] [blame] | 2606 | sysfs_remove_group(&interface->dev.kobj, &imon_display_attr_group); |
| 2607 | sysfs_remove_group(&interface->dev.kobj, &imon_rf_attr_group); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2608 | |
| 2609 | usb_set_intfdata(interface, NULL); |
| 2610 | |
| 2611 | /* Abort ongoing write */ |
| 2612 | if (ictx->tx.busy) { |
| 2613 | usb_kill_urb(ictx->tx_urb); |
Daniel Wagner | 7c073ff | 2016-09-16 08:18:21 -0300 | [diff] [blame] | 2614 | complete(&ictx->tx.finished); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2615 | } |
| 2616 | |
| 2617 | if (ifnum == 0) { |
Jarod Wilson | f789bf4 | 2010-05-24 12:00:31 -0300 | [diff] [blame] | 2618 | ictx->dev_present_intf0 = false; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2619 | usb_kill_urb(ictx->rx_urb_intf0); |
Alexey Khoroshilov | e87cb47 | 2014-09-15 18:36:15 -0300 | [diff] [blame] | 2620 | usb_put_dev(ictx->usbdev_intf0); |
David Härdeman | eaf2bcc | 2010-09-15 15:42:07 -0300 | [diff] [blame] | 2621 | input_unregister_device(ictx->idev); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 2622 | rc_unregister_device(ictx->rdev); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2623 | if (ictx->display_supported) { |
| 2624 | if (ictx->display_type == IMON_DISPLAY_TYPE_LCD) |
| 2625 | usb_deregister_dev(interface, &imon_lcd_class); |
Jarod Wilson | 76a2d21 | 2011-04-28 18:20:58 -0300 | [diff] [blame] | 2626 | else if (ictx->display_type == IMON_DISPLAY_TYPE_VFD) |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2627 | usb_deregister_dev(interface, &imon_vfd_class); |
| 2628 | } |
| 2629 | } else { |
Jarod Wilson | f789bf4 | 2010-05-24 12:00:31 -0300 | [diff] [blame] | 2630 | ictx->dev_present_intf1 = false; |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2631 | usb_kill_urb(ictx->rx_urb_intf1); |
Alexey Khoroshilov | e87cb47 | 2014-09-15 18:36:15 -0300 | [diff] [blame] | 2632 | usb_put_dev(ictx->usbdev_intf1); |
Jarod Wilson | 76a2d21 | 2011-04-28 18:20:58 -0300 | [diff] [blame] | 2633 | if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) { |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2634 | input_unregister_device(ictx->touch); |
Jarod Wilson | 76a2d21 | 2011-04-28 18:20:58 -0300 | [diff] [blame] | 2635 | del_timer_sync(&ictx->ttimer); |
| 2636 | } |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2637 | } |
| 2638 | |
Jarod Wilson | 76a2d21 | 2011-04-28 18:20:58 -0300 | [diff] [blame] | 2639 | if (!ictx->dev_present_intf0 && !ictx->dev_present_intf1) |
| 2640 | free_imon_context(ictx); |
Jarod Wilson | 21677cf | 2010-04-16 18:29:02 -0300 | [diff] [blame] | 2641 | |
| 2642 | mutex_unlock(&driver_lock); |
| 2643 | |
| 2644 | dev_dbg(dev, "%s: iMON device (intf%d) disconnected\n", |
| 2645 | __func__, ifnum); |
| 2646 | } |
| 2647 | |
| 2648 | static int imon_suspend(struct usb_interface *intf, pm_message_t message) |
| 2649 | { |
| 2650 | struct imon_context *ictx = usb_get_intfdata(intf); |
| 2651 | int ifnum = intf->cur_altsetting->desc.bInterfaceNumber; |
| 2652 | |
| 2653 | if (ifnum == 0) |
| 2654 | usb_kill_urb(ictx->rx_urb_intf0); |
| 2655 | else |
| 2656 | usb_kill_urb(ictx->rx_urb_intf1); |
| 2657 | |
| 2658 | return 0; |
| 2659 | } |
| 2660 | |
| 2661 | static int imon_resume(struct usb_interface *intf) |
| 2662 | { |
| 2663 | int rc = 0; |
| 2664 | struct imon_context *ictx = usb_get_intfdata(intf); |
| 2665 | int ifnum = intf->cur_altsetting->desc.bInterfaceNumber; |
| 2666 | |
| 2667 | if (ifnum == 0) { |
| 2668 | usb_fill_int_urb(ictx->rx_urb_intf0, ictx->usbdev_intf0, |
| 2669 | usb_rcvintpipe(ictx->usbdev_intf0, |
| 2670 | ictx->rx_endpoint_intf0->bEndpointAddress), |
| 2671 | ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf), |
| 2672 | usb_rx_callback_intf0, ictx, |
| 2673 | ictx->rx_endpoint_intf0->bInterval); |
| 2674 | |
| 2675 | rc = usb_submit_urb(ictx->rx_urb_intf0, GFP_ATOMIC); |
| 2676 | |
| 2677 | } else { |
| 2678 | usb_fill_int_urb(ictx->rx_urb_intf1, ictx->usbdev_intf1, |
| 2679 | usb_rcvintpipe(ictx->usbdev_intf1, |
| 2680 | ictx->rx_endpoint_intf1->bEndpointAddress), |
| 2681 | ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf), |
| 2682 | usb_rx_callback_intf1, ictx, |
| 2683 | ictx->rx_endpoint_intf1->bInterval); |
| 2684 | |
| 2685 | rc = usb_submit_urb(ictx->rx_urb_intf1, GFP_ATOMIC); |
| 2686 | } |
| 2687 | |
| 2688 | return rc; |
| 2689 | } |
| 2690 | |
Greg Kroah-Hartman | ecb3b2b | 2011-11-18 09:46:12 -0800 | [diff] [blame] | 2691 | module_usb_driver(imon_driver); |