From: Laurent Pinchart Date: Tue, 12 Aug 2025 21:45:39 +0000 (+0300) Subject: media: i2c: ov13858: Use V4L2 sensor clock helper X-Git-Tag: v6.18-rc1~133^2~125 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9df442485b132571fe17f542aa5957185f10ddf7;p=thirdparty%2Fkernel%2Fstable.git media: i2c: ov13858: 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/ov13858.c b/drivers/media/i2c/ov13858.c index d93ad730d6332..162b49046990a 100644 --- a/drivers/media/i2c/ov13858.c +++ b/drivers/media/i2c/ov13858.c @@ -2,6 +2,7 @@ // Copyright (c) 2017 Intel Corporation. #include +#include #include #include #include @@ -1029,6 +1030,7 @@ static const struct ov13858_mode supported_modes[] = { struct ov13858 { struct device *dev; + struct clk *clk; struct v4l2_subdev sd; struct media_pad pad; @@ -1656,12 +1658,8 @@ static void ov13858_free_controls(struct ov13858 *ov13858) static int ov13858_probe(struct i2c_client *client) { struct ov13858 *ov13858; + unsigned long freq; int ret; - u32 val = 0; - - device_property_read_u32(&client->dev, "clock-frequency", &val); - if (val != 19200000) - return -EINVAL; ov13858 = devm_kzalloc(&client->dev, sizeof(*ov13858), GFP_KERNEL); if (!ov13858) @@ -1669,6 +1667,17 @@ static int ov13858_probe(struct i2c_client *client) ov13858->dev = &client->dev; + ov13858->clk = devm_v4l2_sensor_clk_get(ov13858->dev, NULL); + if (IS_ERR(ov13858->clk)) + return dev_err_probe(ov13858->dev, PTR_ERR(ov13858->clk), + "failed to get clock\n"); + + freq = clk_get_rate(ov13858->clk); + if (freq != 19200000) + return dev_err_probe(ov13858->dev, -EINVAL, + "external clock %lu is not supported\n", + freq); + /* Initialize subdev */ v4l2_i2c_subdev_init(&ov13858->sd, client, &ov13858_subdev_ops);