]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: i2c: imx290: Use V4L2 legacy sensor clock helper
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Tue, 12 Aug 2025 21:46:00 +0000 (00:46 +0300)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Tue, 9 Sep 2025 13:59:19 +0000 (15:59 +0200)
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>
drivers/media/i2c/imx290.c

index 81c0af959df4c8ef9b5551bd78d0a626bdeccf4f..8b11f5030220692941bd390aea04537eb8eb4e12 100644 (file)
@@ -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;