V4L/DVB (7375): cx88/saa7134: fix magic number for xc3028 reusage detection
[linux-2.6-block.git] / drivers / media / video / cx88 / cx88-dvb.c
index c786d951a04bda18b30231cc1a5cce445423fc0a..37ebfcc6be55df3016fcc3fe7a6a3df6647bd69c 100644 (file)
@@ -237,6 +237,19 @@ static struct zl10353_config dvico_fusionhdtv_hybrid = {
        .no_tuner      = 1,
 };
 
+static struct zl10353_config dvico_fusionhdtv_xc3028 = {
+       .demod_address = 0x0f,
+       .if2           = 45600,
+       .no_tuner      = 1,
+};
+
+static struct mt352_config dvico_fusionhdtv_mt352_xc3028 = {
+       .demod_address = 0x0f,
+       .if2 = 4560,
+       .no_tuner = 1,
+       .demod_init = dvico_fusionhdtv_demod_init,
+};
+
 static struct zl10353_config dvico_fusionhdtv_plus_v1_1 = {
        .demod_address = 0x0f,
 };
@@ -359,7 +372,7 @@ static int geniatech_dvbs_set_voltage(struct dvb_frontend *fe,
        return 0;
 }
 
-static int cx88_xc3028_callback(void *ptr, int command, int arg)
+static int cx88_pci_nano_callback(void *ptr, int command, int arg)
 {
        struct cx88_core *core = ptr;
 
@@ -439,11 +452,40 @@ static struct zl10353_config cx88_geniatech_x8000_mt = {
        .no_tuner = 1,
 };
 
+static int attach_xc3028(u8 addr, struct cx8802_dev *dev)
+{
+       struct dvb_frontend *fe;
+       struct xc2028_config cfg = {
+               .i2c_adap  = &dev->core->i2c_adap,
+               .i2c_addr  = addr,
+               .video_dev = dev->core->i2c_adap.algo_data,
+       };
+
+       if (!dev->dvb.frontend) {
+               printk(KERN_ERR "%s/2: dvb frontend not attached. "
+                               "Can't attach xc3028\n",
+                      dev->core->name);
+               return -EINVAL;
+       }
+
+       fe = dvb_attach(xc2028_attach, dev->dvb.frontend, &cfg);
+       if (!fe) {
+               printk(KERN_ERR "%s/2: xc3028 attach failed\n",
+                      dev->core->name);
+               dvb_frontend_detach(dev->dvb.frontend);
+               dvb_unregister_frontend(dev->dvb.frontend);
+               dev->dvb.frontend = NULL;
+               return -EINVAL;
+       }
+
+       printk(KERN_INFO "%s/2: xc3028 attached\n",
+              dev->core->name);
+
+       return 0;
+}
 
 static int dvb_register(struct cx8802_dev *dev)
 {
-       int attach_xc3028 = 0;
-
        /* init struct videobuf_dvb */
        dev->dvb.name = dev->core->name;
        dev->ts_gen_cntrl = 0x0c;
@@ -567,6 +609,24 @@ static int dvb_register(struct cx8802_dev *dev)
                                   DVB_PLL_THOMSON_FE6600);
                }
                break;
+       case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO:
+               dev->dvb.frontend = dvb_attach(zl10353_attach,
+                                              &dvico_fusionhdtv_xc3028,
+                                              &dev->core->i2c_adap);
+               if (dev->dvb.frontend == NULL)
+                       dev->dvb.frontend = dvb_attach(mt352_attach,
+                                               &dvico_fusionhdtv_mt352_xc3028,
+                                               &dev->core->i2c_adap);
+               /*
+                * On this board, the demod provides the I2C bus pullup.
+                * We must not permit gate_ctrl to be performed, or
+                * the xc3028 cannot communicate on the bus.
+                */
+               if (dev->dvb.frontend)
+                       dev->dvb.frontend->ops.i2c_gate_ctrl = NULL;
+               if (attach_xc3028(0x61, dev) < 0)
+                       return -EINVAL;
+               break;
        case CX88_BOARD_PCHDTV_HD3000:
                dev->dvb.frontend = dvb_attach(or51132_attach, &pchdtv_hd3000,
                                               &dev->core->i2c_adap);
@@ -721,7 +781,7 @@ static int dvb_register(struct cx8802_dev *dev)
                                .i2c_adap  = &dev->core->i2c_adap,
                                .i2c_addr  = 0x61,
                                .video_dev = dev->core,
-                               .callback  = cx88_xc3028_callback,
+                               .callback  = cx88_pci_nano_callback,
                        };
                        static struct xc2028_ctrl ctl = {
                                .fname       = "xc3028-v27.fw",
@@ -739,7 +799,8 @@ static int dvb_register(struct cx8802_dev *dev)
                dev->dvb.frontend = dvb_attach(zl10353_attach,
                                               &cx88_geniatech_x8000_mt,
                                               &dev->core->i2c_adap);
-               attach_xc3028 = 1;
+               if (attach_xc3028(0x61, dev) < 0)
+                       return -EINVAL;
                break;
         case CX88_BOARD_GENIATECH_X8000_MT:
               dev->ts_gen_cntrl = 0x00;
@@ -747,7 +808,8 @@ static int dvb_register(struct cx8802_dev *dev)
                dev->dvb.frontend = dvb_attach(zl10353_attach,
                                               &cx88_geniatech_x8000_mt,
                                               &dev->core->i2c_adap);
-               attach_xc3028 = 1;
+               if (attach_xc3028(0x61, dev) < 0)
+                       return -EINVAL;
                break;
        default:
                printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n",
@@ -758,25 +820,7 @@ static int dvb_register(struct cx8802_dev *dev)
                printk(KERN_ERR
                       "%s/2: frontend initialization failed\n",
                       dev->core->name);
-               return -1;
-       }
-
-       if (attach_xc3028) {
-               struct dvb_frontend *fe;
-               struct xc2028_config cfg = {
-                       .i2c_adap  = &dev->core->i2c_adap,
-                       .i2c_addr  = 0x61,
-                       .video_dev = dev->core,
-               };
-               fe = dvb_attach(xc2028_attach, dev->dvb.frontend, &cfg);
-               if (!fe) {
-                       printk(KERN_ERR "%s/2: xc3028 attach failed\n",
-                              dev->core->name);
-                       dvb_frontend_detach(dev->dvb.frontend);
-                       dvb_unregister_frontend(dev->dvb.frontend);
-                       dev->dvb.frontend = NULL;
-                       return -1;
-               }
+               return -EINVAL;
        }
 
        /* Ensure all frontends negotiate bus access */