Skip to content

Instantly share code, notes, and snippets.

Created January 25, 2014 13:38
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anonymous/8616490 to your computer and use it in GitHub Desktop.
Here is alternative ndiv code, it is based on vendors code.
It uses the ndiv value not frequency to change the divider.
Signed-off-by: Malcolm Priestley <tvboxspy@gmail.com>
---
drivers/media/dvb-frontends/ts2020.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/drivers/media/dvb-frontends/ts2020.c b/drivers/media/dvb-frontends/ts2020.c
index 9aba044..9e051efb 100644
--- a/drivers/media/dvb-frontends/ts2020.c
+++ b/drivers/media/dvb-frontends/ts2020.c
@@ -186,22 +186,27 @@ static int ts2020_set_params(struct dvb_frontend *fe)
struct ts2020_priv *priv = fe->tuner_priv;
int ret;
u32 frequency = c->frequency;
- s32 offset_khz;
+ u32 offset_khz, ndiv_mul;
u32 symbol_rate = (c->symbol_rate / 1000);
u32 f3db, gdiv28;
u16 value, ndiv, lpf_coeff;
u8 lpf_mxdiv, mlpf_max, mlpf_min, nlpf;
u8 lo = 0x01, div4 = 0x0;
+ ndiv = (u16)((frequency * 14 * 2 + TS2020_XTAL_FREQ / 2)
+ / TS2020_XTAL_FREQ);
+
/* Calculate frequency divider */
- if (frequency < priv->frequency_div) {
+ if (ndiv < 1100) {
lo |= 0x10;
div4 = 0x1;
- ndiv = (frequency * 14 * 4) / TS2020_XTAL_FREQ;
- } else
- ndiv = (frequency * 14 * 2) / TS2020_XTAL_FREQ;
- ndiv = ndiv + ndiv % 2;
- ndiv = ndiv - 1024;
+ ndiv = (u16)((frequency * 14 * 4 + TS2020_XTAL_FREQ / 2)
+ / TS2020_XTAL_FREQ) - 1024;
+ ndiv_mul = ndiv + 1024;
+ } else {
+ ndiv -= 1024;
+ ndiv_mul = ndiv - ndiv % 2 + 1024;
+ }
ret = ts2020_writereg(fe, 0x10, 0x80 | lo);
@@ -272,9 +277,8 @@ static int ts2020_set_params(struct dvb_frontend *fe)
ret |= ts2020_tuner_gate_ctrl(fe, 0x01);
msleep(80);
- /* calculate offset assuming 96000kHz*/
- offset_khz = (ndiv - ndiv % 2 + 1024) * TS2020_XTAL_FREQ
- / (6 + 8) / (div4 + 1) / 2;
+
+ offset_khz = ndiv_mul * TS2020_XTAL_FREQ / 14 / (div4 + 1) / 2;
priv->frequency = offset_khz;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment