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

media: i2c: imx290: Use V4L2 legacy 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 copying deprecated behaviour for OF platforms in new drivers,
and lead to differences in behaviour between drivers. Instead, drivers
that need to preserve the deprecated OF behaviour should use the
devm_v4l2_sensor_clk_get_legacy() helper.

This driver supports OF platforms only. The "clocks" and
"clock-frequency" properties were initially mandatory in the DT
bindings. The driver retrieves the clock, retrieves the clock rate from
the "clock-frequency" property, and sets the clock rate to the retrieved
rate. If the rate does not match one of the expected rates, the driver
fails probing. This is deprecated behaviour for OF.

Switch to using the devm_v4l2_sensor_clk_get_legacy() helper. This
preserves setting the clock rate on OF platforms. Should support for OF
platforms that set the clock rate through clock-frequency be considered
unneeded in the future, the driver will only need to switch to
devm_v4l2_sensor_clk_get() without any other change.

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
44fec2c0 c5b1a92c

+8 -19
+8 -19
drivers/media/i2c/imx290.c
··· 1425 1425 static int imx290_init_clk(struct imx290 *imx290) 1426 1426 { 1427 1427 u32 xclk_freq; 1428 - int ret; 1429 1428 1430 - ret = device_property_read_u32(imx290->dev, "clock-frequency", 1431 - &xclk_freq); 1432 - if (ret) { 1433 - dev_err(imx290->dev, "Could not get xclk frequency\n"); 1434 - return ret; 1435 - } 1429 + imx290->xclk = devm_v4l2_sensor_clk_get_legacy(imx290->dev, "xclk", 1430 + false, 0); 1431 + if (IS_ERR(imx290->xclk)) 1432 + return dev_err_probe(imx290->dev, PTR_ERR(imx290->xclk), 1433 + "Could not get xclk\n"); 1434 + 1435 + xclk_freq = clk_get_rate(imx290->xclk); 1436 1436 1437 1437 /* external clock must be 37.125 MHz or 74.25MHz */ 1438 1438 switch (xclk_freq) { ··· 1446 1446 dev_err(imx290->dev, "External clock frequency %u is not supported\n", 1447 1447 xclk_freq); 1448 1448 return -EINVAL; 1449 - } 1450 - 1451 - ret = clk_set_rate(imx290->xclk, xclk_freq); 1452 - if (ret) { 1453 - dev_err(imx290->dev, "Could not set xclk frequency\n"); 1454 - return ret; 1455 1449 } 1456 1450 1457 1451 return 0; ··· 1593 1599 return ret; 1594 1600 1595 1601 /* Acquire resources. */ 1596 - imx290->xclk = devm_v4l2_sensor_clk_get(dev, "xclk"); 1597 - if (IS_ERR(imx290->xclk)) 1598 - return dev_err_probe(dev, PTR_ERR(imx290->xclk), 1599 - "Could not get xclk\n"); 1600 - 1601 1602 ret = imx290_get_regulators(dev, imx290); 1602 1603 if (ret < 0) 1603 1604 return dev_err_probe(dev, ret, "Cannot get regulators\n"); ··· 1603 1614 return dev_err_probe(dev, PTR_ERR(imx290->rst_gpio), 1604 1615 "Cannot get reset gpio\n"); 1605 1616 1606 - /* Initialize external clock frequency. */ 1617 + /* Initialize external clock. */ 1607 1618 ret = imx290_init_clk(imx290); 1608 1619 if (ret) 1609 1620 return ret;