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: ov5675: 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 ov5675 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
381045e4 2fc08984

+36 -38
+36 -38
drivers/media/i2c/ov5675.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 // Copyright (c) 2019 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> ··· 10 11 #include <linux/module.h> 11 12 #include <linux/pm_runtime.h> 12 13 #include <linux/regulator/consumer.h> 14 + #include <linux/unaligned.h> 15 + 13 16 #include <media/v4l2-ctrls.h> 14 17 #include <media/v4l2-device.h> 15 18 #include <media/v4l2-fwnode.h> ··· 494 493 }; 495 494 496 495 struct ov5675 { 496 + struct device *dev; 497 + 497 498 struct v4l2_subdev sd; 498 499 struct media_pad pad; 499 500 struct v4l2_ctrl_handler ctrl_handler; ··· 587 584 static int ov5675_write_reg_list(struct ov5675 *ov5675, 588 585 const struct ov5675_reg_list *r_list) 589 586 { 590 - struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd); 591 587 unsigned int i; 592 588 int ret; 593 589 ··· 594 592 ret = ov5675_write_reg(ov5675, r_list->regs[i].address, 1, 595 593 r_list->regs[i].val); 596 594 if (ret) { 597 - dev_err_ratelimited(&client->dev, 595 + dev_err_ratelimited(ov5675->dev, 598 596 "failed to write reg 0x%4.4x. error = %d", 599 597 r_list->regs[i].address, ret); 600 598 return ret; ··· 702 700 { 703 701 struct ov5675 *ov5675 = container_of(ctrl->handler, 704 702 struct ov5675, ctrl_handler); 705 - struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd); 706 703 s64 exposure_max; 707 704 int ret = 0; 708 705 ··· 717 716 } 718 717 719 718 /* V4L2 controls values will be applied only when power is already up */ 720 - if (!pm_runtime_get_if_in_use(&client->dev)) 719 + if (!pm_runtime_get_if_in_use(ov5675->dev)) 721 720 return 0; 722 721 723 722 switch (ctrl->id) { ··· 766 765 break; 767 766 } 768 767 769 - pm_runtime_put(&client->dev); 768 + pm_runtime_put(ov5675->dev); 770 769 771 770 return ret; 772 771 } ··· 777 776 778 777 static int ov5675_init_controls(struct ov5675 *ov5675) 779 778 { 780 - struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd); 781 779 struct v4l2_fwnode_device_properties props; 782 780 struct v4l2_ctrl_handler *ctrl_hdlr; 783 781 s64 exposure_max, h_blank; ··· 839 839 return ctrl_hdlr->error; 840 840 } 841 841 842 - ret = v4l2_fwnode_device_parse(&client->dev, &props); 842 + ret = v4l2_fwnode_device_parse(ov5675->dev, &props); 843 843 if (ret) 844 844 goto error; 845 845 ··· 869 869 870 870 static int ov5675_identify_module(struct ov5675 *ov5675) 871 871 { 872 - struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd); 873 872 int ret; 874 873 u32 val; 875 874 ··· 881 882 return ret; 882 883 883 884 if (val != OV5675_CHIP_ID) { 884 - dev_err(&client->dev, "chip id mismatch: %x!=%x", 885 + dev_err(ov5675->dev, "chip id mismatch: %x!=%x", 885 886 OV5675_CHIP_ID, val); 886 887 return -ENXIO; 887 888 } ··· 893 894 894 895 static int ov5675_start_streaming(struct ov5675 *ov5675) 895 896 { 896 - struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd); 897 897 const struct ov5675_reg_list *reg_list; 898 898 int link_freq_index, ret; 899 899 ··· 904 906 reg_list = &link_freq_configs[link_freq_index].reg_list; 905 907 ret = ov5675_write_reg_list(ov5675, reg_list); 906 908 if (ret) { 907 - dev_err(&client->dev, "failed to set plls"); 909 + dev_err(ov5675->dev, "failed to set plls"); 908 910 return ret; 909 911 } 910 912 911 913 reg_list = &ov5675->cur_mode->reg_list; 912 914 ret = ov5675_write_reg_list(ov5675, reg_list); 913 915 if (ret) { 914 - dev_err(&client->dev, "failed to set mode"); 916 + dev_err(ov5675->dev, "failed to set mode"); 915 917 return ret; 916 918 } 917 919 ··· 922 924 ret = ov5675_write_reg(ov5675, OV5675_REG_MODE_SELECT, 923 925 OV5675_REG_VALUE_08BIT, OV5675_MODE_STREAMING); 924 926 if (ret) { 925 - dev_err(&client->dev, "failed to set stream"); 927 + dev_err(ov5675->dev, "failed to set stream"); 926 928 return ret; 927 929 } 928 930 ··· 931 933 932 934 static void ov5675_stop_streaming(struct ov5675 *ov5675) 933 935 { 934 - struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd); 935 - 936 936 if (ov5675_write_reg(ov5675, OV5675_REG_MODE_SELECT, 937 937 OV5675_REG_VALUE_08BIT, OV5675_MODE_STANDBY)) 938 - dev_err(&client->dev, "failed to set stream"); 938 + dev_err(ov5675->dev, "failed to set stream"); 939 939 } 940 940 941 941 static int ov5675_set_stream(struct v4l2_subdev *sd, int enable) 942 942 { 943 943 struct ov5675 *ov5675 = to_ov5675(sd); 944 - struct i2c_client *client = v4l2_get_subdevdata(sd); 945 944 int ret = 0; 946 945 947 946 mutex_lock(&ov5675->mutex); 948 947 if (enable) { 949 - ret = pm_runtime_resume_and_get(&client->dev); 948 + ret = pm_runtime_resume_and_get(ov5675->dev); 950 949 if (ret < 0) { 951 950 mutex_unlock(&ov5675->mutex); 952 951 return ret; ··· 953 958 if (ret) { 954 959 enable = 0; 955 960 ov5675_stop_streaming(ov5675); 956 - pm_runtime_put(&client->dev); 961 + pm_runtime_put(ov5675->dev); 957 962 } 958 963 } else { 959 964 ov5675_stop_streaming(ov5675); 960 - pm_runtime_put(&client->dev); 965 + pm_runtime_put(ov5675->dev); 961 966 } 962 967 963 968 mutex_unlock(&ov5675->mutex); ··· 1166 1171 .open = ov5675_open, 1167 1172 }; 1168 1173 1169 - static int ov5675_get_hwcfg(struct ov5675 *ov5675, struct device *dev) 1174 + static int ov5675_get_hwcfg(struct ov5675 *ov5675) 1170 1175 { 1176 + struct device *dev = ov5675->dev; 1171 1177 struct fwnode_handle *ep; 1172 1178 struct fwnode_handle *fwnode = dev_fwnode(dev); 1173 1179 struct v4l2_fwnode_endpoint bus_cfg = { ··· 1272 1276 v4l2_async_unregister_subdev(sd); 1273 1277 media_entity_cleanup(&sd->entity); 1274 1278 v4l2_ctrl_handler_free(sd->ctrl_handler); 1275 - pm_runtime_disable(&client->dev); 1279 + pm_runtime_disable(ov5675->dev); 1276 1280 mutex_destroy(&ov5675->mutex); 1277 1281 1278 - if (!pm_runtime_status_suspended(&client->dev)) 1279 - ov5675_power_off(&client->dev); 1280 - pm_runtime_set_suspended(&client->dev); 1282 + if (!pm_runtime_status_suspended(ov5675->dev)) 1283 + ov5675_power_off(ov5675->dev); 1284 + pm_runtime_set_suspended(ov5675->dev); 1281 1285 } 1282 1286 1283 1287 static int ov5675_probe(struct i2c_client *client) ··· 1290 1294 if (!ov5675) 1291 1295 return -ENOMEM; 1292 1296 1293 - ret = ov5675_get_hwcfg(ov5675, &client->dev); 1297 + ov5675->dev = &client->dev; 1298 + 1299 + ret = ov5675_get_hwcfg(ov5675); 1294 1300 if (ret) 1295 1301 return ret; 1296 1302 1297 1303 v4l2_i2c_subdev_init(&ov5675->sd, client, &ov5675_subdev_ops); 1298 1304 1299 - ret = ov5675_power_on(&client->dev); 1305 + ret = ov5675_power_on(ov5675->dev); 1300 1306 if (ret) { 1301 - dev_err(&client->dev, "failed to power on: %d\n", ret); 1307 + dev_err(ov5675->dev, "failed to power on: %d\n", ret); 1302 1308 return ret; 1303 1309 } 1304 1310 1305 - full_power = acpi_dev_state_d0(&client->dev); 1311 + full_power = acpi_dev_state_d0(ov5675->dev); 1306 1312 if (full_power) { 1307 1313 ret = ov5675_identify_module(ov5675); 1308 1314 if (ret) { 1309 - dev_err(&client->dev, "failed to find sensor: %d", ret); 1315 + dev_err(ov5675->dev, "failed to find sensor: %d", ret); 1310 1316 goto probe_power_off; 1311 1317 } 1312 1318 } ··· 1317 1319 ov5675->cur_mode = &supported_modes[0]; 1318 1320 ret = ov5675_init_controls(ov5675); 1319 1321 if (ret) { 1320 - dev_err(&client->dev, "failed to init controls: %d", ret); 1322 + dev_err(ov5675->dev, "failed to init controls: %d", ret); 1321 1323 goto probe_error_v4l2_ctrl_handler_free; 1322 1324 } 1323 1325 ··· 1328 1330 ov5675->pad.flags = MEDIA_PAD_FL_SOURCE; 1329 1331 ret = media_entity_pads_init(&ov5675->sd.entity, 1, &ov5675->pad); 1330 1332 if (ret) { 1331 - dev_err(&client->dev, "failed to init entity pads: %d", ret); 1333 + dev_err(ov5675->dev, "failed to init entity pads: %d", ret); 1332 1334 goto probe_error_v4l2_ctrl_handler_free; 1333 1335 } 1334 1336 1335 1337 ret = v4l2_async_register_subdev_sensor(&ov5675->sd); 1336 1338 if (ret < 0) { 1337 - dev_err(&client->dev, "failed to register V4L2 subdev: %d", 1339 + dev_err(ov5675->dev, "failed to register V4L2 subdev: %d", 1338 1340 ret); 1339 1341 goto probe_error_media_entity_cleanup; 1340 1342 } 1341 1343 1342 1344 /* Set the device's state to active if it's in D0 state. */ 1343 1345 if (full_power) 1344 - pm_runtime_set_active(&client->dev); 1345 - pm_runtime_enable(&client->dev); 1346 - pm_runtime_idle(&client->dev); 1346 + pm_runtime_set_active(ov5675->dev); 1347 + pm_runtime_enable(ov5675->dev); 1348 + pm_runtime_idle(ov5675->dev); 1347 1349 1348 1350 return 0; 1349 1351 ··· 1354 1356 v4l2_ctrl_handler_free(ov5675->sd.ctrl_handler); 1355 1357 mutex_destroy(&ov5675->mutex); 1356 1358 probe_power_off: 1357 - ov5675_power_off(&client->dev); 1359 + ov5675_power_off(ov5675->dev); 1358 1360 1359 1361 return ret; 1360 1362 }