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

media: i2c: ov13b10: Use V4L2 sensor clock helper

Several camera sensor drivers access the "clock-frequency" property
directly to retrieve the external clock rate, or modify the clock rate
of the external clock programmatically. Both behaviours are valid on
a subset of ACPI platforms, but are considered deprecated on OF
platforms, and do not support ACPI platforms that implement MIPI DisCo
for Imaging. Implementing them manually in drivers is deprecated, as
that can encourage cargo-cult and lead to differences in behaviour
between drivers. Instead, drivers should use the
devm_v4l2_sensor_clk_get() helper.

This driver supports ACPI platforms only. It retrieves the clock if
present, and retrieves the clock rate from the "clock-frequency"
property. If the rate does not match the expected rate, the driver fails
probing. This is correct behaviour for ACPI.

Switch to using the devm_v4l2_sensor_clk_get() helper. This does not
change the behaviour on ACPI platforms that specify a clock-frequency
property and don't provide a clock. On ACPI platforms that provide a
clock, the clock rate will be set to the value of the clock-frequency
property. This should not change the behaviour either as this driver
expects the clock to be set to that rate, and wouldn't operate correctly
otherwise.

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
964ae05b 42bab2cb

+8 -15
+8 -15
drivers/media/i2c/ov13b10.c
··· 1472 1472 1473 1473 static int ov13b10_get_pm_resources(struct ov13b10 *ov13b) 1474 1474 { 1475 + unsigned long freq; 1475 1476 int ret; 1476 1477 1477 1478 ov13b->reset = devm_gpiod_get_optional(ov13b->dev, "reset", GPIOD_OUT_LOW); ··· 1480 1479 return dev_err_probe(ov13b->dev, PTR_ERR(ov13b->reset), 1481 1480 "failed to get reset gpio\n"); 1482 1481 1483 - ov13b->img_clk = devm_clk_get_optional(ov13b->dev, NULL); 1482 + ov13b->img_clk = devm_v4l2_sensor_clk_get(ov13b->dev, NULL); 1484 1483 if (IS_ERR(ov13b->img_clk)) 1485 1484 return dev_err_probe(ov13b->dev, PTR_ERR(ov13b->img_clk), 1486 1485 "failed to get imaging clock\n"); 1486 + 1487 + freq = clk_get_rate(ov13b->img_clk); 1488 + if (freq != OV13B10_EXT_CLK) 1489 + return dev_err_probe(ov13b->dev, -EINVAL, 1490 + "external clock %lu is not supported\n", 1491 + freq); 1487 1492 1488 1493 ov13b->avdd = devm_regulator_get_optional(ov13b->dev, "avdd"); 1489 1494 if (IS_ERR(ov13b->avdd)) { ··· 1513 1506 struct fwnode_handle *fwnode = dev_fwnode(dev); 1514 1507 unsigned int i, j; 1515 1508 int ret; 1516 - u32 ext_clk; 1517 1509 u8 dlane; 1518 1510 1519 1511 if (!fwnode) ··· 1521 1515 ep = fwnode_graph_get_next_endpoint(fwnode, NULL); 1522 1516 if (!ep) 1523 1517 return -EPROBE_DEFER; 1524 - 1525 - ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency", 1526 - &ext_clk); 1527 - if (ret) { 1528 - dev_err(dev, "can't get clock frequency"); 1529 - return ret; 1530 - } 1531 - 1532 - if (ext_clk != OV13B10_EXT_CLK) { 1533 - dev_err(dev, "external clock %d is not supported", 1534 - ext_clk); 1535 - return -EINVAL; 1536 - } 1537 1518 1538 1519 ret = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg); 1539 1520 fwnode_handle_put(ep);