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

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
8853d26b 5dee9af9

+24 -26
+24 -26
drivers/media/i2c/ov13858.c
··· 1028 1028 }; 1029 1029 1030 1030 struct ov13858 { 1031 + struct device *dev; 1032 + 1031 1033 struct v4l2_subdev sd; 1032 1034 struct media_pad pad; 1033 1035 ··· 1119 1117 static int ov13858_write_regs(struct ov13858 *ov13858, 1120 1118 const struct ov13858_reg *regs, u32 len) 1121 1119 { 1122 - struct i2c_client *client = v4l2_get_subdevdata(&ov13858->sd); 1123 1120 int ret; 1124 1121 u32 i; 1125 1122 ··· 1127 1126 regs[i].val); 1128 1127 if (ret) { 1129 1128 dev_err_ratelimited( 1130 - &client->dev, 1129 + ov13858->dev, 1131 1130 "Failed to write reg 0x%4.4x. error = %d\n", 1132 1131 regs[i].address, ret); 1133 1132 ··· 1210 1209 { 1211 1210 struct ov13858 *ov13858 = container_of(ctrl->handler, 1212 1211 struct ov13858, ctrl_handler); 1213 - struct i2c_client *client = v4l2_get_subdevdata(&ov13858->sd); 1214 1212 s64 max; 1215 1213 int ret; 1216 1214 ··· 1228 1228 * Applying V4L2 control value only happens 1229 1229 * when power is up for streaming 1230 1230 */ 1231 - if (!pm_runtime_get_if_in_use(&client->dev)) 1231 + if (!pm_runtime_get_if_in_use(ov13858->dev)) 1232 1232 return 0; 1233 1233 1234 1234 ret = 0; ··· 1256 1256 ret = ov13858_enable_test_pattern(ov13858, ctrl->val); 1257 1257 break; 1258 1258 default: 1259 - dev_info(&client->dev, 1259 + dev_info(ov13858->dev, 1260 1260 "ctrl(id:0x%x,val:0x%x) is not handled\n", 1261 1261 ctrl->id, ctrl->val); 1262 1262 break; 1263 1263 } 1264 1264 1265 - pm_runtime_put(&client->dev); 1265 + pm_runtime_put(ov13858->dev); 1266 1266 1267 1267 return ret; 1268 1268 } ··· 1408 1408 /* Start streaming */ 1409 1409 static int ov13858_start_streaming(struct ov13858 *ov13858) 1410 1410 { 1411 - struct i2c_client *client = v4l2_get_subdevdata(&ov13858->sd); 1412 1411 const struct ov13858_reg_list *reg_list; 1413 1412 int ret, link_freq_index; 1414 1413 ··· 1415 1416 ret = ov13858_write_reg(ov13858, OV13858_REG_SOFTWARE_RST, 1416 1417 OV13858_REG_VALUE_08BIT, OV13858_SOFTWARE_RST); 1417 1418 if (ret) { 1418 - dev_err(&client->dev, "%s failed to set powerup registers\n", 1419 + dev_err(ov13858->dev, "%s failed to set powerup registers\n", 1419 1420 __func__); 1420 1421 return ret; 1421 1422 } ··· 1425 1426 reg_list = &link_freq_configs[link_freq_index].reg_list; 1426 1427 ret = ov13858_write_reg_list(ov13858, reg_list); 1427 1428 if (ret) { 1428 - dev_err(&client->dev, "%s failed to set plls\n", __func__); 1429 + dev_err(ov13858->dev, "%s failed to set plls\n", __func__); 1429 1430 return ret; 1430 1431 } 1431 1432 ··· 1433 1434 reg_list = &ov13858->cur_mode->reg_list; 1434 1435 ret = ov13858_write_reg_list(ov13858, reg_list); 1435 1436 if (ret) { 1436 - dev_err(&client->dev, "%s failed to set mode\n", __func__); 1437 + dev_err(ov13858->dev, "%s failed to set mode\n", __func__); 1437 1438 return ret; 1438 1439 } 1439 1440 ··· 1457 1458 static int ov13858_set_stream(struct v4l2_subdev *sd, int enable) 1458 1459 { 1459 1460 struct ov13858 *ov13858 = to_ov13858(sd); 1460 - struct i2c_client *client = v4l2_get_subdevdata(sd); 1461 1461 int ret = 0; 1462 1462 1463 1463 mutex_lock(&ov13858->mutex); 1464 1464 1465 1465 if (enable) { 1466 - ret = pm_runtime_resume_and_get(&client->dev); 1466 + ret = pm_runtime_resume_and_get(ov13858->dev); 1467 1467 if (ret < 0) 1468 1468 goto err_unlock; 1469 1469 ··· 1475 1477 goto err_rpm_put; 1476 1478 } else { 1477 1479 ov13858_stop_streaming(ov13858); 1478 - pm_runtime_put(&client->dev); 1480 + pm_runtime_put(ov13858->dev); 1479 1481 } 1480 1482 1481 1483 mutex_unlock(&ov13858->mutex); ··· 1483 1485 return ret; 1484 1486 1485 1487 err_rpm_put: 1486 - pm_runtime_put(&client->dev); 1488 + pm_runtime_put(ov13858->dev); 1487 1489 err_unlock: 1488 1490 mutex_unlock(&ov13858->mutex); 1489 1491 ··· 1493 1495 /* Verify chip ID */ 1494 1496 static int ov13858_identify_module(struct ov13858 *ov13858) 1495 1497 { 1496 - struct i2c_client *client = v4l2_get_subdevdata(&ov13858->sd); 1497 1498 int ret; 1498 1499 u32 val; 1499 1500 ··· 1502 1505 return ret; 1503 1506 1504 1507 if (val != OV13858_CHIP_ID) { 1505 - dev_err(&client->dev, "chip id mismatch: %x!=%x\n", 1508 + dev_err(ov13858->dev, "chip id mismatch: %x!=%x\n", 1506 1509 OV13858_CHIP_ID, val); 1507 1510 return -EIO; 1508 1511 } ··· 1549 1552 /* Initialize control handlers */ 1550 1553 static int ov13858_init_controls(struct ov13858 *ov13858) 1551 1554 { 1552 - struct i2c_client *client = v4l2_get_subdevdata(&ov13858->sd); 1553 1555 struct v4l2_fwnode_device_properties props; 1554 1556 struct v4l2_ctrl_handler *ctrl_hdlr; 1555 1557 s64 exposure_max; ··· 1622 1626 0, 0, ov13858_test_pattern_menu); 1623 1627 if (ctrl_hdlr->error) { 1624 1628 ret = ctrl_hdlr->error; 1625 - dev_err(&client->dev, "%s control init failed (%d)\n", 1629 + dev_err(ov13858->dev, "%s control init failed (%d)\n", 1626 1630 __func__, ret); 1627 1631 goto error; 1628 1632 } 1629 1633 1630 - ret = v4l2_fwnode_device_parse(&client->dev, &props); 1634 + ret = v4l2_fwnode_device_parse(ov13858->dev, &props); 1631 1635 if (ret) 1632 1636 goto error; 1633 1637 ··· 1667 1671 if (!ov13858) 1668 1672 return -ENOMEM; 1669 1673 1674 + ov13858->dev = &client->dev; 1675 + 1670 1676 /* Initialize subdev */ 1671 1677 v4l2_i2c_subdev_init(&ov13858->sd, client, &ov13858_subdev_ops); 1672 1678 1673 1679 /* Check module identity */ 1674 1680 ret = ov13858_identify_module(ov13858); 1675 1681 if (ret) { 1676 - dev_err(&client->dev, "failed to find sensor: %d\n", ret); 1682 + dev_err(ov13858->dev, "failed to find sensor: %d\n", ret); 1677 1683 return ret; 1678 1684 } 1679 1685 ··· 1697 1699 ov13858->pad.flags = MEDIA_PAD_FL_SOURCE; 1698 1700 ret = media_entity_pads_init(&ov13858->sd.entity, 1, &ov13858->pad); 1699 1701 if (ret) { 1700 - dev_err(&client->dev, "%s failed:%d\n", __func__, ret); 1702 + dev_err(ov13858->dev, "%s failed:%d\n", __func__, ret); 1701 1703 goto error_handler_free; 1702 1704 } 1703 1705 ··· 1709 1711 * Device is already turned on by i2c-core with ACPI domain PM. 1710 1712 * Enable runtime PM and turn off the device. 1711 1713 */ 1712 - pm_runtime_set_active(&client->dev); 1713 - pm_runtime_enable(&client->dev); 1714 - pm_runtime_idle(&client->dev); 1714 + pm_runtime_set_active(ov13858->dev); 1715 + pm_runtime_enable(ov13858->dev); 1716 + pm_runtime_idle(ov13858->dev); 1715 1717 1716 1718 return 0; 1717 1719 ··· 1720 1722 1721 1723 error_handler_free: 1722 1724 ov13858_free_controls(ov13858); 1723 - dev_err(&client->dev, "%s failed:%d\n", __func__, ret); 1725 + dev_err(ov13858->dev, "%s failed:%d\n", __func__, ret); 1724 1726 1725 1727 return ret; 1726 1728 } ··· 1734 1736 media_entity_cleanup(&sd->entity); 1735 1737 ov13858_free_controls(ov13858); 1736 1738 1737 - pm_runtime_disable(&client->dev); 1739 + pm_runtime_disable(ov13858->dev); 1738 1740 } 1739 1741 1740 1742 static const struct i2c_device_id ov13858_id_table[] = {