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,
269 .type = CX231XX_VMUX_COMPOSITE1,
270 .vmux = CX231XX_VIN_2_1,
271 .amux = CX231XX_AMUX_LINE_IN,
274 .type = CX231XX_VMUX_SVIDEO,
275 .vmux = CX231XX_VIN_1_1 |
276 (CX231XX_VIN_1_2 << 8) |
278 .amux = CX231XX_AMUX_LINE_IN,
283 [CX231XX_BOARD_CNXT_RDE_250] = {
284 .name = "Conexant Hybrid TV - rde 250",
285 .tuner_type = TUNER_XC5000,
287 .tuner_gpio = RDE250_XCV_TUNER,
288 .tuner_sif_gpio = 0x05,
289 .tuner_scl_gpio = 0x1a,
290 .tuner_sda_gpio = 0x1b,
291 .decoder = CX231XX_AVDECODER,
292 .output_mode = OUT_MODE_VIP11,
293 .demod_xfer_mode = 0,
294 .ctl_pin_status_mask = 0xFFFFFFC4,
295 .agc_analog_digital_select_gpio = 0x0c,
296 .gpio_pin_status_mask = 0x4001000,
297 .tuner_i2c_master = 1,
298 .demod_i2c_master = 2,
301 .norm = V4L2_STD_PAL,
304 .type = CX231XX_VMUX_TELEVISION,
305 .vmux = CX231XX_VIN_2_1,
306 .amux = CX231XX_AMUX_VIDEO,
311 [CX231XX_BOARD_CNXT_RDU_250] = {
312 .name = "Conexant Hybrid TV - RDU 250",
313 .tuner_type = TUNER_XC5000,
315 .tuner_gpio = RDE250_XCV_TUNER,
316 .tuner_sif_gpio = 0x05,
317 .tuner_scl_gpio = 0x1a,
318 .tuner_sda_gpio = 0x1b,
319 .decoder = CX231XX_AVDECODER,
320 .output_mode = OUT_MODE_VIP11,
321 .demod_xfer_mode = 0,
322 .ctl_pin_status_mask = 0xFFFFFFC4,
323 .agc_analog_digital_select_gpio = 0x0c,
324 .gpio_pin_status_mask = 0x4001000,
325 .tuner_i2c_master = 1,
326 .demod_i2c_master = 2,
329 .norm = V4L2_STD_NTSC,
332 .type = CX231XX_VMUX_TELEVISION,
333 .vmux = CX231XX_VIN_2_1,
334 .amux = CX231XX_AMUX_VIDEO,
339 [CX231XX_BOARD_HAUPPAUGE_EXETER] = {
340 .name = "Hauppauge EXETER",
341 .tuner_type = TUNER_NXP_TDA18271,
343 .tuner_gpio = RDE250_XCV_TUNER,
344 .tuner_sif_gpio = 0x05,
345 .tuner_scl_gpio = 0x1a,
346 .tuner_sda_gpio = 0x1b,
347 .decoder = CX231XX_AVDECODER,
348 .output_mode = OUT_MODE_VIP11,
349 .demod_xfer_mode = 0,
350 .ctl_pin_status_mask = 0xFFFFFFC4,
351 .agc_analog_digital_select_gpio = 0x0c,
352 .gpio_pin_status_mask = 0x4001000,
353 .tuner_i2c_master = 1,
354 .demod_i2c_master = 2,
357 .norm = V4L2_STD_NTSC,
360 .type = CX231XX_VMUX_TELEVISION,
361 .vmux = CX231XX_VIN_3_1,
362 .amux = CX231XX_AMUX_VIDEO,
365 .type = CX231XX_VMUX_COMPOSITE1,
366 .vmux = CX231XX_VIN_2_1,
367 .amux = CX231XX_AMUX_LINE_IN,
370 .type = CX231XX_VMUX_SVIDEO,
371 .vmux = CX231XX_VIN_1_1 |
372 (CX231XX_VIN_1_2 << 8) |
374 .amux = CX231XX_AMUX_LINE_IN,
378 [CX231XX_BOARD_HAUPPAUGE_USBLIVE2] = {
379 .name = "Hauppauge USB Live 2",
380 .tuner_type = TUNER_ABSENT,
381 .decoder = CX231XX_AVDECODER,
382 .output_mode = OUT_MODE_VIP11,
383 .demod_xfer_mode = 0,
384 .ctl_pin_status_mask = 0xFFFFFFC4,
385 .agc_analog_digital_select_gpio = 0x0c,
386 .gpio_pin_status_mask = 0x4001000,
387 .norm = V4L2_STD_NTSC,
390 .dont_use_port_3 = 1,
392 .type = CX231XX_VMUX_COMPOSITE1,
393 .vmux = CX231XX_VIN_2_1,
394 .amux = CX231XX_AMUX_LINE_IN,
397 .type = CX231XX_VMUX_SVIDEO,
398 .vmux = CX231XX_VIN_1_1 |
399 (CX231XX_VIN_1_2 << 8) |
401 .amux = CX231XX_AMUX_LINE_IN,
405 [CX231XX_BOARD_KWORLD_UB430_USB_HYBRID] = {
406 .name = "Kworld UB430 USB Hybrid",
407 .tuner_type = TUNER_NXP_TDA18271,
409 .decoder = CX231XX_AVDECODER,
410 .output_mode = OUT_MODE_VIP11,
411 .demod_xfer_mode = 0,
412 .ctl_pin_status_mask = 0xFFFFFFC4,
413 .agc_analog_digital_select_gpio = 0x11, /* According with PV cxPolaris.inf file */
414 .tuner_sif_gpio = -1,
415 .tuner_scl_gpio = -1,
416 .tuner_sda_gpio = -1,
417 .gpio_pin_status_mask = 0x4001000,
418 .tuner_i2c_master = 2,
419 .demod_i2c_master = 1,
423 .norm = V4L2_STD_PAL_M,
425 .type = CX231XX_VMUX_TELEVISION,
426 .vmux = CX231XX_VIN_3_1,
427 .amux = CX231XX_AMUX_VIDEO,
430 .type = CX231XX_VMUX_COMPOSITE1,
431 .vmux = CX231XX_VIN_2_1,
432 .amux = CX231XX_AMUX_LINE_IN,
435 .type = CX231XX_VMUX_SVIDEO,
436 .vmux = CX231XX_VIN_1_1 |
437 (CX231XX_VIN_1_2 << 8) |
439 .amux = CX231XX_AMUX_LINE_IN,
443 [CX231XX_BOARD_PV_PLAYTV_USB_HYBRID] = {
444 .name = "Pixelview PlayTV USB Hybrid",
445 .tuner_type = TUNER_NXP_TDA18271,
447 .decoder = CX231XX_AVDECODER,
448 .output_mode = OUT_MODE_VIP11,
449 .demod_xfer_mode = 0,
450 .ctl_pin_status_mask = 0xFFFFFFC4,
451 .agc_analog_digital_select_gpio = 0x00, /* According with PV cxPolaris.inf file */
452 .tuner_sif_gpio = -1,
453 .tuner_scl_gpio = -1,
454 .tuner_sda_gpio = -1,
455 .gpio_pin_status_mask = 0x4001000,
456 .tuner_i2c_master = 2,
457 .demod_i2c_master = 1,
459 .rc_map_name = RC_MAP_PIXELVIEW_002T,
462 .norm = V4L2_STD_PAL_M,
464 .type = CX231XX_VMUX_TELEVISION,
465 .vmux = CX231XX_VIN_3_1,
466 .amux = CX231XX_AMUX_VIDEO,
469 .type = CX231XX_VMUX_COMPOSITE1,
470 .vmux = CX231XX_VIN_2_1,
471 .amux = CX231XX_AMUX_LINE_IN,
474 .type = CX231XX_VMUX_SVIDEO,
475 .vmux = CX231XX_VIN_1_1 |
476 (CX231XX_VIN_1_2 << 8) |
478 .amux = CX231XX_AMUX_LINE_IN,
482 [CX231XX_BOARD_PV_XCAPTURE_USB] = {
483 .name = "Pixelview Xcapture USB",
484 .tuner_type = TUNER_ABSENT,
485 .decoder = CX231XX_AVDECODER,
486 .output_mode = OUT_MODE_VIP11,
487 .demod_xfer_mode = 0,
488 .ctl_pin_status_mask = 0xFFFFFFC4,
489 .agc_analog_digital_select_gpio = 0x0c,
490 .gpio_pin_status_mask = 0x4001000,
491 .norm = V4L2_STD_NTSC,
494 .dont_use_port_3 = 1,
497 .type = CX231XX_VMUX_COMPOSITE1,
498 .vmux = CX231XX_VIN_2_1,
499 .amux = CX231XX_AMUX_LINE_IN,
502 .type = CX231XX_VMUX_SVIDEO,
503 .vmux = CX231XX_VIN_1_1 |
504 (CX231XX_VIN_1_2 << 8) |
506 .amux = CX231XX_AMUX_LINE_IN,
512 [CX231XX_BOARD_ICONBIT_U100] = {
513 .name = "Iconbit Analog Stick U100 FM",
514 .tuner_type = TUNER_ABSENT,
515 .decoder = CX231XX_AVDECODER,
516 .output_mode = OUT_MODE_VIP11,
517 .demod_xfer_mode = 0,
518 .ctl_pin_status_mask = 0xFFFFFFC4,
519 .agc_analog_digital_select_gpio = 0x1C,
520 .gpio_pin_status_mask = 0x4001000,
523 .type = CX231XX_VMUX_COMPOSITE1,
524 .vmux = CX231XX_VIN_2_1,
525 .amux = CX231XX_AMUX_LINE_IN,
528 .type = CX231XX_VMUX_SVIDEO,
529 .vmux = CX231XX_VIN_1_1 |
530 (CX231XX_VIN_1_2 << 8) |
532 .amux = CX231XX_AMUX_LINE_IN,
536 [CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL] = {
537 .name = "Hauppauge WinTV USB2 FM (PAL)",
538 .tuner_type = TUNER_NXP_TDA18271,
540 .tuner_gpio = RDE250_XCV_TUNER,
541 .tuner_sif_gpio = 0x05,
542 .tuner_scl_gpio = 0x1a,
543 .tuner_sda_gpio = 0x1b,
544 .decoder = CX231XX_AVDECODER,
545 .output_mode = OUT_MODE_VIP11,
546 .ctl_pin_status_mask = 0xFFFFFFC4,
547 .agc_analog_digital_select_gpio = 0x0c,
548 .gpio_pin_status_mask = 0x4001000,
549 .tuner_i2c_master = 1,
550 .norm = V4L2_STD_PAL,
553 .type = CX231XX_VMUX_TELEVISION,
554 .vmux = CX231XX_VIN_3_1,
555 .amux = CX231XX_AMUX_VIDEO,
558 .type = CX231XX_VMUX_COMPOSITE1,
559 .vmux = CX231XX_VIN_2_1,
560 .amux = CX231XX_AMUX_LINE_IN,
563 .type = CX231XX_VMUX_SVIDEO,
564 .vmux = CX231XX_VIN_1_1 |
565 (CX231XX_VIN_1_2 << 8) |
567 .amux = CX231XX_AMUX_LINE_IN,
571 [CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC] = {
572 .name = "Hauppauge WinTV USB2 FM (NTSC)",
573 .tuner_type = TUNER_NXP_TDA18271,
575 .tuner_gpio = RDE250_XCV_TUNER,
576 .tuner_sif_gpio = 0x05,
577 .tuner_scl_gpio = 0x1a,
578 .tuner_sda_gpio = 0x1b,
579 .decoder = CX231XX_AVDECODER,
580 .output_mode = OUT_MODE_VIP11,
581 .ctl_pin_status_mask = 0xFFFFFFC4,
582 .agc_analog_digital_select_gpio = 0x0c,
583 .gpio_pin_status_mask = 0x4001000,
584 .tuner_i2c_master = 1,
585 .norm = V4L2_STD_NTSC,
588 .type = CX231XX_VMUX_TELEVISION,
589 .vmux = CX231XX_VIN_3_1,
590 .amux = CX231XX_AMUX_VIDEO,
593 .type = CX231XX_VMUX_COMPOSITE1,
594 .vmux = CX231XX_VIN_2_1,
595 .amux = CX231XX_AMUX_LINE_IN,
598 .type = CX231XX_VMUX_SVIDEO,
599 .vmux = CX231XX_VIN_1_1 |
600 (CX231XX_VIN_1_2 << 8) |
602 .amux = CX231XX_AMUX_LINE_IN,
606 [CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2] = {
607 .name = "Elgato Video Capture V2",
608 .tuner_type = TUNER_ABSENT,
609 .decoder = CX231XX_AVDECODER,
610 .output_mode = OUT_MODE_VIP11,
611 .demod_xfer_mode = 0,
612 .ctl_pin_status_mask = 0xFFFFFFC4,
613 .agc_analog_digital_select_gpio = 0x0c,
614 .gpio_pin_status_mask = 0x4001000,
615 .norm = V4L2_STD_NTSC,
618 .dont_use_port_3 = 1,
620 .type = CX231XX_VMUX_COMPOSITE1,
621 .vmux = CX231XX_VIN_2_1,
622 .amux = CX231XX_AMUX_LINE_IN,
625 .type = CX231XX_VMUX_SVIDEO,
626 .vmux = CX231XX_VIN_1_1 |
627 (CX231XX_VIN_1_2 << 8) |
629 .amux = CX231XX_AMUX_LINE_IN,
634 const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
636 /* table of devices that work with this driver */
637 struct usb_device_id cx231xx_id_table[] = {
638 {USB_DEVICE(0x0572, 0x5A3C),
639 .driver_info = CX231XX_BOARD_UNKNOWN},
640 {USB_DEVICE(0x0572, 0x58A2),
641 .driver_info = CX231XX_BOARD_CNXT_CARRAERA},
642 {USB_DEVICE(0x0572, 0x58A1),
643 .driver_info = CX231XX_BOARD_CNXT_SHELBY},
644 {USB_DEVICE(0x0572, 0x58A4),
645 .driver_info = CX231XX_BOARD_CNXT_RDE_253S},
646 {USB_DEVICE(0x0572, 0x58A5),
647 .driver_info = CX231XX_BOARD_CNXT_RDU_253S},
648 {USB_DEVICE(0x0572, 0x58A6),
649 .driver_info = CX231XX_BOARD_CNXT_VIDEO_GRABBER},
650 {USB_DEVICE(0x0572, 0x589E),
651 .driver_info = CX231XX_BOARD_CNXT_RDE_250},
652 {USB_DEVICE(0x0572, 0x58A0),
653 .driver_info = CX231XX_BOARD_CNXT_RDU_250},
654 {USB_DEVICE(0x2040, 0xb110),
655 .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL},
656 {USB_DEVICE(0x2040, 0xb111),
657 .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC},
658 {USB_DEVICE(0x2040, 0xb120),
659 .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
660 {USB_DEVICE(0x2040, 0xb140),
661 .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
662 {USB_DEVICE(0x2040, 0xc200),
663 .driver_info = CX231XX_BOARD_HAUPPAUGE_USBLIVE2},
664 {USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x4000, 0x4001),
665 .driver_info = CX231XX_BOARD_PV_PLAYTV_USB_HYBRID},
666 {USB_DEVICE(USB_VID_PIXELVIEW, 0x5014),
667 .driver_info = CX231XX_BOARD_PV_XCAPTURE_USB},
668 {USB_DEVICE(0x1b80, 0xe424),
669 .driver_info = CX231XX_BOARD_KWORLD_UB430_USB_HYBRID},
670 {USB_DEVICE(0x1f4d, 0x0237),
671 .driver_info = CX231XX_BOARD_ICONBIT_U100},
672 {USB_DEVICE(0x0fd9, 0x0037),
673 .driver_info = CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2},
677 MODULE_DEVICE_TABLE(usb, cx231xx_id_table);
679 /* cx231xx_tuner_callback
680 * will be used to reset XC5000 tuner using GPIO pin
683 int cx231xx_tuner_callback(void *ptr, int component, int command, int arg)
686 struct cx231xx *dev = ptr;
688 if (dev->tuner_type == TUNER_XC5000) {
689 if (command == XC5000_TUNER_RESET) {
691 ("Tuner CB: RESET: cmd %d : tuner type %d \n",
692 command, dev->tuner_type);
693 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
696 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
699 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
703 } else if (dev->tuner_type == TUNER_NXP_TDA18271) {
705 case TDA18271_CALLBACK_CMD_AGC_ENABLE:
706 if (dev->model == CX231XX_BOARD_PV_PLAYTV_USB_HYBRID)
707 rc = cx231xx_set_agc_analog_digital_mux_select(dev, arg);
716 EXPORT_SYMBOL_GPL(cx231xx_tuner_callback);
718 static void cx231xx_reset_out(struct cx231xx *dev)
720 cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
722 cx231xx_set_gpio_value(dev, CX23417_RESET, 0);
724 cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
727 static void cx231xx_enable_OSC(struct cx231xx *dev)
729 cx231xx_set_gpio_value(dev, CX23417_OSC_EN, 1);
732 static void cx231xx_sleep_s5h1432(struct cx231xx *dev)
734 cx231xx_set_gpio_value(dev, SLEEP_S5H1432, 0);
737 static inline void cx231xx_set_model(struct cx231xx *dev)
739 dev->board = cx231xx_boards[dev->model];
742 /* Since cx231xx_pre_card_setup() requires a proper dev->model,
743 * this won't work for boards with generic PCI IDs
745 void cx231xx_pre_card_setup(struct cx231xx *dev)
748 cx231xx_set_model(dev);
750 cx231xx_info("Identified as %s (card=%d)\n",
751 dev->board.name, dev->model);
753 /* set the direction for GPIO pins */
754 if (dev->board.tuner_gpio) {
755 cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
756 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
758 if (dev->board.tuner_sif_gpio >= 0)
759 cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
761 /* request some modules if any required */
763 /* set the mode to Analog mode initially */
764 cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
767 /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */
771 static void cx231xx_config_tuner(struct cx231xx *dev)
773 struct tuner_setup tun_setup;
774 struct v4l2_frequency f;
776 if (dev->tuner_type == TUNER_ABSENT)
779 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
780 tun_setup.type = dev->tuner_type;
781 tun_setup.addr = dev->tuner_addr;
782 tun_setup.tuner_callback = cx231xx_tuner_callback;
784 tuner_call(dev, tuner, s_type_addr, &tun_setup);
787 if (tun_setup.type == TUNER_XC5000) {
788 static struct xc2028_ctrl ctrl = {
789 .fname = XC5000_DEFAULT_FIRMWARE,
793 struct v4l2_priv_tun_config cfg = {
794 .tuner = dev->tuner_type,
797 tuner_call(dev, tuner, s_config, &cfg);
800 /* configure tuner */
802 f.type = V4L2_TUNER_ANALOG_TV;
803 f.frequency = 9076; /* just a magic number */
804 dev->ctl_freq = f.frequency;
805 call_all(dev, tuner, s_frequency, &f);
809 void cx231xx_card_setup(struct cx231xx *dev)
812 cx231xx_set_model(dev);
814 dev->tuner_type = cx231xx_boards[dev->model].tuner_type;
815 if (cx231xx_boards[dev->model].tuner_addr)
816 dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr;
818 /* request some modules */
819 if (dev->board.decoder == CX231XX_AVDECODER) {
820 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
821 &dev->i2c_bus[0].i2c_adap,
822 "cx25840", 0x88 >> 1, NULL);
823 if (dev->sd_cx25840 == NULL)
824 cx231xx_info("cx25840 subdev registration failure\n");
825 cx25840_call(dev, core, load_fw);
829 /* Initialize the tuner */
830 if (dev->board.tuner_type != TUNER_ABSENT) {
831 dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev,
832 &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
834 dev->tuner_addr, NULL);
835 if (dev->sd_tuner == NULL)
836 cx231xx_info("tuner subdev registration failure\n");
838 cx231xx_config_tuner(dev);
844 * inits registers with sane defaults
846 int cx231xx_config(struct cx231xx *dev)
848 /* TBD need to add cx231xx specific code */
849 dev->mute = 1; /* maybe not the right place... */
856 * cx231xx_config_i2c()
857 * configure i2c attached devices
859 void cx231xx_config_i2c(struct cx231xx *dev)
861 /* u32 input = INPUT(dev->video_input)->vmux; */
863 call_all(dev, video, s_stream, 1);
867 * cx231xx_realease_resources()
868 * unregisters the v4l2,i2c and usb devices
869 * called when the device gets disconected or at module unload
871 void cx231xx_release_resources(struct cx231xx *dev)
873 cx231xx_release_analog_resources(dev);
875 cx231xx_remove_from_devlist(dev);
877 cx231xx_ir_exit(dev);
879 /* Release I2C buses */
880 cx231xx_dev_uninit(dev);
882 /* delete v4l2 device */
883 v4l2_device_unregister(&dev->v4l2_dev);
885 usb_put_dev(dev->udev);
887 /* Mark device as unused */
888 clear_bit(dev->devno, &cx231xx_devused);
890 kfree(dev->video_mode.alt_max_pkt_size);
891 kfree(dev->vbi_mode.alt_max_pkt_size);
892 kfree(dev->sliced_cc_mode.alt_max_pkt_size);
893 kfree(dev->ts1_mode.alt_max_pkt_size);
899 * allocates and inits the device structs, registers i2c bus and v4l device
901 static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
904 int retval = -ENOMEM;
906 unsigned int maxh, maxw;
909 mutex_init(&dev->lock);
910 mutex_init(&dev->ctrl_urb_lock);
911 mutex_init(&dev->gpio_i2c_lock);
912 mutex_init(&dev->i2c_lock);
914 spin_lock_init(&dev->video_mode.slock);
915 spin_lock_init(&dev->vbi_mode.slock);
916 spin_lock_init(&dev->sliced_cc_mode.slock);
918 init_waitqueue_head(&dev->open);
919 init_waitqueue_head(&dev->wait_frame);
920 init_waitqueue_head(&dev->wait_stream);
922 dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg;
923 dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg;
924 dev->cx231xx_send_usb_command = cx231xx_send_usb_command;
925 dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read;
926 dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write;
928 /* Query cx231xx to find what pcb config it is related to */
929 initialize_cx231xx(dev);
931 /*To workaround error number=-71 on EP0 for VideoGrabber,
933 if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER ||
934 dev->model == CX231XX_BOARD_HAUPPAUGE_USBLIVE2) {
935 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
936 cx231xx_set_alt_setting(dev, INDEX_VANC, 1);
938 /* Cx231xx pre card setup */
939 cx231xx_pre_card_setup(dev);
941 errCode = cx231xx_config(dev);
943 cx231xx_errdev("error configuring device\n");
947 /* set default norm */
948 dev->norm = dev->board.norm;
950 /* register i2c bus */
951 errCode = cx231xx_dev_init(dev);
953 cx231xx_dev_uninit(dev);
954 cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
959 /* Do board specific init */
960 cx231xx_card_setup(dev);
962 /* configure the device */
963 cx231xx_config_i2c(dev);
965 maxw = norm_maxw(dev);
966 maxh = norm_maxh(dev);
968 /* set default image size */
972 dev->video_input = 0;
974 errCode = cx231xx_config(dev);
976 cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
981 /* init video dma queues */
982 INIT_LIST_HEAD(&dev->video_mode.vidq.active);
983 INIT_LIST_HEAD(&dev->video_mode.vidq.queued);
985 /* init vbi dma queues */
986 INIT_LIST_HEAD(&dev->vbi_mode.vidq.active);
987 INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued);
989 /* Reset other chips required if they are tied up with GPIO pins */
990 cx231xx_add_into_devlist(dev);
992 if (dev->board.has_417) {
993 printk(KERN_INFO "attach 417 %d\n", dev->model);
994 if (cx231xx_417_register(dev) < 0) {
996 "%s() Failed to register 417 on VID_B\n",
1001 retval = cx231xx_register_analog_devices(dev);
1003 cx231xx_release_resources(dev);
1007 cx231xx_ir_init(dev);
1009 cx231xx_init_extension(dev);
1014 #if defined(CONFIG_MODULES) && defined(MODULE)
1015 static void request_module_async(struct work_struct *work)
1017 struct cx231xx *dev = container_of(work,
1018 struct cx231xx, request_module_wk);
1020 if (dev->has_alsa_audio)
1021 request_module("cx231xx-alsa");
1023 if (dev->board.has_dvb)
1024 request_module("cx231xx-dvb");
1028 static void request_modules(struct cx231xx *dev)
1030 INIT_WORK(&dev->request_module_wk, request_module_async);
1031 schedule_work(&dev->request_module_wk);
1034 static void flush_request_modules(struct cx231xx *dev)
1036 flush_work(&dev->request_module_wk);
1039 #define request_modules(dev)
1040 #define flush_request_modules(dev)
1041 #endif /* CONFIG_MODULES */
1044 * cx231xx_usb_probe()
1045 * checks for supported devices
1047 static int cx231xx_usb_probe(struct usb_interface *interface,
1048 const struct usb_device_id *id)
1050 struct usb_device *udev;
1051 struct usb_interface *uif;
1052 struct cx231xx *dev = NULL;
1053 int retval = -ENODEV;
1055 int i, isoc_pipe = 0;
1057 struct usb_interface_assoc_descriptor *assoc_desc;
1059 udev = usb_get_dev(interface_to_usbdev(interface));
1060 ifnum = interface->altsetting[0].desc.bInterfaceNumber;
1063 * Interface number 0 - IR interface (handled by mceusb driver)
1064 * Interface number 1 - AV interface (handled by this driver)
1069 /* Check to see next free device and mark as used */
1071 nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
1072 if (nr >= CX231XX_MAXBOARDS) {
1073 /* No free device slots */
1074 cx231xx_err(DRIVER_NAME ": Supports only %i devices.\n",
1078 } while (test_and_set_bit(nr, &cx231xx_devused));
1080 /* allocate memory for our device state and initialize it */
1081 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1083 cx231xx_err(DRIVER_NAME ": out of memory!\n");
1084 clear_bit(nr, &cx231xx_devused);
1088 snprintf(dev->name, 29, "cx231xx #%d", nr);
1090 dev->model = id->driver_info;
1091 dev->video_mode.alt = -1;
1093 dev->interface_count++;
1094 /* reset gpio dir and value */
1097 dev->xc_fw_load_done = 0;
1098 dev->has_alsa_audio = 1;
1099 dev->power_mode = -1;
1100 atomic_set(&dev->devlist_count, 0);
1102 /* 0 - vbi ; 1 -sliced cc mode */
1103 dev->vbi_or_sliced_cc_mode = 0;
1105 /* get maximum no.of IAD interfaces */
1106 assoc_desc = udev->actconfig->intf_assoc[0];
1107 dev->max_iad_interface_count = assoc_desc->bInterfaceCount;
1109 /* init CIR module TBD */
1111 /*mode_tv: digital=1 or analog=0*/
1114 dev->USE_ISO = transfer_mode;
1116 switch (udev->speed) {
1120 case USB_SPEED_UNKNOWN:
1121 case USB_SPEED_FULL:
1124 case USB_SPEED_HIGH:
1131 cx231xx_info("New device %s %s @ %s Mbps "
1132 "(%04x:%04x) with %d interfaces\n",
1133 udev->manufacturer ? udev->manufacturer : "",
1134 udev->product ? udev->product : "",
1136 le16_to_cpu(udev->descriptor.idVendor),
1137 le16_to_cpu(udev->descriptor.idProduct),
1138 dev->max_iad_interface_count);
1140 /* increment interface count */
1141 dev->interface_count++;
1143 /* get device number */
1146 assoc_desc = udev->actconfig->intf_assoc[0];
1147 if (assoc_desc->bFirstInterface != ifnum) {
1148 cx231xx_err(DRIVER_NAME ": Not found "
1149 "matching IAD interface\n");
1150 clear_bit(dev->devno, &cx231xx_devused);
1156 cx231xx_info("registering interface %d\n", ifnum);
1158 /* save our data pointer in this interface device */
1159 usb_set_intfdata(interface, dev);
1162 * AV device initialization - only done at the last interface
1165 /* Create v4l2 device */
1166 retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
1168 cx231xx_errdev("v4l2_device_register failed\n");
1169 clear_bit(dev->devno, &cx231xx_devused);
1174 /* allocate device struct */
1175 retval = cx231xx_init_dev(dev, udev, nr);
1177 clear_bit(dev->devno, &cx231xx_devused);
1178 v4l2_device_unregister(&dev->v4l2_dev);
1181 usb_set_intfdata(interface, NULL);
1186 /* compute alternate max packet sizes for video */
1187 uif = udev->actconfig->interface[dev->current_pcb_config.
1188 hs_config_info[0].interface_info.video_index + 1];
1190 dev->video_mode.end_point_addr = le16_to_cpu(uif->altsetting[0].
1191 endpoint[isoc_pipe].desc.bEndpointAddress);
1193 dev->video_mode.num_alt = uif->num_altsetting;
1194 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1195 dev->video_mode.end_point_addr,
1196 dev->video_mode.num_alt);
1197 dev->video_mode.alt_max_pkt_size =
1198 kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL);
1200 if (dev->video_mode.alt_max_pkt_size == NULL) {
1201 cx231xx_errdev("out of memory!\n");
1202 clear_bit(dev->devno, &cx231xx_devused);
1203 v4l2_device_unregister(&dev->v4l2_dev);
1209 for (i = 0; i < dev->video_mode.num_alt; i++) {
1210 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1211 desc.wMaxPacketSize);
1212 dev->video_mode.alt_max_pkt_size[i] =
1213 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1214 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1215 dev->video_mode.alt_max_pkt_size[i]);
1218 /* compute alternate max packet sizes for vbi */
1219 uif = udev->actconfig->interface[dev->current_pcb_config.
1220 hs_config_info[0].interface_info.
1223 dev->vbi_mode.end_point_addr =
1224 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
1227 dev->vbi_mode.num_alt = uif->num_altsetting;
1228 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1229 dev->vbi_mode.end_point_addr,
1230 dev->vbi_mode.num_alt);
1231 dev->vbi_mode.alt_max_pkt_size =
1232 kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL);
1234 if (dev->vbi_mode.alt_max_pkt_size == NULL) {
1235 cx231xx_errdev("out of memory!\n");
1236 clear_bit(dev->devno, &cx231xx_devused);
1237 v4l2_device_unregister(&dev->v4l2_dev);
1243 for (i = 0; i < dev->vbi_mode.num_alt; i++) {
1245 le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1246 desc.wMaxPacketSize);
1247 dev->vbi_mode.alt_max_pkt_size[i] =
1248 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1249 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1250 dev->vbi_mode.alt_max_pkt_size[i]);
1253 /* compute alternate max packet sizes for sliced CC */
1254 uif = udev->actconfig->interface[dev->current_pcb_config.
1255 hs_config_info[0].interface_info.
1258 dev->sliced_cc_mode.end_point_addr =
1259 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
1262 dev->sliced_cc_mode.num_alt = uif->num_altsetting;
1263 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1264 dev->sliced_cc_mode.end_point_addr,
1265 dev->sliced_cc_mode.num_alt);
1266 dev->sliced_cc_mode.alt_max_pkt_size =
1267 kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL);
1269 if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
1270 cx231xx_errdev("out of memory!\n");
1271 clear_bit(dev->devno, &cx231xx_devused);
1272 v4l2_device_unregister(&dev->v4l2_dev);
1278 for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
1279 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1280 desc.wMaxPacketSize);
1281 dev->sliced_cc_mode.alt_max_pkt_size[i] =
1282 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1283 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1284 dev->sliced_cc_mode.alt_max_pkt_size[i]);
1287 if (dev->current_pcb_config.ts1_source != 0xff) {
1288 /* compute alternate max packet sizes for TS1 */
1289 uif = udev->actconfig->interface[dev->current_pcb_config.
1294 dev->ts1_mode.end_point_addr =
1295 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].
1296 desc.bEndpointAddress);
1298 dev->ts1_mode.num_alt = uif->num_altsetting;
1299 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1300 dev->ts1_mode.end_point_addr,
1301 dev->ts1_mode.num_alt);
1302 dev->ts1_mode.alt_max_pkt_size =
1303 kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL);
1305 if (dev->ts1_mode.alt_max_pkt_size == NULL) {
1306 cx231xx_errdev("out of memory!\n");
1307 clear_bit(dev->devno, &cx231xx_devused);
1308 v4l2_device_unregister(&dev->v4l2_dev);
1314 for (i = 0; i < dev->ts1_mode.num_alt; i++) {
1315 u16 tmp = le16_to_cpu(uif->altsetting[i].
1316 endpoint[isoc_pipe].desc.
1318 dev->ts1_mode.alt_max_pkt_size[i] =
1319 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1320 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1321 dev->ts1_mode.alt_max_pkt_size[i]);
1325 if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) {
1326 cx231xx_enable_OSC(dev);
1327 cx231xx_reset_out(dev);
1328 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
1331 if (dev->model == CX231XX_BOARD_CNXT_RDE_253S)
1332 cx231xx_sleep_s5h1432(dev);
1334 /* load other modules required */
1335 request_modules(dev);
1341 * cx231xx_usb_disconnect()
1342 * called when the device gets diconencted
1343 * video device will be unregistered on v4l2_close in case it is still open
1345 static void cx231xx_usb_disconnect(struct usb_interface *interface)
1347 struct cx231xx *dev;
1349 dev = usb_get_intfdata(interface);
1350 usb_set_intfdata(interface, NULL);
1358 dev->state |= DEV_DISCONNECTED;
1360 flush_request_modules(dev);
1362 /* wait until all current v4l2 io is finished then deallocate
1364 mutex_lock(&dev->lock);
1366 wake_up_interruptible_all(&dev->open);
1370 ("device %s is open! Deregistration and memory "
1371 "deallocation are deferred on close.\n",
1372 video_device_node_name(dev->vdev));
1374 /* Even having users, it is safe to remove the RC i2c driver */
1375 cx231xx_ir_exit(dev);
1378 cx231xx_uninit_isoc(dev);
1380 cx231xx_uninit_bulk(dev);
1381 wake_up_interruptible(&dev->wait_frame);
1382 wake_up_interruptible(&dev->wait_stream);
1386 cx231xx_close_extension(dev);
1388 mutex_unlock(&dev->lock);
1391 cx231xx_release_resources(dev);
1394 static struct usb_driver cx231xx_usb_driver = {
1396 .probe = cx231xx_usb_probe,
1397 .disconnect = cx231xx_usb_disconnect,
1398 .id_table = cx231xx_id_table,
1401 module_usb_driver(cx231xx_usb_driver);