Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: i2c: ov5670: 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 and OF platforms. The "clocks" property has
always been specified as mandatory in the DT bindings, and the
"clock-frequency" property has never been allowed. The driver retrieves
the clock and its rate if present, and falls back to retrieving the rate
from the "clock-frequency" property otherwise. If the rate does not
match the expected rate, the driver fails probing. This is correct
behaviour for ACPI, and for OF platforms that comply with the documented
DT bindings.

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.

The behaviour is also unchanged on OF platforms that comply with the DT
bindings. Non-compliant platforms are not expected, but any regression
could easily be handled by switching to the
devm_v4l2_sensor_clk_get_legacy() helper designed to preserve
non-compliant behaviour.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Mehdi Djait <mehdi.djait@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>

authored by

Laurent Pinchart and committed by
Mauro Carvalho Chehab
2fc08984 be3971e2

+3 -7
+3 -7
drivers/media/i2c/ov5670.c
··· 2655 2655 2656 2656 ov5670->dev = &client->dev; 2657 2657 2658 - ov5670->xvclk = devm_clk_get_optional(ov5670->dev, NULL); 2659 - if (!IS_ERR_OR_NULL(ov5670->xvclk)) 2660 - input_clk = clk_get_rate(ov5670->xvclk); 2661 - else if (!ov5670->xvclk || PTR_ERR(ov5670->xvclk) == -ENOENT) 2662 - device_property_read_u32(ov5670->dev, "clock-frequency", 2663 - &input_clk); 2664 - else 2658 + ov5670->xvclk = devm_v4l2_sensor_clk_get(ov5670->dev, NULL); 2659 + if (IS_ERR(ov5670->xvclk)) 2665 2660 return dev_err_probe(ov5670->dev, PTR_ERR(ov5670->xvclk), 2666 2661 "error getting clock\n"); 2667 2662 2663 + input_clk = clk_get_rate(ov5670->xvclk); 2668 2664 if (input_clk != OV5670_XVCLK_FREQ) { 2669 2665 dev_err(ov5670->dev, 2670 2666 "Unsupported clock frequency %u\n", input_clk);