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/slab.h>
26 #include <linux/delay.h>
27 #include <linux/i2c.h>
28 #include <linux/usb.h>
29 #include <media/tuner.h>
30 #include <media/tveeprom.h>
31 #include <media/v4l2-common.h>
32 #include <media/v4l2-chip-ident.h>
34 #include <media/cx25840.h>
35 #include "dvb-usb-ids.h"
40 static int tuner = -1;
41 module_param(tuner, int, 0444);
42 MODULE_PARM_DESC(tuner, "tuner type");
44 static unsigned int disable_ir;
45 module_param(disable_ir, int, 0444);
46 MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
48 /* Bitmask marking allocated devices from 0 to CX231XX_MAXBOARDS */
49 static unsigned long cx231xx_devused;
52 * Reset sequences for analog/digital modes
55 static struct cx231xx_reg_seq RDE250_XCV_TUNER[] = {
65 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 |
82 (CX231XX_VIN_1_2 << 8) |
84 .amux = CX231XX_AMUX_LINE_IN,
89 [CX231XX_BOARD_CNXT_RDE_250] = {
90 .name = "Conexant Hybrid TV - RDE250",
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 |
121 (CX231XX_VIN_1_2 << 8) |
123 .amux = CX231XX_AMUX_LINE_IN,
129 [CX231XX_BOARD_CNXT_RDU_250] = {
130 .name = "Conexant Hybrid TV - RDU250",
131 .tuner_type = TUNER_XC5000,
133 .tuner_gpio = RDE250_XCV_TUNER,
134 .tuner_sif_gpio = 0x05,
135 .tuner_scl_gpio = 0x1a,
136 .tuner_sda_gpio = 0x1b,
137 .decoder = CX231XX_AVDECODER,
138 .demod_xfer_mode = 0,
139 .ctl_pin_status_mask = 0xFFFFFFC4,
140 .agc_analog_digital_select_gpio = 0x0c,
141 .gpio_pin_status_mask = 0x4001000,
142 .tuner_i2c_master = 1,
143 .demod_i2c_master = 2,
146 .norm = V4L2_STD_NTSC,
149 .type = CX231XX_VMUX_TELEVISION,
150 .vmux = CX231XX_VIN_3_1,
151 .amux = CX231XX_AMUX_VIDEO,
154 .type = CX231XX_VMUX_COMPOSITE1,
155 .vmux = CX231XX_VIN_2_1,
156 .amux = CX231XX_AMUX_LINE_IN,
159 .type = CX231XX_VMUX_SVIDEO,
160 .vmux = CX231XX_VIN_1_1 |
161 (CX231XX_VIN_1_2 << 8) |
163 .amux = CX231XX_AMUX_LINE_IN,
169 const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
171 /* table of devices that work with this driver */
172 struct usb_device_id cx231xx_id_table[] = {
173 {USB_DEVICE(0x0572, 0x5A3C),
174 .driver_info = CX231XX_BOARD_UNKNOWN},
175 {USB_DEVICE(0x0572, 0x58A2),
176 .driver_info = CX231XX_BOARD_CNXT_RDE_250},
177 {USB_DEVICE(0x0572, 0x58A1),
178 .driver_info = CX231XX_BOARD_CNXT_RDU_250},
179 {USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x4000,0x4fff),
180 .driver_info = CX231XX_BOARD_UNKNOWN},
184 MODULE_DEVICE_TABLE(usb, cx231xx_id_table);
186 /* cx231xx_tuner_callback
187 * will be used to reset XC5000 tuner using GPIO pin
190 int cx231xx_tuner_callback(void *ptr, int component, int command, int arg)
193 struct cx231xx *dev = ptr;
195 if (dev->tuner_type == TUNER_XC5000) {
196 if (command == XC5000_TUNER_RESET) {
198 ("Tuner CB: RESET: cmd %d : tuner type %d \n",
199 command, dev->tuner_type);
200 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
203 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
206 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
213 EXPORT_SYMBOL_GPL(cx231xx_tuner_callback);
215 static inline void cx231xx_set_model(struct cx231xx *dev)
217 memcpy(&dev->board, &cx231xx_boards[dev->model], sizeof(dev->board));
220 /* Since cx231xx_pre_card_setup() requires a proper dev->model,
221 * this won't work for boards with generic PCI IDs
223 void cx231xx_pre_card_setup(struct cx231xx *dev)
226 cx231xx_set_model(dev);
228 cx231xx_info("Identified as %s (card=%d)\n",
229 dev->board.name, dev->model);
231 /* set the direction for GPIO pins */
232 if (dev->board.tuner_gpio) {
233 cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
234 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
235 cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
237 /* request some modules if any required */
239 /* reset the Tuner */
240 cx231xx_gpio_set(dev, dev->board.tuner_gpio);
243 /* set the mode to Analog mode initially */
244 cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
247 /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */
251 static void cx231xx_config_tuner(struct cx231xx *dev)
253 struct tuner_setup tun_setup;
254 struct v4l2_frequency f;
256 if (dev->tuner_type == TUNER_ABSENT)
259 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
260 tun_setup.type = dev->tuner_type;
261 tun_setup.addr = dev->tuner_addr;
262 tun_setup.tuner_callback = cx231xx_tuner_callback;
264 tuner_call(dev, tuner, s_type_addr, &tun_setup);
267 if (tun_setup.type == TUNER_XC5000) {
268 static struct xc2028_ctrl ctrl = {
269 .fname = XC5000_DEFAULT_FIRMWARE,
273 struct v4l2_priv_tun_config cfg = {
274 .tuner = dev->tuner_type,
277 tuner_call(dev, tuner, s_config, &cfg);
280 /* configure tuner */
282 f.type = V4L2_TUNER_ANALOG_TV;
283 f.frequency = 9076; /* just a magic number */
284 dev->ctl_freq = f.frequency;
285 call_all(dev, tuner, s_frequency, &f);
289 /* ----------------------------------------------------------------------- */
290 void cx231xx_register_i2c_ir(struct cx231xx *dev)
295 /* REVISIT: instantiate IR device */
297 /* detect & configure */
298 switch (dev->model) {
300 case CX231XX_BOARD_CNXT_RDE_250:
302 case CX231XX_BOARD_CNXT_RDU_250:
309 void cx231xx_card_setup(struct cx231xx *dev)
312 cx231xx_set_model(dev);
314 dev->tuner_type = cx231xx_boards[dev->model].tuner_type;
315 if (cx231xx_boards[dev->model].tuner_addr)
316 dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr;
318 /* request some modules */
319 if (dev->board.decoder == CX231XX_AVDECODER) {
320 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
321 &dev->i2c_bus[0].i2c_adap,
322 "cx25840", "cx25840", 0x88 >> 1, NULL);
323 if (dev->sd_cx25840 == NULL)
324 cx231xx_info("cx25840 subdev registration failure\n");
325 cx25840_call(dev, core, load_fw);
329 if (dev->board.tuner_type != TUNER_ABSENT) {
330 dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev,
331 &dev->i2c_bus[1].i2c_adap,
332 "tuner", "tuner", 0xc2 >> 1, NULL);
333 if (dev->sd_tuner == NULL)
334 cx231xx_info("tuner subdev registration failure\n");
336 cx231xx_config_tuner(dev);
339 cx231xx_config_tuner(dev);
342 /* TBD IR will be added later */
343 cx231xx_ir_init(dev);
349 * inits registers with sane defaults
351 int cx231xx_config(struct cx231xx *dev)
353 /* TBD need to add cx231xx specific code */
354 dev->mute = 1; /* maybe not the right place... */
361 * cx231xx_config_i2c()
362 * configure i2c attached devices
364 void cx231xx_config_i2c(struct cx231xx *dev)
366 /* u32 input = INPUT(dev->video_input)->vmux; */
368 call_all(dev, video, s_stream, 1);
372 * cx231xx_realease_resources()
373 * unregisters the v4l2,i2c and usb devices
374 * called when the device gets disconected or at module unload
376 void cx231xx_release_resources(struct cx231xx *dev)
379 #if 0 /* TBD IR related */
381 cx231xx_ir_fini(dev);
384 cx231xx_release_analog_resources(dev);
386 cx231xx_remove_from_devlist(dev);
388 cx231xx_dev_uninit(dev);
390 usb_put_dev(dev->udev);
392 /* Mark device as unused */
393 cx231xx_devused &= ~(1 << dev->devno);
398 * allocates and inits the device structs, registers i2c bus and v4l device
400 static int cx231xx_init_dev(struct cx231xx **devhandle, struct usb_device *udev,
403 struct cx231xx *dev = *devhandle;
404 int retval = -ENOMEM;
406 unsigned int maxh, maxw;
409 mutex_init(&dev->lock);
410 mutex_init(&dev->ctrl_urb_lock);
411 mutex_init(&dev->gpio_i2c_lock);
413 spin_lock_init(&dev->video_mode.slock);
414 spin_lock_init(&dev->vbi_mode.slock);
415 spin_lock_init(&dev->sliced_cc_mode.slock);
417 init_waitqueue_head(&dev->open);
418 init_waitqueue_head(&dev->wait_frame);
419 init_waitqueue_head(&dev->wait_stream);
421 dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg;
422 dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg;
423 dev->cx231xx_send_usb_command = cx231xx_send_usb_command;
424 dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read;
425 dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write;
427 /* Query cx231xx to find what pcb config it is related to */
428 initialize_cx231xx(dev);
430 /* Cx231xx pre card setup */
431 cx231xx_pre_card_setup(dev);
433 errCode = cx231xx_config(dev);
435 cx231xx_errdev("error configuring device\n");
439 /* set default norm */
440 dev->norm = dev->board.norm;
442 /* register i2c bus */
443 errCode = cx231xx_dev_init(dev);
445 cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
450 /* Do board specific init */
451 cx231xx_card_setup(dev);
453 /* configure the device */
454 cx231xx_config_i2c(dev);
456 maxw = norm_maxw(dev);
457 maxh = norm_maxh(dev);
459 /* set default image size */
465 dev->video_input = 0;
467 errCode = cx231xx_config(dev);
469 cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
474 /* init video dma queues */
475 INIT_LIST_HEAD(&dev->video_mode.vidq.active);
476 INIT_LIST_HEAD(&dev->video_mode.vidq.queued);
478 /* init vbi dma queues */
479 INIT_LIST_HEAD(&dev->vbi_mode.vidq.active);
480 INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued);
482 /* Reset other chips required if they are tied up with GPIO pins */
484 cx231xx_add_into_devlist(dev);
486 retval = cx231xx_register_analog_devices(dev);
488 cx231xx_release_resources(dev);
489 goto fail_reg_devices;
492 cx231xx_init_extension(dev);
497 mutex_unlock(&dev->lock);
501 #if defined(CONFIG_MODULES) && defined(MODULE)
502 static void request_module_async(struct work_struct *work)
504 struct cx231xx *dev = container_of(work,
505 struct cx231xx, request_module_wk);
507 if (dev->has_alsa_audio)
508 request_module("cx231xx-alsa");
510 if (dev->board.has_dvb)
511 request_module("cx231xx-dvb");
515 static void request_modules(struct cx231xx *dev)
517 INIT_WORK(&dev->request_module_wk, request_module_async);
518 schedule_work(&dev->request_module_wk);
521 #define request_modules(dev)
522 #endif /* CONFIG_MODULES */
525 * cx231xx_usb_probe()
526 * checks for supported devices
528 static int cx231xx_usb_probe(struct usb_interface *interface,
529 const struct usb_device_id *id)
531 struct usb_device *udev;
532 struct usb_interface *uif;
533 struct cx231xx *dev = NULL;
534 int retval = -ENODEV;
536 int i, isoc_pipe = 0;
538 char descr[255] = "";
539 struct usb_interface *lif = NULL;
540 int skip_interface = 0;
541 struct usb_interface_assoc_descriptor *assoc_desc;
543 udev = usb_get_dev(interface_to_usbdev(interface));
544 ifnum = interface->altsetting[0].desc.bInterfaceNumber;
548 * Interface number 0 - IR interface
550 /* Check to see next free device and mark as used */
551 nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
552 cx231xx_devused |= 1 << nr;
554 if (nr >= CX231XX_MAXBOARDS) {
555 cx231xx_err(DRIVER_NAME ": Supports only %i cx231xx boards.\n",
557 cx231xx_devused &= ~(1 << nr);
561 /* allocate memory for our device state and initialize it */
562 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
564 cx231xx_err(DRIVER_NAME ": out of memory!\n");
565 cx231xx_devused &= ~(1 << nr);
569 snprintf(dev->name, 29, "cx231xx #%d", nr);
571 dev->model = id->driver_info;
572 dev->video_mode.alt = -1;
573 dev->interface_count++;
575 /* reset gpio dir and value */
578 dev->xc_fw_load_done = 0;
579 dev->has_alsa_audio = 1;
580 dev->power_mode = -1;
582 /* 0 - vbi ; 1 -sliced cc mode */
583 dev->vbi_or_sliced_cc_mode = 0;
585 /* get maximum no.of IAD interfaces */
586 assoc_desc = udev->actconfig->intf_assoc[0];
587 dev->max_iad_interface_count = assoc_desc->bInterfaceCount;
589 /* init CIR module TBD */
591 /* store the current interface */
594 switch (udev->speed) {
598 case USB_SPEED_UNKNOWN:
609 if (udev->manufacturer)
610 strlcpy(descr, udev->manufacturer, sizeof(descr));
614 strlcat(descr, " ", sizeof(descr));
615 strlcat(descr, udev->product, sizeof(descr));
618 strlcat(descr, " ", sizeof(descr));
620 cx231xx_info("New device %s@ %s Mbps "
621 "(%04x:%04x) with %d interfaces\n",
624 le16_to_cpu(udev->descriptor.idVendor),
625 le16_to_cpu(udev->descriptor.idProduct),
626 dev->max_iad_interface_count);
628 /* Get dev structure first */
629 dev = usb_get_intfdata(udev->actconfig->interface[0]);
631 cx231xx_err(DRIVER_NAME ": out of first interface!\n");
635 /* store the interface 0 back */
636 lif = udev->actconfig->interface[0];
638 /* increment interface count */
639 dev->interface_count++;
641 /* get device number */
645 * set skip interface, for all interfaces but
646 * interface 1 and the last one
648 if ((ifnum != 1) && ((dev->interface_count - 1)
649 != dev->max_iad_interface_count))
653 assoc_desc = udev->actconfig->intf_assoc[0];
654 if (assoc_desc->bFirstInterface != ifnum) {
655 cx231xx_err(DRIVER_NAME ": Not found "
656 "matching IAD interface\n");
665 cx231xx_info("registering interface %d\n", ifnum);
667 /* save our data pointer in this interface device */
668 usb_set_intfdata(lif, dev);
670 if ((dev->interface_count - 1) != dev->max_iad_interface_count)
674 * AV device initialization - only done at the last interface
677 /* Create v4l2 device */
678 retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
680 cx231xx_errdev("v4l2_device_register failed\n");
681 cx231xx_devused &= ~(1 << nr);
686 /* allocate device struct */
687 retval = cx231xx_init_dev(&dev, udev, nr);
689 cx231xx_devused &= ~(1 << dev->devno);
690 v4l2_device_unregister(&dev->v4l2_dev);
695 /* compute alternate max packet sizes for video */
696 uif = udev->actconfig->interface[dev->current_pcb_config.
697 hs_config_info[0].interface_info.video_index + 1];
699 dev->video_mode.end_point_addr = le16_to_cpu(uif->altsetting[0].
700 endpoint[isoc_pipe].desc.bEndpointAddress);
702 dev->video_mode.num_alt = uif->num_altsetting;
703 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
704 dev->video_mode.end_point_addr,
705 dev->video_mode.num_alt);
706 dev->video_mode.alt_max_pkt_size =
707 kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL);
709 if (dev->video_mode.alt_max_pkt_size == NULL) {
710 cx231xx_errdev("out of memory!\n");
711 cx231xx_devused &= ~(1 << nr);
712 v4l2_device_unregister(&dev->v4l2_dev);
717 for (i = 0; i < dev->video_mode.num_alt; i++) {
718 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
719 desc.wMaxPacketSize);
720 dev->video_mode.alt_max_pkt_size[i] =
721 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
722 cx231xx_info("Alternate setting %i, max size= %i\n", i,
723 dev->video_mode.alt_max_pkt_size[i]);
726 /* compute alternate max packet sizes for vbi */
727 uif = udev->actconfig->interface[dev->current_pcb_config.
728 hs_config_info[0].interface_info.
731 dev->vbi_mode.end_point_addr =
732 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
735 dev->vbi_mode.num_alt = uif->num_altsetting;
736 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
737 dev->vbi_mode.end_point_addr,
738 dev->vbi_mode.num_alt);
739 dev->vbi_mode.alt_max_pkt_size =
740 kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL);
742 if (dev->vbi_mode.alt_max_pkt_size == NULL) {
743 cx231xx_errdev("out of memory!\n");
744 cx231xx_devused &= ~(1 << nr);
745 v4l2_device_unregister(&dev->v4l2_dev);
750 for (i = 0; i < dev->vbi_mode.num_alt; i++) {
752 le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
753 desc.wMaxPacketSize);
754 dev->vbi_mode.alt_max_pkt_size[i] =
755 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
756 cx231xx_info("Alternate setting %i, max size= %i\n", i,
757 dev->vbi_mode.alt_max_pkt_size[i]);
760 /* compute alternate max packet sizes for sliced CC */
761 uif = udev->actconfig->interface[dev->current_pcb_config.
762 hs_config_info[0].interface_info.
765 dev->sliced_cc_mode.end_point_addr =
766 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
769 dev->sliced_cc_mode.num_alt = uif->num_altsetting;
770 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
771 dev->sliced_cc_mode.end_point_addr,
772 dev->sliced_cc_mode.num_alt);
773 dev->sliced_cc_mode.alt_max_pkt_size =
774 kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL);
776 if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
777 cx231xx_errdev("out of memory!\n");
778 cx231xx_devused &= ~(1 << nr);
779 v4l2_device_unregister(&dev->v4l2_dev);
784 for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
785 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
786 desc.wMaxPacketSize);
787 dev->sliced_cc_mode.alt_max_pkt_size[i] =
788 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
789 cx231xx_info("Alternate setting %i, max size= %i\n", i,
790 dev->sliced_cc_mode.alt_max_pkt_size[i]);
793 if (dev->current_pcb_config.ts1_source != 0xff) {
794 /* compute alternate max packet sizes for TS1 */
795 uif = udev->actconfig->interface[dev->current_pcb_config.
800 dev->ts1_mode.end_point_addr =
801 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].
802 desc.bEndpointAddress);
804 dev->ts1_mode.num_alt = uif->num_altsetting;
805 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
806 dev->ts1_mode.end_point_addr,
807 dev->ts1_mode.num_alt);
808 dev->ts1_mode.alt_max_pkt_size =
809 kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL);
811 if (dev->ts1_mode.alt_max_pkt_size == NULL) {
812 cx231xx_errdev("out of memory!\n");
813 cx231xx_devused &= ~(1 << nr);
814 v4l2_device_unregister(&dev->v4l2_dev);
819 for (i = 0; i < dev->ts1_mode.num_alt; i++) {
820 u16 tmp = le16_to_cpu(uif->altsetting[i].
821 endpoint[isoc_pipe].desc.
823 dev->ts1_mode.alt_max_pkt_size[i] =
824 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
825 cx231xx_info("Alternate setting %i, max size= %i\n", i,
826 dev->ts1_mode.alt_max_pkt_size[i]);
830 /* load other modules required */
831 request_modules(dev);
837 * cx231xx_usb_disconnect()
838 * called when the device gets diconencted
839 * video device will be unregistered on v4l2_close in case it is still open
841 static void cx231xx_usb_disconnect(struct usb_interface *interface)
845 dev = usb_get_intfdata(interface);
846 usb_set_intfdata(interface, NULL);
854 /* delete v4l2 device */
855 v4l2_device_unregister(&dev->v4l2_dev);
857 /* wait until all current v4l2 io is finished then deallocate
859 mutex_lock(&dev->lock);
861 wake_up_interruptible_all(&dev->open);
865 ("device %s is open! Deregistration and memory "
866 "deallocation are deferred on close.\n",
867 video_device_node_name(dev->vdev));
869 dev->state |= DEV_MISCONFIGURED;
870 cx231xx_uninit_isoc(dev);
871 dev->state |= DEV_DISCONNECTED;
872 wake_up_interruptible(&dev->wait_frame);
873 wake_up_interruptible(&dev->wait_stream);
875 dev->state |= DEV_DISCONNECTED;
876 cx231xx_release_resources(dev);
879 cx231xx_close_extension(dev);
881 mutex_unlock(&dev->lock);
884 kfree(dev->video_mode.alt_max_pkt_size);
885 kfree(dev->vbi_mode.alt_max_pkt_size);
886 kfree(dev->sliced_cc_mode.alt_max_pkt_size);
887 kfree(dev->ts1_mode.alt_max_pkt_size);
892 static struct usb_driver cx231xx_usb_driver = {
894 .probe = cx231xx_usb_probe,
895 .disconnect = cx231xx_usb_disconnect,
896 .id_table = cx231xx_id_table,
899 static int __init cx231xx_module_init(void)
903 printk(KERN_INFO DRIVER_NAME " v4l2 driver loaded.\n");
905 /* register this driver with the USB subsystem */
906 result = usb_register(&cx231xx_usb_driver);
908 cx231xx_err(DRIVER_NAME
909 " usb_register failed. Error number %d.\n", result);
914 static void __exit cx231xx_module_exit(void)
916 /* deregister this driver with the USB subsystem */
917 usb_deregister(&cx231xx_usb_driver);
920 module_init(cx231xx_module_init);
921 module_exit(cx231xx_module_exit);