1 From 88c013f4c7e60431bca7bc6487971f671397e0fd Mon Sep 17 00:00:00 2001
2 From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
3 Date: Mon, 16 Jan 2023 15:44:47 +0100
4 Subject: [PATCH] media: i2c: imx290: Factor out clock initialization
7 Upstream commit e5d363ca82b9
9 Move the external clock initialization code from probe() to a separate
10 function to improve readability. No functional change intended.
12 Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
13 Reviewed-by: Alexander Stein <alexander.stein@ew.tq-group.com>
14 Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
15 Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
17 drivers/media/i2c/imx290.c | 57 +++++++++++++++++++++++---------------
18 1 file changed, 35 insertions(+), 22 deletions(-)
20 --- a/drivers/media/i2c/imx290.c
21 +++ b/drivers/media/i2c/imx290.c
22 @@ -1120,6 +1120,34 @@ static int imx290_get_regulators(struct
26 +static int imx290_init_clk(struct imx290 *imx290)
31 + ret = fwnode_property_read_u32(dev_fwnode(imx290->dev),
32 + "clock-frequency", &xclk_freq);
34 + dev_err(imx290->dev, "Could not get xclk frequency\n");
38 + /* external clock must be 37.125 MHz */
39 + if (xclk_freq != 37125000) {
40 + dev_err(imx290->dev, "External clock frequency %u is not supported\n",
45 + ret = clk_set_rate(imx290->xclk, xclk_freq);
47 + dev_err(imx290->dev, "Could not set xclk frequency\n");
55 * Returns 0 if all link frequencies used by the driver for the given number
56 * of MIPI data lanes are mentioned in the device tree, or the value of the
57 @@ -1204,7 +1232,6 @@ static int imx290_probe(struct i2c_clien
59 struct device *dev = &client->dev;
60 struct imx290 *imx290;
64 imx290 = devm_kzalloc(dev, sizeof(*imx290), GFP_KERNEL);
65 @@ -1222,32 +1249,12 @@ static int imx290_probe(struct i2c_clien
69 - /* get system clock (xclk) */
70 + /* Acquire resources. */
71 imx290->xclk = devm_clk_get(dev, "xclk");
72 if (IS_ERR(imx290->xclk))
73 return dev_err_probe(dev, PTR_ERR(imx290->xclk),
74 "Could not get xclk");
76 - ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency",
79 - dev_err(dev, "Could not get xclk frequency\n");
83 - /* external clock must be 37.125 MHz */
84 - if (xclk_freq != 37125000) {
85 - dev_err(dev, "External clock frequency %u is not supported\n",
90 - ret = clk_set_rate(imx290->xclk, xclk_freq);
92 - dev_err(dev, "Could not set xclk frequency\n");
96 ret = imx290_get_regulators(dev, imx290);
98 return dev_err_probe(dev, ret, "Cannot get regulators\n");
99 @@ -1258,8 +1265,14 @@ static int imx290_probe(struct i2c_clien
100 return dev_err_probe(dev, PTR_ERR(imx290->rst_gpio),
101 "Cannot get reset gpio\n");
103 + /* Initialize external clock frequency. */
104 + ret = imx290_init_clk(imx290);
108 mutex_init(&imx290->lock);
110 + /* Initialize and register subdev. */
111 ret = imx290_subdev_init(imx290);