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 int transfer_mode
= 1;
45 module_param(transfer_mode
, int, 0444);
46 MODULE_PARM_DESC(transfer_mode
, "transfer mode (1-ISO or 0-BULK)");
48 static unsigned int disable_ir
;
49 module_param(disable_ir
, int, 0444);
50 MODULE_PARM_DESC(disable_ir
, "disable infrared remote support");
52 /* Bitmask marking allocated devices from 0 to CX231XX_MAXBOARDS */
53 static unsigned long cx231xx_devused
;
56 * Reset sequences for analog/digital modes
59 static struct cx231xx_reg_seq RDE250_XCV_TUNER
[] = {
69 struct cx231xx_board cx231xx_boards
[] = {
70 [CX231XX_BOARD_UNKNOWN
] = {
71 .name
= "Unknown CX231xx video grabber",
72 .tuner_type
= TUNER_ABSENT
,
74 .type
= CX231XX_VMUX_TELEVISION
,
75 .vmux
= CX231XX_VIN_3_1
,
76 .amux
= CX231XX_AMUX_VIDEO
,
79 .type
= CX231XX_VMUX_COMPOSITE1
,
80 .vmux
= CX231XX_VIN_2_1
,
81 .amux
= CX231XX_AMUX_LINE_IN
,
84 .type
= CX231XX_VMUX_SVIDEO
,
85 .vmux
= CX231XX_VIN_1_1
|
86 (CX231XX_VIN_1_2
<< 8) |
88 .amux
= CX231XX_AMUX_LINE_IN
,
93 [CX231XX_BOARD_CNXT_CARRAERA
] = {
94 .name
= "Conexant Hybrid TV - CARRAERA",
95 .tuner_type
= TUNER_XC5000
,
97 .tuner_gpio
= RDE250_XCV_TUNER
,
98 .tuner_sif_gpio
= 0x05,
99 .tuner_scl_gpio
= 0x1a,
100 .tuner_sda_gpio
= 0x1b,
101 .decoder
= CX231XX_AVDECODER
,
102 .demod_xfer_mode
= 0,
103 .ctl_pin_status_mask
= 0xFFFFFFC4,
104 .agc_analog_digital_select_gpio
= 0x0c,
105 .gpio_pin_status_mask
= 0x4001000,
106 .tuner_i2c_master
= 1,
107 .demod_i2c_master
= 2,
110 .norm
= V4L2_STD_PAL
,
113 .type
= CX231XX_VMUX_TELEVISION
,
114 .vmux
= CX231XX_VIN_3_1
,
115 .amux
= CX231XX_AMUX_VIDEO
,
118 .type
= CX231XX_VMUX_COMPOSITE1
,
119 .vmux
= CX231XX_VIN_2_1
,
120 .amux
= CX231XX_AMUX_LINE_IN
,
123 .type
= CX231XX_VMUX_SVIDEO
,
124 .vmux
= CX231XX_VIN_1_1
|
125 (CX231XX_VIN_1_2
<< 8) |
127 .amux
= CX231XX_AMUX_LINE_IN
,
132 [CX231XX_BOARD_CNXT_SHELBY
] = {
133 .name
= "Conexant Hybrid TV - SHELBY",
134 .tuner_type
= TUNER_XC5000
,
136 .tuner_gpio
= RDE250_XCV_TUNER
,
137 .tuner_sif_gpio
= 0x05,
138 .tuner_scl_gpio
= 0x1a,
139 .tuner_sda_gpio
= 0x1b,
140 .decoder
= CX231XX_AVDECODER
,
141 .demod_xfer_mode
= 0,
142 .ctl_pin_status_mask
= 0xFFFFFFC4,
143 .agc_analog_digital_select_gpio
= 0x0c,
144 .gpio_pin_status_mask
= 0x4001000,
145 .tuner_i2c_master
= 1,
146 .demod_i2c_master
= 2,
149 .norm
= V4L2_STD_NTSC
,
152 .type
= CX231XX_VMUX_TELEVISION
,
153 .vmux
= CX231XX_VIN_3_1
,
154 .amux
= CX231XX_AMUX_VIDEO
,
157 .type
= CX231XX_VMUX_COMPOSITE1
,
158 .vmux
= CX231XX_VIN_2_1
,
159 .amux
= CX231XX_AMUX_LINE_IN
,
162 .type
= CX231XX_VMUX_SVIDEO
,
163 .vmux
= CX231XX_VIN_1_1
|
164 (CX231XX_VIN_1_2
<< 8) |
166 .amux
= CX231XX_AMUX_LINE_IN
,
171 [CX231XX_BOARD_CNXT_RDE_253S
] = {
172 .name
= "Conexant Hybrid TV - RDE253S",
173 .tuner_type
= TUNER_NXP_TDA18271
,
175 .tuner_gpio
= RDE250_XCV_TUNER
,
176 .tuner_sif_gpio
= 0x05,
177 .tuner_scl_gpio
= 0x1a,
178 .tuner_sda_gpio
= 0x1b,
179 .decoder
= CX231XX_AVDECODER
,
180 .demod_xfer_mode
= 0,
181 .ctl_pin_status_mask
= 0xFFFFFFC4,
182 .agc_analog_digital_select_gpio
= 0x1c,
183 .gpio_pin_status_mask
= 0x4001000,
184 .tuner_i2c_master
= 1,
185 .demod_i2c_master
= 2,
188 .norm
= V4L2_STD_PAL
,
191 .type
= CX231XX_VMUX_TELEVISION
,
192 .vmux
= CX231XX_VIN_3_1
,
193 .amux
= CX231XX_AMUX_VIDEO
,
196 .type
= CX231XX_VMUX_COMPOSITE1
,
197 .vmux
= CX231XX_VIN_2_1
,
198 .amux
= CX231XX_AMUX_LINE_IN
,
201 .type
= CX231XX_VMUX_SVIDEO
,
202 .vmux
= CX231XX_VIN_1_1
|
203 (CX231XX_VIN_1_2
<< 8) |
205 .amux
= CX231XX_AMUX_LINE_IN
,
211 [CX231XX_BOARD_CNXT_RDU_253S
] = {
212 .name
= "Conexant Hybrid TV - RDU253S",
213 .tuner_type
= TUNER_NXP_TDA18271
,
215 .tuner_gpio
= RDE250_XCV_TUNER
,
216 .tuner_sif_gpio
= 0x05,
217 .tuner_scl_gpio
= 0x1a,
218 .tuner_sda_gpio
= 0x1b,
219 .decoder
= CX231XX_AVDECODER
,
220 .demod_xfer_mode
= 0,
221 .ctl_pin_status_mask
= 0xFFFFFFC4,
222 .agc_analog_digital_select_gpio
= 0x1c,
223 .gpio_pin_status_mask
= 0x4001000,
224 .tuner_i2c_master
= 1,
225 .demod_i2c_master
= 2,
228 .norm
= V4L2_STD_PAL
,
231 .type
= CX231XX_VMUX_TELEVISION
,
232 .vmux
= CX231XX_VIN_3_1
,
233 .amux
= CX231XX_AMUX_VIDEO
,
236 .type
= CX231XX_VMUX_COMPOSITE1
,
237 .vmux
= CX231XX_VIN_2_1
,
238 .amux
= CX231XX_AMUX_LINE_IN
,
241 .type
= CX231XX_VMUX_SVIDEO
,
242 .vmux
= CX231XX_VIN_1_1
|
243 (CX231XX_VIN_1_2
<< 8) |
245 .amux
= CX231XX_AMUX_LINE_IN
,
250 [CX231XX_BOARD_CNXT_VIDEO_GRABBER
] = {
251 .name
= "Conexant VIDEO GRABBER",
252 .tuner_type
= TUNER_NXP_TDA18271
,
254 .tuner_gpio
= RDE250_XCV_TUNER
,
255 .tuner_sif_gpio
= 0x05,
256 .tuner_scl_gpio
= 0x1a,
257 .tuner_sda_gpio
= 0x1b,
258 .decoder
= CX231XX_AVDECODER
,
259 .demod_xfer_mode
= 0,
260 .ctl_pin_status_mask
= 0xFFFFFFC4,
261 .agc_analog_digital_select_gpio
= 0x1c,
262 .gpio_pin_status_mask
= 0x4001000,
263 .tuner_i2c_master
= 1,
264 .demod_i2c_master
= 2,
267 .norm
= V4L2_STD_PAL
,
270 .type
= CX231XX_VMUX_COMPOSITE1
,
271 .vmux
= CX231XX_VIN_2_1
,
272 .amux
= CX231XX_AMUX_LINE_IN
,
275 .type
= CX231XX_VMUX_SVIDEO
,
276 .vmux
= CX231XX_VIN_1_1
|
277 (CX231XX_VIN_1_2
<< 8) |
279 .amux
= CX231XX_AMUX_LINE_IN
,
282 .type
= CX231XX_VMUX_TELEVISION
,
283 .vmux
= CX231XX_VIN_3_1
,
284 .amux
= CX231XX_AMUX_VIDEO
,
289 [CX231XX_BOARD_CNXT_RDE_250
] = {
290 .name
= "Conexant Hybrid TV - rde 250",
291 .tuner_type
= TUNER_XC5000
,
293 .tuner_gpio
= RDE250_XCV_TUNER
,
294 .tuner_sif_gpio
= 0x05,
295 .tuner_scl_gpio
= 0x1a,
296 .tuner_sda_gpio
= 0x1b,
297 .decoder
= CX231XX_AVDECODER
,
298 .demod_xfer_mode
= 0,
299 .ctl_pin_status_mask
= 0xFFFFFFC4,
300 .agc_analog_digital_select_gpio
= 0x0c,
301 .gpio_pin_status_mask
= 0x4001000,
302 .tuner_i2c_master
= 1,
303 .demod_i2c_master
= 2,
306 .norm
= V4L2_STD_PAL
,
309 .type
= CX231XX_VMUX_TELEVISION
,
310 .vmux
= CX231XX_VIN_2_1
,
311 .amux
= CX231XX_AMUX_VIDEO
,
316 [CX231XX_BOARD_CNXT_RDU_250
] = {
317 .name
= "Conexant Hybrid TV - RDU 250",
318 .tuner_type
= TUNER_XC5000
,
320 .tuner_gpio
= RDE250_XCV_TUNER
,
321 .tuner_sif_gpio
= 0x05,
322 .tuner_scl_gpio
= 0x1a,
323 .tuner_sda_gpio
= 0x1b,
324 .decoder
= CX231XX_AVDECODER
,
325 .demod_xfer_mode
= 0,
326 .ctl_pin_status_mask
= 0xFFFFFFC4,
327 .agc_analog_digital_select_gpio
= 0x0c,
328 .gpio_pin_status_mask
= 0x4001000,
329 .tuner_i2c_master
= 1,
330 .demod_i2c_master
= 2,
333 .norm
= V4L2_STD_NTSC
,
336 .type
= CX231XX_VMUX_TELEVISION
,
337 .vmux
= CX231XX_VIN_2_1
,
338 .amux
= CX231XX_AMUX_VIDEO
,
343 [CX231XX_BOARD_HAUPPAUGE_EXETER
] = {
344 .name
= "Hauppauge EXETER",
345 .tuner_type
= TUNER_NXP_TDA18271
,
347 .tuner_gpio
= RDE250_XCV_TUNER
,
348 .tuner_sif_gpio
= 0x05,
349 .tuner_scl_gpio
= 0x1a,
350 .tuner_sda_gpio
= 0x1b,
351 .decoder
= CX231XX_AVDECODER
,
352 .demod_xfer_mode
= 0,
353 .ctl_pin_status_mask
= 0xFFFFFFC4,
354 .agc_analog_digital_select_gpio
= 0x0c,
355 .gpio_pin_status_mask
= 0x4001000,
356 .tuner_i2c_master
= 1,
357 .demod_i2c_master
= 2,
360 .norm
= V4L2_STD_NTSC
,
363 .type
= CX231XX_VMUX_TELEVISION
,
364 .vmux
= CX231XX_VIN_3_1
,
365 .amux
= CX231XX_AMUX_VIDEO
,
368 .type
= CX231XX_VMUX_COMPOSITE1
,
369 .vmux
= CX231XX_VIN_2_1
,
370 .amux
= CX231XX_AMUX_LINE_IN
,
373 .type
= CX231XX_VMUX_SVIDEO
,
374 .vmux
= CX231XX_VIN_1_1
|
375 (CX231XX_VIN_1_2
<< 8) |
377 .amux
= CX231XX_AMUX_LINE_IN
,
387 const unsigned int cx231xx_bcount
= ARRAY_SIZE(cx231xx_boards
);
389 /* table of devices that work with this driver */
390 struct usb_device_id cx231xx_id_table
[] = {
391 {USB_DEVICE(0x0572, 0x5A3C),
392 .driver_info
= CX231XX_BOARD_UNKNOWN
},
393 {USB_DEVICE_VER(USB_VID_PIXELVIEW
, USB_PID_PIXELVIEW_SBTVD
, 0x4000,0x4fff),
394 .driver_info
= CX231XX_BOARD_UNKNOWN
},
395 {USB_DEVICE(0x0572, 0x58A2),
396 .driver_info
= CX231XX_BOARD_CNXT_CARRAERA
},
397 {USB_DEVICE(0x0572, 0x58A1),
398 .driver_info
= CX231XX_BOARD_CNXT_SHELBY
},
399 {USB_DEVICE(0x0572, 0x58A4),
400 .driver_info
= CX231XX_BOARD_CNXT_RDE_253S
},
401 {USB_DEVICE(0x0572, 0x58A5),
402 .driver_info
= CX231XX_BOARD_CNXT_RDU_253S
},
403 {USB_DEVICE(0x0572, 0x58A6),
404 .driver_info
= CX231XX_BOARD_CNXT_VIDEO_GRABBER
},
405 {USB_DEVICE(0x0572, 0x589E),
406 .driver_info
= CX231XX_BOARD_CNXT_RDE_250
},
407 {USB_DEVICE(0x0572, 0x58A0),
408 .driver_info
= CX231XX_BOARD_CNXT_RDU_250
},
409 {USB_DEVICE(0x2040, 0xb120),
410 .driver_info
= CX231XX_BOARD_HAUPPAUGE_EXETER
},
411 {USB_DEVICE(0x2040, 0xb140),
412 .driver_info
= CX231XX_BOARD_HAUPPAUGE_EXETER
},
416 MODULE_DEVICE_TABLE(usb
, cx231xx_id_table
);
418 /* cx231xx_tuner_callback
419 * will be used to reset XC5000 tuner using GPIO pin
422 int cx231xx_tuner_callback(void *ptr
, int component
, int command
, int arg
)
425 struct cx231xx
*dev
= ptr
;
427 if (dev
->tuner_type
== TUNER_XC5000
) {
428 if (command
== XC5000_TUNER_RESET
) {
430 ("Tuner CB: RESET: cmd %d : tuner type %d \n",
431 command
, dev
->tuner_type
);
432 cx231xx_set_gpio_value(dev
, dev
->board
.tuner_gpio
->bit
,
435 cx231xx_set_gpio_value(dev
, dev
->board
.tuner_gpio
->bit
,
438 cx231xx_set_gpio_value(dev
, dev
->board
.tuner_gpio
->bit
,
445 EXPORT_SYMBOL_GPL(cx231xx_tuner_callback
);
447 void cx231xx_reset_out(struct cx231xx
*dev
)
449 cx231xx_set_gpio_value(dev
, CX23417_RESET
, 1);
451 cx231xx_set_gpio_value(dev
, CX23417_RESET
, 0);
453 cx231xx_set_gpio_value(dev
, CX23417_RESET
, 1);
455 void cx231xx_enable_OSC(struct cx231xx
*dev
)
457 cx231xx_set_gpio_value(dev
, CX23417_OSC_EN
, 1);
459 void cx231xx_sleep_s5h1432(struct cx231xx
*dev
)
461 cx231xx_set_gpio_value(dev
, SLEEP_S5H1432
, 0);
464 static inline void cx231xx_set_model(struct cx231xx
*dev
)
466 memcpy(&dev
->board
, &cx231xx_boards
[dev
->model
], sizeof(dev
->board
));
469 /* Since cx231xx_pre_card_setup() requires a proper dev->model,
470 * this won't work for boards with generic PCI IDs
472 void cx231xx_pre_card_setup(struct cx231xx
*dev
)
475 cx231xx_set_model(dev
);
477 cx231xx_info("Identified as %s (card=%d)\n",
478 dev
->board
.name
, dev
->model
);
480 /* set the direction for GPIO pins */
481 if (dev
->board
.tuner_gpio
) {
482 cx231xx_set_gpio_direction(dev
, dev
->board
.tuner_gpio
->bit
, 1);
483 cx231xx_set_gpio_value(dev
, dev
->board
.tuner_gpio
->bit
, 1);
484 cx231xx_set_gpio_direction(dev
, dev
->board
.tuner_sif_gpio
, 1);
486 /* request some modules if any required */
489 /* set the mode to Analog mode initially */
490 cx231xx_set_mode(dev
, CX231XX_ANALOG_MODE
);
493 /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */
497 static void cx231xx_config_tuner(struct cx231xx
*dev
)
499 struct tuner_setup tun_setup
;
500 struct v4l2_frequency f
;
502 if (dev
->tuner_type
== TUNER_ABSENT
)
505 tun_setup
.mode_mask
= T_ANALOG_TV
| T_RADIO
;
506 tun_setup
.type
= dev
->tuner_type
;
507 tun_setup
.addr
= dev
->tuner_addr
;
508 tun_setup
.tuner_callback
= cx231xx_tuner_callback
;
510 tuner_call(dev
, tuner
, s_type_addr
, &tun_setup
);
513 if (tun_setup
.type
== TUNER_XC5000
) {
514 static struct xc2028_ctrl ctrl
= {
515 .fname
= XC5000_DEFAULT_FIRMWARE
,
519 struct v4l2_priv_tun_config cfg
= {
520 .tuner
= dev
->tuner_type
,
523 tuner_call(dev
, tuner
, s_config
, &cfg
);
526 /* configure tuner */
528 f
.type
= V4L2_TUNER_ANALOG_TV
;
529 f
.frequency
= 9076; /* just a magic number */
530 dev
->ctl_freq
= f
.frequency
;
531 call_all(dev
, tuner
, s_frequency
, &f
);
535 /* ----------------------------------------------------------------------- */
536 void cx231xx_register_i2c_ir(struct cx231xx
*dev
)
541 /* REVISIT: instantiate IR device */
543 /* detect & configure */
544 switch (dev
->model
) {
546 case CX231XX_BOARD_CNXT_CARRAERA
:
548 case CX231XX_BOARD_CNXT_RDE_250
:
550 case CX231XX_BOARD_CNXT_SHELBY
:
552 case CX231XX_BOARD_CNXT_RDU_250
:
554 case CX231XX_BOARD_CNXT_RDE_253S
:
556 case CX231XX_BOARD_CNXT_RDU_253S
:
558 case CX231XX_BOARD_CNXT_VIDEO_GRABBER
:
560 case CX231XX_BOARD_HAUPPAUGE_EXETER
:
567 void cx231xx_card_setup(struct cx231xx
*dev
)
570 cx231xx_set_model(dev
);
572 dev
->tuner_type
= cx231xx_boards
[dev
->model
].tuner_type
;
573 if (cx231xx_boards
[dev
->model
].tuner_addr
)
574 dev
->tuner_addr
= cx231xx_boards
[dev
->model
].tuner_addr
;
576 /* request some modules */
577 if (dev
->board
.decoder
== CX231XX_AVDECODER
) {
578 dev
->sd_cx25840
= v4l2_i2c_new_subdev(&dev
->v4l2_dev
,
579 &dev
->i2c_bus
[0].i2c_adap
,
580 "cx25840", "cx25840", 0x88 >> 1, NULL
);
581 if (dev
->sd_cx25840
== NULL
)
582 cx231xx_info("cx25840 subdev registration failure\n");
583 cx25840_call(dev
, core
, load_fw
);
587 /* Initialize the tuner */
588 if (dev
->board
.tuner_type
!= TUNER_ABSENT
) {
589 dev
->sd_tuner
= v4l2_i2c_new_subdev(&dev
->v4l2_dev
,
590 &dev
->i2c_bus
[1].i2c_adap
,
592 dev
->tuner_addr
, NULL
);
593 if (dev
->sd_tuner
== NULL
)
594 cx231xx_info("tuner subdev registration failure\n");
596 cx231xx_config_tuner(dev
);
600 /* TBD IR will be added later */
601 cx231xx_ir_init(dev
);
607 * inits registers with sane defaults
609 int cx231xx_config(struct cx231xx
*dev
)
611 /* TBD need to add cx231xx specific code */
612 dev
->mute
= 1; /* maybe not the right place... */
619 * cx231xx_config_i2c()
620 * configure i2c attached devices
622 void cx231xx_config_i2c(struct cx231xx
*dev
)
624 /* u32 input = INPUT(dev->video_input)->vmux; */
626 call_all(dev
, video
, s_stream
, 1);
630 * cx231xx_realease_resources()
631 * unregisters the v4l2,i2c and usb devices
632 * called when the device gets disconected or at module unload
634 void cx231xx_release_resources(struct cx231xx
*dev
)
637 #if 0 /* TBD IR related */
639 cx231xx_ir_fini(dev
);
642 cx231xx_release_analog_resources(dev
);
644 cx231xx_remove_from_devlist(dev
);
646 cx231xx_dev_uninit(dev
);
648 usb_put_dev(dev
->udev
);
650 /* Mark device as unused */
651 cx231xx_devused
&= ~(1 << dev
->devno
);
656 * allocates and inits the device structs, registers i2c bus and v4l device
658 static int cx231xx_init_dev(struct cx231xx
**devhandle
, struct usb_device
*udev
,
661 struct cx231xx
*dev
= *devhandle
;
662 int retval
= -ENOMEM
;
664 unsigned int maxh
, maxw
;
667 mutex_init(&dev
->lock
);
668 mutex_init(&dev
->ctrl_urb_lock
);
669 mutex_init(&dev
->gpio_i2c_lock
);
670 mutex_init(&dev
->i2c_lock
);
672 spin_lock_init(&dev
->video_mode
.slock
);
673 spin_lock_init(&dev
->vbi_mode
.slock
);
674 spin_lock_init(&dev
->sliced_cc_mode
.slock
);
676 init_waitqueue_head(&dev
->open
);
677 init_waitqueue_head(&dev
->wait_frame
);
678 init_waitqueue_head(&dev
->wait_stream
);
680 dev
->cx231xx_read_ctrl_reg
= cx231xx_read_ctrl_reg
;
681 dev
->cx231xx_write_ctrl_reg
= cx231xx_write_ctrl_reg
;
682 dev
->cx231xx_send_usb_command
= cx231xx_send_usb_command
;
683 dev
->cx231xx_gpio_i2c_read
= cx231xx_gpio_i2c_read
;
684 dev
->cx231xx_gpio_i2c_write
= cx231xx_gpio_i2c_write
;
686 /* Query cx231xx to find what pcb config it is related to */
687 initialize_cx231xx(dev
);
689 /*To workaround error number=-71 on EP0 for VideoGrabber,
691 if (dev
->model
== CX231XX_BOARD_CNXT_VIDEO_GRABBER
) {
692 cx231xx_set_alt_setting(dev
, INDEX_VIDEO
, 3);
693 cx231xx_set_alt_setting(dev
, INDEX_VANC
, 1);
695 /* Cx231xx pre card setup */
696 cx231xx_pre_card_setup(dev
);
698 errCode
= cx231xx_config(dev
);
700 cx231xx_errdev("error configuring device\n");
704 /* set default norm */
705 dev
->norm
= dev
->board
.norm
;
707 /* register i2c bus */
708 errCode
= cx231xx_dev_init(dev
);
710 cx231xx_dev_uninit(dev
);
711 cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
716 /* Do board specific init */
717 cx231xx_card_setup(dev
);
719 /* configure the device */
720 cx231xx_config_i2c(dev
);
722 maxw
= norm_maxw(dev
);
723 maxh
= norm_maxh(dev
);
725 /* set default image size */
731 dev
->video_input
= 0;
733 errCode
= cx231xx_config(dev
);
735 cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
740 /* init video dma queues */
741 INIT_LIST_HEAD(&dev
->video_mode
.vidq
.active
);
742 INIT_LIST_HEAD(&dev
->video_mode
.vidq
.queued
);
744 /* init vbi dma queues */
745 INIT_LIST_HEAD(&dev
->vbi_mode
.vidq
.active
);
746 INIT_LIST_HEAD(&dev
->vbi_mode
.vidq
.queued
);
748 /* Reset other chips required if they are tied up with GPIO pins */
749 cx231xx_add_into_devlist(dev
);
751 printk(KERN_INFO
"attach 417 %d\n", dev
->model
);
752 if (dev
->model
== CX231XX_BOARD_CNXT_VIDEO_GRABBER
) {
753 if (cx231xx_417_register(dev
) < 0) {
755 "%s() Failed to register 417 on VID_B\n",
760 retval
= cx231xx_register_analog_devices(dev
);
762 cx231xx_release_resources(dev
);
763 goto fail_reg_devices
;
766 cx231xx_init_extension(dev
);
771 mutex_unlock(&dev
->lock
);
775 #if defined(CONFIG_MODULES) && defined(MODULE)
776 static void request_module_async(struct work_struct
*work
)
778 struct cx231xx
*dev
= container_of(work
,
779 struct cx231xx
, request_module_wk
);
781 if (dev
->has_alsa_audio
)
782 request_module("cx231xx-alsa");
784 if (dev
->board
.has_dvb
)
785 request_module("cx231xx-dvb");
789 static void request_modules(struct cx231xx
*dev
)
791 INIT_WORK(&dev
->request_module_wk
, request_module_async
);
792 schedule_work(&dev
->request_module_wk
);
795 #define request_modules(dev)
796 #endif /* CONFIG_MODULES */
799 * cx231xx_usb_probe()
800 * checks for supported devices
802 static int cx231xx_usb_probe(struct usb_interface
*interface
,
803 const struct usb_device_id
*id
)
805 struct usb_device
*udev
;
806 struct usb_interface
*uif
;
807 struct cx231xx
*dev
= NULL
;
808 int retval
= -ENODEV
;
810 int i
, isoc_pipe
= 0;
812 char descr
[255] = "";
813 struct usb_interface
*lif
= NULL
;
814 int skip_interface
= 0;
815 struct usb_interface_assoc_descriptor
*assoc_desc
;
817 udev
= usb_get_dev(interface_to_usbdev(interface
));
818 ifnum
= interface
->altsetting
[0].desc
.bInterfaceNumber
;
822 * Interface number 0 - IR interface
824 /* Check to see next free device and mark as used */
825 nr
= find_first_zero_bit(&cx231xx_devused
, CX231XX_MAXBOARDS
);
826 cx231xx_devused
|= 1 << nr
;
828 if (nr
>= CX231XX_MAXBOARDS
) {
829 cx231xx_err(DRIVER_NAME
830 ": Supports only %i cx231xx boards.\n", CX231XX_MAXBOARDS
);
831 cx231xx_devused
&= ~(1 << nr
);
835 /* allocate memory for our device state and initialize it */
836 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
838 cx231xx_err(DRIVER_NAME
": out of memory!\n");
839 cx231xx_devused
&= ~(1 << nr
);
843 snprintf(dev
->name
, 29, "cx231xx #%d", nr
);
845 dev
->model
= id
->driver_info
;
846 dev
->video_mode
.alt
= -1;
847 dev
->interface_count
++;
849 /* reset gpio dir and value */
852 dev
->xc_fw_load_done
= 0;
853 dev
->has_alsa_audio
= 1;
854 dev
->power_mode
= -1;
855 atomic_set(&dev
->devlist_count
, 0);
857 /* 0 - vbi ; 1 -sliced cc mode */
858 dev
->vbi_or_sliced_cc_mode
= 0;
860 /* get maximum no.of IAD interfaces */
861 assoc_desc
= udev
->actconfig
->intf_assoc
[0];
862 dev
->max_iad_interface_count
= assoc_desc
->bInterfaceCount
;
864 /* init CIR module TBD */
866 /* store the current interface */
869 /*mode_tv: digital=1 or analog=0*/
872 dev
->USE_ISO
= transfer_mode
;
874 switch (udev
->speed
) {
878 case USB_SPEED_UNKNOWN
:
889 if (udev
->manufacturer
)
890 strlcpy(descr
, udev
->manufacturer
, sizeof(descr
));
894 strlcat(descr
, " ", sizeof(descr
));
895 strlcat(descr
, udev
->product
, sizeof(descr
));
898 strlcat(descr
, " ", sizeof(descr
));
900 cx231xx_info("New device %s@ %s Mbps "
901 "(%04x:%04x) with %d interfaces\n",
904 le16_to_cpu(udev
->descriptor
.idVendor
),
905 le16_to_cpu(udev
->descriptor
.idProduct
),
906 dev
->max_iad_interface_count
);
908 /* Get dev structure first */
909 dev
= usb_get_intfdata(udev
->actconfig
->interface
[0]);
911 cx231xx_err(DRIVER_NAME
": out of first interface!\n");
915 /* store the interface 0 back */
916 lif
= udev
->actconfig
->interface
[0];
918 /* increment interface count */
919 dev
->interface_count
++;
921 /* get device number */
925 * set skip interface, for all interfaces but
926 * interface 1 and the last one
928 if ((ifnum
!= 1) && ((ifnum
)
929 != dev
->max_iad_interface_count
))
933 assoc_desc
= udev
->actconfig
->intf_assoc
[0];
934 if (assoc_desc
->bFirstInterface
!= ifnum
) {
935 cx231xx_err(DRIVER_NAME
": Not found "
936 "matching IAD interface\n");
945 cx231xx_info("registering interface %d\n", ifnum
);
947 /* save our data pointer in this interface device */
948 usb_set_intfdata(lif
, dev
);
950 if ((ifnum
) != dev
->max_iad_interface_count
)
954 * AV device initialization - only done at the last interface
957 /* Create v4l2 device */
958 retval
= v4l2_device_register(&interface
->dev
, &dev
->v4l2_dev
);
960 cx231xx_errdev("v4l2_device_register failed\n");
961 cx231xx_devused
&= ~(1 << nr
);
966 /* allocate device struct */
967 retval
= cx231xx_init_dev(&dev
, udev
, nr
);
969 cx231xx_devused
&= ~(1 << dev
->devno
);
970 v4l2_device_unregister(&dev
->v4l2_dev
);
973 usb_set_intfdata(lif
, NULL
);
978 /* compute alternate max packet sizes for video */
979 uif
= udev
->actconfig
->interface
[dev
->current_pcb_config
.
980 hs_config_info
[0].interface_info
.video_index
+ 1];
982 dev
->video_mode
.end_point_addr
= le16_to_cpu(uif
->altsetting
[0].
983 endpoint
[isoc_pipe
].desc
.bEndpointAddress
);
985 dev
->video_mode
.num_alt
= uif
->num_altsetting
;
986 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
987 dev
->video_mode
.end_point_addr
,
988 dev
->video_mode
.num_alt
);
989 dev
->video_mode
.alt_max_pkt_size
=
990 kmalloc(32 * dev
->video_mode
.num_alt
, GFP_KERNEL
);
992 if (dev
->video_mode
.alt_max_pkt_size
== NULL
) {
993 cx231xx_errdev("out of memory!\n");
994 cx231xx_devused
&= ~(1 << nr
);
995 v4l2_device_unregister(&dev
->v4l2_dev
);
1001 for (i
= 0; i
< dev
->video_mode
.num_alt
; i
++) {
1002 u16 tmp
= le16_to_cpu(uif
->altsetting
[i
].endpoint
[isoc_pipe
].
1003 desc
.wMaxPacketSize
);
1004 dev
->video_mode
.alt_max_pkt_size
[i
] =
1005 (tmp
& 0x07ff) * (((tmp
& 0x1800) >> 11) + 1);
1006 cx231xx_info("Alternate setting %i, max size= %i\n", i
,
1007 dev
->video_mode
.alt_max_pkt_size
[i
]);
1010 /* compute alternate max packet sizes for vbi */
1011 uif
= udev
->actconfig
->interface
[dev
->current_pcb_config
.
1012 hs_config_info
[0].interface_info
.
1015 dev
->vbi_mode
.end_point_addr
=
1016 le16_to_cpu(uif
->altsetting
[0].endpoint
[isoc_pipe
].desc
.
1019 dev
->vbi_mode
.num_alt
= uif
->num_altsetting
;
1020 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1021 dev
->vbi_mode
.end_point_addr
,
1022 dev
->vbi_mode
.num_alt
);
1023 dev
->vbi_mode
.alt_max_pkt_size
=
1024 kmalloc(32 * dev
->vbi_mode
.num_alt
, GFP_KERNEL
);
1026 if (dev
->vbi_mode
.alt_max_pkt_size
== NULL
) {
1027 cx231xx_errdev("out of memory!\n");
1028 cx231xx_devused
&= ~(1 << nr
);
1029 v4l2_device_unregister(&dev
->v4l2_dev
);
1035 for (i
= 0; i
< dev
->vbi_mode
.num_alt
; i
++) {
1037 le16_to_cpu(uif
->altsetting
[i
].endpoint
[isoc_pipe
].
1038 desc
.wMaxPacketSize
);
1039 dev
->vbi_mode
.alt_max_pkt_size
[i
] =
1040 (tmp
& 0x07ff) * (((tmp
& 0x1800) >> 11) + 1);
1041 cx231xx_info("Alternate setting %i, max size= %i\n", i
,
1042 dev
->vbi_mode
.alt_max_pkt_size
[i
]);
1045 /* compute alternate max packet sizes for sliced CC */
1046 uif
= udev
->actconfig
->interface
[dev
->current_pcb_config
.
1047 hs_config_info
[0].interface_info
.
1050 dev
->sliced_cc_mode
.end_point_addr
=
1051 le16_to_cpu(uif
->altsetting
[0].endpoint
[isoc_pipe
].desc
.
1054 dev
->sliced_cc_mode
.num_alt
= uif
->num_altsetting
;
1055 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1056 dev
->sliced_cc_mode
.end_point_addr
,
1057 dev
->sliced_cc_mode
.num_alt
);
1058 dev
->sliced_cc_mode
.alt_max_pkt_size
=
1059 kmalloc(32 * dev
->sliced_cc_mode
.num_alt
, GFP_KERNEL
);
1061 if (dev
->sliced_cc_mode
.alt_max_pkt_size
== NULL
) {
1062 cx231xx_errdev("out of memory!\n");
1063 cx231xx_devused
&= ~(1 << nr
);
1064 v4l2_device_unregister(&dev
->v4l2_dev
);
1070 for (i
= 0; i
< dev
->sliced_cc_mode
.num_alt
; i
++) {
1071 u16 tmp
= le16_to_cpu(uif
->altsetting
[i
].endpoint
[isoc_pipe
].
1072 desc
.wMaxPacketSize
);
1073 dev
->sliced_cc_mode
.alt_max_pkt_size
[i
] =
1074 (tmp
& 0x07ff) * (((tmp
& 0x1800) >> 11) + 1);
1075 cx231xx_info("Alternate setting %i, max size= %i\n", i
,
1076 dev
->sliced_cc_mode
.alt_max_pkt_size
[i
]);
1079 if (dev
->current_pcb_config
.ts1_source
!= 0xff) {
1080 /* compute alternate max packet sizes for TS1 */
1081 uif
= udev
->actconfig
->interface
[dev
->current_pcb_config
.
1086 dev
->ts1_mode
.end_point_addr
=
1087 le16_to_cpu(uif
->altsetting
[0].endpoint
[isoc_pipe
].
1088 desc
.bEndpointAddress
);
1090 dev
->ts1_mode
.num_alt
= uif
->num_altsetting
;
1091 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1092 dev
->ts1_mode
.end_point_addr
,
1093 dev
->ts1_mode
.num_alt
);
1094 dev
->ts1_mode
.alt_max_pkt_size
=
1095 kmalloc(32 * dev
->ts1_mode
.num_alt
, GFP_KERNEL
);
1097 if (dev
->ts1_mode
.alt_max_pkt_size
== NULL
) {
1098 cx231xx_errdev("out of memory!\n");
1099 cx231xx_devused
&= ~(1 << nr
);
1100 v4l2_device_unregister(&dev
->v4l2_dev
);
1106 for (i
= 0; i
< dev
->ts1_mode
.num_alt
; i
++) {
1107 u16 tmp
= le16_to_cpu(uif
->altsetting
[i
].
1108 endpoint
[isoc_pipe
].desc
.
1110 dev
->ts1_mode
.alt_max_pkt_size
[i
] =
1111 (tmp
& 0x07ff) * (((tmp
& 0x1800) >> 11) + 1);
1112 cx231xx_info("Alternate setting %i, max size= %i\n", i
,
1113 dev
->ts1_mode
.alt_max_pkt_size
[i
]);
1117 if (dev
->model
== CX231XX_BOARD_CNXT_VIDEO_GRABBER
) {
1118 cx231xx_enable_OSC(dev
);
1119 cx231xx_reset_out(dev
);
1120 cx231xx_set_alt_setting(dev
, INDEX_VIDEO
, 3);
1123 if (dev
->model
== CX231XX_BOARD_CNXT_RDE_253S
)
1124 cx231xx_sleep_s5h1432(dev
);
1126 /* load other modules required */
1127 request_modules(dev
);
1133 * cx231xx_usb_disconnect()
1134 * called when the device gets diconencted
1135 * video device will be unregistered on v4l2_close in case it is still open
1137 static void cx231xx_usb_disconnect(struct usb_interface
*interface
)
1139 struct cx231xx
*dev
;
1141 dev
= usb_get_intfdata(interface
);
1142 usb_set_intfdata(interface
, NULL
);
1150 /* delete v4l2 device */
1151 v4l2_device_unregister(&dev
->v4l2_dev
);
1153 /* wait until all current v4l2 io is finished then deallocate
1155 mutex_lock(&dev
->lock
);
1157 wake_up_interruptible_all(&dev
->open
);
1161 ("device %s is open! Deregistration and memory "
1162 "deallocation are deferred on close.\n",
1163 video_device_node_name(dev
->vdev
));
1165 dev
->state
|= DEV_MISCONFIGURED
;
1167 cx231xx_uninit_isoc(dev
);
1169 cx231xx_uninit_bulk(dev
);
1170 dev
->state
|= DEV_DISCONNECTED
;
1171 wake_up_interruptible(&dev
->wait_frame
);
1172 wake_up_interruptible(&dev
->wait_stream
);
1174 dev
->state
|= DEV_DISCONNECTED
;
1175 cx231xx_release_resources(dev
);
1178 cx231xx_close_extension(dev
);
1180 mutex_unlock(&dev
->lock
);
1183 kfree(dev
->video_mode
.alt_max_pkt_size
);
1184 kfree(dev
->vbi_mode
.alt_max_pkt_size
);
1185 kfree(dev
->sliced_cc_mode
.alt_max_pkt_size
);
1186 kfree(dev
->ts1_mode
.alt_max_pkt_size
);
1192 static struct usb_driver cx231xx_usb_driver
= {
1194 .probe
= cx231xx_usb_probe
,
1195 .disconnect
= cx231xx_usb_disconnect
,
1196 .id_table
= cx231xx_id_table
,
1199 static int __init
cx231xx_module_init(void)
1203 printk(KERN_INFO DRIVER_NAME
" v4l2 driver loaded.\n");
1205 /* register this driver with the USB subsystem */
1206 result
= usb_register(&cx231xx_usb_driver
);
1208 cx231xx_err(DRIVER_NAME
1209 " usb_register failed. Error number %d.\n", result
);
1214 static void __exit
cx231xx_module_exit(void)
1216 /* deregister this driver with the USB subsystem */
1217 usb_deregister(&cx231xx_usb_driver
);
1220 module_init(cx231xx_module_init
);
1221 module_exit(cx231xx_module_exit
);