ov534.c 29.7 KB
Newer Older
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 9 10 11
 *
 * Based on a prototype written by Mark Ferrell <majortrips@gmail.com>
 * USB protocol reverse engineered by Jim Paris <jim@jtan.com>
 * https://jim.sh/svn/jim/devl/playstation/ps3/eye/test/
 *
12
 * PS3 Eye camera enhanced by Richard Kaswy http://kaswy.free.fr
13 14
 * PS3 Eye camera, brightness, contrast, hue, AWB control added
 *	by Max Thrun <bear24rw@gmail.com>
15
 *
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#define MODULE_NAME "ov534"

#include "gspca.h"

35
#define OV534_REG_ADDRESS	0xf1	/* sensor address */
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#define OV534_REG_SUBADDR	0xf2
#define OV534_REG_WRITE		0xf3
#define OV534_REG_READ		0xf4
#define OV534_REG_OPERATION	0xf5
#define OV534_REG_STATUS	0xf6

#define OV534_OP_WRITE_3	0x37
#define OV534_OP_WRITE_2	0x33
#define OV534_OP_READ_2		0xf9

#define CTRL_TIMEOUT 500

MODULE_AUTHOR("Antonio Ospite <ospite@studenti.unina.it>");
MODULE_DESCRIPTION("GSPCA/OV534 USB Camera Driver");
MODULE_LICENSE("GPL");

/* specific webcam descriptor */
struct sd {
	struct gspca_dev gspca_dev;	/* !! must be the first item */
55
	__u32 last_pts;
56 57
	u16 last_fid;
	u8 frame_rate;
58 59 60

	u8 brightness;
	u8 contrast;
61 62 63 64
	u8 gain;
	u8 exposure;
	u8 redblc;
	u8 blueblc;
65
	u8 hue;
66
	u8 autogain;
67
	u8 awb;
68
	s8 sharpness;
69 70
	u8 hflip;
	u8 vflip;
71

72 73 74
};

/* V4L2 controls supported by the driver */
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_setredblc(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getredblc(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_setblueblc(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getblueblc(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
91 92 93 94 95 96 97 98
static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val);
static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
99

100
static const struct ctrl sd_ctrls[] = {
101
    {							/* 0 */
102 103 104 105 106 107 108
	{
		.id      = V4L2_CID_BRIGHTNESS,
		.type    = V4L2_CTRL_TYPE_INTEGER,
		.name    = "Brightness",
		.minimum = 0,
		.maximum = 255,
		.step    = 1,
109 110
#define BRIGHTNESS_DEF 20
		.default_value = BRIGHTNESS_DEF,
111 112 113 114
	},
	.set = sd_setbrightness,
	.get = sd_getbrightness,
    },
115
    {							/* 1 */
116 117 118 119 120 121 122
	{
		.id      = V4L2_CID_CONTRAST,
		.type    = V4L2_CTRL_TYPE_INTEGER,
		.name    = "Contrast",
		.minimum = 0,
		.maximum = 255,
		.step    = 1,
123 124
#define CONTRAST_DEF 37
		.default_value = CONTRAST_DEF,
125 126 127 128
	},
	.set = sd_setcontrast,
	.get = sd_getcontrast,
    },
129
    {							/* 2 */
130 131 132 133 134 135 136 137 138 139 140 141 142
	{
	    .id      = V4L2_CID_GAIN,
	    .type    = V4L2_CTRL_TYPE_INTEGER,
	    .name    = "Main Gain",
	    .minimum = 0,
	    .maximum = 63,
	    .step    = 1,
#define GAIN_DEF 20
	    .default_value = GAIN_DEF,
	},
	.set = sd_setgain,
	.get = sd_getgain,
    },
143
    {							/* 3 */
144 145 146 147 148 149 150
	{
	    .id      = V4L2_CID_EXPOSURE,
	    .type    = V4L2_CTRL_TYPE_INTEGER,
	    .name    = "Exposure",
	    .minimum = 0,
	    .maximum = 255,
	    .step    = 1,
151 152
#define EXPO_DEF 120
	    .default_value = EXPO_DEF,
153 154 155 156
	},
	.set = sd_setexposure,
	.get = sd_getexposure,
    },
157
    {							/* 4 */
158 159 160 161 162 163 164 165 166 167 168 169 170
	{
	    .id      = V4L2_CID_RED_BALANCE,
	    .type    = V4L2_CTRL_TYPE_INTEGER,
	    .name    = "Red Balance",
	    .minimum = 0,
	    .maximum = 255,
	    .step    = 1,
#define RED_BALANCE_DEF 128
	    .default_value = RED_BALANCE_DEF,
	},
	.set = sd_setredblc,
	.get = sd_getredblc,
    },
171
    {							/* 5 */
172 173 174 175 176 177 178 179 180 181 182 183 184
	{
	    .id      = V4L2_CID_BLUE_BALANCE,
	    .type    = V4L2_CTRL_TYPE_INTEGER,
	    .name    = "Blue Balance",
	    .minimum = 0,
	    .maximum = 255,
	    .step    = 1,
#define BLUE_BALANCE_DEF 128
	    .default_value = BLUE_BALANCE_DEF,
	},
	.set = sd_setblueblc,
	.get = sd_getblueblc,
    },
185
    {							/* 6 */
186 187 188 189 190 191 192 193 194 195 196 197 198
	{
		.id      = V4L2_CID_HUE,
		.type    = V4L2_CTRL_TYPE_INTEGER,
		.name    = "Hue",
		.minimum = 0,
		.maximum = 255,
		.step    = 1,
#define HUE_DEF 143
		.default_value = HUE_DEF,
	},
	.set = sd_sethue,
	.get = sd_gethue,
    },
199
    {							/* 7 */
200 201 202 203 204 205 206
	{
	    .id      = V4L2_CID_AUTOGAIN,
	    .type    = V4L2_CTRL_TYPE_BOOLEAN,
	    .name    = "Autogain",
	    .minimum = 0,
	    .maximum = 1,
	    .step    = 1,
207 208
#define AUTOGAIN_DEF 0
	    .default_value = AUTOGAIN_DEF,
209 210 211 212
	},
	.set = sd_setautogain,
	.get = sd_getautogain,
    },
213
#define AWB_IDX 8
214
    {							/* 8 */
215 216 217 218 219 220 221 222 223 224 225 226 227
	{
		.id      = V4L2_CID_AUTO_WHITE_BALANCE,
		.type    = V4L2_CTRL_TYPE_BOOLEAN,
		.name    = "Auto White Balance",
		.minimum = 0,
		.maximum = 1,
		.step    = 1,
#define AWB_DEF 0
		.default_value = AWB_DEF,
	},
	.set = sd_setawb,
	.get = sd_getawb,
    },
228
    {							/* 9 */
229 230 231 232 233 234 235
	{
	    .id      = V4L2_CID_SHARPNESS,
	    .type    = V4L2_CTRL_TYPE_INTEGER,
	    .name    = "Sharpness",
	    .minimum = 0,
	    .maximum = 63,
	    .step    = 1,
236 237
#define SHARPNESS_DEF 0
	    .default_value = SHARPNESS_DEF,
238 239 240 241
	},
	.set = sd_setsharpness,
	.get = sd_getsharpness,
    },
242
    {							/* 10 */
243 244 245 246 247 248 249 250 251 252 253 254 255
	{
	    .id      = V4L2_CID_HFLIP,
	    .type    = V4L2_CTRL_TYPE_BOOLEAN,
	    .name    = "HFlip",
	    .minimum = 0,
	    .maximum = 1,
	    .step    = 1,
#define HFLIP_DEF 0
	    .default_value = HFLIP_DEF,
	},
	.set = sd_sethflip,
	.get = sd_gethflip,
    },
256
    {							/* 11 */
257 258 259 260 261 262 263 264 265 266 267 268 269 270
	{
	    .id      = V4L2_CID_VFLIP,
	    .type    = V4L2_CTRL_TYPE_BOOLEAN,
	    .name    = "VFlip",
	    .minimum = 0,
	    .maximum = 1,
	    .step    = 1,
#define VFLIP_DEF 0
	    .default_value = VFLIP_DEF,
	},
	.set = sd_setvflip,
	.get = sd_getvflip,
    },
};
271

272
static const struct v4l2_pix_format ov772x_mode[] = {
273 274 275
	{320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
	 .bytesperline = 320 * 2,
	 .sizeimage = 320 * 240 * 2,
276
	 .colorspace = V4L2_COLORSPACE_SRGB,
277
	 .priv = 1},
278 279 280
	{640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
	 .bytesperline = 640 * 2,
	 .sizeimage = 640 * 480 * 2,
281 282 283 284
	 .colorspace = V4L2_COLORSPACE_SRGB,
	 .priv = 0},
};

285 286 287 288 289 290 291 292 293 294 295 296 297 298
static const u8 qvga_rates[] = {125, 100, 75, 60, 50, 40, 30};
static const u8 vga_rates[] = {60, 50, 40, 30, 15};

static const struct framerates ov772x_framerates[] = {
	{ /* 320x240 */
		.rates = qvga_rates,
		.nrates = ARRAY_SIZE(qvga_rates),
	},
	{ /* 640x480 */
		.rates = vga_rates,
		.nrates = ARRAY_SIZE(vga_rates),
	},
};

299
static const u8 bridge_init[][2] = {
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
	{ 0xc2, 0x0c },
	{ 0x88, 0xf8 },
	{ 0xc3, 0x69 },
	{ 0x89, 0xff },
	{ 0x76, 0x03 },
	{ 0x92, 0x01 },
	{ 0x93, 0x18 },
	{ 0x94, 0x10 },
	{ 0x95, 0x10 },
	{ 0xe2, 0x00 },
	{ 0xe7, 0x3e },

	{ 0x96, 0x00 },

	{ 0x97, 0x20 },
	{ 0x97, 0x20 },
	{ 0x97, 0x20 },
	{ 0x97, 0x0a },
	{ 0x97, 0x3f },
	{ 0x97, 0x4a },
	{ 0x97, 0x20 },
	{ 0x97, 0x15 },
	{ 0x97, 0x0b },

	{ 0x8e, 0x40 },
	{ 0x1f, 0x81 },
	{ 0x34, 0x05 },
	{ 0xe3, 0x04 },
	{ 0x88, 0x00 },
	{ 0x89, 0x00 },
	{ 0x76, 0x00 },
	{ 0xe7, 0x2e },
	{ 0x31, 0xf9 },
	{ 0x25, 0x42 },
	{ 0x21, 0xf0 },

	{ 0x1c, 0x00 },
	{ 0x1d, 0x40 },
338 339
	{ 0x1d, 0x02 }, /* payload size 0x0200 * 4 = 2048 bytes */
	{ 0x1d, 0x00 }, /* payload size */
340

341 342 343
	{ 0x1d, 0x02 }, /* frame size 0x025800 * 4 = 614400 */
	{ 0x1d, 0x58 }, /* frame size */
	{ 0x1d, 0x00 }, /* frame size */
344

345 346 347 348
	{ 0x1c, 0x0a },
	{ 0x1d, 0x08 }, /* turn on UVC header */
	{ 0x1d, 0x0e }, /* .. */

349 350 351 352 353 354 355 356
	{ 0x8d, 0x1c },
	{ 0x8e, 0x80 },
	{ 0xe5, 0x04 },

	{ 0xc0, 0x50 },
	{ 0xc1, 0x3c },
	{ 0xc2, 0x0c },
};
357
static const u8 sensor_init[][2] = {
358 359
	{ 0x12, 0x80 },
	{ 0x11, 0x01 },
360 361 362 363 364 365 366 367 368 369 370
/*fixme: better have a delay?*/
	{ 0x11, 0x01 },
	{ 0x11, 0x01 },
	{ 0x11, 0x01 },
	{ 0x11, 0x01 },
	{ 0x11, 0x01 },
	{ 0x11, 0x01 },
	{ 0x11, 0x01 },
	{ 0x11, 0x01 },
	{ 0x11, 0x01 },
	{ 0x11, 0x01 },
371 372 373 374 375 376 377 378 379 380 381 382

	{ 0x3d, 0x03 },
	{ 0x17, 0x26 },
	{ 0x18, 0xa0 },
	{ 0x19, 0x07 },
	{ 0x1a, 0xf0 },
	{ 0x32, 0x00 },
	{ 0x29, 0xa0 },
	{ 0x2c, 0xf0 },
	{ 0x65, 0x20 },
	{ 0x11, 0x01 },
	{ 0x42, 0x7f },
383
	{ 0x63, 0xaa },		/* AWB - was e0 */
384 385
	{ 0x64, 0xff },
	{ 0x66, 0x00 },
386
	{ 0x13, 0xf0 },		/* com8 */
387 388 389 390 391 392 393 394 395 396 397 398
	{ 0x0d, 0x41 },
	{ 0x0f, 0xc5 },
	{ 0x14, 0x11 },

	{ 0x22, 0x7f },
	{ 0x23, 0x03 },
	{ 0x24, 0x40 },
	{ 0x25, 0x30 },
	{ 0x26, 0xa1 },
	{ 0x2a, 0x00 },
	{ 0x2b, 0x00 },
	{ 0x6b, 0xaa },
399
	{ 0x13, 0xff },		/* AWB */
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446

	{ 0x90, 0x05 },
	{ 0x91, 0x01 },
	{ 0x92, 0x03 },
	{ 0x93, 0x00 },
	{ 0x94, 0x60 },
	{ 0x95, 0x3c },
	{ 0x96, 0x24 },
	{ 0x97, 0x1e },
	{ 0x98, 0x62 },
	{ 0x99, 0x80 },
	{ 0x9a, 0x1e },
	{ 0x9b, 0x08 },
	{ 0x9c, 0x20 },
	{ 0x9e, 0x81 },

	{ 0xa6, 0x04 },
	{ 0x7e, 0x0c },
	{ 0x7f, 0x16 },
	{ 0x80, 0x2a },
	{ 0x81, 0x4e },
	{ 0x82, 0x61 },
	{ 0x83, 0x6f },
	{ 0x84, 0x7b },
	{ 0x85, 0x86 },
	{ 0x86, 0x8e },
	{ 0x87, 0x97 },
	{ 0x88, 0xa4 },
	{ 0x89, 0xaf },
	{ 0x8a, 0xc5 },
	{ 0x8b, 0xd7 },
	{ 0x8c, 0xe8 },
	{ 0x8d, 0x20 },

	{ 0x0c, 0x90 },

	{ 0x2b, 0x00 },
	{ 0x22, 0x7f },
	{ 0x23, 0x03 },
	{ 0x11, 0x01 },
	{ 0x0c, 0xd0 },
	{ 0x64, 0xff },
	{ 0x0d, 0x41 },

	{ 0x14, 0x41 },
	{ 0x0e, 0xcd },
	{ 0xac, 0xbf },
447
	{ 0x8e, 0x00 },		/* De-noise threshold */
448 449
	{ 0x0c, 0xd0 }
};
450
static const u8 bridge_start_vga[][2] = {
451 452 453 454 455 456 457 458 459 460
	{0x1c, 0x00},
	{0x1d, 0x40},
	{0x1d, 0x02},
	{0x1d, 0x00},
	{0x1d, 0x02},
	{0x1d, 0x58},
	{0x1d, 0x00},
	{0xc0, 0x50},
	{0xc1, 0x3c},
};
461
static const u8 sensor_start_vga[][2] = {
462 463 464 465 466 467 468
	{0x12, 0x00},
	{0x17, 0x26},
	{0x18, 0xa0},
	{0x19, 0x07},
	{0x1a, 0xf0},
	{0x29, 0xa0},
	{0x2c, 0xf0},
469
	{0x65, 0x20},
470
};
471
static const u8 bridge_start_qvga[][2] = {
472 473 474 475 476 477 478 479 480 481
	{0x1c, 0x00},
	{0x1d, 0x40},
	{0x1d, 0x02},
	{0x1d, 0x00},
	{0x1d, 0x01},
	{0x1d, 0x4b},
	{0x1d, 0x00},
	{0xc0, 0x28},
	{0xc1, 0x1e},
};
482
static const u8 sensor_start_qvga[][2] = {
483 484 485 486 487 488 489
	{0x12, 0x40},
	{0x17, 0x3f},
	{0x18, 0x50},
	{0x19, 0x03},
	{0x1a, 0x78},
	{0x29, 0x50},
	{0x2c, 0x78},
490
	{0x65, 0x2f},
491
};
492

493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
{
	struct usb_device *udev = gspca_dev->dev;
	int ret;

	PDEBUG(D_USBO, "reg=0x%04x, val=0%02x", reg, val);
	gspca_dev->usb_buf[0] = val;
	ret = usb_control_msg(udev,
			      usb_sndctrlpipe(udev, 0),
			      0x01,
			      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
			      0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
	if (ret < 0)
		PDEBUG(D_ERR, "write failed");
}

static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg)
{
	struct usb_device *udev = gspca_dev->dev;
	int ret;

	ret = usb_control_msg(udev,
			      usb_rcvctrlpipe(udev, 0),
			      0x01,
			      USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
			      0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
	PDEBUG(D_USBI, "reg=0x%04x, data=0x%02x", reg, gspca_dev->usb_buf[0]);
	if (ret < 0)
		PDEBUG(D_ERR, "read failed");
	return gspca_dev->usb_buf[0];
}

/* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
 * (direction and output)? */
static void ov534_set_led(struct gspca_dev *gspca_dev, int status)
{
	u8 data;

	PDEBUG(D_CONF, "led status: %d", status);

	data = ov534_reg_read(gspca_dev, 0x21);
	data |= 0x80;
	ov534_reg_write(gspca_dev, 0x21, data);

	data = ov534_reg_read(gspca_dev, 0x23);
	if (status)
		data |= 0x80;
	else
		data &= ~0x80;

	ov534_reg_write(gspca_dev, 0x23, data);

	if (!status) {
		data = ov534_reg_read(gspca_dev, 0x21);
		data &= ~0x80;
		ov534_reg_write(gspca_dev, 0x21, data);
	}
}

static int sccb_check_status(struct gspca_dev *gspca_dev)
{
	u8 data;
	int i;

	for (i = 0; i < 5; i++) {
		data = ov534_reg_read(gspca_dev, OV534_REG_STATUS);

		switch (data) {
		case 0x00:
			return 1;
		case 0x04:
			return 0;
		case 0x03:
			break;
		default:
			PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5",
			       data, i + 1);
		}
	}
	return 0;
}

static void sccb_reg_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
{
	PDEBUG(D_USBO, "reg: 0x%02x, val: 0x%02x", reg, val);
	ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
	ov534_reg_write(gspca_dev, OV534_REG_WRITE, val);
	ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);

	if (!sccb_check_status(gspca_dev))
		PDEBUG(D_ERR, "sccb_reg_write failed");
}

static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg)
{
	ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
	ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
	if (!sccb_check_status(gspca_dev))
		PDEBUG(D_ERR, "sccb_reg_read failed 1");

	ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
	if (!sccb_check_status(gspca_dev))
		PDEBUG(D_ERR, "sccb_reg_read failed 2");

	return ov534_reg_read(gspca_dev, OV534_REG_READ);
}

/* output a bridge sequence (reg - val) */
static void reg_w_array(struct gspca_dev *gspca_dev,
			const u8 (*data)[2], int len)
{
	while (--len >= 0) {
		ov534_reg_write(gspca_dev, (*data)[0], (*data)[1]);
		data++;
	}
}

/* output a sensor sequence (reg - val) */
static void sccb_w_array(struct gspca_dev *gspca_dev,
			const u8 (*data)[2], int len)
{
	while (--len >= 0) {
		if ((*data)[0] != 0xff) {
			sccb_reg_write(gspca_dev, (*data)[0], (*data)[1]);
		} else {
			sccb_reg_read(gspca_dev, (*data)[1]);
			sccb_reg_write(gspca_dev, 0xff, 0x00);
		}
		data++;
	}
}

625 626
/* ov772x specific controls */
static void set_frame_rate(struct gspca_dev *gspca_dev)
627 628
{
	struct sd *sd = (struct sd *) gspca_dev;
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
	int i;
	struct rate_s {
		u8 fps;
		u8 r11;
		u8 r0d;
		u8 re5;
	};
	const struct rate_s *r;
	static const struct rate_s rate_0[] = {	/* 640x480 */
		{60, 0x01, 0xc1, 0x04},
		{50, 0x01, 0x41, 0x02},
		{40, 0x02, 0xc1, 0x04},
		{30, 0x04, 0x81, 0x02},
		{15, 0x03, 0x41, 0x04},
	};
	static const struct rate_s rate_1[] = {	/* 320x240 */
		{125, 0x02, 0x81, 0x02},
		{100, 0x02, 0xc1, 0x04},
		{75, 0x03, 0xc1, 0x04},
		{60, 0x04, 0xc1, 0x04},
		{50, 0x02, 0x41, 0x04},
		{40, 0x03, 0x41, 0x04},
		{30, 0x04, 0x41, 0x04},
	};

	if (gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv == 0) {
		r = rate_0;
		i = ARRAY_SIZE(rate_0);
	} else {
		r = rate_1;
		i = ARRAY_SIZE(rate_1);
	}
	while (--i > 0) {
		if (sd->frame_rate >= r->fps)
			break;
		r++;
	}

	sccb_reg_write(gspca_dev, 0x11, r->r11);
	sccb_reg_write(gspca_dev, 0x0d, r->r0d);
	ov534_reg_write(gspca_dev, 0xe5, r->re5);

	PDEBUG(D_PROBE, "frame_rate: %d", r->fps);
}

674
static void setbrightness(struct gspca_dev *gspca_dev)
675 676 677 678 679 680
{
	struct sd *sd = (struct sd *) gspca_dev;

	sccb_reg_write(gspca_dev, 0x9B, sd->brightness);
}

681
static void setcontrast(struct gspca_dev *gspca_dev)
682 683 684 685 686 687
{
	struct sd *sd = (struct sd *) gspca_dev;

	sccb_reg_write(gspca_dev, 0x9C, sd->contrast);
}

688 689 690 691
static void setgain(struct gspca_dev *gspca_dev)
{
	struct sd *sd = (struct sd *) gspca_dev;
	u8 val;
692

693 694 695 696
	val = sd->gain;
	switch (val & 0x30) {
	case 0x00:
		val &= 0x0f;
697
		break;
698 699 700
	case 0x10:
		val &= 0x0f;
		val |= 0x30;
701
		break;
702 703 704
	case 0x20:
		val &= 0x0f;
		val |= 0x70;
705
		break;
706 707 708 709
	default:
/*	case 0x30: */
		val &= 0x0f;
		val |= 0xf0;
710 711
		break;
	}
712 713 714
	sccb_reg_write(gspca_dev, 0x00, val);
}

715
static void setexposure(struct gspca_dev *gspca_dev)
716 717 718 719 720 721 722 723 724 725 726 727
{
	struct sd *sd = (struct sd *) gspca_dev;
	u8 val;

	val = sd->exposure;
	sccb_reg_write(gspca_dev, 0x08, val >> 7);
	sccb_reg_write(gspca_dev, 0x10, val << 1);
}

static void setredblc(struct gspca_dev *gspca_dev)
{
	struct sd *sd = (struct sd *) gspca_dev;
728

729 730 731 732 733 734 735 736 737 738
	sccb_reg_write(gspca_dev, 0x43, sd->redblc);
}

static void setblueblc(struct gspca_dev *gspca_dev)
{
	struct sd *sd = (struct sd *) gspca_dev;

	sccb_reg_write(gspca_dev, 0x42, sd->blueblc);
}

739 740 741 742 743 744 745
static void sethue(struct gspca_dev *gspca_dev)
{
	struct sd *sd = (struct sd *) gspca_dev;

	sccb_reg_write(gspca_dev, 0x01, sd->hue);
}

746
static void setautogain(struct gspca_dev *gspca_dev)
747 748 749 750 751 752 753 754 755 756 757 758 759 760
{
	struct sd *sd = (struct sd *) gspca_dev;

	if (sd->autogain) {
		sccb_reg_write(gspca_dev, 0x13, 0xf7); /* AGC,AEC,AWB ON */
		sccb_reg_write(gspca_dev, 0x64,
				sccb_reg_read(gspca_dev, 0x64) | 0x03);
	} else {
		sccb_reg_write(gspca_dev, 0x13, 0xf0); /* AGC,AEC,AWB OFF */
		sccb_reg_write(gspca_dev, 0x64,
				sccb_reg_read(gspca_dev, 0x64) & 0xfc);
	}
}

761 762 763 764 765 766 767 768 769 770
static void setawb(struct gspca_dev *gspca_dev)
{
	struct sd *sd = (struct sd *) gspca_dev;

	if (sd->awb)
		sccb_reg_write(gspca_dev, 0x63, 0xe0);	/* AWB on */
	else
		sccb_reg_write(gspca_dev, 0x63, 0xaa);	/* AWB off */
}

771
static void setsharpness(struct gspca_dev *gspca_dev)
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802
{
	struct sd *sd = (struct sd *) gspca_dev;
	u8 val;

	val = sd->sharpness;
	sccb_reg_write(gspca_dev, 0x91, val);	/* vga noise */
	sccb_reg_write(gspca_dev, 0x8e, val);	/* qvga noise */
}

static void sethflip(struct gspca_dev *gspca_dev)
{
	struct sd *sd = (struct sd *) gspca_dev;

	if (sd->hflip == 0)
		sccb_reg_write(gspca_dev, 0x0c,
				sccb_reg_read(gspca_dev, 0x0c) | 0x40);
	else
		sccb_reg_write(gspca_dev, 0x0c,
				sccb_reg_read(gspca_dev, 0x0c) & 0xbf);
}

static void setvflip(struct gspca_dev *gspca_dev)
{
	struct sd *sd = (struct sd *) gspca_dev;

	if (sd->vflip == 0)
		sccb_reg_write(gspca_dev, 0x0c,
				sccb_reg_read(gspca_dev, 0x0c) | 0x80);
	else
		sccb_reg_write(gspca_dev, 0x0c,
				sccb_reg_read(gspca_dev, 0x0c) & 0x7f);
803
}
804 805 806 807 808

/* this function is called at probe time */
static int sd_config(struct gspca_dev *gspca_dev,
		     const struct usb_device_id *id)
{
809
	struct sd *sd = (struct sd *) gspca_dev;
810 811 812 813
	struct cam *cam;

	cam = &gspca_dev->cam;

814 815
	cam->cam_mode = ov772x_mode;
	cam->nmodes = ARRAY_SIZE(ov772x_mode);
816
	cam->mode_framerates = ov772x_framerates;
817

818 819 820
	cam->bulk = 1;
	cam->bulk_size = 16384;
	cam->bulk_nurbs = 2;
821

822
	sd->frame_rate = 30;
823

824 825 826 827 828 829 830 831 832
	sd->brightness = BRIGHTNESS_DEF;
	sd->contrast = CONTRAST_DEF;
	sd->gain = GAIN_DEF;
	sd->exposure = EXPO_DEF;
	sd->redblc = RED_BALANCE_DEF;
	sd->blueblc = BLUE_BALANCE_DEF;
	sd->hue = HUE_DEF;
#if AUTOGAIN_DEF != 0
	sd->autogain = AUTOGAIN_DEF;
833
#else
834
	gspca_dev->ctrl_inac |= (1 << AWB_IDX);
835 836
#endif
#if AWB_DEF != 0
837
	sd->awb = AWB_DEF
838
#endif
839 840
#if SHARPNESS_DEF != 0
	sd->sharpness = SHARPNESS_DEF;
841
#endif
842
#if HFLIP_DEF != 0
843
	sd->hflip = HFLIP_DEF;
844 845
#endif
#if VFLIP_DEF != 0
846
	sd->vflip = VFLIP_DEF;
847
#endif
848

849 850 851 852 853 854
	return 0;
}

/* this function is called at probe and resume time */
static int sd_init(struct gspca_dev *gspca_dev)
{
855 856 857 858 859 860 861 862
	u16 sensor_id;

	/* reset bridge */
	ov534_reg_write(gspca_dev, 0xe7, 0x3a);
	ov534_reg_write(gspca_dev, 0xe0, 0x08);
	msleep(100);

	/* initialize the sensor address */
863
	ov534_reg_write(gspca_dev, OV534_REG_ADDRESS, 0x42);
864 865 866 867 868 869 870 871 872 873 874 875 876

	/* reset sensor */
	sccb_reg_write(gspca_dev, 0x12, 0x80);
	msleep(10);

	/* probe the sensor */
	sccb_reg_read(gspca_dev, 0x0a);
	sensor_id = sccb_reg_read(gspca_dev, 0x0a) << 8;
	sccb_reg_read(gspca_dev, 0x0b);
	sensor_id |= sccb_reg_read(gspca_dev, 0x0b);
	PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id);

	/* initialize */
877 878 879 880 881 882 883 884
	reg_w_array(gspca_dev, bridge_init,
			ARRAY_SIZE(bridge_init));
	ov534_set_led(gspca_dev, 1);
	sccb_w_array(gspca_dev, sensor_init,
			ARRAY_SIZE(sensor_init));
	ov534_reg_write(gspca_dev, 0xe0, 0x09);
	ov534_set_led(gspca_dev, 0);
	set_frame_rate(gspca_dev);
885 886 887 888

	return 0;
}

889
static int sd_start(struct gspca_dev *gspca_dev)
890
{
891
	int mode;
892

893 894
	mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
	if (mode != 0) {	/* 320x240 */
895 896 897 898
		reg_w_array(gspca_dev, bridge_start_qvga,
				ARRAY_SIZE(bridge_start_qvga));
		sccb_w_array(gspca_dev, sensor_start_qvga,
				ARRAY_SIZE(sensor_start_qvga));
899
	} else {		/* 640x480 */
900 901 902 903
		reg_w_array(gspca_dev, bridge_start_vga,
				ARRAY_SIZE(bridge_start_vga));
		sccb_w_array(gspca_dev, sensor_start_vga,
				ARRAY_SIZE(sensor_start_vga));
904
	}
905
	set_frame_rate(gspca_dev);
906

907
	setautogain(gspca_dev);
908
	setawb(gspca_dev);
909 910 911
	setgain(gspca_dev);
	setredblc(gspca_dev);
	setblueblc(gspca_dev);
912
	sethue(gspca_dev);
913 914 915 916
	setexposure(gspca_dev);
	setbrightness(gspca_dev);
	setcontrast(gspca_dev);
	setsharpness(gspca_dev);
917 918 919 920 921
	setvflip(gspca_dev);
	sethflip(gspca_dev);

	ov534_set_led(gspca_dev, 1);
	ov534_reg_write(gspca_dev, 0xe0, 0x00);
922 923 924
	return 0;
}

925
static void sd_stopN(struct gspca_dev *gspca_dev)
926 927 928 929 930
{
	ov534_reg_write(gspca_dev, 0xe0, 0x09);
	ov534_set_led(gspca_dev, 0);
}

931 932 933 934 935 936 937 938 939 940
/* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
#define UVC_STREAM_EOH	(1 << 7)
#define UVC_STREAM_ERR	(1 << 6)
#define UVC_STREAM_STI	(1 << 5)
#define UVC_STREAM_RES	(1 << 4)
#define UVC_STREAM_SCR	(1 << 3)
#define UVC_STREAM_PTS	(1 << 2)
#define UVC_STREAM_EOF	(1 << 1)
#define UVC_STREAM_FID	(1 << 0)

941 942
static void sd_pkt_scan(struct gspca_dev *gspca_dev,
			u8 *data, int len)
943
{
944
	struct sd *sd = (struct sd *) gspca_dev;
945
	__u32 this_pts;
946
	u16 this_fid;
947 948
	int remaining_len = len;

949
	do {
950
		len = min(remaining_len, 2048);
951

952 953 954 955
		/* Payloads are prefixed with a UVC-style header.  We
		   consider a frame to start when the FID toggles, or the PTS
		   changes.  A frame ends when EOF is set, and we've received
		   the correct number of bytes. */
956

957 958 959 960 961
		/* Verify UVC header.  Header length is always 12 */
		if (data[0] != 12 || len < 12) {
			PDEBUG(D_PACK, "bad header");
			goto discard;
		}
962

963 964 965 966 967
		/* Check errors */
		if (data[1] & UVC_STREAM_ERR) {
			PDEBUG(D_PACK, "payload error");
			goto discard;
		}
968

969 970 971
		/* Extract PTS and FID */
		if (!(data[1] & UVC_STREAM_PTS)) {
			PDEBUG(D_PACK, "PTS not present");
972 973
			goto discard;
		}
974 975 976
		this_pts = (data[5] << 24) | (data[4] << 16)
						| (data[3] << 8) | data[2];
		this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0;
977

978 979
		/* If PTS or FID has changed, start a new frame. */
		if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
980
			if (gspca_dev->last_packet_type == INTER_PACKET)
981 982
				gspca_frame_add(gspca_dev, LAST_PACKET,
						NULL, 0);
983 984
			sd->last_pts = this_pts;
			sd->last_fid = this_fid;
985
			gspca_frame_add(gspca_dev, FIRST_PACKET,
986 987
					data + 12, len - 12);
		/* If this packet is marked as EOF, end the frame */
988
		} else if (data[1] & UVC_STREAM_EOF) {
989 990
			struct gspca_frame *frame;

991
			sd->last_pts = 0;
992 993 994
			frame = gspca_get_i_frame(gspca_dev);
			if (frame == NULL)
				goto discard;
995
			if (frame->data_end - frame->data + (len - 12) !=
996
			    gspca_dev->width * gspca_dev->height * 2) {
997
				PDEBUG(D_PACK, "wrong sized frame");
998 999
				goto discard;
			}
1000 1001
			gspca_frame_add(gspca_dev, LAST_PACKET,
					data + 12, len - 12);
1002 1003 1004
		} else {

			/* Add the data from this payload */
1005 1006
			gspca_frame_add(gspca_dev, INTER_PACKET,
					data + 12, len - 12);
1007
		}
1008

1009 1010
		/* Done this payload */
		goto scan_next;
1011 1012

discard:
1013
		/* Discard data until a new frame starts. */
1014
		gspca_dev->last_packet_type = DISCARD_PACKET;
1015 1016 1017 1018 1019

scan_next:
		remaining_len -= len;
		data += len;
	} while (remaining_len > 0);
1020 1021
}

1022
/* controls */
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	sd->gain = val;
	if (gspca_dev->streaming)
		setgain(gspca_dev);
	return 0;
}

static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	*val = sd->gain;
	return 0;
}

static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	sd->exposure = val;
1046 1047
	if (gspca_dev->streaming)
		setexposure(gspca_dev);
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
	return 0;
}

static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	*val = sd->exposure;
	return 0;
}

1059 1060 1061 1062 1063
static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	sd->brightness = val;
1064 1065
	if (gspca_dev->streaming)
		setbrightness(gspca_dev);
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
	return 0;
}

static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	*val = sd->brightness;
	return 0;
}

static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	sd->contrast = val;
1082 1083
	if (gspca_dev->streaming)
		setcontrast(gspca_dev);
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
	return 0;
}

static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	*val = sd->contrast;
	return 0;
}

1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
static int sd_setredblc(struct gspca_dev *gspca_dev, __s32 val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	sd->redblc = val;
	if (gspca_dev->streaming)
		setredblc(gspca_dev);
	return 0;
}

static int sd_getredblc(struct gspca_dev *gspca_dev, __s32 *val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	*val = sd->redblc;
	return 0;
}

static int sd_setblueblc(struct gspca_dev *gspca_dev, __s32 val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	sd->blueblc = val;
	if (gspca_dev->streaming)
		setblueblc(gspca_dev);
	return 0;
}

static int sd_getblueblc(struct gspca_dev *gspca_dev, __s32 *val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	*val = sd->blueblc;
	return 0;
}

1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	sd->hue = val;
	if (gspca_dev->streaming)
		sethue(gspca_dev);
	return 0;
}

static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	*val = sd->hue;
	return 0;
}

1149 1150 1151 1152 1153
static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	sd->autogain = val;
1154

1155
	if (gspca_dev->streaming) {
1156 1157 1158 1159 1160 1161 1162 1163

		/* the auto white balance control works only
		 * when auto gain is set */
		if (val)
			gspca_dev->ctrl_inac &= ~(1 << AWB_IDX);
		else
			gspca_dev->ctrl_inac |= (1 << AWB_IDX);
		setautogain(gspca_dev);
1164
	}
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
	return 0;
}

static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	*val = sd->autogain;
	return 0;
}

1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193
static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	sd->awb = val;
	if (gspca_dev->streaming)
		setawb(gspca_dev);
	return 0;
}

static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	*val = sd->awb;
	return 0;
}

1194 1195 1196 1197 1198
static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	sd->sharpness = val;
1199 1200
	if (gspca_dev->streaming)
		setsharpness(gspca_dev);
1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247
	return 0;
}

static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	*val = sd->sharpness;
	return 0;
}

static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	sd->hflip = val;
	if (gspca_dev->streaming)
		sethflip(gspca_dev);
	return 0;
}

static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	*val = sd->hflip;
	return 0;
}

static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	sd->vflip = val;
	if (gspca_dev->streaming)
		setvflip(gspca_dev);
	return 0;
}

static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	*val = sd->vflip;
	return 0;
}

1248
/* get stream parameters (framerate) */
1249 1250
static int sd_get_streamparm(struct gspca_dev *gspca_dev,
			     struct v4l2_streamparm *parm)
1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266
{
	struct v4l2_captureparm *cp = &parm->parm.capture;
	struct v4l2_fract *tpf = &cp->timeperframe;
	struct sd *sd = (struct sd *) gspca_dev;

	if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
		return -EINVAL;

	cp->capability |= V4L2_CAP_TIMEPERFRAME;
	tpf->numerator = 1;
	tpf->denominator = sd->frame_rate;

	return 0;
}

/* set stream parameters (framerate) */
1267 1268
static int sd_set_streamparm(struct gspca_dev *gspca_dev,
			     struct v4l2_streamparm *parm)
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278
{
	struct v4l2_captureparm *cp = &parm->parm.capture;
	struct v4l2_fract *tpf = &cp->timeperframe;
	struct sd *sd = (struct sd *) gspca_dev;

	if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
		return -EINVAL;

	/* Set requested framerate */
	sd->frame_rate = tpf->denominator / tpf->numerator;
1279
	if (gspca_dev->streaming)
1280
		set_frame_rate(gspca_dev);
1281 1282 1283 1284 1285 1286 1287 1288

	/* Return the actual framerate */
	tpf->numerator = 1;
	tpf->denominator = sd->frame_rate;

	return 0;
}

1289
/* sub-driver description */
1290
static const struct sd_desc sd_desc = {
1291
	.name     = MODULE_NAME,
1292 1293
	.ctrls    = sd_ctrls,
	.nctrls   = ARRAY_SIZE(sd_ctrls),
1294 1295
	.config   = sd_config,
	.init     = sd_init,
1296 1297
	.start    = sd_start,
	.stopN    = sd_stopN,
1298 1299 1300 1301 1302
	.pkt_scan = sd_pkt_scan,
	.get_streamparm = sd_get_streamparm,
	.set_streamparm = sd_set_streamparm,
};

1303 1304
/* -- module initialisation -- */
static const __devinitdata struct usb_device_id device_table[] = {
1305
	{USB_DEVICE(0x1415, 0x2000)},
1306 1307 1308 1309 1310 1311 1312 1313
	{}
};

MODULE_DEVICE_TABLE(usb, device_table);

/* -- device connect -- */
static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
{
1314
	return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
1315
				THIS_MODULE);
1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331
}

static struct usb_driver sd_driver = {
	.name       = MODULE_NAME,
	.id_table   = device_table,
	.probe      = sd_probe,
	.disconnect = gspca_disconnect,
#ifdef CONFIG_PM
	.suspend    = gspca_suspend,
	.resume     = gspca_resume,
#endif
};

/* -- module insert / remove -- */
static int __init sd_mod_init(void)
{
1332
	int ret;
1333

1334 1335
	ret = usb_register(&sd_driver);
	if (ret < 0)
1336
		return ret;
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348
	PDEBUG(D_PROBE, "registered");
	return 0;
}

static void __exit sd_mod_exit(void)
{
	usb_deregister(&sd_driver);
	PDEBUG(D_PROBE, "deregistered");
}

module_init(sd_mod_init);
module_exit(sd_mod_exit);