Merge gregkh@master.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-rc-fixes-2.6
[pandora-kernel.git] / drivers / media / dvb / bt8xx / dst.c
index 4a70d2a..06ac899 100644 (file)
@@ -393,7 +393,7 @@ static int dst_set_bandwidth(struct dst_state *state, fe_bandwidth_t bandwidth)
        state->bandwidth = bandwidth;
 
        if (state->dst_type != DST_TYPE_IS_TERR)
-               return 0;
+               return -EOPNOTSUPP;
 
        switch (bandwidth) {
        case BANDWIDTH_6_MHZ:
@@ -462,37 +462,49 @@ static int dst_set_symbolrate(struct dst_state *state, u32 srate)
 
        state->symbol_rate = srate;
        if (state->dst_type == DST_TYPE_IS_TERR) {
-               return 0;
+               return -EOPNOTSUPP;
        }
        dprintk(verbose, DST_INFO, 1, "set symrate %u", srate);
        srate /= 1000;
-       if (state->type_flags & DST_TYPE_HAS_SYMDIV) {
-               sval = srate;
-               sval <<= 20;
-               do_div(sval, 88000);
-               symcalc = (u32) sval;
-               dprintk(verbose, DST_INFO, 1, "set symcalc %u", symcalc);
-               state->tx_tuna[5] = (u8) (symcalc >> 12);
-               state->tx_tuna[6] = (u8) (symcalc >> 4);
-               state->tx_tuna[7] = (u8) (symcalc << 4);
-       } else {
-               state->tx_tuna[5] = (u8) (srate >> 16) & 0x7f;
-               state->tx_tuna[6] = (u8) (srate >> 8);
-               state->tx_tuna[7] = (u8) srate;
-       }
-       state->tx_tuna[8] &= ~0x20;
-       if (state->type_flags & DST_TYPE_HAS_OBS_REGS) {
-               if (srate > 8000)
-                       state->tx_tuna[8] |= 0x20;
+       if (state->dst_type == DST_TYPE_IS_SAT) {
+               if (state->type_flags & DST_TYPE_HAS_SYMDIV) {
+                       sval = srate;
+                       sval <<= 20;
+                       do_div(sval, 88000);
+                       symcalc = (u32) sval;
+                       dprintk(verbose, DST_INFO, 1, "set symcalc %u", symcalc);
+                       state->tx_tuna[5] = (u8) (symcalc >> 12);
+                       state->tx_tuna[6] = (u8) (symcalc >> 4);
+                       state->tx_tuna[7] = (u8) (symcalc << 4);
+               } else {
+                       state->tx_tuna[5] = (u8) (srate >> 16) & 0x7f;
+                       state->tx_tuna[6] = (u8) (srate >> 8);
+                       state->tx_tuna[7] = (u8) srate;
+               }
+               state->tx_tuna[8] &= ~0x20;
+               if (state->type_flags & DST_TYPE_HAS_OBS_REGS) {
+                       if (srate > 8000)
+                               state->tx_tuna[8] |= 0x20;
+               }
+       } else if (state->dst_type == DST_TYPE_IS_CABLE) {
+               dprintk(verbose, DST_DEBUG, 1, "%s", state->fw_name);
+               if (!strncmp(state->fw_name, "DCTNEW", 6)) {
+                       state->tx_tuna[5] = (u8) (srate >> 8);
+                       state->tx_tuna[6] = (u8) srate;
+                       state->tx_tuna[7] = 0x00;
+               } else if (!strncmp(state->fw_name, "DCT-CI", 6)) {
+                       state->tx_tuna[5] = 0x00;
+                       state->tx_tuna[6] = (u8) (srate >> 8);
+                       state->tx_tuna[7] = (u8) srate;
+               }
        }
        return 0;
 }
 
-
 static int dst_set_modulation(struct dst_state *state, fe_modulation_t modulation)
 {
        if (state->dst_type != DST_TYPE_IS_CABLE)
-               return 0;
+               return -EOPNOTSUPP;
 
        state->modulation = modulation;
        switch (modulation) {
@@ -509,7 +521,10 @@ static int dst_set_modulation(struct dst_state *state, fe_modulation_t modulatio
                state->tx_tuna[8] = 0x80;
                break;
        case QAM_256:
-               state->tx_tuna[8] = 0x00;
+               if (!strncmp(state->fw_name, "DCTNEW", 6))
+                       state->tx_tuna[8] = 0xff;
+               else if (!strncmp(state->fw_name, "DCT-CI", 6))
+                       state->tx_tuna[8] = 0x00;
                break;
        case QPSK:
        case QAM_AUTO:
@@ -547,12 +562,14 @@ static void dst_type_flags_print(struct dst_state *state)
        u32 type_flags = state->type_flags;
 
        dprintk(verbose, DST_ERROR, 0, "DST type flags :");
-       if (type_flags & DST_TYPE_HAS_NEWTUNE)
-               dprintk(verbose, DST_ERROR, 0, " 0x%x newtuner", DST_TYPE_HAS_NEWTUNE);
+       if (type_flags & DST_TYPE_HAS_TS188)
+               dprintk(verbose, DST_ERROR, 0, " 0x%x newtuner", DST_TYPE_HAS_TS188);
        if (type_flags & DST_TYPE_HAS_NEWTUNE_2)
                dprintk(verbose, DST_ERROR, 0, " 0x%x newtuner 2", DST_TYPE_HAS_NEWTUNE_2);
        if (type_flags & DST_TYPE_HAS_TS204)
                dprintk(verbose, DST_ERROR, 0, " 0x%x ts204", DST_TYPE_HAS_TS204);
+       if (type_flags & DST_TYPE_HAS_VLF)
+               dprintk(verbose, DST_ERROR, 0, " 0x%x VLF", DST_TYPE_HAS_VLF);
        if (type_flags & DST_TYPE_HAS_SYMDIV)
                dprintk(verbose, DST_ERROR, 0, " 0x%x symdiv", DST_TYPE_HAS_SYMDIV);
        if (type_flags & DST_TYPE_HAS_FW_1)
@@ -644,6 +661,13 @@ struct tuner_types tuner_list[] = {
                .fw_name    = "DSTMCI"
        },
 
+       {
+               .tuner_type = TUNER_TYPE_UNKNOWN,
+               .tuner_name = "UNKNOWN",
+               .board_name = "VP2021",
+               .fw_name    = "DCTNEW"
+       },
+
        {
                .tuner_type = TUNER_TYPE_UNKNOWN,
                .tuner_name = "UNKNOWN",
@@ -766,7 +790,7 @@ static struct dst_types dst_tlist[] = {
                .device_id = "DST-030",
                .offset =  0,
                .dst_type = DST_TYPE_IS_SAT,
-               .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
+               .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_TS188 | DST_TYPE_HAS_FW_1,
                .dst_feature = 0,
                .tuner_type = 0
        },      /*      obsolete        */
@@ -803,7 +827,7 @@ static struct dst_types dst_tlist[] = {
                .device_id = "DSTMCI",
                .offset = 1,
                .dst_type = DST_TYPE_IS_SAT,
-               .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD | DST_TYPE_HAS_INC_COUNT,
+               .type_flags = DST_TYPE_HAS_TS188 | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD | DST_TYPE_HAS_INC_COUNT | DST_TYPE_HAS_VLF,
                .dst_feature = DST_TYPE_HAS_CA | DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4
                                                        | DST_TYPE_HAS_MOTO | DST_TYPE_HAS_MAC,
                .tuner_type = TUNER_TYPE_MULTI
@@ -813,7 +837,7 @@ static struct dst_types dst_tlist[] = {
                .device_id = "DSTFCI",
                .offset = 1,
                .dst_type = DST_TYPE_IS_SAT,
-               .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
+               .type_flags = DST_TYPE_HAS_TS188 | DST_TYPE_HAS_FW_1,
                .dst_feature = 0,
                .tuner_type = 0
        },      /* unknown to vendor    */
@@ -822,7 +846,7 @@ static struct dst_types dst_tlist[] = {
                .device_id = "DCT-CI",
                .offset = 1,
                .dst_type = DST_TYPE_IS_CABLE,
-               .type_flags = DST_TYPE_HAS_MULTI_FE | DST_TYPE_HAS_FW_1 | DST_TYPE_HAS_FW_2,
+               .type_flags = DST_TYPE_HAS_MULTI_FE | DST_TYPE_HAS_FW_1 | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_VLF,
                .dst_feature = DST_TYPE_HAS_CA,
                .tuner_type = 0
        },
@@ -831,7 +855,7 @@ static struct dst_types dst_tlist[] = {
                .device_id = "DCTNEW",
                .offset = 1,
                .dst_type = DST_TYPE_IS_CABLE,
-               .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_3 | DST_TYPE_HAS_FW_BUILD,
+               .type_flags = DST_TYPE_HAS_TS188 | DST_TYPE_HAS_FW_3 | DST_TYPE_HAS_FW_BUILD | DST_TYPE_HAS_MULTI_FE,
                .dst_feature = 0,
                .tuner_type = 0
        },
@@ -840,7 +864,7 @@ static struct dst_types dst_tlist[] = {
                .device_id = "DTT-CI",
                .offset = 1,
                .dst_type = DST_TYPE_IS_TERR,
-               .type_flags = DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_MULTI_FE,
+               .type_flags = DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_MULTI_FE | DST_TYPE_HAS_VLF,
                .dst_feature = DST_TYPE_HAS_CA,
                .tuner_type = 0
        },
@@ -1025,12 +1049,12 @@ static int dst_get_tuner_info(struct dst_state *state)
        if (state->type_flags & DST_TYPE_HAS_MULTI_FE) {
                if (dst_command(state, get_tuner_1, 8) < 0) {
                        dprintk(verbose, DST_INFO, 1, "Cmd=[0x13], Unsupported");
-                       return -1;
+                       goto force;
                }
        } else {
                if (dst_command(state, get_tuner_2, 8) < 0) {
                        dprintk(verbose, DST_INFO, 1, "Cmd=[0xb], Unsupported");
-                       return -1;
+                       goto force;
                }
        }
        memset(&state->board_info, '\0', 8);
@@ -1040,7 +1064,7 @@ static int dst_get_tuner_info(struct dst_state *state)
        }
        if (state->board_info[0] == 0xbc) {
                if (state->type_flags != DST_TYPE_IS_ATSC)
-                       state->type_flags |= DST_TYPE_HAS_NEWTUNE;
+                       state->type_flags |= DST_TYPE_HAS_TS188;
                else
                        state->type_flags |= DST_TYPE_HAS_NEWTUNE_2;
 
@@ -1051,6 +1075,13 @@ static int dst_get_tuner_info(struct dst_state *state)
        }
 
        return 0;
+force:
+       if (!strncmp(state->fw_name, "DCT-CI", 6)) {
+               state->type_flags |= DST_TYPE_HAS_TS204;
+               dprintk(verbose, DST_ERROR, 1, "Forcing [%s] to TS188", state->fw_name);
+       }
+
+       return -1;
 }
 
 static int dst_get_device_id(struct dst_state *state)
@@ -1099,14 +1130,20 @@ static int dst_get_device_id(struct dst_state *state)
                        /*      Card capabilities       */
                        state->dst_hw_cap = p_dst_type->dst_feature;
                        dprintk(verbose, DST_ERROR, 1, "Recognise [%s]", p_dst_type->device_id);
-
-//                     if (p_dst_type->tuner_type != TUNER_TYPE_MULTI) {
+                       strncpy(&state->fw_name[0], p_dst_type->device_id, 6);
                        /*      Multiple tuners         */
                        if (p_dst_type->tuner_type & TUNER_TYPE_MULTI) {
-                               /*      STV0299 check   */
-                               if (dst_check_stv0299(state) < 0)
-                                       dprintk(verbose, DST_ERROR, 1, "Unsupported");
-                               /*      MB86A15 check   */
+                               switch (use_dst_type) {
+                               case DST_TYPE_IS_SAT:
+                                       /*      STV0299 check   */
+                                       if (dst_check_stv0299(state) < 0) {
+                                               dprintk(verbose, DST_ERROR, 1, "Unsupported");
+                                               state->tuner_type = TUNER_TYPE_MB86A15;
+                                       }
+                                       break;
+                               default:
+                                       break;
+                               }
                                if (dst_check_mb86a15(state) < 0)
                                        dprintk(verbose, DST_ERROR, 1, "Unsupported");
                        /*      Single tuner            */
@@ -1161,7 +1198,6 @@ static int dst_probe(struct dst_state *state)
        }
        if (dst_get_mac(state) < 0) {
                dprintk(verbose, DST_INFO, 1, "MAC: Unsupported command");
-               return 0;
        }
        if ((state->type_flags & DST_TYPE_HAS_MULTI_FE) || (state->type_flags & DST_TYPE_HAS_FW_BUILD)) {
                if (dst_get_tuner_info(state) < 0)
@@ -1198,7 +1234,7 @@ int dst_command(struct dst_state *state, u8 *data, u8 len)
                goto error;
        }
        if (write_dst(state, data, len)) {
-               dprintk(verbose, DST_INFO, 1, "Tring to recover.. ");
+               dprintk(verbose, DST_INFO, 1, "Trying to recover.. ");
                if ((dst_error_recovery(state)) < 0) {
                        dprintk(verbose, DST_ERROR, 1, "Recovery Failed.");
                        goto error;
@@ -1292,15 +1328,13 @@ static int dst_tone_power_cmd(struct dst_state *state)
 {
        u8 paket[8] = { 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 };
 
-       if (state->dst_type == DST_TYPE_IS_TERR)
-               return 0;
+       if (state->dst_type != DST_TYPE_IS_SAT)
+               return -EOPNOTSUPP;
        paket[4] = state->tx_tuna[4];
        paket[2] = state->tx_tuna[2];
        paket[3] = state->tx_tuna[3];
        paket[7] = dst_check_sum (paket, 7);
-       dst_command(state, paket, 8);
-
-       return 0;
+       return dst_command(state, paket, 8);
 }
 
 static int dst_get_tuna(struct dst_state *state)
@@ -1312,8 +1346,9 @@ static int dst_get_tuna(struct dst_state *state)
        state->diseq_flags &= ~(HAS_LOCK);
        if (!dst_wait_dst_ready(state, NO_DELAY))
                return -EIO;
-       if (state->type_flags & DST_TYPE_HAS_NEWTUNE)
-               /* how to get variable length reply ???? */
+       if ((state->type_flags & DST_TYPE_HAS_VLF) &&
+               !(state->dst_type == DST_TYPE_IS_ATSC))
+
                retval = read_dst(state, state->rx_tuna, 10);
        else
                retval = read_dst(state, &state->rx_tuna[2], FIXED_COMM);
@@ -1321,7 +1356,10 @@ static int dst_get_tuna(struct dst_state *state)
                dprintk(verbose, DST_DEBUG, 1, "read not successful");
                return retval;
        }
-       if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
+       if ((state->type_flags & DST_TYPE_HAS_VLF) &&
+               !(state->dst_type == DST_TYPE_IS_CABLE) &&
+               !(state->dst_type == DST_TYPE_IS_ATSC)) {
+
                if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[0], 9)) {
                        dprintk(verbose, DST_INFO, 1, "checksum failure ? ");
                        return -EIO;
@@ -1367,7 +1405,10 @@ static int dst_write_tuna(struct dvb_frontend *fe)
                dprintk(verbose, DST_DEBUG, 1, "DST Communication initialization failed.");
                goto error;
        }
-       if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
+//     if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
+       if ((state->type_flags & DST_TYPE_HAS_VLF) &&
+               (!(state->dst_type == DST_TYPE_IS_ATSC))) {
+
                state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[0], 9);
                retval = write_dst(state, &state->tx_tuna[0], 10);
        } else {
@@ -1422,23 +1463,25 @@ static int dst_set_diseqc(struct dvb_frontend *fe, struct dvb_diseqc_master_cmd
        u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec };
 
        if (state->dst_type != DST_TYPE_IS_SAT)
-               return 0;
-       if (cmd->msg_len == 0 || cmd->msg_len > 4)
+               return -EOPNOTSUPP;
+       if (cmd->msg_len > 0 && cmd->msg_len < 5)
+               memcpy(&paket[3], cmd->msg, cmd->msg_len);
+       else if (cmd->msg_len == 5 && state->dst_hw_cap & DST_TYPE_HAS_DISEQC5)
+               memcpy(&paket[2], cmd->msg, cmd->msg_len);
+       else
                return -EINVAL;
-       memcpy(&paket[3], cmd->msg, cmd->msg_len);
        paket[7] = dst_check_sum(&paket[0], 7);
-       dst_command(state, paket, 8);
-       return 0;
+       return dst_command(state, paket, 8);
 }
 
 static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
 {
-       int need_cmd;
+       int need_cmd, retval = 0;
        struct dst_state *state = fe->demodulator_priv;
 
        state->voltage = voltage;
        if (state->dst_type != DST_TYPE_IS_SAT)
-               return 0;
+               return -EOPNOTSUPP;
 
        need_cmd = 0;
 
@@ -1460,9 +1503,9 @@ static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
        }
 
        if (need_cmd)
-               dst_tone_power_cmd(state);
+               retval = dst_tone_power_cmd(state);
 
-       return 0;
+       return retval;
 }
 
 static int dst_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
@@ -1471,7 +1514,7 @@ static int dst_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
 
        state->tone = tone;
        if (state->dst_type != DST_TYPE_IS_SAT)
-               return 0;
+               return -EOPNOTSUPP;
 
        switch (tone) {
        case SEC_TONE_OFF:
@@ -1487,9 +1530,7 @@ static int dst_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
        default:
                return -EINVAL;
        }
-       dst_tone_power_cmd(state);
-
-       return 0;
+       return dst_tone_power_cmd(state);
 }
 
 static int dst_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t minicmd)
@@ -1497,7 +1538,7 @@ static int dst_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t minicmd)
        struct dst_state *state = fe->demodulator_priv;
 
        if (state->dst_type != DST_TYPE_IS_SAT)
-               return 0;
+               return -EOPNOTSUPP;
        state->minicmd = minicmd;
        switch (minicmd) {
        case SEC_MINI_A:
@@ -1507,9 +1548,7 @@ static int dst_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t minicmd)
                state->tx_tuna[3] = 0xff;
                break;
        }
-       dst_tone_power_cmd(state);
-
-       return 0;
+       return dst_tone_power_cmd(state);
 }
 
 
@@ -1521,8 +1560,8 @@ static int dst_init(struct dvb_frontend *fe)
        static u8 sat_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x55, 0xbd, 0x50, 0x00, 0x00 };
        static u8 ter_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
        static u8 ter_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
-       static u8 cab_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
        static u8 cab_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
+       static u8 cab_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
        static u8 atsc_tuner[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
 
        state->inversion = INVERSION_OFF;
@@ -1533,11 +1572,11 @@ static int dst_init(struct dvb_frontend *fe)
        state->bandwidth = BANDWIDTH_7_MHZ;
        state->cur_jiff = jiffies;
        if (state->dst_type == DST_TYPE_IS_SAT)
-               memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? sat_tuna_188 : sat_tuna_204), sizeof (sat_tuna_204));
+               memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_VLF) ? sat_tuna_188 : sat_tuna_204), sizeof (sat_tuna_204));
        else if (state->dst_type == DST_TYPE_IS_TERR)
-               memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ter_tuna_188 : ter_tuna_204), sizeof (ter_tuna_204));
+               memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_VLF) ? ter_tuna_188 : ter_tuna_204), sizeof (ter_tuna_204));
        else if (state->dst_type == DST_TYPE_IS_CABLE)
-               memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? cab_tuna_188 : cab_tuna_204), sizeof (cab_tuna_204));
+               memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_VLF) ? cab_tuna_188 : cab_tuna_204), sizeof (cab_tuna_204));
        else if (state->dst_type == DST_TYPE_IS_ATSC)
                memcpy(state->tx_tuna, atsc_tuner, sizeof (atsc_tuner));
 
@@ -1562,28 +1601,31 @@ static int dst_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
 {
        struct dst_state *state = fe->demodulator_priv;
 
-       dst_get_signal(state);
+       int retval = dst_get_signal(state);
        *strength = state->decode_strength;
 
-       return 0;
+       return retval;
 }
 
 static int dst_read_snr(struct dvb_frontend *fe, u16 *snr)
 {
        struct dst_state *state = fe->demodulator_priv;
 
-       dst_get_signal(state);
+       int retval = dst_get_signal(state);
        *snr = state->decode_snr;
 
-       return 0;
+       return retval;
 }
 
 static int dst_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
 {
+       int retval = -EINVAL;
        struct dst_state *state = fe->demodulator_priv;
 
        if (p != NULL) {
-               dst_set_freq(state, p->frequency);
+               retval = dst_set_freq(state, p->frequency);
+               if(retval != 0)
+                       return retval;
                dprintk(verbose, DST_DEBUG, 1, "Set Frequency=[%d]", p->frequency);
 
                if (state->dst_type == DST_TYPE_IS_SAT) {
@@ -1601,10 +1643,10 @@ static int dst_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_paramet
                        dst_set_symbolrate(state, p->u.qam.symbol_rate);
                        dst_set_modulation(state, p->u.qam.modulation);
                }
-               dst_write_tuna(fe);
+               retval = dst_write_tuna(fe);
        }
 
-       return 0;
+       return retval;
 }
 
 static int dst_tune_frontend(struct dvb_frontend* fe,