Lines Matching +full:- +full:1
1 // SPDX-License-Identifier: GPL-2.0
3 * camss-video.c
5 * Qualcomm MSM Camera Subsystem - V4L2 device node
7 * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
8 * Copyright (C) 2015-2018 Linaro Ltd.
11 #include <media/media-entity.h>
12 #include <media/v4l2-dev.h>
13 #include <media/v4l2-device.h>
14 #include <media/v4l2-ioctl.h>
15 #include <media/v4l2-mc.h>
16 #include <media/videobuf2-dma-sg.h>
18 #include "camss-video.h"
21 #define CAMSS_FRAME_MIN_WIDTH 1
23 #define CAMSS_FRAME_MIN_HEIGHT 1
33 * struct camss_format_info - ISP media bus format information
51 { MEDIA_BUS_FMT_UYVY8_2X8, V4L2_PIX_FMT_UYVY, 1,
52 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
53 { MEDIA_BUS_FMT_VYUY8_2X8, V4L2_PIX_FMT_VYUY, 1,
54 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
55 { MEDIA_BUS_FMT_YUYV8_2X8, V4L2_PIX_FMT_YUYV, 1,
56 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
57 { MEDIA_BUS_FMT_YVYU8_2X8, V4L2_PIX_FMT_YVYU, 1,
58 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
59 { MEDIA_BUS_FMT_SBGGR8_1X8, V4L2_PIX_FMT_SBGGR8, 1,
60 { { 1, 1 } }, { { 1, 1 } }, { 8 } },
61 { MEDIA_BUS_FMT_SGBRG8_1X8, V4L2_PIX_FMT_SGBRG8, 1,
62 { { 1, 1 } }, { { 1, 1 } }, { 8 } },
63 { MEDIA_BUS_FMT_SGRBG8_1X8, V4L2_PIX_FMT_SGRBG8, 1,
64 { { 1, 1 } }, { { 1, 1 } }, { 8 } },
65 { MEDIA_BUS_FMT_SRGGB8_1X8, V4L2_PIX_FMT_SRGGB8, 1,
66 { { 1, 1 } }, { { 1, 1 } }, { 8 } },
67 { MEDIA_BUS_FMT_SBGGR10_1X10, V4L2_PIX_FMT_SBGGR10P, 1,
68 { { 1, 1 } }, { { 1, 1 } }, { 10 } },
69 { MEDIA_BUS_FMT_SGBRG10_1X10, V4L2_PIX_FMT_SGBRG10P, 1,
70 { { 1, 1 } }, { { 1, 1 } }, { 10 } },
71 { MEDIA_BUS_FMT_SGRBG10_1X10, V4L2_PIX_FMT_SGRBG10P, 1,
72 { { 1, 1 } }, { { 1, 1 } }, { 10 } },
73 { MEDIA_BUS_FMT_SRGGB10_1X10, V4L2_PIX_FMT_SRGGB10P, 1,
74 { { 1, 1 } }, { { 1, 1 } }, { 10 } },
75 { MEDIA_BUS_FMT_SBGGR12_1X12, V4L2_PIX_FMT_SBGGR12P, 1,
76 { { 1, 1 } }, { { 1, 1 } }, { 12 } },
77 { MEDIA_BUS_FMT_SGBRG12_1X12, V4L2_PIX_FMT_SGBRG12P, 1,
78 { { 1, 1 } }, { { 1, 1 } }, { 12 } },
79 { MEDIA_BUS_FMT_SGRBG12_1X12, V4L2_PIX_FMT_SGRBG12P, 1,
80 { { 1, 1 } }, { { 1, 1 } }, { 12 } },
81 { MEDIA_BUS_FMT_SRGGB12_1X12, V4L2_PIX_FMT_SRGGB12P, 1,
82 { { 1, 1 } }, { { 1, 1 } }, { 12 } },
83 { MEDIA_BUS_FMT_Y10_1X10, V4L2_PIX_FMT_Y10P, 1,
84 { { 1, 1 } }, { { 1, 1 } }, { 10 } },
88 { MEDIA_BUS_FMT_UYVY8_2X8, V4L2_PIX_FMT_UYVY, 1,
89 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
90 { MEDIA_BUS_FMT_VYUY8_2X8, V4L2_PIX_FMT_VYUY, 1,
91 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
92 { MEDIA_BUS_FMT_YUYV8_2X8, V4L2_PIX_FMT_YUYV, 1,
93 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
94 { MEDIA_BUS_FMT_YVYU8_2X8, V4L2_PIX_FMT_YVYU, 1,
95 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
96 { MEDIA_BUS_FMT_SBGGR8_1X8, V4L2_PIX_FMT_SBGGR8, 1,
97 { { 1, 1 } }, { { 1, 1 } }, { 8 } },
98 { MEDIA_BUS_FMT_SGBRG8_1X8, V4L2_PIX_FMT_SGBRG8, 1,
99 { { 1, 1 } }, { { 1, 1 } }, { 8 } },
100 { MEDIA_BUS_FMT_SGRBG8_1X8, V4L2_PIX_FMT_SGRBG8, 1,
101 { { 1, 1 } }, { { 1, 1 } }, { 8 } },
102 { MEDIA_BUS_FMT_SRGGB8_1X8, V4L2_PIX_FMT_SRGGB8, 1,
103 { { 1, 1 } }, { { 1, 1 } }, { 8 } },
104 { MEDIA_BUS_FMT_SBGGR10_1X10, V4L2_PIX_FMT_SBGGR10P, 1,
105 { { 1, 1 } }, { { 1, 1 } }, { 10 } },
106 { MEDIA_BUS_FMT_SGBRG10_1X10, V4L2_PIX_FMT_SGBRG10P, 1,
107 { { 1, 1 } }, { { 1, 1 } }, { 10 } },
108 { MEDIA_BUS_FMT_SGRBG10_1X10, V4L2_PIX_FMT_SGRBG10P, 1,
109 { { 1, 1 } }, { { 1, 1 } }, { 10 } },
110 { MEDIA_BUS_FMT_SRGGB10_1X10, V4L2_PIX_FMT_SRGGB10P, 1,
111 { { 1, 1 } }, { { 1, 1 } }, { 10 } },
112 { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE, V4L2_PIX_FMT_SBGGR10, 1,
113 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
114 { MEDIA_BUS_FMT_SBGGR12_1X12, V4L2_PIX_FMT_SBGGR12P, 1,
115 { { 1, 1 } }, { { 1, 1 } }, { 12 } },
116 { MEDIA_BUS_FMT_SGBRG12_1X12, V4L2_PIX_FMT_SGBRG12P, 1,
117 { { 1, 1 } }, { { 1, 1 } }, { 12 } },
118 { MEDIA_BUS_FMT_SGRBG12_1X12, V4L2_PIX_FMT_SGRBG12P, 1,
119 { { 1, 1 } }, { { 1, 1 } }, { 12 } },
120 { MEDIA_BUS_FMT_SRGGB12_1X12, V4L2_PIX_FMT_SRGGB12P, 1,
121 { { 1, 1 } }, { { 1, 1 } }, { 12 } },
122 { MEDIA_BUS_FMT_SBGGR14_1X14, V4L2_PIX_FMT_SBGGR14P, 1,
123 { { 1, 1 } }, { { 1, 1 } }, { 14 } },
124 { MEDIA_BUS_FMT_SGBRG14_1X14, V4L2_PIX_FMT_SGBRG14P, 1,
125 { { 1, 1 } }, { { 1, 1 } }, { 14 } },
126 { MEDIA_BUS_FMT_SGRBG14_1X14, V4L2_PIX_FMT_SGRBG14P, 1,
127 { { 1, 1 } }, { { 1, 1 } }, { 14 } },
128 { MEDIA_BUS_FMT_SRGGB14_1X14, V4L2_PIX_FMT_SRGGB14P, 1,
129 { { 1, 1 } }, { { 1, 1 } }, { 14 } },
130 { MEDIA_BUS_FMT_Y10_1X10, V4L2_PIX_FMT_Y10P, 1,
131 { { 1, 1 } }, { { 1, 1 } }, { 10 } },
132 { MEDIA_BUS_FMT_Y10_2X8_PADHI_LE, V4L2_PIX_FMT_Y10, 1,
133 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
137 { MEDIA_BUS_FMT_UYVY8_2X8, V4L2_PIX_FMT_UYVY, 1,
138 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
139 { MEDIA_BUS_FMT_VYUY8_2X8, V4L2_PIX_FMT_VYUY, 1,
140 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
141 { MEDIA_BUS_FMT_YUYV8_2X8, V4L2_PIX_FMT_YUYV, 1,
142 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
143 { MEDIA_BUS_FMT_YVYU8_2X8, V4L2_PIX_FMT_YVYU, 1,
144 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
145 { MEDIA_BUS_FMT_SBGGR8_1X8, V4L2_PIX_FMT_SBGGR8, 1,
146 { { 1, 1 } }, { { 1, 1 } }, { 8 } },
147 { MEDIA_BUS_FMT_SGBRG8_1X8, V4L2_PIX_FMT_SGBRG8, 1,
148 { { 1, 1 } }, { { 1, 1 } }, { 8 } },
149 { MEDIA_BUS_FMT_SGRBG8_1X8, V4L2_PIX_FMT_SGRBG8, 1,
150 { { 1, 1 } }, { { 1, 1 } }, { 8 } },
151 { MEDIA_BUS_FMT_SRGGB8_1X8, V4L2_PIX_FMT_SRGGB8, 1,
152 { { 1, 1 } }, { { 1, 1 } }, { 8 } },
153 { MEDIA_BUS_FMT_SBGGR10_1X10, V4L2_PIX_FMT_SBGGR10P, 1,
154 { { 1, 1 } }, { { 1, 1 } }, { 10 } },
155 { MEDIA_BUS_FMT_SGBRG10_1X10, V4L2_PIX_FMT_SGBRG10P, 1,
156 { { 1, 1 } }, { { 1, 1 } }, { 10 } },
157 { MEDIA_BUS_FMT_SGRBG10_1X10, V4L2_PIX_FMT_SGRBG10P, 1,
158 { { 1, 1 } }, { { 1, 1 } }, { 10 } },
159 { MEDIA_BUS_FMT_SRGGB10_1X10, V4L2_PIX_FMT_SRGGB10P, 1,
160 { { 1, 1 } }, { { 1, 1 } }, { 10 } },
161 { MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE, V4L2_PIX_FMT_SBGGR10, 1,
162 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
163 { MEDIA_BUS_FMT_SBGGR12_1X12, V4L2_PIX_FMT_SBGGR12P, 1,
164 { { 1, 1 } }, { { 1, 1 } }, { 12 } },
165 { MEDIA_BUS_FMT_SGBRG12_1X12, V4L2_PIX_FMT_SGBRG12P, 1,
166 { { 1, 1 } }, { { 1, 1 } }, { 12 } },
167 { MEDIA_BUS_FMT_SGRBG12_1X12, V4L2_PIX_FMT_SGRBG12P, 1,
168 { { 1, 1 } }, { { 1, 1 } }, { 12 } },
169 { MEDIA_BUS_FMT_SRGGB12_1X12, V4L2_PIX_FMT_SRGGB12P, 1,
170 { { 1, 1 } }, { { 1, 1 } }, { 12 } },
171 { MEDIA_BUS_FMT_SBGGR14_1X14, V4L2_PIX_FMT_SBGGR14P, 1,
172 { { 1, 1 } }, { { 1, 1 } }, { 14 } },
173 { MEDIA_BUS_FMT_SGBRG14_1X14, V4L2_PIX_FMT_SGBRG14P, 1,
174 { { 1, 1 } }, { { 1, 1 } }, { 14 } },
175 { MEDIA_BUS_FMT_SGRBG14_1X14, V4L2_PIX_FMT_SGRBG14P, 1,
176 { { 1, 1 } }, { { 1, 1 } }, { 14 } },
177 { MEDIA_BUS_FMT_SRGGB14_1X14, V4L2_PIX_FMT_SRGGB14P, 1,
178 { { 1, 1 } }, { { 1, 1 } }, { 14 } },
179 { MEDIA_BUS_FMT_Y8_1X8, V4L2_PIX_FMT_GREY, 1,
180 { { 1, 1 } }, { { 1, 1 } }, { 8 } },
181 { MEDIA_BUS_FMT_Y10_1X10, V4L2_PIX_FMT_Y10P, 1,
182 { { 1, 1 } }, { { 1, 1 } }, { 10 } },
183 { MEDIA_BUS_FMT_Y10_2X8_PADHI_LE, V4L2_PIX_FMT_Y10, 1,
184 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
188 { MEDIA_BUS_FMT_YUYV8_1_5X8, V4L2_PIX_FMT_NV12, 1,
189 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
190 { MEDIA_BUS_FMT_YVYU8_1_5X8, V4L2_PIX_FMT_NV12, 1,
191 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
192 { MEDIA_BUS_FMT_UYVY8_1_5X8, V4L2_PIX_FMT_NV12, 1,
193 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
194 { MEDIA_BUS_FMT_VYUY8_1_5X8, V4L2_PIX_FMT_NV12, 1,
195 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
196 { MEDIA_BUS_FMT_YUYV8_1_5X8, V4L2_PIX_FMT_NV21, 1,
197 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
198 { MEDIA_BUS_FMT_YVYU8_1_5X8, V4L2_PIX_FMT_NV21, 1,
199 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
200 { MEDIA_BUS_FMT_UYVY8_1_5X8, V4L2_PIX_FMT_NV21, 1,
201 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
202 { MEDIA_BUS_FMT_VYUY8_1_5X8, V4L2_PIX_FMT_NV21, 1,
203 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
204 { MEDIA_BUS_FMT_YUYV8_2X8, V4L2_PIX_FMT_NV16, 1,
205 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
206 { MEDIA_BUS_FMT_YVYU8_2X8, V4L2_PIX_FMT_NV16, 1,
207 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
208 { MEDIA_BUS_FMT_UYVY8_2X8, V4L2_PIX_FMT_NV16, 1,
209 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
210 { MEDIA_BUS_FMT_VYUY8_2X8, V4L2_PIX_FMT_NV16, 1,
211 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
212 { MEDIA_BUS_FMT_YUYV8_2X8, V4L2_PIX_FMT_NV61, 1,
213 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
214 { MEDIA_BUS_FMT_YVYU8_2X8, V4L2_PIX_FMT_NV61, 1,
215 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
216 { MEDIA_BUS_FMT_UYVY8_2X8, V4L2_PIX_FMT_NV61, 1,
217 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
218 { MEDIA_BUS_FMT_VYUY8_2X8, V4L2_PIX_FMT_NV61, 1,
219 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
223 { MEDIA_BUS_FMT_YUYV8_1_5X8, V4L2_PIX_FMT_NV12, 1,
224 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
225 { MEDIA_BUS_FMT_YVYU8_1_5X8, V4L2_PIX_FMT_NV12, 1,
226 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
227 { MEDIA_BUS_FMT_UYVY8_1_5X8, V4L2_PIX_FMT_NV12, 1,
228 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
229 { MEDIA_BUS_FMT_VYUY8_1_5X8, V4L2_PIX_FMT_NV12, 1,
230 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
231 { MEDIA_BUS_FMT_YUYV8_1_5X8, V4L2_PIX_FMT_NV21, 1,
232 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
233 { MEDIA_BUS_FMT_YVYU8_1_5X8, V4L2_PIX_FMT_NV21, 1,
234 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
235 { MEDIA_BUS_FMT_UYVY8_1_5X8, V4L2_PIX_FMT_NV21, 1,
236 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
237 { MEDIA_BUS_FMT_VYUY8_1_5X8, V4L2_PIX_FMT_NV21, 1,
238 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
239 { MEDIA_BUS_FMT_YUYV8_2X8, V4L2_PIX_FMT_NV16, 1,
240 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
241 { MEDIA_BUS_FMT_YVYU8_2X8, V4L2_PIX_FMT_NV16, 1,
242 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
243 { MEDIA_BUS_FMT_UYVY8_2X8, V4L2_PIX_FMT_NV16, 1,
244 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
245 { MEDIA_BUS_FMT_VYUY8_2X8, V4L2_PIX_FMT_NV16, 1,
246 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
247 { MEDIA_BUS_FMT_YUYV8_2X8, V4L2_PIX_FMT_NV61, 1,
248 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
249 { MEDIA_BUS_FMT_YVYU8_2X8, V4L2_PIX_FMT_NV61, 1,
250 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
251 { MEDIA_BUS_FMT_UYVY8_2X8, V4L2_PIX_FMT_NV61, 1,
252 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
253 { MEDIA_BUS_FMT_VYUY8_2X8, V4L2_PIX_FMT_NV61, 1,
254 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
255 { MEDIA_BUS_FMT_UYVY8_2X8, V4L2_PIX_FMT_UYVY, 1,
256 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
257 { MEDIA_BUS_FMT_VYUY8_2X8, V4L2_PIX_FMT_VYUY, 1,
258 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
259 { MEDIA_BUS_FMT_YUYV8_2X8, V4L2_PIX_FMT_YUYV, 1,
260 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
261 { MEDIA_BUS_FMT_YVYU8_2X8, V4L2_PIX_FMT_YVYU, 1,
262 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
265 /* -----------------------------------------------------------------------------
285 WARN_ON(1); in video_find_format()
287 return -EINVAL; in video_find_format()
291 * video_mbus_to_pix_mp - Convert v4l2_mbus_framefmt to v4l2_pix_format_mplane
311 pix->pixelformat = f->pixelformat; in video_mbus_to_pix_mp()
312 pix->num_planes = f->planes; in video_mbus_to_pix_mp()
313 for (i = 0; i < pix->num_planes; i++) { in video_mbus_to_pix_mp()
314 bytesperline = pix->width / f->hsub[i].numerator * in video_mbus_to_pix_mp()
315 f->hsub[i].denominator * f->bpp[i] / 8; in video_mbus_to_pix_mp()
317 pix->plane_fmt[i].bytesperline = bytesperline; in video_mbus_to_pix_mp()
318 pix->plane_fmt[i].sizeimage = pix->height / in video_mbus_to_pix_mp()
319 f->vsub[i].numerator * f->vsub[i].denominator * in video_mbus_to_pix_mp()
331 remote = media_pad_remote_pad_first(&video->pad); in video_remote_subdev()
333 if (!remote || !is_media_entity_v4l2_subdev(remote->entity)) in video_remote_subdev()
337 *pad = remote->index; in video_remote_subdev()
339 return media_entity_to_v4l2_subdev(remote->entity); in video_remote_subdev()
354 return -EPIPE; in video_get_subdev_format()
363 format->fmt.pix_mp.pixelformat, in video_get_subdev_format()
364 video->formats, video->nformats); in video_get_subdev_format()
368 format->type = video->type; in video_get_subdev_format()
370 return video_mbus_to_pix_mp(&fmt.format, &format->fmt.pix_mp, in video_get_subdev_format()
371 &video->formats[ret], video->bpl_alignment); in video_get_subdev_format()
374 /* -----------------------------------------------------------------------------
384 &video->active_fmt.fmt.pix_mp; in video_queue_setup()
388 if (*num_planes != format->num_planes) in video_queue_setup()
389 return -EINVAL; in video_queue_setup()
392 if (sizes[i] < format->plane_fmt[i].sizeimage) in video_queue_setup()
393 return -EINVAL; in video_queue_setup()
398 *num_planes = format->num_planes; in video_queue_setup()
401 sizes[i] = format->plane_fmt[i].sizeimage; in video_queue_setup()
409 struct camss_video *video = vb2_get_drv_priv(vb->vb2_queue); in video_buf_init()
413 &video->active_fmt.fmt.pix_mp; in video_buf_init()
417 for (i = 0; i < format->num_planes; i++) { in video_buf_init()
420 return -EFAULT; in video_buf_init()
422 buffer->addr[i] = sg_dma_address(sgt->sgl); in video_buf_init()
425 if (format->pixelformat == V4L2_PIX_FMT_NV12 || in video_buf_init()
426 format->pixelformat == V4L2_PIX_FMT_NV21 || in video_buf_init()
427 format->pixelformat == V4L2_PIX_FMT_NV16 || in video_buf_init()
428 format->pixelformat == V4L2_PIX_FMT_NV61) in video_buf_init()
429 buffer->addr[1] = buffer->addr[0] + in video_buf_init()
430 format->plane_fmt[0].bytesperline * in video_buf_init()
431 format->height; in video_buf_init()
439 struct camss_video *video = vb2_get_drv_priv(vb->vb2_queue); in video_buf_prepare()
441 &video->active_fmt.fmt.pix_mp; in video_buf_prepare()
444 for (i = 0; i < format->num_planes; i++) { in video_buf_prepare()
445 if (format->plane_fmt[i].sizeimage > vb2_plane_size(vb, i)) in video_buf_prepare()
446 return -EINVAL; in video_buf_prepare()
448 vb2_set_plane_payload(vb, i, format->plane_fmt[i].sizeimage); in video_buf_prepare()
451 vbuf->field = V4L2_FIELD_NONE; in video_buf_prepare()
459 struct camss_video *video = vb2_get_drv_priv(vb->vb2_queue); in video_buf_queue()
463 video->ops->queue_buffer(video, buffer); in video_buf_queue()
468 struct v4l2_pix_format_mplane *pix = &video->active_fmt.fmt.pix_mp; in video_check_format()
473 sd_pix->pixelformat = pix->pixelformat; in video_check_format()
478 if (pix->pixelformat != sd_pix->pixelformat || in video_check_format()
479 pix->height != sd_pix->height || in video_check_format()
480 pix->width != sd_pix->width || in video_check_format()
481 pix->num_planes != sd_pix->num_planes || in video_check_format()
482 pix->field != format.fmt.pix_mp.field) in video_check_format()
483 return -EPIPE; in video_check_format()
491 struct video_device *vdev = &video->vdev; in video_start_streaming()
499 dev_err(video->camss->dev, "Failed to start media pipeline: %d\n", ret); in video_start_streaming()
507 entity = &vdev->entity; in video_start_streaming()
508 while (1) { in video_start_streaming()
509 pad = &entity->pads[0]; in video_start_streaming()
510 if (!(pad->flags & MEDIA_PAD_FL_SINK)) in video_start_streaming()
514 if (!pad || !is_media_entity_v4l2_subdev(pad->entity)) in video_start_streaming()
517 entity = pad->entity; in video_start_streaming()
520 ret = v4l2_subdev_call(subdev, video, s_stream, 1); in video_start_streaming()
521 if (ret < 0 && ret != -ENOIOCTLCMD) in video_start_streaming()
531 video->ops->flush_buffers(video, VB2_BUF_STATE_QUEUED); in video_start_streaming()
539 struct video_device *vdev = &video->vdev; in video_stop_streaming()
545 entity = &vdev->entity; in video_stop_streaming()
546 while (1) { in video_stop_streaming()
547 pad = &entity->pads[0]; in video_stop_streaming()
548 if (!(pad->flags & MEDIA_PAD_FL_SINK)) in video_stop_streaming()
552 if (!pad || !is_media_entity_v4l2_subdev(pad->entity)) in video_stop_streaming()
555 entity = pad->entity; in video_stop_streaming()
561 dev_err(video->camss->dev, "Video pipeline stop failed: %d\n", ret); in video_stop_streaming()
568 video->ops->flush_buffers(video, VB2_BUF_STATE_ERROR); in video_stop_streaming()
582 /* -----------------------------------------------------------------------------
589 strscpy(cap->driver, "qcom-camss", sizeof(cap->driver)); in video_querycap()
590 strscpy(cap->card, "Qualcomm Camera Subsystem", sizeof(cap->card)); in video_querycap()
599 u32 mcode = f->mbus_code; in video_enum_fmt()
601 if (f->type != video->type) in video_enum_fmt()
602 return -EINVAL; in video_enum_fmt()
604 if (f->index >= video->nformats) in video_enum_fmt()
605 return -EINVAL; in video_enum_fmt()
610 * If f->mbus_code passed to video_enum_fmt() is not zero, a device in video_enum_fmt()
613 * This is implemented by skipping video->formats[] entries with in video_enum_fmt()
614 * code != f->mbus_code (if f->mbus_code is not zero). in video_enum_fmt()
615 * If the f->mbus_code passed to video_enum_fmt() is not supported, in video_enum_fmt()
616 * -EINVAL is returned. in video_enum_fmt()
617 * If f->mbus_code is zero, all the pixel formats are enumerated. in video_enum_fmt()
619 k = -1; in video_enum_fmt()
620 for (i = 0; i < video->nformats; i++) { in video_enum_fmt()
621 if (mcode != 0 && video->formats[i].code != mcode) in video_enum_fmt()
625 if (mcode != 0 && video->formats[j].code != mcode) in video_enum_fmt()
627 if (video->formats[i].pixelformat == in video_enum_fmt()
628 video->formats[j].pixelformat) in video_enum_fmt()
635 if (k == f->index) in video_enum_fmt()
639 if (k == -1 || k < f->index) in video_enum_fmt()
642 * have been enumerated (k >= 0 and f->index > 0), or in video_enum_fmt()
643 * no pixel formats match the non-zero f->mbus_code (k == -1). in video_enum_fmt()
645 return -EINVAL; in video_enum_fmt()
647 f->pixelformat = video->formats[i].pixelformat; in video_enum_fmt()
658 if (fsize->index) in video_enum_framesizes()
659 return -EINVAL; in video_enum_framesizes()
662 for (i = 0; i < video->nformats; i++) { in video_enum_framesizes()
663 if (video->formats[i].pixelformat == fsize->pixel_format) in video_enum_framesizes()
667 if (i == video->nformats) in video_enum_framesizes()
668 return -EINVAL; in video_enum_framesizes()
670 fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS; in video_enum_framesizes()
671 fsize->stepwise.min_width = CAMSS_FRAME_MIN_WIDTH; in video_enum_framesizes()
672 fsize->stepwise.max_width = CAMSS_FRAME_MAX_WIDTH; in video_enum_framesizes()
673 fsize->stepwise.min_height = CAMSS_FRAME_MIN_HEIGHT; in video_enum_framesizes()
674 fsize->stepwise.max_height = (video->line_based) ? in video_enum_framesizes()
676 fsize->stepwise.step_width = 1; in video_enum_framesizes()
677 fsize->stepwise.step_height = 1; in video_enum_framesizes()
686 *f = video->active_fmt; in video_g_fmt()
702 pix_mp = &f->fmt.pix_mp; in __video_try_fmt()
704 if (video->line_based) in __video_try_fmt()
705 for (i = 0; i < pix_mp->num_planes && i < 3; i++) { in __video_try_fmt()
706 p = &pix_mp->plane_fmt[i]; in __video_try_fmt()
707 bytesperline[i] = clamp_t(u32, p->bytesperline, in __video_try_fmt()
708 1, 65528); in __video_try_fmt()
709 sizeimage[i] = clamp_t(u32, p->sizeimage, in __video_try_fmt()
714 for (j = 0; j < video->nformats; j++) in __video_try_fmt()
715 if (pix_mp->pixelformat == video->formats[j].pixelformat) in __video_try_fmt()
718 if (j == video->nformats) in __video_try_fmt()
721 fi = &video->formats[j]; in __video_try_fmt()
722 width = pix_mp->width; in __video_try_fmt()
723 height = pix_mp->height; in __video_try_fmt()
727 pix_mp->pixelformat = fi->pixelformat; in __video_try_fmt()
728 pix_mp->width = clamp_t(u32, width, 1, CAMSS_FRAME_MAX_WIDTH); in __video_try_fmt()
729 pix_mp->height = clamp_t(u32, height, 1, CAMSS_FRAME_MAX_HEIGHT_RDI); in __video_try_fmt()
730 pix_mp->num_planes = fi->planes; in __video_try_fmt()
731 for (i = 0; i < pix_mp->num_planes; i++) { in __video_try_fmt()
732 bpl = pix_mp->width / fi->hsub[i].numerator * in __video_try_fmt()
733 fi->hsub[i].denominator * fi->bpp[i] / 8; in __video_try_fmt()
734 bpl = ALIGN(bpl, video->bpl_alignment); in __video_try_fmt()
735 pix_mp->plane_fmt[i].bytesperline = bpl; in __video_try_fmt()
736 pix_mp->plane_fmt[i].sizeimage = pix_mp->height / in __video_try_fmt()
737 fi->vsub[i].numerator * fi->vsub[i].denominator * bpl; in __video_try_fmt()
740 pix_mp->field = V4L2_FIELD_NONE; in __video_try_fmt()
741 pix_mp->colorspace = V4L2_COLORSPACE_SRGB; in __video_try_fmt()
742 pix_mp->flags = 0; in __video_try_fmt()
743 pix_mp->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(pix_mp->colorspace); in __video_try_fmt()
744 pix_mp->quantization = V4L2_MAP_QUANTIZATION_DEFAULT(true, in __video_try_fmt()
745 pix_mp->colorspace, pix_mp->ycbcr_enc); in __video_try_fmt()
746 pix_mp->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(pix_mp->colorspace); in __video_try_fmt()
748 if (video->line_based) in __video_try_fmt()
749 for (i = 0; i < pix_mp->num_planes; i++) { in __video_try_fmt()
750 p = &pix_mp->plane_fmt[i]; in __video_try_fmt()
751 p->bytesperline = clamp_t(u32, p->bytesperline, in __video_try_fmt()
752 1, 65528); in __video_try_fmt()
753 p->sizeimage = clamp_t(u32, p->sizeimage, in __video_try_fmt()
754 p->bytesperline, in __video_try_fmt()
755 p->bytesperline * CAMSS_FRAME_MAX_HEIGHT_PIX); in __video_try_fmt()
756 lines = p->sizeimage / p->bytesperline; in __video_try_fmt()
758 if (p->bytesperline < bytesperline[i]) in __video_try_fmt()
759 p->bytesperline = ALIGN(bytesperline[i], 8); in __video_try_fmt()
761 if (p->sizeimage < p->bytesperline * lines) in __video_try_fmt()
762 p->sizeimage = p->bytesperline * lines; in __video_try_fmt()
764 if (p->sizeimage < sizeimage[i]) in __video_try_fmt()
765 p->sizeimage = sizeimage[i]; in __video_try_fmt()
783 if (vb2_is_busy(&video->vb2_q)) in video_s_fmt()
784 return -EBUSY; in video_s_fmt()
790 video->active_fmt = *f; in video_s_fmt()
798 if (input->index > 0) in video_enum_input()
799 return -EINVAL; in video_enum_input()
801 strscpy(input->name, "camera", sizeof(input->name)); in video_enum_input()
802 input->type = V4L2_INPUT_TYPE_CAMERA; in video_enum_input()
816 return input == 0 ? 0 : -EINVAL; in video_s_input()
840 /* -----------------------------------------------------------------------------
851 mutex_lock(&video->lock); in video_open()
855 ret = -ENOMEM; in video_open()
862 file->private_data = vfh; in video_open()
864 ret = v4l2_pipeline_pm_get(&vdev->entity); in video_open()
866 dev_err(video->camss->dev, "Failed to power up pipeline: %d\n", in video_open()
871 mutex_unlock(&video->lock); in video_open()
879 mutex_unlock(&video->lock); in video_open()
890 v4l2_pipeline_pm_put(&vdev->entity); in video_release()
892 file->private_data = NULL; in video_release()
907 /* -----------------------------------------------------------------------------
915 media_entity_cleanup(&vdev->entity); in msm_video_release()
917 mutex_destroy(&video->q_lock); in msm_video_release()
918 mutex_destroy(&video->lock); in msm_video_release()
920 if (atomic_dec_and_test(&video->camss->ref_count)) in msm_video_release()
921 camss_delete(video->camss); in msm_video_release()
925 * msm_video_init_format - Helper function to initialize format
940 .pixelformat = video->formats[0].pixelformat, in msm_video_init_format()
948 video->active_fmt = format; in msm_video_init_format()
954 * msm_video_register - Register a video device node
968 struct media_pad *pad = &video->pad; in msm_video_register()
973 vdev = &video->vdev; in msm_video_register()
975 mutex_init(&video->q_lock); in msm_video_register()
977 q = &video->vb2_q; in msm_video_register()
978 q->drv_priv = video; in msm_video_register()
979 q->mem_ops = &vb2_dma_sg_memops; in msm_video_register()
980 q->ops = &msm_video_vb2_q_ops; in msm_video_register()
981 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; in msm_video_register()
982 q->io_modes = VB2_DMABUF | VB2_MMAP | VB2_READ; in msm_video_register()
983 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in msm_video_register()
984 q->buf_struct_size = sizeof(struct camss_buffer); in msm_video_register()
985 q->dev = video->camss->dev; in msm_video_register()
986 q->lock = &video->q_lock; in msm_video_register()
989 dev_err(v4l2_dev->dev, "Failed to init vb2 queue: %d\n", ret); in msm_video_register()
993 pad->flags = MEDIA_PAD_FL_SINK; in msm_video_register()
994 ret = media_entity_pads_init(&vdev->entity, 1, pad); in msm_video_register()
996 dev_err(v4l2_dev->dev, "Failed to init video entity: %d\n", in msm_video_register()
1001 mutex_init(&video->lock); in msm_video_register()
1003 if (video->camss->version == CAMSS_8x16) { in msm_video_register()
1005 video->formats = formats_pix_8x16; in msm_video_register()
1006 video->nformats = ARRAY_SIZE(formats_pix_8x16); in msm_video_register()
1008 video->formats = formats_rdi_8x16; in msm_video_register()
1009 video->nformats = ARRAY_SIZE(formats_rdi_8x16); in msm_video_register()
1011 } else if (video->camss->version == CAMSS_8x96 || in msm_video_register()
1012 video->camss->version == CAMSS_660) { in msm_video_register()
1014 video->formats = formats_pix_8x96; in msm_video_register()
1015 video->nformats = ARRAY_SIZE(formats_pix_8x96); in msm_video_register()
1017 video->formats = formats_rdi_8x96; in msm_video_register()
1018 video->nformats = ARRAY_SIZE(formats_rdi_8x96); in msm_video_register()
1020 } else if (video->camss->version == CAMSS_845 || in msm_video_register()
1021 video->camss->version == CAMSS_8250) { in msm_video_register()
1022 video->formats = formats_rdi_845; in msm_video_register()
1023 video->nformats = ARRAY_SIZE(formats_rdi_845); in msm_video_register()
1025 ret = -EINVAL; in msm_video_register()
1031 dev_err(v4l2_dev->dev, "Failed to init format: %d\n", ret); in msm_video_register()
1035 vdev->fops = &msm_vid_fops; in msm_video_register()
1036 vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_STREAMING in msm_video_register()
1038 vdev->ioctl_ops = &msm_vid_ioctl_ops; in msm_video_register()
1039 vdev->release = msm_video_release; in msm_video_register()
1040 vdev->v4l2_dev = v4l2_dev; in msm_video_register()
1041 vdev->vfl_dir = VFL_DIR_RX; in msm_video_register()
1042 vdev->queue = &video->vb2_q; in msm_video_register()
1043 vdev->lock = &video->lock; in msm_video_register()
1044 strscpy(vdev->name, name, sizeof(vdev->name)); in msm_video_register()
1046 ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1); in msm_video_register()
1048 dev_err(v4l2_dev->dev, "Failed to register video device: %d\n", in msm_video_register()
1054 atomic_inc(&video->camss->ref_count); in msm_video_register()
1059 media_entity_cleanup(&vdev->entity); in msm_video_register()
1060 mutex_destroy(&video->lock); in msm_video_register()
1062 mutex_destroy(&video->q_lock); in msm_video_register()
1069 atomic_inc(&video->camss->ref_count); in msm_video_unregister()
1070 vb2_video_unregister_device(&video->vdev); in msm_video_unregister()
1071 atomic_dec(&video->camss->ref_count); in msm_video_unregister()