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[] = {
64 struct cx231xx_board cx231xx_boards[] = {
66 [CX231XX_BOARD_UNKNOWN] = {
67 .name = "Unknown CX231xx video grabber",
68 .tuner_type = TUNER_ABSENT,
70 .type = CX231XX_VMUX_TELEVISION,
71 .vmux = CX231XX_VIN_3_1,
72 .amux = CX231XX_AMUX_VIDEO,
75 .type = CX231XX_VMUX_COMPOSITE1,
76 .vmux = CX231XX_VIN_2_1,
77 .amux = CX231XX_AMUX_LINE_IN,
80 .type = CX231XX_VMUX_SVIDEO,
81 .vmux = CX231XX_VIN_1_1 | (CX231XX_VIN_1_2 << 8 ) |
83 .amux = CX231XX_AMUX_LINE_IN,
88 [CX231XX_BOARD_CNXT_RDE_250] = {
89 .name = "Conexant Hybrid TV - RDE250",
90 .valid = CX231XX_BOARD_VALIDATED,
91 .tuner_type = TUNER_XC5000,
93 .tuner_gpio = RDE250_XCV_TUNER,
94 .tuner_sif_gpio = 0x05,
95 .tuner_scl_gpio = 0x1a,
96 .tuner_sda_gpio = 0x1b,
97 .decoder = CX231XX_AVDECODER,
99 .ctl_pin_status_mask = 0xFFFFFFC4,
100 .agc_analog_digital_select_gpio = 0x0c,
101 .gpio_pin_status_mask = 0x4001000,
102 .tuner_i2c_master = 1,
103 .demod_i2c_master = 2,
106 .norm = V4L2_STD_PAL,
109 .type = CX231XX_VMUX_TELEVISION,
110 .vmux = CX231XX_VIN_3_1,
111 .amux = CX231XX_AMUX_VIDEO,
114 .type = CX231XX_VMUX_COMPOSITE1,
115 .vmux = CX231XX_VIN_2_1,
116 .amux = CX231XX_AMUX_LINE_IN,
119 .type = CX231XX_VMUX_SVIDEO,
120 .vmux = CX231XX_VIN_1_1 | (CX231XX_VIN_1_2 << 8 ) |
122 .amux = CX231XX_AMUX_LINE_IN,
127 [CX231XX_BOARD_CNXT_RDU_250] = {
128 .name = "Conexant Hybrid TV - RDU250",
129 .valid = CX231XX_BOARD_VALIDATED,
130 .tuner_type = TUNER_XC5000,
132 .tuner_gpio = RDE250_XCV_TUNER,
133 .tuner_sif_gpio = 0x05,
134 .tuner_scl_gpio = 0x1a,
135 .tuner_sda_gpio = 0x1b,
136 .decoder = CX231XX_AVDECODER,
137 .demod_xfer_mode = 0,
138 .ctl_pin_status_mask = 0xFFFFFFC4,
139 .agc_analog_digital_select_gpio = 0x0c,
140 .gpio_pin_status_mask = 0x4001000,
141 .tuner_i2c_master = 1,
142 .demod_i2c_master = 2,
145 .norm = V4L2_STD_NTSC,
148 .type = CX231XX_VMUX_TELEVISION,
149 .vmux = CX231XX_VIN_3_1,
150 .amux = CX231XX_AMUX_VIDEO,
153 .type = CX231XX_VMUX_COMPOSITE1,
154 .vmux = CX231XX_VIN_2_1,
155 .amux = CX231XX_AMUX_LINE_IN,
158 .type = CX231XX_VMUX_SVIDEO,
159 .vmux = CX231XX_VIN_1_1 | (CX231XX_VIN_1_2 << 8 ) |
161 .amux = CX231XX_AMUX_LINE_IN,
166 const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
168 /* table of devices that work with this driver */
169 struct usb_device_id cx231xx_id_table [] = {
170 { USB_DEVICE(0x0572, 0x58A0),
171 .driver_info = CX231XX_BOARD_UNKNOWN },
172 { USB_DEVICE(0x0572, 0x58A2),
173 .driver_info = CX231XX_BOARD_CNXT_RDE_250 },
174 { USB_DEVICE(0x0572, 0x5A3C),
175 .driver_info = CX231XX_BOARD_CNXT_RDU_250 },
178 MODULE_DEVICE_TABLE(usb, cx231xx_id_table);
180 /* cx231xx_tuner_callback
181 * will be used to reset XC5000 tuner using GPIO pin
184 int cx231xx_tuner_callback(void *ptr, int component, int command, int arg)
187 struct cx231xx *dev = ptr;
189 if (dev->tuner_type == TUNER_XC5000) {
190 if (command == XC5000_TUNER_RESET) {
191 cx231xx_info("Tuner Call back : RESET : command %d : tuner type %d \n",
192 command, dev->tuner_type);
194 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,1);
196 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,0);
198 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,1);
204 EXPORT_SYMBOL_GPL(cx231xx_tuner_callback);
206 static void inline cx231xx_set_model(struct cx231xx *dev)
208 memcpy(&dev->board, &cx231xx_boards[dev->model], sizeof(dev->board));
211 /* Since cx231xx_pre_card_setup() requires a proper dev->model,
212 * this won't work for boards with generic PCI IDs
214 void cx231xx_pre_card_setup(struct cx231xx *dev)
217 cx231xx_set_model(dev);
219 cx231xx_info("Identified as %s (card=%d)\n",
220 dev->board.name, dev->model);
222 /* Do card specific if any */
223 switch (dev->model) {
224 case CX231XX_BOARD_CNXT_RDE_250:
225 /* do card specific GPIO settings if required */
226 cx231xx_info("Precard: Board is Conexnat RDE 250\n");
227 /* set the direction for GPIO pins */
228 cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit,1);
229 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,1);
230 cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio,1);
232 case CX231XX_BOARD_CNXT_RDU_250:
233 /* do card specific GPIO settings if required */
234 cx231xx_info("Precard: Board is Conexnat RDU 250\n");
235 /* set the direction for GPIO pins */
236 cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit,1);
237 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,1);
238 cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio,1);
242 /* request some modules if any required */
244 /* reset the Tuner */
245 cx231xx_gpio_set(dev, dev->board.tuner_gpio);
247 /* set the mode to Analog mode initially */
248 cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
251 /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */
257 static void cx231xx_config_tuner(struct cx231xx *dev)
259 struct tuner_setup tun_setup;
260 struct v4l2_frequency f;
262 if (dev->tuner_type == TUNER_ABSENT)
265 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
266 tun_setup.type = dev->tuner_type;
267 tun_setup.addr = dev->tuner_addr;
268 tun_setup.tuner_callback = cx231xx_tuner_callback;
270 cx231xx_i2c_call_clients(&dev->i2c_bus[1], TUNER_SET_TYPE_ADDR, &tun_setup);
272 if (tun_setup.type == TUNER_XC5000) {
273 static struct xc2028_ctrl ctrl = {
274 .fname = XC5000_DEFAULT_FIRMWARE,
278 struct v4l2_priv_tun_config cfg = {
279 .tuner = dev->tuner_type,
282 cx231xx_i2c_call_clients(&dev->i2c_bus[1], TUNER_SET_CONFIG, &cfg);
286 /* configure tuner */
288 f.type = V4L2_TUNER_ANALOG_TV;
289 f.frequency = 9076; /* just a magic number */
290 dev->ctl_freq = f.frequency;
291 cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_FREQUENCY, &f);
296 /* ----------------------------------------------------------------------- */
297 void cx231xx_set_ir(struct cx231xx *dev, struct IR_i2c *ir)
304 /* detect & configure */
305 switch (dev->model) {
307 case CX231XX_BOARD_CNXT_RDE_250:
309 case CX231XX_BOARD_CNXT_RDU_250:
316 void cx231xx_card_setup(struct cx231xx *dev)
318 cx231xx_set_model(dev);
320 dev->tuner_type = cx231xx_boards[dev->model].tuner_type;
321 if (cx231xx_boards[dev->model].tuner_addr)
322 dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr;
324 cx231xx_info(": tuner type %d, tuner address %d \n",
325 dev->tuner_type, dev->tuner_addr);
327 /* Do card specific if any */
328 switch (dev->model) {
329 case CX231XX_BOARD_CNXT_RDE_250:
330 /* do card specific GPIO settings if required */
331 cx231xx_info("Board is Conexnat RDE 250\n");
333 case CX231XX_BOARD_CNXT_RDU_250:
334 /* do card specific GPIO settings if required */
335 cx231xx_info("Board is Conexnat RDU 250\n");
339 if (dev->board.valid == CX231XX_BOARD_NOT_VALIDATED) {
340 cx231xx_errdev("\n\n");
341 cx231xx_errdev("The support for this board weren't "
343 cx231xx_errdev("Please send a report of having this working\n");
344 cx231xx_errdev("not to V4L mailing list (and/or to other "
349 /* request some modules */
350 if (dev->board.decoder == CX231XX_AVDECODER) {
351 cx231xx_info(": Requesting cx25840 module\n");
352 request_module("cx25840");
355 if (dev->board.tuner_type != TUNER_ABSENT) {
356 cx231xx_info(": Requesting Tuner module\n");
357 request_module("tuner");
360 cx231xx_config_tuner(dev);
362 /* TBD IR will be added later */
363 cx231xx_ir_init(dev);
371 * inits registers with sane defaults
373 int cx231xx_config(struct cx231xx *dev)
375 /* TBD need to add cx231xx specific code */
376 dev->mute = 1; /* maybe not the right place... */
383 * cx231xx_config_i2c()
384 * configure i2c attached devices
386 void cx231xx_config_i2c(struct cx231xx *dev)
388 struct v4l2_routing route;
390 route.input = INPUT(dev->video_input)->vmux;
393 cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_STREAMON, NULL);
397 * cx231xx_realease_resources()
398 * unregisters the v4l2,i2c and usb devices
399 * called when the device gets disconected or at module unload
401 void cx231xx_release_resources(struct cx231xx *dev)
404 #if 0 /* TBD IR related */
406 cx231xx_ir_fini(dev);
409 cx231xx_release_analog_resources(dev);
411 cx231xx_remove_from_devlist(dev);
413 cx231xx_dev_uninit(dev);
415 usb_put_dev(dev->udev);
417 /* Mark device as unused */
418 cx231xx_devused &= ~(1<<dev->devno);
424 * allocates and inits the device structs, registers i2c bus and v4l device
426 static int cx231xx_init_dev(struct cx231xx **devhandle, struct usb_device *udev,
429 struct cx231xx *dev = *devhandle;
430 int retval = -ENOMEM;
432 unsigned int maxh, maxw;
435 mutex_init(&dev->lock);
436 mutex_init(&dev->ctrl_urb_lock);
437 mutex_init(&dev->gpio_i2c_lock);
439 spin_lock_init(&dev->video_mode.slock);
440 spin_lock_init(&dev->vbi_mode.slock);
441 spin_lock_init(&dev->sliced_cc_mode.slock);
443 init_waitqueue_head(&dev->open);
444 init_waitqueue_head(&dev->wait_frame);
445 init_waitqueue_head(&dev->wait_stream);
447 dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg;
448 dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg;
449 dev->cx231xx_send_usb_command = cx231xx_send_usb_command;
450 dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read;
451 dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write;
453 /* Query cx231xx to find what pcb config it is related to */
454 initialize_cx231xx(dev);
456 /* Cx231xx pre card setup */
457 cx231xx_pre_card_setup(dev);
459 errCode = cx231xx_config(dev);
461 cx231xx_errdev("error configuring device\n");
465 /* set default norm */
466 dev->norm = dev->board.norm;
468 /* register i2c bus */
469 errCode = cx231xx_dev_init(dev);
471 cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
476 /* Do board specific init */
477 cx231xx_card_setup(dev);
479 /* configure the device */
480 cx231xx_config_i2c(dev);
482 maxw = norm_maxw(dev);
483 maxh = norm_maxh(dev);
485 /* set default image size */
491 dev->video_input = 0;
493 errCode = cx231xx_config(dev);
495 cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
500 /* init video dma queues */
501 INIT_LIST_HEAD(&dev->video_mode.vidq.active);
502 INIT_LIST_HEAD(&dev->video_mode.vidq.queued);
504 /* init vbi dma queues */
505 INIT_LIST_HEAD(&dev->vbi_mode.vidq.active);
506 INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued);
508 /* Reset other chips required if they are tied up with GPIO pins */
510 cx231xx_add_into_devlist(dev);
512 retval = cx231xx_register_analog_devices(dev);
514 cx231xx_release_resources(dev);
515 goto fail_reg_devices;
518 cx231xx_init_extension(dev);
523 mutex_unlock(&dev->lock);
527 #if defined(CONFIG_MODULES) && defined(MODULE)
528 static void request_module_async(struct work_struct *work)
530 struct cx231xx *dev = container_of(work,
531 struct cx231xx, request_module_wk);
534 if (dev->has_alsa_audio)
535 request_module("cx231xx-alsa");
537 if (dev->board.has_dvb)
538 request_module("cx231xx-dvb");
542 static void request_modules(struct cx231xx *dev)
544 INIT_WORK(&dev->request_module_wk, request_module_async);
545 schedule_work(&dev->request_module_wk);
548 #define request_modules(dev)
549 #endif /* CONFIG_MODULES */
554 * cx231xx_usb_probe()
555 * checks for supported devices
557 static int cx231xx_usb_probe(struct usb_interface *interface,
558 const struct usb_device_id *id)
560 struct usb_device *udev;
561 struct usb_interface *uif;
562 struct cx231xx *dev = NULL;
563 int retval = -ENODEV;
565 int i, isoc_pipe = 0;
567 char descr[255] = "";
568 struct usb_interface *lif = NULL;
569 int skip_interface = 0;
570 struct usb_interface_assoc_descriptor *assoc_desc;
572 udev = usb_get_dev(interface_to_usbdev(interface));
573 ifnum = interface->altsetting[0].desc.bInterfaceNumber;
575 cx231xx_info(": Interface Number %d\n", ifnum);
577 /* Interface number 0 - IR interface */
579 /* Check to see next free device and mark as used */
580 nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
581 cx231xx_devused |= 1<<nr;
583 if (nr >= CX231XX_MAXBOARDS) {
584 cx231xx_info(": Supports only %i cx231xx boards.\n",
586 cx231xx_devused &= ~(1<<nr);
590 /* allocate memory for our device state and initialize it */
591 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
593 cx231xx_err(DRIVER_NAME ": out of memory!\n");
594 cx231xx_devused &= ~(1<<nr);
598 snprintf(dev->name, 29, "cx231xx #%d", nr);
600 dev->model = id->driver_info;
601 dev->video_mode.alt = -1;
602 dev->interface_count++;
604 /* reset gpio dir and value */
607 dev->xc_fw_load_done = 0;
608 dev->has_alsa_audio = 1;
609 dev->power_mode = -1;
611 dev->vbi_or_sliced_cc_mode = 0; /* 0 - vbi ; 1 -sliced cc mode */
613 /* get maximum no.of IAD interfaces */
614 assoc_desc = udev->actconfig->intf_assoc[0];
615 dev->max_iad_interface_count = assoc_desc->bInterfaceCount;
616 cx231xx_info(": Found IAD interface count %d\n", dev->max_iad_interface_count);
618 /* init CIR module TBD */
620 /* store the current interface */
624 else if(ifnum == 1 ){
626 /* Get dev structure first */
627 dev = usb_get_intfdata(udev->actconfig->interface[0]);
629 cx231xx_err(DRIVER_NAME ": out of first interface!\n");
633 /* store the interface 0 back */
634 lif = udev->actconfig->interface[0];
636 /* increment interface count */
637 dev->interface_count++;
639 /* get device number */
642 assoc_desc = udev->actconfig->intf_assoc[0];
643 if(assoc_desc->bFirstInterface == ifnum){
644 cx231xx_info(": Found IAD interface match: AV Descriptor Start!! \n");
646 cx231xx_err(DRIVER_NAME " Not found matching interface\n");
651 else if(ifnum >= 2) {
652 /* Get dev structure first */
653 dev = usb_get_intfdata(udev->actconfig->interface[0]);
655 cx231xx_err(DRIVER_NAME ": out of first interface!\n");
659 /* store the interface 0 back */
660 lif = udev->actconfig->interface[0];
662 /* increment interface count */
663 dev->interface_count++;
665 /* get device number */
668 /* set skip interface */
669 if((dev->interface_count -1) != dev->max_iad_interface_count )
670 skip_interface = 1; /* set skipping */
672 cx231xx_info(": Found IAD interface number match with AV Device number!! \n");
676 switch (udev->speed) {
680 case USB_SPEED_UNKNOWN:
691 if (udev->manufacturer)
692 strlcpy(descr, udev->manufacturer, sizeof(descr));
696 strlcat(descr, " ", sizeof(descr));
697 strlcat(descr, udev->product, sizeof(descr));
700 strlcat(descr, " ", sizeof(descr));
702 cx231xx_info("New device %s@ %s Mbps "
703 "(%04x:%04x, interface %d, class %d)\n",
706 le16_to_cpu(udev->descriptor.idVendor),
707 le16_to_cpu(udev->descriptor.idProduct),
709 interface->altsetting->desc.bInterfaceNumber);
711 /* AV device initialization */
712 if((dev->interface_count -1) == dev->max_iad_interface_count ) {
713 cx231xx_info(" Calling init_dev\n");
714 /* allocate device struct */
715 retval = cx231xx_init_dev(&dev, udev, nr);
717 cx231xx_devused &= ~(1<<dev->devno);
723 /* compute alternate max packet sizes for video */
724 uif = udev->actconfig->interface[dev->current_pcb_config.hs_config_info[0].interface_info.video_index+1];
726 dev->video_mode.end_point_addr = le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.bEndpointAddress);
728 dev->video_mode.num_alt = uif->num_altsetting;
729 cx231xx_info(": EndPoint Addr 0x%x, Alternate settings: %i\n", dev->video_mode.end_point_addr,
730 dev->video_mode.num_alt);
731 dev->video_mode.alt_max_pkt_size = kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL);
733 if (dev->video_mode.alt_max_pkt_size == NULL) {
734 cx231xx_errdev("out of memory!\n");
735 cx231xx_devused &= ~(1<<nr);
740 for (i = 0; i < dev->video_mode.num_alt ; i++) {
741 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].desc.
743 dev->video_mode.alt_max_pkt_size[i] =
744 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
745 cx231xx_info("Alternate setting %i, max size= %i\n", i,
746 dev->video_mode.alt_max_pkt_size[i]);
750 /* compute alternate max packet sizes for vbi */
751 uif = udev->actconfig->interface[dev->current_pcb_config.hs_config_info[0].interface_info.vanc_index+1];
753 dev->vbi_mode.end_point_addr =
754 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.bEndpointAddress);
756 dev->vbi_mode.num_alt = uif->num_altsetting;
757 cx231xx_info(": EndPoint Addr 0x%x, Alternate settings: %i\n", dev->vbi_mode.end_point_addr,
758 dev->vbi_mode.num_alt);
759 dev->vbi_mode.alt_max_pkt_size = kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL);
761 if (dev->vbi_mode.alt_max_pkt_size == NULL) {
762 cx231xx_errdev("out of memory!\n");
763 cx231xx_devused &= ~(1<<nr);
768 for (i = 0; i < dev->vbi_mode.num_alt ; i++) {
769 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].desc.
771 dev->vbi_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->vbi_mode.alt_max_pkt_size[i]);
777 /* compute alternate max packet sizes for sliced CC */
778 uif = udev->actconfig->interface[dev->current_pcb_config.hs_config_info[0].interface_info.hanc_index+1];
780 dev->sliced_cc_mode.end_point_addr =
781 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.bEndpointAddress);
783 dev->sliced_cc_mode.num_alt = uif->num_altsetting;
784 cx231xx_info(": EndPoint Addr 0x%x, Alternate settings: %i\n", dev->sliced_cc_mode.end_point_addr,
785 dev->sliced_cc_mode.num_alt);
786 dev->sliced_cc_mode.alt_max_pkt_size = kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL);
788 if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
789 cx231xx_errdev("out of memory!\n");
790 cx231xx_devused &= ~(1<<nr);
795 for (i = 0; i < dev->sliced_cc_mode.num_alt ; i++) {
796 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].desc.
798 dev->sliced_cc_mode.alt_max_pkt_size[i] =
799 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
800 cx231xx_info("Alternate setting %i, max size= %i\n", i,
801 dev->sliced_cc_mode.alt_max_pkt_size[i]);
804 if(dev->current_pcb_config.ts1_source != 0xff ) {
806 /* compute alternate max packet sizes for TS1 */
807 uif = udev->actconfig->interface[dev->current_pcb_config.hs_config_info[0].interface_info.ts1_index+1];
809 dev->ts1_mode.end_point_addr =
810 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.bEndpointAddress);
812 dev->ts1_mode.num_alt = uif->num_altsetting;
813 cx231xx_info(": EndPoint Addr 0x%x, Alternate settings: %i\n", dev->ts1_mode.end_point_addr,
814 dev->ts1_mode.num_alt);
815 dev->ts1_mode.alt_max_pkt_size = kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL);
817 if (dev->ts1_mode.alt_max_pkt_size == NULL) {
818 cx231xx_errdev("out of memory!\n");
819 cx231xx_devused &= ~(1<<nr);
824 for (i = 0; i < dev->ts1_mode.num_alt ; i++) {
825 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].desc.
827 dev->ts1_mode.alt_max_pkt_size[i] =
828 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
829 cx231xx_info("Alternate setting %i, max size= %i\n", i,
830 dev->ts1_mode.alt_max_pkt_size[i]);
836 /* save our data pointer in this interface device */
837 usb_set_intfdata(lif, dev);
839 /* load other modules required */
840 if((dev->interface_count -1) == dev->max_iad_interface_count )
842 cx231xx_info("Calling request modules\n");
843 request_modules(dev);
846 if(skip_interface ) {
847 cx231xx_info("Skipping the interface\n");
855 * cx231xx_usb_disconnect()
856 * called when the device gets diconencted
857 * video device will be unregistered on v4l2_close in case it is still open
859 static void cx231xx_usb_disconnect(struct usb_interface *interface)
863 dev = usb_get_intfdata(interface);
864 usb_set_intfdata(interface, NULL);
869 /* wait until all current v4l2 io is finished then deallocate
871 mutex_lock(&dev->lock);
873 wake_up_interruptible_all(&dev->open);
877 ("device /dev/video%d is open! Deregistration and memory "
878 "deallocation are deferred on close.\n",
881 dev->state |= DEV_MISCONFIGURED;
882 cx231xx_uninit_isoc(dev);
883 dev->state |= DEV_DISCONNECTED;
884 wake_up_interruptible(&dev->wait_frame);
885 wake_up_interruptible(&dev->wait_stream);
887 dev->state |= DEV_DISCONNECTED;
888 cx231xx_release_resources(dev);
891 cx231xx_close_extension(dev);
893 mutex_unlock(&dev->lock);
896 kfree(dev->video_mode.alt_max_pkt_size);
897 kfree(dev->vbi_mode.alt_max_pkt_size);
898 kfree(dev->sliced_cc_mode.alt_max_pkt_size);
899 kfree(dev->ts1_mode.alt_max_pkt_size);
904 static struct usb_driver cx231xx_usb_driver = {
906 .probe = cx231xx_usb_probe,
907 .disconnect = cx231xx_usb_disconnect,
908 .id_table = cx231xx_id_table,
911 static int __init cx231xx_module_init(void)
915 printk(KERN_INFO DRIVER_NAME " v4l2 driver version %d.%d.%d loaded\n",
916 (CX231XX_VERSION_CODE >> 16) & 0xff,
917 (CX231XX_VERSION_CODE >> 8) & 0xff, CX231XX_VERSION_CODE & 0xff);
919 /* register this driver with the USB subsystem */
920 result = usb_register(&cx231xx_usb_driver);
922 cx231xx_err(DRIVER_NAME
923 " usb_register failed. Error number %d.\n", result);
928 static void __exit cx231xx_module_exit(void)
930 /* deregister this driver with the USB subsystem */
931 usb_deregister(&cx231xx_usb_driver);
934 module_init(cx231xx_module_init);
935 module_exit(cx231xx_module_exit);