summaryrefslogtreecommitdiff
path: root/tvapi/libtv/tvin/CTvin.cpp (plain)
blob: 66a2a1f707ea45934d5d1b76c99e7003ed7dfc2c
1
2#include "CTvin.h"
3#include <CTvLog.h>
4#include <stdio.h>
5#include <unistd.h>
6#include <sys/types.h>
7#include <sys/stat.h>
8#include <sys/ioctl.h>
9#include <fcntl.h>
10#include <string.h>
11#include <errno.h>
12#include <dlfcn.h>
13#include <linux/fb.h>
14#include <stdlib.h>
15#include <cutils/properties.h>
16#include <cutils/log.h>
17#include <sys/mman.h>
18#include "../vpp/CPQdb.h"
19#include "CAv.h"
20#include "../tvsetting/CTvSetting.h"
21#include "../tvutils/tvutils.h"
22#include "../tvconfig/tvconfig.h"
23#include "CFbcCommunication.h"
24
25
26#ifdef LOG_TAG
27#undef LOG_TAG
28#define LOG_TAG "CTvin"
29#endif
30
31#define AFE_DEV_PATH "/dev/tvafe0"
32#define HDMIRX_KSV_PATH "/dev/hdmirx0"
33
34
35#define CC_SEL_VDIN_DEV (0)
36
37#define MODE_3D_DISABLE 0x00000000
38#define MODE_3D_ENABLE 0x00000001
39#define MODE_AUTO 0x00000002
40#define MODE_2D_TO_3D 0x00000004
41#define MODE_LR 0x00000008
42#define MODE_BT 0x00000010
43#define MODE_LR_SWITCH 0x00000020
44#define MODE_FIELD_DEPTH 0x00000040
45#define MODE_3D_TO_2D_L 0x00000080
46#define MODE_3D_TO_2D_R 0x00000100
47#define LR_FORMAT_INDICATOR 0x00000200
48#define BT_FORMAT_INDICATOR 0x00000400
49
50/* ADC calibration pattern & format define */
51/* default 100% 8 color-bar */
52//#define VGA_SOURCE_RGB444
53#define VGA_H_ACTIVE (1024)
54#define VGA_V_ACTIVE (768)
55#define COMP_H_ACTIVE (1280)
56#define COMP_V_ACTIVE (720)
57#define CVBS_H_ACTIVE (720)
58#define CVBS_V_ACTIVE (480)
59
60#define FBIOPUT_OSD_FREE_SCALE_ENABLE 0x4504
61#define FBIOPUT_OSD_FREE_SCALE_WIDTH 0x4505
62#define FBIOPUT_OSD_FREE_SCALE_HEIGHT 0x4506
63
64typedef enum {
65 VIEWMODE_NULL = 0,
66 VIEWMODE_4_3,
67 VIEWMODE_16_9
68} view_mode_t;
69int CTvin::mSourceInputToPortMap[SOURCE_MAX];
70CTvin::CTvin()
71{
72 int i = 0;
73
74 m_vdin_dev_fd = -1;
75 afe_dev_fd = -1;
76
77 m_tvin_param.index = 0;
78 m_is_decoder_start = false;
79 gExistD2D3 = -1;
80 gVideoPath[0] = '\0';
81 m_pathid = TV_PATH_DECODER_3D_AMVIDEO;
82
83 for (i = 0; i < SOURCE_MAX; i++) {
84 mSourceInputToPortMap[i] = TVIN_PORT_NULL;
85 }
86
87 mSourceInputToPortMap[SOURCE_TV] = TVIN_PORT_CVBS3;
88 mSourceInputToPortMap[SOURCE_AV1] = TVIN_PORT_CVBS1;
89 mSourceInputToPortMap[SOURCE_AV2] = TVIN_PORT_CVBS2;
90 mSourceInputToPortMap[SOURCE_YPBPR1] = TVIN_PORT_COMP0;
91 mSourceInputToPortMap[SOURCE_YPBPR2] = TVIN_PORT_COMP1;
92 mSourceInputToPortMap[SOURCE_HDMI1] = TVIN_PORT_HDMI0;
93 mSourceInputToPortMap[SOURCE_HDMI2] = TVIN_PORT_HDMI2;
94 mSourceInputToPortMap[SOURCE_HDMI3] = TVIN_PORT_HDMI1;
95 mSourceInputToPortMap[SOURCE_VGA] = TVIN_PORT_VGA0;
96 mSourceInputToPortMap[SOURCE_MPEG] = TVIN_PORT_MPEG0;
97 mSourceInputToPortMap[SOURCE_DTV] = TVIN_PORT_DTV;
98 mSourceInputToPortMap[SOURCE_IPTV] = TVIN_PORT_BT656;
99}
100
101CTvin::~CTvin()
102{
103
104}
105
106int CTvin::OpenTvin()
107{
108 const char *config_value;
109 config_value = config_get_str ( "TV", "tvin.manual.set.tvpath", "null" );
110 strcpy ( config_tv_path, config_value );
111 memset ( config_default_path, 0x0, 64 );
112 config_value = config_get_str ( "TV", "tvin.manual.set.defaultpath", "null" );
113 strcpy ( config_default_path, config_value );
114 return 0;
115}
116
117int CTvin::IsFileExist ( const char *file_name )
118{
119 struct stat tmp_st;
120
121 if ( stat ( file_name, &tmp_st ) < 0 ) {
122 return 0;
123 }
124
125 return 1;
126}
127
128char *CTvin::DelSub ( char *str, char *sub )
129{
130 char *psrc = str, *pdest = str, *psub = NULL, *p = NULL;
131
132 if ( ( str == NULL ) || ( sub == NULL ) ) {
133 return NULL;
134 }
135
136 while ( *psrc ) {
137 p = psrc;
138 psub = sub;
139
140 while ( *p && *p == *psub ) {
141 p++;
142 psub++;
143 }
144
145 if ( *psub == 0 ) {
146 psrc = p;
147 } else {
148 *pdest++ = *psrc++;
149 }
150 }
151
152 *pdest = 0;
153
154 return str;
155}
156
157int CTvin::setMpeg2Vdin(int enable)
158{
159 /* let output data loop to vdin */
160 FILE *fp = fopen ( "/sys/module/di/parameters/mpeg2vdin_en", "w" );
161
162 if ( fp == NULL ) {
163 LOGW ( "Open /sys/module/di/parameters/mpeg2vdin_en error\n" );
164 return -1;
165 }
166 fprintf ( fp, "%d", enable );
167 fclose ( fp );
168 return 0;
169}
170
171char *CTvin::VDIN_CheckVideoPath ( const char *videopath )
172{
173 strncpy ( gVideoPath, videopath, sizeof ( gVideoPath ) );
174
175 if ( strstr ( videopath, "d2d3 " ) != NULL ) {
176 if ( gExistD2D3 == -1 ) {
177 gExistD2D3 = IsFileExist ( "/sys/class/d2d3/d2d3" );
178 }
179
180 if ( gExistD2D3 == 0 ) {
181 DelSub ( gVideoPath, "d2d3 " );
182 }
183 }
184
185 LOGW ( "%s, video path before check [%s]\n", "TV", videopath );
186 LOGW ( "%s, video path after check [%s]\n", "TV", gVideoPath );
187
188 return gVideoPath;
189}
190
191int CTvin::VDIN_AddPath ( const char *videopath )
192{
193 FILE *fp = NULL;
194 int ret = -1;
195 char *tmp_video_path = NULL;
196
197 tmp_video_path = VDIN_CheckVideoPath ( videopath );
198
199 fp = fopen ( "/sys/class/vfm/map", "w" );
200
201 if ( fp == NULL ) {
202 LOGW ( "Open /sys/class/vfm/map error(%s)!\n", strerror ( errno ) );
203 return -1;
204 }
205
206 ret = fprintf ( fp, "%s", tmp_video_path );
207
208 if ( ret < 0 ) {
209 LOGW ( "Add VideoPath error(%s)!\n", strerror ( errno ) );
210 }
211
212 fclose ( fp );
213 fp = NULL;
214
215 return ret;
216}
217
218int CTvin::VDIN_RmDefPath ( void )
219{
220 int fd = -1, ret;
221 char str[] = "rm default";
222
223
224 fd = open ( "/sys/class/vfm/map", O_RDWR );
225
226 if ( fd < 0 ) {
227 LOGW ( "Open /sys/class/vfm/map error(%s)!\n", strerror ( errno ) );
228 return -1;
229 }
230
231 ret = write ( fd, str, sizeof ( str ) );
232
233 if ( ret < 0 ) {
234 LOGW ( "Rm default path error(%s)!\n", strerror ( errno ) );
235 }
236
237 close ( fd );
238 fd = -1;
239
240 return ret;
241}
242
243int CTvin::VDIN_RmTvPath ( void )
244{
245 int fd, ret;
246 char str[] = "rm tvpath";
247
248
249 fd = open ( "/sys/class/vfm/map", O_RDWR );
250
251 if ( fd < 0 ) {
252 LOGW ( "Open /sys/class/vfm/map error(%s)!\n", strerror ( errno ) );
253 return -1;
254 }
255
256 ret = write ( fd, str, sizeof ( str ) );
257
258 if ( ret <= 0 ) {
259 LOGW ( "Rm tv path error(%s)!\n", strerror ( errno ) );
260 }
261
262 close ( fd );
263 fd = -1;
264 return ret;
265}
266
267int CTvin::VDIN_AddVideoPath ( int selPath )
268{
269 int ret = -1;
270 char prop_value[PROPERTY_VALUE_MAX];
271
272 switch ( selPath ) {
273 case TV_PATH_VDIN_AMVIDEO:
274 ret = VDIN_AddPath ( "add tvpath vdin0 amvideo" );
275 break;
276
277 case TV_PATH_VDIN_DEINTERLACE_AMVIDEO:
278 ret = VDIN_AddPath ( "add tvpath vdin0 deinterlace amvideo" );
279 break;
280
281 case TV_PATH_VDIN_3D_AMVIDEO:
282 ret = VDIN_AddPath ( "add tvpath vdin0 ppmgr amvideo" );
283 break;
284
285 case TV_PATH_VDIN_NEW3D_AMVIDEO:
286 ret = VDIN_AddPath ( "add tvpath vdin0 deinterlace ppmgr d2d3 amvideo" );
287 break;
288
289 case TV_PATH_VDIN_NEW3D_WITHOUTPPMGR_AMVIDEO:
290 ret = VDIN_AddPath ( "add tvpath vdin0 deinterlace d2d3 amvideo" );
291 break;
292
293 case TV_PATH_DECODER_3D_AMVIDEO:
294 ret = VDIN_AddPath ( "add default decoder ppmgr deinterlace amvideo" );
295 break;
296
297 case TV_PATH_DECODER_AMVIDEO:
298 ret = VDIN_AddPath ( "add default decoder deinterlace amvideo" );
299 break;
300
301 case TV_PATH_VDIN_FREESCALE_AMVIDEO:
302 ret = VDIN_AddPath ( "add previewpath vdin0 freescale amvideo" );
303 break;
304
305 case TV_PATH_DECODER_NEW3D_AMVIDEO:
306 ret = VDIN_AddPath ( "add default decoder deinterlace ppmgr d2d3 amvideo" );
307 break;
308
309 case TV_PATH_DECODER_NEW3D_WITHOUTPPMGR_AMVIDEO:
310 ret = VDIN_AddPath ( "add default decoder deinterlace d2d3 amvideo" );
311 break;
312 }
313
314 return ret;
315}
316
317int CTvin::VDIN_RmPreviewPath ( void )
318{
319 int fd, ret;
320 char str[] = "rm previewpath";
321
322
323 fd = open ( "/sys/class/vfm/map", O_RDWR );
324
325 if ( fd < 0 ) {
326 LOGW ( "Open /sys/class/vfm/map error(%s)!\n", strerror ( errno ) );
327 return -1;
328 }
329
330 ret = write ( fd, str, sizeof ( str ) );
331
332 if ( ret < 0 ) {
333 LOGW ( "Rm tv path error(%s)!\n", strerror ( errno ) );
334 }
335
336 close ( fd );
337 fd = -1;
338
339 return ret;
340}
341int CTvin::VDIN_OpenModule()
342{
343 char file_name[64];
344 sprintf ( file_name, "/dev/vdin%d", CC_SEL_VDIN_DEV );
345 m_vdin_dev_fd = open ( file_name, O_RDWR );
346
347 if ( m_vdin_dev_fd < 0 ) {
348 LOGW ( "Open %s error(%s)!\n", file_name, strerror ( errno ) );
349 return -1;
350 }
351
352 memset ( &gTvinVDINParam, 0, sizeof ( gTvinVDINParam ) );
353 memset ( &gTvinVDINSignalInfo, 0, sizeof ( gTvinVDINSignalInfo ) );
354
355 LOGD ( "Open vdin module vdin_dev_fd = [%d]", m_vdin_dev_fd );
356
357 return m_vdin_dev_fd;
358}
359
360int CTvin::VDIN_GetVdinFd()
361{
362 return m_vdin_dev_fd;
363}
364
365int CTvin::VDIN_CloseModule()
366{
367 if ( m_vdin_dev_fd != -1 ) {
368 close ( m_vdin_dev_fd );
369 m_vdin_dev_fd = -1;
370 }
371
372 return 0;
373}
374
375int CTvin::VDIN_DeviceIOCtl ( int request, ... )
376{
377 int tmp_ret = -1;
378 va_list ap;
379 void *arg;
380
381 if ( m_vdin_dev_fd >= 0 ) {
382 va_start ( ap, request );
383 arg = va_arg ( ap, void * );
384 va_end ( ap );
385
386 tmp_ret = ioctl ( m_vdin_dev_fd, request, arg );
387 return tmp_ret;
388 }
389
390 return -1;
391}
392
393int CTvin::VDIN_OpenPort ( tvin_port_t port )
394{
395 int rt = -1;
396 struct tvin_parm_s vdinParam;
397 vdinParam.port = port;
398 vdinParam.index = 0;
399 rt = VDIN_DeviceIOCtl ( TVIN_IOC_OPEN, &vdinParam );
400
401 if ( rt < 0 ) {
402 LOGW ( "Vdin open port, error(%s)!", strerror ( errno ) );
403 }
404
405 return rt;
406}
407
408int CTvin::VDIN_ClosePort()
409{
410 int rt = -1;
411
412 rt = VDIN_DeviceIOCtl ( TVIN_IOC_CLOSE );
413
414 if ( rt < 0 ) {
415 LOGW ( "Vdin close port, error(%s)!", strerror ( errno ) );
416 }
417
418 return rt;
419}
420
421int CTvin::VDIN_StartDec ( const struct tvin_parm_s *vdinParam )
422{
423 int rt = -1;
424
425 if ( vdinParam == NULL ) {
426 return -1;
427 }
428
429 rt = VDIN_DeviceIOCtl ( TVIN_IOC_START_DEC, vdinParam );
430
431 LOGD ( "VDIN_StartDec:\n" );
432 LOGD ( "index = [%d]\n", vdinParam->index );
433 LOGD ( "port = [0x%x]\n", ( unsigned int ) vdinParam->port );
434 LOGD ( "format = [0x%x]\n", ( unsigned int ) ( vdinParam->info.fmt ) );
435
436 if ( rt < 0 ) {
437 LOGW ( "Vdin start decode, error(%s)!\n", strerror ( errno ) );
438 }
439
440 return rt;
441}
442
443int CTvin::VDIN_StopDec()
444{
445 int rt = -1;
446
447 rt = VDIN_DeviceIOCtl ( TVIN_IOC_STOP_DEC );
448
449 if ( rt < 0 ) {
450 LOGW ( "Vdin stop decode, error(%s)", strerror ( errno ) );
451 }
452
453 return rt;
454}
455
456int CTvin::VDIN_GetSignalInfo ( struct tvin_info_s *SignalInfo )
457{
458 int rt = -1;
459
460 rt = VDIN_DeviceIOCtl ( TVIN_IOC_G_SIG_INFO, SignalInfo );
461
462 if ( rt < 0 ) {
463 LOGW ( "Vdin get signal info, error(%s), ret = %d.\n", strerror ( errno ), rt );
464 //system("reboot");
465 }
466
467 return rt;
468}
469
470int CTvin::VDIN_SetVdinParam ( const struct tvin_parm_s *vdinParam )
471{
472 int rt = -1, i = 0;
473
474 rt = VDIN_DeviceIOCtl ( TVIN_IOC_S_PARM, vdinParam );
475
476 if ( rt < 0 ) {
477 LOGW ( "Vdin set signal param, error(%s)\n", strerror ( errno ) );
478 }
479
480 return rt;
481}
482
483int CTvin::VDIN_GetVdinParam ( const struct tvin_parm_s *vdinParam )
484{
485 int rt = -1, i = 0;
486
487 rt = VDIN_DeviceIOCtl ( TVIN_IOC_G_PARM, vdinParam );
488
489 if ( rt < 0 ) {
490 LOGW ( "Vdin get signal param, error(%s)\n", strerror ( errno ) );
491 }
492
493 return rt;
494}
495
496int CTvin::VDIN_OnoffVScaler ( int isOn )
497{
498 FILE *fp = NULL;
499
500 if ( isOn == 1 ) {
501 isOn = 1;
502 } else {
503 isOn = 0;
504 }
505
506
507 fp = fopen ( "/sys/class/video/vscaler", "w" );
508
509 if ( fp == NULL ) {
510 LOGW ( "Open /sys/class/video/vscaler error(%s)!\n", strerror ( errno ) );
511 return -1;
512 }
513
514 fprintf ( fp, "%d", ( int ) isOn );
515
516 fclose ( fp );
517 fp = NULL;
518
519 return 0;
520}
521
522int CTvin::VDIN_GetDisplayVFreq (void)
523{
524 int fd = -1;
525 char buf[32];
526
527 fd = open("/sys/class/display/mode", O_RDWR);
528 if (fd < 0) {
529 LOGW("Open /sys/class/display/mode error(%s)!\n", strerror(errno));
530 return -1;
531 }
532 memset(buf, 0, sizeof(buf));
533 read(fd, buf, sizeof(buf));
534 close(fd);
535 LOGD( "s%, VDIN_GetDisplayVFreq is %s\n", __FUNCTION__, buf);
536 if (strstr(buf, "50hz") != NULL) {
537 return 50;
538 } else if (strstr(buf, "60hz") != 0) {
539 return 60;
540 } else {
541 return 50;
542 }
543}
544
545int CTvin::VDIN_SetDisplayVFreq ( int freq, int display_resolution , bool isFbc)
546{
547 FILE *fp = NULL;
548 const char *config_value = NULL;
549 static int display_mode_type = -1;
550 CFbcCommunication *pFBC = NULL;
551 static int last_freq = 50;
552
553 last_freq = VDIN_GetDisplayVFreq();
554 if (last_freq == freq) {
555 LOGD ( "%s, same freq, last_freq = %d, freq = %d.", __FUNCTION__, last_freq, freq);
556 return 0;
557 } else {
558 LOGD ( "%s, from last_freq[%d[ to new_freq[%d].", __FUNCTION__, last_freq, freq);
559 last_freq = freq;
560 }
561
562 if (display_mode_type == -1) {
563 config_value = config_get_str ( "TV", "tvin.display.mode.type", "null" );
564 if (strcasecmp(config_value, "null") == 0 || strcasecmp(config_value, "hdmi_out") == 0) {
565 display_mode_type = 0;
566 } else if (strcasecmp(config_value, "lvds_out") == 0) {
567 display_mode_type = 1;
568 } else {
569 display_mode_type = 0;
570 }
571 }
572
573 fp = fopen ( "/sys/class/display/mode", "w" );
574
575 if ( fp == NULL ) {
576 LOGW ( "Open /sys/class/display/mode error(%s)!\n", strerror ( errno ) );
577 return -1;
578 }
579
580 if ( isFbc ) {
581 pFBC = GetSingletonFBC();
582 if (pFBC != NULL) {
583 pFBC->cfbc_Set_VMute (COMM_DEV_SERIAL, 2);
584 usleep ( 300000 );
585 }
586 }
587
588 switch ( display_resolution ) {
589 case VPP_DISPLAY_RESOLUTION_1366X768:
590 if ( freq == 50 ) {
591 fprintf ( fp, "%s", "768p50hz" );
592 } else {
593 fprintf ( fp, "%s", "768p60hz" );
594 }
595 break;
596 case VPP_DISPLAY_RESOLUTION_3840X2160:
597 if ( freq == 50 ) {
598 if (isFbc) {
599 fprintf ( fp, "%s", "2160p50hz420" );
600 } else {
601 fprintf ( fp, "%s", "2160p50hz" );
602 }
603 } else {
604 if (isFbc) {
605 fprintf ( fp, "%s", "2160p60hz420" );
606 } else {
607 fprintf ( fp, "%s", "2160p60hz" );
608 }
609 }
610 break;
611 case VPP_DISPLAY_RESOLUTION_1920X1080:
612 default:
613 if ( freq == 50 ) {
614 fprintf ( fp, "%s", "1080p50hz" );
615 } else {
616 fprintf ( fp, "%s", "1080p60hz" );
617 }
618 break;
619 }
620
621 fclose ( fp );
622 fp = NULL;
623
624 return 0;
625}
626
627void CTvin::Tvin_SetDepthOf2Dto3D ( int value )
628{
629 //value = -16~16
630 int tmp_value = DepthTable_2DTO3D[value + 16];
631 LOGD ( "%s, value: %d", __FUNCTION__, value );
632 VDIN_Set2D3DDepth ( value );
633}
634
635
636int CTvin::VDIN_Set2D3DDepth ( int count )
637{
638 FILE *fp = NULL;
639
640
641 fp = fopen ( "/sys/module/d2d3/parameters/depth", "w" );
642
643 if ( fp == NULL ) {
644 LOGW ( "Open /sys/module/d2d3/parameters/depth ERROR(%s)!!\n", strerror ( errno ) );
645 return -1;
646 }
647
648 if ( count >= -127 && count <= 127 ) {
649#ifdef LOGD_3D_FUNCTION
650 LOGD ( "set depth value (%d).\n", count );
651#endif
652 } else {
653 count = 8 * 12;
654 LOGE ( "set depth value ERROR!! set default depth.\n" );
655 }
656
657 fprintf ( fp, "%d", count );
658 fclose ( fp );
659 fp = NULL;
660
661 return 0;
662}
663
664int CTvin::VDIN_Set2Dto3D ( int on_off )
665{
666 struct tvin_parm_s VdinParam;
667 VDIN_GetVdinParam ( &VdinParam );
668 VdinParam.flag &= ( ~TVIN_PARM_FLAG_2D_TO_3D );
669 VdinParam.flag |= ( on_off ) ? ( TVIN_PARM_FLAG_2D_TO_3D ) : ( 0 );
670 return VDIN_SetVdinParam ( &VdinParam );
671}
672
673int CTvin::VDIN_Get_avg_luma(void)
674{
675 unsigned int lum_sum,pixel_sum,luma_avg;
676 struct tvin_parm_s vdinParam;
677
678 if ( 0 == VDIN_GetVdinParam( &vdinParam )) {
679 lum_sum = vdinParam.luma_sum;
680 pixel_sum = vdinParam.pixel_sum*2;
681 if (pixel_sum != 0 && m_is_decoder_start) {
682 luma_avg = lum_sum/pixel_sum;
683 } else {
684 luma_avg = 116;
685 }
686 } else {
687 return -1;
688 }
689 LOGD ( "VDIN_get_avg_lut lum_sum =%d,pixel_sum=%d,lut_avg=%d\n", lum_sum,pixel_sum,luma_avg);
690 return luma_avg;
691}
692
693int CTvin::VDIN_GetHistgram ( int *hisgram )
694{
695 int i = 0;
696 struct tvin_parm_s vdinParam;
697
698 if ( NULL == hisgram ) {
699 return -1;
700 }
701
702 if ( 0 == VDIN_GetVdinParam ( &vdinParam ) ) {
703 for ( i = 0; i < CC_HIST_GRAM_BUF_SIZE; i++ ) {
704 hisgram[i] = ( int ) vdinParam.histgram[i];
705 }
706 } else {
707 return -1;
708 }
709
710 return 0;
711}
712
713int CTvin::VDIN_SetMVCViewMode ( int mode )
714{
715 FILE *fp = NULL;
716
717
718 fp = fopen ( "/sys/module/amvdec_h264mvc/parameters/view_mode", "w" );
719
720 if ( fp == NULL ) {
721 LOGW ( "Open /sys/module/amvdec_h264mvc/parameters/view_mode error(%s)!\n", strerror ( errno ) );
722 return -1;
723 }
724
725 fprintf ( fp, "%d", ( int ) mode );
726
727 fclose ( fp );
728 fp = NULL;
729
730 return 0;
731}
732
733int CTvin::VDIN_GetMVCViewMode ( void )
734{
735 FILE *fp = NULL;
736 int ret = 0;
737 int mode = 0;
738
739
740 fp = fopen ( "/sys/module/amvdec_h264mvc/parameters/view_mode", "w" );
741
742 if ( fp == NULL ) {
743 LOGW ( "Open /sys/module/amvdec_h264mvc/parameters/view_mode ERROR(%s)!!\n", strerror ( errno ) );
744 return -1;
745 }
746
747 ret = fread ( &mode, 1, 1, fp );
748 LOGD ( "fread /sys/module/amvdec_h264mvc/parameters/view_mode = [%d]", mode );
749
750 fclose ( fp );
751 fp = NULL;
752
753 return mode;
754}
755
756int CTvin::VDIN_SetDIBuffMgrMode ( int mgr_mode )
757{
758 FILE *fp = NULL;
759
760
761 fp = fopen ( "sys/module/di/parameters/buf_mgr_mode", "w" );
762
763 if ( fp == NULL ) {
764 LOGW ( "Open /sys/module/di/parameters/buf_mgr_mode error(%s)!\n", strerror ( errno ) );
765 return -1;
766 }
767
768 fprintf ( fp, "%d", mgr_mode );
769
770 fclose ( fp );
771 fp = NULL;
772
773 return 0;
774}
775
776int CTvin::VDIN_SetDICFG ( int cfg )
777{
778 FILE *fp = NULL;
779
780
781 fp = fopen ( "sys/class/deinterlace/di0/config", "w" );
782
783 if ( fp == NULL ) {
784 LOGW ( "Open /sys/class/deinterlace/di0/config error(%s)!\n", strerror ( errno ) );
785 return -1;
786 }
787
788 if ( 0 == cfg ) {
789 fprintf ( fp, "%s", "disable" );
790 } else {
791 fprintf ( fp, "%s", "enable" );
792 }
793
794 fclose ( fp );
795 fp = NULL;
796
797 return 0;
798}
799
800int CTvin::VDIN_SetDI3DDetc ( int enable )
801{
802 FILE *fp = NULL;
803
804
805 fp = fopen ( "/sys/module/di/parameters/det3d_en", "w" );
806
807 if ( fp == NULL ) {
808 LOGW ( "Open /sys/module/di/parameters/det3d_en error(%s)!\n", strerror ( errno ) );
809 return -1;
810 }
811
812 fprintf ( fp, "%d", enable );
813
814
815 fclose ( fp );
816 fp = NULL;
817
818 return 0;
819}
820
821int CTvin::VDIN_Get3DDetc ( void )
822{
823 int fd = -1;
824 int ret = -1;
825 char buf[10];
826
827
828 fd = open ( "/sys/module/di/parameters/det3d_en", O_RDWR );
829
830 if ( fd < 0 ) {
831 LOGW ( "Open /sys/module/di/parameters/det3d_en error(%s)!\n", strerror ( errno ) );
832 return -1;
833 }
834
835 ret = read ( fd, buf, sizeof ( buf ) );
836
837 close ( fd );
838 fd = -1;
839
840
841 if ( strcmp ( "enable", buf ) == 0 ) {
842 return 1;
843 } else {
844 return 0;
845 }
846}
847
848
849int CTvin::VDIN_GetVscalerStatus ( void )
850{
851 int fd = -1;
852 int ret = -1;
853 char buf[7];
854
855
856 fd = open ( "/sys/class/video/vscaler", O_RDWR );
857
858 if ( fd < 0 ) {
859 LOGW ( "Open /sys/class/video/vscaler error(%s)!\n", strerror ( errno ) );
860 return -1;
861 }
862
863 ret = read ( fd, buf, sizeof ( buf ) );
864
865 close ( fd );
866 fd = -1;
867
868 sscanf ( buf, "%d", &ret );
869
870 ret = ( ( ret & 0x40000 ) == 0 ) ? 1 : 0;
871
872 if ( ret == 1 ) {
873 sleep ( 1 );
874 }
875
876 return ret;
877}
878
879int CTvin::VDIN_TurnOnBlackBarDetect ( int isEnable )
880{
881 FILE *fp = NULL;
882
883
884 fp = fopen ( "/sys/module/tvin_vdin/parameters/black_bar_enable", "w" );
885
886 if ( fp == NULL ) {
887 LOGW ( "Open /sys/module/tvin_vdin/parameters/black_bar_enable error(%s)!\n", strerror ( errno ) );
888 return -1;
889 }
890
891 fprintf ( fp, "%d", isEnable );
892
893 fclose ( fp );
894 fp = NULL;
895
896 return 0;
897}
898
899int CTvin::VDIN_LoadHdcpKey ( unsigned char *hdcpkey_buff )
900{
901 unsigned char testHdcp[368] = { 0x53, 0x4B, 0x59, 0x01, 0x00, 0x10, 0x0D, 0x15, 0x3A, 0x8E, 0x99, 0xEE, 0x2A, 0x55, 0x58, 0xEE, 0xED, 0x4B, 0xBE, 0x00, 0x74, 0xA9, 0x00, 0x10, 0x0A, 0x21, 0xE3,
902 0x30, 0x66, 0x34, 0xCE, 0x9C, 0xC7, 0x8B, 0x51, 0x27, 0xF9, 0x0B, 0xAD, 0x09, 0x5F, 0x4D, 0xC2, 0xCA, 0xA2, 0x13, 0x06, 0x18, 0x8D, 0x34, 0x82, 0x46, 0x2D, 0xC9, 0x4B, 0xB0, 0x1C, 0xDE,
903 0x3D, 0x49, 0x39, 0x58, 0xEF, 0x2B, 0x68, 0x39, 0x71, 0xC9, 0x4D, 0x25, 0xE9, 0x75, 0x4D, 0xAC, 0x62, 0xF5, 0xF5, 0x87, 0xA0, 0xB2, 0x4A, 0x60, 0xD3, 0xF1, 0x09, 0x3A, 0xB2, 0x3E, 0x19,
904 0x4F, 0x3B, 0x1B, 0x2F, 0x85, 0x14, 0x28, 0x44, 0xFC, 0x69, 0x6F, 0x50, 0x42, 0x81, 0xBF, 0x7C, 0x2B, 0x3A, 0x17, 0x2C, 0x15, 0xE4, 0x93, 0x77, 0x74, 0xE8, 0x1F, 0x1C, 0x38, 0x54, 0x49,
905 0x10, 0x64, 0x5B, 0x7D, 0x90, 0x3D, 0xA0, 0xE1, 0x8B, 0x67, 0x5C, 0x19, 0xE6, 0xCA, 0x9D, 0xE9, 0x68, 0x5A, 0xB5, 0x62, 0xDF, 0xA1, 0x28, 0xBC, 0x68, 0x82, 0x9A, 0x22, 0xC4, 0xDC, 0x48,
906 0x85, 0x0F, 0xF1, 0x3E, 0x05, 0xDD, 0x1B, 0x2D, 0xF5, 0x49, 0x3A, 0x15, 0x29, 0xE7, 0xB6, 0x0B, 0x2A, 0x40, 0xE3, 0xB0, 0x89, 0xD5, 0x75, 0x84, 0x2E, 0x76, 0xE7, 0xBC, 0x63, 0x67, 0xE3,
907 0x57, 0x67, 0x86, 0x81, 0xF4, 0xD7, 0xEA, 0x4D, 0x89, 0x8E, 0x37, 0x95, 0x59, 0x1C, 0x8A, 0xCD, 0x79, 0xF8, 0x4F, 0x82, 0xF2, 0x6C, 0x7E, 0x7F, 0x79, 0x8A, 0x6B, 0x90, 0xC0, 0xAF, 0x4C,
908 0x8D, 0x43, 0x47, 0x1F, 0x9A, 0xF1, 0xBB, 0x88, 0x64, 0x49, 0x14, 0x50, 0xD1, 0xC3, 0xDF, 0xA6, 0x87, 0xA0, 0x15, 0x98, 0x51, 0x81, 0xF5, 0x97, 0x55, 0x10, 0x4A, 0x99, 0x30, 0x54, 0xA4,
909 0xFC, 0xDA, 0x0E, 0xAC, 0x6A, 0xFA, 0x90, 0xEE, 0x12, 0x70, 0x69, 0x74, 0x63, 0x46, 0x63, 0xFB, 0xE6, 0x1F, 0x72, 0xEC, 0x43, 0x5D, 0x50, 0xFF, 0x03, 0x4F, 0x05, 0x33, 0x88, 0x36, 0x93,
910 0xE4, 0x72, 0xD5, 0xCC, 0x34, 0x52, 0x96, 0x15, 0xCE, 0xD0, 0x32, 0x52, 0x41, 0x4F, 0xBC, 0x2D, 0xDF, 0xC5, 0xD6, 0x7F, 0xD5, 0x74, 0xCE, 0x51, 0xDC, 0x10, 0x5E, 0xF7, 0xAA, 0x4A, 0x2D,
911 0x20, 0x9A, 0x17, 0xDD, 0x30, 0x89, 0x71, 0x82, 0x36, 0x50, 0x09, 0x1F, 0x7C, 0xF3, 0x12, 0xE9, 0x43, 0x10, 0x5F, 0x51, 0xBF, 0xB8, 0x45, 0xA8, 0x5A, 0x8D, 0x3F, 0x77, 0xE5, 0x96, 0x73,
912 0x68, 0xAB, 0x73, 0xE5, 0x4C, 0xFB, 0xE5, 0x98, 0xB9, 0xAE, 0x74, 0xEB, 0x51, 0xDB, 0x91, 0x07, 0x7B, 0x66, 0x02, 0x9B, 0x79, 0x03, 0xC5, 0x34, 0x1C, 0x58, 0x13, 0x31, 0xD2, 0x4A, 0xEC
913 };
914 int ret = -1;
915 int fd = -1;
916
917
918 fd = open ( "/sys/class/hdmirx/hdmirx0/edid", O_RDWR );
919
920 if ( fd < 0 ) {
921 LOGW ( "Open hdmi hdcp key error(%s)!!\n", strerror ( errno ) );
922 return -1;
923 }
924
925 ret = write ( fd, testHdcp, 368 );
926
927 if ( ret < 0 ) {
928 LOGD ( "Write hdmi hdcp key error(%s)!!\n", strerror ( errno ) );
929 }
930
931 close ( fd );
932 fd = -1;
933
934 return ret;
935}
936
937int CTvin::VDIN_KeepLastFrame ( int enable )
938{
939 FILE *fp = NULL;
940
941 return 0;
942
943
944 fp = fopen ( "/sys/module/amvideo/parameters/keep_old_frame", "w" );
945
946 if ( fp == NULL ) {
947 LOGW ( "Open /sys/module/amvideo/parameters/keep_old_frame error(%s)!\n", strerror ( errno ) );
948 return -1;
949 }
950
951 fprintf ( fp, "%d", enable );
952
953 fclose ( fp );
954 fp = NULL;
955
956 return 0;
957}
958
959int CTvin::VDIN_SetVideoFreeze ( int enable )
960{
961 FILE *fp = NULL;
962
963
964 fp = fopen ( "/sys/class/vdin/vdin0/attr", "w" );
965
966 if ( fp == NULL ) {
967 LOGW ( "Open /sys/class/vdin/vdin0/attr error(%s)!\n", strerror ( errno ) );
968 return -1;
969 }
970
971 if ( enable == 1 ) {
972 fprintf ( fp, "freeze" );
973 } else {
974 fprintf ( fp, "unfreeze" );
975 }
976
977 fclose ( fp );
978 fp = NULL;
979
980 return 0;
981}
982
983int CTvin::VDIN_SetDIBypasshd ( int enable )
984{
985 FILE *fp = NULL;
986
987
988 fp = fopen ( "/sys/module/di/parameters/bypass_hd", "w" );
989
990 if ( fp == NULL ) {
991 LOGW ( "Open /sys/module/di/parameters/bypass_hd error(%s)!\n", strerror ( errno ) );
992 return -1;
993 }
994
995 fprintf ( fp, "%d", enable );
996
997 fclose ( fp );
998 fp = NULL;
999
1000 return 0;
1001}
1002
1003int CTvin::VDIN_SetDIBypassAll ( int enable )
1004{
1005 FILE *fp = NULL;
1006
1007 fp = fopen ( "/sys/module/di/parameters/bypass_all", "w" );
1008
1009 if ( fp == NULL ) {
1010 LOGW ( "Open /sys/module/di/parameters/bypass_all error(%s)!\n", strerror ( errno ) );
1011 return -1;
1012 }
1013
1014 fprintf ( fp, "%d", enable );
1015 fclose ( fp );
1016 fp = NULL;
1017 return 0;
1018}
1019
1020int CTvin::VDIN_SetDIBypass_Get_Buf_Threshold ( int enable )
1021{
1022 FILE *fp = NULL;
1023
1024
1025 fp = fopen ( "/sys/module/di/parameters/bypass_get_buf_threshold", "w" );
1026
1027 if ( fp == NULL ) {
1028 LOGW ( "Open /sys/module/di/parameters/bypass_get_buf_threshold error(%s)!\n", strerror ( errno ) );
1029 return -1;
1030 }
1031
1032 fprintf ( fp, "%d", enable );
1033
1034 fclose ( fp );
1035 fp = NULL;
1036
1037 return 0;
1038
1039}
1040
1041int CTvin::VDIN_SetDIBypassProg ( int enable )
1042{
1043 FILE *fp = NULL;
1044
1045
1046 fp = fopen ( "/sys/module/di/parameters/bypass_prog", "w" );
1047
1048 if ( fp == NULL ) {
1049 LOGW ( "Open /sys/module/di/parameters/bypass_prog error(%s)!\n", strerror ( errno ) );
1050 return -1;
1051 }
1052
1053 fprintf ( fp, "%d", enable );
1054
1055 fclose ( fp );
1056 fp = NULL;
1057
1058 return 0;
1059}
1060
1061int CTvin::VDIN_SetDIBypassDynamic ( int flag )
1062{
1063 FILE *fp = NULL;
1064
1065
1066 fp = fopen ( "/sys/module/di/parameters/bypass_dynamic", "w" );
1067
1068 if ( fp == NULL ) {
1069 LOGW ( "Open /sys/module/di/parameters/bypass_dynamic error(%s)!\n", strerror ( errno ) );
1070 return -1;
1071 }
1072
1073 fprintf ( fp, "%d", flag );
1074
1075 fclose ( fp );
1076 fp = NULL;
1077
1078 return 0;
1079}
1080
1081int CTvin::VDIN_SetDIDet3DMode ( int value )
1082{
1083 FILE *fp = NULL;
1084
1085
1086 fp = fopen ( "/sys/module/di/parameters/det3d_mode", "w" );
1087
1088 if ( fp == NULL ) {
1089 LOGW ( "Open /sys/module/di/parameters/det3d_mode error(%s)!\n", strerror ( errno ) );
1090 return -1;
1091 }
1092
1093 fprintf ( fp, "%d", value );
1094
1095 fclose ( fp );
1096 fp = NULL;
1097
1098 return 0;
1099}
1100
1101int CTvin::VDIN_SetDIBypass3D ( int enable )
1102{
1103 FILE *fp = NULL;
1104
1105
1106 fp = fopen ( "/sys/module/di/parameters/bypass_3d", "w" );
1107
1108 if ( fp == NULL ) {
1109 LOGW ( "Open /sys/module/di/parameters/bypass_3d error(%s)!\n", strerror ( errno ) );
1110 return -1;
1111 }
1112
1113 fprintf ( fp, "%d", enable );
1114
1115 fclose ( fp );
1116 fp = NULL;
1117
1118 return 0;
1119}
1120
1121int CTvin::VDIN_SetDIBypassPost ( int enable )
1122{
1123 FILE *fp = NULL;
1124
1125
1126 fp = fopen ( "/sys/module/di/parameters/bypass_post", "w" );
1127
1128 if ( fp == NULL ) {
1129 LOGW ( "Open /sys/module/di/parameters/bypass_post error(%s)!\n", strerror ( errno ) );
1130 return -1;
1131 }
1132
1133 fprintf ( fp, "%d", enable );
1134
1135 fclose ( fp );
1136 fp = NULL;
1137
1138 return 0;
1139}
1140
1141int CTvin::set3D_FL_Frame(int value)
1142{
1143 FILE *fp = NULL;
1144 fp = fopen ( "/sys/module/amvideo/parameters/pause_one_3d_fl_frame", "w" );
1145 if ( fp == NULL ) {
1146 LOGW ( "Open /sys/module/amvideo/parameters/pause_one_3d_fl_frame error(%s)!\n", strerror ( errno ) );
1147 return -1;
1148 }
1149 fprintf ( fp, "%d", value );
1150 fclose ( fp );
1151 fp = NULL;
1152 return 0;
1153}
1154
1155int CTvin::setLatchFlag(int value)
1156{
1157 int fd = -1;
1158 int nodeVal = 0;
1159 char s[10];
1160 FILE *fp = NULL;
1161 memset(s, 0, sizeof(s));
1162 read(fd, s, sizeof(s));
1163 close(fd);
1164 nodeVal = atoi(s);
1165 fp = fopen ( "/sys/module/am_vecm/parameters/vecm_latch_flag", "w" );
1166 if ( fp == NULL ) {
1167 LOGW ( "/sys/module/am_vecm/parameters/vecm_latch_flag error(%s)!\n", strerror ( errno ) );
1168 return -1;
1169 }
1170 fprintf ( fp, "%d", value | nodeVal);
1171 fclose ( fp );
1172 fp = NULL;
1173 LOGD ( "read vecm_latch_flag = (%s)====(0x%x), then set vecm_latch_flag | 0x%x = 0x%x.\n", s, nodeVal, value, value | nodeVal);
1174 return 0;
1175}
1176
1177int CTvin::VDIN_SetDIProg_Proc_Config ( int value )
1178{
1179 FILE *fp = NULL;
1180
1181
1182 fp = fopen ( "/sys/module/di/parameters/prog_proc_config", "w" );
1183
1184 if ( fp == NULL ) {
1185 LOGW ( "Open /sys/module/di/parameters/prog_proc_config error(%s)!\n", strerror ( errno ) );
1186 return -1;
1187 }
1188
1189
1190 fprintf ( fp, "%d", value );
1191
1192 fclose ( fp );
1193 fp = NULL;
1194
1195 return 0;
1196}
1197#if(1)
1198int CTvin::VDIN_SetDIInput2Pre ( int value )
1199{
1200 FILE *fp = NULL;
1201
1202
1203 fp = fopen ( "/sys/module/di/parameters/input2pre", "w" );
1204
1205 if ( fp == NULL ) {
1206 LOGW ( "Open /sys/module/di/parameters/input2pre error(%s)!\n", strerror ( errno ) );
1207 return -1;
1208 }
1209
1210 fprintf ( fp, "%d", value );
1211
1212 fclose ( fp );
1213 fp = NULL;
1214
1215 return 0;
1216
1217}
1218#endif
1219int CTvin::VDIN_SetVdinFlag ( int flag )
1220{
1221 FILE *fp = NULL;
1222 int freq = 1200000;
1223
1224 fp = fopen ( "/sys/class/vdin/memp", "w" );
1225
1226 if ( fp == NULL ) {
1227 LOGW ( "Open /sys/class/vdin/memp error(%s)!\n", strerror ( errno ) );
1228 return -1;
1229 }
1230
1231 fprintf ( fp, "%d", flag );
1232 fclose ( fp );
1233 fp = NULL;
1234
1235 return 0;
1236}
1237
1238int CTvin::VDIN_EnableRDMA ( int enable )
1239{
1240 FILE *fp = NULL;
1241 fp = fopen ( "/sys/module/rdma/parameters/enable", "w" );
1242
1243 if ( fp == NULL ) {
1244 LOGW ( "Open /sys/module/rdma/parameters/enable error(%s)!\n", strerror ( errno ) );
1245 return -1;
1246 }
1247
1248 fprintf ( fp, "%d", enable );
1249 fclose ( fp );
1250 fp = NULL;
1251 return 0;
1252}
1253
1254// AFE
1255int CTvin::AFE_OpenModule ( void )
1256{
1257
1258 if ( afe_dev_fd < 0 ) {
1259 afe_dev_fd = open ( AFE_DEV_PATH, O_RDWR );
1260
1261 if ( afe_dev_fd < 0 ) {
1262 LOGW ( "Open tvafe module, error(%s).\n", strerror ( errno ) );
1263 return -1;
1264 }
1265 }
1266
1267 return afe_dev_fd;
1268}
1269
1270void CTvin::AFE_CloseModule ( void )
1271{
1272 if ( afe_dev_fd >= 0 ) {
1273 close ( afe_dev_fd );
1274 afe_dev_fd = -1;
1275 }
1276
1277 return;
1278}
1279
1280int CTvin::AFE_DeviceIOCtl ( int request, ... )
1281{
1282 int tmp_ret = -1;
1283 va_list ap;
1284 void *arg;
1285
1286
1287 if ( afe_dev_fd >= 0 ) {
1288 va_start ( ap, request );
1289 arg = va_arg ( ap, void * );
1290 va_end ( ap );
1291
1292 tmp_ret = ioctl ( afe_dev_fd, request, arg );
1293
1294 return tmp_ret;
1295 }
1296
1297 return -1;
1298}
1299
1300int CTvin::AFE_GetDeviceFileHandle()
1301{
1302 return afe_dev_fd;
1303}
1304
1305int CTvin::AFE_SetVGAEdid ( const unsigned char *ediddata )
1306{
1307 int rt = -1;
1308 struct tvafe_vga_edid_s vgaEdid;
1309
1310#ifdef NO_IC_TEST
1311
1312 for ( int i = 0; i < 256; i++ ) {
1313 test_edid[i] = ediddata[i];
1314 }
1315
1316#endif
1317
1318 for ( int i = 0; i < 256; i++ ) {
1319 vgaEdid.value[i] = ediddata[i];
1320 }
1321
1322 rt = AFE_DeviceIOCtl ( TVIN_IOC_S_AFE_VGA_EDID, &vgaEdid );
1323
1324 if ( rt < 0 ) {
1325 LOGW ( "AFE_SetVGAEdid, error(%s).!\n", strerror ( errno ) );
1326 }
1327
1328 return rt;
1329}
1330
1331int CTvin::AFE_GetVGAEdid ( unsigned char *ediddata )
1332{
1333 int rt = -1;
1334 struct tvafe_vga_edid_s vgaEdid;
1335
1336#ifdef NO_IC_TEST
1337
1338 for ( int i = 0; i < 256; i++ ) {
1339 ediddata[i] = test_edid[i];
1340 }
1341
1342 LOGD ( "AFE_GetVGAEdid:\n" );
1343 LOGD ( "===================================================\n" );
1344
1345 for ( int i = 0; i < 256; i++ ) {
1346 LOGD ( "vag edid[%d] = [0x%x].\n", i, ediddata[i] );
1347 }
1348
1349 LOGD ( "===================================================\n" );
1350#endif
1351
1352 rt = AFE_DeviceIOCtl ( TVIN_IOC_G_AFE_VGA_EDID, &vgaEdid );
1353
1354 for ( int i = 0; i < 256; i++ ) {
1355 ediddata[i] = vgaEdid.value[i];
1356 }
1357
1358 if ( rt < 0 ) {
1359 LOGW ( "AFE_GetVGAEdid, error(%s)!\n", strerror ( errno ) );
1360 }
1361
1362 return rt;
1363}
1364
1365int CTvin::AFE_SetADCTimingAdjust ( const struct tvafe_vga_parm_s *timingadj )
1366{
1367 int rt = -1;
1368
1369 if ( timingadj == NULL ) {
1370 return rt;
1371 }
1372
1373 rt = AFE_DeviceIOCtl ( TVIN_IOC_S_AFE_VGA_PARM, timingadj );
1374
1375 if ( rt < 0 ) {
1376 LOGW ( "AFE_SetADCTimingAdjust, error(%s)!\n", strerror ( errno ) );
1377 }
1378
1379 return rt;
1380}
1381
1382int CTvin::AFE_GetADCCurrentTimingAdjust ( struct tvafe_vga_parm_s *timingadj )
1383{
1384 int rt = -1;
1385
1386 if ( timingadj == NULL ) {
1387 return rt;
1388 }
1389
1390 rt = AFE_DeviceIOCtl ( TVIN_IOC_G_AFE_VGA_PARM, timingadj );
1391
1392 if ( rt < 0 ) {
1393 LOGW ( "AFE_GetADCCurrentTimingAdjust, error(%s)!\n", strerror ( errno ) );
1394 return -1;
1395 }
1396
1397 return 0;
1398}
1399
1400int CTvin::AFE_VGAAutoAdjust ( struct tvafe_vga_parm_s *timingadj )
1401{
1402 enum tvafe_cmd_status_e CMDStatus = TVAFE_CMD_STATUS_PROCESSING;
1403 struct tvin_parm_s tvin_para;
1404 int rt = -1, i = 0;
1405
1406 if ( timingadj == NULL ) {
1407 return -1;
1408 }
1409
1410 for ( i = 0, CMDStatus == TVAFE_CMD_STATUS_PROCESSING; i < 50; i++ ) {
1411 rt = AFE_DeviceIOCtl ( TVIN_IOC_G_AFE_CMD_STATUS, &CMDStatus );
1412
1413 if ( rt < 0 ) {
1414 LOGD ( "get afe CMD status, error(%s), fd(%d), return(%d).\n", strerror ( errno ), AFE_GetDeviceFileHandle(), rt );
1415 }
1416
1417 if ( ( CMDStatus == TVAFE_CMD_STATUS_IDLE ) || ( CMDStatus == TVAFE_CMD_STATUS_SUCCESSFUL ) ) {
1418 break;
1419 }
1420
1421 usleep ( 10 * 1000 );
1422 }
1423
1424 if ( ( CMDStatus == TVAFE_CMD_STATUS_PROCESSING ) || ( CMDStatus == TVAFE_CMD_STATUS_FAILED ) ) {
1425 return -1;
1426 }
1427
1428 for ( i = 0; i < 100; i++ ) {
1429 rt = VDIN_DeviceIOCtl ( TVIN_IOC_G_PARM, &tvin_para );
1430
1431 if ( tvin_para.info.status == TVIN_SIG_STATUS_STABLE ) {
1432 break;
1433 }
1434
1435 usleep ( 10 * 1000 );
1436 }
1437
1438 rt = AFE_DeviceIOCtl ( TVIN_IOC_S_AFE_VGA_AUTO );
1439
1440 if ( rt < 0 ) {
1441 timingadj->clk_step = 0;
1442 timingadj->phase = 0;
1443 timingadj->hpos_step = 0;
1444 timingadj->vpos_step = 0;
1445 AFE_DeviceIOCtl ( TVIN_IOC_S_AFE_VGA_PARM, timingadj );
1446 return rt;
1447 } else {
1448 ;//AFE_DeviceIOCtl(TVIN_IOC_G_AFE_VGA_PARM, timingadj);
1449 }
1450
1451 for ( i = 0; i < 10; i++ ) {
1452 sleep ( 1 );
1453
1454 rt = AFE_DeviceIOCtl ( TVIN_IOC_G_AFE_CMD_STATUS, &CMDStatus );
1455
1456 if ( rt < 0 ) {
1457 return rt;
1458 } else {
1459 if ( CMDStatus == TVAFE_CMD_STATUS_SUCCESSFUL ) {
1460 usleep ( 100 * 1000 );
1461 AFE_GetADCCurrentTimingAdjust ( timingadj );
1462 LOGD ( "===================================================\n" );
1463 LOGW ( "AFE_VGAAutoAdjust, successfull!\n" );
1464 return 0;
1465 }
1466 }
1467 }
1468
1469 return -1;
1470}
1471
1472int CTvin::AFE_SetVGAAutoAjust ( void )
1473{
1474 int rt = -1;
1475 tvafe_vga_parm_t timingadj;
1476 tvafe_cmd_status_t Status;
1477 rt = AFE_DeviceIOCtl ( TVIN_IOC_G_AFE_CMD_STATUS, &Status );
1478
1479 if ( ( Status == TVAFE_CMD_STATUS_IDLE ) || ( Status == TVAFE_CMD_STATUS_SUCCESSFUL ) ) {
1480 ;
1481 } else {
1482 LOGW ( "AFE_SetVGAAutoAjust, TVIN_IOC_G_AFE_CMD_STATUS failed!\n" );
1483 return -1;
1484 }
1485
1486 rt = AFE_DeviceIOCtl ( TVIN_IOC_S_AFE_VGA_AUTO );
1487
1488 if ( rt < 0 ) {
1489 timingadj.clk_step = 0;
1490 timingadj.phase = 0;
1491 timingadj.hpos_step = 0;
1492 timingadj.vpos_step = 0;
1493 AFE_DeviceIOCtl ( TVIN_IOC_S_AFE_VGA_PARM, &timingadj );
1494 return rt;
1495 }
1496
1497 return 0;
1498}
1499
1500int CTvin::AFE_GetVGAAutoAdjustCMDStatus ( tvafe_cmd_status_t *Status )
1501{
1502 int rt = -1;
1503
1504 if ( Status == NULL ) {
1505 return rt;
1506 }
1507
1508 rt = AFE_DeviceIOCtl ( TVIN_IOC_G_AFE_CMD_STATUS, Status );
1509
1510 if ( rt < 0 ) {
1511 LOGW ( "AFE_GetVGAAutoAdjustStatus, get status, error(%s) fd(%d) return(%d)\n", strerror ( errno ), AFE_GetDeviceFileHandle(), rt );
1512 return rt;
1513 }
1514
1515 return 0;
1516}
1517
1518int CTvin::AFE_GetAdcCal ( struct tvafe_adc_cal_s *adccalvalue )
1519{
1520 int rt = -1;
1521
1522 rt = AFE_DeviceIOCtl ( TVIN_IOC_G_AFE_ADC_CAL, adccalvalue );
1523
1524 if ( rt < 0 ) {
1525 LOGW ( "AFE_GetADCGainOffset, error(%s)!\n", strerror ( errno ) );
1526 }
1527
1528 return rt;
1529}
1530
1531int CTvin::AFE_SetAdcCal ( struct tvafe_adc_cal_s *adccalvalue )
1532{
1533 int rt = AFE_DeviceIOCtl ( TVIN_IOC_S_AFE_ADC_CAL, adccalvalue );
1534
1535 if ( rt < 0 ) {
1536 LOGW ( "AFE_SetAdcCal, error(%s)!", strerror ( errno ) );
1537 }
1538
1539 return rt;
1540}
1541
1542int CTvin::AFE_GetAdcCompCal ( struct tvafe_adc_comp_cal_s *adccalvalue )
1543{
1544 int rt = -1;
1545
1546 rt = AFE_DeviceIOCtl ( TVIN_IOC_G_AFE_ADC_COMP_CAL, adccalvalue );
1547
1548 if ( rt < 0 ) {
1549 LOGW ( "AFE_GetYPbPrADCGainOffset, error(%s)!\n", strerror ( errno ) );
1550 }
1551
1552 return rt;
1553}
1554
1555int CTvin::AFE_SetAdcCompCal ( struct tvafe_adc_comp_cal_s *adccalvalue )
1556{
1557 int rt = AFE_DeviceIOCtl ( TVIN_IOC_S_AFE_ADC_COMP_CAL, adccalvalue );
1558
1559 if ( rt < 0 ) {
1560 LOGW ( "AFE_SetYPbPrADCGainOffset, error(%s)!", strerror ( errno ) );
1561 }
1562
1563 return rt;
1564}
1565int CTvin::AFE_GetYPbPrWSSinfo ( struct tvafe_comp_wss_s *wssinfo )
1566{
1567 int rt = AFE_DeviceIOCtl ( TVIN_IOC_G_AFE_COMP_WSS, wssinfo );
1568
1569 if ( rt < 0 ) {
1570 LOGW ( "AFE_GetYPbPrWSSinfo, error(%s)!", strerror ( errno ) );
1571 }
1572
1573 return rt;
1574}
1575
1576#define RGB444 3
1577#define YCBCR422 2
1578#define YCBCR444 3
1579#define Y422_POS 0
1580#define CB422_POS 1
1581#define CR422_POS 3
1582#define Y444_POS 0
1583#define CB444_POS 1
1584#define CR444_POS 2
1585#define R444_POS 0
1586#define G444_POS 1
1587#define B444_POS 2
1588
1589//=========== VGA =====================
1590#define VGA_BUF_WID (VGA_H_ACTIVE)
1591
1592#ifdef PATTERN_7_COLOR_BAR
1593#define VGA_BAR_WID (VGA_H_ACTIVE/7)
1594#define VGA_H_CUT_WID (10)
1595#else
1596#define VGA_BAR_WID (VGA_H_ACTIVE/8)
1597#define VGA_H_CUT_WID (10)
1598#endif
1599
1600#define VGA_V_CUT_WID (40)
1601#define VGA_V_CAL_WID (200+VGA_V_CUT_WID)
1602
1603#define VGA_WHITE_HS (VGA_BAR_WID*0+VGA_H_CUT_WID)
1604#define VGA_WHITE_HE (VGA_BAR_WID*1-VGA_H_CUT_WID-1)
1605#define VGA_WHITE_VS (VGA_V_CUT_WID)
1606#define VGA_WHITE_VE (VGA_V_CAL_WID-1)
1607#define VGA_WHITE_SIZE ((VGA_WHITE_HE-VGA_WHITE_HS+1)*(VGA_WHITE_VE-VGA_WHITE_VS+1))
1608#ifdef PATTERN_7_COLOR_BAR
1609#define VGA_BLACK_HS (VGA_BAR_WID*6+VGA_H_CUT_WID)
1610#define VGA_BLACK_HE (VGA_BAR_WID*7-VGA_H_CUT_WID-1)
1611#define VGA_BLACK_VS (768-140)
1612#define VGA_BLACK_VE (768-40-1)
1613#define VGA_BLACK_SIZE ((VGA_BLACK_HE-VGA_BLACK_HS+1)*(VGA_BLACK_VE-VGA_BLACK_VS+1))
1614#else
1615#define VGA_BLACK_HS (VGA_BAR_WID*7+VGA_H_CUT_WID)
1616#define VGA_BLACK_HE (VGA_BAR_WID*8-VGA_H_CUT_WID-1)
1617#define VGA_BLACK_VS (VGA_V_CUT_WID)
1618#define VGA_BLACK_VE (VGA_V_CAL_WID-1)
1619#define VGA_BLACK_SIZE ((VGA_BLACK_HE-VGA_BLACK_HS+1)*(VGA_BLACK_VE-VGA_BLACK_VS+1))
1620#endif
1621
1622//=========== YPBPR =====================
1623#define COMP_BUF_WID (COMP_H_ACTIVE)
1624
1625#define COMP_BAR_WID (COMP_H_ACTIVE/8)
1626#define COMP_H_CUT_WID (20)
1627#define COMP_V_CUT_WID (100)
1628#define COMP_V_CAL_WID (200+COMP_V_CUT_WID)
1629
1630#define COMP_WHITE_HS (COMP_BAR_WID*0+COMP_H_CUT_WID)
1631#define COMP_WHITE_HE (COMP_BAR_WID*1-COMP_H_CUT_WID-1)
1632#define COMP_WHITE_VS (COMP_V_CUT_WID)
1633#define COMP_WHITE_VE (COMP_V_CAL_WID-1)
1634#define COMP_WHITE_SIZE ((COMP_WHITE_HE-COMP_WHITE_HS+1)*(COMP_WHITE_VE-COMP_WHITE_VS+1))
1635#define CB_WHITE_SIZE ((COMP_WHITE_HE-COMP_WHITE_HS+1)*(COMP_WHITE_VE-COMP_WHITE_VS+1)/2)
1636#define CR_WHITE_SIZE ((COMP_WHITE_HE-COMP_WHITE_HS+1)*(COMP_WHITE_VE-COMP_WHITE_VS+1)/2)
1637
1638#define COMP_YELLOW_HS (COMP_BAR_WID*1+COMP_H_CUT_WID)
1639#define COMP_YELLOW_HE (COMP_BAR_WID*2-COMP_H_CUT_WID-1)
1640#define COMP_YELLOW_VS (COMP_V_CUT_WID)
1641#define COMP_YELLOW_VE (COMP_V_CAL_WID-1)
1642#define COMP_YELLOW_SIZE ((COMP_YELLOW_HE-COMP_YELLOW_HS+1)*(COMP_YELLOW_VE-COMP_YELLOW_VS+1)/2)
1643
1644#define COMP_CYAN_HS (COMP_BAR_WID*2+COMP_H_CUT_WID)
1645#define COMP_CYAN_HE (COMP_BAR_WID*3-COMP_H_CUT_WID-1)
1646#define COMP_CYAN_VS (COMP_V_CUT_WID)
1647#define COMP_CYAN_VE (COMP_V_CAL_WID-1)
1648#define COMP_CYAN_SIZE ((COMP_CYAN_HE-COMP_CYAN_HS+1)*(COMP_CYAN_VE-COMP_CYAN_VS+1)/2)
1649
1650#define COMP_RED_HS (COMP_BAR_WID*5+COMP_H_CUT_WID)
1651#define COMP_RED_HE (COMP_BAR_WID*6-COMP_H_CUT_WID-1)
1652#define COMP_RED_VS (COMP_V_CUT_WID)
1653#define COMP_RED_VE (COMP_V_CAL_WID-1)
1654#define COMP_RED_SIZE ((COMP_RED_HE-COMP_RED_HS+1)*(COMP_RED_VE-COMP_RED_VS+1)/2)
1655
1656#define COMP_BLUE_HS (COMP_BAR_WID*6+COMP_H_CUT_WID)
1657#define COMP_BLUE_HE (COMP_BAR_WID*7-COMP_H_CUT_WID-1)
1658#define COMP_BLUE_VS (COMP_V_CUT_WID)
1659#define COMP_BLUE_VE (COMP_V_CAL_WID-1)
1660#define COMP_BLUE_SIZE ((COMP_BLUE_HE-COMP_BLUE_HS+1)*(COMP_BLUE_VE-COMP_BLUE_VS+1)/2)
1661
1662#define COMP_BLACK_HS (COMP_BAR_WID*7+COMP_H_CUT_WID)
1663#define COMP_BLACK_HE (COMP_BAR_WID*8-COMP_H_CUT_WID-1)
1664#define COMP_BLACK_VS (COMP_V_CUT_WID)
1665#define COMP_BLACK_VE (COMP_V_CAL_WID-1)
1666#define COMP_BLACK_SIZE ((COMP_BLACK_HE-COMP_BLACK_HS+1)*(COMP_BLACK_VE-COMP_BLACK_VS+1))
1667#define CB_BLACK_SIZE ((COMP_BLACK_HE-COMP_BLACK_HS+1)*(COMP_BLACK_VE-COMP_BLACK_VS+1)/2)
1668#define CR_BLACK_SIZE ((COMP_BLACK_HE-COMP_BLACK_HS+1)*(COMP_BLACK_VE-COMP_BLACK_VS+1)/2)
1669
1670//=========== CVBS =====================
1671#define CVBS_BUF_WID (CVBS_H_ACTIVE)
1672#define CVBS_BAR_WID (CVBS_H_ACTIVE/8)
1673#define CVBS_H_CUT_WID (20)
1674
1675#define CVBS_V_CUT_WID (40)
1676#define CVBS_V_CAL_WID (140+CVBS_V_CUT_WID)
1677
1678#define CVBS_WHITE_HS (CVBS_BAR_WID*0+CVBS_H_CUT_WID)
1679#define CVBS_WHITE_HE (CVBS_BAR_WID*1-CVBS_H_CUT_WID-1)
1680#define CVBS_WHITE_VS (CVBS_V_CUT_WID)
1681#define CVBS_WHITE_VE (CVBS_V_CAL_WID-1)
1682#define CVBS_WHITE_SIZE ((CVBS_WHITE_HE-CVBS_WHITE_HS+1)*(CVBS_WHITE_VE-CVBS_WHITE_VS+1))
1683
1684#define CVBS_BLACK_HS (CVBS_BAR_WID*7+CVBS_H_CUT_WID)
1685#define CVBS_BLACK_HE (CVBS_BAR_WID*8-CVBS_H_CUT_WID-1)
1686#define CVBS_BLACK_VS (CVBS_V_CUT_WID)
1687#define CVBS_BLACK_VE (CVBS_V_CAL_WID-1)
1688#define CVBS_BLACK_SIZE ((CVBS_BLACK_HE-CVBS_BLACK_HS+1)*(CVBS_BLACK_VE-CVBS_BLACK_VS+1))
1689
1690#define COMP_CAP_SIZE (COMP_H_ACTIVE*COMP_V_ACTIVE*YCBCR422)
1691#ifdef VGA_SOURCE_RGB444
1692#define VGA_CAP_SIZE (VGA_H_ACTIVE*VGA_V_ACTIVE*RGB444)
1693#else
1694#define VGA_CAP_SIZE (VGA_H_ACTIVE*VGA_V_ACTIVE*YCBCR444)
1695#endif
1696#define CVBS_CAP_SIZE (CVBS_H_ACTIVE*CVBS_V_ACTIVE)
1697
1698#define PRE_0 -16
1699#define PRE_1 -128
1700#define PRE_2 -128
1701#define COEF_00 1.164
1702#define COEF_01 0
1703#define COEF_02 1.793
1704#define COEF_10 1.164
1705#define COEF_11 -0.213
1706#define COEF_12 -0.534
1707#define COEF_20 1.164
1708#define COEF_21 2.115
1709#define COEF_22 0
1710#define POST_0 0
1711#define POST_1 0
1712#define POST_2 0
1713
1714unsigned int CTvin::data_limit ( float data )
1715{
1716 if ( data < 0 ) {
1717 return ( 0 );
1718 } else if ( data > 255 ) {
1719 return ( 255 );
1720 } else {
1721 return ( ( unsigned int ) data );
1722 }
1723}
1724
1725void CTvin::matrix_convert_yuv709_to_rgb ( unsigned int y, unsigned int u, unsigned int v, unsigned int *r, unsigned int *g, unsigned int *b )
1726{
1727 *r = data_limit ( ( ( float ) y + PRE_0 ) * COEF_00 + ( ( float ) u + PRE_1 ) * COEF_01 + ( ( float ) v + PRE_2 ) * COEF_02 + POST_0 + 0.5 );
1728 *g = data_limit ( ( ( float ) y + PRE_0 ) * COEF_10 + ( ( float ) u + PRE_1 ) * COEF_11 + ( ( float ) v + PRE_2 ) * COEF_12 + POST_1 + 0.5 );
1729 *b = data_limit ( ( ( float ) y + PRE_0 ) * COEF_20 + ( ( float ) u + PRE_1 ) * COEF_21 + ( ( float ) v + PRE_2 ) * COEF_22 + POST_2 + 0.5 );
1730}
1731
1732void CTvin::re_order ( unsigned int *a, unsigned int *b )
1733{
1734 unsigned int c = 0;
1735
1736 if ( *a > *b ) {
1737 c = *a;
1738 *a = *b;
1739 *b = c;
1740 }
1741}
1742
1743char *CTvin::get_cap_addr ( enum adc_cal_type_e calType )
1744{
1745 int n;
1746 char *dp;
1747
1748 for ( n = 0; n < 0x00ff; n++ ) {
1749 if ( VDIN_DeviceIOCtl ( TVIN_IOC_G_SIG_INFO, &gTvinAFESignalInfo ) < 0 ) {
1750 LOGW ( "get_cap_addr, get signal info, error(%s),fd(%d).\n", strerror ( errno ), m_vdin_dev_fd );
1751 return NULL;
1752 } else {
1753 if ( gTvinAFESignalInfo.status == TVIN_SIG_STATUS_STABLE ) {
1754 gTvinAFEParam.info.fmt = gTvinAFESignalInfo.fmt;
1755 break;
1756 }
1757 }
1758 }
1759
1760 if ( gTvinAFESignalInfo.status != TVIN_SIG_STATUS_STABLE ) {
1761 LOGD ( "get_cap_addr, signal isn't stable, out of calibration!\n" );
1762 return NULL;
1763 } else {
1764 if ( VDIN_DeviceIOCtl ( TVIN_IOC_STOP_DEC ) < 0 ) {
1765 LOGW ( "get_cap_addr, stop vdin, error (%s).\n", strerror ( errno ) );
1766 return NULL;
1767 }
1768
1769 usleep ( 1000 );
1770
1771 if ( calType == CAL_YPBPR ) {
1772 dp = ( char * ) mmap ( NULL, COMP_CAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, m_vdin_dev_fd, 0 );
1773 } else {
1774 dp = ( char * ) mmap ( NULL, VGA_CAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, m_vdin_dev_fd, 0 );
1775 }
1776
1777 if ( dp < 0 ) {
1778 LOGD ( "get_cap_addr, mmap failed!\n" );
1779 }
1780
1781 return dp;
1782 }
1783
1784 return NULL;
1785}
1786
1787inline unsigned char CTvin::get_mem_data ( char *dp, unsigned int addr )
1788{
1789 return ( * ( dp + ( addr ^ 7 ) ) );
1790}
1791
1792int CTvin::get_frame_average ( enum adc_cal_type_e calType, struct adc_cal_s *mem_data )
1793{
1794 unsigned int y = 0, cb = 0, cr = 0;
1795 unsigned int r = 0, g = 0, b = 0;
1796 unsigned long n;
1797 unsigned int i = 0, j = 0;
1798 char *dp = get_cap_addr ( calType );
1799
1800 if ( calType == CAL_YPBPR ) {
1801 for ( j = COMP_WHITE_VS; j <= COMP_WHITE_VE; j++ ) {
1802 for ( i = COMP_WHITE_HS; i <= COMP_WHITE_HE; i++ ) {
1803 mem_data->g_y_max += get_mem_data ( dp, ( ( COMP_BUF_WID * j + i ) * YCBCR422 ) );
1804 }
1805 }
1806
1807 mem_data->g_y_max /= COMP_WHITE_SIZE;
1808
1809 for ( j = COMP_WHITE_VS; j <= COMP_WHITE_VE; j++ ) {
1810 for ( i = COMP_WHITE_HS; i <= COMP_WHITE_HE; ) {
1811 mem_data->cb_white += get_mem_data ( dp, ( ( COMP_BUF_WID * j + i ) * YCBCR422 + CB422_POS ) );
1812 mem_data->cr_white += get_mem_data ( dp, ( ( COMP_BUF_WID * j + i ) * YCBCR422 + CR422_POS ) );
1813 i = i + 2;
1814 }
1815 }
1816
1817 mem_data->cb_white /= CB_WHITE_SIZE;
1818 mem_data->cr_white /= CR_WHITE_SIZE;
1819
1820 for ( j = COMP_RED_VS; j <= COMP_RED_VE; j++ ) {
1821 for ( i = COMP_RED_HS; i <= COMP_RED_HE; ) {
1822 mem_data->rcr_max += get_mem_data ( dp, ( ( COMP_BUF_WID * j + i ) * YCBCR422 + CR422_POS ) );
1823 i = i + 2;
1824 }
1825 }
1826
1827 mem_data->rcr_max /= COMP_RED_SIZE;
1828
1829 for ( j = COMP_BLUE_VS; j <= COMP_BLUE_VE; j++ ) {
1830 for ( i = COMP_BLUE_HS; i <= COMP_BLUE_HE; ) {
1831 mem_data->bcb_max += get_mem_data ( dp, ( ( COMP_BUF_WID * j + i ) * YCBCR422 + CB422_POS ) );
1832 i = i + 2;
1833 }
1834 }
1835
1836 mem_data->bcb_max /= COMP_BLUE_SIZE;
1837
1838 for ( j = COMP_BLACK_VS; j <= COMP_BLACK_VE; j++ ) {
1839 for ( i = COMP_BLACK_HS; i <= COMP_BLACK_HE; i++ ) {
1840 mem_data->g_y_min += get_mem_data ( dp, ( ( COMP_BUF_WID * j + i ) * YCBCR422 ) );
1841 }
1842 }
1843
1844 mem_data->g_y_min /= COMP_BLACK_SIZE;
1845
1846 for ( j = COMP_BLACK_VS; j <= COMP_BLACK_VE; j++ ) {
1847 for ( i = COMP_BLACK_HS; i <= COMP_BLACK_HE; ) {
1848 mem_data->cb_black += get_mem_data ( dp, ( ( COMP_BUF_WID * j + i ) * YCBCR422 + CB422_POS ) );
1849 mem_data->cr_black += get_mem_data ( dp, ( ( COMP_BUF_WID * j + i ) * YCBCR422 + CR422_POS ) );
1850 i = i + 2;
1851 }
1852 }
1853
1854 mem_data->cb_black /= CB_BLACK_SIZE;
1855 mem_data->cr_black /= CR_BLACK_SIZE;
1856
1857 /*
1858 for (j=COMP_BLACK_VS; j<=COMP_BLACK_VE; j++) {
1859 for (i=COMP_BLACK_HS; i<=COMP_BLACK_HE;) {
1860 //mem_data->cb_black += get_mem_data(dp, ((COMP_BUF_WID*j+i)*YCBCR422+CB422_POS));
1861 mem_data->cr_black += get_mem_data(dp, ((COMP_BUF_WID*j+i)*YCBCR422+CR422_POS));
1862 i = i+2;
1863 }
1864 }
1865 mem_data->cr_black /= CR_BLACK_SIZE;
1866 */
1867 for ( j = COMP_CYAN_VS; j <= COMP_CYAN_VE; j++ ) {
1868 for ( i = COMP_CYAN_HS; i <= COMP_CYAN_HE; ) {
1869 mem_data->rcr_min += get_mem_data ( dp, ( ( COMP_BUF_WID * j + i ) * YCBCR422 + CR422_POS ) );
1870 i = i + 2;
1871 }
1872 }
1873
1874 mem_data->rcr_min /= COMP_CYAN_SIZE;
1875
1876 for ( j = COMP_YELLOW_VS; j <= COMP_YELLOW_VE; j++ ) {
1877 for ( i = COMP_YELLOW_HS; i <= COMP_YELLOW_HE; ) {
1878 mem_data->bcb_min += get_mem_data ( dp, ( COMP_BUF_WID * j + i ) * YCBCR422 + CB422_POS );
1879 i = i + 2;
1880 }
1881 }
1882
1883 mem_data->bcb_min /= COMP_YELLOW_SIZE;
1884
1885 } else if ( calType == CAL_VGA ) {
1886 for ( j = VGA_WHITE_VS; j <= VGA_WHITE_VE; j++ ) {
1887 for ( i = VGA_WHITE_HS; i <= VGA_WHITE_HE; i++ ) {
1888#ifdef VGA_SOURCE_RGB444
1889 r = get_mem_data ( dp, ( ( VGA_BUF_WID * j + i ) * RGB444 + R444_POS ) );
1890 g = get_mem_data ( dp, ( ( VGA_BUF_WID * j + i ) * RGB444 + G444_POS ) );
1891 b = get_mem_data ( dp, ( ( VGA_BUF_WID * j + i ) * RGB444 + B444_POS ) );
1892#else
1893 y = get_mem_data ( dp, ( ( VGA_BUF_WID * j + i ) * YCBCR444 + Y444_POS ) );
1894 cb = get_mem_data ( dp, ( ( VGA_BUF_WID * j + i ) * YCBCR444 + CB444_POS ) );
1895 cr = get_mem_data ( dp, ( ( VGA_BUF_WID * j + i ) * YCBCR444 + CR444_POS ) );
1896 matrix_convert_yuv709_to_rgb ( y, cb, cr, &r, &g, &b );
1897#endif
1898 mem_data->rcr_max = mem_data->rcr_max + r;
1899 mem_data->g_y_max = mem_data->g_y_max + g;
1900 mem_data->bcb_max = mem_data->bcb_max + b;
1901 }
1902 }
1903
1904 mem_data->rcr_max = mem_data->rcr_max / VGA_WHITE_SIZE;
1905 mem_data->g_y_max = mem_data->g_y_max / VGA_WHITE_SIZE;
1906 mem_data->bcb_max = mem_data->bcb_max / VGA_WHITE_SIZE;
1907
1908 for ( j = VGA_BLACK_VS; j <= VGA_BLACK_VE; j++ ) {
1909 for ( i = VGA_BLACK_HS; i <= VGA_BLACK_HE; i++ ) {
1910#ifdef VGA_SOURCE_RGB444
1911 r = get_mem_data ( dp, ( ( VGA_BUF_WID * j + i ) * RGB444 + R444_POS ) );
1912 g = get_mem_data ( dp, ( ( VGA_BUF_WID * j + i ) * RGB444 + G444_POS ) );
1913 b = get_mem_data ( dp, ( ( VGA_BUF_WID * j + i ) * RGB444 + B444_POS ) );
1914#else
1915 y = get_mem_data ( dp, ( ( VGA_BUF_WID * j + i ) * YCBCR444 + Y444_POS ) );
1916 cb = get_mem_data ( dp, ( ( VGA_BUF_WID * j + i ) * YCBCR444 + CB444_POS ) );
1917 cr = get_mem_data ( dp, ( ( VGA_BUF_WID * j + i ) * YCBCR444 + CR444_POS ) );
1918 matrix_convert_yuv709_to_rgb ( y, cb, cr, &r, &g, &b );
1919#endif
1920 mem_data->rcr_min = mem_data->rcr_min + r;
1921 mem_data->g_y_min = mem_data->g_y_min + g;
1922 mem_data->bcb_min = mem_data->bcb_min + b;
1923 }
1924 }
1925
1926 mem_data->rcr_min = mem_data->rcr_min / VGA_BLACK_SIZE;
1927 mem_data->g_y_min = mem_data->g_y_min / VGA_BLACK_SIZE;
1928 mem_data->bcb_min = mem_data->bcb_min / VGA_BLACK_SIZE;
1929
1930 } else { //CVBS
1931 for ( j = CVBS_WHITE_VS; j <= CVBS_WHITE_VE; j++ ) {
1932 for ( i = CVBS_WHITE_HS; i <= CVBS_WHITE_HE; i++ ) {
1933 mem_data->g_y_max += mem_data->g_y_max + get_mem_data ( dp, ( ( CVBS_BUF_WID * j + i ) * YCBCR422 ) );
1934 }
1935 }
1936
1937 mem_data->g_y_max /= COMP_WHITE_SIZE;
1938
1939 for ( j = CVBS_BLACK_VS; j <= CVBS_BLACK_VE; j++ ) {
1940 for ( i = CVBS_BLACK_HS; i <= CVBS_BLACK_HE; i++ ) {
1941 mem_data->g_y_min += mem_data->g_y_min + get_mem_data ( dp, ( ( CVBS_BUF_WID * j + i ) * YCBCR422 ) );
1942 }
1943 }
1944
1945 mem_data->g_y_min /= CVBS_BLACK_SIZE;
1946 }
1947
1948 if ( calType == CAL_YPBPR ) {
1949 munmap ( dp, COMP_CAP_SIZE );
1950 } else if ( calType == CAL_VGA ) {
1951 munmap ( dp, VGA_CAP_SIZE );
1952 } else {
1953 munmap ( dp, CVBS_CAP_SIZE );
1954 }
1955
1956 if ( VDIN_DeviceIOCtl ( TVIN_IOC_START_DEC, &gTvinAFEParam ) < 0 ) {
1957 LOGW ( "get_frame_average, get vdin signal info, error(%s),fd(%d).\n", strerror ( errno ), m_vdin_dev_fd );
1958 return NULL;
1959 } else {
1960 ;
1961 }
1962
1963 return 0;
1964}
1965
1966#define ADC_CAL_FRAME_QTY_ORDER 2 //NOTE: MUST >=2!!
1967struct adc_cal_s CTvin::get_n_frame_average ( enum adc_cal_type_e calType )
1968{
1969 struct adc_cal_s mem_data = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1970 unsigned int rcrmax[1 << ADC_CAL_FRAME_QTY_ORDER];
1971 unsigned int rcrmin[1 << ADC_CAL_FRAME_QTY_ORDER];
1972 unsigned int g_ymax[1 << ADC_CAL_FRAME_QTY_ORDER];
1973 unsigned int g_ymin[1 << ADC_CAL_FRAME_QTY_ORDER];
1974 unsigned int bcbmax[1 << ADC_CAL_FRAME_QTY_ORDER];
1975 unsigned int bcbmin[1 << ADC_CAL_FRAME_QTY_ORDER];
1976 unsigned int cbwhite[1 << ADC_CAL_FRAME_QTY_ORDER];
1977 unsigned int crwhite[1 << ADC_CAL_FRAME_QTY_ORDER];
1978 unsigned int cbblack[1 << ADC_CAL_FRAME_QTY_ORDER];
1979 unsigned int crblack[1 << ADC_CAL_FRAME_QTY_ORDER];
1980 unsigned int i = 0, j = 0;
1981
1982 for ( i = 0; i < ( 1 << ADC_CAL_FRAME_QTY_ORDER ); i++ ) {
1983 get_frame_average ( calType, &mem_data );
1984 rcrmax[i] = mem_data.rcr_max;
1985 rcrmin[i] = mem_data.rcr_min;
1986 g_ymax[i] = mem_data.g_y_max;
1987 g_ymin[i] = mem_data.g_y_min;
1988 bcbmax[i] = mem_data.bcb_max;
1989 bcbmin[i] = mem_data.bcb_min;
1990 cbwhite[i] = mem_data.cb_white;
1991 crwhite[i] = mem_data.cr_white;
1992 cbblack[i] = mem_data.cb_black;
1993 crblack[i] = mem_data.cr_black;
1994 }
1995
1996 for ( i = 0; i < ( 1 << ADC_CAL_FRAME_QTY_ORDER ) - 1; i++ ) {
1997 for ( j = 1; j < ( 1 << ADC_CAL_FRAME_QTY_ORDER ); j++ ) {
1998 re_order ( & ( rcrmax[i] ), & ( rcrmax[j] ) );
1999 re_order ( & ( rcrmin[i] ), & ( rcrmin[j] ) );
2000 re_order ( & ( g_ymax[i] ), & ( g_ymax[j] ) );
2001 re_order ( & ( g_ymin[i] ), & ( g_ymin[j] ) );
2002 re_order ( & ( bcbmax[i] ), & ( bcbmax[j] ) );
2003 re_order ( & ( bcbmin[i] ), & ( bcbmin[j] ) );
2004 re_order ( & ( cbwhite[i] ), & ( cbwhite[j] ) );
2005 re_order ( & ( crwhite[i] ), & ( crwhite[j] ) );
2006 re_order ( & ( cbblack[i] ), & ( cbblack[j] ) );
2007 re_order ( & ( crblack[i] ), & ( crblack[j] ) );
2008 }
2009 }
2010
2011
2012 memset ( &mem_data, 0, sizeof ( mem_data ) );
2013
2014 for ( i = 0; i < ( 1 << ( ADC_CAL_FRAME_QTY_ORDER - 1 ) ); i++ ) { //(1<<(ADC_CAL_FRAME_QTY_ORDER-1))
2015 mem_data.rcr_max += rcrmax[i + ( 1 << ( ADC_CAL_FRAME_QTY_ORDER - 2 ) )];
2016 mem_data.rcr_min += rcrmin[i + ( 1 << ( ADC_CAL_FRAME_QTY_ORDER - 2 ) )];
2017 mem_data.g_y_max += g_ymax[i + ( 1 << ( ADC_CAL_FRAME_QTY_ORDER - 2 ) )];
2018 mem_data.g_y_min += g_ymin[i + ( 1 << ( ADC_CAL_FRAME_QTY_ORDER - 2 ) )];
2019 mem_data.bcb_max += bcbmax[i + ( 1 << ( ADC_CAL_FRAME_QTY_ORDER - 2 ) )];
2020 mem_data.bcb_min += bcbmin[i + ( 1 << ( ADC_CAL_FRAME_QTY_ORDER - 2 ) )];
2021 mem_data.cb_white += cbwhite[i + ( 1 << ( ADC_CAL_FRAME_QTY_ORDER - 2 ) )];
2022 mem_data.cr_white += crwhite[i + ( 1 << ( ADC_CAL_FRAME_QTY_ORDER - 2 ) )];
2023 mem_data.cb_black += cbblack[i + ( 1 << ( ADC_CAL_FRAME_QTY_ORDER - 2 ) )];
2024 mem_data.cr_black += crblack[i + ( 1 << ( ADC_CAL_FRAME_QTY_ORDER - 2 ) )];
2025 }
2026
2027
2028 mem_data.rcr_max >>= ( ADC_CAL_FRAME_QTY_ORDER - 1 );
2029 mem_data.rcr_min >>= ( ADC_CAL_FRAME_QTY_ORDER - 1 );
2030 mem_data.g_y_max >>= ( ADC_CAL_FRAME_QTY_ORDER - 1 );
2031 mem_data.g_y_min >>= ( ADC_CAL_FRAME_QTY_ORDER - 1 );
2032 mem_data.bcb_max >>= ( ADC_CAL_FRAME_QTY_ORDER - 1 );
2033 mem_data.bcb_min >>= ( ADC_CAL_FRAME_QTY_ORDER - 1 );
2034 mem_data.cb_white >>= ( ADC_CAL_FRAME_QTY_ORDER - 1 );
2035 mem_data.cr_white >>= ( ADC_CAL_FRAME_QTY_ORDER - 1 );
2036 mem_data.cb_black >>= ( ADC_CAL_FRAME_QTY_ORDER - 1 );
2037 mem_data.cr_black >>= ( ADC_CAL_FRAME_QTY_ORDER - 1 );
2038
2039 return mem_data;
2040}
2041
2042int CTvin::AFE_GetMemData ( int typeSel, struct adc_cal_s *mem_data )
2043{
2044 int rt = -1;
2045
2046 if ( m_vdin_dev_fd < 0 || mem_data == NULL ) {
2047 LOGW ( "AFE_GetMemData, didn't open vdin fd, return!\n" );
2048 return -1;
2049 }
2050
2051 memset ( &gTvinAFEParam, 0, sizeof ( gTvinAFEParam ) );
2052 memset ( &gTvinAFESignalInfo, 0, sizeof ( gTvinAFESignalInfo ) );
2053
2054 if ( VDIN_DeviceIOCtl ( TVIN_IOC_G_PARM, &gTvinAFEParam ) < 0 ) {
2055 LOGW ( "AFE_GetMemData, get vdin param, error(%s), fd(%d)!\n", strerror ( errno ), m_vdin_dev_fd );
2056 return -1;
2057 }
2058
2059 gTvinAFEParam.flag = gTvinAFEParam.flag | TVIN_PARM_FLAG_CAP;
2060
2061 if ( VDIN_DeviceIOCtl ( TVIN_IOC_S_PARM, &gTvinAFEParam ) < 0 ) {
2062 LOGW ( "AFE_GetMemData, set vdin param error(%s)!\n", strerror ( errno ) );
2063 return -1;
2064 }
2065
2066 if ( typeSel == 0 ) {
2067 get_frame_average ( CAL_YPBPR, mem_data );
2068 } else if ( typeSel == 1 ) {
2069 get_frame_average ( CAL_VGA, mem_data );
2070 } else {
2071 *mem_data = get_n_frame_average ( CAL_CVBS );
2072 }
2073
2074 gTvinAFEParam.flag &= 0x11111110;
2075
2076 if ( VDIN_DeviceIOCtl ( TVIN_IOC_S_PARM, &gTvinAFEParam ) < 0 ) {
2077 LOGW ( "AFE_GetMemData, set vdin param error(%s)\n", strerror ( errno ) );
2078 return -1;
2079 }
2080
2081 LOGD ( "AFE_GetMemData, MAX ======> :\n Y(White)->%d \n Cb(Blue)->%d \n Cr(Red)->%d\n", mem_data->g_y_max, mem_data->bcb_max, mem_data->rcr_max );
2082 LOGD ( "AFE_GetMemData, MIN ======>:\n Y(Black)->%d \n Cb(Yellow)->%d \n Cr(Cyan)->%d\n Cb(White) ->%d\n Cb(Black)->%d\n Cr(Black)->%d\n", mem_data->g_y_min, mem_data->bcb_min, mem_data->rcr_min,
2083 mem_data->cb_white, mem_data->cb_black, mem_data->cr_black );
2084 return 0;
2085}
2086
2087int CTvin::AFE_GetCVBSLockStatus ( enum tvafe_cvbs_video_e *cvbs_lock_status )
2088{
2089 int rt = -1;
2090
2091 rt = AFE_DeviceIOCtl ( TVIN_IOC_G_AFE_CVBS_LOCK, cvbs_lock_status );
2092
2093 if ( rt < 0 ) {
2094 LOGD ( "AFE_GetCVBSLockStatus, error: return(%d), error(%s)!\n", rt, strerror ( errno ) );
2095 } else {
2096 LOGD ( "AFE_GetCVBSLockStatus, value=%d.\n", *cvbs_lock_status );
2097 }
2098
2099 return *cvbs_lock_status;
2100}
2101
2102int CTvin::AFE_SetCVBSStd ( tvin_sig_fmt_t fmt )
2103{
2104 int rt = -1;
2105
2106 LOGD ( "AFE_SetCVBSStd, sig_fmt = %d\n", fmt );
2107 rt = AFE_DeviceIOCtl ( TVIN_IOC_S_AFE_CVBS_STD, &fmt );
2108
2109 if ( rt < 0 ) {
2110 LOGD ( "AFE_SetCVBSStd, error: return(%d), error(%s)!\n", rt, strerror ( errno ) );
2111 }
2112
2113 return rt;
2114}
2115
2116int CTvin::TvinApi_SetStartDropFrameCn ( int count )
2117{
2118 int ret = -1;
2119 char set_str[4];
2120
2121 memset ( set_str, 0, 4 );
2122 sprintf ( set_str, "%d", count );
2123 return SetFileAttrValue ( "/sys/module/di/parameters/start_frame_drop_count", set_str );
2124}
2125
2126int CTvin::TvinApi_SetVdinHVScale ( int vdinx, int hscale, int vscale )
2127{
2128 int ret = -1;
2129 char set_str[32];
2130
2131 memset ( set_str, 0, 32 );
2132 sprintf ( set_str, "%s %d %d", "hvscaler", hscale, vscale );
2133
2134 if ( vdinx == 0 ) {
2135 ret = SetFileAttrValue ( "/sys/class/vdin/vdin0/attr", set_str );
2136 } else {
2137 ret = SetFileAttrValue ( "/sys/class/vdin/vdin1/attr", set_str );
2138 }
2139
2140 return ret;
2141}
2142int CTvin::TvinApi_SetCompPhase ( am_phase_t &am_phase )
2143{
2144 int ret = -1, fd = -1;
2145 unsigned int i = 0;
2146 int idx = 0, len = 0;
2147 char str1[200], str2[100];
2148
2149 LOGD ( "enter,TvinApi_SetCompPhase" );
2150
2151 fd = open ( "/sys/module/tvin_afe/parameters/comp_phase", O_RDWR );
2152
2153 if ( fd < 0 ) {
2154 LOGW ( "Open vdin_comp_phase_op_mutex error(%s)!!\n", strerror ( errno ) );
2155
2156 return -1;
2157 }
2158
2159 for ( i = 0; i < am_phase.length; i++ ) {
2160 sprintf ( &str1[idx], "%d,", am_phase.phase[i] );
2161 sprintf ( str2, "%d,", am_phase.phase[i] );
2162 int len = strlen ( str2 );
2163 idx = idx + len;
2164 }
2165
2166 LOGD ( "##########str1 = %s\n", str1 );
2167
2168 ret = write ( fd, str1, strlen ( str1 ) );
2169
2170 if ( ret < 0 ) {
2171 LOGD ( "Write vdin_comp_phase_op_mutex error(%s)!!\n", strerror ( errno ) );
2172 }
2173
2174 LOGD ( "write ok!!!" );
2175 close ( fd );
2176 fd = -1;
2177
2178 return ret;
2179}
2180
2181tvin_trans_fmt CTvin::TvinApi_Get3DDectMode()
2182{
2183
2184 int fd;
2185 int ret;
2186 char det_3d[10];
2187 int det_3dmode = 8;
2188 //LOGW("det_3dmode %d\n", det_3dmode);
2189
2190 fd = open ( "/sys/module/di/parameters/det3d_mode", O_RDWR );
2191
2192 if ( fd < 0 ) {
2193 LOGW ( "/sys/module/di/parameters/det3d_mode error(%s)!!\n", strerror ( errno ) );
2194
2195 return TVIN_TFMT_3D_MAX;
2196 }
2197
2198 ret = read ( fd, det_3d, 10 );
2199
2200 if ( ret < 0 ) {
2201 LOGW ( "/sys/module/di/parameters/det3d_mode error(%s)!!\n", strerror ( errno ) );
2202 }
2203
2204 det_3dmode = atoi ( det_3d );
2205 close ( fd );
2206 fd = -1;
2207
2208 return (tvin_trans_fmt)det_3dmode;
2209}
2210int CTvin::TvinApi_SetCompPhaseEnable ( int enable )
2211{
2212 int ret = -1;
2213
2214 if ( enable == 1 ) {
2215 ret = SetFileAttrValue ( "/sys/module/tvin_afe/parameters/enable_dphase", "Y" );
2216 LOGD ( "%s, enable TvinApi_SetCompPhase.", "TV" );
2217 }
2218
2219 return ret;
2220}
2221
2222int CTvin::VDIN_GetPortConnect ( int port )
2223{
2224 int status = 0;
2225
2226 if ( VDIN_DeviceIOCtl ( TVIN_IOC_CALLMASTER_SET, &port ) < 0 ) {
2227 LOGW ( "TVIN_IOC_CALLMASTER_SET error(%s) port %d\n", strerror ( errno ), port );
2228 return 0;
2229 }
2230
2231 if ( VDIN_DeviceIOCtl ( TVIN_IOC_CALLMASTER_GET, &status ) < 0 ) {
2232 LOGW ( "TVIN_IOC_CALLMASTER_GET error(%s)\n", strerror ( errno ) );
2233 return 0;
2234 }
2235
2236 //LOGD("%s, port:%x,status:%d", "TV",port,status);
2237
2238 return status;
2239}
2240
2241int CTvin::VDIN_OpenHDMIPinMuxOn ( bool flag )
2242{
2243 FILE *fp = NULL;
2244 int status = 1;
2245
2246 fp = fopen ( "/sys/class/hdmirx/hdmirx0/debug", "w" );
2247
2248 if ( fp == NULL ) {
2249 LOGW ( "Open /sys/class/hdmirx/hdmirx0/debug(%s)!\n", strerror ( errno ) );
2250 return -1;
2251 }
2252
2253 if ( flag ) {
2254 fprintf ( fp, "%s", "pinmux_on" );
2255 } else {
2256 fprintf ( fp, "%s", "pinmux_off" );
2257
2258 }
2259
2260 fclose ( fp );
2261 fp = NULL;
2262 return status;
2263}
2264
2265int CTvin::VDIN_GetHdmiHdcpKeyKsvInfo(struct _hdcp_ksv *msg)
2266{
2267 int m_ksv_dev_fd = -1;
2268
2269 if (msg == NULL) {
2270 LOGE("%s, msg is NULL\n", __FUNCTION__);
2271 }
2272
2273 //PrintMessage(__FUNCTION__, 0, msg);
2274
2275 m_ksv_dev_fd = open(HDMIRX_KSV_PATH, O_RDWR);
2276 if (m_ksv_dev_fd < 0) {
2277 LOGE("%s, Open file %s error: (%s)!\n", __FUNCTION__, HDMIRX_KSV_PATH, strerror ( errno ));
2278 return -1;
2279 }
2280 LOGD("# call ioctl with HDMI_IOC_HDCP_SENT_KSV #");
2281 ioctl(m_ksv_dev_fd, HDMI_IOC_HDCP_KSV, msg);
2282
2283 close(m_ksv_dev_fd);
2284 m_ksv_dev_fd = -1;
2285
2286 LOGD("msg->bksv0 is %x, msg->bksv1 is %x", msg->bksv0, msg->bksv1);
2287
2288 return 0;
2289}
2290
2291
2292int CTvin::get_hdmi_ksv_info(int source_input, int data_buf[])
2293{
2294 if (source_input != SOURCE_HDMI1 && source_input != SOURCE_HDMI2 && source_input != SOURCE_HDMI3) {
2295 return -1;
2296 }
2297
2298 struct _hdcp_ksv msg;
2299 int ret = -1;
2300 ret = VDIN_GetHdmiHdcpKeyKsvInfo(&msg);
2301 memset((void *)data_buf, 0, 2);
2302 data_buf[0] = msg.bksv0;
2303 data_buf[1] = msg.bksv1;
2304 return ret;
2305}
2306
2307
2308int CTvin::TVAFE_EnablePlugInDetect ( bool flag )
2309{
2310 FILE *fp = NULL;
2311 int status = 1;
2312
2313 fp = fopen ( "/sys/class/tvafe/tvafe0/debug", "w" );
2314
2315 if ( fp == NULL ) {
2316 LOGW ( "Open /sys/class/tvafe/tvafe0/debug (%s)!\n", strerror ( errno ) );
2317 return -1;
2318 }
2319
2320 if ( flag ) {
2321 fprintf ( fp, "%s", "tvafe_enable" );
2322 } else {
2323 fprintf ( fp, "%s", "tvafe_down" );
2324
2325 }
2326
2327 fclose ( fp );
2328 fp = NULL;
2329 return status;
2330}
2331
2332int CTvin::TvinApi_GetHDMIAudioStatus ( void )
2333{
2334 int fd;
2335 int val = 0;
2336 char bcmd[16];
2337 fd = open ( "/sys/module/tvin_hdmirx/parameters/auds_rcv_sts", O_RDONLY );
2338
2339 if ( fd >= 0 ) {
2340 read ( fd, bcmd, sizeof ( bcmd ) );
2341 val = strtol ( bcmd, NULL, 10 );
2342 close ( fd );
2343 } else {
2344 LOGE ( "open /sys/module/tvin_hdmirx/parameters/auds_rcv_sts ERROR(%s)!!\n", strerror ( errno ) );
2345 return -1;
2346 }
2347
2348 return val;
2349}
2350
2351int CTvin::TvinApi_LoadPLLValues ( am_regs_t regs )
2352{
2353 int rt = AFE_DeviceIOCtl ( TVIN_IOC_LOAD_REG, &regs );
2354
2355 if ( rt < 0 ) {
2356 LOGE ( "TvinApi_LoadPLLValues, error(%s)!\n", strerror ( errno ) );
2357 }
2358
2359 return rt;
2360}
2361
2362int CTvin::TvinApi_LoadCVD2Values ( am_regs_t regs )
2363{
2364 int rt = AFE_DeviceIOCtl ( TVIN_IOC_LOAD_REG, &regs );
2365
2366 if ( rt < 0 ) {
2367 LOGE ( "TvinApi_LoadCVD2Values, error(%s)!\n", strerror ( errno ) );
2368 }
2369
2370 return rt;
2371}
2372
2373
2374int CTvin::TvinApi_GetFbSize ( unsigned int *fb_width, unsigned int *fb_height )
2375{
2376 int fbfd = 0;
2377 struct fb_var_screeninfo vinfo;
2378 struct fb_fix_screeninfo finfo;
2379 int xres = 0, yres = 0, bits_per_pixel = 0;
2380
2381 fbfd = open ( "/dev/graphics/fb0", O_RDWR );
2382
2383 if ( !fbfd ) {
2384 return -1;
2385 }
2386
2387 if ( ioctl ( fbfd, FBIOGET_FSCREENINFO, &finfo ) ) {
2388 goto fail_close_fb;
2389 }
2390
2391 if ( ioctl ( fbfd, FBIOGET_VSCREENINFO, &vinfo ) ) {
2392 goto fail_close_fb;
2393 }
2394
2395 *fb_width = vinfo.xres;
2396 *fb_height = vinfo.yres;
2397
2398 return 1;
2399
2400fail_close_fb:
2401 close ( fbfd );;
2402 return -1;
2403}
2404
2405tv_source_input_type_t CTvin::Tvin_SourceInputToSourceInputType ( tv_source_input_t source_input )
2406{
2407 if (source_input == SOURCE_TV) {
2408 return SOURCE_TYPE_TV;
2409 } else if (source_input == SOURCE_AV1 || source_input == SOURCE_AV2) {
2410 return SOURCE_TYPE_AV;
2411 } else if (source_input == SOURCE_YPBPR1 || source_input == SOURCE_YPBPR2) {
2412 return SOURCE_TYPE_COMPONENT;
2413 } else if (source_input == SOURCE_VGA) {
2414 return SOURCE_TYPE_VGA;
2415 } else if (source_input == SOURCE_HDMI1 || source_input == SOURCE_HDMI2 || source_input == SOURCE_HDMI3) {
2416 return SOURCE_TYPE_HDMI;
2417 } else if (source_input == SOURCE_DTV) {
2418 return SOURCE_TYPE_DTV;
2419 } else if (source_input == SOURCE_IPTV) {
2420 return SOURCE_TYPE_IPTV;
2421 } else if (source_input == SOURCE_MPEG) {
2422 return SOURCE_TYPE_MPEG;
2423 }
2424
2425 return SOURCE_TYPE_MPEG;
2426}
2427
2428tv_source_input_type_t CTvin::Tvin_SourcePortToSourceInputType ( tvin_port_t source_port )
2429{
2430 tv_source_input_t source_input = Tvin_PortToSourceInput(source_port);
2431 return Tvin_SourceInputToSourceInputType(source_input);
2432}
2433
2434tvin_port_t CTvin::Tvin_GetSourcePortBySourceType ( tv_source_input_type_t source_type )
2435{
2436 tvin_port_t source_port;
2437
2438 switch ( source_type ) {
2439 case SOURCE_TYPE_TV:
2440 source_port = Tvin_GetSourcePortBySourceInput(SOURCE_TV);
2441 break;
2442 case SOURCE_TYPE_AV:
2443 source_port = Tvin_GetSourcePortBySourceInput(SOURCE_AV1);
2444 break;
2445 case SOURCE_TYPE_COMPONENT:
2446 source_port = Tvin_GetSourcePortBySourceInput(SOURCE_YPBPR1);
2447 break;
2448 case SOURCE_TYPE_VGA:
2449 source_port = Tvin_GetSourcePortBySourceInput(SOURCE_VGA);
2450 break;
2451 case SOURCE_TYPE_HDMI:
2452 source_port = TVIN_PORT_HDMI0;
2453 break;
2454 case SOURCE_TYPE_IPTV:
2455 source_port = Tvin_GetSourcePortBySourceInput(SOURCE_IPTV);
2456 break;
2457 case SOURCE_TYPE_DTV:
2458 source_port = Tvin_GetSourcePortBySourceInput(SOURCE_DTV);
2459 break;
2460 case SOURCE_TYPE_MPEG:
2461 default:
2462 source_port = Tvin_GetSourcePortBySourceInput(SOURCE_MPEG);
2463 break;
2464 }
2465
2466 return source_port;
2467}
2468
2469
2470tvin_port_t CTvin::Tvin_GetSourcePortBySourceInput ( tv_source_input_t source_input )
2471{
2472 tvin_port_t source_port = TVIN_PORT_NULL;
2473
2474 if ( source_input < SOURCE_TV || source_input >= SOURCE_MAX ) {
2475 source_port = TVIN_PORT_NULL;
2476 } else {
2477 source_port = ( tvin_port_t ) mSourceInputToPortMap[ ( int ) source_input];
2478 }
2479
2480 return source_port;
2481}
2482
2483tv_source_input_t CTvin::Tvin_PortToSourceInput ( tvin_port_t port )
2484{
2485 int i;
2486
2487 for ( i = SOURCE_TV; i < SOURCE_MAX; i++ ) {
2488 if ( mSourceInputToPortMap[i] == port ) {
2489 break;
2490 }
2491 }
2492
2493 if ( i == SOURCE_MAX ) {
2494 return SOURCE_MAX;
2495 } else {
2496 return tv_source_input_t ( i );
2497 }
2498}
2499
2500unsigned int CTvin::Tvin_TransPortStringToValue(const char *port_str)
2501{
2502 if (strcasecmp(port_str, "TVIN_PORT_CVBS0") == 0) {
2503 return TVIN_PORT_CVBS0;
2504 } else if (strcasecmp(port_str, "TVIN_PORT_CVBS1") == 0) {
2505 return TVIN_PORT_CVBS1;
2506 } else if (strcasecmp(port_str, "TVIN_PORT_CVBS2") == 0) {
2507 return TVIN_PORT_CVBS2;
2508 } else if (strcasecmp(port_str, "TVIN_PORT_CVBS3") == 0) {
2509 return TVIN_PORT_CVBS3;
2510 } else if (strcasecmp(port_str, "TVIN_PORT_COMP0") == 0) {
2511 return TVIN_PORT_COMP0;
2512 } else if (strcasecmp(port_str, "TVIN_PORT_COMP1") == 0) {
2513 return TVIN_PORT_COMP1;
2514 } else if (strcasecmp(port_str, "TVIN_PORT_VGA0") == 0) {
2515 return TVIN_PORT_VGA0;
2516 } else if (strcasecmp(port_str, "TVIN_PORT_HDMI0") == 0) {
2517 return TVIN_PORT_HDMI0;
2518 } else if (strcasecmp(port_str, "TVIN_PORT_HDMI1") == 0) {
2519 return TVIN_PORT_HDMI1;
2520 } else if (strcasecmp(port_str, "TVIN_PORT_HDMI2") == 0) {
2521 return TVIN_PORT_HDMI2;
2522 } else if (strcasecmp(port_str, "TVIN_PORT_HDMI3") == 0) {
2523 return TVIN_PORT_HDMI3;
2524 }
2525
2526 return TVIN_PORT_MPEG0;
2527}
2528
2529void CTvin::Tvin_LoadSourceInputToPortMap()
2530{
2531 const char *SourceInputMapSection = "SourceInputMap";
2532 const char *config_value = NULL;
2533
2534 config_value = config_get_str(SourceInputMapSection, "ro.tv.tvinchannel.atv", "TVIN_PORT_CVBS3");
2535 mSourceInputToPortMap[SOURCE_TV] = Tvin_TransPortStringToValue(config_value);
2536
2537 config_value = config_get_str(SourceInputMapSection, "ro.tv.tvinchannel.av1", "TVIN_PORT_CVBS1");
2538 mSourceInputToPortMap[SOURCE_AV1] = Tvin_TransPortStringToValue(config_value);
2539
2540 config_value = config_get_str(SourceInputMapSection, "ro.tv.tvinchannel.av2", "TVIN_PORT_CVBS2");
2541 mSourceInputToPortMap[SOURCE_AV2] = Tvin_TransPortStringToValue(config_value);
2542
2543 config_value = config_get_str(SourceInputMapSection, "ro.tv.tvinchannel.ypbpr1", "TVIN_PORT_COMP0");
2544 mSourceInputToPortMap[SOURCE_YPBPR1] = Tvin_TransPortStringToValue(config_value);
2545
2546 config_value = config_get_str(SourceInputMapSection, "ro.tv.tvinchannel.ypbpr2", "TVIN_PORT_COMP1");
2547 mSourceInputToPortMap[SOURCE_YPBPR2] = Tvin_TransPortStringToValue(config_value);
2548
2549 config_value = config_get_str(SourceInputMapSection, "ro.tv.tvinchannel.hdmi1", "TVIN_PORT_HDMI0");
2550 mSourceInputToPortMap[SOURCE_HDMI1] = Tvin_TransPortStringToValue(config_value);
2551
2552 config_value = config_get_str(SourceInputMapSection, "ro.tv.tvinchannel.hdmi2", "TVIN_PORT_HDMI2");
2553 mSourceInputToPortMap[SOURCE_HDMI2] = Tvin_TransPortStringToValue(config_value);
2554
2555 config_value = config_get_str(SourceInputMapSection, "ro.tv.tvinchannel.hdmi3", "TVIN_PORT_HDMI1");
2556 mSourceInputToPortMap[SOURCE_HDMI3] = Tvin_TransPortStringToValue(config_value);
2557
2558 config_value = config_get_str(SourceInputMapSection, "ro.tv.tvinchannel.vga", "TVIN_PORT_VGA0");
2559 mSourceInputToPortMap[SOURCE_VGA] = Tvin_TransPortStringToValue(config_value);
2560
2561 mSourceInputToPortMap[SOURCE_MPEG] = TVIN_PORT_MPEG0;
2562 mSourceInputToPortMap[SOURCE_DTV] = TVIN_PORT_DTV;
2563 mSourceInputToPortMap[SOURCE_IPTV] = TVIN_PORT_BT656;
2564
2565 return;
2566}
2567
2568int CTvin::Tvin_GetSourcePortByCECPhysicalAddress(int physical_addr)
2569{
2570 if (physical_addr == 0x1000) {
2571 return TVIN_PORT_HDMI0;
2572 } else if (physical_addr == 0x2000) {
2573 return TVIN_PORT_HDMI1;
2574 } else if (physical_addr == 0x3000) {
2575 return TVIN_PORT_HDMI2;
2576 }
2577
2578 return TVIN_PORT_MAX;
2579}
2580
2581tv_audio_channel_t CTvin::Tvin_GetInputSourceAudioChannelIndex ( tv_source_input_t source_input )
2582{
2583 int aud_chan = TV_AUDIO_LINE_IN_0;
2584 const char *config_value = NULL;
2585
2586 if ( source_input == SOURCE_TV ) {
2587 config_value = config_get_str("TV", "tvin.aud.chan.atv", "2");
2588 } else if ( source_input == SOURCE_AV1 ) {
2589 config_value = config_get_str("TV", "tvin.aud.chan.av1", "1");
2590 } else if ( source_input == SOURCE_AV2 ) {
2591 config_value = config_get_str("TV", "tvin.aud.chan.av2", "3");
2592 } else if ( source_input == SOURCE_YPBPR1 ) {
2593 config_value = config_get_str("TV", "tvin.aud.chan.comp1", "0");
2594 } else if ( source_input == SOURCE_YPBPR2 ) {
2595 config_value = config_get_str("TV", "tvin.aud.chan.comp2", "0");
2596 } else if ( source_input == SOURCE_HDMI1 ) {
2597 config_value = config_get_str("TV", "tvin.aud.chan.hdmi1", "0");
2598 } else if ( source_input == SOURCE_HDMI2 ) {
2599 config_value = config_get_str("TV", "tvin.aud.chan.hdmi2", "0");
2600 } else if ( source_input == SOURCE_HDMI3 ) {
2601 config_value = config_get_str("TV", "tvin.aud.chan.hdmi3", "0");
2602 } else if ( source_input == SOURCE_VGA ) {
2603 config_value = config_get_str("TV", "tvin.aud.chan.vga", "0");
2604 } else if ( source_input == SOURCE_MPEG ) {
2605 config_value = config_get_str("TV", "tvin.aud.chan.mpeg", "0");
2606 }
2607
2608 if (config_value != NULL) {
2609 aud_chan = strtol (config_value, NULL, 10);
2610 }
2611
2612 return ( tv_audio_channel_t ) aud_chan;
2613}
2614
2615tv_audio_in_source_type_t CTvin::Tvin_GetAudioInSourceType ( tv_source_input_t source_input )
2616{
2617 const char *config_value = NULL;
2618
2619 if (source_input == SOURCE_TV) {
2620 config_value = config_get_str("TV", "tvin.aud.insource.atv", "TV_AUDIO_IN_SOURCE_TYPE_LINEIN");
2621 if (strcasecmp(config_value, "TV_AUDIO_IN_SOURCE_TYPE_ATV") == 0) {
2622 return TV_AUDIO_IN_SOURCE_TYPE_ATV;
2623 }
2624 return TV_AUDIO_IN_SOURCE_TYPE_LINEIN;
2625 } else if (source_input == SOURCE_AV1 || source_input == SOURCE_AV2) {
2626 return TV_AUDIO_IN_SOURCE_TYPE_LINEIN;
2627 } else if (source_input == SOURCE_YPBPR1 || source_input == SOURCE_YPBPR2 || source_input == SOURCE_VGA) {
2628 return TV_AUDIO_IN_SOURCE_TYPE_LINEIN;
2629 } else if (source_input == SOURCE_HDMI1 || source_input == SOURCE_HDMI2 || source_input == SOURCE_HDMI3) {
2630 return TV_AUDIO_IN_SOURCE_TYPE_HDMI;
2631 }
2632
2633 return TV_AUDIO_IN_SOURCE_TYPE_LINEIN;
2634}
2635
2636int CTvin::isVgaFmtInHdmi ( tvin_sig_fmt_t fmt )
2637{
2638 if ( fmt == TVIN_SIG_FMT_HDMI_640X480P_60HZ
2639 || fmt == TVIN_SIG_FMT_HDMI_800X600_00HZ
2640 || fmt == TVIN_SIG_FMT_HDMI_1024X768_00HZ
2641 || fmt == TVIN_SIG_FMT_HDMI_720X400_00HZ
2642 || fmt == TVIN_SIG_FMT_HDMI_1280X768_00HZ
2643 || fmt == TVIN_SIG_FMT_HDMI_1280X800_00HZ
2644 || fmt == TVIN_SIG_FMT_HDMI_1280X960_00HZ
2645 || fmt == TVIN_SIG_FMT_HDMI_1280X1024_00HZ
2646 || fmt == TVIN_SIG_FMT_HDMI_1360X768_00HZ
2647 || fmt == TVIN_SIG_FMT_HDMI_1366X768_00HZ
2648 || fmt == TVIN_SIG_FMT_HDMI_1600X1200_00HZ
2649 || fmt == TVIN_SIG_FMT_HDMI_1920X1200_00HZ ) {
2650 LOGD ( "%s, HDMI source : VGA format.", "TV" );
2651 return 1;
2652 }
2653
2654 return -1;
2655}
2656
2657int CTvin::isSDFmtInHdmi ( tvin_sig_fmt_t fmt )
2658{
2659 if ( fmt == TVIN_SIG_FMT_HDMI_640X480P_60HZ
2660 || fmt == TVIN_SIG_FMT_HDMI_720X480P_60HZ
2661 || fmt == TVIN_SIG_FMT_HDMI_1440X480I_60HZ
2662 || fmt == TVIN_SIG_FMT_HDMI_1440X240P_60HZ
2663 || fmt == TVIN_SIG_FMT_HDMI_2880X480I_60HZ
2664 || fmt == TVIN_SIG_FMT_HDMI_2880X240P_60HZ
2665 || fmt == TVIN_SIG_FMT_HDMI_1440X480P_60HZ
2666 || fmt == TVIN_SIG_FMT_HDMI_720X576P_50HZ
2667 || fmt == TVIN_SIG_FMT_HDMI_1440X576I_50HZ
2668 || fmt == TVIN_SIG_FMT_HDMI_1440X288P_50HZ
2669 || fmt == TVIN_SIG_FMT_HDMI_2880X576I_50HZ
2670 || fmt == TVIN_SIG_FMT_HDMI_2880X288P_50HZ
2671 || fmt == TVIN_SIG_FMT_HDMI_1440X576P_50HZ
2672 || fmt == TVIN_SIG_FMT_HDMI_2880X480P_60HZ
2673 || fmt == TVIN_SIG_FMT_HDMI_2880X576P_60HZ
2674 || fmt == TVIN_SIG_FMT_HDMI_720X576P_100HZ
2675 || fmt == TVIN_SIG_FMT_HDMI_1440X576I_100HZ
2676 || fmt == TVIN_SIG_FMT_HDMI_720X480P_120HZ
2677 || fmt == TVIN_SIG_FMT_HDMI_1440X480I_120HZ
2678 || fmt == TVIN_SIG_FMT_HDMI_720X576P_200HZ
2679 || fmt == TVIN_SIG_FMT_HDMI_1440X576I_200HZ
2680 || fmt == TVIN_SIG_FMT_HDMI_720X480P_240HZ
2681 || fmt == TVIN_SIG_FMT_HDMI_1440X480I_240HZ
2682 || fmt == TVIN_SIG_FMT_HDMI_800X600_00HZ
2683 || fmt == TVIN_SIG_FMT_HDMI_720X400_00HZ ) {
2684 LOGD ( "%s, SD format.", "TV" );
2685 return true;
2686 } else {
2687 LOGD ( "%s, HD format.", "TV" );
2688 return false;
2689 }
2690}
2691
2692bool CTvin::Tvin_is50HzFrameRateFmt ( tvin_sig_fmt_t fmt )
2693{
2694 /** component **/
2695 if ( fmt == TVIN_SIG_FMT_COMP_576P_50HZ_D000
2696 || fmt == TVIN_SIG_FMT_COMP_576I_50HZ_D000
2697 || fmt == TVIN_SIG_FMT_COMP_720P_50HZ_D000
2698 || fmt == TVIN_SIG_FMT_COMP_1080P_50HZ_D000
2699 || fmt == TVIN_SIG_FMT_COMP_1080I_50HZ_D000_A
2700 || fmt == TVIN_SIG_FMT_COMP_1080I_50HZ_D000_B
2701 || fmt == TVIN_SIG_FMT_COMP_1080I_50HZ_D000_C
2702 || fmt == TVIN_SIG_FMT_COMP_1080P_24HZ_D000
2703 || fmt == TVIN_SIG_FMT_COMP_1080P_25HZ_D000
2704 /** hdmi **/
2705 || fmt == TVIN_SIG_FMT_HDMI_720X576P_50HZ
2706 || fmt == TVIN_SIG_FMT_HDMI_1280X720P_50HZ
2707 || fmt == TVIN_SIG_FMT_HDMI_1920X1080I_50HZ_A
2708 || fmt == TVIN_SIG_FMT_HDMI_1440X576I_50HZ
2709 || fmt == TVIN_SIG_FMT_HDMI_1440X288P_50HZ
2710 || fmt == TVIN_SIG_FMT_HDMI_2880X576I_50HZ
2711 || fmt == TVIN_SIG_FMT_HDMI_2880X288P_50HZ
2712 || fmt == TVIN_SIG_FMT_HDMI_1440X576P_50HZ
2713 || fmt == TVIN_SIG_FMT_HDMI_1920X1080P_50HZ
2714 || fmt == TVIN_SIG_FMT_HDMI_1920X1080I_50HZ_B
2715 || fmt == TVIN_SIG_FMT_HDMI_1280X720P_50HZ_FRAME_PACKING
2716 || fmt == TVIN_SIG_FMT_HDMI_1920X1080I_50HZ_FRAME_PACKING
2717 || fmt == TVIN_SIG_FMT_HDMI_720X576P_50HZ_FRAME_PACKING
2718 /** cvbs **/
2719 || fmt == TVIN_SIG_FMT_CVBS_PAL_I
2720 || fmt == TVIN_SIG_FMT_CVBS_PAL_M
2721 || fmt == TVIN_SIG_FMT_CVBS_PAL_CN
2722 || fmt == TVIN_SIG_FMT_CVBS_SECAM ) {
2723 LOGD ( "%s, Frame rate == 50Hz.", "TV" );
2724 return true;
2725 } else {
2726 LOGD ( "%s, Frame rate != 50Hz.", "TV" );
2727 return false;
2728 }
2729}
2730
2731
2732bool CTvin::Tvin_IsDeinterlaceFmt ( tvin_sig_fmt_t fmt )
2733{
2734 if ( fmt == TVIN_SIG_FMT_COMP_480I_59HZ_D940
2735 || fmt == TVIN_SIG_FMT_COMP_576I_50HZ_D000
2736 || fmt == TVIN_SIG_FMT_COMP_1080I_47HZ_D952
2737 || fmt == TVIN_SIG_FMT_COMP_1080I_48HZ_D000
2738 || fmt == TVIN_SIG_FMT_COMP_1080I_50HZ_D000_A
2739 || fmt == TVIN_SIG_FMT_COMP_1080I_50HZ_D000_B
2740 || fmt == TVIN_SIG_FMT_COMP_1080I_50HZ_D000_C
2741 || fmt == TVIN_SIG_FMT_COMP_1080I_60HZ_D000
2742 || fmt == TVIN_SIG_FMT_HDMI_1440X480I_120HZ
2743 || fmt == TVIN_SIG_FMT_HDMI_1440X480I_240HZ
2744 || fmt == TVIN_SIG_FMT_HDMI_1440X480I_60HZ
2745 || fmt == TVIN_SIG_FMT_HDMI_1440X576I_100HZ
2746 || fmt == TVIN_SIG_FMT_HDMI_1440X576I_200HZ
2747 || fmt == TVIN_SIG_FMT_HDMI_1440X576I_50HZ
2748 || fmt == TVIN_SIG_FMT_HDMI_1920X1080I_100HZ
2749 || fmt == TVIN_SIG_FMT_HDMI_1920X1080I_120HZ
2750 || fmt == TVIN_SIG_FMT_HDMI_1920X1080I_50HZ_A
2751 || fmt == TVIN_SIG_FMT_HDMI_1920X1080I_50HZ_B
2752 || fmt == TVIN_SIG_FMT_HDMI_1920X1080I_50HZ_FRAME_PACKING
2753 || fmt == TVIN_SIG_FMT_HDMI_1920X1080I_60HZ
2754 || fmt == TVIN_SIG_FMT_HDMI_1920X1080I_60HZ_FRAME_PACKING
2755 || fmt == TVIN_SIG_FMT_HDMI_2880X480I_60HZ
2756 || fmt == TVIN_SIG_FMT_HDMI_2880X576I_50HZ
2757 || fmt == TVIN_SIG_FMT_CVBS_NTSC_M
2758 || fmt == TVIN_SIG_FMT_CVBS_NTSC_443
2759 || fmt == TVIN_SIG_FMT_CVBS_PAL_60
2760 || fmt == TVIN_SIG_FMT_CVBS_PAL_CN
2761 || fmt == TVIN_SIG_FMT_CVBS_PAL_I
2762 || fmt == TVIN_SIG_FMT_CVBS_PAL_M
2763 || fmt == TVIN_SIG_FMT_CVBS_SECAM ) {
2764 LOGD ( "%s, Interlace format.", "TV" );
2765 return true;
2766 } else {
2767 LOGD ( "%s, Progressive format.", "TV" );
2768 return false;
2769 }
2770}
2771
2772int CTvin::Tvin_StartDecoder ( tvin_info_t &info )
2773{
2774 if ( m_is_decoder_start == false ) {
2775 m_tvin_param.info = info;
2776
2777 if ( VDIN_StartDec ( &m_tvin_param ) >= 0 ) {
2778 LOGD ( "StartDecoder succeed." );
2779 m_is_decoder_start = true;
2780 } else {
2781 LOGW ( "StartDecoder failed." );
2782 return -1;
2783 }
2784 } else {
2785 return -2;
2786 }
2787
2788 return 0;
2789}
2790
2791int CTvin::SwitchPort (tvin_port_t source_port )
2792{
2793 int ret = 0;
2794 LOGD ("%s, source_port = %x", __FUNCTION__, source_port);
2795 ret = Tvin_StopDecoder();
2796 if ( 0 == ret || 1 == ret ) {
2797 if ( 1 == ret ) { //decode not started
2798 //mVpp.Tvin_SetVideoScreenColorType ( TV_SIGNAL_BLUE_PATTERN );
2799 }
2800 VDIN_ClosePort();
2801 } else {
2802 LOGW ( "%s,stop decoder failed.", __FUNCTION__);
2803 return -1;
2804 }
2805 // Open Port
2806 if ( VDIN_OpenPort ( source_port ) < 0 ) {
2807 LOGD ( "%s, OpenPort failed, source_port =%x ", __FUNCTION__, source_port );
2808 }
2809 m_tvin_param.port = source_port;
2810 return 0;
2811}
2812
2813int CTvin::Tvin_StopDecoder()
2814{
2815 if ( m_is_decoder_start == true ) {
2816 if ( VDIN_StopDec() >= 0 ) {
2817 LOGD ( "StopDecoder ok!" );
2818 m_is_decoder_start = false;
2819 return 0;
2820 } else {
2821 LOGD ( "StopDecoder Failed!" );
2822 }
2823 } else {
2824 return 1;
2825 }
2826
2827 return -1;
2828}
2829
2830int CTvin::init_vdin ( void )
2831{
2832 VDIN_OpenModule();
2833 return 0;
2834}
2835
2836int CTvin::uninit_vdin ( void )
2837{
2838 VDIN_ClosePort();
2839 VDIN_CloseModule();
2840 return 0;
2841}
2842
2843int CTvin::Tvin_AddPath ( tvin_path_id_t pathid )
2844{
2845 int ret = -1;
2846 int i = 0, dly = 10;
2847 tv_path_type_t pathtype;
2848
2849 if ( pathid >= TV_PATH_VDIN_AMVIDEO && pathid < TV_PATH_DECODER_3D_AMVIDEO ) {
2850 pathtype = TV_PATH_TYPE_TVIN;
2851 } else {
2852 pathtype = TV_PATH_TYPE_DEFAULT;
2853 }
2854
2855 if ( pathid >= TV_PATH_VDIN_AMVIDEO && pathid < TV_PATH_DECODER_3D_AMVIDEO ) {
2856 if ( m_pathid == pathid ) {
2857 LOGW ( "%s, no need to add the same tvin path.\n", "TV" );
2858 return 0;
2859 }
2860
2861 for ( i = 0; i < 50; i++ ) {
2862 ret = VDIN_RmTvPath();
2863
2864 if ( ret > 0 ) {
2865 LOGD ( "%s, remove tvin path ok, %d ms gone.\n", "TV", ( dly * i ) );
2866 break;
2867 } else {
2868 LOGW ( "%s, remove tvin path faild, %d ms gone.\n", "TV", ( dly * i ) );
2869 usleep ( dly * 1000 );
2870 }
2871 }
2872 } else {
2873 for ( i = 0; i < 50; i++ ) {
2874 ret = VDIN_RmDefPath();
2875
2876 if ( ret > 0 ) {
2877 LOGD ( "%s, remove default path ok, %d ms gone.\n", "TV", ( dly * i ) );
2878 break;
2879 } else {
2880 LOGW ( "%s, remove default path faild, %d ms gone.\n", "TV", ( dly * i ) );
2881 usleep ( dly * 1000 );
2882 }
2883 }
2884 }
2885
2886 for ( i = 0; i < 50; i++ ) {
2887 if ( pathid >= TV_PATH_VDIN_AMVIDEO && pathid < TV_PATH_DECODER_3D_AMVIDEO ) {
2888 if ( strcmp ( config_tv_path, "null" ) == 0 ) {
2889 ret = VDIN_AddVideoPath ( pathid );
2890 } else {
2891 ret = VDIN_AddPath ( config_tv_path );
2892 }
2893 } else {
2894 if ( strcmp ( config_default_path, "null" ) == 0 ) {
2895 ret = VDIN_AddVideoPath ( pathid );
2896 } else {
2897 ret = VDIN_AddPath ( config_default_path );
2898 }
2899 }
2900
2901 if ( ret >= 0 ) {
2902 LOGD ( "%s, add pathid[%d] ok, %d ms gone.\n", "TV", pathid, i );
2903 break;
2904 } else {
2905 LOGW ( "%s, add pathid[%d] faild, %d ms gone.\n", "TV", pathid, i );
2906 usleep ( dly * 1000 );
2907 }
2908 }
2909
2910 if ( pathid >= TV_PATH_VDIN_AMVIDEO && pathid < TV_PATH_MAX ) {
2911 m_pathid = pathid;
2912 }
2913
2914 return ret;
2915}
2916
2917
2918int CTvin::Tvin_RemovePath ( tv_path_type_t pathtype )
2919{
2920 int ret = -1;
2921 int i = 0, dly = 10;
2922
2923 for ( i = 0; i < 500; i++ ) {
2924 ret = Tvin_CheckPathActive ( pathtype, 0 );
2925
2926 if ( ret == TV_PATH_STATUS_INACTIVE ) {
2927 LOGD ( "%s, check path is inactive, %d ms gone.\n", "TV", ( dly * i ) );
2928 break;
2929 } else if ( ret == TV_PATH_STATUS_INACTIVE || ret == TV_PATH_STATUS_ERROR ) {
2930 usleep ( dly * 1000 );
2931 } else {
2932 break;
2933 }
2934 }
2935
2936 if ( i == 500 ) {
2937 LOGE ( "%s, check path active faild, %d ms gone.\n", "TV", ( dly * i ) );
2938 }
2939
2940 if ( pathtype == TV_PATH_TYPE_DEFAULT ) {
2941 for ( i = 0; i < 50; i++ ) {
2942 ret = VDIN_RmDefPath();
2943
2944 if ( ret > 0 ) {
2945 LOGD ( "%s, remove default path ok, %d ms gone.\n", "TV", ( dly * i ) );
2946 break;
2947 } else {
2948 LOGW ( "%s, remove default path faild, %d ms gone.\n", "TV", ( dly * i ) );
2949 usleep ( dly * 1000 );
2950 }
2951 }
2952 } else if ( pathtype == TV_PATH_TYPE_TVIN ) {
2953 for ( i = 0; i < 50; i++ ) {
2954 ret = VDIN_RmTvPath();
2955
2956 if ( ret > 0 ) {
2957 LOGD ( "%s, remove tvin path ok, %d ms gone.\n", "TV", ( dly * i ) );
2958 break;
2959 } else {
2960 LOGW ( "%s, remove tvin path faild, %d ms gone.\n", "TV", ( dly * i ) );
2961 usleep ( dly * 1000 );
2962 }
2963 }
2964
2965 m_pathid = TV_PATH_DECODER_3D_AMVIDEO;
2966 } else if ( pathtype == TV_PATH_TYPE_TVIN_PREVIEW ) {
2967 for ( i = 0; i < 50; i++ ) {
2968 ret = VDIN_RmPreviewPath();
2969
2970 if ( ret > 0 ) {
2971 LOGD ( "%s, remove preview path ok, %d ms gone.\n", "TV", ( dly * i ) );
2972 break;
2973 } else {
2974 LOGW ( "%s, remove preview path faild, %d ms gone.\n", "TV", ( dly * i ) );
2975 usleep ( dly * 1000 );
2976 }
2977 }
2978
2979 m_pathid = TV_PATH_DECODER_NEW3D_WITHOUTPPMGR_AMVIDEO;
2980 } else {
2981 ret = -1;
2982 }
2983
2984 return ret;
2985}
2986
2987
2988int CTvin::Tvin_CheckPathActive ( tv_path_type_t path_type, int isCheckD2D3 )
2989{
2990 FILE *f;
2991 char path[256];
2992 char decoder_str[20] = "default {";
2993 char tvin_str[20] = "tvpath {";
2994 char decoder_active_str[20] = "decoder(1)";
2995 char tvin_active_str[20] = "vdin0(1)";
2996 char di_active_str[20] = "deinterlace(1)";
2997 char d2d3_active_str[20] = "d2d3(1)";
2998 char decoder_inactive_str[20] = "decoder(0)";
2999 char tvin_inactive_str[20] = "vdin0(0)";
3000 char di_inactive_str[20] = "deinterlace(0)";
3001 char d2d3_inactive_str[20] = "d2d3(0)";
3002
3003 char *str_find = NULL;
3004 char *active_str = NULL;
3005 char *inactive_str = NULL;
3006 int mount_freq;
3007 int match;
3008 int is_active = TV_PATH_STATUS_INACTIVE;
3009
3010 memset ( path, 0, 255 );
3011
3012 f = fopen ( "/sys/class/vfm/map", "r" );
3013
3014 if ( !f ) {
3015 LOGE ( "%s, can not open /sys/class/vfm/map!\n", "TV" );
3016 return TV_PATH_STATUS_NO_DEV;
3017 }
3018
3019 while ( fgets ( path, 254, f ) ) {
3020 if ( path_type == TV_PATH_TYPE_DEFAULT ) {
3021 str_find = strstr ( path, decoder_str );
3022 active_str = decoder_active_str;
3023 inactive_str = decoder_inactive_str;
3024 } else if ( path_type == TV_PATH_TYPE_TVIN || path_type == TV_PATH_TYPE_TVIN_PREVIEW ) {
3025 str_find = strstr ( path, tvin_str );
3026 active_str = tvin_active_str;
3027 inactive_str = tvin_inactive_str;
3028 } else {
3029 LOGW ( "%s, there is no %d path_type.\n", "TV", path_type );
3030 break;
3031 }
3032
3033 if ( str_find ) {
3034 if ( isCheckD2D3 == 0 ) {
3035 if ( strstr ( str_find, active_str ) && strstr ( str_find, di_active_str ) ) {
3036 is_active = TV_PATH_STATUS_ACTIVE;
3037 //LOGD("%s, %s is active.\n", "TV", path);
3038 } else if ( strstr ( str_find, inactive_str )
3039 && ( strstr ( str_find, di_inactive_str ) || ( !strstr ( str_find, di_inactive_str ) ) )
3040 ) {
3041 is_active = TV_PATH_STATUS_INACTIVE;
3042 //LOGD("%s, %s is inactive.\n", "TV", path);
3043 } else {
3044 is_active = TV_PATH_STATUS_ERROR;
3045 LOGE ( "%s, %s is error!\n", "TV", path );
3046 }
3047
3048 break;
3049 } else {
3050 if ( strstr ( str_find, active_str ) && strstr ( str_find, di_active_str ) && strstr ( str_find, d2d3_active_str ) ) {
3051 is_active = TV_PATH_STATUS_ACTIVE;
3052 //LOGD("%s, %s is active.\n", "TV", path);
3053 } else if ( strstr ( str_find, inactive_str )
3054 && ( strstr ( str_find, di_inactive_str ) || ( !strstr ( str_find, di_inactive_str ) ) )
3055 && ( strstr ( str_find, d2d3_inactive_str ) || ( !strstr ( str_find, d2d3_inactive_str ) ) )
3056 ) {
3057 is_active = TV_PATH_STATUS_INACTIVE;
3058 //LOGD("%s, %s is inactive.\n", "TV", path);
3059 } else {
3060 is_active = TV_PATH_STATUS_ERROR;
3061 LOGE ( "%s, %s is error!\n", "TV", path );
3062 }
3063
3064 break;
3065 }
3066 }
3067 }
3068
3069 fclose ( f );
3070
3071 return is_active;
3072}
3073
3074
3075int CTvin::Tv_init_afe ( void )
3076{
3077 AFE_OpenModule();
3078 return 0;
3079}
3080
3081int CTvin::Tv_uninit_afe ( void )
3082{
3083 AFE_CloseModule();
3084 return 0;
3085}
3086
3087int CTvin::get_hdmi_sampling_rate()
3088{
3089 int fd;
3090 int val = 0;
3091 char bcmd[16];
3092 fd = open ( "/sys/module/tvin_hdmirx/parameters/audio_sample_rate", O_RDONLY );
3093
3094 if ( fd >= 0 ) {
3095 read ( fd, bcmd, sizeof ( bcmd ) );
3096 val = strtol ( bcmd, NULL, 10 );
3097 close ( fd );
3098 }
3099
3100 return val;
3101}
3102
3103
3104//**************************************************************************
3105CTvin::CTvinSigDetect::CTvinSigDetect ( CTvin *pTvin )
3106{
3107 m_cur_sig_info.trans_fmt = TVIN_TFMT_2D;
3108 m_cur_sig_info.fmt = TVIN_SIG_FMT_NULL;
3109 m_cur_sig_info.status = TVIN_SIG_STATUS_NULL;
3110 m_cur_sig_info.reserved = 0;
3111
3112 m_pre_sig_info = m_cur_sig_info;
3113 mDetectState = STATE_STOPED;
3114 mpObserver = NULL;
3115 mpTvin = pTvin;
3116 mKeepNosigTime = 0;
3117 mResumeLaterTime = 0;
3118 m_is_nosig_checktimes_once_valid = false;
3119}
3120
3121CTvin::CTvinSigDetect::~CTvinSigDetect()
3122{
3123
3124}
3125
3126int CTvin::CTvinSigDetect::startDetect(bool bPause)
3127{
3128 LOGD ( "startDetect()" );
3129
3130 if ( mDetectState == STATE_RUNNING || mDetectState == STATE_PAUSE ) {
3131 return mDetectState;
3132 }
3133
3134 m_cur_sig_info.trans_fmt = TVIN_TFMT_2D;
3135 m_cur_sig_info.fmt = TVIN_SIG_FMT_NULL;
3136 m_cur_sig_info.status = TVIN_SIG_STATUS_NULL;
3137 m_cur_sig_info.reserved = 0;
3138
3139 m_pre_sig_info = m_cur_sig_info;
3140
3141 //
3142 m_request_pause_detect = bPause;
3143 this->run();
3144 return mDetectState;
3145}
3146
3147int CTvin::CTvinSigDetect::initSigState()
3148{
3149 m_cur_sig_info.trans_fmt = TVIN_TFMT_2D;
3150 m_cur_sig_info.fmt = TVIN_SIG_FMT_NULL;
3151 m_cur_sig_info.status = TVIN_SIG_STATUS_NULL;
3152 m_cur_sig_info.reserved = 0;
3153 m_pre_sig_info = m_cur_sig_info;
3154 mKeepNosigTime = 0;
3155 m_is_nosig_checktimes_once_valid = false;
3156 mResumeLaterTime = 0;
3157 return 0;
3158}
3159
3160int CTvin::CTvinSigDetect::stopDetect()
3161{
3162 CMutex::Autolock _l ( mLock );
3163 LOGD ( "stopDetect()" );
3164 requestExit();
3165 return 0;
3166}
3167
3168int CTvin::CTvinSigDetect::pauseDetect()
3169{
3170 CMutex::Autolock _l ( mLock );
3171 LOGD ( "pauseDetect()" );
3172 m_request_pause_detect = true;
3173 return 0;
3174}
3175
3176int CTvin::CTvinSigDetect::requestAndWaitPauseDetect()
3177{
3178 CMutex::Autolock _l ( mLock );
3179 LOGD ( "requestAndWaitPauseDetect()" );
3180 m_request_pause_detect = true;
3181
3182 if ( mDetectState == STATE_RUNNING ) {
3183 mRequestPauseCondition.wait ( mLock );
3184 }
3185
3186 return 0;
3187}
3188
3189int CTvin::CTvinSigDetect::resumeDetect(int later)//ms
3190{
3191 CMutex::Autolock _l ( mLock );
3192 LOGD ( "resumeDetect()" );
3193 mResumeLaterTime = later;
3194 m_request_pause_detect = false;
3195 mDetectPauseCondition.signal();
3196 return 0;
3197}
3198
3199void CTvin::CTvinSigDetect::setVdinNoSigCheckKeepTimes(int times, bool isOnce)
3200{
3201 LOGD("setVdinNoSigCheckKeepTimes mKeepNosigTime = %d, times = %d", mKeepNosigTime, times);
3202 mKeepNosigTime = times;
3203 m_is_nosig_checktimes_once_valid = isOnce;
3204}
3205
3206int CTvin::CTvinSigDetect::Tv_TvinSigDetect ( int &sleeptime )
3207{
3208 mpTvin->VDIN_GetSignalInfo ( &m_cur_sig_info ); //get info
3209 //set no sig check times
3210 static long long sNosigKeepTime = 0;
3211 //LOGD("stime=%d status=%d, fmt = %d sNosigKeepTime = %d, mKeepNosigTime = %d", sleeptime, m_cur_sig_info.status,m_cur_sig_info.fmt, sNosigKeepTime, mKeepNosigTime);
3212 if ( m_cur_sig_info.status == TVIN_SIG_STATUS_NOSIG || m_cur_sig_info.status == TVIN_SIG_STATUS_NULL ) {
3213 sNosigKeepTime += sleeptime;
3214 if ( sNosigKeepTime > mKeepNosigTime ) { //real no sig
3215 //cur is no sig
3216 if ( m_is_nosig_checktimes_once_valid ) { //just once change,is nosig, and default it
3217 m_is_nosig_checktimes_once_valid = false;
3218 mKeepNosigTime = 0;
3219 }
3220 //
3221 } else {//not
3222 m_cur_sig_info.status = m_pre_sig_info.status;
3223 }
3224 } else {
3225 sNosigKeepTime = 0;
3226 //
3227 if ( m_is_nosig_checktimes_once_valid ) { //just once change,not nosig,default is
3228 m_is_nosig_checktimes_once_valid = false;
3229 mKeepNosigTime = 0;
3230 }
3231 //
3232 }
3233
3234 //if state change
3235 if ( m_cur_sig_info.status != m_pre_sig_info.status ) {
3236 //sleeptime = 200;
3237
3238 if ( m_cur_sig_info.status == TVIN_SIG_STATUS_STABLE ) { // to stable
3239 //
3240 sleeptime = 20;
3241 mpObserver->onSigToStable();
3242 } else if ( m_pre_sig_info.status == TVIN_SIG_STATUS_STABLE && m_cur_sig_info.status == TVIN_SIG_STATUS_UNSTABLE ) { //stable to unstable
3243 //
3244 //mVpp.Tvin_SetVideoScreenColorType ( TV_SIGNAL_BLACK_PATTERN );
3245 sleeptime = 20;
3246 mpObserver->onSigStableToUnstable();
3247 } else if ( m_pre_sig_info.status == TVIN_SIG_STATUS_STABLE && m_cur_sig_info.status == TVIN_SIG_STATUS_NOTSUP ) {
3248 //
3249 sleeptime = 20;
3250 mpObserver->onSigStableToUnSupport();
3251 } else if ( m_pre_sig_info.status == TVIN_SIG_STATUS_STABLE && m_cur_sig_info.status == TVIN_SIG_STATUS_NOSIG ) {
3252 //
3253 sleeptime = 20;
3254 mpObserver->onSigStableToNoSig();
3255 } else if ( m_pre_sig_info.status == TVIN_SIG_STATUS_UNSTABLE && m_cur_sig_info.status == TVIN_SIG_STATUS_NOTSUP ) {
3256 //
3257 sleeptime = 20;
3258 mpObserver->onSigUnStableToUnSupport();
3259 } else if ( m_pre_sig_info.status == TVIN_SIG_STATUS_UNSTABLE && m_cur_sig_info.status == TVIN_SIG_STATUS_NOSIG ) {
3260 //
3261 sleeptime = 20;
3262 mpObserver->onSigUnStableToNoSig();
3263 } else if ( m_pre_sig_info.status == TVIN_SIG_STATUS_NULL && m_cur_sig_info.status == TVIN_SIG_STATUS_NOSIG ) {
3264 //
3265 sleeptime = 20;
3266 mpObserver->onSigNullToNoSig();
3267 } else if ( m_pre_sig_info.status == TVIN_SIG_STATUS_NOSIG && m_cur_sig_info.status == TVIN_SIG_STATUS_UNSTABLE ) {
3268 //
3269 sleeptime = 20;
3270 mpObserver->onSigNoSigToUnstable();
3271 } else {
3272 sleeptime = 20;
3273 }
3274 } else { //state not change
3275 //sleeptime = 500;
3276
3277 switch ( m_cur_sig_info.status ) {
3278 case TVIN_SIG_STATUS_STABLE:
3279 //
3280 sleeptime = 20;//sleeptime = 500;
3281 mpObserver->onSigStillStable();
3282 if ( m_cur_sig_info.trans_fmt != m_pre_sig_info.trans_fmt ) {
3283 mpObserver->onStableTransFmtChange();
3284 }
3285 if (m_cur_sig_info.fmt != m_pre_sig_info.fmt) {
3286 mpObserver->onStableSigFmtChange();
3287 }
3288 break;
3289
3290 case TVIN_SIG_STATUS_NOTSUP:
3291 //
3292 sleeptime = 20;
3293 mpObserver->onSigStillNoSupport();
3294 break;
3295
3296 case TVIN_SIG_STATUS_UNSTABLE:
3297 //
3298 sleeptime = 20;
3299 mpObserver->onSigStillUnstable();
3300 break;
3301
3302 case TVIN_SIG_STATUS_NOSIG:
3303 //
3304 sleeptime = 20;
3305 mpObserver->onSigStillNosig();
3306 break;
3307
3308 case TVIN_SIG_STATUS_NULL:
3309 //
3310 sleeptime = 20;
3311 mpObserver->onSigStillNull();
3312 break;
3313
3314 default:
3315 //
3316 sleeptime = 20;
3317 mpObserver->onSigStillNull();
3318 break;
3319 }
3320 }
3321
3322 m_pre_sig_info = m_cur_sig_info;//backup info
3323
3324 return sleeptime;
3325}
3326
3327bool CTvin::CTvinSigDetect::threadLoop()
3328{
3329 //enter onStart()
3330 if ( mpObserver == NULL ) {
3331 return false;
3332 }
3333
3334 int sleeptime = 200;//ms
3335 mDetectState = STATE_RUNNING;
3336 mpObserver->onSigDetectEnter();
3337
3338 while ( !exitPending() ) { //requietexit() or requietexitWait() not call
3339 while ( m_request_pause_detect ) {
3340 mLock.lock();
3341 mRequestPauseCondition.broadcast();
3342 mDetectState = STATE_PAUSE;
3343 mDetectPauseCondition.wait ( mLock ); //first unlock,when return,lock again,so need,call unlock
3344 mDetectState = STATE_RUNNING;
3345 mLock.unlock();
3346 //
3347 while (!m_request_pause_detect && mResumeLaterTime > 0) {
3348 //LOGD("mResumeLaterTime = %d", mResumeLaterTime);
3349 usleep(10 * 1000);
3350 mResumeLaterTime -= 10;
3351 }
3352 }
3353
3354 //
3355 mResumeLaterTime = 0;
3356 //
3357 mpObserver->onSigDetectLoop();
3358 Tv_TvinSigDetect ( sleeptime );
3359 //可以优化
3360 if ( !m_request_pause_detect ) {
3361 usleep ( sleeptime * 1000 );
3362 }
3363 }
3364
3365 mDetectState = STATE_STOPED;
3366 mRequestPauseCondition.broadcast();
3367 //exit
3368 //return true, run again, return false,not run.
3369 return false;
3370}
3371
3372v4l2_std_id CTvin::CvbsFtmToV4l2ColorStd(tvin_sig_fmt_t fmt)
3373{
3374 v4l2_std_id v4l2_std;
3375 if (fmt == TVIN_SIG_FMT_CVBS_NTSC_M || fmt == TVIN_SIG_FMT_CVBS_NTSC_443) {
3376 v4l2_std = V4L2_COLOR_STD_NTSC;
3377 } else if (fmt >= TVIN_SIG_FMT_CVBS_PAL_I && fmt <= TVIN_SIG_FMT_CVBS_PAL_CN) {
3378 v4l2_std = V4L2_COLOR_STD_PAL;
3379 } else if (fmt == TVIN_SIG_FMT_CVBS_SECAM) {
3380 v4l2_std = V4L2_COLOR_STD_SECAM;
3381 } else {
3382 v4l2_std = V4L2_COLOR_STD_PAL;
3383 }
3384 return v4l2_std;
3385}
3386
3387
3388int CTvin::CvbsFtmToColorStdEnum(tvin_sig_fmt_t fmt)
3389{
3390 v4l2_std_id v4l2_std;
3391 if (fmt == TVIN_SIG_FMT_CVBS_NTSC_M || fmt == TVIN_SIG_FMT_CVBS_NTSC_443) {
3392 v4l2_std = CC_ATV_VIDEO_STD_NTSC;
3393 } else if (fmt >= TVIN_SIG_FMT_CVBS_PAL_I && fmt <= TVIN_SIG_FMT_CVBS_PAL_CN) {
3394 v4l2_std = CC_ATV_VIDEO_STD_PAL;
3395 } else if (fmt == TVIN_SIG_FMT_CVBS_SECAM) {
3396 v4l2_std = CC_ATV_VIDEO_STD_SECAM;
3397 } else {
3398 v4l2_std = CC_ATV_VIDEO_STD_PAL;
3399 }
3400 return v4l2_std;
3401}
3402
3403int CTvin::GetITContent()
3404{
3405 FILE *fp = NULL;
3406 int value = 0;
3407 fp = fopen("/sys/module/tvin_hdmirx/parameters/it_content", "r");
3408 if (fp == NULL) {
3409 LOGE ( "Open /sys/module/tvin_hdmirx/parameters/it_content error(%s)!\n", strerror ( errno ) );
3410 return -1;
3411 }
3412 fscanf(fp, "%d", &value );
3413 fclose(fp);
3414 fp = NULL;
3415 return value;
3416}
3417//**************************************************************************
3418