Lines Matching +full:cam +full:- +full:0
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()
73 value, 0, NULL, 0, 1000); in se401_write_req()
74 if (err < 0) { 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()
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()
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()
124 param, selector, NULL, 0, 1000); 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()
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()
162 se401_write_req(gspca_dev, SE401_REQ_SET_BRT, val, 0); in setbrightness()
167 u16 gain = 63 - val; in setgain()
188 sd->expo_change_state = EXPO_CHANGED; in setexposure()
191 integration = integration - integration % 106667; 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()
223 se401_read_req(gspca_dev, SE401_REQ_GET_CAMERA_DESCRIPTOR, 0); in sd_config()
227 se401_write_req(gspca_dev, SE401_REQ_LED_CONTROL, 0, 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()
238 return -ENODEV; in sd_config()
247 return -ENODEV; in sd_config()
250 for (i = 0; i < n ; i++) { in sd_config()
251 widths[i] = cd[6 + i * 4 + 0] | (cd[6 + i * 4 + 1] << 8); in sd_config()
255 for (i = 0; i < n ; i++) { 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()
263 for (j = 0; j < n; j++) { in sd_config()
266 sd->fmts[i].priv = 2; in sd_config()
272 for (j = 0; j < n; j++) { 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()
307 sd->has_brightness = !!gspca_dev->usb_err; in sd_config()
308 gspca_dev->usb_err = 0; in sd_config()
310 return 0; in sd_config()
316 return 0; in sd_init()
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()
332 int mode = 0; 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()
340 se401_write_req(gspca_dev, SE401_REQ_CAMERA_POWER, 1, 0); in sd_start()
342 se401_write_req(gspca_dev, SE401_REQ_LED_CONTROL, 1, 0); in sd_start()
344 se401_set_feature(gspca_dev, HV7131_REG_MODE_B, 0x05); in sd_start()
348 gspca_dev->pixfmt.width * mult, 0); in sd_start()
350 gspca_dev->pixfmt.height * mult, 0); in sd_start()
354 * SE401_FORMAT_BAYER, 0); in sd_start()
359 mode = 0x03; break; in sd_start()
363 mode = (SE401_QUANT_FACT << 4) | 0x02; break; 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()
376 se401_write_req(gspca_dev, SE401_REQ_START_CONTINUOUS_CAPTURE, 0, 0); in sd_start()
378 return gspca_dev->usb_err; in sd_start()
383 se401_write_req(gspca_dev, SE401_REQ_STOP_CONTINUOUS_CAPTURE, 0, 0); in sd_stopN()
384 se401_write_req(gspca_dev, SE401_REQ_LED_CONTROL, 0, 0); in sd_stopN()
385 se401_write_req(gspca_dev, SE401_REQ_CAMERA_POWER, 0, 0); in sd_stopN()
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()
422 while (alrc >= 10 && sd->resetlevel < 63) { in sd_dq_callback()
423 sd->resetlevel++; 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()
486 i = 0; 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()
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()
528 case 0: /* Frame data */ 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()
551 /* Give userspace a 0 bytes frame, so our dq callback gets in sd_pkt_scan_janggu()
553 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0); in sd_pkt_scan_janggu()
554 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0); 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()
595 return -EINVAL; in sd_int_pkt_scan()
597 switch (data[0]) { in sd_int_pkt_scan()
598 case 0: in sd_int_pkt_scan()
600 state = data[0]; 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()
611 return 0; 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()
624 return 0; 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()
653 V4L2_CID_BRIGHTNESS, 0, 255, 1, 15); in sd_init_controls()
656 V4L2_CID_GAIN, 0, 50, 1, 25); in sd_init_controls()
657 sd->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, in sd_init_controls()
658 V4L2_CID_EXPOSURE, 0, 32767, 1, 15000); in sd_init_controls()
659 sd->freq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops, in sd_init_controls()
661 V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0, 0); 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()
668 return 0; in sd_init_controls()
671 /* sub-driver description */
687 /* -- module initialisation -- */
689 {USB_DEVICE(0x03e8, 0x0004)}, /* Endpoints/Aox SE401 */
690 {USB_DEVICE(0x0471, 0x030b)}, /* Philips PCVC665K */
691 {USB_DEVICE(0x047d, 0x5001)}, /* Kensington 67014 */
692 {USB_DEVICE(0x047d, 0x5002)}, /* Kensington 6701(5/7) */
693 {USB_DEVICE(0x047d, 0x5003)}, /* Kensington 67016 */
698 /* -- device connect -- */
708 return 0; in sd_pre_reset()
713 return 0; in sd_post_reset()