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"
41 static int tuner
= -1;
42 module_param(tuner
, int, 0444);
43 MODULE_PARM_DESC(tuner
, "tuner type");
45 static int transfer_mode
= 1;
46 module_param(transfer_mode
, int, 0444);
47 MODULE_PARM_DESC(transfer_mode
, "transfer mode (1-ISO or 0-BULK)");
49 static unsigned int disable_ir
;
50 module_param(disable_ir
, int, 0444);
51 MODULE_PARM_DESC(disable_ir
, "disable infrared remote support");
53 /* Bitmask marking allocated devices from 0 to CX231XX_MAXBOARDS */
54 static unsigned long cx231xx_devused
;
57 * Reset sequences for analog/digital modes
60 static struct cx231xx_reg_seq RDE250_XCV_TUNER
[] = {
70 struct cx231xx_board cx231xx_boards
[] = {
71 [CX231XX_BOARD_UNKNOWN
] = {
72 .name
= "Unknown CX231xx video grabber",
73 .tuner_type
= TUNER_ABSENT
,
75 .type
= CX231XX_VMUX_TELEVISION
,
76 .vmux
= CX231XX_VIN_3_1
,
77 .amux
= CX231XX_AMUX_VIDEO
,
80 .type
= CX231XX_VMUX_COMPOSITE1
,
81 .vmux
= CX231XX_VIN_2_1
,
82 .amux
= CX231XX_AMUX_LINE_IN
,
85 .type
= CX231XX_VMUX_SVIDEO
,
86 .vmux
= CX231XX_VIN_1_1
|
87 (CX231XX_VIN_1_2
<< 8) |
89 .amux
= CX231XX_AMUX_LINE_IN
,
94 [CX231XX_BOARD_CNXT_CARRAERA
] = {
95 .name
= "Conexant Hybrid TV - CARRAERA",
96 .tuner_type
= TUNER_XC5000
,
98 .tuner_gpio
= RDE250_XCV_TUNER
,
99 .tuner_sif_gpio
= 0x05,
100 .tuner_scl_gpio
= 0x1a,
101 .tuner_sda_gpio
= 0x1b,
102 .decoder
= CX231XX_AVDECODER
,
103 .output_mode
= OUT_MODE_VIP11
,
104 .demod_xfer_mode
= 0,
105 .ctl_pin_status_mask
= 0xFFFFFFC4,
106 .agc_analog_digital_select_gpio
= 0x0c,
107 .gpio_pin_status_mask
= 0x4001000,
108 .tuner_i2c_master
= 1,
109 .demod_i2c_master
= 2,
112 .norm
= V4L2_STD_PAL
,
115 .type
= CX231XX_VMUX_TELEVISION
,
116 .vmux
= CX231XX_VIN_3_1
,
117 .amux
= CX231XX_AMUX_VIDEO
,
120 .type
= CX231XX_VMUX_COMPOSITE1
,
121 .vmux
= CX231XX_VIN_2_1
,
122 .amux
= CX231XX_AMUX_LINE_IN
,
125 .type
= CX231XX_VMUX_SVIDEO
,
126 .vmux
= CX231XX_VIN_1_1
|
127 (CX231XX_VIN_1_2
<< 8) |
129 .amux
= CX231XX_AMUX_LINE_IN
,
134 [CX231XX_BOARD_CNXT_SHELBY
] = {
135 .name
= "Conexant Hybrid TV - SHELBY",
136 .tuner_type
= TUNER_XC5000
,
138 .tuner_gpio
= RDE250_XCV_TUNER
,
139 .tuner_sif_gpio
= 0x05,
140 .tuner_scl_gpio
= 0x1a,
141 .tuner_sda_gpio
= 0x1b,
142 .decoder
= CX231XX_AVDECODER
,
143 .output_mode
= OUT_MODE_VIP11
,
144 .demod_xfer_mode
= 0,
145 .ctl_pin_status_mask
= 0xFFFFFFC4,
146 .agc_analog_digital_select_gpio
= 0x0c,
147 .gpio_pin_status_mask
= 0x4001000,
148 .tuner_i2c_master
= 1,
149 .demod_i2c_master
= 2,
152 .norm
= V4L2_STD_NTSC
,
155 .type
= CX231XX_VMUX_TELEVISION
,
156 .vmux
= CX231XX_VIN_3_1
,
157 .amux
= CX231XX_AMUX_VIDEO
,
160 .type
= CX231XX_VMUX_COMPOSITE1
,
161 .vmux
= CX231XX_VIN_2_1
,
162 .amux
= CX231XX_AMUX_LINE_IN
,
165 .type
= CX231XX_VMUX_SVIDEO
,
166 .vmux
= CX231XX_VIN_1_1
|
167 (CX231XX_VIN_1_2
<< 8) |
169 .amux
= CX231XX_AMUX_LINE_IN
,
174 [CX231XX_BOARD_CNXT_RDE_253S
] = {
175 .name
= "Conexant Hybrid TV - RDE253S",
176 .tuner_type
= TUNER_NXP_TDA18271
,
178 .tuner_gpio
= RDE250_XCV_TUNER
,
179 .tuner_sif_gpio
= 0x05,
180 .tuner_scl_gpio
= 0x1a,
181 .tuner_sda_gpio
= 0x1b,
182 .decoder
= CX231XX_AVDECODER
,
183 .output_mode
= OUT_MODE_VIP11
,
184 .demod_xfer_mode
= 0,
185 .ctl_pin_status_mask
= 0xFFFFFFC4,
186 .agc_analog_digital_select_gpio
= 0x1c,
187 .gpio_pin_status_mask
= 0x4001000,
188 .tuner_i2c_master
= 1,
189 .demod_i2c_master
= 2,
192 .norm
= V4L2_STD_PAL
,
195 .type
= CX231XX_VMUX_TELEVISION
,
196 .vmux
= CX231XX_VIN_3_1
,
197 .amux
= CX231XX_AMUX_VIDEO
,
200 .type
= CX231XX_VMUX_COMPOSITE1
,
201 .vmux
= CX231XX_VIN_2_1
,
202 .amux
= CX231XX_AMUX_LINE_IN
,
205 .type
= CX231XX_VMUX_SVIDEO
,
206 .vmux
= CX231XX_VIN_1_1
|
207 (CX231XX_VIN_1_2
<< 8) |
209 .amux
= CX231XX_AMUX_LINE_IN
,
215 [CX231XX_BOARD_CNXT_RDU_253S
] = {
216 .name
= "Conexant Hybrid TV - RDU253S",
217 .tuner_type
= TUNER_NXP_TDA18271
,
219 .tuner_gpio
= RDE250_XCV_TUNER
,
220 .tuner_sif_gpio
= 0x05,
221 .tuner_scl_gpio
= 0x1a,
222 .tuner_sda_gpio
= 0x1b,
223 .decoder
= CX231XX_AVDECODER
,
224 .output_mode
= OUT_MODE_VIP11
,
225 .demod_xfer_mode
= 0,
226 .ctl_pin_status_mask
= 0xFFFFFFC4,
227 .agc_analog_digital_select_gpio
= 0x1c,
228 .gpio_pin_status_mask
= 0x4001000,
229 .tuner_i2c_master
= 1,
230 .demod_i2c_master
= 2,
233 .norm
= V4L2_STD_PAL
,
236 .type
= CX231XX_VMUX_TELEVISION
,
237 .vmux
= CX231XX_VIN_3_1
,
238 .amux
= CX231XX_AMUX_VIDEO
,
241 .type
= CX231XX_VMUX_COMPOSITE1
,
242 .vmux
= CX231XX_VIN_2_1
,
243 .amux
= CX231XX_AMUX_LINE_IN
,
246 .type
= CX231XX_VMUX_SVIDEO
,
247 .vmux
= CX231XX_VIN_1_1
|
248 (CX231XX_VIN_1_2
<< 8) |
250 .amux
= CX231XX_AMUX_LINE_IN
,
255 [CX231XX_BOARD_CNXT_VIDEO_GRABBER
] = {
256 .name
= "Conexant VIDEO GRABBER",
257 .tuner_type
= TUNER_ABSENT
,
258 .decoder
= CX231XX_AVDECODER
,
259 .output_mode
= OUT_MODE_VIP11
,
260 .ctl_pin_status_mask
= 0xFFFFFFC4,
261 .agc_analog_digital_select_gpio
= 0x1c,
262 .gpio_pin_status_mask
= 0x4001000,
263 .norm
= V4L2_STD_PAL
,
266 .type
= CX231XX_VMUX_COMPOSITE1
,
267 .vmux
= CX231XX_VIN_2_1
,
268 .amux
= CX231XX_AMUX_LINE_IN
,
271 .type
= CX231XX_VMUX_SVIDEO
,
272 .vmux
= CX231XX_VIN_1_1
|
273 (CX231XX_VIN_1_2
<< 8) |
275 .amux
= CX231XX_AMUX_LINE_IN
,
280 [CX231XX_BOARD_CNXT_RDE_250
] = {
281 .name
= "Conexant Hybrid TV - rde 250",
282 .tuner_type
= TUNER_XC5000
,
284 .tuner_gpio
= RDE250_XCV_TUNER
,
285 .tuner_sif_gpio
= 0x05,
286 .tuner_scl_gpio
= 0x1a,
287 .tuner_sda_gpio
= 0x1b,
288 .decoder
= CX231XX_AVDECODER
,
289 .output_mode
= OUT_MODE_VIP11
,
290 .demod_xfer_mode
= 0,
291 .ctl_pin_status_mask
= 0xFFFFFFC4,
292 .agc_analog_digital_select_gpio
= 0x0c,
293 .gpio_pin_status_mask
= 0x4001000,
294 .tuner_i2c_master
= 1,
295 .demod_i2c_master
= 2,
298 .norm
= V4L2_STD_PAL
,
301 .type
= CX231XX_VMUX_TELEVISION
,
302 .vmux
= CX231XX_VIN_2_1
,
303 .amux
= CX231XX_AMUX_VIDEO
,
308 [CX231XX_BOARD_CNXT_RDU_250
] = {
309 .name
= "Conexant Hybrid TV - RDU 250",
310 .tuner_type
= TUNER_XC5000
,
312 .tuner_gpio
= RDE250_XCV_TUNER
,
313 .tuner_sif_gpio
= 0x05,
314 .tuner_scl_gpio
= 0x1a,
315 .tuner_sda_gpio
= 0x1b,
316 .decoder
= CX231XX_AVDECODER
,
317 .output_mode
= OUT_MODE_VIP11
,
318 .demod_xfer_mode
= 0,
319 .ctl_pin_status_mask
= 0xFFFFFFC4,
320 .agc_analog_digital_select_gpio
= 0x0c,
321 .gpio_pin_status_mask
= 0x4001000,
322 .tuner_i2c_master
= 1,
323 .demod_i2c_master
= 2,
326 .norm
= V4L2_STD_NTSC
,
329 .type
= CX231XX_VMUX_TELEVISION
,
330 .vmux
= CX231XX_VIN_2_1
,
331 .amux
= CX231XX_AMUX_VIDEO
,
336 [CX231XX_BOARD_HAUPPAUGE_EXETER
] = {
337 .name
= "Hauppauge EXETER",
338 .tuner_type
= TUNER_NXP_TDA18271
,
340 .tuner_gpio
= RDE250_XCV_TUNER
,
341 .tuner_sif_gpio
= 0x05,
342 .tuner_scl_gpio
= 0x1a,
343 .tuner_sda_gpio
= 0x1b,
344 .decoder
= CX231XX_AVDECODER
,
345 .output_mode
= OUT_MODE_VIP11
,
346 .demod_xfer_mode
= 0,
347 .ctl_pin_status_mask
= 0xFFFFFFC4,
348 .agc_analog_digital_select_gpio
= 0x0c,
349 .gpio_pin_status_mask
= 0x4001000,
350 .tuner_i2c_master
= 1,
351 .demod_i2c_master
= 2,
354 .norm
= V4L2_STD_NTSC
,
357 .type
= CX231XX_VMUX_TELEVISION
,
358 .vmux
= CX231XX_VIN_3_1
,
359 .amux
= CX231XX_AMUX_VIDEO
,
362 .type
= CX231XX_VMUX_COMPOSITE1
,
363 .vmux
= CX231XX_VIN_2_1
,
364 .amux
= CX231XX_AMUX_LINE_IN
,
367 .type
= CX231XX_VMUX_SVIDEO
,
368 .vmux
= CX231XX_VIN_1_1
|
369 (CX231XX_VIN_1_2
<< 8) |
371 .amux
= CX231XX_AMUX_LINE_IN
,
375 [CX231XX_BOARD_HAUPPAUGE_USBLIVE2
] = {
376 .name
= "Hauppauge USB Live 2",
377 .tuner_type
= TUNER_ABSENT
,
378 .decoder
= CX231XX_AVDECODER
,
379 .output_mode
= OUT_MODE_VIP11
,
380 .demod_xfer_mode
= 0,
381 .ctl_pin_status_mask
= 0xFFFFFFC4,
382 .agc_analog_digital_select_gpio
= 0x0c,
383 .gpio_pin_status_mask
= 0x4001000,
384 .norm
= V4L2_STD_NTSC
,
386 .type
= CX231XX_VMUX_COMPOSITE1
,
387 .vmux
= CX231XX_VIN_2_1
,
388 .amux
= CX231XX_AMUX_LINE_IN
,
391 .type
= CX231XX_VMUX_SVIDEO
,
392 .vmux
= CX231XX_VIN_1_1
|
393 (CX231XX_VIN_1_2
<< 8) |
395 .amux
= CX231XX_AMUX_LINE_IN
,
399 [CX231XX_BOARD_PV_PLAYTV_USB_HYBRID
] = {
400 .name
= "Pixelview PlayTV USB Hybrid",
401 .tuner_type
= TUNER_NXP_TDA18271
,
403 .decoder
= CX231XX_AVDECODER
,
404 .output_mode
= OUT_MODE_VIP11
,
405 .demod_xfer_mode
= 0,
406 .ctl_pin_status_mask
= 0xFFFFFFC4,
407 .agc_analog_digital_select_gpio
= 0x00, /* According with PV cxPolaris.inf file */
408 .tuner_sif_gpio
= -1,
409 .tuner_scl_gpio
= -1,
410 .tuner_sda_gpio
= -1,
411 .gpio_pin_status_mask
= 0x4001000,
412 .tuner_i2c_master
= 2,
413 .demod_i2c_master
= 1,
415 .rc_map_name
= RC_MAP_PIXELVIEW_002T
,
418 .norm
= V4L2_STD_PAL_M
,
420 .type
= CX231XX_VMUX_TELEVISION
,
421 .vmux
= CX231XX_VIN_3_1
,
422 .amux
= CX231XX_AMUX_VIDEO
,
425 .type
= CX231XX_VMUX_COMPOSITE1
,
426 .vmux
= CX231XX_VIN_2_1
,
427 .amux
= CX231XX_AMUX_LINE_IN
,
430 .type
= CX231XX_VMUX_SVIDEO
,
431 .vmux
= CX231XX_VIN_1_1
|
432 (CX231XX_VIN_1_2
<< 8) |
434 .amux
= CX231XX_AMUX_LINE_IN
,
439 const unsigned int cx231xx_bcount
= ARRAY_SIZE(cx231xx_boards
);
441 /* table of devices that work with this driver */
442 struct usb_device_id cx231xx_id_table
[] = {
443 {USB_DEVICE(0x0572, 0x5A3C),
444 .driver_info
= CX231XX_BOARD_UNKNOWN
},
445 {USB_DEVICE(0x0572, 0x58A2),
446 .driver_info
= CX231XX_BOARD_CNXT_CARRAERA
},
447 {USB_DEVICE(0x0572, 0x58A1),
448 .driver_info
= CX231XX_BOARD_CNXT_SHELBY
},
449 {USB_DEVICE(0x0572, 0x58A4),
450 .driver_info
= CX231XX_BOARD_CNXT_RDE_253S
},
451 {USB_DEVICE(0x0572, 0x58A5),
452 .driver_info
= CX231XX_BOARD_CNXT_RDU_253S
},
453 {USB_DEVICE(0x0572, 0x58A6),
454 .driver_info
= CX231XX_BOARD_CNXT_VIDEO_GRABBER
},
455 {USB_DEVICE(0x0572, 0x589E),
456 .driver_info
= CX231XX_BOARD_CNXT_RDE_250
},
457 {USB_DEVICE(0x0572, 0x58A0),
458 .driver_info
= CX231XX_BOARD_CNXT_RDU_250
},
459 {USB_DEVICE(0x2040, 0xb120),
460 .driver_info
= CX231XX_BOARD_HAUPPAUGE_EXETER
},
461 {USB_DEVICE(0x2040, 0xb140),
462 .driver_info
= CX231XX_BOARD_HAUPPAUGE_EXETER
},
463 {USB_DEVICE(0x2040, 0xc200),
464 .driver_info
= CX231XX_BOARD_HAUPPAUGE_USBLIVE2
},
465 {USB_DEVICE_VER(USB_VID_PIXELVIEW
, USB_PID_PIXELVIEW_SBTVD
, 0x4000, 0x4001),
466 .driver_info
= CX231XX_BOARD_PV_PLAYTV_USB_HYBRID
},
470 MODULE_DEVICE_TABLE(usb
, cx231xx_id_table
);
472 /* cx231xx_tuner_callback
473 * will be used to reset XC5000 tuner using GPIO pin
476 int cx231xx_tuner_callback(void *ptr
, int component
, int command
, int arg
)
479 struct cx231xx
*dev
= ptr
;
481 if (dev
->tuner_type
== TUNER_XC5000
) {
482 if (command
== XC5000_TUNER_RESET
) {
484 ("Tuner CB: RESET: cmd %d : tuner type %d \n",
485 command
, dev
->tuner_type
);
486 cx231xx_set_gpio_value(dev
, dev
->board
.tuner_gpio
->bit
,
489 cx231xx_set_gpio_value(dev
, dev
->board
.tuner_gpio
->bit
,
492 cx231xx_set_gpio_value(dev
, dev
->board
.tuner_gpio
->bit
,
496 } else if (dev
->tuner_type
== TUNER_NXP_TDA18271
) {
498 case TDA18271_CALLBACK_CMD_AGC_ENABLE
:
499 if (dev
->model
== CX231XX_BOARD_PV_PLAYTV_USB_HYBRID
)
500 rc
= cx231xx_set_agc_analog_digital_mux_select(dev
, arg
);
509 EXPORT_SYMBOL_GPL(cx231xx_tuner_callback
);
511 void cx231xx_reset_out(struct cx231xx
*dev
)
513 cx231xx_set_gpio_value(dev
, CX23417_RESET
, 1);
515 cx231xx_set_gpio_value(dev
, CX23417_RESET
, 0);
517 cx231xx_set_gpio_value(dev
, CX23417_RESET
, 1);
519 void cx231xx_enable_OSC(struct cx231xx
*dev
)
521 cx231xx_set_gpio_value(dev
, CX23417_OSC_EN
, 1);
523 void cx231xx_sleep_s5h1432(struct cx231xx
*dev
)
525 cx231xx_set_gpio_value(dev
, SLEEP_S5H1432
, 0);
528 static inline void cx231xx_set_model(struct cx231xx
*dev
)
530 memcpy(&dev
->board
, &cx231xx_boards
[dev
->model
], sizeof(dev
->board
));
533 /* Since cx231xx_pre_card_setup() requires a proper dev->model,
534 * this won't work for boards with generic PCI IDs
536 void cx231xx_pre_card_setup(struct cx231xx
*dev
)
539 cx231xx_set_model(dev
);
541 cx231xx_info("Identified as %s (card=%d)\n",
542 dev
->board
.name
, dev
->model
);
544 /* set the direction for GPIO pins */
545 if (dev
->board
.tuner_gpio
) {
546 cx231xx_set_gpio_direction(dev
, dev
->board
.tuner_gpio
->bit
, 1);
547 cx231xx_set_gpio_value(dev
, dev
->board
.tuner_gpio
->bit
, 1);
549 if (dev
->board
.tuner_sif_gpio
>= 0)
550 cx231xx_set_gpio_direction(dev
, dev
->board
.tuner_sif_gpio
, 1);
552 /* request some modules if any required */
554 /* set the mode to Analog mode initially */
555 cx231xx_set_mode(dev
, CX231XX_ANALOG_MODE
);
558 /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */
562 static void cx231xx_config_tuner(struct cx231xx
*dev
)
564 struct tuner_setup tun_setup
;
565 struct v4l2_frequency f
;
567 if (dev
->tuner_type
== TUNER_ABSENT
)
570 tun_setup
.mode_mask
= T_ANALOG_TV
| T_RADIO
;
571 tun_setup
.type
= dev
->tuner_type
;
572 tun_setup
.addr
= dev
->tuner_addr
;
573 tun_setup
.tuner_callback
= cx231xx_tuner_callback
;
575 tuner_call(dev
, tuner
, s_type_addr
, &tun_setup
);
578 if (tun_setup
.type
== TUNER_XC5000
) {
579 static struct xc2028_ctrl ctrl
= {
580 .fname
= XC5000_DEFAULT_FIRMWARE
,
584 struct v4l2_priv_tun_config cfg
= {
585 .tuner
= dev
->tuner_type
,
588 tuner_call(dev
, tuner
, s_config
, &cfg
);
591 /* configure tuner */
593 f
.type
= V4L2_TUNER_ANALOG_TV
;
594 f
.frequency
= 9076; /* just a magic number */
595 dev
->ctl_freq
= f
.frequency
;
596 call_all(dev
, tuner
, s_frequency
, &f
);
600 void cx231xx_card_setup(struct cx231xx
*dev
)
603 cx231xx_set_model(dev
);
605 dev
->tuner_type
= cx231xx_boards
[dev
->model
].tuner_type
;
606 if (cx231xx_boards
[dev
->model
].tuner_addr
)
607 dev
->tuner_addr
= cx231xx_boards
[dev
->model
].tuner_addr
;
609 /* request some modules */
610 if (dev
->board
.decoder
== CX231XX_AVDECODER
) {
611 dev
->sd_cx25840
= v4l2_i2c_new_subdev(&dev
->v4l2_dev
,
612 &dev
->i2c_bus
[0].i2c_adap
,
613 "cx25840", 0x88 >> 1, NULL
);
614 if (dev
->sd_cx25840
== NULL
)
615 cx231xx_info("cx25840 subdev registration failure\n");
616 cx25840_call(dev
, core
, load_fw
);
620 /* Initialize the tuner */
621 if (dev
->board
.tuner_type
!= TUNER_ABSENT
) {
622 dev
->sd_tuner
= v4l2_i2c_new_subdev(&dev
->v4l2_dev
,
623 &dev
->i2c_bus
[dev
->board
.tuner_i2c_master
].i2c_adap
,
625 dev
->tuner_addr
, NULL
);
626 if (dev
->sd_tuner
== NULL
)
627 cx231xx_info("tuner subdev registration failure\n");
629 cx231xx_config_tuner(dev
);
635 * inits registers with sane defaults
637 int cx231xx_config(struct cx231xx
*dev
)
639 /* TBD need to add cx231xx specific code */
640 dev
->mute
= 1; /* maybe not the right place... */
647 * cx231xx_config_i2c()
648 * configure i2c attached devices
650 void cx231xx_config_i2c(struct cx231xx
*dev
)
652 /* u32 input = INPUT(dev->video_input)->vmux; */
654 call_all(dev
, video
, s_stream
, 1);
658 * cx231xx_realease_resources()
659 * unregisters the v4l2,i2c and usb devices
660 * called when the device gets disconected or at module unload
662 void cx231xx_release_resources(struct cx231xx
*dev
)
664 cx231xx_release_analog_resources(dev
);
666 cx231xx_remove_from_devlist(dev
);
668 /* Release I2C buses */
669 cx231xx_dev_uninit(dev
);
671 cx231xx_ir_exit(dev
);
673 usb_put_dev(dev
->udev
);
675 /* Mark device as unused */
676 cx231xx_devused
&= ~(1 << dev
->devno
);
681 * allocates and inits the device structs, registers i2c bus and v4l device
683 static int cx231xx_init_dev(struct cx231xx
**devhandle
, struct usb_device
*udev
,
686 struct cx231xx
*dev
= *devhandle
;
687 int retval
= -ENOMEM
;
689 unsigned int maxh
, maxw
;
692 mutex_init(&dev
->lock
);
693 mutex_init(&dev
->ctrl_urb_lock
);
694 mutex_init(&dev
->gpio_i2c_lock
);
695 mutex_init(&dev
->i2c_lock
);
697 spin_lock_init(&dev
->video_mode
.slock
);
698 spin_lock_init(&dev
->vbi_mode
.slock
);
699 spin_lock_init(&dev
->sliced_cc_mode
.slock
);
701 init_waitqueue_head(&dev
->open
);
702 init_waitqueue_head(&dev
->wait_frame
);
703 init_waitqueue_head(&dev
->wait_stream
);
705 dev
->cx231xx_read_ctrl_reg
= cx231xx_read_ctrl_reg
;
706 dev
->cx231xx_write_ctrl_reg
= cx231xx_write_ctrl_reg
;
707 dev
->cx231xx_send_usb_command
= cx231xx_send_usb_command
;
708 dev
->cx231xx_gpio_i2c_read
= cx231xx_gpio_i2c_read
;
709 dev
->cx231xx_gpio_i2c_write
= cx231xx_gpio_i2c_write
;
711 /* Query cx231xx to find what pcb config it is related to */
712 initialize_cx231xx(dev
);
714 /*To workaround error number=-71 on EP0 for VideoGrabber,
716 if (dev
->model
== CX231XX_BOARD_CNXT_VIDEO_GRABBER
||
717 dev
->model
== CX231XX_BOARD_HAUPPAUGE_USBLIVE2
) {
718 cx231xx_set_alt_setting(dev
, INDEX_VIDEO
, 3);
719 cx231xx_set_alt_setting(dev
, INDEX_VANC
, 1);
721 /* Cx231xx pre card setup */
722 cx231xx_pre_card_setup(dev
);
724 errCode
= cx231xx_config(dev
);
726 cx231xx_errdev("error configuring device\n");
730 /* set default norm */
731 dev
->norm
= dev
->board
.norm
;
733 /* register i2c bus */
734 errCode
= cx231xx_dev_init(dev
);
736 cx231xx_dev_uninit(dev
);
737 cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
742 /* Do board specific init */
743 cx231xx_card_setup(dev
);
745 /* configure the device */
746 cx231xx_config_i2c(dev
);
748 maxw
= norm_maxw(dev
);
749 maxh
= norm_maxh(dev
);
751 /* set default image size */
755 dev
->video_input
= 0;
757 errCode
= cx231xx_config(dev
);
759 cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
764 /* init video dma queues */
765 INIT_LIST_HEAD(&dev
->video_mode
.vidq
.active
);
766 INIT_LIST_HEAD(&dev
->video_mode
.vidq
.queued
);
768 /* init vbi dma queues */
769 INIT_LIST_HEAD(&dev
->vbi_mode
.vidq
.active
);
770 INIT_LIST_HEAD(&dev
->vbi_mode
.vidq
.queued
);
772 /* Reset other chips required if they are tied up with GPIO pins */
773 cx231xx_add_into_devlist(dev
);
775 if (dev
->model
== CX231XX_BOARD_CNXT_VIDEO_GRABBER
) {
776 printk(KERN_INFO
"attach 417 %d\n", dev
->model
);
777 if (cx231xx_417_register(dev
) < 0) {
779 "%s() Failed to register 417 on VID_B\n",
784 retval
= cx231xx_register_analog_devices(dev
);
786 cx231xx_release_resources(dev
);
790 cx231xx_ir_init(dev
);
792 cx231xx_init_extension(dev
);
797 #if defined(CONFIG_MODULES) && defined(MODULE)
798 static void request_module_async(struct work_struct
*work
)
800 struct cx231xx
*dev
= container_of(work
,
801 struct cx231xx
, request_module_wk
);
803 if (dev
->has_alsa_audio
)
804 request_module("cx231xx-alsa");
806 if (dev
->board
.has_dvb
)
807 request_module("cx231xx-dvb");
811 static void request_modules(struct cx231xx
*dev
)
813 INIT_WORK(&dev
->request_module_wk
, request_module_async
);
814 schedule_work(&dev
->request_module_wk
);
817 static void flush_request_modules(struct cx231xx
*dev
)
819 flush_work_sync(&dev
->request_module_wk
);
822 #define request_modules(dev)
823 #define flush_request_modules(dev)
824 #endif /* CONFIG_MODULES */
827 * cx231xx_usb_probe()
828 * checks for supported devices
830 static int cx231xx_usb_probe(struct usb_interface
*interface
,
831 const struct usb_device_id
*id
)
833 struct usb_device
*udev
;
834 struct usb_interface
*uif
;
835 struct cx231xx
*dev
= NULL
;
836 int retval
= -ENODEV
;
838 int i
, isoc_pipe
= 0;
840 char descr
[255] = "";
841 struct usb_interface
*lif
= NULL
;
842 struct usb_interface_assoc_descriptor
*assoc_desc
;
844 udev
= usb_get_dev(interface_to_usbdev(interface
));
845 ifnum
= interface
->altsetting
[0].desc
.bInterfaceNumber
;
849 * Interface number 0 - IR interface
851 /* Check to see next free device and mark as used */
852 nr
= find_first_zero_bit(&cx231xx_devused
, CX231XX_MAXBOARDS
);
853 cx231xx_devused
|= 1 << nr
;
855 if (nr
>= CX231XX_MAXBOARDS
) {
856 cx231xx_err(DRIVER_NAME
857 ": Supports only %i cx231xx boards.\n", CX231XX_MAXBOARDS
);
858 cx231xx_devused
&= ~(1 << nr
);
862 /* allocate memory for our device state and initialize it */
863 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
865 cx231xx_err(DRIVER_NAME
": out of memory!\n");
866 cx231xx_devused
&= ~(1 << nr
);
870 snprintf(dev
->name
, 29, "cx231xx #%d", nr
);
872 dev
->model
= id
->driver_info
;
873 dev
->video_mode
.alt
= -1;
874 dev
->interface_count
++;
876 /* reset gpio dir and value */
879 dev
->xc_fw_load_done
= 0;
880 dev
->has_alsa_audio
= 1;
881 dev
->power_mode
= -1;
882 atomic_set(&dev
->devlist_count
, 0);
884 /* 0 - vbi ; 1 -sliced cc mode */
885 dev
->vbi_or_sliced_cc_mode
= 0;
887 /* get maximum no.of IAD interfaces */
888 assoc_desc
= udev
->actconfig
->intf_assoc
[0];
889 dev
->max_iad_interface_count
= assoc_desc
->bInterfaceCount
;
891 /* init CIR module TBD */
893 /* store the current interface */
896 /*mode_tv: digital=1 or analog=0*/
899 dev
->USE_ISO
= transfer_mode
;
901 switch (udev
->speed
) {
905 case USB_SPEED_UNKNOWN
:
916 if (udev
->manufacturer
)
917 strlcpy(descr
, udev
->manufacturer
, sizeof(descr
));
921 strlcat(descr
, " ", sizeof(descr
));
922 strlcat(descr
, udev
->product
, sizeof(descr
));
925 strlcat(descr
, " ", sizeof(descr
));
927 cx231xx_info("New device %s@ %s Mbps "
928 "(%04x:%04x) with %d interfaces\n",
931 le16_to_cpu(udev
->descriptor
.idVendor
),
932 le16_to_cpu(udev
->descriptor
.idProduct
),
933 dev
->max_iad_interface_count
);
935 /* store the interface 0 back */
936 lif
= udev
->actconfig
->interface
[0];
938 /* increment interface count */
939 dev
->interface_count
++;
941 /* get device number */
944 assoc_desc
= udev
->actconfig
->intf_assoc
[0];
945 if (assoc_desc
->bFirstInterface
!= ifnum
) {
946 cx231xx_err(DRIVER_NAME
": Not found "
947 "matching IAD interface\n");
954 cx231xx_info("registering interface %d\n", ifnum
);
956 /* save our data pointer in this interface device */
957 usb_set_intfdata(lif
, dev
);
960 * AV device initialization - only done at the last interface
963 /* Create v4l2 device */
964 retval
= v4l2_device_register(&interface
->dev
, &dev
->v4l2_dev
);
966 cx231xx_errdev("v4l2_device_register failed\n");
967 cx231xx_devused
&= ~(1 << nr
);
972 /* allocate device struct */
973 retval
= cx231xx_init_dev(&dev
, udev
, nr
);
975 cx231xx_devused
&= ~(1 << dev
->devno
);
976 v4l2_device_unregister(&dev
->v4l2_dev
);
979 usb_set_intfdata(lif
, NULL
);
984 /* compute alternate max packet sizes for video */
985 uif
= udev
->actconfig
->interface
[dev
->current_pcb_config
.
986 hs_config_info
[0].interface_info
.video_index
+ 1];
988 dev
->video_mode
.end_point_addr
= le16_to_cpu(uif
->altsetting
[0].
989 endpoint
[isoc_pipe
].desc
.bEndpointAddress
);
991 dev
->video_mode
.num_alt
= uif
->num_altsetting
;
992 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
993 dev
->video_mode
.end_point_addr
,
994 dev
->video_mode
.num_alt
);
995 dev
->video_mode
.alt_max_pkt_size
=
996 kmalloc(32 * dev
->video_mode
.num_alt
, GFP_KERNEL
);
998 if (dev
->video_mode
.alt_max_pkt_size
== NULL
) {
999 cx231xx_errdev("out of memory!\n");
1000 cx231xx_devused
&= ~(1 << nr
);
1001 v4l2_device_unregister(&dev
->v4l2_dev
);
1007 for (i
= 0; i
< dev
->video_mode
.num_alt
; i
++) {
1008 u16 tmp
= le16_to_cpu(uif
->altsetting
[i
].endpoint
[isoc_pipe
].
1009 desc
.wMaxPacketSize
);
1010 dev
->video_mode
.alt_max_pkt_size
[i
] =
1011 (tmp
& 0x07ff) * (((tmp
& 0x1800) >> 11) + 1);
1012 cx231xx_info("Alternate setting %i, max size= %i\n", i
,
1013 dev
->video_mode
.alt_max_pkt_size
[i
]);
1016 /* compute alternate max packet sizes for vbi */
1017 uif
= udev
->actconfig
->interface
[dev
->current_pcb_config
.
1018 hs_config_info
[0].interface_info
.
1021 dev
->vbi_mode
.end_point_addr
=
1022 le16_to_cpu(uif
->altsetting
[0].endpoint
[isoc_pipe
].desc
.
1025 dev
->vbi_mode
.num_alt
= uif
->num_altsetting
;
1026 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1027 dev
->vbi_mode
.end_point_addr
,
1028 dev
->vbi_mode
.num_alt
);
1029 dev
->vbi_mode
.alt_max_pkt_size
=
1030 kmalloc(32 * dev
->vbi_mode
.num_alt
, GFP_KERNEL
);
1032 if (dev
->vbi_mode
.alt_max_pkt_size
== NULL
) {
1033 cx231xx_errdev("out of memory!\n");
1034 cx231xx_devused
&= ~(1 << nr
);
1035 v4l2_device_unregister(&dev
->v4l2_dev
);
1041 for (i
= 0; i
< dev
->vbi_mode
.num_alt
; i
++) {
1043 le16_to_cpu(uif
->altsetting
[i
].endpoint
[isoc_pipe
].
1044 desc
.wMaxPacketSize
);
1045 dev
->vbi_mode
.alt_max_pkt_size
[i
] =
1046 (tmp
& 0x07ff) * (((tmp
& 0x1800) >> 11) + 1);
1047 cx231xx_info("Alternate setting %i, max size= %i\n", i
,
1048 dev
->vbi_mode
.alt_max_pkt_size
[i
]);
1051 /* compute alternate max packet sizes for sliced CC */
1052 uif
= udev
->actconfig
->interface
[dev
->current_pcb_config
.
1053 hs_config_info
[0].interface_info
.
1056 dev
->sliced_cc_mode
.end_point_addr
=
1057 le16_to_cpu(uif
->altsetting
[0].endpoint
[isoc_pipe
].desc
.
1060 dev
->sliced_cc_mode
.num_alt
= uif
->num_altsetting
;
1061 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1062 dev
->sliced_cc_mode
.end_point_addr
,
1063 dev
->sliced_cc_mode
.num_alt
);
1064 dev
->sliced_cc_mode
.alt_max_pkt_size
=
1065 kmalloc(32 * dev
->sliced_cc_mode
.num_alt
, GFP_KERNEL
);
1067 if (dev
->sliced_cc_mode
.alt_max_pkt_size
== NULL
) {
1068 cx231xx_errdev("out of memory!\n");
1069 cx231xx_devused
&= ~(1 << nr
);
1070 v4l2_device_unregister(&dev
->v4l2_dev
);
1076 for (i
= 0; i
< dev
->sliced_cc_mode
.num_alt
; i
++) {
1077 u16 tmp
= le16_to_cpu(uif
->altsetting
[i
].endpoint
[isoc_pipe
].
1078 desc
.wMaxPacketSize
);
1079 dev
->sliced_cc_mode
.alt_max_pkt_size
[i
] =
1080 (tmp
& 0x07ff) * (((tmp
& 0x1800) >> 11) + 1);
1081 cx231xx_info("Alternate setting %i, max size= %i\n", i
,
1082 dev
->sliced_cc_mode
.alt_max_pkt_size
[i
]);
1085 if (dev
->current_pcb_config
.ts1_source
!= 0xff) {
1086 /* compute alternate max packet sizes for TS1 */
1087 uif
= udev
->actconfig
->interface
[dev
->current_pcb_config
.
1092 dev
->ts1_mode
.end_point_addr
=
1093 le16_to_cpu(uif
->altsetting
[0].endpoint
[isoc_pipe
].
1094 desc
.bEndpointAddress
);
1096 dev
->ts1_mode
.num_alt
= uif
->num_altsetting
;
1097 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1098 dev
->ts1_mode
.end_point_addr
,
1099 dev
->ts1_mode
.num_alt
);
1100 dev
->ts1_mode
.alt_max_pkt_size
=
1101 kmalloc(32 * dev
->ts1_mode
.num_alt
, GFP_KERNEL
);
1103 if (dev
->ts1_mode
.alt_max_pkt_size
== NULL
) {
1104 cx231xx_errdev("out of memory!\n");
1105 cx231xx_devused
&= ~(1 << nr
);
1106 v4l2_device_unregister(&dev
->v4l2_dev
);
1112 for (i
= 0; i
< dev
->ts1_mode
.num_alt
; i
++) {
1113 u16 tmp
= le16_to_cpu(uif
->altsetting
[i
].
1114 endpoint
[isoc_pipe
].desc
.
1116 dev
->ts1_mode
.alt_max_pkt_size
[i
] =
1117 (tmp
& 0x07ff) * (((tmp
& 0x1800) >> 11) + 1);
1118 cx231xx_info("Alternate setting %i, max size= %i\n", i
,
1119 dev
->ts1_mode
.alt_max_pkt_size
[i
]);
1123 if (dev
->model
== CX231XX_BOARD_CNXT_VIDEO_GRABBER
) {
1124 cx231xx_enable_OSC(dev
);
1125 cx231xx_reset_out(dev
);
1126 cx231xx_set_alt_setting(dev
, INDEX_VIDEO
, 3);
1129 if (dev
->model
== CX231XX_BOARD_CNXT_RDE_253S
)
1130 cx231xx_sleep_s5h1432(dev
);
1132 /* load other modules required */
1133 request_modules(dev
);
1139 * cx231xx_usb_disconnect()
1140 * called when the device gets diconencted
1141 * video device will be unregistered on v4l2_close in case it is still open
1143 static void cx231xx_usb_disconnect(struct usb_interface
*interface
)
1145 struct cx231xx
*dev
;
1147 dev
= usb_get_intfdata(interface
);
1148 usb_set_intfdata(interface
, NULL
);
1156 flush_request_modules(dev
);
1158 /* delete v4l2 device */
1159 v4l2_device_unregister(&dev
->v4l2_dev
);
1161 /* wait until all current v4l2 io is finished then deallocate
1163 mutex_lock(&dev
->lock
);
1165 wake_up_interruptible_all(&dev
->open
);
1169 ("device %s is open! Deregistration and memory "
1170 "deallocation are deferred on close.\n",
1171 video_device_node_name(dev
->vdev
));
1173 dev
->state
|= DEV_MISCONFIGURED
;
1175 cx231xx_uninit_isoc(dev
);
1177 cx231xx_uninit_bulk(dev
);
1178 dev
->state
|= DEV_DISCONNECTED
;
1179 wake_up_interruptible(&dev
->wait_frame
);
1180 wake_up_interruptible(&dev
->wait_stream
);
1182 dev
->state
|= DEV_DISCONNECTED
;
1183 cx231xx_release_resources(dev
);
1186 cx231xx_close_extension(dev
);
1188 mutex_unlock(&dev
->lock
);
1191 kfree(dev
->video_mode
.alt_max_pkt_size
);
1192 kfree(dev
->vbi_mode
.alt_max_pkt_size
);
1193 kfree(dev
->sliced_cc_mode
.alt_max_pkt_size
);
1194 kfree(dev
->ts1_mode
.alt_max_pkt_size
);
1200 static struct usb_driver cx231xx_usb_driver
= {
1202 .probe
= cx231xx_usb_probe
,
1203 .disconnect
= cx231xx_usb_disconnect
,
1204 .id_table
= cx231xx_id_table
,
1207 static int __init
cx231xx_module_init(void)
1211 printk(KERN_INFO DRIVER_NAME
" v4l2 driver loaded.\n");
1213 /* register this driver with the USB subsystem */
1214 result
= usb_register(&cx231xx_usb_driver
);
1216 cx231xx_err(DRIVER_NAME
1217 " usb_register failed. Error number %d.\n", result
);
1222 static void __exit
cx231xx_module_exit(void)
1224 /* deregister this driver with the USB subsystem */
1225 usb_deregister(&cx231xx_usb_driver
);
1228 module_init(cx231xx_module_init
);
1229 module_exit(cx231xx_module_exit
);