matv_hostdrv.c 21.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2009
*
*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
*
*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/

/*****************************************************************************
 *
 * Filename:
 * ---------
 *   matv_hostdrv.c
 *
 * Project:
 * --------
 *   Maui_sw
 *
 * Description:
 * ------------
 *   implement atv function just like sensor
 *
 * Author:
 * -------
 * -------
 *
 *============================================================================

 *****************************************************************************
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/
#if defined(__MTK_TARGET__) && defined(__ATV_SUPPORT__)
#if defined(MT6250)|| defined(MT6260)
#undef __SERIAL_SENSOR_V1_SUPPORT__
#endif

#include "drv_comm.h"
#include "IntrCtrl.h"
#include "reg_base.h"
//#include "gpio_sw.h"
#include "dcl.h"
#include "kal_release.h"
#include "matv_hostdrv.h"
#include "isp_comm_if.h"
#include "upll_ctrl.h"
#include "med_api.h"
#include "matvctrl.h"
#include "hostlib.h"
#include "camera_sccb.h"

#include "lcd_if_manager.h"
#ifndef  _MATV_NOT_REF_MCLK_
  #define _MATV_NOT_REF_MCLK_
#endif

extern void ATV_sccb_write(kal_uint32 addr, kal_uint32 para);
extern kal_uint16 ATV_sccb_read(kal_uint16 addr);
extern kal_uint8 matv_get_customization_frame_rate(void);
extern void ATVSccbInit (void);
extern void MatvGetHWInfo(P_IMAGE_SENSOR_HW_DEPENDENT_STRUCT Info);
extern void lcd_power_ctrl(kal_bool enable);

extern void matv_kal_take_sem(void);
extern void matv_kal_give_sem(void);

#if !defined(__ATV_RECORD_SUPPORT__) && defined(__MM_DCM_SUPPORT__)
#pragma arm section code = "DYNAMIC_CODE_MATVDRIVER_ROCODE", rodata = "DYNAMIC_CODE_MATVDRIVER_ROCODE"
#endif
void ATV_sccb_multi_write(kal_uint8 dev,kal_uint32 addr, kal_uint16 num,kal_uint8 *param)
{
	kal_uint32 i;
//	   volatile kal_uint32 j;  
	   for(i=0;i<num;i++,param++)
	   {
//		ATV_sccb_write((addr&0xFF), (*param));
		 MatvWriteCmosSensor((addr&0xFF), (*param));
	   // addr++;
		}

}	

kal_uint32 ATV_sccb_multi_read(kal_uint8 dev,kal_uint32 addr,kal_uint8 num,kal_uint8 *param)
{
      kal_uint32 i;
//	volatile kal_uint32 j;	
	for(i=0;i<num;i++,param++)
	{
     //*param = ATV_sccb_read((addr&0xFF));
	 *param = MatvReadCmosSensor((addr&0xFF));
	 
	// addr++;
	}
	return num;
}	

kal_bool bIsI2CInit = KAL_FALSE;	
/*************************************************************************
* FUNCTION
*	init_ATV
*
* DESCRIPTION
*	This function initialize the registers of CMOS sensor and ISP control register.
*
* PARAMETERS
*	None
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/

void ATV_i2c_init(void)
{
  	if(bIsI2CInit)
         return;
	ATVSccbInit();

	#if defined(MT6252)||defined(MT6252H)||defined(MT6250)||defined(MT6260)
	{
		CameraSccbOpen(CAMERA_SCCB_MATV, ATV_WRITE_ID, CAMERA_SCCB_8BIT, CAMERA_SCCB_8BIT, 400);
	}
	#else
	    CameraSccbOpen(CAMERA_SCCB_MATV, ATV_WRITE_ID, CAMERA_SCCB_8BIT, CAMERA_SCCB_8BIT, 400);
	#endif
	bIsI2CInit = KAL_TRUE;
}
void ATV_i2c_deinit(void)
{
	CameraSccbClose(CAMERA_SCCB_MATV);
	 bIsI2CInit = KAL_FALSE;
}

extern kal_semid 	matv_sem_id;
/*************************************************************************
* FUNCTION
*	ATV_night_mode
*
* DESCRIPTION
*	This function night mode of ATV.
*
* PARAMETERS
*	none
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void mATV_night_mode(kal_bool enable)
{ 

}	/* ATV_night_mode */



void mATV_CameraParaToSensor(nvram_camera_para_struct *pCameraPara)
{

} /* mATV_CameraParaToSensor() */

// update camera_para from sensor register
void mATV_SensorToCameraPara(nvram_camera_para_struct *pCameraPara)
{

} /* mATV_SensorToCameraPara() */

void mATV_GetSensorInfo(P_IMAGE_SENSOR_GET_SENSOR_INFO_STRUCT pSensorInfo)
{
    pSensorInfo->SensorId=mATV_SENSOR_ID;
  //  pSensorInfo->ResetActiveHigh=KAL_FALSE;
 //   pSensorInfo->PowerOnActiveHigh=KAL_FALSE;
    #if defined(__SERIAL_SENSOR_V1_SUPPORT__)
    pSensorInfo->SensorIf=IMAGE_SENSOR_IF_SERIAL;
    #else
    pSensorInfo->SensorIf=IMAGE_SENSOR_IF_PARALLEL;
    #endif
	pSensorInfo->PixelClkInv = KAL_FALSE;
    pSensorInfo->PreviewNormalDataFormat=IMAGE_SENSOR_DATA_OUT_FORMAT_YUYV;
    pSensorInfo->CaptureDataFormat=IMAGE_SENSOR_DATA_OUT_FORMAT_YUYV;
    pSensorInfo->PixelClkPolarity=POLARITY_LOW;
    pSensorInfo->HsyncPolarity=POLARITY_LOW;
    #if defined(__SERIAL_SENSOR_V1_SUPPORT__)
    pSensorInfo->VsyncPolarity=POLARITY_LOW;
    #else
    pSensorInfo->VsyncPolarity=POLARITY_HIGH;
    #endif
 //   pSensorInfo->DrivingCurrent=ISP_DRIVING_8MA;
    pSensorInfo->PreviewMclkFreq = 0;
    pSensorInfo->CaptureMclkFreq = 0;
    pSensorInfo->VideoMclkFreq = 0;
    pSensorInfo->PreviewWidth=ATV_IMAGE_SENSOR_FULL_WIDTH;
    pSensorInfo->PreviewHeight=ATV_IMAGE_SENSOR_FULL_HEIGHT;
    pSensorInfo->FullWidth=ATV_IMAGE_SENSOR_FULL_WIDTH;
    pSensorInfo->FullHeight=ATV_IMAGE_SENSOR_FULL_HEIGHT;
    pSensorInfo->SensorAfSupport=KAL_FALSE;
    pSensorInfo->SensorFlashSupport=KAL_FALSE;
} /* mATV_GetSensorInfo() */


MM_ERROR_CODE_ENUM mATV_GetSerialSensorInfo(P_SERIAL_SENSOR_INFO_IN_STRUCT In,P_SERIAL_SENSOR_INFO_OUT_STRUCT Out)
{
	Out->para_1 = KAL_TRUE; 								/* SCK clock inverse */
	Out->para_2 = 4;										/* Cycle */
	Out->para_3 = ATV_IMAGE_SENSOR_FULL_WIDTH_SERIAL; 	/* Sensor capture data valid width */
	Out->para_4 = ATV_IMAGE_SENSOR_FULL_HEIGHT_SERIAL;	/* Sensor capture data valid height */

#if defined(__SERIAL_SENSOR_V1_SUPPORT__)
	Out->para_5 = 1;// 1 lane
	Out->para_6 = 0;//DDR supprt
	Out->para_7 = 0;//CRC support
#endif

	return MM_ERROR_NONE; 
}

//#if 0
static kal_uint16 mATV_PowerOn(void)
{

//	volatile signed char i,j;
#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
	#endif
	return mATV_SENSOR_ID;
} /* mATV_PowerOn() */
//#endif

//kal_uint32 mATV_DetectSensorId(void)
//{
//    return mATV_SENSOR_ID;
//}   /* mATV_DetectSensorId() */

MM_ERROR_CODE_ENUM mATV_SensorOpen(void)
{


//    if (mATV_PowerOn()!= mATV_SENSOR_ID)
//        return MM_ERROR_SENSOR_READ_ID_FAIL;
    return MM_ERROR_NONE;
} /* mATV_SensorOpen() */

kal_uint16 mATV_get_NTSC_Framerate(kal_uint16 framerateIn)
{
    kal_uint16 return_value=ATV_15FPS;
	if(framerateIn > 200)
	{
        return_value = ATV_30FPS;
	}
    else if(framerateIn > 150)
    {
       return_value = ATV_20FPS;
	}
	/*else
	{
        return_value = ATV_15FPS;
	}*/
	return return_value;
}
/*****************************************************************************
 * FUNCTION
 *	matv_get_LCM_WriteCycle
 * DESCRIPTION
 *	get LCM Write cycle for matv hopping table
 * PARAMETERS
 *	0
 * RETURNS
  *	LCM Writecycle:  unit:  1T(for example if LCD IF Clock is 52MHZ, 1T = 19.2ns)
 *****************************************************************************/  
kal_uint16 matv_get_LCM_WriteCycle(void)
{
kal_uint16 lcm_write_cycle;
#if (defined(MT6253E) || defined(MT6253L)||defined(MT6253) || defined(MT6253D)  || defined(MT6253T) || defined(MT6252) || defined(MT6252H) || defined(MT6258) || defined(MT6258H))
kal_uint32 main_lcd_if_handle;
LCD_IOCTRL_LCD_SETTING_T main_lcd_setting; 
LCD_IOCTRL_RESULT_E result;
main_lcd_if_handle = lcd_get_ioctrl_device_if_handle(LCD_IF_USER_MATV); 
lcm_write_cycle = 0xffff;

lcd_power_ctrl(KAL_TRUE);
result = lcd_ioctrl_device_if_settings(main_lcd_if_handle, LCD_IOCTRL_QUERY_MAIN_LCD_IF, &main_lcd_setting, sizeof(LCD_IOCTRL_LCD_SETTING_T)); 
lcd_power_ctrl(KAL_FALSE);
if(result != LCD_IOCTRL_OK)
{
//   lcm_write_cycle = 0xffff;
}
else
{
  if(main_lcd_setting.lcd_if_setting.if_type == LCD_IF_TYPE_DBI_PARALLEL)
  {
       kal_uint8 tempCycle = main_lcd_setting.lcd_if_setting.if_settings.dbi_parallel_if.if_total_write_cycles; // mostly lcm write cycle shouldn't more than 255
       kal_uint8 magicBit = 0;  // platform bit
#if (defined(MT6253) || defined(MT6253D)  || defined(MT6253T))
       magicBit = 0;
#elif (defined(MT6253E) || defined(MT6253L)|| defined(MT6252) || defined(MT6252H) || defined(MT6258) || defined(MT6258H))
       magicBit = 1;
#endif
lcm_write_cycle = (magicBit<<8)|(tempCycle&0xff);
  }
  else
  {
  //     lcm_write_cycle = 0xffff;
  }
}

#else
 lcm_write_cycle = 0xffff;
#endif
  return lcm_write_cycle;
}

static void mATV_Preview_Capture_Setting(CAL_SCENARIO_ENUM ScenarioId,
								   P_IMAGE_SENSOR_SCENARIO_PARA_IN_STRUCT pParaIn,
								   P_IMAGE_SENSOR_SCENARIO_PARA_OUT_STRUCT pParaOut)

{
	kal_uint32 IsCaptureMode = 0;
		  kal_wap_trace(MOD_MATV, TRACE_INFO, "mATV_Preview\n");

	matv_kal_take_sem();
	
	pParaOut->GrabStartX=ATV_IMAGE_SENSOR_PV_INSERTED_PIXELS;
	pParaOut->GrabStartY=ATV_IMAGE_SENSOR_PV_INSERTED_LINES;
	pParaOut->ExposureWindowWidth=ATV_IMAGE_SENSOR_FULL_WIDTH;
	pParaOut->ExposureWindowHeight=ATV_IMAGE_SENSOR_FULL_HEIGHT;

	#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
	#else
	if (ScenarioId==CAL_SCENARIO_CAMERA_STILL_CAPTURE)
	{
		DrvSetChipDep(MTK_TVD_CamIFCaptureMode,1);
	}
	else
	{
		if(0 == matv_get_customization_frame_rate()) // it means use default frame rate
			DrvSetChipDep(MTK_TVD_MaxFrameRate, (mATV_get_NTSC_Framerate(pParaIn->MaxVideoFrameRate)));
		else
		   DrvSetChipDep(MTK_TVD_MaxFrameRate, (matv_get_customization_frame_rate()));
		DrvSetChipDep(MTK_TVD_CamIFCaptureMode,0);
	}
	#endif
	
	
	DrvSetChipDep(MTK_TVD_CamIFResolution,(( pParaOut->ExposureWindowWidth)<<16)|pParaOut->ExposureWindowHeight);
	matv_kal_give_sem();

}
static void mATV_Preview(CAL_SCENARIO_ENUM ScenarioId,
                               P_IMAGE_SENSOR_SCENARIO_PARA_IN_STRUCT pParaIn,
                               P_IMAGE_SENSOR_SCENARIO_PARA_OUT_STRUCT pParaOut)
{
	  pParaOut->GrabStartX=ATV_IMAGE_SENSOR_PV_INSERTED_PIXELS;
	  pParaOut->GrabStartY=ATV_IMAGE_SENSOR_PV_INSERTED_LINES;
	  pParaOut->ExposureWindowWidth=ATV_IMAGE_SENSOR_FULL_WIDTH;
	  pParaOut->ExposureWindowHeight=ATV_IMAGE_SENSOR_FULL_HEIGHT;
	  kal_wap_trace(MOD_MATV, TRACE_INFO, "mATV_Preview\n");
	  


        matv_kal_take_sem();
		if(0 == matv_get_customization_frame_rate()) // it means use default frame rate
        DrvSetChipDep(MTK_TVD_MaxFrameRate, (mATV_get_NTSC_Framerate(pParaIn->MaxVideoFrameRate)));
        else
		   DrvSetChipDep(MTK_TVD_MaxFrameRate, (matv_get_customization_frame_rate()));
		DrvSetChipDep(MTK_TVD_CamIFCaptureMode,0);
		DrvSetChipDep(MTK_TVD_CamIFResolution,(( pParaOut->ExposureWindowWidth)<<16)|pParaOut->ExposureWindowHeight);
		matv_kal_give_sem();


}/* mATV_Preview */

static void mATV_Capture(CAL_SCENARIO_ENUM ScenarioId,
                               P_IMAGE_SENSOR_SCENARIO_PARA_IN_STRUCT pParaIn,
                               P_IMAGE_SENSOR_SCENARIO_PARA_OUT_STRUCT pParaOut)
{


	  pParaOut->GrabStartX=ATV_IMAGE_SENSOR_PV_INSERTED_PIXELS;
	  pParaOut->GrabStartY=ATV_IMAGE_SENSOR_PV_INSERTED_LINES;
	  pParaOut->ExposureWindowWidth=ATV_IMAGE_SENSOR_FULL_WIDTH;
	  pParaOut->ExposureWindowHeight=ATV_IMAGE_SENSOR_FULL_HEIGHT;
		matv_kal_take_sem();
		DrvSetChipDep(MTK_TVD_CamIFCaptureMode,1);
		DrvSetChipDep(MTK_TVD_CamIFResolution,(( pParaOut->ExposureWindowWidth)<<16)|pParaOut->ExposureWindowHeight);
		matv_kal_give_sem();
} /* mATV_Capture() */

#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
//void mATV_InitOperationPara(P_IMAGE_SENSOR_GET_INIT_OPERATION_PARA_STRUCT pInitOperPara)
//{
//	pInitOperPara->CaptureDelayFrame = 2;			/* wait stable frame when sensor change mode (pre to cap) */
//	pInitOperPara->PreviewDelayFrame = 3;			/* wait stable frame when sensor change mode (cap to pre) */
//	pInitOperPara->PreviewDisplayWaitFrame = 2;	/* wait stable frame when sensor change mode (cap to pre) */

//} /* mATV_InitOperationPara() */

//void mATV_DscSupportInfo(P_IMAGE_SENSOR_GET_DSC_SUPPORT_INFO_STRUCT pDscSupportInfo)
//{

//} /* mATV_DscSupportInfo() */

// for YUV sensor sample code
//MM_ERROR_CODE_ENUM mATV_Sharpness(P_CAL_FEATURE_CTRL_STRUCT pFeatureParaIn,
//                                        P_CAL_FEATURE_CTRL_STRUCT pFeatureParaOut,
//                                        kal_uint32 FeatureParaOutLen, kal_uint32 *pRealFeatureParaOutLen)
//{

//    return MM_ERROR_NONE;
//}   /* mATV_Sharpness() */


MM_ERROR_CODE_ENUM mATV_SensorFeatureCtrl(kal_uint32 FeatureId,
                                                void* pFeatureParaIn, void* pFeatureParaOut,
                                                kal_uint32 FeatureParaOutLen, kal_uint32 *pRealFeatureParaOutLen)
{
    MM_ERROR_CODE_ENUM ErrorCode=MM_ERROR_NONE;

//    if ((FeatureId>=CAL_FEATURE_WEBCAM_BEGIN)&&
//        (FeatureId<=CAL_FEATURE_WEBCAM_END))
//    {
//        ErrorCode = MM_ERROR_INVALID_PARAMETER;
//        return ErrorCode;
//    }
    // for the features that not support in the sensor, then it is not necessary to implement it.
    switch (FeatureId)
    {
        case IMAGE_SENSOR_FEATURE_GET_SERIAL_SENSOR_INFO:
            mATV_GetSerialSensorInfo((P_SERIAL_SENSOR_INFO_IN_STRUCT) pFeatureParaIn, (P_SERIAL_SENSOR_INFO_OUT_STRUCT)pFeatureParaOut);
        break;
        case IMAGE_SENSOR_FEATURE_GET_SENSOR_INFO:
            mATV_GetSensorInfo((P_IMAGE_SENSOR_GET_SENSOR_INFO_STRUCT) pFeatureParaOut);
        break;
        case IMAGE_SENSOR_FEATURE_GET_SENSOR_ID:
            ((P_IMAGE_SENSOR_COMM_DATA_STRUCT) pFeatureParaOut)->FeatureValue=mATV_SENSOR_ID;//mATV_DetectSensorId();
        break;
//        case IMAGE_SENSOR_FEATURE_SET_CAMERA_SOURCE:
         //   CameraSource_mATV = ((P_IMAGE_SENSOR_SET_CAMERA_SOURCE_STRUCT) pFeatureParaIn)->ImageSensorIdx;
        //break;
//        case IMAGE_SENSOR_FEATURE_CTRL_NIGHTMODE:
        //    mATV_night_mode(((P_IMAGE_SENSOR_COMM_CTRL_STRUCT)pFeatureParaIn)->FeatureEnable);
//        break;

        case IMAGE_SENSOR_FEATURE_GET_SENSOR_FRAME_RATE:
			if(0 == matv_get_customization_frame_rate())
			 ErrorCode=MM_ERROR_SENSOR_FEATURE_NOT_SUPPORT;
			else
             ((P_IMAGE_SENSOR_COMM_DATA_STRUCT)pFeatureParaOut)->FeatureValue = matv_get_customization_frame_rate();
        break;

        // customized by customer
//        case CAL_FEATURE_CAMERA_STILL_CAPTURE_SIZE:
        //    ErrorCode=mATV_StillCaptureSize((P_CAL_FEATURE_CTRL_STRUCT)pFeatureParaIn,
        //                                 (P_CAL_FEATURE_CTRL_STRUCT)pFeatureParaOut, FeatureParaOutLen, pRealFeatureParaOutLen);
        //break;
        // for YUV sensor sample code
        // the following are for YUV sensor only
//        case CAL_FEATURE_CAMERA_SHARPNESS:
        // please refer the sample code of mATV_Sharpness();
        //    ErrorCode=mATV_Sharpness((P_CAL_FEATURE_CTRL_STRUCT)pFeatureParaIn,
        //                                   (P_CAL_FEATURE_CTRL_STRUCT)pFeatureParaOut, FeatureParaOutLen, pRealFeatureParaOutLen);
        //break;
//        case CAL_FEATURE_CAMERA_EV_VALUE:
//        case CAL_FEATURE_CAMERA_BANDING_FREQ:
//        case CAL_FEATURE_CAMERA_WB:
//        case CAL_FEATURE_CAMERA_HUE:
//        case CAL_FEATURE_CAMERA_BRIGHTNESS:
//        case CAL_FEATURE_CAMERA_CONTRAST:
//        case CAL_FEATURE_CAMERA_IMAGE_EFFECT:
//        case CAL_FEATURE_CAMERA_SATURATION:
//        break;
//        case IMAGE_SENSOR_FEATURE_YUV_3A_CTRL:
//        case CAL_FEATURE_CAMERA_FLASH_MODE:
            // These features are supported in YUV sensor only.
            // Put here just for notifying DD colleagues. Should be removed later for MT9P012. PC Huang 20100903
//            ErrorCode=MM_ERROR_SENSOR_FEATURE_NOT_SUPPORT;
//        break;
        // the above are for YUV sensor only

        case IMAGE_SENSOR_FEATURE_GET_INIT_OPERATION_PARA:
            //mATV_InitOperationPara((P_IMAGE_SENSOR_GET_INIT_OPERATION_PARA_STRUCT)pFeatureParaOut);

	((P_IMAGE_SENSOR_GET_INIT_OPERATION_PARA_STRUCT)pFeatureParaOut)->CaptureDelayFrame = 2;			/* wait stable frame when sensor change mode (pre to cap) */
	((P_IMAGE_SENSOR_GET_INIT_OPERATION_PARA_STRUCT)pFeatureParaOut)->PreviewDelayFrame = 3;			/* wait stable frame when sensor change mode (cap to pre) */
	((P_IMAGE_SENSOR_GET_INIT_OPERATION_PARA_STRUCT)pFeatureParaOut)->PreviewDisplayWaitFrame = 2;	/* wait stable frame when sensor change mode (cap to pre) */
			
        break;
        //case IMAGE_SENSOR_FEATURE_GET_DSC_SUPPORT_INFO:
            //mATV_DscSupportInfo((P_IMAGE_SENSOR_GET_DSC_SUPPORT_INFO_STRUCT)pFeatureParaOut);
        //break;
//        case IMAGE_SENSOR_FEATURE_SET_NVRAM_SENSOR_INFO:
            //pNvramSensorData_mATV = &(((nvram_camera_para_struct *) pFeatureParaIn)->SENSOR);
//        break;
		case IMAGE_SENSOR_FEATURE_GET_HW_DEPENDENT_SETTING:
            MatvGetHWInfo(pFeatureParaOut);
         break;
        default:
            ErrorCode=MM_ERROR_SENSOR_FEATURE_NOT_SUPPORT;
        break;
    }
    return ErrorCode;
} /* mATV_SensorFeatureCtrl() */

MM_ERROR_CODE_ENUM mATV_SensorCtrl(CAL_SCENARIO_ENUM ScenarioId, void *pParaIn,
                                         void *pParaOut, kal_uint32 ParaOutLen, kal_uint32 *pRealParaOutLen)
{
    MM_ERROR_CODE_ENUM ErrorCode=MM_ERROR_NONE;

    switch (ScenarioId)
    {
        case CAL_SCENARIO_CAMERA_PREVIEW:
        case CAL_SCENARIO_VIDEO:
            mATV_Preview(ScenarioId, pParaIn, pParaOut);
        break;
        case CAL_SCENARIO_CAMERA_STILL_CAPTURE:
            mATV_Capture(ScenarioId, pParaIn, pParaOut);
		//mATV_Preview_Capture_Setting(ScenarioId, pParaIn, pParaOut);
		break;
        default:
        break;
    }
    return ErrorCode;
}

MM_ERROR_CODE_ENUM mATV_SensorClose(void)
{
	//cis_module_power_on(KAL_FALSE);      // Power Off CIS Power
#ifdef ATV_USE_48MHZ
	UPLL_Disable(UPLL_OWNER_ISP);
#endif
    return MM_ERROR_NONE;
}


IMAGE_SENSOR_FUNCTION_STRUCT ImageSensorFunc_mATV=
{
    mATV_SensorOpen,
    mATV_SensorFeatureCtrl,
    mATV_SensorCtrl,
    mATV_SensorClose,
};

MM_ERROR_CODE_ENUM mATV_SensorFunc(P_IMAGE_SENSOR_FUNCTION_STRUCT *pfSensorFunc)
{
	*pfSensorFunc=&ImageSensorFunc_mATV;
    return MM_ERROR_NONE;
}	/* cam_module_func_config() */
#if !defined(__ATV_RECORD_SUPPORT__) && defined(__MM_DCM_SUPPORT__)
#pragma arm section code, rodata
#endif
#endif /* __MTK_TARGET__ && __ATV_SUPPORT__ */