1 /* 2 cx231xx-cards.c - driver for Conexant Cx23100/101/102 3 USB video capture devices 4 5 Copyright (C) 2008 <srinivasa.deevi at conexant dot com> 6 Based on em28xx driver 7 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. 12 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. 17 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. 21 */ 22 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> 33 34 #include <media/cx25840.h> 35 #include "dvb-usb-ids.h" 36 #include "xc5000.h" 37 #include "tda18271.h" 38 39 #include "cx231xx.h" 40 41 static int tuner = -1; 42 module_param(tuner, int, 0444); 43 MODULE_PARM_DESC(tuner, "tuner type"); 44 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)"); 48 49 static unsigned int disable_ir; 50 module_param(disable_ir, int, 0444); 51 MODULE_PARM_DESC(disable_ir, "disable infrared remote support"); 52 53 /* Bitmask marking allocated devices from 0 to CX231XX_MAXBOARDS */ 54 static unsigned long cx231xx_devused; 55 56 /* 57 * Reset sequences for analog/digital modes 58 */ 59 60 static struct cx231xx_reg_seq RDE250_XCV_TUNER[] = { 61 {0x03, 0x01, 10}, 62 {0x03, 0x00, 30}, 63 {0x03, 0x01, 10}, 64 {-1, -1, -1}, 65 }; 66 67 /* 68 * Board definitions 69 */ 70 struct cx231xx_board cx231xx_boards[] = { 71 [CX231XX_BOARD_UNKNOWN] = { 72 .name = "Unknown CX231xx video grabber", 73 .tuner_type = TUNER_ABSENT, 74 .input = {{ 75 .type = CX231XX_VMUX_TELEVISION, 76 .vmux = CX231XX_VIN_3_1, 77 .amux = CX231XX_AMUX_VIDEO, 78 .gpio = NULL, 79 }, { 80 .type = CX231XX_VMUX_COMPOSITE1, 81 .vmux = CX231XX_VIN_2_1, 82 .amux = CX231XX_AMUX_LINE_IN, 83 .gpio = NULL, 84 }, { 85 .type = CX231XX_VMUX_SVIDEO, 86 .vmux = CX231XX_VIN_1_1 | 87 (CX231XX_VIN_1_2 << 8) | 88 CX25840_SVIDEO_ON, 89 .amux = CX231XX_AMUX_LINE_IN, 90 .gpio = NULL, 91 } 92 }, 93 }, 94 [CX231XX_BOARD_CNXT_CARRAERA] = { 95 .name = "Conexant Hybrid TV - CARRAERA", 96 .tuner_type = TUNER_XC5000, 97 .tuner_addr = 0x61, 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, 110 .has_dvb = 1, 111 .demod_addr = 0x02, 112 .norm = V4L2_STD_PAL, 113 114 .input = {{ 115 .type = CX231XX_VMUX_TELEVISION, 116 .vmux = CX231XX_VIN_3_1, 117 .amux = CX231XX_AMUX_VIDEO, 118 .gpio = NULL, 119 }, { 120 .type = CX231XX_VMUX_COMPOSITE1, 121 .vmux = CX231XX_VIN_2_1, 122 .amux = CX231XX_AMUX_LINE_IN, 123 .gpio = NULL, 124 }, { 125 .type = CX231XX_VMUX_SVIDEO, 126 .vmux = CX231XX_VIN_1_1 | 127 (CX231XX_VIN_1_2 << 8) | 128 CX25840_SVIDEO_ON, 129 .amux = CX231XX_AMUX_LINE_IN, 130 .gpio = NULL, 131 } 132 }, 133 }, 134 [CX231XX_BOARD_CNXT_SHELBY] = { 135 .name = "Conexant Hybrid TV - SHELBY", 136 .tuner_type = TUNER_XC5000, 137 .tuner_addr = 0x61, 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, 150 .has_dvb = 1, 151 .demod_addr = 0x32, 152 .norm = V4L2_STD_NTSC, 153 154 .input = {{ 155 .type = CX231XX_VMUX_TELEVISION, 156 .vmux = CX231XX_VIN_3_1, 157 .amux = CX231XX_AMUX_VIDEO, 158 .gpio = NULL, 159 }, { 160 .type = CX231XX_VMUX_COMPOSITE1, 161 .vmux = CX231XX_VIN_2_1, 162 .amux = CX231XX_AMUX_LINE_IN, 163 .gpio = NULL, 164 }, { 165 .type = CX231XX_VMUX_SVIDEO, 166 .vmux = CX231XX_VIN_1_1 | 167 (CX231XX_VIN_1_2 << 8) | 168 CX25840_SVIDEO_ON, 169 .amux = CX231XX_AMUX_LINE_IN, 170 .gpio = NULL, 171 } 172 }, 173 }, 174 [CX231XX_BOARD_CNXT_RDE_253S] = { 175 .name = "Conexant Hybrid TV - RDE253S", 176 .tuner_type = TUNER_NXP_TDA18271, 177 .tuner_addr = 0x60, 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, 190 .has_dvb = 1, 191 .demod_addr = 0x02, 192 .norm = V4L2_STD_PAL, 193 194 .input = {{ 195 .type = CX231XX_VMUX_TELEVISION, 196 .vmux = CX231XX_VIN_3_1, 197 .amux = CX231XX_AMUX_VIDEO, 198 .gpio = NULL, 199 }, { 200 .type = CX231XX_VMUX_COMPOSITE1, 201 .vmux = CX231XX_VIN_2_1, 202 .amux = CX231XX_AMUX_LINE_IN, 203 .gpio = NULL, 204 }, { 205 .type = CX231XX_VMUX_SVIDEO, 206 .vmux = CX231XX_VIN_1_1 | 207 (CX231XX_VIN_1_2 << 8) | 208 CX25840_SVIDEO_ON, 209 .amux = CX231XX_AMUX_LINE_IN, 210 .gpio = NULL, 211 } 212 }, 213 }, 214 215 [CX231XX_BOARD_CNXT_RDU_253S] = { 216 .name = "Conexant Hybrid TV - RDU253S", 217 .tuner_type = TUNER_NXP_TDA18271, 218 .tuner_addr = 0x60, 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, 231 .has_dvb = 1, 232 .demod_addr = 0x02, 233 .norm = V4L2_STD_PAL, 234 235 .input = {{ 236 .type = CX231XX_VMUX_TELEVISION, 237 .vmux = CX231XX_VIN_3_1, 238 .amux = CX231XX_AMUX_VIDEO, 239 .gpio = NULL, 240 }, { 241 .type = CX231XX_VMUX_COMPOSITE1, 242 .vmux = CX231XX_VIN_2_1, 243 .amux = CX231XX_AMUX_LINE_IN, 244 .gpio = NULL, 245 }, { 246 .type = CX231XX_VMUX_SVIDEO, 247 .vmux = CX231XX_VIN_1_1 | 248 (CX231XX_VIN_1_2 << 8) | 249 CX25840_SVIDEO_ON, 250 .amux = CX231XX_AMUX_LINE_IN, 251 .gpio = NULL, 252 } 253 }, 254 }, 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, 264 .no_alt_vanc = 1, 265 .external_av = 1, 266 .has_417 = 1, 267 268 .input = {{ 269 .type = CX231XX_VMUX_COMPOSITE1, 270 .vmux = CX231XX_VIN_2_1, 271 .amux = CX231XX_AMUX_LINE_IN, 272 .gpio = NULL, 273 }, { 274 .type = CX231XX_VMUX_SVIDEO, 275 .vmux = CX231XX_VIN_1_1 | 276 (CX231XX_VIN_1_2 << 8) | 277 CX25840_SVIDEO_ON, 278 .amux = CX231XX_AMUX_LINE_IN, 279 .gpio = NULL, 280 } 281 }, 282 }, 283 [CX231XX_BOARD_CNXT_RDE_250] = { 284 .name = "Conexant Hybrid TV - rde 250", 285 .tuner_type = TUNER_XC5000, 286 .tuner_addr = 0x61, 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, 299 .has_dvb = 1, 300 .demod_addr = 0x02, 301 .norm = V4L2_STD_PAL, 302 303 .input = {{ 304 .type = CX231XX_VMUX_TELEVISION, 305 .vmux = CX231XX_VIN_2_1, 306 .amux = CX231XX_AMUX_VIDEO, 307 .gpio = NULL, 308 } 309 }, 310 }, 311 [CX231XX_BOARD_CNXT_RDU_250] = { 312 .name = "Conexant Hybrid TV - RDU 250", 313 .tuner_type = TUNER_XC5000, 314 .tuner_addr = 0x61, 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, 327 .has_dvb = 1, 328 .demod_addr = 0x32, 329 .norm = V4L2_STD_NTSC, 330 331 .input = {{ 332 .type = CX231XX_VMUX_TELEVISION, 333 .vmux = CX231XX_VIN_2_1, 334 .amux = CX231XX_AMUX_VIDEO, 335 .gpio = NULL, 336 } 337 }, 338 }, 339 [CX231XX_BOARD_HAUPPAUGE_EXETER] = { 340 .name = "Hauppauge EXETER", 341 .tuner_type = TUNER_NXP_TDA18271, 342 .tuner_addr = 0x60, 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, 355 .has_dvb = 1, 356 .demod_addr = 0x0e, 357 .norm = V4L2_STD_NTSC, 358 359 .input = {{ 360 .type = CX231XX_VMUX_TELEVISION, 361 .vmux = CX231XX_VIN_3_1, 362 .amux = CX231XX_AMUX_VIDEO, 363 .gpio = NULL, 364 }, { 365 .type = CX231XX_VMUX_COMPOSITE1, 366 .vmux = CX231XX_VIN_2_1, 367 .amux = CX231XX_AMUX_LINE_IN, 368 .gpio = NULL, 369 }, { 370 .type = CX231XX_VMUX_SVIDEO, 371 .vmux = CX231XX_VIN_1_1 | 372 (CX231XX_VIN_1_2 << 8) | 373 CX25840_SVIDEO_ON, 374 .amux = CX231XX_AMUX_LINE_IN, 375 .gpio = NULL, 376 } }, 377 }, 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, 388 .no_alt_vanc = 1, 389 .external_av = 1, 390 .dont_use_port_3 = 1, 391 .input = {{ 392 .type = CX231XX_VMUX_COMPOSITE1, 393 .vmux = CX231XX_VIN_2_1, 394 .amux = CX231XX_AMUX_LINE_IN, 395 .gpio = NULL, 396 }, { 397 .type = CX231XX_VMUX_SVIDEO, 398 .vmux = CX231XX_VIN_1_1 | 399 (CX231XX_VIN_1_2 << 8) | 400 CX25840_SVIDEO_ON, 401 .amux = CX231XX_AMUX_LINE_IN, 402 .gpio = NULL, 403 } }, 404 }, 405 [CX231XX_BOARD_KWORLD_UB430_USB_HYBRID] = { 406 .name = "Kworld UB430 USB Hybrid", 407 .tuner_type = TUNER_NXP_TDA18271, 408 .tuner_addr = 0x60, 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, 420 .ir_i2c_master = 2, 421 .has_dvb = 1, 422 .demod_addr = 0x10, 423 .norm = V4L2_STD_PAL_M, 424 .input = {{ 425 .type = CX231XX_VMUX_TELEVISION, 426 .vmux = CX231XX_VIN_3_1, 427 .amux = CX231XX_AMUX_VIDEO, 428 .gpio = NULL, 429 }, { 430 .type = CX231XX_VMUX_COMPOSITE1, 431 .vmux = CX231XX_VIN_2_1, 432 .amux = CX231XX_AMUX_LINE_IN, 433 .gpio = NULL, 434 }, { 435 .type = CX231XX_VMUX_SVIDEO, 436 .vmux = CX231XX_VIN_1_1 | 437 (CX231XX_VIN_1_2 << 8) | 438 CX25840_SVIDEO_ON, 439 .amux = CX231XX_AMUX_LINE_IN, 440 .gpio = NULL, 441 } }, 442 }, 443 [CX231XX_BOARD_PV_PLAYTV_USB_HYBRID] = { 444 .name = "Pixelview PlayTV USB Hybrid", 445 .tuner_type = TUNER_NXP_TDA18271, 446 .tuner_addr = 0x60, 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, 458 .ir_i2c_master = 2, 459 .rc_map_name = RC_MAP_PIXELVIEW_002T, 460 .has_dvb = 1, 461 .demod_addr = 0x10, 462 .norm = V4L2_STD_PAL_M, 463 .input = {{ 464 .type = CX231XX_VMUX_TELEVISION, 465 .vmux = CX231XX_VIN_3_1, 466 .amux = CX231XX_AMUX_VIDEO, 467 .gpio = NULL, 468 }, { 469 .type = CX231XX_VMUX_COMPOSITE1, 470 .vmux = CX231XX_VIN_2_1, 471 .amux = CX231XX_AMUX_LINE_IN, 472 .gpio = NULL, 473 }, { 474 .type = CX231XX_VMUX_SVIDEO, 475 .vmux = CX231XX_VIN_1_1 | 476 (CX231XX_VIN_1_2 << 8) | 477 CX25840_SVIDEO_ON, 478 .amux = CX231XX_AMUX_LINE_IN, 479 .gpio = NULL, 480 } }, 481 }, 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, 492 .no_alt_vanc = 1, 493 .external_av = 1, 494 .dont_use_port_3 = 1, 495 496 .input = {{ 497 .type = CX231XX_VMUX_COMPOSITE1, 498 .vmux = CX231XX_VIN_2_1, 499 .amux = CX231XX_AMUX_LINE_IN, 500 .gpio = NULL, 501 }, { 502 .type = CX231XX_VMUX_SVIDEO, 503 .vmux = CX231XX_VIN_1_1 | 504 (CX231XX_VIN_1_2 << 8) | 505 CX25840_SVIDEO_ON, 506 .amux = CX231XX_AMUX_LINE_IN, 507 .gpio = NULL, 508 } 509 }, 510 }, 511 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, 521 522 .input = {{ 523 .type = CX231XX_VMUX_COMPOSITE1, 524 .vmux = CX231XX_VIN_2_1, 525 .amux = CX231XX_AMUX_LINE_IN, 526 .gpio = NULL, 527 }, { 528 .type = CX231XX_VMUX_SVIDEO, 529 .vmux = CX231XX_VIN_1_1 | 530 (CX231XX_VIN_1_2 << 8) | 531 CX25840_SVIDEO_ON, 532 .amux = CX231XX_AMUX_LINE_IN, 533 .gpio = NULL, 534 } }, 535 }, 536 [CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL] = { 537 .name = "Hauppauge WinTV USB2 FM (PAL)", 538 .tuner_type = TUNER_NXP_TDA18271, 539 .tuner_addr = 0x60, 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, 551 552 .input = {{ 553 .type = CX231XX_VMUX_TELEVISION, 554 .vmux = CX231XX_VIN_3_1, 555 .amux = CX231XX_AMUX_VIDEO, 556 .gpio = NULL, 557 }, { 558 .type = CX231XX_VMUX_COMPOSITE1, 559 .vmux = CX231XX_VIN_2_1, 560 .amux = CX231XX_AMUX_LINE_IN, 561 .gpio = NULL, 562 }, { 563 .type = CX231XX_VMUX_SVIDEO, 564 .vmux = CX231XX_VIN_1_1 | 565 (CX231XX_VIN_1_2 << 8) | 566 CX25840_SVIDEO_ON, 567 .amux = CX231XX_AMUX_LINE_IN, 568 .gpio = NULL, 569 } }, 570 }, 571 [CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC] = { 572 .name = "Hauppauge WinTV USB2 FM (NTSC)", 573 .tuner_type = TUNER_NXP_TDA18271, 574 .tuner_addr = 0x60, 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, 586 587 .input = {{ 588 .type = CX231XX_VMUX_TELEVISION, 589 .vmux = CX231XX_VIN_3_1, 590 .amux = CX231XX_AMUX_VIDEO, 591 .gpio = NULL, 592 }, { 593 .type = CX231XX_VMUX_COMPOSITE1, 594 .vmux = CX231XX_VIN_2_1, 595 .amux = CX231XX_AMUX_LINE_IN, 596 .gpio = NULL, 597 }, { 598 .type = CX231XX_VMUX_SVIDEO, 599 .vmux = CX231XX_VIN_1_1 | 600 (CX231XX_VIN_1_2 << 8) | 601 CX25840_SVIDEO_ON, 602 .amux = CX231XX_AMUX_LINE_IN, 603 .gpio = NULL, 604 } }, 605 }, 606 }; 607 const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards); 608 609 /* table of devices that work with this driver */ 610 struct usb_device_id cx231xx_id_table[] = { 611 {USB_DEVICE(0x0572, 0x5A3C), 612 .driver_info = CX231XX_BOARD_UNKNOWN}, 613 {USB_DEVICE(0x0572, 0x58A2), 614 .driver_info = CX231XX_BOARD_CNXT_CARRAERA}, 615 {USB_DEVICE(0x0572, 0x58A1), 616 .driver_info = CX231XX_BOARD_CNXT_SHELBY}, 617 {USB_DEVICE(0x0572, 0x58A4), 618 .driver_info = CX231XX_BOARD_CNXT_RDE_253S}, 619 {USB_DEVICE(0x0572, 0x58A5), 620 .driver_info = CX231XX_BOARD_CNXT_RDU_253S}, 621 {USB_DEVICE(0x0572, 0x58A6), 622 .driver_info = CX231XX_BOARD_CNXT_VIDEO_GRABBER}, 623 {USB_DEVICE(0x0572, 0x589E), 624 .driver_info = CX231XX_BOARD_CNXT_RDE_250}, 625 {USB_DEVICE(0x0572, 0x58A0), 626 .driver_info = CX231XX_BOARD_CNXT_RDU_250}, 627 {USB_DEVICE(0x2040, 0xb110), 628 .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL}, 629 {USB_DEVICE(0x2040, 0xb111), 630 .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC}, 631 {USB_DEVICE(0x2040, 0xb120), 632 .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER}, 633 {USB_DEVICE(0x2040, 0xb140), 634 .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER}, 635 {USB_DEVICE(0x2040, 0xc200), 636 .driver_info = CX231XX_BOARD_HAUPPAUGE_USBLIVE2}, 637 {USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x4000, 0x4001), 638 .driver_info = CX231XX_BOARD_PV_PLAYTV_USB_HYBRID}, 639 {USB_DEVICE(USB_VID_PIXELVIEW, 0x5014), 640 .driver_info = CX231XX_BOARD_PV_XCAPTURE_USB}, 641 {USB_DEVICE(0x1b80, 0xe424), 642 .driver_info = CX231XX_BOARD_KWORLD_UB430_USB_HYBRID}, 643 {USB_DEVICE(0x1f4d, 0x0237), 644 .driver_info = CX231XX_BOARD_ICONBIT_U100}, 645 {}, 646 }; 647 648 MODULE_DEVICE_TABLE(usb, cx231xx_id_table); 649 650 /* cx231xx_tuner_callback 651 * will be used to reset XC5000 tuner using GPIO pin 652 */ 653 654 int cx231xx_tuner_callback(void *ptr, int component, int command, int arg) 655 { 656 int rc = 0; 657 struct cx231xx *dev = ptr; 658 659 if (dev->tuner_type == TUNER_XC5000) { 660 if (command == XC5000_TUNER_RESET) { 661 cx231xx_info 662 ("Tuner CB: RESET: cmd %d : tuner type %d \n", 663 command, dev->tuner_type); 664 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 665 1); 666 msleep(10); 667 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 668 0); 669 msleep(330); 670 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 671 1); 672 msleep(10); 673 } 674 } else if (dev->tuner_type == TUNER_NXP_TDA18271) { 675 switch (command) { 676 case TDA18271_CALLBACK_CMD_AGC_ENABLE: 677 if (dev->model == CX231XX_BOARD_PV_PLAYTV_USB_HYBRID) 678 rc = cx231xx_set_agc_analog_digital_mux_select(dev, arg); 679 break; 680 default: 681 rc = -EINVAL; 682 break; 683 } 684 } 685 return rc; 686 } 687 EXPORT_SYMBOL_GPL(cx231xx_tuner_callback); 688 689 static void cx231xx_reset_out(struct cx231xx *dev) 690 { 691 cx231xx_set_gpio_value(dev, CX23417_RESET, 1); 692 msleep(200); 693 cx231xx_set_gpio_value(dev, CX23417_RESET, 0); 694 msleep(200); 695 cx231xx_set_gpio_value(dev, CX23417_RESET, 1); 696 } 697 698 static void cx231xx_enable_OSC(struct cx231xx *dev) 699 { 700 cx231xx_set_gpio_value(dev, CX23417_OSC_EN, 1); 701 } 702 703 static void cx231xx_sleep_s5h1432(struct cx231xx *dev) 704 { 705 cx231xx_set_gpio_value(dev, SLEEP_S5H1432, 0); 706 } 707 708 static inline void cx231xx_set_model(struct cx231xx *dev) 709 { 710 memcpy(&dev->board, &cx231xx_boards[dev->model], sizeof(dev->board)); 711 } 712 713 /* Since cx231xx_pre_card_setup() requires a proper dev->model, 714 * this won't work for boards with generic PCI IDs 715 */ 716 void cx231xx_pre_card_setup(struct cx231xx *dev) 717 { 718 719 cx231xx_set_model(dev); 720 721 cx231xx_info("Identified as %s (card=%d)\n", 722 dev->board.name, dev->model); 723 724 /* set the direction for GPIO pins */ 725 if (dev->board.tuner_gpio) { 726 cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1); 727 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1); 728 } 729 if (dev->board.tuner_sif_gpio >= 0) 730 cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1); 731 732 /* request some modules if any required */ 733 734 /* set the mode to Analog mode initially */ 735 cx231xx_set_mode(dev, CX231XX_ANALOG_MODE); 736 737 /* Unlock device */ 738 /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */ 739 740 } 741 742 static void cx231xx_config_tuner(struct cx231xx *dev) 743 { 744 struct tuner_setup tun_setup; 745 struct v4l2_frequency f; 746 747 if (dev->tuner_type == TUNER_ABSENT) 748 return; 749 750 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO; 751 tun_setup.type = dev->tuner_type; 752 tun_setup.addr = dev->tuner_addr; 753 tun_setup.tuner_callback = cx231xx_tuner_callback; 754 755 tuner_call(dev, tuner, s_type_addr, &tun_setup); 756 757 #if 0 758 if (tun_setup.type == TUNER_XC5000) { 759 static struct xc2028_ctrl ctrl = { 760 .fname = XC5000_DEFAULT_FIRMWARE, 761 .max_len = 64, 762 .demod = 0; 763 }; 764 struct v4l2_priv_tun_config cfg = { 765 .tuner = dev->tuner_type, 766 .priv = &ctrl, 767 }; 768 tuner_call(dev, tuner, s_config, &cfg); 769 } 770 #endif 771 /* configure tuner */ 772 f.tuner = 0; 773 f.type = V4L2_TUNER_ANALOG_TV; 774 f.frequency = 9076; /* just a magic number */ 775 dev->ctl_freq = f.frequency; 776 call_all(dev, tuner, s_frequency, &f); 777 778 } 779 780 void cx231xx_card_setup(struct cx231xx *dev) 781 { 782 783 cx231xx_set_model(dev); 784 785 dev->tuner_type = cx231xx_boards[dev->model].tuner_type; 786 if (cx231xx_boards[dev->model].tuner_addr) 787 dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr; 788 789 /* request some modules */ 790 if (dev->board.decoder == CX231XX_AVDECODER) { 791 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev, 792 &dev->i2c_bus[0].i2c_adap, 793 "cx25840", 0x88 >> 1, NULL); 794 if (dev->sd_cx25840 == NULL) 795 cx231xx_info("cx25840 subdev registration failure\n"); 796 cx25840_call(dev, core, load_fw); 797 798 } 799 800 /* Initialize the tuner */ 801 if (dev->board.tuner_type != TUNER_ABSENT) { 802 dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev, 803 &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap, 804 "tuner", 805 dev->tuner_addr, NULL); 806 if (dev->sd_tuner == NULL) 807 cx231xx_info("tuner subdev registration failure\n"); 808 else 809 cx231xx_config_tuner(dev); 810 } 811 } 812 813 /* 814 * cx231xx_config() 815 * inits registers with sane defaults 816 */ 817 int cx231xx_config(struct cx231xx *dev) 818 { 819 /* TBD need to add cx231xx specific code */ 820 dev->mute = 1; /* maybe not the right place... */ 821 dev->volume = 0x1f; 822 823 return 0; 824 } 825 826 /* 827 * cx231xx_config_i2c() 828 * configure i2c attached devices 829 */ 830 void cx231xx_config_i2c(struct cx231xx *dev) 831 { 832 /* u32 input = INPUT(dev->video_input)->vmux; */ 833 834 call_all(dev, video, s_stream, 1); 835 } 836 837 /* 838 * cx231xx_realease_resources() 839 * unregisters the v4l2,i2c and usb devices 840 * called when the device gets disconected or at module unload 841 */ 842 void cx231xx_release_resources(struct cx231xx *dev) 843 { 844 cx231xx_release_analog_resources(dev); 845 846 cx231xx_remove_from_devlist(dev); 847 848 cx231xx_ir_exit(dev); 849 850 /* Release I2C buses */ 851 cx231xx_dev_uninit(dev); 852 853 /* delete v4l2 device */ 854 v4l2_device_unregister(&dev->v4l2_dev); 855 856 usb_put_dev(dev->udev); 857 858 /* Mark device as unused */ 859 clear_bit(dev->devno, &cx231xx_devused); 860 861 kfree(dev->video_mode.alt_max_pkt_size); 862 kfree(dev->vbi_mode.alt_max_pkt_size); 863 kfree(dev->sliced_cc_mode.alt_max_pkt_size); 864 kfree(dev->ts1_mode.alt_max_pkt_size); 865 kfree(dev); 866 } 867 868 /* 869 * cx231xx_init_dev() 870 * allocates and inits the device structs, registers i2c bus and v4l device 871 */ 872 static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev, 873 int minor) 874 { 875 int retval = -ENOMEM; 876 int errCode; 877 unsigned int maxh, maxw; 878 879 dev->udev = udev; 880 mutex_init(&dev->lock); 881 mutex_init(&dev->ctrl_urb_lock); 882 mutex_init(&dev->gpio_i2c_lock); 883 mutex_init(&dev->i2c_lock); 884 885 spin_lock_init(&dev->video_mode.slock); 886 spin_lock_init(&dev->vbi_mode.slock); 887 spin_lock_init(&dev->sliced_cc_mode.slock); 888 889 init_waitqueue_head(&dev->open); 890 init_waitqueue_head(&dev->wait_frame); 891 init_waitqueue_head(&dev->wait_stream); 892 893 dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg; 894 dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg; 895 dev->cx231xx_send_usb_command = cx231xx_send_usb_command; 896 dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read; 897 dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write; 898 899 /* Query cx231xx to find what pcb config it is related to */ 900 initialize_cx231xx(dev); 901 902 /*To workaround error number=-71 on EP0 for VideoGrabber, 903 need set alt here.*/ 904 if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER || 905 dev->model == CX231XX_BOARD_HAUPPAUGE_USBLIVE2) { 906 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3); 907 cx231xx_set_alt_setting(dev, INDEX_VANC, 1); 908 } 909 /* Cx231xx pre card setup */ 910 cx231xx_pre_card_setup(dev); 911 912 errCode = cx231xx_config(dev); 913 if (errCode) { 914 cx231xx_errdev("error configuring device\n"); 915 return -ENOMEM; 916 } 917 918 /* set default norm */ 919 dev->norm = dev->board.norm; 920 921 /* register i2c bus */ 922 errCode = cx231xx_dev_init(dev); 923 if (errCode < 0) { 924 cx231xx_dev_uninit(dev); 925 cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n", 926 __func__, errCode); 927 return errCode; 928 } 929 930 /* Do board specific init */ 931 cx231xx_card_setup(dev); 932 933 /* configure the device */ 934 cx231xx_config_i2c(dev); 935 936 maxw = norm_maxw(dev); 937 maxh = norm_maxh(dev); 938 939 /* set default image size */ 940 dev->width = maxw; 941 dev->height = maxh; 942 dev->interlaced = 0; 943 dev->video_input = 0; 944 945 errCode = cx231xx_config(dev); 946 if (errCode < 0) { 947 cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n", 948 __func__, errCode); 949 return errCode; 950 } 951 952 /* init video dma queues */ 953 INIT_LIST_HEAD(&dev->video_mode.vidq.active); 954 INIT_LIST_HEAD(&dev->video_mode.vidq.queued); 955 956 /* init vbi dma queues */ 957 INIT_LIST_HEAD(&dev->vbi_mode.vidq.active); 958 INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued); 959 960 /* Reset other chips required if they are tied up with GPIO pins */ 961 cx231xx_add_into_devlist(dev); 962 963 if (dev->board.has_417) { 964 printk(KERN_INFO "attach 417 %d\n", dev->model); 965 if (cx231xx_417_register(dev) < 0) { 966 printk(KERN_ERR 967 "%s() Failed to register 417 on VID_B\n", 968 __func__); 969 } 970 } 971 972 retval = cx231xx_register_analog_devices(dev); 973 if (retval < 0) { 974 cx231xx_release_resources(dev); 975 return retval; 976 } 977 978 cx231xx_ir_init(dev); 979 980 cx231xx_init_extension(dev); 981 982 return 0; 983 } 984 985 #if defined(CONFIG_MODULES) && defined(MODULE) 986 static void request_module_async(struct work_struct *work) 987 { 988 struct cx231xx *dev = container_of(work, 989 struct cx231xx, request_module_wk); 990 991 if (dev->has_alsa_audio) 992 request_module("cx231xx-alsa"); 993 994 if (dev->board.has_dvb) 995 request_module("cx231xx-dvb"); 996 997 } 998 999 static void request_modules(struct cx231xx *dev) 1000 { 1001 INIT_WORK(&dev->request_module_wk, request_module_async); 1002 schedule_work(&dev->request_module_wk); 1003 } 1004 1005 static void flush_request_modules(struct cx231xx *dev) 1006 { 1007 flush_work(&dev->request_module_wk); 1008 } 1009 #else 1010 #define request_modules(dev) 1011 #define flush_request_modules(dev) 1012 #endif /* CONFIG_MODULES */ 1013 1014 /* 1015 * cx231xx_usb_probe() 1016 * checks for supported devices 1017 */ 1018 static int cx231xx_usb_probe(struct usb_interface *interface, 1019 const struct usb_device_id *id) 1020 { 1021 struct usb_device *udev; 1022 struct usb_interface *uif; 1023 struct cx231xx *dev = NULL; 1024 int retval = -ENODEV; 1025 int nr = 0, ifnum; 1026 int i, isoc_pipe = 0; 1027 char *speed; 1028 struct usb_interface_assoc_descriptor *assoc_desc; 1029 1030 udev = usb_get_dev(interface_to_usbdev(interface)); 1031 ifnum = interface->altsetting[0].desc.bInterfaceNumber; 1032 1033 /* 1034 * Interface number 0 - IR interface (handled by mceusb driver) 1035 * Interface number 1 - AV interface (handled by this driver) 1036 */ 1037 if (ifnum != 1) 1038 return -ENODEV; 1039 1040 /* Check to see next free device and mark as used */ 1041 do { 1042 nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS); 1043 if (nr >= CX231XX_MAXBOARDS) { 1044 /* No free device slots */ 1045 cx231xx_err(DRIVER_NAME ": Supports only %i devices.\n", 1046 CX231XX_MAXBOARDS); 1047 return -ENOMEM; 1048 } 1049 } while (test_and_set_bit(nr, &cx231xx_devused)); 1050 1051 /* allocate memory for our device state and initialize it */ 1052 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 1053 if (dev == NULL) { 1054 cx231xx_err(DRIVER_NAME ": out of memory!\n"); 1055 clear_bit(nr, &cx231xx_devused); 1056 return -ENOMEM; 1057 } 1058 1059 snprintf(dev->name, 29, "cx231xx #%d", nr); 1060 dev->devno = nr; 1061 dev->model = id->driver_info; 1062 dev->video_mode.alt = -1; 1063 1064 dev->interface_count++; 1065 /* reset gpio dir and value */ 1066 dev->gpio_dir = 0; 1067 dev->gpio_val = 0; 1068 dev->xc_fw_load_done = 0; 1069 dev->has_alsa_audio = 1; 1070 dev->power_mode = -1; 1071 atomic_set(&dev->devlist_count, 0); 1072 1073 /* 0 - vbi ; 1 -sliced cc mode */ 1074 dev->vbi_or_sliced_cc_mode = 0; 1075 1076 /* get maximum no.of IAD interfaces */ 1077 assoc_desc = udev->actconfig->intf_assoc[0]; 1078 dev->max_iad_interface_count = assoc_desc->bInterfaceCount; 1079 1080 /* init CIR module TBD */ 1081 1082 /*mode_tv: digital=1 or analog=0*/ 1083 dev->mode_tv = 0; 1084 1085 dev->USE_ISO = transfer_mode; 1086 1087 switch (udev->speed) { 1088 case USB_SPEED_LOW: 1089 speed = "1.5"; 1090 break; 1091 case USB_SPEED_UNKNOWN: 1092 case USB_SPEED_FULL: 1093 speed = "12"; 1094 break; 1095 case USB_SPEED_HIGH: 1096 speed = "480"; 1097 break; 1098 default: 1099 speed = "unknown"; 1100 } 1101 1102 cx231xx_info("New device %s %s @ %s Mbps " 1103 "(%04x:%04x) with %d interfaces\n", 1104 udev->manufacturer ? udev->manufacturer : "", 1105 udev->product ? udev->product : "", 1106 speed, 1107 le16_to_cpu(udev->descriptor.idVendor), 1108 le16_to_cpu(udev->descriptor.idProduct), 1109 dev->max_iad_interface_count); 1110 1111 /* increment interface count */ 1112 dev->interface_count++; 1113 1114 /* get device number */ 1115 nr = dev->devno; 1116 1117 assoc_desc = udev->actconfig->intf_assoc[0]; 1118 if (assoc_desc->bFirstInterface != ifnum) { 1119 cx231xx_err(DRIVER_NAME ": Not found " 1120 "matching IAD interface\n"); 1121 clear_bit(dev->devno, &cx231xx_devused); 1122 kfree(dev); 1123 dev = NULL; 1124 return -ENODEV; 1125 } 1126 1127 cx231xx_info("registering interface %d\n", ifnum); 1128 1129 /* save our data pointer in this interface device */ 1130 usb_set_intfdata(interface, dev); 1131 1132 /* 1133 * AV device initialization - only done at the last interface 1134 */ 1135 1136 /* Create v4l2 device */ 1137 retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev); 1138 if (retval) { 1139 cx231xx_errdev("v4l2_device_register failed\n"); 1140 clear_bit(dev->devno, &cx231xx_devused); 1141 kfree(dev); 1142 dev = NULL; 1143 return -EIO; 1144 } 1145 /* allocate device struct */ 1146 retval = cx231xx_init_dev(dev, udev, nr); 1147 if (retval) { 1148 clear_bit(dev->devno, &cx231xx_devused); 1149 v4l2_device_unregister(&dev->v4l2_dev); 1150 kfree(dev); 1151 dev = NULL; 1152 usb_set_intfdata(interface, NULL); 1153 1154 return retval; 1155 } 1156 1157 /* compute alternate max packet sizes for video */ 1158 uif = udev->actconfig->interface[dev->current_pcb_config. 1159 hs_config_info[0].interface_info.video_index + 1]; 1160 1161 dev->video_mode.end_point_addr = le16_to_cpu(uif->altsetting[0]. 1162 endpoint[isoc_pipe].desc.bEndpointAddress); 1163 1164 dev->video_mode.num_alt = uif->num_altsetting; 1165 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", 1166 dev->video_mode.end_point_addr, 1167 dev->video_mode.num_alt); 1168 dev->video_mode.alt_max_pkt_size = 1169 kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL); 1170 1171 if (dev->video_mode.alt_max_pkt_size == NULL) { 1172 cx231xx_errdev("out of memory!\n"); 1173 clear_bit(dev->devno, &cx231xx_devused); 1174 v4l2_device_unregister(&dev->v4l2_dev); 1175 kfree(dev); 1176 dev = NULL; 1177 return -ENOMEM; 1178 } 1179 1180 for (i = 0; i < dev->video_mode.num_alt; i++) { 1181 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe]. 1182 desc.wMaxPacketSize); 1183 dev->video_mode.alt_max_pkt_size[i] = 1184 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); 1185 cx231xx_info("Alternate setting %i, max size= %i\n", i, 1186 dev->video_mode.alt_max_pkt_size[i]); 1187 } 1188 1189 /* compute alternate max packet sizes for vbi */ 1190 uif = udev->actconfig->interface[dev->current_pcb_config. 1191 hs_config_info[0].interface_info. 1192 vanc_index + 1]; 1193 1194 dev->vbi_mode.end_point_addr = 1195 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc. 1196 bEndpointAddress); 1197 1198 dev->vbi_mode.num_alt = uif->num_altsetting; 1199 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", 1200 dev->vbi_mode.end_point_addr, 1201 dev->vbi_mode.num_alt); 1202 dev->vbi_mode.alt_max_pkt_size = 1203 kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL); 1204 1205 if (dev->vbi_mode.alt_max_pkt_size == NULL) { 1206 cx231xx_errdev("out of memory!\n"); 1207 clear_bit(dev->devno, &cx231xx_devused); 1208 v4l2_device_unregister(&dev->v4l2_dev); 1209 kfree(dev); 1210 dev = NULL; 1211 return -ENOMEM; 1212 } 1213 1214 for (i = 0; i < dev->vbi_mode.num_alt; i++) { 1215 u16 tmp = 1216 le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe]. 1217 desc.wMaxPacketSize); 1218 dev->vbi_mode.alt_max_pkt_size[i] = 1219 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); 1220 cx231xx_info("Alternate setting %i, max size= %i\n", i, 1221 dev->vbi_mode.alt_max_pkt_size[i]); 1222 } 1223 1224 /* compute alternate max packet sizes for sliced CC */ 1225 uif = udev->actconfig->interface[dev->current_pcb_config. 1226 hs_config_info[0].interface_info. 1227 hanc_index + 1]; 1228 1229 dev->sliced_cc_mode.end_point_addr = 1230 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc. 1231 bEndpointAddress); 1232 1233 dev->sliced_cc_mode.num_alt = uif->num_altsetting; 1234 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", 1235 dev->sliced_cc_mode.end_point_addr, 1236 dev->sliced_cc_mode.num_alt); 1237 dev->sliced_cc_mode.alt_max_pkt_size = 1238 kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL); 1239 1240 if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) { 1241 cx231xx_errdev("out of memory!\n"); 1242 clear_bit(dev->devno, &cx231xx_devused); 1243 v4l2_device_unregister(&dev->v4l2_dev); 1244 kfree(dev); 1245 dev = NULL; 1246 return -ENOMEM; 1247 } 1248 1249 for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) { 1250 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe]. 1251 desc.wMaxPacketSize); 1252 dev->sliced_cc_mode.alt_max_pkt_size[i] = 1253 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); 1254 cx231xx_info("Alternate setting %i, max size= %i\n", i, 1255 dev->sliced_cc_mode.alt_max_pkt_size[i]); 1256 } 1257 1258 if (dev->current_pcb_config.ts1_source != 0xff) { 1259 /* compute alternate max packet sizes for TS1 */ 1260 uif = udev->actconfig->interface[dev->current_pcb_config. 1261 hs_config_info[0]. 1262 interface_info. 1263 ts1_index + 1]; 1264 1265 dev->ts1_mode.end_point_addr = 1266 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe]. 1267 desc.bEndpointAddress); 1268 1269 dev->ts1_mode.num_alt = uif->num_altsetting; 1270 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", 1271 dev->ts1_mode.end_point_addr, 1272 dev->ts1_mode.num_alt); 1273 dev->ts1_mode.alt_max_pkt_size = 1274 kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL); 1275 1276 if (dev->ts1_mode.alt_max_pkt_size == NULL) { 1277 cx231xx_errdev("out of memory!\n"); 1278 clear_bit(dev->devno, &cx231xx_devused); 1279 v4l2_device_unregister(&dev->v4l2_dev); 1280 kfree(dev); 1281 dev = NULL; 1282 return -ENOMEM; 1283 } 1284 1285 for (i = 0; i < dev->ts1_mode.num_alt; i++) { 1286 u16 tmp = le16_to_cpu(uif->altsetting[i]. 1287 endpoint[isoc_pipe].desc. 1288 wMaxPacketSize); 1289 dev->ts1_mode.alt_max_pkt_size[i] = 1290 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); 1291 cx231xx_info("Alternate setting %i, max size= %i\n", i, 1292 dev->ts1_mode.alt_max_pkt_size[i]); 1293 } 1294 } 1295 1296 if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) { 1297 cx231xx_enable_OSC(dev); 1298 cx231xx_reset_out(dev); 1299 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3); 1300 } 1301 1302 if (dev->model == CX231XX_BOARD_CNXT_RDE_253S) 1303 cx231xx_sleep_s5h1432(dev); 1304 1305 /* load other modules required */ 1306 request_modules(dev); 1307 1308 return 0; 1309 } 1310 1311 /* 1312 * cx231xx_usb_disconnect() 1313 * called when the device gets diconencted 1314 * video device will be unregistered on v4l2_close in case it is still open 1315 */ 1316 static void cx231xx_usb_disconnect(struct usb_interface *interface) 1317 { 1318 struct cx231xx *dev; 1319 1320 dev = usb_get_intfdata(interface); 1321 usb_set_intfdata(interface, NULL); 1322 1323 if (!dev) 1324 return; 1325 1326 if (!dev->udev) 1327 return; 1328 1329 dev->state |= DEV_DISCONNECTED; 1330 1331 flush_request_modules(dev); 1332 1333 /* wait until all current v4l2 io is finished then deallocate 1334 resources */ 1335 mutex_lock(&dev->lock); 1336 1337 wake_up_interruptible_all(&dev->open); 1338 1339 if (dev->users) { 1340 cx231xx_warn 1341 ("device %s is open! Deregistration and memory " 1342 "deallocation are deferred on close.\n", 1343 video_device_node_name(dev->vdev)); 1344 1345 /* Even having users, it is safe to remove the RC i2c driver */ 1346 cx231xx_ir_exit(dev); 1347 1348 if (dev->USE_ISO) 1349 cx231xx_uninit_isoc(dev); 1350 else 1351 cx231xx_uninit_bulk(dev); 1352 wake_up_interruptible(&dev->wait_frame); 1353 wake_up_interruptible(&dev->wait_stream); 1354 } else { 1355 } 1356 1357 cx231xx_close_extension(dev); 1358 1359 mutex_unlock(&dev->lock); 1360 1361 if (!dev->users) 1362 cx231xx_release_resources(dev); 1363 } 1364 1365 static struct usb_driver cx231xx_usb_driver = { 1366 .name = "cx231xx", 1367 .probe = cx231xx_usb_probe, 1368 .disconnect = cx231xx_usb_disconnect, 1369 .id_table = cx231xx_id_table, 1370 }; 1371 1372 module_usb_driver(cx231xx_usb_driver); 1373