]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: i2c: ov2740: Use V4L2 sensor clock helper
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Tue, 12 Aug 2025 21:45:43 +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 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>
drivers/media/i2c/ov2740.c

index aedf62df6e93a465f8d289d1ef3bfc1580da6201..fb590dfadda130d68849d6d7b171a1ebdd694343 100644 (file)
@@ -1133,7 +1133,6 @@ static int ov2740_check_hwcfg(struct ov2740 *ov2740)
        struct v4l2_fwnode_endpoint bus_cfg = {
                .bus_type = V4L2_MBUS_CSI2_DPHY
        };
-       u32 mclk;
        int ret;
        unsigned int i, j;
 
@@ -1146,20 +1145,6 @@ static int ov2740_check_hwcfg(struct ov2740 *ov2740)
                return dev_err_probe(dev, -EPROBE_DEFER,
                                     "waiting for fwnode graph endpoint\n");
 
-       ret = fwnode_property_read_u32(fwnode, "clock-frequency", &mclk);
-       if (ret) {
-               fwnode_handle_put(ep);
-               return dev_err_probe(dev, ret,
-                                    "reading clock-frequency property\n");
-       }
-
-       if (mclk != OV2740_MCLK) {
-               fwnode_handle_put(ep);
-               return dev_err_probe(dev, -EINVAL,
-                                    "external clock %d is not supported\n",
-                                    mclk);
-       }
-
        ret = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg);
        fwnode_handle_put(ep);
        if (ret)
@@ -1342,6 +1327,7 @@ static int ov2740_probe(struct i2c_client *client)
 {
        struct device *dev = &client->dev;
        struct ov2740 *ov2740;
+       unsigned long freq;
        bool full_power;
        unsigned int i;
        int ret;
@@ -1379,11 +1365,17 @@ static int ov2740_probe(struct i2c_client *client)
                msleep(20);
        }
 
-       ov2740->clk = devm_clk_get_optional(dev, "clk");
+       ov2740->clk = devm_v4l2_sensor_clk_get(dev, "clk");
        if (IS_ERR(ov2740->clk))
                return dev_err_probe(dev, PTR_ERR(ov2740->clk),
                                     "failed to get clock\n");
 
+       freq = clk_get_rate(ov2740->clk);
+       if (freq != OV2740_MCLK)
+               return dev_err_probe(dev, -EINVAL,
+                                    "external clock %lu is not supported\n",
+                                    freq);
+
        for (i = 0; i < ARRAY_SIZE(ov2740_supply_name); i++)
                ov2740->supplies[i].supply = ov2740_supply_name[i];