linux/drivers/media/usb/cx231xx/cx231xx-cards.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0-or-later
   2/*
   3   cx231xx-cards.c - driver for Conexant Cx23100/101/102
   4                                USB video capture devices
   5
   6   Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
   7                                Based on em28xx driver
   8
   9 */
  10
  11#include "cx231xx.h"
  12#include <linux/init.h>
  13#include <linux/module.h>
  14#include <linux/slab.h>
  15#include <linux/delay.h>
  16#include <linux/i2c.h>
  17#include <media/tuner.h>
  18#include <media/tveeprom.h>
  19#include <media/v4l2-common.h>
  20
  21#include <media/drv-intf/cx25840.h>
  22#include <media/dvb-usb-ids.h>
  23#include "xc5000.h"
  24#include "tda18271.h"
  25
  26
  27static int tuner = -1;
  28module_param(tuner, int, 0444);
  29MODULE_PARM_DESC(tuner, "tuner type");
  30
  31static int transfer_mode = 1;
  32module_param(transfer_mode, int, 0444);
  33MODULE_PARM_DESC(transfer_mode, "transfer mode (1-ISO or 0-BULK)");
  34
  35static unsigned int disable_ir;
  36module_param(disable_ir, int, 0444);
  37MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
  38
  39/* Bitmask marking allocated devices from 0 to CX231XX_MAXBOARDS */
  40static unsigned long cx231xx_devused;
  41
  42/*
  43 *  Reset sequences for analog/digital modes
  44 */
  45
  46static struct cx231xx_reg_seq RDE250_XCV_TUNER[] = {
  47        {0x03, 0x01, 10},
  48        {0x03, 0x00, 30},
  49        {0x03, 0x01, 10},
  50        {-1, -1, -1},
  51};
  52
  53/*
  54 *  Board definitions
  55 */
  56struct cx231xx_board cx231xx_boards[] = {
  57        [CX231XX_BOARD_UNKNOWN] = {
  58                .name = "Unknown CX231xx video grabber",
  59                .tuner_type = TUNER_ABSENT,
  60                .input = {{
  61                                .type = CX231XX_VMUX_TELEVISION,
  62                                .vmux = CX231XX_VIN_3_1,
  63                                .amux = CX231XX_AMUX_VIDEO,
  64                                .gpio = NULL,
  65                        }, {
  66                                .type = CX231XX_VMUX_COMPOSITE1,
  67                                .vmux = CX231XX_VIN_2_1,
  68                                .amux = CX231XX_AMUX_LINE_IN,
  69                                .gpio = NULL,
  70                        }, {
  71                                .type = CX231XX_VMUX_SVIDEO,
  72                                .vmux = CX231XX_VIN_1_1 |
  73                                        (CX231XX_VIN_1_2 << 8) |
  74                                        CX25840_SVIDEO_ON,
  75                                .amux = CX231XX_AMUX_LINE_IN,
  76                                .gpio = NULL,
  77                        }
  78                },
  79        },
  80        [CX231XX_BOARD_CNXT_CARRAERA] = {
  81                .name = "Conexant Hybrid TV - CARRAERA",
  82                .tuner_type = TUNER_XC5000,
  83                .tuner_addr = 0x61,
  84                .tuner_gpio = RDE250_XCV_TUNER,
  85                .tuner_sif_gpio = 0x05,
  86                .tuner_scl_gpio = 0x1a,
  87                .tuner_sda_gpio = 0x1b,
  88                .decoder = CX231XX_AVDECODER,
  89                .output_mode = OUT_MODE_VIP11,
  90                .demod_xfer_mode = 0,
  91                .ctl_pin_status_mask = 0xFFFFFFC4,
  92                .agc_analog_digital_select_gpio = 0x0c,
  93                .gpio_pin_status_mask = 0x4001000,
  94                .tuner_i2c_master = I2C_1_MUX_3,
  95                .demod_i2c_master = I2C_2,
  96                .has_dvb = 1,
  97                .demod_addr = 0x02,
  98                .norm = V4L2_STD_PAL,
  99
 100                .input = {{
 101                                .type = CX231XX_VMUX_TELEVISION,
 102                                .vmux = CX231XX_VIN_3_1,
 103                                .amux = CX231XX_AMUX_VIDEO,
 104                                .gpio = NULL,
 105                        }, {
 106                                .type = CX231XX_VMUX_COMPOSITE1,
 107                                .vmux = CX231XX_VIN_2_1,
 108                                .amux = CX231XX_AMUX_LINE_IN,
 109                                .gpio = NULL,
 110                        }, {
 111                                .type = CX231XX_VMUX_SVIDEO,
 112                                .vmux = CX231XX_VIN_1_1 |
 113                                        (CX231XX_VIN_1_2 << 8) |
 114                                        CX25840_SVIDEO_ON,
 115                                .amux = CX231XX_AMUX_LINE_IN,
 116                                .gpio = NULL,
 117                        }
 118                },
 119        },
 120        [CX231XX_BOARD_CNXT_SHELBY] = {
 121                .name = "Conexant Hybrid TV - SHELBY",
 122                .tuner_type = TUNER_XC5000,
 123                .tuner_addr = 0x61,
 124                .tuner_gpio = RDE250_XCV_TUNER,
 125                .tuner_sif_gpio = 0x05,
 126                .tuner_scl_gpio = 0x1a,
 127                .tuner_sda_gpio = 0x1b,
 128                .decoder = CX231XX_AVDECODER,
 129                .output_mode = OUT_MODE_VIP11,
 130                .demod_xfer_mode = 0,
 131                .ctl_pin_status_mask = 0xFFFFFFC4,
 132                .agc_analog_digital_select_gpio = 0x0c,
 133                .gpio_pin_status_mask = 0x4001000,
 134                .tuner_i2c_master = I2C_1_MUX_3,
 135                .demod_i2c_master = I2C_2,
 136                .has_dvb = 1,
 137                .demod_addr = 0x32,
 138                .norm = V4L2_STD_NTSC,
 139
 140                .input = {{
 141                                .type = CX231XX_VMUX_TELEVISION,
 142                                .vmux = CX231XX_VIN_3_1,
 143                                .amux = CX231XX_AMUX_VIDEO,
 144                                .gpio = NULL,
 145                        }, {
 146                                .type = CX231XX_VMUX_COMPOSITE1,
 147                                .vmux = CX231XX_VIN_2_1,
 148                                .amux = CX231XX_AMUX_LINE_IN,
 149                                .gpio = NULL,
 150                        }, {
 151                                .type = CX231XX_VMUX_SVIDEO,
 152                                .vmux = CX231XX_VIN_1_1 |
 153                                        (CX231XX_VIN_1_2 << 8) |
 154                                        CX25840_SVIDEO_ON,
 155                                .amux = CX231XX_AMUX_LINE_IN,
 156                                .gpio = NULL,
 157                        }
 158                },
 159        },
 160        [CX231XX_BOARD_CNXT_RDE_253S] = {
 161                .name = "Conexant Hybrid TV - RDE253S",
 162                .tuner_type = TUNER_NXP_TDA18271,
 163                .tuner_addr = 0x60,
 164                .tuner_gpio = RDE250_XCV_TUNER,
 165                .tuner_sif_gpio = 0x05,
 166                .tuner_scl_gpio = 0x1a,
 167                .tuner_sda_gpio = 0x1b,
 168                .decoder = CX231XX_AVDECODER,
 169                .output_mode = OUT_MODE_VIP11,
 170                .demod_xfer_mode = 0,
 171                .ctl_pin_status_mask = 0xFFFFFFC4,
 172                .agc_analog_digital_select_gpio = 0x1c,
 173                .gpio_pin_status_mask = 0x4001000,
 174                .tuner_i2c_master = I2C_1_MUX_3,
 175                .demod_i2c_master = I2C_2,
 176                .has_dvb = 1,
 177                .demod_addr = 0x02,
 178                .norm = V4L2_STD_PAL,
 179
 180                .input = {{
 181                                .type = CX231XX_VMUX_TELEVISION,
 182                                .vmux = CX231XX_VIN_3_1,
 183                                .amux = CX231XX_AMUX_VIDEO,
 184                                .gpio = NULL,
 185                        }, {
 186                                .type = CX231XX_VMUX_COMPOSITE1,
 187                                .vmux = CX231XX_VIN_2_1,
 188                                .amux = CX231XX_AMUX_LINE_IN,
 189                                .gpio = NULL,
 190                        }, {
 191                                .type = CX231XX_VMUX_SVIDEO,
 192                                .vmux = CX231XX_VIN_1_1 |
 193                                        (CX231XX_VIN_1_2 << 8) |
 194                                        CX25840_SVIDEO_ON,
 195                                .amux = CX231XX_AMUX_LINE_IN,
 196                                .gpio = NULL,
 197                        }
 198                },
 199        },
 200
 201        [CX231XX_BOARD_CNXT_RDU_253S] = {
 202                .name = "Conexant Hybrid TV - RDU253S",
 203                .tuner_type = TUNER_NXP_TDA18271,
 204                .tuner_addr = 0x60,
 205                .tuner_gpio = RDE250_XCV_TUNER,
 206                .tuner_sif_gpio = 0x05,
 207                .tuner_scl_gpio = 0x1a,
 208                .tuner_sda_gpio = 0x1b,
 209                .decoder = CX231XX_AVDECODER,
 210                .output_mode = OUT_MODE_VIP11,
 211                .demod_xfer_mode = 0,
 212                .ctl_pin_status_mask = 0xFFFFFFC4,
 213                .agc_analog_digital_select_gpio = 0x1c,
 214                .gpio_pin_status_mask = 0x4001000,
 215                .tuner_i2c_master = I2C_1_MUX_3,
 216                .demod_i2c_master = I2C_2,
 217                .has_dvb = 1,
 218                .demod_addr = 0x02,
 219                .norm = V4L2_STD_PAL,
 220
 221                .input = {{
 222                                .type = CX231XX_VMUX_TELEVISION,
 223                                .vmux = CX231XX_VIN_3_1,
 224                                .amux = CX231XX_AMUX_VIDEO,
 225                                .gpio = NULL,
 226                        }, {
 227                                .type = CX231XX_VMUX_COMPOSITE1,
 228                                .vmux = CX231XX_VIN_2_1,
 229                                .amux = CX231XX_AMUX_LINE_IN,
 230                                .gpio = NULL,
 231                        }, {
 232                                .type = CX231XX_VMUX_SVIDEO,
 233                                .vmux = CX231XX_VIN_1_1 |
 234                                        (CX231XX_VIN_1_2 << 8) |
 235                                        CX25840_SVIDEO_ON,
 236                                .amux = CX231XX_AMUX_LINE_IN,
 237                                .gpio = NULL,
 238                        }
 239                },
 240        },
 241        [CX231XX_BOARD_CNXT_VIDEO_GRABBER] = {
 242                .name = "Conexant VIDEO GRABBER",
 243                .tuner_type = TUNER_ABSENT,
 244                .decoder = CX231XX_AVDECODER,
 245                .output_mode = OUT_MODE_VIP11,
 246                .ctl_pin_status_mask = 0xFFFFFFC4,
 247                .agc_analog_digital_select_gpio = 0x1c,
 248                .gpio_pin_status_mask = 0x4001000,
 249                .norm = V4L2_STD_PAL,
 250                .no_alt_vanc = 1,
 251                .external_av = 1,
 252                /* Actually, it has a 417, but it isn't working correctly.
 253                 * So set to 0 for now until someone can manage to get this
 254                 * to work reliably. */
 255                .has_417 = 0,
 256
 257                .input = {{
 258                                .type = CX231XX_VMUX_COMPOSITE1,
 259                                .vmux = CX231XX_VIN_2_1,
 260                                .amux = CX231XX_AMUX_LINE_IN,
 261                                .gpio = NULL,
 262                        }, {
 263                                .type = CX231XX_VMUX_SVIDEO,
 264                                .vmux = CX231XX_VIN_1_1 |
 265                                        (CX231XX_VIN_1_2 << 8) |
 266                                        CX25840_SVIDEO_ON,
 267                                .amux = CX231XX_AMUX_LINE_IN,
 268                                .gpio = NULL,
 269                        }
 270                },
 271        },
 272        [CX231XX_BOARD_CNXT_RDE_250] = {
 273                .name = "Conexant Hybrid TV - rde 250",
 274                .tuner_type = TUNER_XC5000,
 275                .tuner_addr = 0x61,
 276                .tuner_gpio = RDE250_XCV_TUNER,
 277                .tuner_sif_gpio = 0x05,
 278                .tuner_scl_gpio = 0x1a,
 279                .tuner_sda_gpio = 0x1b,
 280                .decoder = CX231XX_AVDECODER,
 281                .output_mode = OUT_MODE_VIP11,
 282                .demod_xfer_mode = 0,
 283                .ctl_pin_status_mask = 0xFFFFFFC4,
 284                .agc_analog_digital_select_gpio = 0x0c,
 285                .gpio_pin_status_mask = 0x4001000,
 286                .tuner_i2c_master = I2C_1_MUX_3,
 287                .demod_i2c_master = I2C_2,
 288                .has_dvb = 1,
 289                .demod_addr = 0x02,
 290                .norm = V4L2_STD_PAL,
 291
 292                .input = {{
 293                                .type = CX231XX_VMUX_TELEVISION,
 294                                .vmux = CX231XX_VIN_2_1,
 295                                .amux = CX231XX_AMUX_VIDEO,
 296                                .gpio = NULL,
 297                        }
 298                },
 299        },
 300        [CX231XX_BOARD_CNXT_RDU_250] = {
 301                .name = "Conexant Hybrid TV - RDU 250",
 302                .tuner_type = TUNER_XC5000,
 303                .tuner_addr = 0x61,
 304                .tuner_gpio = RDE250_XCV_TUNER,
 305                .tuner_sif_gpio = 0x05,
 306                .tuner_scl_gpio = 0x1a,
 307                .tuner_sda_gpio = 0x1b,
 308                .decoder = CX231XX_AVDECODER,
 309                .output_mode = OUT_MODE_VIP11,
 310                .demod_xfer_mode = 0,
 311                .ctl_pin_status_mask = 0xFFFFFFC4,
 312                .agc_analog_digital_select_gpio = 0x0c,
 313                .gpio_pin_status_mask = 0x4001000,
 314                .tuner_i2c_master = I2C_1_MUX_3,
 315                .demod_i2c_master = I2C_2,
 316                .has_dvb = 1,
 317                .demod_addr = 0x32,
 318                .norm = V4L2_STD_NTSC,
 319
 320                .input = {{
 321                                .type = CX231XX_VMUX_TELEVISION,
 322                                .vmux = CX231XX_VIN_2_1,
 323                                .amux = CX231XX_AMUX_VIDEO,
 324                                .gpio = NULL,
 325                        }
 326                },
 327        },
 328        [CX231XX_BOARD_HAUPPAUGE_EXETER] = {
 329                .name = "Hauppauge EXETER",
 330                .tuner_type = TUNER_NXP_TDA18271,
 331                .tuner_addr = 0x60,
 332                .tuner_gpio = RDE250_XCV_TUNER,
 333                .tuner_sif_gpio = 0x05,
 334                .tuner_scl_gpio = 0x1a,
 335                .tuner_sda_gpio = 0x1b,
 336                .decoder = CX231XX_AVDECODER,
 337                .output_mode = OUT_MODE_VIP11,
 338                .demod_xfer_mode = 0,
 339                .ctl_pin_status_mask = 0xFFFFFFC4,
 340                .agc_analog_digital_select_gpio = 0x0c,
 341                .gpio_pin_status_mask = 0x4001000,
 342                .tuner_i2c_master = I2C_1_MUX_1,
 343                .demod_i2c_master = I2C_1_MUX_1,
 344                .has_dvb = 1,
 345                .demod_addr = 0x0e,
 346                .norm = V4L2_STD_NTSC,
 347
 348                .input = {{
 349                        .type = CX231XX_VMUX_TELEVISION,
 350                        .vmux = CX231XX_VIN_3_1,
 351                        .amux = CX231XX_AMUX_VIDEO,
 352                        .gpio = NULL,
 353                }, {
 354                        .type = CX231XX_VMUX_COMPOSITE1,
 355                        .vmux = CX231XX_VIN_2_1,
 356                        .amux = CX231XX_AMUX_LINE_IN,
 357                        .gpio = NULL,
 358                }, {
 359                        .type = CX231XX_VMUX_SVIDEO,
 360                        .vmux = CX231XX_VIN_1_1 |
 361                                (CX231XX_VIN_1_2 << 8) |
 362                                CX25840_SVIDEO_ON,
 363                        .amux = CX231XX_AMUX_LINE_IN,
 364                        .gpio = NULL,
 365                } },
 366        },
 367        [CX231XX_BOARD_HAUPPAUGE_USBLIVE2] = {
 368                .name = "Hauppauge USB Live 2",
 369                .tuner_type = TUNER_ABSENT,
 370                .decoder = CX231XX_AVDECODER,
 371                .output_mode = OUT_MODE_VIP11,
 372                .demod_xfer_mode = 0,
 373                .ctl_pin_status_mask = 0xFFFFFFC4,
 374                .agc_analog_digital_select_gpio = 0x0c,
 375                .gpio_pin_status_mask = 0x4001000,
 376                .norm = V4L2_STD_NTSC,
 377                .no_alt_vanc = 1,
 378                .external_av = 1,
 379                .input = {{
 380                        .type = CX231XX_VMUX_COMPOSITE1,
 381                        .vmux = CX231XX_VIN_2_1,
 382                        .amux = CX231XX_AMUX_LINE_IN,
 383                        .gpio = NULL,
 384                }, {
 385                        .type = CX231XX_VMUX_SVIDEO,
 386                        .vmux = CX231XX_VIN_1_1 |
 387                                (CX231XX_VIN_1_2 << 8) |
 388                                CX25840_SVIDEO_ON,
 389                        .amux = CX231XX_AMUX_LINE_IN,
 390                        .gpio = NULL,
 391                } },
 392        },
 393        [CX231XX_BOARD_KWORLD_UB430_USB_HYBRID] = {
 394                .name = "Kworld UB430 USB Hybrid",
 395                .tuner_type = TUNER_NXP_TDA18271,
 396                .tuner_addr = 0x60,
 397                .decoder = CX231XX_AVDECODER,
 398                .output_mode = OUT_MODE_VIP11,
 399                .demod_xfer_mode = 0,
 400                .ctl_pin_status_mask = 0xFFFFFFC4,
 401                .agc_analog_digital_select_gpio = 0x11, /* According with PV cxPolaris.inf file */
 402                .tuner_sif_gpio = -1,
 403                .tuner_scl_gpio = -1,
 404                .tuner_sda_gpio = -1,
 405                .gpio_pin_status_mask = 0x4001000,
 406                .tuner_i2c_master = I2C_2,
 407                .demod_i2c_master = I2C_1_MUX_3,
 408                .ir_i2c_master = I2C_2,
 409                .has_dvb = 1,
 410                .demod_addr = 0x10,
 411                .norm = V4L2_STD_PAL_M,
 412                .input = {{
 413                        .type = CX231XX_VMUX_TELEVISION,
 414                        .vmux = CX231XX_VIN_3_1,
 415                        .amux = CX231XX_AMUX_VIDEO,
 416                        .gpio = NULL,
 417                }, {
 418                        .type = CX231XX_VMUX_COMPOSITE1,
 419                        .vmux = CX231XX_VIN_2_1,
 420                        .amux = CX231XX_AMUX_LINE_IN,
 421                        .gpio = NULL,
 422                }, {
 423                        .type = CX231XX_VMUX_SVIDEO,
 424                        .vmux = CX231XX_VIN_1_1 |
 425                                (CX231XX_VIN_1_2 << 8) |
 426                                CX25840_SVIDEO_ON,
 427                        .amux = CX231XX_AMUX_LINE_IN,
 428                        .gpio = NULL,
 429                } },
 430        },
 431        [CX231XX_BOARD_KWORLD_UB445_USB_HYBRID] = {
 432                .name = "Kworld UB445 USB Hybrid",
 433                .tuner_type = TUNER_NXP_TDA18271,
 434                .tuner_addr = 0x60,
 435                .decoder = CX231XX_AVDECODER,
 436                .output_mode = OUT_MODE_VIP11,
 437                .demod_xfer_mode = 0,
 438                .ctl_pin_status_mask = 0xFFFFFFC4,
 439                .agc_analog_digital_select_gpio = 0x11, /* According with PV cxPolaris.inf file */
 440                .tuner_sif_gpio = -1,
 441                .tuner_scl_gpio = -1,
 442                .tuner_sda_gpio = -1,
 443                .gpio_pin_status_mask = 0x4001000,
 444                .tuner_i2c_master = I2C_2,
 445                .demod_i2c_master = I2C_1_MUX_3,
 446                .ir_i2c_master = I2C_2,
 447                .has_dvb = 1,
 448                .demod_addr = 0x10,
 449                .norm = V4L2_STD_NTSC_M,
 450                .input = {{
 451                        .type = CX231XX_VMUX_TELEVISION,
 452                        .vmux = CX231XX_VIN_3_1,
 453                        .amux = CX231XX_AMUX_VIDEO,
 454                        .gpio = NULL,
 455                }, {
 456                        .type = CX231XX_VMUX_COMPOSITE1,
 457                        .vmux = CX231XX_VIN_2_1,
 458                        .amux = CX231XX_AMUX_LINE_IN,
 459                        .gpio = NULL,
 460                }, {
 461                        .type = CX231XX_VMUX_SVIDEO,
 462                        .vmux = CX231XX_VIN_1_1 |
 463                                (CX231XX_VIN_1_2 << 8) |
 464                                CX25840_SVIDEO_ON,
 465                        .amux = CX231XX_AMUX_LINE_IN,
 466                        .gpio = NULL,
 467                } },
 468        },
 469        [CX231XX_BOARD_PV_PLAYTV_USB_HYBRID] = {
 470                .name = "Pixelview PlayTV USB Hybrid",
 471                .tuner_type = TUNER_NXP_TDA18271,
 472                .tuner_addr = 0x60,
 473                .decoder = CX231XX_AVDECODER,
 474                .output_mode = OUT_MODE_VIP11,
 475                .demod_xfer_mode = 0,
 476                .ctl_pin_status_mask = 0xFFFFFFC4,
 477                .agc_analog_digital_select_gpio = 0x1c,
 478                .tuner_sif_gpio = -1,
 479                .tuner_scl_gpio = -1,
 480                .tuner_sda_gpio = -1,
 481                .gpio_pin_status_mask = 0x4001000,
 482                .tuner_i2c_master = I2C_2,
 483                .demod_i2c_master = I2C_1_MUX_3,
 484                .ir_i2c_master = I2C_2,
 485                .rc_map_name = RC_MAP_PIXELVIEW_002T,
 486                .has_dvb = 1,
 487                .demod_addr = 0x10,
 488                .norm = V4L2_STD_PAL_M,
 489                .input = {{
 490                        .type = CX231XX_VMUX_TELEVISION,
 491                        .vmux = CX231XX_VIN_3_1,
 492                        .amux = CX231XX_AMUX_VIDEO,
 493                        .gpio = NULL,
 494                }, {
 495                        .type = CX231XX_VMUX_COMPOSITE1,
 496                        .vmux = CX231XX_VIN_2_1,
 497                        .amux = CX231XX_AMUX_LINE_IN,
 498                        .gpio = NULL,
 499                }, {
 500                        .type = CX231XX_VMUX_SVIDEO,
 501                        .vmux = CX231XX_VIN_1_1 |
 502                                (CX231XX_VIN_1_2 << 8) |
 503                                CX25840_SVIDEO_ON,
 504                        .amux = CX231XX_AMUX_LINE_IN,
 505                        .gpio = NULL,
 506                } },
 507        },
 508        [CX231XX_BOARD_PV_XCAPTURE_USB] = {
 509                .name = "Pixelview Xcapture USB",
 510                .tuner_type = TUNER_ABSENT,
 511                .decoder = CX231XX_AVDECODER,
 512                .output_mode = OUT_MODE_VIP11,
 513                .demod_xfer_mode = 0,
 514                .ctl_pin_status_mask = 0xFFFFFFC4,
 515                .agc_analog_digital_select_gpio = 0x0c,
 516                .gpio_pin_status_mask = 0x4001000,
 517                .norm = V4L2_STD_NTSC,
 518                .no_alt_vanc = 1,
 519                .external_av = 1,
 520
 521                .input = {{
 522                                .type = CX231XX_VMUX_COMPOSITE1,
 523                                .vmux = CX231XX_VIN_2_1,
 524                                .amux = CX231XX_AMUX_LINE_IN,
 525                                .gpio = NULL,
 526                        }, {
 527                                .type = CX231XX_VMUX_SVIDEO,
 528                                .vmux = CX231XX_VIN_1_1 |
 529                                        (CX231XX_VIN_1_2 << 8) |
 530                                        CX25840_SVIDEO_ON,
 531                                .amux = CX231XX_AMUX_LINE_IN,
 532                                .gpio = NULL,
 533                        }
 534                },
 535        },
 536
 537        [CX231XX_BOARD_ICONBIT_U100] = {
 538                .name = "Iconbit Analog Stick U100 FM",
 539                .tuner_type = TUNER_ABSENT,
 540                .decoder = CX231XX_AVDECODER,
 541                .output_mode = OUT_MODE_VIP11,
 542                .demod_xfer_mode = 0,
 543                .ctl_pin_status_mask = 0xFFFFFFC4,
 544                .agc_analog_digital_select_gpio = 0x1C,
 545                .gpio_pin_status_mask = 0x4001000,
 546
 547                .input = {{
 548                        .type = CX231XX_VMUX_COMPOSITE1,
 549                        .vmux = CX231XX_VIN_2_1,
 550                        .amux = CX231XX_AMUX_LINE_IN,
 551                        .gpio = NULL,
 552                }, {
 553                        .type = CX231XX_VMUX_SVIDEO,
 554                        .vmux = CX231XX_VIN_1_1 |
 555                                (CX231XX_VIN_1_2 << 8) |
 556                                CX25840_SVIDEO_ON,
 557                        .amux = CX231XX_AMUX_LINE_IN,
 558                        .gpio = NULL,
 559                } },
 560        },
 561        [CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL] = {
 562                .name = "Hauppauge WinTV USB2 FM (PAL)",
 563                .tuner_type = TUNER_NXP_TDA18271,
 564                .tuner_addr = 0x60,
 565                .tuner_gpio = RDE250_XCV_TUNER,
 566                .tuner_sif_gpio = 0x05,
 567                .tuner_scl_gpio = 0x1a,
 568                .tuner_sda_gpio = 0x1b,
 569                .decoder = CX231XX_AVDECODER,
 570                .output_mode = OUT_MODE_VIP11,
 571                .ctl_pin_status_mask = 0xFFFFFFC4,
 572                .agc_analog_digital_select_gpio = 0x0c,
 573                .gpio_pin_status_mask = 0x4001000,
 574                .tuner_i2c_master = I2C_1_MUX_3,
 575                .norm = V4L2_STD_PAL,
 576
 577                .input = {{
 578                        .type = CX231XX_VMUX_TELEVISION,
 579                        .vmux = CX231XX_VIN_3_1,
 580                        .amux = CX231XX_AMUX_VIDEO,
 581                        .gpio = NULL,
 582                }, {
 583                        .type = CX231XX_VMUX_COMPOSITE1,
 584                        .vmux = CX231XX_VIN_2_1,
 585                        .amux = CX231XX_AMUX_LINE_IN,
 586                        .gpio = NULL,
 587                }, {
 588                        .type = CX231XX_VMUX_SVIDEO,
 589                        .vmux = CX231XX_VIN_1_1 |
 590                                (CX231XX_VIN_1_2 << 8) |
 591                                CX25840_SVIDEO_ON,
 592                        .amux = CX231XX_AMUX_LINE_IN,
 593                        .gpio = NULL,
 594                } },
 595        },
 596        [CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC] = {
 597                .name = "Hauppauge WinTV USB2 FM (NTSC)",
 598                .tuner_type = TUNER_NXP_TDA18271,
 599                .tuner_addr = 0x60,
 600                .tuner_gpio = RDE250_XCV_TUNER,
 601                .tuner_sif_gpio = 0x05,
 602                .tuner_scl_gpio = 0x1a,
 603                .tuner_sda_gpio = 0x1b,
 604                .decoder = CX231XX_AVDECODER,
 605                .output_mode = OUT_MODE_VIP11,
 606                .ctl_pin_status_mask = 0xFFFFFFC4,
 607                .agc_analog_digital_select_gpio = 0x0c,
 608                .gpio_pin_status_mask = 0x4001000,
 609                .tuner_i2c_master = I2C_1_MUX_3,
 610                .norm = V4L2_STD_NTSC,
 611
 612                .input = {{
 613                        .type = CX231XX_VMUX_TELEVISION,
 614                        .vmux = CX231XX_VIN_3_1,
 615                        .amux = CX231XX_AMUX_VIDEO,
 616                        .gpio = NULL,
 617                }, {
 618                        .type = CX231XX_VMUX_COMPOSITE1,
 619                        .vmux = CX231XX_VIN_2_1,
 620                        .amux = CX231XX_AMUX_LINE_IN,
 621                        .gpio = NULL,
 622                }, {
 623                        .type = CX231XX_VMUX_SVIDEO,
 624                        .vmux = CX231XX_VIN_1_1 |
 625                                (CX231XX_VIN_1_2 << 8) |
 626                                CX25840_SVIDEO_ON,
 627                        .amux = CX231XX_AMUX_LINE_IN,
 628                        .gpio = NULL,
 629                } },
 630        },
 631        [CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2] = {
 632                .name = "Elgato Video Capture V2",
 633                .tuner_type = TUNER_ABSENT,
 634                .decoder = CX231XX_AVDECODER,
 635                .output_mode = OUT_MODE_VIP11,
 636                .demod_xfer_mode = 0,
 637                .ctl_pin_status_mask = 0xFFFFFFC4,
 638                .agc_analog_digital_select_gpio = 0x0c,
 639                .gpio_pin_status_mask = 0x4001000,
 640                .norm = V4L2_STD_NTSC,
 641                .no_alt_vanc = 1,
 642                .external_av = 1,
 643                .input = {{
 644                        .type = CX231XX_VMUX_COMPOSITE1,
 645                        .vmux = CX231XX_VIN_2_1,
 646                        .amux = CX231XX_AMUX_LINE_IN,
 647                        .gpio = NULL,
 648                }, {
 649                        .type = CX231XX_VMUX_SVIDEO,
 650                        .vmux = CX231XX_VIN_1_1 |
 651                                (CX231XX_VIN_1_2 << 8) |
 652                                CX25840_SVIDEO_ON,
 653                        .amux = CX231XX_AMUX_LINE_IN,
 654                        .gpio = NULL,
 655                } },
 656        },
 657        [CX231XX_BOARD_OTG102] = {
 658                .name = "Geniatech OTG102",
 659                .tuner_type = TUNER_ABSENT,
 660                .decoder = CX231XX_AVDECODER,
 661                .output_mode = OUT_MODE_VIP11,
 662                .ctl_pin_status_mask = 0xFFFFFFC4,
 663                .agc_analog_digital_select_gpio = 0x0c,
 664                        /* According with PV CxPlrCAP.inf file */
 665                .gpio_pin_status_mask = 0x4001000,
 666                .norm = V4L2_STD_NTSC,
 667                .no_alt_vanc = 1,
 668                .external_av = 1,
 669                /*.has_417 = 1, */
 670                /* This board is believed to have a hardware encoding chip
 671                 * supporting mpeg1/2/4, but as the 417 is apparently not
 672                 * working for the reference board it is not here either. */
 673
 674                .input = {{
 675                                .type = CX231XX_VMUX_COMPOSITE1,
 676                                .vmux = CX231XX_VIN_2_1,
 677                                .amux = CX231XX_AMUX_LINE_IN,
 678                                .gpio = NULL,
 679                        }, {
 680                                .type = CX231XX_VMUX_SVIDEO,
 681                                .vmux = CX231XX_VIN_1_1 |
 682                                        (CX231XX_VIN_1_2 << 8) |
 683                                        CX25840_SVIDEO_ON,
 684                                .amux = CX231XX_AMUX_LINE_IN,
 685                                .gpio = NULL,
 686                        }
 687                },
 688        },
 689        [CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx] = {
 690                .name = "Hauppauge WinTV 930C-HD (1113xx) / HVR-900H (111xxx) / PCTV QuatroStick 521e",
 691                .tuner_type = TUNER_NXP_TDA18271,
 692                .tuner_addr = 0x60,
 693                .tuner_gpio = RDE250_XCV_TUNER,
 694                .tuner_sif_gpio = 0x05,
 695                .tuner_scl_gpio = 0x1a,
 696                .tuner_sda_gpio = 0x1b,
 697                .decoder = CX231XX_AVDECODER,
 698                .output_mode = OUT_MODE_VIP11,
 699                .demod_xfer_mode = 0,
 700                .ctl_pin_status_mask = 0xFFFFFFC4,
 701                .agc_analog_digital_select_gpio = 0x0c,
 702                .gpio_pin_status_mask = 0x4001000,
 703                .tuner_i2c_master = I2C_1_MUX_3,
 704                .demod_i2c_master = I2C_1_MUX_3,
 705                .has_dvb = 1,
 706                .demod_addr = 0x64, /* 0xc8 >> 1 */
 707                .norm = V4L2_STD_PAL,
 708
 709                .input = {{
 710                        .type = CX231XX_VMUX_TELEVISION,
 711                        .vmux = CX231XX_VIN_3_1,
 712                        .amux = CX231XX_AMUX_VIDEO,
 713                        .gpio = NULL,
 714                }, {
 715                        .type = CX231XX_VMUX_COMPOSITE1,
 716                        .vmux = CX231XX_VIN_2_1,
 717                        .amux = CX231XX_AMUX_LINE_IN,
 718                        .gpio = NULL,
 719                }, {
 720                        .type = CX231XX_VMUX_SVIDEO,
 721                        .vmux = CX231XX_VIN_1_1 |
 722                                (CX231XX_VIN_1_2 << 8) |
 723                                CX25840_SVIDEO_ON,
 724                        .amux = CX231XX_AMUX_LINE_IN,
 725                        .gpio = NULL,
 726                } },
 727        },
 728        [CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx] = {
 729                .name = "Hauppauge WinTV 930C-HD (1114xx) / HVR-901H (1114xx) / PCTV QuatroStick 522e",
 730                .tuner_type = TUNER_ABSENT,
 731                .tuner_addr = 0x60,
 732                .tuner_gpio = RDE250_XCV_TUNER,
 733                .tuner_sif_gpio = 0x05,
 734                .tuner_scl_gpio = 0x1a,
 735                .tuner_sda_gpio = 0x1b,
 736                .decoder = CX231XX_AVDECODER,
 737                .output_mode = OUT_MODE_VIP11,
 738                .demod_xfer_mode = 0,
 739                .ctl_pin_status_mask = 0xFFFFFFC4,
 740                .agc_analog_digital_select_gpio = 0x0c,
 741                .gpio_pin_status_mask = 0x4001000,
 742                .tuner_i2c_master = I2C_1_MUX_3,
 743                .demod_i2c_master = I2C_1_MUX_3,
 744                .has_dvb = 1,
 745                .demod_addr = 0x64, /* 0xc8 >> 1 */
 746                .norm = V4L2_STD_PAL,
 747
 748                .input = {{
 749                        .type = CX231XX_VMUX_TELEVISION,
 750                        .vmux = CX231XX_VIN_3_1,
 751                        .amux = CX231XX_AMUX_VIDEO,
 752                        .gpio = NULL,
 753                }, {
 754                        .type = CX231XX_VMUX_COMPOSITE1,
 755                        .vmux = CX231XX_VIN_2_1,
 756                        .amux = CX231XX_AMUX_LINE_IN,
 757                        .gpio = NULL,
 758                }, {
 759                        .type = CX231XX_VMUX_SVIDEO,
 760                        .vmux = CX231XX_VIN_1_1 |
 761                                (CX231XX_VIN_1_2 << 8) |
 762                                CX25840_SVIDEO_ON,
 763                        .amux = CX231XX_AMUX_LINE_IN,
 764                        .gpio = NULL,
 765                } },
 766        },
 767        [CX231XX_BOARD_HAUPPAUGE_955Q] = {
 768                .name = "Hauppauge WinTV-HVR-955Q (111401)",
 769                .tuner_type = TUNER_ABSENT,
 770                .tuner_addr = 0x60,
 771                .tuner_gpio = RDE250_XCV_TUNER,
 772                .tuner_sif_gpio = 0x05,
 773                .tuner_scl_gpio = 0x1a,
 774                .tuner_sda_gpio = 0x1b,
 775                .decoder = CX231XX_AVDECODER,
 776                .output_mode = OUT_MODE_VIP11,
 777                .demod_xfer_mode = 0,
 778                .ctl_pin_status_mask = 0xFFFFFFC4,
 779                .agc_analog_digital_select_gpio = 0x0c,
 780                .gpio_pin_status_mask = 0x4001000,
 781                .tuner_i2c_master = I2C_1_MUX_3,
 782                .demod_i2c_master = I2C_1_MUX_3,
 783                .has_dvb = 1,
 784                .demod_addr = 0x59, /* 0xb2 >> 1 */
 785                .norm = V4L2_STD_NTSC,
 786
 787                .input = {{
 788                        .type = CX231XX_VMUX_TELEVISION,
 789                        .vmux = CX231XX_VIN_3_1,
 790                        .amux = CX231XX_AMUX_VIDEO,
 791                        .gpio = NULL,
 792                }, {
 793                        .type = CX231XX_VMUX_COMPOSITE1,
 794                        .vmux = CX231XX_VIN_2_1,
 795                        .amux = CX231XX_AMUX_LINE_IN,
 796                        .gpio = NULL,
 797                }, {
 798                        .type = CX231XX_VMUX_SVIDEO,
 799                        .vmux = CX231XX_VIN_1_1 |
 800                                (CX231XX_VIN_1_2 << 8) |
 801                                CX25840_SVIDEO_ON,
 802                        .amux = CX231XX_AMUX_LINE_IN,
 803                        .gpio = NULL,
 804                } },
 805        },
 806        [CX231XX_BOARD_TERRATEC_GRABBY] = {
 807                .name = "Terratec Grabby",
 808                .tuner_type = TUNER_ABSENT,
 809                .decoder = CX231XX_AVDECODER,
 810                .output_mode = OUT_MODE_VIP11,
 811                .demod_xfer_mode = 0,
 812                .ctl_pin_status_mask = 0xFFFFFFC4,
 813                .agc_analog_digital_select_gpio = 0x0c,
 814                .gpio_pin_status_mask = 0x4001000,
 815                .norm = V4L2_STD_PAL,
 816                .no_alt_vanc = 1,
 817                .external_av = 1,
 818                .input = {{
 819                        .type = CX231XX_VMUX_COMPOSITE1,
 820                        .vmux = CX231XX_VIN_2_1,
 821                        .amux = CX231XX_AMUX_LINE_IN,
 822                        .gpio = NULL,
 823                }, {
 824                        .type = CX231XX_VMUX_SVIDEO,
 825                        .vmux = CX231XX_VIN_1_1 |
 826                                (CX231XX_VIN_1_2 << 8) |
 827                                CX25840_SVIDEO_ON,
 828                        .amux = CX231XX_AMUX_LINE_IN,
 829                        .gpio = NULL,
 830                } },
 831        },
 832        [CX231XX_BOARD_EVROMEDIA_FULL_HYBRID_FULLHD] = {
 833                .name = "Evromedia USB Full Hybrid Full HD",
 834                .tuner_type = TUNER_ABSENT,
 835                .demod_addr = 0x64, /* 0xc8 >> 1 */
 836                .demod_i2c_master = I2C_1_MUX_3,
 837                .has_dvb = 1,
 838                .decoder = CX231XX_AVDECODER,
 839                .norm = V4L2_STD_PAL,
 840                .output_mode = OUT_MODE_VIP11,
 841                .tuner_addr = 0x60, /* 0xc0 >> 1 */
 842                .tuner_i2c_master = I2C_2,
 843                .input = {{
 844                        .type = CX231XX_VMUX_TELEVISION,
 845                        .vmux = 0,
 846                        .amux = CX231XX_AMUX_VIDEO,
 847                }, {
 848                        .type = CX231XX_VMUX_COMPOSITE1,
 849                        .vmux = CX231XX_VIN_2_1,
 850                        .amux = CX231XX_AMUX_LINE_IN,
 851                }, {
 852                        .type = CX231XX_VMUX_SVIDEO,
 853                        .vmux = CX231XX_VIN_1_1 |
 854                                (CX231XX_VIN_1_2 << 8) |
 855                                CX25840_SVIDEO_ON,
 856                        .amux = CX231XX_AMUX_LINE_IN,
 857                } },
 858        },
 859        [CX231XX_BOARD_ASTROMETA_T2HYBRID] = {
 860                .name = "Astrometa T2hybrid",
 861                .tuner_type = TUNER_ABSENT,
 862                .has_dvb = 1,
 863                .decoder = CX231XX_AVDECODER,
 864                .output_mode = OUT_MODE_VIP11,
 865                .agc_analog_digital_select_gpio = 0x01,
 866                .ctl_pin_status_mask = 0xffffffc4,
 867                .demod_addr = 0x18, /* 0x30 >> 1 */
 868                .demod_i2c_master = I2C_1_MUX_1,
 869                .gpio_pin_status_mask = 0xa,
 870                .norm = V4L2_STD_NTSC,
 871                .tuner_addr = 0x3a, /* 0x74 >> 1 */
 872                .tuner_i2c_master = I2C_1_MUX_3,
 873                .tuner_scl_gpio = 0x1a,
 874                .tuner_sda_gpio = 0x1b,
 875                .tuner_sif_gpio = 0x05,
 876                .input = {{
 877                                .type = CX231XX_VMUX_TELEVISION,
 878                                .vmux = CX231XX_VIN_1_1,
 879                                .amux = CX231XX_AMUX_VIDEO,
 880                        }, {
 881                                .type = CX231XX_VMUX_COMPOSITE1,
 882                                .vmux = CX231XX_VIN_2_1,
 883                                .amux = CX231XX_AMUX_LINE_IN,
 884                        },
 885                },
 886        },
 887        [CX231XX_BOARD_THE_IMAGING_SOURCE_DFG_USB2_PRO] = {
 888                .name = "The Imaging Source DFG/USB2pro",
 889                .tuner_type = TUNER_ABSENT,
 890                .decoder = CX231XX_AVDECODER,
 891                .output_mode = OUT_MODE_VIP11,
 892                .demod_xfer_mode = 0,
 893                .ctl_pin_status_mask = 0xFFFFFFC4,
 894                .agc_analog_digital_select_gpio = 0x0c,
 895                .gpio_pin_status_mask = 0x4001000,
 896                .norm = V4L2_STD_PAL,
 897                .no_alt_vanc = 1,
 898                .external_av = 1,
 899                .input = {{
 900                        .type = CX231XX_VMUX_COMPOSITE1,
 901                        .vmux = CX231XX_VIN_1_1,
 902                        .amux = CX231XX_AMUX_LINE_IN,
 903                        .gpio = NULL,
 904                }, {
 905                        .type = CX231XX_VMUX_SVIDEO,
 906                        .vmux = CX231XX_VIN_2_1 |
 907                                (CX231XX_VIN_2_2 << 8) |
 908                                CX25840_SVIDEO_ON,
 909                        .amux = CX231XX_AMUX_LINE_IN,
 910                        .gpio = NULL,
 911                } },
 912        },
 913        [CX231XX_BOARD_HAUPPAUGE_935C] = {
 914                .name = "Hauppauge WinTV-HVR-935C",
 915                .tuner_type = TUNER_ABSENT,
 916                .tuner_addr = 0x60,
 917                .tuner_gpio = RDE250_XCV_TUNER,
 918                .tuner_sif_gpio = 0x05,
 919                .tuner_scl_gpio = 0x1a,
 920                .tuner_sda_gpio = 0x1b,
 921                .decoder = CX231XX_AVDECODER,
 922                .output_mode = OUT_MODE_VIP11,
 923                .demod_xfer_mode = 0,
 924                .ctl_pin_status_mask = 0xFFFFFFC4,
 925                .agc_analog_digital_select_gpio = 0x0c,
 926                .gpio_pin_status_mask = 0x4001000,
 927                .tuner_i2c_master = I2C_1_MUX_3,
 928                .demod_i2c_master = I2C_1_MUX_3,
 929                .has_dvb = 1,
 930                .demod_addr = 0x64, /* 0xc8 >> 1 */
 931                .norm = V4L2_STD_PAL,
 932
 933                .input = {{
 934                        .type = CX231XX_VMUX_TELEVISION,
 935                        .vmux = CX231XX_VIN_3_1,
 936                        .amux = CX231XX_AMUX_VIDEO,
 937                        .gpio = NULL,
 938                }, {
 939                        .type = CX231XX_VMUX_COMPOSITE1,
 940                        .vmux = CX231XX_VIN_2_1,
 941                        .amux = CX231XX_AMUX_LINE_IN,
 942                        .gpio = NULL,
 943                }, {
 944                        .type = CX231XX_VMUX_SVIDEO,
 945                        .vmux = CX231XX_VIN_1_1 |
 946                                (CX231XX_VIN_1_2 << 8) |
 947                                CX25840_SVIDEO_ON,
 948                        .amux = CX231XX_AMUX_LINE_IN,
 949                        .gpio = NULL,
 950                } },
 951        },
 952        [CX231XX_BOARD_HAUPPAUGE_975] = {
 953                .name = "Hauppauge WinTV-HVR-975",
 954                .tuner_type = TUNER_ABSENT,
 955                .tuner_addr = 0x60,
 956                .tuner_gpio = RDE250_XCV_TUNER,
 957                .tuner_sif_gpio = 0x05,
 958                .tuner_scl_gpio = 0x1a,
 959                .tuner_sda_gpio = 0x1b,
 960                .decoder = CX231XX_AVDECODER,
 961                .output_mode = OUT_MODE_VIP11,
 962                .demod_xfer_mode = 0,
 963                .ctl_pin_status_mask = 0xFFFFFFC4,
 964                .agc_analog_digital_select_gpio = 0x0c,
 965                .gpio_pin_status_mask = 0x4001000,
 966                .tuner_i2c_master = I2C_1_MUX_3,
 967                .demod_i2c_master = I2C_1_MUX_3,
 968                .has_dvb = 1,
 969                .demod_addr = 0x59, /* 0xb2 >> 1 */
 970                .demod_addr2 = 0x64, /* 0xc8 >> 1 */
 971                .norm = V4L2_STD_ALL,
 972
 973                .input = {{
 974                        .type = CX231XX_VMUX_TELEVISION,
 975                        .vmux = CX231XX_VIN_3_1,
 976                        .amux = CX231XX_AMUX_VIDEO,
 977                        .gpio = NULL,
 978                }, {
 979                        .type = CX231XX_VMUX_COMPOSITE1,
 980                        .vmux = CX231XX_VIN_2_1,
 981                        .amux = CX231XX_AMUX_LINE_IN,
 982                        .gpio = NULL,
 983                }, {
 984                        .type = CX231XX_VMUX_SVIDEO,
 985                        .vmux = CX231XX_VIN_1_1 |
 986                                (CX231XX_VIN_1_2 << 8) |
 987                                CX25840_SVIDEO_ON,
 988                        .amux = CX231XX_AMUX_LINE_IN,
 989                        .gpio = NULL,
 990                } },
 991        },
 992};
 993const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
 994
 995/* table of devices that work with this driver */
 996struct usb_device_id cx231xx_id_table[] = {
 997        {USB_DEVICE(0x1D19, 0x6109),
 998        .driver_info = CX231XX_BOARD_PV_XCAPTURE_USB},
 999        {USB_DEVICE(0x0572, 0x5A3C),
1000         .driver_info = CX231XX_BOARD_UNKNOWN},
1001        {USB_DEVICE(0x0572, 0x58A2),
1002         .driver_info = CX231XX_BOARD_CNXT_CARRAERA},
1003        {USB_DEVICE(0x0572, 0x58A1),
1004         .driver_info = CX231XX_BOARD_CNXT_SHELBY},
1005        {USB_DEVICE(0x0572, 0x58A4),
1006         .driver_info = CX231XX_BOARD_CNXT_RDE_253S},
1007        {USB_DEVICE(0x0572, 0x58A5),
1008         .driver_info = CX231XX_BOARD_CNXT_RDU_253S},
1009        {USB_DEVICE(0x0572, 0x58A6),
1010         .driver_info = CX231XX_BOARD_CNXT_VIDEO_GRABBER},
1011        {USB_DEVICE(0x0572, 0x589E),
1012         .driver_info = CX231XX_BOARD_CNXT_RDE_250},
1013        {USB_DEVICE(0x0572, 0x58A0),
1014         .driver_info = CX231XX_BOARD_CNXT_RDU_250},
1015        /* AverMedia DVD EZMaker 7 */
1016        {USB_DEVICE(0x07ca, 0xc039),
1017         .driver_info = CX231XX_BOARD_CNXT_VIDEO_GRABBER},
1018        {USB_DEVICE(0x2040, 0xb110),
1019         .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL},
1020        {USB_DEVICE(0x2040, 0xb111),
1021         .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC},
1022        {USB_DEVICE(0x2040, 0xb120),
1023         .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
1024        {USB_DEVICE(0x2040, 0xb123),
1025         .driver_info = CX231XX_BOARD_HAUPPAUGE_955Q},
1026        {USB_DEVICE(0x2040, 0xb124),
1027         .driver_info = CX231XX_BOARD_HAUPPAUGE_955Q},
1028        {USB_DEVICE(0x2040, 0xb151),
1029         .driver_info = CX231XX_BOARD_HAUPPAUGE_935C},
1030        {USB_DEVICE(0x2040, 0xb150),
1031         .driver_info = CX231XX_BOARD_HAUPPAUGE_975},
1032        {USB_DEVICE(0x2040, 0xb130),
1033         .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx},
1034        {USB_DEVICE(0x2040, 0xb131),
1035         .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx},
1036        /* Hauppauge WinTV-HVR-900-H */
1037        {USB_DEVICE(0x2040, 0xb138),
1038         .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx},
1039        /* Hauppauge WinTV-HVR-901-H */
1040        {USB_DEVICE(0x2040, 0xb139),
1041         .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx},
1042        {USB_DEVICE(0x2040, 0xb140),
1043         .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
1044        {USB_DEVICE(0x2040, 0xc200),
1045         .driver_info = CX231XX_BOARD_HAUPPAUGE_USBLIVE2},
1046        /* PCTV QuatroStick 521e */
1047        {USB_DEVICE(0x2013, 0x0259),
1048         .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx},
1049        /* PCTV QuatroStick 522e */
1050        {USB_DEVICE(0x2013, 0x025e),
1051         .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx},
1052        {USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x4000, 0x4001),
1053         .driver_info = CX231XX_BOARD_PV_PLAYTV_USB_HYBRID},
1054        {USB_DEVICE(USB_VID_PIXELVIEW, 0x5014),
1055         .driver_info = CX231XX_BOARD_PV_XCAPTURE_USB},
1056        {USB_DEVICE(0x1b80, 0xe424),
1057         .driver_info = CX231XX_BOARD_KWORLD_UB430_USB_HYBRID},
1058        {USB_DEVICE(0x1b80, 0xe421),
1059         .driver_info = CX231XX_BOARD_KWORLD_UB445_USB_HYBRID},
1060        {USB_DEVICE(0x1f4d, 0x0237),
1061         .driver_info = CX231XX_BOARD_ICONBIT_U100},
1062        {USB_DEVICE(0x0fd9, 0x0037),
1063         .driver_info = CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2},
1064        {USB_DEVICE(0x1f4d, 0x0102),
1065         .driver_info = CX231XX_BOARD_OTG102},
1066        {USB_DEVICE(USB_VID_TERRATEC, 0x00a6),
1067         .driver_info = CX231XX_BOARD_TERRATEC_GRABBY},
1068        {USB_DEVICE(0x1b80, 0xd3b2),
1069        .driver_info = CX231XX_BOARD_EVROMEDIA_FULL_HYBRID_FULLHD},
1070        {USB_DEVICE(0x15f4, 0x0135),
1071        .driver_info = CX231XX_BOARD_ASTROMETA_T2HYBRID},
1072        {USB_DEVICE(0x199e, 0x8002),
1073         .driver_info = CX231XX_BOARD_THE_IMAGING_SOURCE_DFG_USB2_PRO},
1074        {},
1075};
1076
1077MODULE_DEVICE_TABLE(usb, cx231xx_id_table);
1078
1079/* cx231xx_tuner_callback
1080 * will be used to reset XC5000 tuner using GPIO pin
1081 */
1082
1083int cx231xx_tuner_callback(void *ptr, int component, int command, int arg)
1084{
1085        int rc = 0;
1086        struct cx231xx *dev = ptr;
1087
1088        if (dev->tuner_type == TUNER_XC5000) {
1089                if (command == XC5000_TUNER_RESET) {
1090                        dev_dbg(dev->dev,
1091                                "Tuner CB: RESET: cmd %d : tuner type %d\n",
1092                                command, dev->tuner_type);
1093                        cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
1094                                               1);
1095                        msleep(10);
1096                        cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
1097                                               0);
1098                        msleep(330);
1099                        cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
1100                                               1);
1101                        msleep(10);
1102                }
1103        } else if (dev->tuner_type == TUNER_NXP_TDA18271) {
1104                switch (command) {
1105                case TDA18271_CALLBACK_CMD_AGC_ENABLE:
1106                        if (dev->model == CX231XX_BOARD_PV_PLAYTV_USB_HYBRID)
1107                                rc = cx231xx_set_agc_analog_digital_mux_select(dev, arg);
1108                        break;
1109                default:
1110                        rc = -EINVAL;
1111                        break;
1112                }
1113        }
1114        return rc;
1115}
1116EXPORT_SYMBOL_GPL(cx231xx_tuner_callback);
1117
1118static void cx231xx_reset_out(struct cx231xx *dev)
1119{
1120        cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
1121        msleep(200);
1122        cx231xx_set_gpio_value(dev, CX23417_RESET, 0);
1123        msleep(200);
1124        cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
1125}
1126
1127static void cx231xx_enable_OSC(struct cx231xx *dev)
1128{
1129        cx231xx_set_gpio_value(dev, CX23417_OSC_EN, 1);
1130}
1131
1132static void cx231xx_sleep_s5h1432(struct cx231xx *dev)
1133{
1134        cx231xx_set_gpio_value(dev, SLEEP_S5H1432, 0);
1135}
1136
1137static inline void cx231xx_set_model(struct cx231xx *dev)
1138{
1139        dev->board = cx231xx_boards[dev->model];
1140}
1141
1142/* Since cx231xx_pre_card_setup() requires a proper dev->model,
1143 * this won't work for boards with generic PCI IDs
1144 */
1145void cx231xx_pre_card_setup(struct cx231xx *dev)
1146{
1147        dev_info(dev->dev, "Identified as %s (card=%d)\n",
1148                dev->board.name, dev->model);
1149
1150        if (CX231XX_BOARD_ASTROMETA_T2HYBRID == dev->model) {
1151                /* turn on demodulator chip */
1152                cx231xx_set_gpio_value(dev, 0x03, 0x01);
1153        }
1154
1155        /* set the direction for GPIO pins */
1156        if (dev->board.tuner_gpio) {
1157                cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
1158                cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
1159        }
1160        if (dev->board.tuner_sif_gpio >= 0)
1161                cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
1162
1163        /* request some modules if any required */
1164
1165        /* set the mode to Analog mode initially */
1166        cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
1167
1168        /* Unlock device */
1169        /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */
1170
1171}
1172
1173static void cx231xx_config_tuner(struct cx231xx *dev)
1174{
1175        struct tuner_setup tun_setup;
1176        struct v4l2_frequency f;
1177
1178        if (dev->tuner_type == TUNER_ABSENT)
1179                return;
1180
1181        tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
1182        tun_setup.type = dev->tuner_type;
1183        tun_setup.addr = dev->tuner_addr;
1184        tun_setup.tuner_callback = cx231xx_tuner_callback;
1185
1186        tuner_call(dev, tuner, s_type_addr, &tun_setup);
1187
1188#if 0
1189        if (tun_setup.type == TUNER_XC5000) {
1190                static struct xc2028_ctrl ctrl = {
1191                        .fname = XC5000_DEFAULT_FIRMWARE,
1192                        .max_len = 64,
1193                        .demod = 0;
1194                };
1195                struct v4l2_priv_tun_config cfg = {
1196                        .tuner = dev->tuner_type,
1197                        .priv = &ctrl,
1198                };
1199                tuner_call(dev, tuner, s_config, &cfg);
1200        }
1201#endif
1202        /* configure tuner */
1203        f.tuner = 0;
1204        f.type = V4L2_TUNER_ANALOG_TV;
1205        f.frequency = 9076;     /* just a magic number */
1206        dev->ctl_freq = f.frequency;
1207        call_all(dev, tuner, s_frequency, &f);
1208
1209}
1210
1211static int read_eeprom(struct cx231xx *dev, struct i2c_client *client,
1212                       u8 *eedata, int len)
1213{
1214        int ret;
1215        u8 start_offset = 0;
1216        int len_todo = len;
1217        u8 *eedata_cur = eedata;
1218        int i;
1219        struct i2c_msg msg_write = { .addr = client->addr, .flags = 0,
1220                .buf = &start_offset, .len = 1 };
1221        struct i2c_msg msg_read = { .addr = client->addr, .flags = I2C_M_RD };
1222
1223        /* start reading at offset 0 */
1224        ret = i2c_transfer(client->adapter, &msg_write, 1);
1225        if (ret < 0) {
1226                dev_err(dev->dev, "Can't read eeprom\n");
1227                return ret;
1228        }
1229
1230        while (len_todo > 0) {
1231                msg_read.len = (len_todo > 64) ? 64 : len_todo;
1232                msg_read.buf = eedata_cur;
1233
1234                ret = i2c_transfer(client->adapter, &msg_read, 1);
1235                if (ret < 0) {
1236                        dev_err(dev->dev, "Can't read eeprom\n");
1237                        return ret;
1238                }
1239                eedata_cur += msg_read.len;
1240                len_todo -= msg_read.len;
1241        }
1242
1243        for (i = 0; i + 15 < len; i += 16)
1244                dev_dbg(dev->dev, "i2c eeprom %02x: %*ph\n",
1245                        i, 16, &eedata[i]);
1246
1247        return 0;
1248}
1249
1250void cx231xx_card_setup(struct cx231xx *dev)
1251{
1252
1253        cx231xx_set_model(dev);
1254
1255        dev->tuner_type = cx231xx_boards[dev->model].tuner_type;
1256        if (cx231xx_boards[dev->model].tuner_addr)
1257                dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr;
1258
1259        /* request some modules */
1260        if (dev->board.decoder == CX231XX_AVDECODER) {
1261                dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
1262                                        cx231xx_get_i2c_adap(dev, I2C_0),
1263                                        "cx25840", 0x88 >> 1, NULL);
1264                if (dev->sd_cx25840 == NULL)
1265                        dev_err(dev->dev,
1266                                "cx25840 subdev registration failure\n");
1267                cx25840_call(dev, core, load_fw);
1268
1269        }
1270
1271        /* Initialize the tuner */
1272        if (dev->board.tuner_type != TUNER_ABSENT) {
1273                struct i2c_adapter *tuner_i2c = cx231xx_get_i2c_adap(dev,
1274                                                dev->board.tuner_i2c_master);
1275                dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev,
1276                                                    tuner_i2c,
1277                                                    "tuner",
1278                                                    dev->tuner_addr, NULL);
1279                if (dev->sd_tuner == NULL)
1280                        dev_err(dev->dev,
1281                                "tuner subdev registration failure\n");
1282                else
1283                        cx231xx_config_tuner(dev);
1284        }
1285
1286        switch (dev->model) {
1287        case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx:
1288        case CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx:
1289        case CX231XX_BOARD_HAUPPAUGE_955Q:
1290        case CX231XX_BOARD_HAUPPAUGE_935C:
1291        case CX231XX_BOARD_HAUPPAUGE_975:
1292                {
1293                        struct eeprom {
1294                                struct tveeprom tvee;
1295                                u8 eeprom[256];
1296                                struct i2c_client client;
1297                        };
1298                        struct eeprom *e = kzalloc(sizeof(*e), GFP_KERNEL);
1299
1300                        if (e == NULL) {
1301                                dev_err(dev->dev,
1302                                        "failed to allocate memory to read eeprom\n");
1303                                break;
1304                        }
1305                        e->client.adapter = cx231xx_get_i2c_adap(dev, I2C_1_MUX_1);
1306                        e->client.addr = 0xa0 >> 1;
1307
1308                        read_eeprom(dev, &e->client, e->eeprom, sizeof(e->eeprom));
1309                        tveeprom_hauppauge_analog(&e->tvee, e->eeprom + 0xc0);
1310                        kfree(e);
1311                        break;
1312                }
1313        }
1314
1315}
1316
1317/*
1318 * cx231xx_config()
1319 * inits registers with sane defaults
1320 */
1321int cx231xx_config(struct cx231xx *dev)
1322{
1323        /* TBD need to add cx231xx specific code */
1324
1325        return 0;
1326}
1327
1328/*
1329 * cx231xx_config_i2c()
1330 * configure i2c attached devices
1331 */
1332void cx231xx_config_i2c(struct cx231xx *dev)
1333{
1334        /* u32 input = INPUT(dev->video_input)->vmux; */
1335
1336        call_all(dev, video, s_stream, 1);
1337}
1338
1339static void cx231xx_unregister_media_device(struct cx231xx *dev)
1340{
1341#ifdef CONFIG_MEDIA_CONTROLLER
1342        if (dev->media_dev) {
1343                media_device_unregister(dev->media_dev);
1344                media_device_cleanup(dev->media_dev);
1345                kfree(dev->media_dev);
1346                dev->media_dev = NULL;
1347        }
1348#endif
1349}
1350
1351/*
1352 * cx231xx_realease_resources()
1353 * unregisters the v4l2,i2c and usb devices
1354 * called when the device gets disconnected or at module unload
1355*/
1356void cx231xx_release_resources(struct cx231xx *dev)
1357{
1358        cx231xx_ir_exit(dev);
1359
1360        cx231xx_release_analog_resources(dev);
1361
1362        cx231xx_remove_from_devlist(dev);
1363
1364        /* Release I2C buses */
1365        cx231xx_dev_uninit(dev);
1366
1367        /* delete v4l2 device */
1368        v4l2_device_unregister(&dev->v4l2_dev);
1369
1370        cx231xx_unregister_media_device(dev);
1371
1372        usb_put_dev(dev->udev);
1373
1374        /* Mark device as unused */
1375        clear_bit(dev->devno, &cx231xx_devused);
1376}
1377
1378static int cx231xx_media_device_init(struct cx231xx *dev,
1379                                      struct usb_device *udev)
1380{
1381#ifdef CONFIG_MEDIA_CONTROLLER
1382        struct media_device *mdev;
1383
1384        mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
1385        if (!mdev)
1386                return -ENOMEM;
1387
1388        media_device_usb_init(mdev, udev, dev->board.name);
1389
1390        dev->media_dev = mdev;
1391#endif
1392        return 0;
1393}
1394
1395/*
1396 * cx231xx_init_dev()
1397 * allocates and inits the device structs, registers i2c bus and v4l device
1398 */
1399static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
1400                            int minor)
1401{
1402        int retval = -ENOMEM;
1403        unsigned int maxh, maxw;
1404
1405        dev->udev = udev;
1406        mutex_init(&dev->lock);
1407        mutex_init(&dev->ctrl_urb_lock);
1408        mutex_init(&dev->gpio_i2c_lock);
1409        mutex_init(&dev->i2c_lock);
1410
1411        spin_lock_init(&dev->video_mode.slock);
1412        spin_lock_init(&dev->vbi_mode.slock);
1413        spin_lock_init(&dev->sliced_cc_mode.slock);
1414
1415        init_waitqueue_head(&dev->open);
1416        init_waitqueue_head(&dev->wait_frame);
1417        init_waitqueue_head(&dev->wait_stream);
1418
1419        dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg;
1420        dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg;
1421        dev->cx231xx_send_usb_command = cx231xx_send_usb_command;
1422        dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read;
1423        dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write;
1424
1425        /* Query cx231xx to find what pcb config it is related to */
1426        retval = initialize_cx231xx(dev);
1427        if (retval < 0) {
1428                dev_err(dev->dev, "Failed to read PCB config\n");
1429                return retval;
1430        }
1431
1432        /*To workaround error number=-71 on EP0 for VideoGrabber,
1433                 need set alt here.*/
1434        if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER ||
1435            dev->model == CX231XX_BOARD_HAUPPAUGE_USBLIVE2) {
1436                cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
1437                cx231xx_set_alt_setting(dev, INDEX_VANC, 1);
1438        }
1439        /* Cx231xx pre card setup */
1440        cx231xx_pre_card_setup(dev);
1441
1442        retval = cx231xx_config(dev);
1443        if (retval) {
1444                dev_err(dev->dev, "error configuring device\n");
1445                return -ENOMEM;
1446        }
1447
1448        /* set default norm */
1449        dev->norm = dev->board.norm;
1450
1451        /* register i2c bus */
1452        retval = cx231xx_dev_init(dev);
1453        if (retval) {
1454                dev_err(dev->dev,
1455                        "%s: cx231xx_i2c_register - errCode [%d]!\n",
1456                        __func__, retval);
1457                goto err_dev_init;
1458        }
1459
1460        /* Do board specific init */
1461        cx231xx_card_setup(dev);
1462
1463        /* configure the device */
1464        cx231xx_config_i2c(dev);
1465
1466        maxw = norm_maxw(dev);
1467        maxh = norm_maxh(dev);
1468
1469        /* set default image size */
1470        dev->width = maxw;
1471        dev->height = maxh;
1472        dev->interlaced = 0;
1473        dev->video_input = 0;
1474
1475        retval = cx231xx_config(dev);
1476        if (retval) {
1477                dev_err(dev->dev, "%s: cx231xx_config - errCode [%d]!\n",
1478                        __func__, retval);
1479                goto err_dev_init;
1480        }
1481
1482        /* init video dma queue */
1483        INIT_LIST_HEAD(&dev->video_mode.vidq.active);
1484
1485        /* init vbi dma queue */
1486        INIT_LIST_HEAD(&dev->vbi_mode.vidq.active);
1487
1488        /* Reset other chips required if they are tied up with GPIO pins */
1489        cx231xx_add_into_devlist(dev);
1490
1491        if (dev->board.has_417) {
1492                dev_info(dev->dev, "attach 417 %d\n", dev->model);
1493                if (cx231xx_417_register(dev) < 0) {
1494                        dev_err(dev->dev,
1495                                "%s() Failed to register 417 on VID_B\n",
1496                                __func__);
1497                }
1498        }
1499
1500        retval = cx231xx_register_analog_devices(dev);
1501        if (retval)
1502                goto err_analog;
1503
1504        cx231xx_ir_init(dev);
1505
1506        cx231xx_init_extension(dev);
1507
1508        return 0;
1509err_analog:
1510        cx231xx_unregister_media_device(dev);
1511        cx231xx_release_analog_resources(dev);
1512        cx231xx_remove_from_devlist(dev);
1513err_dev_init:
1514        cx231xx_dev_uninit(dev);
1515        return retval;
1516}
1517
1518#if defined(CONFIG_MODULES) && defined(MODULE)
1519static void request_module_async(struct work_struct *work)
1520{
1521        struct cx231xx *dev = container_of(work,
1522                                           struct cx231xx, request_module_wk);
1523
1524        if (dev->has_alsa_audio)
1525                request_module("cx231xx-alsa");
1526
1527        if (dev->board.has_dvb)
1528                request_module("cx231xx-dvb");
1529
1530}
1531
1532static void request_modules(struct cx231xx *dev)
1533{
1534        INIT_WORK(&dev->request_module_wk, request_module_async);
1535        schedule_work(&dev->request_module_wk);
1536}
1537
1538static void flush_request_modules(struct cx231xx *dev)
1539{
1540        flush_work(&dev->request_module_wk);
1541}
1542#else
1543#define request_modules(dev)
1544#define flush_request_modules(dev)
1545#endif /* CONFIG_MODULES */
1546
1547static int cx231xx_init_v4l2(struct cx231xx *dev,
1548                             struct usb_device *udev,
1549                             struct usb_interface *interface,
1550                             int isoc_pipe)
1551{
1552        struct usb_interface *uif;
1553        int i, idx;
1554
1555        /* Video Init */
1556
1557        /* compute alternate max packet sizes for video */
1558        idx = dev->current_pcb_config.hs_config_info[0].interface_info.video_index + 1;
1559        if (idx >= dev->max_iad_interface_count) {
1560                dev_err(dev->dev,
1561                        "Video PCB interface #%d doesn't exist\n", idx);
1562                return -ENODEV;
1563        }
1564
1565        uif = udev->actconfig->interface[idx];
1566
1567        if (uif->altsetting[0].desc.bNumEndpoints < isoc_pipe + 1)
1568                return -ENODEV;
1569
1570        dev->video_mode.end_point_addr = uif->altsetting[0].endpoint[isoc_pipe].desc.bEndpointAddress;
1571        dev->video_mode.num_alt = uif->num_altsetting;
1572
1573        dev_info(dev->dev,
1574                 "video EndPoint Addr 0x%x, Alternate settings: %i\n",
1575                 dev->video_mode.end_point_addr,
1576                 dev->video_mode.num_alt);
1577
1578        dev->video_mode.alt_max_pkt_size = devm_kmalloc_array(&udev->dev, 32, dev->video_mode.num_alt, GFP_KERNEL);
1579        if (dev->video_mode.alt_max_pkt_size == NULL)
1580                return -ENOMEM;
1581
1582        for (i = 0; i < dev->video_mode.num_alt; i++) {
1583                u16 tmp;
1584
1585                if (uif->altsetting[i].desc.bNumEndpoints < isoc_pipe + 1)
1586                        return -ENODEV;
1587
1588                tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].desc.wMaxPacketSize);
1589                dev->video_mode.alt_max_pkt_size[i] = (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1590                dev_dbg(dev->dev,
1591                        "Alternate setting %i, max size= %i\n", i,
1592                        dev->video_mode.alt_max_pkt_size[i]);
1593        }
1594
1595        /* VBI Init */
1596
1597        idx = dev->current_pcb_config.hs_config_info[0].interface_info.vanc_index + 1;
1598        if (idx >= dev->max_iad_interface_count) {
1599                dev_err(dev->dev,
1600                        "VBI PCB interface #%d doesn't exist\n", idx);
1601                return -ENODEV;
1602        }
1603        uif = udev->actconfig->interface[idx];
1604
1605        if (uif->altsetting[0].desc.bNumEndpoints < isoc_pipe + 1)
1606                return -ENODEV;
1607
1608        dev->vbi_mode.end_point_addr =
1609            uif->altsetting[0].endpoint[isoc_pipe].desc.
1610                        bEndpointAddress;
1611
1612        dev->vbi_mode.num_alt = uif->num_altsetting;
1613        dev_info(dev->dev,
1614                 "VBI EndPoint Addr 0x%x, Alternate settings: %i\n",
1615                 dev->vbi_mode.end_point_addr,
1616                 dev->vbi_mode.num_alt);
1617
1618        /* compute alternate max packet sizes for vbi */
1619        dev->vbi_mode.alt_max_pkt_size = devm_kmalloc_array(&udev->dev, 32, dev->vbi_mode.num_alt, GFP_KERNEL);
1620        if (dev->vbi_mode.alt_max_pkt_size == NULL)
1621                return -ENOMEM;
1622
1623        for (i = 0; i < dev->vbi_mode.num_alt; i++) {
1624                u16 tmp;
1625
1626                if (uif->altsetting[i].desc.bNumEndpoints < isoc_pipe + 1)
1627                        return -ENODEV;
1628
1629                tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1630                                desc.wMaxPacketSize);
1631                dev->vbi_mode.alt_max_pkt_size[i] =
1632                    (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1633                dev_dbg(dev->dev,
1634                        "Alternate setting %i, max size= %i\n", i,
1635                        dev->vbi_mode.alt_max_pkt_size[i]);
1636        }
1637
1638        /* Sliced CC VBI init */
1639
1640        /* compute alternate max packet sizes for sliced CC */
1641        idx = dev->current_pcb_config.hs_config_info[0].interface_info.hanc_index + 1;
1642        if (idx >= dev->max_iad_interface_count) {
1643                dev_err(dev->dev,
1644                        "Sliced CC PCB interface #%d doesn't exist\n", idx);
1645                return -ENODEV;
1646        }
1647        uif = udev->actconfig->interface[idx];
1648
1649        if (uif->altsetting[0].desc.bNumEndpoints < isoc_pipe + 1)
1650                return -ENODEV;
1651
1652        dev->sliced_cc_mode.end_point_addr =
1653            uif->altsetting[0].endpoint[isoc_pipe].desc.
1654                        bEndpointAddress;
1655
1656        dev->sliced_cc_mode.num_alt = uif->num_altsetting;
1657        dev_info(dev->dev,
1658                 "sliced CC EndPoint Addr 0x%x, Alternate settings: %i\n",
1659                 dev->sliced_cc_mode.end_point_addr,
1660                 dev->sliced_cc_mode.num_alt);
1661        dev->sliced_cc_mode.alt_max_pkt_size = devm_kmalloc_array(&udev->dev, 32, dev->sliced_cc_mode.num_alt, GFP_KERNEL);
1662        if (dev->sliced_cc_mode.alt_max_pkt_size == NULL)
1663                return -ENOMEM;
1664
1665        for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
1666                u16 tmp;
1667
1668                if (uif->altsetting[i].desc.bNumEndpoints < isoc_pipe + 1)
1669                        return -ENODEV;
1670
1671                tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1672                                desc.wMaxPacketSize);
1673                dev->sliced_cc_mode.alt_max_pkt_size[i] =
1674                    (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1675                dev_dbg(dev->dev,
1676                        "Alternate setting %i, max size= %i\n", i,
1677                        dev->sliced_cc_mode.alt_max_pkt_size[i]);
1678        }
1679
1680        return 0;
1681}
1682
1683/*
1684 * cx231xx_usb_probe()
1685 * checks for supported devices
1686 */
1687static int cx231xx_usb_probe(struct usb_interface *interface,
1688                             const struct usb_device_id *id)
1689{
1690        struct usb_device *udev;
1691        struct device *d = &interface->dev;
1692        struct usb_interface *uif;
1693        struct cx231xx *dev = NULL;
1694        int retval = -ENODEV;
1695        int nr = 0, ifnum;
1696        int i, isoc_pipe = 0;
1697        char *speed;
1698        u8 idx;
1699        struct usb_interface_assoc_descriptor *assoc_desc;
1700
1701        ifnum = interface->altsetting[0].desc.bInterfaceNumber;
1702
1703        /*
1704         * Interface number 0 - IR interface (handled by mceusb driver)
1705         * Interface number 1 - AV interface (handled by this driver)
1706         */
1707        if (ifnum != 1)
1708                return -ENODEV;
1709
1710        /* Check to see next free device and mark as used */
1711        do {
1712                nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
1713                if (nr >= CX231XX_MAXBOARDS) {
1714                        /* No free device slots */
1715                        dev_err(d,
1716                                "Supports only %i devices.\n",
1717                                CX231XX_MAXBOARDS);
1718                        return -ENOMEM;
1719                }
1720        } while (test_and_set_bit(nr, &cx231xx_devused));
1721
1722        udev = usb_get_dev(interface_to_usbdev(interface));
1723
1724        /* allocate memory for our device state and initialize it */
1725        dev = devm_kzalloc(&udev->dev, sizeof(*dev), GFP_KERNEL);
1726        if (dev == NULL) {
1727                retval = -ENOMEM;
1728                goto err_if;
1729        }
1730
1731        snprintf(dev->name, 29, "cx231xx #%d", nr);
1732        dev->devno = nr;
1733        dev->model = id->driver_info;
1734        dev->video_mode.alt = -1;
1735        dev->dev = d;
1736
1737        cx231xx_set_model(dev);
1738
1739        dev->interface_count++;
1740        /* reset gpio dir and value */
1741        dev->gpio_dir = 0;
1742        dev->gpio_val = 0;
1743        dev->xc_fw_load_done = 0;
1744        dev->has_alsa_audio = 1;
1745        dev->power_mode = -1;
1746        atomic_set(&dev->devlist_count, 0);
1747
1748        /* 0 - vbi ; 1 -sliced cc mode */
1749        dev->vbi_or_sliced_cc_mode = 0;
1750
1751        /* get maximum no.of IAD interfaces */
1752        dev->max_iad_interface_count = udev->config->desc.bNumInterfaces;
1753
1754        /* init CIR module TBD */
1755
1756        /*mode_tv: digital=1 or analog=0*/
1757        dev->mode_tv = 0;
1758
1759        dev->USE_ISO = transfer_mode;
1760
1761        switch (udev->speed) {
1762        case USB_SPEED_LOW:
1763                speed = "1.5";
1764                break;
1765        case USB_SPEED_UNKNOWN:
1766        case USB_SPEED_FULL:
1767                speed = "12";
1768                break;
1769        case USB_SPEED_HIGH:
1770                speed = "480";
1771                break;
1772        default:
1773                speed = "unknown";
1774        }
1775
1776        dev_info(d,
1777                 "New device %s %s @ %s Mbps (%04x:%04x) with %d interfaces\n",
1778                 udev->manufacturer ? udev->manufacturer : "",
1779                 udev->product ? udev->product : "",
1780                 speed,
1781                 le16_to_cpu(udev->descriptor.idVendor),
1782                 le16_to_cpu(udev->descriptor.idProduct),
1783                 dev->max_iad_interface_count);
1784
1785        /* increment interface count */
1786        dev->interface_count++;
1787
1788        /* get device number */
1789        nr = dev->devno;
1790
1791        assoc_desc = udev->actconfig->intf_assoc[0];
1792        if (!assoc_desc || assoc_desc->bFirstInterface != ifnum) {
1793                dev_err(d, "Not found matching IAD interface\n");
1794                retval = -ENODEV;
1795                goto err_if;
1796        }
1797
1798        dev_dbg(d, "registering interface %d\n", ifnum);
1799
1800        /* save our data pointer in this interface device */
1801        usb_set_intfdata(interface, dev);
1802
1803        /* Initialize the media controller */
1804        retval = cx231xx_media_device_init(dev, udev);
1805        if (retval) {
1806                dev_err(d, "cx231xx_media_device_init failed\n");
1807                goto err_media_init;
1808        }
1809
1810        /* Create v4l2 device */
1811#ifdef CONFIG_MEDIA_CONTROLLER
1812        dev->v4l2_dev.mdev = dev->media_dev;
1813#endif
1814        retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
1815        if (retval) {
1816                dev_err(d, "v4l2_device_register failed\n");
1817                goto err_v4l2;
1818        }
1819
1820        /* allocate device struct */
1821        retval = cx231xx_init_dev(dev, udev, nr);
1822        if (retval)
1823                goto err_init;
1824
1825        retval = cx231xx_init_v4l2(dev, udev, interface, isoc_pipe);
1826        if (retval)
1827                goto err_init;
1828
1829        if (dev->current_pcb_config.ts1_source != 0xff) {
1830                /* compute alternate max packet sizes for TS1 */
1831                idx = dev->current_pcb_config.hs_config_info[0].interface_info.ts1_index + 1;
1832                if (idx >= dev->max_iad_interface_count) {
1833                        dev_err(d, "TS1 PCB interface #%d doesn't exist\n",
1834                                idx);
1835                        retval = -ENODEV;
1836                        goto err_video_alt;
1837                }
1838                uif = udev->actconfig->interface[idx];
1839
1840                if (uif->altsetting[0].desc.bNumEndpoints < isoc_pipe + 1) {
1841                        retval = -ENODEV;
1842                        goto err_video_alt;
1843                }
1844
1845                dev->ts1_mode.end_point_addr =
1846                    uif->altsetting[0].endpoint[isoc_pipe].
1847                                desc.bEndpointAddress;
1848
1849                dev->ts1_mode.num_alt = uif->num_altsetting;
1850                dev_info(d,
1851                         "TS EndPoint Addr 0x%x, Alternate settings: %i\n",
1852                         dev->ts1_mode.end_point_addr,
1853                         dev->ts1_mode.num_alt);
1854
1855                dev->ts1_mode.alt_max_pkt_size = devm_kmalloc_array(&udev->dev, 32, dev->ts1_mode.num_alt, GFP_KERNEL);
1856                if (dev->ts1_mode.alt_max_pkt_size == NULL) {
1857                        retval = -ENOMEM;
1858                        goto err_video_alt;
1859                }
1860
1861                for (i = 0; i < dev->ts1_mode.num_alt; i++) {
1862                        u16 tmp;
1863
1864                        if (uif->altsetting[i].desc.bNumEndpoints < isoc_pipe + 1) {
1865                                retval = -ENODEV;
1866                                goto err_video_alt;
1867                        }
1868
1869                        tmp = le16_to_cpu(uif->altsetting[i].
1870                                                endpoint[isoc_pipe].desc.
1871                                                wMaxPacketSize);
1872                        dev->ts1_mode.alt_max_pkt_size[i] =
1873                            (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1874                        dev_dbg(d, "Alternate setting %i, max size= %i\n",
1875                                i, dev->ts1_mode.alt_max_pkt_size[i]);
1876                }
1877        }
1878
1879        if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) {
1880                cx231xx_enable_OSC(dev);
1881                cx231xx_reset_out(dev);
1882                cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
1883        }
1884
1885        if (dev->model == CX231XX_BOARD_CNXT_RDE_253S)
1886                cx231xx_sleep_s5h1432(dev);
1887
1888        /* load other modules required */
1889        request_modules(dev);
1890
1891#ifdef CONFIG_MEDIA_CONTROLLER
1892        /* Init entities at the Media Controller */
1893        cx231xx_v4l2_create_entities(dev);
1894
1895        retval = v4l2_mc_create_media_graph(dev->media_dev);
1896        if (!retval)
1897                retval = media_device_register(dev->media_dev);
1898#endif
1899        if (retval < 0)
1900                cx231xx_release_resources(dev);
1901        return retval;
1902
1903err_video_alt:
1904        /* cx231xx_uninit_dev: */
1905        cx231xx_close_extension(dev);
1906        cx231xx_ir_exit(dev);
1907        cx231xx_release_analog_resources(dev);
1908        cx231xx_417_unregister(dev);
1909        cx231xx_remove_from_devlist(dev);
1910        cx231xx_dev_uninit(dev);
1911err_init:
1912        v4l2_device_unregister(&dev->v4l2_dev);
1913err_v4l2:
1914        cx231xx_unregister_media_device(dev);
1915err_media_init:
1916        usb_set_intfdata(interface, NULL);
1917err_if:
1918        usb_put_dev(udev);
1919        clear_bit(nr, &cx231xx_devused);
1920        return retval;
1921}
1922
1923/*
1924 * cx231xx_usb_disconnect()
1925 * called when the device gets disconnected
1926 * video device will be unregistered on v4l2_close in case it is still open
1927 */
1928static void cx231xx_usb_disconnect(struct usb_interface *interface)
1929{
1930        struct cx231xx *dev;
1931
1932        dev = usb_get_intfdata(interface);
1933        usb_set_intfdata(interface, NULL);
1934
1935        if (!dev)
1936                return;
1937
1938        if (!dev->udev)
1939                return;
1940
1941        dev->state |= DEV_DISCONNECTED;
1942
1943        flush_request_modules(dev);
1944
1945        /* wait until all current v4l2 io is finished then deallocate
1946           resources */
1947        mutex_lock(&dev->lock);
1948
1949        wake_up_interruptible_all(&dev->open);
1950
1951        if (dev->users) {
1952                dev_warn(dev->dev,
1953                         "device %s is open! Deregistration and memory deallocation are deferred on close.\n",
1954                         video_device_node_name(&dev->vdev));
1955
1956                /* Even having users, it is safe to remove the RC i2c driver */
1957                cx231xx_ir_exit(dev);
1958
1959                if (dev->USE_ISO)
1960                        cx231xx_uninit_isoc(dev);
1961                else
1962                        cx231xx_uninit_bulk(dev);
1963                wake_up_interruptible(&dev->wait_frame);
1964                wake_up_interruptible(&dev->wait_stream);
1965        } else {
1966        }
1967
1968        cx231xx_close_extension(dev);
1969
1970        mutex_unlock(&dev->lock);
1971
1972        if (!dev->users)
1973                cx231xx_release_resources(dev);
1974}
1975
1976static struct usb_driver cx231xx_usb_driver = {
1977        .name = "cx231xx",
1978        .probe = cx231xx_usb_probe,
1979        .disconnect = cx231xx_usb_disconnect,
1980        .id_table = cx231xx_id_table,
1981};
1982
1983module_usb_driver(cx231xx_usb_driver);
1984