[media] cx24120: Tidy cx24120_init
[firefly-linux-kernel-4.4.55.git] / drivers / media / dvb-frontends / cx24120.c
index 554601512ee42a040ae757d3258a340293b73797..8f195afe4eccb63ec920a77e243c10c43189e9f9 100644 (file)
@@ -143,6 +143,8 @@ struct cx24120_state {
        /* current and next tuning parameters */
        struct cx24120_tuning dcur;
        struct cx24120_tuning dnxt;
+
+       fe_status_t fe_status;
 };
 
 /* Command message to firmware */
@@ -158,7 +160,8 @@ static int cx24120_readreg(struct cx24120_state *state, u8 reg)
        int ret;
        u8 buf = 0;
        struct i2c_msg msg[] = {
-               {       .addr = state->config->i2c_addr,
+               {
+                       .addr = state->config->i2c_addr,
                        .flags = 0,
                        .len = 1,
                        .buf = &reg
@@ -176,8 +179,7 @@ static int cx24120_readreg(struct cx24120_state *state, u8 reg)
                return ret;
        }
 
-       dev_dbg(&state->i2c->dev, "%s: reg=0x%02x; data=0x%02x\n",
-               __func__, reg, buf);
+       dev_dbg(&state->i2c->dev, "reg=0x%02x; data=0x%02x\n", reg, buf);
 
        return buf;
 }
@@ -201,8 +203,7 @@ static int cx24120_writereg(struct cx24120_state *state, u8 reg, u8 data)
                return ret;
        }
 
-       dev_dbg(&state->i2c->dev, "%s: reg=0x%02x; data=0x%02x\n",
-               __func__, reg, data);
+       dev_dbg(&state->i2c->dev, "reg=0x%02x; data=0x%02x\n", reg, data);
 
        return 0;
 }
@@ -243,9 +244,8 @@ static int cx24120_writeregs(struct cx24120_state *state,
                        goto out;
                }
 
-               dev_dbg(&state->i2c->dev,
-                       "%s: reg=0x%02x; data=%*ph\n",
-                       __func__, reg, msg.len, msg.buf + 1);
+               dev_dbg(&state->i2c->dev, "reg=0x%02x; data=%*ph\n",
+                       reg, msg.len - 1, msg.buf + 1);
        }
 
        ret = 0;
@@ -317,11 +317,12 @@ static int cx24120_test_rom(struct cx24120_state *state)
 
 static int cx24120_read_snr(struct dvb_frontend *fe, u16 *snr)
 {
-       struct cx24120_state *state = fe->demodulator_priv;
+       struct dtv_frontend_properties *c = &fe->dtv_property_cache;
 
-       *snr =  (cx24120_readreg(state, CX24120_REG_QUALITY_H) << 8) |
-               (cx24120_readreg(state, CX24120_REG_QUALITY_L));
-       dev_dbg(&state->i2c->dev, "%s: read SNR index = %d\n", __func__, *snr);
+       if (c->cnr.stat[0].scale != FE_SCALE_DECIBEL)
+               *snr = 0;
+       else
+               *snr = div_s64(c->cnr.stat[0].svalue, 100);
 
        return 0;
 }
@@ -334,7 +335,7 @@ static int cx24120_read_ber(struct dvb_frontend *fe, u32 *ber)
                (cx24120_readreg(state, CX24120_REG_BER_HL) << 16)      |
                (cx24120_readreg(state, CX24120_REG_BER_LH) <<  8)      |
                 cx24120_readreg(state, CX24120_REG_BER_LL);
-       dev_dbg(&state->i2c->dev, "%s: read BER index = %d\n", __func__, *ber);
+       dev_dbg(&state->i2c->dev, "read BER index = %d\n", *ber);
 
        return 0;
 }
@@ -352,6 +353,7 @@ static void cx24120_check_cmd(struct cx24120_state *state, u8 id)
        case CMD_DISEQC_MSG2:
        case CMD_SETVOLTAGE:
        case CMD_SETTONE:
+       case CMD_DISEQC_BURST:
                cx24120_msg_mpeg_output_global_config(state, 0);
                /* Old driver would do a msleep(100) here */
        default:
@@ -384,8 +386,7 @@ static int cx24120_message_send(struct cx24120_state *state,
                        return -EREMOTEIO;
                }
        }
-       dev_dbg(&state->i2c->dev, "%s: Successfully send message 0x%02x\n",
-               __func__, cmd->id);
+       dev_dbg(&state->i2c->dev, "sent message 0x%02x\n", cmd->id);
 
        return 0;
 }
@@ -418,30 +419,12 @@ static int cx24120_message_sendrcv(struct cx24120_state *state,
 static int cx24120_read_signal_strength(struct dvb_frontend *fe,
                                        u16 *signal_strength)
 {
-       struct cx24120_state *state = fe->demodulator_priv;
-       struct cx24120_cmd cmd;
-       int ret, sigstr_h, sigstr_l;
-
-       cmd.id = CMD_READ_SNR;
-       cmd.len = 1;
-       cmd.arg[0] = 0x00;
-
-       ret = cx24120_message_send(state, &cmd);
-       if (ret != 0) {
-               err("error reading signal strength\n");
-               return -EREMOTEIO;
-       }
-
-       /* raw */
-       sigstr_h = (cx24120_readreg(state, CX24120_REG_SIGSTR_H) >> 6) << 8;
-       sigstr_l = cx24120_readreg(state, CX24120_REG_SIGSTR_L);
-       dev_dbg(&state->i2c->dev, "%s: Signal strength from firmware= 0x%x\n",
-               __func__, (sigstr_h | sigstr_l));
+       struct dtv_frontend_properties *c = &fe->dtv_property_cache;
 
-       /* cooked */
-       *signal_strength = ((sigstr_h | sigstr_l)  << 5) & 0x0000ffff;
-       dev_dbg(&state->i2c->dev, "%s: Signal strength= 0x%x\n",
-               __func__, *signal_strength);
+       if (c->strength.stat[0].scale != FE_SCALE_RELATIVE)
+               *signal_strength = 0;
+       else
+               *signal_strength = c->strength.stat[0].uvalue;
 
        return 0;
 }
@@ -461,15 +444,14 @@ static int cx24120_msg_mpeg_output_global_config(struct cx24120_state *state,
 
        ret = cx24120_message_send(state, &cmd);
        if (ret != 0) {
-               dev_dbg(&state->i2c->dev,
-                       "%s: Failed to set MPEG output to %s\n",
-                       __func__, enable ? "enabled" : "disabled");
+               dev_dbg(&state->i2c->dev, "failed to %s MPEG output\n",
+                       enable ? "enable" : "disable");
                return ret;
        }
 
        state->mpeg_enabled = enable;
-       dev_dbg(&state->i2c->dev, "%s: MPEG output %s\n",
-               __func__, enable ? "enabled" : "disabled");
+       dev_dbg(&state->i2c->dev, "MPEG output %s\n",
+               enable ? "enabled" : "disabled");
 
        return 0;
 }
@@ -499,7 +481,10 @@ static int cx24120_diseqc_send_burst(struct dvb_frontend *fe,
        struct cx24120_state *state = fe->demodulator_priv;
        struct cx24120_cmd cmd;
 
-       /* Yes, cmd.len is set to zero. The old driver
+       dev_dbg(&state->i2c->dev, "\n");
+
+       /*
+        * Yes, cmd.len is set to zero. The old driver
         * didn't specify any len, but also had a
         * memset 0 before every use of the cmd struct
         * which would have set it to zero.
@@ -508,10 +493,7 @@ static int cx24120_diseqc_send_burst(struct dvb_frontend *fe,
        cmd.id = CMD_DISEQC_BURST;
        cmd.len = 0;
        cmd.arg[0] = 0x00;
-       if (burst)
-               cmd.arg[1] = 0x01;
-
-       dev_dbg(&state->i2c->dev, "%s: burst sent.\n", __func__);
+       cmd.arg[1] = (burst == SEC_MINI_B) ? 0x01 : 0x00;
 
        return cx24120_message_send(state, &cmd);
 }
@@ -521,7 +503,7 @@ static int cx24120_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
        struct cx24120_state *state = fe->demodulator_priv;
        struct cx24120_cmd cmd;
 
-       dev_dbg(&state->i2c->dev, "%s(%d)\n", __func__, tone);
+       dev_dbg(&state->i2c->dev, "(%d)\n", tone);
 
        if ((tone != SEC_TONE_ON) && (tone != SEC_TONE_OFF)) {
                err("Invalid tone=%d\n", tone);
@@ -544,7 +526,7 @@ static int cx24120_set_voltage(struct dvb_frontend *fe,
        struct cx24120_state *state = fe->demodulator_priv;
        struct cx24120_cmd cmd;
 
-       dev_dbg(&state->i2c->dev, "%s(%d)\n", __func__, voltage);
+       dev_dbg(&state->i2c->dev, "(%d)\n", voltage);
 
        cmd.id = CMD_SETVOLTAGE;
        cmd.len = 2;
@@ -561,7 +543,7 @@ static int cx24120_send_diseqc_msg(struct dvb_frontend *fe,
        struct cx24120_cmd cmd;
        int back_count;
 
-       dev_dbg(&state->i2c->dev, "%s()\n", __func__);
+       dev_dbg(&state->i2c->dev, "\n");
 
        cmd.id = CMD_DISEQC_MSG1;
        cmd.len = 11;
@@ -601,9 +583,7 @@ static int cx24120_send_diseqc_msg(struct dvb_frontend *fe,
        back_count = 500;
        do {
                if (!(cx24120_readreg(state, 0x93) & 0x01)) {
-                       dev_dbg(&state->i2c->dev,
-                               "%s: diseqc sequence sent success\n",
-                               __func__);
+                       dev_dbg(&state->i2c->dev, "diseqc sequence sent\n");
                        return 0;
                }
                msleep(20);
@@ -614,6 +594,62 @@ static int cx24120_send_diseqc_msg(struct dvb_frontend *fe,
        return -ETIMEDOUT;
 }
 
+static void cx24120_get_stats(struct cx24120_state *state)
+{
+       struct dvb_frontend *fe = &state->frontend;
+       struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+       struct cx24120_cmd cmd;
+       int ret, cnr;
+       u16 sig;
+
+       dev_dbg(&state->i2c->dev, "\n");
+
+       /* signal strength */
+       if (state->fe_status & FE_HAS_SIGNAL) {
+               cmd.id = CMD_READ_SNR;
+               cmd.len = 1;
+               cmd.arg[0] = 0x00;
+
+               ret = cx24120_message_send(state, &cmd);
+               if (ret != 0) {
+                       err("error reading signal strength\n");
+                       return;
+               }
+
+               /* raw */
+               sig = cx24120_readreg(state, CX24120_REG_SIGSTR_H) >> 6;
+               sig = sig << 8;
+               sig |= cx24120_readreg(state, CX24120_REG_SIGSTR_L);
+               dev_dbg(&state->i2c->dev,
+                       "signal strength from firmware = 0x%x\n", sig);
+
+               /* cooked */
+               sig = -100 * sig + 94324;
+
+               c->strength.stat[0].scale = FE_SCALE_RELATIVE;
+               c->strength.stat[0].uvalue = sig;
+       } else {
+               c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+       }
+
+       /* CNR */
+       if (state->fe_status & FE_HAS_VITERBI) {
+               cnr = cx24120_readreg(state, CX24120_REG_QUALITY_H) << 8;
+               cnr |= cx24120_readreg(state, CX24120_REG_QUALITY_L);
+               dev_dbg(&state->i2c->dev, "read SNR index = %d\n", cnr);
+
+               /* guessed - seems about right */
+               cnr = cnr * 100;
+
+               c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
+               c->cnr.stat[0].svalue = cnr;
+       } else {
+               c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+       }
+
+       /* FIXME: add UCB/BER */
+}
+
 static void cx24120_set_clock_ratios(struct dvb_frontend *fe);
 
 /* Read current tuning status */
@@ -624,8 +660,7 @@ static int cx24120_read_status(struct dvb_frontend *fe, fe_status_t *status)
 
        lock = cx24120_readreg(state, CX24120_REG_STATUS);
 
-       dev_dbg(&state->i2c->dev, "%s() status = 0x%02x\n",
-               __func__, lock);
+       dev_dbg(&state->i2c->dev, "status = 0x%02x\n", lock);
 
        *status = 0;
 
@@ -638,9 +673,14 @@ static int cx24120_read_status(struct dvb_frontend *fe, fe_status_t *status)
        if (lock & CX24120_HAS_LOCK)
                *status |= FE_HAS_LOCK;
 
-       /* TODO: is FE_HAS_SYNC in the right place?
+       /*
+        * TODO: is FE_HAS_SYNC in the right place?
         * Other cx241xx drivers have this slightly
-        * different */
+        * different
+        */
+
+       state->fe_status = *status;
+       cx24120_get_stats(state);
 
        /* Set the clock once tuned in */
        if (state->need_clock_set && *status & FE_HAS_LOCK) {
@@ -659,7 +699,8 @@ static int cx24120_read_status(struct dvb_frontend *fe, fe_status_t *status)
        return 0;
 }
 
-/* FEC & modulation lookup table
+/*
+ * FEC & modulation lookup table
  * Used for decoding the REG_FECMODE register
  * once tuned in.
  */
@@ -704,12 +745,10 @@ static int cx24120_get_fec(struct dvb_frontend *fe)
        int ret;
        int fec;
 
-       dev_dbg(&state->i2c->dev, "%s()\n", __func__);
-
        ret = cx24120_readreg(state, CX24120_REG_FECMODE);
        fec = ret & 0x3f; /* Lower 6 bits */
 
-       dev_dbg(&state->i2c->dev, "%s: Get FEC: %d\n", __func__, fec);
+       dev_dbg(&state->i2c->dev, "raw fec = %d\n", fec);
 
        for (idx = 0; idx < ARRAY_SIZE(modfec_lookup_table); idx++) {
                if (modfec_lookup_table[idx].delsys != state->dcur.delsys)
@@ -721,8 +760,7 @@ static int cx24120_get_fec(struct dvb_frontend *fe)
        }
 
        if (idx >= ARRAY_SIZE(modfec_lookup_table)) {
-               dev_dbg(&state->i2c->dev, "%s: Couldn't find fec!\n",
-                       __func__);
+               dev_dbg(&state->i2c->dev, "couldn't find fec!\n");
                return -EINVAL;
        }
 
@@ -731,22 +769,21 @@ static int cx24120_get_fec(struct dvb_frontend *fe)
        c->fec_inner = modfec_lookup_table[idx].fec;
        c->pilot = (ret & 0x80) ? PILOT_ON : PILOT_OFF;
 
-       dev_dbg(&state->i2c->dev,
-               "%s: mod(%d), fec(%d), pilot(%d)\n",
-               __func__,
+       dev_dbg(&state->i2c->dev, "mod(%d), fec(%d), pilot(%d)\n",
                c->modulation, c->fec_inner, c->pilot);
 
        return 0;
 }
 
-/* Clock ratios lookup table
+/*
+ * Clock ratios lookup table
  *
  * Values obtained from much larger table in old driver
  * which had numerous entries which would never match.
  *
  * There's probably some way of calculating these but I
  * can't determine the pattern
-*/
+ */
 static struct cx24120_clock_ratios_table {
        fe_delivery_system_t delsys;
        fe_pilot_t pilot;
@@ -833,9 +870,7 @@ static void cx24120_set_clock_ratios(struct dvb_frontend *fe)
                return;
        /* in cmd[0]-[5] - result */
 
-       dev_dbg(&state->i2c->dev,
-               "%s: m=%d, n=%d; idx: %d m=%d, n=%d, rate=%d\n",
-               __func__,
+       dev_dbg(&state->i2c->dev, "m=%d, n=%d; idx: %d m=%d, n=%d, rate=%d\n",
                cmd.arg[2] | (cmd.arg[1] << 8) | (cmd.arg[0] << 16),
                cmd.arg[5] | (cmd.arg[4] << 8) | (cmd.arg[3] << 16),
                idx,
@@ -864,7 +899,7 @@ static void cx24120_set_clock_ratios(struct dvb_frontend *fe)
 static int cx24120_set_inversion(struct cx24120_state *state,
                                 fe_spectral_inversion_t inversion)
 {
-       dev_dbg(&state->i2c->dev, "%s(%d)\n", __func__, inversion);
+       dev_dbg(&state->i2c->dev, "(%d)\n", inversion);
 
        switch (inversion) {
        case INVERSION_OFF:
@@ -899,7 +934,7 @@ static struct cx24120_modfec_table {
        fe_code_rate_t fec;
        u8 val;
 } modfec_table[] = {
-/*delsys       mod     fec      val */
+       /*delsys        mod     fec      val */
        { SYS_DVBS,  QPSK,  FEC_1_2, 0x2e },
        { SYS_DVBS,  QPSK,  FEC_2_3, 0x2f },
        { SYS_DVBS,  QPSK,  FEC_3_4, 0x30 },
@@ -919,7 +954,7 @@ static int cx24120_set_fec(struct cx24120_state *state, fe_modulation_t mod,
 {
        int idx;
 
-       dev_dbg(&state->i2c->dev, "%s(0x%02x,0x%02x)\n", __func__, mod, fec);
+       dev_dbg(&state->i2c->dev, "(0x%02x,0x%02x)\n", mod, fec);
 
        state->dnxt.fec = fec;
 
@@ -954,7 +989,7 @@ static int cx24120_set_fec(struct cx24120_state *state, fe_modulation_t mod,
 /* Set pilot */
 static int cx24120_set_pilot(struct cx24120_state *state, fe_pilot_t pilot)
 {
-       dev_dbg(&state->i2c->dev, "%s(%d)\n", __func__, pilot);
+       dev_dbg(&state->i2c->dev, "(%d)\n", pilot);
 
        /* Pilot only valid in DVBS2 */
        if (state->dnxt.delsys != SYS_DVBS2) {
@@ -980,8 +1015,7 @@ static int cx24120_set_pilot(struct cx24120_state *state, fe_pilot_t pilot)
 /* Set symbol rate */
 static int cx24120_set_symbolrate(struct cx24120_state *state, u32 rate)
 {
-       dev_dbg(&state->i2c->dev, "%s(%d)\n",
-               __func__, rate);
+       dev_dbg(&state->i2c->dev, "(%d)\n", rate);
 
        state->dnxt.symbol_rate = rate;
 
@@ -1014,17 +1048,15 @@ static int cx24120_set_frontend(struct dvb_frontend *fe)
 
        switch (c->delivery_system) {
        case SYS_DVBS2:
-               dev_dbg(&state->i2c->dev, "%s() DVB-S2\n",
-                       __func__);
+               dev_dbg(&state->i2c->dev, "DVB-S2\n");
                break;
        case SYS_DVBS:
-               dev_dbg(&state->i2c->dev, "%s() DVB-S\n",
-                       __func__);
+               dev_dbg(&state->i2c->dev, "DVB-S\n");
                break;
        default:
                dev_dbg(&state->i2c->dev,
-                       "%s() Delivery system(%d) not supported\n",
-                       __func__, c->delivery_system);
+                       "delivery system(%d) not supported\n",
+                       c->delivery_system);
                ret = -EINVAL;
                break;
        }
@@ -1054,23 +1086,23 @@ static int cx24120_set_frontend(struct dvb_frontend *fe)
        cx24120_clone_params(fe);
 
        dev_dbg(&state->i2c->dev,
-               "%s: delsys      = %d\n", __func__, state->dcur.delsys);
+               "delsys      = %d\n", state->dcur.delsys);
        dev_dbg(&state->i2c->dev,
-               "%s: modulation  = %d\n", __func__, state->dcur.modulation);
+               "modulation  = %d\n", state->dcur.modulation);
        dev_dbg(&state->i2c->dev,
-               "%s: frequency   = %d\n", __func__, state->dcur.frequency);
+               "frequency   = %d\n", state->dcur.frequency);
        dev_dbg(&state->i2c->dev,
-               "%s: pilot       = %d (val = 0x%02x)\n", __func__,
+               "pilot       = %d (val = 0x%02x)\n",
                state->dcur.pilot, state->dcur.pilot_val);
        dev_dbg(&state->i2c->dev,
-               "%s: symbol_rate = %d (clkdiv/ratediv = 0x%02x/0x%02x)\n",
-                __func__, state->dcur.symbol_rate,
+               "symbol_rate = %d (clkdiv/ratediv = 0x%02x/0x%02x)\n",
+                state->dcur.symbol_rate,
                 state->dcur.clkdiv, state->dcur.ratediv);
        dev_dbg(&state->i2c->dev,
-               "%s: FEC         = %d (mask/val = 0x%02x/0x%02x)\n", __func__,
+               "FEC         = %d (mask/val = 0x%02x/0x%02x)\n",
                state->dcur.fec, state->dcur.fec_mask, state->dcur.fec_val);
        dev_dbg(&state->i2c->dev,
-               "%s: Inversion   = %d (val = 0x%02x)\n", __func__,
+               "Inversion   = %d (val = 0x%02x)\n",
                state->dcur.inversion, state->dcur.inversion_val);
 
        /* Flag that clock needs to be set after tune */
@@ -1110,35 +1142,46 @@ static int cx24120_set_frontend(struct dvb_frontend *fe)
        return 0;
 }
 
-/* Calculate vco from config */
-static u64 cx24120_calculate_vco(struct cx24120_state *state)
+/* Set vco from config */
+static int cx24120_set_vco(struct cx24120_state *state)
 {
-       u32 vco;
-       u64 inv_vco, res, xxyyzz;
+       struct cx24120_cmd cmd;
+       u32 nxtal_khz, vco;
+       u64 inv_vco;
        u32 xtal_khz = state->config->xtal_khz;
 
-       xxyyzz = 0x400000000ULL;
-       vco = xtal_khz * 10 * 4;
-       inv_vco = xxyyzz / vco;
-       res = xxyyzz % vco;
+       nxtal_khz = xtal_khz * 4;
+       vco = nxtal_khz * 10;
+       inv_vco = DIV_ROUND_CLOSEST_ULL(0x400000000ULL, vco);
 
-       if (inv_vco > xtal_khz * 10 * 2)
-               ++inv_vco;
+       dev_dbg(&state->i2c->dev, "xtal=%d, vco=%d, inv_vco=%lld\n",
+               xtal_khz, vco, inv_vco);
 
-       dev_dbg(&state->i2c->dev,
-               "%s: xtal=%d, vco=%d, inv_vco=%lld, res=%lld\n",
-               __func__, xtal_khz, vco, inv_vco, res);
+       cmd.id = CMD_VCO_SET;
+       cmd.len = 12;
+       cmd.arg[0] = (vco >> 16) & 0xff;
+       cmd.arg[1] = (vco >> 8) & 0xff;
+       cmd.arg[2] = vco & 0xff;
+       cmd.arg[3] = (inv_vco >> 8) & 0xff;
+       cmd.arg[4] = (inv_vco) & 0xff;
+       cmd.arg[5] = 0x03;
+       cmd.arg[6] = (nxtal_khz >> 8) & 0xff;
+       cmd.arg[7] = nxtal_khz & 0xff;
+       cmd.arg[8] = 0x06;
+       cmd.arg[9] = 0x03;
+       cmd.arg[10] = (xtal_khz >> 16) & 0xff;
+       cmd.arg[11] = xtal_khz & 0xff;
 
-       return inv_vco;
+       return cx24120_message_send(state, &cmd);
 }
 
 int cx24120_init(struct dvb_frontend *fe)
 {
        const struct firmware *fw;
+       struct dtv_frontend_properties *c = &fe->dtv_property_cache;
        struct cx24120_state *state = fe->demodulator_priv;
        struct cx24120_cmd cmd;
-       u8 ret, ret_EA, reg1;
-       u64 inv_vco;
+       u8 ret, reg, reg1;
        int reset_result;
 
        int i;
@@ -1148,43 +1191,42 @@ int cx24120_init(struct dvb_frontend *fe)
                return 0;
 
        /* ???? */
-       ret = cx24120_writereg(state, 0xea, 0x00);
-       ret = cx24120_test_rom(state);
-       ret = cx24120_readreg(state, 0xfb) & 0xfe;
-       ret = cx24120_writereg(state, 0xfb, ret);
-       ret = cx24120_readreg(state, 0xfc) & 0xfe;
-       ret = cx24120_writereg(state, 0xfc, ret);
-       ret = cx24120_writereg(state, 0xc3, 0x04);
-       ret = cx24120_writereg(state, 0xc4, 0x04);
-       ret = cx24120_writereg(state, 0xce, 0x00);
-       ret = cx24120_writereg(state, 0xcf, 0x00);
-       ret_EA = cx24120_readreg(state, 0xea) & 0xfe;
-       ret = cx24120_writereg(state, 0xea, ret_EA);
-       ret = cx24120_writereg(state, 0xeb, 0x0c);
-       ret = cx24120_writereg(state, 0xec, 0x06);
-       ret = cx24120_writereg(state, 0xed, 0x05);
-       ret = cx24120_writereg(state, 0xee, 0x03);
-       ret = cx24120_writereg(state, 0xef, 0x05);
-       ret = cx24120_writereg(state, 0xf3, 0x03);
-       ret = cx24120_writereg(state, 0xf4, 0x44);
+       cx24120_writereg(state, 0xea, 0x00);
+       cx24120_test_rom(state);
+       reg = cx24120_readreg(state, 0xfb) & 0xfe;
+       cx24120_writereg(state, 0xfb, reg);
+       reg = cx24120_readreg(state, 0xfc) & 0xfe;
+       cx24120_writereg(state, 0xfc, reg);
+       cx24120_writereg(state, 0xc3, 0x04);
+       cx24120_writereg(state, 0xc4, 0x04);
+       cx24120_writereg(state, 0xce, 0x00);
+       cx24120_writereg(state, 0xcf, 0x00);
+       reg = cx24120_readreg(state, 0xea) & 0xfe;
+       cx24120_writereg(state, 0xea, reg);
+       cx24120_writereg(state, 0xeb, 0x0c);
+       cx24120_writereg(state, 0xec, 0x06);
+       cx24120_writereg(state, 0xed, 0x05);
+       cx24120_writereg(state, 0xee, 0x03);
+       cx24120_writereg(state, 0xef, 0x05);
+       cx24120_writereg(state, 0xf3, 0x03);
+       cx24120_writereg(state, 0xf4, 0x44);
 
        for (reg1 = 0xf0; reg1 < 0xf3; reg1++) {
                cx24120_writereg(state, reg1, 0x04);
                cx24120_writereg(state, reg1 - 10, 0x02);
        }
 
-       ret = cx24120_writereg(state, 0xea, (ret_EA | 0x01));
+       cx24120_writereg(state, 0xea, (reg | 0x01));
        for (reg1 = 0xc5; reg1 < 0xcb; reg1 += 2) {
-               ret = cx24120_writereg(state, reg1, 0x00);
-               ret = cx24120_writereg(state, reg1 + 1, 0x00);
+               cx24120_writereg(state, reg1, 0x00);
+               cx24120_writereg(state, reg1 + 1, 0x00);
        }
 
-       ret = cx24120_writereg(state, 0xe4, 0x03);
-       ret = cx24120_writereg(state, 0xeb, 0x0a);
+       cx24120_writereg(state, 0xe4, 0x03);
+       cx24120_writereg(state, 0xeb, 0x0a);
 
-       dev_dbg(&state->i2c->dev,
-               "%s: Requesting firmware (%s) to download...\n",
-               __func__, CX24120_FIRMWARE);
+       dev_dbg(&state->i2c->dev, "requesting firmware (%s) to download...\n",
+               CX24120_FIRMWARE);
 
        ret = state->config->request_firmware(fe, &fw, CX24120_FIRMWARE);
        if (ret) {
@@ -1194,45 +1236,42 @@ int cx24120_init(struct dvb_frontend *fe)
        }
 
        dev_dbg(&state->i2c->dev,
-               "%s: Firmware found, size %d bytes (%02x %02x .. %02x %02x)\n",
-               __func__,
+               "Firmware found, size %d bytes (%02x %02x .. %02x %02x)\n",
                (int)fw->size,                  /* firmware_size in bytes */
                fw->data[0],                    /* fw 1st byte */
                fw->data[1],                    /* fw 2d byte */
                fw->data[fw->size - 2],         /* fw before last byte */
                fw->data[fw->size - 1]);        /* fw last byte */
 
-       ret = cx24120_test_rom(state);
-       ret = cx24120_readreg(state, 0xfb) & 0xfe;
-       ret = cx24120_writereg(state, 0xfb, ret);
-       ret = cx24120_writereg(state, 0xe0, 0x76);
-       ret = cx24120_writereg(state, 0xf7, 0x81);
-       ret = cx24120_writereg(state, 0xf8, 0x00);
-       ret = cx24120_writereg(state, 0xf9, 0x00);
-       ret = cx24120_writeregs(state, 0xfa, fw->data, (fw->size - 1), 0x00);
-       ret = cx24120_writereg(state, 0xf7, 0xc0);
-       ret = cx24120_writereg(state, 0xe0, 0x00);
-       ret = (fw->size - 2) & 0x00ff;
-       ret = cx24120_writereg(state, 0xf8, ret);
-       ret = ((fw->size - 2) >> 8) & 0x00ff;
-       ret = cx24120_writereg(state, 0xf9, ret);
-       ret = cx24120_writereg(state, 0xf7, 0x00);
-       ret = cx24120_writereg(state, 0xdc, 0x00);
-       ret = cx24120_writereg(state, 0xdc, 0x07);
+       cx24120_test_rom(state);
+       reg = cx24120_readreg(state, 0xfb) & 0xfe;
+       cx24120_writereg(state, 0xfb, reg);
+       cx24120_writereg(state, 0xe0, 0x76);
+       cx24120_writereg(state, 0xf7, 0x81);
+       cx24120_writereg(state, 0xf8, 0x00);
+       cx24120_writereg(state, 0xf9, 0x00);
+       cx24120_writeregs(state, 0xfa, fw->data, (fw->size - 1), 0x00);
+       cx24120_writereg(state, 0xf7, 0xc0);
+       cx24120_writereg(state, 0xe0, 0x00);
+       reg = (fw->size - 2) & 0x00ff;
+       cx24120_writereg(state, 0xf8, reg);
+       reg = ((fw->size - 2) >> 8) & 0x00ff;
+       cx24120_writereg(state, 0xf9, reg);
+       cx24120_writereg(state, 0xf7, 0x00);
+       cx24120_writereg(state, 0xdc, 0x00);
+       cx24120_writereg(state, 0xdc, 0x07);
        msleep(500);
 
        /* Check final byte matches final byte of firmware */
-       ret = cx24120_readreg(state, 0xe1);
-       if (ret == fw->data[fw->size - 1]) {
-               dev_dbg(&state->i2c->dev,
-                       "%s: Firmware uploaded successfully\n",
-                       __func__);
+       reg = cx24120_readreg(state, 0xe1);
+       if (reg == fw->data[fw->size - 1]) {
+               dev_dbg(&state->i2c->dev, "Firmware uploaded successfully\n");
                reset_result = 0;
        } else {
                err("Firmware upload failed. Last byte returned=0x%x\n", ret);
                reset_result = -EREMOTEIO;
        }
-       ret = cx24120_writereg(state, 0xdc, 0x00);
+       cx24120_writereg(state, 0xdc, 0x00);
        release_firmware(fw);
        if (reset_result != 0)
                return reset_result;
@@ -1250,26 +1289,10 @@ int cx24120_init(struct dvb_frontend *fe)
        }
 
        /* Set VCO */
-       inv_vco = cx24120_calculate_vco(state);
-
-       cmd.id = CMD_VCO_SET;
-       cmd.len = 12;
-       cmd.arg[0] = 0x06;
-       cmd.arg[1] = 0x2b;
-       cmd.arg[2] = 0xd8;
-       cmd.arg[3] = (inv_vco >> 8) & 0xff;
-       cmd.arg[4] = (inv_vco) & 0xff;
-       cmd.arg[5] = 0x03;
-       cmd.arg[6] = 0x9d;
-       cmd.arg[7] = 0xfc;
-       cmd.arg[8] = 0x06;
-       cmd.arg[9] = 0x03;
-       cmd.arg[10] = 0x27;
-       cmd.arg[11] = 0x7f;
-
-       if (cx24120_message_send(state, &cmd)) {
+       ret = cx24120_set_vco(state);
+       if (ret != 0) {
                err("Error set VCO! :(\n");
-               return -EREMOTEIO;
+               return ret;
        }
 
        /* set bandwidth */
@@ -1293,19 +1316,17 @@ int cx24120_init(struct dvb_frontend *fe)
                return -EREMOTEIO;
        }
 
-       ret = cx24120_readreg(state, 0xba);
-       if (ret > 3) {
-               dev_dbg(&state->i2c->dev, "%s: Reset-readreg 0xba: %x\n",
-                       __func__, ret);
+       reg = cx24120_readreg(state, 0xba);
+       if (reg > 3) {
+               dev_dbg(&state->i2c->dev, "Reset-readreg 0xba: %x\n", ret);
                err("Error initialising tuner!\n");
                return -EREMOTEIO;
        }
 
-       dev_dbg(&state->i2c->dev, "%s: Tuner initialised correctly.\n",
-               __func__);
+       dev_dbg(&state->i2c->dev, "Tuner initialised correctly.\n");
 
        /* Initialise mpeg outputs */
-       ret = cx24120_writereg(state, 0xeb, 0x0a);
+       cx24120_writereg(state, 0xeb, 0x0a);
        if (cx24120_msg_mpeg_output_global_config(state, 0) ||
            cx24120_msg_mpeg_output_config(state, 0) ||
            cx24120_msg_mpeg_output_config(state, 1) ||
@@ -1337,6 +1358,12 @@ int cx24120_init(struct dvb_frontend *fe)
        }
        info("FW version %i.%i.%i.%i\n", vers[0], vers[1], vers[2], vers[3]);
 
+       /* init stats here in order signal app which stats are supported */
+       c->strength.len = 1;
+       c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+       c->cnr.len = 1;
+       c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+
        state->cold_init = 1;
        return 0;
 }
@@ -1348,7 +1375,7 @@ static int cx24120_tune(struct dvb_frontend *fe, bool re_tune,
        struct cx24120_state *state = fe->demodulator_priv;
        int ret;
 
-       dev_dbg(&state->i2c->dev, "%s(%d)\n", __func__, re_tune);
+       dev_dbg(&state->i2c->dev, "(%d)\n", re_tune);
 
        /* TODO: Do we need to set delay? */
 
@@ -1376,13 +1403,11 @@ static int cx24120_get_frontend(struct dvb_frontend *fe)
        struct dtv_frontend_properties *c = &fe->dtv_property_cache;
        struct cx24120_state *state = fe->demodulator_priv;
        u8 freq1, freq2, freq3;
-       fe_status_t status;
 
-       dev_dbg(&state->i2c->dev, "%s()", __func__);
+       dev_dbg(&state->i2c->dev, "\n");
 
        /* don't return empty data if we're not tuned in */
-       cx24120_read_status(fe, &status);
-       if ((status & FE_HAS_LOCK) == 0)
+       if ((state->fe_status & FE_HAS_LOCK) == 0)
                return 0;
 
        /* Get frequency */
@@ -1390,8 +1415,7 @@ static int cx24120_get_frontend(struct dvb_frontend *fe)
        freq2 = cx24120_readreg(state, CX24120_REG_FREQ2);
        freq3 = cx24120_readreg(state, CX24120_REG_FREQ3);
        c->frequency = (freq3 << 16) | (freq2 << 8) | freq1;
-       dev_dbg(&state->i2c->dev, "%s frequency = %d\n", __func__,
-               c->frequency);
+       dev_dbg(&state->i2c->dev, "frequency = %d\n", c->frequency);
 
        /* Get modulation, fec, pilot */
        cx24120_get_fec(fe);
@@ -1403,7 +1427,7 @@ static void cx24120_release(struct dvb_frontend *fe)
 {
        struct cx24120_state *state = fe->demodulator_priv;
 
-       dev_dbg(&state->i2c->dev, "%s: Clear state structure\n", __func__);
+       dev_dbg(&state->i2c->dev, "Clear state structure\n");
        kfree(state);
 }
 
@@ -1414,7 +1438,7 @@ static int cx24120_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
        *ucblocks = (cx24120_readreg(state, CX24120_REG_UCB_H) << 8) |
                     cx24120_readreg(state, CX24120_REG_UCB_L);
 
-       dev_dbg(&state->i2c->dev, "%s: Blocks = %d\n", __func__, *ucblocks);
+       dev_dbg(&state->i2c->dev, "ucblocks = %d\n", *ucblocks);
        return 0;
 }