linux/drivers/media/video/gspca/ov534.c
<<
>>
Prefs
   1/*
   2 * ov534-ov772x gspca driver
   3 *
   4 * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it>
   5 * Copyright (C) 2008 Jim Paris <jim@jtan.com>
   6 * Copyright (C) 2009 Jean-Francois Moine http://moinejf.free.fr
   7 *
   8 * Based on a prototype written by Mark Ferrell <majortrips@gmail.com>
   9 * USB protocol reverse engineered by Jim Paris <jim@jtan.com>
  10 * https://jim.sh/svn/jim/devl/playstation/ps3/eye/test/
  11 *
  12 * PS3 Eye camera enhanced by Richard Kaswy http://kaswy.free.fr
  13 * PS3 Eye camera - brightness, contrast, awb, agc, aec controls
  14 *                  added by Max Thrun <bear24rw@gmail.com>
  15 *
  16 * This program is free software; you can redistribute it and/or modify
  17 * it under the terms of the GNU General Public License as published by
  18 * the Free Software Foundation; either version 2 of the License, or
  19 * any later version.
  20 *
  21 * This program is distributed in the hope that it will be useful,
  22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24 * GNU General Public License for more details.
  25 *
  26 * You should have received a copy of the GNU General Public License
  27 * along with this program; if not, write to the Free Software
  28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  29 */
  30
  31#define MODULE_NAME "ov534"
  32
  33#include "gspca.h"
  34
  35#define OV534_REG_ADDRESS       0xf1    /* sensor address */
  36#define OV534_REG_SUBADDR       0xf2
  37#define OV534_REG_WRITE         0xf3
  38#define OV534_REG_READ          0xf4
  39#define OV534_REG_OPERATION     0xf5
  40#define OV534_REG_STATUS        0xf6
  41
  42#define OV534_OP_WRITE_3        0x37
  43#define OV534_OP_WRITE_2        0x33
  44#define OV534_OP_READ_2         0xf9
  45
  46#define CTRL_TIMEOUT 500
  47
  48MODULE_AUTHOR("Antonio Ospite <ospite@studenti.unina.it>");
  49MODULE_DESCRIPTION("GSPCA/OV534 USB Camera Driver");
  50MODULE_LICENSE("GPL");
  51
  52/* specific webcam descriptor */
  53struct sd {
  54        struct gspca_dev gspca_dev;     /* !! must be the first item */
  55        __u32 last_pts;
  56        u16 last_fid;
  57        u8 frame_rate;
  58
  59        u8 brightness;
  60        u8 contrast;
  61        u8 gain;
  62        u8 exposure;
  63        u8 agc;
  64        u8 awb;
  65        u8 aec;
  66        s8 sharpness;
  67        u8 hflip;
  68        u8 vflip;
  69        u8 freqfltr;
  70};
  71
  72/* V4L2 controls supported by the driver */
  73static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
  74static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
  75static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
  76static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
  77static int sd_setagc(struct gspca_dev *gspca_dev, __s32 val);
  78static int sd_getagc(struct gspca_dev *gspca_dev, __s32 *val);
  79static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
  80static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
  81static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
  82static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
  83static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
  84static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
  85static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val);
  86static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val);
  87static int sd_setaec(struct gspca_dev *gspca_dev, __s32 val);
  88static int sd_getaec(struct gspca_dev *gspca_dev, __s32 *val);
  89static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  90static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  91static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  92static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  93static int sd_setfreqfltr(struct gspca_dev *gspca_dev, __s32 val);
  94static int sd_getfreqfltr(struct gspca_dev *gspca_dev, __s32 *val);
  95static int sd_querymenu(struct gspca_dev *gspca_dev,
  96                struct v4l2_querymenu *menu);
  97
  98static const struct ctrl sd_ctrls[] = {
  99        {       /* 0 */
 100                {
 101                        .id      = V4L2_CID_BRIGHTNESS,
 102                        .type    = V4L2_CTRL_TYPE_INTEGER,
 103                        .name    = "Brightness",
 104                        .minimum = 0,
 105                        .maximum = 255,
 106                        .step    = 1,
 107#define BRIGHTNESS_DEF 0
 108                        .default_value = BRIGHTNESS_DEF,
 109                },
 110                .set = sd_setbrightness,
 111                .get = sd_getbrightness,
 112        },
 113        {       /* 1 */
 114                {
 115                        .id      = V4L2_CID_CONTRAST,
 116                        .type    = V4L2_CTRL_TYPE_INTEGER,
 117                        .name    = "Contrast",
 118                        .minimum = 0,
 119                        .maximum = 255,
 120                        .step    = 1,
 121#define CONTRAST_DEF 32
 122                        .default_value = CONTRAST_DEF,
 123                },
 124                .set = sd_setcontrast,
 125                .get = sd_getcontrast,
 126        },
 127        {       /* 2 */
 128                {
 129                        .id      = V4L2_CID_GAIN,
 130                        .type    = V4L2_CTRL_TYPE_INTEGER,
 131                        .name    = "Main Gain",
 132                        .minimum = 0,
 133                        .maximum = 63,
 134                        .step    = 1,
 135#define GAIN_DEF 20
 136                        .default_value = GAIN_DEF,
 137                },
 138                .set = sd_setgain,
 139                .get = sd_getgain,
 140        },
 141        {       /* 3 */
 142                {
 143                        .id      = V4L2_CID_EXPOSURE,
 144                        .type    = V4L2_CTRL_TYPE_INTEGER,
 145                        .name    = "Exposure",
 146                        .minimum = 0,
 147                        .maximum = 255,
 148                        .step    = 1,
 149#define EXPO_DEF 120
 150                        .default_value = EXPO_DEF,
 151                },
 152                .set = sd_setexposure,
 153                .get = sd_getexposure,
 154        },
 155        {       /* 4 */
 156                {
 157                        .id      = V4L2_CID_AUTOGAIN,
 158                        .type    = V4L2_CTRL_TYPE_BOOLEAN,
 159                        .name    = "Auto Gain",
 160                        .minimum = 0,
 161                        .maximum = 1,
 162                        .step    = 1,
 163#define AGC_DEF 1
 164                        .default_value = AGC_DEF,
 165                },
 166                .set = sd_setagc,
 167                .get = sd_getagc,
 168        },
 169#define AWB_IDX 5
 170        {       /* 5 */
 171                {
 172                        .id      = V4L2_CID_AUTO_WHITE_BALANCE,
 173                        .type    = V4L2_CTRL_TYPE_BOOLEAN,
 174                        .name    = "Auto White Balance",
 175                        .minimum = 0,
 176                        .maximum = 1,
 177                        .step    = 1,
 178#define AWB_DEF 1
 179                        .default_value = AWB_DEF,
 180                },
 181                .set = sd_setawb,
 182                .get = sd_getawb,
 183        },
 184        {       /* 6 */
 185                {
 186                        .id      = V4L2_CID_EXPOSURE_AUTO,
 187                        .type    = V4L2_CTRL_TYPE_BOOLEAN,
 188                        .name    = "Auto Exposure",
 189                        .minimum = 0,
 190                        .maximum = 1,
 191                        .step    = 1,
 192#define AEC_DEF 1
 193                        .default_value = AEC_DEF,
 194                },
 195                .set = sd_setaec,
 196                .get = sd_getaec,
 197        },
 198        {       /* 7 */
 199                {
 200                        .id      = V4L2_CID_SHARPNESS,
 201                        .type    = V4L2_CTRL_TYPE_INTEGER,
 202                        .name    = "Sharpness",
 203                        .minimum = 0,
 204                        .maximum = 63,
 205                        .step    = 1,
 206#define SHARPNESS_DEF 0
 207                        .default_value = SHARPNESS_DEF,
 208                },
 209                .set = sd_setsharpness,
 210                .get = sd_getsharpness,
 211        },
 212        {       /* 8 */
 213                {
 214                        .id      = V4L2_CID_HFLIP,
 215                        .type    = V4L2_CTRL_TYPE_BOOLEAN,
 216                        .name    = "HFlip",
 217                        .minimum = 0,
 218                        .maximum = 1,
 219                        .step    = 1,
 220#define HFLIP_DEF 0
 221                        .default_value = HFLIP_DEF,
 222                },
 223                .set = sd_sethflip,
 224                .get = sd_gethflip,
 225        },
 226        {       /* 9 */
 227                {
 228                        .id      = V4L2_CID_VFLIP,
 229                        .type    = V4L2_CTRL_TYPE_BOOLEAN,
 230                        .name    = "VFlip",
 231                        .minimum = 0,
 232                        .maximum = 1,
 233                        .step    = 1,
 234#define VFLIP_DEF 0
 235                        .default_value = VFLIP_DEF,
 236                },
 237                .set = sd_setvflip,
 238                .get = sd_getvflip,
 239        },
 240        {       /* 10 */
 241                {
 242                        .id      = V4L2_CID_POWER_LINE_FREQUENCY,
 243                        .type    = V4L2_CTRL_TYPE_MENU,
 244                        .name    = "Light Frequency Filter",
 245                        .minimum = 0,
 246                        .maximum = 1,
 247                        .step    = 1,
 248#define FREQFLTR_DEF 0
 249                        .default_value = FREQFLTR_DEF,
 250                },
 251                .set = sd_setfreqfltr,
 252                .get = sd_getfreqfltr,
 253        },
 254};
 255
 256static const struct v4l2_pix_format ov772x_mode[] = {
 257        {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
 258         .bytesperline = 320 * 2,
 259         .sizeimage = 320 * 240 * 2,
 260         .colorspace = V4L2_COLORSPACE_SRGB,
 261         .priv = 1},
 262        {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
 263         .bytesperline = 640 * 2,
 264         .sizeimage = 640 * 480 * 2,
 265         .colorspace = V4L2_COLORSPACE_SRGB,
 266         .priv = 0},
 267};
 268
 269static const u8 qvga_rates[] = {125, 100, 75, 60, 50, 40, 30};
 270static const u8 vga_rates[] = {60, 50, 40, 30, 15};
 271
 272static const struct framerates ov772x_framerates[] = {
 273        { /* 320x240 */
 274                .rates = qvga_rates,
 275                .nrates = ARRAY_SIZE(qvga_rates),
 276        },
 277        { /* 640x480 */
 278                .rates = vga_rates,
 279                .nrates = ARRAY_SIZE(vga_rates),
 280        },
 281};
 282
 283static const u8 bridge_init[][2] = {
 284        { 0xc2, 0x0c },
 285        { 0x88, 0xf8 },
 286        { 0xc3, 0x69 },
 287        { 0x89, 0xff },
 288        { 0x76, 0x03 },
 289        { 0x92, 0x01 },
 290        { 0x93, 0x18 },
 291        { 0x94, 0x10 },
 292        { 0x95, 0x10 },
 293        { 0xe2, 0x00 },
 294        { 0xe7, 0x3e },
 295
 296        { 0x96, 0x00 },
 297
 298        { 0x97, 0x20 },
 299        { 0x97, 0x20 },
 300        { 0x97, 0x20 },
 301        { 0x97, 0x0a },
 302        { 0x97, 0x3f },
 303        { 0x97, 0x4a },
 304        { 0x97, 0x20 },
 305        { 0x97, 0x15 },
 306        { 0x97, 0x0b },
 307
 308        { 0x8e, 0x40 },
 309        { 0x1f, 0x81 },
 310        { 0x34, 0x05 },
 311        { 0xe3, 0x04 },
 312        { 0x88, 0x00 },
 313        { 0x89, 0x00 },
 314        { 0x76, 0x00 },
 315        { 0xe7, 0x2e },
 316        { 0x31, 0xf9 },
 317        { 0x25, 0x42 },
 318        { 0x21, 0xf0 },
 319
 320        { 0x1c, 0x00 },
 321        { 0x1d, 0x40 },
 322        { 0x1d, 0x02 }, /* payload size 0x0200 * 4 = 2048 bytes */
 323        { 0x1d, 0x00 }, /* payload size */
 324
 325        { 0x1d, 0x02 }, /* frame size 0x025800 * 4 = 614400 */
 326        { 0x1d, 0x58 }, /* frame size */
 327        { 0x1d, 0x00 }, /* frame size */
 328
 329        { 0x1c, 0x0a },
 330        { 0x1d, 0x08 }, /* turn on UVC header */
 331        { 0x1d, 0x0e }, /* .. */
 332
 333        { 0x8d, 0x1c },
 334        { 0x8e, 0x80 },
 335        { 0xe5, 0x04 },
 336
 337        { 0xc0, 0x50 },
 338        { 0xc1, 0x3c },
 339        { 0xc2, 0x0c },
 340};
 341static const u8 sensor_init[][2] = {
 342        { 0x12, 0x80 },
 343        { 0x11, 0x01 },
 344/*fixme: better have a delay?*/
 345        { 0x11, 0x01 },
 346        { 0x11, 0x01 },
 347        { 0x11, 0x01 },
 348        { 0x11, 0x01 },
 349        { 0x11, 0x01 },
 350        { 0x11, 0x01 },
 351        { 0x11, 0x01 },
 352        { 0x11, 0x01 },
 353        { 0x11, 0x01 },
 354        { 0x11, 0x01 },
 355
 356        { 0x3d, 0x03 },
 357        { 0x17, 0x26 },
 358        { 0x18, 0xa0 },
 359        { 0x19, 0x07 },
 360        { 0x1a, 0xf0 },
 361        { 0x32, 0x00 },
 362        { 0x29, 0xa0 },
 363        { 0x2c, 0xf0 },
 364        { 0x65, 0x20 },
 365        { 0x11, 0x01 },
 366        { 0x42, 0x7f },
 367        { 0x63, 0xaa },         /* AWB - was e0 */
 368        { 0x64, 0xff },
 369        { 0x66, 0x00 },
 370        { 0x13, 0xf0 },         /* com8 */
 371        { 0x0d, 0x41 },
 372        { 0x0f, 0xc5 },
 373        { 0x14, 0x11 },
 374
 375        { 0x22, 0x7f },
 376        { 0x23, 0x03 },
 377        { 0x24, 0x40 },
 378        { 0x25, 0x30 },
 379        { 0x26, 0xa1 },
 380        { 0x2a, 0x00 },
 381        { 0x2b, 0x00 },
 382        { 0x6b, 0xaa },
 383        { 0x13, 0xff },         /* AWB */
 384
 385        { 0x90, 0x05 },
 386        { 0x91, 0x01 },
 387        { 0x92, 0x03 },
 388        { 0x93, 0x00 },
 389        { 0x94, 0x60 },
 390        { 0x95, 0x3c },
 391        { 0x96, 0x24 },
 392        { 0x97, 0x1e },
 393        { 0x98, 0x62 },
 394        { 0x99, 0x80 },
 395        { 0x9a, 0x1e },
 396        { 0x9b, 0x08 },
 397        { 0x9c, 0x20 },
 398        { 0x9e, 0x81 },
 399
 400        { 0xa6, 0x04 },
 401        { 0x7e, 0x0c },
 402        { 0x7f, 0x16 },
 403        { 0x80, 0x2a },
 404        { 0x81, 0x4e },
 405        { 0x82, 0x61 },
 406        { 0x83, 0x6f },
 407        { 0x84, 0x7b },
 408        { 0x85, 0x86 },
 409        { 0x86, 0x8e },
 410        { 0x87, 0x97 },
 411        { 0x88, 0xa4 },
 412        { 0x89, 0xaf },
 413        { 0x8a, 0xc5 },
 414        { 0x8b, 0xd7 },
 415        { 0x8c, 0xe8 },
 416        { 0x8d, 0x20 },
 417
 418        { 0x0c, 0x90 },
 419
 420        { 0x2b, 0x00 },
 421        { 0x22, 0x7f },
 422        { 0x23, 0x03 },
 423        { 0x11, 0x01 },
 424        { 0x0c, 0xd0 },
 425        { 0x64, 0xff },
 426        { 0x0d, 0x41 },
 427
 428        { 0x14, 0x41 },
 429        { 0x0e, 0xcd },
 430        { 0xac, 0xbf },
 431        { 0x8e, 0x00 },         /* De-noise threshold */
 432        { 0x0c, 0xd0 }
 433};
 434static const u8 bridge_start_vga[][2] = {
 435        {0x1c, 0x00},
 436        {0x1d, 0x40},
 437        {0x1d, 0x02},
 438        {0x1d, 0x00},
 439        {0x1d, 0x02},
 440        {0x1d, 0x58},
 441        {0x1d, 0x00},
 442        {0xc0, 0x50},
 443        {0xc1, 0x3c},
 444};
 445static const u8 sensor_start_vga[][2] = {
 446        {0x12, 0x00},
 447        {0x17, 0x26},
 448        {0x18, 0xa0},
 449        {0x19, 0x07},
 450        {0x1a, 0xf0},
 451        {0x29, 0xa0},
 452        {0x2c, 0xf0},
 453        {0x65, 0x20},
 454};
 455static const u8 bridge_start_qvga[][2] = {
 456        {0x1c, 0x00},
 457        {0x1d, 0x40},
 458        {0x1d, 0x02},
 459        {0x1d, 0x00},
 460        {0x1d, 0x01},
 461        {0x1d, 0x4b},
 462        {0x1d, 0x00},
 463        {0xc0, 0x28},
 464        {0xc1, 0x1e},
 465};
 466static const u8 sensor_start_qvga[][2] = {
 467        {0x12, 0x40},
 468        {0x17, 0x3f},
 469        {0x18, 0x50},
 470        {0x19, 0x03},
 471        {0x1a, 0x78},
 472        {0x29, 0x50},
 473        {0x2c, 0x78},
 474        {0x65, 0x2f},
 475};
 476
 477static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
 478{
 479        struct usb_device *udev = gspca_dev->dev;
 480        int ret;
 481
 482        if (gspca_dev->usb_err < 0)
 483                return;
 484
 485        PDEBUG(D_USBO, "SET 01 0000 %04x %02x", reg, val);
 486        gspca_dev->usb_buf[0] = val;
 487        ret = usb_control_msg(udev,
 488                              usb_sndctrlpipe(udev, 0),
 489                              0x01,
 490                              USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
 491                              0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
 492        if (ret < 0) {
 493                err("write failed %d", ret);
 494                gspca_dev->usb_err = ret;
 495        }
 496}
 497
 498static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg)
 499{
 500        struct usb_device *udev = gspca_dev->dev;
 501        int ret;
 502
 503        if (gspca_dev->usb_err < 0)
 504                return 0;
 505        ret = usb_control_msg(udev,
 506                              usb_rcvctrlpipe(udev, 0),
 507                              0x01,
 508                              USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
 509                              0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
 510        PDEBUG(D_USBI, "GET 01 0000 %04x %02x", reg, gspca_dev->usb_buf[0]);
 511        if (ret < 0) {
 512                err("read failed %d", ret);
 513                gspca_dev->usb_err = ret;
 514        }
 515        return gspca_dev->usb_buf[0];
 516}
 517
 518/* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
 519 * (direction and output)? */
 520static void ov534_set_led(struct gspca_dev *gspca_dev, int status)
 521{
 522        u8 data;
 523
 524        PDEBUG(D_CONF, "led status: %d", status);
 525
 526        data = ov534_reg_read(gspca_dev, 0x21);
 527        data |= 0x80;
 528        ov534_reg_write(gspca_dev, 0x21, data);
 529
 530        data = ov534_reg_read(gspca_dev, 0x23);
 531        if (status)
 532                data |= 0x80;
 533        else
 534                data &= ~0x80;
 535
 536        ov534_reg_write(gspca_dev, 0x23, data);
 537
 538        if (!status) {
 539                data = ov534_reg_read(gspca_dev, 0x21);
 540                data &= ~0x80;
 541                ov534_reg_write(gspca_dev, 0x21, data);
 542        }
 543}
 544
 545static int sccb_check_status(struct gspca_dev *gspca_dev)
 546{
 547        u8 data;
 548        int i;
 549
 550        for (i = 0; i < 5; i++) {
 551                data = ov534_reg_read(gspca_dev, OV534_REG_STATUS);
 552
 553                switch (data) {
 554                case 0x00:
 555                        return 1;
 556                case 0x04:
 557                        return 0;
 558                case 0x03:
 559                        break;
 560                default:
 561                        PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5",
 562                               data, i + 1);
 563                }
 564        }
 565        return 0;
 566}
 567
 568static void sccb_reg_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
 569{
 570        PDEBUG(D_USBO, "sccb write: %02x %02x", reg, val);
 571        ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
 572        ov534_reg_write(gspca_dev, OV534_REG_WRITE, val);
 573        ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
 574
 575        if (!sccb_check_status(gspca_dev)) {
 576                err("sccb_reg_write failed");
 577                gspca_dev->usb_err = -EIO;
 578        }
 579}
 580
 581static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg)
 582{
 583        ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
 584        ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
 585        if (!sccb_check_status(gspca_dev))
 586                err("sccb_reg_read failed 1");
 587
 588        ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
 589        if (!sccb_check_status(gspca_dev))
 590                err("sccb_reg_read failed 2");
 591
 592        return ov534_reg_read(gspca_dev, OV534_REG_READ);
 593}
 594
 595/* output a bridge sequence (reg - val) */
 596static void reg_w_array(struct gspca_dev *gspca_dev,
 597                        const u8 (*data)[2], int len)
 598{
 599        while (--len >= 0) {
 600                ov534_reg_write(gspca_dev, (*data)[0], (*data)[1]);
 601                data++;
 602        }
 603}
 604
 605/* output a sensor sequence (reg - val) */
 606static void sccb_w_array(struct gspca_dev *gspca_dev,
 607                        const u8 (*data)[2], int len)
 608{
 609        while (--len >= 0) {
 610                if ((*data)[0] != 0xff) {
 611                        sccb_reg_write(gspca_dev, (*data)[0], (*data)[1]);
 612                } else {
 613                        sccb_reg_read(gspca_dev, (*data)[1]);
 614                        sccb_reg_write(gspca_dev, 0xff, 0x00);
 615                }
 616                data++;
 617        }
 618}
 619
 620/* ov772x specific controls */
 621static void set_frame_rate(struct gspca_dev *gspca_dev)
 622{
 623        struct sd *sd = (struct sd *) gspca_dev;
 624        int i;
 625        struct rate_s {
 626                u8 fps;
 627                u8 r11;
 628                u8 r0d;
 629                u8 re5;
 630        };
 631        const struct rate_s *r;
 632        static const struct rate_s rate_0[] = { /* 640x480 */
 633                {60, 0x01, 0xc1, 0x04},
 634                {50, 0x01, 0x41, 0x02},
 635                {40, 0x02, 0xc1, 0x04},
 636                {30, 0x04, 0x81, 0x02},
 637                {15, 0x03, 0x41, 0x04},
 638        };
 639        static const struct rate_s rate_1[] = { /* 320x240 */
 640                {125, 0x02, 0x81, 0x02},
 641                {100, 0x02, 0xc1, 0x04},
 642                {75, 0x03, 0xc1, 0x04},
 643                {60, 0x04, 0xc1, 0x04},
 644                {50, 0x02, 0x41, 0x04},
 645                {40, 0x03, 0x41, 0x04},
 646                {30, 0x04, 0x41, 0x04},
 647        };
 648
 649        if (gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv == 0) {
 650                r = rate_0;
 651                i = ARRAY_SIZE(rate_0);
 652        } else {
 653                r = rate_1;
 654                i = ARRAY_SIZE(rate_1);
 655        }
 656        while (--i > 0) {
 657                if (sd->frame_rate >= r->fps)
 658                        break;
 659                r++;
 660        }
 661
 662        sccb_reg_write(gspca_dev, 0x11, r->r11);
 663        sccb_reg_write(gspca_dev, 0x0d, r->r0d);
 664        ov534_reg_write(gspca_dev, 0xe5, r->re5);
 665
 666        PDEBUG(D_PROBE, "frame_rate: %d", r->fps);
 667}
 668
 669static void setbrightness(struct gspca_dev *gspca_dev)
 670{
 671        struct sd *sd = (struct sd *) gspca_dev;
 672
 673        sccb_reg_write(gspca_dev, 0x9b, sd->brightness);
 674}
 675
 676static void setcontrast(struct gspca_dev *gspca_dev)
 677{
 678        struct sd *sd = (struct sd *) gspca_dev;
 679
 680        sccb_reg_write(gspca_dev, 0x9c, sd->contrast);
 681}
 682
 683static void setgain(struct gspca_dev *gspca_dev)
 684{
 685        struct sd *sd = (struct sd *) gspca_dev;
 686        u8 val;
 687
 688        if (sd->agc)
 689                return;
 690
 691        val = sd->gain;
 692        switch (val & 0x30) {
 693        case 0x00:
 694                val &= 0x0f;
 695                break;
 696        case 0x10:
 697                val &= 0x0f;
 698                val |= 0x30;
 699                break;
 700        case 0x20:
 701                val &= 0x0f;
 702                val |= 0x70;
 703                break;
 704        default:
 705/*      case 0x30: */
 706                val &= 0x0f;
 707                val |= 0xf0;
 708                break;
 709        }
 710        sccb_reg_write(gspca_dev, 0x00, val);
 711}
 712
 713static void setexposure(struct gspca_dev *gspca_dev)
 714{
 715        struct sd *sd = (struct sd *) gspca_dev;
 716        u8 val;
 717
 718        if (sd->aec)
 719                return;
 720
 721        /* 'val' is one byte and represents half of the exposure value we are
 722         * going to set into registers, a two bytes value:
 723         *
 724         *    MSB: ((u16) val << 1) >> 8   == val >> 7
 725         *    LSB: ((u16) val << 1) & 0xff == val << 1
 726         */
 727        val = sd->exposure;
 728        sccb_reg_write(gspca_dev, 0x08, val >> 7);
 729        sccb_reg_write(gspca_dev, 0x10, val << 1);
 730}
 731
 732static void setagc(struct gspca_dev *gspca_dev)
 733{
 734        struct sd *sd = (struct sd *) gspca_dev;
 735
 736        if (sd->agc) {
 737                sccb_reg_write(gspca_dev, 0x13,
 738                                sccb_reg_read(gspca_dev, 0x13) | 0x04);
 739                sccb_reg_write(gspca_dev, 0x64,
 740                                sccb_reg_read(gspca_dev, 0x64) | 0x03);
 741        } else {
 742                sccb_reg_write(gspca_dev, 0x13,
 743                                sccb_reg_read(gspca_dev, 0x13) & ~0x04);
 744                sccb_reg_write(gspca_dev, 0x64,
 745                                sccb_reg_read(gspca_dev, 0x64) & ~0x03);
 746
 747                setgain(gspca_dev);
 748        }
 749}
 750
 751static void setawb(struct gspca_dev *gspca_dev)
 752{
 753        struct sd *sd = (struct sd *) gspca_dev;
 754
 755        if (sd->awb) {
 756                sccb_reg_write(gspca_dev, 0x13,
 757                                sccb_reg_read(gspca_dev, 0x13) | 0x02);
 758                sccb_reg_write(gspca_dev, 0x63,
 759                                sccb_reg_read(gspca_dev, 0x63) | 0xc0);
 760        } else {
 761                sccb_reg_write(gspca_dev, 0x13,
 762                                sccb_reg_read(gspca_dev, 0x13) & ~0x02);
 763                sccb_reg_write(gspca_dev, 0x63,
 764                                sccb_reg_read(gspca_dev, 0x63) & ~0xc0);
 765        }
 766}
 767
 768static void setaec(struct gspca_dev *gspca_dev)
 769{
 770        struct sd *sd = (struct sd *) gspca_dev;
 771
 772        if (sd->aec)
 773                sccb_reg_write(gspca_dev, 0x13,
 774                                sccb_reg_read(gspca_dev, 0x13) | 0x01);
 775        else {
 776                sccb_reg_write(gspca_dev, 0x13,
 777                                sccb_reg_read(gspca_dev, 0x13) & ~0x01);
 778                setexposure(gspca_dev);
 779        }
 780}
 781
 782static void setsharpness(struct gspca_dev *gspca_dev)
 783{
 784        struct sd *sd = (struct sd *) gspca_dev;
 785        u8 val;
 786
 787        val = sd->sharpness;
 788        sccb_reg_write(gspca_dev, 0x91, val);   /* Auto de-noise threshold */
 789        sccb_reg_write(gspca_dev, 0x8e, val);   /* De-noise threshold */
 790}
 791
 792static void sethflip(struct gspca_dev *gspca_dev)
 793{
 794        struct sd *sd = (struct sd *) gspca_dev;
 795
 796        if (sd->hflip == 0)
 797                sccb_reg_write(gspca_dev, 0x0c,
 798                                sccb_reg_read(gspca_dev, 0x0c) | 0x40);
 799        else
 800                sccb_reg_write(gspca_dev, 0x0c,
 801                                sccb_reg_read(gspca_dev, 0x0c) & ~0x40);
 802}
 803
 804static void setvflip(struct gspca_dev *gspca_dev)
 805{
 806        struct sd *sd = (struct sd *) gspca_dev;
 807
 808        if (sd->vflip == 0)
 809                sccb_reg_write(gspca_dev, 0x0c,
 810                                sccb_reg_read(gspca_dev, 0x0c) | 0x80);
 811        else
 812                sccb_reg_write(gspca_dev, 0x0c,
 813                                sccb_reg_read(gspca_dev, 0x0c) & ~0x80);
 814}
 815
 816static void setfreqfltr(struct gspca_dev *gspca_dev)
 817{
 818        struct sd *sd = (struct sd *) gspca_dev;
 819
 820        if (sd->freqfltr == 0)
 821                sccb_reg_write(gspca_dev, 0x2b, 0x00);
 822        else
 823                sccb_reg_write(gspca_dev, 0x2b, 0x9e);
 824}
 825
 826
 827/* this function is called at probe time */
 828static int sd_config(struct gspca_dev *gspca_dev,
 829                     const struct usb_device_id *id)
 830{
 831        struct sd *sd = (struct sd *) gspca_dev;
 832        struct cam *cam;
 833
 834        cam = &gspca_dev->cam;
 835
 836        cam->cam_mode = ov772x_mode;
 837        cam->nmodes = ARRAY_SIZE(ov772x_mode);
 838        cam->mode_framerates = ov772x_framerates;
 839
 840        cam->bulk = 1;
 841        cam->bulk_size = 16384;
 842        cam->bulk_nurbs = 2;
 843
 844        sd->frame_rate = 30;
 845
 846        sd->brightness = BRIGHTNESS_DEF;
 847        sd->contrast = CONTRAST_DEF;
 848        sd->gain = GAIN_DEF;
 849        sd->exposure = EXPO_DEF;
 850#if AGC_DEF != 0
 851        sd->agc = AGC_DEF;
 852#else
 853        gspca_dev->ctrl_inac |= (1 << AWB_IDX);
 854#endif
 855        sd->awb = AWB_DEF;
 856        sd->aec = AEC_DEF;
 857        sd->sharpness = SHARPNESS_DEF;
 858        sd->hflip = HFLIP_DEF;
 859        sd->vflip = VFLIP_DEF;
 860        sd->freqfltr = FREQFLTR_DEF;
 861
 862        return 0;
 863}
 864
 865/* this function is called at probe and resume time */
 866static int sd_init(struct gspca_dev *gspca_dev)
 867{
 868        u16 sensor_id;
 869
 870        /* reset bridge */
 871        ov534_reg_write(gspca_dev, 0xe7, 0x3a);
 872        ov534_reg_write(gspca_dev, 0xe0, 0x08);
 873        msleep(100);
 874
 875        /* initialize the sensor address */
 876        ov534_reg_write(gspca_dev, OV534_REG_ADDRESS, 0x42);
 877
 878        /* reset sensor */
 879        sccb_reg_write(gspca_dev, 0x12, 0x80);
 880        msleep(10);
 881
 882        /* probe the sensor */
 883        sccb_reg_read(gspca_dev, 0x0a);
 884        sensor_id = sccb_reg_read(gspca_dev, 0x0a) << 8;
 885        sccb_reg_read(gspca_dev, 0x0b);
 886        sensor_id |= sccb_reg_read(gspca_dev, 0x0b);
 887        PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id);
 888
 889        /* initialize */
 890        reg_w_array(gspca_dev, bridge_init,
 891                        ARRAY_SIZE(bridge_init));
 892        ov534_set_led(gspca_dev, 1);
 893        sccb_w_array(gspca_dev, sensor_init,
 894                        ARRAY_SIZE(sensor_init));
 895        ov534_reg_write(gspca_dev, 0xe0, 0x09);
 896        ov534_set_led(gspca_dev, 0);
 897        set_frame_rate(gspca_dev);
 898
 899        return gspca_dev->usb_err;
 900}
 901
 902static int sd_start(struct gspca_dev *gspca_dev)
 903{
 904        int mode;
 905
 906        mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
 907        if (mode != 0) {        /* 320x240 */
 908                reg_w_array(gspca_dev, bridge_start_qvga,
 909                                ARRAY_SIZE(bridge_start_qvga));
 910                sccb_w_array(gspca_dev, sensor_start_qvga,
 911                                ARRAY_SIZE(sensor_start_qvga));
 912        } else {                /* 640x480 */
 913                reg_w_array(gspca_dev, bridge_start_vga,
 914                                ARRAY_SIZE(bridge_start_vga));
 915                sccb_w_array(gspca_dev, sensor_start_vga,
 916                                ARRAY_SIZE(sensor_start_vga));
 917        }
 918        set_frame_rate(gspca_dev);
 919
 920        setagc(gspca_dev);
 921        setawb(gspca_dev);
 922        setaec(gspca_dev);
 923        setgain(gspca_dev);
 924        setexposure(gspca_dev);
 925        setbrightness(gspca_dev);
 926        setcontrast(gspca_dev);
 927        setsharpness(gspca_dev);
 928        setvflip(gspca_dev);
 929        sethflip(gspca_dev);
 930        setfreqfltr(gspca_dev);
 931
 932        ov534_set_led(gspca_dev, 1);
 933        ov534_reg_write(gspca_dev, 0xe0, 0x00);
 934        return gspca_dev->usb_err;
 935}
 936
 937static void sd_stopN(struct gspca_dev *gspca_dev)
 938{
 939        ov534_reg_write(gspca_dev, 0xe0, 0x09);
 940        ov534_set_led(gspca_dev, 0);
 941}
 942
 943/* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
 944#define UVC_STREAM_EOH  (1 << 7)
 945#define UVC_STREAM_ERR  (1 << 6)
 946#define UVC_STREAM_STI  (1 << 5)
 947#define UVC_STREAM_RES  (1 << 4)
 948#define UVC_STREAM_SCR  (1 << 3)
 949#define UVC_STREAM_PTS  (1 << 2)
 950#define UVC_STREAM_EOF  (1 << 1)
 951#define UVC_STREAM_FID  (1 << 0)
 952
 953static void sd_pkt_scan(struct gspca_dev *gspca_dev,
 954                        u8 *data, int len)
 955{
 956        struct sd *sd = (struct sd *) gspca_dev;
 957        __u32 this_pts;
 958        u16 this_fid;
 959        int remaining_len = len;
 960
 961        do {
 962                len = min(remaining_len, 2048);
 963
 964                /* Payloads are prefixed with a UVC-style header.  We
 965                   consider a frame to start when the FID toggles, or the PTS
 966                   changes.  A frame ends when EOF is set, and we've received
 967                   the correct number of bytes. */
 968
 969                /* Verify UVC header.  Header length is always 12 */
 970                if (data[0] != 12 || len < 12) {
 971                        PDEBUG(D_PACK, "bad header");
 972                        goto discard;
 973                }
 974
 975                /* Check errors */
 976                if (data[1] & UVC_STREAM_ERR) {
 977                        PDEBUG(D_PACK, "payload error");
 978                        goto discard;
 979                }
 980
 981                /* Extract PTS and FID */
 982                if (!(data[1] & UVC_STREAM_PTS)) {
 983                        PDEBUG(D_PACK, "PTS not present");
 984                        goto discard;
 985                }
 986                this_pts = (data[5] << 24) | (data[4] << 16)
 987                                                | (data[3] << 8) | data[2];
 988                this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0;
 989
 990                /* If PTS or FID has changed, start a new frame. */
 991                if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
 992                        if (gspca_dev->last_packet_type == INTER_PACKET)
 993                                gspca_frame_add(gspca_dev, LAST_PACKET,
 994                                                NULL, 0);
 995                        sd->last_pts = this_pts;
 996                        sd->last_fid = this_fid;
 997                        gspca_frame_add(gspca_dev, FIRST_PACKET,
 998                                        data + 12, len - 12);
 999                /* If this packet is marked as EOF, end the frame */
1000                } else if (data[1] & UVC_STREAM_EOF) {
1001                        sd->last_pts = 0;
1002                        if (gspca_dev->image_len + len - 12 !=
1003                            gspca_dev->width * gspca_dev->height * 2) {
1004                                PDEBUG(D_PACK, "wrong sized frame");
1005                                goto discard;
1006                        }
1007                        gspca_frame_add(gspca_dev, LAST_PACKET,
1008                                        data + 12, len - 12);
1009                } else {
1010
1011                        /* Add the data from this payload */
1012                        gspca_frame_add(gspca_dev, INTER_PACKET,
1013                                        data + 12, len - 12);
1014                }
1015
1016                /* Done this payload */
1017                goto scan_next;
1018
1019discard:
1020                /* Discard data until a new frame starts. */
1021                gspca_dev->last_packet_type = DISCARD_PACKET;
1022
1023scan_next:
1024                remaining_len -= len;
1025                data += len;
1026        } while (remaining_len > 0);
1027}
1028
1029/* controls */
1030static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
1031{
1032        struct sd *sd = (struct sd *) gspca_dev;
1033
1034        sd->gain = val;
1035        if (gspca_dev->streaming)
1036                setgain(gspca_dev);
1037        return 0;
1038}
1039
1040static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
1041{
1042        struct sd *sd = (struct sd *) gspca_dev;
1043
1044        *val = sd->gain;
1045        return 0;
1046}
1047
1048static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
1049{
1050        struct sd *sd = (struct sd *) gspca_dev;
1051
1052        sd->exposure = val;
1053        if (gspca_dev->streaming)
1054                setexposure(gspca_dev);
1055        return 0;
1056}
1057
1058static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
1059{
1060        struct sd *sd = (struct sd *) gspca_dev;
1061
1062        *val = sd->exposure;
1063        return 0;
1064}
1065
1066static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
1067{
1068        struct sd *sd = (struct sd *) gspca_dev;
1069
1070        sd->brightness = val;
1071        if (gspca_dev->streaming)
1072                setbrightness(gspca_dev);
1073        return 0;
1074}
1075
1076static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
1077{
1078        struct sd *sd = (struct sd *) gspca_dev;
1079
1080        *val = sd->brightness;
1081        return 0;
1082}
1083
1084static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
1085{
1086        struct sd *sd = (struct sd *) gspca_dev;
1087
1088        sd->contrast = val;
1089        if (gspca_dev->streaming)
1090                setcontrast(gspca_dev);
1091        return 0;
1092}
1093
1094static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
1095{
1096        struct sd *sd = (struct sd *) gspca_dev;
1097
1098        *val = sd->contrast;
1099        return 0;
1100}
1101
1102static int sd_setagc(struct gspca_dev *gspca_dev, __s32 val)
1103{
1104        struct sd *sd = (struct sd *) gspca_dev;
1105
1106        sd->agc = val;
1107
1108        if (gspca_dev->streaming) {
1109
1110                /* the auto white balance control works only
1111                 * when auto gain is set */
1112                if (val)
1113                        gspca_dev->ctrl_inac &= ~(1 << AWB_IDX);
1114                else
1115                        gspca_dev->ctrl_inac |= (1 << AWB_IDX);
1116                setagc(gspca_dev);
1117        }
1118        return 0;
1119}
1120
1121static int sd_getagc(struct gspca_dev *gspca_dev, __s32 *val)
1122{
1123        struct sd *sd = (struct sd *) gspca_dev;
1124
1125        *val = sd->agc;
1126        return 0;
1127}
1128
1129static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val)
1130{
1131        struct sd *sd = (struct sd *) gspca_dev;
1132
1133        sd->awb = val;
1134        if (gspca_dev->streaming)
1135                setawb(gspca_dev);
1136        return 0;
1137}
1138
1139static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val)
1140{
1141        struct sd *sd = (struct sd *) gspca_dev;
1142
1143        *val = sd->awb;
1144        return 0;
1145}
1146
1147static int sd_setaec(struct gspca_dev *gspca_dev, __s32 val)
1148{
1149        struct sd *sd = (struct sd *) gspca_dev;
1150
1151        sd->aec = val;
1152        if (gspca_dev->streaming)
1153                setaec(gspca_dev);
1154        return 0;
1155}
1156
1157static int sd_getaec(struct gspca_dev *gspca_dev, __s32 *val)
1158{
1159        struct sd *sd = (struct sd *) gspca_dev;
1160
1161        *val = sd->aec;
1162        return 0;
1163}
1164
1165static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
1166{
1167        struct sd *sd = (struct sd *) gspca_dev;
1168
1169        sd->sharpness = val;
1170        if (gspca_dev->streaming)
1171                setsharpness(gspca_dev);
1172        return 0;
1173}
1174
1175static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
1176{
1177        struct sd *sd = (struct sd *) gspca_dev;
1178
1179        *val = sd->sharpness;
1180        return 0;
1181}
1182
1183static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
1184{
1185        struct sd *sd = (struct sd *) gspca_dev;
1186
1187        sd->hflip = val;
1188        if (gspca_dev->streaming)
1189                sethflip(gspca_dev);
1190        return 0;
1191}
1192
1193static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
1194{
1195        struct sd *sd = (struct sd *) gspca_dev;
1196
1197        *val = sd->hflip;
1198        return 0;
1199}
1200
1201static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
1202{
1203        struct sd *sd = (struct sd *) gspca_dev;
1204
1205        sd->vflip = val;
1206        if (gspca_dev->streaming)
1207                setvflip(gspca_dev);
1208        return 0;
1209}
1210
1211static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
1212{
1213        struct sd *sd = (struct sd *) gspca_dev;
1214
1215        *val = sd->vflip;
1216        return 0;
1217}
1218
1219static int sd_setfreqfltr(struct gspca_dev *gspca_dev, __s32 val)
1220{
1221        struct sd *sd = (struct sd *) gspca_dev;
1222
1223        sd->freqfltr = val;
1224        if (gspca_dev->streaming)
1225                setfreqfltr(gspca_dev);
1226        return 0;
1227}
1228
1229static int sd_getfreqfltr(struct gspca_dev *gspca_dev, __s32 *val)
1230{
1231        struct sd *sd = (struct sd *) gspca_dev;
1232
1233        *val = sd->freqfltr;
1234        return 0;
1235}
1236
1237static int sd_querymenu(struct gspca_dev *gspca_dev,
1238                struct v4l2_querymenu *menu)
1239{
1240        switch (menu->id) {
1241        case V4L2_CID_POWER_LINE_FREQUENCY:
1242                switch (menu->index) {
1243                case 0:         /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
1244                        strcpy((char *) menu->name, "Disabled");
1245                        return 0;
1246                case 1:         /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
1247                        strcpy((char *) menu->name, "50 Hz");
1248                        return 0;
1249                }
1250                break;
1251        }
1252
1253        return -EINVAL;
1254}
1255
1256/* get stream parameters (framerate) */
1257static void sd_get_streamparm(struct gspca_dev *gspca_dev,
1258                             struct v4l2_streamparm *parm)
1259{
1260        struct v4l2_captureparm *cp = &parm->parm.capture;
1261        struct v4l2_fract *tpf = &cp->timeperframe;
1262        struct sd *sd = (struct sd *) gspca_dev;
1263
1264        cp->capability |= V4L2_CAP_TIMEPERFRAME;
1265        tpf->numerator = 1;
1266        tpf->denominator = sd->frame_rate;
1267}
1268
1269/* set stream parameters (framerate) */
1270static void sd_set_streamparm(struct gspca_dev *gspca_dev,
1271                             struct v4l2_streamparm *parm)
1272{
1273        struct v4l2_captureparm *cp = &parm->parm.capture;
1274        struct v4l2_fract *tpf = &cp->timeperframe;
1275        struct sd *sd = (struct sd *) gspca_dev;
1276
1277        /* Set requested framerate */
1278        sd->frame_rate = tpf->denominator / tpf->numerator;
1279        if (gspca_dev->streaming)
1280                set_frame_rate(gspca_dev);
1281
1282        /* Return the actual framerate */
1283        tpf->numerator = 1;
1284        tpf->denominator = sd->frame_rate;
1285}
1286
1287/* sub-driver description */
1288static const struct sd_desc sd_desc = {
1289        .name     = MODULE_NAME,
1290        .ctrls    = sd_ctrls,
1291        .nctrls   = ARRAY_SIZE(sd_ctrls),
1292        .config   = sd_config,
1293        .init     = sd_init,
1294        .start    = sd_start,
1295        .stopN    = sd_stopN,
1296        .pkt_scan = sd_pkt_scan,
1297        .querymenu = sd_querymenu,
1298        .get_streamparm = sd_get_streamparm,
1299        .set_streamparm = sd_set_streamparm,
1300};
1301
1302/* -- module initialisation -- */
1303static const struct usb_device_id device_table[] = {
1304        {USB_DEVICE(0x1415, 0x2000)},
1305        {}
1306};
1307
1308MODULE_DEVICE_TABLE(usb, device_table);
1309
1310/* -- device connect -- */
1311static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
1312{
1313        return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
1314                                THIS_MODULE);
1315}
1316
1317static struct usb_driver sd_driver = {
1318        .name       = MODULE_NAME,
1319        .id_table   = device_table,
1320        .probe      = sd_probe,
1321        .disconnect = gspca_disconnect,
1322#ifdef CONFIG_PM
1323        .suspend    = gspca_suspend,
1324        .resume     = gspca_resume,
1325#endif
1326};
1327
1328/* -- module insert / remove -- */
1329static int __init sd_mod_init(void)
1330{
1331        return usb_register(&sd_driver);
1332}
1333
1334static void __exit sd_mod_exit(void)
1335{
1336        usb_deregister(&sd_driver);
1337}
1338
1339module_init(sd_mod_init);
1340module_exit(sd_mod_exit);
1341