diff options
author | Michael Krufky <mkrufky@linuxtv.org> | 2007-12-02 14:36:05 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2008-01-25 16:03:13 -0500 |
commit | b5f3e1e153b60f7bc338cdd6eefacd59c2dfb375 (patch) | |
tree | 75a18d39c89b415c10aaa2152730944135e5ff7c /drivers/media/dvb/frontends/tda18271-fe.c | |
parent | aaeccba68a60eedee5fe90f9e1478367b1f97345 (diff) |
V4L/DVB (6727): tda18271: convert table lookup loops to functions
Signed-off-by: Michael Krufky <mkrufky@linuxtv.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/dvb/frontends/tda18271-fe.c')
-rw-r--r-- | drivers/media/dvb/frontends/tda18271-fe.c | 119 |
1 files changed, 25 insertions, 94 deletions
diff --git a/drivers/media/dvb/frontends/tda18271-fe.c b/drivers/media/dvb/frontends/tda18271-fe.c index fee38c1657e1..5d3c4b0975f6 100644 --- a/drivers/media/dvb/frontends/tda18271-fe.c +++ b/drivers/media/dvb/frontends/tda18271-fe.c | |||
@@ -25,22 +25,10 @@ | |||
25 | #include "tda18271.h" | 25 | #include "tda18271.h" |
26 | #include "tda18271-priv.h" | 26 | #include "tda18271-priv.h" |
27 | 27 | ||
28 | static int tda18271_debug; | 28 | int tda18271_debug; |
29 | module_param_named(debug, tda18271_debug, int, 0644); | 29 | module_param_named(debug, tda18271_debug, int, 0644); |
30 | MODULE_PARM_DESC(debug, "set debug level (info=1, map=2, reg=4 (or-able))"); | 30 | MODULE_PARM_DESC(debug, "set debug level (info=1, map=2, reg=4 (or-able))"); |
31 | 31 | ||
32 | #define dprintk(level, fmt, arg...) do {\ | ||
33 | if (tda18271_debug & level) \ | ||
34 | printk(KERN_DEBUG "%s: " fmt, __FUNCTION__, ##arg); } while (0) | ||
35 | |||
36 | #define DBG_INFO 1 | ||
37 | #define DBG_MAP 2 | ||
38 | #define DBG_REG 4 | ||
39 | |||
40 | #define dbg_info(fmt, arg...) dprintk(DBG_INFO, fmt, ##arg) | ||
41 | #define dbg_map(fmt, arg...) dprintk(DBG_MAP, fmt, ##arg) | ||
42 | #define dbg_reg(fmt, arg...) dprintk(DBG_REG, fmt, ##arg) | ||
43 | |||
44 | /*---------------------------------------------------------------------*/ | 32 | /*---------------------------------------------------------------------*/ |
45 | 33 | ||
46 | #define TDA18271_ANALOG 0 | 34 | #define TDA18271_ANALOG 0 |
@@ -365,7 +353,7 @@ static int tda18271_tune(struct dvb_frontend *fe, | |||
365 | struct tda18271_priv *priv = fe->tuner_priv; | 353 | struct tda18271_priv *priv = fe->tuner_priv; |
366 | unsigned char *regs = priv->tda18271_regs; | 354 | unsigned char *regs = priv->tda18271_regs; |
367 | u32 div, N = 0; | 355 | u32 div, N = 0; |
368 | int i; | 356 | u8 d, pd, val; |
369 | 357 | ||
370 | tda18271_init(fe); | 358 | tda18271_init(fe); |
371 | 359 | ||
@@ -374,16 +362,10 @@ static int tda18271_tune(struct dvb_frontend *fe, | |||
374 | /* RF tracking filter calibration */ | 362 | /* RF tracking filter calibration */ |
375 | 363 | ||
376 | /* calculate BP_Filter */ | 364 | /* calculate BP_Filter */ |
377 | i = 0; | 365 | tda18271_calc_bp_filter(&freq, &val); |
378 | while ((tda18271_bp_filter[i].rfmax * 1000) < freq) { | ||
379 | if (tda18271_bp_filter[i + 1].rfmax == 0) | ||
380 | break; | ||
381 | i++; | ||
382 | } | ||
383 | dbg_map("bp filter = 0x%x, i = %d\n", tda18271_bp_filter[i].val, i); | ||
384 | 366 | ||
385 | regs[R_EP1] &= ~0x07; /* clear bp filter bits */ | 367 | regs[R_EP1] &= ~0x07; /* clear bp filter bits */ |
386 | regs[R_EP1] |= tda18271_bp_filter[i].val; | 368 | regs[R_EP1] |= val; |
387 | tda18271_write_regs(fe, R_EP1, 1); | 369 | tda18271_write_regs(fe, R_EP1, 1); |
388 | 370 | ||
389 | regs[R_EB4] &= 0x07; | 371 | regs[R_EB4] &= 0x07; |
@@ -413,18 +395,11 @@ static int tda18271_tune(struct dvb_frontend *fe, | |||
413 | break; | 395 | break; |
414 | } | 396 | } |
415 | 397 | ||
416 | i = 0; | 398 | tda18271_calc_cal_pll(&N, &pd, &d); |
417 | while ((tda18271_cal_pll[i].lomax * 1000) < N) { | ||
418 | if (tda18271_cal_pll[i + 1].lomax == 0) | ||
419 | break; | ||
420 | i++; | ||
421 | } | ||
422 | dbg_map("cal pll, pd = 0x%x, d = 0x%x, i = %d\n", | ||
423 | tda18271_cal_pll[i].pd, tda18271_cal_pll[i].d, i); | ||
424 | 399 | ||
425 | regs[R_CPD] = tda18271_cal_pll[i].pd; | 400 | regs[R_CPD] = pd; |
426 | 401 | ||
427 | div = ((tda18271_cal_pll[i].d * (N / 1000)) << 7) / 125; | 402 | div = ((d * (N / 1000)) << 7) / 125; |
428 | regs[R_CD1] = 0xff & (div >> 16); | 403 | regs[R_CD1] = 0xff & (div >> 16); |
429 | regs[R_CD2] = 0xff & (div >> 8); | 404 | regs[R_CD2] = 0xff & (div >> 8); |
430 | regs[R_CD3] = 0xff & div; | 405 | regs[R_CD3] = 0xff & div; |
@@ -440,16 +415,9 @@ static int tda18271_tune(struct dvb_frontend *fe, | |||
440 | break; | 415 | break; |
441 | } | 416 | } |
442 | 417 | ||
443 | i = 0; | 418 | tda18271_calc_main_pll(&N, &pd, &d); |
444 | while ((tda18271_main_pll[i].lomax * 1000) < N) { | ||
445 | if (tda18271_main_pll[i + 1].lomax == 0) | ||
446 | break; | ||
447 | i++; | ||
448 | } | ||
449 | dbg_map("main pll, pd = 0x%x, d = 0x%x, i = %d\n", | ||
450 | tda18271_main_pll[i].pd, tda18271_main_pll[i].d, i); | ||
451 | 419 | ||
452 | regs[R_MPD] = (0x7f & tda18271_main_pll[i].pd); | 420 | regs[R_MPD] = (0x7f & pd); |
453 | 421 | ||
454 | switch (priv->mode) { | 422 | switch (priv->mode) { |
455 | case TDA18271_ANALOG: | 423 | case TDA18271_ANALOG: |
@@ -460,7 +428,7 @@ static int tda18271_tune(struct dvb_frontend *fe, | |||
460 | break; | 428 | break; |
461 | } | 429 | } |
462 | 430 | ||
463 | div = ((tda18271_main_pll[i].d * (N / 1000)) << 7) / 125; | 431 | div = ((d * (N / 1000)) << 7) / 125; |
464 | regs[R_MD1] = 0xff & (div >> 16); | 432 | regs[R_MD1] = 0xff & (div >> 16); |
465 | regs[R_MD2] = 0xff & (div >> 8); | 433 | regs[R_MD2] = 0xff & (div >> 8); |
466 | regs[R_MD3] = 0xff & div; | 434 | regs[R_MD3] = 0xff & div; |
@@ -469,42 +437,23 @@ static int tda18271_tune(struct dvb_frontend *fe, | |||
469 | msleep(5); /* RF tracking filter calibration initialization */ | 437 | msleep(5); /* RF tracking filter calibration initialization */ |
470 | 438 | ||
471 | /* search for K,M,CO for RF Calibration */ | 439 | /* search for K,M,CO for RF Calibration */ |
472 | i = 0; | 440 | tda18271_calc_km(&freq, &val); |
473 | while ((tda18271_km[i].rfmax * 1000) < freq) { | ||
474 | if (tda18271_km[i + 1].rfmax == 0) | ||
475 | break; | ||
476 | i++; | ||
477 | } | ||
478 | dbg_map("km = 0x%x, i = %d\n", tda18271_km[i].val, i); | ||
479 | 441 | ||
480 | regs[R_EB13] &= 0x83; | 442 | regs[R_EB13] &= 0x83; |
481 | regs[R_EB13] |= tda18271_km[i].val; | 443 | regs[R_EB13] |= val; |
482 | tda18271_write_regs(fe, R_EB13, 1); | 444 | tda18271_write_regs(fe, R_EB13, 1); |
483 | 445 | ||
484 | /* search for RF_BAND */ | 446 | /* search for RF_BAND */ |
485 | i = 0; | 447 | tda18271_calc_rf_band(&freq, &val); |
486 | while ((tda18271_rf_band[i].rfmax * 1000) < freq) { | ||
487 | if (tda18271_rf_band[i + 1].rfmax == 0) | ||
488 | break; | ||
489 | i++; | ||
490 | } | ||
491 | dbg_map("rf band = 0x%x, i = %d\n", tda18271_rf_band[i].val, i); | ||
492 | 448 | ||
493 | regs[R_EP2] &= ~0xe0; /* clear rf band bits */ | 449 | regs[R_EP2] &= ~0xe0; /* clear rf band bits */ |
494 | regs[R_EP2] |= (tda18271_rf_band[i].val << 5); | 450 | regs[R_EP2] |= (val << 5); |
495 | 451 | ||
496 | /* search for Gain_Taper */ | 452 | /* search for Gain_Taper */ |
497 | i = 0; | 453 | tda18271_calc_gain_taper(&freq, &val); |
498 | while ((tda18271_gain_taper[i].rfmax * 1000) < freq) { | ||
499 | if (tda18271_gain_taper[i + 1].rfmax == 0) | ||
500 | break; | ||
501 | i++; | ||
502 | } | ||
503 | dbg_map("gain taper = 0x%x, i = %d\n", | ||
504 | tda18271_gain_taper[i].val, i); | ||
505 | 454 | ||
506 | regs[R_EP2] &= ~0x1f; /* clear gain taper bits */ | 455 | regs[R_EP2] &= ~0x1f; /* clear gain taper bits */ |
507 | regs[R_EP2] |= tda18271_gain_taper[i].val; | 456 | regs[R_EP2] |= val; |
508 | 457 | ||
509 | tda18271_write_regs(fe, R_EP2, 1); | 458 | tda18271_write_regs(fe, R_EP2, 1); |
510 | tda18271_write_regs(fe, R_EP1, 1); | 459 | tda18271_write_regs(fe, R_EP1, 1); |
@@ -529,17 +478,11 @@ static int tda18271_tune(struct dvb_frontend *fe, | |||
529 | tda18271_write_regs(fe, R_EP1, 1); | 478 | tda18271_write_regs(fe, R_EP1, 1); |
530 | 479 | ||
531 | /* RF tracking filer correction for VHF_Low band */ | 480 | /* RF tracking filer correction for VHF_Low band */ |
532 | i = 0; | 481 | tda18271_calc_rf_cal(&freq, &val); |
533 | while ((tda18271_rf_cal[i].rfmax * 1000) < freq) { | ||
534 | if (tda18271_rf_cal[i].rfmax == 0) | ||
535 | break; | ||
536 | i++; | ||
537 | } | ||
538 | dbg_map("rf cal = 0x%x, i = %d\n", tda18271_rf_cal[i].val, i); | ||
539 | 482 | ||
540 | /* VHF_Low band only */ | 483 | /* VHF_Low band only */ |
541 | if (tda18271_rf_cal[i].rfmax != 0) { | 484 | if (val != 0) { |
542 | regs[R_EB14] = tda18271_rf_cal[i].val; | 485 | regs[R_EB14] = val; |
543 | tda18271_write_regs(fe, R_EB14, 1); | 486 | tda18271_write_regs(fe, R_EB14, 1); |
544 | } | 487 | } |
545 | 488 | ||
@@ -579,29 +522,17 @@ static int tda18271_tune(struct dvb_frontend *fe, | |||
579 | regs[R_EP4] &= ~0x80; /* turn this bit on only for fm */ | 522 | regs[R_EP4] &= ~0x80; /* turn this bit on only for fm */ |
580 | 523 | ||
581 | /* image rejection validity EP5[2:0] */ | 524 | /* image rejection validity EP5[2:0] */ |
582 | i = 0; | 525 | tda18271_calc_ir_measure(&freq, &val); |
583 | while ((tda18271_ir_measure[i].rfmax * 1000) < freq) { | 526 | |
584 | if (tda18271_ir_measure[i].rfmax == 0) | ||
585 | break; | ||
586 | i++; | ||
587 | } | ||
588 | dbg_map("ir measure, i = %d\n", i); | ||
589 | regs[R_EP5] &= ~0x07; | 527 | regs[R_EP5] &= ~0x07; |
590 | regs[R_EP5] |= tda18271_ir_measure[i].val; | 528 | regs[R_EP5] |= val; |
591 | 529 | ||
592 | /* calculate MAIN PLL */ | 530 | /* calculate MAIN PLL */ |
593 | N = freq + ifc; | 531 | N = freq + ifc; |
594 | 532 | ||
595 | i = 0; | 533 | tda18271_calc_main_pll(&N, &pd, &d); |
596 | while ((tda18271_main_pll[i].lomax * 1000) < N) { | ||
597 | if (tda18271_main_pll[i + 1].lomax == 0) | ||
598 | break; | ||
599 | i++; | ||
600 | } | ||
601 | dbg_map("main pll, pd = 0x%x, d = 0x%x, i = %d\n", | ||
602 | tda18271_main_pll[i].pd, tda18271_main_pll[i].d, i); | ||
603 | 534 | ||
604 | regs[R_MPD] = (0x7f & tda18271_main_pll[i].pd); | 535 | regs[R_MPD] = (0x7f & pd); |
605 | switch (priv->mode) { | 536 | switch (priv->mode) { |
606 | case TDA18271_ANALOG: | 537 | case TDA18271_ANALOG: |
607 | regs[R_MPD] &= ~0x08; | 538 | regs[R_MPD] &= ~0x08; |
@@ -611,7 +542,7 @@ static int tda18271_tune(struct dvb_frontend *fe, | |||
611 | break; | 542 | break; |
612 | } | 543 | } |
613 | 544 | ||
614 | div = ((tda18271_main_pll[i].d * (N / 1000)) << 7) / 125; | 545 | div = ((d * (N / 1000)) << 7) / 125; |
615 | regs[R_MD1] = 0xff & (div >> 16); | 546 | regs[R_MD1] = 0xff & (div >> 16); |
616 | regs[R_MD2] = 0xff & (div >> 8); | 547 | regs[R_MD2] = 0xff & (div >> 8); |
617 | regs[R_MD3] = 0xff & div; | 548 | regs[R_MD3] = 0xff & div; |