From: Laurent Pinchart Date: Tue, 12 Aug 2025 21:45:52 +0000 (+0300) Subject: media: i2c: ov9734: Use V4L2 sensor clock helper X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=bfa626306cf7be5868a24b86cc358879f4d21dc1;p=users%2Fhch%2Fmisc.git media: i2c: ov9734: 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 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/ov9734.c b/drivers/media/i2c/ov9734.c index d74d99344210..0eaf33807fc9 100644 --- a/drivers/media/i2c/ov9734.c +++ b/drivers/media/i2c/ov9734.c @@ -2,6 +2,7 @@ // Copyright (c) 2020 Intel Corporation. #include +#include #include #include #include @@ -323,6 +324,7 @@ static const struct ov9734_mode supported_modes[] = { struct ov9734 { struct device *dev; + struct clk *clk; struct v4l2_subdev sd; struct media_pad pad; @@ -828,22 +830,12 @@ static int ov9734_check_hwcfg(struct device *dev) 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) - return ret; - - if (mclk != OV9734_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; @@ -896,6 +888,7 @@ static void ov9734_remove(struct i2c_client *client) static int ov9734_probe(struct i2c_client *client) { struct ov9734 *ov9734; + unsigned long freq; int ret; ret = ov9734_check_hwcfg(&client->dev); @@ -911,6 +904,17 @@ static int ov9734_probe(struct i2c_client *client) ov9734->dev = &client->dev; + ov9734->clk = devm_v4l2_sensor_clk_get(ov9734->dev, NULL); + if (IS_ERR(ov9734->clk)) + return dev_err_probe(ov9734->dev, PTR_ERR(ov9734->clk), + "failed to get clock\n"); + + freq = clk_get_rate(ov9734->clk); + if (freq != OV9734_MCLK) + return dev_err_probe(ov9734->dev, -EINVAL, + "external clock %lu is not supported", + freq); + v4l2_i2c_subdev_init(&ov9734->sd, client, &ov9734_subdev_ops); ret = ov9734_identify_module(ov9734); if (ret) {