[media] cx24120: More coding style fixes
[firefly-linux-kernel-4.4.55.git] / drivers / media / dvb-frontends / cx24120.c
index 57634c618d63d6e3a9beeb2f7ea4deb9d0921ec1..2876b8aae90a5585e05b593654a164d090933106 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
@@ -420,28 +423,14 @@ 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;
-       }
+       struct dtv_frontend_properties *c = &fe->dtv_property_cache;
 
-       /* 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));
+       if (c->strength.stat[0].scale != FE_SCALE_RELATIVE)
+               *signal_strength = 0;
+       else
+               *signal_strength = c->strength.stat[0].uvalue;
 
-       /* cooked */
-       *signal_strength = ((sigstr_h | sigstr_l)  << 5) & 0x0000ffff;
-       dev_dbg(&state->i2c->dev, "%s: Signal strength= 0x%x\n",
+       dev_dbg(&state->i2c->dev, "%s: Signal strength from cache: 0x%x\n",
                __func__, *signal_strength);
 
        return 0;
@@ -500,7 +489,8 @@ 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
+       /*
+        * 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.
@@ -615,23 +605,41 @@ static int cx24120_send_diseqc_msg(struct dvb_frontend *fe,
        return -ETIMEDOUT;
 }
 
-static void cx24120_get_stats(struct cx24120_state *state, fe_status_t status)
+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;
-       u16 u16tmp;
+       u16 sig;
 
        dev_dbg(&state->i2c->dev, "%s()\n", __func__);
 
        /* signal strength */
-       if (status & FE_HAS_SIGNAL) {
-               ret = cx24120_read_signal_strength(fe, &u16tmp);
-               if (ret != 0)
+       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,
+                       "%s: Signal strength from firmware= 0x%x\n",
+                       __func__, sig);
+
+               /* cooked */
+               sig = -100 * sig + 94324;
 
                c->strength.stat[0].scale = FE_SCALE_RELATIVE;
-               c->strength.stat[0].uvalue = u16tmp;
+               c->strength.stat[0].uvalue = sig;
        } else {
                c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
        }
@@ -665,11 +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
+        */
 
-       cx24120_get_stats(state, *status);
+       state->fe_status = *status;
+       cx24120_get_stats(state);
 
        /* Set the clock once tuned in */
        if (state->need_clock_set && *status & FE_HAS_LOCK) {
@@ -688,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.
  */
@@ -768,14 +780,15 @@ static int cx24120_get_fec(struct dvb_frontend *fe)
        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;
@@ -928,7 +941,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 },
@@ -1405,13 +1418,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__);
 
        /* 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 */