]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: i2c: et8ek8: Use V4L2 legacy sensor clock helper
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Tue, 12 Aug 2025 21:45:55 +0000 (00:45 +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
and were both set in the upstream DT sources. The driver retrieves the
clock, retrieves and ignores the clock rate from the clock-frequency
property, and sets the clock rate to a fixed value. 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/et8ek8/et8ek8_driver.c

index d46fe7a0eec2c91befc510b2bccaef00b0d905c8..2cb7b718782b253ad32ac2b429964426c7a0736b 100644 (file)
@@ -816,7 +816,6 @@ static int et8ek8_power_on(struct et8ek8_sensor *sensor)
 {
        struct v4l2_subdev *subdev = &sensor->subdev;
        struct i2c_client *client = v4l2_get_subdevdata(subdev);
-       unsigned int xclk_freq = 9600000;
        int val, rval;
 
        rval = regulator_enable(sensor->vana);
@@ -825,12 +824,6 @@ static int et8ek8_power_on(struct et8ek8_sensor *sensor)
                return rval;
        }
 
-       rval = clk_set_rate(sensor->ext_clk, xclk_freq);
-       if (rval < 0) {
-               dev_err(&client->dev, "unable to set extclk clock freq to %u\n",
-                       xclk_freq);
-               goto out;
-       }
        rval = clk_prepare_enable(sensor->ext_clk);
        if (rval < 0) {
                dev_err(&client->dev, "failed to enable extclk\n");
@@ -844,7 +837,7 @@ static int et8ek8_power_on(struct et8ek8_sensor *sensor)
 
        gpiod_set_value(sensor->reset, 1);
 
-       msleep(5000 * 1000 / xclk_freq + 1); /* Wait 5000 cycles */
+       msleep(5000 * 1000 / sensor->xclk_freq + 1); /* Wait 5000 cycles */
 
        rval = et8ek8_i2c_reglist_find_write(client, &meta_reglist,
                                             ET8EK8_REGLIST_POWERON);
@@ -1425,17 +1418,13 @@ static int et8ek8_probe(struct i2c_client *client)
                return PTR_ERR(sensor->vana);
        }
 
-       sensor->ext_clk = devm_v4l2_sensor_clk_get(dev, NULL);
+       sensor->ext_clk = devm_v4l2_sensor_clk_get_legacy(dev, NULL, true,
+                                                         9600000);
        if (IS_ERR(sensor->ext_clk))
                return dev_err_probe(&client->dev, PTR_ERR(sensor->ext_clk),
                                     "could not get clock\n");
 
-       ret = of_property_read_u32(dev->of_node, "clock-frequency",
-                                  &sensor->xclk_freq);
-       if (ret) {
-               dev_warn(dev, "can't get clock-frequency\n");
-               return ret;
-       }
+       sensor->xclk_freq = clk_get_rate(sensor->ext_clk);
 
        mutex_init(&sensor->power_lock);