diff options
author | Michael Krufky <mkrufky@linuxtv.org> | 2007-12-25 16:54:22 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2008-01-25 16:04:26 -0500 |
commit | b92bf0f6a94b73a1b8bd0023b1fa642d13b01a76 (patch) | |
tree | e4159338155174bf07110ce7f87282f1e78242fb /drivers/media/dvb | |
parent | 182519f4c99f73f376323580dda494d986b4760b (diff) |
V4L/DVB (6928): tda18271: break calculation functions out of tda18271_tune
Break out the following new functions from tda18271_tune:
tda18271_calc_bp_filter
tda18271_calc_km
tda18271_calc_rf_band
tda18271_calc_gain_taper
tda18271_calc_ir_measure
tda18271_calc_rf_cal
Signed-off-by: Michael Krufky <mkrufky@linuxtv.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/dvb')
-rw-r--r-- | drivers/media/dvb/frontends/tda18271-fe.c | 143 |
1 files changed, 114 insertions, 29 deletions
diff --git a/drivers/media/dvb/frontends/tda18271-fe.c b/drivers/media/dvb/frontends/tda18271-fe.c index 8146c4e7ee7b..d5807c98afc1 100644 --- a/drivers/media/dvb/frontends/tda18271-fe.c +++ b/drivers/media/dvb/frontends/tda18271-fe.c | |||
@@ -406,13 +406,118 @@ fail: | |||
406 | return ret; | 406 | return ret; |
407 | } | 407 | } |
408 | 408 | ||
409 | static int tda18271_calc_bp_filter(struct dvb_frontend *fe, u32 *freq) | ||
410 | { | ||
411 | /* Sets BP filter bits, but does not write them */ | ||
412 | struct tda18271_priv *priv = fe->tuner_priv; | ||
413 | unsigned char *regs = priv->tda18271_regs; | ||
414 | u8 val; | ||
415 | |||
416 | int ret = tda18271_lookup_map(BP_FILTER, freq, &val); | ||
417 | if (ret < 0) | ||
418 | goto fail; | ||
419 | |||
420 | regs[R_EP1] &= ~0x07; /* clear bp filter bits */ | ||
421 | regs[R_EP1] |= (0x07 & val); | ||
422 | fail: | ||
423 | return ret; | ||
424 | } | ||
425 | |||
426 | static int tda18271_calc_km(struct dvb_frontend *fe, u32 *freq) | ||
427 | { | ||
428 | /* Sets K & M bits, but does not write them */ | ||
429 | struct tda18271_priv *priv = fe->tuner_priv; | ||
430 | unsigned char *regs = priv->tda18271_regs; | ||
431 | u8 val; | ||
432 | |||
433 | int ret = tda18271_lookup_map(RF_CAL_KMCO, freq, &val); | ||
434 | if (ret < 0) | ||
435 | goto fail; | ||
436 | |||
437 | regs[R_EB13] &= ~0x7c; /* clear k & m bits */ | ||
438 | regs[R_EB13] |= (0x7c & val); | ||
439 | fail: | ||
440 | return ret; | ||
441 | } | ||
442 | |||
443 | static int tda18271_calc_rf_band(struct dvb_frontend *fe, u32 *freq) | ||
444 | { | ||
445 | /* Sets RF Band bits, but does not write them */ | ||
446 | struct tda18271_priv *priv = fe->tuner_priv; | ||
447 | unsigned char *regs = priv->tda18271_regs; | ||
448 | u8 val; | ||
449 | |||
450 | int ret = tda18271_lookup_map(RF_BAND, freq, &val); | ||
451 | if (ret < 0) | ||
452 | goto fail; | ||
453 | |||
454 | regs[R_EP2] &= ~0xe0; /* clear rf band bits */ | ||
455 | regs[R_EP2] |= (0xe0 & (val << 5)); | ||
456 | fail: | ||
457 | return ret; | ||
458 | } | ||
459 | |||
460 | static int tda18271_calc_gain_taper(struct dvb_frontend *fe, u32 *freq) | ||
461 | { | ||
462 | /* Sets Gain Taper bits, but does not write them */ | ||
463 | struct tda18271_priv *priv = fe->tuner_priv; | ||
464 | unsigned char *regs = priv->tda18271_regs; | ||
465 | u8 val; | ||
466 | |||
467 | int ret = tda18271_lookup_map(GAIN_TAPER, freq, &val); | ||
468 | if (ret < 0) | ||
469 | goto fail; | ||
470 | |||
471 | regs[R_EP2] &= ~0x1f; /* clear gain taper bits */ | ||
472 | regs[R_EP2] |= (0x1f & val); | ||
473 | fail: | ||
474 | return ret; | ||
475 | } | ||
476 | |||
477 | static int tda18271_calc_ir_measure(struct dvb_frontend *fe, u32 *freq) | ||
478 | { | ||
479 | /* Sets IR Meas bits, but does not write them */ | ||
480 | struct tda18271_priv *priv = fe->tuner_priv; | ||
481 | unsigned char *regs = priv->tda18271_regs; | ||
482 | u8 val; | ||
483 | |||
484 | int ret = tda18271_lookup_map(IR_MEASURE, freq, &val); | ||
485 | if (ret < 0) | ||
486 | goto fail; | ||
487 | |||
488 | regs[R_EP5] &= ~0x07; | ||
489 | regs[R_EP5] |= (0x07 & val); | ||
490 | fail: | ||
491 | return ret; | ||
492 | } | ||
493 | |||
494 | static int tda18271_calc_rf_cal(struct dvb_frontend *fe, u32 *freq) | ||
495 | { | ||
496 | /* Sets RF Cal bits, but does not write them */ | ||
497 | struct tda18271_priv *priv = fe->tuner_priv; | ||
498 | unsigned char *regs = priv->tda18271_regs; | ||
499 | u8 val; | ||
500 | |||
501 | int ret = tda18271_lookup_map(RF_CAL, freq, &val); | ||
502 | if (ret < 0) | ||
503 | goto fail; | ||
504 | |||
505 | /* VHF_Low band only */ | ||
506 | if (0 == val) { | ||
507 | ret = -ERANGE; | ||
508 | goto fail; | ||
509 | } | ||
510 | regs[R_EB14] = val; | ||
511 | fail: | ||
512 | return ret; | ||
513 | } | ||
514 | |||
409 | static int tda18271_tune(struct dvb_frontend *fe, | 515 | static int tda18271_tune(struct dvb_frontend *fe, |
410 | u32 ifc, u32 freq, u32 bw, u8 std) | 516 | u32 ifc, u32 freq, u32 bw, u8 std) |
411 | { | 517 | { |
412 | struct tda18271_priv *priv = fe->tuner_priv; | 518 | struct tda18271_priv *priv = fe->tuner_priv; |
413 | unsigned char *regs = priv->tda18271_regs; | 519 | unsigned char *regs = priv->tda18271_regs; |
414 | u32 N = 0; | 520 | u32 N = 0; |
415 | u8 val; | ||
416 | 521 | ||
417 | tda18271_init(fe); | 522 | tda18271_init(fe); |
418 | 523 | ||
@@ -421,10 +526,7 @@ static int tda18271_tune(struct dvb_frontend *fe, | |||
421 | /* RF tracking filter calibration */ | 526 | /* RF tracking filter calibration */ |
422 | 527 | ||
423 | /* calculate BP_Filter */ | 528 | /* calculate BP_Filter */ |
424 | tda18271_lookup_map(BP_FILTER, &freq, &val); | 529 | tda18271_calc_bp_filter(fe, &freq); |
425 | |||
426 | regs[R_EP1] &= ~0x07; /* clear bp filter bits */ | ||
427 | regs[R_EP1] |= val; | ||
428 | tda18271_write_regs(fe, R_EP1, 1); | 530 | tda18271_write_regs(fe, R_EP1, 1); |
429 | 531 | ||
430 | regs[R_EB4] &= 0x07; | 532 | regs[R_EB4] &= 0x07; |
@@ -473,23 +575,14 @@ static int tda18271_tune(struct dvb_frontend *fe, | |||
473 | msleep(5); /* RF tracking filter calibration initialization */ | 575 | msleep(5); /* RF tracking filter calibration initialization */ |
474 | 576 | ||
475 | /* search for K,M,CO for RF Calibration */ | 577 | /* search for K,M,CO for RF Calibration */ |
476 | tda18271_lookup_map(RF_CAL_KMCO, &freq, &val); | 578 | tda18271_calc_km(fe, &freq); |
477 | |||
478 | regs[R_EB13] &= 0x83; | ||
479 | regs[R_EB13] |= val; | ||
480 | tda18271_write_regs(fe, R_EB13, 1); | 579 | tda18271_write_regs(fe, R_EB13, 1); |
481 | 580 | ||
482 | /* search for RF_BAND */ | 581 | /* search for RF_BAND */ |
483 | tda18271_lookup_map(RF_BAND, &freq, &val); | 582 | tda18271_calc_rf_band(fe, &freq); |
484 | |||
485 | regs[R_EP2] &= ~0xe0; /* clear rf band bits */ | ||
486 | regs[R_EP2] |= (val << 5); | ||
487 | 583 | ||
488 | /* search for Gain_Taper */ | 584 | /* search for Gain_Taper */ |
489 | tda18271_lookup_map(GAIN_TAPER, &freq, &val); | 585 | tda18271_calc_gain_taper(fe, &freq); |
490 | |||
491 | regs[R_EP2] &= ~0x1f; /* clear gain taper bits */ | ||
492 | regs[R_EP2] |= val; | ||
493 | 586 | ||
494 | tda18271_write_regs(fe, R_EP2, 1); | 587 | tda18271_write_regs(fe, R_EP2, 1); |
495 | tda18271_write_regs(fe, R_EP1, 1); | 588 | tda18271_write_regs(fe, R_EP1, 1); |
@@ -513,14 +606,9 @@ static int tda18271_tune(struct dvb_frontend *fe, | |||
513 | 606 | ||
514 | tda18271_write_regs(fe, R_EP1, 1); | 607 | tda18271_write_regs(fe, R_EP1, 1); |
515 | 608 | ||
516 | /* RF tracking filer correction for VHF_Low band */ | 609 | /* RF tracking filter correction for VHF_Low band */ |
517 | tda18271_lookup_map(RF_CAL, &freq, &val); | 610 | if (0 == tda18271_calc_rf_cal(fe, &freq)) |
518 | |||
519 | /* VHF_Low band only */ | ||
520 | if (val != 0) { | ||
521 | regs[R_EB14] = val; | ||
522 | tda18271_write_regs(fe, R_EB14, 1); | 611 | tda18271_write_regs(fe, R_EB14, 1); |
523 | } | ||
524 | 612 | ||
525 | /* Channel Configuration */ | 613 | /* Channel Configuration */ |
526 | 614 | ||
@@ -557,11 +645,8 @@ static int tda18271_tune(struct dvb_frontend *fe, | |||
557 | 645 | ||
558 | regs[R_EP4] &= ~0x80; /* turn this bit on only for fm */ | 646 | regs[R_EP4] &= ~0x80; /* turn this bit on only for fm */ |
559 | 647 | ||
560 | /* image rejection validity EP5[2:0] */ | 648 | /* image rejection validity */ |
561 | tda18271_lookup_map(IR_MEASURE, &freq, &val); | 649 | tda18271_calc_ir_measure(fe, &freq); |
562 | |||
563 | regs[R_EP5] &= ~0x07; | ||
564 | regs[R_EP5] |= val; | ||
565 | 650 | ||
566 | /* calculate MAIN PLL */ | 651 | /* calculate MAIN PLL */ |
567 | N = freq + ifc; | 652 | N = freq + ifc; |