Lines Matching +full:gain +full:- +full:offset

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2009-2011 Jean-François Moine <http://moinejf.free.fr>
14 0x10 high nibble red gain low nibble blue gain
15 0x11 low nibble green gain
17 0x05 red gain 0-127
18 0x06 blue gain 0-127
19 0x07 green gain 0-127
21 0x08-0x0f i2c / 3wire registers
24 0x15 hsize (hsize = register-value * 16)
25 0x16 vsize (vsize = register-value * 16)
27 0x18 bit 7 enables compression, bit 4-5 set image down scaling:
29 0x19 high-nibble is sensor clock divider, changes exposure on sensors which
31 0x1c auto_exposure area (for avg_lum) startx (startx = register-value * 32)
32 0x1d auto_exposure area (for avg_lum) starty (starty = register-value * 32)
33 0x1e auto_exposure area (for avg_lum) stopx (hsize = (0x1e - 0x1c) * 32)
34 0x1f auto_exposure area (for avg_lum) stopy (vsize = (0x1f - 0x1d) * 32)
42 MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
101 #define MCK_INIT1 0x20 /*fixme: Bayer - 0x50 for JPEG ??*/
115 if we adjust the gain or exposure we must ignore at least the next frame for
230 add a bit additional red gain and a lot additional blue gain, which
278 0x03 Variable framerate bits 4-11
279 0x04 Var framerate bits 0-3, one must leave the 4 msb's at 0 !!
282 0x05 Shutter Time Line Offset, this can be used as an exposure control:
284 Note this may never be larger then "var-framerate control" / 2 - 2.
285 When var-framerate control is < 514, no exposure is reached at the max
287 0x06 Shutter Time Pixel Offset, like reg05 this influences exposure, but
289 0x07 offset sign bit (bit0 1 > negative offset)
290 0x08 offset
291 0x09 Blue Gain
292 0x0a Green1 Gain
293 0x0b Green2 Gain
294 0x0c Red Gain
295 0x0e Global gain
306 /* Shutter Time Line Offset (also seen as 0x6d) */
308 /* Shutter Time Pixel Offset (also seen as 0xb1) */
315 /* Color Gain B Pixel 5 a */
317 /* Color Gain G1 Pixel 1 5 */
319 /* Color Gain G2 Pixel 1 0 5 */
321 /* Color Gain R Pixel 3 1 */
325 /* Global Gain */
350 0x04 Variable framerate bits 6-11 (*)
351 0x05 Var framerate bits 0-5, one must leave the 2 msb's at 0 !!
352 0x07 Blue Gain
353 0x08 Green Gain
354 0x09 Red Gain
355 0x0b offset sign bit (bit0 1 > negative offset)
356 0x0c offset
359 0x0f Exposure 0-255, 0 = use full frame time, 255 = no exposure at all
360 0x10 Master gain 0 - 31
366 /* Set the clock divider to 4 -> 30 / 4 = 7.5 fps, we would like
400 * reg02: gain, bit order reversed!! 0 == max gain, 255 == min gain
434 /* get one byte in gspca_dev->usb_buf */
440 if (gspca_dev->usb_err < 0) in reg_r()
443 res = usb_control_msg(gspca_dev->dev, in reg_r()
444 usb_rcvctrlpipe(gspca_dev->dev, 0), in reg_r()
449 gspca_dev->usb_buf, 1, in reg_r()
453 dev_err(gspca_dev->v4l2_dev.dev, in reg_r()
455 gspca_dev->usb_err = res; in reg_r()
460 gspca_dev->usb_buf[0] = 0; in reg_r()
471 if (gspca_dev->usb_err < 0) in reg_w()
474 memcpy(gspca_dev->usb_buf, buffer, len); in reg_w()
475 res = usb_control_msg(gspca_dev->dev, in reg_w()
476 usb_sndctrlpipe(gspca_dev->dev, 0), in reg_w()
481 gspca_dev->usb_buf, len, in reg_w()
485 dev_err(gspca_dev->v4l2_dev.dev, in reg_w()
487 gspca_dev->usb_err = res; in reg_w()
495 if (gspca_dev->usb_err < 0) in i2c_w()
500 while (retry--) { in i2c_w()
501 if (gspca_dev->usb_err < 0) in i2c_w()
505 if (gspca_dev->usb_buf[0] & 0x04) { in i2c_w()
506 if (gspca_dev->usb_buf[0] & 0x08) { in i2c_w()
507 dev_err(gspca_dev->v4l2_dev.dev, in i2c_w()
509 gspca_dev->usb_err = -EIO; in i2c_w()
515 dev_err(gspca_dev->v4l2_dev.dev, "i2c write timeout\n"); in i2c_w()
516 gspca_dev->usb_err = -EIO; in i2c_w()
523 if (gspca_dev->usb_err < 0) in i2c_w_vector()
526 len -= 8; in i2c_w_vector()
537 switch (sd->sensor) { in setbrightness()
544 i2cOV[1] = sensor_data[sd->sensor].sensor_addr; in setbrightness()
545 i2cOV[3] = sd->brightness->val; in setbrightness()
557 if (sd->sensor == SENSOR_PAS106) { in setbrightness()
562 if (sd->brightness->val < 127) { in setbrightness()
565 /* set reg 0x0c, offset */ in setbrightness()
566 i2cpbright[4] = 127 - sd->brightness->val; in setbrightness()
568 i2cpbright[4] = sd->brightness->val - 127; in setbrightness()
582 u8 gain = gspca_dev->gain->val; in setgain() local
584 switch (sd->sensor) { in setgain()
589 i2c[3] = 0x3f - gain; in setgain()
590 i2c[4] = 0x3f - gain; in setgain()
591 i2c[5] = 0x3f - gain; in setgain()
601 i2c[4] = 255 - gain; in setgain()
608 gain = 255 - gain; in setgain()
610 i2c[3] |= (gain & 0x80) >> 7; in setgain()
611 i2c[3] |= (gain & 0x40) >> 5; in setgain()
612 i2c[3] |= (gain & 0x20) >> 3; in setgain()
613 i2c[3] |= (gain & 0x10) >> 1; in setgain()
614 i2c[3] |= (gain & 0x08) << 1; in setgain()
615 i2c[3] |= (gain & 0x04) << 3; in setgain()
616 i2c[3] |= (gain & 0x02) << 5; in setgain()
617 i2c[3] |= (gain & 0x01) << 7; in setgain()
626 * The ov7630's gain is weird, at 32 the gain drops to the in setgain()
627 * same level as at 16, so skip 32-47 (of the 0-63 scale). in setgain()
629 if (sd->sensor == SENSOR_OV7630 && gain >= 32) in setgain()
630 gain += 16; in setgain()
632 i2c[1] = sensor_data[sd->sensor].sensor_addr; in setgain()
633 i2c[3] = gain; in setgain()
647 if (sd->sensor == SENSOR_PAS106) { in setgain()
654 i2cpgain[3] = gain; in setgain()
655 i2cpcolorgain[3] = gain >> 1; in setgain()
656 i2cpcolorgain[4] = gain >> 1; in setgain()
657 i2cpcolorgain[5] = gain >> 1; in setgain()
658 i2cpcolorgain[6] = gain >> 1; in setgain()
666 if (sd->bridge == BRIDGE_103) { in setgain()
667 u8 buf[3] = { gain, gain, gain }; /* R, G, B */ in setgain()
671 buf[0] = gain << 4 | gain; /* Red and blue */ in setgain()
672 buf[1] = gain; /* Green */ in setgain()
682 switch (sd->sensor) { in setexposure()
687 u16 reg = gspca_dev->exposure->val; in setexposure()
699 u8 reg = gspca_dev->exposure->val; in setexposure()
718 The code maps our 0 - 510 ms exposure ctrl to these 2 in setexposure()
730 if (sd->sensor == SENSOR_OV6650) { in setexposure()
736 reg11 = (15 * gspca_dev->exposure->val + 999) / 1000; in setexposure()
745 if (gspca_dev->pixfmt.width == 640 && reg11 < 4) in setexposure()
748 /* frame exposure time in ms = 1000 * reg11 / 30 -> in setexposure()
749 reg10 = (gspca_dev->exposure->val / 2) * reg10_max in setexposure()
751 reg10 = (gspca_dev->exposure->val * 15 * reg10_max) in setexposure()
758 if (gspca_dev->autogain->val && reg10 < 10) in setexposure()
764 i2c[1] = sensor_data[sd->sensor].sensor_addr; in setexposure()
766 i2c[4] |= reg11 - 1; in setexposure()
769 if (sd->reg11 == reg11) in setexposure()
773 if (gspca_dev->usb_err == 0) in setexposure()
774 sd->reg11 = reg11; in setexposure()
796 if (gspca_dev->exposure->val < 200) { in setexposure()
797 i2cpexpo[3] = 255 - (gspca_dev->exposure->val * 255) in setexposure()
801 /* The PAS202's exposure control goes from 0 - 4095, in setexposure()
803 our 200-1023 to 500-4095 */ in setexposure()
804 framerate_ctrl = (gspca_dev->exposure->val - 200) in setexposure()
826 if (gspca_dev->exposure->val < 150) { in setexposure()
827 i2cpexpo[3] = 150 - gspca_dev->exposure->val; in setexposure()
830 /* The PAS106's exposure control goes from 0 - 4095, in setexposure()
832 our 150-1023 to 300-4095 */ in setexposure()
833 framerate_ctrl = (gspca_dev->exposure->val - 150) in setexposure()
853 if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630) { in setfreq()
857 0x4f / 0x8a -> (30 fps -> 25 fps), 0x00 -> no adjustment */ in setfreq()
859 switch (sd->plfreq->val) { in setfreq()
866 i2c[3] = (sd->sensor == SENSOR_OV6650) in setfreq()
870 i2c[1] = sensor_data[sd->sensor].sensor_addr; in setfreq()
880 avg_lum = atomic_read(&sd->avg_lum); in do_autogain()
881 if (avg_lum == -1) in do_autogain()
884 if (sd->autogain_ignore_frames > 0) { in do_autogain()
885 sd->autogain_ignore_frames--; in do_autogain()
891 if (sensor_data[sd->sensor].flags & F_SIF) { in do_autogain()
900 if (sd->brightness) in do_autogain()
901 desired_avg_lum = sd->brightness->val * desired_avg_lum / 127; in do_autogain()
903 if (gspca_dev->exposure->maximum < 500) { in do_autogain()
906 sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES; in do_autogain()
908 int gain_knee = (s32)gspca_dev->gain->maximum * 9 / 10; in do_autogain()
910 deadzone, gain_knee, sd->exposure_knee)) in do_autogain()
911 sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES; in do_autogain()
923 if (gspca_dev->usb_buf[0] != 0x10) in sd_config()
924 return -ENODEV; in sd_config()
927 sd->sensor = id->driver_info >> 8; in sd_config()
928 sd->bridge = id->driver_info & 0xff; in sd_config()
930 cam = &gspca_dev->cam; in sd_config()
931 if (!(sensor_data[sd->sensor].flags & F_SIF)) { in sd_config()
932 cam->cam_mode = vga_mode; in sd_config()
933 cam->nmodes = ARRAY_SIZE(vga_mode); in sd_config()
935 cam->cam_mode = sif_mode; in sd_config()
936 cam->nmodes = ARRAY_SIZE(sif_mode); in sd_config()
938 cam->npkt = 36; /* 36 packets per ISOC message */ in sd_config()
950 return gspca_dev->usb_err; in sd_init()
956 container_of(ctrl->handler, struct gspca_dev, ctrl_handler); in sd_s_ctrl()
959 gspca_dev->usb_err = 0; in sd_s_ctrl()
961 if (ctrl->id == V4L2_CID_AUTOGAIN && ctrl->is_new && ctrl->val) { in sd_s_ctrl()
963 we are on a valid point of the autogain gain / in sd_s_ctrl()
966 gspca_dev->gain->val = gspca_dev->gain->default_value; in sd_s_ctrl()
967 gspca_dev->exposure->val = gspca_dev->exposure->default_value; in sd_s_ctrl()
968 sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES; in sd_s_ctrl()
971 if (!gspca_dev->streaming) in sd_s_ctrl()
974 switch (ctrl->id) { in sd_s_ctrl()
979 if (gspca_dev->exposure->is_new || (ctrl->is_new && ctrl->val)) in sd_s_ctrl()
981 if (gspca_dev->gain->is_new || (ctrl->is_new && ctrl->val)) in sd_s_ctrl()
988 return -EINVAL; in sd_s_ctrl()
990 return gspca_dev->usb_err; in sd_s_ctrl()
1001 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler; in sd_init_controls()
1003 gspca_dev->vdev.ctrl_handler = hdl; in sd_init_controls()
1006 if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630 || in sd_init_controls()
1007 sd->sensor == SENSOR_PAS106 || sd->sensor == SENSOR_PAS202) in sd_init_controls()
1008 sd->brightness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, in sd_init_controls()
1011 /* Gain range is sensor dependent */ in sd_init_controls()
1012 switch (sd->sensor) { in sd_init_controls()
1016 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, in sd_init_controls()
1020 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, in sd_init_controls()
1024 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, in sd_init_controls()
1030 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, in sd_init_controls()
1034 if (sd->bridge == BRIDGE_103) { in sd_init_controls()
1035 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, in sd_init_controls()
1038 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, in sd_init_controls()
1044 switch (sd->sensor) { in sd_init_controls()
1046 gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, in sd_init_controls()
1048 sd->exposure_knee = 964; in sd_init_controls()
1054 gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, in sd_init_controls()
1056 sd->exposure_knee = 200; in sd_init_controls()
1060 gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, in sd_init_controls()
1065 if (gspca_dev->exposure) { in sd_init_controls()
1066 gspca_dev->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, in sd_init_controls()
1070 if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630) in sd_init_controls()
1071 sd->plfreq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops, in sd_init_controls()
1076 if (hdl->error) { in sd_init_controls()
1078 return hdl->error; in sd_init_controls()
1081 if (gspca_dev->autogain) in sd_init_controls()
1082 v4l2_ctrl_auto_cluster(3, &gspca_dev->autogain, 0, false); in sd_init_controls()
1087 /* -- start the camera -- */
1091 struct cam *cam = &gspca_dev->cam; in sd_start()
1095 mode = cam->cam_mode[gspca_dev->curr_mode].priv & 0x07; in sd_start()
1096 /* Copy registers 0x01 - 0x19 from the template */ in sd_start()
1097 memcpy(&regs[0x01], sensor_data[sd->sensor].bridge_init, 0x19); in sd_start()
1101 /* Set bridge gain to 1.0 */ in sd_start()
1102 if (sd->bridge == BRIDGE_103) { in sd_start()
1112 if (sensor_data[sd->sensor].flags & F_SIF) { in sd_start()
1115 regs[0x1c] = 0x02; /* AE H-start 64 */ in sd_start()
1116 regs[0x1d] = 0x02; /* AE V-start 64 */ in sd_start()
1117 regs[0x1e] = 0x09; /* AE H-end 288 */ in sd_start()
1118 regs[0x1f] = 0x07; /* AE V-end 224 */ in sd_start()
1122 regs[0x1c] = 0x05; /* AE H-start 160 */ in sd_start()
1123 regs[0x1d] = 0x03; /* AE V-start 96 */ in sd_start()
1124 regs[0x1e] = 0x0f; /* AE H-end 480 */ in sd_start()
1125 regs[0x1f] = 0x0c; /* AE V-end 384 */ in sd_start()
1134 switch (sd->sensor) { in sd_start()
1147 if (sd->bridge == BRIDGE_103) { in sd_start()
1155 if (sd->bridge == BRIDGE_103) in sd_start()
1160 if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_RAW) in sd_start()
1164 if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_REDUCED_SIF) { in sd_start()
1177 (sd->bridge == BRIDGE_103) ? 0x30 : 0x1f); in sd_start()
1180 i2c_w_vector(gspca_dev, sensor_data[sd->sensor].sensor_init, in sd_start()
1181 sensor_data[sd->sensor].sensor_init_size); in sd_start()
1184 switch (sd->sensor) { in sd_start()
1188 /* clockdiv from 4 to 3 (7.5 -> 10 fps) when in low res mode */ in sd_start()
1196 if (sd->bridge == BRIDGE_103) { in sd_start()
1203 /* H_size V_size 0x28, 0x1e -> 640x480. 0x16, 0x12 -> 352x288 */ in sd_start()
1214 /*MCKSIZE ->3 */ /*fixme: not ov7630*/ in sd_start()
1224 sd->reg11 = -1; in sd_start()
1231 sd->frames_to_drop = 0; in sd_start()
1232 sd->autogain_ignore_frames = 0; in sd_start()
1233 gspca_dev->exp_too_high_cnt = 0; in sd_start()
1234 gspca_dev->exp_too_low_cnt = 0; in sd_start()
1235 atomic_set(&sd->avg_lum, -1); in sd_start()
1236 return gspca_dev->usb_err; in sd_start()
1247 int i, header_size = (sd->bridge == BRIDGE_103) ? 18 : 12; in find_sof()
1253 * (xx) (idem - extra byte for sn9c103) in find_sof()
1259 switch (sd->header_read) { in find_sof()
1262 sd->header_read++; in find_sof()
1266 sd->header_read++; in find_sof()
1268 sd->header_read = 0; in find_sof()
1272 sd->header_read++; in find_sof()
1274 sd->header_read = 0; in find_sof()
1278 sd->header_read++; in find_sof()
1280 sd->header_read = 1; in find_sof()
1282 sd->header_read = 0; in find_sof()
1286 sd->header_read++; in find_sof()
1288 sd->header_read = 1; in find_sof()
1290 sd->header_read = 0; in find_sof()
1294 sd->header_read++; in find_sof()
1296 sd->header_read = 1; in find_sof()
1298 sd->header_read = 0; in find_sof()
1301 sd->header[sd->header_read - 6] = data[i]; in find_sof()
1302 sd->header_read++; in find_sof()
1303 if (sd->header_read == header_size) { in find_sof()
1304 sd->header_read = 0; in find_sof()
1318 struct cam *cam = &gspca_dev->cam; in sd_pkt_scan()
1323 if (sd->bridge == BRIDGE_103) { in sd_pkt_scan()
1331 len_after_sof = len - (sof - data); in sd_pkt_scan()
1332 len = (sof - data) - fr_h_sz; in sd_pkt_scan()
1337 if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_RAW) { in sd_pkt_scan()
1341 int size = cam->cam_mode[gspca_dev->curr_mode].sizeimage; in sd_pkt_scan()
1343 used = gspca_dev->image_len; in sd_pkt_scan()
1345 len = size - used; in sd_pkt_scan()
1351 int lum = sd->header[lum_offset] + in sd_pkt_scan()
1352 (sd->header[lum_offset + 1] << 8); in sd_pkt_scan()
1361 if (lum == 0 && sd->prev_avg_lum != 0) { in sd_pkt_scan()
1362 lum = -1; in sd_pkt_scan()
1363 sd->frames_to_drop = 2; in sd_pkt_scan()
1364 sd->prev_avg_lum = 0; in sd_pkt_scan()
1366 sd->prev_avg_lum = lum; in sd_pkt_scan()
1367 atomic_set(&sd->avg_lum, lum); in sd_pkt_scan()
1369 if (sd->frames_to_drop) in sd_pkt_scan()
1370 sd->frames_to_drop--; in sd_pkt_scan()
1383 int ret = -EINVAL; in sd_int_pkt_scan()
1386 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1); in sd_int_pkt_scan()
1387 input_sync(gspca_dev->input_dev); in sd_int_pkt_scan()
1388 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); in sd_int_pkt_scan()
1389 input_sync(gspca_dev->input_dev); in sd_int_pkt_scan()
1397 /* sub-driver description */
1412 /* -- module initialisation -- */
1449 /* -- device connect -- */