diff options
author | Michael Krufky <mkrufky@linuxtv.org> | 2006-11-20 14:45:29 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2006-12-10 06:05:05 -0500 |
commit | 89faeefcf875c16d8923eaed50bd57731c221bcc (patch) | |
tree | fd6d7f56a3169b3fb9ff3dca12730bc2f469ad8e /drivers/media/dvb/frontends/dvb-pll.c | |
parent | 47ae9ae895a5228e7a3ca47b1c9ab00a3f641923 (diff) |
V4L/DVB (4868): Dvb-pll: return frequency set by dvb_pll_configure()
This patch removes some duplicated code by returning the frequency set by
dvb_pll_configure(), instead of recalculating it again in dvb_pll_set_params()
and dvb_pll_calc_regs().
If the return value of dvb_pll_configure is less than zero, it is an error
code. Otherwise, the return value is the frequency actually set by the
function.
Signed-off-by: Michael Krufky <mkrufky@linuxtv.org>
Acked-by: Andrew de Quincey <adq_dvb@lidskialf.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/dvb/frontends/dvb-pll.c')
-rw-r--r-- | drivers/media/dvb/frontends/dvb-pll.c | 44 |
1 files changed, 14 insertions, 30 deletions
diff --git a/drivers/media/dvb/frontends/dvb-pll.c b/drivers/media/dvb/frontends/dvb-pll.c index b0785d542f03..62de760c844f 100644 --- a/drivers/media/dvb/frontends/dvb-pll.c +++ b/drivers/media/dvb/frontends/dvb-pll.c | |||
@@ -472,7 +472,8 @@ int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf, | |||
472 | printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n", | 472 | printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n", |
473 | desc->name, div, buf[0], buf[1], buf[2], buf[3]); | 473 | desc->name, div, buf[0], buf[1], buf[2], buf[3]); |
474 | 474 | ||
475 | return 0; | 475 | // calculate the frequency we set it to |
476 | return (div * desc->entries[i].stepsize) - desc->entries[i].offset; | ||
476 | } | 477 | } |
477 | EXPORT_SYMBOL(dvb_pll_configure); | 478 | EXPORT_SYMBOL(dvb_pll_configure); |
478 | 479 | ||
@@ -526,9 +527,7 @@ static int dvb_pll_set_params(struct dvb_frontend *fe, | |||
526 | { .addr = priv->pll_i2c_address, .flags = 0, | 527 | { .addr = priv->pll_i2c_address, .flags = 0, |
527 | .buf = buf, .len = sizeof(buf) }; | 528 | .buf = buf, .len = sizeof(buf) }; |
528 | int result; | 529 | int result; |
529 | u32 div; | 530 | u32 bandwidth = 0, frequency = 0; |
530 | int i; | ||
531 | u32 bandwidth = 0; | ||
532 | 531 | ||
533 | if (priv->i2c == NULL) | 532 | if (priv->i2c == NULL) |
534 | return -EINVAL; | 533 | return -EINVAL; |
@@ -538,9 +537,11 @@ static int dvb_pll_set_params(struct dvb_frontend *fe, | |||
538 | bandwidth = params->u.ofdm.bandwidth; | 537 | bandwidth = params->u.ofdm.bandwidth; |
539 | } | 538 | } |
540 | 539 | ||
541 | if ((result = dvb_pll_configure(priv->pll_desc, buf, params->frequency, | 540 | if ((result = dvb_pll_configure(priv->pll_desc, buf, |
542 | bandwidth)) != 0) | 541 | params->frequency, bandwidth)) < 0) |
543 | return result; | 542 | return result; |
543 | else | ||
544 | frequency = result; | ||
544 | 545 | ||
545 | if (fe->ops.i2c_gate_ctrl) | 546 | if (fe->ops.i2c_gate_ctrl) |
546 | fe->ops.i2c_gate_ctrl(fe, 1); | 547 | fe->ops.i2c_gate_ctrl(fe, 1); |
@@ -548,16 +549,7 @@ static int dvb_pll_set_params(struct dvb_frontend *fe, | |||
548 | return result; | 549 | return result; |
549 | } | 550 | } |
550 | 551 | ||
551 | // calculate the frequency we set it to | 552 | priv->frequency = frequency; |
552 | for (i = 0; i < priv->pll_desc->count; i++) { | ||
553 | if (params->frequency > priv->pll_desc->entries[i].limit) | ||
554 | continue; | ||
555 | break; | ||
556 | } | ||
557 | div = (params->frequency + priv->pll_desc->entries[i].offset) / | ||
558 | priv->pll_desc->entries[i].stepsize; | ||
559 | priv->frequency = (div * priv->pll_desc->entries[i].stepsize) - | ||
560 | priv->pll_desc->entries[i].offset; | ||
561 | priv->bandwidth = bandwidth; | 553 | priv->bandwidth = bandwidth; |
562 | 554 | ||
563 | return 0; | 555 | return 0; |
@@ -569,9 +561,7 @@ static int dvb_pll_calc_regs(struct dvb_frontend *fe, | |||
569 | { | 561 | { |
570 | struct dvb_pll_priv *priv = fe->tuner_priv; | 562 | struct dvb_pll_priv *priv = fe->tuner_priv; |
571 | int result; | 563 | int result; |
572 | u32 div; | 564 | u32 bandwidth = 0, frequency = 0; |
573 | int i; | ||
574 | u32 bandwidth = 0; | ||
575 | 565 | ||
576 | if (buf_len < 5) | 566 | if (buf_len < 5) |
577 | return -EINVAL; | 567 | return -EINVAL; |
@@ -582,20 +572,14 @@ static int dvb_pll_calc_regs(struct dvb_frontend *fe, | |||
582 | } | 572 | } |
583 | 573 | ||
584 | if ((result = dvb_pll_configure(priv->pll_desc, buf+1, | 574 | if ((result = dvb_pll_configure(priv->pll_desc, buf+1, |
585 | params->frequency, bandwidth)) != 0) | 575 | params->frequency, bandwidth)) < 0) |
586 | return result; | 576 | return result; |
577 | else | ||
578 | frequency = result; | ||
579 | |||
587 | buf[0] = priv->pll_i2c_address; | 580 | buf[0] = priv->pll_i2c_address; |
588 | 581 | ||
589 | // calculate the frequency we set it to | 582 | priv->frequency = frequency; |
590 | for (i = 0; i < priv->pll_desc->count; i++) { | ||
591 | if (params->frequency > priv->pll_desc->entries[i].limit) | ||
592 | continue; | ||
593 | break; | ||
594 | } | ||
595 | div = (params->frequency + priv->pll_desc->entries[i].offset) / | ||
596 | priv->pll_desc->entries[i].stepsize; | ||
597 | priv->frequency = (div * priv->pll_desc->entries[i].stepsize) - | ||
598 | priv->pll_desc->entries[i].offset; | ||
599 | priv->bandwidth = bandwidth; | 583 | priv->bandwidth = bandwidth; |
600 | 584 | ||
601 | return 5; | 585 | return 5; |