From: Laurent Pinchart Date: Tue, 12 Aug 2025 21:46:07 +0000 (+0300) Subject: media: i2c: ov8856: Use V4L2 legacy sensor clock helper X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d2fa1134a48b1e1caa5e4b7f94212d27afa1f586;p=thirdparty%2Fkernel%2Fstable.git media: i2c: ov8856: Use V4L2 legacy sensor clock helper 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 ACPI and OF platforms. The "clocks" and "clock-frequency" properties were initially specified as mandatory in the DT bindings and were both set in the upstream DT sources. The driver retrieves the clock rate from the "clock-frequency" property. On OF platforms, it retrieves the clock and sets its rate. If the rate does not match the expected rate, the driver prints a warning. This is correct behaviour for ACPI, and 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 Signed-off-by: Sakari Ailus Reviewed-by: Mehdi Djait Signed-off-by: Hans Verkuil --- diff --git a/drivers/media/i2c/ov8856.c b/drivers/media/i2c/ov8856.c index 674ee36e394ca..e2998cfa0d18a 100644 --- a/drivers/media/i2c/ov8856.c +++ b/drivers/media/i2c/ov8856.c @@ -2266,19 +2266,17 @@ static int ov8856_get_hwcfg(struct ov8856 *ov8856) if (!fwnode) return -ENXIO; - ret = fwnode_property_read_u32(fwnode, "clock-frequency", &xvclk_rate); - if (ret) - return ret; - - if (!is_acpi_node(fwnode)) { - ov8856->xvclk = devm_v4l2_sensor_clk_get(dev, "xvclk"); - if (IS_ERR(ov8856->xvclk)) - return dev_err_probe(dev, PTR_ERR(ov8856->xvclk), - "could not get xvclk clock\n"); + ov8856->xvclk = devm_v4l2_sensor_clk_get_legacy(dev, "xvclk", false, 0); + if (IS_ERR(ov8856->xvclk)) + return dev_err_probe(dev, PTR_ERR(ov8856->xvclk), + "could not get xvclk clock\n"); - clk_set_rate(ov8856->xvclk, xvclk_rate); - xvclk_rate = clk_get_rate(ov8856->xvclk); + xvclk_rate = clk_get_rate(ov8856->xvclk); + if (xvclk_rate != OV8856_XVCLK_19_2) + dev_warn(dev, "external clock rate %u is unsupported", + xvclk_rate); + if (!is_acpi_node(fwnode)) { ov8856->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); if (IS_ERR(ov8856->reset_gpio)) @@ -2294,10 +2292,6 @@ static int ov8856_get_hwcfg(struct ov8856 *ov8856) return ret; } - if (xvclk_rate != OV8856_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;