V4L/DVB (13811): [MB86A16] Update Copyright header
[safe/jmp/linux-2.6] / drivers / media / dvb / frontends / stv0299.c
index e91bb58..9688744 100644 (file)
@@ -45,7 +45,6 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/moduleparam.h>
 #include <linux/string.h>
 #include <linux/slab.h>
 #include <linux/jiffies.h>
@@ -56,7 +55,6 @@
 
 struct stv0299_state {
        struct i2c_adapter* i2c;
-       struct dvb_frontend_ops ops;
        const struct stv0299_config* config;
        struct dvb_frontend frontend;
 
@@ -65,6 +63,7 @@ struct stv0299_state {
        u32 symbol_rate;
        fe_code_rate_t fec_inner;
        int errmode;
+       u32 ucblocks;
 };
 
 #define STATUS_BER 0
@@ -88,16 +87,19 @@ static int stv0299_writeregI (struct stv0299_state* state, u8 reg, u8 data)
 
        if (ret != 1)
                dprintk("%s: writereg error (reg == 0x%02x, val == 0x%02x, "
-                       "ret == %i)\n", __FUNCTION__, reg, data, ret);
+                       "ret == %i)\n", __func__, reg, data, ret);
 
        return (ret != 1) ? -EREMOTEIO : 0;
 }
 
-int stv0299_writereg (struct dvb_frontend* fe, u8 reg, u8 data)
+static int stv0299_write(struct dvb_frontend* fe, u8 *buf, int len)
 {
        struct stv0299_state* state = fe->demodulator_priv;
 
-       return stv0299_writeregI(state, reg, data);
+       if (len != 2)
+               return -EINVAL;
+
+       return stv0299_writeregI(state, buf[0], buf[1]);
 }
 
 static u8 stv0299_readreg (struct stv0299_state* state, u8 reg)
@@ -112,7 +114,7 @@ static u8 stv0299_readreg (struct stv0299_state* state, u8 reg)
 
        if (ret != 2)
                dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n",
-                               __FUNCTION__, reg, ret);
+                               __func__, reg, ret);
 
        return b1[0];
 }
@@ -126,14 +128,14 @@ static int stv0299_readregs (struct stv0299_state* state, u8 reg1, u8 *b, u8 len
        ret = i2c_transfer (state->i2c, msg, 2);
 
        if (ret != 2)
-               dprintk("%s: readreg error (ret == %i)\n", __FUNCTION__, ret);
+               dprintk("%s: readreg error (ret == %i)\n", __func__, ret);
 
        return ret == 2 ? 0 : ret;
 }
 
 static int stv0299_set_FEC (struct stv0299_state* state, fe_code_rate_t fec)
 {
-       dprintk ("%s\n", __FUNCTION__);
+       dprintk ("%s\n", __func__);
 
        switch (fec) {
        case FEC_AUTO:
@@ -173,7 +175,7 @@ static fe_code_rate_t stv0299_get_fec (struct stv0299_state* state)
                                             FEC_7_8, FEC_1_2 };
        u8 index;
 
-       dprintk ("%s\n", __FUNCTION__);
+       dprintk ("%s\n", __func__);
 
        index = stv0299_readreg (state, 0x1b);
        index &= 0x7;
@@ -188,11 +190,11 @@ static int stv0299_wait_diseqc_fifo (struct stv0299_state* state, int timeout)
 {
        unsigned long start = jiffies;
 
-       dprintk ("%s\n", __FUNCTION__);
+       dprintk ("%s\n", __func__);
 
        while (stv0299_readreg(state, 0x0a) & 1) {
                if (jiffies - start > timeout) {
-                       dprintk ("%s: timeout!!\n", __FUNCTION__);
+                       dprintk ("%s: timeout!!\n", __func__);
                        return -ETIMEDOUT;
                }
                msleep(10);
@@ -205,11 +207,11 @@ static int stv0299_wait_diseqc_idle (struct stv0299_state* state, int timeout)
 {
        unsigned long start = jiffies;
 
-       dprintk ("%s\n", __FUNCTION__);
+       dprintk ("%s\n", __func__);
 
        while ((stv0299_readreg(state, 0x0a) & 3) != 2 ) {
                if (jiffies - start > timeout) {
-                       dprintk ("%s: timeout!!\n", __FUNCTION__);
+                       dprintk ("%s: timeout!!\n", __func__);
                        return -ETIMEDOUT;
                }
                msleep(10);
@@ -244,10 +246,10 @@ static int stv0299_get_symbolrate (struct stv0299_state* state)
        u8 sfr[3];
        s8 rtf;
 
-       dprintk ("%s\n", __FUNCTION__);
+       dprintk ("%s\n", __func__);
 
        stv0299_readregs (state, 0x1f, sfr, 3);
-       stv0299_readregs (state, 0x1a, &rtf, 1);
+       stv0299_readregs (state, 0x1a, (u8 *)&rtf, 1);
 
        srate = (sfr[0] << 8) | sfr[1];
        srate *= Mclk;
@@ -256,8 +258,8 @@ static int stv0299_get_symbolrate (struct stv0299_state* state)
        offset = (s32) rtf * (srate / 4096L);
        offset /= 128;
 
-       dprintk ("%s : srate = %i\n", __FUNCTION__, srate);
-       dprintk ("%s : ofset = %i\n", __FUNCTION__, offset);
+       dprintk ("%s : srate = %i\n", __func__, srate);
+       dprintk ("%s : ofset = %i\n", __func__, offset);
 
        srate += offset;
 
@@ -275,7 +277,7 @@ static int stv0299_send_diseqc_msg (struct dvb_frontend* fe,
        u8 val;
        int i;
 
-       dprintk ("%s\n", __FUNCTION__);
+       dprintk ("%s\n", __func__);
 
        if (stv0299_wait_diseqc_idle (state, 100) < 0)
                return -ETIMEDOUT;
@@ -304,7 +306,7 @@ static int stv0299_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t
        struct stv0299_state* state = fe->demodulator_priv;
        u8 val;
 
-       dprintk ("%s\n", __FUNCTION__);
+       dprintk ("%s\n", __func__);
 
        if (stv0299_wait_diseqc_idle (state, 100) < 0)
                return -ETIMEDOUT;
@@ -354,7 +356,7 @@ static int stv0299_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltag
        u8 reg0x08;
        u8 reg0x0c;
 
-       dprintk("%s: %s\n", __FUNCTION__,
+       dprintk("%s: %s\n", __func__,
                voltage == SEC_VOLTAGE_13 ? "SEC_VOLTAGE_13" :
                voltage == SEC_VOLTAGE_18 ? "SEC_VOLTAGE_18" : "??");
 
@@ -365,26 +367,32 @@ static int stv0299_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltag
         *  H/V switching over OP0, OP1 and OP2 are LNB power enable bits
         */
        reg0x0c &= 0x0f;
-
-       if (voltage == SEC_VOLTAGE_OFF) {
-               stv0299_writeregI (state, 0x0c, 0x00); /*       LNB power off! */
-               return stv0299_writeregI (state, 0x08, 0x00); /*        LNB power off! */
-       }
-
-       stv0299_writeregI (state, 0x08, (reg0x08 & 0x3f) | (state->config->lock_output << 6));
+       reg0x08 = (reg0x08 & 0x3f) | (state->config->lock_output << 6);
 
        switch (voltage) {
        case SEC_VOLTAGE_13:
-               if (state->config->volt13_op0_op1 == STV0299_VOLT13_OP0) reg0x0c |= 0x10;
-               else reg0x0c |= 0x40;
-
-               return stv0299_writeregI(state, 0x0c, reg0x0c);
-
+               if (state->config->volt13_op0_op1 == STV0299_VOLT13_OP0)
+                       reg0x0c |= 0x10; /* OP1 off, OP0 on */
+               else
+                       reg0x0c |= 0x40; /* OP1 on, OP0 off */
+               break;
        case SEC_VOLTAGE_18:
-               return stv0299_writeregI(state, 0x0c, reg0x0c | 0x50);
+               reg0x0c |= 0x50; /* OP1 on, OP0 on */
+               break;
+       case SEC_VOLTAGE_OFF:
+               /* LNB power off! */
+               reg0x08 = 0x00;
+               reg0x0c = 0x00;
+               break;
        default:
                return -EINVAL;
        };
+
+       if (state->config->op0_off)
+               reg0x0c &= ~0x10;
+
+       stv0299_writeregI(state, 0x08, reg0x08);
+       return stv0299_writeregI(state, 0x0c, reg0x0c);
 }
 
 static int stv0299_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long cmd)
@@ -407,7 +415,7 @@ static int stv0299_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long
 
        cmd = cmd << 1;
        if (debug_legacy_dish_switch)
-               printk ("%s switch command: 0x%04lx\n",__FUNCTION__, cmd);
+               printk ("%s switch command: 0x%04lx\n",__func__, cmd);
 
        do_gettimeofday (&nexttime);
        if (debug_legacy_dish_switch)
@@ -432,7 +440,7 @@ static int stv0299_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long
        }
        if (debug_legacy_dish_switch) {
                printk ("%s(%d): switch delay (should be 32k followed by all 8k\n",
-                       __FUNCTION__, fe->dvb->num);
+                       __func__, fe->dvb->num);
                for (i = 1; i < 10; i++)
                        printk ("%d: %d\n", i, timeval_usec_diff(tv[i-1] , tv[i]));
        }
@@ -444,11 +452,20 @@ static int stv0299_init (struct dvb_frontend* fe)
 {
        struct stv0299_state* state = fe->demodulator_priv;
        int i;
+       u8 reg;
+       u8 val;
 
        dprintk("stv0299: init chip\n");
 
-       for (i=0; !(state->config->inittab[i] == 0xff && state->config->inittab[i+1] == 0xff); i+=2)
-               stv0299_writeregI(state, state->config->inittab[i], state->config->inittab[i+1]);
+       for (i = 0; ; i += 2)  {
+               reg = state->config->inittab[i];
+               val = state->config->inittab[i+1];
+               if (reg == 0xff && val == 0xff)
+                       break;
+               if (reg == 0x0c && state->config->op0_off)
+                       val &= ~0x10;
+               stv0299_writeregI(state, reg, val);
+       }
 
        return 0;
 }
@@ -460,7 +477,7 @@ static int stv0299_read_status(struct dvb_frontend* fe, fe_status_t* status)
        u8 signal = 0xff - stv0299_readreg (state, 0x18);
        u8 sync = stv0299_readreg (state, 0x1b);
 
-       dprintk ("%s : FE_READ_STATUS : VSTATUS: 0x%02x\n", __FUNCTION__, sync);
+       dprintk ("%s : FE_READ_STATUS : VSTATUS: 0x%02x\n", __func__, sync);
        *status = 0;
 
        if (signal > 10)
@@ -485,8 +502,10 @@ static int stv0299_read_ber(struct dvb_frontend* fe, u32* ber)
 {
        struct stv0299_state* state = fe->demodulator_priv;
 
-       if (state->errmode != STATUS_BER) return 0;
-       *ber = (stv0299_readreg (state, 0x1d) << 8) | stv0299_readreg (state, 0x1e);
+       if (state->errmode != STATUS_BER)
+               return -ENOSYS;
+
+       *ber = stv0299_readreg(state, 0x1e) | (stv0299_readreg(state, 0x1d) << 8);
 
        return 0;
 }
@@ -498,7 +517,7 @@ static int stv0299_read_signal_strength(struct dvb_frontend* fe, u16* strength)
        s32 signal =  0xffff - ((stv0299_readreg (state, 0x18) << 8)
                               | stv0299_readreg (state, 0x19));
 
-       dprintk ("%s : FE_READ_SIGNAL_STRENGTH : AGC2I: 0x%02x%02x, signal=0x%04x\n", __FUNCTION__,
+       dprintk ("%s : FE_READ_SIGNAL_STRENGTH : AGC2I: 0x%02x%02x, signal=0x%04x\n", __func__,
                 stv0299_readreg (state, 0x18),
                 stv0299_readreg (state, 0x19), (int) signal);
 
@@ -524,8 +543,12 @@ static int stv0299_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
 {
        struct stv0299_state* state = fe->demodulator_priv;
 
-       if (state->errmode != STATUS_UCBLOCKS) *ucblocks = 0;
-       else *ucblocks = (stv0299_readreg (state, 0x1d) << 8) | stv0299_readreg (state, 0x1e);
+       if (state->errmode != STATUS_UCBLOCKS)
+               return -ENOSYS;
+
+       state->ucblocks += stv0299_readreg(state, 0x1e);
+       state->ucblocks += (stv0299_readreg(state, 0x1d) << 8);
+       *ucblocks = state->ucblocks;
 
        return 0;
 }
@@ -535,7 +558,9 @@ static int stv0299_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
        struct stv0299_state* state = fe->demodulator_priv;
        int invval = 0;
 
-       dprintk ("%s : FE_SET_FRONTEND\n", __FUNCTION__);
+       dprintk ("%s : FE_SET_FRONTEND\n", __func__);
+       if (state->config->set_ts_params)
+               state->config->set_ts_params(fe, 0);
 
        // set the inversion
        if (p->inversion == INVERSION_OFF) invval = 0;
@@ -547,9 +572,9 @@ static int stv0299_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
        if (state->config->invert) invval = (~invval) & 1;
        stv0299_writeregI(state, 0x0c, (stv0299_readreg(state, 0x0c) & 0xfe) | invval);
 
-       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);
+       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);
        }
 
        stv0299_set_FEC (state, p->u.qpsk.fec_inner);
@@ -642,13 +667,12 @@ struct dvb_frontend* stv0299_attach(const struct stv0299_config* config,
        int id;
 
        /* allocate memory for the internal state */
-       state = kmalloc(sizeof(struct stv0299_state), GFP_KERNEL);
+       state = kzalloc(sizeof(struct stv0299_state), GFP_KERNEL);
        if (state == NULL) goto error;
 
        /* setup the state */
        state->config = config;
        state->i2c = i2c;
-       memcpy(&state->ops, &stv0299_ops, sizeof(struct dvb_frontend_ops));
        state->initialised = 0;
        state->tuner_frequency = 0;
        state->symbol_rate = 0;
@@ -665,7 +689,7 @@ struct dvb_frontend* stv0299_attach(const struct stv0299_config* config,
        if (id != 0xa1 && id != 0x80) goto error;
 
        /* create dvb_frontend */
-       state->frontend.ops = &state->ops;
+       memcpy(&state->frontend.ops, &stv0299_ops, sizeof(struct dvb_frontend_ops));
        state->frontend.demodulator_priv = state;
        return &state->frontend;
 
@@ -696,6 +720,7 @@ static struct dvb_frontend_ops stv0299_ops = {
 
        .init = stv0299_init,
        .sleep = stv0299_sleep,
+       .write = stv0299_write,
        .i2c_gate_ctrl = stv0299_i2c_gate_ctrl,
 
        .set_frontend = stv0299_set_frontend,
@@ -726,5 +751,4 @@ MODULE_AUTHOR("Ralph Metzler, Holger Waechtler, Peter Schildmann, Felix Domke, "
              "Andreas Oberritter, Andrew de Quincey, Kenneth Aafly");
 MODULE_LICENSE("GPL");
 
-EXPORT_SYMBOL(stv0299_writereg);
 EXPORT_SYMBOL(stv0299_attach);