V4L/DVB (9227): MFE: Add multi-frontend mutual exclusion
[safe/jmp/linux-2.6] / drivers / media / video / saa7134 / saa7134-dvb.c
index 5b65aa2..d2d2389 100644 (file)
@@ -65,6 +65,8 @@ static int debug;
 module_param(debug, int, 0644);
 MODULE_PARM_DESC(debug, "Turn on/off module debugging (default:off).");
 
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
 #define dprintk(fmt, arg...)   do { if (debug) \
        printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg); } while(0)
 
@@ -151,6 +153,23 @@ static int mt352_aver777_init(struct dvb_frontend* fe)
        return 0;
 }
 
+static int mt352_avermedia_xc3028_init(struct dvb_frontend *fe)
+{
+       static u8 clock_config []  = { CLOCK_CTL, 0x38, 0x2d };
+       static u8 reset []         = { RESET, 0x80 };
+       static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
+       static u8 agc_cfg []       = { AGC_TARGET, 0xe };
+       static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
+
+       mt352_write(fe, clock_config,   sizeof(clock_config));
+       udelay(200);
+       mt352_write(fe, reset,          sizeof(reset));
+       mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
+       mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
+       mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
+       return 0;
+}
+
 static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe,
                                           struct dvb_frontend_parameters* params)
 {
@@ -193,9 +212,10 @@ static struct mt352_config avermedia_777 = {
        .demod_init    = mt352_aver777_init,
 };
 
-static struct mt352_config avermedia_e506r_mt352_dev = {
+static struct mt352_config avermedia_xc3028_mt352_dev = {
        .demod_address   = (0x1e >> 1),
        .no_tuner        = 1,
+       .demod_init      = mt352_avermedia_xc3028_init,
 };
 
 /* ==================================================================
@@ -511,25 +531,33 @@ static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
        return 0;
 }
 
-static void configure_tda827x_fe(struct saa7134_dev *dev, struct tda1004x_config *cdec_conf,
-                                                         struct tda827x_config *tuner_conf)
+static int configure_tda827x_fe(struct saa7134_dev *dev,
+                               struct tda1004x_config *cdec_conf,
+                               struct tda827x_config *tuner_conf)
 {
-       dev->dvb.frontend = dvb_attach(tda10046_attach, cdec_conf, &dev->i2c_adap);
-       if (dev->dvb.frontend) {
+       struct videobuf_dvb_frontend *fe0;
+
+       /* Get the first frontend */
+       fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
+
+       fe0->dvb.frontend = dvb_attach(tda10046_attach, cdec_conf, &dev->i2c_adap);
+       if (fe0->dvb.frontend) {
                if (cdec_conf->i2c_gate)
-                       dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
-               if (dvb_attach(tda827x_attach, dev->dvb.frontend, cdec_conf->tuner_address,
-                                                       &dev->i2c_adap, tuner_conf) == NULL) {
-                       wprintk("no tda827x tuner found at addr: %02x\n",
+                       fe0->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
+               if (dvb_attach(tda827x_attach, fe0->dvb.frontend,
+                              cdec_conf->tuner_address,
+                              &dev->i2c_adap, tuner_conf))
+                       return 0;
+
+               wprintk("no tda827x tuner found at addr: %02x\n",
                                cdec_conf->tuner_address);
-               }
        }
+       return -EINVAL;
 }
 
 /* ------------------------------------------------------------------ */
 
 static struct tda827x_config tda827x_cfg_0 = {
-       .tuner_callback = saa7134_tuner_callback,
        .init = philips_tda827x_tuner_init,
        .sleep = philips_tda827x_tuner_sleep,
        .config = 0,
@@ -537,7 +565,6 @@ static struct tda827x_config tda827x_cfg_0 = {
 };
 
 static struct tda827x_config tda827x_cfg_1 = {
-       .tuner_callback = saa7134_tuner_callback,
        .init = philips_tda827x_tuner_init,
        .sleep = philips_tda827x_tuner_sleep,
        .config = 1,
@@ -545,7 +572,6 @@ static struct tda827x_config tda827x_cfg_1 = {
 };
 
 static struct tda827x_config tda827x_cfg_2 = {
-       .tuner_callback = saa7134_tuner_callback,
        .init = philips_tda827x_tuner_init,
        .sleep = philips_tda827x_tuner_sleep,
        .config = 2,
@@ -553,7 +579,6 @@ static struct tda827x_config tda827x_cfg_2 = {
 };
 
 static struct tda827x_config tda827x_cfg_2_sw42 = {
-       .tuner_callback = saa7134_tuner_callback,
        .init = philips_tda827x_tuner_init,
        .sleep = philips_tda827x_tuner_sleep,
        .config = 2,
@@ -775,6 +800,20 @@ static struct tda1004x_config twinhan_dtv_dvb_3056_config = {
        .request_firmware = philips_tda1004x_request_firmware
 };
 
+static struct tda1004x_config asus_tiger_3in1_config = {
+       .demod_address = 0x0b,
+       .invert        = 1,
+       .invert_oclk   = 0,
+       .xtal_freq     = TDA10046_XTAL_16M,
+       .agc_config    = TDA10046_AGC_TDA827X,
+       .gpio_config   = TDA10046_GP11_I,
+       .if_freq       = TDA10046_FREQ_045,
+       .i2c_gate      = 0x4b,
+       .tuner_address = 0x61,
+       .antenna_switch = 1,
+       .request_firmware = philips_tda1004x_request_firmware
+};
+
 /* ------------------------------------------------------------------
  * special case: this card uses saa713x GPIO22 for the mode switch
  */
@@ -798,7 +837,6 @@ static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
 }
 
 static struct tda827x_config ads_duo_cfg = {
-       .tuner_callback = saa7134_tuner_callback,
        .init = ads_duo_tuner_init,
        .sleep = ads_duo_tuner_sleep,
        .config = 0
@@ -824,6 +862,14 @@ static struct tda10086_config flydvbs = {
        .demod_address = 0x0e,
        .invert = 0,
        .diseqc_tone = 0,
+       .xtal_freq = TDA10086_XTAL_16M,
+};
+
+static struct tda10086_config sd1878_4m = {
+       .demod_address = 0x0e,
+       .invert = 0,
+       .diseqc_tone = 0,
+       .xtal_freq = TDA10086_XTAL_4M,
 };
 
 /* ------------------------------------------------------------------
@@ -903,12 +949,30 @@ static int dvb_init(struct saa7134_dev *dev)
 {
        int ret;
        int attach_xc3028 = 0;
+       struct videobuf_dvb_frontend *fe0;
+
+       /* FIXME: add support for multi-frontend */
+       mutex_init(&dev->frontends.lock);
+       INIT_LIST_HEAD(&dev->frontends.frontend.felist);
+       dev->frontends.active_fe_id = 0;
+
+       printk(KERN_INFO "%s() allocating 1 frontend\n", __func__);
+
+       if (videobuf_dvb_alloc_frontend(dev, &dev->frontends, 1) == NULL) {
+               printk(KERN_ERR "%s() failed to alloc\n", __func__);
+               return -ENOMEM;
+       }
+
+       /* Get the first frontend */
+       fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
+       if (!fe0)
+               return -EINVAL;
 
        /* init struct videobuf_dvb */
        dev->ts.nr_bufs    = 32;
        dev->ts.nr_packets = 32*4;
-       dev->dvb.name = dev->name;
-       videobuf_queue_sg_init(&dev->dvb.dvbq, &saa7134_ts_qops,
+       fe0->dvb.name = dev->name;
+       videobuf_queue_sg_init(&fe0->dvb.dvbq, &saa7134_ts_qops,
                            &dev->pci->dev, &dev->slock,
                            V4L2_BUF_TYPE_VIDEO_CAPTURE,
                            V4L2_FIELD_ALTERNATE,
@@ -918,142 +982,178 @@ static int dvb_init(struct saa7134_dev *dev)
        switch (dev->board) {
        case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
                dprintk("pinnacle 300i dvb setup\n");
-               dev->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
+               fe0->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
                                               &dev->i2c_adap);
-               if (dev->dvb.frontend) {
-                       dev->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
+               if (fe0->dvb.frontend) {
+                       fe0->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
                }
                break;
        case SAA7134_BOARD_AVERMEDIA_777:
        case SAA7134_BOARD_AVERMEDIA_A16AR:
                dprintk("avertv 777 dvb setup\n");
-               dev->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
+               fe0->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
                                               &dev->i2c_adap);
-               if (dev->dvb.frontend) {
-                       dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
-                                  NULL, DVB_PLL_PHILIPS_TD1316);
+               if (fe0->dvb.frontend) {
+                       dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
+                                  &dev->i2c_adap, 0x61,
+                                  TUNER_PHILIPS_TD1316);
                }
                break;
+       case SAA7134_BOARD_AVERMEDIA_A16D:
+               dprintk("AverMedia A16D dvb setup\n");
+               fe0->dvb.frontend = dvb_attach(mt352_attach,
+                                               &avermedia_xc3028_mt352_dev,
+                                               &dev->i2c_adap);
+               attach_xc3028 = 1;
+               break;
        case SAA7134_BOARD_MD7134:
-               dev->dvb.frontend = dvb_attach(tda10046_attach,
+               fe0->dvb.frontend = dvb_attach(tda10046_attach,
                                               &medion_cardbus,
                                               &dev->i2c_adap);
-               if (dev->dvb.frontend) {
-                       dvb_attach(simple_tuner_attach, dev->dvb.frontend,
+               if (fe0->dvb.frontend) {
+                       dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
                                   &dev->i2c_adap, medion_cardbus.tuner_address,
                                   TUNER_PHILIPS_FMD1216ME_MK3);
                }
                break;
        case SAA7134_BOARD_PHILIPS_TOUGH:
-               dev->dvb.frontend = dvb_attach(tda10046_attach,
+               fe0->dvb.frontend = dvb_attach(tda10046_attach,
                                               &philips_tu1216_60_config,
                                               &dev->i2c_adap);
-               if (dev->dvb.frontend) {
-                       dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
-                       dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
+               if (fe0->dvb.frontend) {
+                       fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
+                       fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
                }
                break;
        case SAA7134_BOARD_FLYDVBTDUO:
        case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
-               configure_tda827x_fe(dev, &tda827x_lifeview_config, &tda827x_cfg_0);
+               if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
+                                        &tda827x_cfg_0) < 0)
+                       goto dettach_frontend;
                break;
        case SAA7134_BOARD_PHILIPS_EUROPA:
        case SAA7134_BOARD_VIDEOMATE_DVBT_300:
-               dev->dvb.frontend = dvb_attach(tda10046_attach,
+               fe0->dvb.frontend = dvb_attach(tda10046_attach,
                                               &philips_europa_config,
                                               &dev->i2c_adap);
-               if (dev->dvb.frontend) {
-                       dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
-                       dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
-                       dev->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
-                       dev->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
-                       dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
+               if (fe0->dvb.frontend) {
+                       dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
+                       fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
+                       fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
+                       fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
+                       fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
                }
                break;
        case SAA7134_BOARD_VIDEOMATE_DVBT_200:
-               dev->dvb.frontend = dvb_attach(tda10046_attach,
+               fe0->dvb.frontend = dvb_attach(tda10046_attach,
                                               &philips_tu1216_61_config,
                                               &dev->i2c_adap);
-               if (dev->dvb.frontend) {
-                       dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
-                       dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
+               if (fe0->dvb.frontend) {
+                       fe0->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
+                       fe0->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
                }
                break;
        case SAA7134_BOARD_KWORLD_DVBT_210:
-               configure_tda827x_fe(dev, &kworld_dvb_t_210_config, &tda827x_cfg_2);
+               if (configure_tda827x_fe(dev, &kworld_dvb_t_210_config,
+                                        &tda827x_cfg_2) < 0)
+                       goto dettach_frontend;
                break;
        case SAA7134_BOARD_PHILIPS_TIGER:
-               configure_tda827x_fe(dev, &philips_tiger_config, &tda827x_cfg_0);
+               if (configure_tda827x_fe(dev, &philips_tiger_config,
+                                        &tda827x_cfg_0) < 0)
+                       goto dettach_frontend;
                break;
        case SAA7134_BOARD_PINNACLE_PCTV_310i:
-               configure_tda827x_fe(dev, &pinnacle_pctv_310i_config, &tda827x_cfg_1);
+               if (configure_tda827x_fe(dev, &pinnacle_pctv_310i_config,
+                                        &tda827x_cfg_1) < 0)
+                       goto dettach_frontend;
                break;
        case SAA7134_BOARD_HAUPPAUGE_HVR1110:
-               configure_tda827x_fe(dev, &hauppauge_hvr_1110_config, &tda827x_cfg_1);
+               if (configure_tda827x_fe(dev, &hauppauge_hvr_1110_config,
+                                        &tda827x_cfg_1) < 0)
+                       goto dettach_frontend;
                break;
        case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
-               configure_tda827x_fe(dev, &asus_p7131_dual_config, &tda827x_cfg_0);
+               if (configure_tda827x_fe(dev, &asus_p7131_dual_config,
+                                        &tda827x_cfg_0) < 0)
+                       goto dettach_frontend;
                break;
        case SAA7134_BOARD_FLYDVBT_LR301:
-               configure_tda827x_fe(dev, &tda827x_lifeview_config, &tda827x_cfg_0);
+               if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
+                                        &tda827x_cfg_0) < 0)
+                       goto dettach_frontend;
                break;
        case SAA7134_BOARD_FLYDVB_TRIO:
-               if(! use_frontend) {    /* terrestrial */
-                       configure_tda827x_fe(dev, &lifeview_trio_config, &tda827x_cfg_0);
+               if (!use_frontend) {    /* terrestrial */
+                       if (configure_tda827x_fe(dev, &lifeview_trio_config,
+                                                &tda827x_cfg_0) < 0)
+                               goto dettach_frontend;
                } else {                /* satellite */
-                       dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
-                       if (dev->dvb.frontend) {
-                               if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x63,
+                       fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
+                       if (fe0->dvb.frontend) {
+                               if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x63,
                                                                        &dev->i2c_adap, 0) == NULL) {
                                        wprintk("%s: Lifeview Trio, No tda826x found!\n", __func__);
+                                       goto dettach_frontend;
                                }
-                               if (dvb_attach(isl6421_attach, dev->dvb.frontend, &dev->i2c_adap,
+                               if (dvb_attach(isl6421_attach, fe0->dvb.frontend, &dev->i2c_adap,
                                                                                0x08, 0, 0) == NULL) {
                                        wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __func__);
+                                       goto dettach_frontend;
                                }
                        }
                }
                break;
        case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
        case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
-               dev->dvb.frontend = dvb_attach(tda10046_attach,
+               fe0->dvb.frontend = dvb_attach(tda10046_attach,
                                               &ads_tech_duo_config,
                                               &dev->i2c_adap);
-               if (dev->dvb.frontend) {
-                       if (dvb_attach(tda827x_attach,dev->dvb.frontend,
+               if (fe0->dvb.frontend) {
+                       if (dvb_attach(tda827x_attach,fe0->dvb.frontend,
                                   ads_tech_duo_config.tuner_address, &dev->i2c_adap,
                                                                &ads_duo_cfg) == NULL) {
                                wprintk("no tda827x tuner found at addr: %02x\n",
                                        ads_tech_duo_config.tuner_address);
+                               goto dettach_frontend;
                        }
-               }
+               } else
+                       wprintk("failed to attach tda10046\n");
                break;
        case SAA7134_BOARD_TEVION_DVBT_220RF:
-               configure_tda827x_fe(dev, &tevion_dvbt220rf_config, &tda827x_cfg_0);
+               if (configure_tda827x_fe(dev, &tevion_dvbt220rf_config,
+                                        &tda827x_cfg_0) < 0)
+                       goto dettach_frontend;
                break;
        case SAA7134_BOARD_MEDION_MD8800_QUADRO:
                if (!use_frontend) {     /* terrestrial */
-                       configure_tda827x_fe(dev, &md8800_dvbt_config, &tda827x_cfg_0);
+                       if (configure_tda827x_fe(dev, &md8800_dvbt_config,
+                                                &tda827x_cfg_0) < 0)
+                               goto dettach_frontend;
                } else {        /* satellite */
-                       dev->dvb.frontend = dvb_attach(tda10086_attach,
+                       fe0->dvb.frontend = dvb_attach(tda10086_attach,
                                                        &flydvbs, &dev->i2c_adap);
-                       if (dev->dvb.frontend) {
-                               struct dvb_frontend *fe = dev->dvb.frontend;
+                       if (fe0->dvb.frontend) {
+                               struct dvb_frontend *fe = fe0->dvb.frontend;
                                u8 dev_id = dev->eedata[2];
                                u8 data = 0xc4;
                                struct i2c_msg msg = {.addr = 0x08, .flags = 0, .len = 1};
 
-                               if (dvb_attach(tda826x_attach, dev->dvb.frontend,
-                                               0x60, &dev->i2c_adap, 0) == NULL)
+                               if (dvb_attach(tda826x_attach, fe0->dvb.frontend,
+                                               0x60, &dev->i2c_adap, 0) == NULL) {
                                        wprintk("%s: Medion Quadro, no tda826x "
                                                "found !\n", __func__);
+                                       goto dettach_frontend;
+                               }
                                if (dev_id != 0x08) {
                                        /* we need to open the i2c gate (we know it exists) */
                                        fe->ops.i2c_gate_ctrl(fe, 1);
                                        if (dvb_attach(isl6405_attach, fe,
-                                                       &dev->i2c_adap, 0x08, 0, 0) == NULL)
+                                                       &dev->i2c_adap, 0x08, 0, 0) == NULL) {
                                                wprintk("%s: Medion Quadro, no ISL6405 "
                                                        "found !\n", __func__);
+                                               goto dettach_frontend;
+                                       }
                                        if (dev_id == 0x07) {
                                                /* fire up the 2nd section of the LNB supply since
                                                   we can't do this from the other section */
@@ -1073,118 +1173,150 @@ static int dvb_init(struct saa7134_dev *dev)
                }
                break;
        case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
-               dev->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
+               fe0->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
                                               &dev->i2c_adap);
-               if (dev->dvb.frontend) {
-                       dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
+               if (fe0->dvb.frontend)
+                       dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x61,
                                   NULL, DVB_PLL_TDHU2);
-               }
                break;
+       case SAA7134_BOARD_ADS_INSTANT_HDTV_PCI:
        case SAA7134_BOARD_KWORLD_ATSC110:
-               dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
+               fe0->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
                                               &dev->i2c_adap);
-               if (dev->dvb.frontend) {
-                       dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
-                                  NULL, DVB_PLL_TUV1236D);
-               }
+               if (fe0->dvb.frontend)
+                       dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
+                                  &dev->i2c_adap, 0x61,
+                                  TUNER_PHILIPS_TUV1236D);
                break;
        case SAA7134_BOARD_FLYDVBS_LR300:
-               dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
+               fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
                                               &dev->i2c_adap);
-               if (dev->dvb.frontend) {
-                       if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
+               if (fe0->dvb.frontend) {
+                       if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
                                       &dev->i2c_adap, 0) == NULL) {
                                wprintk("%s: No tda826x found!\n", __func__);
+                               goto dettach_frontend;
                        }
-                       if (dvb_attach(isl6421_attach, dev->dvb.frontend,
+                       if (dvb_attach(isl6421_attach, fe0->dvb.frontend,
                                       &dev->i2c_adap, 0x08, 0, 0) == NULL) {
                                wprintk("%s: No ISL6421 found!\n", __func__);
+                               goto dettach_frontend;
                        }
                }
                break;
        case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
-               dev->dvb.frontend = dvb_attach(tda10046_attach,
+               fe0->dvb.frontend = dvb_attach(tda10046_attach,
                                               &medion_cardbus,
                                               &dev->i2c_adap);
-               if (dev->dvb.frontend) {
-                       dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
-                       dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
+               if (fe0->dvb.frontend) {
+                       dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
+                       fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
 
-                       dvb_attach(simple_tuner_attach, dev->dvb.frontend,
+                       dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
                                   &dev->i2c_adap, medion_cardbus.tuner_address,
                                   TUNER_PHILIPS_FMD1216ME_MK3);
                }
                break;
        case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
-               dev->dvb.frontend = dvb_attach(tda10046_attach,
+               fe0->dvb.frontend = dvb_attach(tda10046_attach,
                                &philips_europa_config,
                                &dev->i2c_adap);
-               if (dev->dvb.frontend) {
-                       dev->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
-                       dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
+               if (fe0->dvb.frontend) {
+                       fe0->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
+                       fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
                }
                break;
        case SAA7134_BOARD_CINERGY_HT_PCMCIA:
-               configure_tda827x_fe(dev, &cinergy_ht_config, &tda827x_cfg_0);
+               if (configure_tda827x_fe(dev, &cinergy_ht_config,
+                                        &tda827x_cfg_0) < 0)
+                       goto dettach_frontend;
                break;
        case SAA7134_BOARD_CINERGY_HT_PCI:
-               configure_tda827x_fe(dev, &cinergy_ht_pci_config, &tda827x_cfg_0);
+               if (configure_tda827x_fe(dev, &cinergy_ht_pci_config,
+                                        &tda827x_cfg_0) < 0)
+                       goto dettach_frontend;
                break;
        case SAA7134_BOARD_PHILIPS_TIGER_S:
-               configure_tda827x_fe(dev, &philips_tiger_s_config, &tda827x_cfg_2);
+               if (configure_tda827x_fe(dev, &philips_tiger_s_config,
+                                        &tda827x_cfg_2) < 0)
+                       goto dettach_frontend;
                break;
        case SAA7134_BOARD_ASUS_P7131_4871:
-               configure_tda827x_fe(dev, &asus_p7131_4871_config, &tda827x_cfg_2);
+               if (configure_tda827x_fe(dev, &asus_p7131_4871_config,
+                                        &tda827x_cfg_2) < 0)
+                       goto dettach_frontend;
                break;
        case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
-               configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config, &tda827x_cfg_2);
+               if (configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config,
+                                        &tda827x_cfg_2) < 0)
+                       goto dettach_frontend;
                break;
        case SAA7134_BOARD_AVERMEDIA_SUPER_007:
-               configure_tda827x_fe(dev, &avermedia_super_007_config, &tda827x_cfg_0);
+               if (configure_tda827x_fe(dev, &avermedia_super_007_config,
+                                        &tda827x_cfg_0) < 0)
+                       goto dettach_frontend;
                break;
        case SAA7134_BOARD_TWINHAN_DTV_DVB_3056:
-               configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config, &tda827x_cfg_2_sw42);
+               if (configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config,
+                                        &tda827x_cfg_2_sw42) < 0)
+                       goto dettach_frontend;
                break;
        case SAA7134_BOARD_PHILIPS_SNAKE:
-               dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
+               fe0->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
                                                &dev->i2c_adap);
-               if (dev->dvb.frontend) {
-                       if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
-                                       &dev->i2c_adap, 0) == NULL)
+               if (fe0->dvb.frontend) {
+                       if (dvb_attach(tda826x_attach, fe0->dvb.frontend, 0x60,
+                                       &dev->i2c_adap, 0) == NULL) {
                                wprintk("%s: No tda826x found!\n", __func__);
-                       if (dvb_attach(lnbp21_attach, dev->dvb.frontend,
-                                       &dev->i2c_adap, 0, 0) == NULL)
+                               goto dettach_frontend;
+                       }
+                       if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
+                                       &dev->i2c_adap, 0, 0) == NULL) {
                                wprintk("%s: No lnbp21 found!\n", __func__);
+                               goto dettach_frontend;
+                       }
                }
                break;
        case SAA7134_BOARD_CREATIX_CTX953:
-               configure_tda827x_fe(dev, &md8800_dvbt_config, &tda827x_cfg_0);
+               if (configure_tda827x_fe(dev, &md8800_dvbt_config,
+                                        &tda827x_cfg_0) < 0)
+                       goto dettach_frontend;
                break;
        case SAA7134_BOARD_MSI_TVANYWHERE_AD11:
-               configure_tda827x_fe(dev, &philips_tiger_s_config, &tda827x_cfg_2);
+               if (configure_tda827x_fe(dev, &philips_tiger_s_config,
+                                        &tda827x_cfg_2) < 0)
+                       goto dettach_frontend;
                break;
        case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
-               dev->dvb.frontend = dvb_attach(mt352_attach,
-                                              &avermedia_e506r_mt352_dev,
-                                              &dev->i2c_adap);
+               dprintk("AverMedia E506R dvb setup\n");
+               saa7134_set_gpio(dev, 25, 0);
+               msleep(10);
+               saa7134_set_gpio(dev, 25, 1);
+               fe0->dvb.frontend = dvb_attach(mt352_attach,
+                                               &avermedia_xc3028_mt352_dev,
+                                               &dev->i2c_adap);
                attach_xc3028 = 1;
                break;
        case SAA7134_BOARD_MD7134_BRIDGE_2:
-               dev->dvb.frontend = dvb_attach(tda10086_attach,
-                                               &flydvbs, &dev->i2c_adap);
-               if (dev->dvb.frontend) {
+               fe0->dvb.frontend = dvb_attach(tda10086_attach,
+                                               &sd1878_4m, &dev->i2c_adap);
+               if (fe0->dvb.frontend) {
                        struct dvb_frontend *fe;
-                       if (dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x60,
-                                 &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL)
+                       if (dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x60,
+                                 &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL) {
                                wprintk("%s: MD7134 DVB-S, no SD1878 "
                                        "found !\n", __func__);
+                               goto dettach_frontend;
+                       }
                        /* we need to open the i2c gate (we know it exists) */
-                       fe = dev->dvb.frontend;
+                       fe = fe0->dvb.frontend;
                        fe->ops.i2c_gate_ctrl(fe, 1);
                        if (dvb_attach(isl6405_attach, fe,
-                                       &dev->i2c_adap, 0x08, 0, 0) == NULL)
+                                       &dev->i2c_adap, 0x08, 0, 0) == NULL) {
                                wprintk("%s: MD7134 DVB-S, no ISL6405 "
                                        "found !\n", __func__);
+                               goto dettach_frontend;
+                       }
                        fe->ops.i2c_gate_ctrl(fe, 0);
                        dev->original_set_voltage = fe->ops.set_voltage;
                        fe->ops.set_voltage = md8800_set_voltage;
@@ -1192,6 +1324,45 @@ static int dvb_init(struct saa7134_dev *dev)
                        fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
                }
                break;
+       case SAA7134_BOARD_AVERMEDIA_M103:
+               saa7134_set_gpio(dev, 25, 0);
+               msleep(10);
+               saa7134_set_gpio(dev, 25, 1);
+               fe0->dvb.frontend = dvb_attach(mt352_attach,
+                                               &avermedia_xc3028_mt352_dev,
+                                               &dev->i2c_adap);
+               attach_xc3028 = 1;
+               break;
+       case SAA7134_BOARD_ASUSTeK_TIGER_3IN1:
+               if (!use_frontend) {     /* terrestrial */
+                       if (configure_tda827x_fe(dev, &asus_tiger_3in1_config,
+                                                       &tda827x_cfg_2) < 0)
+                               goto dettach_frontend;
+               } else {                /* satellite */
+                       fe0->dvb.frontend = dvb_attach(tda10086_attach,
+                                               &flydvbs, &dev->i2c_adap);
+                       if (fe0->dvb.frontend) {
+                               if (dvb_attach(tda826x_attach,
+                                               fe0->dvb.frontend, 0x60,
+                                               &dev->i2c_adap, 0) == NULL) {
+                                       wprintk("%s: Asus Tiger 3in1, no "
+                                               "tda826x found!\n", __func__);
+                                       goto dettach_frontend;
+                               }
+                               if (dvb_attach(lnbp21_attach, fe0->dvb.frontend,
+                                               &dev->i2c_adap, 0, 0) == NULL) {
+                                       wprintk("%s: Asus Tiger 3in1, no lnbp21"
+                                               " found!\n", __func__);
+                                       goto dettach_frontend;
+                               }
+                       }
+               }
+               break;
+       case SAA7134_BOARD_ASUSTeK_TIGER:
+               if (configure_tda827x_fe(dev, &philips_tiger_config,
+                                        &tda827x_cfg_0) < 0)
+                       goto dettach_frontend;
+               break;
        default:
                wprintk("Huh? unknown DVB card?\n");
                break;
@@ -1203,41 +1374,59 @@ static int dvb_init(struct saa7134_dev *dev)
                        .i2c_adap  = &dev->i2c_adap,
                        .i2c_addr  = 0x61,
                };
-               fe = dvb_attach(xc2028_attach, dev->dvb.frontend, &cfg);
+
+               if (!fe0->dvb.frontend)
+                       return -1;
+
+               fe = dvb_attach(xc2028_attach, fe0->dvb.frontend, &cfg);
                if (!fe) {
                        printk(KERN_ERR "%s/2: xc3028 attach failed\n",
                               dev->name);
-                       dvb_frontend_detach(dev->dvb.frontend);
-                       dvb_unregister_frontend(dev->dvb.frontend);
-                       dev->dvb.frontend = NULL;
-                       return -1;
+                       goto dettach_frontend;
                }
        }
 
-       if (NULL == dev->dvb.frontend) {
+       if (NULL == fe0->dvb.frontend) {
                printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name);
                return -1;
        }
+       /* define general-purpose callback pointer */
+       fe0->dvb.frontend->callback = saa7134_tuner_callback;
 
        /* register everything else */
-       ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev);
+       ret = videobuf_dvb_register_bus(&dev->frontends, THIS_MODULE, dev,
+               &dev->pci->dev, adapter_nr, 0);
 
        /* this sequence is necessary to make the tda1004x load its firmware
         * and to enter analog mode of hybrid boards
         */
        if (!ret) {
-               if (dev->dvb.frontend->ops.init)
-                       dev->dvb.frontend->ops.init(dev->dvb.frontend);
-               if (dev->dvb.frontend->ops.sleep)
-                       dev->dvb.frontend->ops.sleep(dev->dvb.frontend);
-               if (dev->dvb.frontend->ops.tuner_ops.sleep)
-                       dev->dvb.frontend->ops.tuner_ops.sleep(dev->dvb.frontend);
+               if (fe0->dvb.frontend->ops.init)
+                       fe0->dvb.frontend->ops.init(fe0->dvb.frontend);
+               if (fe0->dvb.frontend->ops.sleep)
+                       fe0->dvb.frontend->ops.sleep(fe0->dvb.frontend);
+               if (fe0->dvb.frontend->ops.tuner_ops.sleep)
+                       fe0->dvb.frontend->ops.tuner_ops.sleep(fe0->dvb.frontend);
        }
        return ret;
+
+dettach_frontend:
+       if (fe0->dvb.frontend)
+               dvb_frontend_detach(fe0->dvb.frontend);
+       fe0->dvb.frontend = NULL;
+
+       return -1;
 }
 
 static int dvb_fini(struct saa7134_dev *dev)
 {
+       struct videobuf_dvb_frontend *fe0;
+
+       /* Get the first frontend */
+       fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
+       if (!fe0)
+               return -EINVAL;
+
        /* FIXME: I suspect that this code is bogus, since the entry for
           Pinnacle 300I DVB-T PAL already defines the proper init to allow
           the detection of mt2032 (TDA9887_PORT2_INACTIVE)
@@ -1257,7 +1446,7 @@ static int dvb_fini(struct saa7134_dev *dev)
                        u8 data = 0x80;
                        struct i2c_msg msg = {.addr = 0x08, .buf = &data, .flags = 0, .len = 1};
                        struct dvb_frontend *fe;
-                       fe = dev->dvb.frontend;
+                       fe = fe0->dvb.frontend;
                        if (fe->ops.i2c_gate_ctrl) {
                                fe->ops.i2c_gate_ctrl(fe, 1);
                                i2c_transfer(&dev->i2c_adap, &msg, 1);
@@ -1265,7 +1454,8 @@ static int dvb_fini(struct saa7134_dev *dev)
                        }
                }
        }
-       videobuf_dvb_unregister(&dev->dvb);
+       if (fe0->dvb.frontend)
+               videobuf_dvb_unregister_bus(&dev->frontends);
        return 0;
 }