Commit 31e67fae authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

[media] mt2063: simplify lockstatus logic

Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 66aea30d
...@@ -8,13 +8,7 @@ ...@@ -8,13 +8,7 @@
static unsigned int verbose; static unsigned int verbose;
module_param(verbose, int, 0644); module_param(verbose, int, 0644);
/* Internal structures and types */ /* positive error codes used internally */
/* FIXME: Those two error codes need conversion*/
/* Error: Upconverter PLL is not locked */
#define MT2063_UPC_UNLOCK (0x80000002)
/* Error: Downconverter PLL is not locked */
#define MT2063_DNC_UNLOCK (0x80000004)
/* Info: Unavoidable LO-related spur may be present in the output */ /* Info: Unavoidable LO-related spur may be present in the output */
#define MT2063_SPUR_PRESENT_ERR (0x00800000) #define MT2063_SPUR_PRESENT_ERR (0x00800000)
...@@ -29,10 +23,6 @@ module_param(verbose, int, 0644); ...@@ -29,10 +23,6 @@ module_param(verbose, int, 0644);
/* Info: Downconverter frequency is out of range (may be reason for MT_DPC_UNLOCK) */ /* Info: Downconverter frequency is out of range (may be reason for MT_DPC_UNLOCK) */
#define MT2063_DNC_RANGE (0x08000000) #define MT2063_DNC_RANGE (0x08000000)
/*
* Data Types
*/
/* /*
* Constant defining the version of the following structure * Constant defining the version of the following structure
* and therefore the API for this code. * and therefore the API for this code.
...@@ -362,29 +352,6 @@ unsigned int mt2063_setTune(struct dvb_frontend *fe, u32 f_in, ...@@ -362,29 +352,6 @@ unsigned int mt2063_setTune(struct dvb_frontend *fe, u32 f_in,
return err; return err;
} }
unsigned int mt2063_lockStatus(struct dvb_frontend *fe)
{
struct dvb_frontend_ops *frontend_ops = &fe->ops;
struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops;
struct tuner_state t_state;
int err = 0;
if (&fe->ops)
frontend_ops = &fe->ops;
if (&frontend_ops->tuner_ops)
tuner_ops = &frontend_ops->tuner_ops;
if (tuner_ops->get_state) {
if ((err =
tuner_ops->get_state(fe, DVBFE_TUNER_REFCLOCK,
&t_state)) < 0) {
printk("%s: Invalid parameter\n", __func__);
return err;
}
}
return err;
}
unsigned int tuner_MT2063_SoftwareShutdown(struct dvb_frontend *fe) unsigned int tuner_MT2063_SoftwareShutdown(struct dvb_frontend *fe)
{ {
struct mt2063_state *state = fe->tuner_priv; struct mt2063_state *state = fe->tuner_priv;
...@@ -1193,39 +1160,21 @@ static u32 MT2063_CalcLO2Mult(u32 * Div, u32 * FracN, u32 f_LO, ...@@ -1193,39 +1160,21 @@ static u32 MT2063_CalcLO2Mult(u32 * Div, u32 * FracN, u32 f_LO,
static u32 MT2063_fLO_FractionalTerm(u32 f_ref, u32 num, static u32 MT2063_fLO_FractionalTerm(u32 f_ref, u32 num,
u32 denom); u32 denom);
/**************************************************************************** /**
** * mt2063_lockStatus - Checks to see if LO1 and LO2 are locked
** Name: MT2063_GetLocked *
** * @state: struct mt2063_state pointer
** Description: Checks to see if LO1 and LO2 are locked. *
** * This function returns 0, if no lock, 1 if locked and a value < 1 if error
** Parameters: h - Open handle to the tuner (from MT2063_Open). */
** unsigned int mt2063_lockStatus(struct mt2063_state *state)
** Returns: status:
** MT_OK - No errors
** MT_UPC_UNLOCK - Upconverter PLL unlocked
** MT_DNC_UNLOCK - Downconverter PLL unlocked
** MT_COMM_ERR - Serial bus communications error
** MT_INV_HANDLE - Invalid tuner handle
**
** Dependencies: MT_ReadSub - Read byte(s) of data from the serial bus
** MT_Sleep - Delay execution for x milliseconds
**
** Revision History:
**
** SCR Date Author Description
** -------------------------------------------------------------------------
** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
**
****************************************************************************/
static u32 MT2063_GetLocked(struct mt2063_state *state)
{ {
const u32 nMaxWait = 100; /* wait a maximum of 100 msec */ const u32 nMaxWait = 100; /* wait a maximum of 100 msec */
const u32 nPollRate = 2; /* poll status bits every 2 ms */ const u32 nPollRate = 2; /* poll status bits every 2 ms */
const u32 nMaxLoops = nMaxWait / nPollRate; const u32 nMaxLoops = nMaxWait / nPollRate;
const u8 LO1LK = 0x80; const u8 LO1LK = 0x80;
u8 LO2LK = 0x08; u8 LO2LK = 0x08;
u32 status = 0; /* Status to be returned */ u32 status;
u32 nDelays = 0; u32 nDelays = 0;
/* LO2 Lock bit was in a different place for B0 version */ /* LO2 Lock bit was in a different place for B0 version */
...@@ -1233,28 +1182,24 @@ static u32 MT2063_GetLocked(struct mt2063_state *state) ...@@ -1233,28 +1182,24 @@ static u32 MT2063_GetLocked(struct mt2063_state *state)
LO2LK = 0x40; LO2LK = 0x40;
do { do {
status |= status = mt2063_read(state, MT2063_REG_LO_STATUS,
mt2063_read(state, &state->reg[MT2063_REG_LO_STATUS], 1);
MT2063_REG_LO_STATUS,
&state->reg[MT2063_REG_LO_STATUS], 1);
if (status < 0) if (status < 0)
return (status); return status;
if ((state->reg[MT2063_REG_LO_STATUS] & (LO1LK | LO2LK)) == if ((state->reg[MT2063_REG_LO_STATUS] & (LO1LK | LO2LK)) ==
(LO1LK | LO2LK)) { (LO1LK | LO2LK)) {
return (status); return TUNER_STATUS_LOCKED | TUNER_STATUS_STEREO;
} }
msleep(nPollRate); /* Wait between retries */ msleep(nPollRate); /* Wait between retries */
} }
while (++nDelays < nMaxLoops); while (++nDelays < nMaxLoops);
if ((state->reg[MT2063_REG_LO_STATUS] & LO1LK) == 0x00) /*
status |= MT2063_UPC_UNLOCK; * Got no lock or partial lock
if ((state->reg[MT2063_REG_LO_STATUS] & LO2LK) == 0x00) */
status |= MT2063_DNC_UNLOCK; return 0;
return (status);
} }
/**************************************************************************** /****************************************************************************
...@@ -2424,15 +2369,14 @@ static u32 MT2063_ClearPowerMaskBits(struct mt2063_state *state, enum MT2063_Mas ...@@ -2424,15 +2369,14 @@ static u32 MT2063_ClearPowerMaskBits(struct mt2063_state *state, enum MT2063_Mas
****************************************************************************/ ****************************************************************************/
static u32 MT2063_SoftwareShutdown(struct mt2063_state *state, u8 Shutdown) static u32 MT2063_SoftwareShutdown(struct mt2063_state *state, u8 Shutdown)
{ {
u32 status = 0; /* Status to be returned */ u32 status; /* Status to be returned */
if (Shutdown == 1) if (Shutdown == 1)
state->reg[MT2063_REG_PWR_1] |= 0x04; /* Turn the bit on */ state->reg[MT2063_REG_PWR_1] |= 0x04; /* Turn the bit on */
else else
state->reg[MT2063_REG_PWR_1] &= ~0x04; /* Turn off the bit */ state->reg[MT2063_REG_PWR_1] &= ~0x04; /* Turn off the bit */
status |= status = mt2063_write(state,
mt2063_write(state,
MT2063_REG_PWR_1, MT2063_REG_PWR_1,
&state->reg[MT2063_REG_PWR_1], 1); &state->reg[MT2063_REG_PWR_1], 1);
...@@ -2453,7 +2397,7 @@ static u32 MT2063_SoftwareShutdown(struct mt2063_state *state, u8 Shutdown) ...@@ -2453,7 +2397,7 @@ static u32 MT2063_SoftwareShutdown(struct mt2063_state *state, u8 Shutdown)
1); 1);
} }
return (status); return status;
} }
/**************************************************************************** /****************************************************************************
...@@ -2486,17 +2430,18 @@ static u32 MT2063_SoftwareShutdown(struct mt2063_state *state, u8 Shutdown) ...@@ -2486,17 +2430,18 @@ static u32 MT2063_SoftwareShutdown(struct mt2063_state *state, u8 Shutdown)
****************************************************************************/ ****************************************************************************/
static u32 MT2063_SetReg(struct mt2063_state *state, u8 reg, u8 val) static u32 MT2063_SetReg(struct mt2063_state *state, u8 reg, u8 val)
{ {
u32 status = 0; /* Status to be returned */ u32 status;
if (reg >= MT2063_REG_END_REGS) if (reg >= MT2063_REG_END_REGS)
status |= -ERANGE; return -ERANGE;
status = mt2063_write(state, reg, &val, status = mt2063_write(state, reg, &val, 1);
1); if (status < 0)
if (status >= 0) return status;
state->reg[reg] = val;
return (status); state->reg[reg] = val;
return 0;
} }
static u32 MT2063_Round_fLO(u32 f_LO, u32 f_LO_Step, u32 f_ref) static u32 MT2063_Round_fLO(u32 f_LO, u32 f_LO_Step, u32 f_ref)
...@@ -2670,7 +2615,7 @@ static u32 FindClearTuneFilter(struct mt2063_state *state, u32 f_in) ...@@ -2670,7 +2615,7 @@ static u32 FindClearTuneFilter(struct mt2063_state *state, u32 f_in)
break; break;
} }
} }
return (RFBand); return RFBand;
} }
/**************************************************************************** /****************************************************************************
...@@ -2899,18 +2844,22 @@ static u32 MT2063_Tune(struct mt2063_state *state, u32 f_in) ...@@ -2899,18 +2844,22 @@ static u32 MT2063_Tune(struct mt2063_state *state, u32 f_in)
** Check for LO's locking ** Check for LO's locking
*/ */
if (status >= 0) { if (status < 0)
status |= MT2063_GetLocked(state); return status;
}
status = mt2063_lockStatus(state);
if (status < 0)
return status;
if (!status)
return -EINVAL; /* Couldn't lock */
/* /*
** If we locked OK, assign calculated data to mt2063_state structure * If we locked OK, assign calculated data to mt2063_state structure
*/ */
if (status >= 0) { state->f_IF1_actual = state->AS_Data.f_LO1 - f_in;
state->f_IF1_actual = state->AS_Data.f_LO1 - f_in;
}
} }
return (status); return status;
} }
static u32 MT_Tune_atv(void *h, u32 f_in, u32 bw_in, static u32 MT_Tune_atv(void *h, u32 f_in, u32 bw_in,
...@@ -3321,7 +3270,7 @@ static int mt2063_get_state(struct dvb_frontend *fe, ...@@ -3321,7 +3270,7 @@ static int mt2063_get_state(struct dvb_frontend *fe,
//get bandwidth //get bandwidth
break; break;
case DVBFE_TUNER_REFCLOCK: case DVBFE_TUNER_REFCLOCK:
tunstate->refclock = (u32) MT2063_GetLocked(state); tunstate->refclock = mt2063_lockStatus(state);
break; break;
default: default:
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment