]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: i2c: ov08d10: Use V4L2 sensor clock helper
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Tue, 12 Aug 2025 21:45:35 +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 rate
from the "clock-frequency" property. If the rate does not match the
expected rate, the driver prints a warning. 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/ov08d10.c

index 2523adcaacf70d9310879d514f6191f678a8d68b..43ec2a1f2fcffb7fa11a6268af3c2edc4df129f3 100644 (file)
@@ -516,13 +516,12 @@ static const char * const ov08d10_test_pattern_menu[] = {
 
 struct ov08d10 {
        struct device *dev;
+       struct clk *clk;
 
        struct v4l2_subdev sd;
        struct media_pad pad;
        struct v4l2_ctrl_handler ctrl_handler;
 
-       struct clk              *xvclk;
-
        /* V4L2 Controls */
        struct v4l2_ctrl *link_freq;
        struct v4l2_ctrl *pixel_rate;
@@ -1309,21 +1308,12 @@ static int ov08d10_get_hwcfg(struct ov08d10 *ov08d10)
        struct v4l2_fwnode_endpoint bus_cfg = {
                .bus_type = V4L2_MBUS_CSI2_DPHY
        };
-       u32 xvclk_rate;
        unsigned int i, j;
        int ret;
 
        if (!fwnode)
                return -ENXIO;
 
-       ret = fwnode_property_read_u32(fwnode, "clock-frequency", &xvclk_rate);
-       if (ret)
-               return ret;
-
-       if (xvclk_rate != OV08D10_XVCLK_19_2)
-               dev_warn(dev, "external clock rate %u is unsupported",
-                        xvclk_rate);
-
        ep = fwnode_graph_get_next_endpoint(fwnode, NULL);
        if (!ep)
                return -ENXIO;
@@ -1388,6 +1378,7 @@ static void ov08d10_remove(struct i2c_client *client)
 static int ov08d10_probe(struct i2c_client *client)
 {
        struct ov08d10 *ov08d10;
+       unsigned long freq;
        int ret;
 
        ov08d10 = devm_kzalloc(&client->dev, sizeof(*ov08d10), GFP_KERNEL);
@@ -1396,6 +1387,16 @@ static int ov08d10_probe(struct i2c_client *client)
 
        ov08d10->dev = &client->dev;
 
+       ov08d10->clk = devm_v4l2_sensor_clk_get(ov08d10->dev, NULL);
+       if (IS_ERR(ov08d10->clk))
+               return dev_err_probe(ov08d10->dev, PTR_ERR(ov08d10->clk),
+                                    "failed to get clock\n");
+
+       freq = clk_get_rate(ov08d10->clk);
+       if (freq != OV08D10_XVCLK_19_2)
+               dev_warn(ov08d10->dev,
+                        "external clock rate %lu is not supported\n", freq);
+
        ret = ov08d10_get_hwcfg(ov08d10);
        if (ret) {
                dev_err(ov08d10->dev, "failed to get HW configuration: %d",