Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=794604c3efb511b74fb664af72c5dd7046e91075
Commit:     794604c3efb511b74fb664af72c5dd7046e91075
Parent:     58d834ea89664b41e6e21ed2d8dc5680d0dd76b6
Author:     Chris Pascoe <[EMAIL PROTECTED]>
AuthorDate: Mon Nov 19 03:55:45 2007 -0300
Committer:  Mauro Carvalho Chehab <[EMAIL PROTECTED]>
CommitDate: Fri Jan 25 19:02:21 2008 -0200

    V4L/DVB (6630): zl10353: calculate input frequency register instead of 
using hardcoded value
    
    Now we know the zl10353's correct ADC clock, we can calculate the input
    frequency registers correctly instead of just blindly setting them.
    
    Signed-off-by: Chris Pascoe <[EMAIL PROTECTED]>
    Signed-off-by: Mauro Carvalho Chehab <[EMAIL PROTECTED]>
---
 drivers/media/dvb/frontends/zl10353.c      |   42 ++++++++++++++++++++++++---
 drivers/media/dvb/frontends/zl10353.h      |    3 +-
 drivers/media/dvb/frontends/zl10353_priv.h |    6 ++-
 3 files changed, 43 insertions(+), 8 deletions(-)

diff --git a/drivers/media/dvb/frontends/zl10353.c 
b/drivers/media/dvb/frontends/zl10353.c
index 9bfdc01..1736c6a 100644
--- a/drivers/media/dvb/frontends/zl10353.c
+++ b/drivers/media/dvb/frontends/zl10353.c
@@ -1,7 +1,7 @@
 /*
  * Driver for Zarlink DVB-T ZL10353 demodulator
  *
- * Copyright (C) 2006 Christopher Pascoe <[EMAIL PROTECTED]>
+ * Copyright (C) 2006, 2007 Christopher Pascoe <[EMAIL PROTECTED]>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/kernel.h>
@@ -25,6 +25,7 @@
 #include <linux/delay.h>
 #include <linux/string.h>
 #include <linux/slab.h>
+#include <asm/div64.h>
 
 #include "dvb_frontend.h"
 #include "zl10353_priv.h"
@@ -148,6 +149,35 @@ static void zl10353_calc_nominal_rate(struct dvb_frontend 
*fe,
                __FUNCTION__, bw, adc_clock, *nominal_rate);
 }
 
+static void zl10353_calc_input_freq(struct dvb_frontend *fe,
+                                   u16 *input_freq)
+{
+       struct zl10353_state *state = fe->demodulator_priv;
+       u32 adc_clock = 45056;  /* 45.056 MHz */
+       int if2 = 36167;        /* 36.167 MHz */
+       int ife;
+       u64 value;
+
+       if (state->config.adc_clock)
+               adc_clock = state->config.adc_clock;
+       if (state->config.if2)
+               if2 = state->config.if2;
+
+       if (adc_clock >= if2 * 2)
+               ife = if2;
+       else {
+               ife = adc_clock - (if2 % adc_clock);
+               if (ife > adc_clock / 2)
+                       ife = adc_clock - ife;
+       }
+       value = 65536ULL * ife + adc_clock / 2;
+       do_div(value, adc_clock);
+       *input_freq = -value;
+
+       dprintk("%s: if2 %d, ife %d, adc_clock %d => %d / 0x%x\n",
+               __FUNCTION__, if2, ife, adc_clock, -(int)value, *input_freq);
+}
+
 static int zl10353_sleep(struct dvb_frontend *fe)
 {
        static u8 zl10353_softdown[] = { 0x50, 0x0C, 0x44 };
@@ -160,7 +190,7 @@ static int zl10353_set_parameters(struct dvb_frontend *fe,
                                  struct dvb_frontend_parameters *param)
 {
        struct zl10353_state *state = fe->demodulator_priv;
-       u16 nominal_rate;
+       u16 nominal_rate, input_freq;
        u8 pllbuf[6] = { 0x67 };
 
        /* These settings set "auto-everything" and start the FSM. */
@@ -178,8 +208,10 @@ static int zl10353_set_parameters(struct dvb_frontend *fe,
        zl10353_single_write(fe, TRL_NOMINAL_RATE_1, msb(nominal_rate));
        zl10353_single_write(fe, TRL_NOMINAL_RATE_0, lsb(nominal_rate));
 
-       zl10353_single_write(fe, 0x6C, 0xCD);
-       zl10353_single_write(fe, 0x6D, 0x7E);
+       zl10353_calc_input_freq(fe, &input_freq);
+       zl10353_single_write(fe, INPUT_FREQ_1, msb(input_freq));
+       zl10353_single_write(fe, INPUT_FREQ_0, lsb(input_freq));
+
        if (fe->ops.i2c_gate_ctrl)
                fe->ops.i2c_gate_ctrl(fe, 0);
 
diff --git a/drivers/media/dvb/frontends/zl10353.h 
b/drivers/media/dvb/frontends/zl10353.h
index 1c3d494..2660cec 100644
--- a/drivers/media/dvb/frontends/zl10353.h
+++ b/drivers/media/dvb/frontends/zl10353.h
@@ -1,7 +1,7 @@
 /*
  *  Driver for Zarlink DVB-T ZL10353 demodulator
  *
- *  Copyright (C) 2006 Christopher Pascoe <[EMAIL PROTECTED]>
+ *  Copyright (C) 2006, 2007 Christopher Pascoe <[EMAIL PROTECTED]>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -31,6 +31,7 @@ struct zl10353_config
 
        /* frequencies in kHz */
        int adc_clock;  /* default: 45056 */
+       int if2;        /* default: 36167 */
 
        /* set if no pll is connected to the secondary i2c bus */
        int no_tuner;
diff --git a/drivers/media/dvb/frontends/zl10353_priv.h 
b/drivers/media/dvb/frontends/zl10353_priv.h
index 42855df..fcad922 100644
--- a/drivers/media/dvb/frontends/zl10353_priv.h
+++ b/drivers/media/dvb/frontends/zl10353_priv.h
@@ -1,7 +1,7 @@
 /*
  *  Driver for Zarlink DVB-T ZL10353 demodulator
  *
- *  Copyright (C) 2006 Christopher Pascoe <[EMAIL PROTECTED]>
+ *  Copyright (C) 2006, 2007 Christopher Pascoe <[EMAIL PROTECTED]>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #ifndef _ZL10353_PRIV_
@@ -48,6 +48,8 @@ enum zl10353_reg_addr {
        RS_UBC_0           = 0x15,
        TRL_NOMINAL_RATE_1 = 0x65,
        TRL_NOMINAL_RATE_0 = 0x66,
+       INPUT_FREQ_1       = 0x6C,
+       INPUT_FREQ_0       = 0x6D,
        TUNER_GO           = 0x70,
        FSM_GO             = 0x71,
        CHIP_ID            = 0x7F,
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to