Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

media: i2c: ov9734: Replace client->dev usage

The driver needs to access the struct device in many places, and
retrieves it from the i2c_client itself retrieved with
v4l2_get_subdevdata(). Store it as a pointer in struct ov9734 and access
it from there instead, to simplify the driver.

While at it, fix a mistake in the sort order of include statements.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Mehdi Djait <mehdi.djait@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>

authored by

Laurent Pinchart and committed by
Mauro Carvalho Chehab
9f16195e 5b428a40

+28 -30
+28 -30
drivers/media/i2c/ov9734.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 // Copyright (c) 2020 Intel Corporation. 3 3 4 - #include <linux/unaligned.h> 5 4 #include <linux/acpi.h> 6 5 #include <linux/delay.h> 7 6 #include <linux/i2c.h> 8 7 #include <linux/module.h> 9 8 #include <linux/pm_runtime.h> 9 + #include <linux/unaligned.h> 10 + 10 11 #include <media/v4l2-ctrls.h> 11 12 #include <media/v4l2-device.h> 12 13 #include <media/v4l2-fwnode.h> ··· 322 321 }; 323 322 324 323 struct ov9734 { 324 + struct device *dev; 325 + 325 326 struct v4l2_subdev sd; 326 327 struct media_pad pad; 327 328 struct v4l2_ctrl_handler ctrl_handler; ··· 417 414 static int ov9734_write_reg_list(struct ov9734 *ov9734, 418 415 const struct ov9734_reg_list *r_list) 419 416 { 420 - struct i2c_client *client = v4l2_get_subdevdata(&ov9734->sd); 421 417 unsigned int i; 422 418 int ret; 423 419 ··· 424 422 ret = ov9734_write_reg(ov9734, r_list->regs[i].address, 1, 425 423 r_list->regs[i].val); 426 424 if (ret) { 427 - dev_err_ratelimited(&client->dev, 425 + dev_err_ratelimited(ov9734->dev, 428 426 "write reg 0x%4.4x return err = %d", 429 427 r_list->regs[i].address, ret); 430 428 return ret; ··· 478 476 { 479 477 struct ov9734 *ov9734 = container_of(ctrl->handler, 480 478 struct ov9734, ctrl_handler); 481 - struct i2c_client *client = v4l2_get_subdevdata(&ov9734->sd); 482 479 s64 exposure_max; 483 480 int ret = 0; 484 481 ··· 493 492 } 494 493 495 494 /* V4L2 controls values will be applied only when power is already up */ 496 - if (!pm_runtime_get_if_in_use(&client->dev)) 495 + if (!pm_runtime_get_if_in_use(ov9734->dev)) 497 496 return 0; 498 497 499 498 switch (ctrl->id) { ··· 526 525 break; 527 526 } 528 527 529 - pm_runtime_put(&client->dev); 528 + pm_runtime_put(ov9734->dev); 530 529 531 530 return ret; 532 531 } ··· 611 610 612 611 static int ov9734_start_streaming(struct ov9734 *ov9734) 613 612 { 614 - struct i2c_client *client = v4l2_get_subdevdata(&ov9734->sd); 615 613 const struct ov9734_reg_list *reg_list; 616 614 int link_freq_index, ret; 617 615 ··· 618 618 reg_list = &link_freq_configs[link_freq_index].reg_list; 619 619 ret = ov9734_write_reg_list(ov9734, reg_list); 620 620 if (ret) { 621 - dev_err(&client->dev, "failed to set plls"); 621 + dev_err(ov9734->dev, "failed to set plls"); 622 622 return ret; 623 623 } 624 624 625 625 reg_list = &ov9734->cur_mode->reg_list; 626 626 ret = ov9734_write_reg_list(ov9734, reg_list); 627 627 if (ret) { 628 - dev_err(&client->dev, "failed to set mode"); 628 + dev_err(ov9734->dev, "failed to set mode"); 629 629 return ret; 630 630 } 631 631 ··· 636 636 ret = ov9734_write_reg(ov9734, OV9734_REG_MODE_SELECT, 637 637 1, OV9734_MODE_STREAMING); 638 638 if (ret) 639 - dev_err(&client->dev, "failed to start stream"); 639 + dev_err(ov9734->dev, "failed to start stream"); 640 640 641 641 return ret; 642 642 } 643 643 644 644 static void ov9734_stop_streaming(struct ov9734 *ov9734) 645 645 { 646 - struct i2c_client *client = v4l2_get_subdevdata(&ov9734->sd); 647 - 648 646 if (ov9734_write_reg(ov9734, OV9734_REG_MODE_SELECT, 649 647 1, OV9734_MODE_STANDBY)) 650 - dev_err(&client->dev, "failed to stop stream"); 648 + dev_err(ov9734->dev, "failed to stop stream"); 651 649 } 652 650 653 651 static int ov9734_set_stream(struct v4l2_subdev *sd, int enable) 654 652 { 655 653 struct ov9734 *ov9734 = to_ov9734(sd); 656 - struct i2c_client *client = v4l2_get_subdevdata(sd); 657 654 int ret = 0; 658 655 659 656 mutex_lock(&ov9734->mutex); 660 657 661 658 if (enable) { 662 - ret = pm_runtime_resume_and_get(&client->dev); 659 + ret = pm_runtime_resume_and_get(ov9734->dev); 663 660 if (ret < 0) { 664 661 mutex_unlock(&ov9734->mutex); 665 662 return ret; ··· 666 669 if (ret) { 667 670 enable = 0; 668 671 ov9734_stop_streaming(ov9734); 669 - pm_runtime_put(&client->dev); 672 + pm_runtime_put(ov9734->dev); 670 673 } 671 674 } else { 672 675 ov9734_stop_streaming(ov9734); 673 - pm_runtime_put(&client->dev); 676 + pm_runtime_put(ov9734->dev); 674 677 } 675 678 676 679 mutex_unlock(&ov9734->mutex); ··· 805 808 806 809 static int ov9734_identify_module(struct ov9734 *ov9734) 807 810 { 808 - struct i2c_client *client = v4l2_get_subdevdata(&ov9734->sd); 809 811 int ret; 810 812 u32 val; 811 813 ··· 813 817 return ret; 814 818 815 819 if (val != OV9734_CHIP_ID) { 816 - dev_err(&client->dev, "chip id mismatch: %x!=%x", 820 + dev_err(ov9734->dev, "chip id mismatch: %x!=%x", 817 821 OV9734_CHIP_ID, val); 818 822 return -ENXIO; 819 823 } ··· 888 892 v4l2_async_unregister_subdev(sd); 889 893 media_entity_cleanup(&sd->entity); 890 894 v4l2_ctrl_handler_free(sd->ctrl_handler); 891 - pm_runtime_disable(&client->dev); 892 - pm_runtime_set_suspended(&client->dev); 895 + pm_runtime_disable(ov9734->dev); 896 + pm_runtime_set_suspended(ov9734->dev); 893 897 mutex_destroy(&ov9734->mutex); 894 898 } 895 899 ··· 909 913 if (!ov9734) 910 914 return -ENOMEM; 911 915 916 + ov9734->dev = &client->dev; 917 + 912 918 v4l2_i2c_subdev_init(&ov9734->sd, client, &ov9734_subdev_ops); 913 919 ret = ov9734_identify_module(ov9734); 914 920 if (ret) { 915 - dev_err(&client->dev, "failed to find sensor: %d", ret); 921 + dev_err(ov9734->dev, "failed to find sensor: %d", ret); 916 922 return ret; 917 923 } 918 924 ··· 922 924 ov9734->cur_mode = &supported_modes[0]; 923 925 ret = ov9734_init_controls(ov9734); 924 926 if (ret) { 925 - dev_err(&client->dev, "failed to init controls: %d", ret); 927 + dev_err(ov9734->dev, "failed to init controls: %d", ret); 926 928 goto probe_error_v4l2_ctrl_handler_free; 927 929 } 928 930 ··· 933 935 ov9734->pad.flags = MEDIA_PAD_FL_SOURCE; 934 936 ret = media_entity_pads_init(&ov9734->sd.entity, 1, &ov9734->pad); 935 937 if (ret) { 936 - dev_err(&client->dev, "failed to init entity pads: %d", ret); 938 + dev_err(ov9734->dev, "failed to init entity pads: %d", ret); 937 939 goto probe_error_v4l2_ctrl_handler_free; 938 940 } 939 941 ··· 941 943 * Device is already turned on by i2c-core with ACPI domain PM. 942 944 * Enable runtime PM and turn off the device. 943 945 */ 944 - pm_runtime_set_active(&client->dev); 945 - pm_runtime_enable(&client->dev); 946 - pm_runtime_idle(&client->dev); 946 + pm_runtime_set_active(ov9734->dev); 947 + pm_runtime_enable(ov9734->dev); 948 + pm_runtime_idle(ov9734->dev); 947 949 948 950 ret = v4l2_async_register_subdev_sensor(&ov9734->sd); 949 951 if (ret < 0) { 950 - dev_err(&client->dev, "failed to register V4L2 subdev: %d", 952 + dev_err(ov9734->dev, "failed to register V4L2 subdev: %d", 951 953 ret); 952 954 goto probe_error_media_entity_cleanup_pm; 953 955 } ··· 955 957 return 0; 956 958 957 959 probe_error_media_entity_cleanup_pm: 958 - pm_runtime_disable(&client->dev); 959 - pm_runtime_set_suspended(&client->dev); 960 + pm_runtime_disable(ov9734->dev); 961 + pm_runtime_set_suspended(ov9734->dev); 960 962 media_entity_cleanup(&ov9734->sd.entity); 961 963 962 964 probe_error_v4l2_ctrl_handler_free: