1 From 4afc11ae3b786ad8425435b70ab0285fbf951b05 Mon Sep 17 00:00:00 2001
2 From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
3 Date: Mon, 16 Jan 2023 15:44:45 +0100
4 Subject: [PATCH] media: i2c: imx290: Factor out DT parsing to separate
7 Upstream commit 6b69c52277ed
9 Make the probe() function more readable by factoring out the DT parsing
10 code to a separate function. 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 | 95 +++++++++++++++++++++-----------------
18 1 file changed, 52 insertions(+), 43 deletions(-)
20 --- a/drivers/media/i2c/imx290.c
21 +++ b/drivers/media/i2c/imx290.c
22 @@ -1142,111 +1142,124 @@ static s64 imx290_check_link_freqs(const
26 -static int imx290_probe(struct i2c_client *client)
27 +static int imx290_parse_dt(struct imx290 *imx290)
29 - struct device *dev = &client->dev;
30 - struct fwnode_handle *endpoint;
31 /* Only CSI2 is supported for now: */
32 struct v4l2_fwnode_endpoint ep = {
33 .bus_type = V4L2_MBUS_CSI2_DPHY
35 - struct imx290 *imx290;
38 + struct fwnode_handle *endpoint;
42 - imx290 = devm_kzalloc(dev, sizeof(*imx290), GFP_KERNEL);
47 - imx290->regmap = devm_regmap_init_i2c(client, &imx290_regmap_config);
48 - if (IS_ERR(imx290->regmap)) {
49 - dev_err(dev, "Unable to initialize I2C\n");
53 - endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(dev), NULL);
54 + endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(imx290->dev), NULL);
56 - dev_err(dev, "Endpoint node not found\n");
57 + dev_err(imx290->dev, "Endpoint node not found\n");
61 ret = v4l2_fwnode_endpoint_alloc_parse(endpoint, &ep);
62 fwnode_handle_put(endpoint);
64 - dev_err(dev, "Unsupported bus type, should be CSI2\n");
66 + dev_err(imx290->dev, "Unsupported bus type, should be CSI2\n");
69 - dev_err(dev, "Parsing endpoint node failed\n");
71 + dev_err(imx290->dev, "Parsing endpoint node failed\n");
75 /* Get number of data lanes */
76 imx290->nlanes = ep.bus.mipi_csi2.num_data_lanes;
77 if (imx290->nlanes != 2 && imx290->nlanes != 4) {
78 - dev_err(dev, "Invalid data lanes: %d\n", imx290->nlanes);
79 + dev_err(imx290->dev, "Invalid data lanes: %d\n", imx290->nlanes);
85 - dev_dbg(dev, "Using %u data lanes\n", imx290->nlanes);
86 + dev_dbg(imx290->dev, "Using %u data lanes\n", imx290->nlanes);
88 if (!ep.nr_of_link_frequencies) {
89 - dev_err(dev, "link-frequency property not found in DT\n");
90 + dev_err(imx290->dev, "link-frequency property not found in DT\n");
96 /* Check that link frequences for all the modes are in device tree */
97 fq = imx290_check_link_freqs(imx290, &ep);
99 - dev_err(dev, "Link frequency of %lld is not supported\n", fq);
100 + dev_err(imx290->dev, "Link frequency of %lld is not supported\n",
110 + v4l2_fwnode_endpoint_free(&ep);
114 +static int imx290_probe(struct i2c_client *client)
116 + struct device *dev = &client->dev;
117 + struct imx290 *imx290;
121 + imx290 = devm_kzalloc(dev, sizeof(*imx290), GFP_KERNEL);
126 + imx290->regmap = devm_regmap_init_i2c(client, &imx290_regmap_config);
127 + if (IS_ERR(imx290->regmap)) {
128 + dev_err(dev, "Unable to initialize I2C\n");
132 + ret = imx290_parse_dt(imx290);
136 /* get system clock (xclk) */
137 imx290->xclk = devm_clk_get(dev, "xclk");
138 if (IS_ERR(imx290->xclk)) {
139 dev_err(dev, "Could not get xclk");
140 - ret = PTR_ERR(imx290->xclk);
142 + return PTR_ERR(imx290->xclk);
145 ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency",
148 dev_err(dev, "Could not get xclk frequency\n");
153 /* external clock must be 37.125 MHz */
154 if (xclk_freq != 37125000) {
155 dev_err(dev, "External clock frequency %u is not supported\n",
162 ret = clk_set_rate(imx290->xclk, xclk_freq);
164 dev_err(dev, "Could not set xclk frequency\n");
169 ret = imx290_get_regulators(dev, imx290);
171 dev_err(dev, "Cannot get regulators\n");
176 imx290->rst_gpio = devm_gpiod_get_optional(dev, "reset",
178 if (IS_ERR(imx290->rst_gpio)) {
179 dev_err(dev, "Cannot get reset gpio\n");
180 - ret = PTR_ERR(imx290->rst_gpio);
182 + return PTR_ERR(imx290->rst_gpio);
185 mutex_init(&imx290->lock);
186 @@ -1272,16 +1285,12 @@ static int imx290_probe(struct i2c_clien
187 pm_runtime_enable(dev);
188 pm_runtime_idle(dev);
190 - v4l2_fwnode_endpoint_free(&ep);
195 imx290_subdev_cleanup(imx290);
197 mutex_destroy(&imx290->lock);
199 - v4l2_fwnode_endpoint_free(&ep);