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()
622 struct cam_params *params = &sd->params; in reset_camera_params()
627 params->colourParams.brightness = BRIGHTNESS_DEF; in reset_camera_params()
628 params->colourParams.contrast = CONTRAST_DEF; in reset_camera_params()
629 params->colourParams.saturation = SATURATION_DEF; in reset_camera_params()
630 params->exposure.gainMode = 4; in reset_camera_params()
631 params->exposure.expMode = 2; /* AEC */ in reset_camera_params()
632 params->exposure.compMode = 1; in reset_camera_params()
633 params->exposure.centreWeight = 1; in reset_camera_params()
634 params->exposure.gain = 0; in reset_camera_params()
635 params->exposure.fineExp = 0; in reset_camera_params()
636 params->exposure.coarseExpLo = 185; in reset_camera_params()
637 params->exposure.coarseExpHi = 0; in reset_camera_params()
638 params->exposure.redComp = COMP_RED; in reset_camera_params()
639 params->exposure.green1Comp = COMP_GREEN1; in reset_camera_params()
640 params->exposure.green2Comp = COMP_GREEN2; in reset_camera_params()
641 params->exposure.blueComp = COMP_BLUE; in reset_camera_params()
642 params->colourBalance.balanceMode = 2; /* ACB */ in reset_camera_params()
643 params->colourBalance.redGain = 32; in reset_camera_params()
644 params->colourBalance.greenGain = 6; in reset_camera_params()
645 params->colourBalance.blueGain = 92; in reset_camera_params()
646 params->apcor.gain1 = 0x18; in reset_camera_params()
647 params->apcor.gain2 = 0x16; in reset_camera_params()
648 params->apcor.gain4 = 0x24; in reset_camera_params()
649 params->apcor.gain8 = 0x34; in reset_camera_params()
650 params->vlOffset.gain1 = 20; in reset_camera_params()
651 params->vlOffset.gain2 = 24; in reset_camera_params()
652 params->vlOffset.gain4 = 26; in reset_camera_params()
653 params->vlOffset.gain8 = 26; in reset_camera_params()
654 params->compressionParams.hysteresis = 3; in reset_camera_params()
655 params->compressionParams.threshMax = 11; in reset_camera_params()
656 params->compressionParams.smallStep = 1; in reset_camera_params()
657 params->compressionParams.largeStep = 3; in reset_camera_params()
658 params->compressionParams.decimationHysteresis = 2; in reset_camera_params()
659 params->compressionParams.frDiffStepThresh = 5; in reset_camera_params()
660 params->compressionParams.qDiffStepThresh = 3; in reset_camera_params()
661 params->compressionParams.decimationThreshMod = 2; in reset_camera_params()
664 /* Set Sensor FPS to 15fps. This seems better than 30fps in reset_camera_params()
666 params->sensorFps.divisor = 1; in reset_camera_params()
667 params->sensorFps.baserate = 1; in reset_camera_params()
669 params->flickerControl.flickerMode = 0; in reset_camera_params()
670 params->flickerControl.disabled = 1; in reset_camera_params()
671 params->flickerControl.coarseJump = in reset_camera_params()
672 flicker_jumps[sd->mainsFreq] in reset_camera_params()
673 [params->sensorFps.baserate] in reset_camera_params()
674 [params->sensorFps.divisor]; in reset_camera_params()
675 params->flickerControl.allowableOverExposure = in reset_camera_params()
676 find_over_exposure(params->colourParams.brightness); in reset_camera_params()
678 params->yuvThreshold.yThreshold = 6; /* From windows driver */ in reset_camera_params()
679 params->yuvThreshold.uvThreshold = 6; /* From windows driver */ in reset_camera_params()
681 params->format.subSample = SUBSAMPLE_420; in reset_camera_params()
682 params->format.yuvOrder = YUVORDER_YUYV; in reset_camera_params()
684 params->compression.mode = CPIA_COMPRESSION_AUTO; in reset_camera_params()
685 params->compression.decimation = NO_DECIMATION; in reset_camera_params()
687 params->compressionTarget.frTargeting = COMP_TARGET_DEF; in reset_camera_params()
688 params->compressionTarget.targetFR = 15; /* From windows driver */ in reset_camera_params()
689 params->compressionTarget.targetQ = 5; /* From windows driver */ in reset_camera_params()
691 params->qx3.qx3_detected = 0; in reset_camera_params()
692 params->qx3.toplight = 0; in reset_camera_params()
693 params->qx3.bottomlight = 0; in reset_camera_params()
694 params->qx3.button = 0; in reset_camera_params()
695 params->qx3.cradled = 0; in reset_camera_params()
701 params->status.systemState, params->status.grabState, in printstatus()
702 params->status.streamState, params->status.fatalError, in printstatus()
703 params->status.cmdError, params->status.debugFlags, in printstatus()
704 params->status.vpStatus, params->status.errorCode); in printstatus()
720 if (sd->params.status.systemState != LO_POWER_STATE) { in goto_low_power()
721 if (sd->params.status.systemState != WARM_BOOT_STATE) { in goto_low_power()
723 sd->params.status.systemState); in goto_low_power()
724 printstatus(gspca_dev, &sd->params); in goto_low_power()
726 return -EIO; in goto_low_power()
729 gspca_dbg(gspca_dev, D_CONF, "camera now in LOW power state\n"); in goto_low_power()
745 return -EINTR; in goto_high_power()
751 if (sd->params.status.systemState != HI_POWER_STATE) { in goto_high_power()
753 sd->params.status.systemState); in goto_high_power()
754 printstatus(gspca_dev, &sd->params); in goto_high_power()
755 return -EIO; in goto_high_power()
758 gspca_dbg(gspca_dev, D_CONF, "camera now in HIGH power state\n"); in goto_high_power()
792 sd->params.format.videoSize, in command_setformat()
793 sd->params.format.subSample, in command_setformat()
794 sd->params.format.yuvOrder, 0); in command_setformat()
799 sd->params.roi.colStart, sd->params.roi.colEnd, in command_setformat()
800 sd->params.roi.rowStart, sd->params.roi.rowEnd); in command_setformat()
807 sd->params.colourParams.brightness, in command_setcolourparams()
808 sd->params.colourParams.contrast, in command_setcolourparams()
809 sd->params.colourParams.saturation, 0); in command_setcolourparams()
816 sd->params.apcor.gain1, in command_setapcor()
817 sd->params.apcor.gain2, in command_setapcor()
818 sd->params.apcor.gain4, in command_setapcor()
819 sd->params.apcor.gain8); in command_setapcor()
826 sd->params.vlOffset.gain1, in command_setvloffset()
827 sd->params.vlOffset.gain2, in command_setvloffset()
828 sd->params.vlOffset.gain4, in command_setvloffset()
829 sd->params.vlOffset.gain8); in command_setvloffset()
838 sd->params.exposure.gainMode, in command_setexposure()
840 sd->params.exposure.compMode, in command_setexposure()
841 sd->params.exposure.centreWeight, in command_setexposure()
842 sd->params.exposure.gain, in command_setexposure()
843 sd->params.exposure.fineExp, in command_setexposure()
844 sd->params.exposure.coarseExpLo, in command_setexposure()
845 sd->params.exposure.coarseExpHi, in command_setexposure()
846 sd->params.exposure.redComp, in command_setexposure()
847 sd->params.exposure.green1Comp, in command_setexposure()
848 sd->params.exposure.green2Comp, in command_setexposure()
849 sd->params.exposure.blueComp); in command_setexposure()
853 if (sd->params.exposure.expMode != 1) { in command_setexposure()
856 sd->params.exposure.expMode, in command_setexposure()
858 sd->params.exposure.gain, in command_setexposure()
859 sd->params.exposure.fineExp, in command_setexposure()
860 sd->params.exposure.coarseExpLo, in command_setexposure()
861 sd->params.exposure.coarseExpHi, in command_setexposure()
872 if (sd->params.colourBalance.balanceMode == 1) { in command_setcolourbalance()
877 sd->params.colourBalance.redGain, in command_setcolourbalance()
878 sd->params.colourBalance.greenGain, in command_setcolourbalance()
879 sd->params.colourBalance.blueGain); in command_setcolourbalance()
886 if (sd->params.colourBalance.balanceMode == 2) { in command_setcolourbalance()
890 if (sd->params.colourBalance.balanceMode == 3) { in command_setcolourbalance()
895 return -EINVAL; in command_setcolourbalance()
903 sd->params.compressionTarget.frTargeting, in command_setcompressiontarget()
904 sd->params.compressionTarget.targetFR, in command_setcompressiontarget()
905 sd->params.compressionTarget.targetQ, 0); in command_setcompressiontarget()
913 sd->params.yuvThreshold.yThreshold, in command_setyuvtresh()
914 sd->params.yuvThreshold.uvThreshold, 0, 0); in command_setyuvtresh()
924 sd->params.compressionParams.hysteresis, in command_setcompressionparams()
925 sd->params.compressionParams.threshMax, in command_setcompressionparams()
926 sd->params.compressionParams.smallStep, in command_setcompressionparams()
927 sd->params.compressionParams.largeStep, in command_setcompressionparams()
928 sd->params.compressionParams.decimationHysteresis, in command_setcompressionparams()
929 sd->params.compressionParams.frDiffStepThresh, in command_setcompressionparams()
930 sd->params.compressionParams.qDiffStepThresh, in command_setcompressionparams()
931 sd->params.compressionParams.decimationThreshMod); in command_setcompressionparams()
939 sd->params.compression.mode, in command_setcompression()
940 sd->params.compression.decimation, 0, 0); in command_setcompression()
948 sd->params.sensorFps.divisor, in command_setsensorfps()
949 sd->params.sensorFps.baserate, 0, 0); in command_setsensorfps()
957 sd->params.flickerControl.flickerMode, in command_setflickerctrl()
958 sd->params.flickerControl.coarseJump, in command_setflickerctrl()
959 sd->params.flickerControl.allowableOverExposure, in command_setflickerctrl()
968 sd->params.ecpTiming, 0, 0, 0); in command_setecptiming()
981 0, sd->params.streamStartLine, 0, 0); in command_resume()
989 p1 = (sd->params.qx3.bottomlight == 0) << 1; in command_setlights()
990 p2 = (sd->params.qx3.toplight == 0) << 3; in command_setlights()
1007 (u8) ((((float) base - 128.0) * ((float) curexp / (float) newexp)) + 128.5) in set_flicker()
1010 (float)(u8)(basecomp - 128)) in set_flicker()
1014 (u8)(128 + (((u32)(2*(base-128)*curexp + newexp)) / (2 * newexp))) in set_flicker()
1016 (u16)(((u32)(curexp * (u8)(curcomp + 128)) / (u8)(basecomp - 128))) in set_flicker()
1020 int currentexp = sd->params.exposure.coarseExpLo + in set_flicker()
1021 sd->params.exposure.coarseExpHi * 256; in set_flicker()
1025 int cj = sd->params.flickerControl.coarseJump; in set_flicker()
1026 sd->params.flickerControl.flickerMode = 1; in set_flicker()
1027 sd->params.flickerControl.disabled = 0; in set_flicker()
1028 if (sd->params.exposure.expMode != 2) { in set_flicker()
1029 sd->params.exposure.expMode = 2; in set_flicker()
1030 sd->exposure_status = EXPOSURE_NORMAL; in set_flicker()
1032 if (sd->params.exposure.gain >= BITS_PER_TYPE(currentexp)) in set_flicker()
1033 return -EINVAL; in set_flicker()
1034 currentexp = currentexp << sd->params.exposure.gain; in set_flicker()
1035 sd->params.exposure.gain = 0; in set_flicker()
1040 startexp = (startexp * cj) - 1; in set_flicker()
1043 startexp -= cj; in set_flicker()
1046 startexp -= cj; in set_flicker()
1047 sd->params.exposure.coarseExpLo = startexp & 0xff; in set_flicker()
1048 sd->params.exposure.coarseExpHi = startexp >> 8; in set_flicker()
1052 sd->params.exposure.redComp = in set_flicker()
1054 sd->params.exposure.green1Comp = in set_flicker()
1056 sd->params.exposure.green2Comp = in set_flicker()
1058 sd->params.exposure.blueComp = in set_flicker()
1061 sd->params.exposure.redComp = COMP_RED; in set_flicker()
1062 sd->params.exposure.green1Comp = COMP_GREEN1; in set_flicker()
1063 sd->params.exposure.green2Comp = COMP_GREEN2; in set_flicker()
1064 sd->params.exposure.blueComp = COMP_BLUE; in set_flicker()
1067 sd->params.exposure.compMode = 0; in set_flicker()
1069 sd->params.exposure.compMode = 1; in set_flicker()
1071 sd->params.apcor.gain1 = 0x18; in set_flicker()
1072 sd->params.apcor.gain2 = 0x18; in set_flicker()
1073 sd->params.apcor.gain4 = 0x16; in set_flicker()
1074 sd->params.apcor.gain8 = 0x14; in set_flicker()
1076 sd->params.flickerControl.flickerMode = 0; in set_flicker()
1077 sd->params.flickerControl.disabled = 1; in set_flicker()
1080 sd->params.exposure.redComp, currentexp); in set_flicker()
1082 sd->params.exposure.green1Comp, currentexp); in set_flicker()
1084 sd->params.exposure.green2Comp, currentexp); in set_flicker()
1086 sd->params.exposure.blueComp, currentexp); in set_flicker()
1088 while (startexp > MAX_EXP && sd->params.exposure.gain < in set_flicker()
1089 sd->params.exposure.gainMode - 1) { in set_flicker()
1091 ++sd->params.exposure.gain; in set_flicker()
1097 sd->params.exposure.coarseExpLo = startexp & 0xff; in set_flicker()
1098 sd->params.exposure.coarseExpHi = startexp >> 8; in set_flicker()
1099 sd->params.exposure.redComp = COMP_RED; in set_flicker()
1100 sd->params.exposure.green1Comp = COMP_GREEN1; in set_flicker()
1101 sd->params.exposure.green2Comp = COMP_GREEN2; in set_flicker()
1102 sd->params.exposure.blueComp = COMP_BLUE; in set_flicker()
1103 sd->params.exposure.compMode = 1; in set_flicker()
1104 sd->params.apcor.gain1 = 0x18; in set_flicker()
1105 sd->params.apcor.gain2 = 0x16; in set_flicker()
1106 sd->params.apcor.gain4 = 0x24; in set_flicker()
1107 sd->params.apcor.gain8 = 0x34; in set_flicker()
1109 sd->params.vlOffset.gain1 = 20; in set_flicker()
1110 sd->params.vlOffset.gain2 = 24; in set_flicker()
1111 sd->params.vlOffset.gain4 = 26; in set_flicker()
1112 sd->params.vlOffset.gain8 = 26; in set_flicker()
1146 /* get necessary stats and register settings from camera */ in monitor_exposure()
1158 pr_err("ReadVPRegs(30,4,9,8) - failed: %d\n", ret); in monitor_exposure()
1161 exp_acc = gspca_dev->usb_buf[0]; in monitor_exposure()
1162 bcomp = gspca_dev->usb_buf[1]; in monitor_exposure()
1164 light_exp = sd->params.colourParams.brightness + in monitor_exposure()
1165 TC - 50 + EXP_ACC_LIGHT; in monitor_exposure()
1168 dark_exp = sd->params.colourParams.brightness + in monitor_exposure()
1169 TC - 50 - EXP_ACC_DARK; in monitor_exposure()
1174 old_exposure = sd->params.exposure.coarseExpHi * 256 + in monitor_exposure()
1175 sd->params.exposure.coarseExpLo; in monitor_exposure()
1177 if (!sd->params.flickerControl.disabled) { in monitor_exposure()
1186 if (sd->exposure_status == EXPOSURE_VERY_DARK) in monitor_exposure()
1187 ++sd->exposure_count; in monitor_exposure()
1189 sd->exposure_status = in monitor_exposure()
1191 sd->exposure_count = 1; in monitor_exposure()
1195 if (sd->exposure_status == EXPOSURE_DARK) in monitor_exposure()
1196 ++sd->exposure_count; in monitor_exposure()
1198 sd->exposure_status = EXPOSURE_DARK; in monitor_exposure()
1199 sd->exposure_count = 1; in monitor_exposure()
1206 if (sd->exposure_status == EXPOSURE_VERY_LIGHT) in monitor_exposure()
1207 ++sd->exposure_count; in monitor_exposure()
1209 sd->exposure_status = in monitor_exposure()
1211 sd->exposure_count = 1; in monitor_exposure()
1215 if (sd->exposure_status == EXPOSURE_LIGHT) in monitor_exposure()
1216 ++sd->exposure_count; in monitor_exposure()
1218 sd->exposure_status = EXPOSURE_LIGHT; in monitor_exposure()
1219 sd->exposure_count = 1; in monitor_exposure()
1224 sd->exposure_status = EXPOSURE_NORMAL; in monitor_exposure()
1232 if (sd->exposure_status == EXPOSURE_VERY_DARK) in monitor_exposure()
1233 ++sd->exposure_count; in monitor_exposure()
1235 sd->exposure_status = in monitor_exposure()
1237 sd->exposure_count = 1; in monitor_exposure()
1241 if (sd->exposure_status == EXPOSURE_DARK) in monitor_exposure()
1242 ++sd->exposure_count; in monitor_exposure()
1244 sd->exposure_status = EXPOSURE_DARK; in monitor_exposure()
1245 sd->exposure_count = 1; in monitor_exposure()
1252 if (sd->exposure_status == EXPOSURE_VERY_LIGHT) in monitor_exposure()
1253 ++sd->exposure_count; in monitor_exposure()
1255 sd->exposure_status = in monitor_exposure()
1257 sd->exposure_count = 1; in monitor_exposure()
1261 if (sd->exposure_status == EXPOSURE_LIGHT) in monitor_exposure()
1262 ++sd->exposure_count; in monitor_exposure()
1264 sd->exposure_status = EXPOSURE_LIGHT; in monitor_exposure()
1265 sd->exposure_count = 1; in monitor_exposure()
1270 sd->exposure_status = EXPOSURE_NORMAL; in monitor_exposure()
1274 framerate = atomic_read(&sd->fps); in monitor_exposure()
1278 if (!sd->params.flickerControl.disabled) { in monitor_exposure()
1280 if ((sd->exposure_status == EXPOSURE_VERY_DARK || in monitor_exposure()
1281 sd->exposure_status == EXPOSURE_DARK) && in monitor_exposure()
1282 sd->exposure_count >= DARK_TIME * framerate && in monitor_exposure()
1283 sd->params.sensorFps.divisor < 2) { in monitor_exposure()
1286 ++sd->params.sensorFps.divisor; in monitor_exposure()
1289 sd->params.flickerControl.coarseJump = in monitor_exposure()
1290 flicker_jumps[sd->mainsFreq] in monitor_exposure()
1291 [sd->params.sensorFps.baserate] in monitor_exposure()
1292 [sd->params.sensorFps.divisor]; in monitor_exposure()
1295 new_exposure = sd->params.flickerControl.coarseJump-1; in monitor_exposure()
1298 sd->params.flickerControl.coarseJump; in monitor_exposure()
1299 sd->params.exposure.coarseExpLo = new_exposure & 0xff; in monitor_exposure()
1300 sd->params.exposure.coarseExpHi = new_exposure >> 8; in monitor_exposure()
1302 sd->exposure_status = EXPOSURE_NORMAL; in monitor_exposure()
1305 } else if ((sd->exposure_status == EXPOSURE_VERY_LIGHT || in monitor_exposure()
1306 sd->exposure_status == EXPOSURE_LIGHT) && in monitor_exposure()
1307 sd->exposure_count >= LIGHT_TIME * framerate && in monitor_exposure()
1308 sd->params.sensorFps.divisor > 0) { in monitor_exposure()
1313 --sd->params.sensorFps.divisor; in monitor_exposure()
1316 sd->params.flickerControl.coarseJump = in monitor_exposure()
1317 flicker_jumps[sd->mainsFreq] in monitor_exposure()
1318 [sd->params.sensorFps.baserate] in monitor_exposure()
1319 [sd->params.sensorFps.divisor]; in monitor_exposure()
1322 new_exposure = sd->params.flickerControl.coarseJump-1; in monitor_exposure()
1325 sd->params.flickerControl.coarseJump < max_exp) in monitor_exposure()
1327 sd->params.flickerControl.coarseJump; in monitor_exposure()
1328 sd->params.exposure.coarseExpLo = new_exposure & 0xff; in monitor_exposure()
1329 sd->params.exposure.coarseExpHi = new_exposure >> 8; in monitor_exposure()
1331 sd->exposure_status = EXPOSURE_NORMAL; in monitor_exposure()
1336 if ((sd->exposure_status == EXPOSURE_VERY_DARK || in monitor_exposure()
1337 sd->exposure_status == EXPOSURE_DARK) && in monitor_exposure()
1338 sd->exposure_count >= DARK_TIME * framerate && in monitor_exposure()
1339 sd->params.sensorFps.divisor < 2) { in monitor_exposure()
1342 ++sd->params.sensorFps.divisor; in monitor_exposure()
1345 if (sd->params.exposure.gain > 0) { in monitor_exposure()
1346 --sd->params.exposure.gain; in monitor_exposure()
1349 sd->exposure_status = EXPOSURE_NORMAL; in monitor_exposure()
1352 } else if ((sd->exposure_status == EXPOSURE_VERY_LIGHT || in monitor_exposure()
1353 sd->exposure_status == EXPOSURE_LIGHT) && in monitor_exposure()
1354 sd->exposure_count >= LIGHT_TIME * framerate && in monitor_exposure()
1355 sd->params.sensorFps.divisor > 0) { in monitor_exposure()
1358 --sd->params.sensorFps.divisor; in monitor_exposure()
1361 if (sd->params.exposure.gain < in monitor_exposure()
1362 sd->params.exposure.gainMode - 1) { in monitor_exposure()
1363 ++sd->params.exposure.gain; in monitor_exposure()
1366 sd->exposure_status = EXPOSURE_NORMAL; in monitor_exposure()
1381 /*-----------------------------------------------------------------*/
1386 It also adjust the colour balance when an exposure step is detected - as
1397 cam_exposure = atomic_read(&sd->cam_exposure); in restart_flicker()
1399 if (sd->params.flickerControl.flickerMode == 0 || in restart_flicker()
1403 old_exp = sd->params.exposure.coarseExpLo + in restart_flicker()
1404 sd->params.exposure.coarseExpHi*256; in restart_flicker()
1406 see how far away camera exposure is from a valid in restart_flicker()
1409 cam_exposure %= sd->params.flickerControl.coarseJump; in restart_flicker()
1410 if (!sd->params.flickerControl.disabled && in restart_flicker()
1411 cam_exposure <= sd->params.flickerControl.coarseJump - 3) { in restart_flicker()
1412 /* Flicker control auto-disabled */ in restart_flicker()
1413 sd->params.flickerControl.disabled = 1; in restart_flicker()
1416 if (sd->params.flickerControl.disabled && in restart_flicker()
1417 old_exp > sd->params.flickerControl.coarseJump + in restart_flicker()
1432 sd->mainsFreq = FREQ_DEF == V4L2_CID_POWER_LINE_FREQUENCY_60HZ; in sd_config()
1435 gspca_dbg(gspca_dev, D_PROBE, "cpia CPiA camera detected (vid/pid 0x%04X:0x%04X)\n", in sd_config()
1436 id->idVendor, id->idProduct); in sd_config()
1438 cam = &gspca_dev->cam; in sd_config()
1439 cam->cam_mode = mode; in sd_config()
1440 cam->nmodes = ARRAY_SIZE(mode); in sd_config()
1444 sd->params.version.firmwareVersion = 0; in sd_config()
1446 if (sd->params.version.firmwareVersion != 1) { in sd_config()
1448 sd->params.version.firmwareVersion); in sd_config()
1449 return -ENODEV; in sd_config()
1452 /* A bug in firmware 1-02 limits gainMode to 2 */ in sd_config()
1453 if (sd->params.version.firmwareRevision <= 2 && in sd_config()
1454 sd->params.exposure.gainMode > 2) { in sd_config()
1455 sd->params.exposure.gainMode = 2; in sd_config()
1458 /* set QX3 detected flag */ in sd_config()
1459 sd->params.qx3.qx3_detected = (sd->params.pnpID.vendor == 0x0813 && in sd_config()
1460 sd->params.pnpID.product == 0x0001); in sd_config()
1464 /* -- start the camera -- */
1470 /* Start the camera in low power mode */ in sd_start()
1472 if (sd->params.status.systemState != WARM_BOOT_STATE) { in sd_start()
1474 sd->params.status.systemState); in sd_start()
1475 printstatus(gspca_dev, &sd->params); in sd_start()
1476 return -ENODEV; in sd_start()
1494 /* procedure described in developer's guide p3-28 */ in sd_start()
1497 sd->params.version.firmwareVersion = 0; in sd_start()
1501 * the camera powers up (developer's guide p 3-38) */ in sd_start()
1503 /* Set streamState before transition to high power to avoid bug in sd_start()
1504 * in firmware 1-02 */ in sd_start()
1515 /* Check the camera status */ in sd_start()
1520 if (sd->params.status.fatalError) { in sd_start()
1522 sd->params.status.fatalError, in sd_start()
1523 sd->params.status.vpStatus); in sd_start()
1524 return -EIO; in sd_start()
1527 /* VPVersion can't be retrieved before the camera is in HiPower, in sd_start()
1534 sd->params.streamStartLine = 120; in sd_start()
1536 priv = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; in sd_start()
1538 sd->params.roi.colStart = 2; in sd_start()
1539 sd->params.roi.rowStart = 6; in sd_start()
1541 sd->params.roi.colStart = 0; in sd_start()
1542 sd->params.roi.rowStart = 0; in sd_start()
1546 sd->params.format.videoSize = VIDEOSIZE_QCIF; in sd_start()
1547 sd->params.roi.colStart /= 2; in sd_start()
1548 sd->params.roi.rowStart /= 2; in sd_start()
1549 sd->params.streamStartLine /= 2; in sd_start()
1551 sd->params.format.videoSize = VIDEOSIZE_CIF; in sd_start()
1553 sd->params.roi.colEnd = sd->params.roi.colStart + in sd_start()
1554 (gspca_dev->pixfmt.width >> 3); in sd_start()
1555 sd->params.roi.rowEnd = sd->params.roi.rowStart + in sd_start()
1556 (gspca_dev->pixfmt.height >> 2); in sd_start()
1558 /* And now set the camera to a known state */ in sd_start()
1614 sd->first_frame = 6; in sd_start()
1615 sd->exposure_status = EXPOSURE_NORMAL; in sd_start()
1616 sd->exposure_count = 0; in sd_start()
1617 atomic_set(&sd->cam_exposure, 0); in sd_start()
1618 atomic_set(&sd->fps, 0); in sd_start()
1629 /* save camera state for later open (developers guide ch 3.5.3) */ in sd_stopN()
1635 /* Update the camera status */ in sd_stopN()
1640 if (sd->params.qx3.button) { in sd_stopN()
1641 /* The camera latch will hold the pressed state until we reset in sd_stopN()
1642 the latch, so we do not reset sd->params.qx3.button now, to in sd_stopN()
1644 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); in sd_stopN()
1645 input_sync(gspca_dev->input_dev); in sd_stopN()
1656 /* Start / Stop the camera to make sure we are talking to in sd_init()
1657 a supported camera, and to get some information from it in sd_init()
1665 if (sd->params.qx3.qx3_detected) in sd_init()
1671 sd->params.version.firmwareVersion, in sd_init()
1672 sd->params.version.firmwareRevision, in sd_init()
1673 sd->params.version.vcVersion, in sd_init()
1674 sd->params.version.vcRevision); in sd_init()
1675 gspca_dbg(gspca_dev, D_PROBE, "CPIA PnP-ID: %04x:%04x:%04x", in sd_init()
1676 sd->params.pnpID.vendor, sd->params.pnpID.product, in sd_init()
1677 sd->params.pnpID.deviceRevision); in sd_init()
1678 gspca_dbg(gspca_dev, D_PROBE, "VP-Version: %d.%d %04x", in sd_init()
1679 sd->params.vpVersion.vpVersion, in sd_init()
1680 sd->params.vpVersion.vpRevision, in sd_init()
1681 sd->params.vpVersion.cameraHeadID); in sd_init()
1695 data[16] == sd->params.format.videoSize && in sd_pkt_scan()
1696 data[17] == sd->params.format.subSample && in sd_pkt_scan()
1697 data[18] == sd->params.format.yuvOrder && in sd_pkt_scan()
1698 data[24] == sd->params.roi.colStart && in sd_pkt_scan()
1699 data[25] == sd->params.roi.colEnd && in sd_pkt_scan()
1700 data[26] == sd->params.roi.rowStart && in sd_pkt_scan()
1701 data[27] == sd->params.roi.rowEnd) { in sd_pkt_scan()
1704 atomic_set(&sd->cam_exposure, data[39] * 2); in sd_pkt_scan()
1705 atomic_set(&sd->fps, data[41]); in sd_pkt_scan()
1708 image = gspca_dev->image; in sd_pkt_scan()
1710 gspca_dev->image_len > 4 && in sd_pkt_scan()
1711 image[gspca_dev->image_len - 4] == 0xff && in sd_pkt_scan()
1712 image[gspca_dev->image_len - 3] == 0xff && in sd_pkt_scan()
1713 image[gspca_dev->image_len - 2] == 0xff && in sd_pkt_scan()
1714 image[gspca_dev->image_len - 1] == 0xff) in sd_pkt_scan()
1729 /* Set the normal compression settings once we have captured a in sd_dq_callback()
1731 if (sd->first_frame) { in sd_dq_callback()
1732 sd->first_frame--; in sd_dq_callback()
1733 if (sd->first_frame == 0) in sd_dq_callback()
1742 if (sd->params.exposure.expMode == 2) in sd_dq_callback()
1745 /* Update our knowledge of the camera state */ in sd_dq_callback()
1753 container_of(ctrl->handler, struct gspca_dev, ctrl_handler); in sd_s_ctrl()
1756 gspca_dev->usb_err = 0; in sd_s_ctrl()
1758 if (!gspca_dev->streaming && ctrl->id != V4L2_CID_POWER_LINE_FREQUENCY) in sd_s_ctrl()
1761 switch (ctrl->id) { in sd_s_ctrl()
1763 sd->params.colourParams.brightness = ctrl->val; in sd_s_ctrl()
1764 sd->params.flickerControl.allowableOverExposure = in sd_s_ctrl()
1765 find_over_exposure(sd->params.colourParams.brightness); in sd_s_ctrl()
1766 gspca_dev->usb_err = command_setcolourparams(gspca_dev); in sd_s_ctrl()
1767 if (!gspca_dev->usb_err) in sd_s_ctrl()
1768 gspca_dev->usb_err = command_setflickerctrl(gspca_dev); in sd_s_ctrl()
1771 sd->params.colourParams.contrast = ctrl->val; in sd_s_ctrl()
1772 gspca_dev->usb_err = command_setcolourparams(gspca_dev); in sd_s_ctrl()
1775 sd->params.colourParams.saturation = ctrl->val; in sd_s_ctrl()
1776 gspca_dev->usb_err = command_setcolourparams(gspca_dev); in sd_s_ctrl()
1779 sd->mainsFreq = ctrl->val == V4L2_CID_POWER_LINE_FREQUENCY_60HZ; in sd_s_ctrl()
1780 sd->params.flickerControl.coarseJump = in sd_s_ctrl()
1781 flicker_jumps[sd->mainsFreq] in sd_s_ctrl()
1782 [sd->params.sensorFps.baserate] in sd_s_ctrl()
1783 [sd->params.sensorFps.divisor]; in sd_s_ctrl()
1785 gspca_dev->usb_err = set_flicker(gspca_dev, in sd_s_ctrl()
1786 ctrl->val != V4L2_CID_POWER_LINE_FREQUENCY_DISABLED, in sd_s_ctrl()
1787 gspca_dev->streaming); in sd_s_ctrl()
1790 sd->params.qx3.bottomlight = ctrl->val; in sd_s_ctrl()
1791 gspca_dev->usb_err = command_setlights(gspca_dev); in sd_s_ctrl()
1794 sd->params.qx3.toplight = ctrl->val; in sd_s_ctrl()
1795 gspca_dev->usb_err = command_setlights(gspca_dev); in sd_s_ctrl()
1798 sd->params.compressionTarget.frTargeting = ctrl->val; in sd_s_ctrl()
1799 gspca_dev->usb_err = command_setcompressiontarget(gspca_dev); in sd_s_ctrl()
1802 return gspca_dev->usb_err; in sd_s_ctrl()
1812 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler; in sd_init_controls()
1828 gspca_dev->vdev.ctrl_handler = hdl; in sd_init_controls()
1836 sd->freq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops, in sd_init_controls()
1840 if (sd->params.qx3.qx3_detected) { in sd_init_controls()
1850 if (hdl->error) { in sd_init_controls()
1852 return hdl->error; in sd_init_controls()
1857 /* sub-driver description */
1872 /* -- module initialisation -- */
1880 /* -- device connect -- */