aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/em28xx/em28xx-input.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/em28xx/em28xx-input.c')
-rw-r--r--drivers/media/video/em28xx/em28xx-input.c78
1 files changed, 36 insertions, 42 deletions
diff --git a/drivers/media/video/em28xx/em28xx-input.c b/drivers/media/video/em28xx/em28xx-input.c
index 6759cd5570dd..29cc74441a7d 100644
--- a/drivers/media/video/em28xx/em28xx-input.c
+++ b/drivers/media/video/em28xx/em28xx-input.c
@@ -25,7 +25,6 @@
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/input.h>
29#include <linux/usb.h> 28#include <linux/usb.h>
30#include <linux/slab.h> 29#include <linux/slab.h>
31 30
@@ -64,7 +63,7 @@ struct em28xx_ir_poll_result {
64 63
65struct em28xx_IR { 64struct em28xx_IR {
66 struct em28xx *dev; 65 struct em28xx *dev;
67 struct input_dev *input; 66 struct rc_dev *rc;
68 char name[32]; 67 char name[32];
69 char phys[32]; 68 char phys[32];
70 69
@@ -75,10 +74,6 @@ struct em28xx_IR {
75 unsigned int last_readcount; 74 unsigned int last_readcount;
76 75
77 int (*get_key)(struct em28xx_IR *, struct em28xx_ir_poll_result *); 76 int (*get_key)(struct em28xx_IR *, struct em28xx_ir_poll_result *);
78
79 /* IR device properties */
80
81 struct ir_dev_props props;
82}; 77};
83 78
84/********************************************************** 79/**********************************************************
@@ -302,12 +297,12 @@ static void em28xx_ir_handle_key(struct em28xx_IR *ir)
302 poll_result.toggle_bit, poll_result.read_count, 297 poll_result.toggle_bit, poll_result.read_count,
303 poll_result.rc_address, poll_result.rc_data[0]); 298 poll_result.rc_address, poll_result.rc_data[0]);
304 if (ir->full_code) 299 if (ir->full_code)
305 ir_keydown(ir->input, 300 rc_keydown(ir->rc,
306 poll_result.rc_address << 8 | 301 poll_result.rc_address << 8 |
307 poll_result.rc_data[0], 302 poll_result.rc_data[0],
308 poll_result.toggle_bit); 303 poll_result.toggle_bit);
309 else 304 else
310 ir_keydown(ir->input, 305 rc_keydown(ir->rc,
311 poll_result.rc_data[0], 306 poll_result.rc_data[0],
312 poll_result.toggle_bit); 307 poll_result.toggle_bit);
313 308
@@ -331,9 +326,9 @@ static void em28xx_ir_work(struct work_struct *work)
331 schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling)); 326 schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
332} 327}
333 328
334static int em28xx_ir_start(void *priv) 329static int em28xx_ir_start(struct rc_dev *rc)
335{ 330{
336 struct em28xx_IR *ir = priv; 331 struct em28xx_IR *ir = rc->priv;
337 332
338 INIT_DELAYED_WORK(&ir->work, em28xx_ir_work); 333 INIT_DELAYED_WORK(&ir->work, em28xx_ir_work);
339 schedule_delayed_work(&ir->work, 0); 334 schedule_delayed_work(&ir->work, 0);
@@ -341,30 +336,30 @@ static int em28xx_ir_start(void *priv)
341 return 0; 336 return 0;
342} 337}
343 338
344static void em28xx_ir_stop(void *priv) 339static void em28xx_ir_stop(struct rc_dev *rc)
345{ 340{
346 struct em28xx_IR *ir = priv; 341 struct em28xx_IR *ir = rc->priv;
347 342
348 cancel_delayed_work_sync(&ir->work); 343 cancel_delayed_work_sync(&ir->work);
349} 344}
350 345
351int em28xx_ir_change_protocol(void *priv, u64 ir_type) 346int em28xx_ir_change_protocol(struct rc_dev *rc_dev, u64 rc_type)
352{ 347{
353 int rc = 0; 348 int rc = 0;
354 struct em28xx_IR *ir = priv; 349 struct em28xx_IR *ir = rc_dev->priv;
355 struct em28xx *dev = ir->dev; 350 struct em28xx *dev = ir->dev;
356 u8 ir_config = EM2874_IR_RC5; 351 u8 ir_config = EM2874_IR_RC5;
357 352
358 /* Adjust xclk based o IR table for RC5/NEC tables */ 353 /* Adjust xclk based o IR table for RC5/NEC tables */
359 354
360 if (ir_type == IR_TYPE_RC5) { 355 if (rc_type == RC_TYPE_RC5) {
361 dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE; 356 dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
362 ir->full_code = 1; 357 ir->full_code = 1;
363 } else if (ir_type == IR_TYPE_NEC) { 358 } else if (rc_type == RC_TYPE_NEC) {
364 dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE; 359 dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE;
365 ir_config = EM2874_IR_NEC; 360 ir_config = EM2874_IR_NEC;
366 ir->full_code = 1; 361 ir->full_code = 1;
367 } else if (ir_type != IR_TYPE_UNKNOWN) 362 } else if (rc_type != RC_TYPE_UNKNOWN)
368 rc = -EINVAL; 363 rc = -EINVAL;
369 364
370 em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk, 365 em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk,
@@ -391,7 +386,7 @@ int em28xx_ir_change_protocol(void *priv, u64 ir_type)
391int em28xx_ir_init(struct em28xx *dev) 386int em28xx_ir_init(struct em28xx *dev)
392{ 387{
393 struct em28xx_IR *ir; 388 struct em28xx_IR *ir;
394 struct input_dev *input_dev; 389 struct rc_dev *rc;
395 int err = -ENOMEM; 390 int err = -ENOMEM;
396 391
397 if (dev->board.ir_codes == NULL) { 392 if (dev->board.ir_codes == NULL) {
@@ -400,28 +395,27 @@ int em28xx_ir_init(struct em28xx *dev)
400 } 395 }
401 396
402 ir = kzalloc(sizeof(*ir), GFP_KERNEL); 397 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
403 input_dev = input_allocate_device(); 398 rc = rc_allocate_device();
404 if (!ir || !input_dev) 399 if (!ir || !rc)
405 goto err_out_free; 400 goto err_out_free;
406 401
407 /* record handles to ourself */ 402 /* record handles to ourself */
408 ir->dev = dev; 403 ir->dev = dev;
409 dev->ir = ir; 404 dev->ir = ir;
410 405 ir->rc = rc;
411 ir->input = input_dev;
412 406
413 /* 407 /*
414 * em2874 supports more protocols. For now, let's just announce 408 * em2874 supports more protocols. For now, let's just announce
415 * the two protocols that were already tested 409 * the two protocols that were already tested
416 */ 410 */
417 ir->props.allowed_protos = IR_TYPE_RC5 | IR_TYPE_NEC; 411 rc->allowed_protos = RC_TYPE_RC5 | RC_TYPE_NEC;
418 ir->props.priv = ir; 412 rc->priv = ir;
419 ir->props.change_protocol = em28xx_ir_change_protocol; 413 rc->change_protocol = em28xx_ir_change_protocol;
420 ir->props.open = em28xx_ir_start; 414 rc->open = em28xx_ir_start;
421 ir->props.close = em28xx_ir_stop; 415 rc->close = em28xx_ir_stop;
422 416
423 /* By default, keep protocol field untouched */ 417 /* By default, keep protocol field untouched */
424 err = em28xx_ir_change_protocol(ir, IR_TYPE_UNKNOWN); 418 err = em28xx_ir_change_protocol(rc, RC_TYPE_UNKNOWN);
425 if (err) 419 if (err)
426 goto err_out_free; 420 goto err_out_free;
427 421
@@ -435,27 +429,27 @@ int em28xx_ir_init(struct em28xx *dev)
435 usb_make_path(dev->udev, ir->phys, sizeof(ir->phys)); 429 usb_make_path(dev->udev, ir->phys, sizeof(ir->phys));
436 strlcat(ir->phys, "/input0", sizeof(ir->phys)); 430 strlcat(ir->phys, "/input0", sizeof(ir->phys));
437 431
438 input_dev->name = ir->name; 432 rc->input_name = ir->name;
439 input_dev->phys = ir->phys; 433 rc->input_phys = ir->phys;
440 input_dev->id.bustype = BUS_USB; 434 rc->input_id.bustype = BUS_USB;
441 input_dev->id.version = 1; 435 rc->input_id.version = 1;
442 input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor); 436 rc->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
443 input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct); 437 rc->input_id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
444 438 rc->dev.parent = &dev->udev->dev;
445 input_dev->dev.parent = &dev->udev->dev; 439 rc->map_name = dev->board.ir_codes;
446 440 rc->driver_name = MODULE_NAME;
447
448 441
449 /* all done */ 442 /* all done */
450 err = ir_input_register(ir->input, dev->board.ir_codes, 443 err = rc_register_device(rc);
451 &ir->props, MODULE_NAME);
452 if (err) 444 if (err)
453 goto err_out_stop; 445 goto err_out_stop;
454 446
455 return 0; 447 return 0;
448
456 err_out_stop: 449 err_out_stop:
457 dev->ir = NULL; 450 dev->ir = NULL;
458 err_out_free: 451 err_out_free:
452 rc_free_device(rc);
459 kfree(ir); 453 kfree(ir);
460 return err; 454 return err;
461} 455}
@@ -468,8 +462,8 @@ int em28xx_ir_fini(struct em28xx *dev)
468 if (!ir) 462 if (!ir)
469 return 0; 463 return 0;
470 464
471 em28xx_ir_stop(ir); 465 em28xx_ir_stop(ir->rc);
472 ir_input_unregister(ir->input); 466 rc_unregister_device(ir->rc);
473 kfree(ir); 467 kfree(ir);
474 468
475 /* done */ 469 /* done */