V4L/DVB: cx22702: Some things never change
[cascardo/linux.git] / drivers / media / dvb / frontends / cx22702.c
index 00b5c7e..f9a7aae 100644 (file)
@@ -54,7 +54,7 @@ MODULE_PARM_DESC(debug, "Enable verbose debug messages");
 #define dprintk        if (debug) printk
 
 /* Register values to initialise the demod */
-static u8 init_tab[] = {
+static const u8 init_tab[] = {
        0x00, 0x00, /* Stop aquisition */
        0x0B, 0x06,
        0x09, 0x01,
@@ -92,52 +92,56 @@ static int cx22702_writereg(struct cx22702_state *state, u8 reg, u8 data)
 
        ret = i2c_transfer(state->i2c, &msg, 1);
 
-       if (ret != 1)
+       if (unlikely(ret != 1)) {
                printk(KERN_ERR
                        "%s: error (reg == 0x%02x, val == 0x%02x, ret == %i)\n",
                        __func__, reg, data, ret);
+               return -1;
+       }
 
-       return (ret != 1) ? -1 : 0;
+       return 0;
 }
 
 static u8 cx22702_readreg(struct cx22702_state *state, u8 reg)
 {
        int ret;
-       u8 b0[] = { reg };
-       u8 b1[] = { 0 };
+       u8 data;
 
        struct i2c_msg msg[] = {
                { .addr = state->config->demod_address, .flags = 0,
-                       .buf = b0, .len = 1 },
+                       .buf = &reg, .len = 1 },
                { .addr = state->config->demod_address, .flags = I2C_M_RD,
-                       .buf = b1, .len = 1 } };
+                       .buf = &data, .len = 1 } };
 
        ret = i2c_transfer(state->i2c, msg, 2);
 
-       if (ret != 2)
-               printk(KERN_ERR "%s: readreg error (ret == %i)\n",
-                       __func__, ret);
+       if (unlikely(ret != 2)) {
+               printk(KERN_ERR "%s: error (reg == 0x%02x, ret == %i)\n",
+                       __func__, reg, ret);
+               return 0;
+       }
 
-       return b1[0];
+       return data;
 }
 
 static int cx22702_set_inversion(struct cx22702_state *state, int inversion)
 {
        u8 val;
 
+       val = cx22702_readreg(state, 0x0C);
        switch (inversion) {
        case INVERSION_AUTO:
                return -EOPNOTSUPP;
        case INVERSION_ON:
-               val = cx22702_readreg(state, 0x0C);
-               return cx22702_writereg(state, 0x0C, val | 0x01);
+               val |= 0x01;
+               break;
        case INVERSION_OFF:
-               val = cx22702_readreg(state, 0x0C);
-               return cx22702_writereg(state, 0x0C, val & 0xfe);
+               val &= 0xfe;
+               break;
        default:
                return -EINVAL;
        }
-
+       return cx22702_writereg(state, 0x0C, val);
 }
 
 /* Retrieve the demod settings */
@@ -244,13 +248,15 @@ static int cx22702_get_tps(struct cx22702_state *state,
 static int cx22702_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
 {
        struct cx22702_state *state = fe->demodulator_priv;
+       u8 val;
+
        dprintk("%s(%d)\n", __func__, enable);
+       val = cx22702_readreg(state, 0x0D);
        if (enable)
-               return cx22702_writereg(state, 0x0D,
-                       cx22702_readreg(state, 0x0D) & 0xfe);
+               val &= 0xfe;
        else
-               return cx22702_writereg(state, 0x0D,
-                       cx22702_readreg(state, 0x0D) | 1);
+               val |= 0x01;
+       return cx22702_writereg(state, 0x0D, val);
 }
 
 /* Talk to the demod, set the FEC, GUARD, QAM settings etc */
@@ -270,23 +276,21 @@ static int cx22702_set_tps(struct dvb_frontend *fe,
        cx22702_set_inversion(state, p->inversion);
 
        /* set bandwidth */
+       val = cx22702_readreg(state, 0x0C) & 0xcf;
        switch (p->u.ofdm.bandwidth) {
        case BANDWIDTH_6_MHZ:
-               cx22702_writereg(state, 0x0C,
-                       (cx22702_readreg(state, 0x0C) & 0xcf) | 0x20);
+               val |= 0x20;
                break;
        case BANDWIDTH_7_MHZ:
-               cx22702_writereg(state, 0x0C,
-                       (cx22702_readreg(state, 0x0C) & 0xcf) | 0x10);
+               val |= 0x10;
                break;
        case BANDWIDTH_8_MHZ:
-               cx22702_writereg(state, 0x0C,
-                       cx22702_readreg(state, 0x0C) & 0xcf);
                break;
        default:
                dprintk("%s: invalid bandwidth\n", __func__);
                return -EINVAL;
        }
+       cx22702_writereg(state, 0x0C, val);
 
        p->u.ofdm.code_rate_LP = FEC_AUTO; /* temp hack as manual not working */
 
@@ -505,7 +509,7 @@ static int cx22702_read_signal_strength(struct dvb_frontend *fe,
 {
        struct cx22702_state *state = fe->demodulator_priv;
 
-       u16 rs_ber = 0;
+       u16 rs_ber;
        rs_ber = cx22702_readreg(state, 0x23);
        *signal_strength = (rs_ber << 8) | rs_ber;
 
@@ -516,7 +520,7 @@ static int cx22702_read_snr(struct dvb_frontend *fe, u16 *snr)
 {
        struct cx22702_state *state = fe->demodulator_priv;
 
-       u16 rs_ber = 0;
+       u16 rs_ber;
        if (cx22702_readreg(state, 0xE4) & 0x02) {
                /* Realtime statistics */
                rs_ber = (cx22702_readreg(state, 0xDE) & 0x7F) << 7
@@ -572,7 +576,7 @@ static void cx22702_release(struct dvb_frontend *fe)
        kfree(state);
 }
 
-static struct dvb_frontend_ops cx22702_ops;
+static const struct dvb_frontend_ops cx22702_ops;
 
 struct dvb_frontend *cx22702_attach(const struct cx22702_config *config,
        struct i2c_adapter *i2c)
@@ -587,7 +591,6 @@ struct dvb_frontend *cx22702_attach(const struct cx22702_config *config,
        /* setup the state */
        state->config = config;
        state->i2c = i2c;
-       state->prevUCBlocks = 0;
 
        /* check if the demod is there */
        if (cx22702_readreg(state, 0x1f) != 0x3)
@@ -605,7 +608,7 @@ error:
 }
 EXPORT_SYMBOL(cx22702_attach);
 
-static struct dvb_frontend_ops cx22702_ops = {
+static const struct dvb_frontend_ops cx22702_ops = {
 
        .info = {
                .name                   = "Conexant CX22702 DVB-T",