V4L/DVB (4028): Change dvb_frontend_ops to be a real field instead of a pointer field...
[sfrench/cifs-2.6.git] / drivers / media / dvb / frontends / tda10021.c
index eaf130e666d8b232b311103a95ebdcb1cfd9db27..e83ff2104c9b650c2e30a52118b7e291afa581f9 100644 (file)
@@ -1,10 +1,10 @@
 /*
     TDA10021  - Single Chip Cable Channel Receiver driver module
-               used on the the Siemens DVB-C cards
+              used on the the Siemens DVB-C cards
 
     Copyright (C) 1999 Convergence Integrated Media GmbH <ralph@convergence.de>
     Copyright (C) 2004 Markus Schulz <msc@antzsystem.de>
-                   Support for TDA10021
+                  Support for TDA10021
 
     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
@@ -36,7 +36,6 @@
 
 struct tda10021_state {
        struct i2c_adapter* i2c;
-       struct dvb_frontend_ops ops;
        /* configuration settings */
        const struct tda10021_config* config;
        struct dvb_frontend frontend;
@@ -76,9 +75,9 @@ static u8 tda10021_inittab[0x40]=
 
 static int tda10021_writereg (struct tda10021_state* state, u8 reg, u8 data)
 {
-        u8 buf[] = { reg, data };
+       u8 buf[] = { reg, data };
        struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf, .len = 2 };
-        int ret;
+       int ret;
 
        ret = i2c_transfer (state->i2c, &msg, 1);
        if (ret != 1)
@@ -90,12 +89,20 @@ static int tda10021_writereg (struct tda10021_state* state, u8 reg, u8 data)
        return (ret != 1) ? -EREMOTEIO : 0;
 }
 
+int tda10021_write_byte(struct dvb_frontend* fe, int reg, int data)
+{
+       struct tda10021_state* state = fe->demodulator_priv;
+
+       return tda10021_writereg(state, reg, data);
+}
+EXPORT_SYMBOL(tda10021_write_byte);
+
 static u8 tda10021_readreg (struct tda10021_state* state, u8 reg)
 {
        u8 b0 [] = { reg };
        u8 b1 [] = { 0 };
        struct i2c_msg msg [] = { { .addr = state->config->demod_address, .flags = 0, .buf = b0, .len = 1 },
-                                 { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b1, .len = 1 } };
+                                 { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b1, .len = 1 } };
        int ret;
 
        ret = i2c_transfer (state->i2c, msg, 2);
@@ -225,13 +232,6 @@ static int tda10021_init (struct dvb_frontend *fe)
 
        //Activate PLL
        tda10021_writereg(state, 0x2a, tda10021_inittab[0x2a] & 0xef);
-
-       if (state->config->pll_init) {
-               lock_tuner(state);
-               state->config->pll_init(fe);
-               unlock_tuner(state);
-       }
-
        return 0;
 }
 
@@ -259,9 +259,10 @@ static int tda10021_set_parameters (struct dvb_frontend *fe,
 
        //printk("tda10021: set frequency to %d qam=%d symrate=%d\n", p->frequency,qam,p->u.qam.symbol_rate);
 
-       lock_tuner(state);
-       state->config->pll_set(fe, p);
-       unlock_tuner(state);
+       if (fe->ops.tuner_ops.set_params) {
+               fe->ops.tuner_ops.set_params(fe, p);
+               if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0);
+       }
 
        tda10021_set_symbolrate (state, p->u.qam.symbol_rate);
        tda10021_writereg (state, 0x34, state->pwm);
@@ -376,6 +377,18 @@ static int tda10021_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_pa
        return 0;
 }
 
+static int tda10021_i2c_gate_ctrl(struct dvb_frontend* fe, int enable)
+{
+       struct tda10021_state* state = fe->demodulator_priv;
+
+       if (enable) {
+               lock_tuner(state);
+       } else {
+               unlock_tuner(state);
+       }
+       return 0;
+}
+
 static int tda10021_sleep(struct dvb_frontend* fe)
 {
        struct tda10021_state* state = fe->demodulator_priv;
@@ -407,7 +420,6 @@ struct dvb_frontend* tda10021_attach(const struct tda10021_config* config,
        /* setup the state */
        state->config = config;
        state->i2c = i2c;
-       memcpy(&state->ops, &tda10021_ops, sizeof(struct dvb_frontend_ops));
        state->pwm = pwm;
        state->reg0 = tda10021_inittab[0];
 
@@ -415,7 +427,7 @@ struct dvb_frontend* tda10021_attach(const struct tda10021_config* config,
        if ((tda10021_readreg(state, 0x1a) & 0xf0) != 0x70) goto error;
 
        /* create dvb_frontend */
-       state->frontend.ops = &state->ops;
+       memcpy(&state->frontend.ops, &tda10021_ops, sizeof(struct dvb_frontend_ops));
        state->frontend.demodulator_priv = state;
        return &state->frontend;
 
@@ -434,7 +446,7 @@ static struct dvb_frontend_ops tda10021_ops = {
                .frequency_max = 858000000,
                .symbol_rate_min = (XIN/2)/64,     /* SACLK/64 == (XIN/2)/64 */
                .symbol_rate_max = (XIN/2)/4,      /* SACLK/4 */
-       #if 0
+#if 0
                .frequency_tolerance = ???,
                .symbol_rate_tolerance = ???,  /* ppm */  /* == 8% (spec p. 5) */
        #endif
@@ -448,6 +460,7 @@ static struct dvb_frontend_ops tda10021_ops = {
 
        .init = tda10021_init,
        .sleep = tda10021_sleep,
+       .i2c_gate_ctrl = tda10021_i2c_gate_ctrl,
 
        .set_frontend = tda10021_set_parameters,
        .get_frontend = tda10021_get_frontend,