firedtv: cleanups and minor fixes
[linux-2.6-block.git] / drivers / media / dvb / firesat / firesat_fe.c
index ec614ea8de224c3587b0c3b4d0d5cf145b05b24b..1ed972b79573fef52bb2a25b889f5f76bd2dc45a 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <linux/errno.h>
 #include <linux/kernel.h>
+#include <linux/string.h>
 #include <linux/types.h>
 
 #include <dvb_frontend.h>
 
 static int firesat_dvb_init(struct dvb_frontend *fe)
 {
-       int result;
        struct firesat *firesat = fe->sec_priv;
-//     printk("fdi: 1\n");
-       firesat->isochannel = firesat->adapter->num; //<< 1 | (firesat->subunit & 0x1); // ### ask IRM
-//     printk("fdi: 2\n");
-       result = try_CMPEstablishPPconnection(firesat, firesat->subunit, firesat->isochannel);
-       if (result != 0) {
+       int err;
+
+       /* FIXME - allocate free channel at IRM */
+       firesat->isochannel = firesat->adapter.num;
+
+       err = cmp_establish_pp_connection(firesat, firesat->subunit,
+                                         firesat->isochannel);
+       if (err) {
                printk(KERN_ERR "Could not establish point to point "
                       "connection.\n");
-               return -1;
+               return err;
        }
-//     printk("fdi: 3\n");
 
-       result = setup_iso_channel(firesat);
-//     printk("fdi: 4. Result was %d\n", result);
-       return result;
+       return setup_iso_channel(firesat);
 }
 
 static int firesat_sleep(struct dvb_frontend *fe)
@@ -45,7 +45,7 @@ static int firesat_sleep(struct dvb_frontend *fe)
        struct firesat *firesat = fe->sec_priv;
 
        tear_down_iso_channel(firesat);
-       try_CMPBreakPPconnection(firesat, firesat->subunit, firesat->isochannel);
+       cmp_break_pp_connection(firesat, firesat->subunit, firesat->isochannel);
        firesat->isochannel = -1;
        return 0;
 }
@@ -55,8 +55,8 @@ static int firesat_diseqc_send_master_cmd(struct dvb_frontend *fe,
 {
        struct firesat *firesat = fe->sec_priv;
 
-       return AVCLNBControl(firesat, LNBCONTROL_DONTCARE, LNBCONTROL_DONTCARE,
-                            LNBCONTROL_DONTCARE, 1, cmd);
+       return avc_lnb_control(firesat, LNBCONTROL_DONTCARE,
+                       LNBCONTROL_DONTCARE, LNBCONTROL_DONTCARE, 1, cmd);
 }
 
 static int firesat_diseqc_send_burst(struct dvb_frontend *fe,
@@ -82,24 +82,19 @@ static int firesat_set_voltage(struct dvb_frontend *fe,
        return 0;
 }
 
-static int firesat_read_status (struct dvb_frontend *fe, fe_status_t *status)
+static int firesat_read_status(struct dvb_frontend *fe, fe_status_t *status)
 {
        struct firesat *firesat = fe->sec_priv;
        ANTENNA_INPUT_INFO info;
 
-       if (AVCTunerStatus(firesat, &info))
+       if (avc_tuner_status(firesat, &info))
                return -EINVAL;
 
-       if (info.NoRF) {
+       if (info.NoRF)
                *status = 0;
-       } else {
-               *status = FE_HAS_SIGNAL |
-                       FE_HAS_VITERBI  |
-                       FE_HAS_SYNC     |
-                       FE_HAS_CARRIER  |
-                       FE_HAS_LOCK;
-       }
-
+       else
+               *status = FE_HAS_SIGNAL | FE_HAS_VITERBI | FE_HAS_SYNC |
+                         FE_HAS_CARRIER | FE_HAS_LOCK;
        return 0;
 }
 
@@ -108,14 +103,11 @@ static int firesat_read_ber(struct dvb_frontend *fe, u32 *ber)
        struct firesat *firesat = fe->sec_priv;
        ANTENNA_INPUT_INFO info;
 
-       if (AVCTunerStatus(firesat, &info))
+       if (avc_tuner_status(firesat, &info))
                return -EINVAL;
 
-       *ber = (info.BER[0] << 24) |
-               (info.BER[1] << 16) |
-               (info.BER[2] <<  8) |
-               info.BER[3];
-
+       *ber = info.BER[0] << 24 | info.BER[1] << 16 |
+              info.BER[2] << 8 | info.BER[3];
        return 0;
 }
 
@@ -124,11 +116,10 @@ static int firesat_read_signal_strength (struct dvb_frontend *fe, u16 *strength)
        struct firesat *firesat = fe->sec_priv;
        ANTENNA_INPUT_INFO info;
 
-       if (AVCTunerStatus(firesat, &info))
+       if (avc_tuner_status(firesat, &info))
                return -EINVAL;
 
        *strength = info.SignalStrength << 8;
-
        return 0;
 }
 
@@ -137,14 +128,12 @@ static int firesat_read_snr(struct dvb_frontend *fe, u16 *snr)
        struct firesat *firesat = fe->sec_priv;
        ANTENNA_INPUT_INFO info;
 
-       if (AVCTunerStatus(firesat, &info))
+       if (avc_tuner_status(firesat, &info))
                return -EINVAL;
 
-       *snr = (info.CarrierNoiseRatio[0] << 8) +
-               info.CarrierNoiseRatio[1];
+       /* C/N[dB] = -10 * log10(snr / 65535) */
+       *snr = (info.CarrierNoiseRatio[0] << 8) + info.CarrierNoiseRatio[1];
        *snr *= 257;
-       // C/N[dB] = -10 * log10(snr / 65535)
-
        return 0;
 }
 
@@ -158,10 +147,11 @@ static int firesat_set_frontend(struct dvb_frontend *fe,
 {
        struct firesat *firesat = fe->sec_priv;
 
-       if (AVCTuner_DSD(firesat, params, NULL) != ACCEPTED)
+       /* FIXME: avc_tuner_dsd never returns ACCEPTED. Check status? */
+       if (avc_tuner_dsd(firesat, params) != ACCEPTED)
                return -EINVAL;
        else
-               return 0; //not sure of this...
+               return 0; /* not sure of this... */
 }
 
 static int firesat_get_frontend(struct dvb_frontend *fe,
@@ -170,107 +160,86 @@ static int firesat_get_frontend(struct dvb_frontend *fe,
        return -EOPNOTSUPP;
 }
 
-static struct dvb_frontend_info firesat_S_frontend_info;
-static struct dvb_frontend_info firesat_C_frontend_info;
-static struct dvb_frontend_info firesat_T_frontend_info;
-
-static struct dvb_frontend_ops firesat_ops = {
+void firesat_frontend_init(struct firesat *firesat)
+{
+       struct dvb_frontend_ops *ops = &firesat->fe.ops;
+       struct dvb_frontend_info *fi = &ops->info;
 
-       .init                           = firesat_dvb_init,
-       .sleep                          = firesat_sleep,
+       ops->init                       = firesat_dvb_init;
+       ops->sleep                      = firesat_sleep;
 
-       .set_frontend                   = firesat_set_frontend,
-       .get_frontend                   = firesat_get_frontend,
+       ops->set_frontend               = firesat_set_frontend;
+       ops->get_frontend               = firesat_get_frontend;
 
-       .read_status                    = firesat_read_status,
-       .read_ber                       = firesat_read_ber,
-       .read_signal_strength           = firesat_read_signal_strength,
-       .read_snr                       = firesat_read_snr,
-       .read_ucblocks                  = firesat_read_uncorrected_blocks,
+       ops->read_status                = firesat_read_status;
+       ops->read_ber                   = firesat_read_ber;
+       ops->read_signal_strength       = firesat_read_signal_strength;
+       ops->read_snr                   = firesat_read_snr;
+       ops->read_ucblocks              = firesat_read_uncorrected_blocks;
 
-       .diseqc_send_master_cmd         = firesat_diseqc_send_master_cmd,
-       .diseqc_send_burst              = firesat_diseqc_send_burst,
-       .set_tone                       = firesat_set_tone,
-       .set_voltage                    = firesat_set_voltage,
-};
+       ops->diseqc_send_master_cmd     = firesat_diseqc_send_master_cmd;
+       ops->diseqc_send_burst          = firesat_diseqc_send_burst;
+       ops->set_tone                   = firesat_set_tone;
+       ops->set_voltage                = firesat_set_voltage;
 
-int firesat_frontend_attach(struct firesat *firesat, struct dvb_frontend *fe)
-{
        switch (firesat->type) {
        case FireSAT_DVB_S:
-               firesat->frontend_info = &firesat_S_frontend_info;
+               fi->type                = FE_QPSK;
+
+               fi->frequency_min       = 950000;
+               fi->frequency_max       = 2150000;
+               fi->frequency_stepsize  = 125;
+               fi->symbol_rate_min     = 1000000;
+               fi->symbol_rate_max     = 40000000;
+
+               fi->caps                = FE_CAN_INVERSION_AUTO |
+                                         FE_CAN_FEC_1_2        |
+                                         FE_CAN_FEC_2_3        |
+                                         FE_CAN_FEC_3_4        |
+                                         FE_CAN_FEC_5_6        |
+                                         FE_CAN_FEC_7_8        |
+                                         FE_CAN_FEC_AUTO       |
+                                         FE_CAN_QPSK;
                break;
+
        case FireSAT_DVB_C:
-               firesat->frontend_info = &firesat_C_frontend_info;
+               fi->type                = FE_QAM;
+
+               fi->frequency_min       = 47000000;
+               fi->frequency_max       = 866000000;
+               fi->frequency_stepsize  = 62500;
+               fi->symbol_rate_min     = 870000;
+               fi->symbol_rate_max     = 6900000;
+
+               fi->caps                = FE_CAN_INVERSION_AUTO |
+                                         FE_CAN_QAM_16         |
+                                         FE_CAN_QAM_32         |
+                                         FE_CAN_QAM_64         |
+                                         FE_CAN_QAM_128        |
+                                         FE_CAN_QAM_256        |
+                                         FE_CAN_QAM_AUTO;
                break;
+
        case FireSAT_DVB_T:
-               firesat->frontend_info = &firesat_T_frontend_info;
+               fi->type                = FE_OFDM;
+
+               fi->frequency_min       = 49000000;
+               fi->frequency_max       = 861000000;
+               fi->frequency_stepsize  = 62500;
+
+               fi->caps                = FE_CAN_INVERSION_AUTO         |
+                                         FE_CAN_FEC_2_3                |
+                                         FE_CAN_TRANSMISSION_MODE_AUTO |
+                                         FE_CAN_GUARD_INTERVAL_AUTO    |
+                                         FE_CAN_HIERARCHY_AUTO;
                break;
+
        default:
-               printk(KERN_ERR "firedtv: no frontend for model type 0x%x\n",
+               printk(KERN_ERR "FireDTV: no frontend for model type %d\n",
                       firesat->type);
-               firesat->frontend_info = NULL;
        }
-       fe->ops = firesat_ops;
-       fe->ops.info = *(firesat->frontend_info);
-       fe->dvb = firesat->adapter;
+       strcpy(fi->name, firedtv_model_names[firesat->type]);
 
-       return 0;
+       firesat->fe.dvb = &firesat->adapter;
+       firesat->fe.sec_priv = firesat;
 }
-
-static struct dvb_frontend_info firesat_S_frontend_info = {
-
-       .name                   = "FireDTV DVB-S Frontend",
-       .type                   = FE_QPSK,
-
-       .frequency_min          = 950000,
-       .frequency_max          = 2150000,
-       .frequency_stepsize     = 125,
-       .symbol_rate_min        = 1000000,
-       .symbol_rate_max        = 40000000,
-
-       .caps                   = FE_CAN_INVERSION_AUTO         |
-                                 FE_CAN_FEC_1_2                |
-                                 FE_CAN_FEC_2_3                |
-                                 FE_CAN_FEC_3_4                |
-                                 FE_CAN_FEC_5_6                |
-                                 FE_CAN_FEC_7_8                |
-                                 FE_CAN_FEC_AUTO               |
-                                 FE_CAN_QPSK,
-};
-
-static struct dvb_frontend_info firesat_C_frontend_info = {
-
-       .name                   = "FireDTV DVB-C Frontend",
-       .type                   = FE_QAM,
-
-       .frequency_min          = 47000000,
-       .frequency_max          = 866000000,
-       .frequency_stepsize     = 62500,
-       .symbol_rate_min        = 870000,
-       .symbol_rate_max        = 6900000,
-
-       .caps                   = FE_CAN_INVERSION_AUTO         |
-                                 FE_CAN_QAM_16                 |
-                                 FE_CAN_QAM_32                 |
-                                 FE_CAN_QAM_64                 |
-                                 FE_CAN_QAM_128                |
-                                 FE_CAN_QAM_256                |
-                                 FE_CAN_QAM_AUTO,
-};
-
-static struct dvb_frontend_info firesat_T_frontend_info = {
-
-       .name                   = "FireDTV DVB-T Frontend",
-       .type                   = FE_OFDM,
-
-       .frequency_min          = 49000000,
-       .frequency_max          = 861000000,
-       .frequency_stepsize     = 62500,
-
-       .caps                   = FE_CAN_INVERSION_AUTO         |
-                                 FE_CAN_FEC_2_3                |
-                                 FE_CAN_TRANSMISSION_MODE_AUTO |
-                                 FE_CAN_GUARD_INTERVAL_AUTO    |
-                                 FE_CAN_HIERARCHY_AUTO,
-};