Lines Matching +full:1 +full:- +full:sd

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * cpia CPiA (1) gspca driver
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>
34 #define VIDEOSIZE_CIF 1 /* 352x288 */
36 #define SUBSAMPLE_422 1
38 #define YUVORDER_UYVY 1
40 #define COMPRESSED 1
42 #define DECIMATION_ENAB 1
49 #define CPIA_GRAB_CONTINEOUS 1
53 #define CPIA_COMPRESSION_AUTO 1
56 #define CPIA_COMPRESSION_TARGET_FRAMERATE 1
60 #define GRABSTATE 1
70 #define PASS_THROUGH_STATE 1
77 #define GRAB_ACTIVE 1
82 #define STREAM_READY 1
88 #define CPIA_FLAG 1
118 #define EXPOSURE_LIGHT 1
124 #define CPIA_MODULE_SYSTEM (1 << 5)
132 #define CPIA_COMMAND_GetCPIAVersion (INPUT | CPIA_MODULE_CPIA | 1)
141 #define CPIA_COMMAND_ReadVCRegs (INPUT | CPIA_MODULE_SYSTEM | 1)
155 #define CPIA_COMMAND_GetVPVersion (INPUT | CPIA_MODULE_VP_CTRL | 1)
173 #define CPIA_COMMAND_GrabFrame (OUTPUT | CPIA_MODULE_CAPTURE | 1)
189 #define CPIA_COMMAND_OutputRS232 (OUTPUT | CPIA_MODULE_DEBUG | 1)
213 #define FIRMWARE_VERSION(x, y) (sd->params.version.firmwareVersion == (x) && \
214 sd->params.version.firmwareRevision == (y))
225 /* Developer's Guide Table 5 p 3-34
352 struct sd { struct
361 u8 mainsFreq; /* 0 = 50hz, 1 = 60hz */
383 .priv = 1},
406 pipe = usb_rcvctrlpipe(gspca_dev->dev, 0); in cpia_usb_transferCmd()
409 pipe = usb_sndctrlpipe(gspca_dev->dev, 0); in cpia_usb_transferCmd()
414 return -EINVAL; in cpia_usb_transferCmd()
418 ret = usb_control_msg(gspca_dev->dev, pipe, in cpia_usb_transferCmd()
419 command[1], in cpia_usb_transferCmd()
423 gspca_dev->usb_buf, databytes, 1000); in cpia_usb_transferCmd()
426 pr_err("usb_control_msg %02x, error %d\n", command[1], ret); in cpia_usb_transferCmd()
428 if (ret == -EPIPE && retries > 0) { in cpia_usb_transferCmd()
429 retries--; in cpia_usb_transferCmd()
440 struct sd *sd = (struct sd *) gspca_dev; in do_command() local
464 cmd[1] = command & 0xff; in do_command()
478 sd->params.version.firmwareVersion = gspca_dev->usb_buf[0]; in do_command()
479 sd->params.version.firmwareRevision = gspca_dev->usb_buf[1]; in do_command()
480 sd->params.version.vcVersion = gspca_dev->usb_buf[2]; in do_command()
481 sd->params.version.vcRevision = gspca_dev->usb_buf[3]; in do_command()
484 sd->params.pnpID.vendor = in do_command()
485 gspca_dev->usb_buf[0] | (gspca_dev->usb_buf[1] << 8); in do_command()
486 sd->params.pnpID.product = in do_command()
487 gspca_dev->usb_buf[2] | (gspca_dev->usb_buf[3] << 8); in do_command()
488 sd->params.pnpID.deviceRevision = in do_command()
489 gspca_dev->usb_buf[4] | (gspca_dev->usb_buf[5] << 8); in do_command()
492 sd->params.status.systemState = gspca_dev->usb_buf[0]; in do_command()
493 sd->params.status.grabState = gspca_dev->usb_buf[1]; in do_command()
494 sd->params.status.streamState = gspca_dev->usb_buf[2]; in do_command()
495 sd->params.status.fatalError = gspca_dev->usb_buf[3]; in do_command()
496 sd->params.status.cmdError = gspca_dev->usb_buf[4]; in do_command()
497 sd->params.status.debugFlags = gspca_dev->usb_buf[5]; in do_command()
498 sd->params.status.vpStatus = gspca_dev->usb_buf[6]; in do_command()
499 sd->params.status.errorCode = gspca_dev->usb_buf[7]; in do_command()
502 sd->params.vpVersion.vpVersion = gspca_dev->usb_buf[0]; in do_command()
503 sd->params.vpVersion.vpRevision = gspca_dev->usb_buf[1]; in do_command()
504 sd->params.vpVersion.cameraHeadID = in do_command()
505 gspca_dev->usb_buf[2] | (gspca_dev->usb_buf[3] << 8); in do_command()
508 sd->params.colourParams.brightness = gspca_dev->usb_buf[0]; in do_command()
509 sd->params.colourParams.contrast = gspca_dev->usb_buf[1]; in do_command()
510 sd->params.colourParams.saturation = gspca_dev->usb_buf[2]; in do_command()
513 sd->params.colourBalance.redGain = gspca_dev->usb_buf[0]; in do_command()
514 sd->params.colourBalance.greenGain = gspca_dev->usb_buf[1]; in do_command()
515 sd->params.colourBalance.blueGain = gspca_dev->usb_buf[2]; in do_command()
518 sd->params.exposure.gain = gspca_dev->usb_buf[0]; in do_command()
519 sd->params.exposure.fineExp = gspca_dev->usb_buf[1]; in do_command()
520 sd->params.exposure.coarseExpLo = gspca_dev->usb_buf[2]; in do_command()
521 sd->params.exposure.coarseExpHi = gspca_dev->usb_buf[3]; in do_command()
522 sd->params.exposure.redComp = gspca_dev->usb_buf[4]; in do_command()
523 sd->params.exposure.green1Comp = gspca_dev->usb_buf[5]; in do_command()
524 sd->params.exposure.green2Comp = gspca_dev->usb_buf[6]; in do_command()
525 sd->params.exposure.blueComp = gspca_dev->usb_buf[7]; in do_command()
530 a = ((gspca_dev->usb_buf[1] & 0x02) == 0); in do_command()
531 if (a != sd->params.qx3.button) { in do_command()
533 input_report_key(gspca_dev->input_dev, KEY_CAMERA, a); in do_command()
534 input_sync(gspca_dev->input_dev); in do_command()
536 sd->params.qx3.button = a; in do_command()
538 if (sd->params.qx3.button) { in do_command()
539 /* button pressed - unlock the latch */ in do_command()
551 sd->params.qx3.cradled = ((gspca_dev->usb_buf[2] & 0x40) == 0); in do_command()
567 cmd[1] = command & 0xff; in do_command_extended()
574 gspca_dev->usb_buf[0] = e; in do_command_extended()
575 gspca_dev->usb_buf[1] = f; in do_command_extended()
576 gspca_dev->usb_buf[2] = g; in do_command_extended()
577 gspca_dev->usb_buf[3] = h; in do_command_extended()
578 gspca_dev->usb_buf[4] = i; in do_command_extended()
579 gspca_dev->usb_buf[5] = j; in do_command_extended()
580 gspca_dev->usb_buf[6] = k; in do_command_extended()
581 gspca_dev->usb_buf[7] = l; in do_command_extended()
591 * Parameters: Brightness - last brightness value set with SetColourParameters
602 MaxAllowableOverExposure = FLICKER_MAX_EXPOSURE - brightness - in find_over_exposure()
619 struct sd *sd = (struct sd *) gspca_dev; in reset_camera_params() local
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()
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()
707 struct sd *sd = (struct sd *) gspca_dev; in goto_low_power() local
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()
733 struct sd *sd = (struct sd *) gspca_dev; in goto_high_power() local
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()
786 struct sd *sd = (struct sd *) gspca_dev; in command_setformat() local
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()
803 struct sd *sd = (struct sd *) gspca_dev; in command_setcolourparams() local
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()
812 struct sd *sd = (struct sd *) gspca_dev; in command_setapcor() local
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()
822 struct sd *sd = (struct sd *) gspca_dev; in command_setvloffset() local
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()
832 struct sd *sd = (struct sd *) gspca_dev; in command_setexposure() local
836 sd->params.exposure.gainMode, in command_setexposure()
837 1, 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()
868 struct sd *sd = (struct sd *) gspca_dev; in command_setcolourbalance() local
870 if (sd->params.colourBalance.balanceMode == 1) { in command_setcolourbalance()
874 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()
898 struct sd *sd = (struct sd *) gspca_dev; in command_setcompressiontarget() local
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()
908 struct sd *sd = (struct sd *) gspca_dev; in command_setyuvtresh() local
911 sd->params.yuvThreshold.yThreshold, in command_setyuvtresh()
912 sd->params.yuvThreshold.uvThreshold, 0, 0); in command_setyuvtresh()
917 struct sd *sd = (struct sd *) gspca_dev; in command_setcompressionparams() local
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()
934 struct sd *sd = (struct sd *) gspca_dev; in command_setcompression() local
937 sd->params.compression.mode, in command_setcompression()
938 sd->params.compression.decimation, 0, 0); in command_setcompression()
943 struct sd *sd = (struct sd *) gspca_dev; in command_setsensorfps() local
946 sd->params.sensorFps.divisor, in command_setsensorfps()
947 sd->params.sensorFps.baserate, 0, 0); in command_setsensorfps()
952 struct sd *sd = (struct sd *) gspca_dev; in command_setflickerctrl() local
955 sd->params.flickerControl.flickerMode, in command_setflickerctrl()
956 sd->params.flickerControl.coarseJump, in command_setflickerctrl()
957 sd->params.flickerControl.allowableOverExposure, in command_setflickerctrl()
963 struct sd *sd = (struct sd *) gspca_dev; in command_setecptiming() local
966 sd->params.ecpTiming, 0, 0, 0); in command_setecptiming()
976 struct sd *sd = (struct sd *) gspca_dev; in command_resume() local
979 0, sd->params.streamStartLine, 0, 0); in command_resume()
984 struct sd *sd = (struct sd *) gspca_dev; in command_setlights() local
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()
1017 struct sd *sd = (struct sd *) gspca_dev; in set_flicker() local
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 currentexp = currentexp << sd->params.exposure.gain; in set_flicker()
1031 sd->params.exposure.gain = 0; in set_flicker()
1034 if (startexp < 1) in set_flicker()
1035 startexp = 1; in set_flicker()
1036 startexp = (startexp * cj) - 1; in set_flicker()
1037 if (FIRMWARE_VERSION(1, 2)) in set_flicker()
1039 startexp -= cj; in set_flicker()
1042 startexp -= cj; in set_flicker()
1043 sd->params.exposure.coarseExpLo = startexp & 0xff; in set_flicker()
1044 sd->params.exposure.coarseExpHi = startexp >> 8; in set_flicker()
1048 sd->params.exposure.redComp = in set_flicker()
1050 sd->params.exposure.green1Comp = in set_flicker()
1052 sd->params.exposure.green2Comp = in set_flicker()
1054 sd->params.exposure.blueComp = in set_flicker()
1057 sd->params.exposure.redComp = COMP_RED; in set_flicker()
1058 sd->params.exposure.green1Comp = COMP_GREEN1; in set_flicker()
1059 sd->params.exposure.green2Comp = COMP_GREEN2; in set_flicker()
1060 sd->params.exposure.blueComp = COMP_BLUE; in set_flicker()
1062 if (FIRMWARE_VERSION(1, 2)) in set_flicker()
1063 sd->params.exposure.compMode = 0; in set_flicker()
1065 sd->params.exposure.compMode = 1; in set_flicker()
1067 sd->params.apcor.gain1 = 0x18; in set_flicker()
1068 sd->params.apcor.gain2 = 0x18; in set_flicker()
1069 sd->params.apcor.gain4 = 0x16; in set_flicker()
1070 sd->params.apcor.gain8 = 0x14; in set_flicker()
1072 sd->params.flickerControl.flickerMode = 0; in set_flicker()
1073 sd->params.flickerControl.disabled = 1; in set_flicker()
1076 sd->params.exposure.redComp, currentexp); in set_flicker()
1078 sd->params.exposure.green1Comp, currentexp); in set_flicker()
1080 sd->params.exposure.green2Comp, currentexp); in set_flicker()
1082 sd->params.exposure.blueComp, currentexp); in set_flicker()
1084 while (startexp > MAX_EXP && sd->params.exposure.gain < in set_flicker()
1085 sd->params.exposure.gainMode - 1) { in set_flicker()
1086 startexp = startexp >> 1; in set_flicker()
1087 ++sd->params.exposure.gain; in set_flicker()
1089 if (FIRMWARE_VERSION(1, 2) && startexp > MAX_EXP_102) in set_flicker()
1093 sd->params.exposure.coarseExpLo = startexp & 0xff; in set_flicker()
1094 sd->params.exposure.coarseExpHi = startexp >> 8; in set_flicker()
1095 sd->params.exposure.redComp = COMP_RED; in set_flicker()
1096 sd->params.exposure.green1Comp = COMP_GREEN1; in set_flicker()
1097 sd->params.exposure.green2Comp = COMP_GREEN2; in set_flicker()
1098 sd->params.exposure.blueComp = COMP_BLUE; in set_flicker()
1099 sd->params.exposure.compMode = 1; in set_flicker()
1100 sd->params.apcor.gain1 = 0x18; in set_flicker()
1101 sd->params.apcor.gain2 = 0x16; in set_flicker()
1102 sd->params.apcor.gain4 = 0x24; in set_flicker()
1103 sd->params.apcor.gain8 = 0x34; in set_flicker()
1105 sd->params.vlOffset.gain1 = 20; in set_flicker()
1106 sd->params.vlOffset.gain2 = 24; in set_flicker()
1107 sd->params.vlOffset.gain4 = 26; in set_flicker()
1108 sd->params.vlOffset.gain8 = 26; in set_flicker()
1136 struct sd *sd = (struct sd *) gspca_dev; in monitor_exposure() local
1145 cmd[1] = CPIA_COMMAND_ReadVPRegs & 0xff; in monitor_exposure()
1154 pr_err("ReadVPRegs(30,4,9,8) - failed: %d\n", ret); in monitor_exposure()
1157 exp_acc = gspca_dev->usb_buf[0]; in monitor_exposure()
1158 bcomp = gspca_dev->usb_buf[1]; in monitor_exposure()
1160 light_exp = sd->params.colourParams.brightness + in monitor_exposure()
1161 TC - 50 + EXP_ACC_LIGHT; in monitor_exposure()
1164 dark_exp = sd->params.colourParams.brightness + in monitor_exposure()
1165 TC - 50 - EXP_ACC_DARK; in monitor_exposure()
1170 old_exposure = sd->params.exposure.coarseExpHi * 256 + in monitor_exposure()
1171 sd->params.exposure.coarseExpLo; in monitor_exposure()
1173 if (!sd->params.flickerControl.disabled) { in monitor_exposure()
1175 int max_comp = FIRMWARE_VERSION(1, 2) ? MAX_COMP : in monitor_exposure()
1182 if (sd->exposure_status == EXPOSURE_VERY_DARK) in monitor_exposure()
1183 ++sd->exposure_count; in monitor_exposure()
1185 sd->exposure_status = in monitor_exposure()
1187 sd->exposure_count = 1; in monitor_exposure()
1191 if (sd->exposure_status == EXPOSURE_DARK) in monitor_exposure()
1192 ++sd->exposure_count; in monitor_exposure()
1194 sd->exposure_status = EXPOSURE_DARK; in monitor_exposure()
1195 sd->exposure_count = 1; in monitor_exposure()
1202 if (sd->exposure_status == EXPOSURE_VERY_LIGHT) in monitor_exposure()
1203 ++sd->exposure_count; in monitor_exposure()
1205 sd->exposure_status = in monitor_exposure()
1207 sd->exposure_count = 1; in monitor_exposure()
1211 if (sd->exposure_status == EXPOSURE_LIGHT) in monitor_exposure()
1212 ++sd->exposure_count; in monitor_exposure()
1214 sd->exposure_status = EXPOSURE_LIGHT; in monitor_exposure()
1215 sd->exposure_count = 1; in monitor_exposure()
1220 sd->exposure_status = EXPOSURE_NORMAL; in monitor_exposure()
1228 if (sd->exposure_status == EXPOSURE_VERY_DARK) in monitor_exposure()
1229 ++sd->exposure_count; in monitor_exposure()
1231 sd->exposure_status = in monitor_exposure()
1233 sd->exposure_count = 1; in monitor_exposure()
1237 if (sd->exposure_status == EXPOSURE_DARK) in monitor_exposure()
1238 ++sd->exposure_count; in monitor_exposure()
1240 sd->exposure_status = EXPOSURE_DARK; in monitor_exposure()
1241 sd->exposure_count = 1; in monitor_exposure()
1248 if (sd->exposure_status == EXPOSURE_VERY_LIGHT) in monitor_exposure()
1249 ++sd->exposure_count; in monitor_exposure()
1251 sd->exposure_status = in monitor_exposure()
1253 sd->exposure_count = 1; in monitor_exposure()
1257 if (sd->exposure_status == EXPOSURE_LIGHT) in monitor_exposure()
1258 ++sd->exposure_count; in monitor_exposure()
1260 sd->exposure_status = EXPOSURE_LIGHT; in monitor_exposure()
1261 sd->exposure_count = 1; in monitor_exposure()
1266 sd->exposure_status = EXPOSURE_NORMAL; in monitor_exposure()
1270 framerate = atomic_read(&sd->fps); in monitor_exposure()
1271 if (framerate > 30 || framerate < 1) in monitor_exposure()
1272 framerate = 1; in monitor_exposure()
1274 if (!sd->params.flickerControl.disabled) { in monitor_exposure()
1276 if ((sd->exposure_status == EXPOSURE_VERY_DARK || in monitor_exposure()
1277 sd->exposure_status == EXPOSURE_DARK) && in monitor_exposure()
1278 sd->exposure_count >= DARK_TIME * framerate && in monitor_exposure()
1279 sd->params.sensorFps.divisor < 2) { in monitor_exposure()
1282 ++sd->params.sensorFps.divisor; in monitor_exposure()
1283 setfps = 1; in monitor_exposure()
1285 sd->params.flickerControl.coarseJump = in monitor_exposure()
1286 flicker_jumps[sd->mainsFreq] in monitor_exposure()
1287 [sd->params.sensorFps.baserate] in monitor_exposure()
1288 [sd->params.sensorFps.divisor]; in monitor_exposure()
1289 setflicker = 1; in monitor_exposure()
1291 new_exposure = sd->params.flickerControl.coarseJump-1; in monitor_exposure()
1294 sd->params.flickerControl.coarseJump; in monitor_exposure()
1295 sd->params.exposure.coarseExpLo = new_exposure & 0xff; in monitor_exposure()
1296 sd->params.exposure.coarseExpHi = new_exposure >> 8; in monitor_exposure()
1297 setexp = 1; in monitor_exposure()
1298 sd->exposure_status = EXPOSURE_NORMAL; in monitor_exposure()
1301 } else if ((sd->exposure_status == EXPOSURE_VERY_LIGHT || in monitor_exposure()
1302 sd->exposure_status == EXPOSURE_LIGHT) && in monitor_exposure()
1303 sd->exposure_count >= LIGHT_TIME * framerate && in monitor_exposure()
1304 sd->params.sensorFps.divisor > 0) { in monitor_exposure()
1307 int max_exp = FIRMWARE_VERSION(1, 2) ? MAX_EXP_102 : in monitor_exposure()
1309 --sd->params.sensorFps.divisor; in monitor_exposure()
1310 setfps = 1; in monitor_exposure()
1312 sd->params.flickerControl.coarseJump = in monitor_exposure()
1313 flicker_jumps[sd->mainsFreq] in monitor_exposure()
1314 [sd->params.sensorFps.baserate] in monitor_exposure()
1315 [sd->params.sensorFps.divisor]; in monitor_exposure()
1316 setflicker = 1; in monitor_exposure()
1318 new_exposure = sd->params.flickerControl.coarseJump-1; in monitor_exposure()
1321 sd->params.flickerControl.coarseJump < max_exp) in monitor_exposure()
1323 sd->params.flickerControl.coarseJump; in monitor_exposure()
1324 sd->params.exposure.coarseExpLo = new_exposure & 0xff; in monitor_exposure()
1325 sd->params.exposure.coarseExpHi = new_exposure >> 8; in monitor_exposure()
1326 setexp = 1; in monitor_exposure()
1327 sd->exposure_status = EXPOSURE_NORMAL; in monitor_exposure()
1332 if ((sd->exposure_status == EXPOSURE_VERY_DARK || in monitor_exposure()
1333 sd->exposure_status == EXPOSURE_DARK) && in monitor_exposure()
1334 sd->exposure_count >= DARK_TIME * framerate && in monitor_exposure()
1335 sd->params.sensorFps.divisor < 2) { in monitor_exposure()
1338 ++sd->params.sensorFps.divisor; in monitor_exposure()
1339 setfps = 1; in monitor_exposure()
1341 if (sd->params.exposure.gain > 0) { in monitor_exposure()
1342 --sd->params.exposure.gain; in monitor_exposure()
1343 setexp = 1; in monitor_exposure()
1345 sd->exposure_status = EXPOSURE_NORMAL; in monitor_exposure()
1348 } else if ((sd->exposure_status == EXPOSURE_VERY_LIGHT || in monitor_exposure()
1349 sd->exposure_status == EXPOSURE_LIGHT) && in monitor_exposure()
1350 sd->exposure_count >= LIGHT_TIME * framerate && in monitor_exposure()
1351 sd->params.sensorFps.divisor > 0) { in monitor_exposure()
1354 --sd->params.sensorFps.divisor; in monitor_exposure()
1355 setfps = 1; in monitor_exposure()
1357 if (sd->params.exposure.gain < in monitor_exposure()
1358 sd->params.exposure.gainMode - 1) { in monitor_exposure()
1359 ++sd->params.exposure.gain; in monitor_exposure()
1360 setexp = 1; in monitor_exposure()
1362 sd->exposure_status = EXPOSURE_NORMAL; in monitor_exposure()
1377 /*-----------------------------------------------------------------*/
1382 It also adjust the colour balance when an exposure step is detected - as
1387 struct sd *sd = (struct sd *) gspca_dev; in restart_flicker() local
1390 if (!FIRMWARE_VERSION(1, 2)) in restart_flicker()
1393 cam_exposure = atomic_read(&sd->cam_exposure); in restart_flicker()
1395 if (sd->params.flickerControl.flickerMode == 0 || in restart_flicker()
1399 old_exp = sd->params.exposure.coarseExpLo + in restart_flicker()
1400 sd->params.exposure.coarseExpHi*256; in restart_flicker()
1405 cam_exposure %= sd->params.flickerControl.coarseJump; in restart_flicker()
1406 if (!sd->params.flickerControl.disabled && in restart_flicker()
1407 cam_exposure <= sd->params.flickerControl.coarseJump - 3) { in restart_flicker()
1408 /* Flicker control auto-disabled */ in restart_flicker()
1409 sd->params.flickerControl.disabled = 1; in restart_flicker()
1412 if (sd->params.flickerControl.disabled && in restart_flicker()
1413 old_exp > sd->params.flickerControl.coarseJump + in restart_flicker()
1417 set_flicker(gspca_dev, 1, 1); in restart_flicker()
1425 struct sd *sd = (struct sd *) gspca_dev; in sd_config() local
1429 sd->mainsFreq = FREQ_DEF == V4L2_CID_POWER_LINE_FREQUENCY_60HZ; in sd_config()
1433 id->idVendor, id->idProduct); in sd_config()
1435 cam = &gspca_dev->cam; in sd_config()
1436 cam->cam_mode = mode; in sd_config()
1437 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()
1447 gspca_err(gspca_dev, "only firmware version 1 is supported (got: %d)\n", 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()
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 -- */
1467 struct sd *sd = (struct sd *) gspca_dev; in sd_start() local
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()
1504 * in firmware 1-02 */ 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()
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()
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()
1625 struct sd *sd __maybe_unused = (struct sd *) gspca_dev; in sd_stopN()
1640 if (sd->params.qx3.button) { 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()
1653 struct sd *sd = (struct sd *) gspca_dev; in sd_init() local
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()
1690 struct sd *sd = (struct sd *) gspca_dev; in sd_pkt_scan() local
1694 data[0] == MAGIC_0 && data[1] == MAGIC_1 && in sd_pkt_scan()
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()
1727 struct sd *sd = (struct sd *) gspca_dev; in sd_dq_callback() local
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()
1753 container_of(ctrl->handler, struct gspca_dev, ctrl_handler); in sd_s_ctrl()
1754 struct sd *sd = (struct sd *)gspca_dev; in sd_s_ctrl() local
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()
1811 struct sd *sd = (struct sd *)gspca_dev; in sd_init_controls() local
1812 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler; in sd_init_controls()
1824 .max = 1, in sd_init_controls()
1828 gspca_dev->vdev.ctrl_handler = hdl; in sd_init_controls()
1831 V4L2_CID_BRIGHTNESS, 0, 100, 1, BRIGHTNESS_DEF); in sd_init_controls()
1835 V4L2_CID_SATURATION, 0, 100, 1, SATURATION_DEF); 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()
1842 V4L2_CID_ILLUMINATORS_1, 0, 1, 1, in sd_init_controls()
1845 V4L2_CID_ILLUMINATORS_2, 0, 1, 1, in sd_init_controls()
1850 if (hdl->error) { in sd_init_controls()
1852 return hdl->error; in sd_init_controls()
1857 /* sub-driver description */
1868 .other_input = 1,
1872 /* -- module initialisation -- */
1880 /* -- device connect -- */
1884 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), in sd_probe()