Lines Matching +full:1 +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_Y10_1X10, V4L2_PIX_FMT_Y10P, 1,
180 { { 1, 1 } }, { { 1, 1 } }, { 10 } },
181 { MEDIA_BUS_FMT_Y10_2X8_PADHI_LE, V4L2_PIX_FMT_Y10, 1,
182 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
186 { MEDIA_BUS_FMT_YUYV8_1_5X8, V4L2_PIX_FMT_NV12, 1,
187 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
188 { MEDIA_BUS_FMT_YVYU8_1_5X8, V4L2_PIX_FMT_NV12, 1,
189 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
190 { MEDIA_BUS_FMT_UYVY8_1_5X8, V4L2_PIX_FMT_NV12, 1,
191 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
192 { MEDIA_BUS_FMT_VYUY8_1_5X8, V4L2_PIX_FMT_NV12, 1,
193 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
194 { MEDIA_BUS_FMT_YUYV8_1_5X8, V4L2_PIX_FMT_NV21, 1,
195 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
196 { MEDIA_BUS_FMT_YVYU8_1_5X8, V4L2_PIX_FMT_NV21, 1,
197 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
198 { MEDIA_BUS_FMT_UYVY8_1_5X8, V4L2_PIX_FMT_NV21, 1,
199 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
200 { MEDIA_BUS_FMT_VYUY8_1_5X8, V4L2_PIX_FMT_NV21, 1,
201 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
202 { MEDIA_BUS_FMT_YUYV8_2X8, V4L2_PIX_FMT_NV16, 1,
203 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
204 { MEDIA_BUS_FMT_YVYU8_2X8, V4L2_PIX_FMT_NV16, 1,
205 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
206 { MEDIA_BUS_FMT_UYVY8_2X8, V4L2_PIX_FMT_NV16, 1,
207 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
208 { MEDIA_BUS_FMT_VYUY8_2X8, V4L2_PIX_FMT_NV16, 1,
209 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
210 { MEDIA_BUS_FMT_YUYV8_2X8, V4L2_PIX_FMT_NV61, 1,
211 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
212 { MEDIA_BUS_FMT_YVYU8_2X8, V4L2_PIX_FMT_NV61, 1,
213 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
214 { MEDIA_BUS_FMT_UYVY8_2X8, V4L2_PIX_FMT_NV61, 1,
215 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
216 { MEDIA_BUS_FMT_VYUY8_2X8, V4L2_PIX_FMT_NV61, 1,
217 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
221 { MEDIA_BUS_FMT_YUYV8_1_5X8, V4L2_PIX_FMT_NV12, 1,
222 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
223 { MEDIA_BUS_FMT_YVYU8_1_5X8, V4L2_PIX_FMT_NV12, 1,
224 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
225 { MEDIA_BUS_FMT_UYVY8_1_5X8, V4L2_PIX_FMT_NV12, 1,
226 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
227 { MEDIA_BUS_FMT_VYUY8_1_5X8, V4L2_PIX_FMT_NV12, 1,
228 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
229 { MEDIA_BUS_FMT_YUYV8_1_5X8, V4L2_PIX_FMT_NV21, 1,
230 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
231 { MEDIA_BUS_FMT_YVYU8_1_5X8, V4L2_PIX_FMT_NV21, 1,
232 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
233 { MEDIA_BUS_FMT_UYVY8_1_5X8, V4L2_PIX_FMT_NV21, 1,
234 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
235 { MEDIA_BUS_FMT_VYUY8_1_5X8, V4L2_PIX_FMT_NV21, 1,
236 { { 1, 1 } }, { { 2, 3 } }, { 8 } },
237 { MEDIA_BUS_FMT_YUYV8_2X8, V4L2_PIX_FMT_NV16, 1,
238 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
239 { MEDIA_BUS_FMT_YVYU8_2X8, V4L2_PIX_FMT_NV16, 1,
240 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
241 { MEDIA_BUS_FMT_UYVY8_2X8, V4L2_PIX_FMT_NV16, 1,
242 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
243 { MEDIA_BUS_FMT_VYUY8_2X8, V4L2_PIX_FMT_NV16, 1,
244 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
245 { MEDIA_BUS_FMT_YUYV8_2X8, V4L2_PIX_FMT_NV61, 1,
246 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
247 { MEDIA_BUS_FMT_YVYU8_2X8, V4L2_PIX_FMT_NV61, 1,
248 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
249 { MEDIA_BUS_FMT_UYVY8_2X8, V4L2_PIX_FMT_NV61, 1,
250 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
251 { MEDIA_BUS_FMT_VYUY8_2X8, V4L2_PIX_FMT_NV61, 1,
252 { { 1, 1 } }, { { 1, 2 } }, { 8 } },
253 { MEDIA_BUS_FMT_UYVY8_2X8, V4L2_PIX_FMT_UYVY, 1,
254 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
255 { MEDIA_BUS_FMT_VYUY8_2X8, V4L2_PIX_FMT_VYUY, 1,
256 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
257 { MEDIA_BUS_FMT_YUYV8_2X8, V4L2_PIX_FMT_YUYV, 1,
258 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
259 { MEDIA_BUS_FMT_YVYU8_2X8, V4L2_PIX_FMT_YVYU, 1,
260 { { 1, 1 } }, { { 1, 1 } }, { 16 } },
263 /* -----------------------------------------------------------------------------
283 WARN_ON(1); in video_find_format()
285 return -EINVAL; in video_find_format()
289 * video_mbus_to_pix_mp - Convert v4l2_mbus_framefmt to v4l2_pix_format_mplane
309 pix->pixelformat = f->pixelformat; in video_mbus_to_pix_mp()
310 pix->num_planes = f->planes; in video_mbus_to_pix_mp()
311 for (i = 0; i < pix->num_planes; i++) { in video_mbus_to_pix_mp()
312 bytesperline = pix->width / f->hsub[i].numerator * in video_mbus_to_pix_mp()
313 f->hsub[i].denominator * f->bpp[i] / 8; in video_mbus_to_pix_mp()
315 pix->plane_fmt[i].bytesperline = bytesperline; in video_mbus_to_pix_mp()
316 pix->plane_fmt[i].sizeimage = pix->height / in video_mbus_to_pix_mp()
317 f->vsub[i].numerator * f->vsub[i].denominator * in video_mbus_to_pix_mp()
329 remote = media_entity_remote_pad(&video->pad); in video_remote_subdev()
331 if (!remote || !is_media_entity_v4l2_subdev(remote->entity)) in video_remote_subdev()
335 *pad = remote->index; in video_remote_subdev()
337 return media_entity_to_v4l2_subdev(remote->entity); in video_remote_subdev()
350 return -EPIPE; in video_get_subdev_format()
360 format->fmt.pix_mp.pixelformat, in video_get_subdev_format()
361 video->formats, video->nformats); in video_get_subdev_format()
365 format->type = video->type; in video_get_subdev_format()
367 return video_mbus_to_pix_mp(&fmt.format, &format->fmt.pix_mp, in video_get_subdev_format()
368 &video->formats[ret], video->bpl_alignment); in video_get_subdev_format()
371 /* -----------------------------------------------------------------------------
381 &video->active_fmt.fmt.pix_mp; in video_queue_setup()
385 if (*num_planes != format->num_planes) in video_queue_setup()
386 return -EINVAL; in video_queue_setup()
389 if (sizes[i] < format->plane_fmt[i].sizeimage) in video_queue_setup()
390 return -EINVAL; in video_queue_setup()
395 *num_planes = format->num_planes; in video_queue_setup()
398 sizes[i] = format->plane_fmt[i].sizeimage; in video_queue_setup()
406 struct camss_video *video = vb2_get_drv_priv(vb->vb2_queue); in video_buf_init()
410 &video->active_fmt.fmt.pix_mp; in video_buf_init()
414 for (i = 0; i < format->num_planes; i++) { in video_buf_init()
417 return -EFAULT; in video_buf_init()
419 buffer->addr[i] = sg_dma_address(sgt->sgl); in video_buf_init()
422 if (format->pixelformat == V4L2_PIX_FMT_NV12 || in video_buf_init()
423 format->pixelformat == V4L2_PIX_FMT_NV21 || in video_buf_init()
424 format->pixelformat == V4L2_PIX_FMT_NV16 || in video_buf_init()
425 format->pixelformat == V4L2_PIX_FMT_NV61) in video_buf_init()
426 buffer->addr[1] = buffer->addr[0] + in video_buf_init()
427 format->plane_fmt[0].bytesperline * in video_buf_init()
428 format->height; in video_buf_init()
436 struct camss_video *video = vb2_get_drv_priv(vb->vb2_queue); in video_buf_prepare()
438 &video->active_fmt.fmt.pix_mp; in video_buf_prepare()
441 for (i = 0; i < format->num_planes; i++) { in video_buf_prepare()
442 if (format->plane_fmt[i].sizeimage > vb2_plane_size(vb, i)) in video_buf_prepare()
443 return -EINVAL; in video_buf_prepare()
445 vb2_set_plane_payload(vb, i, format->plane_fmt[i].sizeimage); in video_buf_prepare()
448 vbuf->field = V4L2_FIELD_NONE; in video_buf_prepare()
456 struct camss_video *video = vb2_get_drv_priv(vb->vb2_queue); in video_buf_queue()
460 video->ops->queue_buffer(video, buffer); in video_buf_queue()
465 struct v4l2_pix_format_mplane *pix = &video->active_fmt.fmt.pix_mp; in video_check_format()
470 sd_pix->pixelformat = pix->pixelformat; in video_check_format()
475 if (pix->pixelformat != sd_pix->pixelformat || in video_check_format()
476 pix->height != sd_pix->height || in video_check_format()
477 pix->width != sd_pix->width || in video_check_format()
478 pix->num_planes != sd_pix->num_planes || in video_check_format()
479 pix->field != format.fmt.pix_mp.field) in video_check_format()
480 return -EPIPE; in video_check_format()
488 struct video_device *vdev = &video->vdev; in video_start_streaming()
494 ret = media_pipeline_start(&vdev->entity, &video->pipe); in video_start_streaming()
502 entity = &vdev->entity; in video_start_streaming()
503 while (1) { in video_start_streaming()
504 pad = &entity->pads[0]; in video_start_streaming()
505 if (!(pad->flags & MEDIA_PAD_FL_SINK)) in video_start_streaming()
509 if (!pad || !is_media_entity_v4l2_subdev(pad->entity)) in video_start_streaming()
512 entity = pad->entity; in video_start_streaming()
515 ret = v4l2_subdev_call(subdev, video, s_stream, 1); in video_start_streaming()
516 if (ret < 0 && ret != -ENOIOCTLCMD) in video_start_streaming()
523 media_pipeline_stop(&vdev->entity); in video_start_streaming()
525 video->ops->flush_buffers(video, VB2_BUF_STATE_QUEUED); in video_start_streaming()
533 struct video_device *vdev = &video->vdev; in video_stop_streaming()
538 entity = &vdev->entity; in video_stop_streaming()
539 while (1) { in video_stop_streaming()
540 pad = &entity->pads[0]; in video_stop_streaming()
541 if (!(pad->flags & MEDIA_PAD_FL_SINK)) in video_stop_streaming()
545 if (!pad || !is_media_entity_v4l2_subdev(pad->entity)) in video_stop_streaming()
548 entity = pad->entity; in video_stop_streaming()
554 media_pipeline_stop(&vdev->entity); in video_stop_streaming()
556 video->ops->flush_buffers(video, VB2_BUF_STATE_ERROR); in video_stop_streaming()
570 /* -----------------------------------------------------------------------------
579 strscpy(cap->driver, "qcom-camss", sizeof(cap->driver)); in video_querycap()
580 strscpy(cap->card, "Qualcomm Camera Subsystem", sizeof(cap->card)); in video_querycap()
581 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s", in video_querycap()
582 dev_name(video->camss->dev)); in video_querycap()
591 u32 mcode = f->mbus_code; in video_enum_fmt()
593 if (f->type != video->type) in video_enum_fmt()
594 return -EINVAL; in video_enum_fmt()
596 if (f->index >= video->nformats) in video_enum_fmt()
597 return -EINVAL; in video_enum_fmt()
602 * If f->mbus_code passed to video_enum_fmt() is not zero, a device in video_enum_fmt()
605 * This is implemented by skipping video->formats[] entries with in video_enum_fmt()
606 * code != f->mbus_code (if f->mbus_code is not zero). in video_enum_fmt()
607 * If the f->mbus_code passed to video_enum_fmt() is not supported, in video_enum_fmt()
608 * -EINVAL is returned. in video_enum_fmt()
609 * If f->mbus_code is zero, all the pixel formats are enumerated. in video_enum_fmt()
611 k = -1; in video_enum_fmt()
612 for (i = 0; i < video->nformats; i++) { in video_enum_fmt()
613 if (mcode != 0 && video->formats[i].code != mcode) in video_enum_fmt()
617 if (mcode != 0 && video->formats[j].code != mcode) in video_enum_fmt()
619 if (video->formats[i].pixelformat == in video_enum_fmt()
620 video->formats[j].pixelformat) in video_enum_fmt()
627 if (k == f->index) in video_enum_fmt()
631 if (k == -1 || k < f->index) in video_enum_fmt()
634 * have been enumerated (k >= 0 and f->index > 0), or in video_enum_fmt()
635 * no pixel formats match the non-zero f->mbus_code (k == -1). in video_enum_fmt()
637 return -EINVAL; in video_enum_fmt()
639 f->pixelformat = video->formats[i].pixelformat; in video_enum_fmt()
650 if (fsize->index) in video_enum_framesizes()
651 return -EINVAL; in video_enum_framesizes()
654 for (i = 0; i < video->nformats; i++) { in video_enum_framesizes()
655 if (video->formats[i].pixelformat == fsize->pixel_format) in video_enum_framesizes()
659 if (i == video->nformats) in video_enum_framesizes()
660 return -EINVAL; in video_enum_framesizes()
662 fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS; in video_enum_framesizes()
663 fsize->stepwise.min_width = CAMSS_FRAME_MIN_WIDTH; in video_enum_framesizes()
664 fsize->stepwise.max_width = CAMSS_FRAME_MAX_WIDTH; in video_enum_framesizes()
665 fsize->stepwise.min_height = CAMSS_FRAME_MIN_HEIGHT; in video_enum_framesizes()
666 fsize->stepwise.max_height = (video->line_based) ? in video_enum_framesizes()
668 fsize->stepwise.step_width = 1; in video_enum_framesizes()
669 fsize->stepwise.step_height = 1; in video_enum_framesizes()
678 *f = video->active_fmt; in video_g_fmt()
694 pix_mp = &f->fmt.pix_mp; in __video_try_fmt()
696 if (video->line_based) in __video_try_fmt()
697 for (i = 0; i < pix_mp->num_planes && i < 3; i++) { in __video_try_fmt()
698 p = &pix_mp->plane_fmt[i]; in __video_try_fmt()
699 bytesperline[i] = clamp_t(u32, p->bytesperline, in __video_try_fmt()
700 1, 65528); in __video_try_fmt()
701 sizeimage[i] = clamp_t(u32, p->sizeimage, in __video_try_fmt()
706 for (j = 0; j < video->nformats; j++) in __video_try_fmt()
707 if (pix_mp->pixelformat == video->formats[j].pixelformat) in __video_try_fmt()
710 if (j == video->nformats) in __video_try_fmt()
713 fi = &video->formats[j]; in __video_try_fmt()
714 width = pix_mp->width; in __video_try_fmt()
715 height = pix_mp->height; in __video_try_fmt()
719 pix_mp->pixelformat = fi->pixelformat; in __video_try_fmt()
720 pix_mp->width = clamp_t(u32, width, 1, CAMSS_FRAME_MAX_WIDTH); in __video_try_fmt()
721 pix_mp->height = clamp_t(u32, height, 1, CAMSS_FRAME_MAX_HEIGHT_RDI); in __video_try_fmt()
722 pix_mp->num_planes = fi->planes; in __video_try_fmt()
723 for (i = 0; i < pix_mp->num_planes; i++) { in __video_try_fmt()
724 bpl = pix_mp->width / fi->hsub[i].numerator * in __video_try_fmt()
725 fi->hsub[i].denominator * fi->bpp[i] / 8; in __video_try_fmt()
726 bpl = ALIGN(bpl, video->bpl_alignment); in __video_try_fmt()
727 pix_mp->plane_fmt[i].bytesperline = bpl; in __video_try_fmt()
728 pix_mp->plane_fmt[i].sizeimage = pix_mp->height / in __video_try_fmt()
729 fi->vsub[i].numerator * fi->vsub[i].denominator * bpl; in __video_try_fmt()
732 pix_mp->field = V4L2_FIELD_NONE; in __video_try_fmt()
733 pix_mp->colorspace = V4L2_COLORSPACE_SRGB; in __video_try_fmt()
734 pix_mp->flags = 0; in __video_try_fmt()
735 pix_mp->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(pix_mp->colorspace); in __video_try_fmt()
736 pix_mp->quantization = V4L2_MAP_QUANTIZATION_DEFAULT(true, in __video_try_fmt()
737 pix_mp->colorspace, pix_mp->ycbcr_enc); in __video_try_fmt()
738 pix_mp->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(pix_mp->colorspace); in __video_try_fmt()
740 if (video->line_based) in __video_try_fmt()
741 for (i = 0; i < pix_mp->num_planes; i++) { in __video_try_fmt()
742 p = &pix_mp->plane_fmt[i]; in __video_try_fmt()
743 p->bytesperline = clamp_t(u32, p->bytesperline, in __video_try_fmt()
744 1, 65528); in __video_try_fmt()
745 p->sizeimage = clamp_t(u32, p->sizeimage, in __video_try_fmt()
746 p->bytesperline, in __video_try_fmt()
747 p->bytesperline * CAMSS_FRAME_MAX_HEIGHT_PIX); in __video_try_fmt()
748 lines = p->sizeimage / p->bytesperline; in __video_try_fmt()
750 if (p->bytesperline < bytesperline[i]) in __video_try_fmt()
751 p->bytesperline = ALIGN(bytesperline[i], 8); in __video_try_fmt()
753 if (p->sizeimage < p->bytesperline * lines) in __video_try_fmt()
754 p->sizeimage = p->bytesperline * lines; in __video_try_fmt()
756 if (p->sizeimage < sizeimage[i]) in __video_try_fmt()
757 p->sizeimage = sizeimage[i]; in __video_try_fmt()
775 if (vb2_is_busy(&video->vb2_q)) in video_s_fmt()
776 return -EBUSY; in video_s_fmt()
782 video->active_fmt = *f; in video_s_fmt()
790 if (input->index > 0) in video_enum_input()
791 return -EINVAL; in video_enum_input()
793 strscpy(input->name, "camera", sizeof(input->name)); in video_enum_input()
794 input->type = V4L2_INPUT_TYPE_CAMERA; in video_enum_input()
808 return input == 0 ? 0 : -EINVAL; in video_s_input()
832 /* -----------------------------------------------------------------------------
843 mutex_lock(&video->lock); in video_open()
847 ret = -ENOMEM; in video_open()
854 file->private_data = vfh; in video_open()
856 ret = v4l2_pipeline_pm_get(&vdev->entity); in video_open()
858 dev_err(video->camss->dev, "Failed to power up pipeline: %d\n", in video_open()
863 mutex_unlock(&video->lock); in video_open()
871 mutex_unlock(&video->lock); in video_open()
882 v4l2_pipeline_pm_put(&vdev->entity); in video_release()
884 file->private_data = NULL; in video_release()
899 /* -----------------------------------------------------------------------------
907 media_entity_cleanup(&vdev->entity); in msm_video_release()
909 mutex_destroy(&video->q_lock); in msm_video_release()
910 mutex_destroy(&video->lock); in msm_video_release()
912 if (atomic_dec_and_test(&video->camss->ref_count)) in msm_video_release()
913 camss_delete(video->camss); in msm_video_release()
917 * msm_video_init_format - Helper function to initialize format
932 .pixelformat = video->formats[0].pixelformat, in msm_video_init_format()
940 video->active_fmt = format; in msm_video_init_format()
946 * msm_video_register - Register a video device node
960 struct media_pad *pad = &video->pad; in msm_video_register()
965 vdev = &video->vdev; in msm_video_register()
967 mutex_init(&video->q_lock); in msm_video_register()
969 q = &video->vb2_q; in msm_video_register()
970 q->drv_priv = video; in msm_video_register()
971 q->mem_ops = &vb2_dma_sg_memops; in msm_video_register()
972 q->ops = &msm_video_vb2_q_ops; in msm_video_register()
973 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; in msm_video_register()
974 q->io_modes = VB2_DMABUF | VB2_MMAP | VB2_READ; in msm_video_register()
975 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in msm_video_register()
976 q->buf_struct_size = sizeof(struct camss_buffer); in msm_video_register()
977 q->dev = video->camss->dev; in msm_video_register()
978 q->lock = &video->q_lock; in msm_video_register()
981 dev_err(v4l2_dev->dev, "Failed to init vb2 queue: %d\n", ret); in msm_video_register()
985 pad->flags = MEDIA_PAD_FL_SINK; in msm_video_register()
986 ret = media_entity_pads_init(&vdev->entity, 1, pad); in msm_video_register()
988 dev_err(v4l2_dev->dev, "Failed to init video entity: %d\n", in msm_video_register()
993 mutex_init(&video->lock); in msm_video_register()
995 if (video->camss->version == CAMSS_8x16) { in msm_video_register()
997 video->formats = formats_pix_8x16; in msm_video_register()
998 video->nformats = ARRAY_SIZE(formats_pix_8x16); in msm_video_register()
1000 video->formats = formats_rdi_8x16; in msm_video_register()
1001 video->nformats = ARRAY_SIZE(formats_rdi_8x16); in msm_video_register()
1003 } else if (video->camss->version == CAMSS_8x96 || in msm_video_register()
1004 video->camss->version == CAMSS_660) { in msm_video_register()
1006 video->formats = formats_pix_8x96; in msm_video_register()
1007 video->nformats = ARRAY_SIZE(formats_pix_8x96); in msm_video_register()
1009 video->formats = formats_rdi_8x96; in msm_video_register()
1010 video->nformats = ARRAY_SIZE(formats_rdi_8x96); in msm_video_register()
1012 } else if (video->camss->version == CAMSS_845) { in msm_video_register()
1013 video->formats = formats_rdi_845; in msm_video_register()
1014 video->nformats = ARRAY_SIZE(formats_rdi_845); in msm_video_register()
1016 ret = -EINVAL; in msm_video_register()
1022 dev_err(v4l2_dev->dev, "Failed to init format: %d\n", ret); in msm_video_register()
1026 vdev->fops = &msm_vid_fops; in msm_video_register()
1027 vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_STREAMING in msm_video_register()
1029 vdev->ioctl_ops = &msm_vid_ioctl_ops; in msm_video_register()
1030 vdev->release = msm_video_release; in msm_video_register()
1031 vdev->v4l2_dev = v4l2_dev; in msm_video_register()
1032 vdev->vfl_dir = VFL_DIR_RX; in msm_video_register()
1033 vdev->queue = &video->vb2_q; in msm_video_register()
1034 vdev->lock = &video->lock; in msm_video_register()
1035 strscpy(vdev->name, name, sizeof(vdev->name)); in msm_video_register()
1037 ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1); in msm_video_register()
1039 dev_err(v4l2_dev->dev, "Failed to register video device: %d\n", in msm_video_register()
1045 atomic_inc(&video->camss->ref_count); in msm_video_register()
1050 media_entity_cleanup(&vdev->entity); in msm_video_register()
1051 mutex_destroy(&video->lock); in msm_video_register()
1053 mutex_destroy(&video->q_lock); in msm_video_register()
1060 atomic_inc(&video->camss->ref_count); in msm_video_unregister()
1061 vb2_video_unregister_device(&video->vdev); in msm_video_unregister()
1062 atomic_dec(&video->camss->ref_count); in msm_video_unregister()