📄 drv_8722.c
字号:
/****************************************************************************/
/* CONEXANT PROPRIETARY AND CONFIDENTIAL */
/* Conexant Systems Inc. (c) 2003 - 2004 */
/* Shanghai, CHINA */
/* All Rights Reserved */
/****************************************************************************/
/*
* Filename: DRV_8722.C
*
* Description: SGS-THOMSON DCF8722 FrontEnd (Tuner + Demodulator) Driver.
* The driver is ONLY for SGS-THOMSON.
*
* Author: Steven Shen
*
****************************************************************************/
/* $Header: DRV_8722.C, 4, 2006-5-1 5:01:26, Eric (Feng) Liu$
* $Id: DRV_8722.C,v 1.3, 2006-04-30 21:01:26Z, Eric (Feng) Liu$
****************************************************************************/
/***************************/
/* Header Files */
/***************************/
#include "stbcfg.h"
#include "kal.h"
#include "iic.h"
/* header file of the cable dcf8722 can tuner driver */
#include "DRV_8722.h"
/* header file of the demodulator chip STV0297 driver */
#include "STV0297.h"
/* header file of the debug output function */
#include "DEBUGINF.h"
/***************************/
/* Local Constants */
/***************************/
/***************************/
/* Global Variables */
/***************************/
/* the STV0297 internal registers */
#include "REG0297.C"
extern int32 gST0CN[5][40];
CNIM_CFG gCNimCfg;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* ======================================================= */
/* = TUNER OPERATION FUNCTIONS OF CABLE FRONT-END DRIVER = */
/* ======================================================= */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static DRV_RETURN dcf872x_tuner_write (CNIM_CFG *pCFG);
static DRV_RETURN dcf872x_tuner_set_freq (CNIM_CFG *pCFG, u_int32 uFreq);
static DRV_RETURN dcf872x_tuner_get_freq (CNIM_CFG *pCFG, u_int32 *pData);
static DRV_RETURN dcf872x_tuner_set_cp (CNIM_CFG *pCFG, u_int8 ui8CP);
//static DRV_RETURN dcf872x_tuner_get_cp (CNIM_CFG *pCFG, u_int8 *pData);
static DRV_RETURN dcf872x_tuner_set_step (CNIM_CFG *pCFG, u_int32 uStep);
static DRV_RETURN dcf872x_tuner_init (CNIM_CFG *pCFG);
/*****************************************************************************/
/* FUNCTION: dcf872x_tuner_write */
/* */
/* PARAMETERS: pCFG - pointer to the CNIM_CFG structure */
/* */
/* DESCRIPTION: The function writes the control bytes to the tuner with i2c */
/* bus (through i2c repeater). */
/* Before writing, control bytes must be set to value to write */
/* */
/* RETURNS: DRV_OK if successful, DRV_ERROR if unsuccessful. */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/*****************************************************************************/
static DRV_RETURN dcf872x_tuner_write (CNIM_CFG *pCFG)
{
IICTRANS iicTransBuf;
u_int8 ui8Data[6];
u_int8 ui8Cmd[6];
bool bReturn;
/* setup data and commands for i2c transaction */
ui8Data[0] = pCFG->TunerB[0];
ui8Data[1] = pCFG->TunerB[1];
ui8Data[2] = pCFG->TunerB[2];
ui8Data[3] = pCFG->TunerB[3];
ui8Data[4] = pCFG->TunerB[4];
ui8Cmd[0] = IIC_START;
ui8Cmd[1] = IIC_DATA;
ui8Cmd[2] = IIC_DATA;
ui8Cmd[3] = IIC_DATA;
ui8Cmd[4] = IIC_DATA;
ui8Cmd[5] = IIC_STOP;
iicTransBuf.dwCount = 6;
iicTransBuf.pData = ui8Data;
iicTransBuf.pCmd = ui8Cmd;
if ( pCFG->TunerI2cRepeater == 1 )
{
st0_start_i2c_repeater (pCFG->DemodAddr);
}
bReturn = iicTransaction (&iicTransBuf, I2C_BUS_CABLE_FE);
if ( pCFG->TunerI2cRepeater == 1 )
{
st0_stop_i2c_repeater (pCFG->DemodAddr);
}
if (TRUE == bReturn)
{
return (DRV_OK);
}
else
{
return (DRV_ERROR);
}
}
/*****************************************************************************/
/* FUNCTION: dcf872x_tuner_set_freq */
/* */
/* PARAMETERS: pCFG - pointer to the CNIM_CFG structure */
/* uFreq - the signal frequency to tune */
/* */
/* DESCRIPTION: The function set the tuner to the signal frequency F(IN). */
/* N = F(OSC)/F(REF) = F(IN)/F(REF) + F(IF)/F(REF) */
/* = F(IN)/F(REF) + TunerIFN */
/* */
/* NOTES: Bandwidth 8 MHz = 128 * 62500, 6 MHz = 96 * 62500, 1M->16 */
/* Bandwidth 8 MHz = 256 * 31250, 6 MHz = 192 * 31250, 1M->32 */
/* Bandwidth 8 MHz = 160 * 50000, 6 MHz = 120 * 62500, 1M->20 */
/* */
/* RETURNS: DRV_OK if successful, DRV_ERROR if unsuccessful. */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/*****************************************************************************/
static DRV_RETURN dcf872x_tuner_set_freq (CNIM_CFG *pCFG, u_int32 uFreq)
{
u_int32 uDivider;
/* calculate the divider and set the tuner's programmable divider. */
uDivider = uFreq / (pCFG->TunerREF);
uDivider = uDivider + (pCFG->TunerIFN);
pCFG->TunerB[1] = (u_int8)((uDivider & 0x00007F00) >> 8);
pCFG->TunerB[2] = (u_int8)(uDivider & 0x000000FF);
/* get the tuner actual frequency. (only for debugging) */
dcf872x_tuner_get_freq (pCFG, &(pCFG->TunerFREQ));
/* write the configuration bytes to the tuner through the i2c repeater */
dcf872x_tuner_write (pCFG);
/*
* delay enough time to wait for the tuner lock, then go on.
* the delay time is about 100ms. The delay must be provided!!!
*/
task_time_sleep ((u_int32)(DCF872x_TUNER_DELAY));
return (DRV_OK);
}
/*****************************************************************************/
/* FUNCTION: dcf872x_tuner_get_freq */
/* */
/* PARAMETERS: pCFG - pointer to the CNIM_CFG structure */
/* pData - pointer to the return data */
/* */
/* DESCRIPTION: The function get the signal frequency F(IN). */
/* F(IN) = F(OSC) - F(IF) = Divider * F(STEP) - F(IF) */
/* */
/* RETURNS: DRV_OK if successful, DRV_ERROR if unsuccessful. */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/*****************************************************************************/
static DRV_RETURN dcf872x_tuner_get_freq (CNIM_CFG *pCFG, u_int32 *pData)
{
u_int32 uDivider;
uDivider = ((u_int32)(pCFG->TunerB[1]) & 0x0000007F) << 8;
uDivider += ((u_int32)(pCFG->TunerB[2]) & 0x000000FF);
if (uDivider < (pCFG->TunerIFN))
{
return (DRV_ERROR);
}
else
{
uDivider = uDivider - (pCFG->TunerIFN);
*pData = (pCFG->TunerREF) * uDivider;
return (DRV_OK);
}
}
/*****************************************************************************/
/* FUNCTION: dcf872x_tuner_set_cp */
/* */
/* PARAMETERS: pCFG - pointer to the CNIM_CFG structure */
/* ui8CP - the definition of tuner charge pump current mode */
/* */
/* DESCRIPTION: The function sets the tuner charge pump current. */
/* The tuner default charge pump current is 50 uA. */
/* */
/* RETURNS: DRV_OK if successful, DRV_ERROR if unsuccessful. */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/*****************************************************************************/
static DRV_RETURN dcf872x_tuner_set_cp (CNIM_CFG *pCFG, u_int8 ui8CP)
{
switch ( ui8CP )
{
case DCF872x_CP_220:
/* TunerB[3] - x1xx xxxx b */
pCFG->TunerB[3] = pCFG->TunerB[3] | 0x40;
break;
case DCF872x_CP_50:
/* TunerB[3] - x0xx xxxx b */
pCFG->TunerB[3] = pCFG->TunerB[3] & 0xBF;
break;
default:
/* TunerB[3] - x0xx xxxx b */
pCFG->TunerB[3] = pCFG->TunerB[3] & 0xBF;
break;
}
return (DRV_OK);
}
/*****************************************************************************/
/* FUNCTION: dcf872x_tuner_get_cp */
/* */
/* PARAMETERS: pCFG - pointer to the CNIM_CFG structure */
/* pData - pointer to the return data */
/* */
/* DESCRIPTION: The function gets the current tuner charge pump current. */
/* */
/* RETURNS: DRV_OK if successful, DRV_ERROR if unsuccessful. */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/*****************************************************************************/
/*
static DRV_RETURN dcf872x_tuner_get_cp (CNIM_CFG *pCFG, u_int8 *pData)
{
//TunerB[3] - x?xx xxxx b
if ( pCFG->TunerB[3] & 0x40 )
{
*pData = DCF872x_CP_220;
}
else
{
*pData = DCF872x_CP_50;
}
return (DRV_OK);
}
*/
/*****************************************************************************/
/* FUNCTION: dcf872x_tuner_set_step */
/* */
/* PARAMETERS: pCFG - pointer to the CNIM_CFG structure */
/* uStep - the definition of tuner step */
/* */
/* DESCRIPTION: The function sets the tuner reference frequency (step). */
/* The tuner default IF is 36000000 Hz. (FOR 36 MHz ONLY) */
/* The tuner default step is 62500 Hz. */
/* */
/* RETURNS: DRV_OK if successful, DRV_ERROR if unsuccessful. */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/*****************************************************************************/
static DRV_RETURN dcf872x_tuner_set_step (CNIM_CFG *pCFG, u_int32 uStep)
{
switch ( uStep )
{
case DCF872x_STEP_31250:
/* TunerB[3] - xxxx x01x b */
pCFG->TunerB[3] = pCFG->TunerB[3] | 0x02;
pCFG->TunerB[3] = pCFG->TunerB[3] & 0xFB;
pCFG->TunerREF = 31250;
pCFG->TunerIFN = 1152; /* TunerIFN = TunerIF / TunerREF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -