diff options
Diffstat (limited to 'drivers/media/video/gspca/pac207.c')
| -rw-r--r-- | drivers/media/video/gspca/pac207.c | 87 |
1 files changed, 23 insertions, 64 deletions
diff --git a/drivers/media/video/gspca/pac207.c b/drivers/media/video/gspca/pac207.c index 7ef18d578811..83b5f740c947 100644 --- a/drivers/media/video/gspca/pac207.c +++ b/drivers/media/video/gspca/pac207.c | |||
| @@ -56,12 +56,6 @@ MODULE_LICENSE("GPL"); | |||
| 56 | #define PAC207_GAIN_KNEE 20 | 56 | #define PAC207_GAIN_KNEE 20 |
| 57 | 57 | ||
| 58 | #define PAC207_AUTOGAIN_DEADZONE 30 | 58 | #define PAC207_AUTOGAIN_DEADZONE 30 |
| 59 | /* We calculating the autogain at the end of the transfer of a frame, at this | ||
| 60 | moment a frame with the old settings is being transmitted, and a frame is | ||
| 61 | being captured with the old settings. So if we adjust the autogain we must | ||
| 62 | ignore atleast the 2 next frames for the new settings to come into effect | ||
| 63 | before doing any other adjustments */ | ||
| 64 | #define PAC207_AUTOGAIN_IGNORE_FRAMES 3 | ||
| 65 | 59 | ||
| 66 | /* specific webcam descriptor */ | 60 | /* specific webcam descriptor */ |
| 67 | struct sd { | 61 | struct sd { |
| @@ -131,7 +125,8 @@ static struct ctrl sd_ctrls[] = { | |||
| 131 | .minimum = 0, | 125 | .minimum = 0, |
| 132 | .maximum = 1, | 126 | .maximum = 1, |
| 133 | .step = 1, | 127 | .step = 1, |
| 134 | .default_value = 1, | 128 | #define AUTOGAIN_DEF 1 |
| 129 | .default_value = AUTOGAIN_DEF, | ||
| 135 | .flags = 0, | 130 | .flags = 0, |
| 136 | }, | 131 | }, |
| 137 | .set = sd_setautogain, | 132 | .set = sd_setautogain, |
| @@ -181,9 +176,6 @@ static const __u8 pac207_sensor_init[][8] = { | |||
| 181 | /* 48 reg_72 Rate Control end BalSize_4a =0x36 */ | 176 | /* 48 reg_72 Rate Control end BalSize_4a =0x36 */ |
| 182 | static const __u8 PacReg72[] = { 0x00, 0x00, 0x36, 0x00 }; | 177 | static const __u8 PacReg72[] = { 0x00, 0x00, 0x36, 0x00 }; |
| 183 | 178 | ||
| 184 | static const unsigned char pac207_sof_marker[5] = | ||
| 185 | { 0xff, 0xff, 0x00, 0xff, 0x96 }; | ||
| 186 | |||
| 187 | static int pac207_write_regs(struct gspca_dev *gspca_dev, u16 index, | 179 | static int pac207_write_regs(struct gspca_dev *gspca_dev, u16 index, |
| 188 | const u8 *buffer, u16 length) | 180 | const u8 *buffer, u16 length) |
| 189 | { | 181 | { |
| @@ -259,35 +251,32 @@ static int sd_config(struct gspca_dev *gspca_dev, | |||
| 259 | return -ENODEV; | 251 | return -ENODEV; |
| 260 | } | 252 | } |
| 261 | 253 | ||
| 262 | pac207_write_reg(gspca_dev, 0x41, 0x00); | ||
| 263 | /* Bit_0=Image Format, | ||
| 264 | * Bit_1=LED, | ||
| 265 | * Bit_2=Compression test mode enable */ | ||
| 266 | pac207_write_reg(gspca_dev, 0x0f, 0x00); /* Power Control */ | ||
| 267 | pac207_write_reg(gspca_dev, 0x11, 0x30); /* Analog Bias */ | ||
| 268 | |||
| 269 | PDEBUG(D_PROBE, | 254 | PDEBUG(D_PROBE, |
| 270 | "Pixart PAC207BCA Image Processor and Control Chip detected" | 255 | "Pixart PAC207BCA Image Processor and Control Chip detected" |
| 271 | " (vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct); | 256 | " (vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct); |
| 272 | 257 | ||
| 273 | cam = &gspca_dev->cam; | 258 | cam = &gspca_dev->cam; |
| 274 | cam->dev_name = (char *) id->driver_info; | ||
| 275 | cam->epaddr = 0x05; | 259 | cam->epaddr = 0x05; |
| 276 | cam->cam_mode = sif_mode; | 260 | cam->cam_mode = sif_mode; |
| 277 | cam->nmodes = ARRAY_SIZE(sif_mode); | 261 | cam->nmodes = ARRAY_SIZE(sif_mode); |
| 278 | sd->brightness = PAC207_BRIGHTNESS_DEFAULT; | 262 | sd->brightness = PAC207_BRIGHTNESS_DEFAULT; |
| 279 | sd->exposure = PAC207_EXPOSURE_DEFAULT; | 263 | sd->exposure = PAC207_EXPOSURE_DEFAULT; |
| 280 | sd->gain = PAC207_GAIN_DEFAULT; | 264 | sd->gain = PAC207_GAIN_DEFAULT; |
| 265 | sd->autogain = AUTOGAIN_DEF; | ||
| 281 | 266 | ||
| 282 | return 0; | 267 | return 0; |
| 283 | } | 268 | } |
| 284 | 269 | ||
| 285 | /* this function is called at open time */ | 270 | /* this function is called at probe and resume time */ |
| 286 | static int sd_open(struct gspca_dev *gspca_dev) | 271 | static int sd_init(struct gspca_dev *gspca_dev) |
| 287 | { | 272 | { |
| 288 | struct sd *sd = (struct sd *) gspca_dev; | 273 | pac207_write_reg(gspca_dev, 0x41, 0x00); |
| 274 | /* Bit_0=Image Format, | ||
| 275 | * Bit_1=LED, | ||
| 276 | * Bit_2=Compression test mode enable */ | ||
| 277 | pac207_write_reg(gspca_dev, 0x0f, 0x00); /* Power Control */ | ||
| 278 | pac207_write_reg(gspca_dev, 0x11, 0x30); /* Analog Bias */ | ||
| 289 | 279 | ||
| 290 | sd->autogain = 1; | ||
| 291 | return 0; | 280 | return 0; |
| 292 | } | 281 | } |
| 293 | 282 | ||
| @@ -343,14 +332,8 @@ static void sd_stopN(struct gspca_dev *gspca_dev) | |||
| 343 | pac207_write_reg(gspca_dev, 0x0f, 0x00); /* Power Control */ | 332 | pac207_write_reg(gspca_dev, 0x0f, 0x00); /* Power Control */ |
| 344 | } | 333 | } |
| 345 | 334 | ||
| 346 | static void sd_stop0(struct gspca_dev *gspca_dev) | 335 | /* Include pac common sof detection functions */ |
| 347 | { | 336 | #include "pac_common.h" |
| 348 | } | ||
| 349 | |||
| 350 | /* this function is called at close time */ | ||
| 351 | static void sd_close(struct gspca_dev *gspca_dev) | ||
| 352 | { | ||
| 353 | } | ||
| 354 | 337 | ||
| 355 | static void pac207_do_auto_gain(struct gspca_dev *gspca_dev) | 338 | static void pac207_do_auto_gain(struct gspca_dev *gspca_dev) |
| 356 | { | 339 | { |
| @@ -365,33 +348,7 @@ static void pac207_do_auto_gain(struct gspca_dev *gspca_dev) | |||
| 365 | else if (gspca_auto_gain_n_exposure(gspca_dev, avg_lum, | 348 | else if (gspca_auto_gain_n_exposure(gspca_dev, avg_lum, |
| 366 | 100 + sd->brightness / 2, PAC207_AUTOGAIN_DEADZONE, | 349 | 100 + sd->brightness / 2, PAC207_AUTOGAIN_DEADZONE, |
| 367 | PAC207_GAIN_KNEE, PAC207_EXPOSURE_KNEE)) | 350 | PAC207_GAIN_KNEE, PAC207_EXPOSURE_KNEE)) |
| 368 | sd->autogain_ignore_frames = PAC207_AUTOGAIN_IGNORE_FRAMES; | 351 | sd->autogain_ignore_frames = PAC_AUTOGAIN_IGNORE_FRAMES; |
| 369 | } | ||
| 370 | |||
| 371 | static unsigned char *pac207_find_sof(struct gspca_dev *gspca_dev, | ||
| 372 | unsigned char *m, int len) | ||
| 373 | { | ||
| 374 | struct sd *sd = (struct sd *) gspca_dev; | ||
| 375 | int i; | ||
| 376 | |||
| 377 | /* Search for the SOF marker (fixed part) in the header */ | ||
| 378 | for (i = 0; i < len; i++) { | ||
| 379 | if (m[i] == pac207_sof_marker[sd->sof_read]) { | ||
| 380 | sd->sof_read++; | ||
| 381 | if (sd->sof_read == sizeof(pac207_sof_marker)) { | ||
| 382 | PDEBUG(D_STREAM, | ||
| 383 | "SOF found, bytes to analyze: %u." | ||
| 384 | " Frame starts at byte #%u", | ||
| 385 | len, i + 1); | ||
| 386 | sd->sof_read = 0; | ||
| 387 | return m + i + 1; | ||
| 388 | } | ||
| 389 | } else { | ||
| 390 | sd->sof_read = 0; | ||
| 391 | } | ||
| 392 | } | ||
| 393 | |||
| 394 | return NULL; | ||
| 395 | } | 352 | } |
| 396 | 353 | ||
| 397 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, | 354 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, |
| @@ -402,14 +359,14 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, | |||
| 402 | struct sd *sd = (struct sd *) gspca_dev; | 359 | struct sd *sd = (struct sd *) gspca_dev; |
| 403 | unsigned char *sof; | 360 | unsigned char *sof; |
| 404 | 361 | ||
| 405 | sof = pac207_find_sof(gspca_dev, data, len); | 362 | sof = pac_find_sof(gspca_dev, data, len); |
| 406 | if (sof) { | 363 | if (sof) { |
| 407 | int n; | 364 | int n; |
| 408 | 365 | ||
| 409 | /* finish decoding current frame */ | 366 | /* finish decoding current frame */ |
| 410 | n = sof - data; | 367 | n = sof - data; |
| 411 | if (n > sizeof pac207_sof_marker) | 368 | if (n > sizeof pac_sof_marker) |
| 412 | n -= sizeof pac207_sof_marker; | 369 | n -= sizeof pac_sof_marker; |
| 413 | else | 370 | else |
| 414 | n = 0; | 371 | n = 0; |
| 415 | frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame, | 372 | frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame, |
| @@ -537,7 +494,7 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val) | |||
| 537 | sd->gain = PAC207_GAIN_DEFAULT; | 494 | sd->gain = PAC207_GAIN_DEFAULT; |
| 538 | if (gspca_dev->streaming) { | 495 | if (gspca_dev->streaming) { |
| 539 | sd->autogain_ignore_frames = | 496 | sd->autogain_ignore_frames = |
| 540 | PAC207_AUTOGAIN_IGNORE_FRAMES; | 497 | PAC_AUTOGAIN_IGNORE_FRAMES; |
| 541 | setexposure(gspca_dev); | 498 | setexposure(gspca_dev); |
| 542 | setgain(gspca_dev); | 499 | setgain(gspca_dev); |
| 543 | } | 500 | } |
| @@ -560,11 +517,9 @@ static const struct sd_desc sd_desc = { | |||
| 560 | .ctrls = sd_ctrls, | 517 | .ctrls = sd_ctrls, |
| 561 | .nctrls = ARRAY_SIZE(sd_ctrls), | 518 | .nctrls = ARRAY_SIZE(sd_ctrls), |
| 562 | .config = sd_config, | 519 | .config = sd_config, |
| 563 | .open = sd_open, | 520 | .init = sd_init, |
| 564 | .start = sd_start, | 521 | .start = sd_start, |
| 565 | .stopN = sd_stopN, | 522 | .stopN = sd_stopN, |
| 566 | .stop0 = sd_stop0, | ||
| 567 | .close = sd_close, | ||
| 568 | .dq_callback = pac207_do_auto_gain, | 523 | .dq_callback = pac207_do_auto_gain, |
| 569 | .pkt_scan = sd_pkt_scan, | 524 | .pkt_scan = sd_pkt_scan, |
| 570 | }; | 525 | }; |
| @@ -597,6 +552,10 @@ static struct usb_driver sd_driver = { | |||
| 597 | .id_table = device_table, | 552 | .id_table = device_table, |
| 598 | .probe = sd_probe, | 553 | .probe = sd_probe, |
| 599 | .disconnect = gspca_disconnect, | 554 | .disconnect = gspca_disconnect, |
| 555 | #ifdef CONFIG_PM | ||
| 556 | .suspend = gspca_suspend, | ||
| 557 | .resume = gspca_resume, | ||
| 558 | #endif | ||
| 600 | }; | 559 | }; |
| 601 | 560 | ||
| 602 | /* -- module insert / remove -- */ | 561 | /* -- module insert / remove -- */ |
