Lines Matching +full:cam +full:- +full:if
1 // SPDX-License-Identifier: GPL-2.0-or-later
19 #define MAX_MODES ((READ_REQ_SIZE - 6) / 4)
67 if (gspca_dev->usb_err < 0) in se401_write_req()
70 err = usb_control_msg(gspca_dev->dev, in se401_write_req()
71 usb_sndctrlpipe(gspca_dev->dev, 0), req, in se401_write_req()
74 if (err < 0) { in se401_write_req()
75 if (!silent) in se401_write_req()
78 gspca_dev->usb_err = err; in se401_write_req()
86 if (gspca_dev->usb_err < 0) in se401_read_req()
89 if (USB_BUF_SZ < READ_REQ_SIZE) { in se401_read_req()
91 gspca_dev->usb_err = -ENOBUFS; in se401_read_req()
95 err = usb_control_msg(gspca_dev->dev, in se401_read_req()
96 usb_rcvctrlpipe(gspca_dev->dev, 0), req, in se401_read_req()
98 0, 0, gspca_dev->usb_buf, READ_REQ_SIZE, 1000); in se401_read_req()
99 if (err < 0) { in se401_read_req()
100 if (!silent) in se401_read_req()
103 gspca_dev->usb_err = err; in se401_read_req()
108 memset(gspca_dev->usb_buf, 0, READ_REQ_SIZE); in se401_read_req()
117 if (gspca_dev->usb_err < 0) in se401_set_feature()
120 err = usb_control_msg(gspca_dev->dev, in se401_set_feature()
121 usb_sndctrlpipe(gspca_dev->dev, 0), in se401_set_feature()
125 if (err < 0) { in se401_set_feature()
128 gspca_dev->usb_err = err; in se401_set_feature()
136 if (gspca_dev->usb_err < 0) in se401_get_feature()
137 return gspca_dev->usb_err; in se401_get_feature()
139 if (USB_BUF_SZ < 2) { in se401_get_feature()
141 gspca_dev->usb_err = -ENOBUFS; in se401_get_feature()
142 return gspca_dev->usb_err; in se401_get_feature()
145 err = usb_control_msg(gspca_dev->dev, in se401_get_feature()
146 usb_rcvctrlpipe(gspca_dev->dev, 0), in se401_get_feature()
149 0, selector, gspca_dev->usb_buf, 2, 1000); in se401_get_feature()
150 if (err < 0) { in se401_get_feature()
153 gspca_dev->usb_err = err; in se401_get_feature()
156 return gspca_dev->usb_buf[0] | (gspca_dev->usb_buf[1] << 8); in se401_get_feature()
161 /* HDG: this does not seem to do anything on my cam */ in setbrightness()
167 u16 gain = 63 - val; in setgain()
186 avoiding underexposed frames getting send out, if one sneaks in setexposure()
188 sd->expo_change_state = EXPO_CHANGED; in setexposure()
190 if (freq == V4L2_CID_POWER_LINE_FREQUENCY_50HZ) in setexposure()
191 integration = integration - integration % 106667; in setexposure()
192 if (freq == V4L2_CID_POWER_LINE_FREQUENCY_60HZ) in setexposure()
193 integration = integration - integration % 88889; in setexposure()
211 struct cam *cam = &gspca_dev->cam; in sd_config() local
212 u8 *cd = gspca_dev->usb_buf; in sd_config()
218 if (gspca_dev->usb_err) { in sd_config()
221 usb_reset_device(gspca_dev->dev); in sd_config()
222 gspca_dev->usb_err = 0; in sd_config()
228 if (gspca_dev->usb_err) in sd_config()
229 return gspca_dev->usb_err; in sd_config()
231 if (cd[1] != 0x41) { in sd_config()
233 return -ENODEV; in sd_config()
236 if (!(cd[2] & SE401_FORMAT_BAYER)) { in sd_config()
238 return -ENODEV; in sd_config()
241 if (cd[3]) in sd_config()
245 if (n > MAX_MODES) { in sd_config()
247 return -ENODEV; in sd_config()
256 sd->fmts[i].width = widths[i]; in sd_config()
257 sd->fmts[i].height = heights[i]; in sd_config()
258 sd->fmts[i].field = V4L2_FIELD_NONE; in sd_config()
259 sd->fmts[i].colorspace = V4L2_COLORSPACE_SRGB; in sd_config()
260 sd->fmts[i].priv = 1; in sd_config()
264 if (widths[j] / 2 == widths[i] && in sd_config()
266 sd->fmts[i].priv = 2; in sd_config()
270 /* 1/16th if available too is better then 1/4th, because in sd_config()
273 if (widths[j] / 4 == widths[i] && in sd_config()
275 sd->fmts[i].priv = 4; in sd_config()
280 if (sd->fmts[i].priv == 1) { in sd_config()
282 sd->fmts[i].pixelformat = V4L2_PIX_FMT_SBGGR8; in sd_config()
283 sd->fmts[i].bytesperline = widths[i]; in sd_config()
284 sd->fmts[i].sizeimage = widths[i] * heights[i]; in sd_config()
289 sd->fmts[i].pixelformat = V4L2_PIX_FMT_SE401; in sd_config()
290 sd->fmts[i].bytesperline = 0; in sd_config()
291 sd->fmts[i].sizeimage = widths[i] * heights[i] * 3; in sd_config()
294 sd->fmts[i].priv * sd->fmts[i].priv); in sd_config()
298 cam->cam_mode = sd->fmts; in sd_config()
299 cam->nmodes = n; in sd_config()
300 cam->bulk = 1; in sd_config()
301 cam->bulk_size = BULK_SIZE; in sd_config()
302 cam->bulk_nurbs = 4; in sd_config()
303 sd->resetlevel = 0x2d; /* Set initial resetlevel */ in sd_config()
305 /* See if the camera supports brightness */ in sd_config()
307 sd->has_brightness = !!gspca_dev->usb_err; in sd_config()
308 gspca_dev->usb_err = 0; in sd_config()
322 gspca_dev->alt = 1; /* Ignore the bogus isoc alt settings */ in sd_isoc_init()
324 return gspca_dev->usb_err; in sd_isoc_init()
327 /* -- start the camera -- */
331 int mult = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; in sd_start()
335 if (gspca_dev->usb_err) { in sd_start()
338 usb_reset_device(gspca_dev->dev); in sd_start()
339 gspca_dev->usb_err = 0; in sd_start()
348 gspca_dev->pixfmt.width * mult, 0); in sd_start()
350 gspca_dev->pixfmt.height * mult, 0); in sd_start()
367 se401_set_feature(gspca_dev, HV7131_REG_ARLV, sd->resetlevel); in sd_start()
369 sd->packet_read = 0; in sd_start()
370 sd->pixels_read = 0; in sd_start()
371 sd->restart_stream = 0; in sd_start()
372 sd->resetlevel_frame_count = 0; in sd_start()
373 sd->resetlevel_adjust_dir = 0; in sd_start()
374 sd->expo_change_state = EXPO_NO_CHANGE; in sd_start()
378 return gspca_dev->usb_err; in sd_start()
394 /* Restart the stream if requested do so by pkt_scan */ in sd_dq_callback()
395 if (sd->restart_stream) { in sd_dq_callback()
398 sd->restart_stream = 0; in sd_dq_callback()
404 sd->resetlevel_frame_count++; in sd_dq_callback()
405 if (sd->resetlevel_frame_count < 20) in sd_dq_callback()
408 /* For some reason this normally read-only register doesn't get reset in sd_dq_callback()
420 oldreset = sd->resetlevel; in sd_dq_callback()
421 if (alrc > 10) { in sd_dq_callback()
422 while (alrc >= 10 && sd->resetlevel < 63) { in sd_dq_callback()
423 sd->resetlevel++; in sd_dq_callback()
426 } else if (ahrc > 20) { in sd_dq_callback()
427 while (ahrc >= 20 && sd->resetlevel > 0) { in sd_dq_callback()
428 sd->resetlevel--; in sd_dq_callback()
432 /* Detect ping-pong-ing and halve adjustment to avoid overshoot */ in sd_dq_callback()
433 if (sd->resetlevel > oldreset) in sd_dq_callback()
436 adjust_dir = -1; in sd_dq_callback()
437 if (sd->resetlevel_adjust_dir && in sd_dq_callback()
438 sd->resetlevel_adjust_dir != adjust_dir) in sd_dq_callback()
439 sd->resetlevel = oldreset + (sd->resetlevel - oldreset) / 2; in sd_dq_callback()
441 if (sd->resetlevel != oldreset) { in sd_dq_callback()
442 sd->resetlevel_adjust_dir = adjust_dir; in sd_dq_callback()
443 se401_set_feature(gspca_dev, HV7131_REG_ARLV, sd->resetlevel); in sd_dq_callback()
446 sd->resetlevel_frame_count = 0; in sd_dq_callback()
453 switch (sd->expo_change_state) { in sd_complete_frame()
457 sd->expo_change_state = EXPO_DROP_FRAME; in sd_complete_frame()
462 gspca_dev->last_packet_type = DISCARD_PACKET; in sd_complete_frame()
463 sd->expo_change_state = EXPO_NO_CHANGE; in sd_complete_frame()
474 int imagesize = gspca_dev->pixfmt.width * gspca_dev->pixfmt.height; in sd_pkt_scan_janggu()
477 if (sd->restart_stream) in sd_pkt_scan_janggu()
481 if (gspca_dev->last_packet_type == LAST_PACKET && len == 1024) { in sd_pkt_scan_janggu()
482 gspca_dev->last_packet_type = DISCARD_PACKET; in sd_pkt_scan_janggu()
488 /* Read header if not already be present from prev bulk pkt */ in sd_pkt_scan_janggu()
489 if (sd->packet_read < 4) { in sd_pkt_scan_janggu()
490 count = 4 - sd->packet_read; in sd_pkt_scan_janggu()
491 if (count > len - i) in sd_pkt_scan_janggu()
492 count = len - i; in sd_pkt_scan_janggu()
493 memcpy(&sd->packet[sd->packet_read], &data[i], count); in sd_pkt_scan_janggu()
494 sd->packet_read += count; in sd_pkt_scan_janggu()
496 if (sd->packet_read < 4) in sd_pkt_scan_janggu()
499 bits = sd->packet[3] + (sd->packet[2] << 8); in sd_pkt_scan_janggu()
500 pixels = sd->packet[1] + ((sd->packet[0] & 0x3f) << 8); in sd_pkt_scan_janggu()
501 info = (sd->packet[0] & 0xc0) >> 6; in sd_pkt_scan_janggu()
504 if (plen > 1024) { in sd_pkt_scan_janggu()
509 if (info == 3) { in sd_pkt_scan_janggu()
515 count = plen - sd->packet_read; in sd_pkt_scan_janggu()
516 if (count > len - i) in sd_pkt_scan_janggu()
517 count = len - i; in sd_pkt_scan_janggu()
518 memcpy(&sd->packet[sd->packet_read], &data[i], count); in sd_pkt_scan_janggu()
519 sd->packet_read += count; in sd_pkt_scan_janggu()
521 if (sd->packet_read < plen) in sd_pkt_scan_janggu()
524 sd->pixels_read += pixels; in sd_pkt_scan_janggu()
525 sd->packet_read = 0; in sd_pkt_scan_janggu()
529 gspca_frame_add(gspca_dev, INTER_PACKET, sd->packet, in sd_pkt_scan_janggu()
533 if (sd->pixels_read != imagesize) { in sd_pkt_scan_janggu()
535 sd->pixels_read, imagesize); in sd_pkt_scan_janggu()
538 sd_complete_frame(gspca_dev, sd->packet, plen); in sd_pkt_scan_janggu()
541 gspca_frame_add(gspca_dev, FIRST_PACKET, sd->packet, in sd_pkt_scan_janggu()
543 sd->pixels_read = pixels; in sd_pkt_scan_janggu()
550 sd->restart_stream = 1; in sd_pkt_scan_janggu()
559 struct cam *cam = &gspca_dev->cam; in sd_pkt_scan_bayer() local
560 int imagesize = cam->cam_mode[gspca_dev->curr_mode].sizeimage; in sd_pkt_scan_bayer()
562 if (gspca_dev->image_len == 0) { in sd_pkt_scan_bayer()
567 if (gspca_dev->image_len + len >= imagesize) { in sd_pkt_scan_bayer()
577 int mult = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; in sd_pkt_scan()
579 if (len == 0) in sd_pkt_scan()
582 if (mult == 1) /* mult == 1 means raw bayer */ in sd_pkt_scan()
588 #if IS_ENABLED(CONFIG_INPUT)
594 if (len != 2) in sd_int_pkt_scan()
595 return -EINVAL; in sd_int_pkt_scan()
603 return -EINVAL; in sd_int_pkt_scan()
605 if (sd->button_state != state) { in sd_int_pkt_scan()
606 input_report_key(gspca_dev->input_dev, KEY_CAMERA, state); in sd_int_pkt_scan()
607 input_sync(gspca_dev->input_dev); in sd_int_pkt_scan()
608 sd->button_state = state; in sd_int_pkt_scan()
618 container_of(ctrl->handler, struct gspca_dev, ctrl_handler); in sd_s_ctrl()
621 gspca_dev->usb_err = 0; in sd_s_ctrl()
623 if (!gspca_dev->streaming) in sd_s_ctrl()
626 switch (ctrl->id) { in sd_s_ctrl()
628 setbrightness(gspca_dev, ctrl->val); in sd_s_ctrl()
631 setgain(gspca_dev, ctrl->val); in sd_s_ctrl()
634 setexposure(gspca_dev, ctrl->val, sd->freq->val); in sd_s_ctrl()
637 return gspca_dev->usb_err; in sd_s_ctrl()
647 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler; in sd_init_controls()
649 gspca_dev->vdev.ctrl_handler = hdl; in sd_init_controls()
651 if (sd->has_brightness) in sd_init_controls()
657 sd->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, in sd_init_controls()
659 sd->freq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops, in sd_init_controls()
663 if (hdl->error) { in sd_init_controls()
665 return hdl->error; in sd_init_controls()
667 v4l2_ctrl_cluster(2, &sd->exposure); in sd_init_controls()
671 /* sub-driver description */
682 #if IS_ENABLED(CONFIG_INPUT)
687 /* -- module initialisation -- */
698 /* -- device connect -- */