b23d667d6597642654e8daefe274a23d9cff67ea
[openwrt/staging/blocktrron.git] /
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
5 to separate function
6
7 Upstream commit e5d363ca82b9
8
9 Move the external clock initialization code from probe() to a separate
10 function to improve readability. No functional change intended.
11
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>
16 ---
17 drivers/media/i2c/imx290.c | 57 +++++++++++++++++++++++---------------
18 1 file changed, 35 insertions(+), 22 deletions(-)
19
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
23 imx290->supplies);
24 }
25
26 +static int imx290_init_clk(struct imx290 *imx290)
27 +{
28 + u32 xclk_freq;
29 + int ret;
30 +
31 + ret = fwnode_property_read_u32(dev_fwnode(imx290->dev),
32 + "clock-frequency", &xclk_freq);
33 + if (ret) {
34 + dev_err(imx290->dev, "Could not get xclk frequency\n");
35 + return ret;
36 + }
37 +
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",
41 + xclk_freq);
42 + return -EINVAL;
43 + }
44 +
45 + ret = clk_set_rate(imx290->xclk, xclk_freq);
46 + if (ret) {
47 + dev_err(imx290->dev, "Could not set xclk frequency\n");
48 + return ret;
49 + }
50 +
51 + return 0;
52 +}
53 +
54 /*
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
58 {
59 struct device *dev = &client->dev;
60 struct imx290 *imx290;
61 - u32 xclk_freq;
62 int ret;
63
64 imx290 = devm_kzalloc(dev, sizeof(*imx290), GFP_KERNEL);
65 @@ -1222,32 +1249,12 @@ static int imx290_probe(struct i2c_clien
66 if (ret)
67 return ret;
68
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");
75
76 - ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency",
77 - &xclk_freq);
78 - if (ret) {
79 - dev_err(dev, "Could not get xclk frequency\n");
80 - return ret;
81 - }
82 -
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",
86 - xclk_freq);
87 - return -EINVAL;
88 - }
89 -
90 - ret = clk_set_rate(imx290->xclk, xclk_freq);
91 - if (ret) {
92 - dev_err(dev, "Could not set xclk frequency\n");
93 - return ret;
94 - }
95 -
96 ret = imx290_get_regulators(dev, imx290);
97 if (ret < 0)
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");
102
103 + /* Initialize external clock frequency. */
104 + ret = imx290_init_clk(imx290);
105 + if (ret)
106 + return ret;
107 +
108 mutex_init(&imx290->lock);
109
110 + /* Initialize and register subdev. */
111 ret = imx290_subdev_init(imx290);
112 if (ret)
113 goto err_mutex;