Lines Matching +full:camera +full:- +full:command +full:- +full:set
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2010-2011 Hans de Goede <hdegoede@redhat.com>
9 * (C) Copyright 1999-2000 Peter Pregler
10 * (C) Copyright 1999-2000 Scott J. Bertin
11 * (C) Copyright 1999-2000 Johannes Erdfelt <johannes@erdfelt.com>
214 #define FIRMWARE_VERSION(x, y) (sd->params.version.firmwareVersion == (x) && \
215 sd->params.version.firmwareRevision == (y))
226 /* Developer's Guide Table 5 p 3-34
355 struct cam_params params; /* camera settings */
369 * the camera will pad out usb frames, making the image
399 static int cpia_usb_transferCmd(struct gspca_dev *gspca_dev, u8 *command) in cpia_usb_transferCmd() argument
403 int ret, databytes = command[6] | (command[7] << 8); in cpia_usb_transferCmd()
407 if (command[0] == DATA_IN) { in cpia_usb_transferCmd()
408 pipe = usb_rcvctrlpipe(gspca_dev->dev, 0); in cpia_usb_transferCmd()
410 } else if (command[0] == DATA_OUT) { in cpia_usb_transferCmd()
411 pipe = usb_sndctrlpipe(gspca_dev->dev, 0); in cpia_usb_transferCmd()
414 gspca_err(gspca_dev, "Unexpected first byte of command: %x\n", in cpia_usb_transferCmd()
415 command[0]); in cpia_usb_transferCmd()
416 return -EINVAL; in cpia_usb_transferCmd()
420 ret = usb_control_msg(gspca_dev->dev, pipe, in cpia_usb_transferCmd()
421 command[1], in cpia_usb_transferCmd()
423 command[2] | (command[3] << 8), in cpia_usb_transferCmd()
424 command[4] | (command[5] << 8), in cpia_usb_transferCmd()
425 gspca_dev->usb_buf, databytes, 1000); in cpia_usb_transferCmd()
428 pr_err("usb_control_msg %02x, error %d\n", command[1], ret); in cpia_usb_transferCmd()
430 if (ret == -EPIPE && retries > 0) { in cpia_usb_transferCmd()
431 retries--; in cpia_usb_transferCmd()
438 /* send an arbitrary command to the camera */
439 static int do_command(struct gspca_dev *gspca_dev, u16 command, in do_command() argument
446 switch (command) { in do_command()
465 cmd[0] = command >> 8; in do_command()
466 cmd[1] = command & 0xff; in do_command()
478 switch (command) { in do_command()
480 sd->params.version.firmwareVersion = gspca_dev->usb_buf[0]; in do_command()
481 sd->params.version.firmwareRevision = gspca_dev->usb_buf[1]; in do_command()
482 sd->params.version.vcVersion = gspca_dev->usb_buf[2]; in do_command()
483 sd->params.version.vcRevision = gspca_dev->usb_buf[3]; in do_command()
486 sd->params.pnpID.vendor = in do_command()
487 gspca_dev->usb_buf[0] | (gspca_dev->usb_buf[1] << 8); in do_command()
488 sd->params.pnpID.product = in do_command()
489 gspca_dev->usb_buf[2] | (gspca_dev->usb_buf[3] << 8); in do_command()
490 sd->params.pnpID.deviceRevision = in do_command()
491 gspca_dev->usb_buf[4] | (gspca_dev->usb_buf[5] << 8); in do_command()
494 sd->params.status.systemState = gspca_dev->usb_buf[0]; in do_command()
495 sd->params.status.grabState = gspca_dev->usb_buf[1]; in do_command()
496 sd->params.status.streamState = gspca_dev->usb_buf[2]; in do_command()
497 sd->params.status.fatalError = gspca_dev->usb_buf[3]; in do_command()
498 sd->params.status.cmdError = gspca_dev->usb_buf[4]; in do_command()
499 sd->params.status.debugFlags = gspca_dev->usb_buf[5]; in do_command()
500 sd->params.status.vpStatus = gspca_dev->usb_buf[6]; in do_command()
501 sd->params.status.errorCode = gspca_dev->usb_buf[7]; in do_command()
504 sd->params.vpVersion.vpVersion = gspca_dev->usb_buf[0]; in do_command()
505 sd->params.vpVersion.vpRevision = gspca_dev->usb_buf[1]; in do_command()
506 sd->params.vpVersion.cameraHeadID = in do_command()
507 gspca_dev->usb_buf[2] | (gspca_dev->usb_buf[3] << 8); in do_command()
510 sd->params.colourParams.brightness = gspca_dev->usb_buf[0]; in do_command()
511 sd->params.colourParams.contrast = gspca_dev->usb_buf[1]; in do_command()
512 sd->params.colourParams.saturation = gspca_dev->usb_buf[2]; in do_command()
515 sd->params.colourBalance.redGain = gspca_dev->usb_buf[0]; in do_command()
516 sd->params.colourBalance.greenGain = gspca_dev->usb_buf[1]; in do_command()
517 sd->params.colourBalance.blueGain = gspca_dev->usb_buf[2]; in do_command()
520 sd->params.exposure.gain = gspca_dev->usb_buf[0]; in do_command()
521 sd->params.exposure.fineExp = gspca_dev->usb_buf[1]; in do_command()
522 sd->params.exposure.coarseExpLo = gspca_dev->usb_buf[2]; in do_command()
523 sd->params.exposure.coarseExpHi = gspca_dev->usb_buf[3]; in do_command()
524 sd->params.exposure.redComp = gspca_dev->usb_buf[4]; in do_command()
525 sd->params.exposure.green1Comp = gspca_dev->usb_buf[5]; in do_command()
526 sd->params.exposure.green2Comp = gspca_dev->usb_buf[6]; in do_command()
527 sd->params.exposure.blueComp = gspca_dev->usb_buf[7]; in do_command()
532 a = ((gspca_dev->usb_buf[1] & 0x02) == 0); in do_command()
533 if (a != sd->params.qx3.button) { in do_command()
535 input_report_key(gspca_dev->input_dev, KEY_CAMERA, a); in do_command()
536 input_sync(gspca_dev->input_dev); in do_command()
538 sd->params.qx3.button = a; in do_command()
540 if (sd->params.qx3.button) { in do_command()
541 /* button pressed - unlock the latch */ in do_command()
553 sd->params.qx3.cradled = ((gspca_dev->usb_buf[2] & 0x40) == 0); in do_command()
560 /* send a command to the camera with an additional data transaction */
561 static int do_command_extended(struct gspca_dev *gspca_dev, u16 command, in do_command_extended() argument
568 cmd[0] = command >> 8; in do_command_extended()
569 cmd[1] = command & 0xff; in do_command_extended()
576 gspca_dev->usb_buf[0] = e; in do_command_extended()
577 gspca_dev->usb_buf[1] = f; in do_command_extended()
578 gspca_dev->usb_buf[2] = g; in do_command_extended()
579 gspca_dev->usb_buf[3] = h; in do_command_extended()
580 gspca_dev->usb_buf[4] = i; in do_command_extended()
581 gspca_dev->usb_buf[5] = j; in do_command_extended()
582 gspca_dev->usb_buf[6] = k; in do_command_extended()
583 gspca_dev->usb_buf[7] = l; in do_command_extended()
591 * set with SetColourParameters
593 * Parameters: Brightness - last brightness value set with SetColourParameters
604 MaxAllowableOverExposure = FLICKER_MAX_EXPOSURE - brightness - in find_over_exposure()
620 struct cam_params *params = &sd->params; in reset_camera_params()
625 params->colourParams.brightness = BRIGHTNESS_DEF; in reset_camera_params()
626 params->colourParams.contrast = CONTRAST_DEF; in reset_camera_params()
627 params->colourParams.saturation = SATURATION_DEF; in reset_camera_params()
628 params->exposure.gainMode = 4; in reset_camera_params()
629 params->exposure.expMode = 2; /* AEC */ in reset_camera_params()
630 params->exposure.compMode = 1; in reset_camera_params()
631 params->exposure.centreWeight = 1; in reset_camera_params()
632 params->exposure.gain = 0; in reset_camera_params()
633 params->exposure.fineExp = 0; in reset_camera_params()
634 params->exposure.coarseExpLo = 185; in reset_camera_params()
635 params->exposure.coarseExpHi = 0; in reset_camera_params()
636 params->exposure.redComp = COMP_RED; in reset_camera_params()
637 params->exposure.green1Comp = COMP_GREEN1; in reset_camera_params()
638 params->exposure.green2Comp = COMP_GREEN2; in reset_camera_params()
639 params->exposure.blueComp = COMP_BLUE; in reset_camera_params()
640 params->colourBalance.balanceMode = 2; /* ACB */ in reset_camera_params()
641 params->colourBalance.redGain = 32; in reset_camera_params()
642 params->colourBalance.greenGain = 6; in reset_camera_params()
643 params->colourBalance.blueGain = 92; in reset_camera_params()
644 params->apcor.gain1 = 0x18; in reset_camera_params()
645 params->apcor.gain2 = 0x16; in reset_camera_params()
646 params->apcor.gain4 = 0x24; in reset_camera_params()
647 params->apcor.gain8 = 0x34; in reset_camera_params()
648 params->vlOffset.gain1 = 20; in reset_camera_params()
649 params->vlOffset.gain2 = 24; in reset_camera_params()
650 params->vlOffset.gain4 = 26; in reset_camera_params()
651 params->vlOffset.gain8 = 26; in reset_camera_params()
652 params->compressionParams.hysteresis = 3; in reset_camera_params()
653 params->compressionParams.threshMax = 11; in reset_camera_params()
654 params->compressionParams.smallStep = 1; in reset_camera_params()
655 params->compressionParams.largeStep = 3; in reset_camera_params()
656 params->compressionParams.decimationHysteresis = 2; in reset_camera_params()
657 params->compressionParams.frDiffStepThresh = 5; in reset_camera_params()
658 params->compressionParams.qDiffStepThresh = 3; in reset_camera_params()
659 params->compressionParams.decimationThreshMod = 2; in reset_camera_params()
662 /* Set Sensor FPS to 15fps. This seems better than 30fps in reset_camera_params()
664 params->sensorFps.divisor = 1; in reset_camera_params()
665 params->sensorFps.baserate = 1; in reset_camera_params()
667 params->flickerControl.flickerMode = 0; in reset_camera_params()
668 params->flickerControl.disabled = 1; in reset_camera_params()
669 params->flickerControl.coarseJump = in reset_camera_params()
670 flicker_jumps[sd->mainsFreq] in reset_camera_params()
671 [params->sensorFps.baserate] in reset_camera_params()
672 [params->sensorFps.divisor]; in reset_camera_params()
673 params->flickerControl.allowableOverExposure = in reset_camera_params()
674 find_over_exposure(params->colourParams.brightness); in reset_camera_params()
676 params->yuvThreshold.yThreshold = 6; /* From windows driver */ in reset_camera_params()
677 params->yuvThreshold.uvThreshold = 6; /* From windows driver */ in reset_camera_params()
679 params->format.subSample = SUBSAMPLE_420; in reset_camera_params()
680 params->format.yuvOrder = YUVORDER_YUYV; in reset_camera_params()
682 params->compression.mode = CPIA_COMPRESSION_AUTO; in reset_camera_params()
683 params->compression.decimation = NO_DECIMATION; in reset_camera_params()
685 params->compressionTarget.frTargeting = COMP_TARGET_DEF; in reset_camera_params()
686 params->compressionTarget.targetFR = 15; /* From windows driver */ in reset_camera_params()
687 params->compressionTarget.targetQ = 5; /* From windows driver */ in reset_camera_params()
689 params->qx3.qx3_detected = 0; in reset_camera_params()
690 params->qx3.toplight = 0; in reset_camera_params()
691 params->qx3.bottomlight = 0; in reset_camera_params()
692 params->qx3.button = 0; in reset_camera_params()
693 params->qx3.cradled = 0; in reset_camera_params()
699 params->status.systemState, params->status.grabState, in printstatus()
700 params->status.streamState, params->status.fatalError, in printstatus()
701 params->status.cmdError, params->status.debugFlags, in printstatus()
702 params->status.vpStatus, params->status.errorCode); in printstatus()
718 if (sd->params.status.systemState != LO_POWER_STATE) { in goto_low_power()
719 if (sd->params.status.systemState != WARM_BOOT_STATE) { in goto_low_power()
721 sd->params.status.systemState); in goto_low_power()
722 printstatus(gspca_dev, &sd->params); in goto_low_power()
724 return -EIO; in goto_low_power()
727 gspca_dbg(gspca_dev, D_CONF, "camera now in LOW power state\n"); in goto_low_power()
743 return -EINTR; in goto_high_power()
749 if (sd->params.status.systemState != HI_POWER_STATE) { in goto_high_power()
751 sd->params.status.systemState); in goto_high_power()
752 printstatus(gspca_dev, &sd->params); in goto_high_power()
753 return -EIO; in goto_high_power()
756 gspca_dbg(gspca_dev, D_CONF, "camera now in HIGH power state\n"); in goto_high_power()
790 sd->params.format.videoSize, in command_setformat()
791 sd->params.format.subSample, in command_setformat()
792 sd->params.format.yuvOrder, 0); in command_setformat()
797 sd->params.roi.colStart, sd->params.roi.colEnd, in command_setformat()
798 sd->params.roi.rowStart, sd->params.roi.rowEnd); in command_setformat()
805 sd->params.colourParams.brightness, in command_setcolourparams()
806 sd->params.colourParams.contrast, in command_setcolourparams()
807 sd->params.colourParams.saturation, 0); in command_setcolourparams()
814 sd->params.apcor.gain1, in command_setapcor()
815 sd->params.apcor.gain2, in command_setapcor()
816 sd->params.apcor.gain4, in command_setapcor()
817 sd->params.apcor.gain8); in command_setapcor()
824 sd->params.vlOffset.gain1, in command_setvloffset()
825 sd->params.vlOffset.gain2, in command_setvloffset()
826 sd->params.vlOffset.gain4, in command_setvloffset()
827 sd->params.vlOffset.gain8); in command_setvloffset()
836 sd->params.exposure.gainMode, in command_setexposure()
838 sd->params.exposure.compMode, in command_setexposure()
839 sd->params.exposure.centreWeight, in command_setexposure()
840 sd->params.exposure.gain, in command_setexposure()
841 sd->params.exposure.fineExp, in command_setexposure()
842 sd->params.exposure.coarseExpLo, in command_setexposure()
843 sd->params.exposure.coarseExpHi, in command_setexposure()
844 sd->params.exposure.redComp, in command_setexposure()
845 sd->params.exposure.green1Comp, in command_setexposure()
846 sd->params.exposure.green2Comp, in command_setexposure()
847 sd->params.exposure.blueComp); in command_setexposure()
851 if (sd->params.exposure.expMode != 1) { in command_setexposure()
854 sd->params.exposure.expMode, in command_setexposure()
856 sd->params.exposure.gain, in command_setexposure()
857 sd->params.exposure.fineExp, in command_setexposure()
858 sd->params.exposure.coarseExpLo, in command_setexposure()
859 sd->params.exposure.coarseExpHi, in command_setexposure()
870 if (sd->params.colourBalance.balanceMode == 1) { in command_setcolourbalance()
875 sd->params.colourBalance.redGain, in command_setcolourbalance()
876 sd->params.colourBalance.greenGain, in command_setcolourbalance()
877 sd->params.colourBalance.blueGain); in command_setcolourbalance()
884 if (sd->params.colourBalance.balanceMode == 2) { in command_setcolourbalance()
888 if (sd->params.colourBalance.balanceMode == 3) { in command_setcolourbalance()
893 return -EINVAL; in command_setcolourbalance()
901 sd->params.compressionTarget.frTargeting, in command_setcompressiontarget()
902 sd->params.compressionTarget.targetFR, in command_setcompressiontarget()
903 sd->params.compressionTarget.targetQ, 0); in command_setcompressiontarget()
911 sd->params.yuvThreshold.yThreshold, in command_setyuvtresh()
912 sd->params.yuvThreshold.uvThreshold, 0, 0); in command_setyuvtresh()
922 sd->params.compressionParams.hysteresis, in command_setcompressionparams()
923 sd->params.compressionParams.threshMax, in command_setcompressionparams()
924 sd->params.compressionParams.smallStep, in command_setcompressionparams()
925 sd->params.compressionParams.largeStep, in command_setcompressionparams()
926 sd->params.compressionParams.decimationHysteresis, in command_setcompressionparams()
927 sd->params.compressionParams.frDiffStepThresh, in command_setcompressionparams()
928 sd->params.compressionParams.qDiffStepThresh, in command_setcompressionparams()
929 sd->params.compressionParams.decimationThreshMod); in command_setcompressionparams()
937 sd->params.compression.mode, in command_setcompression()
938 sd->params.compression.decimation, 0, 0); in command_setcompression()
946 sd->params.sensorFps.divisor, in command_setsensorfps()
947 sd->params.sensorFps.baserate, 0, 0); in command_setsensorfps()
955 sd->params.flickerControl.flickerMode, in command_setflickerctrl()
956 sd->params.flickerControl.coarseJump, in command_setflickerctrl()
957 sd->params.flickerControl.allowableOverExposure, in command_setflickerctrl()
966 sd->params.ecpTiming, 0, 0, 0); in command_setecptiming()
979 0, sd->params.streamStartLine, 0, 0); in command_resume()
987 p1 = (sd->params.qx3.bottomlight == 0) << 1; in command_setlights()
988 p2 = (sd->params.qx3.toplight == 0) << 3; in command_setlights()
1005 (u8) ((((float) base - 128.0) * ((float) curexp / (float) newexp)) + 128.5) in set_flicker()
1008 (float)(u8)(basecomp - 128)) in set_flicker()
1012 (u8)(128 + (((u32)(2*(base-128)*curexp + newexp)) / (2 * newexp))) in set_flicker()
1014 (u16)(((u32)(curexp * (u8)(curcomp + 128)) / (u8)(basecomp - 128))) in set_flicker()
1018 int currentexp = sd->params.exposure.coarseExpLo + in set_flicker()
1019 sd->params.exposure.coarseExpHi * 256; in set_flicker()
1023 int cj = sd->params.flickerControl.coarseJump; in set_flicker()
1024 sd->params.flickerControl.flickerMode = 1; in set_flicker()
1025 sd->params.flickerControl.disabled = 0; in set_flicker()
1026 if (sd->params.exposure.expMode != 2) { in set_flicker()
1027 sd->params.exposure.expMode = 2; in set_flicker()
1028 sd->exposure_status = EXPOSURE_NORMAL; in set_flicker()
1030 if (sd->params.exposure.gain >= BITS_PER_TYPE(currentexp)) in set_flicker()
1031 return -EINVAL; in set_flicker()
1032 currentexp = currentexp << sd->params.exposure.gain; in set_flicker()
1033 sd->params.exposure.gain = 0; in set_flicker()
1038 startexp = (startexp * cj) - 1; in set_flicker()
1041 startexp -= cj; in set_flicker()
1044 startexp -= cj; in set_flicker()
1045 sd->params.exposure.coarseExpLo = startexp & 0xff; in set_flicker()
1046 sd->params.exposure.coarseExpHi = startexp >> 8; in set_flicker()
1050 sd->params.exposure.redComp = in set_flicker()
1052 sd->params.exposure.green1Comp = in set_flicker()
1054 sd->params.exposure.green2Comp = in set_flicker()
1056 sd->params.exposure.blueComp = in set_flicker()
1059 sd->params.exposure.redComp = COMP_RED; in set_flicker()
1060 sd->params.exposure.green1Comp = COMP_GREEN1; in set_flicker()
1061 sd->params.exposure.green2Comp = COMP_GREEN2; in set_flicker()
1062 sd->params.exposure.blueComp = COMP_BLUE; in set_flicker()
1065 sd->params.exposure.compMode = 0; in set_flicker()
1067 sd->params.exposure.compMode = 1; in set_flicker()
1069 sd->params.apcor.gain1 = 0x18; in set_flicker()
1070 sd->params.apcor.gain2 = 0x18; in set_flicker()
1071 sd->params.apcor.gain4 = 0x16; in set_flicker()
1072 sd->params.apcor.gain8 = 0x14; in set_flicker()
1074 sd->params.flickerControl.flickerMode = 0; in set_flicker()
1075 sd->params.flickerControl.disabled = 1; in set_flicker()
1078 sd->params.exposure.redComp, currentexp); in set_flicker()
1080 sd->params.exposure.green1Comp, currentexp); in set_flicker()
1082 sd->params.exposure.green2Comp, currentexp); in set_flicker()
1084 sd->params.exposure.blueComp, currentexp); in set_flicker()
1086 while (startexp > MAX_EXP && sd->params.exposure.gain < in set_flicker()
1087 sd->params.exposure.gainMode - 1) { in set_flicker()
1089 ++sd->params.exposure.gain; in set_flicker()
1095 sd->params.exposure.coarseExpLo = startexp & 0xff; in set_flicker()
1096 sd->params.exposure.coarseExpHi = startexp >> 8; in set_flicker()
1097 sd->params.exposure.redComp = COMP_RED; in set_flicker()
1098 sd->params.exposure.green1Comp = COMP_GREEN1; in set_flicker()
1099 sd->params.exposure.green2Comp = COMP_GREEN2; in set_flicker()
1100 sd->params.exposure.blueComp = COMP_BLUE; in set_flicker()
1101 sd->params.exposure.compMode = 1; in set_flicker()
1102 sd->params.apcor.gain1 = 0x18; in set_flicker()
1103 sd->params.apcor.gain2 = 0x16; in set_flicker()
1104 sd->params.apcor.gain4 = 0x24; in set_flicker()
1105 sd->params.apcor.gain8 = 0x34; in set_flicker()
1107 sd->params.vlOffset.gain1 = 20; in set_flicker()
1108 sd->params.vlOffset.gain2 = 24; in set_flicker()
1109 sd->params.vlOffset.gain4 = 26; in set_flicker()
1110 sd->params.vlOffset.gain8 = 26; in set_flicker()
1144 /* get necessary stats and register settings from camera */ in monitor_exposure()
1156 pr_err("ReadVPRegs(30,4,9,8) - failed: %d\n", ret); in monitor_exposure()
1159 exp_acc = gspca_dev->usb_buf[0]; in monitor_exposure()
1160 bcomp = gspca_dev->usb_buf[1]; in monitor_exposure()
1162 light_exp = sd->params.colourParams.brightness + in monitor_exposure()
1163 TC - 50 + EXP_ACC_LIGHT; in monitor_exposure()
1166 dark_exp = sd->params.colourParams.brightness + in monitor_exposure()
1167 TC - 50 - EXP_ACC_DARK; in monitor_exposure()
1172 old_exposure = sd->params.exposure.coarseExpHi * 256 + in monitor_exposure()
1173 sd->params.exposure.coarseExpLo; in monitor_exposure()
1175 if (!sd->params.flickerControl.disabled) { in monitor_exposure()
1184 if (sd->exposure_status == EXPOSURE_VERY_DARK) in monitor_exposure()
1185 ++sd->exposure_count; in monitor_exposure()
1187 sd->exposure_status = in monitor_exposure()
1189 sd->exposure_count = 1; in monitor_exposure()
1193 if (sd->exposure_status == EXPOSURE_DARK) in monitor_exposure()
1194 ++sd->exposure_count; in monitor_exposure()
1196 sd->exposure_status = EXPOSURE_DARK; in monitor_exposure()
1197 sd->exposure_count = 1; in monitor_exposure()
1204 if (sd->exposure_status == EXPOSURE_VERY_LIGHT) in monitor_exposure()
1205 ++sd->exposure_count; in monitor_exposure()
1207 sd->exposure_status = in monitor_exposure()
1209 sd->exposure_count = 1; in monitor_exposure()
1213 if (sd->exposure_status == EXPOSURE_LIGHT) in monitor_exposure()
1214 ++sd->exposure_count; in monitor_exposure()
1216 sd->exposure_status = EXPOSURE_LIGHT; in monitor_exposure()
1217 sd->exposure_count = 1; in monitor_exposure()
1222 sd->exposure_status = EXPOSURE_NORMAL; in monitor_exposure()
1230 if (sd->exposure_status == EXPOSURE_VERY_DARK) in monitor_exposure()
1231 ++sd->exposure_count; in monitor_exposure()
1233 sd->exposure_status = in monitor_exposure()
1235 sd->exposure_count = 1; in monitor_exposure()
1239 if (sd->exposure_status == EXPOSURE_DARK) in monitor_exposure()
1240 ++sd->exposure_count; in monitor_exposure()
1242 sd->exposure_status = EXPOSURE_DARK; in monitor_exposure()
1243 sd->exposure_count = 1; in monitor_exposure()
1250 if (sd->exposure_status == EXPOSURE_VERY_LIGHT) in monitor_exposure()
1251 ++sd->exposure_count; in monitor_exposure()
1253 sd->exposure_status = in monitor_exposure()
1255 sd->exposure_count = 1; in monitor_exposure()
1259 if (sd->exposure_status == EXPOSURE_LIGHT) in monitor_exposure()
1260 ++sd->exposure_count; in monitor_exposure()
1262 sd->exposure_status = EXPOSURE_LIGHT; in monitor_exposure()
1263 sd->exposure_count = 1; in monitor_exposure()
1268 sd->exposure_status = EXPOSURE_NORMAL; in monitor_exposure()
1272 framerate = atomic_read(&sd->fps); in monitor_exposure()
1276 if (!sd->params.flickerControl.disabled) { in monitor_exposure()
1278 if ((sd->exposure_status == EXPOSURE_VERY_DARK || in monitor_exposure()
1279 sd->exposure_status == EXPOSURE_DARK) && in monitor_exposure()
1280 sd->exposure_count >= DARK_TIME * framerate && in monitor_exposure()
1281 sd->params.sensorFps.divisor < 2) { in monitor_exposure()
1284 ++sd->params.sensorFps.divisor; in monitor_exposure()
1287 sd->params.flickerControl.coarseJump = in monitor_exposure()
1288 flicker_jumps[sd->mainsFreq] in monitor_exposure()
1289 [sd->params.sensorFps.baserate] in monitor_exposure()
1290 [sd->params.sensorFps.divisor]; in monitor_exposure()
1293 new_exposure = sd->params.flickerControl.coarseJump-1; in monitor_exposure()
1296 sd->params.flickerControl.coarseJump; in monitor_exposure()
1297 sd->params.exposure.coarseExpLo = new_exposure & 0xff; in monitor_exposure()
1298 sd->params.exposure.coarseExpHi = new_exposure >> 8; in monitor_exposure()
1300 sd->exposure_status = EXPOSURE_NORMAL; in monitor_exposure()
1303 } else if ((sd->exposure_status == EXPOSURE_VERY_LIGHT || in monitor_exposure()
1304 sd->exposure_status == EXPOSURE_LIGHT) && in monitor_exposure()
1305 sd->exposure_count >= LIGHT_TIME * framerate && in monitor_exposure()
1306 sd->params.sensorFps.divisor > 0) { in monitor_exposure()
1311 --sd->params.sensorFps.divisor; in monitor_exposure()
1314 sd->params.flickerControl.coarseJump = in monitor_exposure()
1315 flicker_jumps[sd->mainsFreq] in monitor_exposure()
1316 [sd->params.sensorFps.baserate] in monitor_exposure()
1317 [sd->params.sensorFps.divisor]; in monitor_exposure()
1320 new_exposure = sd->params.flickerControl.coarseJump-1; in monitor_exposure()
1323 sd->params.flickerControl.coarseJump < max_exp) in monitor_exposure()
1325 sd->params.flickerControl.coarseJump; in monitor_exposure()
1326 sd->params.exposure.coarseExpLo = new_exposure & 0xff; in monitor_exposure()
1327 sd->params.exposure.coarseExpHi = new_exposure >> 8; in monitor_exposure()
1329 sd->exposure_status = EXPOSURE_NORMAL; in monitor_exposure()
1334 if ((sd->exposure_status == EXPOSURE_VERY_DARK || in monitor_exposure()
1335 sd->exposure_status == EXPOSURE_DARK) && in monitor_exposure()
1336 sd->exposure_count >= DARK_TIME * framerate && in monitor_exposure()
1337 sd->params.sensorFps.divisor < 2) { in monitor_exposure()
1340 ++sd->params.sensorFps.divisor; in monitor_exposure()
1343 if (sd->params.exposure.gain > 0) { in monitor_exposure()
1344 --sd->params.exposure.gain; in monitor_exposure()
1347 sd->exposure_status = EXPOSURE_NORMAL; in monitor_exposure()
1350 } else if ((sd->exposure_status == EXPOSURE_VERY_LIGHT || in monitor_exposure()
1351 sd->exposure_status == EXPOSURE_LIGHT) && in monitor_exposure()
1352 sd->exposure_count >= LIGHT_TIME * framerate && in monitor_exposure()
1353 sd->params.sensorFps.divisor > 0) { in monitor_exposure()
1356 --sd->params.sensorFps.divisor; in monitor_exposure()
1359 if (sd->params.exposure.gain < in monitor_exposure()
1360 sd->params.exposure.gainMode - 1) { in monitor_exposure()
1361 ++sd->params.exposure.gain; in monitor_exposure()
1364 sd->exposure_status = EXPOSURE_NORMAL; in monitor_exposure()
1379 /*-----------------------------------------------------------------*/
1384 It also adjust the colour balance when an exposure step is detected - as
1395 cam_exposure = atomic_read(&sd->cam_exposure); in restart_flicker()
1397 if (sd->params.flickerControl.flickerMode == 0 || in restart_flicker()
1401 old_exp = sd->params.exposure.coarseExpLo + in restart_flicker()
1402 sd->params.exposure.coarseExpHi*256; in restart_flicker()
1404 see how far away camera exposure is from a valid in restart_flicker()
1407 cam_exposure %= sd->params.flickerControl.coarseJump; in restart_flicker()
1408 if (!sd->params.flickerControl.disabled && in restart_flicker()
1409 cam_exposure <= sd->params.flickerControl.coarseJump - 3) { in restart_flicker()
1410 /* Flicker control auto-disabled */ in restart_flicker()
1411 sd->params.flickerControl.disabled = 1; in restart_flicker()
1414 if (sd->params.flickerControl.disabled && in restart_flicker()
1415 old_exp > sd->params.flickerControl.coarseJump + in restart_flicker()
1430 sd->mainsFreq = FREQ_DEF == V4L2_CID_POWER_LINE_FREQUENCY_60HZ; in sd_config()
1433 gspca_dbg(gspca_dev, D_PROBE, "cpia CPiA camera detected (vid/pid 0x%04X:0x%04X)\n", in sd_config()
1434 id->idVendor, id->idProduct); in sd_config()
1436 cam = &gspca_dev->cam; in sd_config()
1437 cam->cam_mode = mode; in sd_config()
1438 cam->nmodes = ARRAY_SIZE(mode); in sd_config()
1442 sd->params.version.firmwareVersion = 0; in sd_config()
1444 if (sd->params.version.firmwareVersion != 1) { in sd_config()
1446 sd->params.version.firmwareVersion); in sd_config()
1447 return -ENODEV; in sd_config()
1450 /* A bug in firmware 1-02 limits gainMode to 2 */ in sd_config()
1451 if (sd->params.version.firmwareRevision <= 2 && in sd_config()
1452 sd->params.exposure.gainMode > 2) { in sd_config()
1453 sd->params.exposure.gainMode = 2; in sd_config()
1456 /* set QX3 detected flag */ in sd_config()
1457 sd->params.qx3.qx3_detected = (sd->params.pnpID.vendor == 0x0813 && in sd_config()
1458 sd->params.pnpID.product == 0x0001); in sd_config()
1462 /* -- start the camera -- */
1468 /* Start the camera in low power mode */ in sd_start()
1470 if (sd->params.status.systemState != WARM_BOOT_STATE) { in sd_start()
1472 sd->params.status.systemState); in sd_start()
1473 printstatus(gspca_dev, &sd->params); in sd_start()
1474 return -ENODEV; in sd_start()
1492 /* procedure described in developer's guide p3-28 */ in sd_start()
1495 sd->params.version.firmwareVersion = 0; in sd_start()
1499 * the camera powers up (developer's guide p 3-38) */ in sd_start()
1501 /* Set streamState before transition to high power to avoid bug in sd_start()
1502 * in firmware 1-02 */ in sd_start()
1513 /* Check the camera status */ in sd_start()
1518 if (sd->params.status.fatalError) { in sd_start()
1520 sd->params.status.fatalError, in sd_start()
1521 sd->params.status.vpStatus); in sd_start()
1522 return -EIO; in sd_start()
1525 /* VPVersion can't be retrieved before the camera is in HiPower, in sd_start()
1532 sd->params.streamStartLine = 120; in sd_start()
1534 priv = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; in sd_start()
1536 sd->params.roi.colStart = 2; in sd_start()
1537 sd->params.roi.rowStart = 6; in sd_start()
1539 sd->params.roi.colStart = 0; in sd_start()
1540 sd->params.roi.rowStart = 0; in sd_start()
1544 sd->params.format.videoSize = VIDEOSIZE_QCIF; in sd_start()
1545 sd->params.roi.colStart /= 2; in sd_start()
1546 sd->params.roi.rowStart /= 2; in sd_start()
1547 sd->params.streamStartLine /= 2; in sd_start()
1549 sd->params.format.videoSize = VIDEOSIZE_CIF; in sd_start()
1551 sd->params.roi.colEnd = sd->params.roi.colStart + in sd_start()
1552 (gspca_dev->pixfmt.width >> 3); in sd_start()
1553 sd->params.roi.rowEnd = sd->params.roi.rowStart + in sd_start()
1554 (gspca_dev->pixfmt.height >> 2); in sd_start()
1556 /* And now set the camera to a known state */ in sd_start()
1612 sd->first_frame = 6; in sd_start()
1613 sd->exposure_status = EXPOSURE_NORMAL; in sd_start()
1614 sd->exposure_count = 0; in sd_start()
1615 atomic_set(&sd->cam_exposure, 0); in sd_start()
1616 atomic_set(&sd->fps, 0); in sd_start()
1627 /* save camera state for later open (developers guide ch 3.5.3) */ in sd_stopN()
1633 /* Update the camera status */ in sd_stopN()
1638 if (sd->params.qx3.button) { in sd_stopN()
1639 /* The camera latch will hold the pressed state until we reset in sd_stopN()
1640 the latch, so we do not reset sd->params.qx3.button now, to in sd_stopN()
1642 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); in sd_stopN()
1643 input_sync(gspca_dev->input_dev); in sd_stopN()
1654 /* Start / Stop the camera to make sure we are talking to in sd_init()
1655 a supported camera, and to get some information from it in sd_init()
1663 if (sd->params.qx3.qx3_detected) in sd_init()
1669 sd->params.version.firmwareVersion, in sd_init()
1670 sd->params.version.firmwareRevision, in sd_init()
1671 sd->params.version.vcVersion, in sd_init()
1672 sd->params.version.vcRevision); in sd_init()
1673 gspca_dbg(gspca_dev, D_PROBE, "CPIA PnP-ID: %04x:%04x:%04x", in sd_init()
1674 sd->params.pnpID.vendor, sd->params.pnpID.product, in sd_init()
1675 sd->params.pnpID.deviceRevision); in sd_init()
1676 gspca_dbg(gspca_dev, D_PROBE, "VP-Version: %d.%d %04x", in sd_init()
1677 sd->params.vpVersion.vpVersion, in sd_init()
1678 sd->params.vpVersion.vpRevision, in sd_init()
1679 sd->params.vpVersion.cameraHeadID); in sd_init()
1693 data[16] == sd->params.format.videoSize && in sd_pkt_scan()
1694 data[17] == sd->params.format.subSample && in sd_pkt_scan()
1695 data[18] == sd->params.format.yuvOrder && in sd_pkt_scan()
1696 data[24] == sd->params.roi.colStart && in sd_pkt_scan()
1697 data[25] == sd->params.roi.colEnd && in sd_pkt_scan()
1698 data[26] == sd->params.roi.rowStart && in sd_pkt_scan()
1699 data[27] == sd->params.roi.rowEnd) { in sd_pkt_scan()
1702 atomic_set(&sd->cam_exposure, data[39] * 2); in sd_pkt_scan()
1703 atomic_set(&sd->fps, data[41]); in sd_pkt_scan()
1706 image = gspca_dev->image; in sd_pkt_scan()
1708 gspca_dev->image_len > 4 && in sd_pkt_scan()
1709 image[gspca_dev->image_len - 4] == 0xff && in sd_pkt_scan()
1710 image[gspca_dev->image_len - 3] == 0xff && in sd_pkt_scan()
1711 image[gspca_dev->image_len - 2] == 0xff && in sd_pkt_scan()
1712 image[gspca_dev->image_len - 1] == 0xff) in sd_pkt_scan()
1727 /* Set the normal compression settings once we have captured a in sd_dq_callback()
1729 if (sd->first_frame) { in sd_dq_callback()
1730 sd->first_frame--; in sd_dq_callback()
1731 if (sd->first_frame == 0) in sd_dq_callback()
1740 if (sd->params.exposure.expMode == 2) in sd_dq_callback()
1743 /* Update our knowledge of the camera state */ in sd_dq_callback()
1751 container_of(ctrl->handler, struct gspca_dev, ctrl_handler); in sd_s_ctrl()
1754 gspca_dev->usb_err = 0; in sd_s_ctrl()
1756 if (!gspca_dev->streaming && ctrl->id != V4L2_CID_POWER_LINE_FREQUENCY) in sd_s_ctrl()
1759 switch (ctrl->id) { in sd_s_ctrl()
1761 sd->params.colourParams.brightness = ctrl->val; in sd_s_ctrl()
1762 sd->params.flickerControl.allowableOverExposure = in sd_s_ctrl()
1763 find_over_exposure(sd->params.colourParams.brightness); in sd_s_ctrl()
1764 gspca_dev->usb_err = command_setcolourparams(gspca_dev); in sd_s_ctrl()
1765 if (!gspca_dev->usb_err) in sd_s_ctrl()
1766 gspca_dev->usb_err = command_setflickerctrl(gspca_dev); in sd_s_ctrl()
1769 sd->params.colourParams.contrast = ctrl->val; in sd_s_ctrl()
1770 gspca_dev->usb_err = command_setcolourparams(gspca_dev); in sd_s_ctrl()
1773 sd->params.colourParams.saturation = ctrl->val; in sd_s_ctrl()
1774 gspca_dev->usb_err = command_setcolourparams(gspca_dev); in sd_s_ctrl()
1777 sd->mainsFreq = ctrl->val == V4L2_CID_POWER_LINE_FREQUENCY_60HZ; in sd_s_ctrl()
1778 sd->params.flickerControl.coarseJump = in sd_s_ctrl()
1779 flicker_jumps[sd->mainsFreq] in sd_s_ctrl()
1780 [sd->params.sensorFps.baserate] in sd_s_ctrl()
1781 [sd->params.sensorFps.divisor]; in sd_s_ctrl()
1783 gspca_dev->usb_err = set_flicker(gspca_dev, in sd_s_ctrl()
1784 ctrl->val != V4L2_CID_POWER_LINE_FREQUENCY_DISABLED, in sd_s_ctrl()
1785 gspca_dev->streaming); in sd_s_ctrl()
1788 sd->params.qx3.bottomlight = ctrl->val; in sd_s_ctrl()
1789 gspca_dev->usb_err = command_setlights(gspca_dev); in sd_s_ctrl()
1792 sd->params.qx3.toplight = ctrl->val; in sd_s_ctrl()
1793 gspca_dev->usb_err = command_setlights(gspca_dev); in sd_s_ctrl()
1796 sd->params.compressionTarget.frTargeting = ctrl->val; in sd_s_ctrl()
1797 gspca_dev->usb_err = command_setcompressiontarget(gspca_dev); in sd_s_ctrl()
1800 return gspca_dev->usb_err; in sd_s_ctrl()
1810 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler; in sd_init_controls()
1826 gspca_dev->vdev.ctrl_handler = hdl; in sd_init_controls()
1834 sd->freq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops, in sd_init_controls()
1838 if (sd->params.qx3.qx3_detected) { in sd_init_controls()
1848 if (hdl->error) { in sd_init_controls()
1850 return hdl->error; in sd_init_controls()
1855 /* sub-driver description */
1870 /* -- module initialisation -- */
1878 /* -- device connect -- */