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