tvp5150a.c
上传用户:dahaojd
上传日期:2008-01-29
资源大小:14357k
文件大小:12k
- /*
- * Copyright 2003 by Texas Instruments Incorporated.
- * All rights reserved. Property of Texas Instruments Incorporated.
- * Restricted rights to use, duplicate or disclose this code are
- * granted through contract.
- *
- */
- /* "@(#) DDK 1.10.00.23 07-02-03 (ddk-b12)" */
- /**************************************************************************/
- /* tvp5150a.c file */
- /**************************************************************************/
- #include <std.h>
- #include <csl_i2c.h>
- #include <csl_stdinc.h>
- #include <edc.h>
- #include <tvp5150a.h>
- #include "_iic.h"
- #include "_tvp5150a.h"
- typedef enum {INTERLACED = TRUE, PROGRESSIVE = FALSE} FrameType ;
- static void configTVP5150A(Int decNum, TVP5150A_Mode inMode,
- TVP5150A_Mode outMode, TVP5150A_AnalogFormat inFormat);
- static void configTVP5146(Int decNum, TVP5150A_Mode inMode,
- TVP5150A_Mode outMode, TVP5150A_AnalogFormat inFormat);
- static void initTVP5150ADef(Uns channel);
- static void initTVP5146Def(Uns channel);
- static void powerdownTVP5150A(Int channel, Bool powerDownEnable);
- static void resetTVP5150A(Int channel);
- static void scalerReset(Uns channel);
- static void setTVP5150AInputFormat(Int channel, TVP5150A_AnalogFormat inFormat);
- static void setTVP5146InputFormat(Int channel, TVP5150A_AnalogFormat inFormat);
- static void setTVP5150ASyncMode(Int channel, Bool enableBT656Sync);
- static void setupUserDefResolution(Arg arg);
- static Int TVP5150A_ctrl(EDC_Handle handle, TVP5150A_Cmd cmd, Arg arg);
- static Int TVP5150A_close(EDC_Handle handle);
- static EDC_Handle TVP5150A_open(String devName, Arg optArg);
- EDC_Fxns TVP5150A_Fxns = {
- TVP5150A_open,
- TVP5150A_close,
- TVP5150A_ctrl
- };
- static I2C_Handle hI2C[2] = {INV, INV};
- /*
- * ======== configTVP5150A ========
- */
- static void configTVP5150A(Int decNum, TVP5150A_Mode inMode,
- TVP5150A_Mode outMode, TVP5150A_AnalogFormat inFormat)
- {
- initTVP5150ADef(decNum);
- setTVP5150AInputFormat(decNum, inFormat);
- }
- /*
- * ======== configTVP5146 ========
- */
- static void configTVP5146(Int decNum, TVP5150A_Mode inMode,
- TVP5150A_Mode outMode, TVP5150A_AnalogFormat inFormat)
- {
- initTVP5146Def(decNum);
- setTVP5146InputFormat(decNum, inFormat);
- }
- /*
- * ======== enableIPortOutput ========
- */
- /*
- static void enableIPortOutput(Int channel, Bool iPortOutputEnable)
- {
- _TVP5150A_settingsDef[channel].globals.iPortEnable = iPortOutputEnable;
- _TVP5150A_settingsDef[channel].globals.xPortEnable = !iPortOutputEnable;
- }
- */
- /*
- * ======== initTVP5150ADef ========
- */
- static void initTVP5150ADef(Uns channel)
- {
- Uint8 addrI2C;
- Uint8 misc_ctrl = 0x6D;
- Uint8 output_format = 0x47;
- // Uint8 input_sel = 0x01; // for svideo
- // Uint8 input_sel = 0x00; // for cvbs
- // Uint8 input_sel = 0x02;
- Uint8 pin_cfg = 0x00;
-
- // addrI2C = (channel == 0) ? _TVP5150A_IIC_ADDR0 : _TVP5150A_IIC_ADDR1;
- addrI2C = _TVP5150A_IIC_ADDR0;
- /* if(channel==0)
- input_sel = 0x0; //CVBS port1
- else if(channel==1)
- input_sel = 0x02; //CVBS port2
- else if(channel==2)
- input_sel = 0x01; //S-Video
- */
- // _IIC_write(hI2C[0], addrI2C,0x00, &input_sel,0x1);
- _IIC_write(hI2C[0], addrI2C,0x03, &misc_ctrl,0x1);
- _IIC_write(hI2C[0], addrI2C,0x0D, &output_format,0x1);
- _IIC_write(hI2C[0], addrI2C,0x0F, &pin_cfg,0x1);
- // _IIC_write(hI2C[channel], addrI2C,0x16, &h_start,0x1);
-
- }
- /*
- * ======== initTVP5150ADef ========
- */
- static void initTVP5146Def(Uns channel)
- {
- Uint8 addrI2C;
- Uint8 input_sel = 0x0C;
- Uint8 autoswitch = 0x3F;
- Uint8 pedestal = 0x40;
- Uint8 luminance = 0x00;
- Uint8 chrominance = 0x04;
-
- Uint8 output2 = 0x11;
- Uint8 output3 = 0xFA;
- Uint8 output4 = 0xAF;
- Uint8 output1 = 0x40;//10bit BT.656
-
- if (channel >=9 && channel <=0xC)
- output1 = 0x41;//20bit YCbCr with separate syn
-
- addrI2C = _TVP5150A_IIC_ADDR1;
- _IIC_write(hI2C[1], addrI2C,0x00, &input_sel,0x1);
- _IIC_write(hI2C[1], addrI2C,0x04, &autoswitch,0x1);
- _IIC_write(hI2C[1], addrI2C,0x06, &pedestal,0x1);
- _IIC_write(hI2C[1], addrI2C,0x08, &luminance,0x1);
- _IIC_write(hI2C[1], addrI2C,0x0E, &chrominance,0x1);
- _IIC_write(hI2C[1], addrI2C,0x33, &output1,0x1);
- _IIC_write(hI2C[1], addrI2C,0x34, &output2,0x1);
- _IIC_write(hI2C[1], addrI2C,0x35, &output3,0x1);
- _IIC_write(hI2C[1], addrI2C,0x36, &output4,0x1);
-
- }
- /*
- * ======== powerdownTVP5150A ========
- */
- static void powerdownTVP5150A(Int channel, Bool powerDownEnable)
- {
- Uint8 addrI2C;
- Uint8 powerdownSettings = 0x01;
- /*Put _TVP5150A in power down mode */
- if(!powerDownEnable) {
- powerdownSettings = 0x00;
- }
- addrI2C = (channel == 0) ? _TVP5150A_IIC_ADDR0 : _TVP5150A_IIC_ADDR1;
- _IIC_write(hI2C[channel], addrI2C,0x02,&powerdownSettings,1);
- }
- /*
- * ======== resetTVP5150A ========
- */
- static void resetTVP5150A(Int channel)
- {
- /***************************************************************/
- /* Reset 5150 */
- /***************************************************************/
- scalerReset(channel);
- powerdownTVP5150A(channel, FALSE);
- }
- /*
- * ======== scalerReset ========
- */
- static void scalerReset(Uns channel)
- {
- _TVP5150A_Generics *genericPtr;
- Uint8 addrI2C;
- addrI2C = (channel == 0) ? _TVP5150A_IIC_ADDR0 : _TVP5150A_IIC_ADDR1;
- genericPtr = &_TVP5150A_settingsDef[channel].generics;
- /* reset */
- genericPtr->reset = 1;
- _IIC_write( hI2C[channel], addrI2C, 0x05, (Uint8 *)genericPtr + 5, 1 );
- /* unreset */
- genericPtr->reset = 0;
- _IIC_write( hI2C[channel], addrI2C, 0x05, (Uint8 *)genericPtr + 5, 1 );
- }
- /*
- * ======== setTVP5150AInputFormat ========
- */
- static void setTVP5150AInputFormat(Int channel, TVP5150A_AnalogFormat inFormat)
- {
- // _TVP5150A_Generics *genericPtr;
- Uint8 addrI2C;
- // Uint8 temp=1;
- Uint8 input_format = 0;
-
- // addrI2C = (channel == 0) ? _TVP5150A_IIC_ADDR0 : _TVP5150A_IIC_ADDR1;
- addrI2C = _TVP5150A_IIC_ADDR0;
- // genericPtr = &_TVP5150A_settingsDef[channel].generics;
- if(inFormat == TVP5150A_AFMT_SVIDEO) {
- // _TVP5150A_settingsDef[channel].generics.svideo_sel = 1;
- input_format = 1;
- }
- else if(channel == 0) {
- input_format = 0;
- }
- else if(channel == 1) {
- input_format = 2;
- }
-
- _IIC_write(hI2C[0], addrI2C, 0x0, &input_format,1);
- // _IIC_write(hI2C[channel], addrI2C, 0x0, &temp,1);
- }
- /*
- * ======== setTVP5146InputFormat ========
- */
- static void setTVP5146InputFormat(Int channel, TVP5150A_AnalogFormat inFormat)
- {
- // _TVP5150A_Generics *genericPtr;
- Uint8 addrI2C;
- // Uint8 temp=1;
- Uint8 input_format = 0x0C;
-
- // addrI2C = (channel == 0) ? _TVP5150A_IIC_ADDR0 : _TVP5150A_IIC_ADDR1;
- addrI2C = _TVP5150A_IIC_ADDR1;
- // genericPtr = &_TVP5150A_settingsDef[channel].generics;
- if(inFormat == TVP5150A_AFMT_SVIDEO) {
- // _TVP5150A_settingsDef[channel].generics.svideo_sel = 1;
- input_format = 0x46;
- }
- else if(channel == 3 || channel == 9 )
- input_format = 0x01;
- else if(channel == 4 || channel == 0xA)
- input_format = 0x05;
- else if(channel == 5 || channel == 0xB)
- input_format = 0x09;
- else if(channel == 6 || channel == 0xC)
- input_format = 0x0C;
- else if(channel == 8)
- input_format = 0x84; //RGB
-
-
-
- _IIC_write(hI2C[1], addrI2C, 0x0, &input_format,1);
- // _IIC_write(hI2C[channel], addrI2C, 0x0, &temp,1);
- }
- /*
- ======== setTVP5150ASyncMode ========
- */
- /*static void setTVP5150ASyncMode(Int channel, Bool enableBT656Sync)
- {
- _TVP5150A_Generics *genericPtr;
- Uint8 addrI2C;
- addrI2C = (channel == 0) ? _TVP5150A_IIC_ADDR0 : _TVP5150A_IIC_ADDR1;
- genericPtr = &_TVP5150A_settingsDef[channel].generics;
- if(enableBT656Sync) {
- _TVP5150A_settingsDef[channel].generics.ycrcb_output_format = 0x07;
- } else {
- _TVP5150A_settingsDef[channel].generics.ycrcb_output_format = 0;
-
-
- }
- _IIC_write(hI2C[channel], addrI2C,0x0D,(Uint8 *)genericPtr + 0x0D,1);
-
- }*/
-
- /*
- * ======== setupUserDefResolution ========
- */
- /*static void setupUserDefResolution(Arg arg)
- {
- TVP5150A_ConfParams *TVP5150AParams = (TVP5150A_ConfParams *)arg;
- if(TVP5150AParams->outMode == TVP5150A_MODE_USER) {
- outModeTbl[TVP5150A_MODE_USER][0] = TVP5150AParams->hSize;
- outModeTbl[TVP5150A_MODE_USER][1] = TVP5150AParams->vSize;
- outModeTbl[TVP5150A_MODE_USER][2] = TVP5150AParams->interlaced;
-
-
- }
-
- }*/
- /*
- * ======== TVP5150A_close ========
- */
- static Int TVP5150A_close(EDC_Handle handle)
- {
- Int devId = (int)handle;
- /*First Check if the Handle is correct */
- if(devId == 0 || devId == 1) {
- /*Put _TVP5150A in power down mode */
- powerdownTVP5150A(devId, TRUE);
- return EDC_SUCCESS;
- } else {
- return EDC_FAILED;
- }
- }
- /*
- * ======== TVP5150A_ctrl ========
- */
- static Int TVP5150A_ctrl(EDC_Handle handle, TVP5150A_Cmd cmd, Arg arg)
- {
- Int devId = (int)handle;
- // _TVP5150A_Generics *genericPtr;
- // Uint8 addrI2C;
-
- // addrI2C = (devId == 0) ? _TVP5150A_IIC_ADDR0 : _TVP5150A_IIC_ADDR1;
- // genericPtr = &_TVP5150A_settingsDef[devId].generics;
- /*First Check if the Handle is correct */
- if(devId > 0xC || devId < 0) {
- return EDC_FAILED;
- }
-
- switch(cmd) {
- case EDC_CONFIG: {
- TVP5150A_ConfParams *TVP5150AParams = (TVP5150A_ConfParams *)arg;
- // hI2C[devId] = TVP5150AParams->hI2C;
- hI2C[0] = TVP5150AParams->hI2C;
- hI2C[1] = TVP5150AParams->hI2C;
- // setupUserDefResolution(arg);
- if(devId==0 || devId==1 || devId==2) {
- configTVP5150A(devId, TVP5150AParams->inMode, TVP5150AParams->outMode,
- TVP5150AParams->aFmt);
- // setTVP5150ASyncMode(devId, TVP5150AParams->enableBT656Sync);
- }
- else {
- configTVP5146(devId, TVP5150AParams->inMode, TVP5150AParams->outMode,
- TVP5150AParams->aFmt);
- }
- }
- break;
- case EDC_RESET:
- resetTVP5150A(devId);
- break;
- case TVP5150A_POWERDOWN:
- powerdownTVP5150A(devId, TRUE);
- break;
- case TVP5150A_POWERUP:
- powerdownTVP5150A(devId, FALSE);
- break;
- /*
- case TVP5150A_SET_AMUXMODE:
- _TVP5150A_settingsDef[devId].generics.analogMuxMode = (int)arg;
- */
- }
- return EDC_SUCCESS;
- }
-
- /*
- * ======== TVP5150A_open ========
- */
- static EDC_Handle TVP5150A_open(String devName, Arg optArg)
- {
- Int devId;
- /* Check if the addresse is correct */
- if(devName[0] != '/') {
- devId = -1;
- } else if(devName[1] == '0') {
- devId = 0; //TVP5150A CVBS port1
- } else if(devName[1] == '1'){
- devId = 1; //TVP5150A CVBS port2
- } else if(devName[1] == '2') {
- devId = 2; //TVP5150A S-Video
- } else if(devName[1] == '3') {
- devId = 3; //TVP5146 CVBS port1
- } else if(devName[1] == '4'){
- devId = 4; //TVP5146 CVBS port2
- } else if(devName[1] == '5') {
- devId = 5; //TVP5146 CVBS port3
- } else if(devName[1] == '6') {
- devId = 6; //TVP5146 CVBS port4
- } else if(devName[1] == '7'){
- devId = 7; //TVP5146 S-Video
- } else if(devName[1] == '8') {
- devId = 8; //TVP5146 RGB
- } else if(devName[1] == '9') {
- devId = 9; //TVP5146 CVBS port1 20bit YCbCr with separate syn
- } else if(devName[1] == 'A') {
- devId = 0xA;//TVP5146 CVBS port2 20bit YCbCr with separate syn
- } else if(devName[1] == 'B') {
- devId = 0xB; //TVP5146 CVBS port3 20bit YCbCr with separate syn
- } else if(devName[1] == 'C') {
- devId = 0xC; //TVP5146 CVBS port4 20bit YCbCr with separate syn
- } else {
- devId = -1;
- }
- return (EDC_Handle)devId;
- }
- /**************************************************************************/
- /* End of file */
- /**************************************************************************/