Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 1 | /* |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 2 | handle em28xx IR remotes via linux kernel input layer. |
| 3 | |
| 4 | Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it> |
| 5 | Markus Rechberger <mrechberger@gmail.com> |
Mauro Carvalho Chehab | 2e7c6dc | 2006-04-03 07:53:40 -0300 | [diff] [blame] | 6 | Mauro Carvalho Chehab <mchehab@infradead.org> |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 7 | Sascha Sommer <saschasommer@freenet.de> |
| 8 | |
| 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation; either version 2 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with this program; if not, write to the Free Software |
| 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | #include <linux/module.h> |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 25 | #include <linux/init.h> |
| 26 | #include <linux/delay.h> |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 27 | #include <linux/interrupt.h> |
| 28 | #include <linux/input.h> |
| 29 | #include <linux/usb.h> |
| 30 | |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 31 | #include "em28xx.h" |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 32 | |
Devin Heitmueller | a9fc52b | 2008-06-28 08:57:06 -0300 | [diff] [blame] | 33 | #define EM28XX_SNAPSHOT_KEY KEY_CAMERA |
| 34 | #define EM28XX_SBUTTON_QUERY_INTERVAL 500 |
| 35 | #define EM28XX_R0C_USBSUSP_SNAPSHOT 0x20 |
| 36 | |
Mauro Carvalho Chehab | c8793b0 | 2008-01-13 15:42:17 -0300 | [diff] [blame] | 37 | static unsigned int ir_debug; |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 38 | module_param(ir_debug, int, 0644); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 39 | MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]"); |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 40 | |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 41 | #define i2cdprintk(fmt, arg...) \ |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 42 | if (ir_debug) { \ |
| 43 | printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg); \ |
| 44 | } |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 45 | |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 46 | #define dprintk(fmt, arg...) \ |
| 47 | if (ir_debug) { \ |
| 48 | printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg); \ |
| 49 | } |
| 50 | |
| 51 | /********************************************************** |
| 52 | Polling structure used by em28xx IR's |
| 53 | **********************************************************/ |
| 54 | |
| 55 | struct em28xx_IR { |
| 56 | struct em28xx *dev; |
| 57 | struct input_dev *input; |
| 58 | struct ir_input_state ir; |
| 59 | char name[32]; |
| 60 | char phys[32]; |
| 61 | |
| 62 | /* poll external decoder */ |
| 63 | int polling; |
| 64 | struct work_struct work; |
| 65 | struct timer_list timer; |
| 66 | u32 last_gpio; |
| 67 | u32 mask_keycode; |
| 68 | u32 mask_keydown; |
| 69 | u32 mask_keyup; |
| 70 | |
| 71 | int (*get_key)(struct em28xx_IR *); |
| 72 | }; |
| 73 | |
| 74 | /********************************************************** |
| 75 | I2C IR based get keycodes - should be used with ir-kbd-i2c |
| 76 | **********************************************************/ |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 77 | |
Mauro Carvalho Chehab | c8793b0 | 2008-01-13 15:42:17 -0300 | [diff] [blame] | 78 | int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 79 | { |
| 80 | unsigned char b; |
| 81 | |
| 82 | /* poll IR chip */ |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 83 | if (1 != i2c_master_recv(&ir->c, &b, 1)) { |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 84 | i2cdprintk("read error\n"); |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 85 | return -EIO; |
| 86 | } |
| 87 | |
| 88 | /* it seems that 0xFE indicates that a button is still hold |
Mauro Carvalho Chehab | 4f9c05a | 2005-11-08 21:37:36 -0800 | [diff] [blame] | 89 | down, while 0xff indicates that no button is hold |
| 90 | down. 0xfe sequences are sometimes interrupted by 0xFF */ |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 91 | |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 92 | i2cdprintk("key %02x\n", b); |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 93 | |
Mauro Carvalho Chehab | 4f9c05a | 2005-11-08 21:37:36 -0800 | [diff] [blame] | 94 | if (b == 0xff) |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 95 | return 0; |
| 96 | |
Mauro Carvalho Chehab | 4f9c05a | 2005-11-08 21:37:36 -0800 | [diff] [blame] | 97 | if (b == 0xfe) |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 98 | /* keep old data */ |
| 99 | return 1; |
| 100 | |
| 101 | *ir_key = b; |
| 102 | *ir_raw = b; |
| 103 | return 1; |
| 104 | } |
| 105 | |
Mauro Carvalho Chehab | c8793b0 | 2008-01-13 15:42:17 -0300 | [diff] [blame] | 106 | int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 107 | { |
| 108 | unsigned char buf[2]; |
| 109 | unsigned char code; |
| 110 | |
| 111 | /* poll IR chip */ |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 112 | if (2 != i2c_master_recv(&ir->c, buf, 2)) |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 113 | return -EIO; |
| 114 | |
| 115 | /* Does eliminate repeated parity code */ |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 116 | if (buf[1] == 0xff) |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 117 | return 0; |
| 118 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 119 | ir->old = buf[1]; |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 120 | |
| 121 | /* Rearranges bits to the right order */ |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 122 | code = ((buf[0]&0x01)<<5) | /* 0010 0000 */ |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 123 | ((buf[0]&0x02)<<3) | /* 0001 0000 */ |
| 124 | ((buf[0]&0x04)<<1) | /* 0000 1000 */ |
| 125 | ((buf[0]&0x08)>>1) | /* 0000 0100 */ |
| 126 | ((buf[0]&0x10)>>3) | /* 0000 0010 */ |
| 127 | ((buf[0]&0x20)>>5); /* 0000 0001 */ |
| 128 | |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 129 | i2cdprintk("ir hauppauge (em2840): code=0x%02x (rcv=0x%02x)\n", |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 130 | code, buf[0]); |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 131 | |
| 132 | /* return key */ |
| 133 | *ir_key = code; |
| 134 | *ir_raw = code; |
| 135 | return 1; |
| 136 | } |
| 137 | |
Mauro Carvalho Chehab | c8793b0 | 2008-01-13 15:42:17 -0300 | [diff] [blame] | 138 | int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key, |
| 139 | u32 *ir_raw) |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 140 | { |
| 141 | unsigned char buf[3]; |
| 142 | |
| 143 | /* poll IR chip */ |
| 144 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 145 | if (3 != i2c_master_recv(&ir->c, buf, 3)) { |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 146 | i2cdprintk("read error\n"); |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 147 | return -EIO; |
| 148 | } |
| 149 | |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 150 | i2cdprintk("key %02x\n", buf[2]&0x3f); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 151 | if (buf[0] != 0x00) |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 152 | return 0; |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 153 | |
| 154 | *ir_key = buf[2]&0x3f; |
| 155 | *ir_raw = buf[2]&0x3f; |
| 156 | |
| 157 | return 1; |
| 158 | } |
| 159 | |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 160 | /********************************************************** |
| 161 | Poll based get keycode functions |
| 162 | **********************************************************/ |
| 163 | |
| 164 | static int default_polling_getkey(struct em28xx_IR *ir) |
| 165 | { |
| 166 | struct em28xx *dev = ir->dev; |
| 167 | int rc; |
| 168 | u32 msg; |
| 169 | |
| 170 | /* Read key toggle, brand, and key code */ |
| 171 | rc = dev->em28xx_read_reg_req_len(dev, 0, EM28XX_R45_IR, |
| 172 | (u8 *)&msg, sizeof(msg)); |
| 173 | if (rc < 0) |
| 174 | return rc; |
| 175 | |
| 176 | return (int)(msg & 0x7fffffffl); |
| 177 | } |
| 178 | |
| 179 | /********************************************************** |
| 180 | Polling code for em28xx |
| 181 | **********************************************************/ |
| 182 | |
| 183 | static void em28xx_ir_handle_key(struct em28xx_IR *ir) |
| 184 | { |
| 185 | int gpio; |
| 186 | u32 data; |
| 187 | |
| 188 | /* read gpio value */ |
| 189 | gpio = ir->get_key(ir); |
| 190 | if (gpio < 0) |
| 191 | return; |
| 192 | |
| 193 | if (gpio == ir->last_gpio) |
| 194 | return; |
| 195 | ir->last_gpio = gpio; |
| 196 | |
| 197 | /* extract data */ |
| 198 | data = ir_extract_bits(gpio, ir->mask_keycode); |
| 199 | dprintk("irq gpio=0x%x code=%d | poll%s%s\n", |
| 200 | gpio, data, |
| 201 | (gpio & ir->mask_keydown) ? " down" : "", |
| 202 | (gpio & ir->mask_keyup) ? " up" : ""); |
| 203 | |
| 204 | /* Generate keyup/keydown events */ |
| 205 | if (ir->mask_keydown) { |
| 206 | /* bit set on keydown */ |
| 207 | if (gpio & ir->mask_keydown) |
| 208 | ir_input_keydown(ir->input, &ir->ir, data, data); |
| 209 | else |
| 210 | ir_input_nokey(ir->input, &ir->ir); |
| 211 | } else if (ir->mask_keyup) { |
| 212 | /* bit cleared on keydown */ |
| 213 | if (!(gpio & ir->mask_keyup)) |
| 214 | ir_input_keydown(ir->input, &ir->ir, data, data); |
| 215 | else |
| 216 | ir_input_nokey(ir->input, &ir->ir); |
| 217 | } else { |
| 218 | /* can't distinguish keydown/up :-/ */ |
| 219 | ir_input_keydown(ir->input, &ir->ir, data, data); |
| 220 | ir_input_nokey(ir->input, &ir->ir); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | static void ir_timer(unsigned long data) |
| 225 | { |
| 226 | struct em28xx_IR *ir = (struct em28xx_IR *)data; |
| 227 | |
| 228 | schedule_work(&ir->work); |
| 229 | } |
| 230 | |
| 231 | static void em28xx_ir_work(struct work_struct *work) |
| 232 | { |
| 233 | struct em28xx_IR *ir = container_of(work, struct em28xx_IR, work); |
| 234 | |
| 235 | em28xx_ir_handle_key(ir); |
| 236 | mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling)); |
| 237 | } |
| 238 | |
| 239 | void em28xx_ir_start(struct em28xx_IR *ir) |
| 240 | { |
| 241 | setup_timer(&ir->timer, ir_timer, (unsigned long)ir); |
| 242 | INIT_WORK(&ir->work, em28xx_ir_work); |
| 243 | schedule_work(&ir->work); |
| 244 | } |
| 245 | |
| 246 | static void em28xx_ir_stop(struct em28xx_IR *ir) |
| 247 | { |
| 248 | del_timer_sync(&ir->timer); |
| 249 | flush_scheduled_work(); |
| 250 | } |
| 251 | |
| 252 | int em28xx_ir_init(struct em28xx *dev) |
| 253 | { |
| 254 | struct em28xx_IR *ir; |
| 255 | struct input_dev *input_dev; |
| 256 | IR_KEYTAB_TYPE *ir_codes = NULL; |
| 257 | int ir_type = IR_TYPE_OTHER; |
| 258 | int err = -ENOMEM; |
| 259 | |
| 260 | ir = kzalloc(sizeof(*ir), GFP_KERNEL); |
| 261 | input_dev = input_allocate_device(); |
| 262 | if (!ir || !input_dev) |
| 263 | goto err_out_free; |
| 264 | |
| 265 | ir->input = input_dev; |
| 266 | |
| 267 | /* */ |
| 268 | ir->get_key = default_polling_getkey; |
| 269 | ir->polling = 50; /* ms */ |
| 270 | |
| 271 | /* detect & configure */ |
| 272 | switch (dev->model) { |
Mauro Carvalho Chehab | 91812fa | 2008-11-12 14:05:46 -0300 | [diff] [blame^] | 273 | case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950: |
| 274 | ir_type = IR_TYPE_OTHER; |
| 275 | ir_codes = ir_codes_hauppauge_new; |
| 276 | ir->mask_keycode = 0x007f0000; |
| 277 | break; |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | if (NULL == ir_codes) { |
| 281 | err = -ENODEV; |
| 282 | goto err_out_free; |
| 283 | } |
| 284 | |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 285 | /* init input device */ |
| 286 | snprintf(ir->name, sizeof(ir->name), "em28xx IR (%s)", |
| 287 | dev->name); |
| 288 | |
| 289 | usb_make_path(dev->udev, ir->phys, sizeof(ir->phys)); |
| 290 | strlcat(ir->phys, "/input0", sizeof(ir->phys)); |
| 291 | |
| 292 | ir_input_init(input_dev, &ir->ir, ir_type, ir_codes); |
| 293 | input_dev->name = ir->name; |
| 294 | input_dev->phys = ir->phys; |
| 295 | input_dev->id.bustype = BUS_USB; |
| 296 | input_dev->id.version = 1; |
| 297 | input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor); |
| 298 | input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct); |
| 299 | |
| 300 | input_dev->dev.parent = &dev->udev->dev; |
| 301 | /* record handles to ourself */ |
| 302 | ir->dev = dev; |
| 303 | dev->ir = ir; |
| 304 | |
Mauro Carvalho Chehab | 91812fa | 2008-11-12 14:05:46 -0300 | [diff] [blame^] | 305 | /* Get the current key status, to avoid adding an |
| 306 | unexistent key code */ |
| 307 | ir->last_gpio = ir->get_key(ir); |
| 308 | |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 309 | em28xx_ir_start(ir); |
| 310 | |
| 311 | /* all done */ |
| 312 | err = input_register_device(ir->input); |
| 313 | if (err) |
| 314 | goto err_out_stop; |
| 315 | |
| 316 | return 0; |
| 317 | err_out_stop: |
| 318 | em28xx_ir_stop(ir); |
| 319 | dev->ir = NULL; |
| 320 | err_out_free: |
| 321 | input_free_device(input_dev); |
| 322 | kfree(ir); |
| 323 | return err; |
| 324 | } |
| 325 | |
| 326 | int em28xx_ir_fini(struct em28xx *dev) |
| 327 | { |
| 328 | struct em28xx_IR *ir = dev->ir; |
| 329 | |
| 330 | /* skip detach on non attached boards */ |
| 331 | if (!ir) |
| 332 | return 0; |
| 333 | |
| 334 | em28xx_ir_stop(ir); |
| 335 | input_unregister_device(ir->input); |
| 336 | kfree(ir); |
| 337 | |
| 338 | /* done */ |
| 339 | dev->ir = NULL; |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | /********************************************************** |
| 344 | Handle Webcam snapshot button |
| 345 | **********************************************************/ |
| 346 | |
Devin Heitmueller | a9fc52b | 2008-06-28 08:57:06 -0300 | [diff] [blame] | 347 | static void em28xx_query_sbutton(struct work_struct *work) |
| 348 | { |
| 349 | /* Poll the register and see if the button is depressed */ |
| 350 | struct em28xx *dev = |
| 351 | container_of(work, struct em28xx, sbutton_query_work.work); |
| 352 | int ret; |
| 353 | |
| 354 | ret = em28xx_read_reg(dev, EM28XX_R0C_USBSUSP); |
| 355 | |
| 356 | if (ret & EM28XX_R0C_USBSUSP_SNAPSHOT) { |
| 357 | u8 cleared; |
| 358 | /* Button is depressed, clear the register */ |
| 359 | cleared = ((u8) ret) & ~EM28XX_R0C_USBSUSP_SNAPSHOT; |
| 360 | em28xx_write_regs(dev, EM28XX_R0C_USBSUSP, &cleared, 1); |
| 361 | |
| 362 | /* Not emulate the keypress */ |
| 363 | input_report_key(dev->sbutton_input_dev, EM28XX_SNAPSHOT_KEY, |
| 364 | 1); |
| 365 | /* Now unpress the key */ |
| 366 | input_report_key(dev->sbutton_input_dev, EM28XX_SNAPSHOT_KEY, |
| 367 | 0); |
| 368 | } |
| 369 | |
| 370 | /* Schedule next poll */ |
| 371 | schedule_delayed_work(&dev->sbutton_query_work, |
| 372 | msecs_to_jiffies(EM28XX_SBUTTON_QUERY_INTERVAL)); |
| 373 | } |
| 374 | |
| 375 | void em28xx_register_snapshot_button(struct em28xx *dev) |
| 376 | { |
| 377 | struct input_dev *input_dev; |
| 378 | int err; |
| 379 | |
| 380 | em28xx_info("Registering snapshot button...\n"); |
| 381 | input_dev = input_allocate_device(); |
| 382 | if (!input_dev) { |
| 383 | em28xx_errdev("input_allocate_device failed\n"); |
| 384 | return; |
| 385 | } |
| 386 | |
| 387 | usb_make_path(dev->udev, dev->snapshot_button_path, |
| 388 | sizeof(dev->snapshot_button_path)); |
| 389 | strlcat(dev->snapshot_button_path, "/sbutton", |
| 390 | sizeof(dev->snapshot_button_path)); |
| 391 | INIT_DELAYED_WORK(&dev->sbutton_query_work, em28xx_query_sbutton); |
| 392 | |
| 393 | input_dev->name = "em28xx snapshot button"; |
| 394 | input_dev->phys = dev->snapshot_button_path; |
| 395 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); |
| 396 | set_bit(EM28XX_SNAPSHOT_KEY, input_dev->keybit); |
| 397 | input_dev->keycodesize = 0; |
| 398 | input_dev->keycodemax = 0; |
| 399 | input_dev->id.bustype = BUS_USB; |
| 400 | input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor); |
| 401 | input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct); |
| 402 | input_dev->id.version = 1; |
| 403 | input_dev->dev.parent = &dev->udev->dev; |
| 404 | |
| 405 | err = input_register_device(input_dev); |
| 406 | if (err) { |
| 407 | em28xx_errdev("input_register_device failed\n"); |
| 408 | input_free_device(input_dev); |
| 409 | return; |
| 410 | } |
| 411 | |
| 412 | dev->sbutton_input_dev = input_dev; |
| 413 | schedule_delayed_work(&dev->sbutton_query_work, |
| 414 | msecs_to_jiffies(EM28XX_SBUTTON_QUERY_INTERVAL)); |
| 415 | return; |
| 416 | |
| 417 | } |
| 418 | |
| 419 | void em28xx_deregister_snapshot_button(struct em28xx *dev) |
| 420 | { |
| 421 | if (dev->sbutton_input_dev != NULL) { |
| 422 | em28xx_info("Deregistering snapshot button\n"); |
| 423 | cancel_rearming_delayed_work(&dev->sbutton_query_work); |
| 424 | input_unregister_device(dev->sbutton_input_dev); |
| 425 | dev->sbutton_input_dev = NULL; |
| 426 | } |
| 427 | return; |
| 428 | } |