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