aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/common
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@redhat.com>2011-07-21 09:30:11 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-01-04 19:20:21 -0500
commit31e67faeaf058e0575cfb304a39dbcccf3d8569b (patch)
tree1027d3ceafd6cb8188d77060669f0e1d93081c2b /drivers/media/common
parent66aea30d32b8938f0b6ef06b0a2811272bd9968d (diff)
[media] mt2063: simplify lockstatus logic
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/common')
-rw-r--r--drivers/media/common/tuners/mt2063.c137
1 files changed, 43 insertions, 94 deletions
diff --git a/drivers/media/common/tuners/mt2063.c b/drivers/media/common/tuners/mt2063.c
index a43a859cf063..3c0b3f1ec248 100644
--- a/drivers/media/common/tuners/mt2063.c
+++ b/drivers/media/common/tuners/mt2063.c
@@ -8,13 +8,7 @@
8static unsigned int verbose; 8static unsigned int verbose;
9module_param(verbose, int, 0644); 9module_param(verbose, int, 0644);
10 10
11/* Internal structures and types */ 11/* positive error codes used internally */
12
13/* FIXME: Those two error codes need conversion*/
14/* Error: Upconverter PLL is not locked */
15#define MT2063_UPC_UNLOCK (0x80000002)
16/* Error: Downconverter PLL is not locked */
17#define MT2063_DNC_UNLOCK (0x80000004)
18 12
19/* Info: Unavoidable LO-related spur may be present in the output */ 13/* Info: Unavoidable LO-related spur may be present in the output */
20#define MT2063_SPUR_PRESENT_ERR (0x00800000) 14#define MT2063_SPUR_PRESENT_ERR (0x00800000)
@@ -30,10 +24,6 @@ module_param(verbose, int, 0644);
30#define MT2063_DNC_RANGE (0x08000000) 24#define MT2063_DNC_RANGE (0x08000000)
31 25
32/* 26/*
33 * Data Types
34 */
35
36/*
37 * Constant defining the version of the following structure 27 * Constant defining the version of the following structure
38 * and therefore the API for this code. 28 * and therefore the API for this code.
39 * 29 *
@@ -362,29 +352,6 @@ unsigned int mt2063_setTune(struct dvb_frontend *fe, u32 f_in,
362 return err; 352 return err;
363} 353}
364 354
365unsigned int mt2063_lockStatus(struct dvb_frontend *fe)
366{
367 struct dvb_frontend_ops *frontend_ops = &fe->ops;
368 struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops;
369 struct tuner_state t_state;
370 int err = 0;
371
372 if (&fe->ops)
373 frontend_ops = &fe->ops;
374 if (&frontend_ops->tuner_ops)
375 tuner_ops = &frontend_ops->tuner_ops;
376 if (tuner_ops->get_state) {
377 if ((err =
378 tuner_ops->get_state(fe, DVBFE_TUNER_REFCLOCK,
379 &t_state)) < 0) {
380 printk("%s: Invalid parameter\n", __func__);
381 return err;
382 }
383 }
384 return err;
385}
386
387
388unsigned int tuner_MT2063_SoftwareShutdown(struct dvb_frontend *fe) 355unsigned int tuner_MT2063_SoftwareShutdown(struct dvb_frontend *fe)
389{ 356{
390 struct mt2063_state *state = fe->tuner_priv; 357 struct mt2063_state *state = fe->tuner_priv;
@@ -1193,39 +1160,21 @@ static u32 MT2063_CalcLO2Mult(u32 * Div, u32 * FracN, u32 f_LO,
1193static u32 MT2063_fLO_FractionalTerm(u32 f_ref, u32 num, 1160static u32 MT2063_fLO_FractionalTerm(u32 f_ref, u32 num,
1194 u32 denom); 1161 u32 denom);
1195 1162
1196/**************************************************************************** 1163/**
1197** 1164 * mt2063_lockStatus - Checks to see if LO1 and LO2 are locked
1198** Name: MT2063_GetLocked 1165 *
1199** 1166 * @state: struct mt2063_state pointer
1200** Description: Checks to see if LO1 and LO2 are locked. 1167 *
1201** 1168 * This function returns 0, if no lock, 1 if locked and a value < 1 if error
1202** Parameters: h - Open handle to the tuner (from MT2063_Open). 1169 */
1203** 1170unsigned int mt2063_lockStatus(struct mt2063_state *state)
1204** Returns: status:
1205** MT_OK - No errors
1206** MT_UPC_UNLOCK - Upconverter PLL unlocked
1207** MT_DNC_UNLOCK - Downconverter PLL unlocked
1208** MT_COMM_ERR - Serial bus communications error
1209** MT_INV_HANDLE - Invalid tuner handle
1210**
1211** Dependencies: MT_ReadSub - Read byte(s) of data from the serial bus
1212** MT_Sleep - Delay execution for x milliseconds
1213**
1214** Revision History:
1215**
1216** SCR Date Author Description
1217** -------------------------------------------------------------------------
1218** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
1219**
1220****************************************************************************/
1221static u32 MT2063_GetLocked(struct mt2063_state *state)
1222{ 1171{
1223 const u32 nMaxWait = 100; /* wait a maximum of 100 msec */ 1172 const u32 nMaxWait = 100; /* wait a maximum of 100 msec */
1224 const u32 nPollRate = 2; /* poll status bits every 2 ms */ 1173 const u32 nPollRate = 2; /* poll status bits every 2 ms */
1225 const u32 nMaxLoops = nMaxWait / nPollRate; 1174 const u32 nMaxLoops = nMaxWait / nPollRate;
1226 const u8 LO1LK = 0x80; 1175 const u8 LO1LK = 0x80;
1227 u8 LO2LK = 0x08; 1176 u8 LO2LK = 0x08;
1228 u32 status = 0; /* Status to be returned */ 1177 u32 status;
1229 u32 nDelays = 0; 1178 u32 nDelays = 0;
1230 1179
1231 /* LO2 Lock bit was in a different place for B0 version */ 1180 /* LO2 Lock bit was in a different place for B0 version */
@@ -1233,28 +1182,24 @@ static u32 MT2063_GetLocked(struct mt2063_state *state)
1233 LO2LK = 0x40; 1182 LO2LK = 0x40;
1234 1183
1235 do { 1184 do {
1236 status |= 1185 status = mt2063_read(state, MT2063_REG_LO_STATUS,
1237 mt2063_read(state, 1186 &state->reg[MT2063_REG_LO_STATUS], 1);
1238 MT2063_REG_LO_STATUS,
1239 &state->reg[MT2063_REG_LO_STATUS], 1);
1240 1187
1241 if (status < 0) 1188 if (status < 0)
1242 return (status); 1189 return status;
1243 1190
1244 if ((state->reg[MT2063_REG_LO_STATUS] & (LO1LK | LO2LK)) == 1191 if ((state->reg[MT2063_REG_LO_STATUS] & (LO1LK | LO2LK)) ==
1245 (LO1LK | LO2LK)) { 1192 (LO1LK | LO2LK)) {
1246 return (status); 1193 return TUNER_STATUS_LOCKED | TUNER_STATUS_STEREO;
1247 } 1194 }
1248 msleep(nPollRate); /* Wait between retries */ 1195 msleep(nPollRate); /* Wait between retries */
1249 } 1196 }
1250 while (++nDelays < nMaxLoops); 1197 while (++nDelays < nMaxLoops);
1251 1198
1252 if ((state->reg[MT2063_REG_LO_STATUS] & LO1LK) == 0x00) 1199 /*
1253 status |= MT2063_UPC_UNLOCK; 1200 * Got no lock or partial lock
1254 if ((state->reg[MT2063_REG_LO_STATUS] & LO2LK) == 0x00) 1201 */
1255 status |= MT2063_DNC_UNLOCK; 1202 return 0;
1256
1257 return (status);
1258} 1203}
1259 1204
1260/**************************************************************************** 1205/****************************************************************************
@@ -2424,15 +2369,14 @@ static u32 MT2063_ClearPowerMaskBits(struct mt2063_state *state, enum MT2063_Mas
2424****************************************************************************/ 2369****************************************************************************/
2425static u32 MT2063_SoftwareShutdown(struct mt2063_state *state, u8 Shutdown) 2370static u32 MT2063_SoftwareShutdown(struct mt2063_state *state, u8 Shutdown)
2426{ 2371{
2427 u32 status = 0; /* Status to be returned */ 2372 u32 status; /* Status to be returned */
2428 2373
2429 if (Shutdown == 1) 2374 if (Shutdown == 1)
2430 state->reg[MT2063_REG_PWR_1] |= 0x04; /* Turn the bit on */ 2375 state->reg[MT2063_REG_PWR_1] |= 0x04; /* Turn the bit on */
2431 else 2376 else
2432 state->reg[MT2063_REG_PWR_1] &= ~0x04; /* Turn off the bit */ 2377 state->reg[MT2063_REG_PWR_1] &= ~0x04; /* Turn off the bit */
2433 2378
2434 status |= 2379 status = mt2063_write(state,
2435 mt2063_write(state,
2436 MT2063_REG_PWR_1, 2380 MT2063_REG_PWR_1,
2437 &state->reg[MT2063_REG_PWR_1], 1); 2381 &state->reg[MT2063_REG_PWR_1], 1);
2438 2382
@@ -2453,7 +2397,7 @@ static u32 MT2063_SoftwareShutdown(struct mt2063_state *state, u8 Shutdown)
2453 1); 2397 1);
2454 } 2398 }
2455 2399
2456 return (status); 2400 return status;
2457} 2401}
2458 2402
2459/**************************************************************************** 2403/****************************************************************************
@@ -2486,17 +2430,18 @@ static u32 MT2063_SoftwareShutdown(struct mt2063_state *state, u8 Shutdown)
2486****************************************************************************/ 2430****************************************************************************/
2487static u32 MT2063_SetReg(struct mt2063_state *state, u8 reg, u8 val) 2431static u32 MT2063_SetReg(struct mt2063_state *state, u8 reg, u8 val)
2488{ 2432{
2489 u32 status = 0; /* Status to be returned */ 2433 u32 status;
2490 2434
2491 if (reg >= MT2063_REG_END_REGS) 2435 if (reg >= MT2063_REG_END_REGS)
2492 status |= -ERANGE; 2436 return -ERANGE;
2493 2437
2494 status = mt2063_write(state, reg, &val, 2438 status = mt2063_write(state, reg, &val, 1);
2495 1); 2439 if (status < 0)
2496 if (status >= 0) 2440 return status;
2497 state->reg[reg] = val;
2498 2441
2499 return (status); 2442 state->reg[reg] = val;
2443
2444 return 0;
2500} 2445}
2501 2446
2502static u32 MT2063_Round_fLO(u32 f_LO, u32 f_LO_Step, u32 f_ref) 2447static 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 break; 2615 break;
2671 } 2616 }
2672 } 2617 }
2673 return (RFBand); 2618 return RFBand;
2674} 2619}
2675 2620
2676/**************************************************************************** 2621/****************************************************************************
@@ -2899,18 +2844,22 @@ static u32 MT2063_Tune(struct mt2063_state *state, u32 f_in)
2899 ** Check for LO's locking 2844 ** Check for LO's locking
2900 */ 2845 */
2901 2846
2902 if (status >= 0) { 2847 if (status < 0)
2903 status |= MT2063_GetLocked(state); 2848 return status;
2904 } 2849
2850 status = mt2063_lockStatus(state);
2851 if (status < 0)
2852 return status;
2853 if (!status)
2854 return -EINVAL; /* Couldn't lock */
2855
2905 /* 2856 /*
2906 ** If we locked OK, assign calculated data to mt2063_state structure 2857 * If we locked OK, assign calculated data to mt2063_state structure
2907 */ 2858 */
2908 if (status >= 0) { 2859 state->f_IF1_actual = state->AS_Data.f_LO1 - f_in;
2909 state->f_IF1_actual = state->AS_Data.f_LO1 - f_in;
2910 }
2911 } 2860 }
2912 2861
2913 return (status); 2862 return status;
2914} 2863}
2915 2864
2916static u32 MT_Tune_atv(void *h, u32 f_in, u32 bw_in, 2865static 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 //get bandwidth 3270 //get bandwidth
3322 break; 3271 break;
3323 case DVBFE_TUNER_REFCLOCK: 3272 case DVBFE_TUNER_REFCLOCK:
3324 tunstate->refclock = (u32) MT2063_GetLocked(state); 3273 tunstate->refclock = mt2063_lockStatus(state);
3325 break; 3274 break;
3326 default: 3275 default:
3327 break; 3276 break;