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

media: i2c: et8ek8: 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 OF platforms only. The "clocks" and
"clock-frequency" properties were initially mandatory in the DT bindings
and were both set in the upstream DT sources. The driver retrieves the
clock, retrieves and ignores the clock rate from the clock-frequency
property, and sets the clock rate to a fixed value. This is 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
fdee2124 cf7ea1d6

+4 -15
+4 -15
drivers/media/i2c/et8ek8/et8ek8_driver.c
··· 816 816 { 817 817 struct v4l2_subdev *subdev = &sensor->subdev; 818 818 struct i2c_client *client = v4l2_get_subdevdata(subdev); 819 - unsigned int xclk_freq = 9600000; 820 819 int val, rval; 821 820 822 821 rval = regulator_enable(sensor->vana); ··· 824 825 return rval; 825 826 } 826 827 827 - rval = clk_set_rate(sensor->ext_clk, xclk_freq); 828 - if (rval < 0) { 829 - dev_err(&client->dev, "unable to set extclk clock freq to %u\n", 830 - xclk_freq); 831 - goto out; 832 - } 833 828 rval = clk_prepare_enable(sensor->ext_clk); 834 829 if (rval < 0) { 835 830 dev_err(&client->dev, "failed to enable extclk\n"); ··· 837 844 838 845 gpiod_set_value(sensor->reset, 1); 839 846 840 - msleep(5000 * 1000 / xclk_freq + 1); /* Wait 5000 cycles */ 847 + msleep(5000 * 1000 / sensor->xclk_freq + 1); /* Wait 5000 cycles */ 841 848 842 849 rval = et8ek8_i2c_reglist_find_write(client, &meta_reglist, 843 850 ET8EK8_REGLIST_POWERON); ··· 1418 1425 return PTR_ERR(sensor->vana); 1419 1426 } 1420 1427 1421 - sensor->ext_clk = devm_v4l2_sensor_clk_get(dev, NULL); 1428 + sensor->ext_clk = devm_v4l2_sensor_clk_get_legacy(dev, NULL, true, 1429 + 9600000); 1422 1430 if (IS_ERR(sensor->ext_clk)) 1423 1431 return dev_err_probe(&client->dev, PTR_ERR(sensor->ext_clk), 1424 1432 "could not get clock\n"); 1425 1433 1426 - ret = of_property_read_u32(dev->of_node, "clock-frequency", 1427 - &sensor->xclk_freq); 1428 - if (ret) { 1429 - dev_warn(dev, "can't get clock-frequency\n"); 1430 - return ret; 1431 - } 1434 + sensor->xclk_freq = clk_get_rate(sensor->ext_clk); 1432 1435 1433 1436 mutex_init(&sensor->power_lock); 1434 1437