V4L/DVB (9403): Fix the CA module not working issue
[safe/jmp/linux-2.6] / drivers / media / dvb / bt8xx / dst.c
index 35d25c0..29e8f15 100644 (file)
@@ -51,22 +51,27 @@ MODULE_PARM_DESC(dst_algo, "tuning algo: default is 0=(SW), 1=(HW)");
 #define DST_INFO               2
 #define DST_DEBUG              3
 
-#define dprintk(x, y, z, format, arg...) do {                                          \
-       if (z) {                                                                        \
-               if      ((x > DST_ERROR) && (x > y))                                    \
-                       printk(KERN_ERR "%s: " format "\n", __FUNCTION__ , ##arg);      \
-               else if ((x > DST_NOTICE) && (x > y))                                   \
-                       printk(KERN_NOTICE "%s: " format "\n", __FUNCTION__ , ##arg);   \
-               else if ((x > DST_INFO) && (x > y))                                     \
-                       printk(KERN_INFO "%s: " format "\n", __FUNCTION__ , ##arg);     \
-               else if ((x > DST_DEBUG) && (x > y))                                    \
-                       printk(KERN_DEBUG "%s: " format "\n", __FUNCTION__ , ##arg);    \
-       } else {                                                                        \
-               if (x > y)                                                              \
-                       printk(format, ##arg);                                          \
-       }                                                                               \
+#define dprintk(x, y, z, format, arg...) do {                          \
+       if (z) {                                                        \
+               if      ((x > DST_ERROR) && (x > y))                    \
+                       printk(KERN_ERR "dst(%d) %s: " format "\n",     \
+                               state->bt->nr, __func__ , ##arg);       \
+               else if ((x > DST_NOTICE) && (x > y))                   \
+                       printk(KERN_NOTICE "dst(%d) %s: " format "\n",  \
+                               state->bt->nr, __func__ , ##arg);       \
+               else if ((x > DST_INFO) && (x > y))                     \
+                       printk(KERN_INFO "dst(%d) %s: " format "\n",    \
+                               state->bt->nr, __func__ , ##arg);       \
+               else if ((x > DST_DEBUG) && (x > y))                    \
+                       printk(KERN_DEBUG "dst(%d) %s: " format "\n",   \
+                               state->bt->nr,  __func__ , ##arg);      \
+       } else {                                                        \
+               if (x > y)                                              \
+                       printk(format, ##arg);                          \
+       }                                                               \
 } while(0)
 
+static int dst_command(struct dst_state *state, u8 *data, u8 len);
 
 static void dst_packsize(struct dst_state *state, int psize)
 {
@@ -76,7 +81,8 @@ static void dst_packsize(struct dst_state *state, int psize)
        bt878_device_control(state->bt, DST_IG_TS, &bits);
 }
 
-int dst_gpio_outb(struct dst_state *state, u32 mask, u32 enbb, u32 outhigh, int delay)
+static int dst_gpio_outb(struct dst_state *state, u32 mask, u32 enbb,
+                        u32 outhigh, int delay)
 {
        union dst_gpio_packet enb;
        union dst_gpio_packet bits;
@@ -105,23 +111,21 @@ int dst_gpio_outb(struct dst_state *state, u32 mask, u32 enbb, u32 outhigh, int
 
        return 0;
 }
-EXPORT_SYMBOL(dst_gpio_outb);
 
-int dst_gpio_inb(struct dst_state *state, u8 *result)
+static int dst_gpio_inb(struct dst_state *state, u8 *result)
 {
        union dst_gpio_packet rd_packet;
        int err;
 
        *result = 0;
        if ((err = bt878_device_control(state->bt, DST_IG_READ, &rd_packet)) < 0) {
-               dprintk(verbose, DST_ERROR, 1, "dst_gpio_inb error (err == %i)\n", err);
+               dprintk(verbose, DST_ERROR, 1, "dst_gpio_inb error (err == %i)", err);
                return -EREMOTEIO;
        }
        *result = (u8) rd_packet.rd.value;
 
        return 0;
 }
-EXPORT_SYMBOL(dst_gpio_inb);
 
 int rdc_reset_state(struct dst_state *state)
 {
@@ -141,7 +145,7 @@ int rdc_reset_state(struct dst_state *state)
 }
 EXPORT_SYMBOL(rdc_reset_state);
 
-int rdc_8820_reset(struct dst_state *state)
+static int rdc_8820_reset(struct dst_state *state)
 {
        dprintk(verbose, DST_DEBUG, 1, "Resetting DST");
        if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, 0, NO_DELAY) < 0) {
@@ -156,9 +160,8 @@ int rdc_8820_reset(struct dst_state *state)
 
        return 0;
 }
-EXPORT_SYMBOL(rdc_8820_reset);
 
-int dst_pio_enable(struct dst_state *state)
+static int dst_pio_enable(struct dst_state *state)
 {
        if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_ENABLE, 0, NO_DELAY) < 0) {
                dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
@@ -168,7 +171,6 @@ int dst_pio_enable(struct dst_state *state)
 
        return 0;
 }
-EXPORT_SYMBOL(dst_pio_enable);
 
 int dst_pio_disable(struct dst_state *state)
 {
@@ -389,7 +391,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:
@@ -458,37 +460,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) {
@@ -505,7 +519,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:
@@ -538,15 +555,19 @@ u8 dst_check_sum(u8 *buf, u32 len)
 }
 EXPORT_SYMBOL(dst_check_sum);
 
-static void dst_type_flags_print(u32 type_flags)
+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)
@@ -559,7 +580,7 @@ static void dst_type_flags_print(u32 type_flags)
 }
 
 
-static int dst_type_print(u8 type)
+static int dst_type_print(struct dst_state *state, u8 type)
 {
        char *otype;
        switch (type) {
@@ -588,7 +609,7 @@ static int dst_type_print(u8 type)
        return 0;
 }
 
-struct tuner_types tuner_list[] = {
+static struct tuner_types tuner_list[] = {
        {
                .tuner_type = TUNER_TYPE_L64724,
                .tuner_name = "L 64724",
@@ -641,6 +662,13 @@ struct tuner_types tuner_list[] = {
        {
                .tuner_type = TUNER_TYPE_UNKNOWN,
                .tuner_name = "UNKNOWN",
+               .board_name = "VP2021",
+               .fw_name    = "DCTNEW"
+       },
+
+       {
+               .tuner_type = TUNER_TYPE_UNKNOWN,
+               .tuner_name = "UNKNOWN",
                .board_name = "VP2030",
                .fw_name    = "DCT-CI"
        },
@@ -760,7 +788,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        */
@@ -797,7 +825,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
@@ -807,7 +835,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    */
@@ -816,7 +844,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
        },
@@ -825,7 +853,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
        },
@@ -834,7 +862,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
        },
@@ -889,9 +917,7 @@ static int dst_get_mac(struct dst_state *state)
        }
        memset(&state->mac_address, '\0', 8);
        memcpy(&state->mac_address, &state->rxbuffer, 6);
-       dprintk(verbose, DST_ERROR, 1, "MAC Address=[%02x:%02x:%02x:%02x:%02x:%02x]",
-               state->mac_address[0], state->mac_address[1], state->mac_address[2],
-               state->mac_address[4], state->mac_address[5], state->mac_address[6]);
+       dprintk(verbose, DST_ERROR, 1, "MAC Address=[%pM]", state->mac_address);
 
        return 0;
 }
@@ -933,7 +959,7 @@ static int dst_card_type(struct dst_state *state)
        for (j = 0, p_tuner_list = tuner_list; j < ARRAY_SIZE(tuner_list); j++, p_tuner_list++) {
                if (!strcmp(&state->card_info[0], p_tuner_list->board_name)) {
                        state->tuner_type = p_tuner_list->tuner_type;
-                       dprintk(verbose, DST_ERROR, 1, "DST has [%s] tuner, tuner type=[%d]\n",
+                       dprintk(verbose, DST_ERROR, 1, "DST has [%s] tuner, tuner type=[%d]",
                                p_tuner_list->tuner_name, p_tuner_list->tuner_type);
                }
        }
@@ -956,6 +982,58 @@ static int dst_get_vendor(struct dst_state *state)
        return 0;
 }
 
+static void debug_dst_buffer(struct dst_state *state)
+{
+       int i;
+
+       if (verbose > 2) {
+               printk("%s: [", __func__);
+               for (i = 0; i < 8; i++)
+                       printk(" %02x", state->rxbuffer[i]);
+               printk("]\n");
+       }
+}
+
+static int dst_check_stv0299(struct dst_state *state)
+{
+       u8 check_stv0299[] = { 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+       check_stv0299[7] = dst_check_sum(check_stv0299, 7);
+       if (dst_command(state, check_stv0299, 8) < 0) {
+               dprintk(verbose, DST_ERROR, 1, "Cmd=[0x04] failed");
+               return -1;
+       }
+       debug_dst_buffer(state);
+
+       if (memcmp(&check_stv0299, &state->rxbuffer, 8)) {
+               dprintk(verbose, DST_ERROR, 1, "Found a STV0299 NIM");
+               state->tuner_type = TUNER_TYPE_STV0299;
+               return 0;
+       }
+
+       return -1;
+}
+
+static int dst_check_mb86a15(struct dst_state *state)
+{
+       u8 check_mb86a15[] = { 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+       check_mb86a15[7] = dst_check_sum(check_mb86a15, 7);
+       if (dst_command(state, check_mb86a15, 8) < 0) {
+               dprintk(verbose, DST_ERROR, 1, "Cmd=[0x10], failed");
+               return -1;
+       }
+       debug_dst_buffer(state);
+
+       if (memcmp(&check_mb86a15, &state->rxbuffer, 8) < 0) {
+               dprintk(verbose, DST_ERROR, 1, "Found a MB86A15 NIM");
+               state->tuner_type = TUNER_TYPE_MB86A15;
+               return 0;
+       }
+
+       return -1;
+}
+
 static int dst_get_tuner_info(struct dst_state *state)
 {
        u8 get_tuner_1[] = { 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
@@ -967,12 +1045,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);
@@ -982,7 +1060,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;
 
@@ -993,6 +1071,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)
@@ -1000,14 +1085,15 @@ static int dst_get_device_id(struct dst_state *state)
        u8 reply;
 
        int i, j;
-       struct dst_types *p_dst_type;
-       struct tuner_types *p_tuner_list;
+       struct dst_types *p_dst_type = NULL;
+       struct tuner_types *p_tuner_list = NULL;
 
        u8 use_dst_type = 0;
        u32 use_type_flags = 0;
 
        static u8 device_type[8] = {0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
 
+       state->tuner_type = 0;
        device_type[7] = dst_check_sum(device_type, 7);
 
        if (write_dst(state, device_type, FIXED_COMM))
@@ -1039,32 +1125,48 @@ 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]\n", p_dst_type->device_id);
-
-                       if (p_dst_type->tuner_type != TUNER_TYPE_MULTI) {
-                               state->tuner_type = p_dst_type->tuner_type;
-
-                               for (j = 0, p_tuner_list = tuner_list; j < ARRAY_SIZE(tuner_list); j++, p_tuner_list++) {
-                                       if (p_dst_type->tuner_type == p_tuner_list->tuner_type) {
-                                               state->tuner_type = p_tuner_list->tuner_type;
-                                               dprintk(verbose, DST_ERROR, 1, "DST has a [%s] based tuner\n", p_tuner_list->tuner_name);
+                       dprintk(verbose, DST_ERROR, 1, "Recognise [%s]", p_dst_type->device_id);
+                       strncpy(&state->fw_name[0], p_dst_type->device_id, 6);
+                       /*      Multiple tuners         */
+                       if (p_dst_type->tuner_type & TUNER_TYPE_MULTI) {
+                               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            */
+                       } else {
+                               state->tuner_type = p_dst_type->tuner_type;
+                       }
+                       for (j = 0, p_tuner_list = tuner_list; j < ARRAY_SIZE(tuner_list); j++, p_tuner_list++) {
+                               if (!(strncmp(p_dst_type->device_id, p_tuner_list->fw_name, 7)) &&
+                                       p_tuner_list->tuner_type == state->tuner_type) {
+                                       dprintk(verbose, DST_ERROR, 1, "[%s] has a [%s]",
+                                               p_dst_type->device_id, p_tuner_list->tuner_name);
                                }
                        }
                        break;
                }
        }
 
-       if (i >= sizeof (dst_tlist) / sizeof (dst_tlist [0])) {
+       if (i >= ARRAY_SIZE(dst_tlist)) {
                dprintk(verbose, DST_ERROR, 1, "Unable to recognize %s or %s", &state->rxbuffer[0], &state->rxbuffer[1]);
                dprintk(verbose, DST_ERROR, 1, "please email linux-dvb@linuxtv.org with this type in");
                use_dst_type = DST_TYPE_IS_SAT;
                use_type_flags = DST_TYPE_HAS_SYMDIV;
        }
-       dst_type_print(use_dst_type);
+       dst_type_print(state, use_dst_type);
        state->type_flags = use_type_flags;
        state->dst_type = use_dst_type;
-       dst_type_flags_print(state->type_flags);
+       dst_type_flags_print(state);
 
        return 0;
 }
@@ -1092,7 +1194,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)
@@ -1119,7 +1220,7 @@ static int dst_probe(struct dst_state *state)
        return 0;
 }
 
-int dst_command(struct dst_state *state, u8 *data, u8 len)
+static int dst_command(struct dst_state *state, u8 *data, u8 len)
 {
        u8 reply;
 
@@ -1129,7 +1230,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;
@@ -1141,7 +1242,7 @@ int dst_command(struct dst_state *state, u8 *data, u8 len)
                goto error;
        }
        if (state->type_flags & DST_TYPE_HAS_FW_1)
-               udelay(3000);
+               mdelay(3);
        if (read_dst(state, &reply, GET_ACK)) {
                dprintk(verbose, DST_DEBUG, 1, "Trying to recover.. ");
                if ((dst_error_recovery(state)) < 0) {
@@ -1157,7 +1258,7 @@ int dst_command(struct dst_state *state, u8 *data, u8 len)
        if (len >= 2 && data[0] == 0 && (data[1] == 1 || data[1] == 3))
                goto error;
        if (state->type_flags & DST_TYPE_HAS_FW_1)
-               udelay(3000);
+               mdelay(3);
        else
                udelay(2000);
        if (!dst_wait_dst_ready(state, NO_DELAY))
@@ -1182,13 +1283,12 @@ error:
        return -EIO;
 
 }
-EXPORT_SYMBOL(dst_command);
 
 static int dst_get_signal(struct dst_state *state)
 {
        int retval;
        u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb };
-       //dprintk("%s: Getting Signal strength and other parameters\n", __FUNCTION__);
+       //dprintk("%s: Getting Signal strength and other parameters\n", __func__);
        if ((state->diseq_flags & ATTEMPT_TUNE) == 0) {
                state->decode_lock = state->decode_strength = state->decode_snr = 0;
                return 0;
@@ -1223,15 +1323,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)
@@ -1243,8 +1341,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);
@@ -1252,7 +1351,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;
@@ -1298,7 +1400,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 {
@@ -1353,23 +1458,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;
 
@@ -1391,9 +1498,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)
@@ -1402,7 +1509,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:
@@ -1418,9 +1525,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)
@@ -1428,7 +1533,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:
@@ -1438,9 +1543,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);
 }
 
 
@@ -1452,8 +1555,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;
@@ -1464,11 +1567,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));
 
@@ -1493,28 +1596,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) {
@@ -1532,16 +1638,16 @@ 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,
                            struct dvb_frontend_parameters* p,
                            unsigned int mode_flags,
-                           int *delay,
+                           unsigned int *delay,
                            fe_status_t *status)
 {
        struct dst_state *state = fe->demodulator_priv;
@@ -1604,6 +1710,12 @@ static int dst_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_paramet
 static void dst_release(struct dvb_frontend *fe)
 {
        struct dst_state *state = fe->demodulator_priv;
+       if (state->dst_ca) {
+               dvb_unregister_device(state->dst_ca);
+#ifdef CONFIG_MEDIA_ATTACH
+               symbol_put(dst_ca_attach);
+#endif
+       }
        kfree(state);
 }