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

Configure Feed

Select the types of activity you want to include in your feed.

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 <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
bfa62630 9f16195e

+14 -10
+14 -10
drivers/media/i2c/ov9734.c
··· 2 2 // Copyright (c) 2020 Intel Corporation. 3 3 4 4 #include <linux/acpi.h> 5 + #include <linux/clk.h> 5 6 #include <linux/delay.h> 6 7 #include <linux/i2c.h> 7 8 #include <linux/module.h> ··· 324 323 325 324 struct ov9734 { 326 325 struct device *dev; 326 + struct clk *clk; 327 327 328 328 struct v4l2_subdev sd; 329 329 struct media_pad pad; ··· 830 828 struct v4l2_fwnode_endpoint bus_cfg = { 831 829 .bus_type = V4L2_MBUS_CSI2_DPHY 832 830 }; 833 - u32 mclk; 834 831 int ret; 835 832 unsigned int i, j; 836 833 837 834 if (!fwnode) 838 835 return -ENXIO; 839 - 840 - ret = fwnode_property_read_u32(fwnode, "clock-frequency", &mclk); 841 - if (ret) 842 - return ret; 843 - 844 - if (mclk != OV9734_MCLK) { 845 - dev_err(dev, "external clock %d is not supported", mclk); 846 - return -EINVAL; 847 - } 848 836 849 837 ep = fwnode_graph_get_next_endpoint(fwnode, NULL); 850 838 if (!ep) ··· 888 896 static int ov9734_probe(struct i2c_client *client) 889 897 { 890 898 struct ov9734 *ov9734; 899 + unsigned long freq; 891 900 int ret; 892 901 893 902 ret = ov9734_check_hwcfg(&client->dev); ··· 903 910 return -ENOMEM; 904 911 905 912 ov9734->dev = &client->dev; 913 + 914 + ov9734->clk = devm_v4l2_sensor_clk_get(ov9734->dev, NULL); 915 + if (IS_ERR(ov9734->clk)) 916 + return dev_err_probe(ov9734->dev, PTR_ERR(ov9734->clk), 917 + "failed to get clock\n"); 918 + 919 + freq = clk_get_rate(ov9734->clk); 920 + if (freq != OV9734_MCLK) 921 + return dev_err_probe(ov9734->dev, -EINVAL, 922 + "external clock %lu is not supported", 923 + freq); 906 924 907 925 v4l2_i2c_subdev_init(&ov9734->sd, client, &ov9734_subdev_ops); 908 926 ret = ov9734_identify_module(ov9734);