linux/drivers/media/usb/go7007/go7007-usb.c
<<
>>
Prefs
   1/*
   2 * Copyright (C) 2005-2006 Micronas USA Inc.
   3 *
   4 * This program is free software; you can redistribute it and/or modify
   5 * it under the terms of the GNU General Public License (Version 2) as
   6 * published by the Free Software Foundation.
   7 *
   8 * This program is distributed in the hope that it will be useful,
   9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11 * GNU General Public License for more details.
  12 */
  13
  14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  15
  16#include <linux/module.h>
  17#include <linux/kernel.h>
  18#include <linux/wait.h>
  19#include <linux/list.h>
  20#include <linux/slab.h>
  21#include <linux/time.h>
  22#include <linux/mm.h>
  23#include <linux/usb.h>
  24#include <linux/i2c.h>
  25#include <asm/byteorder.h>
  26#include <media/saa7115.h>
  27#include <media/tuner.h>
  28#include <media/uda1342.h>
  29
  30#include "go7007-priv.h"
  31
  32static unsigned int assume_endura;
  33module_param(assume_endura, int, 0644);
  34MODULE_PARM_DESC(assume_endura,
  35                        "when probing fails, hardware is a Pelco Endura");
  36
  37/* #define GO7007_I2C_DEBUG */ /* for debugging the EZ-USB I2C adapter */
  38
  39#define HPI_STATUS_ADDR 0xFFF4
  40#define INT_PARAM_ADDR  0xFFF6
  41#define INT_INDEX_ADDR  0xFFF8
  42
  43/*
  44 * Pipes on EZ-USB interface:
  45 *      0 snd - Control
  46 *      0 rcv - Control
  47 *      2 snd - Download firmware (control)
  48 *      4 rcv - Read Interrupt (interrupt)
  49 *      6 rcv - Read Video (bulk)
  50 *      8 rcv - Read Audio (bulk)
  51 */
  52
  53#define GO7007_USB_EZUSB                (1<<0)
  54#define GO7007_USB_EZUSB_I2C            (1<<1)
  55
  56struct go7007_usb_board {
  57        unsigned int flags;
  58        struct go7007_board_info main_info;
  59};
  60
  61struct go7007_usb {
  62        const struct go7007_usb_board *board;
  63        struct mutex i2c_lock;
  64        struct usb_device *usbdev;
  65        struct urb *video_urbs[8];
  66        struct urb *audio_urbs[8];
  67        struct urb *intr_urb;
  68};
  69
  70/*********************** Product specification data ***********************/
  71
  72static const struct go7007_usb_board board_matrix_ii = {
  73        .flags          = GO7007_USB_EZUSB,
  74        .main_info      = {
  75                .flags           = GO7007_BOARD_HAS_AUDIO |
  76                                        GO7007_BOARD_USE_ONBOARD_I2C,
  77                .audio_flags     = GO7007_AUDIO_I2S_MODE_1 |
  78                                        GO7007_AUDIO_WORD_16,
  79                .audio_rate      = 48000,
  80                .audio_bclk_div  = 8,
  81                .audio_main_div  = 2,
  82                .hpi_buffer_cap  = 7,
  83                .sensor_flags    = GO7007_SENSOR_656 |
  84                                        GO7007_SENSOR_VALID_ENABLE |
  85                                        GO7007_SENSOR_TV |
  86                                        GO7007_SENSOR_SAA7115 |
  87                                        GO7007_SENSOR_VBI |
  88                                        GO7007_SENSOR_SCALING,
  89                .num_i2c_devs    = 1,
  90                .i2c_devs        = {
  91                        {
  92                                .type   = "saa7115",
  93                                .addr   = 0x20,
  94                                .is_video = 1,
  95                        },
  96                },
  97                .num_inputs      = 2,
  98                .inputs          = {
  99                        {
 100                                .video_input    = 0,
 101                                .name           = "Composite",
 102                        },
 103                        {
 104                                .video_input    = 9,
 105                                .name           = "S-Video",
 106                        },
 107                },
 108                .video_config   = SAA7115_IDQ_IS_DEFAULT,
 109        },
 110};
 111
 112static const struct go7007_usb_board board_matrix_reload = {
 113        .flags          = GO7007_USB_EZUSB,
 114        .main_info      = {
 115                .flags           = GO7007_BOARD_HAS_AUDIO |
 116                                        GO7007_BOARD_USE_ONBOARD_I2C,
 117                .audio_flags     = GO7007_AUDIO_I2S_MODE_1 |
 118                                        GO7007_AUDIO_I2S_MASTER |
 119                                        GO7007_AUDIO_WORD_16,
 120                .audio_rate      = 48000,
 121                .audio_bclk_div  = 8,
 122                .audio_main_div  = 2,
 123                .hpi_buffer_cap  = 7,
 124                .sensor_flags    = GO7007_SENSOR_656 |
 125                                        GO7007_SENSOR_TV,
 126                .num_i2c_devs    = 1,
 127                .i2c_devs        = {
 128                        {
 129                                .type   = "saa7113",
 130                                .addr   = 0x25,
 131                                .is_video = 1,
 132                        },
 133                },
 134                .num_inputs      = 2,
 135                .inputs          = {
 136                        {
 137                                .video_input    = 0,
 138                                .name           = "Composite",
 139                        },
 140                        {
 141                                .video_input    = 9,
 142                                .name           = "S-Video",
 143                        },
 144                },
 145                .video_config   = SAA7115_IDQ_IS_DEFAULT,
 146        },
 147};
 148
 149static const struct go7007_usb_board board_star_trek = {
 150        .flags          = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
 151        .main_info      = {
 152                .flags           = GO7007_BOARD_HAS_AUDIO, /* |
 153                                        GO7007_BOARD_HAS_TUNER, */
 154                .sensor_flags    = GO7007_SENSOR_656 |
 155                                        GO7007_SENSOR_VALID_ENABLE |
 156                                        GO7007_SENSOR_TV |
 157                                        GO7007_SENSOR_SAA7115 |
 158                                        GO7007_SENSOR_VBI |
 159                                        GO7007_SENSOR_SCALING,
 160                .audio_flags     = GO7007_AUDIO_I2S_MODE_1 |
 161                                        GO7007_AUDIO_WORD_16,
 162                .audio_bclk_div  = 8,
 163                .audio_main_div  = 2,
 164                .hpi_buffer_cap  = 7,
 165                .num_i2c_devs    = 1,
 166                .i2c_devs        = {
 167                        {
 168                                .type   = "saa7115",
 169                                .addr   = 0x20,
 170                                .is_video = 1,
 171                        },
 172                },
 173                .num_inputs      = 2,
 174                .inputs          = {
 175                /*      {
 176                 *              .video_input    = 3,
 177                 *              .audio_index    = AUDIO_TUNER,
 178                 *              .name           = "Tuner",
 179                 *      },
 180                 */
 181                        {
 182                                .video_input    = 1,
 183                        /*      .audio_index    = AUDIO_EXTERN, */
 184                                .name           = "Composite",
 185                        },
 186                        {
 187                                .video_input    = 8,
 188                        /*      .audio_index    = AUDIO_EXTERN, */
 189                                .name           = "S-Video",
 190                        },
 191                },
 192                .video_config   = SAA7115_IDQ_IS_DEFAULT,
 193        },
 194};
 195
 196static const struct go7007_usb_board board_px_tv402u = {
 197        .flags          = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
 198        .main_info      = {
 199                .flags           = GO7007_BOARD_HAS_AUDIO |
 200                                        GO7007_BOARD_HAS_TUNER,
 201                .sensor_flags    = GO7007_SENSOR_656 |
 202                                        GO7007_SENSOR_VALID_ENABLE |
 203                                        GO7007_SENSOR_TV |
 204                                        GO7007_SENSOR_SAA7115 |
 205                                        GO7007_SENSOR_VBI |
 206                                        GO7007_SENSOR_SCALING,
 207                .audio_flags     = GO7007_AUDIO_I2S_MODE_1 |
 208                                        GO7007_AUDIO_WORD_16,
 209                .audio_bclk_div  = 8,
 210                .audio_main_div  = 2,
 211                .hpi_buffer_cap  = 7,
 212                .num_i2c_devs    = 5,
 213                .i2c_devs        = {
 214                        {
 215                                .type   = "saa7115",
 216                                .addr   = 0x20,
 217                                .is_video = 1,
 218                        },
 219                        {
 220                                .type   = "uda1342",
 221                                .addr   = 0x1a,
 222                                .is_audio = 1,
 223                        },
 224                        {
 225                                .type   = "tuner",
 226                                .addr   = 0x60,
 227                        },
 228                        {
 229                                .type   = "tuner",
 230                                .addr   = 0x43,
 231                        },
 232                        {
 233                                .type   = "sony-btf-mpx",
 234                                .addr   = 0x44,
 235                        },
 236                },
 237                .num_inputs      = 3,
 238                .inputs          = {
 239                        {
 240                                .video_input    = 3,
 241                                .audio_index    = 0,
 242                                .name           = "Tuner",
 243                        },
 244                        {
 245                                .video_input    = 1,
 246                                .audio_index    = 1,
 247                                .name           = "Composite",
 248                        },
 249                        {
 250                                .video_input    = 8,
 251                                .audio_index    = 1,
 252                                .name           = "S-Video",
 253                        },
 254                },
 255                .video_config   = SAA7115_IDQ_IS_DEFAULT,
 256                .num_aud_inputs  = 2,
 257                .aud_inputs      = {
 258                        {
 259                                .audio_input    = UDA1342_IN2,
 260                                .name           = "Tuner",
 261                        },
 262                        {
 263                                .audio_input    = UDA1342_IN1,
 264                                .name           = "Line In",
 265                        },
 266                },
 267        },
 268};
 269
 270static const struct go7007_usb_board board_xmen = {
 271        .flags          = 0,
 272        .main_info      = {
 273                .flags            = GO7007_BOARD_USE_ONBOARD_I2C,
 274                .hpi_buffer_cap   = 0,
 275                .sensor_flags     = GO7007_SENSOR_VREF_POLAR,
 276                .sensor_width     = 320,
 277                .sensor_height    = 240,
 278                .sensor_framerate = 30030,
 279                .audio_flags      = GO7007_AUDIO_ONE_CHANNEL |
 280                                        GO7007_AUDIO_I2S_MODE_3 |
 281                                        GO7007_AUDIO_WORD_14 |
 282                                        GO7007_AUDIO_I2S_MASTER |
 283                                        GO7007_AUDIO_BCLK_POLAR |
 284                                        GO7007_AUDIO_OKI_MODE,
 285                .audio_rate       = 8000,
 286                .audio_bclk_div   = 48,
 287                .audio_main_div   = 1,
 288                .num_i2c_devs     = 1,
 289                .i2c_devs         = {
 290                        {
 291                                .type   = "ov7640",
 292                                .addr   = 0x21,
 293                        },
 294                },
 295                .num_inputs       = 1,
 296                .inputs           = {
 297                        {
 298                                .name           = "Camera",
 299                        },
 300                },
 301        },
 302};
 303
 304static const struct go7007_usb_board board_matrix_revolution = {
 305        .flags          = GO7007_USB_EZUSB,
 306        .main_info      = {
 307                .flags           = GO7007_BOARD_HAS_AUDIO |
 308                                        GO7007_BOARD_USE_ONBOARD_I2C,
 309                .audio_flags     = GO7007_AUDIO_I2S_MODE_1 |
 310                                        GO7007_AUDIO_I2S_MASTER |
 311                                        GO7007_AUDIO_WORD_16,
 312                .audio_rate      = 48000,
 313                .audio_bclk_div  = 8,
 314                .audio_main_div  = 2,
 315                .hpi_buffer_cap  = 7,
 316                .sensor_flags    = GO7007_SENSOR_656 |
 317                                        GO7007_SENSOR_TV |
 318                                        GO7007_SENSOR_VBI,
 319                .num_i2c_devs    = 1,
 320                .i2c_devs        = {
 321                        {
 322                                .type   = "tw9903",
 323                                .is_video = 1,
 324                                .addr   = 0x44,
 325                        },
 326                },
 327                .num_inputs      = 2,
 328                .inputs          = {
 329                        {
 330                                .video_input    = 2,
 331                                .name           = "Composite",
 332                        },
 333                        {
 334                                .video_input    = 8,
 335                                .name           = "S-Video",
 336                        },
 337                },
 338        },
 339};
 340
 341static const struct go7007_usb_board board_lifeview_lr192 = {
 342        .flags          = GO7007_USB_EZUSB,
 343        .main_info      = {
 344                .flags           = GO7007_BOARD_HAS_AUDIO |
 345                                        GO7007_BOARD_USE_ONBOARD_I2C,
 346                .audio_flags     = GO7007_AUDIO_I2S_MODE_1 |
 347                                        GO7007_AUDIO_WORD_16,
 348                .audio_rate      = 48000,
 349                .audio_bclk_div  = 8,
 350                .audio_main_div  = 2,
 351                .hpi_buffer_cap  = 7,
 352                .sensor_flags    = GO7007_SENSOR_656 |
 353                                        GO7007_SENSOR_VALID_ENABLE |
 354                                        GO7007_SENSOR_TV |
 355                                        GO7007_SENSOR_VBI |
 356                                        GO7007_SENSOR_SCALING,
 357                .num_i2c_devs    = 0,
 358                .num_inputs      = 1,
 359                .inputs          = {
 360                        {
 361                                .video_input    = 0,
 362                                .name           = "Composite",
 363                        },
 364                },
 365        },
 366};
 367
 368static const struct go7007_usb_board board_endura = {
 369        .flags          = 0,
 370        .main_info      = {
 371                .flags           = 0,
 372                .audio_flags     = GO7007_AUDIO_I2S_MODE_1 |
 373                                        GO7007_AUDIO_I2S_MASTER |
 374                                        GO7007_AUDIO_WORD_16,
 375                .audio_rate      = 8000,
 376                .audio_bclk_div  = 48,
 377                .audio_main_div  = 8,
 378                .hpi_buffer_cap  = 0,
 379                .sensor_flags    = GO7007_SENSOR_656 |
 380                                        GO7007_SENSOR_TV,
 381                .sensor_h_offset = 8,
 382                .num_i2c_devs    = 0,
 383                .num_inputs      = 1,
 384                .inputs          = {
 385                        {
 386                                .name           = "Camera",
 387                        },
 388                },
 389        },
 390};
 391
 392static const struct go7007_usb_board board_adlink_mpg24 = {
 393        .flags          = 0,
 394        .main_info      = {
 395                .flags           = GO7007_BOARD_USE_ONBOARD_I2C,
 396                .audio_flags     = GO7007_AUDIO_I2S_MODE_1 |
 397                                        GO7007_AUDIO_I2S_MASTER |
 398                                        GO7007_AUDIO_WORD_16,
 399                .audio_rate      = 48000,
 400                .audio_bclk_div  = 8,
 401                .audio_main_div  = 2,
 402                .hpi_buffer_cap  = 0,
 403                .sensor_flags    = GO7007_SENSOR_656 |
 404                                        GO7007_SENSOR_TV |
 405                                        GO7007_SENSOR_VBI,
 406                .num_i2c_devs    = 1,
 407                .i2c_devs        = {
 408                        {
 409                                .type   = "tw2804",
 410                                .addr   = 0x00, /* yes, really */
 411                                .flags  = I2C_CLIENT_TEN,
 412                                .is_video = 1,
 413                        },
 414                },
 415                .num_inputs      = 1,
 416                .inputs          = {
 417                        {
 418                                .name           = "Composite",
 419                        },
 420                },
 421        },
 422};
 423
 424static const struct go7007_usb_board board_sensoray_2250 = {
 425        .flags          = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
 426        .main_info      = {
 427                .audio_flags     = GO7007_AUDIO_I2S_MODE_1 |
 428                                        GO7007_AUDIO_I2S_MASTER |
 429                                        GO7007_AUDIO_WORD_16,
 430                .flags           = GO7007_BOARD_HAS_AUDIO,
 431                .audio_rate      = 48000,
 432                .audio_bclk_div  = 8,
 433                .audio_main_div  = 2,
 434                .hpi_buffer_cap  = 7,
 435                .sensor_flags    = GO7007_SENSOR_656 |
 436                                        GO7007_SENSOR_TV,
 437                .num_i2c_devs    = 1,
 438                .i2c_devs        = {
 439                        {
 440                                .type   = "s2250",
 441                                .addr   = 0x43,
 442                                .is_video = 1,
 443                                .is_audio = 1,
 444                        },
 445                },
 446                .num_inputs      = 2,
 447                .inputs          = {
 448                        {
 449                                .video_input    = 0,
 450                                .name           = "Composite",
 451                        },
 452                        {
 453                                .video_input    = 1,
 454                                .name           = "S-Video",
 455                        },
 456                },
 457                .num_aud_inputs  = 3,
 458                .aud_inputs      = {
 459                        {
 460                                .audio_input    = 0,
 461                                .name           = "Line In",
 462                        },
 463                        {
 464                                .audio_input    = 1,
 465                                .name           = "Mic",
 466                        },
 467                        {
 468                                .audio_input    = 2,
 469                                .name           = "Mic Boost",
 470                        },
 471                },
 472        },
 473};
 474
 475static const struct go7007_usb_board board_ads_usbav_709 = {
 476        .flags          = GO7007_USB_EZUSB,
 477        .main_info      = {
 478                .flags           = GO7007_BOARD_HAS_AUDIO |
 479                                        GO7007_BOARD_USE_ONBOARD_I2C,
 480                .audio_flags     = GO7007_AUDIO_I2S_MODE_1 |
 481                                        GO7007_AUDIO_I2S_MASTER |
 482                                        GO7007_AUDIO_WORD_16,
 483                .audio_rate      = 48000,
 484                .audio_bclk_div  = 8,
 485                .audio_main_div  = 2,
 486                .hpi_buffer_cap  = 7,
 487                .sensor_flags    = GO7007_SENSOR_656 |
 488                                        GO7007_SENSOR_TV |
 489                                        GO7007_SENSOR_VBI,
 490                .num_i2c_devs    = 1,
 491                .i2c_devs        = {
 492                        {
 493                                .type   = "tw9906",
 494                                .is_video = 1,
 495                                .addr   = 0x44,
 496                        },
 497                },
 498                .num_inputs      = 2,
 499                .inputs          = {
 500                        {
 501                                .video_input    = 0,
 502                                .name           = "Composite",
 503                        },
 504                        {
 505                                .video_input    = 10,
 506                                .name           = "S-Video",
 507                        },
 508                },
 509        },
 510};
 511
 512static const struct usb_device_id go7007_usb_id_table[] = {
 513        {
 514                .match_flags    = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
 515                                        USB_DEVICE_ID_MATCH_INT_INFO,
 516                .idVendor       = 0x0eb1,  /* Vendor ID of WIS Technologies */
 517                .idProduct      = 0x7007,  /* Product ID of GO7007SB chip */
 518                .bcdDevice_lo   = 0x200,   /* Revision number of XMen */
 519                .bcdDevice_hi   = 0x200,
 520                .bInterfaceClass        = 255,
 521                .bInterfaceSubClass     = 0,
 522                .bInterfaceProtocol     = 255,
 523                .driver_info    = (kernel_ulong_t)GO7007_BOARDID_XMEN,
 524        },
 525        {
 526                .match_flags    = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
 527                .idVendor       = 0x0eb1,  /* Vendor ID of WIS Technologies */
 528                .idProduct      = 0x7007,  /* Product ID of GO7007SB chip */
 529                .bcdDevice_lo   = 0x202,   /* Revision number of Matrix II */
 530                .bcdDevice_hi   = 0x202,
 531                .driver_info    = (kernel_ulong_t)GO7007_BOARDID_MATRIX_II,
 532        },
 533        {
 534                .match_flags    = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
 535                .idVendor       = 0x0eb1,  /* Vendor ID of WIS Technologies */
 536                .idProduct      = 0x7007,  /* Product ID of GO7007SB chip */
 537                .bcdDevice_lo   = 0x204,   /* Revision number of Matrix */
 538                .bcdDevice_hi   = 0x204,   /*     Reloaded */
 539                .driver_info    = (kernel_ulong_t)GO7007_BOARDID_MATRIX_RELOAD,
 540        },
 541        {
 542                .match_flags    = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
 543                                        USB_DEVICE_ID_MATCH_INT_INFO,
 544                .idVendor       = 0x0eb1,  /* Vendor ID of WIS Technologies */
 545                .idProduct      = 0x7007,  /* Product ID of GO7007SB chip */
 546                .bcdDevice_lo   = 0x205,   /* Revision number of XMen-II */
 547                .bcdDevice_hi   = 0x205,
 548                .bInterfaceClass        = 255,
 549                .bInterfaceSubClass     = 0,
 550                .bInterfaceProtocol     = 255,
 551                .driver_info    = (kernel_ulong_t)GO7007_BOARDID_XMEN_II,
 552        },
 553        {
 554                .match_flags    = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
 555                .idVendor       = 0x0eb1,  /* Vendor ID of WIS Technologies */
 556                .idProduct      = 0x7007,  /* Product ID of GO7007SB chip */
 557                .bcdDevice_lo   = 0x208,   /* Revision number of Star Trek */
 558                .bcdDevice_hi   = 0x208,
 559                .driver_info    = (kernel_ulong_t)GO7007_BOARDID_STAR_TREK,
 560        },
 561        {
 562                .match_flags    = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
 563                                        USB_DEVICE_ID_MATCH_INT_INFO,
 564                .idVendor       = 0x0eb1,  /* Vendor ID of WIS Technologies */
 565                .idProduct      = 0x7007,  /* Product ID of GO7007SB chip */
 566                .bcdDevice_lo   = 0x209,   /* Revision number of XMen-III */
 567                .bcdDevice_hi   = 0x209,
 568                .bInterfaceClass        = 255,
 569                .bInterfaceSubClass     = 0,
 570                .bInterfaceProtocol     = 255,
 571                .driver_info    = (kernel_ulong_t)GO7007_BOARDID_XMEN_III,
 572        },
 573        {
 574                .match_flags    = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
 575                .idVendor       = 0x0eb1,  /* Vendor ID of WIS Technologies */
 576                .idProduct      = 0x7007,  /* Product ID of GO7007SB chip */
 577                .bcdDevice_lo   = 0x210,   /* Revision number of Matrix */
 578                .bcdDevice_hi   = 0x210,   /*     Revolution */
 579                .driver_info    = (kernel_ulong_t)GO7007_BOARDID_MATRIX_REV,
 580        },
 581        {
 582                .match_flags    = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
 583                .idVendor       = 0x093b,  /* Vendor ID of Plextor */
 584                .idProduct      = 0xa102,  /* Product ID of M402U */
 585                .bcdDevice_lo   = 0x1,     /* revision number of Blueberry */
 586                .bcdDevice_hi   = 0x1,
 587                .driver_info    = (kernel_ulong_t)GO7007_BOARDID_PX_M402U,
 588        },
 589        {
 590                .match_flags    = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
 591                .idVendor       = 0x093b,  /* Vendor ID of Plextor */
 592                .idProduct      = 0xa104,  /* Product ID of TV402U */
 593                .bcdDevice_lo   = 0x1,
 594                .bcdDevice_hi   = 0x1,
 595                .driver_info    = (kernel_ulong_t)GO7007_BOARDID_PX_TV402U,
 596        },
 597        {
 598                .match_flags    = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
 599                .idVendor       = 0x10fd,  /* Vendor ID of Anubis Electronics */
 600                .idProduct      = 0xde00,  /* Product ID of Lifeview LR192 */
 601                .bcdDevice_lo   = 0x1,
 602                .bcdDevice_hi   = 0x1,
 603                .driver_info    = (kernel_ulong_t)GO7007_BOARDID_LIFEVIEW_LR192,
 604        },
 605        {
 606                .match_flags    = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
 607                .idVendor       = 0x1943,  /* Vendor ID Sensoray */
 608                .idProduct      = 0x2250,  /* Product ID of 2250/2251 */
 609                .bcdDevice_lo   = 0x1,
 610                .bcdDevice_hi   = 0x1,
 611                .driver_info    = (kernel_ulong_t)GO7007_BOARDID_SENSORAY_2250,
 612        },
 613        {
 614                .match_flags    = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
 615                .idVendor       = 0x06e1,  /* Vendor ID of ADS Technologies */
 616                .idProduct      = 0x0709,  /* Product ID of DVD Xpress DX2 */
 617                .bcdDevice_lo   = 0x204,
 618                .bcdDevice_hi   = 0x204,
 619                .driver_info    = (kernel_ulong_t)GO7007_BOARDID_ADS_USBAV_709,
 620        },
 621        { }                                     /* Terminating entry */
 622};
 623
 624MODULE_DEVICE_TABLE(usb, go7007_usb_id_table);
 625
 626/********************* Driver for EZ-USB HPI interface *********************/
 627
 628static int go7007_usb_vendor_request(struct go7007 *go, int request,
 629                int value, int index, void *transfer_buffer, int length, int in)
 630{
 631        struct go7007_usb *usb = go->hpi_context;
 632        int timeout = 5000;
 633
 634        if (in) {
 635                return usb_control_msg(usb->usbdev,
 636                                usb_rcvctrlpipe(usb->usbdev, 0), request,
 637                                USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
 638                                value, index, transfer_buffer, length, timeout);
 639        } else {
 640                return usb_control_msg(usb->usbdev,
 641                                usb_sndctrlpipe(usb->usbdev, 0), request,
 642                                USB_TYPE_VENDOR | USB_RECIP_DEVICE,
 643                                value, index, transfer_buffer, length, timeout);
 644        }
 645}
 646
 647static int go7007_usb_interface_reset(struct go7007 *go)
 648{
 649        struct go7007_usb *usb = go->hpi_context;
 650        u16 intr_val, intr_data;
 651
 652        if (go->status == STATUS_SHUTDOWN)
 653                return -1;
 654        /* Reset encoder */
 655        if (go7007_write_interrupt(go, 0x0001, 0x0001) < 0)
 656                return -1;
 657        msleep(100);
 658
 659        if (usb->board->flags & GO7007_USB_EZUSB) {
 660                /* Reset buffer in EZ-USB */
 661                pr_debug("resetting EZ-USB buffers\n");
 662                if (go7007_usb_vendor_request(go, 0x10, 0, 0, NULL, 0, 0) < 0 ||
 663                    go7007_usb_vendor_request(go, 0x10, 0, 0, NULL, 0, 0) < 0)
 664                        return -1;
 665
 666                /* Reset encoder again */
 667                if (go7007_write_interrupt(go, 0x0001, 0x0001) < 0)
 668                        return -1;
 669                msleep(100);
 670        }
 671
 672        /* Wait for an interrupt to indicate successful hardware reset */
 673        if (go7007_read_interrupt(go, &intr_val, &intr_data) < 0 ||
 674                        (intr_val & ~0x1) != 0x55aa) {
 675                dev_err(go->dev, "unable to reset the USB interface\n");
 676                return -1;
 677        }
 678        return 0;
 679}
 680
 681static int go7007_usb_ezusb_write_interrupt(struct go7007 *go,
 682                                                int addr, int data)
 683{
 684        struct go7007_usb *usb = go->hpi_context;
 685        int i, r;
 686        u16 status_reg = 0;
 687        int timeout = 500;
 688
 689        pr_debug("WriteInterrupt: %04x %04x\n", addr, data);
 690
 691        for (i = 0; i < 100; ++i) {
 692                r = usb_control_msg(usb->usbdev,
 693                                usb_rcvctrlpipe(usb->usbdev, 0), 0x14,
 694                                USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
 695                                0, HPI_STATUS_ADDR, go->usb_buf,
 696                                sizeof(status_reg), timeout);
 697                if (r < 0)
 698                        break;
 699                status_reg = le16_to_cpu(*((__le16 *)go->usb_buf));
 700                if (!(status_reg & 0x0010))
 701                        break;
 702                msleep(10);
 703        }
 704        if (r < 0)
 705                goto write_int_error;
 706        if (i == 100) {
 707                dev_err(go->dev, "device is hung, status reg = 0x%04x\n", status_reg);
 708                return -1;
 709        }
 710        r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 0), 0x12,
 711                        USB_TYPE_VENDOR | USB_RECIP_DEVICE, data,
 712                        INT_PARAM_ADDR, NULL, 0, timeout);
 713        if (r < 0)
 714                goto write_int_error;
 715        r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 0),
 716                        0x12, USB_TYPE_VENDOR | USB_RECIP_DEVICE, addr,
 717                        INT_INDEX_ADDR, NULL, 0, timeout);
 718        if (r < 0)
 719                goto write_int_error;
 720        return 0;
 721
 722write_int_error:
 723        dev_err(go->dev, "error in WriteInterrupt: %d\n", r);
 724        return r;
 725}
 726
 727static int go7007_usb_onboard_write_interrupt(struct go7007 *go,
 728                                                int addr, int data)
 729{
 730        struct go7007_usb *usb = go->hpi_context;
 731        int r;
 732        int timeout = 500;
 733
 734        pr_debug("WriteInterrupt: %04x %04x\n", addr, data);
 735
 736        go->usb_buf[0] = data & 0xff;
 737        go->usb_buf[1] = data >> 8;
 738        go->usb_buf[2] = addr & 0xff;
 739        go->usb_buf[3] = addr >> 8;
 740        go->usb_buf[4] = go->usb_buf[5] = go->usb_buf[6] = go->usb_buf[7] = 0;
 741        r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 2), 0x00,
 742                        USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 0x55aa,
 743                        0xf0f0, go->usb_buf, 8, timeout);
 744        if (r < 0) {
 745                dev_err(go->dev, "error in WriteInterrupt: %d\n", r);
 746                return r;
 747        }
 748        return 0;
 749}
 750
 751static void go7007_usb_readinterrupt_complete(struct urb *urb)
 752{
 753        struct go7007 *go = (struct go7007 *)urb->context;
 754        __le16 *regs = (__le16 *)urb->transfer_buffer;
 755        int status = urb->status;
 756
 757        if (status) {
 758                if (status != -ESHUTDOWN &&
 759                                go->status != STATUS_SHUTDOWN) {
 760                        dev_err(go->dev, "error in read interrupt: %d\n", urb->status);
 761                } else {
 762                        wake_up(&go->interrupt_waitq);
 763                        return;
 764                }
 765        } else if (urb->actual_length != urb->transfer_buffer_length) {
 766                dev_err(go->dev, "short read in interrupt pipe!\n");
 767        } else {
 768                go->interrupt_available = 1;
 769                go->interrupt_data = __le16_to_cpu(regs[0]);
 770                go->interrupt_value = __le16_to_cpu(regs[1]);
 771                pr_debug("ReadInterrupt: %04x %04x\n",
 772                                go->interrupt_value, go->interrupt_data);
 773        }
 774
 775        wake_up(&go->interrupt_waitq);
 776}
 777
 778static int go7007_usb_read_interrupt(struct go7007 *go)
 779{
 780        struct go7007_usb *usb = go->hpi_context;
 781        int r;
 782
 783        r = usb_submit_urb(usb->intr_urb, GFP_KERNEL);
 784        if (r < 0) {
 785                dev_err(go->dev, "unable to submit interrupt urb: %d\n", r);
 786                return r;
 787        }
 788        return 0;
 789}
 790
 791static void go7007_usb_read_video_pipe_complete(struct urb *urb)
 792{
 793        struct go7007 *go = (struct go7007 *)urb->context;
 794        int r, status = urb->status;
 795
 796        if (!vb2_is_streaming(&go->vidq)) {
 797                wake_up_interruptible(&go->frame_waitq);
 798                return;
 799        }
 800        if (status) {
 801                dev_err(go->dev, "error in video pipe: %d\n", status);
 802                return;
 803        }
 804        if (urb->actual_length != urb->transfer_buffer_length) {
 805                dev_err(go->dev, "short read in video pipe!\n");
 806                return;
 807        }
 808        go7007_parse_video_stream(go, urb->transfer_buffer, urb->actual_length);
 809        r = usb_submit_urb(urb, GFP_ATOMIC);
 810        if (r < 0)
 811                dev_err(go->dev, "error in video pipe: %d\n", r);
 812}
 813
 814static void go7007_usb_read_audio_pipe_complete(struct urb *urb)
 815{
 816        struct go7007 *go = (struct go7007 *)urb->context;
 817        int r, status = urb->status;
 818
 819        if (!vb2_is_streaming(&go->vidq))
 820                return;
 821        if (status) {
 822                dev_err(go->dev, "error in audio pipe: %d\n",
 823                        status);
 824                return;
 825        }
 826        if (urb->actual_length != urb->transfer_buffer_length) {
 827                dev_err(go->dev, "short read in audio pipe!\n");
 828                return;
 829        }
 830        if (go->audio_deliver != NULL)
 831                go->audio_deliver(go, urb->transfer_buffer, urb->actual_length);
 832        r = usb_submit_urb(urb, GFP_ATOMIC);
 833        if (r < 0)
 834                dev_err(go->dev, "error in audio pipe: %d\n", r);
 835}
 836
 837static int go7007_usb_stream_start(struct go7007 *go)
 838{
 839        struct go7007_usb *usb = go->hpi_context;
 840        int i, r;
 841
 842        for (i = 0; i < 8; ++i) {
 843                r = usb_submit_urb(usb->video_urbs[i], GFP_KERNEL);
 844                if (r < 0) {
 845                        dev_err(go->dev, "error submitting video urb %d: %d\n", i, r);
 846                        goto video_submit_failed;
 847                }
 848        }
 849        if (!go->audio_enabled)
 850                return 0;
 851
 852        for (i = 0; i < 8; ++i) {
 853                r = usb_submit_urb(usb->audio_urbs[i], GFP_KERNEL);
 854                if (r < 0) {
 855                        dev_err(go->dev, "error submitting audio urb %d: %d\n", i, r);
 856                        goto audio_submit_failed;
 857                }
 858        }
 859        return 0;
 860
 861audio_submit_failed:
 862        for (i = 0; i < 7; ++i)
 863                usb_kill_urb(usb->audio_urbs[i]);
 864video_submit_failed:
 865        for (i = 0; i < 8; ++i)
 866                usb_kill_urb(usb->video_urbs[i]);
 867        return -1;
 868}
 869
 870static int go7007_usb_stream_stop(struct go7007 *go)
 871{
 872        struct go7007_usb *usb = go->hpi_context;
 873        int i;
 874
 875        if (go->status == STATUS_SHUTDOWN)
 876                return 0;
 877        for (i = 0; i < 8; ++i)
 878                usb_kill_urb(usb->video_urbs[i]);
 879        if (go->audio_enabled)
 880                for (i = 0; i < 8; ++i)
 881                        usb_kill_urb(usb->audio_urbs[i]);
 882        return 0;
 883}
 884
 885static int go7007_usb_send_firmware(struct go7007 *go, u8 *data, int len)
 886{
 887        struct go7007_usb *usb = go->hpi_context;
 888        int transferred, pipe;
 889        int timeout = 500;
 890
 891        pr_debug("DownloadBuffer sending %d bytes\n", len);
 892
 893        if (usb->board->flags & GO7007_USB_EZUSB)
 894                pipe = usb_sndbulkpipe(usb->usbdev, 2);
 895        else
 896                pipe = usb_sndbulkpipe(usb->usbdev, 3);
 897
 898        return usb_bulk_msg(usb->usbdev, pipe, data, len,
 899                                        &transferred, timeout);
 900}
 901
 902static void go7007_usb_release(struct go7007 *go)
 903{
 904        struct go7007_usb *usb = go->hpi_context;
 905        struct urb *vurb, *aurb;
 906        int i;
 907
 908        if (usb->intr_urb) {
 909                usb_kill_urb(usb->intr_urb);
 910                kfree(usb->intr_urb->transfer_buffer);
 911                usb_free_urb(usb->intr_urb);
 912        }
 913
 914        /* Free USB-related structs */
 915        for (i = 0; i < 8; ++i) {
 916                vurb = usb->video_urbs[i];
 917                if (vurb) {
 918                        usb_kill_urb(vurb);
 919                        kfree(vurb->transfer_buffer);
 920                        usb_free_urb(vurb);
 921                }
 922                aurb = usb->audio_urbs[i];
 923                if (aurb) {
 924                        usb_kill_urb(aurb);
 925                        kfree(aurb->transfer_buffer);
 926                        usb_free_urb(aurb);
 927                }
 928        }
 929
 930        kfree(go->hpi_context);
 931}
 932
 933static struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops = {
 934        .interface_reset        = go7007_usb_interface_reset,
 935        .write_interrupt        = go7007_usb_ezusb_write_interrupt,
 936        .read_interrupt         = go7007_usb_read_interrupt,
 937        .stream_start           = go7007_usb_stream_start,
 938        .stream_stop            = go7007_usb_stream_stop,
 939        .send_firmware          = go7007_usb_send_firmware,
 940        .release                = go7007_usb_release,
 941};
 942
 943static struct go7007_hpi_ops go7007_usb_onboard_hpi_ops = {
 944        .interface_reset        = go7007_usb_interface_reset,
 945        .write_interrupt        = go7007_usb_onboard_write_interrupt,
 946        .read_interrupt         = go7007_usb_read_interrupt,
 947        .stream_start           = go7007_usb_stream_start,
 948        .stream_stop            = go7007_usb_stream_stop,
 949        .send_firmware          = go7007_usb_send_firmware,
 950        .release                = go7007_usb_release,
 951};
 952
 953/********************* Driver for EZ-USB I2C adapter *********************/
 954
 955static int go7007_usb_i2c_master_xfer(struct i2c_adapter *adapter,
 956                                        struct i2c_msg msgs[], int num)
 957{
 958        struct go7007 *go = i2c_get_adapdata(adapter);
 959        struct go7007_usb *usb = go->hpi_context;
 960        u8 *buf = go->usb_buf;
 961        int buf_len, i;
 962        int ret = -EIO;
 963
 964        if (go->status == STATUS_SHUTDOWN)
 965                return -ENODEV;
 966
 967        mutex_lock(&usb->i2c_lock);
 968
 969        for (i = 0; i < num; ++i) {
 970                /* The hardware command is "write some bytes then read some
 971                 * bytes", so we try to coalesce a write followed by a read
 972                 * into a single USB transaction */
 973                if (i + 1 < num && msgs[i].addr == msgs[i + 1].addr &&
 974                                !(msgs[i].flags & I2C_M_RD) &&
 975                                (msgs[i + 1].flags & I2C_M_RD)) {
 976#ifdef GO7007_I2C_DEBUG
 977                        pr_debug("i2c write/read %d/%d bytes on %02x\n",
 978                                msgs[i].len, msgs[i + 1].len, msgs[i].addr);
 979#endif
 980                        buf[0] = 0x01;
 981                        buf[1] = msgs[i].len + 1;
 982                        buf[2] = msgs[i].addr << 1;
 983                        memcpy(&buf[3], msgs[i].buf, msgs[i].len);
 984                        buf_len = msgs[i].len + 3;
 985                        buf[buf_len++] = msgs[++i].len;
 986                } else if (msgs[i].flags & I2C_M_RD) {
 987#ifdef GO7007_I2C_DEBUG
 988                        pr_debug("i2c read %d bytes on %02x\n",
 989                                        msgs[i].len, msgs[i].addr);
 990#endif
 991                        buf[0] = 0x01;
 992                        buf[1] = 1;
 993                        buf[2] = msgs[i].addr << 1;
 994                        buf[3] = msgs[i].len;
 995                        buf_len = 4;
 996                } else {
 997#ifdef GO7007_I2C_DEBUG
 998                        pr_debug("i2c write %d bytes on %02x\n",
 999                                        msgs[i].len, msgs[i].addr);
1000#endif
1001                        buf[0] = 0x00;
1002                        buf[1] = msgs[i].len + 1;
1003                        buf[2] = msgs[i].addr << 1;
1004                        memcpy(&buf[3], msgs[i].buf, msgs[i].len);
1005                        buf_len = msgs[i].len + 3;
1006                        buf[buf_len++] = 0;
1007                }
1008                if (go7007_usb_vendor_request(go, 0x24, 0, 0,
1009                                                buf, buf_len, 0) < 0)
1010                        goto i2c_done;
1011                if (msgs[i].flags & I2C_M_RD) {
1012                        memset(buf, 0, msgs[i].len + 1);
1013                        if (go7007_usb_vendor_request(go, 0x25, 0, 0, buf,
1014                                                msgs[i].len + 1, 1) < 0)
1015                                goto i2c_done;
1016                        memcpy(msgs[i].buf, buf + 1, msgs[i].len);
1017                }
1018        }
1019        ret = num;
1020
1021i2c_done:
1022        mutex_unlock(&usb->i2c_lock);
1023        return ret;
1024}
1025
1026static u32 go7007_usb_functionality(struct i2c_adapter *adapter)
1027{
1028        /* No errors are reported by the hardware, so we don't bother
1029         * supporting quick writes to avoid confusing probing */
1030        return (I2C_FUNC_SMBUS_EMUL) & ~I2C_FUNC_SMBUS_QUICK;
1031}
1032
1033static struct i2c_algorithm go7007_usb_algo = {
1034        .master_xfer    = go7007_usb_i2c_master_xfer,
1035        .functionality  = go7007_usb_functionality,
1036};
1037
1038static struct i2c_adapter go7007_usb_adap_templ = {
1039        .owner                  = THIS_MODULE,
1040        .name                   = "WIS GO7007SB EZ-USB",
1041        .algo                   = &go7007_usb_algo,
1042};
1043
1044/********************* USB add/remove functions *********************/
1045
1046static int go7007_usb_probe(struct usb_interface *intf,
1047                const struct usb_device_id *id)
1048{
1049        struct go7007 *go;
1050        struct go7007_usb *usb;
1051        const struct go7007_usb_board *board;
1052        struct usb_device *usbdev = interface_to_usbdev(intf);
1053        unsigned num_i2c_devs;
1054        char *name;
1055        int video_pipe, i, v_urb_len;
1056
1057        pr_debug("probing new GO7007 USB board\n");
1058
1059        switch (id->driver_info) {
1060        case GO7007_BOARDID_MATRIX_II:
1061                name = "WIS Matrix II or compatible";
1062                board = &board_matrix_ii;
1063                break;
1064        case GO7007_BOARDID_MATRIX_RELOAD:
1065                name = "WIS Matrix Reloaded or compatible";
1066                board = &board_matrix_reload;
1067                break;
1068        case GO7007_BOARDID_MATRIX_REV:
1069                name = "WIS Matrix Revolution or compatible";
1070                board = &board_matrix_revolution;
1071                break;
1072        case GO7007_BOARDID_STAR_TREK:
1073                name = "WIS Star Trek or compatible";
1074                board = &board_star_trek;
1075                break;
1076        case GO7007_BOARDID_XMEN:
1077                name = "WIS XMen or compatible";
1078                board = &board_xmen;
1079                break;
1080        case GO7007_BOARDID_XMEN_II:
1081                name = "WIS XMen II or compatible";
1082                board = &board_xmen;
1083                break;
1084        case GO7007_BOARDID_XMEN_III:
1085                name = "WIS XMen III or compatible";
1086                board = &board_xmen;
1087                break;
1088        case GO7007_BOARDID_PX_M402U:
1089                name = "Plextor PX-M402U";
1090                board = &board_matrix_ii;
1091                break;
1092        case GO7007_BOARDID_PX_TV402U:
1093                name = "Plextor PX-TV402U (unknown tuner)";
1094                board = &board_px_tv402u;
1095                break;
1096        case GO7007_BOARDID_LIFEVIEW_LR192:
1097                dev_err(&intf->dev, "The Lifeview TV Walker Ultra is not supported. Sorry!\n");
1098                return -ENODEV;
1099                name = "Lifeview TV Walker Ultra";
1100                board = &board_lifeview_lr192;
1101                break;
1102        case GO7007_BOARDID_SENSORAY_2250:
1103                dev_info(&intf->dev, "Sensoray 2250 found\n");
1104                name = "Sensoray 2250/2251";
1105                board = &board_sensoray_2250;
1106                break;
1107        case GO7007_BOARDID_ADS_USBAV_709:
1108                name = "ADS Tech DVD Xpress DX2";
1109                board = &board_ads_usbav_709;
1110                break;
1111        default:
1112                dev_err(&intf->dev, "unknown board ID %d!\n",
1113                                (unsigned int)id->driver_info);
1114                return -ENODEV;
1115        }
1116
1117        go = go7007_alloc(&board->main_info, &intf->dev);
1118        if (go == NULL)
1119                return -ENOMEM;
1120
1121        usb = kzalloc(sizeof(struct go7007_usb), GFP_KERNEL);
1122        if (usb == NULL) {
1123                kfree(go);
1124                return -ENOMEM;
1125        }
1126
1127        usb->board = board;
1128        usb->usbdev = usbdev;
1129        usb_make_path(usbdev, go->bus_info, sizeof(go->bus_info));
1130        go->board_id = id->driver_info;
1131        strncpy(go->name, name, sizeof(go->name));
1132        if (board->flags & GO7007_USB_EZUSB)
1133                go->hpi_ops = &go7007_usb_ezusb_hpi_ops;
1134        else
1135                go->hpi_ops = &go7007_usb_onboard_hpi_ops;
1136        go->hpi_context = usb;
1137
1138        /* Allocate the URB and buffer for receiving incoming interrupts */
1139        usb->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
1140        if (usb->intr_urb == NULL)
1141                goto allocfail;
1142        usb->intr_urb->transfer_buffer = kmalloc(2*sizeof(u16), GFP_KERNEL);
1143        if (usb->intr_urb->transfer_buffer == NULL)
1144                goto allocfail;
1145
1146        if (go->board_id == GO7007_BOARDID_SENSORAY_2250)
1147                usb_fill_bulk_urb(usb->intr_urb, usb->usbdev,
1148                        usb_rcvbulkpipe(usb->usbdev, 4),
1149                        usb->intr_urb->transfer_buffer, 2*sizeof(u16),
1150                        go7007_usb_readinterrupt_complete, go);
1151        else
1152                usb_fill_int_urb(usb->intr_urb, usb->usbdev,
1153                        usb_rcvintpipe(usb->usbdev, 4),
1154                        usb->intr_urb->transfer_buffer, 2*sizeof(u16),
1155                        go7007_usb_readinterrupt_complete, go, 8);
1156        usb_set_intfdata(intf, &go->v4l2_dev);
1157
1158        /* Boot the GO7007 */
1159        if (go7007_boot_encoder(go, go->board_info->flags &
1160                                        GO7007_BOARD_USE_ONBOARD_I2C) < 0)
1161                goto allocfail;
1162
1163        /* Register the EZ-USB I2C adapter, if we're using it */
1164        if (board->flags & GO7007_USB_EZUSB_I2C) {
1165                memcpy(&go->i2c_adapter, &go7007_usb_adap_templ,
1166                                sizeof(go7007_usb_adap_templ));
1167                mutex_init(&usb->i2c_lock);
1168                go->i2c_adapter.dev.parent = go->dev;
1169                i2c_set_adapdata(&go->i2c_adapter, go);
1170                if (i2c_add_adapter(&go->i2c_adapter) < 0) {
1171                        dev_err(go->dev, "error: i2c_add_adapter failed\n");
1172                        goto allocfail;
1173                }
1174                go->i2c_adapter_online = 1;
1175        }
1176
1177        /* Pelco and Adlink reused the XMen and XMen-III vendor and product
1178         * IDs for their own incompatible designs.  We can detect XMen boards
1179         * by probing the sensor, but there is no way to probe the sensors on
1180         * the Pelco and Adlink designs so we default to the Adlink.  If it
1181         * is actually a Pelco, the user must set the assume_endura module
1182         * parameter. */
1183        if ((go->board_id == GO7007_BOARDID_XMEN ||
1184                                go->board_id == GO7007_BOARDID_XMEN_III) &&
1185                        go->i2c_adapter_online) {
1186                union i2c_smbus_data data;
1187
1188                /* Check to see if register 0x0A is 0x76 */
1189                i2c_smbus_xfer(&go->i2c_adapter, 0x21, I2C_CLIENT_SCCB,
1190                        I2C_SMBUS_READ, 0x0A, I2C_SMBUS_BYTE_DATA, &data);
1191                if (data.byte != 0x76) {
1192                        if (assume_endura) {
1193                                go->board_id = GO7007_BOARDID_ENDURA;
1194                                usb->board = board = &board_endura;
1195                                go->board_info = &board->main_info;
1196                                strncpy(go->name, "Pelco Endura",
1197                                        sizeof(go->name));
1198                        } else {
1199                                u16 channel;
1200
1201                                /* read channel number from GPIO[1:0] */
1202                                go7007_read_addr(go, 0x3c81, &channel);
1203                                channel &= 0x3;
1204                                go->board_id = GO7007_BOARDID_ADLINK_MPG24;
1205                                usb->board = board = &board_adlink_mpg24;
1206                                go->board_info = &board->main_info;
1207                                go->channel_number = channel;
1208                                snprintf(go->name, sizeof(go->name),
1209                                        "Adlink PCI-MPG24, channel #%d",
1210                                        channel);
1211                        }
1212                        go7007_update_board(go);
1213                }
1214        }
1215
1216        num_i2c_devs = go->board_info->num_i2c_devs;
1217
1218        /* Probe the tuner model on the TV402U */
1219        if (go->board_id == GO7007_BOARDID_PX_TV402U) {
1220                /* Board strapping indicates tuner model */
1221                if (go7007_usb_vendor_request(go, 0x41, 0, 0, go->usb_buf, 3,
1222                                        1) < 0) {
1223                        dev_err(go->dev, "GPIO read failed!\n");
1224                        goto allocfail;
1225                }
1226                switch (go->usb_buf[0] >> 6) {
1227                case 1:
1228                        go->tuner_type = TUNER_SONY_BTF_PG472Z;
1229                        go->std = V4L2_STD_PAL;
1230                        strncpy(go->name, "Plextor PX-TV402U-EU",
1231                                        sizeof(go->name));
1232                        break;
1233                case 2:
1234                        go->tuner_type = TUNER_SONY_BTF_PK467Z;
1235                        go->std = V4L2_STD_NTSC_M_JP;
1236                        num_i2c_devs -= 2;
1237                        strncpy(go->name, "Plextor PX-TV402U-JP",
1238                                        sizeof(go->name));
1239                        break;
1240                case 3:
1241                        go->tuner_type = TUNER_SONY_BTF_PB463Z;
1242                        num_i2c_devs -= 2;
1243                        strncpy(go->name, "Plextor PX-TV402U-NA",
1244                                        sizeof(go->name));
1245                        break;
1246                default:
1247                        pr_debug("unable to detect tuner type!\n");
1248                        break;
1249                }
1250                /* Configure tuner mode selection inputs connected
1251                 * to the EZ-USB GPIO output pins */
1252                if (go7007_usb_vendor_request(go, 0x40, 0x7f02, 0,
1253                                        NULL, 0, 0) < 0) {
1254                        dev_err(go->dev, "GPIO write failed!\n");
1255                        goto allocfail;
1256                }
1257        }
1258
1259        /* Print a nasty message if the user attempts to use a USB2.0 device in
1260         * a USB1.1 port.  There will be silent corruption of the stream. */
1261        if ((board->flags & GO7007_USB_EZUSB) &&
1262                        usbdev->speed != USB_SPEED_HIGH)
1263                dev_err(go->dev, "*** WARNING ***  This device must be connected to a USB 2.0 port! Attempting to capture video through a USB 1.1 port will result in stream corruption, even at low bitrates!\n");
1264
1265        /* Allocate the URBs and buffers for receiving the video stream */
1266        if (board->flags & GO7007_USB_EZUSB) {
1267                v_urb_len = 1024;
1268                video_pipe = usb_rcvbulkpipe(usb->usbdev, 6);
1269        } else {
1270                v_urb_len = 512;
1271                video_pipe = usb_rcvbulkpipe(usb->usbdev, 1);
1272        }
1273        for (i = 0; i < 8; ++i) {
1274                usb->video_urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
1275                if (usb->video_urbs[i] == NULL)
1276                        goto allocfail;
1277                usb->video_urbs[i]->transfer_buffer =
1278                                                kmalloc(v_urb_len, GFP_KERNEL);
1279                if (usb->video_urbs[i]->transfer_buffer == NULL)
1280                        goto allocfail;
1281                usb_fill_bulk_urb(usb->video_urbs[i], usb->usbdev, video_pipe,
1282                                usb->video_urbs[i]->transfer_buffer, v_urb_len,
1283                                go7007_usb_read_video_pipe_complete, go);
1284        }
1285
1286        /* Allocate the URBs and buffers for receiving the audio stream */
1287        if ((board->flags & GO7007_USB_EZUSB) &&
1288            (board->flags & GO7007_BOARD_HAS_AUDIO)) {
1289                for (i = 0; i < 8; ++i) {
1290                        usb->audio_urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
1291                        if (usb->audio_urbs[i] == NULL)
1292                                goto allocfail;
1293                        usb->audio_urbs[i]->transfer_buffer = kmalloc(4096,
1294                                                                GFP_KERNEL);
1295                        if (usb->audio_urbs[i]->transfer_buffer == NULL)
1296                                goto allocfail;
1297                        usb_fill_bulk_urb(usb->audio_urbs[i], usb->usbdev,
1298                                usb_rcvbulkpipe(usb->usbdev, 8),
1299                                usb->audio_urbs[i]->transfer_buffer, 4096,
1300                                go7007_usb_read_audio_pipe_complete, go);
1301                }
1302        }
1303
1304        /* Do any final GO7007 initialization, then register the
1305         * V4L2 and ALSA interfaces */
1306        if (go7007_register_encoder(go, num_i2c_devs) < 0)
1307                goto allocfail;
1308
1309        go->status = STATUS_ONLINE;
1310        return 0;
1311
1312allocfail:
1313        go7007_usb_release(go);
1314        kfree(go);
1315        return -ENOMEM;
1316}
1317
1318static void go7007_usb_disconnect(struct usb_interface *intf)
1319{
1320        struct go7007 *go = to_go7007(usb_get_intfdata(intf));
1321
1322        mutex_lock(&go->queue_lock);
1323        mutex_lock(&go->serialize_lock);
1324
1325        if (go->audio_enabled)
1326                go7007_snd_remove(go);
1327
1328        go->status = STATUS_SHUTDOWN;
1329        v4l2_device_disconnect(&go->v4l2_dev);
1330        video_unregister_device(&go->vdev);
1331        mutex_unlock(&go->serialize_lock);
1332        mutex_unlock(&go->queue_lock);
1333
1334        v4l2_device_put(&go->v4l2_dev);
1335}
1336
1337static struct usb_driver go7007_usb_driver = {
1338        .name           = "go7007",
1339        .probe          = go7007_usb_probe,
1340        .disconnect     = go7007_usb_disconnect,
1341        .id_table       = go7007_usb_id_table,
1342};
1343
1344module_usb_driver(go7007_usb_driver);
1345MODULE_LICENSE("GPL v2");
1346
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.