]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - drivers/media/dvb/bt8xx/dst.c
V4L/DVB (4163): Initialize ATSC frontend
[mv-sheeva.git] / drivers / media / dvb / bt8xx / dst.c
index 3a2ff1cc24b709eb70fad464b0deb36ac9744fbe..5431caebcd680a5220f6eb65aaf1141835dc1c22 100644 (file)
@@ -38,6 +38,10 @@ static unsigned int dst_addons;
 module_param(dst_addons, int, 0644);
 MODULE_PARM_DESC(dst_addons, "CA daughterboard, default is 0 (No addons)");
 
+static unsigned int dst_algo;
+module_param(dst_algo, int, 0644);
+MODULE_PARM_DESC(dst_algo, "tuning algo: default is 0=(SW), 1=(HW)");
+
 #define HAS_LOCK               1
 #define ATTEMPT_TUNE           2
 #define HAS_POWER              4
@@ -363,6 +367,17 @@ static int dst_set_freq(struct dst_state *state, u32 freq)
                state->tx_tuna[2] = (freq >> 16) & 0xff;
                state->tx_tuna[3] = (freq >> 8) & 0xff;
                state->tx_tuna[4] = (u8) freq;
+       } else if (state->dst_type == DST_TYPE_IS_ATSC) {
+               freq = freq / 1000;
+               if (freq < 51000 || freq > 858000)
+                       return -EINVAL;
+               state->tx_tuna[2] = (freq >> 16) & 0xff;
+               state->tx_tuna[3] = (freq >>  8) & 0xff;
+               state->tx_tuna[4] = (u8) freq;
+               state->tx_tuna[5] = 0x00;               /*      ATSC    */
+               state->tx_tuna[6] = 0x00;
+               if (state->dst_hw_cap & DST_TYPE_HAS_ANALOG)
+                       state->tx_tuna[7] = 0x00;       /*      Digital */
        } else
                return -EINVAL;
 
@@ -558,6 +573,10 @@ static int dst_type_print(u8 type)
                otype = "cable";
                break;
 
+       case DST_TYPE_IS_ATSC:
+               otype = "atsc";
+               break;
+
        default:
                dprintk(verbose, DST_INFO, 1, "invalid dst type %d", type);
                return -EINVAL;
@@ -602,7 +621,7 @@ static int dst_type_print(u8 type)
 
 */
 
-struct dst_types dst_tlist[] = {
+static struct dst_types dst_tlist[] = {
        {
                .device_id = "200103A",
                .offset = 0,
@@ -648,7 +667,7 @@ struct dst_types dst_tlist[] = {
                .device_id = "DST-CI",
                .offset = 1,
                .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_FW_1,
                .dst_feature = DST_TYPE_HAS_CA
        },      /*      An OEM board    */
 
@@ -673,8 +692,7 @@ struct dst_types dst_tlist[] = {
                .device_id = "DCT-CI",
                .offset = 1,
                .dst_type = DST_TYPE_IS_CABLE,
-               .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | 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_feature = DST_TYPE_HAS_CA
        },
 
@@ -690,7 +708,7 @@ struct dst_types dst_tlist[] = {
                .device_id = "DTT-CI",
                .offset = 1,
                .dst_type = DST_TYPE_IS_TERR,
-               .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_MULTI_FE,
+               .type_flags = DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_MULTI_FE,
                .dst_feature = DST_TYPE_HAS_CA
        },
 
@@ -722,8 +740,8 @@ struct dst_types dst_tlist[] = {
                .device_id = "ATSCAD",
                .offset = 1,
                .dst_type = DST_TYPE_IS_ATSC,
-               .type_flags = DST_TYPE_HAS_FW_2,
-               .dst_feature = 0
+               .type_flags = DST_TYPE_HAS_MULTI_FE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD,
+               .dst_feature = DST_TYPE_HAS_MAC | DST_TYPE_HAS_ANALOG
        },
 
        { }
@@ -803,20 +821,25 @@ static int dst_get_tuner_info(struct dst_state *state)
 
        get_tuner_1[7] = dst_check_sum(get_tuner_1, 7);
        get_tuner_2[7] = dst_check_sum(get_tuner_2, 7);
+       dprintk(verbose, DST_ERROR, 1, "DST TYpe = MULTI FE");
        if (state->type_flags & DST_TYPE_HAS_MULTI_FE) {
-               if (dst_command(state, get_tuner_2, 8) < 0) {
-                       dprintk(verbose, DST_INFO, 1, "Unsupported Command");
+//             if (dst_command(state, get_tuner_2, 8) < 0) {
+               if (dst_command(state, get_tuner_1, 8) < 0) {
+                       dprintk(verbose, DST_INFO, 1, "Cmd=[0x13], Unsupported");
                        return -1;
                }
        } else {
-               if (dst_command(state, get_tuner_1, 8) < 0) {
-                       dprintk(verbose, DST_INFO, 1, "Unsupported Command");
+//             if (dst_command(state, get_tuner_1, 8) < 0) {
+               if (dst_command(state, get_tuner_2, 8) < 0) {
+                       dprintk(verbose, DST_INFO, 1, "Cmd=[0xb], Unsupported");
                        return -1;
                }
        }
        memset(&state->board_info, '\0', 8);
        memcpy(&state->board_info, &state->rxbuffer, 8);
        if (state->type_flags & DST_TYPE_HAS_MULTI_FE) {
+               dprintk(verbose, DST_ERROR, 1, "DST type has TS=188");
+/*
                if (state->board_info[1] == 0x0b) {
                        if (state->type_flags & DST_TYPE_HAS_TS204)
                                state->type_flags &= ~DST_TYPE_HAS_TS204;
@@ -829,19 +852,21 @@ static int dst_get_tuner_info(struct dst_state *state)
                        dprintk(verbose, DST_INFO, 1, "DST type has TS=204");
                }
        } else {
-               if (state->board_info[0] == 0xbc) {
-                       if (state->type_flags & DST_TYPE_HAS_TS204)
-                               state->type_flags &= ~DST_TYPE_HAS_TS204;
-                       state->type_flags |= DST_TYPE_HAS_NEWTUNE;
-                       dprintk(verbose, DST_INFO, 1, "DST type has TS=188, Daughterboard=[%d]", state->board_info[1]);
+*/
+       }
+       if (state->board_info[0] == 0xbc) {
+//             if (state->type_flags & DST_TYPE_HAS_TS204)
+//                     state->type_flags &= ~DST_TYPE_HAS_TS204;
+               state->type_flags |= DST_TYPE_HAS_NEWTUNE;
+               dprintk(verbose, DST_INFO, 1, "DST type has TS=188, Daughterboard=[%d]", state->board_info[1]);
 
-               } else if (state->board_info[0] == 0xcc) {
-                       if (state->type_flags & DST_TYPE_HAS_NEWTUNE)
-                               state->type_flags &= ~DST_TYPE_HAS_NEWTUNE;
-                       state->type_flags |= DST_TYPE_HAS_TS204;
-                       dprintk(verbose, DST_INFO, 1, "DST type has TS=204 Daughterboard=[%d]", state->board_info[1]);
-               }
+       } else if (state->board_info[0] == 0xcc) {
+//             if (state->type_flags & DST_TYPE_HAS_NEWTUNE)
+//                     state->type_flags &= ~DST_TYPE_HAS_NEWTUNE;
+               state->type_flags |= DST_TYPE_HAS_TS204;
+               dprintk(verbose, DST_INFO, 1, "DST type has TS=204 Daughterboard=[%d]", state->board_info[1]);
        }
+//     }
 
        return 0;
 }
@@ -910,16 +935,16 @@ static int dst_get_device_id(struct dst_state *state)
 
 static int dst_probe(struct dst_state *state)
 {
-       sema_init(&state->dst_mutex, 1);
-       if ((rdc_8820_reset(state)) < 0) {
-               dprintk(verbose, DST_ERROR, 1, "RDC 8820 RESET Failed.");
-               return -1;
-       }
-       if (dst_addons & DST_TYPE_HAS_CA)
+       mutex_init(&state->dst_mutex);
+       if (dst_addons & DST_TYPE_HAS_CA) {
+               if ((rdc_8820_reset(state)) < 0) {
+                       dprintk(verbose, DST_ERROR, 1, "RDC 8820 RESET Failed.");
+                       return -1;
+               }
                msleep(4000);
-       else
+       } else {
                msleep(100);
-
+       }
        if ((dst_comm_init(state)) < 0) {
                dprintk(verbose, DST_ERROR, 1, "DST Initialization Failed.");
                return -1;
@@ -962,7 +987,7 @@ int dst_command(struct dst_state *state, u8 *data, u8 len)
 {
        u8 reply;
 
-       down(&state->dst_mutex);
+       mutex_lock(&state->dst_mutex);
        if ((dst_comm_init(state)) < 0) {
                dprintk(verbose, DST_NOTICE, 1, "DST Communication Initialization Failed.");
                goto error;
@@ -1013,11 +1038,11 @@ int dst_command(struct dst_state *state, u8 *data, u8 len)
                dprintk(verbose, DST_INFO, 1, "checksum failure");
                goto error;
        }
-       up(&state->dst_mutex);
+       mutex_unlock(&state->dst_mutex);
        return 0;
 
 error:
-       up(&state->dst_mutex);
+       mutex_unlock(&state->dst_mutex);
        return -EIO;
 
 }
@@ -1048,6 +1073,10 @@ static int dst_get_signal(struct dst_state *state)
                        state->decode_lock = (state->rxbuffer[1]) ? 1 : 0;
                        state->decode_strength = state->rxbuffer[4] << 8;
                        state->decode_snr = state->rxbuffer[3] << 8;
+               } else if (state->dst_type == DST_TYPE_IS_ATSC) {
+                       state->decode_lock = (state->rxbuffer[6] == 0x00) ? 1 : 0;
+                       state->decode_strength = state->rxbuffer[4] << 8;
+                       state->decode_snr = state->rxbuffer[2] << 8 | state->rxbuffer[3];
                }
                state->cur_jiff = jiffies;
        }
@@ -1128,7 +1157,7 @@ static int dst_write_tuna(struct dvb_frontend *fe)
                        dst_set_voltage(fe, SEC_VOLTAGE_13);
        }
        state->diseq_flags &= ~(HAS_LOCK | ATTEMPT_TUNE);
-       down(&state->dst_mutex);
+       mutex_lock(&state->dst_mutex);
        if ((dst_comm_init(state)) < 0) {
                dprintk(verbose, DST_DEBUG, 1, "DST Communication initialization failed.");
                goto error;
@@ -1160,11 +1189,11 @@ static int dst_write_tuna(struct dvb_frontend *fe)
        state->diseq_flags |= ATTEMPT_TUNE;
        retval = dst_get_tuna(state);
 werr:
-       up(&state->dst_mutex);
+       mutex_unlock(&state->dst_mutex);
        return retval;
 
 error:
-       up(&state->dst_mutex);
+       mutex_unlock(&state->dst_mutex);
        return -EIO;
 }
 
@@ -1289,6 +1318,8 @@ static int dst_init(struct dvb_frontend *fe)
        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 atsc_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
+       static u8 atsc_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
 
        state->inversion = INVERSION_OFF;
        state->voltage = SEC_VOLTAGE_13;
@@ -1303,6 +1334,8 @@ static int dst_init(struct dvb_frontend *fe)
                memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? 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));
+       else if (state->dst_type == DST_TYPE_IS_ATSC)
+               memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? atsc_tuna_188 : atsc_tuna_204), sizeof (atsc_tuna_204));
 
        return 0;
 }
@@ -1341,7 +1374,36 @@ static int dst_read_snr(struct dvb_frontend *fe, u16 *snr)
        return 0;
 }
 
-static int dst_set_frontend(struct dvb_frontend* fe,
+static int dst_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
+{
+       struct dst_state *state = fe->demodulator_priv;
+
+       if (p != NULL) {
+               dst_set_freq(state, p->frequency);
+               dprintk(verbose, DST_DEBUG, 1, "Set Frequency=[%d]", p->frequency);
+
+               if (state->dst_type == DST_TYPE_IS_SAT) {
+                       if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
+                               dst_set_inversion(state, p->inversion);
+                       dst_set_fec(state, p->u.qpsk.fec_inner);
+                       dst_set_symbolrate(state, p->u.qpsk.symbol_rate);
+                       dst_set_polarization(state);
+                       dprintk(verbose, DST_DEBUG, 1, "Set Symbolrate=[%d]", p->u.qpsk.symbol_rate);
+
+               } else if (state->dst_type == DST_TYPE_IS_TERR)
+                       dst_set_bandwidth(state, p->u.ofdm.bandwidth);
+               else if (state->dst_type == DST_TYPE_IS_CABLE) {
+                       dst_set_fec(state, p->u.qam.fec_inner);
+                       dst_set_symbolrate(state, p->u.qam.symbol_rate);
+                       dst_set_modulation(state, p->u.qam.modulation);
+               }
+               dst_write_tuna(fe);
+       }
+
+       return 0;
+}
+
+static int dst_tune_frontend(struct dvb_frontend* fe,
                            struct dvb_frontend_parameters* p,
                            unsigned int mode_flags,
                            int *delay,
@@ -1378,6 +1440,11 @@ static int dst_set_frontend(struct dvb_frontend* fe,
        return 0;
 }
 
+static int dst_get_tuning_algo(struct dvb_frontend *fe)
+{
+       return dst_algo;
+}
+
 static int dst_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
 {
        struct dst_state *state = fe->demodulator_priv;
@@ -1408,6 +1475,7 @@ static void dst_release(struct dvb_frontend *fe)
 static struct dvb_frontend_ops dst_dvbt_ops;
 static struct dvb_frontend_ops dst_dvbs_ops;
 static struct dvb_frontend_ops dst_dvbc_ops;
+static struct dvb_frontend_ops dst_atsc_ops;
 
 struct dst_state *dst_attach(struct dst_state *state, struct dvb_adapter *dvb_adapter)
 {
@@ -1417,24 +1485,25 @@ struct dst_state *dst_attach(struct dst_state *state, struct dvb_adapter *dvb_ad
                return NULL;
        }
        /* determine settings based on type */
+       /* create dvb_frontend */
        switch (state->dst_type) {
        case DST_TYPE_IS_TERR:
-               memcpy(&state->ops, &dst_dvbt_ops, sizeof(struct dvb_frontend_ops));
+               memcpy(&state->frontend.ops, &dst_dvbt_ops, sizeof(struct dvb_frontend_ops));
                break;
        case DST_TYPE_IS_CABLE:
-               memcpy(&state->ops, &dst_dvbc_ops, sizeof(struct dvb_frontend_ops));
+               memcpy(&state->frontend.ops, &dst_dvbc_ops, sizeof(struct dvb_frontend_ops));
                break;
        case DST_TYPE_IS_SAT:
-               memcpy(&state->ops, &dst_dvbs_ops, sizeof(struct dvb_frontend_ops));
+               memcpy(&state->frontend.ops, &dst_dvbs_ops, sizeof(struct dvb_frontend_ops));
+               break;
+       case DST_TYPE_IS_ATSC:
+               memcpy(&state->frontend.ops, &dst_atsc_ops, sizeof(struct dvb_frontend_ops));
                break;
        default:
                dprintk(verbose, DST_ERROR, 1, "unknown DST type. please report to the LinuxTV.org DVB mailinglist.");
                kfree(state);
                return NULL;
        }
-
-       /* create dvb_frontend */
-       state->frontend.ops = &state->ops;
        state->frontend.demodulator_priv = state;
 
        return state;                           /*      Manu (DST is a card not a frontend)     */
@@ -1455,8 +1524,10 @@ static struct dvb_frontend_ops dst_dvbt_ops = {
 
        .release = dst_release,
        .init = dst_init,
-       .tune = dst_set_frontend,
+       .tune = dst_tune_frontend,
+       .set_frontend = dst_set_frontend,
        .get_frontend = dst_get_frontend,
+       .get_frontend_algo = dst_get_tuning_algo,
        .read_status = dst_read_status,
        .read_signal_strength = dst_read_signal_strength,
        .read_snr = dst_read_snr,
@@ -1479,8 +1550,10 @@ static struct dvb_frontend_ops dst_dvbs_ops = {
 
        .release = dst_release,
        .init = dst_init,
-       .tune = dst_set_frontend,
+       .tune = dst_tune_frontend,
+       .set_frontend = dst_set_frontend,
        .get_frontend = dst_get_frontend,
+       .get_frontend_algo = dst_get_tuning_algo,
        .read_status = dst_read_status,
        .read_signal_strength = dst_read_signal_strength,
        .read_snr = dst_read_snr,
@@ -1506,13 +1579,38 @@ static struct dvb_frontend_ops dst_dvbc_ops = {
 
        .release = dst_release,
        .init = dst_init,
-       .tune = dst_set_frontend,
+       .tune = dst_tune_frontend,
+       .set_frontend = dst_set_frontend,
+       .get_frontend = dst_get_frontend,
+       .get_frontend_algo = dst_get_tuning_algo,
+       .read_status = dst_read_status,
+       .read_signal_strength = dst_read_signal_strength,
+       .read_snr = dst_read_snr,
+};
+
+static struct dvb_frontend_ops dst_atsc_ops = {
+       .info = {
+               .name = "DST ATSC",
+               .type = FE_ATSC,
+               .frequency_stepsize = 62500,
+               .frequency_min = 510000000,
+               .frequency_max = 858000000,
+               .symbol_rate_min = 1000000,
+               .symbol_rate_max = 45000000,
+               .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO | FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
+       },
+
+       .release = dst_release,
+       .init = dst_init,
+       .tune = dst_tune_frontend,
+       .set_frontend = dst_set_frontend,
        .get_frontend = dst_get_frontend,
+       .get_frontend_algo = dst_get_tuning_algo,
        .read_status = dst_read_status,
        .read_signal_strength = dst_read_signal_strength,
        .read_snr = dst_read_snr,
 };
 
-MODULE_DESCRIPTION("DST DVB-S/T/C Combo Frontend driver");
+MODULE_DESCRIPTION("DST DVB-S/T/C/ATSC Combo Frontend driver");
 MODULE_AUTHOR("Jamie Honan, Manu Abraham");
 MODULE_LICENSE("GPL");