Merge branch 'drm-intel-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/ickle...
[pandora-kernel.git] / drivers / media / dvb / frontends / mt352.c
index aaaec90..319672f 100644 (file)
@@ -32,7 +32,6 @@
 
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/moduleparam.h>
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/string.h>
@@ -45,7 +44,6 @@
 struct mt352_state {
        struct i2c_adapter* i2c;
        struct dvb_frontend frontend;
-       struct dvb_frontend_ops ops;
 
        /* configuration settings */
        struct mt352_config config;
@@ -71,7 +69,7 @@ static int mt352_single_write(struct dvb_frontend *fe, u8 reg, u8 val)
        return 0;
 }
 
-int mt352_write(struct dvb_frontend* fe, u8* ibuf, int ilen)
+static int _mt352_write(struct dvb_frontend* fe, const u8 ibuf[], int ilen)
 {
        int err,i;
        for (i=0; i < ilen-1; i++)
@@ -97,7 +95,7 @@ static int mt352_read_register(struct mt352_state* state, u8 reg)
 
        if (ret != 2) {
                printk("%s: readreg error (reg=%d, ret==%i)\n",
-                      __FUNCTION__, reg, ret);
+                      __func__, reg, ret);
                return ret;
        }
 
@@ -108,7 +106,7 @@ static int mt352_sleep(struct dvb_frontend* fe)
 {
        static u8 mt352_softdown[] = { CLOCK_CTL, 0x20, 0x08 };
 
-       mt352_write(fe, mt352_softdown, sizeof(mt352_softdown));
+       _mt352_write(fe, mt352_softdown, sizeof(mt352_softdown));
        return 0;
 }
 
@@ -137,7 +135,7 @@ static void mt352_calc_nominal_rate(struct mt352_state* state,
        value = 64 * bw * (1<<16) / (7 * 8);
        value = value * 1000 / adc_clock;
        dprintk("%s: bw %d, adc_clock %d => 0x%x\n",
-               __FUNCTION__, bw, adc_clock, value);
+               __func__, bw, adc_clock, value);
        buf[0] = msb(value);
        buf[1] = lsb(value);
 }
@@ -154,10 +152,16 @@ static void mt352_calc_input_freq(struct mt352_state* state,
        if (state->config.if2)
                if2 = state->config.if2;
 
-       ife = (2*adc_clock - 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 = -16374 * ife / adc_clock;
        dprintk("%s: if2 %d, ife %d, adc_clock %d => %d / 0x%x\n",
-               __FUNCTION__, if2, ife, adc_clock, value, value & 0x3fff);
+               __func__, if2, ife, adc_clock, value, value & 0x3fff);
        buf[0] = msb(value);
        buf[1] = lsb(value);
 }
@@ -286,16 +290,25 @@ static int mt352_set_parameters(struct dvb_frontend* fe,
 
        mt352_calc_nominal_rate(state, op->bandwidth, buf+4);
        mt352_calc_input_freq(state, buf+6);
-       state->config.pll_set(fe, param, buf+8);
 
-       mt352_write(fe, buf, sizeof(buf));
        if (state->config.no_tuner) {
-               /* start decoding */
-               mt352_write(fe, fsm_go, 2);
+               if (fe->ops.tuner_ops.set_params) {
+                       fe->ops.tuner_ops.set_params(fe, param);
+                       if (fe->ops.i2c_gate_ctrl)
+                               fe->ops.i2c_gate_ctrl(fe, 0);
+               }
+
+               _mt352_write(fe, buf, 8);
+               _mt352_write(fe, fsm_go, 2);
        } else {
-               /* start tuning */
-               mt352_write(fe, tuner_go, 2);
+               if (fe->ops.tuner_ops.calc_regs) {
+                       fe->ops.tuner_ops.calc_regs(fe, param, buf+8, 5);
+                       buf[8] <<= 1;
+                       _mt352_write(fe, buf, sizeof(buf));
+                       _mt352_write(fe, tuner_go, 2);
+               }
        }
+
        return 0;
 }
 
@@ -508,13 +521,13 @@ static int mt352_init(struct dvb_frontend* fe)
 
        static u8 mt352_reset_attach [] = { RESET, 0xC0 };
 
-       dprintk("%s: hello\n",__FUNCTION__);
+       dprintk("%s: hello\n",__func__);
 
        if ((mt352_read_register(state, CLOCK_CTL) & 0x10) == 0 ||
            (mt352_read_register(state, CONFIG) & 0x20) == 0) {
 
                /* Do a "hard" reset */
-               mt352_write(fe, mt352_reset_attach, sizeof(mt352_reset_attach));
+               _mt352_write(fe, mt352_reset_attach, sizeof(mt352_reset_attach));
                return state->config.demod_init(fe);
        }
 
@@ -541,13 +554,12 @@ struct dvb_frontend* mt352_attach(const struct mt352_config* config,
        /* setup the state */
        state->i2c = i2c;
        memcpy(&state->config,config,sizeof(struct mt352_config));
-       memcpy(&state->ops, &mt352_ops, sizeof(struct dvb_frontend_ops));
 
        /* check if the demod is there */
        if (mt352_read_register(state, CHIP_ID) != ID_MT352) goto error;
 
        /* create dvb_frontend */
-       state->frontend.ops = &state->ops;
+       memcpy(&state->frontend.ops, &mt352_ops, sizeof(struct dvb_frontend_ops));
        state->frontend.demodulator_priv = state;
        return &state->frontend;
 
@@ -578,6 +590,7 @@ static struct dvb_frontend_ops mt352_ops = {
 
        .init = mt352_init,
        .sleep = mt352_sleep,
+       .write = _mt352_write,
 
        .set_frontend = mt352_set_parameters,
        .get_frontend = mt352_get_parameters,
@@ -598,4 +611,3 @@ MODULE_AUTHOR("Holger Waechtler, Daniel Mack, Antonio Mancuso");
 MODULE_LICENSE("GPL");
 
 EXPORT_SYMBOL(mt352_attach);
-EXPORT_SYMBOL(mt352_write);