bcm27xx: import latest patches from the RPi foundation
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0826-media-i2c-imx290-set-bus_type-before-calling-v4l2_fw.patch
1 From e5b34fd95be9c59fe55e4755ba84aa05efaaaf62 Mon Sep 17 00:00:00 2001
2 From: Andrey Konovalov <andrey.konovalov@linaro.org>
3 Date: Fri, 12 Jun 2020 15:53:55 +0200
4 Subject: [PATCH] media: i2c: imx290: set bus_type before calling
5 v4l2_fwnode_endpoint_alloc_parse()
6
7 Commit a270675875829b6d46eb9e38960fd6019555ebb8 upstream.
8
9 The bus_type field of v4l2_fwnode_endpoint structure passed as the argument
10 to v4l2_fwnode_endpoint_alloc_parse() function must be initiaized.
11 Set it to V4L2_MBUS_CSI2_DPHY, and check for -ENXIO which is returned
12 when the requested media bus type doesn't match the fwnode.
13
14 Also remove v4l2_fwnode_endpoint field from struct imx290 as it is only
15 needed in the probe function: use the local variable for this purpose.
16
17 Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
18 Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
19 Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
20 ---
21 drivers/media/i2c/imx290.c | 38 +++++++++++++++++++-------------------
22 1 file changed, 19 insertions(+), 19 deletions(-)
23
24 --- a/drivers/media/i2c/imx290.c
25 +++ b/drivers/media/i2c/imx290.c
26 @@ -70,7 +70,6 @@ struct imx290 {
27 u8 bpp;
28
29 struct v4l2_subdev sd;
30 - struct v4l2_fwnode_endpoint ep;
31 struct media_pad pad;
32 struct v4l2_mbus_framefmt current_format;
33 const struct imx290_mode *current_mode;
34 @@ -914,17 +913,18 @@ static const struct media_entity_operati
35 * of MIPI data lanes are mentioned in the device tree, or the value of the
36 * first missing frequency otherwise.
37 */
38 -static s64 imx290_check_link_freqs(const struct imx290 *imx290)
39 +static s64 imx290_check_link_freqs(const struct imx290 *imx290,
40 + const struct v4l2_fwnode_endpoint *ep)
41 {
42 int i, j;
43 const s64 *freqs = imx290_link_freqs_ptr(imx290);
44 int freqs_count = imx290_link_freqs_num(imx290);
45
46 for (i = 0; i < freqs_count; i++) {
47 - for (j = 0; j < imx290->ep.nr_of_link_frequencies; j++)
48 - if (freqs[i] == imx290->ep.link_frequencies[j])
49 + for (j = 0; j < ep->nr_of_link_frequencies; j++)
50 + if (freqs[i] == ep->link_frequencies[j])
51 break;
52 - if (j == imx290->ep.nr_of_link_frequencies)
53 + if (j == ep->nr_of_link_frequencies)
54 return freqs[i];
55 }
56 return 0;
57 @@ -934,6 +934,10 @@ static int imx290_probe(struct i2c_clien
58 {
59 struct device *dev = &client->dev;
60 struct fwnode_handle *endpoint;
61 + /* Only CSI2 is supported for now: */
62 + struct v4l2_fwnode_endpoint ep = {
63 + .bus_type = V4L2_MBUS_CSI2_DPHY
64 + };
65 struct imx290 *imx290;
66 u32 xclk_freq;
67 s64 fq;
68 @@ -956,15 +960,18 @@ static int imx290_probe(struct i2c_clien
69 return -EINVAL;
70 }
71
72 - ret = v4l2_fwnode_endpoint_alloc_parse(endpoint, &imx290->ep);
73 + ret = v4l2_fwnode_endpoint_alloc_parse(endpoint, &ep);
74 fwnode_handle_put(endpoint);
75 - if (ret) {
76 + if (ret == -ENXIO) {
77 + dev_err(dev, "Unsupported bus type, should be CSI2\n");
78 + goto free_err;
79 + } else if (ret) {
80 dev_err(dev, "Parsing endpoint node failed\n");
81 goto free_err;
82 }
83
84 /* Get number of data lanes */
85 - imx290->nlanes = imx290->ep.bus.mipi_csi2.num_data_lanes;
86 + imx290->nlanes = ep.bus.mipi_csi2.num_data_lanes;
87 if (imx290->nlanes != 2 && imx290->nlanes != 4) {
88 dev_err(dev, "Invalid data lanes: %d\n", imx290->nlanes);
89 ret = -EINVAL;
90 @@ -973,27 +980,20 @@ static int imx290_probe(struct i2c_clien
91
92 dev_dbg(dev, "Using %u data lanes\n", imx290->nlanes);
93
94 - if (!imx290->ep.nr_of_link_frequencies) {
95 + if (!ep.nr_of_link_frequencies) {
96 dev_err(dev, "link-frequency property not found in DT\n");
97 ret = -EINVAL;
98 goto free_err;
99 }
100
101 /* Check that link frequences for all the modes are in device tree */
102 - fq = imx290_check_link_freqs(imx290);
103 + fq = imx290_check_link_freqs(imx290, &ep);
104 if (fq) {
105 dev_err(dev, "Link frequency of %lld is not supported\n", fq);
106 ret = -EINVAL;
107 goto free_err;
108 }
109
110 - /* Only CSI2 is supported for now */
111 - if (imx290->ep.bus_type != V4L2_MBUS_CSI2_DPHY) {
112 - dev_err(dev, "Unsupported bus type, should be CSI2\n");
113 - ret = -EINVAL;
114 - goto free_err;
115 - }
116 -
117 /* get system clock (xclk) */
118 imx290->xclk = devm_clk_get(dev, "xclk");
119 if (IS_ERR(imx290->xclk)) {
120 @@ -1108,7 +1108,7 @@ static int imx290_probe(struct i2c_clien
121 pm_runtime_enable(dev);
122 pm_runtime_idle(dev);
123
124 - v4l2_fwnode_endpoint_free(&imx290->ep);
125 + v4l2_fwnode_endpoint_free(&ep);
126
127 return 0;
128
129 @@ -1118,7 +1118,7 @@ free_ctrl:
130 v4l2_ctrl_handler_free(&imx290->ctrls);
131 mutex_destroy(&imx290->lock);
132 free_err:
133 - v4l2_fwnode_endpoint_free(&imx290->ep);
134 + v4l2_fwnode_endpoint_free(&ep);
135
136 return ret;
137 }