]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: i2c: ov4689: Use V4L2 sensor clock helper
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Tue, 12 Aug 2025 21:45:44 +0000 (00:45 +0300)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Tue, 9 Sep 2025 13:59:18 +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 cargo-cult and lead to differences in behaviour
between drivers. Instead, drivers should use the
devm_v4l2_sensor_clk_get() helper.

This driver supports OF platforms only. The "clocks" property has always
been specified as mandatory in the DT bindings and the "clock-frequency"
property has never been allowed. The driver retrieves the clock and its
rate if present, and falls back to retrieving the rate from the
"clock-frequency" property otherwise. If the rate does not match the
expected rate, the driver fails probing. This is deprecated on OF
platforms, but behaves correctly on platforms that comply with the DT
bindings.

Switch to using the devm_v4l2_sensor_clk_get() helper. This does not
change the behaviour on OF platforms that comply with the DT bindings.
Non-compliant platforms are not expected, but any regression could
easily be handled by switching to the devm_v4l2_sensor_clk_get_legacy()
helper designed to preserve non-compliant behaviour.

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/ov4689.c

index 1c3a449f935462400001aa46a4be2c391ca0e300..4e68f8c3d3de56089d4d78109dbe5545fd2ee12d 100644 (file)
@@ -909,20 +909,12 @@ static int ov4689_probe(struct i2c_client *client)
 
        ov4689->cur_mode = &supported_modes[OV4689_MODE_2688_1520];
 
-       ov4689->xvclk = devm_clk_get_optional(dev, NULL);
+       ov4689->xvclk = devm_v4l2_sensor_clk_get(dev, NULL);
        if (IS_ERR(ov4689->xvclk))
                return dev_err_probe(dev, PTR_ERR(ov4689->xvclk),
                                     "Failed to get external clock\n");
 
-       if (!ov4689->xvclk) {
-               dev_dbg(dev,
-                       "No clock provided, using clock-frequency property\n");
-               device_property_read_u32(dev, "clock-frequency",
-                                        &ov4689->clock_rate);
-       } else {
-               ov4689->clock_rate = clk_get_rate(ov4689->xvclk);
-       }
-
+       ov4689->clock_rate = clk_get_rate(ov4689->xvclk);
        if (ov4689->clock_rate != OV4689_XVCLK_FREQ) {
                dev_err(dev,
                        "External clock rate mismatch: got %d Hz, expected %d Hz\n",