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: 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 <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
9df44248 8853d26b

+14 -5
+14 -5
drivers/media/i2c/ov13858.c
··· 2 2 // Copyright (c) 2017 Intel Corporation. 3 3 4 4 #include <linux/acpi.h> 5 + #include <linux/clk.h> 5 6 #include <linux/i2c.h> 6 7 #include <linux/module.h> 7 8 #include <linux/pm_runtime.h> ··· 1030 1029 1031 1030 struct ov13858 { 1032 1031 struct device *dev; 1032 + struct clk *clk; 1033 1033 1034 1034 struct v4l2_subdev sd; 1035 1035 struct media_pad pad; ··· 1658 1656 static int ov13858_probe(struct i2c_client *client) 1659 1657 { 1660 1658 struct ov13858 *ov13858; 1659 + unsigned long freq; 1661 1660 int ret; 1662 - u32 val = 0; 1663 - 1664 - device_property_read_u32(&client->dev, "clock-frequency", &val); 1665 - if (val != 19200000) 1666 - return -EINVAL; 1667 1661 1668 1662 ov13858 = devm_kzalloc(&client->dev, sizeof(*ov13858), GFP_KERNEL); 1669 1663 if (!ov13858) 1670 1664 return -ENOMEM; 1671 1665 1672 1666 ov13858->dev = &client->dev; 1667 + 1668 + ov13858->clk = devm_v4l2_sensor_clk_get(ov13858->dev, NULL); 1669 + if (IS_ERR(ov13858->clk)) 1670 + return dev_err_probe(ov13858->dev, PTR_ERR(ov13858->clk), 1671 + "failed to get clock\n"); 1672 + 1673 + freq = clk_get_rate(ov13858->clk); 1674 + if (freq != 19200000) 1675 + return dev_err_probe(ov13858->dev, -EINVAL, 1676 + "external clock %lu is not supported\n", 1677 + freq); 1673 1678 1674 1679 /* Initialize subdev */ 1675 1680 v4l2_i2c_subdev_init(&ov13858->sd, client, &ov13858_subdev_ops);