From: Laurent Pinchart Date: Tue, 12 Aug 2025 21:46:00 +0000 (+0300) Subject: media: i2c: imx290: Use V4L2 legacy sensor clock helper X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=44fec2c00d8c83583f746e15db1becaed2f62754;p=thirdparty%2Fkernel%2Fstable.git 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 Signed-off-by: Sakari Ailus Reviewed-by: Mehdi Djait Signed-off-by: Hans Verkuil --- diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 81c0af959df4c..8b11f50302206 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -1425,14 +1425,14 @@ static int imx290_get_regulators(struct device *dev, struct imx290 *imx290) static int imx290_init_clk(struct imx290 *imx290) { u32 xclk_freq; - int ret; - ret = device_property_read_u32(imx290->dev, "clock-frequency", - &xclk_freq); - if (ret) { - dev_err(imx290->dev, "Could not get xclk frequency\n"); - return ret; - } + imx290->xclk = devm_v4l2_sensor_clk_get_legacy(imx290->dev, "xclk", + false, 0); + if (IS_ERR(imx290->xclk)) + return dev_err_probe(imx290->dev, PTR_ERR(imx290->xclk), + "Could not get xclk\n"); + + xclk_freq = clk_get_rate(imx290->xclk); /* external clock must be 37.125 MHz or 74.25MHz */ switch (xclk_freq) { @@ -1448,12 +1448,6 @@ static int imx290_init_clk(struct imx290 *imx290) return -EINVAL; } - ret = clk_set_rate(imx290->xclk, xclk_freq); - if (ret) { - dev_err(imx290->dev, "Could not set xclk frequency\n"); - return ret; - } - return 0; } @@ -1599,11 +1593,6 @@ static int imx290_probe(struct i2c_client *client) return ret; /* Acquire resources. */ - imx290->xclk = devm_v4l2_sensor_clk_get(dev, "xclk"); - if (IS_ERR(imx290->xclk)) - return dev_err_probe(dev, PTR_ERR(imx290->xclk), - "Could not get xclk\n"); - ret = imx290_get_regulators(dev, imx290); if (ret < 0) return dev_err_probe(dev, ret, "Cannot get regulators\n"); @@ -1614,7 +1603,7 @@ static int imx290_probe(struct i2c_client *client) return dev_err_probe(dev, PTR_ERR(imx290->rst_gpio), "Cannot get reset gpio\n"); - /* Initialize external clock frequency. */ + /* Initialize external clock. */ ret = imx290_init_clk(imx290); if (ret) return ret;