@@ -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;