aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@redhat.com>2011-12-17 18:36:59 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-12-20 10:27:19 -0500
commit37c52abd565aa8d10ffd7f31a37792425d1564df (patch)
tree0aed05d95a97010981607e5d547f5969bf930f54
parent0d7d0ac87b7f023a4e76e7ea7a16e904d5a49ca1 (diff)
[media] tda10023: Don't use a magic numbers for QAM modulation
Convert the existing data struct to use the QAM modulation macros, instead of assuming that they're numbered from 0 to 5. Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/dvb/frontends/tda10023.c66
1 files changed, 43 insertions, 23 deletions
diff --git a/drivers/media/dvb/frontends/tda10023.c b/drivers/media/dvb/frontends/tda10023.c
index a3c34eecdee9..e6c321e799d7 100644
--- a/drivers/media/dvb/frontends/tda10023.c
+++ b/drivers/media/dvb/frontends/tda10023.c
@@ -298,25 +298,43 @@ static int tda10023_init (struct dvb_frontend *fe)
298 return 0; 298 return 0;
299} 299}
300 300
301struct qam_params {
302 u8 qam, lockthr, mseth, aref, agcrefnyq, eragnyq_thd;
303};
304
301static int tda10023_set_parameters (struct dvb_frontend *fe, 305static int tda10023_set_parameters (struct dvb_frontend *fe,
302 struct dvb_frontend_parameters *p) 306 struct dvb_frontend_parameters *p)
303{ 307{
304 struct tda10023_state* state = fe->demodulator_priv; 308 struct tda10023_state* state = fe->demodulator_priv;
305 309 static const struct qam_params qam_params[] = {
306 static int qamvals[6][6] = { 310 /* Modulation QAM LOCKTHR MSETH AREF AGCREFNYQ ERAGCNYQ_THD */
307 // QAM LOCKTHR MSETH AREF AGCREFNYQ ERAGCNYQ_THD 311 [QPSK] = { (5<<2), 0x78, 0x8c, 0x96, 0x78, 0x4c },
308 { (5<<2), 0x78, 0x8c, 0x96, 0x78, 0x4c }, // 4 QAM 312 [QAM_16] = { (0<<2), 0x87, 0xa2, 0x91, 0x8c, 0x57 },
309 { (0<<2), 0x87, 0xa2, 0x91, 0x8c, 0x57 }, // 16 QAM 313 [QAM_32] = { (1<<2), 0x64, 0x74, 0x96, 0x8c, 0x57 },
310 { (1<<2), 0x64, 0x74, 0x96, 0x8c, 0x57 }, // 32 QAM 314 [QAM_64] = { (2<<2), 0x46, 0x43, 0x6a, 0x6a, 0x44 },
311 { (2<<2), 0x46, 0x43, 0x6a, 0x6a, 0x44 }, // 64 QAM 315 [QAM_128] = { (3<<2), 0x36, 0x34, 0x7e, 0x78, 0x4c },
312 { (3<<2), 0x36, 0x34, 0x7e, 0x78, 0x4c }, // 128 QAM 316 [QAM_256] = { (4<<2), 0x26, 0x23, 0x6c, 0x5c, 0x3c },
313 { (4<<2), 0x26, 0x23, 0x6c, 0x5c, 0x3c }, // 256 QAM
314 }; 317 };
315 318 unsigned qam = p->u.qam.modulation;
316 int qam = p->u.qam.modulation; 319
317 320 /*
318 if (qam < 0 || qam > 5) 321 * gcc optimizes the code bellow the same way as it would code:
322 * "if (qam > 5) return -EINVAL;"
323 * Yet, the code is clearer, as it shows what QAM standards are
324 * supported by the driver, and avoids the usage of magic numbers on
325 * it.
326 */
327 switch (qam) {
328 case QPSK:
329 case QAM_16:
330 case QAM_32:
331 case QAM_64:
332 case QAM_128:
333 case QAM_256:
334 break;
335 default:
319 return -EINVAL; 336 return -EINVAL;
337 }
320 338
321 if (fe->ops.tuner_ops.set_params) { 339 if (fe->ops.tuner_ops.set_params) {
322 fe->ops.tuner_ops.set_params(fe, p); 340 fe->ops.tuner_ops.set_params(fe, p);
@@ -324,16 +342,18 @@ static int tda10023_set_parameters (struct dvb_frontend *fe,
324 } 342 }
325 343
326 tda10023_set_symbolrate (state, p->u.qam.symbol_rate); 344 tda10023_set_symbolrate (state, p->u.qam.symbol_rate);
327 tda10023_writereg (state, 0x05, qamvals[qam][1]); 345 tda10023_writereg(state, 0x05, qam_params[qam].lockthr);
328 tda10023_writereg (state, 0x08, qamvals[qam][2]); 346 tda10023_writereg(state, 0x08, qam_params[qam].mseth);
329 tda10023_writereg (state, 0x09, qamvals[qam][3]); 347 tda10023_writereg(state, 0x09, qam_params[qam].aref);
330 tda10023_writereg (state, 0xb4, qamvals[qam][4]); 348 tda10023_writereg(state, 0xb4, qam_params[qam].agcrefnyq);
331 tda10023_writereg (state, 0xb6, qamvals[qam][5]); 349 tda10023_writereg(state, 0xb6, qam_params[qam].eragnyq_thd);
332 350
333// tda10023_writereg (state, 0x04, (p->inversion?0x12:0x32)); 351#if 0
334// tda10023_writebit (state, 0x04, 0x60, (p->inversion?0:0x20)); 352 tda10023_writereg(state, 0x04, (p->inversion ? 0x12 : 0x32));
335 tda10023_writebit (state, 0x04, 0x40, 0x40); 353 tda10023_writebit(state, 0x04, 0x60, (p->inversion ? 0 : 0x20));
336 tda10023_setup_reg0 (state, qamvals[qam][0]); 354#endif
355 tda10023_writebit(state, 0x04, 0x40, 0x40);
356 tda10023_setup_reg0(state, qam_params[qam].qam);
337 357
338 return 0; 358 return 0;
339} 359}