diff options
author | Frank Schaefer <fschaefer.oss@googlemail.com> | 2013-01-13 08:20:44 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2013-02-05 17:42:34 -0500 |
commit | 1d968cdaaec2ea994b2656c00b5a4f10d4159fe8 (patch) | |
tree | 40433c9b5e750de3d12a78d816b9993c5d62cc74 /drivers/media | |
parent | 450c7dd65b6c28c8f5b445c75bb55e8b84133bb9 (diff) |
[media] em28xx: i2c RC devices: minor code size and memory usage optimization
Set up the i2c_client locally in em28xx_i2c_ir_handle_key().
Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/usb/em28xx/em28xx-input.c | 42 |
1 files changed, 16 insertions, 26 deletions
diff --git a/drivers/media/usb/em28xx/em28xx-input.c b/drivers/media/usb/em28xx/em28xx-input.c index f3cff2bfb5ba..63b97285ddbd 100644 --- a/drivers/media/usb/em28xx/em28xx-input.c +++ b/drivers/media/usb/em28xx/em28xx-input.c | |||
@@ -69,8 +69,8 @@ struct em28xx_IR { | |||
69 | unsigned int last_readcount; | 69 | unsigned int last_readcount; |
70 | u64 rc_type; | 70 | u64 rc_type; |
71 | 71 | ||
72 | /* external device (if used) */ | 72 | /* i2c slave address of external device (if used) */ |
73 | struct i2c_client *i2c_dev; | 73 | u16 i2c_dev_addr; |
74 | 74 | ||
75 | int (*get_key_i2c)(struct i2c_client *, u32 *); | 75 | int (*get_key_i2c)(struct i2c_client *, u32 *); |
76 | int (*get_key)(struct em28xx_IR *, struct em28xx_ir_poll_result *); | 76 | int (*get_key)(struct em28xx_IR *, struct em28xx_ir_poll_result *); |
@@ -282,8 +282,12 @@ static int em28xx_i2c_ir_handle_key(struct em28xx_IR *ir) | |||
282 | { | 282 | { |
283 | static u32 ir_key; | 283 | static u32 ir_key; |
284 | int rc; | 284 | int rc; |
285 | struct i2c_client client; | ||
285 | 286 | ||
286 | rc = ir->get_key_i2c(ir->i2c_dev, &ir_key); | 287 | client.adapter = &ir->dev->i2c_adap; |
288 | client.addr = ir->i2c_dev_addr; | ||
289 | |||
290 | rc = ir->get_key_i2c(&client, &ir_key); | ||
287 | if (rc < 0) { | 291 | if (rc < 0) { |
288 | dprintk("ir->get_key_i2c() failed: %d\n", rc); | 292 | dprintk("ir->get_key_i2c() failed: %d\n", rc); |
289 | return rc; | 293 | return rc; |
@@ -354,7 +358,7 @@ static int em28xx_ir_start(struct rc_dev *rc) | |||
354 | { | 358 | { |
355 | struct em28xx_IR *ir = rc->priv; | 359 | struct em28xx_IR *ir = rc->priv; |
356 | 360 | ||
357 | if (ir->i2c_dev) /* external i2c device */ | 361 | if (ir->i2c_dev_addr) /* external i2c device */ |
358 | INIT_DELAYED_WORK(&ir->work, em28xx_i2c_ir_work); | 362 | INIT_DELAYED_WORK(&ir->work, em28xx_i2c_ir_work); |
359 | else /* internal device */ | 363 | else /* internal device */ |
360 | INIT_DELAYED_WORK(&ir->work, em28xx_ir_work); | 364 | INIT_DELAYED_WORK(&ir->work, em28xx_ir_work); |
@@ -454,10 +458,9 @@ static int em28xx_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_type) | |||
454 | } | 458 | } |
455 | } | 459 | } |
456 | 460 | ||
457 | static struct i2c_client *em28xx_probe_i2c_ir(struct em28xx *dev) | 461 | static int em28xx_probe_i2c_ir(struct em28xx *dev) |
458 | { | 462 | { |
459 | int i = 0; | 463 | int i = 0; |
460 | struct i2c_client *i2c_dev = NULL; | ||
461 | /* Leadtek winfast tv USBII deluxe can find a non working IR-device */ | 464 | /* Leadtek winfast tv USBII deluxe can find a non working IR-device */ |
462 | /* at address 0x18, so if that address is needed for another board in */ | 465 | /* at address 0x18, so if that address is needed for another board in */ |
463 | /* the future, please put it after 0x1f. */ | 466 | /* the future, please put it after 0x1f. */ |
@@ -466,21 +469,12 @@ static struct i2c_client *em28xx_probe_i2c_ir(struct em28xx *dev) | |||
466 | }; | 469 | }; |
467 | 470 | ||
468 | while (addr_list[i] != I2C_CLIENT_END) { | 471 | while (addr_list[i] != I2C_CLIENT_END) { |
469 | if (i2c_probe_func_quick_read(&dev->i2c_adap, addr_list[i]) == 1) { | 472 | if (i2c_probe_func_quick_read(&dev->i2c_adap, addr_list[i]) == 1) |
470 | i2c_dev = kzalloc(sizeof(*i2c_dev), GFP_KERNEL); | 473 | return addr_list[i]; |
471 | if (i2c_dev) { | ||
472 | i2c_dev->addr = addr_list[i]; | ||
473 | i2c_dev->adapter = &dev->i2c_adap; | ||
474 | /* NOTE: as long as we don't register the device | ||
475 | * at the i2c subsystem, no other fields need to | ||
476 | * be set up */ | ||
477 | } | ||
478 | break; | ||
479 | } | ||
480 | i++; | 474 | i++; |
481 | } | 475 | } |
482 | 476 | ||
483 | return i2c_dev; | 477 | return -ENODEV; |
484 | } | 478 | } |
485 | 479 | ||
486 | /********************************************************** | 480 | /********************************************************** |
@@ -576,14 +570,14 @@ static int em28xx_ir_init(struct em28xx *dev) | |||
576 | struct rc_dev *rc; | 570 | struct rc_dev *rc; |
577 | int err = -ENOMEM; | 571 | int err = -ENOMEM; |
578 | u64 rc_type; | 572 | u64 rc_type; |
579 | struct i2c_client *i2c_rc_dev = NULL; | 573 | u16 i2c_rc_dev_addr = 0; |
580 | 574 | ||
581 | if (dev->board.has_snapshot_button) | 575 | if (dev->board.has_snapshot_button) |
582 | em28xx_register_snapshot_button(dev); | 576 | em28xx_register_snapshot_button(dev); |
583 | 577 | ||
584 | if (dev->board.has_ir_i2c) { | 578 | if (dev->board.has_ir_i2c) { |
585 | i2c_rc_dev = em28xx_probe_i2c_ir(dev); | 579 | i2c_rc_dev_addr = em28xx_probe_i2c_ir(dev); |
586 | if (!i2c_rc_dev) { | 580 | if (!i2c_rc_dev_addr) { |
587 | dev->board.has_ir_i2c = 0; | 581 | dev->board.has_ir_i2c = 0; |
588 | em28xx_warn("No i2c IR remote control device found.\n"); | 582 | em28xx_warn("No i2c IR remote control device found.\n"); |
589 | return -ENODEV; | 583 | return -ENODEV; |
@@ -636,7 +630,7 @@ static int em28xx_ir_init(struct em28xx *dev) | |||
636 | goto error; | 630 | goto error; |
637 | } | 631 | } |
638 | 632 | ||
639 | ir->i2c_dev = i2c_rc_dev; | 633 | ir->i2c_dev_addr = i2c_rc_dev_addr; |
640 | } else { /* internal device */ | 634 | } else { /* internal device */ |
641 | switch (dev->chip_id) { | 635 | switch (dev->chip_id) { |
642 | case CHIP_ID_EM2860: | 636 | case CHIP_ID_EM2860: |
@@ -692,8 +686,6 @@ static int em28xx_ir_init(struct em28xx *dev) | |||
692 | return 0; | 686 | return 0; |
693 | 687 | ||
694 | error: | 688 | error: |
695 | if (ir && ir->i2c_dev) | ||
696 | kfree(ir->i2c_dev); | ||
697 | dev->ir = NULL; | 689 | dev->ir = NULL; |
698 | rc_free_device(rc); | 690 | rc_free_device(rc); |
699 | kfree(ir); | 691 | kfree(ir); |
@@ -713,8 +705,6 @@ static int em28xx_ir_fini(struct em28xx *dev) | |||
713 | if (ir->rc) | 705 | if (ir->rc) |
714 | rc_unregister_device(ir->rc); | 706 | rc_unregister_device(ir->rc); |
715 | 707 | ||
716 | kfree(ir->i2c_dev); | ||
717 | |||
718 | /* done */ | 708 | /* done */ |
719 | kfree(ir); | 709 | kfree(ir); |
720 | dev->ir = NULL; | 710 | dev->ir = NULL; |