blob: 217ce51c17a64aedd348109a8306646961d3c75f [file] [log] [blame]
codeworkx62f02ba2012-05-20 12:00:36 +02001/*
2 * Copyright@ Samsung Electronics Co. LTD
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//#define LOG_NDEBUG 0
18//#define LOG_TAG "libhdmi"
19#include <cutils/log.h>
20
21#include <sys/types.h>
22#include <sys/stat.h>
23#include <sys/ioctl.h>
24#include <sys/mman.h>
25#include <fcntl.h>
26#include <ctype.h>
27#include <unistd.h>
28#include <string.h>
29#include <errno.h>
30#include <signal.h>
31
32#if defined(BOARD_USE_V4L2)
33#include "sec_utils_v4l2.h"
34#include "s5p_tvout_v4l2.h"
35#include "videodev2.h"
36#else
37#include "sec_utils.h"
38#include "s5p_tvout.h"
39#endif
40#include "SecFimc.h"
41#if defined(BOARD_USES_FIMGAPI)
42#include "sec_g2d_4x.h"
43#include "FimgApi.h"
44#endif
45
46#include "audio.h"
47#include "video.h"
48#include "../libhdmi/libsForhdmi/libedid/libedid.h"
49#include "../libhdmi/libsForhdmi/libcec/libcec.h"
50
51#include "SecHdmiCommon.h"
52#include "SecHdmiV4L2Utils.h"
53
54namespace android {
55
56unsigned int output_type = V4L2_OUTPUT_TYPE_DIGITAL;
57#if defined(BOARD_USE_V4L2)
58unsigned int g_preset_id = V4L2_DV_1080P30;
59#endif
60v4l2_std_id t_std_id = V4L2_STD_1080P_30;
61int g_hpd_state = HPD_CABLE_OUT;
62unsigned int g_hdcp_en = 0;
63
64int fp_tvout = -1;
65int fp_tvout_v = -1;
66int fp_tvout_g0 = -1;
67int fp_tvout_g1 = -1;
68
69struct vid_overlay_param vo_param;
70
71#if defined(BOARD_USES_FIMGAPI)
72unsigned int g2d_reserved_memory[HDMI_G2D_OUTPUT_BUF_NUM];
73unsigned int g2d_reserved_memory_size = 0;
74unsigned int cur_g2d_address = 0;
75unsigned int g2d_buf_index = 0;
76#endif
77
78void display_menu(void)
79{
80 struct HDMIVideoParameter video;
81 struct HDMIAudioParameter audio;
82
83#ifdef DEBUG_HDMI_HW_LEVEL
84 LOGD("%s", __func__);
85#endif
86
87 audio.formatCode = LPCM_FORMAT;
88 audio.outPacket = HDMI_ASP;
89 audio.channelNum = CH_2;
90 audio.sampleFreq = SF_44KHZ;
91
92 LOGI("=============== HDMI Audio =============\n");
93
94 if (EDIDAudioModeSupport(&audio))
95 LOGI("= 2CH_PCM 44100Hz audio supported =\n");
96
97 LOGI("========= HDMI Mode & Color Space =======\n");
98
99 video.mode = HDMI;
100 if (EDIDHDMIModeSupport(&video)) {
101 video.colorSpace = HDMI_CS_YCBCR444;
102 if (EDIDColorSpaceSupport(&video))
103 LOGI("= 1. HDMI(YCbCr) =\n");
104
105 video.colorSpace = HDMI_CS_RGB;
106 if (EDIDColorSpaceSupport(&video))
107 LOGI("= 2. HDMI(RGB) =\n");
108 } else {
109 video.mode = DVI;
110 if (EDIDHDMIModeSupport(&video))
111 LOGI("= 3. DVI =\n");
112 }
113
114 LOGI("=========== HDMI Rseolution ========\n");
115
116 /* 480P */
117 video.resolution = v720x480p_60Hz;
118 video.pixelAspectRatio = HDMI_PIXEL_RATIO_16_9;
119 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
120 if (EDIDVideoResolutionSupport(&video))
121 LOGI("= 4. 480P_60_16_9 (0x04000000) =\n");
122
123 video.resolution = v640x480p_60Hz;
124 video.pixelAspectRatio = HDMI_PIXEL_RATIO_4_3;
125 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
126 if (EDIDVideoResolutionSupport(&video))
127 LOGI("= 5. 480P_60_4_3 (0x05000000) =\n");
128
129 /* 576P */
130 video.resolution = v720x576p_50Hz;
131 video.pixelAspectRatio = HDMI_PIXEL_RATIO_16_9;
132 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
133 if (EDIDVideoResolutionSupport(&video))
134 LOGI("= 6. 576P_50_16_9 (0x06000000) =\n");
135
136 video.pixelAspectRatio = HDMI_PIXEL_RATIO_4_3;
137 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
138 if (EDIDVideoResolutionSupport(&video))
139 LOGI("= 7. 576P_50_4_3 (0x07000000) =\n");
140
141 /* 720P 60 */
142 video.resolution = v1280x720p_60Hz;
143 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
144 if (EDIDVideoResolutionSupport(&video))
145 LOGI("= 8. 720P_60 (0x08000000) =\n");
146
147 /* 720P_50 */
148 video.resolution = v1280x720p_50Hz;
149 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
150 if (EDIDVideoResolutionSupport(&video))
151 LOGI("= 9. 720P_50 (0x09000000) =\n");
152
153 /* 1080P_60 */
154 video.resolution = v1920x1080p_60Hz;
155 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
156 if (EDIDVideoResolutionSupport(&video))
157 LOGI("= a. 1080P_60 (0x0a000000) =\n");
158
159 /* 1080P_50 */
160 video.resolution = v1920x1080p_50Hz;
161 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
162 if (EDIDVideoResolutionSupport(&video))
163 LOGI("= b. 1080P_50 (0x0b000000) =\n");
164
165 /* 1080I_60 */
166 video.resolution = v1920x1080i_60Hz;
167 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
168 if (EDIDVideoResolutionSupport(&video))
169 LOGI("= c. 1080I_60 (0x0c000000) =\n");
170
171 /* 1080I_50 */
172 video.resolution = v1920x1080i_50Hz;
173 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
174 if (EDIDVideoResolutionSupport(&video))
175 LOGI("= d. 1080I_50 (0x0d000000) =\n");
176
177 /* 1080P_30 */
178 video.resolution = v1920x1080p_30Hz;
179 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
180 if (EDIDVideoResolutionSupport(&video))
181 LOGI("= e. 1080P_30 (0x12000000) =\n");
182
183 LOGI("=========== HDMI 3D Format ========\n");
184
185 /* 720P_60_SBS_HALF */
186 video.resolution = v1280x720p_60Hz;
187 video.hdmi_3d_format = HDMI_3D_SSH_FORMAT;
188 if (EDIDVideoResolutionSupport(&video))
189 LOGI("= f. 720P_60_SBS_HALF (0x13000000) =\n");
190
191 /* 720P_59_SBS_HALF */
192 video.resolution = v1280x720p_60Hz;
193 video.hdmi_3d_format = HDMI_3D_SSH_FORMAT;
194 if (EDIDVideoResolutionSupport(&video))
195 LOGI("= 10. 720P_59_SBS_HALF (0x14000000) =\n");
196
197 /* 720P_50_TB */
198 video.resolution = v1280x720p_50Hz;
199 video.hdmi_3d_format = HDMI_3D_TB_FORMAT;
200 if (EDIDVideoResolutionSupport(&video))
201 LOGI("= 11. 720P_50_TB (0x15000000) =\n");
202
203 /* 1080P_24_TB */
204 video.resolution = v1920x1080p_24Hz;
205 video.hdmi_3d_format = HDMI_3D_TB_FORMAT;
206 if (EDIDVideoResolutionSupport(&video))
207 LOGI("= 12. 1080P_24_TB (0x16000000) =\n");
208
209 /* 1080P_23_TB */
210 video.resolution = v1920x1080p_24Hz;
211 video.hdmi_3d_format = HDMI_3D_TB_FORMAT;
212 if (EDIDVideoResolutionSupport(&video))
213 LOGI("= 13. 1080P_24_TB (0x17000000) =\n");
214 LOGI("=========================================\n");
215}
216
217int tvout_open(const char *fp_name)
218{
219#ifdef DEBUG_HDMI_HW_LEVEL
220 LOGD("%s", __func__);
221#endif
222
223 int fp;
224
225 fp = open(fp_name, O_RDWR);
226 if (fp < 0)
227 LOGE("drv (%s) open failed!!\n", fp_name);
228
229 return fp;
230}
231#if defined(BOARD_USE_V4L2)
232int tvout_std_v4l2_init(int fd, unsigned int preset_id)
233{
234#ifdef DEBUG_HDMI_HW_LEVEL
235 LOGD("%s:: preset_id = 0x%x", __func__, preset_id);
236#endif
237
238 int ret;
239 struct v4l2_output output;
240 struct v4l2_dv_preset preset;
241
242 unsigned int matched = 0, i = 0;
243 int output_index;
244
245/*
246 if (output_type >= V4L2_OUTPUT_TYPE_DIGITAL &&
247 output_type <= V4L2_OUTPUT_TYPE_DVI)
248 if (ioctl(fd_tvout, VIDIOC_HDCP_ENABLE, g_hdcp_en) < 0)
249 LOGE("%s::VIDIOC_HDCP_ENABLE failed %d", __func__, errno);
250*/
251
252 i = 0;
253
254 do {
255 output.index = i;
256 ret = tvout_std_v4l2_enum_output(fd, &output);
257 LOGD("tvout_v4l2_enum_output():: output_type=%d output.index=%d output.name=%s", output.type, output.index, output.name);
258 if (output.type == output_type) {
259 matched = 1;
260 break;
261 }
262 i++;
263 } while (ret >=0);
264
265 if (!matched) {
266 LOGE("%s::no matched output type [type=%d]", __func__, output_type);
267// return -1;
268 }
269
270 // set output
271// tvout_std_v4l2_s_output(fp_tvout, output.index);
272// output_index = 0;
273// tvout_std_v4l2_g_output(fp_tvout, &output_index);
274
275// if (output.capabilities & V4L2_OUT_CAP_PRESETS) {
276 tvout_std_v4l2_enum_dv_presets(fd);
277 preset.preset = preset_id;
278 if (tvout_std_v4l2_s_dv_preset(fd, &preset) < 0 ) {
279 LOGE("%s::tvout_std_v4l2_s_dv_preset failed", __func__);
280 return -1;
281 }
282// }
283
284 return 0;
285}
286
287int tvout_std_v4l2_querycap(int fd, char *node)
288{
289#ifdef DEBUG_HDMI_HW_LEVEL
290 LOGD("%s", __func__);
291#endif
292
293 struct v4l2_capability v4l2cap;
294
295 if (ioctl(fd, VIDIOC_QUERYCAP, &v4l2cap) < 0) {
296 LOGE("%s::VIDIOC_QUERYCAP failed", __func__);
297 return -1;
298 }
299
300 if (!(v4l2cap.capabilities & V4L2_CAP_STREAMING)) {
301 LOGE("%s::%s is not support streaming", __func__, node);
302 return -1;
303 }
304
305 if (!(v4l2cap.capabilities & V4L2_CAP_VIDEO_OUTPUT_MPLANE)) {
306 LOGE("%s::%s is not support video output mplane", __func__, node);
307 return -1;
308 }
309
310 return 0;
311}
312
313int tvout_std_v4l2_enum_dv_presets(int fd)
314{
315#ifdef DEBUG_HDMI_HW_LEVEL
316 LOGD("%s", __func__);
317#endif
318
319 struct v4l2_dv_enum_preset enum_preset;
320 int ret = -1;
321
322 for (int index = 0; ; index++) {
323 enum_preset.index = index;
324 ret = ioctl(fd, VIDIOC_ENUM_DV_PRESETS, &enum_preset);
325
326 if (ret < 0) {
327 if (errno == EINVAL)
328 break;
329 LOGE("%s::VIDIOC_ENUM_DV_PRESETS", __func__);
330 return -1;
331 }
332#ifdef DEBUG_HDMI_HW_LEVEL
333 LOGD("%s::index=%d, preset=0x%08x, name=%s, w=%d, h=%d",
334 __func__, enum_preset.index, enum_preset.preset, enum_preset.name, enum_preset.width, enum_preset.height);
335#endif
336 }
337
338 return 0;
339}
340
341int tvout_std_v4l2_s_dv_preset(int fd, struct v4l2_dv_preset *preset)
342{
343#ifdef DEBUG_HDMI_HW_LEVEL
344 LOGD("%s", __func__);
345#endif
346
347 if (ioctl(fd, VIDIOC_S_DV_PRESET, preset) < 0) {
348 LOGE("%s::VIDIOC_S_DV_PRESET failed", __func__);
349 return -1;
350 }
351
352 return 0;
353}
354
355/*
356 ioctl VIDIOC_ENUMOUTPUT
357 To query the attributes of a video outputs applications initialize the index field of struct v4l2_output
358 and call the VIDIOC_ENUMOUTPUT ioctl with a pointer to this structure. Drivers fill the rest of the
359 structure or return an EINVAL error code when the index is out of bounds
360 */
361int tvout_std_v4l2_enum_output(int fd, struct v4l2_output *output)
362{
363#ifdef DEBUG_HDMI_HW_LEVEL
364 LOGD("%s", __func__);
365#endif
366
367 int ret;
368
369 ret = ioctl(fd, VIDIOC_ENUMOUTPUT, output);
370
371 if (ret >=0)
372 LOGV("tvout_v4l2_enum_output" "enum. output [index = %d] :: type : 0x%08x , name = %s\n",
373 output->index,output->type,output->name);
374
375 return ret;
376}
377
378/*
379 ioctl VIDIOC_G_OUTPUT, VIDIOC_S_OUTPUT
380 To query the current video output applications call the VIDIOC_G_OUTPUT ioctl with a pointer to an
381 integer where the driver stores the number of the output, as in the struct v4l2_output index field.
382 This ioctl will fail only when there are no video outputs, returning the EINVAL error code
383 */
384int tvout_std_v4l2_s_output(int fd, int index)
385{
386#ifdef DEBUG_HDMI_HW_LEVEL
387 LOGD("%s:: index = 0x%x", __func__, index);
388#endif
389
390 int ret;
391
392 ret = ioctl(fd, VIDIOC_S_OUTPUT, &index);
393 if (ret < 0) {
394 LOGE("tvout_v4l2_s_output" "VIDIOC_S_OUTPUT failed %d\n", errno);
395 return ret;
396 }
397
398 return ret;
399}
400
401int tvout_std_v4l2_g_output(int fd, int *index)
402{
403#ifdef DEBUG_HDMI_HW_LEVEL
404 LOGD("%s", __func__);
405#endif
406
407 int ret;
408
409 ret = ioctl(fd, VIDIOC_G_OUTPUT, index);
410 if (ret < 0) {
411 LOGE("tvout_v4l2_g_output" "VIDIOC_G_OUTPUT failed %d\n", errno);
412 return ret;
413 } else {
414 LOGV("tvout_v4l2_g_output" "Current output index %d\n", *index);
415 }
416
417 return ret;
418}
419
420int tvout_std_v4l2_s_fmt(int fd, enum v4l2_buf_type type, enum v4l2_field field, int w, int h, int colorformat, int num_planes)
421{
422#ifdef DEBUG_HDMI_HW_LEVEL
423 LOGD("%s", __func__);
424#endif
425
426 struct v4l2_format fmt;
427
428 fmt.type = type;
429// if (ioctl(fd, VIDIOC_G_FMT, &fmt) < 0) {
430// LOGE("%s::VIDIOC_G_FMT failed", __func__);
431// return -1;
432// }
433
434 switch (fmt.type) {
435 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
436 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
437 fmt.fmt.pix.width = w;
438 fmt.fmt.pix.height = h;
439 fmt.fmt.pix.pixelformat = colorformat;
440 fmt.fmt.pix.field = field;
441 break;
442 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
443 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
444 fmt.fmt.pix_mp.width = w;
445 fmt.fmt.pix_mp.height = h;
446 fmt.fmt.pix_mp.pixelformat = colorformat;
447 fmt.fmt.pix_mp.field = field;
448 fmt.fmt.pix_mp.num_planes = num_planes;
449 break;
450 default:
451 LOGE("%s::invalid buffer type", __func__);
452 return -1;
453 break;
454 }
455
456 if (ioctl(fd, VIDIOC_S_FMT, &fmt) < 0) {
457 LOGE("%s::VIDIOC_S_FMT failed", __func__);
458 return -1;
459 }
460
461 return 0;
462}
463
464int tvout_std_v4l2_s_crop(int fd, enum v4l2_buf_type type, enum v4l2_field, int x, int y, int w, int h)
465{
466#ifdef DEBUG_HDMI_HW_LEVEL
467 LOGD("%s", __func__);
468#endif
469
470 struct v4l2_crop crop;
471
472 crop.type = type;
473 crop.c.left = x;
474 crop.c.top = y;
475 crop.c.width = w;
476 crop.c.height = h;
477
478 if (ioctl(fd, VIDIOC_S_CROP, &crop) < 0) {
479 LOGE("%s::VIDIOC_S_CROP (x=%d, y=%d, w=%d, h=%d) failed",
480 __func__, x, y, w, h);
481 return -1;
482 }
483
484 return 0;
485}
486
487int tvout_std_v4l2_s_ctrl(int fd, int id, int value)
488{
489#ifdef DEBUG_HDMI_HW_LEVEL
490 LOGD("%s", __func__);
491#endif
492
493 struct v4l2_control vc;
494
495 vc.id = id;
496 vc.value = value;
497
498 if (ioctl(fd, VIDIOC_S_CTRL, &vc) < 0) {
499 LOGE("%s::VIDIOC_S_CTRL (id=%d,value=%d) failed", __func__, id, value);
500 return -1;
501 }
502
503 return 0;
504}
505
506int tvout_std_v4l2_reqbuf(int fd, enum v4l2_buf_type type, enum v4l2_memory memory, unsigned int num_bufs)
507{
508#ifdef DEBUG_HDMI_HW_LEVEL
509 LOGD("%s", __func__);
510#endif
511
512 struct v4l2_requestbuffers reqbuf;
513
514 reqbuf.type = type;
515 reqbuf.memory = memory;
516 reqbuf.count = num_bufs;
517
518 if (ioctl(fd, VIDIOC_REQBUFS, &reqbuf) < 0) {
519 LOGE("%s::VIDIOC_REQBUFS failed", __func__);
520 return -1;
521 }
522
523 if (reqbuf.count < num_bufs) {
524 LOGE("%s::VIDIOC_REQBUFS failed ((reqbuf.count(%d) < num_bufs(%d))",
525 __func__, reqbuf.count, num_bufs);
526 return -1;
527 }
528
529 return 0;
530}
531
532int tvout_std_v4l2_querybuf(int fd, enum v4l2_buf_type type, enum v4l2_memory memory, unsigned int buf_index, unsigned int num_planes, SecBuffer *secBuf)
533{
534#ifdef DEBUG_HDMI_HW_LEVEL
535 LOGD("%s", __func__);
536#endif
537
538 struct v4l2_buffer buf;
539 struct v4l2_plane planes[MAX_PLANES_MIXER];
540
541 memset(&buf, 0, sizeof(struct v4l2_buffer));
542
543 for (int i = 0; i < MAX_PLANES_MIXER; i++)
544 memset(&planes[i], 0, sizeof(struct v4l2_plane));
545
546 if (MAX_BUFFERS_MIXER <= buf_index || MAX_PLANES_MIXER <= num_planes) {
547 LOGE("%s::exceed MAX! : buf_index=%d, num_plane=%d", __func__, buf_index, num_planes);
548 return -1;
549 }
550
551 buf.type = type;
552 buf.memory = V4L2_MEMORY_MMAP;
553 buf.index = buf_index;
554 buf.length = num_planes;
555 buf.m.planes = planes;
556
557 if (ioctl(fd, VIDIOC_QUERYBUF, &buf) < 0) {
558 LOGE("%s::VIDIOC_QUERYBUF failed, plane_cnt=%d", __func__, buf.length);
559 return -1;
560 }
561
562 for (unsigned int i = 0; i < num_planes; i++) {
563 if ((secBuf->virt.extP[i] = (char *)mmap(0, buf.m.planes[i].length,
564 PROT_READ | PROT_WRITE, MAP_SHARED, fd, buf.m.planes[i].m.mem_offset)) < 0) {
565 LOGE("%s::mmap failed", __func__);
566 LOGE("%s::Offset = 0x%x", __func__, buf.m.planes[i].m.mem_offset);
567 LOGE("%s::Legnth = %d" , __func__, buf.m.planes[i].length);
568 LOGE("%s::vaddr[%d][%d] = 0x%x", __func__, buf_index, i, (unsigned int)secBuf->virt.extP[i]);
569 return -1;
570 }
571 secBuf->size.extS[i] = buf.m.planes[i].length;
572
573#ifdef DEBUG_LIB_FIMC
574 LOGD("%s::vaddr[bufidx=%d][planeidx=%d] = 0x%x", __func__, buf_index, i, (unsigned int)secBuf->virt.extP[i]);
575 LOGD("%s::Legnth = %d" , __func__, buf.m.planes[i].length);
576#endif
577 }
578
579 return 0;
580}
581
582int tvout_std_v4l2_qbuf(int fd, enum v4l2_buf_type type, enum v4l2_memory memory, int buf_index, int num_planes, SecBuffer *secBuf)
583{
584#ifdef DEBUG_HDMI_HW_LEVEL
585 LOGD("%s", __func__);
586#endif
587
588 struct v4l2_buffer buf;
589 struct v4l2_plane planes[MAX_PLANES_MIXER];
590
591 memset(&buf, 0, sizeof(struct v4l2_buffer));
592
593 for (int i = 0; i < MAX_PLANES_MIXER; i++)
594 memset(&planes[i], 0, sizeof(struct v4l2_plane));
595
596 buf.type = type;
597 buf.memory = memory;
598 buf.length = num_planes;
599 buf.index = buf_index;
600 buf.m.planes = planes;
601
602 for (unsigned int i = 0; i < buf.length; i++) {
603 buf.m.planes[i].m.userptr = (unsigned long)secBuf->virt.extP[i];
604 buf.m.planes[i].length = secBuf->size.extS[i];
605 }
606
607 if (ioctl(fd, VIDIOC_QBUF, &buf) < 0) {
608 LOGE("%s::VIDIOC_QBUF failed", __func__);
609 return -1;
610 }
611
612 return 0;
613}
614
615int tvout_std_v4l2_dqbuf(int fd, enum v4l2_buf_type type, enum v4l2_memory memory, int *buf_index, int num_planes)
616{
617#ifdef DEBUG_HDMI_HW_LEVEL
618 LOGD("%s", __func__);
619#endif
620
621 struct v4l2_buffer buf;
622 struct v4l2_plane planes[MAX_PLANES_MIXER];
623
624 memset(&buf, 0, sizeof(struct v4l2_buffer));
625
626 for (int i = 0; i < MAX_PLANES_MIXER; i++)
627 memset(&planes[i], 0, sizeof(struct v4l2_plane));
628
629 buf.type = type;
630 buf.memory = memory;
631 buf.length = num_planes;
632 buf.m.planes = planes;
633
634 if (ioctl(fd, VIDIOC_DQBUF, &buf) < 0) {
635 LOGE("%s::VIDIOC_DQBUF failed", __func__);
636 return -1;
637 }
638 *buf_index = buf.index;
639
640 return 0;
641}
642
643int tvout_std_v4l2_streamon(int fd, enum v4l2_buf_type type)
644{
645#ifdef DEBUG_HDMI_HW_LEVEL
646 LOGD("%s", __func__);
647#endif
648
649 if (ioctl(fd, VIDIOC_STREAMON, &type) < 0) {
650 LOGE("%s::VIDIOC_STREAMON failed", __func__);
651 return -1;
652 }
653
654 return 0;
655}
656
657int tvout_std_v4l2_streamoff(int fd, enum v4l2_buf_type type)
658{
659#ifdef DEBUG_HDMI_HW_LEVEL
660 LOGD("%s", __func__);
661#endif
662
663 if (ioctl(fd, VIDIOC_STREAMOFF, &type) < 0) {
664 LOGE("%s::VIDIOC_STREAMOFF failed", __func__);
665 return -1;
666 }
667
668 return 0;
669}
670#else
671int tvout_init(v4l2_std_id std_id)
672{
673#ifdef DEBUG_HDMI_HW_LEVEL
674 LOGD("%s:: std_id = 0x%x", __func__, std_id);
675#endif
676
677 int ret;
678 struct v4l2_output output;
679 struct v4l2_standard std;
680 v4l2_std_id std_g_id;
681 struct tvout_param tv_g_param;
682
683 unsigned int matched = 0, i = 0;
684 int output_index;
685
686 // It was initialized already
687 if (fp_tvout <= 0) {
688 fp_tvout = tvout_open(TVOUT_DEV);
689 if (fp_tvout < 0) {
690 LOGE("tvout video drv open failed\n");
691 return -1;
692 }
693 }
694
695 if (output_type >= V4L2_OUTPUT_TYPE_DIGITAL &&
696 output_type <= V4L2_OUTPUT_TYPE_DVI)
697 if (ioctl(fp_tvout, VIDIOC_HDCP_ENABLE, g_hdcp_en) < 0)
698 LOGE("tvout_init" "VIDIOC_HDCP_ENABLE failed %d\n", errno);
699
700 /* ============== query capability============== */
701 tvout_v4l2_querycap(fp_tvout);
702
703 tvout_v4l2_enum_std(fp_tvout, &std, std_id);
704
705 // set std
706 tvout_v4l2_s_std(fp_tvout, std_id);
707 tvout_v4l2_g_std(fp_tvout, &std_g_id);
708
709 i = 0;
710
711 do {
712 output.index = i;
713 ret = tvout_v4l2_enum_output(fp_tvout, &output);
714 if (output.type == output_type) {
715 matched = 1;
716 break;
717 }
718 i++;
719 } while (ret >=0);
720
721 if (!matched) {
722 LOGE("no matched output type [type : 0x%08x]\n", output_type);
723 return -1;
724 }
725
726 // set output
727 tvout_v4l2_s_output(fp_tvout, output.index);
728 output_index = 0;
729 tvout_v4l2_g_output(fp_tvout, &output_index);
730
731 //set fmt param
732 vo_param.src.base_y = (void *)0x0;
733 vo_param.src.base_c = (void *)0x0;
734 vo_param.src.pix_fmt.width = 0;
735 vo_param.src.pix_fmt.height = 0;
736 vo_param.src.pix_fmt.field = V4L2_FIELD_NONE;
737 vo_param.src.pix_fmt.pixelformat = V4L2_PIX_FMT_NV12T;
738
739 vo_param.src_crop.left = 0;
740 vo_param.src_crop.top = 0;
741 vo_param.src_crop.width = 0;
742 vo_param.src_crop.height = 0;
743
744 return fp_tvout;
745}
746
747int tvout_deinit()
748{
749#ifdef DEBUG_HDMI_HW_LEVEL
750 LOGD("%s", __func__);
751#endif
752
753 if (0 < fp_tvout) {
754 close(fp_tvout);
755 fp_tvout = -1;
756 }
757 return 0;
758}
759
760int tvout_v4l2_querycap(int fp)
761{
762#ifdef DEBUG_HDMI_HW_LEVEL
763 LOGD("%s:: fp = 0x%x", __func__, fp);
764#endif
765
766 struct v4l2_capability cap;
767 int ret;
768
769 ret = ioctl(fp, VIDIOC_QUERYCAP, &cap);
770
771 if (ret < 0) {
772 LOGE("tvout_v4l2_querycap" "VIDIOC_QUERYCAP failed %d\n", errno);
773 return ret;
774 }
775
776#ifdef DEBUG_HDMI_HW_LEVEL
777 LOGD("tvout_v4l2_querycap" "DRIVER : %s, CARD : %s, CAP.: 0x%08x\n",
778 cap.driver, cap.card, cap.capabilities);
779#endif
780
781 return ret;
782}
783
784/*
785 ioctl VIDIOC_G_STD, VIDIOC_S_STD
786 To query and select the current video standard applications use the VIDIOC_G_STD and
787 VIDIOC_S_STD ioctls which take a pointer to a v4l2_std_id type as argument. VIDIOC_G_STD can
788 return a single flag or a set of flags as in struct v4l2_standard field id
789 */
790
791int tvout_v4l2_g_std(int fp, v4l2_std_id *std_id)
792{
793#ifdef DEBUG_HDMI_HW_LEVEL
794 LOGD("%s", __func__);
795#endif
796
797 int ret;
798
799 ret = ioctl(fp, VIDIOC_G_STD, std_id);
800 if (ret < 0) {
801 LOGE("tvout_v4l2_g_std" "VIDIOC_G_STD failed %d\n", errno);
802 return ret;
803 }
804
805 return ret;
806}
807
808int tvout_v4l2_s_std(int fp, v4l2_std_id std_id)
809{
810#ifdef DEBUG_HDMI_HW_LEVEL
811 LOGD("%s:: std_id = 0x%x", __func__, std_id);
812#endif
813
814 int ret;
815
816 ret = ioctl(fp, VIDIOC_S_STD, &std_id);
817 if (ret < 0) {
818 LOGE("tvout_v4l2_s_std" "VIDIOC_S_STD failed %d\n", errno);
819 return ret;
820 }
821
822 return ret;
823}
824
825/*
826 ioctl VIDIOC_ENUMSTD
827 To query the attributes of a video standard, especially a custom (driver defined) one, applications
828 initialize the index field of struct v4l2_standard and call the VIDIOC_ENUMSTD ioctl with a pointer
829 to this structure. Drivers fill the rest of the structure or return an EINVAL error code when the index
830 is out of bounds.
831 */
832int tvout_v4l2_enum_std(int fp, struct v4l2_standard *std, v4l2_std_id std_id)
833{
834#ifdef DEBUG_HDMI_HW_LEVEL
835 LOGD("%s", __func__);
836#endif
837
838 std->index = 0;
839 while (0 == ioctl (fp, VIDIOC_ENUMSTD, std)) {
840 if (std->id & std_id)
841 LOGV("tvout_v4l2_enum_std" "Current video standard: %s\n", std->name);
842
843 std->index++;
844 }
845
846 return 0;
847}
848
849/*
850 ioctl VIDIOC_ENUMOUTPUT
851 To query the attributes of a video outputs applications initialize the index field of struct v4l2_output
852 and call the VIDIOC_ENUMOUTPUT ioctl with a pointer to this structure. Drivers fill the rest of the
853 structure or return an EINVAL error code when the index is out of bounds
854 */
855int tvout_v4l2_enum_output(int fp, struct v4l2_output *output)
856{
857#ifdef DEBUG_HDMI_HW_LEVEL
858 LOGD("%s", __func__);
859#endif
860
861 int ret;
862
863 ret = ioctl(fp, VIDIOC_ENUMOUTPUT, output);
864
865 if (ret >=0)
866 LOGV("tvout_v4l2_enum_output" "enum. output [index = %d] :: type : 0x%08x , name = %s\n",
867 output->index,output->type,output->name);
868
869 return ret;
870}
871
872/*
873 ioctl VIDIOC_G_OUTPUT, VIDIOC_S_OUTPUT
874 To query the current video output applications call the VIDIOC_G_OUTPUT ioctl with a pointer to an
875 integer where the driver stores the number of the output, as in the struct v4l2_output index field.
876 This ioctl will fail only when there are no video outputs, returning the EINVAL error code
877 */
878int tvout_v4l2_s_output(int fp, int index)
879{
880#ifdef DEBUG_HDMI_HW_LEVEL
881 LOGD("%s:: index = 0x%x", __func__, index);
882#endif
883
884 int ret;
885
886 ret = ioctl(fp, VIDIOC_S_OUTPUT, &index);
887 if (ret < 0) {
888 LOGE("tvout_v4l2_s_output" "VIDIOC_S_OUTPUT failed %d\n", errno);
889 return ret;
890 }
891
892 return ret;
893}
894
895int tvout_v4l2_g_output(int fp, int *index)
896{
897#ifdef DEBUG_HDMI_HW_LEVEL
898 LOGD("%s", __func__);
899#endif
900
901 int ret;
902
903 ret = ioctl(fp, VIDIOC_G_OUTPUT, index);
904 if (ret < 0) {
905 LOGE("tvout_v4l2_g_output" "VIDIOC_G_OUTPUT failed %d\n", errno);
906 return ret;
907 } else {
908 LOGV("tvout_v4l2_g_output" "Current output index %d\n", *index);
909 }
910
911 return ret;
912}
913
914/*
915 ioctl VIDIOC_ENUM_FMT
916 To enumerate image formats applications initialize the type and index field of struct v4l2_fmtdesc
917 and call the VIDIOC_ENUM_FMT ioctl with a pointer to this structure. Drivers fill the rest of the
918 structure or return an EINVAL error code. All formats are enumerable by beginning at index zero
919 and incrementing by one until EINVAL is returned.
920 */
921int tvout_v4l2_enum_fmt(int fp, struct v4l2_fmtdesc *desc)
922{
923#ifdef DEBUG_HDMI_HW_LEVEL
924 LOGD("%s", __func__);
925#endif
926
927 desc->index = 0;
928 while (0 == ioctl(fp, VIDIOC_ENUM_FMT, desc)) {
929 LOGV("tvout_v4l2_enum_fmt" "enum. fmt [id : 0x%08x] :: type = 0x%08x, name = %s, pxlfmt = 0x%08x\n",
930 desc->index,
931 desc->type,
932 desc->description,
933 desc->pixelformat);
934 desc->index++;
935 }
936
937 return 0;
938}
939
940int tvout_v4l2_g_fmt(int fp, int buf_type, void* ptr)
941{
942#ifdef DEBUG_HDMI_HW_LEVEL
943 LOGD("%s", __func__);
944#endif
945
946 int ret;
947 struct v4l2_format format;
948 struct v4l2_pix_format_s5p_tvout *fmt_param = (struct v4l2_pix_format_s5p_tvout*)ptr;
949
950 format.type = (enum v4l2_buf_type)buf_type;
951
952 ret = ioctl(fp, VIDIOC_G_FMT, &format);
953 if (ret < 0) {
954 LOGE("tvout_v4l2_g_fmt" "type : %d, VIDIOC_G_FMT failed %d\n", buf_type, errno);
955 return ret;
956 } else {
957 memcpy(fmt_param, format.fmt.raw_data, sizeof(struct v4l2_pix_format_s5p_tvout));
958 LOGV("tvout_v4l2_g_fmt" "get. fmt [base_c : 0x%08x], [base_y : 0x%08x] type = 0x%08x, width = %d, height = %d\n",
959 fmt_param->base_c,
960 fmt_param->base_y,
961 fmt_param->pix_fmt.pixelformat,
962 fmt_param->pix_fmt.width,
963 fmt_param->pix_fmt.height);
964 }
965
966 return 0;
967}
968
969int tvout_v4l2_s_fmt(int fp, int buf_type, void *ptr)
970{
971#ifdef DEBUG_HDMI_HW_LEVEL
972 LOGD("%s", __func__);
973#endif
974
975 struct v4l2_format format;
976 int ret;
977
978 format.type = (enum v4l2_buf_type)buf_type;
979 switch (buf_type) {
980 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
981 format.fmt.win = *((struct v4l2_window *) ptr);
982 break;
983
984 case V4L2_BUF_TYPE_PRIVATE: {
985 struct v4l2_vid_overlay_src *fmt_param =
986 (struct v4l2_vid_overlay_src *) ptr;
987
988 memcpy(format.fmt.raw_data, fmt_param,
989 sizeof(struct v4l2_vid_overlay_src));
990 break;
991 }
992 case V4L2_BUF_TYPE_VIDEO_OUTPUT: {
993 struct v4l2_pix_format_s5p_tvout *fmt_param =
994 (struct v4l2_pix_format_s5p_tvout *)ptr;
995 memcpy(format.fmt.raw_data, fmt_param,
996 sizeof(struct v4l2_pix_format_s5p_tvout));
997 break;
998 }
999 default:
1000 break;
1001 }
1002
1003 ret = ioctl(fp, VIDIOC_S_FMT, &format);
1004 if (ret < 0) {
1005 LOGE("tvout_v4l2_s_fmt [tvout_v4l2_s_fmt] : type : %d, VIDIOC_S_FMT failed %d\n",
1006 buf_type, errno);
1007 return ret;
1008 }
1009 return 0;
1010
1011}
1012
1013int tvout_v4l2_g_fbuf(int fp, struct v4l2_framebuffer *frame)
1014{
1015#ifdef DEBUG_HDMI_HW_LEVEL
1016 LOGD("%s", __func__);
1017#endif
1018
1019 int ret;
1020
1021 ret = ioctl(fp, VIDIOC_G_FBUF, frame);
1022 if (ret < 0) {
1023 LOGE("tvout_v4l2_g_fbuf" "VIDIOC_STREAMON failed %d\n", errno);
1024 return ret;
1025 }
1026
1027 LOGV("tvout_v4l2_g_fbuf" "get. fbuf: base = 0x%08X, pixel format = %d\n",
1028 frame->base,
1029 frame->fmt.pixelformat);
1030 return 0;
1031}
1032
1033int tvout_v4l2_s_fbuf(int fp, struct v4l2_framebuffer *frame)
1034{
1035#ifdef DEBUG_HDMI_HW_LEVEL
1036 LOGD("%s", __func__);
1037#endif
1038
1039 int ret;
1040
1041 ret = ioctl(fp, VIDIOC_S_FBUF, frame);
1042 if (ret < 0) {
1043 LOGE("tvout_v4l2_s_fbuf" "VIDIOC_STREAMON failed %d\n", errno);
1044 return ret;
1045 }
1046 return 0;
1047}
1048
1049int tvout_v4l2_s_baseaddr(int fp, void *base_addr)
1050{
1051#ifdef DEBUG_HDMI_HW_LEVEL
1052 LOGD("%s", __func__);
1053#endif
1054
1055 int ret;
1056
1057 ret = ioctl(fp, S5PTVFB_WIN_SET_ADDR, base_addr);
1058 if (ret < 0) {
1059 LOGE("tvout_v4l2_baseaddr" "VIDIOC_S_BASEADDR failed %d\n", errno);
1060 return ret;
1061 }
1062 return 0;
1063}
1064
1065int tvout_v4l2_g_crop(int fp, unsigned int type, struct v4l2_rect *rect)
1066{
1067#ifdef DEBUG_HDMI_HW_LEVEL
1068 LOGD("%s", __func__);
1069#endif
1070
1071 int ret;
1072 struct v4l2_crop crop;
1073 crop.type = (enum v4l2_buf_type)type;
1074 ret = ioctl(fp, VIDIOC_G_CROP, &crop);
1075 if (ret < 0) {
1076 LOGE("tvout_v4l2_g_crop" "VIDIOC_G_CROP failed %d\n", errno);
1077 return ret;
1078 }
1079
1080 rect->left = crop.c.left;
1081 rect->top = crop.c.top;
1082 rect->width = crop.c.width;
1083 rect->height = crop.c.height;
1084
1085 LOGV("tvout_v4l2_g_crop" "get. crop : left = %d, top = %d, width = %d, height = %d\n",
1086 rect->left,
1087 rect->top,
1088 rect->width,
1089 rect->height);
1090 return 0;
1091}
1092
1093int tvout_v4l2_s_crop(int fp, unsigned int type, struct v4l2_rect *rect)
1094{
1095#ifdef DEBUG_HDMI_HW_LEVEL
1096 LOGD("%s", __func__);
1097#endif
1098
1099 struct v4l2_crop crop;
1100 int ret;
1101
1102 crop.type = (enum v4l2_buf_type)type;
1103
1104 crop.c.left = rect->left;
1105 crop.c.top = rect->top;
1106 crop.c.width = rect->width;
1107 crop.c.height = rect->height;
1108
1109 ret = ioctl(fp, VIDIOC_S_CROP, &crop);
1110 if (ret < 0) {
1111 LOGE("tvout_v4l2_s_crop" "VIDIOC_S_CROP failed %d\n", errno);
1112 return ret;
1113 }
1114
1115 return 0;
1116}
1117
1118int tvout_v4l2_start_overlay(int fp)
1119{
1120#ifdef DEBUG_HDMI_HW_LEVEL
1121 LOGD("%s", __func__);
1122#endif
1123
1124 int ret, start = 1;
1125
1126 ret = ioctl(fp, VIDIOC_OVERLAY, &start);
1127 if (ret < 0) {
1128 LOGE("tvout_v4l2_start_overlay" "VIDIOC_OVERLAY failed\n");
1129 return ret;
1130 }
1131
1132 return ret;
1133}
1134
1135int tvout_v4l2_stop_overlay(int fp)
1136{
1137#ifdef DEBUG_HDMI_HW_LEVEL
1138 LOGD("%s", __func__);
1139#endif
1140
1141 int ret, stop =0;
1142
1143 ret = ioctl(fp, VIDIOC_OVERLAY, &stop);
1144 if (ret < 0) {
1145 LOGE("tvout_v4l2_stop_overlay" "VIDIOC_OVERLAY failed\n");
1146 return ret;
1147 }
1148
1149 return ret;
1150}
1151#endif
1152
1153int hdmi_init_layer(int layer)
1154{
1155 int fd = -1;
1156#ifdef DEBUG_HDMI_HW_LEVEL
1157 LOGD("### %s (layer = %d) called", __func__, layer);
1158#endif
1159
1160 switch (layer) {
1161 case HDMI_LAYER_VIDEO :
1162 if (fp_tvout_v <= 0) {
1163 fp_tvout_v = tvout_open(TVOUT_DEV_V);
1164 if (fp_tvout_v < 0) {
1165 LOGE("tvout video layer open failed\n");
1166 return -1;
1167 }
1168 fd = fp_tvout_v;
1169 }
1170 break;
1171 case HDMI_LAYER_GRAPHIC_0 :
1172 if (fp_tvout_g0 <= 0) {
1173#if defined(BOARD_USE_V4L2)
1174 fp_tvout_g0 = tvout_open(TVOUT_DEV_G0);
1175#else
1176 fp_tvout_g0 = fb_open(TVOUT_FB_G0);
1177#endif
1178 if (fp_tvout_g0 < 0) {
1179 LOGE("tvout graphic layer 0 open failed\n");
1180 return -1;
1181 }
1182 fd = fp_tvout_g0;
1183 }
1184 break;
1185 case HDMI_LAYER_GRAPHIC_1 :
1186 if (fp_tvout_g1 <= 0) {
1187#if defined(BOARD_USE_V4L2)
1188 fp_tvout_g1 = tvout_open(TVOUT_DEV_G1);
1189#else
1190 fp_tvout_g1 = fb_open(TVOUT_FB_G1);
1191#endif
1192 if (fp_tvout_g1 < 0) {
1193 LOGE("tvout graphic layer 1 open failed\n");
1194 return -1;
1195 }
1196 fd = fp_tvout_g1;
1197 }
1198 break;
1199 default :
1200 LOGE("%s::unmathced layer(%d) fail", __func__, layer);
1201 fd = -1;
1202 break;
1203 }
1204
1205 return fd;
1206}
1207
1208int hdmi_deinit_layer(int layer)
1209{
1210 int ret = 0;
1211#ifdef DEBUG_HDMI_HW_LEVEL
1212 LOGD("### %s(layer = %d) called", __func__, layer);
1213#endif
1214 switch (layer) {
1215 case HDMI_LAYER_VIDEO :
1216 if (0 < fp_tvout_v) {
1217 close(fp_tvout_v);
1218 fp_tvout_v = -1;
1219 }
1220 break;
1221 case HDMI_LAYER_GRAPHIC_0 :
1222 if (0 < fp_tvout_g0) {
1223 close(fp_tvout_g0);
1224 fp_tvout_g0 = -1;
1225 }
1226 break;
1227 case HDMI_LAYER_GRAPHIC_1 :
1228 if (0 < fp_tvout_g1) {
1229 close(fp_tvout_g1);
1230 fp_tvout_g1 = -1;
1231 }
1232 break;
1233 default :
1234 LOGE("%s::unmathced layer(%d) fail", __func__, layer);
1235 ret = -1;
1236 break;
1237 }
1238
1239 return ret;
1240}
1241
1242#define ROUND_UP(value, boundary) ((((uint32_t)(value)) + \
1243 (((uint32_t) boundary)-1)) & \
1244 (~(((uint32_t) boundary)-1)))
1245
1246void hdmi_cal_rect(int src_w, int src_h, int dst_w, int dst_h, struct v4l2_rect *dst_rect)
1247{
1248 if (dst_w * src_h <= dst_h * src_w) {
1249 dst_rect->left = 0;
1250 dst_rect->top = (dst_h - ((dst_w * src_h) / src_w)) >> 1;
1251 dst_rect->width = dst_w;
1252 dst_rect->height = ((dst_w * src_h) / src_w);
1253 } else {
1254 dst_rect->left = (dst_w - ((dst_h * src_w) / src_h)) >> 1;
1255 dst_rect->top = 0;
1256 dst_rect->width = ((dst_h * src_w) / src_h);
1257 dst_rect->height = dst_h;
1258 }
1259}
1260
1261#if defined(BOARD_USE_V4L2)
1262int hdmi_get_src_plane(int srcColorFormat, unsigned int *num_of_plane)
1263{
1264 int v4l2ColorFormat = HAL_PIXEL_FORMAT_2_V4L2_PIX(srcColorFormat);
1265
1266 switch (v4l2ColorFormat) {
1267 case V4L2_PIX_FMT_NV12:
1268 case V4L2_PIX_FMT_NV21:
1269 case V4L2_PIX_FMT_BGR32:
1270 case V4L2_PIX_FMT_RGB32:
1271 case V4L2_PIX_FMT_RGB565X:
1272 *num_of_plane = 1;
1273 break;
1274 case V4L2_PIX_FMT_NV12M:
1275 case V4L2_PIX_FMT_NV12MT:
1276 case V4L2_PIX_FMT_NV21M:
1277 *num_of_plane = 2;
1278 break;
1279 default:
1280 LOGE("%s::invalid color type", __func__);
1281 return -1;
1282 }
1283
1284 return 0;
1285}
1286#endif
1287
1288#if defined(BOARD_USE_V4L2)
1289int hdmi_set_v_param(int fd, int layer,
1290 int srcColorFormat,
1291 int src_w, int src_h,
1292 SecBuffer * dstBuffer,
1293 int dst_x, int dst_y, int dst_w, int dst_h)
1294{
1295#ifdef DEBUG_HDMI_HW_LEVEL
1296 LOGD("%s", __func__);
1297#endif
1298
1299 int v4l2ColorFormat = HAL_PIXEL_FORMAT_2_V4L2_PIX(srcColorFormat);
1300 int round_up_src_w;
1301 int round_up_src_h;
1302 unsigned int num_of_plane;
1303 struct v4l2_rect rect;
1304
1305 /* src_w, src_h round up to DWORD because of VP restriction */
1306#if defined(SAMSUNG_EXYNOS4x12)
1307 round_up_src_w = ROUND_UP(src_w, 16);
1308#else defined(SAMSUNG_EXYNOS4210)
1309 round_up_src_w = ROUND_UP(src_w, 8);
1310#endif
1311 round_up_src_h = ROUND_UP(src_h, 8);
1312
1313 switch (v4l2ColorFormat) {
1314 case V4L2_PIX_FMT_NV12:
1315 case V4L2_PIX_FMT_NV21:
1316 dstBuffer->size.s = (round_up_src_w * round_up_src_h * 3) >> 1;
1317 num_of_plane = 1;
1318 break;
1319 case V4L2_PIX_FMT_NV12M:
1320 case V4L2_PIX_FMT_NV12MT:
1321 case V4L2_PIX_FMT_NV21M:
1322 dstBuffer->size.extS[0] = (round_up_src_w * round_up_src_h * 3) >> 1;
1323 dstBuffer->size.extS[1] = (round_up_src_w * round_up_src_h * 3) >> 2;
1324 num_of_plane = 2;
1325 break;
1326 default:
1327 LOGE("%s::invalid color type", __func__);
1328 return false;
1329 break;
1330 }
1331
1332 hdmi_cal_rect(src_w, src_h, dst_w, dst_h, &rect);
1333 rect.left = ALIGN(rect.left, 16);
1334
1335 /* set format for VP input */
1336 if (tvout_std_v4l2_s_fmt(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, V4L2_FIELD_ANY, round_up_src_w, round_up_src_h, v4l2ColorFormat, num_of_plane) < 0) {
1337 LOGE("%s::tvout_std_v4l2_s_fmt()[video layer] failed", __func__);
1338 return -1;
1339 }
1340
1341 /* set crop for VP input */
1342 if (tvout_std_v4l2_s_crop(fd, V4L2_BUF_TYPE_VIDEO_OVERLAY, V4L2_FIELD_ANY, 0, 0, src_w, src_h) < 0) {
1343 LOGE("%s::tvout_std_v4l2_s_crop()[video layer] failed", __func__);
1344 return -1;
1345 }
1346
1347 /* set crop for VP output */
1348 if (tvout_std_v4l2_s_crop(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, V4L2_FIELD_ANY, rect.left, rect.top, rect.width, rect.height) < 0) {
1349 LOGE("%s::tvout_std_v4l2_s_crop()[video layer] failed", __func__);
1350 return -1;
1351 }
1352
1353 /* request buffer for VP input */
1354 if (tvout_std_v4l2_reqbuf(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, V4L2_MEMORY_USERPTR, HDMI_NUM_MIXER_BUF) < 0) {
1355 LOGE("%s::tvout_std_v4l2_reqbuf(buf_num=%d)[video layer] failed", __func__, HDMI_NUM_MIXER_BUF);
1356 return -1;
1357 }
1358
1359 return 0;
1360}
1361
1362int hdmi_set_g_param(int fd, int layer,
1363 int srcColorFormat,
1364 int src_w, int src_h,
1365 SecBuffer * dstBuffer,
1366 int dst_x, int dst_y, int dst_w, int dst_h)
1367{
1368#ifdef DEBUG_HDMI_HW_LEVEL
1369 LOGD("%s", __func__);
1370#endif
1371
1372 struct v4l2_rect rect;
1373 int v4l2ColorFormat = HAL_PIXEL_FORMAT_2_V4L2_PIX(srcColorFormat);
1374
1375 rect.left = dst_x;
1376 rect.top = dst_y;
1377
1378#if defined(BOARD_USES_FIMGAPI)
1379 rect.width = dst_w;
1380 rect.height = dst_h;
1381#else
1382 rect.width = src_w;
1383 rect.height = src_h;
1384#endif
1385
1386 switch (v4l2ColorFormat) {
1387 case V4L2_PIX_FMT_BGR32:
1388 case V4L2_PIX_FMT_RGB32:
1389 dstBuffer->size.s = rect.width * rect.height << 2;
1390 break;
1391 case V4L2_PIX_FMT_RGB565X:
1392 dstBuffer->size.s = rect.width * rect.height << 1;
1393 break;
1394 default:
1395 LOGE("%s::invalid color type", __func__);
1396 return false;
1397 break;
1398 }
1399
1400 /* set format for mixer graphic layer input device*/
1401 if (tvout_std_v4l2_s_fmt(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, V4L2_FIELD_ANY, rect.width, rect.height, v4l2ColorFormat, 1) < 0) {
1402 LOGE("%s::tvout_std_v4l2_s_fmt() [layer=%d] failed", __func__, layer);
1403 return -1;
1404 }
1405
1406 /* set crop for mixer graphic layer input device*/
1407 if (tvout_std_v4l2_s_crop(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, V4L2_FIELD_ANY, rect.left, rect.top, rect.width, rect.height) < 0) {
1408 LOGE("%s::tvout_std_v4l2_s_crop() [layer=%d] failed", __func__, layer);
1409 return -1;
1410 }
1411
1412 /* request buffer for mixer graphic layer input device */
1413 if (tvout_std_v4l2_reqbuf(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, V4L2_MEMORY_USERPTR, HDMI_NUM_MIXER_BUF) < 0) {
1414 LOGE("%s::tvout_std_v4l2_reqbuf(buf_num=%d) [layer=%d] failed", __func__, HDMI_NUM_MIXER_BUF, layer);
1415 return -1;
1416 }
1417
1418 /* enable alpha blending for mixer graphic layer */
1419 if (tvout_std_v4l2_s_ctrl(fd, V4L2_CID_TV_LAYER_BLEND_ENABLE, 1) < 0) {
1420 LOGE("%s::tvout_std_v4l2_s_ctrl() [layer=%d] failed", __func__, layer);
1421 return -1;
1422 }
1423
1424 /* enable per-pixel blending for mixer graphic layer */
1425 if (tvout_std_v4l2_s_ctrl(fd, V4L2_CID_TV_PIXEL_BLEND_ENABLE, 1) < 0) {
1426 LOGE("%s::tvout_std_v4l2_s_ctrl [layer=%d] failed", __func__, layer);
1427 return false;
1428 }
1429
1430 /* set global alpha value for mixer graphic layer */
1431 if (tvout_std_v4l2_s_ctrl(fd, V4L2_CID_TV_LAYER_BLEND_ALPHA, 255) < 0) {
1432 LOGE("%s::tvout_std_v4l2_s_ctrl() [layer=%d] failed", __func__, layer);
1433 return -1;
1434 }
1435
1436 return 0;
1437}
1438
1439int hdmi_set_g_scaling(int layer,
1440 int srcColorFormat,
1441 int src_w, int src_h,
1442 unsigned int src_address, SecBuffer * dstBuffer,
1443 int dst_x, int dst_y, int dst_w, int dst_h,
1444 int rotVal, unsigned int hwc_layer)
1445{
1446#if defined(BOARD_USES_FIMGAPI)
1447 int dst_color_format;
1448 int dst_bpp;
1449 unsigned char *dst_addr;
1450 fimg2d_blit BlitParam;
1451 rotation g2d_rotation;
1452
1453 fimg2d_addr srcAddr;
1454 fimg2d_image srcImage;
1455 fimg2d_rect srcRect;
1456
1457 fimg2d_addr dstAddr;
1458 fimg2d_image dstImage;
1459 fimg2d_rect dstRect;
1460
1461 fimg2d_clip dstClip;
1462 fimg2d_scale Scaling;
1463
1464 switch (g_preset_id) {
1465 case V4L2_DV_1080P60:
1466 case V4L2_DV_1080P30:
1467 case V4L2_DV_1080I60:
1468 case V4L2_DV_720P60_SB_HALF:
1469 case V4L2_DV_720P59_94_SB_HALF:
1470 case V4L2_DV_1080P24_TB:
1471 case V4L2_DV_1080P23_98_TB:
1472 dst_color_format = CF_ARGB_8888;
1473 dst_bpp = 4;
1474 break;
1475 case V4L2_DV_480P60:
1476 case V4L2_DV_576P50:
1477 case V4L2_DV_720P60:
1478 case V4L2_DV_720P50_TB:
1479 default:
1480 dst_color_format = CF_ARGB_4444;
1481 dst_bpp = 2;
1482 break;
1483 }
1484
1485 static unsigned int prev_src_addr = 0;
1486
1487 if ((cur_g2d_address == 0) || (src_address != prev_src_addr)) {
1488 dst_addr = (unsigned char *)g2d_reserved_memory[g2d_buf_index];
1489
1490 g2d_buf_index++;
1491 if (g2d_buf_index >= HDMI_G2D_OUTPUT_BUF_NUM)
1492 g2d_buf_index = 0;
1493
1494 cur_g2d_address = (unsigned int)dst_addr;
1495 prev_src_addr = src_address;
1496
1497 srcAddr = {(addr_space)ADDR_USER, (unsigned long)src_address, src_w * src_h * 4, 1, 0};
1498 srcImage = {srcAddr, srcAddr, src_w, src_h, src_w*4, AX_RGB, CF_ARGB_8888};
1499 srcRect = {0, 0, src_w, src_h};
1500
1501 dstAddr = {(addr_space)ADDR_USER, (unsigned long)dst_addr, dst_w * dst_h * dst_bpp, 1, 0};
1502 dstImage = {dstAddr, dstAddr, dst_w, dst_h, dst_w*dst_bpp, AX_RGB, (color_format)dst_color_format};
1503 dstRect = {0, 0, dst_w, dst_h};
1504 dstClip = {0, 0, 0, dst_w, dst_h};
1505
1506 if (rotVal == 0 || rotVal == 180)
1507 Scaling = {SCALING_BILINEAR, SCALING_PIXELS, 0, 0, src_w, src_h, dst_w, dst_h};
1508 else
1509 Scaling = {SCALING_BILINEAR, SCALING_PIXELS, 0, 0, src_w, src_h, dst_h, dst_w};
1510
1511 switch (rotVal) {
1512 case 0:
1513 g2d_rotation = ORIGIN;
1514 break;
1515 case 90:
1516 g2d_rotation = ROT_90;
1517 break;
1518 case 180:
1519 g2d_rotation = ROT_180;
1520 break;
1521 case 270:
1522 g2d_rotation = ROT_270;
1523 break;
1524 default:
1525 LOGE("%s::invalid rotVal(%d) fail", __func__, rotVal);
1526 return -1;
1527 break;
1528 }
1529
1530 BlitParam = {BLIT_OP_SRC, NON_PREMULTIPLIED, 0xff, 0, g2d_rotation, &Scaling, 0, 0, &dstClip, 0, &srcImage, &dstImage, NULL, &srcRect, &dstRect, NULL, 0};
1531
1532 if (stretchFimgApi(&BlitParam) < 0) {
1533 LOGE("%s::stretchFimgApi() fail", __func__);
1534 return -1;
1535 }
1536
1537#ifdef DEBUG_MSG_ENABLE
1538 LOGD("hdmi_set_g_scaling:: \n \\
1539 layer=%d,\n \\
1540 srcColorFormat=%d,\n \\
1541 src_w=%d, src_h=%d,\n\\
1542 src_address=0x%x, dst_addr=0x%x,\n\\
1543 dst_x=%d, dst_y=%d, dst_w=%d, dst_h=%d ",
1544 layer,
1545 srcColorFormat,
1546 src_w, src_h,
1547 src_address, dst_addr,
1548 dst_x, dst_y, dst_w, dst_h);
1549#endif
1550 dstBuffer->virt.p = (char *)dst_addr;
1551 }
1552#else
1553 dstBuffer->virt.p = (char *)src_address;
1554#endif
1555
1556 return 0;
1557}
1558#else
1559int hdmi_set_v_param(int layer,
1560 int src_w, int src_h, int colorFormat,
1561 unsigned int src_y_address, unsigned int src_c_address,
1562 int dst_w, int dst_h)
1563{
1564#ifdef DEBUG_HDMI_HW_LEVEL
1565 LOGD("%s", __func__);
1566#endif
1567
1568 int round_up_src_w;
1569 int round_up_src_h;
1570 if (fp_tvout_v <= 0) {
1571 LOGE("fp_tvout is < 0 fail\n");
1572 return -1;
1573 }
1574
1575 /* src_w, src_h round up to DWORD because of VP restriction */
1576#if defined(SAMSUNG_EXYNOS4x12)
1577 round_up_src_w = ROUND_UP(src_w, 16);
1578#else defined(SAMSUNG_EXYNOS4210)
1579 round_up_src_w = ROUND_UP(src_w, 8);
1580#endif
1581 round_up_src_h = ROUND_UP(src_h, 8);
1582
1583 vo_param.src.base_y = (void *)src_y_address;
1584 vo_param.src.base_c = (void *)src_c_address;
1585 vo_param.src.pix_fmt.width = round_up_src_w;
1586 vo_param.src.pix_fmt.height = round_up_src_h;
1587 vo_param.src.pix_fmt.field = V4L2_FIELD_NONE;
1588 vo_param.src.pix_fmt.pixelformat = colorFormat;
1589
1590 tvout_v4l2_s_fmt(fp_tvout_v, V4L2_BUF_TYPE_PRIVATE, &vo_param.src);
1591
1592 vo_param.src_crop.width = src_w;
1593 vo_param.src_crop.height = src_h;
1594
1595 tvout_v4l2_s_crop(fp_tvout_v, V4L2_BUF_TYPE_PRIVATE, &vo_param.src_crop);
1596
1597 if (dst_w * src_h <= dst_h * src_w) {
1598 vo_param.dst_win.w.left = 0;
1599 vo_param.dst_win.w.top = (dst_h - ((dst_w * src_h) / src_w)) >> 1;
1600 vo_param.dst_win.w.width = dst_w;
1601 vo_param.dst_win.w.height = ((dst_w * src_h) / src_w);
1602 } else {
1603 vo_param.dst_win.w.left = (dst_w - ((dst_h * src_w) / src_h)) >> 1;
1604 vo_param.dst_win.w.top = 0;
1605 vo_param.dst_win.w.width = ((dst_h * src_w) / src_h);
1606 vo_param.dst_win.w.height = dst_h;
1607 }
1608
1609 vo_param.dst.fmt.priv = 10;
1610 vo_param.dst_win.global_alpha = 255;
1611 tvout_v4l2_s_fbuf(fp_tvout_v, &vo_param.dst);
1612 tvout_v4l2_s_fmt(fp_tvout_v, V4L2_BUF_TYPE_VIDEO_OVERLAY, &vo_param.dst_win);
1613
1614 return 0;
1615}
1616
1617int hdmi_gl_set_param(int layer,
1618 int srcColorFormat,
1619 int src_w, int src_h,
1620 unsigned int src_y_address, unsigned int src_c_address,
1621 int dst_x, int dst_y, int dst_w, int dst_h,
1622 int rotVal)
1623{
1624#if defined(BOARD_USES_FIMGAPI)
1625 int dst_color_format;
1626 int dst_bpp;
1627 unsigned char *dst_addr;
1628 fimg2d_blit BlitParam;
1629 rotation g2d_rotation;
1630
1631 fimg2d_addr srcAddr;
1632 fimg2d_image srcImage;
1633 fimg2d_rect srcRect;
1634
1635 fimg2d_addr dstAddr;
1636 fimg2d_image dstImage;
1637 fimg2d_rect dstRect;
1638
1639 fimg2d_clip dstClip;
1640 fimg2d_scale Scaling;
1641
1642 struct fb_var_screeninfo var;
1643 struct s5ptvfb_user_window window;
1644
1645 int fp_tvout_g;
1646
1647 if(layer == HDMI_LAYER_GRAPHIC_0)
1648 fp_tvout_g = fp_tvout_g0;
1649 else
1650 fp_tvout_g = fp_tvout_g1;
1651
1652 switch (t_std_id) {
1653 case V4L2_STD_1080P_60:
1654 case V4L2_STD_1080P_30:
1655 case V4L2_STD_1080I_60:
1656 case V4L2_STD_TVOUT_720P_60_SBS_HALF:
1657 case V4L2_STD_TVOUT_720P_59_SBS_HALF:
1658 case V4L2_STD_TVOUT_1080P_24_TB:
1659 case V4L2_STD_TVOUT_1080P_23_TB:
1660 dst_color_format = CF_ARGB_8888;
1661 dst_bpp = 4;
1662 var.bits_per_pixel = 32;
1663 var.transp.length = 8;
1664 break;
1665 case V4L2_STD_480P_60_16_9:
1666 case V4L2_STD_576P_50_16_9:
1667 case V4L2_STD_720P_60:
1668 case V4L2_STD_TVOUT_720P_50_TB:
1669 default:
1670 dst_color_format = CF_ARGB_4444;
1671 dst_bpp = 2;
1672 var.bits_per_pixel = 16;
1673 var.transp.length = 4;
1674 break;
1675 }
1676
1677 static unsigned int prev_src_addr = 0;
1678
1679 if ((cur_g2d_address == 0) || (src_y_address != prev_src_addr)) {
1680 dst_addr = (unsigned char *)g2d_reserved_memory[g2d_buf_index];
1681
1682 g2d_buf_index++;
1683 if (g2d_buf_index >= HDMI_G2D_OUTPUT_BUF_NUM)
1684 g2d_buf_index = 0;
1685
1686 cur_g2d_address = (unsigned int)dst_addr;
1687 prev_src_addr = src_y_address;
1688
1689 srcAddr = {(addr_space)ADDR_PHYS, (unsigned long)src_y_address, src_w*src_h*4, 1, 0};
1690 srcImage = {srcAddr, srcAddr, src_w, src_h, src_w*4, AX_RGB, CF_ARGB_8888};
1691 srcRect = {0, 0, src_w, src_h};
1692
1693 dstAddr = {(addr_space)ADDR_PHYS, (unsigned long)dst_addr, dst_w*dst_h*dst_bpp, 1, 0};
1694 dstImage = {dstAddr, dstAddr, dst_w, dst_h, dst_w*dst_bpp, AX_RGB, (color_format)dst_color_format};
1695 dstRect = {0, 0, dst_w, dst_h};
1696 dstClip = {0, 0, 0, dst_w, dst_h};
1697
1698 if (rotVal == 0 || rotVal == 180)
1699 Scaling = {SCALING_BILINEAR, SCALING_PIXELS, 0, 0, src_w, src_h, dst_w, dst_h};
1700 else
1701 Scaling = {SCALING_BILINEAR, SCALING_PIXELS, 0, 0, src_w, src_h, dst_h, dst_w};
1702
1703 switch (rotVal) {
1704 case 0:
1705 g2d_rotation = ORIGIN;
1706 break;
1707 case 90:
1708 g2d_rotation = ROT_90;
1709 break;
1710 case 180:
1711 g2d_rotation = ROT_180;
1712 break;
1713 case 270:
1714 g2d_rotation = ROT_270;
1715 break;
1716 default:
1717 LOGE("%s::invalid rotVal(%d) fail", __func__, rotVal);
1718 return -1;
1719 break;
1720 }
1721
1722 BlitParam = {BLIT_OP_SRC, NON_PREMULTIPLIED, 0xff, 0, g2d_rotation, &Scaling, 0, 0, &dstClip, 0, &srcImage, &dstImage, NULL, &srcRect, &dstRect, NULL, 0};
1723
1724 if (stretchFimgApi(&BlitParam) < 0) {
1725 LOGE("%s::stretchFimgApi() fail", __func__);
1726 return -1;
1727 }
1728
1729 var.xres = dst_w;
1730 var.yres = dst_h;
1731
1732 var.xres_virtual = var.xres;
1733 var.yres_virtual = var.yres;
1734 var.xoffset = 0;
1735 var.yoffset = 0;
1736 var.width = 0;
1737 var.height = 0;
1738 var.activate = FB_ACTIVATE_FORCE;
1739
1740 window.x = dst_x;
1741 window.y = dst_y;
1742
1743 tvout_v4l2_s_baseaddr(fp_tvout_g, (void *)dst_addr);
1744 put_vscreeninfo(fp_tvout_g, &var);
1745
1746 if (ioctl(fp_tvout_g, S5PTVFB_WIN_POSITION, &window) < 0) {
1747 LOGE("%s::S5PTVFB_WIN_POSITION ioctl failed.", __func__);
1748 return -1;
1749 }
1750 }
1751
1752 return 0;
1753#else
1754 struct fb_var_screeninfo var;
1755 struct s5ptvfb_user_window window;
1756
1757 struct overlay_param ov_param;
1758
1759 // set base address for grp layer0 of mixer
1760 int fp_tvout_g;
1761
1762#ifdef DEBUG_MSG_ENABLE
1763 LOGD("hdmi_gl_set_param:: \n \\
1764 layer=%d,\n \\
1765 srcColorFormat=%d,\n \\
1766 src_w=%d, src_h=%d,\n\\
1767 src_y_address=0x%x, src_c_address=0x%x,\n\\
1768 dst_x=%d, dst_y=%d, dst_w=%d, dst_h=%d ",
1769 layer,
1770 srcColorFormat,
1771 src_w, src_h,
1772 src_y_address, src_c_address,
1773 dst_x, dst_y, dst_w, dst_h);
1774#endif
1775
1776 if (layer == HDMI_LAYER_GRAPHIC_0)
1777 fp_tvout_g = fp_tvout_g0;
1778 else
1779 fp_tvout_g = fp_tvout_g1;
1780
1781 var.xres = src_w;
1782 var.yres = src_h;
1783 var.xres_virtual = var.xres;
1784 var.yres_virtual = var.yres;
1785 var.xoffset = 0;
1786 var.yoffset = 0;
1787 var.width = src_w;
1788 var.height = src_h;
1789 var.activate = FB_ACTIVATE_FORCE;
1790 if (srcColorFormat == HAL_PIXEL_FORMAT_RGB_565) {
1791 var.bits_per_pixel = 16;
1792 var.transp.length = 0;
1793 }
1794 else {
1795 var.bits_per_pixel = 32;
1796 var.transp.length = 8;
1797 }
1798
1799 window.x = dst_x;
1800 window.y = dst_y;
1801
1802 tvout_v4l2_s_baseaddr(fp_tvout_g, (void *)src_y_address);
1803 put_vscreeninfo(fp_tvout_g, &var);
1804 if (ioctl(fp_tvout_g, S5PTVFB_WIN_POSITION, &window) < 0) {
1805 LOGE("%s:: S5PTVFB_WIN_POSITION ioctl failed.", __func__);
1806 return -1;
1807 }
1808
1809 return 0;
1810#endif
1811}
1812#endif
1813
1814int hdmi_cable_status()
1815{
1816#if defined(BOARD_USE_V4L2)
1817#ifdef DEBUG_HDMI_HW_LEVEL
1818 LOGD("%s", __func__);
1819#endif
1820
1821 int cable_status = 0;
1822 int fd = 0;
1823 struct v4l2_control ctrl;
1824
1825 fd = open(TVOUT_DEV_G0, O_RDWR);
1826 if (fd <= 0) {
1827 LOGE("%s: graphic layer 0 drv open failed", __func__);
1828 return -1;
1829 }
1830
1831 ctrl.id = V4L2_CID_TV_HPD_STATUS;
1832
1833 if (ioctl(fd, VIDIOC_S_CTRL, &ctrl) < 0) {
1834 LOGE("Get HPD_STATUS fail");
1835 cable_status = -1;
1836 } else {
1837 cable_status = ctrl.value;
1838 }
1839
1840#ifdef DEBUG_HDMI_HW_LEVEL
1841 LOGD("HPD_STATUS = %d", cable_status);
1842#endif
1843
1844 close(fd);
1845
1846 return cable_status;
1847#else
1848 int cable_status = 0;
1849 int fp_hpd = 0;
1850
1851 fp_hpd = open(HPD_DEV, O_RDWR);
1852 if (fp_hpd <= 0) {
1853 LOGE("hpd drv open failed\n");
1854 return -1;
1855 }
1856
1857 //Delay about 0.3s
1858 usleep(500000);
1859 if (ioctl(fp_hpd, HPD_GET_STATE, &cable_status) < 0) {
1860 LOGE("hpd drv HPD_GET_STATE ioctl failed\n");
1861 cable_status = -1;
1862 }
1863
1864 close(fp_hpd);
1865
1866 return cable_status;
1867#endif
1868}
1869
1870int hdmi_outputmode_2_v4l2_output_type(int output_mode)
1871{
1872 int v4l2_output_type = -1;
1873
1874 switch (output_mode) {
1875 case HDMI_OUTPUT_MODE_YCBCR:
1876 v4l2_output_type = V4L2_OUTPUT_TYPE_DIGITAL;
1877 break;
1878 case HDMI_OUTPUT_MODE_RGB:
1879 v4l2_output_type = V4L2_OUTPUT_TYPE_HDMI_RGB;
1880 break;
1881 case HDMI_OUTPUT_MODE_DVI:
1882 v4l2_output_type = V4L2_OUTPUT_TYPE_DVI;
1883 break;
1884 case COMPOSITE_OUTPUT_MODE:
1885 v4l2_output_type = V4L2_OUTPUT_TYPE_COMPOSITE;
1886 break;
1887 default:
1888 LOGE("%s::unmathced HDMI_mode(%d)", __func__, output_mode);
1889 v4l2_output_type = -1;
1890 break;
1891 }
1892
1893 return v4l2_output_type;
1894}
1895
1896int hdmi_v4l2_output_type_2_outputmode(int v4l2_output_type)
1897{
1898 int outputMode = -1;
1899
1900 switch (v4l2_output_type) {
1901 case V4L2_OUTPUT_TYPE_DIGITAL:
1902 outputMode = HDMI_OUTPUT_MODE_YCBCR;
1903 break;
1904 case V4L2_OUTPUT_TYPE_HDMI_RGB:
1905 outputMode = HDMI_OUTPUT_MODE_RGB;
1906 break;
1907 case V4L2_OUTPUT_TYPE_DVI:
1908 outputMode = HDMI_OUTPUT_MODE_DVI;
1909 break;
1910 case V4L2_OUTPUT_TYPE_COMPOSITE:
1911 outputMode = COMPOSITE_OUTPUT_MODE;
1912 break;
1913 default:
1914 LOGE("%s::unmathced v4l2_output_type(%d)", __func__, v4l2_output_type);
1915 outputMode = -1;
1916 break;
1917 }
1918
1919 return outputMode;
1920}
1921
1922int composite_std_2_v4l2_std_id(int std)
1923{
1924 int std_id = -1;
1925
1926 switch (std) {
1927 case COMPOSITE_STD_NTSC_M:
1928 std_id = V4L2_STD_NTSC_M;
1929 break;
1930 case COMPOSITE_STD_NTSC_443:
1931 std_id = V4L2_STD_NTSC_443;
1932 break;
1933 case COMPOSITE_STD_PAL_BDGHI:
1934 std_id = V4L2_STD_PAL_BDGHI;
1935 break;
1936 case COMPOSITE_STD_PAL_M:
1937 std_id = V4L2_STD_PAL_M;
1938 break;
1939 case COMPOSITE_STD_PAL_N:
1940 std_id = V4L2_STD_PAL_N;
1941 break;
1942 case COMPOSITE_STD_PAL_Nc:
1943 std_id = V4L2_STD_PAL_Nc;
1944 break;
1945 case COMPOSITE_STD_PAL_60:
1946 std_id = V4L2_STD_PAL_60;
1947 break;
1948 default:
1949 LOGE("%s::unmathced composite_std(%d)", __func__, std);
1950 break;
1951 }
1952
1953 return std_id;
1954}
1955
1956int hdmi_check_output_mode(int v4l2_output_type)
1957{
1958 struct HDMIVideoParameter video;
1959 struct HDMIAudioParameter audio;
1960 int calbirate_v4l2_mode = v4l2_output_type;
1961
1962 audio.formatCode = LPCM_FORMAT;
1963 audio.outPacket = HDMI_ASP;
1964 audio.channelNum = CH_2;
1965 audio.sampleFreq = SF_44KHZ;
1966
1967 switch (v4l2_output_type) {
1968 case V4L2_OUTPUT_TYPE_DIGITAL :
1969 video.mode = HDMI;
1970 if (!EDIDHDMIModeSupport(&video)) {
1971 calbirate_v4l2_mode = V4L2_OUTPUT_TYPE_DVI;
1972 LOGI("Change mode into DVI\n");
1973 break;
1974 }
1975
1976 video.colorSpace = HDMI_CS_YCBCR444;
1977 if (!EDIDColorSpaceSupport(&video)) {
1978 calbirate_v4l2_mode = V4L2_OUTPUT_TYPE_HDMI_RGB;
1979 LOGI("Change mode into HDMI_RGB\n");
1980 }
1981 break;
1982
1983 case V4L2_OUTPUT_TYPE_HDMI_RGB:
1984 video.mode = HDMI;
1985 if (!EDIDHDMIModeSupport(&video)) {
1986 calbirate_v4l2_mode = V4L2_OUTPUT_TYPE_DVI;
1987 LOGI("Change mode into DVI\n");
1988 break;
1989 }
1990
1991 video.colorSpace = HDMI_CS_RGB;
1992 if (!EDIDColorSpaceSupport(&video)) {
1993 calbirate_v4l2_mode = V4L2_OUTPUT_TYPE_DIGITAL;
1994 LOGI("Change mode into HDMI_YCBCR\n");
1995 }
1996 break;
1997
1998 case V4L2_OUTPUT_TYPE_DVI:
1999 video.mode = DVI;
2000 if (!EDIDHDMIModeSupport(&video)) {
2001 video.colorSpace = HDMI_CS_YCBCR444;
2002 if (!EDIDColorSpaceSupport(&video)) {
2003 calbirate_v4l2_mode = V4L2_OUTPUT_TYPE_HDMI_RGB;
2004 LOGI("Change mode into HDMI_RGB\n");
2005 } else {
2006 calbirate_v4l2_mode = V4L2_OUTPUT_TYPE_DIGITAL;
2007 LOGI("Change mode into HDMI_YCBCR\n");
2008 }
2009 break;
2010 }
2011
2012 break;
2013
2014 default:
2015 break;
2016 }
2017 return calbirate_v4l2_mode;
2018}
2019
2020#if defined(BOARD_USE_V4L2)
2021int hdmi_check_resolution(unsigned int preset_id)
2022{
2023 struct HDMIVideoParameter video;
2024 struct HDMIAudioParameter audio;
2025
2026 switch (preset_id) {
2027 case V4L2_DV_480P60:
2028 video.resolution = v720x480p_60Hz;
2029 video.pixelAspectRatio = HDMI_PIXEL_RATIO_16_9;
2030 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2031 break;
2032 case V4L2_DV_576P50:
2033 video.resolution = v720x576p_50Hz;
2034 video.pixelAspectRatio = HDMI_PIXEL_RATIO_16_9;
2035 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2036 break;
2037 case V4L2_DV_720P60:
2038 video.resolution = v1280x720p_60Hz;
2039 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2040 break;
2041 case V4L2_DV_720P50:
2042 video.resolution = v1280x720p_50Hz;
2043 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2044 break;
2045 case V4L2_DV_1080P60:
2046 video.resolution = v1920x1080p_60Hz;
2047 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2048 break;
2049 case V4L2_DV_1080P50:
2050 video.resolution = v1920x1080p_50Hz;
2051 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2052 break;
2053 case V4L2_DV_1080I60:
2054 video.resolution = v1920x1080i_60Hz;
2055 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2056 break;
2057 case V4L2_DV_1080I50:
2058 video.resolution = v1920x1080i_50Hz;
2059 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2060 break;
2061 case V4L2_DV_480P59_94:
2062 video.resolution = v720x480p_60Hz;
2063 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2064 break;
2065 case V4L2_DV_720P59_94:
2066 video.resolution = v1280x720p_60Hz;
2067 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2068 break;
2069 case V4L2_DV_1080I59_94:
2070 video.resolution = v1920x1080i_60Hz;
2071 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2072 break;
2073 case V4L2_DV_1080P59_94:
2074 video.resolution = v1920x1080p_60Hz;
2075 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2076 break;
2077 case V4L2_DV_1080P30:
2078 video.resolution = v1920x1080p_30Hz;
2079 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2080 break;
2081 case V4L2_DV_720P60_SB_HALF:
2082 video.resolution = v1280x720p_60Hz;
2083 video.hdmi_3d_format = HDMI_3D_SSH_FORMAT;
2084 break;
2085 case V4L2_DV_720P59_94_SB_HALF:
2086 video.resolution = v1280x720p_60Hz;
2087 video.hdmi_3d_format = HDMI_3D_SSH_FORMAT;
2088 break;
2089 case V4L2_DV_720P50_TB:
2090 video.resolution = v1280x720p_50Hz;
2091 video.hdmi_3d_format = HDMI_3D_TB_FORMAT;
2092 break;
2093 case V4L2_DV_1080P24_TB:
2094 video.resolution = v1920x1080p_24Hz;
2095 video.hdmi_3d_format = HDMI_3D_TB_FORMAT;
2096 break;
2097 case V4L2_DV_1080P23_98_TB:
2098 video.resolution = v1920x1080p_24Hz;
2099 video.hdmi_3d_format = HDMI_3D_TB_FORMAT;
2100 break;
2101 default:
2102 LOGE("%s::unmathced preset_id(%d)", __func__, preset_id);
2103 return -1;
2104 break;
2105 }
2106
2107 if (!EDIDVideoResolutionSupport(&video)) {
2108#ifdef DEBUG_MSG_ENABLE
2109 LOGD("%s::EDIDVideoResolutionSupport(%d) fail (not suppoted preset_id) \n", __func__, preset_id);
2110#endif
2111 return -1;
2112 }
2113
2114 return 0;
2115}
2116
2117int hdmi_resolution_2_preset_id(unsigned int resolution, int * w, int * h, unsigned int *preset_id)
2118{
2119 int ret = 0;
2120
2121 switch (resolution) {
2122 case 1080960:
2123 *w = 1920;
2124 *h = 1080;
2125 *preset_id = V4L2_DV_1080P60;
2126 break;
2127 case 1080950:
2128 *w = 1920;
2129 *h = 1080;
2130 *preset_id = V4L2_DV_1080P50;
2131 break;
2132 case 1080930:
2133 *w = 1920;
2134 *h = 1080;
2135 *preset_id = V4L2_DV_1080P30;
2136 break;
2137 case 1080924:
2138 *w = 1920;
2139 *h = 1080;
2140 *preset_id = V4L2_DV_1080P24_TB;
2141 break;
2142 case 1080160:
2143 *w = 1920;
2144 *h = 1080;
2145 *preset_id = V4L2_DV_1080I60;
2146 break;
2147 case 1080150:
2148 *w = 1920;
2149 *h = 1080;
2150 *preset_id = V4L2_DV_1080I50;
2151 break;
2152 case 720960:
2153 *w = 1280;
2154 *h = 720;
2155 *preset_id = V4L2_DV_720P60;
2156 break;
2157 case 7209601:
2158 *w = 1280;
2159 *h = 720;
2160 *preset_id = V4L2_DV_720P60_SB_HALF;
2161 break;
2162 case 720950:
2163 *w = 1280;
2164 *h = 720;
2165 *preset_id = V4L2_DV_720P50;
2166 break;
2167 case 7209501:
2168 *w = 1280;
2169 *h = 720;
2170 *preset_id = V4L2_DV_720P50_TB;
2171 break;
2172 case 5769501:
2173 *w = 720;
2174 *h = 576;
2175 *preset_id = V4L2_DV_576P50;
2176 break;
2177 case 5769502:
2178 *w = 720;
2179 *h = 576;
2180 *preset_id = V4L2_DV_576P50;
2181 break;
2182 case 4809601:
2183 *w = 720;
2184 *h = 480;
2185 *preset_id = V4L2_DV_480P60;
2186 break;
2187 case 4809602:
2188 *w = 720;
2189 *h = 480;
2190 *preset_id = V4L2_DV_480P60;
2191 break;
2192 default:
2193 LOGE("%s::unmathced resolution(%d)", __func__, resolution);
2194 ret = -1;
2195 break;
2196 }
2197
2198 return ret;
2199}
2200#else
2201int hdmi_check_resolution(v4l2_std_id std_id)
2202{
2203 struct HDMIVideoParameter video;
2204 struct HDMIAudioParameter audio;
2205
2206 switch (std_id) {
2207 case V4L2_STD_480P_60_16_9:
2208 video.resolution = v720x480p_60Hz;
2209 video.pixelAspectRatio = HDMI_PIXEL_RATIO_16_9;
2210 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2211 break;
2212 case V4L2_STD_480P_60_4_3:
2213 video.resolution = v640x480p_60Hz;
2214 video.pixelAspectRatio = HDMI_PIXEL_RATIO_4_3;
2215 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2216 break;
2217 case V4L2_STD_576P_50_16_9:
2218 video.resolution = v720x576p_50Hz;
2219 video.pixelAspectRatio = HDMI_PIXEL_RATIO_16_9;
2220 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2221 break;
2222 case V4L2_STD_576P_50_4_3:
2223 video.resolution = v720x576p_50Hz;
2224 video.pixelAspectRatio = HDMI_PIXEL_RATIO_4_3;
2225 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2226 break;
2227 case V4L2_STD_720P_60:
2228 video.resolution = v1280x720p_60Hz;
2229 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2230 break;
2231 case V4L2_STD_720P_50:
2232 video.resolution = v1280x720p_50Hz;
2233 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2234 break;
2235 case V4L2_STD_1080P_60:
2236 video.resolution = v1920x1080p_60Hz;
2237 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2238 break;
2239 case V4L2_STD_1080P_50:
2240 video.resolution = v1920x1080p_50Hz;
2241 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2242 break;
2243 case V4L2_STD_1080I_60:
2244 video.resolution = v1920x1080i_60Hz;
2245 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2246 break;
2247 case V4L2_STD_1080I_50:
2248 video.resolution = v1920x1080i_50Hz;
2249 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2250 break;
2251 case V4L2_STD_480P_59:
2252 video.resolution = v720x480p_60Hz;
2253 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2254 break;
2255 case V4L2_STD_720P_59:
2256 video.resolution = v1280x720p_60Hz;
2257 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2258 break;
2259 case V4L2_STD_1080I_59:
2260 video.resolution = v1920x1080i_60Hz;
2261 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2262 break;
2263 case V4L2_STD_1080P_59:
2264 video.resolution = v1920x1080p_60Hz;
2265 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2266 break;
2267 case V4L2_STD_1080P_30:
2268 video.resolution = v1920x1080p_30Hz;
2269 video.hdmi_3d_format = HDMI_2D_VIDEO_FORMAT;
2270 break;
2271 case V4L2_STD_TVOUT_720P_60_SBS_HALF:
2272 video.resolution = v1280x720p_60Hz;
2273 video.hdmi_3d_format = HDMI_3D_SSH_FORMAT;
2274 break;
2275 case V4L2_STD_TVOUT_720P_59_SBS_HALF:
2276 video.resolution = v1280x720p_60Hz;
2277 video.hdmi_3d_format = HDMI_3D_SSH_FORMAT;
2278 break;
2279 case V4L2_STD_TVOUT_720P_50_TB:
2280 video.resolution = v1280x720p_50Hz;
2281 video.hdmi_3d_format = HDMI_3D_TB_FORMAT;
2282 break;
2283 case V4L2_STD_TVOUT_1080P_24_TB:
2284 video.resolution = v1920x1080p_24Hz;
2285 video.hdmi_3d_format = HDMI_3D_TB_FORMAT;
2286 break;
2287 case V4L2_STD_TVOUT_1080P_23_TB:
2288 video.resolution = v1920x1080p_24Hz;
2289 video.hdmi_3d_format = HDMI_3D_TB_FORMAT;
2290 break;
2291 default:
2292 LOGE("%s::unmathced std_id(%lld)", __func__, std_id);
2293 return -1;
2294 break;
2295 }
2296
2297 if (!EDIDVideoResolutionSupport(&video)) {
2298#ifdef DEBUG_MSG_ENABLE
2299 LOGD("%s::EDIDVideoResolutionSupport(%llx) fail (not suppoted std_id) \n", __func__, std_id);
2300#endif
2301 return -1;
2302 }
2303
2304 return 0;
2305}
2306
2307int hdmi_resolution_2_std_id(unsigned int resolution, int * w, int * h, v4l2_std_id * std_id)
2308{
2309 int ret = 0;
2310
2311 switch (resolution) {
2312 case 1080960:
2313 *std_id = V4L2_STD_1080P_60;
2314 *w = 1920;
2315 *h = 1080;
2316 break;
2317 case 1080950:
2318 *std_id = V4L2_STD_1080P_50;
2319 *w = 1920;
2320 *h = 1080;
2321 break;
2322 case 1080930:
2323 *std_id = V4L2_STD_1080P_30;
2324 *w = 1920;
2325 *h = 1080;
2326 break;
2327 case 1080924:
2328 *std_id = V4L2_STD_TVOUT_1080P_24_TB;
2329 *w = 1920;
2330 *h = 1080;
2331 break;
2332 case 1080160:
2333 *std_id = V4L2_STD_1080I_60;
2334 *w = 1920;
2335 *h = 1080;
2336 break;
2337 case 1080150:
2338 *std_id = V4L2_STD_1080I_50;
2339 *w = 1920;
2340 *h = 1080;
2341 break;
2342 case 720960:
2343 *std_id = V4L2_STD_720P_60;
2344 *w = 1280;
2345 *h = 720;
2346 break;
2347 case 7209601:
2348 *std_id = V4L2_STD_TVOUT_720P_60_SBS_HALF;
2349 *w = 1280;
2350 *h = 720;
2351 break;
2352 case 720950:
2353 *std_id = V4L2_STD_720P_50;
2354 *w = 1280;
2355 *h = 720;
2356 break;
2357 case 7209501:
2358 *std_id = V4L2_STD_TVOUT_720P_50_TB;
2359 *w = 1280;
2360 *h = 720;
2361 break;
2362 case 5769501:
2363 *std_id = V4L2_STD_576P_50_16_9;
2364 *w = 720;
2365 *h = 576;
2366 break;
2367 case 5769502:
2368 *std_id = V4L2_STD_576P_50_4_3;
2369 *w = 720;
2370 *h = 576;
2371 break;
2372 case 4809601:
2373 *std_id = V4L2_STD_480P_60_16_9;
2374 *w = 720;
2375 *h = 480;
2376 break;
2377 case 4809602:
2378 *std_id = V4L2_STD_480P_60_4_3;
2379 *w = 720;
2380 *h = 480;
2381 break;
2382 default:
2383 LOGE("%s::unmathced resolution(%d)", __func__, resolution);
2384 ret = -1;
2385 break;
2386 }
2387
2388 return ret;
2389}
2390#endif
2391
2392int hdmi_enable_hdcp(unsigned int hdcp_en)
2393{
2394 if (ioctl(fp_tvout, VIDIOC_HDCP_ENABLE, hdcp_en) < 0) {
2395 LOGD("%s::VIDIOC_HDCP_ENABLE(%d) fail \n", __func__, hdcp_en);
2396 return -1;
2397 }
2398
2399 return 0;
2400}
2401
2402int hdmi_check_audio(void)
2403{
2404 struct HDMIAudioParameter audio;
2405 enum state audio_state = ON;
2406 int ret = 0;
2407
2408 audio.formatCode = LPCM_FORMAT;
2409 audio.outPacket = HDMI_ASP;
2410 audio.channelNum = CH_2;
2411 audio.sampleFreq = SF_44KHZ;
2412
2413#if defined(BOARD_USES_EDID)
2414 if (!EDIDAudioModeSupport(&audio))
2415 audio_state = NOT_SUPPORT;
2416 else
2417 audio_state = ON;
2418#endif
2419 if (audio_state == ON) {
2420 if (ioctl(fp_tvout, VIDIOC_INIT_AUDIO, 1) < 0) {
2421 LOGE("%s::VIDIOC_INIT_AUDIO(1) fail", __func__);
2422 ret = -1;
2423 }
2424 } else {
2425 if (ioctl(fp_tvout, VIDIOC_INIT_AUDIO, 0) < 0) {
2426 LOGE("%s::VIDIOC_INIT_AUDIO(0) fail", __func__);
2427 ret = -1;
2428 }
2429 }
2430
2431 return ret;
2432}
2433
2434}