]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: i2c: s5k5baf: Use V4L2 legacy sensor clock helper
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Tue, 12 Aug 2025 21:46:09 +0000 (00:46 +0300)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Tue, 9 Sep 2025 13:59:20 +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" property has always
been specified as mandatory in the DT bindings and the "clock-frequency"
property has always been optional. Both properties were initially set in
the upstream DT sources. The driver retrieves the clock, retrieves the
clock rate from the "clock-frequency" property if available or uses a
fixed default otherwise, and sets the clock rate. 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.

For all meaningful purposes, devm_v4l2_sensor_clk_get_legacy() returns
-EPROBE_DEFER in situations when the driver would want to defer probing.
Replace the hardcoded -EPROBE_DEFER error with propagating the error
code from devm_v4l2_sensor_clk_get_legacy().

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

index 01d37f49e5ad985f4bbfaa492836755be18f2609..d1d00eca870838d86ca6a283780d2485b848392f 100644 (file)
@@ -284,7 +284,6 @@ struct s5k5baf {
        struct regulator_bulk_data supplies[S5K5BAF_NUM_SUPPLIES];
 
        struct clk *clock;
-       u32 mclk_frequency;
 
        struct s5k5baf_fw *fw;
 
@@ -576,7 +575,7 @@ static void s5k5baf_hw_patch(struct s5k5baf *state)
 
 static void s5k5baf_hw_set_clocks(struct s5k5baf *state)
 {
-       unsigned long mclk = state->mclk_frequency / 1000;
+       unsigned long mclk = clk_get_rate(state->clock) / 1000;
        u16 status;
        static const u16 nseq_clk_cfg[] = {
                NSEQ(REG_I_USE_NPVI_CLOCKS,
@@ -946,10 +945,6 @@ static int s5k5baf_power_on(struct s5k5baf *state)
        if (ret < 0)
                goto err;
 
-       ret = clk_set_rate(state->clock, state->mclk_frequency);
-       if (ret < 0)
-               goto err_reg_dis;
-
        ret = clk_prepare_enable(state->clock);
        if (ret < 0)
                goto err_reg_dis;
@@ -1841,14 +1836,6 @@ static int s5k5baf_parse_device_node(struct s5k5baf *state, struct device *dev)
                return -EINVAL;
        }
 
-       ret = of_property_read_u32(node, "clock-frequency",
-                                  &state->mclk_frequency);
-       if (ret < 0) {
-               state->mclk_frequency = S5K5BAF_DEFAULT_MCLK_FREQ;
-               dev_info(dev, "using default %u Hz clock frequency\n",
-                        state->mclk_frequency);
-       }
-
        node_ep = of_graph_get_endpoint_by_regs(node, 0, -1);
        if (!node_ep) {
                dev_err(dev, "no endpoint defined at node %pOF\n", node);
@@ -1967,9 +1954,11 @@ static int s5k5baf_probe(struct i2c_client *c)
        if (ret < 0)
                goto err_me;
 
-       state->clock = devm_v4l2_sensor_clk_get(state->sd.dev, S5K5BAF_CLK_NAME);
+       state->clock = devm_v4l2_sensor_clk_get_legacy(state->sd.dev,
+                                                      S5K5BAF_CLK_NAME, false,
+                                                      S5K5BAF_DEFAULT_MCLK_FREQ);
        if (IS_ERR(state->clock)) {
-               ret = -EPROBE_DEFER;
+               ret = PTR_ERR(state->clock);
                goto err_me;
        }