V4L/DVB (11380): v4l2-subdev: change s_routing prototype
[linux-2.6.git] / drivers / media / video / cx231xx / cx231xx-cards.c
index f18d0c1..c8a32b1 100644 (file)
@@ -61,137 +61,118 @@ static struct cx231xx_reg_seq RDE250_XCV_TUNER[] = {
  *  Board definitions
  */
 struct cx231xx_board cx231xx_boards[] = {
-
        [CX231XX_BOARD_UNKNOWN] = {
-                                  .name = "Unknown CX231xx video grabber",
-                                  .tuner_type = TUNER_ABSENT,
-                                  .input = {{
-                                             .type = CX231XX_VMUX_TELEVISION,
-                                             .vmux = CX231XX_VIN_3_1,
-                                             .amux = CX231XX_AMUX_VIDEO,
-                                             .gpio = 0,
-                                             }, {
-                                                 .type =
-                                                 CX231XX_VMUX_COMPOSITE1,
-                                                 .vmux = CX231XX_VIN_2_1,
-                                                 .amux = CX231XX_AMUX_LINE_IN,
-                                                 .gpio = 0,
-                                                 }, {
-                                                     .type =
-                                                     CX231XX_VMUX_SVIDEO,
-                                                     .vmux =
-                                                     CX231XX_VIN_1_1 |
-                                                     (CX231XX_VIN_1_2 << 8) |
-                                                     CX25840_SVIDEO_ON,
-                                                     .amux =
-                                                     CX231XX_AMUX_LINE_IN,
-                                                     .gpio = 0,
-                                                     } },
-                                  },
-
+               .name = "Unknown CX231xx video grabber",
+               .tuner_type = TUNER_ABSENT,
+               .input = {{
+                               .type = CX231XX_VMUX_TELEVISION,
+                               .vmux = CX231XX_VIN_3_1,
+                               .amux = CX231XX_AMUX_VIDEO,
+                               .gpio = 0,
+                       }, {
+                               .type = CX231XX_VMUX_COMPOSITE1,
+                               .vmux = CX231XX_VIN_2_1,
+                               .amux = CX231XX_AMUX_LINE_IN,
+                               .gpio = 0,
+                       }, {
+                               .type = CX231XX_VMUX_SVIDEO,
+                               .vmux = CX231XX_VIN_1_1 |
+                                       (CX231XX_VIN_1_2 << 8) |
+                                       CX25840_SVIDEO_ON,
+                               .amux = CX231XX_AMUX_LINE_IN,
+                               .gpio = 0,
+                       }
+               },
+       },
        [CX231XX_BOARD_CNXT_RDE_250] = {
-                                       .name = "Conexant Hybrid TV - RDE250",
-                                       .valid = CX231XX_BOARD_VALIDATED,
-                                       .tuner_type = TUNER_XC5000,
-                                       .tuner_addr = 0x61,
-                                       .tuner_gpio = RDE250_XCV_TUNER,
-                                       .tuner_sif_gpio = 0x05,
-                                       .tuner_scl_gpio = 0x1a,
-                                       .tuner_sda_gpio = 0x1b,
-                                       .decoder = CX231XX_AVDECODER,
-                                       .demod_xfer_mode = 0,
-                                       .ctl_pin_status_mask = 0xFFFFFFC4,
-                                       .agc_analog_digital_select_gpio = 0x0c,
-                                       .gpio_pin_status_mask = 0x4001000,
-                                       .tuner_i2c_master = 1,
-                                       .demod_i2c_master = 2,
-                                       .has_dvb = 1,
-                                       .demod_addr = 0x02,
-                                       .norm = V4L2_STD_PAL,
-
-                                       .input = {{
-                                                  .type =
-                                                  CX231XX_VMUX_TELEVISION,
-                                                  .vmux = CX231XX_VIN_3_1,
-                                                  .amux = CX231XX_AMUX_VIDEO,
-                                                  .gpio = 0,
-                                                  }, {
-                                                      .type =
-                                                      CX231XX_VMUX_COMPOSITE1,
-                                                      .vmux = CX231XX_VIN_2_1,
-                                                      .amux =
-                                                      CX231XX_AMUX_LINE_IN,
-                                                      .gpio = 0,
-                                                      }, {
-                                                          .type =
-                                                          CX231XX_VMUX_SVIDEO,
-                                                          .vmux =
-                                                          CX231XX_VIN_1_1 |
-                                                          (CX231XX_VIN_1_2 <<
-                                                           8) |
-                                                          CX25840_SVIDEO_ON,
-                                                          .amux =
-                                                          CX231XX_AMUX_LINE_IN,
-                                                          .gpio = 0,
-                                                          } },
-                                       },
+               .name = "Conexant Hybrid TV - RDE250",
+               .tuner_type = TUNER_XC5000,
+               .tuner_addr = 0x61,
+               .tuner_gpio = RDE250_XCV_TUNER,
+               .tuner_sif_gpio = 0x05,
+               .tuner_scl_gpio = 0x1a,
+               .tuner_sda_gpio = 0x1b,
+               .decoder = CX231XX_AVDECODER,
+               .demod_xfer_mode = 0,
+               .ctl_pin_status_mask = 0xFFFFFFC4,
+               .agc_analog_digital_select_gpio = 0x0c,
+               .gpio_pin_status_mask = 0x4001000,
+               .tuner_i2c_master = 1,
+               .demod_i2c_master = 2,
+               .has_dvb = 1,
+               .demod_addr = 0x02,
+               .norm = V4L2_STD_PAL,
+
+               .input = {{
+                               .type = CX231XX_VMUX_TELEVISION,
+                               .vmux = CX231XX_VIN_3_1,
+                               .amux = CX231XX_AMUX_VIDEO,
+                               .gpio = 0,
+                       }, {
+                               .type = CX231XX_VMUX_COMPOSITE1,
+                               .vmux = CX231XX_VIN_2_1,
+                               .amux = CX231XX_AMUX_LINE_IN,
+                               .gpio = 0,
+                       }, {
+                               .type = CX231XX_VMUX_SVIDEO,
+                               .vmux = CX231XX_VIN_1_1 |
+                                       (CX231XX_VIN_1_2 << 8) |
+                                       CX25840_SVIDEO_ON,
+                               .amux = CX231XX_AMUX_LINE_IN,
+                               .gpio = 0,
+                       }
+               },
+       },
 
        [CX231XX_BOARD_CNXT_RDU_250] = {
-                                       .name = "Conexant Hybrid TV - RDU250",
-                                       .valid = CX231XX_BOARD_VALIDATED,
-                                       .tuner_type = TUNER_XC5000,
-                                       .tuner_addr = 0x61,
-                                       .tuner_gpio = RDE250_XCV_TUNER,
-                                       .tuner_sif_gpio = 0x05,
-                                       .tuner_scl_gpio = 0x1a,
-                                       .tuner_sda_gpio = 0x1b,
-                                       .decoder = CX231XX_AVDECODER,
-                                       .demod_xfer_mode = 0,
-                                       .ctl_pin_status_mask = 0xFFFFFFC4,
-                                       .agc_analog_digital_select_gpio = 0x0c,
-                                       .gpio_pin_status_mask = 0x4001000,
-                                       .tuner_i2c_master = 1,
-                                       .demod_i2c_master = 2,
-                                       .has_dvb = 1,
-                                       .demod_addr = 0x32,
-                                       .norm = V4L2_STD_NTSC,
-
-                                       .input = {{
-                                                  .type =
-                                                  CX231XX_VMUX_TELEVISION,
-                                                  .vmux = CX231XX_VIN_3_1,
-                                                  .amux = CX231XX_AMUX_VIDEO,
-                                                  .gpio = 0,
-                                                  }, {
-                                                      .type =
-                                                      CX231XX_VMUX_COMPOSITE1,
-                                                      .vmux = CX231XX_VIN_2_1,
-                                                      .amux =
-                                                      CX231XX_AMUX_LINE_IN,
-                                                      .gpio = 0,
-                                                      }, {
-                                                          .type =
-                                                          CX231XX_VMUX_SVIDEO,
-                                                          .vmux =
-                                                          CX231XX_VIN_1_1 |
-                                                          (CX231XX_VIN_1_2 <<
-                                                           8) |
-                                                          CX25840_SVIDEO_ON,
-                                                          .amux =
-                                                          CX231XX_AMUX_LINE_IN,
-                                                          .gpio = 0,
-                                                          } },
-                                       },
+               .name = "Conexant Hybrid TV - RDU250",
+               .tuner_type = TUNER_XC5000,
+               .tuner_addr = 0x61,
+               .tuner_gpio = RDE250_XCV_TUNER,
+               .tuner_sif_gpio = 0x05,
+               .tuner_scl_gpio = 0x1a,
+               .tuner_sda_gpio = 0x1b,
+               .decoder = CX231XX_AVDECODER,
+               .demod_xfer_mode = 0,
+               .ctl_pin_status_mask = 0xFFFFFFC4,
+               .agc_analog_digital_select_gpio = 0x0c,
+               .gpio_pin_status_mask = 0x4001000,
+               .tuner_i2c_master = 1,
+               .demod_i2c_master = 2,
+               .has_dvb = 1,
+               .demod_addr = 0x32,
+               .norm = V4L2_STD_NTSC,
+
+               .input = {{
+                               .type = CX231XX_VMUX_TELEVISION,
+                               .vmux = CX231XX_VIN_3_1,
+                               .amux = CX231XX_AMUX_VIDEO,
+                               .gpio = 0,
+                       }, {
+                               .type = CX231XX_VMUX_COMPOSITE1,
+                               .vmux = CX231XX_VIN_2_1,
+                               .amux = CX231XX_AMUX_LINE_IN,
+                               .gpio = 0,
+                       }, {
+                               .type = CX231XX_VMUX_SVIDEO,
+                               .vmux = CX231XX_VIN_1_1 |
+                                       (CX231XX_VIN_1_2 << 8) |
+                                       CX25840_SVIDEO_ON,
+                               .amux = CX231XX_AMUX_LINE_IN,
+                               .gpio = 0,
+                       }
+               },
+       },
 };
 const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
 
 /* table of devices that work with this driver */
 struct usb_device_id cx231xx_id_table[] = {
-       {USB_DEVICE(0x0572, 0x58A0),
+       {USB_DEVICE(0x0572, 0x5A3C),
         .driver_info = CX231XX_BOARD_UNKNOWN},
        {USB_DEVICE(0x0572, 0x58A2),
         .driver_info = CX231XX_BOARD_CNXT_RDE_250},
-       {USB_DEVICE(0x0572, 0x5A3C),
+       {USB_DEVICE(0x0572, 0x58A1),
         .driver_info = CX231XX_BOARD_CNXT_RDU_250},
        {},
 };
@@ -243,25 +224,10 @@ void cx231xx_pre_card_setup(struct cx231xx *dev)
        cx231xx_info("Identified as %s (card=%d)\n",
                     dev->board.name, dev->model);
 
-       /* Do card specific if any */
-       switch (dev->model) {
-       case CX231XX_BOARD_CNXT_RDE_250:
-               /* do card specific GPIO settings if required */
-               cx231xx_info("Precard: Board is Conexnat RDE 250\n");
-               /* set the direction for GPIO pins */
-               cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
-               cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
-               cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
-               break;
-       case CX231XX_BOARD_CNXT_RDU_250:
-               /* do card specific GPIO settings if required */
-               cx231xx_info("Precard: Board is Conexnat RDU 250\n");
-               /* set the direction for GPIO pins */
-               cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
-               cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
-               cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
-               break;
-       }
+       /* set the direction for GPIO pins */
+       cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
+       cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
+       cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
 
        /* request some modules if any required */
 
@@ -276,8 +242,6 @@ void cx231xx_pre_card_setup(struct cx231xx *dev)
 
 }
 
-#if 0
-
 static void cx231xx_config_tuner(struct cx231xx *dev)
 {
        struct tuner_setup tun_setup;
@@ -291,8 +255,8 @@ static void cx231xx_config_tuner(struct cx231xx *dev)
        tun_setup.addr = dev->tuner_addr;
        tun_setup.tuner_callback = cx231xx_tuner_callback;
 
-       cx231xx_i2c_call_clients(&dev->i2c_bus[1], TUNER_SET_TYPE_ADDR,
-                                &tun_setup);
+       tuner_call(dev, tuner, s_type_addr, &tun_setup);
+
 #if 0
        if (tun_setup.type == TUNER_XC5000) {
                static struct xc2028_ctrl ctrl = {
@@ -304,20 +268,17 @@ static void cx231xx_config_tuner(struct cx231xx *dev)
                        .tuner = dev->tuner_type,
                        .priv = &ctrl,
                };
-               cx231xx_i2c_call_clients(&dev->i2c_bus[1], TUNER_SET_CONFIG,
-                                        &cfg);
+               tuner_call(dev, tuner, s_config, &cfg);
        }
 #endif
-
        /* configure tuner */
        f.tuner = 0;
        f.type = V4L2_TUNER_ANALOG_TV;
        f.frequency = 9076;     /* just a magic number */
        dev->ctl_freq = f.frequency;
-       cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_FREQUENCY, &f);
-}
+       call_all(dev, tuner, s_frequency, &f);
 
-#endif
+}
 
 /* ----------------------------------------------------------------------- */
 void cx231xx_set_ir(struct cx231xx *dev, struct IR_i2c *ir)
@@ -341,49 +302,37 @@ void cx231xx_set_ir(struct cx231xx *dev, struct IR_i2c *ir)
 
 void cx231xx_card_setup(struct cx231xx *dev)
 {
+
        cx231xx_set_model(dev);
 
        dev->tuner_type = cx231xx_boards[dev->model].tuner_type;
        if (cx231xx_boards[dev->model].tuner_addr)
                dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr;
 
-       cx231xx_info(": tuner type %d, tuner address %d \n",
-                    dev->tuner_type, dev->tuner_addr);
-
-       /* Do card specific if any */
-       switch (dev->model) {
-       case CX231XX_BOARD_CNXT_RDE_250:
-               /* do card specific GPIO settings if required */
-               cx231xx_info("Board is Conexnat RDE 250\n");
-               break;
-       case CX231XX_BOARD_CNXT_RDU_250:
-               /* do card specific GPIO settings if required */
-               cx231xx_info("Board is Conexnat RDU 250\n");
-               break;
-       }
-
-       if (dev->board.valid == CX231XX_BOARD_NOT_VALIDATED) {
-               cx231xx_errdev("\n\n");
-               cx231xx_errdev("The support for this board weren't "
-                              "valid yet.\n");
-               cx231xx_errdev("Please send a report of having this working\n");
-               cx231xx_errdev("not to V4L mailing list (and/or to other "
-                              "addresses)\n\n");
-       }
-
        /* request some modules */
        if (dev->board.decoder == CX231XX_AVDECODER) {
-               cx231xx_info(": Requesting cx25840 module\n");
-               request_module("cx25840");
+               dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
+                                       &dev->i2c_bus[0].i2c_adap,
+                                       "cx25840", "cx25840", 0x88 >> 1);
+               if (dev->sd_cx25840 == NULL)
+                       cx231xx_info("cx25840 subdev registration failure\n");
+               cx25840_call(dev, core, load_fw);
+
        }
-#if 0
+
        if (dev->board.tuner_type != TUNER_ABSENT) {
-               cx231xx_info(": Requesting Tuner module\n");
-               request_module("tuner");
+               dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev,
+                               &dev->i2c_bus[1].i2c_adap,
+                               "tuner", "tuner", 0xc2 >> 1);
+               if (dev->sd_tuner == NULL)
+                       cx231xx_info("tuner subdev registration failure\n");
+
+               cx231xx_config_tuner(dev);
        }
 
        cx231xx_config_tuner(dev);
 
+#if 0
        /* TBD  IR will be added later */
        cx231xx_ir_init(dev);
 #endif
@@ -408,12 +357,9 @@ int cx231xx_config(struct cx231xx *dev)
  */
 void cx231xx_config_i2c(struct cx231xx *dev)
 {
-       struct v4l2_routing route;
+       /* u32 input = INPUT(dev->video_input)->vmux; */
 
-       route.input = INPUT(dev->video_input)->vmux;
-       route.output = 0;
-
-       cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_STREAMON, NULL);
+       call_all(dev, video, s_stream, 1);
 }
 
 /*
@@ -580,7 +526,7 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
        struct usb_interface *uif;
        struct cx231xx *dev = NULL;
        int retval = -ENODEV;
-       int nr, ifnum;
+       int nr = 0, ifnum;
        int i, isoc_pipe = 0;
        char *speed;
        char descr[255] = "";
@@ -591,16 +537,16 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
        udev = usb_get_dev(interface_to_usbdev(interface));
        ifnum = interface->altsetting[0].desc.bInterfaceNumber;
 
-       cx231xx_info(": Interface Number %d\n", ifnum);
-
-       /* Interface number 0 - IR interface */
-       if (ifnum == 0) {
+       if (!ifnum) {
+               /*
+                * Interface number 0 - IR interface
+                */
                /* Check to see next free device and mark as used */
                nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
                cx231xx_devused |= 1 << nr;
 
                if (nr >= CX231XX_MAXBOARDS) {
-                       cx231xx_info(": Supports only %i cx231xx boards.\n",
+                       cx231xx_err(DRIVER_NAME ": Supports only %i cx231xx boards.\n",
                                     CX231XX_MAXBOARDS);
                        cx231xx_devused &= ~(1 << nr);
                        return -ENOMEM;
@@ -633,42 +579,46 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
                /* get maximum no.of IAD interfaces */
                assoc_desc = udev->actconfig->intf_assoc[0];
                dev->max_iad_interface_count = assoc_desc->bInterfaceCount;
-               cx231xx_info("Found IAD interface count %d\n",
-                            dev->max_iad_interface_count);
 
                /* init CIR module TBD */
 
                /* store the current interface */
                lif = interface;
 
-       } else if (ifnum == 1) {
-
-               /* Get dev structure first */
-               dev = usb_get_intfdata(udev->actconfig->interface[0]);
-               if (dev == NULL) {
-                       cx231xx_err(DRIVER_NAME ": out of first interface!\n");
-                       return -ENODEV;
+               switch (udev->speed) {
+               case USB_SPEED_LOW:
+                       speed = "1.5";
+                       break;
+               case USB_SPEED_UNKNOWN:
+               case USB_SPEED_FULL:
+                       speed = "12";
+                       break;
+               case USB_SPEED_HIGH:
+                       speed = "480";
+                       break;
+               default:
+                       speed = "unknown";
                }
 
-               /* store the interface 0 back */
-               lif = udev->actconfig->interface[0];
-
-               /* increment interface count */
-               dev->interface_count++;
+               if (udev->manufacturer)
+                       strlcpy(descr, udev->manufacturer, sizeof(descr));
 
-               /* get device number */
-               nr = dev->devno;
-
-               assoc_desc = udev->actconfig->intf_assoc[0];
-               if (assoc_desc->bFirstInterface == ifnum) {
-                       cx231xx_info
-                       ("Found IAD interface match: AV Desc Start!! \n");
-               } else {
-                       cx231xx_err(" Not found matching interface\n");
-                       return -ENODEV;
+               if (udev->product) {
+                       if (*descr)
+                               strlcat(descr, " ", sizeof(descr));
+                       strlcat(descr, udev->product, sizeof(descr));
                }
+               if (*descr)
+                       strlcat(descr, " ", sizeof(descr));
 
-       } else if (ifnum >= 2) {
+               cx231xx_info("New device %s@ %s Mbps "
+                    "(%04x:%04x) with %d interfaces\n",
+                    descr,
+                    speed,
+                    le16_to_cpu(udev->descriptor.idVendor),
+                    le16_to_cpu(udev->descriptor.idProduct),
+                    dev->max_iad_interface_count);
+       } else {
                /* Get dev structure first */
                dev = usb_get_intfdata(udev->actconfig->interface[0]);
                if (dev == NULL) {
@@ -685,220 +635,194 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
                /* get device number */
                nr = dev->devno;
 
-               /* set skip interface */
-               if ((dev->interface_count - 1) != dev->max_iad_interface_count)
-                       skip_interface = 1;     /* set skipping */
-               else {
-                       cx231xx_info
-                       ("Found IAD interface no. match with AV Device no.!\n");
+               /*
+                * set skip interface, for all interfaces but
+                * interface 1 and the last one
+                */
+               if ((ifnum != 1) && ((dev->interface_count - 1)
+                                    != dev->max_iad_interface_count))
+                       skip_interface = 1;
+
+               if (ifnum == 1) {
+                       assoc_desc = udev->actconfig->intf_assoc[0];
+                       if (assoc_desc->bFirstInterface != ifnum) {
+                               cx231xx_err(DRIVER_NAME ": Not found "
+                                           "matching IAD interface\n");
+                               return -ENODEV;
+                       }
                }
        }
 
-       switch (udev->speed) {
-       case USB_SPEED_LOW:
-               speed = "1.5";
-               break;
-       case USB_SPEED_UNKNOWN:
-       case USB_SPEED_FULL:
-               speed = "12";
-               break;
-       case USB_SPEED_HIGH:
-               speed = "480";
-               break;
-       default:
-               speed = "unknown";
-       }
+       if (skip_interface)
+               return -ENODEV;
 
-       if (udev->manufacturer)
-               strlcpy(descr, udev->manufacturer, sizeof(descr));
+       cx231xx_info("registering interface %d\n", ifnum);
 
-       if (udev->product) {
-               if (*descr)
-                       strlcat(descr, " ", sizeof(descr));
-               strlcat(descr, udev->product, sizeof(descr));
-       }
-       if (*descr)
-               strlcat(descr, " ", sizeof(descr));
+       /* save our data pointer in this interface device */
+       usb_set_intfdata(lif, dev);
 
-       cx231xx_info("New device %s@ %s Mbps "
-                    "(%04x:%04x, interface %d, class %d)\n",
-                    descr,
-                    speed,
-                    le16_to_cpu(udev->descriptor.idVendor),
-                    le16_to_cpu(udev->descriptor.idProduct),
-                    ifnum, interface->altsetting->desc.bInterfaceNumber);
-
-       /* AV device initialization */
-       if ((dev->interface_count - 1) == dev->max_iad_interface_count) {
-               cx231xx_info(" Calling init_dev\n");
-               /* allocate device struct */
-               retval = cx231xx_init_dev(&dev, udev, nr);
-               if (retval) {
-                       cx231xx_devused &= ~(1 << dev->devno);
-                       kfree(dev);
+       if ((dev->interface_count - 1) != dev->max_iad_interface_count)
+               return 0;
 
-                       return retval;
-               }
+       /*
+        * AV device initialization - only done at the last interface
+        */
 
-               /* compute alternate max packet sizes for video */
-               uif =
-                   udev->actconfig->interface[dev->current_pcb_config.
-                                              hs_config_info[0].interface_info.
-                                              video_index + 1];
+       /* Create v4l2 device */
+       retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
+       if (retval) {
+               cx231xx_errdev("v4l2_device_register failed\n");
+               cx231xx_devused &= ~(1 << nr);
+               kfree(dev);
+               return -EIO;
+       }
 
-               dev->video_mode.end_point_addr =
-                   le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
-                               bEndpointAddress);
+       /* allocate device struct */
+       retval = cx231xx_init_dev(&dev, udev, nr);
+       if (retval) {
+               cx231xx_devused &= ~(1 << dev->devno);
+               v4l2_device_unregister(&dev->v4l2_dev);
+               kfree(dev);
+               return retval;
+       }
 
-               dev->video_mode.num_alt = uif->num_altsetting;
-               cx231xx_info(": EndPoint Addr 0x%x, Alternate settings: %i\n",
-                            dev->video_mode.end_point_addr,
-                            dev->video_mode.num_alt);
-               dev->video_mode.alt_max_pkt_size =
-                   kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL);
+       /* compute alternate max packet sizes for video */
+       uif = udev->actconfig->interface[dev->current_pcb_config.
+                      hs_config_info[0].interface_info.video_index + 1];
 
-               if (dev->video_mode.alt_max_pkt_size == NULL) {
-                       cx231xx_errdev("out of memory!\n");
-                       cx231xx_devused &= ~(1 << nr);
-                       kfree(dev);
-                       return -ENOMEM;
-               }
+       dev->video_mode.end_point_addr = le16_to_cpu(uif->altsetting[0].
+                       endpoint[isoc_pipe].desc.bEndpointAddress);
 
-               for (i = 0; i < dev->video_mode.num_alt; i++) {
-                       u16 tmp =
-                           le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
-                                       desc.wMaxPacketSize);
-                       dev->video_mode.alt_max_pkt_size[i] =
-                           (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
-                       cx231xx_info("Alternate setting %i, max size= %i\n", i,
-                                    dev->video_mode.alt_max_pkt_size[i]);
-               }
+       dev->video_mode.num_alt = uif->num_altsetting;
+       cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
+                    dev->video_mode.end_point_addr,
+                    dev->video_mode.num_alt);
+       dev->video_mode.alt_max_pkt_size =
+               kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL);
 
-               /* compute alternate max packet sizes for vbi */
-               uif =
-                   udev->actconfig->interface[dev->current_pcb_config.
-                                              hs_config_info[0].interface_info.
-                                              vanc_index + 1];
+       if (dev->video_mode.alt_max_pkt_size == NULL) {
+               cx231xx_errdev("out of memory!\n");
+               cx231xx_devused &= ~(1 << nr);
+               v4l2_device_unregister(&dev->v4l2_dev);
+               kfree(dev);
+               return -ENOMEM;
+       }
 
-               dev->vbi_mode.end_point_addr =
-                   le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
-                               bEndpointAddress);
+       for (i = 0; i < dev->video_mode.num_alt; i++) {
+               u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
+                               desc.wMaxPacketSize);
+               dev->video_mode.alt_max_pkt_size[i] =
+                   (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
+               cx231xx_info("Alternate setting %i, max size= %i\n", i,
+                            dev->video_mode.alt_max_pkt_size[i]);
+       }
 
-               dev->vbi_mode.num_alt = uif->num_altsetting;
-               cx231xx_info(": EndPoint Addr 0x%x, Alternate settings: %i\n",
-                            dev->vbi_mode.end_point_addr,
-                            dev->vbi_mode.num_alt);
-               dev->vbi_mode.alt_max_pkt_size =
-                   kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL);
+       /* compute alternate max packet sizes for vbi */
+       uif = udev->actconfig->interface[dev->current_pcb_config.
+                                      hs_config_info[0].interface_info.
+                                      vanc_index + 1];
+
+       dev->vbi_mode.end_point_addr =
+           le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
+                       bEndpointAddress);
+
+       dev->vbi_mode.num_alt = uif->num_altsetting;
+       cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
+                    dev->vbi_mode.end_point_addr,
+                    dev->vbi_mode.num_alt);
+       dev->vbi_mode.alt_max_pkt_size =
+           kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL);
+
+       if (dev->vbi_mode.alt_max_pkt_size == NULL) {
+               cx231xx_errdev("out of memory!\n");
+               cx231xx_devused &= ~(1 << nr);
+               v4l2_device_unregister(&dev->v4l2_dev);
+               kfree(dev);
+               return -ENOMEM;
+       }
 
-               if (dev->vbi_mode.alt_max_pkt_size == NULL) {
-                       cx231xx_errdev("out of memory!\n");
-                       cx231xx_devused &= ~(1 << nr);
-                       kfree(dev);
-                       return -ENOMEM;
-               }
+       for (i = 0; i < dev->vbi_mode.num_alt; i++) {
+               u16 tmp =
+                   le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
+                               desc.wMaxPacketSize);
+               dev->vbi_mode.alt_max_pkt_size[i] =
+                   (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
+               cx231xx_info("Alternate setting %i, max size= %i\n", i,
+                            dev->vbi_mode.alt_max_pkt_size[i]);
+       }
 
-               for (i = 0; i < dev->vbi_mode.num_alt; i++) {
-                       u16 tmp =
-                           le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
-                                       desc.wMaxPacketSize);
-                       dev->vbi_mode.alt_max_pkt_size[i] =
-                           (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
-                       cx231xx_info("Alternate setting %i, max size= %i\n", i,
-                                    dev->vbi_mode.alt_max_pkt_size[i]);
-               }
+       /* compute alternate max packet sizes for sliced CC */
+       uif = udev->actconfig->interface[dev->current_pcb_config.
+                                      hs_config_info[0].interface_info.
+                                      hanc_index + 1];
+
+       dev->sliced_cc_mode.end_point_addr =
+           le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
+                       bEndpointAddress);
+
+       dev->sliced_cc_mode.num_alt = uif->num_altsetting;
+       cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
+                    dev->sliced_cc_mode.end_point_addr,
+                    dev->sliced_cc_mode.num_alt);
+       dev->sliced_cc_mode.alt_max_pkt_size =
+               kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL);
+
+       if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
+               cx231xx_errdev("out of memory!\n");
+               cx231xx_devused &= ~(1 << nr);
+               v4l2_device_unregister(&dev->v4l2_dev);
+               kfree(dev);
+               return -ENOMEM;
+       }
 
-               /* compute alternate max packet sizes for sliced CC */
-               uif =
-                   udev->actconfig->interface[dev->current_pcb_config.
-                                              hs_config_info[0].interface_info.
-                                              hanc_index + 1];
+       for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
+               u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
+                               desc.wMaxPacketSize);
+               dev->sliced_cc_mode.alt_max_pkt_size[i] =
+                   (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
+               cx231xx_info("Alternate setting %i, max size= %i\n", i,
+                            dev->sliced_cc_mode.alt_max_pkt_size[i]);
+       }
+
+       if (dev->current_pcb_config.ts1_source != 0xff) {
+               /* compute alternate max packet sizes for TS1 */
+               uif = udev->actconfig->interface[dev->current_pcb_config.
+                                              hs_config_info[0].
+                                              interface_info.
+                                              ts1_index + 1];
 
-               dev->sliced_cc_mode.end_point_addr =
-                   le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
-                               bEndpointAddress);
+               dev->ts1_mode.end_point_addr =
+                   le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].
+                               desc.bEndpointAddress);
 
-               dev->sliced_cc_mode.num_alt = uif->num_altsetting;
-               cx231xx_info(": EndPoint Addr 0x%x, Alternate settings: %i\n",
-                            dev->sliced_cc_mode.end_point_addr,
-                            dev->sliced_cc_mode.num_alt);
-               dev->sliced_cc_mode.alt_max_pkt_size =
-                   kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL);
+               dev->ts1_mode.num_alt = uif->num_altsetting;
+               cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
+                            dev->ts1_mode.end_point_addr,
+                            dev->ts1_mode.num_alt);
+               dev->ts1_mode.alt_max_pkt_size =
+                       kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL);
 
-               if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
+               if (dev->ts1_mode.alt_max_pkt_size == NULL) {
                        cx231xx_errdev("out of memory!\n");
                        cx231xx_devused &= ~(1 << nr);
+                       v4l2_device_unregister(&dev->v4l2_dev);
                        kfree(dev);
                        return -ENOMEM;
                }
 
-               for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
-                       u16 tmp =
-                           le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
-                                       desc.wMaxPacketSize);
-                       dev->sliced_cc_mode.alt_max_pkt_size[i] =
-                           (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
-                       cx231xx_info("Alternate setting %i, max size= %i\n", i,
-                                    dev->sliced_cc_mode.alt_max_pkt_size[i]);
-               }
-
-               if (dev->current_pcb_config.ts1_source != 0xff) {
-
-                       /* compute alternate max packet sizes for TS1 */
-                       uif =
-                           udev->actconfig->interface[dev->current_pcb_config.
-                                                      hs_config_info[0].
-                                                      interface_info.
-                                                      ts1_index + 1];
-
-                       dev->ts1_mode.end_point_addr =
-                           le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].
-                                       desc.bEndpointAddress);
-
-                       dev->ts1_mode.num_alt = uif->num_altsetting;
-                       cx231xx_info
-                           (": EndPoint Addr 0x%x, Alternate settings: %i\n",
-                            dev->ts1_mode.end_point_addr,
-                            dev->ts1_mode.num_alt);
-                       dev->ts1_mode.alt_max_pkt_size =
-                           kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL);
-
-                       if (dev->ts1_mode.alt_max_pkt_size == NULL) {
-                               cx231xx_errdev("out of memory!\n");
-                               cx231xx_devused &= ~(1 << nr);
-                               kfree(dev);
-                               return -ENOMEM;
-                       }
-
-                       for (i = 0; i < dev->ts1_mode.num_alt; i++) {
-                               u16 tmp =
-                                   le16_to_cpu(uif->altsetting[i].
+               for (i = 0; i < dev->ts1_mode.num_alt; i++) {
+                       u16 tmp = le16_to_cpu(uif->altsetting[i].
                                                endpoint[isoc_pipe].desc.
                                                wMaxPacketSize);
-                               dev->ts1_mode.alt_max_pkt_size[i] =
-                                   (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) +
-                                                     1);
-                               cx231xx_info
-                                   ("Alternate setting %i, max size= %i\n", i,
+                       dev->ts1_mode.alt_max_pkt_size[i] =
+                           (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
+                       cx231xx_info("Alternate setting %i, max size= %i\n", i,
                                     dev->ts1_mode.alt_max_pkt_size[i]);
-                       }
                }
-
        }
 
-       /* save our data pointer in this interface device */
-       usb_set_intfdata(lif, dev);
-
        /* load other modules required */
-       if ((dev->interface_count - 1) == dev->max_iad_interface_count) {
-               cx231xx_info("Calling request modules\n");
-               request_modules(dev);
-       }
-
-       if (skip_interface) {
-               cx231xx_info("Skipping the interface\n");
-               return -ENODEV;
-       }
+       request_modules(dev);
 
        return 0;
 }
@@ -918,6 +842,12 @@ static void cx231xx_usb_disconnect(struct usb_interface *interface)
        if (!dev)
                return;
 
+       if (!dev->udev)
+               return;
+
+       /* delete v4l2 device */
+       v4l2_device_unregister(&dev->v4l2_dev);
+
        /* wait until all current v4l2 io is finished then deallocate
           resources */
        mutex_lock(&dev->lock);