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

media: i2c: ov2740: 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 ov2740 and access
it from there instead, to simplify the driver.

While at it, fix mistakes 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
fdba8eba 964ae05b

+31 -36
+31 -36
drivers/media/i2c/ov2740.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/clk.h> 7 6 #include <linux/delay.h> 8 7 #include <linux/gpio/consumer.h> 9 8 #include <linux/i2c.h> 10 9 #include <linux/module.h> 11 - #include <linux/pm_runtime.h> 12 10 #include <linux/nvmem-provider.h> 11 + #include <linux/pm_runtime.h> 13 12 #include <linux/regmap.h> 14 13 #include <linux/regulator/consumer.h> 14 + #include <linux/unaligned.h> 15 15 #include <media/v4l2-ctrls.h> 16 16 #include <media/v4l2-device.h> 17 17 #include <media/v4l2-fwnode.h> ··· 519 519 }; 520 520 521 521 struct ov2740 { 522 + struct device *dev; 523 + 522 524 struct v4l2_subdev sd; 523 525 struct media_pad pad; 524 526 struct v4l2_ctrl_handler ctrl_handler; ··· 618 616 static int ov2740_write_reg_list(struct ov2740 *ov2740, 619 617 const struct ov2740_reg_list *r_list) 620 618 { 621 - struct i2c_client *client = v4l2_get_subdevdata(&ov2740->sd); 622 619 unsigned int i; 623 620 int ret; 624 621 ··· 625 624 ret = ov2740_write_reg(ov2740, r_list->regs[i].address, 1, 626 625 r_list->regs[i].val); 627 626 if (ret) { 628 - dev_err_ratelimited(&client->dev, 627 + dev_err_ratelimited(ov2740->dev, 629 628 "write reg 0x%4.4x return err = %d\n", 630 629 r_list->regs[i].address, ret); 631 630 return ret; ··· 637 636 638 637 static int ov2740_identify_module(struct ov2740 *ov2740) 639 638 { 640 - struct i2c_client *client = v4l2_get_subdevdata(&ov2740->sd); 641 639 int ret; 642 640 u32 val; 643 641 ··· 648 648 return ret; 649 649 650 650 if (val != OV2740_CHIP_ID) { 651 - dev_err(&client->dev, "chip id mismatch: %x != %x\n", 651 + dev_err(ov2740->dev, "chip id mismatch: %x != %x\n", 652 652 OV2740_CHIP_ID, val); 653 653 return -ENXIO; 654 654 } 655 655 656 - dev_dbg(&client->dev, "chip id: 0x%x\n", val); 656 + dev_dbg(ov2740->dev, "chip id: 0x%x\n", val); 657 657 658 658 ov2740->identified = true; 659 659 ··· 704 704 { 705 705 struct ov2740 *ov2740 = container_of(ctrl->handler, 706 706 struct ov2740, ctrl_handler); 707 - struct i2c_client *client = v4l2_get_subdevdata(&ov2740->sd); 708 707 s64 exposure_max; 709 708 int ret; 710 709 ··· 719 720 } 720 721 721 722 /* V4L2 controls values will be applied only when power is already up */ 722 - if (!pm_runtime_get_if_in_use(&client->dev)) 723 + if (!pm_runtime_get_if_in_use(ov2740->dev)) 723 724 return 0; 724 725 725 726 switch (ctrl->id) { ··· 752 753 break; 753 754 } 754 755 755 - pm_runtime_put(&client->dev); 756 + pm_runtime_put(ov2740->dev); 756 757 757 758 return ret; 758 759 } ··· 763 764 764 765 static int ov2740_init_controls(struct ov2740 *ov2740) 765 766 { 766 - struct i2c_client *client = v4l2_get_subdevdata(&ov2740->sd); 767 767 struct v4l2_ctrl_handler *ctrl_hdlr; 768 768 s64 exposure_max, h_blank, pixel_rate; 769 769 u32 vblank_min, vblank_max, vblank_default; ··· 819 821 ARRAY_SIZE(ov2740_test_pattern_menu) - 1, 820 822 0, 0, ov2740_test_pattern_menu); 821 823 822 - ret = v4l2_fwnode_device_parse(&client->dev, &props); 824 + ret = v4l2_fwnode_device_parse(ov2740->dev, &props); 823 825 if (ret) { 824 826 v4l2_ctrl_handler_free(ctrl_hdlr); 825 827 return ret; ··· 938 940 939 941 static int ov2740_start_streaming(struct ov2740 *ov2740) 940 942 { 941 - struct i2c_client *client = v4l2_get_subdevdata(&ov2740->sd); 942 943 const struct ov2740_reg_list *reg_list; 943 944 int link_freq_index; 944 945 int ret; ··· 952 955 /* Reset the sensor */ 953 956 ret = ov2740_write_reg(ov2740, 0x0103, 1, 0x01); 954 957 if (ret) { 955 - dev_err(&client->dev, "failed to reset\n"); 958 + dev_err(ov2740->dev, "failed to reset\n"); 956 959 return ret; 957 960 } 958 961 ··· 962 965 reg_list = &link_freq_configs[link_freq_index].reg_list; 963 966 ret = ov2740_write_reg_list(ov2740, reg_list); 964 967 if (ret) { 965 - dev_err(&client->dev, "failed to set plls\n"); 968 + dev_err(ov2740->dev, "failed to set plls\n"); 966 969 return ret; 967 970 } 968 971 969 972 reg_list = &ov2740->cur_mode->reg_list; 970 973 ret = ov2740_write_reg_list(ov2740, reg_list); 971 974 if (ret) { 972 - dev_err(&client->dev, "failed to set mode\n"); 975 + dev_err(ov2740->dev, "failed to set mode\n"); 973 976 return ret; 974 977 } 975 978 ··· 980 983 ret = ov2740_write_reg(ov2740, OV2740_REG_MODE_SELECT, 1, 981 984 OV2740_MODE_STREAMING); 982 985 if (ret) 983 - dev_err(&client->dev, "failed to start streaming\n"); 986 + dev_err(ov2740->dev, "failed to start streaming\n"); 984 987 985 988 return ret; 986 989 } 987 990 988 991 static void ov2740_stop_streaming(struct ov2740 *ov2740) 989 992 { 990 - struct i2c_client *client = v4l2_get_subdevdata(&ov2740->sd); 991 - 992 993 if (ov2740_write_reg(ov2740, OV2740_REG_MODE_SELECT, 1, 993 994 OV2740_MODE_STANDBY)) 994 - dev_err(&client->dev, "failed to stop streaming\n"); 995 + dev_err(ov2740->dev, "failed to stop streaming\n"); 995 996 } 996 997 997 998 static int ov2740_set_stream(struct v4l2_subdev *sd, int enable) 998 999 { 999 1000 struct ov2740 *ov2740 = to_ov2740(sd); 1000 - struct i2c_client *client = v4l2_get_subdevdata(sd); 1001 1001 struct v4l2_subdev_state *sd_state; 1002 1002 int ret = 0; 1003 1003 1004 1004 sd_state = v4l2_subdev_lock_and_get_active_state(&ov2740->sd); 1005 1005 1006 1006 if (enable) { 1007 - ret = pm_runtime_resume_and_get(&client->dev); 1007 + ret = pm_runtime_resume_and_get(ov2740->dev); 1008 1008 if (ret < 0) 1009 1009 goto out_unlock; 1010 1010 ··· 1009 1015 if (ret) { 1010 1016 enable = 0; 1011 1017 ov2740_stop_streaming(ov2740); 1012 - pm_runtime_put(&client->dev); 1018 + pm_runtime_put(ov2740->dev); 1013 1019 } 1014 1020 } else { 1015 1021 ov2740_stop_streaming(ov2740); 1016 - pm_runtime_put(&client->dev); 1022 + pm_runtime_put(ov2740->dev); 1017 1023 } 1018 1024 1019 1025 out_unlock: ··· 1125 1131 .link_validate = v4l2_subdev_link_validate, 1126 1132 }; 1127 1133 1128 - static int ov2740_check_hwcfg(struct device *dev) 1134 + static int ov2740_check_hwcfg(struct ov2740 *ov2740) 1129 1135 { 1130 - struct v4l2_subdev *sd = dev_get_drvdata(dev); 1131 - struct ov2740 *ov2740 = to_ov2740(sd); 1136 + struct device *dev = ov2740->dev; 1132 1137 struct fwnode_handle *ep; 1133 1138 struct fwnode_handle *fwnode = dev_fwnode(dev); 1134 1139 struct v4l2_fwnode_endpoint bus_cfg = { ··· 1263 1270 struct regmap_config regmap_config = { }; 1264 1271 struct nvmem_config nvmem_config = { }; 1265 1272 struct regmap *regmap; 1266 - struct device *dev = &client->dev; 1273 + struct device *dev = ov2740->dev; 1267 1274 1268 1275 nvm = devm_kzalloc(dev, sizeof(*nvm), GFP_KERNEL); 1269 1276 if (!nvm) ··· 1350 1357 if (!ov2740) 1351 1358 return -ENOMEM; 1352 1359 1360 + ov2740->dev = &client->dev; 1361 + 1353 1362 v4l2_i2c_subdev_init(&ov2740->sd, client, &ov2740_subdev_ops); 1354 1363 ov2740->sd.internal_ops = &ov2740_internal_ops; 1355 1364 1356 - ret = ov2740_check_hwcfg(dev); 1365 + ret = ov2740_check_hwcfg(ov2740); 1357 1366 if (ret) 1358 1367 return ret; 1359 1368 ··· 1392 1397 if (ret) 1393 1398 return dev_err_probe(dev, ret, "failed to get regulators\n"); 1394 1399 1395 - full_power = acpi_dev_state_d0(&client->dev); 1400 + full_power = acpi_dev_state_d0(ov2740->dev); 1396 1401 if (full_power) { 1397 1402 /* ACPI does not always clear the reset GPIO / enable the clock */ 1398 1403 ret = ov2740_resume(dev); ··· 1430 1435 1431 1436 /* Set the device's state to active if it's in D0 state. */ 1432 1437 if (full_power) 1433 - pm_runtime_set_active(&client->dev); 1434 - pm_runtime_enable(&client->dev); 1435 - pm_runtime_idle(&client->dev); 1438 + pm_runtime_set_active(ov2740->dev); 1439 + pm_runtime_enable(ov2740->dev); 1440 + pm_runtime_idle(ov2740->dev); 1436 1441 1437 1442 ret = v4l2_async_register_subdev_sensor(&ov2740->sd); 1438 1443 if (ret < 0) { ··· 1442 1447 1443 1448 ret = ov2740_register_nvmem(client, ov2740); 1444 1449 if (ret) 1445 - dev_warn(&client->dev, "register nvmem failed, ret %d\n", ret); 1450 + dev_warn(ov2740->dev, "register nvmem failed, ret %d\n", ret); 1446 1451 1447 1452 return 0; 1448 1453 1449 1454 probe_error_v4l2_subdev_cleanup: 1450 - pm_runtime_disable(&client->dev); 1451 - pm_runtime_set_suspended(&client->dev); 1455 + pm_runtime_disable(ov2740->dev); 1456 + pm_runtime_set_suspended(ov2740->dev); 1452 1457 v4l2_subdev_cleanup(&ov2740->sd); 1453 1458 1454 1459 probe_error_media_entity_cleanup: