From: Laurent Pinchart Date: Tue, 12 Aug 2025 21:45:41 +0000 (+0300) Subject: media: i2c: ov13b10: Use V4L2 sensor clock helper X-Git-Tag: v6.18-rc1~133^2~123 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=964ae05b0d6972dcf5df86f30636ca3aef1be9b1;p=thirdparty%2Flinux.git media: i2c: ov13b10: Use V4L2 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 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 if present, and retrieves the clock rate from the "clock-frequency" property. If the rate does not match the expected rate, the driver fails probing. 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 Signed-off-by: Sakari Ailus Reviewed-by: Mehdi Djait Signed-off-by: Hans Verkuil --- diff --git a/drivers/media/i2c/ov13b10.c b/drivers/media/i2c/ov13b10.c index 3f17cdd9f42c1..869bc78ed7925 100644 --- a/drivers/media/i2c/ov13b10.c +++ b/drivers/media/i2c/ov13b10.c @@ -1472,6 +1472,7 @@ static void ov13b10_free_controls(struct ov13b10 *ov13b) static int ov13b10_get_pm_resources(struct ov13b10 *ov13b) { + unsigned long freq; int ret; ov13b->reset = devm_gpiod_get_optional(ov13b->dev, "reset", GPIOD_OUT_LOW); @@ -1479,11 +1480,17 @@ static int ov13b10_get_pm_resources(struct ov13b10 *ov13b) return dev_err_probe(ov13b->dev, PTR_ERR(ov13b->reset), "failed to get reset gpio\n"); - ov13b->img_clk = devm_clk_get_optional(ov13b->dev, NULL); + ov13b->img_clk = devm_v4l2_sensor_clk_get(ov13b->dev, NULL); if (IS_ERR(ov13b->img_clk)) return dev_err_probe(ov13b->dev, PTR_ERR(ov13b->img_clk), "failed to get imaging clock\n"); + freq = clk_get_rate(ov13b->img_clk); + if (freq != OV13B10_EXT_CLK) + return dev_err_probe(ov13b->dev, -EINVAL, + "external clock %lu is not supported\n", + freq); + ov13b->avdd = devm_regulator_get_optional(ov13b->dev, "avdd"); if (IS_ERR(ov13b->avdd)) { ret = PTR_ERR(ov13b->avdd); @@ -1506,7 +1513,6 @@ static int ov13b10_check_hwcfg(struct ov13b10 *ov13b) struct fwnode_handle *fwnode = dev_fwnode(dev); unsigned int i, j; int ret; - u32 ext_clk; u8 dlane; if (!fwnode) @@ -1516,19 +1522,6 @@ static int ov13b10_check_hwcfg(struct ov13b10 *ov13b) if (!ep) return -EPROBE_DEFER; - ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency", - &ext_clk); - if (ret) { - dev_err(dev, "can't get clock frequency"); - return ret; - } - - if (ext_clk != OV13B10_EXT_CLK) { - dev_err(dev, "external clock %d is not supported", - ext_clk); - return -EINVAL; - } - ret = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg); fwnode_handle_put(ep); if (ret)