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

media: i2c: ov8856: Use V4L2 legacy 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 copying deprecated behaviour for OF platforms in new drivers,
and lead to differences in behaviour between drivers. Instead, drivers
that need to preserve the deprecated OF behaviour should use the
devm_v4l2_sensor_clk_get_legacy() helper.

This driver supports ACPI and OF platforms. The "clocks" and
"clock-frequency" properties were initially specified as mandatory in
the DT bindings and were both set in the upstream DT sources. The driver
retrieves the clock rate from the "clock-frequency" property. On OF
platforms, it retrieves the clock and sets its rate. If the rate does
not match the expected rate, the driver prints a warning. This is
correct behaviour for ACPI, and deprecated behaviour for OF.

Switch to using the devm_v4l2_sensor_clk_get_legacy() helper. This
preserves setting the clock rate on OF platforms. Should support for OF
platforms that set the clock rate through clock-frequency be considered
unneeded in the future, the driver will only need to switch to
devm_v4l2_sensor_clk_get() without any other change.

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
d2fa1134 f2cc0cca

+9 -15
+9 -15
drivers/media/i2c/ov8856.c
··· 2266 2266 if (!fwnode) 2267 2267 return -ENXIO; 2268 2268 2269 - ret = fwnode_property_read_u32(fwnode, "clock-frequency", &xvclk_rate); 2270 - if (ret) 2271 - return ret; 2269 + ov8856->xvclk = devm_v4l2_sensor_clk_get_legacy(dev, "xvclk", false, 0); 2270 + if (IS_ERR(ov8856->xvclk)) 2271 + return dev_err_probe(dev, PTR_ERR(ov8856->xvclk), 2272 + "could not get xvclk clock\n"); 2273 + 2274 + xvclk_rate = clk_get_rate(ov8856->xvclk); 2275 + if (xvclk_rate != OV8856_XVCLK_19_2) 2276 + dev_warn(dev, "external clock rate %u is unsupported", 2277 + xvclk_rate); 2272 2278 2273 2279 if (!is_acpi_node(fwnode)) { 2274 - ov8856->xvclk = devm_v4l2_sensor_clk_get(dev, "xvclk"); 2275 - if (IS_ERR(ov8856->xvclk)) 2276 - return dev_err_probe(dev, PTR_ERR(ov8856->xvclk), 2277 - "could not get xvclk clock\n"); 2278 - 2279 - clk_set_rate(ov8856->xvclk, xvclk_rate); 2280 - xvclk_rate = clk_get_rate(ov8856->xvclk); 2281 - 2282 2280 ov8856->reset_gpio = devm_gpiod_get_optional(dev, "reset", 2283 2281 GPIOD_OUT_LOW); 2284 2282 if (IS_ERR(ov8856->reset_gpio)) ··· 2291 2293 if (ret) 2292 2294 return ret; 2293 2295 } 2294 - 2295 - if (xvclk_rate != OV8856_XVCLK_19_2) 2296 - dev_warn(dev, "external clock rate %u is unsupported", 2297 - xvclk_rate); 2298 2296 2299 2297 ep = fwnode_graph_get_next_endpoint(fwnode, NULL); 2300 2298 if (!ep)