]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: i2c: og01a1b: Use V4L2 sensor clock helper
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Tue, 12 Aug 2025 21:45:29 +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 and OF platforms. The "clocks" property is
specified as mandatory in the DT bindings and the "clock-frequency"
property is not allowed. The driver retrieves the clock if present,
retrieves the clock rate from the "clock-frequency" property and falls
back to retrieving it from the clock. If the rate does not match the
expected rate, the driver fails probing. This is correct behaviour for
ACPI, and for OF platforms that comply with the documented DT bindings.

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.

The behaviour is also unchanged 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/og01a1b.c

index a9baf8095d4f3beabfd8854c925365ddddf91dd0..c7184de6251ae69f98ca7547e220911988a525a7 100644 (file)
@@ -910,28 +910,12 @@ static int og01a1b_check_hwcfg(struct og01a1b *og01a1b)
        struct v4l2_fwnode_endpoint bus_cfg = {
                .bus_type = V4L2_MBUS_CSI2_DPHY
        };
-       u32 mclk;
        int ret;
        unsigned int i, j;
 
        if (!fwnode)
                return -ENXIO;
 
-       ret = fwnode_property_read_u32(fwnode, "clock-frequency", &mclk);
-       if (ret) {
-               if (!og01a1b->xvclk) {
-                       dev_err(dev, "can't get clock frequency");
-                       return ret;
-               }
-
-               mclk = clk_get_rate(og01a1b->xvclk);
-       }
-
-       if (mclk != OG01A1B_MCLK) {
-               dev_err(dev, "external clock %d is not supported", mclk);
-               return -EINVAL;
-       }
-
        ep = fwnode_graph_get_next_endpoint(fwnode, NULL);
        if (!ep)
                return -ENXIO;
@@ -1067,6 +1051,7 @@ static void og01a1b_remove(struct i2c_client *client)
 static int og01a1b_probe(struct i2c_client *client)
 {
        struct og01a1b *og01a1b;
+       unsigned long freq;
        int ret;
 
        og01a1b = devm_kzalloc(&client->dev, sizeof(*og01a1b), GFP_KERNEL);
@@ -1077,12 +1062,16 @@ static int og01a1b_probe(struct i2c_client *client)
 
        v4l2_i2c_subdev_init(&og01a1b->sd, client, &og01a1b_subdev_ops);
 
-       og01a1b->xvclk = devm_clk_get_optional(og01a1b->dev, NULL);
-       if (IS_ERR(og01a1b->xvclk)) {
-               ret = PTR_ERR(og01a1b->xvclk);
-               dev_err(og01a1b->dev, "failed to get xvclk clock: %d\n", ret);
-               return ret;
-       }
+       og01a1b->xvclk = devm_v4l2_sensor_clk_get(og01a1b->dev, NULL);
+       if (IS_ERR(og01a1b->xvclk))
+               return dev_err_probe(og01a1b->dev, PTR_ERR(og01a1b->xvclk),
+                                    "failed to get xvclk clock\n");
+
+       freq = clk_get_rate(og01a1b->xvclk);
+       if (freq != OG01A1B_MCLK)
+               return dev_err_probe(og01a1b->dev, -EINVAL,
+                                    "external clock %lu is not supported",
+                                    freq);
 
        ret = og01a1b_check_hwcfg(og01a1b);
        if (ret) {