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

1 // SPDX-License-Identifier: GPL-2.0-or-later
19 #define MAX_MODES ((READ_REQ_SIZE - 6) / 4)
42 struct sd { struct
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()
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()
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()
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()
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()
167 u16 gain = 63 - val; in setgain()
179 struct sd *sd = (struct sd *) gspca_dev; in setexposure() local
188 sd->expo_change_state = EXPO_CHANGED; in setexposure()
191 integration = integration - integration % 106667; in setexposure()
193 integration = integration - integration % 88889; in setexposure()
210 struct sd *sd = (struct sd *)gspca_dev; in sd_config() local
211 struct cam *cam = &gspca_dev->cam; in sd_config()
212 u8 *cd = gspca_dev->usb_buf; in sd_config()
217 se401_read_req(gspca_dev, SE401_REQ_GET_CAMERA_DESCRIPTOR, 1); 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()
238 return -ENODEV; in sd_config()
247 return -ENODEV; in sd_config()
251 widths[i] = cd[6 + i * 4 + 0] | (cd[6 + i * 4 + 1] << 8); 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()
262 /* janggu compression only works for 1/4th or 1/16th res */ 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()
275 sd->fmts[i].priv = 4; in sd_config()
280 if (sd->fmts[i].priv == 1) { in sd_config()
281 /* Not a 1/4th or 1/16th res, use bayer */ 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()
292 pr_info("Frame size: %dx%d 1/%dth janggu\n", 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()
306 se401_read_req(gspca_dev, SE401_REQ_GET_BRT, 1); 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 -- */
330 struct sd *sd = (struct sd *)gspca_dev; in sd_start() local
331 int mult = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; in sd_start()
334 se401_write_req(gspca_dev, SE401_REQ_CAMERA_POWER, 1, 1); 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()
348 gspca_dev->pixfmt.width * mult, 0); in sd_start()
350 gspca_dev->pixfmt.height * mult, 0); in sd_start()
358 case 1: /* Raw bayer */ in sd_start()
360 case 2: /* 1/4th janggu */ in sd_start()
362 case 4: /* 1/16th janggu */ 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()
390 struct sd *sd = (struct sd *)gspca_dev; in sd_dq_callback() local
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()
434 adjust_dir = 1; 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()
451 struct sd *sd = (struct sd *)gspca_dev; in sd_complete_frame() local
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()
473 struct sd *sd = (struct sd *)gspca_dev; in sd_pkt_scan_janggu() local
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()
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()
502 plen = ((bits + 47) >> 4) << 1; 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()
532 case 1: /* EOF */ 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()
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()
582 if (mult == 1) /* mult == 1 means raw bayer */ in sd_pkt_scan()
591 struct sd *sd = (struct sd *)gspca_dev; in sd_int_pkt_scan() local
595 return -EINVAL; in sd_int_pkt_scan()
599 case 1: 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()
619 struct sd *sd = (struct sd *)gspca_dev; in sd_s_ctrl() local
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()
646 struct sd *sd = (struct sd *)gspca_dev; in sd_init_controls() local
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()
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 */
687 /* -- module initialisation -- */
698 /* -- device connect -- */
702 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), in sd_probe()