2 cx231xx-cards.c - driver for Conexant Cx23100/101/102 USB video capture devices
4 Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/init.h>
23 #include <linux/module.h>
24 #include <linux/delay.h>
25 #include <linux/i2c.h>
26 #include <linux/usb.h>
27 #include <media/tuner.h>
28 #include <media/tveeprom.h>
29 #include <media/v4l2-common.h>
30 #include <media/v4l2-chip-ident.h>
32 #include <media/cx25840.h>
37 static int tuner = -1;
38 module_param(tuner, int, 0444);
39 MODULE_PARM_DESC(tuner, "tuner type");
41 static unsigned int disable_ir;
42 module_param(disable_ir, int, 0444);
43 MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
45 /* Bitmask marking allocated devices from 0 to CX231XX_MAXBOARDS */
46 static unsigned long cx231xx_devused;
49 * Reset sequences for analog/digital modes
52 static struct cx231xx_reg_seq RDE250_XCV_TUNER[] = {
62 struct cx231xx_board cx231xx_boards[] = {
64 [CX231XX_BOARD_UNKNOWN] = {
65 .name = "Unknown CX231xx video grabber",
66 .tuner_type = TUNER_ABSENT,
68 .type = CX231XX_VMUX_TELEVISION,
69 .vmux = CX231XX_VIN_3_1,
70 .amux = CX231XX_AMUX_VIDEO,
74 CX231XX_VMUX_COMPOSITE1,
75 .vmux = CX231XX_VIN_2_1,
76 .amux = CX231XX_AMUX_LINE_IN,
83 (CX231XX_VIN_1_2 << 8) |
91 [CX231XX_BOARD_CNXT_RDE_250] = {
92 .name = "Conexant Hybrid TV - RDE250",
93 .valid = CX231XX_BOARD_VALIDATED,
94 .tuner_type = TUNER_XC5000,
96 .tuner_gpio = RDE250_XCV_TUNER,
97 .tuner_sif_gpio = 0x05,
98 .tuner_scl_gpio = 0x1a,
99 .tuner_sda_gpio = 0x1b,
100 .decoder = CX231XX_AVDECODER,
101 .demod_xfer_mode = 0,
102 .ctl_pin_status_mask = 0xFFFFFFC4,
103 .agc_analog_digital_select_gpio = 0x0c,
104 .gpio_pin_status_mask = 0x4001000,
105 .tuner_i2c_master = 1,
106 .demod_i2c_master = 2,
109 .norm = V4L2_STD_PAL,
113 CX231XX_VMUX_TELEVISION,
114 .vmux = CX231XX_VIN_3_1,
115 .amux = CX231XX_AMUX_VIDEO,
119 CX231XX_VMUX_COMPOSITE1,
120 .vmux = CX231XX_VIN_2_1,
122 CX231XX_AMUX_LINE_IN,
133 CX231XX_AMUX_LINE_IN,
138 [CX231XX_BOARD_CNXT_RDU_250] = {
139 .name = "Conexant Hybrid TV - RDU250",
140 .valid = CX231XX_BOARD_VALIDATED,
141 .tuner_type = TUNER_XC5000,
143 .tuner_gpio = RDE250_XCV_TUNER,
144 .tuner_sif_gpio = 0x05,
145 .tuner_scl_gpio = 0x1a,
146 .tuner_sda_gpio = 0x1b,
147 .decoder = CX231XX_AVDECODER,
148 .demod_xfer_mode = 0,
149 .ctl_pin_status_mask = 0xFFFFFFC4,
150 .agc_analog_digital_select_gpio = 0x0c,
151 .gpio_pin_status_mask = 0x4001000,
152 .tuner_i2c_master = 1,
153 .demod_i2c_master = 2,
156 .norm = V4L2_STD_NTSC,
160 CX231XX_VMUX_TELEVISION,
161 .vmux = CX231XX_VIN_3_1,
162 .amux = CX231XX_AMUX_VIDEO,
166 CX231XX_VMUX_COMPOSITE1,
167 .vmux = CX231XX_VIN_2_1,
169 CX231XX_AMUX_LINE_IN,
180 CX231XX_AMUX_LINE_IN,
185 const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
187 /* table of devices that work with this driver */
188 struct usb_device_id cx231xx_id_table[] = {
189 {USB_DEVICE(0x0572, 0x58A0),
190 .driver_info = CX231XX_BOARD_UNKNOWN},
191 {USB_DEVICE(0x0572, 0x58A2),
192 .driver_info = CX231XX_BOARD_CNXT_RDE_250},
193 {USB_DEVICE(0x0572, 0x5A3C),
194 .driver_info = CX231XX_BOARD_CNXT_RDU_250},
198 MODULE_DEVICE_TABLE(usb, cx231xx_id_table);
200 /* cx231xx_tuner_callback
201 * will be used to reset XC5000 tuner using GPIO pin
204 int cx231xx_tuner_callback(void *ptr, int component, int command, int arg)
207 struct cx231xx *dev = ptr;
209 if (dev->tuner_type == TUNER_XC5000) {
210 if (command == XC5000_TUNER_RESET) {
212 ("Tuner Call back : RESET : command %d : tuner type %d \n",
213 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,
229 EXPORT_SYMBOL_GPL(cx231xx_tuner_callback);
231 static void inline cx231xx_set_model(struct cx231xx *dev)
233 memcpy(&dev->board, &cx231xx_boards[dev->model], sizeof(dev->board));
236 /* Since cx231xx_pre_card_setup() requires a proper dev->model,
237 * this won't work for boards with generic PCI IDs
239 void cx231xx_pre_card_setup(struct cx231xx *dev)
242 cx231xx_set_model(dev);
244 cx231xx_info("Identified as %s (card=%d)\n",
245 dev->board.name, dev->model);
247 /* Do card specific if any */
248 switch (dev->model) {
249 case CX231XX_BOARD_CNXT_RDE_250:
250 /* do card specific GPIO settings if required */
251 cx231xx_info("Precard: Board is Conexnat RDE 250\n");
252 /* set the direction for GPIO pins */
253 cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
254 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
255 cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
257 case CX231XX_BOARD_CNXT_RDU_250:
258 /* do card specific GPIO settings if required */
259 cx231xx_info("Precard: Board is Conexnat RDU 250\n");
260 /* set the direction for GPIO pins */
261 cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
262 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
263 cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
267 /* request some modules if any required */
269 /* reset the Tuner */
270 cx231xx_gpio_set(dev, dev->board.tuner_gpio);
272 /* set the mode to Analog mode initially */
273 cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
276 /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */
282 static void cx231xx_config_tuner(struct cx231xx *dev)
284 struct tuner_setup tun_setup;
285 struct v4l2_frequency f;
287 if (dev->tuner_type == TUNER_ABSENT)
290 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
291 tun_setup.type = dev->tuner_type;
292 tun_setup.addr = dev->tuner_addr;
293 tun_setup.tuner_callback = cx231xx_tuner_callback;
295 cx231xx_i2c_call_clients(&dev->i2c_bus[1], TUNER_SET_TYPE_ADDR,
298 if (tun_setup.type == TUNER_XC5000) {
299 static struct xc2028_ctrl ctrl = {
300 .fname = XC5000_DEFAULT_FIRMWARE,
304 struct v4l2_priv_tun_config cfg = {
305 .tuner = dev->tuner_type,
308 cx231xx_i2c_call_clients(&dev->i2c_bus[1], TUNER_SET_CONFIG,
313 /* configure tuner */
315 f.type = V4L2_TUNER_ANALOG_TV;
316 f.frequency = 9076; /* just a magic number */
317 dev->ctl_freq = f.frequency;
318 cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_FREQUENCY, &f);
323 /* ----------------------------------------------------------------------- */
324 void cx231xx_set_ir(struct cx231xx *dev, struct IR_i2c *ir)
331 /* detect & configure */
332 switch (dev->model) {
334 case CX231XX_BOARD_CNXT_RDE_250:
336 case CX231XX_BOARD_CNXT_RDU_250:
343 void cx231xx_card_setup(struct cx231xx *dev)
345 cx231xx_set_model(dev);
347 dev->tuner_type = cx231xx_boards[dev->model].tuner_type;
348 if (cx231xx_boards[dev->model].tuner_addr)
349 dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr;
351 cx231xx_info(": tuner type %d, tuner address %d \n",
352 dev->tuner_type, dev->tuner_addr);
354 /* Do card specific if any */
355 switch (dev->model) {
356 case CX231XX_BOARD_CNXT_RDE_250:
357 /* do card specific GPIO settings if required */
358 cx231xx_info("Board is Conexnat RDE 250\n");
360 case CX231XX_BOARD_CNXT_RDU_250:
361 /* do card specific GPIO settings if required */
362 cx231xx_info("Board is Conexnat RDU 250\n");
366 if (dev->board.valid == CX231XX_BOARD_NOT_VALIDATED) {
367 cx231xx_errdev("\n\n");
368 cx231xx_errdev("The support for this board weren't "
370 cx231xx_errdev("Please send a report of having this working\n");
371 cx231xx_errdev("not to V4L mailing list (and/or to other "
375 /* request some modules */
376 if (dev->board.decoder == CX231XX_AVDECODER) {
377 cx231xx_info(": Requesting cx25840 module\n");
378 request_module("cx25840");
381 if (dev->board.tuner_type != TUNER_ABSENT) {
382 cx231xx_info(": Requesting Tuner module\n");
383 request_module("tuner");
386 cx231xx_config_tuner(dev);
388 /* TBD IR will be added later */
389 cx231xx_ir_init(dev);
395 * inits registers with sane defaults
397 int cx231xx_config(struct cx231xx *dev)
399 /* TBD need to add cx231xx specific code */
400 dev->mute = 1; /* maybe not the right place... */
407 * cx231xx_config_i2c()
408 * configure i2c attached devices
410 void cx231xx_config_i2c(struct cx231xx *dev)
412 struct v4l2_routing route;
414 route.input = INPUT(dev->video_input)->vmux;
417 cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_STREAMON, NULL);
421 * cx231xx_realease_resources()
422 * unregisters the v4l2,i2c and usb devices
423 * called when the device gets disconected or at module unload
425 void cx231xx_release_resources(struct cx231xx *dev)
428 #if 0 /* TBD IR related */
430 cx231xx_ir_fini(dev);
433 cx231xx_release_analog_resources(dev);
435 cx231xx_remove_from_devlist(dev);
437 cx231xx_dev_uninit(dev);
439 usb_put_dev(dev->udev);
441 /* Mark device as unused */
442 cx231xx_devused &= ~(1 << dev->devno);
447 * allocates and inits the device structs, registers i2c bus and v4l device
449 static int cx231xx_init_dev(struct cx231xx **devhandle, struct usb_device *udev,
452 struct cx231xx *dev = *devhandle;
453 int retval = -ENOMEM;
455 unsigned int maxh, maxw;
458 mutex_init(&dev->lock);
459 mutex_init(&dev->ctrl_urb_lock);
460 mutex_init(&dev->gpio_i2c_lock);
462 spin_lock_init(&dev->video_mode.slock);
463 spin_lock_init(&dev->vbi_mode.slock);
464 spin_lock_init(&dev->sliced_cc_mode.slock);
466 init_waitqueue_head(&dev->open);
467 init_waitqueue_head(&dev->wait_frame);
468 init_waitqueue_head(&dev->wait_stream);
470 dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg;
471 dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg;
472 dev->cx231xx_send_usb_command = cx231xx_send_usb_command;
473 dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read;
474 dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write;
476 /* Query cx231xx to find what pcb config it is related to */
477 initialize_cx231xx(dev);
479 /* Cx231xx pre card setup */
480 cx231xx_pre_card_setup(dev);
482 errCode = cx231xx_config(dev);
484 cx231xx_errdev("error configuring device\n");
488 /* set default norm */
489 dev->norm = dev->board.norm;
491 /* register i2c bus */
492 errCode = cx231xx_dev_init(dev);
494 cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
499 /* Do board specific init */
500 cx231xx_card_setup(dev);
502 /* configure the device */
503 cx231xx_config_i2c(dev);
505 maxw = norm_maxw(dev);
506 maxh = norm_maxh(dev);
508 /* set default image size */
514 dev->video_input = 0;
516 errCode = cx231xx_config(dev);
518 cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
523 /* init video dma queues */
524 INIT_LIST_HEAD(&dev->video_mode.vidq.active);
525 INIT_LIST_HEAD(&dev->video_mode.vidq.queued);
527 /* init vbi dma queues */
528 INIT_LIST_HEAD(&dev->vbi_mode.vidq.active);
529 INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued);
531 /* Reset other chips required if they are tied up with GPIO pins */
533 cx231xx_add_into_devlist(dev);
535 retval = cx231xx_register_analog_devices(dev);
537 cx231xx_release_resources(dev);
538 goto fail_reg_devices;
541 cx231xx_init_extension(dev);
546 mutex_unlock(&dev->lock);
550 #if defined(CONFIG_MODULES) && defined(MODULE)
551 static void request_module_async(struct work_struct *work)
553 struct cx231xx *dev = container_of(work,
554 struct cx231xx, request_module_wk);
556 if (dev->has_alsa_audio)
557 request_module("cx231xx-alsa");
559 if (dev->board.has_dvb)
560 request_module("cx231xx-dvb");
564 static void request_modules(struct cx231xx *dev)
566 INIT_WORK(&dev->request_module_wk, request_module_async);
567 schedule_work(&dev->request_module_wk);
570 #define request_modules(dev)
571 #endif /* CONFIG_MODULES */
574 * cx231xx_usb_probe()
575 * checks for supported devices
577 static int cx231xx_usb_probe(struct usb_interface *interface,
578 const struct usb_device_id *id)
580 struct usb_device *udev;
581 struct usb_interface *uif;
582 struct cx231xx *dev = NULL;
583 int retval = -ENODEV;
585 int i, isoc_pipe = 0;
587 char descr[255] = "";
588 struct usb_interface *lif = NULL;
589 int skip_interface = 0;
590 struct usb_interface_assoc_descriptor *assoc_desc;
592 udev = usb_get_dev(interface_to_usbdev(interface));
593 ifnum = interface->altsetting[0].desc.bInterfaceNumber;
595 cx231xx_info(": Interface Number %d\n", ifnum);
597 /* Interface number 0 - IR interface */
599 /* Check to see next free device and mark as used */
600 nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
601 cx231xx_devused |= 1 << nr;
603 if (nr >= CX231XX_MAXBOARDS) {
604 cx231xx_info(": Supports only %i cx231xx boards.\n",
606 cx231xx_devused &= ~(1 << nr);
610 /* allocate memory for our device state and initialize it */
611 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
613 cx231xx_err(DRIVER_NAME ": out of memory!\n");
614 cx231xx_devused &= ~(1 << nr);
618 snprintf(dev->name, 29, "cx231xx #%d", nr);
620 dev->model = id->driver_info;
621 dev->video_mode.alt = -1;
622 dev->interface_count++;
624 /* reset gpio dir and value */
627 dev->xc_fw_load_done = 0;
628 dev->has_alsa_audio = 1;
629 dev->power_mode = -1;
631 dev->vbi_or_sliced_cc_mode = 0; /* 0 - vbi ; 1 -sliced cc mode */
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 Descriptor Start!! \n");
667 cx231xx_err(DRIVER_NAME
668 " Not found matching interface\n");
672 } else if (ifnum >= 2) {
673 /* Get dev structure first */
674 dev = usb_get_intfdata(udev->actconfig->interface[0]);
676 cx231xx_err(DRIVER_NAME ": out of first interface!\n");
680 /* store the interface 0 back */
681 lif = udev->actconfig->interface[0];
683 /* increment interface count */
684 dev->interface_count++;
686 /* get device number */
689 /* set skip interface */
690 if ((dev->interface_count - 1) != dev->max_iad_interface_count)
691 skip_interface = 1; /* set skipping */
694 (": Found IAD interface number match with AV Device number!! \n");
698 switch (udev->speed) {
702 case USB_SPEED_UNKNOWN:
713 if (udev->manufacturer)
714 strlcpy(descr, udev->manufacturer, sizeof(descr));
718 strlcat(descr, " ", sizeof(descr));
719 strlcat(descr, udev->product, sizeof(descr));
722 strlcat(descr, " ", sizeof(descr));
724 cx231xx_info("New device %s@ %s Mbps "
725 "(%04x:%04x, interface %d, class %d)\n",
728 le16_to_cpu(udev->descriptor.idVendor),
729 le16_to_cpu(udev->descriptor.idProduct),
730 ifnum, interface->altsetting->desc.bInterfaceNumber);
732 /* AV device initialization */
733 if ((dev->interface_count - 1) == dev->max_iad_interface_count) {
734 cx231xx_info(" Calling init_dev\n");
735 /* allocate device struct */
736 retval = cx231xx_init_dev(&dev, udev, nr);
738 cx231xx_devused &= ~(1 << dev->devno);
744 /* compute alternate max packet sizes for video */
746 udev->actconfig->interface[dev->current_pcb_config.
747 hs_config_info[0].interface_info.
750 dev->video_mode.end_point_addr =
751 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
754 dev->video_mode.num_alt = uif->num_altsetting;
755 cx231xx_info(": EndPoint Addr 0x%x, Alternate settings: %i\n",
756 dev->video_mode.end_point_addr,
757 dev->video_mode.num_alt);
758 dev->video_mode.alt_max_pkt_size =
759 kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL);
761 if (dev->video_mode.alt_max_pkt_size == NULL) {
762 cx231xx_errdev("out of memory!\n");
763 cx231xx_devused &= ~(1 << nr);
768 for (i = 0; i < dev->video_mode.num_alt; i++) {
770 le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
771 desc.wMaxPacketSize);
772 dev->video_mode.alt_max_pkt_size[i] =
773 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
774 cx231xx_info("Alternate setting %i, max size= %i\n", i,
775 dev->video_mode.alt_max_pkt_size[i]);
778 /* compute alternate max packet sizes for vbi */
780 udev->actconfig->interface[dev->current_pcb_config.
781 hs_config_info[0].interface_info.
784 dev->vbi_mode.end_point_addr =
785 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
788 dev->vbi_mode.num_alt = uif->num_altsetting;
789 cx231xx_info(": EndPoint Addr 0x%x, Alternate settings: %i\n",
790 dev->vbi_mode.end_point_addr,
791 dev->vbi_mode.num_alt);
792 dev->vbi_mode.alt_max_pkt_size =
793 kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL);
795 if (dev->vbi_mode.alt_max_pkt_size == NULL) {
796 cx231xx_errdev("out of memory!\n");
797 cx231xx_devused &= ~(1 << nr);
802 for (i = 0; i < dev->vbi_mode.num_alt; i++) {
804 le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
805 desc.wMaxPacketSize);
806 dev->vbi_mode.alt_max_pkt_size[i] =
807 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
808 cx231xx_info("Alternate setting %i, max size= %i\n", i,
809 dev->vbi_mode.alt_max_pkt_size[i]);
812 /* compute alternate max packet sizes for sliced CC */
814 udev->actconfig->interface[dev->current_pcb_config.
815 hs_config_info[0].interface_info.
818 dev->sliced_cc_mode.end_point_addr =
819 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
822 dev->sliced_cc_mode.num_alt = uif->num_altsetting;
823 cx231xx_info(": EndPoint Addr 0x%x, Alternate settings: %i\n",
824 dev->sliced_cc_mode.end_point_addr,
825 dev->sliced_cc_mode.num_alt);
826 dev->sliced_cc_mode.alt_max_pkt_size =
827 kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL);
829 if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
830 cx231xx_errdev("out of memory!\n");
831 cx231xx_devused &= ~(1 << nr);
836 for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
838 le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
839 desc.wMaxPacketSize);
840 dev->sliced_cc_mode.alt_max_pkt_size[i] =
841 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
842 cx231xx_info("Alternate setting %i, max size= %i\n", i,
843 dev->sliced_cc_mode.alt_max_pkt_size[i]);
846 if (dev->current_pcb_config.ts1_source != 0xff) {
848 /* compute alternate max packet sizes for TS1 */
850 udev->actconfig->interface[dev->current_pcb_config.
855 dev->ts1_mode.end_point_addr =
856 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].
857 desc.bEndpointAddress);
859 dev->ts1_mode.num_alt = uif->num_altsetting;
861 (": EndPoint Addr 0x%x, Alternate settings: %i\n",
862 dev->ts1_mode.end_point_addr,
863 dev->ts1_mode.num_alt);
864 dev->ts1_mode.alt_max_pkt_size =
865 kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL);
867 if (dev->ts1_mode.alt_max_pkt_size == NULL) {
868 cx231xx_errdev("out of memory!\n");
869 cx231xx_devused &= ~(1 << nr);
874 for (i = 0; i < dev->ts1_mode.num_alt; i++) {
876 le16_to_cpu(uif->altsetting[i].
877 endpoint[isoc_pipe].desc.
879 dev->ts1_mode.alt_max_pkt_size[i] =
880 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) +
883 ("Alternate setting %i, max size= %i\n", i,
884 dev->ts1_mode.alt_max_pkt_size[i]);
890 /* save our data pointer in this interface device */
891 usb_set_intfdata(lif, dev);
893 /* load other modules required */
894 if ((dev->interface_count - 1) == dev->max_iad_interface_count) {
895 cx231xx_info("Calling request modules\n");
896 request_modules(dev);
899 if (skip_interface) {
900 cx231xx_info("Skipping the interface\n");
908 * cx231xx_usb_disconnect()
909 * called when the device gets diconencted
910 * video device will be unregistered on v4l2_close in case it is still open
912 static void cx231xx_usb_disconnect(struct usb_interface *interface)
916 dev = usb_get_intfdata(interface);
917 usb_set_intfdata(interface, NULL);
922 /* wait until all current v4l2 io is finished then deallocate
924 mutex_lock(&dev->lock);
926 wake_up_interruptible_all(&dev->open);
930 ("device /dev/video%d is open! Deregistration and memory "
931 "deallocation are deferred on close.\n", dev->vdev->num);
933 dev->state |= DEV_MISCONFIGURED;
934 cx231xx_uninit_isoc(dev);
935 dev->state |= DEV_DISCONNECTED;
936 wake_up_interruptible(&dev->wait_frame);
937 wake_up_interruptible(&dev->wait_stream);
939 dev->state |= DEV_DISCONNECTED;
940 cx231xx_release_resources(dev);
943 cx231xx_close_extension(dev);
945 mutex_unlock(&dev->lock);
948 kfree(dev->video_mode.alt_max_pkt_size);
949 kfree(dev->vbi_mode.alt_max_pkt_size);
950 kfree(dev->sliced_cc_mode.alt_max_pkt_size);
951 kfree(dev->ts1_mode.alt_max_pkt_size);
956 static struct usb_driver cx231xx_usb_driver = {
958 .probe = cx231xx_usb_probe,
959 .disconnect = cx231xx_usb_disconnect,
960 .id_table = cx231xx_id_table,
963 static int __init cx231xx_module_init(void)
967 printk(KERN_INFO DRIVER_NAME " v4l2 driver loaded.\n");
969 /* register this driver with the USB subsystem */
970 result = usb_register(&cx231xx_usb_driver);
972 cx231xx_err(DRIVER_NAME
973 " usb_register failed. Error number %d.\n", result);
978 static void __exit cx231xx_module_exit(void)
980 /* deregister this driver with the USB subsystem */
981 usb_deregister(&cx231xx_usb_driver);
984 module_init(cx231xx_module_init);
985 module_exit(cx231xx_module_exit);