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

media: i2c: imx208: 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
cff41636 5fa4f866

+14 -9
+14 -9
drivers/media/i2c/imx208.c
··· 2 2 // Copyright (C) 2021 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> ··· 271 270 272 271 struct imx208 { 273 272 struct device *dev; 273 + struct clk *clk; 274 274 275 275 struct v4l2_subdev sd; 276 276 struct media_pad pad; ··· 936 934 static int imx208_probe(struct i2c_client *client) 937 935 { 938 936 struct imx208 *imx208; 937 + unsigned long freq; 939 938 int ret; 940 939 bool full_power; 941 - u32 val = 0; 942 - 943 - device_property_read_u32(&client->dev, "clock-frequency", &val); 944 - if (val != 19200000) { 945 - dev_err(&client->dev, 946 - "Unsupported clock-frequency %u. Expected 19200000.\n", 947 - val); 948 - return -EINVAL; 949 - } 950 940 951 941 imx208 = devm_kzalloc(&client->dev, sizeof(*imx208), GFP_KERNEL); 952 942 if (!imx208) 953 943 return -ENOMEM; 954 944 955 945 imx208->dev = &client->dev; 946 + 947 + imx208->clk = devm_v4l2_sensor_clk_get(imx208->dev, NULL); 948 + if (IS_ERR(imx208->clk)) 949 + return dev_err_probe(imx208->dev, PTR_ERR(imx208->clk), 950 + "failed to get clock\n"); 951 + 952 + freq = clk_get_rate(imx208->clk); 953 + if (freq != 19200000) 954 + return dev_err_probe(imx208->dev, -EINVAL, 955 + "external clock %lu is not supported\n", 956 + freq); 956 957 957 958 /* Initialize subdev */ 958 959 v4l2_i2c_subdev_init(&imx208->sd, client, &imx208_subdev_ops);