blob: 4cdd32692ad788a7a157ce1a07261cad8a738d9e [file] [log] [blame]
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -08001/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#include <linux/slab.h>
15#include <soc/qcom/scm.h>
16#include "msm_vidc_internal.h"
17#include "msm_vidc_common.h"
18#include "vidc_hfi_api.h"
19#include "msm_vidc_debug.h"
20#include "msm_vidc_clocks.h"
21
22#define MSM_VDEC_DVC_NAME "msm_vdec_8974"
Praneeth Paladugu6e637472017-05-16 16:06:46 -070023#define MIN_NUM_THUMBNAIL_MODE_OUTPUT_BUFFERS MIN_NUM_OUTPUT_BUFFERS
Praneeth Paladugudefea4e2017-02-09 23:44:08 -080024#define MIN_NUM_THUMBNAIL_MODE_CAPTURE_BUFFERS MIN_NUM_CAPTURE_BUFFERS
Praneeth Paladugu6e637472017-05-16 16:06:46 -070025#define MIN_NUM_DEC_OUTPUT_BUFFERS 4
26#define MIN_NUM_DEC_CAPTURE_BUFFERS 4
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -080027#define DEFAULT_VIDEO_CONCEAL_COLOR_BLACK 0x8010
28#define MB_SIZE_IN_PIXEL (16 * 16)
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -080029#define OPERATING_FRAME_RATE_STEP (1 << 16)
30
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -080031static const char *const mpeg_video_stream_format[] = {
32 "NAL Format Start Codes",
33 "NAL Format One NAL Per Buffer",
34 "NAL Format One Byte Length",
35 "NAL Format Two Byte Length",
36 "NAL Format Four Byte Length",
37 NULL
38};
39static const char *const mpeg_video_output_order[] = {
40 "Display Order",
41 "Decode Order",
42 NULL
43};
44static const char *const mpeg_vidc_video_alloc_mode_type[] = {
45 "Buffer Allocation Static",
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -080046 "Buffer Allocation Dynamic Buffer"
47};
48
49static const char *const perf_level[] = {
50 "Nominal",
51 "Performance",
52 "Turbo"
53};
54
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -080055static const char *const vp8_profile_level[] = {
56 "Unused",
57 "0.0",
58 "1.0",
59 "2.0",
60 "3.0",
61};
62
63static const char *const mpeg2_profile[] = {
64 "Simple",
65 "Main",
66 "422",
67 "Snr Scalable",
68 "Spatial Scalable",
69 "High",
70};
71
72static const char *const mpeg2_level[] = {
73 "0",
74 "1",
75 "2",
76 "3",
77};
78static const char *const mpeg_vidc_video_entropy_mode[] = {
79 "CAVLC Entropy Mode",
80 "CABAC Entropy Mode",
81};
82
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -080083static const char *const mpeg_vidc_video_dpb_color_format[] = {
84 "DPB Color Format None",
85 "DPB Color Format UBWC",
86 "DPB Color Format UBWC TP10",
87};
88
89static struct msm_vidc_ctrl msm_vdec_ctrls[] = {
90 {
91 .id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_FORMAT,
92 .name = "NAL Format",
93 .type = V4L2_CTRL_TYPE_MENU,
94 .minimum = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_STARTCODES,
95 .maximum = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_FOUR_BYTE_LENGTH,
96 .default_value = V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_STARTCODES,
97 .menu_skip_mask = ~(
98 (1 << V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_STARTCODES) |
99 (1 << V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_ONE_NAL_PER_BUFFER) |
100 (1 << V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_ONE_BYTE_LENGTH) |
101 (1 << V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_TWO_BYTE_LENGTH) |
102 (1 << V4L2_MPEG_VIDC_VIDEO_NAL_FORMAT_FOUR_BYTE_LENGTH)
103 ),
104 .qmenu = mpeg_video_stream_format,
105 },
106 {
107 .id = V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER,
108 .name = "Output Order",
109 .type = V4L2_CTRL_TYPE_MENU,
110 .minimum = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DISPLAY,
111 .maximum = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DECODE,
112 .default_value = V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DISPLAY,
113 .menu_skip_mask = ~(
114 (1 << V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DISPLAY) |
115 (1 << V4L2_MPEG_VIDC_VIDEO_OUTPUT_ORDER_DECODE)
116 ),
117 .qmenu = mpeg_video_output_order,
118 },
119 {
120 .id = V4L2_CID_MPEG_VIDC_VIDEO_PICTYPE_DEC_MODE,
121 .name = "Picture Type Decoding",
122 .type = V4L2_CTRL_TYPE_BOOLEAN,
123 .minimum = 0,
124 .maximum = 1,
125 .default_value = 0,
126 .step = 1,
127 .menu_skip_mask = 0,
128 .qmenu = NULL,
129 },
130 {
131 .id = V4L2_CID_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE,
132 .name = "Sync Frame Decode",
133 .type = V4L2_CTRL_TYPE_BOOLEAN,
134 .minimum = V4L2_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE_DISABLE,
135 .maximum = V4L2_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE_ENABLE,
136 .default_value = V4L2_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE_DISABLE,
137 .step = 1,
138 },
139 {
140 .id = V4L2_CID_MPEG_VIDC_VIDEO_SECURE,
141 .name = "Secure mode",
142 .type = V4L2_CTRL_TYPE_BUTTON,
143 .minimum = 0,
144 .maximum = 0,
145 .default_value = 0,
146 .step = 0,
147 .menu_skip_mask = 0,
148 .qmenu = NULL,
149 },
150 {
151 .id = V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA,
152 .name = "Extradata Type",
153 .type = V4L2_CTRL_TYPE_MENU,
154 .minimum = V4L2_MPEG_VIDC_EXTRADATA_NONE,
155 .maximum = V4L2_MPEG_VIDC_EXTRADATA_VPX_COLORSPACE,
156 .default_value = V4L2_MPEG_VIDC_EXTRADATA_NONE,
157 .menu_skip_mask = ~(
158 (1 << V4L2_MPEG_VIDC_EXTRADATA_NONE) |
159 (1 << V4L2_MPEG_VIDC_EXTRADATA_MB_QUANTIZATION) |
160 (1 << V4L2_MPEG_VIDC_EXTRADATA_INTERLACE_VIDEO) |
161 (1 << V4L2_MPEG_VIDC_EXTRADATA_TIMESTAMP) |
162 (1 << V4L2_MPEG_VIDC_EXTRADATA_S3D_FRAME_PACKING) |
163 (1 << V4L2_MPEG_VIDC_EXTRADATA_FRAME_RATE) |
164 (1 << V4L2_MPEG_VIDC_EXTRADATA_PANSCAN_WINDOW) |
165 (1 << V4L2_MPEG_VIDC_EXTRADATA_RECOVERY_POINT_SEI) |
166 (1 << V4L2_MPEG_VIDC_EXTRADATA_MULTISLICE_INFO) |
167 (1 << V4L2_MPEG_VIDC_EXTRADATA_NUM_CONCEALED_MB) |
168 (1 << V4L2_MPEG_VIDC_EXTRADATA_METADATA_FILLER) |
169 (1 << V4L2_MPEG_VIDC_EXTRADATA_INPUT_CROP) |
170 (1 << V4L2_MPEG_VIDC_EXTRADATA_DIGITAL_ZOOM) |
171 (1 << V4L2_MPEG_VIDC_EXTRADATA_ASPECT_RATIO) |
172 (1 << V4L2_MPEG_VIDC_EXTRADATA_MPEG2_SEQDISP) |
173 (1 << V4L2_MPEG_VIDC_EXTRADATA_STREAM_USERDATA) |
174 (1 << V4L2_MPEG_VIDC_EXTRADATA_FRAME_QP) |
175 (1 << V4L2_MPEG_VIDC_EXTRADATA_FRAME_BITS_INFO) |
176 (1 << V4L2_MPEG_VIDC_EXTRADATA_VQZIP_SEI) |
177 (1 << V4L2_MPEG_VIDC_EXTRADATA_OUTPUT_CROP) |
178 (1 << V4L2_MPEG_VIDC_EXTRADATA_DISPLAY_COLOUR_SEI) |
179 (1 <<
180 V4L2_MPEG_VIDC_EXTRADATA_CONTENT_LIGHT_LEVEL_SEI) |
181 (1 << V4L2_MPEG_VIDC_EXTRADATA_VUI_DISPLAY) |
182 (1 << V4L2_MPEG_VIDC_EXTRADATA_VPX_COLORSPACE)
183 ),
184 .qmenu = mpeg_video_vidc_extradata,
185 },
186 {
187 .id = V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_MODE,
188 .name = "Video decoder multi stream",
189 .type = V4L2_CTRL_TYPE_BOOLEAN,
190 .minimum =
191 V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_PRIMARY,
192 .maximum =
193 V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_SECONDARY,
194 .default_value =
195 V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_PRIMARY,
196 .menu_skip_mask = 0,
197 .step = 1,
198 .qmenu = NULL,
199 },
200 {
201 .id = V4L2_CID_MPEG_VIDEO_H264_PROFILE,
202 .name = "H264 Profile",
203 .type = V4L2_CTRL_TYPE_MENU,
204 .maximum = V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_HIGH,
205 .default_value = V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE,
206 .menu_skip_mask = 0,
207 .flags = V4L2_CTRL_FLAG_VOLATILE,
208 .qmenu = NULL,
209 },
210 {
211 .id = V4L2_CID_MPEG_VIDEO_H264_LEVEL,
212 .name = "H264 Level",
213 .type = V4L2_CTRL_TYPE_MENU,
214 .maximum = V4L2_MPEG_VIDEO_H264_LEVEL_5_2,
215 .default_value = V4L2_MPEG_VIDEO_H264_LEVEL_1_0,
216 .menu_skip_mask = 0,
217 .flags = V4L2_CTRL_FLAG_VOLATILE,
218 .qmenu = NULL,
219 },
220 {
221 .id = V4L2_CID_MPEG_VIDC_VIDEO_VP8_PROFILE_LEVEL,
222 .name = "VP8 Profile Level",
223 .type = V4L2_CTRL_TYPE_MENU,
224 .minimum = V4L2_MPEG_VIDC_VIDEO_VP8_UNUSED,
Chinmay Sawarkar7f1cc152017-05-05 18:16:36 -0700225 .maximum = V4L2_MPEG_VIDC_VIDEO_VP8_VERSION_3,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800226 .default_value = V4L2_MPEG_VIDC_VIDEO_VP8_VERSION_0,
Chinmay Sawarkar7f1cc152017-05-05 18:16:36 -0700227 .menu_skip_mask = 0,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800228 .qmenu = vp8_profile_level,
229 .flags = V4L2_CTRL_FLAG_VOLATILE | V4L2_CTRL_FLAG_READ_ONLY,
230 },
231 {
232 .id = V4L2_CID_MPEG_VIDC_VIDEO_MPEG2_PROFILE,
233 .name = "MPEG2 Profile",
234 .type = V4L2_CTRL_TYPE_MENU,
235 .minimum = V4L2_MPEG_VIDC_VIDEO_MPEG2_PROFILE_SIMPLE,
236 .maximum = V4L2_MPEG_VIDC_VIDEO_MPEG2_PROFILE_HIGH,
237 .default_value = V4L2_MPEG_VIDC_VIDEO_MPEG2_PROFILE_SIMPLE,
238 .menu_skip_mask = ~(
239 (1 << V4L2_MPEG_VIDC_VIDEO_MPEG2_PROFILE_SIMPLE) |
240 (1 << V4L2_MPEG_VIDC_VIDEO_MPEG2_PROFILE_MAIN) |
241 (1 << V4L2_MPEG_VIDC_VIDEO_MPEG2_PROFILE_422) |
242 (1 << V4L2_MPEG_VIDC_VIDEO_MPEG2_PROFILE_SNR_SCALABLE) |
243 (1 << V4L2_MPEG_VIDC_VIDEO_MPEG2_PROFILE_SPATIAL_SCALABLE) |
244 (1 << V4L2_MPEG_VIDC_VIDEO_MPEG2_PROFILE_HIGH)
245 ),
246 .qmenu = mpeg2_profile,
247 .flags = V4L2_CTRL_FLAG_VOLATILE | V4L2_CTRL_FLAG_READ_ONLY,
248 },
249 {
250 .id = V4L2_CID_MPEG_VIDC_VIDEO_MPEG2_LEVEL,
251 .name = "MPEG2 Level",
252 .type = V4L2_CTRL_TYPE_MENU,
253 .minimum = V4L2_MPEG_VIDC_VIDEO_MPEG2_LEVEL_0,
254 .maximum = V4L2_MPEG_VIDC_VIDEO_MPEG2_LEVEL_3,
255 .default_value = V4L2_MPEG_VIDC_VIDEO_MPEG2_LEVEL_0,
256 .menu_skip_mask = ~(
257 (1 << V4L2_MPEG_VIDC_VIDEO_MPEG2_LEVEL_0) |
258 (1 << V4L2_MPEG_VIDC_VIDEO_MPEG2_LEVEL_1) |
259 (1 << V4L2_MPEG_VIDC_VIDEO_MPEG2_LEVEL_2) |
260 (1 << V4L2_MPEG_VIDC_VIDEO_MPEG2_LEVEL_3)
261 ),
262 .qmenu = mpeg2_level,
263 .flags = V4L2_CTRL_FLAG_VOLATILE | V4L2_CTRL_FLAG_READ_ONLY,
264 },
265 {
266 .id = V4L2_CID_MPEG_VIDC_VIDEO_CONCEAL_COLOR,
267 .name = "Picture concealed color",
268 .type = V4L2_CTRL_TYPE_INTEGER,
269 .minimum = 0x0,
270 .maximum = 0xffffff,
271 .default_value = DEFAULT_VIDEO_CONCEAL_COLOR_BLACK,
272 .step = 1,
273 },
274 {
275 .id = V4L2_CID_MPEG_VIDC_VIDEO_BUFFER_SIZE_LIMIT,
276 .name = "Buffer size limit",
277 .type = V4L2_CTRL_TYPE_INTEGER,
278 .minimum = 0,
279 .maximum = INT_MAX,
280 .default_value = 0,
281 .step = 1,
282 .menu_skip_mask = 0,
283 .qmenu = NULL,
284 },
285 {
Praneeth Paladugudefea4e2017-02-09 23:44:08 -0800286 .id = V4L2_CID_MIN_BUFFERS_FOR_CAPTURE,
287 .name = "CAPTURE Count",
288 .type = V4L2_CTRL_TYPE_INTEGER,
289 .minimum = MIN_NUM_CAPTURE_BUFFERS,
290 .maximum = MAX_NUM_CAPTURE_BUFFERS,
291 .default_value = MIN_NUM_CAPTURE_BUFFERS,
292 .step = 1,
293 .menu_skip_mask = 0,
294 .qmenu = NULL,
295 .flags = V4L2_CTRL_FLAG_VOLATILE,
296 },
297 {
298 .id = V4L2_CID_MIN_BUFFERS_FOR_OUTPUT,
299 .name = "OUTPUT Count",
300 .type = V4L2_CTRL_TYPE_INTEGER,
301 .minimum = MIN_NUM_OUTPUT_BUFFERS,
302 .maximum = MAX_NUM_OUTPUT_BUFFERS,
303 .default_value = MIN_NUM_OUTPUT_BUFFERS,
304 .step = 1,
305 .menu_skip_mask = 0,
306 .qmenu = NULL,
307 .flags = V4L2_CTRL_FLAG_VOLATILE,
308 },
309 {
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800310 .id = V4L2_CID_MPEG_VIDC_VIDEO_DPB_COLOR_FORMAT,
311 .name = "Video decoder dpb color format",
312 .type = V4L2_CTRL_TYPE_MENU,
313 .minimum = V4L2_MPEG_VIDC_VIDEO_DPB_COLOR_FMT_NONE,
314 .maximum = V4L2_MPEG_VIDC_VIDEO_DPB_COLOR_FMT_TP10_UBWC,
315 .default_value = V4L2_MPEG_VIDC_VIDEO_DPB_COLOR_FMT_NONE,
316 .menu_skip_mask = ~(
317 (1 << V4L2_MPEG_VIDC_VIDEO_DPB_COLOR_FMT_NONE) |
318 (1 << V4L2_MPEG_VIDC_VIDEO_DPB_COLOR_FMT_UBWC) |
319 (1 << V4L2_MPEG_VIDC_VIDEO_DPB_COLOR_FMT_TP10_UBWC)
320 ),
321 .qmenu = mpeg_vidc_video_dpb_color_format,
322 },
323 {
324 .id = V4L2_CID_VIDC_QBUF_MODE,
325 .name = "Allows batching of buffers for power savings",
326 .type = V4L2_CTRL_TYPE_BOOLEAN,
327 .minimum = V4L2_VIDC_QBUF_STANDARD,
328 .maximum = V4L2_VIDC_QBUF_BATCHED,
329 .default_value = V4L2_VIDC_QBUF_STANDARD,
330 .step = 1,
331 },
332 {
333 .id = V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE,
334 .name = "Entropy Mode",
335 .type = V4L2_CTRL_TYPE_MENU,
336 .minimum = V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC,
337 .maximum = V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC,
338 .default_value = V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC,
339 .step = 0,
340 .menu_skip_mask = ~(
341 (1 << V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC) |
342 (1 << V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC)
343 ),
344 .qmenu = mpeg_vidc_video_entropy_mode,
345 .flags = V4L2_CTRL_FLAG_VOLATILE | V4L2_CTRL_FLAG_READ_ONLY,
346 },
347 {
348 .id = V4L2_CID_MPEG_VIDC_VIDEO_PRIORITY,
349 .name = "Session Priority",
350 .type = V4L2_CTRL_TYPE_BOOLEAN,
351 .minimum = V4L2_MPEG_VIDC_VIDEO_PRIORITY_REALTIME_ENABLE,
352 .maximum = V4L2_MPEG_VIDC_VIDEO_PRIORITY_REALTIME_DISABLE,
353 .default_value = V4L2_MPEG_VIDC_VIDEO_PRIORITY_REALTIME_DISABLE,
354 .step = 1,
355 },
356 {
357 .id = V4L2_CID_MPEG_VIDC_VIDEO_OPERATING_RATE,
358 .name = "Set Decoder Operating rate",
359 .type = V4L2_CTRL_TYPE_INTEGER,
360 .minimum = 0,
Praneeth Paladugue5fd0872017-04-19 11:24:28 -0700361 .maximum = INT_MAX,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800362 .default_value = 0,
363 .step = OPERATING_FRAME_RATE_STEP,
364 },
365};
366
367#define NUM_CTRLS ARRAY_SIZE(msm_vdec_ctrls)
368
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800369static u32 get_frame_size_compressed_full_yuv(int plane,
370 u32 max_mbs_per_frame, u32 size_per_mb)
371{
372 return (max_mbs_per_frame * size_per_mb * 3 / 2);
373}
374
375static u32 get_frame_size_compressed(int plane,
376 u32 max_mbs_per_frame, u32 size_per_mb)
377{
378 return (max_mbs_per_frame * size_per_mb * 3/2)/2;
379}
380
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800381static u32 get_frame_size(struct msm_vidc_inst *inst,
382 const struct msm_vidc_format *fmt,
383 int fmt_type, int plane)
384{
385 u32 frame_size = 0;
386
387 if (fmt_type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
388 frame_size = fmt->get_frame_size(plane,
389 inst->capability.mbs_per_frame.max,
390 MB_SIZE_IN_PIXEL);
391 if (inst->buffer_size_limit &&
392 (inst->buffer_size_limit < frame_size)) {
393 frame_size = inst->buffer_size_limit;
394 dprintk(VIDC_DBG, "input buffer size limited to %d\n",
395 frame_size);
396 } else {
397 dprintk(VIDC_DBG, "set input buffer size to %d\n",
398 frame_size);
399 }
400 } else if (fmt_type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
401 frame_size = fmt->get_frame_size(plane,
402 inst->capability.height.max,
403 inst->capability.width.max);
404 dprintk(VIDC_DBG, "set output buffer size to %d\n",
405 frame_size);
406 } else {
407 dprintk(VIDC_WARN, "Wrong format type\n");
408 }
409 return frame_size;
410}
411
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800412struct msm_vidc_format vdec_formats[] = {
413 {
414 .name = "YCbCr Semiplanar 4:2:0",
415 .description = "Y/CbCr 4:2:0",
416 .fourcc = V4L2_PIX_FMT_NV12,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800417 .get_frame_size = get_frame_size_nv12,
418 .type = CAPTURE_PORT,
419 },
420 {
421 .name = "UBWC YCbCr Semiplanar 4:2:0",
422 .description = "UBWC Y/CbCr 4:2:0",
423 .fourcc = V4L2_PIX_FMT_NV12_UBWC,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800424 .get_frame_size = get_frame_size_nv12_ubwc,
425 .type = CAPTURE_PORT,
426 },
427 {
428 .name = "UBWC YCbCr Semiplanar 4:2:0 10bit",
429 .description = "UBWC Y/CbCr 4:2:0 10bit",
430 .fourcc = V4L2_PIX_FMT_NV12_TP10_UBWC,
Umesh Pandeyf2995f82017-05-01 16:44:45 -0700431 .get_frame_size = get_frame_size_tp10_ubwc,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800432 .type = CAPTURE_PORT,
433 },
434 {
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800435 .name = "Mpeg2",
436 .description = "Mpeg2 compressed format",
437 .fourcc = V4L2_PIX_FMT_MPEG2,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800438 .get_frame_size = get_frame_size_compressed,
439 .type = OUTPUT_PORT,
Vaibhav Deshu Venkatesh8c9b6db2017-02-08 11:22:36 -0800440 .defer_outputs = false,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800441 },
442 {
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800443 .name = "H264",
444 .description = "H264 compressed format",
445 .fourcc = V4L2_PIX_FMT_H264,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800446 .get_frame_size = get_frame_size_compressed,
447 .type = OUTPUT_PORT,
Vaibhav Deshu Venkatesh8c9b6db2017-02-08 11:22:36 -0800448 .defer_outputs = false,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800449 },
450 {
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800451 .name = "HEVC",
452 .description = "HEVC compressed format",
453 .fourcc = V4L2_PIX_FMT_HEVC,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800454 .get_frame_size = get_frame_size_compressed,
455 .type = OUTPUT_PORT,
Vaibhav Deshu Venkatesh8c9b6db2017-02-08 11:22:36 -0800456 .defer_outputs = false,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800457 },
458 {
459 .name = "VP8",
460 .description = "VP8 compressed format",
461 .fourcc = V4L2_PIX_FMT_VP8,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800462 .get_frame_size = get_frame_size_compressed,
463 .type = OUTPUT_PORT,
Vaibhav Deshu Venkatesh8c9b6db2017-02-08 11:22:36 -0800464 .defer_outputs = false,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800465 },
466 {
467 .name = "VP9",
468 .description = "VP9 compressed format",
469 .fourcc = V4L2_PIX_FMT_VP9,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800470 .get_frame_size = get_frame_size_compressed_full_yuv,
471 .type = OUTPUT_PORT,
Vaibhav Deshu Venkatesh8c9b6db2017-02-08 11:22:36 -0800472 .defer_outputs = true,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800473 },
474};
475
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800476int msm_vdec_s_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f)
477{
478 struct msm_vidc_format *fmt = NULL;
479 struct hal_frame_size frame_sz;
480 unsigned int extra_idx = 0;
481 int rc = 0;
482 int ret = 0;
483 int i;
484 int max_input_size = 0;
485
486 if (!inst || !f) {
487 dprintk(VIDC_ERR, "%s invalid parameters\n", __func__);
488 return -EINVAL;
489 }
490
491 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
492 fmt = msm_comm_get_pixel_fmt_fourcc(vdec_formats,
493 ARRAY_SIZE(vdec_formats), f->fmt.pix_mp.pixelformat,
494 CAPTURE_PORT);
495 if (!fmt || fmt->type != CAPTURE_PORT) {
496 dprintk(VIDC_ERR,
497 "Format: %d not supported on CAPTURE port\n",
498 f->fmt.pix_mp.pixelformat);
499 rc = -EINVAL;
500 goto err_invalid_fmt;
501 }
Praneeth Paladugudefea4e2017-02-09 23:44:08 -0800502
503 if (inst->fmts[fmt->type].fourcc == f->fmt.pix_mp.pixelformat &&
504 inst->prop.width[CAPTURE_PORT] == f->fmt.pix_mp.width &&
505 inst->prop.height[CAPTURE_PORT] ==
506 f->fmt.pix_mp.height) {
Praneeth Paladugu1f9d1d92017-04-11 10:36:16 -0700507 dprintk(VIDC_DBG, "No change in CAPTURE port params\n");
Praneeth Paladugudefea4e2017-02-09 23:44:08 -0800508 return 0;
509 }
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800510 memcpy(&inst->fmts[fmt->type], fmt,
511 sizeof(struct msm_vidc_format));
512
513 inst->prop.width[CAPTURE_PORT] = f->fmt.pix_mp.width;
514 inst->prop.height[CAPTURE_PORT] = f->fmt.pix_mp.height;
515 msm_comm_set_color_format(inst,
516 msm_comm_get_hal_output_buffer(inst),
517 f->fmt.pix_mp.pixelformat);
518
519 if (msm_comm_get_stream_output_mode(inst) ==
520 HAL_VIDEO_DECODER_SECONDARY) {
521 frame_sz.buffer_type = HAL_BUFFER_OUTPUT2;
522 frame_sz.width = inst->prop.width[CAPTURE_PORT];
523 frame_sz.height = inst->prop.height[CAPTURE_PORT];
524 dprintk(VIDC_DBG,
525 "buffer type = %d width = %d, height = %d\n",
526 frame_sz.buffer_type, frame_sz.width,
527 frame_sz.height);
528 ret = msm_comm_try_set_prop(inst,
529 HAL_PARAM_FRAME_SIZE, &frame_sz);
530 }
531
532 f->fmt.pix_mp.plane_fmt[0].sizeimage =
533 inst->fmts[fmt->type].get_frame_size(0,
534 f->fmt.pix_mp.height, f->fmt.pix_mp.width);
535
Praneeth Paladugudefea4e2017-02-09 23:44:08 -0800536 extra_idx = EXTRADATA_IDX(inst->bufq[fmt->type].num_planes);
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800537 if (extra_idx && extra_idx < VIDEO_MAX_PLANES) {
538 f->fmt.pix_mp.plane_fmt[extra_idx].sizeimage =
539 VENUS_EXTRADATA_SIZE(
540 inst->prop.height[CAPTURE_PORT],
541 inst->prop.width[CAPTURE_PORT]);
542 }
543
Praneeth Paladugudefea4e2017-02-09 23:44:08 -0800544 f->fmt.pix_mp.num_planes = inst->bufq[fmt->type].num_planes;
545 for (i = 0; i < inst->bufq[fmt->type].num_planes; i++) {
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800546 inst->bufq[CAPTURE_PORT].plane_sizes[i] =
547 f->fmt.pix_mp.plane_fmt[i].sizeimage;
548 }
Praneeth Paladugubdf4a2f2017-04-21 13:32:49 -0700549
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800550 } else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800551
552 fmt = msm_comm_get_pixel_fmt_fourcc(vdec_formats,
553 ARRAY_SIZE(vdec_formats),
554 f->fmt.pix_mp.pixelformat,
555 OUTPUT_PORT);
556 if (!fmt || fmt->type != OUTPUT_PORT) {
557 dprintk(VIDC_ERR,
558 "Format: %d not supported on OUTPUT port\n",
559 f->fmt.pix_mp.pixelformat);
560 rc = -EINVAL;
561 goto err_invalid_fmt;
562 }
563 memcpy(&inst->fmts[fmt->type], fmt,
564 sizeof(struct msm_vidc_format));
565
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800566 rc = msm_comm_try_state(inst, MSM_VIDC_OPEN_DONE);
567 if (rc) {
568 dprintk(VIDC_ERR, "Failed to open instance\n");
569 goto err_invalid_fmt;
570 }
571
Praneeth Paladugudefea4e2017-02-09 23:44:08 -0800572 if (inst->fmts[fmt->type].fourcc == f->fmt.pix_mp.pixelformat &&
573 inst->prop.width[OUTPUT_PORT] == f->fmt.pix_mp.width &&
574 inst->prop.height[OUTPUT_PORT] ==
575 f->fmt.pix_mp.height) {
Praneeth Paladugu1f9d1d92017-04-11 10:36:16 -0700576 dprintk(VIDC_DBG, "No change in OUTPUT port params\n");
Praneeth Paladugudefea4e2017-02-09 23:44:08 -0800577 return 0;
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800578 }
Praneeth Paladugudefea4e2017-02-09 23:44:08 -0800579 inst->prop.width[OUTPUT_PORT] = f->fmt.pix_mp.width;
580 inst->prop.height[OUTPUT_PORT] = f->fmt.pix_mp.height;
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800581
582 frame_sz.buffer_type = HAL_BUFFER_INPUT;
583 frame_sz.width = inst->prop.width[OUTPUT_PORT];
584 frame_sz.height = inst->prop.height[OUTPUT_PORT];
585 dprintk(VIDC_DBG,
586 "buffer type = %d width = %d, height = %d\n",
587 frame_sz.buffer_type, frame_sz.width,
588 frame_sz.height);
589 msm_comm_try_set_prop(inst, HAL_PARAM_FRAME_SIZE, &frame_sz);
590
591 max_input_size = get_frame_size(
Praneeth Paladugudefea4e2017-02-09 23:44:08 -0800592 inst, &inst->fmts[fmt->type], f->type, 0);
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800593 if (f->fmt.pix_mp.plane_fmt[0].sizeimage > max_input_size ||
594 !f->fmt.pix_mp.plane_fmt[0].sizeimage) {
595 f->fmt.pix_mp.plane_fmt[0].sizeimage = max_input_size;
596 }
597
Praneeth Paladugudefea4e2017-02-09 23:44:08 -0800598 f->fmt.pix_mp.num_planes = inst->bufq[fmt->type].num_planes;
599 for (i = 0; i < inst->bufq[fmt->type].num_planes; ++i) {
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800600 inst->bufq[OUTPUT_PORT].plane_sizes[i] =
601 f->fmt.pix_mp.plane_fmt[i].sizeimage;
602 }
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800603 }
604err_invalid_fmt:
605 return rc;
606}
607
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800608int msm_vdec_enum_fmt(struct msm_vidc_inst *inst, struct v4l2_fmtdesc *f)
609{
610 const struct msm_vidc_format *fmt = NULL;
611 int rc = 0;
612
613 if (!inst || !f) {
614 dprintk(VIDC_ERR,
615 "Invalid input, inst = %pK, f = %pK\n", inst, f);
616 return -EINVAL;
617 }
618 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
619 fmt = msm_comm_get_pixel_fmt_index(vdec_formats,
620 ARRAY_SIZE(vdec_formats), f->index, CAPTURE_PORT);
621 } else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
622 fmt = msm_comm_get_pixel_fmt_index(vdec_formats,
623 ARRAY_SIZE(vdec_formats), f->index, OUTPUT_PORT);
624 f->flags = V4L2_FMT_FLAG_COMPRESSED;
625 }
626
627 memset(f->reserved, 0, sizeof(f->reserved));
628 if (fmt) {
629 strlcpy(f->description, fmt->description,
630 sizeof(f->description));
631 f->pixelformat = fmt->fourcc;
632 } else {
633 dprintk(VIDC_DBG, "No more formats found\n");
634 rc = -EINVAL;
635 }
636 return rc;
637}
638
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800639int msm_vdec_inst_init(struct msm_vidc_inst *inst)
640{
641 int rc = 0;
Praneeth Paladugua6b6aa42017-05-16 13:33:01 -0700642 struct msm_vidc_format *fmt = NULL;
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800643
644 if (!inst) {
645 dprintk(VIDC_ERR, "Invalid input = %pK\n", inst);
646 return -EINVAL;
647 }
648 inst->prop.height[CAPTURE_PORT] = DEFAULT_HEIGHT;
649 inst->prop.width[CAPTURE_PORT] = DEFAULT_WIDTH;
650 inst->prop.height[OUTPUT_PORT] = DEFAULT_HEIGHT;
651 inst->prop.width[OUTPUT_PORT] = DEFAULT_WIDTH;
652 inst->capability.height.min = MIN_SUPPORTED_HEIGHT;
653 inst->capability.height.max = DEFAULT_HEIGHT;
654 inst->capability.width.min = MIN_SUPPORTED_WIDTH;
655 inst->capability.width.max = DEFAULT_WIDTH;
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800656 inst->capability.secure_output2_threshold.min = 0;
657 inst->capability.secure_output2_threshold.max = 0;
658 inst->buffer_mode_set[OUTPUT_PORT] = HAL_BUFFER_MODE_STATIC;
Chinmay Sawarkar2de3f772017-02-07 12:03:44 -0800659 inst->buffer_mode_set[CAPTURE_PORT] = HAL_BUFFER_MODE_DYNAMIC;
Praneeth Paladugudefea4e2017-02-09 23:44:08 -0800660 /* To start with, both ports are 1 plane each */
661 inst->bufq[OUTPUT_PORT].num_planes = 1;
662 inst->bufq[CAPTURE_PORT].num_planes = 1;
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800663 inst->prop.fps = DEFAULT_FPS;
Praneeth Paladugue5fd0872017-04-19 11:24:28 -0700664 inst->clk_data.operating_rate = 0;
Praneeth Paladugua6b6aa42017-05-16 13:33:01 -0700665
666 /* By default, initialize CAPTURE port to UBWC YUV format */
667 fmt = msm_comm_get_pixel_fmt_fourcc(vdec_formats,
668 ARRAY_SIZE(vdec_formats), V4L2_PIX_FMT_NV12_UBWC,
669 CAPTURE_PORT);
670 if (!fmt || fmt->type != CAPTURE_PORT) {
671 dprintk(VIDC_ERR,
672 "vdec_formats corrupted\n");
673 return -EINVAL;
674 }
675 memcpy(&inst->fmts[fmt->type], fmt,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800676 sizeof(struct msm_vidc_format));
Praneeth Paladugua6b6aa42017-05-16 13:33:01 -0700677
Praneeth Paladugu6e637472017-05-16 16:06:46 -0700678 inst->buff_req.buffer[1].buffer_type = HAL_BUFFER_INPUT;
679 inst->buff_req.buffer[1].buffer_count_min_host =
680 inst->buff_req.buffer[1].buffer_count_actual =
681 MIN_NUM_DEC_OUTPUT_BUFFERS;
682 inst->buff_req.buffer[2].buffer_type = HAL_BUFFER_OUTPUT;
683 inst->buff_req.buffer[2].buffer_count_min_host =
684 inst->buff_req.buffer[2].buffer_count_actual =
685 MIN_NUM_DEC_CAPTURE_BUFFERS;
686 inst->buff_req.buffer[3].buffer_type = HAL_BUFFER_OUTPUT2;
687 inst->buff_req.buffer[3].buffer_count_min_host =
688 inst->buff_req.buffer[3].buffer_count_actual =
689 MIN_NUM_DEC_CAPTURE_BUFFERS;
690
Praneeth Paladugua6b6aa42017-05-16 13:33:01 -0700691 /* By default, initialize OUTPUT port to H264 decoder */
692 fmt = msm_comm_get_pixel_fmt_fourcc(vdec_formats,
693 ARRAY_SIZE(vdec_formats), V4L2_PIX_FMT_H264,
694 OUTPUT_PORT);
695 if (!fmt || fmt->type != OUTPUT_PORT) {
696 dprintk(VIDC_ERR,
697 "vdec_formats corrupted\n");
698 return -EINVAL;
699 }
700 memcpy(&inst->fmts[fmt->type], fmt,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800701 sizeof(struct msm_vidc_format));
Praneeth Paladugua6b6aa42017-05-16 13:33:01 -0700702
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800703 return rc;
704}
705
Praneeth Paladugube42cb22016-04-12 22:34:39 -0700706static struct v4l2_ctrl *get_ctrl_from_cluster(int id,
707 struct v4l2_ctrl **cluster, int ncontrols)
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800708{
Praneeth Paladugube42cb22016-04-12 22:34:39 -0700709 int c;
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800710
Praneeth Paladugube42cb22016-04-12 22:34:39 -0700711 for (c = 0; c < ncontrols; ++c)
712 if (cluster[c]->id == id)
713 return cluster[c];
714 return NULL;
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800715}
716
Praneeth Paladugube42cb22016-04-12 22:34:39 -0700717int msm_vdec_s_ctrl(struct msm_vidc_inst *inst, struct v4l2_ctrl *ctrl)
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800718{
719 int rc = 0;
720 struct hal_nal_stream_format_supported stream_format;
721 struct hal_enable_picture enable_picture;
722 struct hal_enable hal_property;
723 enum hal_property property_id = 0;
724 u32 property_val = 0;
725 void *pdata = NULL;
726 struct hfi_device *hdev;
727 struct hal_extradata_enable extra;
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800728 struct hal_multi_stream multi_stream;
729 struct v4l2_ctrl *temp_ctrl = NULL;
730 struct hal_profile_level profile_level;
731 struct hal_frame_size frame_sz;
Praneeth Paladugu6e637472017-05-16 16:06:46 -0700732 struct hal_buffer_requirements *bufreq;
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800733
734 if (!inst || !inst->core || !inst->core->device) {
735 dprintk(VIDC_ERR, "%s invalid parameters\n", __func__);
736 return -EINVAL;
737 }
738 hdev = inst->core->device;
739
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800740 /* Small helper macro for quickly getting a control and err checking */
741#define TRY_GET_CTRL(__ctrl_id) ({ \
742 struct v4l2_ctrl *__temp; \
743 __temp = get_ctrl_from_cluster( \
744 __ctrl_id, \
745 ctrl->cluster, ctrl->ncontrols); \
746 if (!__temp) { \
747 dprintk(VIDC_ERR, "Can't find %s (%x) in cluster\n", \
748 #__ctrl_id, __ctrl_id); \
749 /* Clusters are hardcoded, if we can't find */ \
750 /* something then things are massively screwed up */ \
751 MSM_VIDC_ERROR(1); \
752 } \
753 __temp; \
754 })
755
756 v4l2_ctrl_unlock(ctrl);
757
758 switch (ctrl->id) {
759 case V4L2_CID_MPEG_VIDC_VIDEO_STREAM_FORMAT:
760 property_id = HAL_PARAM_NAL_STREAM_FORMAT_SELECT;
761 stream_format.nal_stream_format_supported = BIT(ctrl->val);
762 pdata = &stream_format;
763 break;
764 case V4L2_CID_MPEG_VIDC_VIDEO_OUTPUT_ORDER:
765 property_id = HAL_PARAM_VDEC_OUTPUT_ORDER;
766 property_val = ctrl->val;
767 pdata = &property_val;
768 break;
769 case V4L2_CID_MPEG_VIDC_VIDEO_PICTYPE_DEC_MODE:
770 property_id = HAL_PARAM_VDEC_PICTURE_TYPE_DECODE;
771 if (ctrl->val ==
772 V4L2_MPEG_VIDC_VIDEO_PICTYPE_DECODE_ON)
773 enable_picture.picture_type = HAL_PICTURE_I;
774 else
775 enable_picture.picture_type = HAL_PICTURE_I |
776 HAL_PICTURE_P | HAL_PICTURE_B |
777 HAL_PICTURE_IDR;
778 pdata = &enable_picture;
779 break;
780 case V4L2_CID_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE:
781 switch (ctrl->val) {
782 case V4L2_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE_DISABLE:
783 inst->flags &= ~VIDC_THUMBNAIL;
784 break;
785 case V4L2_MPEG_VIDC_VIDEO_SYNC_FRAME_DECODE_ENABLE:
786 inst->flags |= VIDC_THUMBNAIL;
787 break;
788 }
789
790 property_id = HAL_PARAM_VDEC_SYNC_FRAME_DECODE;
791 hal_property.enable = ctrl->val;
792 pdata = &hal_property;
Praneeth Paladugu75cf18e2016-12-08 16:12:11 -0800793 msm_dcvs_try_enable(inst);
Praneeth Paladugu6e637472017-05-16 16:06:46 -0700794
795 bufreq = get_buff_req_buffer(inst,
796 HAL_BUFFER_INPUT);
797 if (!bufreq) {
798 dprintk(VIDC_ERR,
799 "Failed : No buffer requirements : %x\n",
800 HAL_BUFFER_OUTPUT);
801 return -EINVAL;
802 }
803 bufreq->buffer_count_min =
804 MIN_NUM_THUMBNAIL_MODE_OUTPUT_BUFFERS;
805
806 if (msm_comm_get_stream_output_mode(inst) ==
807 HAL_VIDEO_DECODER_SECONDARY) {
808
809 bufreq = get_buff_req_buffer(inst,
810 HAL_BUFFER_OUTPUT);
811 if (!bufreq) {
812 dprintk(VIDC_ERR,
813 "Failed : No buffer requirements: %x\n",
814 HAL_BUFFER_OUTPUT);
815 return -EINVAL;
816 }
817
818 bufreq->buffer_count_min =
819 MIN_NUM_THUMBNAIL_MODE_CAPTURE_BUFFERS;
820
821 bufreq = get_buff_req_buffer(inst,
822 HAL_BUFFER_OUTPUT2);
823 if (!bufreq) {
824 dprintk(VIDC_ERR,
825 "Failed : No buffer requirements: %x\n",
826 HAL_BUFFER_OUTPUT2);
827 return -EINVAL;
828 }
829
830 bufreq->buffer_count_min =
831 MIN_NUM_THUMBNAIL_MODE_CAPTURE_BUFFERS;
832 } else {
833
834 bufreq = get_buff_req_buffer(inst,
835 HAL_BUFFER_OUTPUT);
836 if (!bufreq) {
837 dprintk(VIDC_ERR,
838 "Failed : No buffer requirements: %x\n",
839 HAL_BUFFER_OUTPUT);
840 return -EINVAL;
841 }
842 bufreq->buffer_count_min =
843 MIN_NUM_THUMBNAIL_MODE_CAPTURE_BUFFERS;
844
845 }
846
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800847 break;
848 case V4L2_CID_MPEG_VIDC_VIDEO_SECURE:
Karthikeyan Periasamya0e4bad2017-04-26 12:51:10 -0700849 property_id = HAL_PARAM_SECURE;
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800850 inst->flags |= VIDC_SECURE;
Karthikeyan Periasamya0e4bad2017-04-26 12:51:10 -0700851 property_val = !!(inst->flags & VIDC_SECURE);
852 pdata = &property_val;
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800853 dprintk(VIDC_DBG, "Setting secure mode to: %d\n",
854 !!(inst->flags & VIDC_SECURE));
855 break;
856 case V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA:
857 property_id = HAL_PARAM_INDEX_EXTRADATA;
858 extra.index = msm_comm_get_hal_extradata_index(ctrl->val);
Praneeth Paladugudefea4e2017-02-09 23:44:08 -0800859 switch (ctrl->val) {
860 case V4L2_MPEG_VIDC_EXTRADATA_MB_QUANTIZATION:
861 case V4L2_MPEG_VIDC_EXTRADATA_INTERLACE_VIDEO:
862 case V4L2_MPEG_VIDC_EXTRADATA_TIMESTAMP:
863 case V4L2_MPEG_VIDC_EXTRADATA_S3D_FRAME_PACKING:
864 case V4L2_MPEG_VIDC_EXTRADATA_FRAME_RATE:
865 case V4L2_MPEG_VIDC_EXTRADATA_PANSCAN_WINDOW:
866 case V4L2_MPEG_VIDC_EXTRADATA_RECOVERY_POINT_SEI:
867 case V4L2_MPEG_VIDC_EXTRADATA_NUM_CONCEALED_MB:
868 case V4L2_MPEG_VIDC_EXTRADATA_ASPECT_RATIO:
869 case V4L2_MPEG_VIDC_EXTRADATA_MPEG2_SEQDISP:
870 case V4L2_MPEG_VIDC_EXTRADATA_STREAM_USERDATA:
871 case V4L2_MPEG_VIDC_EXTRADATA_FRAME_QP:
872 case V4L2_MPEG_VIDC_EXTRADATA_FRAME_BITS_INFO:
873 case V4L2_MPEG_VIDC_EXTRADATA_VQZIP_SEI:
874 case V4L2_MPEG_VIDC_EXTRADATA_OUTPUT_CROP:
875 case V4L2_MPEG_VIDC_EXTRADATA_DISPLAY_COLOUR_SEI:
876 case V4L2_MPEG_VIDC_EXTRADATA_CONTENT_LIGHT_LEVEL_SEI:
877 case V4L2_MPEG_VIDC_EXTRADATA_VUI_DISPLAY:
878 case V4L2_MPEG_VIDC_EXTRADATA_VPX_COLORSPACE:
879 inst->bufq[CAPTURE_PORT].num_planes = 2;
880 inst->bufq[CAPTURE_PORT].plane_sizes[EXTRADATA_IDX(2)] =
881 VENUS_EXTRADATA_SIZE(
882 inst->prop.height[CAPTURE_PORT],
883 inst->prop.width[CAPTURE_PORT]);
884 break;
885 default:
886 rc = -ENOTSUPP;
887 break;
888 }
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800889 extra.enable = 1;
890 pdata = &extra;
891 break;
892 case V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_MODE:
893 if (ctrl->val && !(inst->capability.pixelprocess_capabilities &
894 HAL_VIDEO_DECODER_MULTI_STREAM_CAPABILITY)) {
895 dprintk(VIDC_ERR, "Downscaling not supported: %#x\n",
896 ctrl->id);
897 rc = -ENOTSUPP;
898 break;
899 }
900 switch (ctrl->val) {
901 case V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_PRIMARY:
902 multi_stream.buffer_type = HAL_BUFFER_OUTPUT;
903 multi_stream.enable = true;
904 pdata = &multi_stream;
905 rc = call_hfi_op(hdev, session_set_property, (void *)
906 inst->session, HAL_PARAM_VDEC_MULTI_STREAM,
907 pdata);
908 if (rc) {
909 dprintk(VIDC_ERR,
910 "Failed : Enabling OUTPUT port : %d\n",
911 rc);
912 break;
913 }
914 multi_stream.buffer_type = HAL_BUFFER_OUTPUT2;
915 multi_stream.enable = false;
916 pdata = &multi_stream;
917 rc = call_hfi_op(hdev, session_set_property, (void *)
918 inst->session, HAL_PARAM_VDEC_MULTI_STREAM,
919 pdata);
920 if (rc)
921 dprintk(VIDC_ERR,
922 "Failed:Disabling OUTPUT2 port : %d\n",
923 rc);
924 break;
925 case V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_SECONDARY:
926 multi_stream.buffer_type = HAL_BUFFER_OUTPUT2;
927 multi_stream.enable = true;
928 pdata = &multi_stream;
929 rc = call_hfi_op(hdev, session_set_property, (void *)
930 inst->session, HAL_PARAM_VDEC_MULTI_STREAM,
931 pdata);
932 if (rc) {
933 dprintk(VIDC_ERR,
934 "Failed :Enabling OUTPUT2 port : %d\n",
935 rc);
936 break;
937 }
938 multi_stream.buffer_type = HAL_BUFFER_OUTPUT;
939 multi_stream.enable = false;
940 pdata = &multi_stream;
941 rc = call_hfi_op(hdev, session_set_property, (void *)
942 inst->session, HAL_PARAM_VDEC_MULTI_STREAM,
943 pdata);
944 if (rc) {
945 dprintk(VIDC_ERR,
946 "Failed disabling OUTPUT port : %d\n",
947 rc);
948 break;
949 }
950
951 frame_sz.buffer_type = HAL_BUFFER_OUTPUT2;
952 frame_sz.width = inst->prop.width[CAPTURE_PORT];
953 frame_sz.height = inst->prop.height[CAPTURE_PORT];
954 pdata = &frame_sz;
955 dprintk(VIDC_DBG,
956 "buffer type = %d width = %d, height = %d\n",
957 frame_sz.buffer_type, frame_sz.width,
958 frame_sz.height);
959 rc = call_hfi_op(hdev, session_set_property, (void *)
960 inst->session, HAL_PARAM_FRAME_SIZE, pdata);
961 if (rc)
962 dprintk(VIDC_ERR,
963 "Failed setting OUTPUT2 size : %d\n",
964 rc);
965
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800966 break;
967 default:
968 dprintk(VIDC_ERR,
969 "Failed : Unsupported multi stream setting\n");
970 rc = -ENOTSUPP;
971 break;
972 }
973 break;
974 case V4L2_CID_MPEG_VIDC_VIDEO_CONCEAL_COLOR:
975 property_id = HAL_PARAM_VDEC_CONCEAL_COLOR;
976 property_val = ctrl->val;
977 pdata = &property_val;
978 break;
979 case V4L2_CID_MPEG_VIDEO_H264_PROFILE:
980 temp_ctrl = TRY_GET_CTRL(V4L2_CID_MPEG_VIDEO_H264_LEVEL);
981 property_id =
982 HAL_PARAM_PROFILE_LEVEL_CURRENT;
Chinmay Sawarkarb3c6ccb2017-02-23 18:01:32 -0800983 profile_level.profile = msm_comm_v4l2_to_hal(ctrl->id,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800984 ctrl->val);
Chinmay Sawarkarb3c6ccb2017-02-23 18:01:32 -0800985 profile_level.level = msm_comm_v4l2_to_hal(
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800986 V4L2_CID_MPEG_VIDEO_H264_LEVEL,
987 temp_ctrl->val);
988 pdata = &profile_level;
989 break;
990 case V4L2_CID_MPEG_VIDEO_H264_LEVEL:
991 temp_ctrl = TRY_GET_CTRL(V4L2_CID_MPEG_VIDEO_H264_PROFILE);
992 property_id =
993 HAL_PARAM_PROFILE_LEVEL_CURRENT;
Chinmay Sawarkarb3c6ccb2017-02-23 18:01:32 -0800994 profile_level.level = msm_comm_v4l2_to_hal(ctrl->id,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800995 ctrl->val);
Chinmay Sawarkarb3c6ccb2017-02-23 18:01:32 -0800996 profile_level.profile = msm_comm_v4l2_to_hal(
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800997 V4L2_CID_MPEG_VIDEO_H264_PROFILE,
998 temp_ctrl->val);
999 pdata = &profile_level;
1000 break;
1001 case V4L2_CID_MPEG_VIDC_VIDEO_BUFFER_SIZE_LIMIT:
1002 dprintk(VIDC_DBG,
1003 "Limiting input buffer size from %u to %u\n",
1004 inst->buffer_size_limit, ctrl->val);
1005 inst->buffer_size_limit = ctrl->val;
1006 break;
1007 case V4L2_CID_VIDC_QBUF_MODE:
1008 property_id = HAL_PARAM_SYNC_BASED_INTERRUPT;
1009 hal_property.enable = ctrl->val == V4L2_VIDC_QBUF_BATCHED;
1010 pdata = &hal_property;
1011 break;
1012 case V4L2_CID_MPEG_VIDC_VIDEO_PRIORITY:
1013 property_id = HAL_CONFIG_REALTIME;
1014 /* firmware has inverted values for realtime and
1015 * non-realtime priority
1016 */
1017 hal_property.enable = !(ctrl->val);
1018 pdata = &hal_property;
1019 switch (ctrl->val) {
1020 case V4L2_MPEG_VIDC_VIDEO_PRIORITY_REALTIME_DISABLE:
1021 inst->flags &= ~VIDC_REALTIME;
1022 break;
1023 case V4L2_MPEG_VIDC_VIDEO_PRIORITY_REALTIME_ENABLE:
1024 inst->flags |= VIDC_REALTIME;
1025 break;
1026 default:
1027 dprintk(VIDC_WARN,
1028 "inst(%pK) invalid priority ctrl value %#x\n",
1029 inst, ctrl->val);
1030 break;
1031 }
1032 break;
1033 case V4L2_CID_MPEG_VIDC_VIDEO_OPERATING_RATE:
1034 dprintk(VIDC_DBG,
1035 "inst(%pK) operating rate changed from %d to %d\n",
Praneeth Paladugue5fd0872017-04-19 11:24:28 -07001036 inst, inst->clk_data.operating_rate >> 16,
1037 ctrl->val >> 16);
1038 inst->clk_data.operating_rate = ctrl->val;
1039
1040 msm_vidc_update_operating_rate(inst);
1041
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -08001042 break;
1043 default:
1044 break;
1045 }
1046
1047 v4l2_ctrl_lock(ctrl);
1048#undef TRY_GET_CTRL
1049
1050 if (!rc && property_id) {
1051 dprintk(VIDC_DBG,
Praneeth Paladugu92fc3b02017-05-02 15:35:17 -07001052 "Control: Name = %s, ID = 0x%x Value = %d\n",
1053 ctrl->name, ctrl->id, ctrl->val);
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -08001054 rc = call_hfi_op(hdev, session_set_property, (void *)
1055 inst->session, property_id, pdata);
1056 }
1057
1058 return rc;
1059}
1060
Praneeth Paladugube42cb22016-04-12 22:34:39 -07001061int msm_vdec_s_ext_ctrl(struct msm_vidc_inst *inst,
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -08001062 struct v4l2_ext_controls *ctrl)
1063{
1064 int rc = 0, i = 0, fourcc = 0;
1065 struct v4l2_ext_control *ext_control;
1066 struct v4l2_control control;
1067
1068 if (!inst || !inst->core || !ctrl) {
1069 dprintk(VIDC_ERR,
1070 "%s invalid parameters\n", __func__);
1071 return -EINVAL;
1072 }
1073
1074 ext_control = ctrl->controls;
1075 control.id =
1076 V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_MODE;
1077
1078 for (i = 0; i < ctrl->count; i++) {
1079 switch (ext_control[i].id) {
1080 case V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_MODE:
1081 control.value = ext_control[i].value;
1082
1083 rc = msm_comm_s_ctrl(inst, &control);
1084 if (rc)
1085 dprintk(VIDC_ERR,
1086 "%s Failed setting stream output mode : %d\n",
1087 __func__, rc);
1088 break;
1089 case V4L2_CID_MPEG_VIDC_VIDEO_DPB_COLOR_FORMAT:
1090 switch (ext_control[i].value) {
1091 case V4L2_MPEG_VIDC_VIDEO_DPB_COLOR_FMT_NONE:
1092 if (!msm_comm_g_ctrl_for_id(inst, control.id)) {
1093 rc = msm_comm_release_output_buffers(
Vaibhav Deshu Venkatesh8c9b6db2017-02-08 11:22:36 -08001094 inst, false);
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -08001095 if (rc)
1096 dprintk(VIDC_ERR,
1097 "%s Release output buffers failed\n",
1098 __func__);
1099 }
1100 break;
1101 case V4L2_MPEG_VIDC_VIDEO_DPB_COLOR_FMT_UBWC:
1102 case V4L2_MPEG_VIDC_VIDEO_DPB_COLOR_FMT_TP10_UBWC:
1103 if (ext_control[i].value ==
1104 V4L2_MPEG_VIDC_VIDEO_DPB_COLOR_FMT_UBWC)
1105 fourcc = V4L2_PIX_FMT_NV12_UBWC;
1106 else
1107 fourcc = V4L2_PIX_FMT_NV12_TP10_UBWC;
1108 if (msm_comm_g_ctrl_for_id(inst, control.id)) {
1109 rc = msm_comm_set_color_format(inst,
1110 HAL_BUFFER_OUTPUT, fourcc);
1111 if (rc) {
1112 dprintk(VIDC_ERR,
1113 "%s Failed setting output color format : %d\n",
1114 __func__, rc);
1115 break;
1116 }
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -08001117 }
1118 break;
1119 default:
1120 dprintk(VIDC_ERR,
1121 "%s Unsupported output color format\n",
1122 __func__);
1123 rc = -ENOTSUPP;
1124 break;
1125 }
1126 break;
1127 default:
1128 dprintk(VIDC_ERR
1129 , "%s Unsupported set control %d",
1130 __func__, ext_control[i].id);
1131 rc = -ENOTSUPP;
1132 break;
1133 }
1134 }
1135
1136 return rc;
1137}
1138
Praneeth Paladugube42cb22016-04-12 22:34:39 -07001139int msm_vdec_ctrl_init(struct msm_vidc_inst *inst,
1140 const struct v4l2_ctrl_ops *ctrl_ops)
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -08001141{
1142 return msm_comm_ctrl_init(inst, msm_vdec_ctrls,
Praneeth Paladugube42cb22016-04-12 22:34:39 -07001143 ARRAY_SIZE(msm_vdec_ctrls), ctrl_ops);
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -08001144}