blob: 27cf51b78d6db1c49a4b8e661d499945ec290186 [file] [log] [blame]
Sri Deevie0d3baf2009-03-03 14:37:50 -03001/*
2 cx231xx-cards.c - driver for Conexant Cx23100/101/102 USB video capture devices
3
4 Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03005 Based on em28xx driver
Sri Deevie0d3baf2009-03-03 14:37:50 -03006
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.
11
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.
16
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.
20 */
21
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>
31
32#include <media/cx25840.h>
33#include "xc5000.h"
34
35#include "cx231xx.h"
36
37static int tuner = -1;
38module_param(tuner, int, 0444);
39MODULE_PARM_DESC(tuner, "tuner type");
40
41static unsigned int disable_ir;
42module_param(disable_ir, int, 0444);
43MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
44
45/* Bitmask marking allocated devices from 0 to CX231XX_MAXBOARDS */
46static unsigned long cx231xx_devused;
47
48/*
49 * Reset sequences for analog/digital modes
50 */
51
52static struct cx231xx_reg_seq RDE250_XCV_TUNER[] = {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -030053 {0x03, 0x01, 10},
54 {0x03, 0x00, 30},
55 {0x03, 0x01, 10},
56 {-1, -1, -1},
Sri Deevie0d3baf2009-03-03 14:37:50 -030057};
58
Sri Deevie0d3baf2009-03-03 14:37:50 -030059/*
60 * Board definitions
61 */
62struct cx231xx_board cx231xx_boards[] = {
63
64 [CX231XX_BOARD_UNKNOWN] = {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -030065 .name = "Unknown CX231xx video grabber",
66 .tuner_type = TUNER_ABSENT,
67 .input = {{
68 .type = CX231XX_VMUX_TELEVISION,
69 .vmux = CX231XX_VIN_3_1,
70 .amux = CX231XX_AMUX_VIDEO,
71 .gpio = 0,
72 }, {
73 .type =
74 CX231XX_VMUX_COMPOSITE1,
75 .vmux = CX231XX_VIN_2_1,
76 .amux = CX231XX_AMUX_LINE_IN,
77 .gpio = 0,
78 }, {
79 .type =
80 CX231XX_VMUX_SVIDEO,
81 .vmux =
82 CX231XX_VIN_1_1 |
83 (CX231XX_VIN_1_2 << 8) |
84 CX25840_SVIDEO_ON,
85 .amux =
86 CX231XX_AMUX_LINE_IN,
87 .gpio = 0,
88 }},
89 },
Sri Deevie0d3baf2009-03-03 14:37:50 -030090
91 [CX231XX_BOARD_CNXT_RDE_250] = {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -030092 .name = "Conexant Hybrid TV - RDE250",
93 .valid = CX231XX_BOARD_VALIDATED,
94 .tuner_type = TUNER_XC5000,
95 .tuner_addr = 0x61,
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,
107 .has_dvb = 1,
108 .demod_addr = 0x02,
109 .norm = V4L2_STD_PAL,
Sri Deevie0d3baf2009-03-03 14:37:50 -0300110
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300111 .input = {{
112 .type =
113 CX231XX_VMUX_TELEVISION,
114 .vmux = CX231XX_VIN_3_1,
115 .amux = CX231XX_AMUX_VIDEO,
116 .gpio = 0,
117 }, {
118 .type =
119 CX231XX_VMUX_COMPOSITE1,
120 .vmux = CX231XX_VIN_2_1,
121 .amux =
122 CX231XX_AMUX_LINE_IN,
123 .gpio = 0,
124 }, {
125 .type =
126 CX231XX_VMUX_SVIDEO,
127 .vmux =
128 CX231XX_VIN_1_1 |
129 (CX231XX_VIN_1_2 <<
130 8) |
131 CX25840_SVIDEO_ON,
132 .amux =
133 CX231XX_AMUX_LINE_IN,
134 .gpio = 0,
135 }},
136 },
Sri Deevie0d3baf2009-03-03 14:37:50 -0300137
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300138 [CX231XX_BOARD_CNXT_RDU_250] = {
139 .name = "Conexant Hybrid TV - RDU250",
140 .valid = CX231XX_BOARD_VALIDATED,
141 .tuner_type = TUNER_XC5000,
142 .tuner_addr = 0x61,
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,
154 .has_dvb = 1,
155 .demod_addr = 0x32,
156 .norm = V4L2_STD_NTSC,
Sri Deevie0d3baf2009-03-03 14:37:50 -0300157
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300158 .input = {{
159 .type =
160 CX231XX_VMUX_TELEVISION,
161 .vmux = CX231XX_VIN_3_1,
162 .amux = CX231XX_AMUX_VIDEO,
163 .gpio = 0,
164 }, {
165 .type =
166 CX231XX_VMUX_COMPOSITE1,
167 .vmux = CX231XX_VIN_2_1,
168 .amux =
169 CX231XX_AMUX_LINE_IN,
170 .gpio = 0,
171 }, {
172 .type =
173 CX231XX_VMUX_SVIDEO,
174 .vmux =
175 CX231XX_VIN_1_1 |
176 (CX231XX_VIN_1_2 <<
177 8) |
178 CX25840_SVIDEO_ON,
179 .amux =
180 CX231XX_AMUX_LINE_IN,
181 .gpio = 0,
182 }},
183 },
Sri Deevie0d3baf2009-03-03 14:37:50 -0300184};
185const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
186
187/* table of devices that work with this driver */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300188struct 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},
195 {},
Sri Deevie0d3baf2009-03-03 14:37:50 -0300196};
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300197
Sri Deevie0d3baf2009-03-03 14:37:50 -0300198MODULE_DEVICE_TABLE(usb, cx231xx_id_table);
199
200/* cx231xx_tuner_callback
201 * will be used to reset XC5000 tuner using GPIO pin
202 */
203
204int cx231xx_tuner_callback(void *ptr, int component, int command, int arg)
205{
206 int rc = 0;
207 struct cx231xx *dev = ptr;
208
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300209 if (dev->tuner_type == TUNER_XC5000) {
210 if (command == XC5000_TUNER_RESET) {
211 cx231xx_info
212 ("Tuner Call back : RESET : command %d : tuner type %d \n",
213 command, dev->tuner_type);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300214
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300215 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
216 1);
217 msleep(10);
218 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
219 0);
220 msleep(330);
221 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
222 1);
223 msleep(10);
224 }
225 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300226 return rc;
227}
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300228
Sri Deevie0d3baf2009-03-03 14:37:50 -0300229EXPORT_SYMBOL_GPL(cx231xx_tuner_callback);
230
231static void inline cx231xx_set_model(struct cx231xx *dev)
232{
233 memcpy(&dev->board, &cx231xx_boards[dev->model], sizeof(dev->board));
234}
235
236/* Since cx231xx_pre_card_setup() requires a proper dev->model,
237 * this won't work for boards with generic PCI IDs
238 */
239void cx231xx_pre_card_setup(struct cx231xx *dev)
240{
241
242 cx231xx_set_model(dev);
243
244 cx231xx_info("Identified as %s (card=%d)\n",
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300245 dev->board.name, dev->model);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300246
247 /* Do card specific if any */
248 switch (dev->model) {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300249 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);
256 break;
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);
264 break;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300265 }
266
267 /* request some modules if any required */
268
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300269 /* reset the Tuner */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300270 cx231xx_gpio_set(dev, dev->board.tuner_gpio);
271
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300272 /* set the mode to Analog mode initially */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300273 cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
274
275 /* Unlock device */
276 /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */
277
278}
279
280#if 0
281
282static void cx231xx_config_tuner(struct cx231xx *dev)
283{
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300284 struct tuner_setup tun_setup;
285 struct v4l2_frequency f;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300286
287 if (dev->tuner_type == TUNER_ABSENT)
288 return;
289
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;
294
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300295 cx231xx_i2c_call_clients(&dev->i2c_bus[1], TUNER_SET_TYPE_ADDR,
296 &tun_setup);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300297#if 0
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300298 if (tun_setup.type == TUNER_XC5000) {
Sri Deevie0d3baf2009-03-03 14:37:50 -0300299 static struct xc2028_ctrl ctrl = {
300 .fname = XC5000_DEFAULT_FIRMWARE,
301 .max_len = 64,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300302 .demod = 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300303 };
304 struct v4l2_priv_tun_config cfg = {
305 .tuner = dev->tuner_type,
306 .priv = &ctrl,
307 };
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300308 cx231xx_i2c_call_clients(&dev->i2c_bus[1], TUNER_SET_CONFIG,
309 &cfg);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300310 }
311#endif
312
313 /* configure tuner */
314 f.tuner = 0;
315 f.type = V4L2_TUNER_ANALOG_TV;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300316 f.frequency = 9076; /* just a magic number */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300317 dev->ctl_freq = f.frequency;
318 cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_FREQUENCY, &f);
319}
320
321#endif
322
323/* ----------------------------------------------------------------------- */
324void cx231xx_set_ir(struct cx231xx *dev, struct IR_i2c *ir)
325{
326 if (disable_ir) {
327 ir->get_key = NULL;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300328 return;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300329 }
330
331 /* detect & configure */
332 switch (dev->model) {
333
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300334 case CX231XX_BOARD_CNXT_RDE_250:
335 break;
336 case CX231XX_BOARD_CNXT_RDU_250:
337 break;
338 default:
339 break;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300340 }
341}
342
343void cx231xx_card_setup(struct cx231xx *dev)
344{
345 cx231xx_set_model(dev);
346
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;
350
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300351 cx231xx_info(": tuner type %d, tuner address %d \n",
352 dev->tuner_type, dev->tuner_addr);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300353
354 /* Do card specific if any */
355 switch (dev->model) {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300356 case CX231XX_BOARD_CNXT_RDE_250:
357 /* do card specific GPIO settings if required */
358 cx231xx_info("Board is Conexnat RDE 250\n");
359 break;
360 case CX231XX_BOARD_CNXT_RDU_250:
361 /* do card specific GPIO settings if required */
362 cx231xx_info("Board is Conexnat RDU 250\n");
363 break;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300364 }
365
366 if (dev->board.valid == CX231XX_BOARD_NOT_VALIDATED) {
367 cx231xx_errdev("\n\n");
368 cx231xx_errdev("The support for this board weren't "
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300369 "valid yet.\n");
Sri Deevie0d3baf2009-03-03 14:37:50 -0300370 cx231xx_errdev("Please send a report of having this working\n");
371 cx231xx_errdev("not to V4L mailing list (and/or to other "
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300372 "addresses)\n\n");
Sri Deevie0d3baf2009-03-03 14:37:50 -0300373 }
374
Sri Deevie0d3baf2009-03-03 14:37:50 -0300375 /* request some modules */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300376 if (dev->board.decoder == CX231XX_AVDECODER) {
377 cx231xx_info(": Requesting cx25840 module\n");
Sri Deevie0d3baf2009-03-03 14:37:50 -0300378 request_module("cx25840");
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300379 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300380#if 0
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300381 if (dev->board.tuner_type != TUNER_ABSENT) {
382 cx231xx_info(": Requesting Tuner module\n");
Sri Deevie0d3baf2009-03-03 14:37:50 -0300383 request_module("tuner");
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300384 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300385
386 cx231xx_config_tuner(dev);
387
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300388 /* TBD IR will be added later */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300389 cx231xx_ir_init(dev);
390#endif
391}
392
Sri Deevie0d3baf2009-03-03 14:37:50 -0300393/*
394 * cx231xx_config()
395 * inits registers with sane defaults
396 */
397int cx231xx_config(struct cx231xx *dev)
398{
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300399 /* TBD need to add cx231xx specific code */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300400 dev->mute = 1; /* maybe not the right place... */
401 dev->volume = 0x1f;
402
403 return 0;
404}
405
406/*
407 * cx231xx_config_i2c()
408 * configure i2c attached devices
409 */
410void cx231xx_config_i2c(struct cx231xx *dev)
411{
412 struct v4l2_routing route;
413
414 route.input = INPUT(dev->video_input)->vmux;
415 route.output = 0;
416
417 cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_STREAMON, NULL);
418}
419
420/*
421 * cx231xx_realease_resources()
422 * unregisters the v4l2,i2c and usb devices
423 * called when the device gets disconected or at module unload
424*/
425void cx231xx_release_resources(struct cx231xx *dev)
426{
427
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300428#if 0 /* TBD IR related */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300429 if (dev->ir)
430 cx231xx_ir_fini(dev);
431#endif
432
433 cx231xx_release_analog_resources(dev);
434
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300435 cx231xx_remove_from_devlist(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300436
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300437 cx231xx_dev_uninit(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300438
439 usb_put_dev(dev->udev);
440
441 /* Mark device as unused */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300442 cx231xx_devused &= ~(1 << dev->devno);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300443}
444
Sri Deevie0d3baf2009-03-03 14:37:50 -0300445/*
446 * cx231xx_init_dev()
447 * allocates and inits the device structs, registers i2c bus and v4l device
448 */
449static int cx231xx_init_dev(struct cx231xx **devhandle, struct usb_device *udev,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300450 int minor)
Sri Deevie0d3baf2009-03-03 14:37:50 -0300451{
452 struct cx231xx *dev = *devhandle;
453 int retval = -ENOMEM;
454 int errCode;
455 unsigned int maxh, maxw;
456
457 dev->udev = udev;
458 mutex_init(&dev->lock);
459 mutex_init(&dev->ctrl_urb_lock);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300460 mutex_init(&dev->gpio_i2c_lock);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300461
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300462 spin_lock_init(&dev->video_mode.slock);
463 spin_lock_init(&dev->vbi_mode.slock);
464 spin_lock_init(&dev->sliced_cc_mode.slock);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300465
466 init_waitqueue_head(&dev->open);
467 init_waitqueue_head(&dev->wait_frame);
468 init_waitqueue_head(&dev->wait_stream);
469
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300470 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;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300475
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300476 /* Query cx231xx to find what pcb config it is related to */
477 initialize_cx231xx(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300478
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300479 /* Cx231xx pre card setup */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300480 cx231xx_pre_card_setup(dev);
481
482 errCode = cx231xx_config(dev);
483 if (errCode) {
484 cx231xx_errdev("error configuring device\n");
485 return -ENOMEM;
486 }
487
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300488 /* set default norm */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300489 dev->norm = dev->board.norm;
490
491 /* register i2c bus */
492 errCode = cx231xx_dev_init(dev);
493 if (errCode < 0) {
494 cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300495 __func__, errCode);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300496 return errCode;
497 }
498
499 /* Do board specific init */
500 cx231xx_card_setup(dev);
501
502 /* configure the device */
503 cx231xx_config_i2c(dev);
504
505 maxw = norm_maxw(dev);
506 maxh = norm_maxh(dev);
507
508 /* set default image size */
509 dev->width = maxw;
510 dev->height = maxh;
511 dev->interlaced = 0;
512 dev->hscale = 0;
513 dev->vscale = 0;
514 dev->video_input = 0;
515
516 errCode = cx231xx_config(dev);
517 if (errCode < 0) {
518 cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300519 __func__, errCode);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300520 return errCode;
521 }
522
523 /* init video dma queues */
524 INIT_LIST_HEAD(&dev->video_mode.vidq.active);
525 INIT_LIST_HEAD(&dev->video_mode.vidq.queued);
526
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300527 /* init vbi dma queues */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300528 INIT_LIST_HEAD(&dev->vbi_mode.vidq.active);
529 INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued);
530
531 /* Reset other chips required if they are tied up with GPIO pins */
532
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300533 cx231xx_add_into_devlist(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300534
535 retval = cx231xx_register_analog_devices(dev);
536 if (retval < 0) {
537 cx231xx_release_resources(dev);
538 goto fail_reg_devices;
539 }
540
541 cx231xx_init_extension(dev);
542
543 return 0;
544
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300545 fail_reg_devices:
Sri Deevie0d3baf2009-03-03 14:37:50 -0300546 mutex_unlock(&dev->lock);
547 return retval;
548}
549
550#if defined(CONFIG_MODULES) && defined(MODULE)
551static void request_module_async(struct work_struct *work)
552{
553 struct cx231xx *dev = container_of(work,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300554 struct cx231xx, request_module_wk);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300555
556 if (dev->has_alsa_audio)
557 request_module("cx231xx-alsa");
558
559 if (dev->board.has_dvb)
560 request_module("cx231xx-dvb");
561
562}
563
564static void request_modules(struct cx231xx *dev)
565{
566 INIT_WORK(&dev->request_module_wk, request_module_async);
567 schedule_work(&dev->request_module_wk);
568}
569#else
570#define request_modules(dev)
571#endif /* CONFIG_MODULES */
572
Sri Deevie0d3baf2009-03-03 14:37:50 -0300573/*
574 * cx231xx_usb_probe()
575 * checks for supported devices
576 */
577static int cx231xx_usb_probe(struct usb_interface *interface,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300578 const struct usb_device_id *id)
Sri Deevie0d3baf2009-03-03 14:37:50 -0300579{
580 struct usb_device *udev;
581 struct usb_interface *uif;
582 struct cx231xx *dev = NULL;
583 int retval = -ENODEV;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300584 int nr, ifnum;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300585 int i, isoc_pipe = 0;
586 char *speed;
587 char descr[255] = "";
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300588 struct usb_interface *lif = NULL;
589 int skip_interface = 0;
590 struct usb_interface_assoc_descriptor *assoc_desc;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300591
592 udev = usb_get_dev(interface_to_usbdev(interface));
593 ifnum = interface->altsetting[0].desc.bInterfaceNumber;
594
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300595 cx231xx_info(": Interface Number %d\n", ifnum);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300596
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300597 /* Interface number 0 - IR interface */
598 if (ifnum == 0) {
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;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300602
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300603 if (nr >= CX231XX_MAXBOARDS) {
604 cx231xx_info(": Supports only %i cx231xx boards.\n",
605 CX231XX_MAXBOARDS);
606 cx231xx_devused &= ~(1 << nr);
607 return -ENOMEM;
608 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300609
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300610 /* allocate memory for our device state and initialize it */
611 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
612 if (dev == NULL) {
613 cx231xx_err(DRIVER_NAME ": out of memory!\n");
614 cx231xx_devused &= ~(1 << nr);
615 return -ENOMEM;
616 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300617
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300618 snprintf(dev->name, 29, "cx231xx #%d", nr);
619 dev->devno = nr;
620 dev->model = id->driver_info;
621 dev->video_mode.alt = -1;
622 dev->interface_count++;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300623
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300624 /* reset gpio dir and value */
625 dev->gpio_dir = 0;
626 dev->gpio_val = 0;
627 dev->xc_fw_load_done = 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300628 dev->has_alsa_audio = 1;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300629 dev->power_mode = -1;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300630
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300631 dev->vbi_or_sliced_cc_mode = 0; /* 0 - vbi ; 1 -sliced cc mode */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300632
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300633 /* 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);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300638
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300639 /* init CIR module TBD */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300640
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300641 /* store the current interface */
642 lif = interface;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300643
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300644 } else if (ifnum == 1) {
Sri Deevie0d3baf2009-03-03 14:37:50 -0300645
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300646 /* Get dev structure first */
647 dev = usb_get_intfdata(udev->actconfig->interface[0]);
648 if (dev == NULL) {
649 cx231xx_err(DRIVER_NAME ": out of first interface!\n");
650 return -ENODEV;
651 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300652
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300653 /* store the interface 0 back */
654 lif = udev->actconfig->interface[0];
Sri Deevie0d3baf2009-03-03 14:37:50 -0300655
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300656 /* increment interface count */
657 dev->interface_count++;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300658
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300659 /* get device number */
660 nr = dev->devno;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300661
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300662 assoc_desc = udev->actconfig->intf_assoc[0];
663 if (assoc_desc->bFirstInterface == ifnum) {
664 cx231xx_info
665 (": Found IAD interface match: AV Descriptor Start!! \n");
666 } else {
667 cx231xx_err(DRIVER_NAME
668 " Not found matching interface\n");
669 return -ENODEV;
670 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300671
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300672 } else if (ifnum >= 2) {
673 /* Get dev structure first */
674 dev = usb_get_intfdata(udev->actconfig->interface[0]);
675 if (dev == NULL) {
676 cx231xx_err(DRIVER_NAME ": out of first interface!\n");
677 return -ENODEV;
678 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300679
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300680 /* store the interface 0 back */
681 lif = udev->actconfig->interface[0];
Sri Deevie0d3baf2009-03-03 14:37:50 -0300682
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300683 /* increment interface count */
684 dev->interface_count++;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300685
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300686 /* get device number */
687 nr = dev->devno;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300688
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300689 /* set skip interface */
690 if ((dev->interface_count - 1) != dev->max_iad_interface_count)
691 skip_interface = 1; /* set skipping */
692 else {
693 cx231xx_info
694 (": Found IAD interface number match with AV Device number!! \n");
695 }
696 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300697
698 switch (udev->speed) {
699 case USB_SPEED_LOW:
700 speed = "1.5";
701 break;
702 case USB_SPEED_UNKNOWN:
703 case USB_SPEED_FULL:
704 speed = "12";
705 break;
706 case USB_SPEED_HIGH:
707 speed = "480";
708 break;
709 default:
710 speed = "unknown";
711 }
712
713 if (udev->manufacturer)
714 strlcpy(descr, udev->manufacturer, sizeof(descr));
715
716 if (udev->product) {
717 if (*descr)
718 strlcat(descr, " ", sizeof(descr));
719 strlcat(descr, udev->product, sizeof(descr));
720 }
721 if (*descr)
722 strlcat(descr, " ", sizeof(descr));
723
724 cx231xx_info("New device %s@ %s Mbps "
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300725 "(%04x:%04x, interface %d, class %d)\n",
726 descr,
727 speed,
728 le16_to_cpu(udev->descriptor.idVendor),
729 le16_to_cpu(udev->descriptor.idProduct),
730 ifnum, interface->altsetting->desc.bInterfaceNumber);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300731
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300732 /* 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);
737 if (retval) {
738 cx231xx_devused &= ~(1 << dev->devno);
739 kfree(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300740
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300741 return retval;
742 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300743
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300744 /* compute alternate max packet sizes for video */
745 uif =
746 udev->actconfig->interface[dev->current_pcb_config.
747 hs_config_info[0].interface_info.
748 video_index + 1];
Sri Deevie0d3baf2009-03-03 14:37:50 -0300749
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300750 dev->video_mode.end_point_addr =
751 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
752 bEndpointAddress);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300753
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300754 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);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300760
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300761 if (dev->video_mode.alt_max_pkt_size == NULL) {
762 cx231xx_errdev("out of memory!\n");
763 cx231xx_devused &= ~(1 << nr);
764 kfree(dev);
765 return -ENOMEM;
766 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300767
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300768 for (i = 0; i < dev->video_mode.num_alt; i++) {
769 u16 tmp =
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]);
776 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300777
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300778 /* compute alternate max packet sizes for vbi */
779 uif =
780 udev->actconfig->interface[dev->current_pcb_config.
781 hs_config_info[0].interface_info.
782 vanc_index + 1];
Sri Deevie0d3baf2009-03-03 14:37:50 -0300783
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300784 dev->vbi_mode.end_point_addr =
785 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
786 bEndpointAddress);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300787
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300788 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);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300794
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300795 if (dev->vbi_mode.alt_max_pkt_size == NULL) {
796 cx231xx_errdev("out of memory!\n");
797 cx231xx_devused &= ~(1 << nr);
798 kfree(dev);
799 return -ENOMEM;
800 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300801
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300802 for (i = 0; i < dev->vbi_mode.num_alt; i++) {
803 u16 tmp =
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]);
810 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300811
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300812 /* compute alternate max packet sizes for sliced CC */
813 uif =
814 udev->actconfig->interface[dev->current_pcb_config.
815 hs_config_info[0].interface_info.
816 hanc_index + 1];
Sri Deevie0d3baf2009-03-03 14:37:50 -0300817
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300818 dev->sliced_cc_mode.end_point_addr =
819 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
820 bEndpointAddress);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300821
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300822 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);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300828
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300829 if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
830 cx231xx_errdev("out of memory!\n");
831 cx231xx_devused &= ~(1 << nr);
832 kfree(dev);
833 return -ENOMEM;
834 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300835
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300836 for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
837 u16 tmp =
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]);
844 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300845
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300846 if (dev->current_pcb_config.ts1_source != 0xff) {
Sri Deevie0d3baf2009-03-03 14:37:50 -0300847
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300848 /* compute alternate max packet sizes for TS1 */
849 uif =
850 udev->actconfig->interface[dev->current_pcb_config.
851 hs_config_info[0].
852 interface_info.
853 ts1_index + 1];
Sri Deevie0d3baf2009-03-03 14:37:50 -0300854
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300855 dev->ts1_mode.end_point_addr =
856 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].
857 desc.bEndpointAddress);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300858
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300859 dev->ts1_mode.num_alt = uif->num_altsetting;
860 cx231xx_info
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);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300866
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300867 if (dev->ts1_mode.alt_max_pkt_size == NULL) {
868 cx231xx_errdev("out of memory!\n");
869 cx231xx_devused &= ~(1 << nr);
870 kfree(dev);
871 return -ENOMEM;
872 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300873
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300874 for (i = 0; i < dev->ts1_mode.num_alt; i++) {
875 u16 tmp =
876 le16_to_cpu(uif->altsetting[i].
877 endpoint[isoc_pipe].desc.
878 wMaxPacketSize);
879 dev->ts1_mode.alt_max_pkt_size[i] =
880 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) +
881 1);
882 cx231xx_info
883 ("Alternate setting %i, max size= %i\n", i,
884 dev->ts1_mode.alt_max_pkt_size[i]);
885 }
886 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300887
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300888 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300889
890 /* save our data pointer in this interface device */
891 usb_set_intfdata(lif, dev);
892
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300893 /* 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);
897 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300898
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300899 if (skip_interface) {
900 cx231xx_info("Skipping the interface\n");
901 return -ENODEV;
902 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300903
904 return 0;
905}
906
907/*
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
911 */
912static void cx231xx_usb_disconnect(struct usb_interface *interface)
913{
914 struct cx231xx *dev;
915
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300916 dev = usb_get_intfdata(interface);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300917 usb_set_intfdata(interface, NULL);
918
919 if (!dev)
920 return;
921
922 /* wait until all current v4l2 io is finished then deallocate
923 resources */
924 mutex_lock(&dev->lock);
925
926 wake_up_interruptible_all(&dev->open);
927
928 if (dev->users) {
929 cx231xx_warn
930 ("device /dev/video%d is open! Deregistration and memory "
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300931 "deallocation are deferred on close.\n", dev->vdev->num);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300932
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);
938 } else {
939 dev->state |= DEV_DISCONNECTED;
940 cx231xx_release_resources(dev);
941 }
942
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300943 cx231xx_close_extension(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300944
945 mutex_unlock(&dev->lock);
946
947 if (!dev->users) {
948 kfree(dev->video_mode.alt_max_pkt_size);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300949 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);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300952 kfree(dev);
953 }
954}
955
956static struct usb_driver cx231xx_usb_driver = {
957 .name = "cx231xx",
958 .probe = cx231xx_usb_probe,
959 .disconnect = cx231xx_usb_disconnect,
960 .id_table = cx231xx_id_table,
961};
962
963static int __init cx231xx_module_init(void)
964{
965 int result;
966
Mauro Carvalho Chehab818fdf32009-03-13 07:41:58 -0300967 printk(KERN_INFO DRIVER_NAME " v4l2 driver loaded.\n");
Sri Deevie0d3baf2009-03-03 14:37:50 -0300968
969 /* register this driver with the USB subsystem */
970 result = usb_register(&cx231xx_usb_driver);
971 if (result)
972 cx231xx_err(DRIVER_NAME
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300973 " usb_register failed. Error number %d.\n", result);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300974
975 return result;
976}
977
978static void __exit cx231xx_module_exit(void)
979{
980 /* deregister this driver with the USB subsystem */
981 usb_deregister(&cx231xx_usb_driver);
982}
983
984module_init(cx231xx_module_init);
985module_exit(cx231xx_module_exit);