[media] tda18271c2dd: Lots of coding-style fixes

Signed-off-by: Oliver Endriss <o.endriss@gmx.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
Oliver Endriss 2011-07-03 13:37:31 -03:00 committed by Mauro Carvalho Chehab
parent e8783950f8
commit 0fe4462930
2 changed files with 1107 additions and 1132 deletions

View File

@ -64,8 +64,7 @@ struct SRFBandMap {
u32 m_RF3_Default;
};
enum ERegister
{
enum ERegister {
ID = 0,
TM,
PL,
@ -131,7 +130,7 @@ static int i2c_write(struct i2c_adapter *adap, u8 adr, u8 *data, int len)
.buf = data, .len = len};
if (i2c_transfer(adap, &msg, 1) != 1) {
printk("i2c_write error\n");
printk(KERN_ERR "i2c_write error\n");
return -1;
}
return 0;
@ -186,7 +185,7 @@ static void reset(struct tda_state *state)
u32 ulIFLevelDVBC = 7;
u32 ulIFLevelDVBT = 6;
u32 ulXTOut = 0;
u32 ulStandbyMode = 0x06; // Send in stdb, but leave osc on
u32 ulStandbyMode = 0x06; /* Send in stdb, but leave osc on */
u32 ulSlave = 0;
u32 ulFMInput = 0;
u32 ulSettlingTime = 100;
@ -199,7 +198,8 @@ static void reset(struct tda_state *state)
state->m_IFLevelDVBT = (ulIFLevelDVBT & 0x07) << 2;
state->m_EP4 = 0x20;
if( ulXTOut != 0 ) state->m_EP4 |= 0x40;
if (ulXTOut != 0)
state->m_EP4 |= 0x40;
state->m_EP3_Standby = ((ulStandbyMode & 0x07) << 5) | 0x0F;
state->m_bMaster = (ulSlave == 0);
@ -280,11 +280,12 @@ static int ThermometerRead(struct tda_state *state, u8 *pTM_Value)
msleep(10);
CHK_ERROR(Read(state, Regs));
}
*pTM_Value = (Regs[TM] & 0x20 ) ? m_Thermometer_Map_2[Regs[TM] & 0x0F] :
m_Thermometer_Map_1[Regs[TM] & 0x0F] ;
state->m_Regs[TM] &= ~0x10; // Thermometer off
*pTM_Value = (Regs[TM] & 0x20)
? m_Thermometer_Map_2[Regs[TM] & 0x0F]
: m_Thermometer_Map_1[Regs[TM] & 0x0F] ;
state->m_Regs[TM] &= ~0x10; /* Thermometer off */
CHK_ERROR(UpdateReg(state, TM));
state->m_Regs[EP4] &= ~0x03; // CAL_mode = 0 ?????????
state->m_Regs[EP4] &= ~0x03; /* CAL_mode = 0 ????????? */
CHK_ERROR(UpdateReg(state, EP4));
} while (0);
@ -295,14 +296,14 @@ static int StandBy(struct tda_state *state)
{
int status = 0;
do {
state->m_Regs[EB12] &= ~0x20; // PD_AGC1_Det = 0
state->m_Regs[EB12] &= ~0x20; /* PD_AGC1_Det = 0 */
CHK_ERROR(UpdateReg(state, EB12));
state->m_Regs[EB18] &= ~0x83; // AGC1_loop_off = 0, AGC1_Gain = 6 dB
state->m_Regs[EB18] &= ~0x83; /* AGC1_loop_off = 0, AGC1_Gain = 6 dB */
CHK_ERROR(UpdateReg(state, EB18));
state->m_Regs[EB21] |= 0x03; // AGC2_Gain = -6 dB
state->m_Regs[EB21] |= 0x03; /* AGC2_Gain = -6 dB */
state->m_Regs[EP3] = state->m_EP3_Standby;
CHK_ERROR(UpdateReg(state, EP3));
state->m_Regs[EB23] &= ~0x06; // ForceLP_Fc2_En = 0, LP_Fc[2] = 0
state->m_Regs[EB23] &= ~0x06; /* ForceLP_Fc2_En = 0, LP_Fc[2] = 0 */
CHK_ERROR(UpdateRegs(state, EB21, EB23));
} while (0);
return status;
@ -316,9 +317,8 @@ static int CalcMainPLL(struct tda_state *state, u32 freq)
u64 OscFreq;
u32 MainDiv;
if (!SearchMap3(m_Main_PLL_Map, freq, &PostDiv, &Div)) {
if (!SearchMap3(m_Main_PLL_Map, freq, &PostDiv, &Div))
return -EINVAL;
}
OscFreq = (u64) freq * (u64) Div;
OscFreq *= (u64) 16384;
@ -328,27 +328,23 @@ static int CalcMainPLL(struct tda_state *state, u32 freq)
state->m_Regs[MPD] = PostDiv & 0x77;
state->m_Regs[MD1] = ((MainDiv >> 16) & 0x7F);
state->m_Regs[MD2] = ((MainDiv >> 8) & 0xFF);
state->m_Regs[MD3] = ((MainDiv ) & 0xFF);
state->m_Regs[MD3] = (MainDiv & 0xFF);
return UpdateRegs(state, MPD, MD3);
}
static int CalcCalPLL(struct tda_state *state, u32 freq)
{
//KdPrintEx((MSG_TRACE " - " __FUNCTION__ "(%d)\n",freq));
u8 PostDiv;
u8 Div;
u64 OscFreq;
u32 CalDiv;
if (!SearchMap3(m_Cal_PLL_Map, freq, &PostDiv, &Div))
{
return -EINVAL;
}
OscFreq = (u64)freq * (u64)Div;
//CalDiv = u32( OscFreq * 16384 / 16000000 );
/* CalDiv = u32( OscFreq * 16384 / 16000000 ); */
OscFreq *= (u64)16384;
do_div(OscFreq, (u64)16000000);
CalDiv = OscFreq;
@ -356,7 +352,7 @@ static int CalcCalPLL(struct tda_state *state, u32 freq)
state->m_Regs[CPD] = PostDiv;
state->m_Regs[CD1] = ((CalDiv >> 16) & 0xFF);
state->m_Regs[CD2] = ((CalDiv >> 8) & 0xFF);
state->m_Regs[CD3] = ((CalDiv ) & 0xFF);
state->m_Regs[CD3] = (CalDiv & 0xFF);
return UpdateRegs(state, CPD, CD3);
}
@ -364,7 +360,6 @@ static int CalcCalPLL(struct tda_state *state, u32 freq)
static int CalibrateRF(struct tda_state *state,
u8 RFBand, u32 freq, s32 *pCprog)
{
//KdPrintEx((MSG_TRACE " - " __FUNCTION__ " ID = %02x\n",state->m_Regs[ID]));
int status = 0;
u8 Regs[NUM_REGS];
do {
@ -373,24 +368,20 @@ static int CalibrateRF(struct tda_state *state,
u8 RFC_K = 0;
u8 RFC_M = 0;
state->m_Regs[EP4] &= ~0x03; // CAL_mode = 0
state->m_Regs[EP4] &= ~0x03; /* CAL_mode = 0 */
CHK_ERROR(UpdateReg(state, EP4));
state->m_Regs[EB18] |= 0x03; // AGC1_Gain = 3
state->m_Regs[EB18] |= 0x03; /* AGC1_Gain = 3 */
CHK_ERROR(UpdateReg(state, EB18));
// Switching off LT (as datasheet says) causes calibration on C1 to fail
// (Readout of Cprog is allways 255)
if( state->m_Regs[ID] != 0x83 ) // C1: ID == 83, C2: ID == 84
{
state->m_Regs[EP3] |= 0x40; // SM_LT = 1
}
/* Switching off LT (as datasheet says) causes calibration on C1 to fail */
/* (Readout of Cprog is allways 255) */
if (state->m_Regs[ID] != 0x83) /* C1: ID == 83, C2: ID == 84 */
state->m_Regs[EP3] |= 0x40; /* SM_LT = 1 */
if (!(SearchMap1(m_BP_Filter_Map, freq, &BP_Filter) &&
SearchMap1(m_GainTaper_Map, freq, &GainTaper) &&
SearchMap3(m_KM_Map, freq, &RFC_K, &RFC_M)))
{
return -EINVAL;
}
state->m_Regs[EP1] = (state->m_Regs[EP1] & ~0x07) | BP_Filter;
state->m_Regs[EP2] = (RFBand << 5) | GainTaper;
@ -400,19 +391,19 @@ static int CalibrateRF(struct tda_state *state,
CHK_ERROR(UpdateRegs(state, EP1, EP3));
CHK_ERROR(UpdateReg(state, EB13));
state->m_Regs[EB4] |= 0x20; // LO_ForceSrce = 1
state->m_Regs[EB4] |= 0x20; /* LO_ForceSrce = 1 */
CHK_ERROR(UpdateReg(state, EB4));
state->m_Regs[EB7] |= 0x20; // CAL_ForceSrce = 1
state->m_Regs[EB7] |= 0x20; /* CAL_ForceSrce = 1 */
CHK_ERROR(UpdateReg(state, EB7));
state->m_Regs[EB14] = 0; // RFC_Cprog = 0
state->m_Regs[EB14] = 0; /* RFC_Cprog = 0 */
CHK_ERROR(UpdateReg(state, EB14));
state->m_Regs[EB20] &= ~0x20; // ForceLock = 0;
state->m_Regs[EB20] &= ~0x20; /* ForceLock = 0; */
CHK_ERROR(UpdateReg(state, EB20));
state->m_Regs[EP4] |= 0x03; // CAL_Mode = 3
state->m_Regs[EP4] |= 0x03; /* CAL_Mode = 3 */
CHK_ERROR(UpdateRegs(state, EP4, EP5));
CHK_ERROR(CalcCalPLL(state, freq));
@ -424,20 +415,20 @@ static int CalibrateRF(struct tda_state *state,
CHK_ERROR(UpdateReg(state, EP2));
CHK_ERROR(UpdateReg(state, EP1));
state->m_Regs[EB4] &= ~0x20; // LO_ForceSrce = 0
state->m_Regs[EB4] &= ~0x20; /* LO_ForceSrce = 0 */
CHK_ERROR(UpdateReg(state, EB4));
state->m_Regs[EB7] &= ~0x20; // CAL_ForceSrce = 0
state->m_Regs[EB7] &= ~0x20; /* CAL_ForceSrce = 0 */
CHK_ERROR(UpdateReg(state, EB7));
msleep(10);
state->m_Regs[EB20] |= 0x20; // ForceLock = 1;
state->m_Regs[EB20] |= 0x20; /* ForceLock = 1; */
CHK_ERROR(UpdateReg(state, EB20));
msleep(60);
state->m_Regs[EP4] &= ~0x03; // CAL_Mode = 0
state->m_Regs[EP3] &= ~0x40; // SM_LT = 0
state->m_Regs[EB18] &= ~0x03; // AGC1_Gain = 0
state->m_Regs[EP4] &= ~0x03; /* CAL_Mode = 0 */
state->m_Regs[EP3] &= ~0x40; /* SM_LT = 0 */
state->m_Regs[EB18] &= ~0x03; /* AGC1_Gain = 0 */
CHK_ERROR(UpdateReg(state, EB18));
CHK_ERROR(UpdateRegs(state, EP3, EP4));
CHK_ERROR(UpdateReg(state, EP1));
@ -445,7 +436,6 @@ static int CalibrateRF(struct tda_state *state,
CHK_ERROR(ReadExtented(state, Regs));
*pCprog = Regs[EB14];
//KdPrintEx((MSG_TRACE " - " __FUNCTION__ " Cprog = %d\n",Regs[EB14]));
} while (0);
return status;
@ -454,7 +444,6 @@ static int CalibrateRF(struct tda_state *state,
static int RFTrackingFiltersInit(struct tda_state *state,
u8 RFBand)
{
//KdPrintEx((MSG_TRACE " - " __FUNCTION__ "\n"));
int status = 0;
u32 RF1 = m_RF_Band_Map[RFBand].m_RF1_Default;
@ -480,13 +469,13 @@ static int RFTrackingFiltersInit(struct tda_state *state,
CHK_ERROR(CalibrateRF(state, RFBand, RF1, &Cprog_cal1));
}
SearchMap2(m_RF_Cal_Map, RF1, &Cprog_table1);
if( !bcal ) {
if (!bcal)
Cprog_cal1 = Cprog_table1;
}
state->m_RF_B1[RFBand] = Cprog_cal1 - Cprog_table1;
//state->m_RF_A1[RF_Band] = ????
/* state->m_RF_A1[RF_Band] = ???? */
if( RF2 == 0 ) break;
if (RF2 == 0)
break;
CHK_ERROR(PowerScan(state, RFBand, RF2, &RF2, &bcal));
if (bcal) {
@ -494,26 +483,22 @@ static int RFTrackingFiltersInit(struct tda_state *state,
}
SearchMap2(m_RF_Cal_Map, RF2, &Cprog_table2);
if (!bcal)
{
Cprog_cal2 = Cprog_table2;
}
state->m_RF_A1[RFBand] =
(Cprog_cal2 - Cprog_table2 - Cprog_cal1 + Cprog_table1) /
((s32)(RF2) - (s32)(RF1));
if( RF3 == 0 ) break;
if (RF3 == 0)
break;
CHK_ERROR(PowerScan(state, RFBand, RF3, &RF3, &bcal));
if( bcal )
{
if (bcal) {
CHK_ERROR(CalibrateRF(state, RFBand, RF3, &Cprog_cal3));
}
SearchMap2(m_RF_Cal_Map, RF3, &Cprog_table3);
if (!bcal)
{
Cprog_cal3 = Cprog_table3;
}
state->m_RF_A2[RFBand] = (Cprog_cal3 - Cprog_table3 - Cprog_cal2 + Cprog_table2) / ((s32)(RF3) - (s32)(RF2));
state->m_RF_B2[RFBand] = Cprog_cal2 - Cprog_table2;
@ -524,7 +509,7 @@ static int RFTrackingFiltersInit(struct tda_state *state,
state->m_RF3[RFBand] = RF3;
#if 0
printk("%s %d RF1 = %d A1 = %d B1 = %d RF2 = %d A2 = %d B2 = %d RF3 = %d\n", __FUNCTION__,
printk(KERN_ERR "%s %d RF1 = %d A1 = %d B1 = %d RF2 = %d A2 = %d B2 = %d RF3 = %d\n", __func__,
RFBand, RF1, state->m_RF_A1[RFBand], state->m_RF_B1[RFBand], RF2,
state->m_RF_A2[RFBand], state->m_RF_B2[RFBand], RF3);
#endif
@ -535,7 +520,6 @@ static int RFTrackingFiltersInit(struct tda_state *state,
static int PowerScan(struct tda_state *state,
u8 RFBand, u32 RF_in, u32 *pRF_Out, bool *pbcal)
{
//KdPrintEx((MSG_TRACE " - " __FUNCTION__ "(%d,%d)\n",RFBand,RF_in));
int status = 0;
do {
u8 Gain_Taper = 0;
@ -552,7 +536,8 @@ static int PowerScan(struct tda_state *state,
if (!(SearchMap2(m_RF_Cal_Map, RF_in, &RFC_Cprog) &&
SearchMap1(m_GainTaper_Map, RF_in, &Gain_Taper) &&
SearchMap3(m_CID_Target_Map, RF_in, &CID_Target, &CountLimit))) {
printk("%s Search map failed\n", __FUNCTION__);
printk(KERN_ERR "%s Search map failed\n", __func__);
return -EINVAL;
}
@ -564,12 +549,12 @@ static int PowerScan(struct tda_state *state,
freq_MainPLL = RF_in + 1000000;
CHK_ERROR(CalcMainPLL(state, freq_MainPLL));
msleep(5);
state->m_Regs[EP4] = (state->m_Regs[EP4] & ~0x03) | 1; // CAL_mode = 1
state->m_Regs[EP4] = (state->m_Regs[EP4] & ~0x03) | 1; /* CAL_mode = 1 */
CHK_ERROR(UpdateReg(state, EP4));
CHK_ERROR(UpdateReg(state,EP2)); // Launch power measurement
CHK_ERROR(UpdateReg(state, EP2)); /* Launch power measurement */
CHK_ERROR(ReadExtented(state, Regs));
CID_Gain = Regs[EB10] & 0x3F;
state->m_Regs[ID] = Regs[ID]; // Chip version, (needed for C1 workarround in CalibrateRF )
state->m_Regs[ID] = Regs[ID]; /* Chip version, (needed for C1 workarround in CalibrateRF) */
*pRF_Out = RF_in;
@ -578,46 +563,42 @@ static int PowerScan(struct tda_state *state,
CHK_ERROR(CalcMainPLL(state, freq_MainPLL));
msleep(wait ? 5 : 1);
wait = false;
CHK_ERROR(UpdateReg(state,EP2)); // Launch power measurement
CHK_ERROR(UpdateReg(state, EP2)); /* Launch power measurement */
CHK_ERROR(ReadExtented(state, Regs));
CID_Gain = Regs[EB10] & 0x3F;
Count += 200000;
if( Count < CountLimit * 100000 ) continue;
if( sign < 0 ) break;
if (Count < CountLimit * 100000)
continue;
if (sign < 0)
break;
sign = -sign;
Count = 200000;
wait = true;
}
CHK_ERROR(status);
if( CID_Gain >= CID_Target )
{
if (CID_Gain >= CID_Target) {
*pbcal = true;
*pRF_Out = freq_MainPLL - 1000000;
}
else
{
} else
*pbcal = false;
}
} while (0);
//KdPrintEx((MSG_TRACE " - " __FUNCTION__ " Found = %d RF = %d\n",*pbcal,*pRF_Out));
return status;
}
static int PowerScanInit(struct tda_state *state)
{
//KdPrintEx((MSG_TRACE " - " __FUNCTION__ "\n"));
int status = 0;
do
{
do {
state->m_Regs[EP3] = (state->m_Regs[EP3] & ~0x1F) | 0x12;
state->m_Regs[EP4] = (state->m_Regs[EP4] & ~0x1F); // If level = 0, Cal mode = 0
state->m_Regs[EP4] = (state->m_Regs[EP4] & ~0x1F); /* If level = 0, Cal mode = 0 */
CHK_ERROR(UpdateRegs(state, EP3, EP4));
state->m_Regs[EB18] = (state->m_Regs[EB18] & ~0x03 ); // AGC 1 Gain = 0
state->m_Regs[EB18] = (state->m_Regs[EB18] & ~0x03); /* AGC 1 Gain = 0 */
CHK_ERROR(UpdateReg(state, EB18));
state->m_Regs[EB21] = (state->m_Regs[EB21] & ~0x03 ); // AGC 2 Gain = 0 (Datasheet = 3)
state->m_Regs[EB23] = (state->m_Regs[EB23] | 0x06 ); // ForceLP_Fc2_En = 1, LPFc[2] = 1
state->m_Regs[EB21] = (state->m_Regs[EB21] & ~0x03); /* AGC 2 Gain = 0 (Datasheet = 3) */
state->m_Regs[EB23] = (state->m_Regs[EB23] | 0x06); /* ForceLP_Fc2_En = 1, LPFc[2] = 1 */
CHK_ERROR(UpdateRegs(state, EB21, EB23));
} while (0);
return status;
@ -625,11 +606,9 @@ static int PowerScanInit(struct tda_state *state)
static int CalcRFFilterCurve(struct tda_state *state)
{
//KdPrintEx((MSG_TRACE " - " __FUNCTION__ "\n"));
int status = 0;
do
{
msleep(200); // Temperature stabilisation
do {
msleep(200); /* Temperature stabilisation */
CHK_ERROR(PowerScanInit(state));
CHK_ERROR(RFTrackingFiltersInit(state, 0));
CHK_ERROR(RFTrackingFiltersInit(state, 1));
@ -638,7 +617,7 @@ static int CalcRFFilterCurve(struct tda_state *state)
CHK_ERROR(RFTrackingFiltersInit(state, 4));
CHK_ERROR(RFTrackingFiltersInit(state, 5));
CHK_ERROR(RFTrackingFiltersInit(state, 6));
CHK_ERROR(ThermometerRead(state,&state->m_TMValue_RFCal)); // also switches off Cal mode !!!
CHK_ERROR(ThermometerRead(state, &state->m_TMValue_RFCal)); /* also switches off Cal mode !!! */
} while (0);
return status;
@ -663,7 +642,7 @@ static int FixedContentsI2CUpdate(struct tda_state *state)
do {
CHK_ERROR(UpdateRegs(state, TM, EB23));
// AGC1 gain setup
/* AGC1 gain setup */
state->m_Regs[EB17] = 0x00;
CHK_ERROR(UpdateReg(state, EB17));
state->m_Regs[EB17] = 0x03;
@ -673,7 +652,7 @@ static int FixedContentsI2CUpdate(struct tda_state *state)
state->m_Regs[EB17] = 0x4C;
CHK_ERROR(UpdateReg(state, EB17));
// IRC Cal Low band
/* IRC Cal Low band */
state->m_Regs[EP3] = 0x1F;
state->m_Regs[EP4] = 0x66;
state->m_Regs[EP5] = 0x81;
@ -685,13 +664,15 @@ static int FixedContentsI2CUpdate(struct tda_state *state)
state->m_Regs[MD1] = 0x77;
state->m_Regs[MD2] = 0x08;
state->m_Regs[MD3] = 0x00;
CHK_ERROR(UpdateRegs(state,EP2,MD3)); // diff between sw and datasheet (ep3-md3)
CHK_ERROR(UpdateRegs(state, EP2, MD3)); /* diff between sw and datasheet (ep3-md3) */
//state->m_Regs[EB4] = 0x61; // missing in sw
//CHK_ERROR(UpdateReg(state,EB4));
//msleep(1);
//state->m_Regs[EB4] = 0x41;
//CHK_ERROR(UpdateReg(state,EB4));
#if 0
state->m_Regs[EB4] = 0x61; /* missing in sw */
CHK_ERROR(UpdateReg(state, EB4));
msleep(1);
state->m_Regs[EB4] = 0x41;
CHK_ERROR(UpdateReg(state, EB4));
#endif
msleep(5);
CHK_ERROR(UpdateReg(state, EP1));
@ -706,11 +687,11 @@ static int FixedContentsI2CUpdate(struct tda_state *state)
CHK_ERROR(UpdateReg(state, EP2));
msleep(30);
// IRC Cal mid band
/* IRC Cal mid band */
state->m_Regs[EP5] = 0x82;
state->m_Regs[CPD] = 0xA8;
state->m_Regs[CD2] = 0x00;
state->m_Regs[MPD] = 0xA1; // Datasheet = 0xA9
state->m_Regs[MPD] = 0xA1; /* Datasheet = 0xA9 */
state->m_Regs[MD1] = 0x73;
state->m_Regs[MD2] = 0x1A;
CHK_ERROR(UpdateRegs(state, EP3, MD3));
@ -728,12 +709,12 @@ static int FixedContentsI2CUpdate(struct tda_state *state)
CHK_ERROR(UpdateReg(state, EP2));
msleep(30);
// IRC Cal high band
/* IRC Cal high band */
state->m_Regs[EP5] = 0x83;
state->m_Regs[CPD] = 0x98;
state->m_Regs[CD1] = 0x65;
state->m_Regs[CD2] = 0x00;
state->m_Regs[MPD] = 0x91; // Datasheet = 0x91
state->m_Regs[MPD] = 0x91; /* Datasheet = 0x91 */
state->m_Regs[MD1] = 0x71;
state->m_Regs[MD2] = 0xCD;
CHK_ERROR(UpdateRegs(state, EP3, MD3));
@ -748,7 +729,7 @@ static int FixedContentsI2CUpdate(struct tda_state *state)
CHK_ERROR(UpdateReg(state, EP2));
msleep(30);
// Back to normal
/* Back to normal */
state->m_Regs[EP4] = 0x64;
CHK_ERROR(UpdateReg(state, EP4));
CHK_ERROR(UpdateReg(state, EP1));
@ -761,12 +742,11 @@ static int InitCal(struct tda_state *state)
{
int status = 0;
do
{
do {
CHK_ERROR(FixedContentsI2CUpdate(state));
CHK_ERROR(CalcRFFilterCurve(state));
CHK_ERROR(StandBy(state));
//m_bInitDone = true;
/* m_bInitDone = true; */
} while (0);
return status;
};
@ -782,12 +762,10 @@ static int RFTrackingFiltersCorrection(struct tda_state *state,
if (!SearchMap2(m_RF_Cal_Map, Frequency, &Cprog_table) ||
!SearchMap4(m_RF_Band_Map, Frequency, &RFBand) ||
!SearchMap1(m_RF_Cal_DC_Over_DT_Map, Frequency, &dCoverdT))
{
return -EINVAL;
}
do
{
return -EINVAL;
do {
u8 TMValue_Current;
u32 RF1 = state->m_RF1[RFBand];
u32 RF2 = state->m_RF1[RFBand];
@ -799,31 +777,29 @@ static int RFTrackingFiltersCorrection(struct tda_state *state,
s32 Capprox = 0;
int TComp;
state->m_Regs[EP3] &= ~0xE0; // Power up
state->m_Regs[EP3] &= ~0xE0; /* Power up */
CHK_ERROR(UpdateReg(state, EP3));
CHK_ERROR(ThermometerRead(state, &TMValue_Current));
if (RF3 == 0 || Frequency < RF2)
{
Capprox = RF_A1 * ((s32)(Frequency) - (s32)(RF1)) + RF_B1 + Cprog_table;
}
else
{
Capprox = RF_A2 * ((s32)(Frequency) - (s32)(RF2)) + RF_B2 + Cprog_table;
}
TComp = (int)(dCoverdT) * ((int)(TMValue_Current) - (int)(state->m_TMValue_RFCal))/1000;
Capprox += TComp;
if( Capprox < 0 ) Capprox = 0;
else if( Capprox > 255 ) Capprox = 255;
if (Capprox < 0)
Capprox = 0;
else if (Capprox > 255)
Capprox = 255;
// TODO Temperature compensation. There is defenitely a scale factor
// missing in the datasheet, so leave it out for now.
state->m_Regs[EB14] = (Capprox );
/* TODO Temperature compensation. There is defenitely a scale factor */
/* missing in the datasheet, so leave it out for now. */
state->m_Regs[EB14] = Capprox;
CHK_ERROR(UpdateReg(state, EB14));
@ -844,66 +820,70 @@ static int ChannelConfiguration(struct tda_state *state,
u8 IR_Meas;
state->IF = IntermediateFrequency;
//printk("%s Freq = %d Standard = %d IF = %d\n",__FUNCTION__,Frequency,Standard,IntermediateFrequency);
// get values from tables
/* printk("%s Freq = %d Standard = %d IF = %d\n", __func__, Frequency, Standard, IntermediateFrequency); */
/* get values from tables */
if (!(SearchMap1(m_BP_Filter_Map, Frequency, &BP_Filter) &&
SearchMap1(m_GainTaper_Map, Frequency, &GainTaper) &&
SearchMap1(m_IR_Meas_Map, Frequency, &IR_Meas) &&
SearchMap4(m_RF_Band_Map,Frequency,&RF_Band) ) )
{
printk("%s SearchMap failed\n", __FUNCTION__);
SearchMap4(m_RF_Band_Map, Frequency, &RF_Band))) {
printk(KERN_ERR "%s SearchMap failed\n", __func__);
return -EINVAL;
}
do
{
do {
state->m_Regs[EP3] = (state->m_Regs[EP3] & ~0x1F) | m_StandardTable[Standard].m_EP3_4_0;
state->m_Regs[EP3] &= ~0x04; // switch RFAGC to high speed mode
state->m_Regs[EP3] &= ~0x04; /* switch RFAGC to high speed mode */
// m_EP4 default for XToutOn, CAL_Mode (0)
/* m_EP4 default for XToutOn, CAL_Mode (0) */
state->m_Regs[EP4] = state->m_EP4 | ((Standard > HF_AnalogMax) ? state->m_IFLevelDigital : state->m_IFLevelAnalog);
//state->m_Regs[EP4] = state->m_EP4 | state->m_IFLevelDigital;
if( Standard <= HF_AnalogMax ) state->m_Regs[EP4] = state->m_EP4 | state->m_IFLevelAnalog;
else if( Standard <= HF_ATSC ) state->m_Regs[EP4] = state->m_EP4 | state->m_IFLevelDVBT;
else if( Standard <= HF_DVBC ) state->m_Regs[EP4] = state->m_EP4 | state->m_IFLevelDVBC;
else state->m_Regs[EP4] = state->m_EP4 | state->m_IFLevelDigital;
/* state->m_Regs[EP4] = state->m_EP4 | state->m_IFLevelDigital; */
if (Standard <= HF_AnalogMax)
state->m_Regs[EP4] = state->m_EP4 | state->m_IFLevelAnalog;
else if (Standard <= HF_ATSC)
state->m_Regs[EP4] = state->m_EP4 | state->m_IFLevelDVBT;
else if (Standard <= HF_DVBC)
state->m_Regs[EP4] = state->m_EP4 | state->m_IFLevelDVBC;
else
state->m_Regs[EP4] = state->m_EP4 | state->m_IFLevelDigital;
if( (Standard == HF_FM_Radio) && state->m_bFMInput ) state->m_Regs[EP4] |= 80;
if ((Standard == HF_FM_Radio) && state->m_bFMInput)
state->m_Regs[EP4] |= 80;
state->m_Regs[MPD] &= ~0x80;
if( Standard > HF_AnalogMax ) state->m_Regs[MPD] |= 0x80; // Add IF_notch for digital
if (Standard > HF_AnalogMax)
state->m_Regs[MPD] |= 0x80; /* Add IF_notch for digital */
state->m_Regs[EB22] = m_StandardTable[Standard].m_EB22;
// Note: This is missing from flowchart in TDA18271 specification ( 1.5 MHz cutoff for FM )
if( Standard == HF_FM_Radio ) state->m_Regs[EB23] |= 0x06; // ForceLP_Fc2_En = 1, LPFc[2] = 1
else state->m_Regs[EB23] &= ~0x06; // ForceLP_Fc2_En = 0, LPFc[2] = 0
/* Note: This is missing from flowchart in TDA18271 specification ( 1.5 MHz cutoff for FM ) */
if (Standard == HF_FM_Radio)
state->m_Regs[EB23] |= 0x06; /* ForceLP_Fc2_En = 1, LPFc[2] = 1 */
else
state->m_Regs[EB23] &= ~0x06; /* ForceLP_Fc2_En = 0, LPFc[2] = 0 */
CHK_ERROR(UpdateRegs(state, EB22, EB23));
state->m_Regs[EP1] = (state->m_Regs[EP1] & ~0x07) | 0x40 | BP_Filter; // Dis_Power_level = 1, Filter
state->m_Regs[EP1] = (state->m_Regs[EP1] & ~0x07) | 0x40 | BP_Filter; /* Dis_Power_level = 1, Filter */
state->m_Regs[EP5] = (state->m_Regs[EP5] & ~0x07) | IR_Meas;
state->m_Regs[EP2] = (RF_Band << 5) | GainTaper;
state->m_Regs[EB1] = (state->m_Regs[EB1] & ~0x07) |
(state->m_bMaster ? 0x04 : 0x00); // CALVCO_FortLOn = MS
// AGC1_always_master = 0
// AGC_firstn = 0
(state->m_bMaster ? 0x04 : 0x00); /* CALVCO_FortLOn = MS */
/* AGC1_always_master = 0 */
/* AGC_firstn = 0 */
CHK_ERROR(UpdateReg(state, EB1));
if( state->m_bMaster )
{
if (state->m_bMaster) {
CHK_ERROR(CalcMainPLL(state, Frequency + IntermediateFrequency));
CHK_ERROR(UpdateRegs(state, TM, EP5));
state->m_Regs[EB4] |= 0x20; // LO_forceSrce = 1
state->m_Regs[EB4] |= 0x20; /* LO_forceSrce = 1 */
CHK_ERROR(UpdateReg(state, EB4));
msleep(1);
state->m_Regs[EB4] &= ~0x20; // LO_forceSrce = 0
state->m_Regs[EB4] &= ~0x20; /* LO_forceSrce = 0 */
CHK_ERROR(UpdateReg(state, EB4));
}
else
{
} else {
u8 PostDiv;
u8 Div;
CHK_ERROR(CalcCalPLL(state, Frequency + IntermediateFrequency));
@ -913,17 +893,15 @@ static int ChannelConfiguration(struct tda_state *state,
CHK_ERROR(UpdateReg(state, MPD));
CHK_ERROR(UpdateRegs(state, TM, EP5));
state->m_Regs[EB7] |= 0x20; // CAL_forceSrce = 1
state->m_Regs[EB7] |= 0x20; /* CAL_forceSrce = 1 */
CHK_ERROR(UpdateReg(state, EB7));
msleep(1);
state->m_Regs[EB7] &= ~0x20; // CAL_forceSrce = 0
state->m_Regs[EB7] &= ~0x20; /* CAL_forceSrce = 0 */
CHK_ERROR(UpdateReg(state, EB7));
}
msleep(20);
if (Standard != HF_FM_Radio)
{
state->m_Regs[EP3] |= 0x04; // RFAGC to normal mode
}
state->m_Regs[EP3] |= 0x04; /* RFAGC to normal mode */
CHK_ERROR(UpdateReg(state, EP3));
} while (0);
@ -940,7 +918,6 @@ static int sleep(struct dvb_frontend* fe)
static int init(struct dvb_frontend *fe)
{
//struct tda_state *state = fe->tuner_priv;
return 0;
}
@ -981,7 +958,7 @@ static int set_params(struct dvb_frontend *fe,
CHK_ERROR(RFTrackingFiltersCorrection(state, params->frequency));
CHK_ERROR(ChannelConfiguration(state, params->frequency, Standard));
msleep(state->m_SettlingTime); // Allow AGC's to settle down
msleep(state->m_SettlingTime); /* Allow AGC's to settle down */
} while (0);
return status;
}
@ -990,10 +967,10 @@ static int set_params(struct dvb_frontend *fe,
static int GetSignalStrength(s32 *pSignalStrength, u32 RFAgc, u32 IFAgc)
{
if (IFAgc < 500) {
// Scale this from 0 to 50000
/* Scale this from 0 to 50000 */
*pSignalStrength = IFAgc * 100;
} else {
// Scale range 500-1500 to 50000-80000
/* Scale range 500-1500 to 50000-80000 */
*pSignalStrength = 50000 + (IFAgc - 500) * 30;
}
@ -1011,8 +988,8 @@ static int get_frequency(struct dvb_frontend *fe, u32 *frequency)
static int get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
{
//struct tda_state *state = fe->tuner_priv;
//*bandwidth = priv->bandwidth;
/* struct tda_state *state = fe->tuner_priv; */
/* *bandwidth = priv->bandwidth; */
return 0;
}
@ -1050,14 +1027,8 @@ struct dvb_frontend *tda18271c2dd_attach(struct dvb_frontend *fe,
return fe;
}
EXPORT_SYMBOL_GPL(tda18271c2dd_attach);
MODULE_DESCRIPTION("TDA18271C2 driver");
MODULE_AUTHOR("DD");
MODULE_LICENSE("GPL");
/*
* Local variables:
* c-basic-offset: 8
* End:
*/

View File

@ -5,27 +5,26 @@ enum HF_S {
HF_DVBC_8MHZ, HF_DVBC
};
struct SStandardParam m_StandardTable[] =
{
{ 0, 0, 0x00, 0x00 }, // HF_None
{ 6000000, 7000000, 0x1D, 0x2C }, // HF_B,
{ 6900000, 8000000, 0x1E, 0x2C }, // HF_DK,
{ 7100000, 8000000, 0x1E, 0x2C }, // HF_G,
{ 7250000, 8000000, 0x1E, 0x2C }, // HF_I,
{ 6900000, 8000000, 0x1E, 0x2C }, // HF_L,
{ 1250000, 8000000, 0x1E, 0x2C }, // HF_L1,
{ 5400000, 6000000, 0x1C, 0x2C }, // HF_MN,
{ 1250000, 500000, 0x18, 0x2C }, // HF_FM_Radio,
{ 0, 0, 0x00, 0x00 }, // HF_AnalogMax (Unused)
{ 3300000, 6000000, 0x1C, 0x58 }, // HF_DVBT_6MHZ
{ 3500000, 7000000, 0x1C, 0x37 }, // HF_DVBT_7MHZ
{ 4000000, 8000000, 0x1D, 0x37 }, // HF_DVBT_8MHZ
{ 0, 0, 0x00, 0x00 }, // HF_DVBT (Unused)
{ 5000000, 6000000, 0x1C, 0x37 }, // HF_ATSC (center = 3.25 MHz)
{ 4000000, 6000000, 0x1D, 0x58 }, // HF_DVBC_6MHZ (Chicago)
{ 4500000, 7000000, 0x1E, 0x37 }, // HF_DVBC_7MHZ (not documented by NXP)
{ 5000000, 8000000, 0x1F, 0x37 }, // HF_DVBC_8MHZ
{ 0, 0, 0x00, 0x00 }, // HF_DVBC (Unused)
struct SStandardParam m_StandardTable[] = {
{ 0, 0, 0x00, 0x00 }, /* HF_None */
{ 6000000, 7000000, 0x1D, 0x2C }, /* HF_B, */
{ 6900000, 8000000, 0x1E, 0x2C }, /* HF_DK, */
{ 7100000, 8000000, 0x1E, 0x2C }, /* HF_G, */
{ 7250000, 8000000, 0x1E, 0x2C }, /* HF_I, */
{ 6900000, 8000000, 0x1E, 0x2C }, /* HF_L, */
{ 1250000, 8000000, 0x1E, 0x2C }, /* HF_L1, */
{ 5400000, 6000000, 0x1C, 0x2C }, /* HF_MN, */
{ 1250000, 500000, 0x18, 0x2C }, /* HF_FM_Radio, */
{ 0, 0, 0x00, 0x00 }, /* HF_AnalogMax (Unused) */
{ 3300000, 6000000, 0x1C, 0x58 }, /* HF_DVBT_6MHZ */
{ 3500000, 7000000, 0x1C, 0x37 }, /* HF_DVBT_7MHZ */
{ 4000000, 8000000, 0x1D, 0x37 }, /* HF_DVBT_8MHZ */
{ 0, 0, 0x00, 0x00 }, /* HF_DVBT (Unused) */
{ 5000000, 6000000, 0x1C, 0x37 }, /* HF_ATSC (center = 3.25 MHz) */
{ 4000000, 6000000, 0x1D, 0x58 }, /* HF_DVBC_6MHZ (Chicago) */
{ 4500000, 7000000, 0x1E, 0x37 }, /* HF_DVBC_7MHZ (not documented by NXP) */
{ 5000000, 8000000, 0x1F, 0x37 }, /* HF_DVBC_8MHZ */
{ 0, 0, 0x00, 0x00 }, /* HF_DVBC (Unused) */
};
struct SMap m_BP_Filter_Map[] = {
@ -36,7 +35,7 @@ struct SMap m_BP_Filter_Map[] = {
{ 170000000, 0x04 },
{ 180000000, 0x05 },
{ 865000000, 0x06 },
{ 0, 0x00 }, // Table End
{ 0, 0x00 }, /* Table End */
};
static struct SMapI m_RF_Cal_Map[] = {
@ -477,7 +476,7 @@ static struct SMapI m_RF_Cal_Map[] = {
{ 863000000, 0xB6 },
{ 864000000, 0xB8 },
{ 865000000, 0xB9 },
{ 0, 0x00 }, // Table End
{ 0, 0x00 }, /* Table End */
};
@ -487,7 +486,7 @@ static struct SMap2 m_KM_Map[] = {
{ 350000000, 3, 0 },
{ 720000000, 2, 1 },
{ 865000000, 3, 3 },
{ 0, 0x00 }, // Table End
{ 0, 0x00 }, /* Table End */
};
static struct SMap2 m_Main_PLL_Map[] = {
@ -531,7 +530,7 @@ static struct SMap2 m_Main_PLL_Map[] = {
{ 795000000, 0x12, 0x0A },
{ 883000000, 0x11, 0x09 },
{ 994000000, 0x10, 0x08 },
{ 0, 0x00, 0x00 }, // Table End
{ 0, 0x00, 0x00 }, /* Table End */
};
static struct SMap2 m_Cal_PLL_Map[] = {
@ -569,7 +568,7 @@ static struct SMap2 m_Cal_PLL_Map[] = {
{ 703000000, 0x9A, 0x0A },
{ 781000000, 0x99, 0x09 },
{ 879000000, 0x98, 0x08 },
{ 0, 0x00, 0x00 }, // Table End
{ 0, 0x00, 0x00 }, /* Table End */
};
static struct SMap m_GainTaper_Map[] = {
@ -658,7 +657,7 @@ static struct SMap m_GainTaper_Map[] = {
{ 828000000, 0x06 },
{ 846500000, 0x05 },
{ 865000000, 0x04 },
{ 0, 0x00 }, // Table End
{ 0, 0x00 }, /* Table End */
};
static struct SMap m_RF_Cal_DC_Over_DT_Map[] = {
@ -763,7 +762,7 @@ static struct SMap m_RF_Cal_DC_Over_DT_Map[] = {
{ 854000000, 0x84 },
{ 859000000, 0x8F },
{ 865000000, 0x9A },
{ 0, 0x00 }, // Table End
{ 0, 0x00 }, /* Table End */
};
@ -771,7 +770,7 @@ static struct SMap m_IR_Meas_Map[] = {
{ 200000000, 0x05 },
{ 400000000, 0x06 },
{ 865000000, 0x07 },
{ 0, 0x00 }, // Table End
{ 0, 0x00 }, /* Table End */
};
static struct SMap2 m_CID_Target_Map[] = {
@ -787,7 +786,7 @@ static struct SMap2 m_CID_Target_Map[] = {
{ 489500000, 0x1E, 40 },
{ 697500000, 0x32, 40 },
{ 842000000, 0x3A, 40 },
{ 0, 0x00, 0 }, // Table End
{ 0, 0x00, 0 }, /* Table End */
};
static struct SRFBandMap m_RF_Band_Map[7] = {
@ -801,10 +800,15 @@ static struct SRFBandMap m_RF_Band_Map[7] = {
};
u8 m_Thermometer_Map_1[16] = {
60,62,66,64, 74,72,68,70, 90,88,84,86, 76,78,82,80,
60, 62, 66, 64,
74, 72, 68, 70,
90, 88, 84, 86,
76, 78, 82, 80,
};
u8 m_Thermometer_Map_2[16] = {
92,94,98,96, 106,104,100,102, 122,120,116,118, 108,110,114,112,
92, 94, 98, 96,
106, 104, 100, 102,
122, 120, 116, 118,
108, 110, 114, 112,
};