2 cx231xx-cards.c - driver for Conexant Cx23100/101/102
3 USB video capture devices
5 Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/init.h>
24 #include <linux/module.h>
25 #include <linux/delay.h>
26 #include <linux/i2c.h>
27 #include <linux/usb.h>
28 #include <media/tuner.h>
29 #include <media/tveeprom.h>
30 #include <media/v4l2-common.h>
31 #include <media/v4l2-chip-ident.h>
33 #include <media/cx25840.h>
38 static int tuner = -1;
39 module_param(tuner, int, 0444);
40 MODULE_PARM_DESC(tuner, "tuner type");
42 static unsigned int disable_ir;
43 module_param(disable_ir, int, 0444);
44 MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
46 /* Bitmask marking allocated devices from 0 to CX231XX_MAXBOARDS */
47 static unsigned long cx231xx_devused;
50 * Reset sequences for analog/digital modes
53 static struct cx231xx_reg_seq RDE250_XCV_TUNER[] = {
63 struct cx231xx_board cx231xx_boards[] = {
65 [CX231XX_BOARD_UNKNOWN] = {
66 .name = "Unknown CX231xx video grabber",
67 .tuner_type = TUNER_ABSENT,
69 .type = CX231XX_VMUX_TELEVISION,
70 .vmux = CX231XX_VIN_3_1,
71 .amux = CX231XX_AMUX_VIDEO,
75 CX231XX_VMUX_COMPOSITE1,
76 .vmux = CX231XX_VIN_2_1,
77 .amux = CX231XX_AMUX_LINE_IN,
84 (CX231XX_VIN_1_2 << 8) |
92 [CX231XX_BOARD_CNXT_RDE_250] = {
93 .name = "Conexant Hybrid TV - RDE250",
94 .valid = CX231XX_BOARD_VALIDATED,
95 .tuner_type = TUNER_XC5000,
97 .tuner_gpio = RDE250_XCV_TUNER,
98 .tuner_sif_gpio = 0x05,
99 .tuner_scl_gpio = 0x1a,
100 .tuner_sda_gpio = 0x1b,
101 .decoder = CX231XX_AVDECODER,
102 .demod_xfer_mode = 0,
103 .ctl_pin_status_mask = 0xFFFFFFC4,
104 .agc_analog_digital_select_gpio = 0x0c,
105 .gpio_pin_status_mask = 0x4001000,
106 .tuner_i2c_master = 1,
107 .demod_i2c_master = 2,
110 .norm = V4L2_STD_PAL,
114 CX231XX_VMUX_TELEVISION,
115 .vmux = CX231XX_VIN_3_1,
116 .amux = CX231XX_AMUX_VIDEO,
120 CX231XX_VMUX_COMPOSITE1,
121 .vmux = CX231XX_VIN_2_1,
123 CX231XX_AMUX_LINE_IN,
134 CX231XX_AMUX_LINE_IN,
139 [CX231XX_BOARD_CNXT_RDU_250] = {
140 .name = "Conexant Hybrid TV - RDU250",
141 .valid = CX231XX_BOARD_VALIDATED,
142 .tuner_type = TUNER_XC5000,
144 .tuner_gpio = RDE250_XCV_TUNER,
145 .tuner_sif_gpio = 0x05,
146 .tuner_scl_gpio = 0x1a,
147 .tuner_sda_gpio = 0x1b,
148 .decoder = CX231XX_AVDECODER,
149 .demod_xfer_mode = 0,
150 .ctl_pin_status_mask = 0xFFFFFFC4,
151 .agc_analog_digital_select_gpio = 0x0c,
152 .gpio_pin_status_mask = 0x4001000,
153 .tuner_i2c_master = 1,
154 .demod_i2c_master = 2,
157 .norm = V4L2_STD_NTSC,
161 CX231XX_VMUX_TELEVISION,
162 .vmux = CX231XX_VIN_3_1,
163 .amux = CX231XX_AMUX_VIDEO,
167 CX231XX_VMUX_COMPOSITE1,
168 .vmux = CX231XX_VIN_2_1,
170 CX231XX_AMUX_LINE_IN,
181 CX231XX_AMUX_LINE_IN,
186 const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
188 /* table of devices that work with this driver */
189 struct usb_device_id cx231xx_id_table[] = {
190 {USB_DEVICE(0x0572, 0x58A0),
191 .driver_info = CX231XX_BOARD_UNKNOWN},
192 {USB_DEVICE(0x0572, 0x58A2),
193 .driver_info = CX231XX_BOARD_CNXT_RDE_250},
194 {USB_DEVICE(0x0572, 0x5A3C),
195 .driver_info = CX231XX_BOARD_CNXT_RDU_250},
199 MODULE_DEVICE_TABLE(usb, cx231xx_id_table);
201 /* cx231xx_tuner_callback
202 * will be used to reset XC5000 tuner using GPIO pin
205 int cx231xx_tuner_callback(void *ptr, int component, int command, int arg)
208 struct cx231xx *dev = ptr;
210 if (dev->tuner_type == TUNER_XC5000) {
211 if (command == XC5000_TUNER_RESET) {
213 ("Tuner CB: RESET: cmd %d : tuner type %d \n",
214 command, dev->tuner_type);
215 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
218 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
221 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
228 EXPORT_SYMBOL_GPL(cx231xx_tuner_callback);
230 static inline void cx231xx_set_model(struct cx231xx *dev)
232 memcpy(&dev->board, &cx231xx_boards[dev->model], sizeof(dev->board));
235 /* Since cx231xx_pre_card_setup() requires a proper dev->model,
236 * this won't work for boards with generic PCI IDs
238 void cx231xx_pre_card_setup(struct cx231xx *dev)
241 cx231xx_set_model(dev);
243 cx231xx_info("Identified as %s (card=%d)\n",
244 dev->board.name, dev->model);
246 /* Do card specific if any */
247 switch (dev->model) {
248 case CX231XX_BOARD_CNXT_RDE_250:
249 /* do card specific GPIO settings if required */
250 cx231xx_info("Precard: Board is Conexnat RDE 250\n");
251 /* set the direction for GPIO pins */
252 cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
253 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
254 cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
256 case CX231XX_BOARD_CNXT_RDU_250:
257 /* do card specific GPIO settings if required */
258 cx231xx_info("Precard: Board is Conexnat RDU 250\n");
259 /* set the direction for GPIO pins */
260 cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
261 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
262 cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
266 /* request some modules if any required */
268 /* reset the Tuner */
269 cx231xx_gpio_set(dev, dev->board.tuner_gpio);
271 /* set the mode to Analog mode initially */
272 cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
275 /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */
281 static void cx231xx_config_tuner(struct cx231xx *dev)
283 struct tuner_setup tun_setup;
284 struct v4l2_frequency f;
286 if (dev->tuner_type == TUNER_ABSENT)
289 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
290 tun_setup.type = dev->tuner_type;
291 tun_setup.addr = dev->tuner_addr;
292 tun_setup.tuner_callback = cx231xx_tuner_callback;
294 cx231xx_i2c_call_clients(&dev->i2c_bus[1], TUNER_SET_TYPE_ADDR,
297 if (tun_setup.type == TUNER_XC5000) {
298 static struct xc2028_ctrl ctrl = {
299 .fname = XC5000_DEFAULT_FIRMWARE,
303 struct v4l2_priv_tun_config cfg = {
304 .tuner = dev->tuner_type,
307 cx231xx_i2c_call_clients(&dev->i2c_bus[1], TUNER_SET_CONFIG,
312 /* configure tuner */
314 f.type = V4L2_TUNER_ANALOG_TV;
315 f.frequency = 9076; /* just a magic number */
316 dev->ctl_freq = f.frequency;
317 cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_FREQUENCY, &f);
322 /* ----------------------------------------------------------------------- */
323 void cx231xx_set_ir(struct cx231xx *dev, struct IR_i2c *ir)
330 /* detect & configure */
331 switch (dev->model) {
333 case CX231XX_BOARD_CNXT_RDE_250:
335 case CX231XX_BOARD_CNXT_RDU_250:
342 void cx231xx_card_setup(struct cx231xx *dev)
344 cx231xx_set_model(dev);
346 dev->tuner_type = cx231xx_boards[dev->model].tuner_type;
347 if (cx231xx_boards[dev->model].tuner_addr)
348 dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr;
350 cx231xx_info(": tuner type %d, tuner address %d \n",
351 dev->tuner_type, dev->tuner_addr);
353 /* Do card specific if any */
354 switch (dev->model) {
355 case CX231XX_BOARD_CNXT_RDE_250:
356 /* do card specific GPIO settings if required */
357 cx231xx_info("Board is Conexnat RDE 250\n");
359 case CX231XX_BOARD_CNXT_RDU_250:
360 /* do card specific GPIO settings if required */
361 cx231xx_info("Board is Conexnat RDU 250\n");
365 if (dev->board.valid == CX231XX_BOARD_NOT_VALIDATED) {
366 cx231xx_errdev("\n\n");
367 cx231xx_errdev("The support for this board weren't "
369 cx231xx_errdev("Please send a report of having this working\n");
370 cx231xx_errdev("not to V4L mailing list (and/or to other "
374 /* request some modules */
375 if (dev->board.decoder == CX231XX_AVDECODER) {
376 cx231xx_info(": Requesting cx25840 module\n");
377 request_module("cx25840");
380 if (dev->board.tuner_type != TUNER_ABSENT) {
381 cx231xx_info(": Requesting Tuner module\n");
382 request_module("tuner");
385 cx231xx_config_tuner(dev);
387 /* TBD IR will be added later */
388 cx231xx_ir_init(dev);
394 * inits registers with sane defaults
396 int cx231xx_config(struct cx231xx *dev)
398 /* TBD need to add cx231xx specific code */
399 dev->mute = 1; /* maybe not the right place... */
406 * cx231xx_config_i2c()
407 * configure i2c attached devices
409 void cx231xx_config_i2c(struct cx231xx *dev)
411 struct v4l2_routing route;
413 route.input = INPUT(dev->video_input)->vmux;
416 cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_STREAMON, NULL);
420 * cx231xx_realease_resources()
421 * unregisters the v4l2,i2c and usb devices
422 * called when the device gets disconected or at module unload
424 void cx231xx_release_resources(struct cx231xx *dev)
427 #if 0 /* TBD IR related */
429 cx231xx_ir_fini(dev);
432 cx231xx_release_analog_resources(dev);
434 cx231xx_remove_from_devlist(dev);
436 cx231xx_dev_uninit(dev);
438 usb_put_dev(dev->udev);
440 /* Mark device as unused */
441 cx231xx_devused &= ~(1 << dev->devno);
446 * allocates and inits the device structs, registers i2c bus and v4l device
448 static int cx231xx_init_dev(struct cx231xx **devhandle, struct usb_device *udev,
451 struct cx231xx *dev = *devhandle;
452 int retval = -ENOMEM;
454 unsigned int maxh, maxw;
457 mutex_init(&dev->lock);
458 mutex_init(&dev->ctrl_urb_lock);
459 mutex_init(&dev->gpio_i2c_lock);
461 spin_lock_init(&dev->video_mode.slock);
462 spin_lock_init(&dev->vbi_mode.slock);
463 spin_lock_init(&dev->sliced_cc_mode.slock);
465 init_waitqueue_head(&dev->open);
466 init_waitqueue_head(&dev->wait_frame);
467 init_waitqueue_head(&dev->wait_stream);
469 dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg;
470 dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg;
471 dev->cx231xx_send_usb_command = cx231xx_send_usb_command;
472 dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read;
473 dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write;
475 /* Query cx231xx to find what pcb config it is related to */
476 initialize_cx231xx(dev);
478 /* Cx231xx pre card setup */
479 cx231xx_pre_card_setup(dev);
481 errCode = cx231xx_config(dev);
483 cx231xx_errdev("error configuring device\n");
487 /* set default norm */
488 dev->norm = dev->board.norm;
490 /* register i2c bus */
491 errCode = cx231xx_dev_init(dev);
493 cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
498 /* Do board specific init */
499 cx231xx_card_setup(dev);
501 /* configure the device */
502 cx231xx_config_i2c(dev);
504 maxw = norm_maxw(dev);
505 maxh = norm_maxh(dev);
507 /* set default image size */
513 dev->video_input = 0;
515 errCode = cx231xx_config(dev);
517 cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
522 /* init video dma queues */
523 INIT_LIST_HEAD(&dev->video_mode.vidq.active);
524 INIT_LIST_HEAD(&dev->video_mode.vidq.queued);
526 /* init vbi dma queues */
527 INIT_LIST_HEAD(&dev->vbi_mode.vidq.active);
528 INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued);
530 /* Reset other chips required if they are tied up with GPIO pins */
532 cx231xx_add_into_devlist(dev);
534 retval = cx231xx_register_analog_devices(dev);
536 cx231xx_release_resources(dev);
537 goto fail_reg_devices;
540 cx231xx_init_extension(dev);
545 mutex_unlock(&dev->lock);
549 #if defined(CONFIG_MODULES) && defined(MODULE)
550 static void request_module_async(struct work_struct *work)
552 struct cx231xx *dev = container_of(work,
553 struct cx231xx, request_module_wk);
555 if (dev->has_alsa_audio)
556 request_module("cx231xx-alsa");
558 if (dev->board.has_dvb)
559 request_module("cx231xx-dvb");
563 static void request_modules(struct cx231xx *dev)
565 INIT_WORK(&dev->request_module_wk, request_module_async);
566 schedule_work(&dev->request_module_wk);
569 #define request_modules(dev)
570 #endif /* CONFIG_MODULES */
573 * cx231xx_usb_probe()
574 * checks for supported devices
576 static int cx231xx_usb_probe(struct usb_interface *interface,
577 const struct usb_device_id *id)
579 struct usb_device *udev;
580 struct usb_interface *uif;
581 struct cx231xx *dev = NULL;
582 int retval = -ENODEV;
584 int i, isoc_pipe = 0;
586 char descr[255] = "";
587 struct usb_interface *lif = NULL;
588 int skip_interface = 0;
589 struct usb_interface_assoc_descriptor *assoc_desc;
591 udev = usb_get_dev(interface_to_usbdev(interface));
592 ifnum = interface->altsetting[0].desc.bInterfaceNumber;
594 cx231xx_info(": Interface Number %d\n", ifnum);
596 /* Interface number 0 - IR interface */
598 /* Check to see next free device and mark as used */
599 nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
600 cx231xx_devused |= 1 << nr;
602 if (nr >= CX231XX_MAXBOARDS) {
603 cx231xx_info(": Supports only %i cx231xx boards.\n",
605 cx231xx_devused &= ~(1 << nr);
609 /* allocate memory for our device state and initialize it */
610 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
612 cx231xx_err(DRIVER_NAME ": out of memory!\n");
613 cx231xx_devused &= ~(1 << nr);
617 snprintf(dev->name, 29, "cx231xx #%d", nr);
619 dev->model = id->driver_info;
620 dev->video_mode.alt = -1;
621 dev->interface_count++;
623 /* reset gpio dir and value */
626 dev->xc_fw_load_done = 0;
627 dev->has_alsa_audio = 1;
628 dev->power_mode = -1;
630 /* 0 - vbi ; 1 -sliced cc mode */
631 dev->vbi_or_sliced_cc_mode = 0;
633 /* get maximum no.of IAD interfaces */
634 assoc_desc = udev->actconfig->intf_assoc[0];
635 dev->max_iad_interface_count = assoc_desc->bInterfaceCount;
636 cx231xx_info("Found IAD interface count %d\n",
637 dev->max_iad_interface_count);
639 /* init CIR module TBD */
641 /* store the current interface */
644 } else if (ifnum == 1) {
646 /* Get dev structure first */
647 dev = usb_get_intfdata(udev->actconfig->interface[0]);
649 cx231xx_err(DRIVER_NAME ": out of first interface!\n");
653 /* store the interface 0 back */
654 lif = udev->actconfig->interface[0];
656 /* increment interface count */
657 dev->interface_count++;
659 /* get device number */
662 assoc_desc = udev->actconfig->intf_assoc[0];
663 if (assoc_desc->bFirstInterface == ifnum) {
665 ("Found IAD interface match: AV Desc Start!! \n");
667 cx231xx_err(" Not found matching interface\n");
671 } else if (ifnum >= 2) {
672 /* Get dev structure first */
673 dev = usb_get_intfdata(udev->actconfig->interface[0]);
675 cx231xx_err(DRIVER_NAME ": out of first interface!\n");
679 /* store the interface 0 back */
680 lif = udev->actconfig->interface[0];
682 /* increment interface count */
683 dev->interface_count++;
685 /* get device number */
688 /* set skip interface */
689 if ((dev->interface_count - 1) != dev->max_iad_interface_count)
690 skip_interface = 1; /* set skipping */
693 ("Found IAD interface no. match with AV Device no.!\n");
697 switch (udev->speed) {
701 case USB_SPEED_UNKNOWN:
712 if (udev->manufacturer)
713 strlcpy(descr, udev->manufacturer, sizeof(descr));
717 strlcat(descr, " ", sizeof(descr));
718 strlcat(descr, udev->product, sizeof(descr));
721 strlcat(descr, " ", sizeof(descr));
723 cx231xx_info("New device %s@ %s Mbps "
724 "(%04x:%04x, interface %d, class %d)\n",
727 le16_to_cpu(udev->descriptor.idVendor),
728 le16_to_cpu(udev->descriptor.idProduct),
729 ifnum, interface->altsetting->desc.bInterfaceNumber);
731 /* AV device initialization */
732 if ((dev->interface_count - 1) == dev->max_iad_interface_count) {
733 cx231xx_info(" Calling init_dev\n");
734 /* allocate device struct */
735 retval = cx231xx_init_dev(&dev, udev, nr);
737 cx231xx_devused &= ~(1 << dev->devno);
743 /* compute alternate max packet sizes for video */
745 udev->actconfig->interface[dev->current_pcb_config.
746 hs_config_info[0].interface_info.
749 dev->video_mode.end_point_addr =
750 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
753 dev->video_mode.num_alt = uif->num_altsetting;
754 cx231xx_info(": EndPoint Addr 0x%x, Alternate settings: %i\n",
755 dev->video_mode.end_point_addr,
756 dev->video_mode.num_alt);
757 dev->video_mode.alt_max_pkt_size =
758 kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL);
760 if (dev->video_mode.alt_max_pkt_size == NULL) {
761 cx231xx_errdev("out of memory!\n");
762 cx231xx_devused &= ~(1 << nr);
767 for (i = 0; i < dev->video_mode.num_alt; i++) {
769 le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
770 desc.wMaxPacketSize);
771 dev->video_mode.alt_max_pkt_size[i] =
772 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
773 cx231xx_info("Alternate setting %i, max size= %i\n", i,
774 dev->video_mode.alt_max_pkt_size[i]);
777 /* compute alternate max packet sizes for vbi */
779 udev->actconfig->interface[dev->current_pcb_config.
780 hs_config_info[0].interface_info.
783 dev->vbi_mode.end_point_addr =
784 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
787 dev->vbi_mode.num_alt = uif->num_altsetting;
788 cx231xx_info(": EndPoint Addr 0x%x, Alternate settings: %i\n",
789 dev->vbi_mode.end_point_addr,
790 dev->vbi_mode.num_alt);
791 dev->vbi_mode.alt_max_pkt_size =
792 kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL);
794 if (dev->vbi_mode.alt_max_pkt_size == NULL) {
795 cx231xx_errdev("out of memory!\n");
796 cx231xx_devused &= ~(1 << nr);
801 for (i = 0; i < dev->vbi_mode.num_alt; i++) {
803 le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
804 desc.wMaxPacketSize);
805 dev->vbi_mode.alt_max_pkt_size[i] =
806 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
807 cx231xx_info("Alternate setting %i, max size= %i\n", i,
808 dev->vbi_mode.alt_max_pkt_size[i]);
811 /* compute alternate max packet sizes for sliced CC */
813 udev->actconfig->interface[dev->current_pcb_config.
814 hs_config_info[0].interface_info.
817 dev->sliced_cc_mode.end_point_addr =
818 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
821 dev->sliced_cc_mode.num_alt = uif->num_altsetting;
822 cx231xx_info(": EndPoint Addr 0x%x, Alternate settings: %i\n",
823 dev->sliced_cc_mode.end_point_addr,
824 dev->sliced_cc_mode.num_alt);
825 dev->sliced_cc_mode.alt_max_pkt_size =
826 kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL);
828 if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
829 cx231xx_errdev("out of memory!\n");
830 cx231xx_devused &= ~(1 << nr);
835 for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
837 le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
838 desc.wMaxPacketSize);
839 dev->sliced_cc_mode.alt_max_pkt_size[i] =
840 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
841 cx231xx_info("Alternate setting %i, max size= %i\n", i,
842 dev->sliced_cc_mode.alt_max_pkt_size[i]);
845 if (dev->current_pcb_config.ts1_source != 0xff) {
847 /* compute alternate max packet sizes for TS1 */
849 udev->actconfig->interface[dev->current_pcb_config.
854 dev->ts1_mode.end_point_addr =
855 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].
856 desc.bEndpointAddress);
858 dev->ts1_mode.num_alt = uif->num_altsetting;
860 (": EndPoint Addr 0x%x, Alternate settings: %i\n",
861 dev->ts1_mode.end_point_addr,
862 dev->ts1_mode.num_alt);
863 dev->ts1_mode.alt_max_pkt_size =
864 kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL);
866 if (dev->ts1_mode.alt_max_pkt_size == NULL) {
867 cx231xx_errdev("out of memory!\n");
868 cx231xx_devused &= ~(1 << nr);
873 for (i = 0; i < dev->ts1_mode.num_alt; i++) {
875 le16_to_cpu(uif->altsetting[i].
876 endpoint[isoc_pipe].desc.
878 dev->ts1_mode.alt_max_pkt_size[i] =
879 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) +
882 ("Alternate setting %i, max size= %i\n", i,
883 dev->ts1_mode.alt_max_pkt_size[i]);
889 /* save our data pointer in this interface device */
890 usb_set_intfdata(lif, dev);
892 /* load other modules required */
893 if ((dev->interface_count - 1) == dev->max_iad_interface_count) {
894 cx231xx_info("Calling request modules\n");
895 request_modules(dev);
898 if (skip_interface) {
899 cx231xx_info("Skipping the interface\n");
907 * cx231xx_usb_disconnect()
908 * called when the device gets diconencted
909 * video device will be unregistered on v4l2_close in case it is still open
911 static void cx231xx_usb_disconnect(struct usb_interface *interface)
915 dev = usb_get_intfdata(interface);
916 usb_set_intfdata(interface, NULL);
921 /* wait until all current v4l2 io is finished then deallocate
923 mutex_lock(&dev->lock);
925 wake_up_interruptible_all(&dev->open);
929 ("device /dev/video%d is open! Deregistration and memory "
930 "deallocation are deferred on close.\n", dev->vdev->num);
932 dev->state |= DEV_MISCONFIGURED;
933 cx231xx_uninit_isoc(dev);
934 dev->state |= DEV_DISCONNECTED;
935 wake_up_interruptible(&dev->wait_frame);
936 wake_up_interruptible(&dev->wait_stream);
938 dev->state |= DEV_DISCONNECTED;
939 cx231xx_release_resources(dev);
942 cx231xx_close_extension(dev);
944 mutex_unlock(&dev->lock);
947 kfree(dev->video_mode.alt_max_pkt_size);
948 kfree(dev->vbi_mode.alt_max_pkt_size);
949 kfree(dev->sliced_cc_mode.alt_max_pkt_size);
950 kfree(dev->ts1_mode.alt_max_pkt_size);
955 static struct usb_driver cx231xx_usb_driver = {
957 .probe = cx231xx_usb_probe,
958 .disconnect = cx231xx_usb_disconnect,
959 .id_table = cx231xx_id_table,
962 static int __init cx231xx_module_init(void)
966 printk(KERN_INFO DRIVER_NAME " v4l2 driver loaded.\n");
968 /* register this driver with the USB subsystem */
969 result = usb_register(&cx231xx_usb_driver);
971 cx231xx_err(DRIVER_NAME
972 " usb_register failed. Error number %d.\n", result);
977 static void __exit cx231xx_module_exit(void)
979 /* deregister this driver with the USB subsystem */
980 usb_deregister(&cx231xx_usb_driver);
983 module_init(cx231xx_module_init);
984 module_exit(cx231xx_module_exit);