diff options
author | Michael Krufky <mkrufky@linuxtv.org> | 2007-12-24 03:05:05 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2008-01-25 16:04:19 -0500 |
commit | fe0bf6d783d8057bd3dd0dd69613a390d6986c47 (patch) | |
tree | c360d7686028f99bf2514bcd540d2a8cf0ce9e24 /drivers/media/dvb | |
parent | f0bd504fb91c8929bfbacbad759a8e3fe572589f (diff) |
V4L/DVB (6907): tda18271: create separate calc_pll functions
Consolidate duplicated code by creating functions:
tda18271_calc_main_pll
tda18271_calc_cal_pll
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 | 99 |
1 files changed, 56 insertions, 43 deletions
diff --git a/drivers/media/dvb/frontends/tda18271-fe.c b/drivers/media/dvb/frontends/tda18271-fe.c index 4c105853d93c..19c9be92de51 100644 --- a/drivers/media/dvb/frontends/tda18271-fe.c +++ b/drivers/media/dvb/frontends/tda18271-fe.c | |||
@@ -371,13 +371,64 @@ static int tda18271_init(struct dvb_frontend *fe) | |||
371 | return 0; | 371 | return 0; |
372 | } | 372 | } |
373 | 373 | ||
374 | static int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq) | ||
375 | { | ||
376 | /* Sets Main Post-Divider & Divider bytes, but does not write them */ | ||
377 | struct tda18271_priv *priv = fe->tuner_priv; | ||
378 | unsigned char *regs = priv->tda18271_regs; | ||
379 | u8 d, pd; | ||
380 | u32 div; | ||
381 | |||
382 | tda18271_lookup_main_pll(&freq, &pd, &d); | ||
383 | |||
384 | regs[R_MPD] = (0x77 & pd); | ||
385 | |||
386 | switch (priv->mode) { | ||
387 | case TDA18271_ANALOG: | ||
388 | regs[R_MPD] &= ~0x08; | ||
389 | break; | ||
390 | case TDA18271_DIGITAL: | ||
391 | regs[R_MPD] |= 0x08; | ||
392 | break; | ||
393 | } | ||
394 | |||
395 | div = ((d * (freq / 1000)) << 7) / 125; | ||
396 | |||
397 | regs[R_MD1] = 0x7f & (div >> 16); | ||
398 | regs[R_MD2] = 0xff & (div >> 8); | ||
399 | regs[R_MD3] = 0xff & div; | ||
400 | |||
401 | return 0; | ||
402 | } | ||
403 | |||
404 | static int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq) | ||
405 | { | ||
406 | /* Sets Cal Post-Divider & Divider bytes, but does not write them */ | ||
407 | struct tda18271_priv *priv = fe->tuner_priv; | ||
408 | unsigned char *regs = priv->tda18271_regs; | ||
409 | u8 d, pd; | ||
410 | u32 div; | ||
411 | |||
412 | tda18271_lookup_cal_pll(&freq, &pd, &d); | ||
413 | |||
414 | regs[R_CPD] = pd; | ||
415 | |||
416 | div = ((d * (freq / 1000)) << 7) / 125; | ||
417 | |||
418 | regs[R_CD1] = 0x7f & (div >> 16); | ||
419 | regs[R_CD2] = 0xff & (div >> 8); | ||
420 | regs[R_CD3] = 0xff & div; | ||
421 | |||
422 | return 0; | ||
423 | } | ||
424 | |||
374 | static int tda18271_tune(struct dvb_frontend *fe, | 425 | static int tda18271_tune(struct dvb_frontend *fe, |
375 | u32 ifc, u32 freq, u32 bw, u8 std) | 426 | u32 ifc, u32 freq, u32 bw, u8 std) |
376 | { | 427 | { |
377 | struct tda18271_priv *priv = fe->tuner_priv; | 428 | struct tda18271_priv *priv = fe->tuner_priv; |
378 | unsigned char *regs = priv->tda18271_regs; | 429 | unsigned char *regs = priv->tda18271_regs; |
379 | u32 div, N = 0; | 430 | u32 N = 0; |
380 | u8 d, pd, val; | 431 | u8 val; |
381 | 432 | ||
382 | tda18271_init(fe); | 433 | tda18271_init(fe); |
383 | 434 | ||
@@ -419,14 +470,7 @@ static int tda18271_tune(struct dvb_frontend *fe, | |||
419 | break; | 470 | break; |
420 | } | 471 | } |
421 | 472 | ||
422 | tda18271_lookup_cal_pll(&N, &pd, &d); | 473 | tda18271_calc_cal_pll(fe, N); |
423 | |||
424 | regs[R_CPD] = pd; | ||
425 | |||
426 | div = ((d * (N / 1000)) << 7) / 125; | ||
427 | regs[R_CD1] = 0x7f & (div >> 16); | ||
428 | regs[R_CD2] = 0xff & (div >> 8); | ||
429 | regs[R_CD3] = 0xff & div; | ||
430 | 474 | ||
431 | /* calculate MAIN PLL */ | 475 | /* calculate MAIN PLL */ |
432 | 476 | ||
@@ -439,23 +483,7 @@ static int tda18271_tune(struct dvb_frontend *fe, | |||
439 | break; | 483 | break; |
440 | } | 484 | } |
441 | 485 | ||
442 | tda18271_lookup_main_pll(&N, &pd, &d); | 486 | tda18271_calc_main_pll(fe, N); |
443 | |||
444 | regs[R_MPD] = (0x7f & pd); | ||
445 | |||
446 | switch (priv->mode) { | ||
447 | case TDA18271_ANALOG: | ||
448 | regs[R_MPD] &= ~0x08; | ||
449 | break; | ||
450 | case TDA18271_DIGITAL: | ||
451 | regs[R_MPD] |= 0x08; | ||
452 | break; | ||
453 | } | ||
454 | |||
455 | div = ((d * (N / 1000)) << 7) / 125; | ||
456 | regs[R_MD1] = 0x7f & (div >> 16); | ||
457 | regs[R_MD2] = 0xff & (div >> 8); | ||
458 | regs[R_MD3] = 0xff & div; | ||
459 | 487 | ||
460 | tda18271_write_regs(fe, R_EP3, 11); | 488 | tda18271_write_regs(fe, R_EP3, 11); |
461 | msleep(5); /* RF tracking filter calibration initialization */ | 489 | msleep(5); /* RF tracking filter calibration initialization */ |
@@ -554,22 +582,7 @@ static int tda18271_tune(struct dvb_frontend *fe, | |||
554 | /* calculate MAIN PLL */ | 582 | /* calculate MAIN PLL */ |
555 | N = freq + ifc; | 583 | N = freq + ifc; |
556 | 584 | ||
557 | tda18271_lookup_main_pll(&N, &pd, &d); | 585 | tda18271_calc_main_pll(fe, N); |
558 | |||
559 | regs[R_MPD] = (0x7f & pd); | ||
560 | switch (priv->mode) { | ||
561 | case TDA18271_ANALOG: | ||
562 | regs[R_MPD] &= ~0x08; | ||
563 | break; | ||
564 | case TDA18271_DIGITAL: | ||
565 | regs[R_MPD] |= 0x08; | ||
566 | break; | ||
567 | } | ||
568 | |||
569 | div = ((d * (N / 1000)) << 7) / 125; | ||
570 | regs[R_MD1] = 0x7f & (div >> 16); | ||
571 | regs[R_MD2] = 0xff & (div >> 8); | ||
572 | regs[R_MD3] = 0xff & div; | ||
573 | 586 | ||
574 | tda18271_write_regs(fe, R_TM, 15); | 587 | tda18271_write_regs(fe, R_TM, 15); |
575 | msleep(5); | 588 | msleep(5); |