From: Laurent Pinchart Date: Tue, 12 Aug 2025 21:45:35 +0000 (+0300) Subject: media: i2c: ov08d10: Use V4L2 sensor clock helper X-Git-Tag: v6.18-rc1~133^2~129 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1e921b267eb709ef76601c4aefb001079c604f18;p=thirdparty%2Fkernel%2Fstable.git media: i2c: ov08d10: 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 prints a warning. 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/ov08d10.c b/drivers/media/i2c/ov08d10.c index 2523adcaacf70..43ec2a1f2fcff 100644 --- a/drivers/media/i2c/ov08d10.c +++ b/drivers/media/i2c/ov08d10.c @@ -516,13 +516,12 @@ static const char * const ov08d10_test_pattern_menu[] = { struct ov08d10 { struct device *dev; + struct clk *clk; struct v4l2_subdev sd; struct media_pad pad; struct v4l2_ctrl_handler ctrl_handler; - struct clk *xvclk; - /* V4L2 Controls */ struct v4l2_ctrl *link_freq; struct v4l2_ctrl *pixel_rate; @@ -1309,21 +1308,12 @@ static int ov08d10_get_hwcfg(struct ov08d10 *ov08d10) struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = V4L2_MBUS_CSI2_DPHY }; - u32 xvclk_rate; unsigned int i, j; int ret; if (!fwnode) return -ENXIO; - ret = fwnode_property_read_u32(fwnode, "clock-frequency", &xvclk_rate); - if (ret) - return ret; - - if (xvclk_rate != OV08D10_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; @@ -1388,6 +1378,7 @@ static void ov08d10_remove(struct i2c_client *client) static int ov08d10_probe(struct i2c_client *client) { struct ov08d10 *ov08d10; + unsigned long freq; int ret; ov08d10 = devm_kzalloc(&client->dev, sizeof(*ov08d10), GFP_KERNEL); @@ -1396,6 +1387,16 @@ static int ov08d10_probe(struct i2c_client *client) ov08d10->dev = &client->dev; + ov08d10->clk = devm_v4l2_sensor_clk_get(ov08d10->dev, NULL); + if (IS_ERR(ov08d10->clk)) + return dev_err_probe(ov08d10->dev, PTR_ERR(ov08d10->clk), + "failed to get clock\n"); + + freq = clk_get_rate(ov08d10->clk); + if (freq != OV08D10_XVCLK_19_2) + dev_warn(ov08d10->dev, + "external clock rate %lu is not supported\n", freq); + ret = ov08d10_get_hwcfg(ov08d10); if (ret) { dev_err(ov08d10->dev, "failed to get HW configuration: %d",