Lines Matching +full:video +full:- +full:firmware

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * s2255drv.c - a driver for the Sensoray 2255 USB video capture device
5 * Copyright (C) 2007-2014 by Sensoray Company Inc.
8 * Some video buffer code based on vivi driver:
12 * attached to separate video decoders.
19 * -full size, color mode YUYV or YUV422P: 2 channels at once
20 * -full or half size Grey scale: all 4 channels at once
21 * -half size, color mode YUYV or YUV422P: all 4 channels at once
22 * -full size, color mode YUYV or YUV422P 1/2 frame rate: all 4 channels
27 #include <linux/firmware.h>
35 #include <media/videobuf2-v4l2.h>
36 #include <media/videobuf2-vmalloc.h>
37 #include <media/v4l2-common.h>
38 #include <media/v4l2-device.h>
39 #include <media/v4l2-ioctl.h>
40 #include <media/v4l2-ctrls.h>
41 #include <media/v4l2-event.h>
52 /* firmware query */
58 /* maximum time to wait for firmware to load (ms) */
114 /*-------------------------------------------------------
116 *-------------------------------------------------------*/
134 u32 format; /* input video format (NTSC, PAL) */
135 u32 scale; /* output video scale */
136 u32 color; /* output video color format */
169 /* for firmware loading, fw_state */
186 const struct firmware *fw;
203 /* 2255 video channel */
232 /* video status items */
240 int idx; /* channel number on device, 0-3 */
263 /* dsp firmware version (f2255usb.bin) */
280 /* buffer for one video frame */
282 /* common v4l buffer stuff -- must be first */
288 /* current cypress EEPROM firmware version */
292 /* Need DSP version 5+ for video status feature */
307 * = = s-video or = composite =
315 * channels 0-3 on 2255 are composite
316 * channels 0-1 on 2257 are composite, 2-3 are s-video
352 dev_err(dev, S2255_DRIVER_NAME " - " fmt, ##arg)
355 v4l2_dbg(level, debug, &dev->v4l2_dev, fmt, ## arg)
359 /* start video number */
360 static int video_nr = -1; /* /dev/videoN, -1 for autodetect */
366 MODULE_PARM_DESC(debug, "Debug level(0-100) default 0");
368 MODULE_PARM_DESC(video_nr, "start video minor(-1 default autodetect)");
370 MODULE_PARM_DESC(jpeg_enable, "Jpeg enable(1-on 0-off) default 1");
411 return (vc->std & V4L2_STD_525_60) ? in norm_maxw()
417 return (vc->std & V4L2_STD_525_60) ? in norm_maxh()
423 return (vc->std & V4L2_STD_525_60) ? in norm_minw()
429 return (vc->std & V4L2_STD_525_60) ? in norm_minh()
470 /* kickstarts the firmware loading. from probe
475 struct s2255_fw *data = dev->fw_data; in s2255_timer()
476 if (usb_submit_urb(data->fw_urb, GFP_ATOMIC) < 0) { in s2255_timer()
478 atomic_set(&data->fw_state, S2255_FW_FAILED); in s2255_timer()
479 /* wake up anything waiting for the firmware */ in s2255_timer()
480 wake_up(&data->wait_fw); in s2255_timer()
486 /* this loads the firmware asynchronously.
494 struct s2255_fw *data = urb->context; in s2255_fwchunk_complete()
495 struct usb_device *udev = urb->dev; in s2255_fwchunk_complete()
497 if (urb->status) { in s2255_fwchunk_complete()
498 dev_err(&udev->dev, "URB failed with status %d\n", urb->status); in s2255_fwchunk_complete()
499 atomic_set(&data->fw_state, S2255_FW_FAILED); in s2255_fwchunk_complete()
500 /* wake up anything waiting for the firmware */ in s2255_fwchunk_complete()
501 wake_up(&data->wait_fw); in s2255_fwchunk_complete()
504 if (data->fw_urb == NULL) { in s2255_fwchunk_complete()
505 s2255_dev_err(&udev->dev, "disconnected\n"); in s2255_fwchunk_complete()
506 atomic_set(&data->fw_state, S2255_FW_FAILED); in s2255_fwchunk_complete()
507 /* wake up anything waiting for the firmware */ in s2255_fwchunk_complete()
508 wake_up(&data->wait_fw); in s2255_fwchunk_complete()
514 upload the firmware in chunks in s2255_fwchunk_complete()
516 if (data->fw_loaded < data->fw_size) { in s2255_fwchunk_complete()
517 len = (data->fw_loaded + CHUNK_SIZE) > data->fw_size ? in s2255_fwchunk_complete()
518 data->fw_size % CHUNK_SIZE : CHUNK_SIZE; in s2255_fwchunk_complete()
521 memset(data->pfw_data, 0, CHUNK_SIZE); in s2255_fwchunk_complete()
523 memcpy(data->pfw_data, in s2255_fwchunk_complete()
524 (char *) data->fw->data + data->fw_loaded, len); in s2255_fwchunk_complete()
526 usb_fill_bulk_urb(data->fw_urb, udev, usb_sndbulkpipe(udev, 2), in s2255_fwchunk_complete()
527 data->pfw_data, CHUNK_SIZE, in s2255_fwchunk_complete()
529 if (usb_submit_urb(data->fw_urb, GFP_ATOMIC) < 0) { in s2255_fwchunk_complete()
530 dev_err(&udev->dev, "failed submit URB\n"); in s2255_fwchunk_complete()
531 atomic_set(&data->fw_state, S2255_FW_FAILED); in s2255_fwchunk_complete()
532 /* wake up anything waiting for the firmware */ in s2255_fwchunk_complete()
533 wake_up(&data->wait_fw); in s2255_fwchunk_complete()
536 data->fw_loaded += len; in s2255_fwchunk_complete()
538 atomic_set(&data->fw_state, S2255_FW_LOADED_DSPWAIT); in s2255_fwchunk_complete()
546 struct s2255_dev *dev = to_s2255_dev(vc->vdev.v4l2_dev); in s2255_got_frame()
549 spin_lock_irqsave(&vc->qlock, flags); in s2255_got_frame()
550 if (list_empty(&vc->buf_list)) { in s2255_got_frame()
552 spin_unlock_irqrestore(&vc->qlock, flags); in s2255_got_frame()
555 buf = list_entry(vc->buf_list.next, in s2255_got_frame()
557 list_del(&buf->list); in s2255_got_frame()
558 buf->vb.vb2_buf.timestamp = ktime_get_ns(); in s2255_got_frame()
559 buf->vb.field = vc->field; in s2255_got_frame()
560 buf->vb.sequence = vc->frame_count; in s2255_got_frame()
561 spin_unlock_irqrestore(&vc->qlock, flags); in s2255_got_frame()
565 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE); in s2255_got_frame()
573 if (-1 == formats[i].fourcc) in format_by_fourcc()
584 /* video buffer vmalloc implementation based partly on VIVI driver which is
586 * Mauro Carvalho Chehab <mchehab--a.t--infradead.org>
587 * Ted Walther <ted--a.t--enumera.com>
588 * John Sokol <sokol--a.t--videotechnology.com>
597 char *vbuf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0); in s2255_fillbuff()
599 struct s2255_dev *dev = vc->dev; in s2255_fillbuff()
603 last_frame = vc->last_frame; in s2255_fillbuff()
604 if (last_frame != -1) { in s2255_fillbuff()
606 (const char *)vc->buffer.frame[last_frame].lpvbits; in s2255_fillbuff()
607 switch (vc->fmt->fourcc) { in s2255_fillbuff()
611 vbuf, vc->width, in s2255_fillbuff()
612 vc->height, in s2255_fillbuff()
613 vc->fmt->fourcc); in s2255_fillbuff()
616 memcpy(vbuf, tmpbuf, vc->width * vc->height); in s2255_fillbuff()
620 vb2_set_plane_payload(&buf->vb.vb2_buf, 0, jpgsize); in s2255_fillbuff()
625 vc->width * vc->height * 2); in s2255_fillbuff()
630 vc->last_frame = -1; in s2255_fillbuff()
640 /* ------------------------------------------------------------------
642 ------------------------------------------------------------------*/
652 sizes[0] = vc->width * vc->height * (vc->fmt->depth >> 3); in queue_setup()
658 struct s2255_vc *vc = vb2_get_drv_priv(vb->vb2_queue); in buffer_prepare()
661 int w = vc->width; in buffer_prepare()
662 int h = vc->height; in buffer_prepare()
665 dprintk(vc->dev, 4, "%s\n", __func__); in buffer_prepare()
666 if (vc->fmt == NULL) in buffer_prepare()
667 return -EINVAL; in buffer_prepare()
673 dprintk(vc->dev, 4, "invalid buffer prepare\n"); in buffer_prepare()
674 return -EINVAL; in buffer_prepare()
676 size = w * h * (vc->fmt->depth >> 3); in buffer_prepare()
678 dprintk(vc->dev, 4, "invalid buffer prepare\n"); in buffer_prepare()
679 return -EINVAL; in buffer_prepare()
682 vb2_set_plane_payload(&buf->vb.vb2_buf, 0, size); in buffer_prepare()
690 struct s2255_vc *vc = vb2_get_drv_priv(vb->vb2_queue); in buffer_queue()
692 dprintk(vc->dev, 1, "%s\n", __func__); in buffer_queue()
693 spin_lock_irqsave(&vc->qlock, flags); in buffer_queue()
694 list_add_tail(&buf->list, &vc->buf_list); in buffer_queue()
695 spin_unlock_irqrestore(&vc->qlock, flags); in buffer_queue()
715 struct s2255_dev *dev = vc->dev; in vidioc_querycap()
717 strscpy(cap->driver, "s2255", sizeof(cap->driver)); in vidioc_querycap()
718 strscpy(cap->card, "s2255", sizeof(cap->card)); in vidioc_querycap()
719 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); in vidioc_querycap()
726 int index = f->index; in vidioc_enum_fmt_vid_cap()
729 return -EINVAL; in vidioc_enum_fmt_vid_cap()
732 return -EINVAL; in vidioc_enum_fmt_vid_cap()
733 f->pixelformat = formats[index].fourcc; in vidioc_enum_fmt_vid_cap()
741 int is_ntsc = vc->std & V4L2_STD_525_60; in vidioc_g_fmt_vid_cap()
743 f->fmt.pix.width = vc->width; in vidioc_g_fmt_vid_cap()
744 f->fmt.pix.height = vc->height; in vidioc_g_fmt_vid_cap()
745 if (f->fmt.pix.height >= in vidioc_g_fmt_vid_cap()
747 f->fmt.pix.field = V4L2_FIELD_INTERLACED; in vidioc_g_fmt_vid_cap()
749 f->fmt.pix.field = V4L2_FIELD_TOP; in vidioc_g_fmt_vid_cap()
750 f->fmt.pix.pixelformat = vc->fmt->fourcc; in vidioc_g_fmt_vid_cap()
751 f->fmt.pix.bytesperline = f->fmt.pix.width * (vc->fmt->depth >> 3); in vidioc_g_fmt_vid_cap()
752 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; in vidioc_g_fmt_vid_cap()
753 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; in vidioc_g_fmt_vid_cap()
763 int is_ntsc = vc->std & V4L2_STD_525_60; in vidioc_try_fmt_vid_cap()
765 fmt = format_by_fourcc(f->fmt.pix.pixelformat); in vidioc_try_fmt_vid_cap()
768 return -EINVAL; in vidioc_try_fmt_vid_cap()
770 dprintk(vc->dev, 50, "%s NTSC: %d suggested width: %d, height: %d\n", in vidioc_try_fmt_vid_cap()
771 __func__, is_ntsc, f->fmt.pix.width, f->fmt.pix.height); in vidioc_try_fmt_vid_cap()
774 if (f->fmt.pix.height >= NUM_LINES_1CIFS_NTSC * 2) { in vidioc_try_fmt_vid_cap()
775 f->fmt.pix.height = NUM_LINES_1CIFS_NTSC * 2; in vidioc_try_fmt_vid_cap()
778 f->fmt.pix.height = NUM_LINES_1CIFS_NTSC; in vidioc_try_fmt_vid_cap()
781 if (f->fmt.pix.width >= LINE_SZ_4CIFS_NTSC) in vidioc_try_fmt_vid_cap()
782 f->fmt.pix.width = LINE_SZ_4CIFS_NTSC; in vidioc_try_fmt_vid_cap()
784 f->fmt.pix.width = LINE_SZ_1CIFS_NTSC; in vidioc_try_fmt_vid_cap()
787 if (f->fmt.pix.height >= NUM_LINES_1CIFS_PAL * 2) { in vidioc_try_fmt_vid_cap()
788 f->fmt.pix.height = NUM_LINES_1CIFS_PAL * 2; in vidioc_try_fmt_vid_cap()
791 f->fmt.pix.height = NUM_LINES_1CIFS_PAL; in vidioc_try_fmt_vid_cap()
794 if (f->fmt.pix.width >= LINE_SZ_4CIFS_PAL) in vidioc_try_fmt_vid_cap()
795 f->fmt.pix.width = LINE_SZ_4CIFS_PAL; in vidioc_try_fmt_vid_cap()
797 f->fmt.pix.width = LINE_SZ_1CIFS_PAL; in vidioc_try_fmt_vid_cap()
799 f->fmt.pix.field = field; in vidioc_try_fmt_vid_cap()
800 f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3; in vidioc_try_fmt_vid_cap()
801 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; in vidioc_try_fmt_vid_cap()
802 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; in vidioc_try_fmt_vid_cap()
803 dprintk(vc->dev, 50, "%s: set width %d height %d field %d\n", __func__, in vidioc_try_fmt_vid_cap()
804 f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.field); in vidioc_try_fmt_vid_cap()
813 struct vb2_queue *q = &vc->vb_vidq; in vidioc_s_fmt_vid_cap()
822 fmt = format_by_fourcc(f->fmt.pix.pixelformat); in vidioc_s_fmt_vid_cap()
825 return -EINVAL; in vidioc_s_fmt_vid_cap()
828 dprintk(vc->dev, 1, "queue busy\n"); in vidioc_s_fmt_vid_cap()
829 return -EBUSY; in vidioc_s_fmt_vid_cap()
832 mode = vc->mode; in vidioc_s_fmt_vid_cap()
833 vc->fmt = fmt; in vidioc_s_fmt_vid_cap()
834 vc->width = f->fmt.pix.width; in vidioc_s_fmt_vid_cap()
835 vc->height = f->fmt.pix.height; in vidioc_s_fmt_vid_cap()
836 vc->field = f->fmt.pix.field; in vidioc_s_fmt_vid_cap()
837 if (vc->width > norm_minw(vc)) { in vidioc_s_fmt_vid_cap()
838 if (vc->height > norm_minh(vc)) { in vidioc_s_fmt_vid_cap()
839 if (vc->cap_parm.capturemode & in vidioc_s_fmt_vid_cap()
851 switch (vc->fmt->fourcc) { in vidioc_s_fmt_vid_cap()
860 mode.color |= (vc->jpegqual << 8); in vidioc_s_fmt_vid_cap()
873 if ((mode.color & MASK_COLOR) != (vc->mode.color & MASK_COLOR)) in vidioc_s_fmt_vid_cap()
875 else if (mode.scale != vc->mode.scale) in vidioc_s_fmt_vid_cap()
877 else if (mode.format != vc->mode.format) in vidioc_s_fmt_vid_cap()
879 vc->mode = mode; in vidioc_s_fmt_vid_cap()
891 long retval = -1; in s2255_write_config()
910 if (mode->format == FORMAT_NTSC) { in get_transfer_size()
911 switch (mode->scale) { in get_transfer_size()
928 } else if (mode->format == FORMAT_PAL) { in get_transfer_size()
929 switch (mode->scale) { in get_transfer_size()
948 if ((mode->color & MASK_COLOR) != COLOR_Y8) { in get_transfer_size()
956 mask_mult = 0xffffffffUL - DEF_USB_BLOCK + 1; in get_transfer_size()
965 struct device *dev = &sdev->udev->dev; in s2255_print_cfg()
966 dev_info(dev, "------------------------------------------------\n"); in s2255_print_cfg()
967 dev_info(dev, "format: %d\nscale %d\n", mode->format, mode->scale); in s2255_print_cfg()
968 dev_info(dev, "fdec: %d\ncolor %d\n", mode->fdec, mode->color); in s2255_print_cfg()
969 dev_info(dev, "bright: 0x%x\n", mode->bright); in s2255_print_cfg()
970 dev_info(dev, "------------------------------------------------\n"); in s2255_print_cfg()
976 * the image size could change via color format, video system or image
986 struct s2255_dev *dev = to_s2255_dev(vc->vdev.v4l2_dev); in s2255_set_mode()
988 __le32 *buffer = dev->cmdbuf; in s2255_set_mode()
990 mutex_lock(&dev->cmdlock); in s2255_set_mode()
991 chn_rev = G_chnmap[vc->idx]; in s2255_set_mode()
992 dprintk(dev, 3, "%s channel: %d\n", __func__, vc->idx); in s2255_set_mode()
994 if ((mode->color & MASK_COLOR) == COLOR_JPG) { in s2255_set_mode()
995 mode->color &= ~MASK_COLOR; in s2255_set_mode()
996 mode->color |= COLOR_JPG; in s2255_set_mode()
997 mode->color &= ~MASK_JPG_QUALITY; in s2255_set_mode()
998 mode->color |= (vc->jpegqual << 8); in s2255_set_mode()
1001 vc->mode = *mode; in s2255_set_mode()
1002 vc->req_image_size = get_transfer_size(mode); in s2255_set_mode()
1003 dprintk(dev, 1, "%s: reqsize %ld\n", __func__, vc->req_image_size); in s2255_set_mode()
1009 buffer[3 + i] = cpu_to_le32(((u32 *)&vc->mode)[i]); in s2255_set_mode()
1010 vc->setmode_ready = 0; in s2255_set_mode()
1011 res = s2255_write_config(dev->udev, (unsigned char *)buffer, 512); in s2255_set_mode()
1015 if (mode->restart) { in s2255_set_mode()
1016 wait_event_timeout(vc->wait_setmode, in s2255_set_mode()
1017 (vc->setmode_ready != 0), in s2255_set_mode()
1019 if (vc->setmode_ready != 1) { in s2255_set_mode()
1021 res = -EFAULT; in s2255_set_mode()
1025 vc->mode.restart = 0; in s2255_set_mode()
1026 dprintk(dev, 1, "%s chn %d, result: %d\n", __func__, vc->idx, res); in s2255_set_mode()
1027 mutex_unlock(&dev->cmdlock); in s2255_set_mode()
1035 struct s2255_dev *dev = to_s2255_dev(vc->vdev.v4l2_dev); in s2255_cmd_status()
1036 __le32 *buffer = dev->cmdbuf; in s2255_cmd_status()
1038 mutex_lock(&dev->cmdlock); in s2255_cmd_status()
1039 chn_rev = G_chnmap[vc->idx]; in s2255_cmd_status()
1040 dprintk(dev, 4, "%s chan %d\n", __func__, vc->idx); in s2255_cmd_status()
1046 vc->vidstatus_ready = 0; in s2255_cmd_status()
1047 res = s2255_write_config(dev->udev, (unsigned char *)buffer, 512); in s2255_cmd_status()
1048 wait_event_timeout(vc->wait_vidstatus, in s2255_cmd_status()
1049 (vc->vidstatus_ready != 0), in s2255_cmd_status()
1051 if (vc->vidstatus_ready != 1) { in s2255_cmd_status()
1053 res = -EFAULT; in s2255_cmd_status()
1055 *pstatus = vc->vidstatus; in s2255_cmd_status()
1057 mutex_unlock(&dev->cmdlock); in s2255_cmd_status()
1066 vc->last_frame = -1; in start_streaming()
1067 vc->bad_payload = 0; in start_streaming()
1068 vc->cur_frame = 0; in start_streaming()
1069 vc->frame_count = 0; in start_streaming()
1071 vc->buffer.frame[j].ulState = S2255_READ_IDLE; in start_streaming()
1072 vc->buffer.frame[j].cur_size = 0; in start_streaming()
1084 spin_lock_irqsave(&vc->qlock, flags); in stop_streaming()
1085 list_for_each_entry_safe(buf, node, &vc->buf_list, list) { in stop_streaming()
1086 list_del(&buf->list); in stop_streaming()
1087 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); in stop_streaming()
1088 dprintk(vc->dev, 2, "[%p/%d] done\n", in stop_streaming()
1089 buf, buf->vb.vb2_buf.index); in stop_streaming()
1091 spin_unlock_irqrestore(&vc->qlock, flags); in stop_streaming()
1098 struct vb2_queue *q = &vc->vb_vidq; in vidioc_s_std()
1105 return -EBUSY; in vidioc_s_std()
1107 mode = vc->mode; in vidioc_s_std()
1109 dprintk(vc->dev, 4, "%s 60 Hz\n", __func__); in vidioc_s_std()
1115 vc->width = LINE_SZ_4CIFS_NTSC; in vidioc_s_std()
1116 vc->height = NUM_LINES_4CIFS_NTSC * 2; in vidioc_s_std()
1119 dprintk(vc->dev, 4, "%s 50 Hz\n", __func__); in vidioc_s_std()
1124 vc->width = LINE_SZ_4CIFS_PAL; in vidioc_s_std()
1125 vc->height = NUM_LINES_4CIFS_PAL * 2; in vidioc_s_std()
1128 return -EINVAL; in vidioc_s_std()
1129 vc->std = i; in vidioc_s_std()
1139 *i = vc->std; in vidioc_g_std()
1154 struct s2255_dev *dev = vc->dev; in vidioc_enum_input()
1157 if (inp->index != 0) in vidioc_enum_input()
1158 return -EINVAL; in vidioc_enum_input()
1159 inp->type = V4L2_INPUT_TYPE_CAMERA; in vidioc_enum_input()
1160 inp->std = S2255_NORMS; in vidioc_enum_input()
1161 inp->status = 0; in vidioc_enum_input()
1162 if (dev->dsp_fw_ver >= S2255_MIN_DSP_STATUS) { in vidioc_enum_input()
1168 inp->status = (status & 0x01) ? 0 in vidioc_enum_input()
1171 switch (dev->pid) { in vidioc_enum_input()
1174 strscpy(inp->name, "Composite", sizeof(inp->name)); in vidioc_enum_input()
1177 strscpy(inp->name, (vc->idx < 2) ? "Composite" : "S-Video", in vidioc_enum_input()
1178 sizeof(inp->name)); in vidioc_enum_input()
1192 return -EINVAL; in vidioc_s_input()
1199 container_of(ctrl->handler, struct s2255_vc, hdl); in s2255_s_ctrl()
1201 mode = vc->mode; in s2255_s_ctrl()
1203 switch (ctrl->id) { in s2255_s_ctrl()
1205 mode.bright = ctrl->val; in s2255_s_ctrl()
1208 mode.contrast = ctrl->val; in s2255_s_ctrl()
1211 mode.hue = ctrl->val; in s2255_s_ctrl()
1214 mode.saturation = ctrl->val; in s2255_s_ctrl()
1218 mode.color |= !ctrl->val << 16; in s2255_s_ctrl()
1221 vc->jpegqual = ctrl->val; in s2255_s_ctrl()
1224 return -EINVAL; in s2255_s_ctrl()
1241 jc->quality = vc->jpegqual; in vidioc_g_jpegcomp()
1242 dprintk(vc->dev, 2, "%s: quality %d\n", __func__, jc->quality); in vidioc_g_jpegcomp()
1251 if (jc->quality < 0 || jc->quality > 100) in vidioc_s_jpegcomp()
1252 return -EINVAL; in vidioc_s_jpegcomp()
1253 v4l2_ctrl_s_ctrl(vc->jpegqual_ctrl, jc->quality); in vidioc_s_jpegcomp()
1254 dprintk(vc->dev, 2, "%s: quality %d\n", __func__, jc->quality); in vidioc_s_jpegcomp()
1264 if (sp->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) in vidioc_g_parm()
1265 return -EINVAL; in vidioc_g_parm()
1266 sp->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; in vidioc_g_parm()
1267 sp->parm.capture.capturemode = vc->cap_parm.capturemode; in vidioc_g_parm()
1268 sp->parm.capture.readbuffers = S2255_MIN_BUFS; in vidioc_g_parm()
1269 def_num = (vc->mode.format == FORMAT_NTSC) ? 1001 : 1000; in vidioc_g_parm()
1270 def_dem = (vc->mode.format == FORMAT_NTSC) ? 30000 : 25000; in vidioc_g_parm()
1271 sp->parm.capture.timeperframe.denominator = def_dem; in vidioc_g_parm()
1272 switch (vc->mode.fdec) { in vidioc_g_parm()
1275 sp->parm.capture.timeperframe.numerator = def_num; in vidioc_g_parm()
1278 sp->parm.capture.timeperframe.numerator = def_num * 2; in vidioc_g_parm()
1281 sp->parm.capture.timeperframe.numerator = def_num * 3; in vidioc_g_parm()
1284 sp->parm.capture.timeperframe.numerator = def_num * 5; in vidioc_g_parm()
1287 dprintk(vc->dev, 4, "%s capture mode, %d timeperframe %d/%d\n", in vidioc_g_parm()
1289 sp->parm.capture.capturemode, in vidioc_g_parm()
1290 sp->parm.capture.timeperframe.numerator, in vidioc_g_parm()
1291 sp->parm.capture.timeperframe.denominator); in vidioc_g_parm()
1302 if (sp->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) in vidioc_s_parm()
1303 return -EINVAL; in vidioc_s_parm()
1304 mode = vc->mode; in vidioc_s_parm()
1306 if ((vc->cap_parm.capturemode != sp->parm.capture.capturemode) in vidioc_s_parm()
1307 && vb2_is_streaming(&vc->vb_vidq)) in vidioc_s_parm()
1308 return -EBUSY; in vidioc_s_parm()
1311 if (def_dem != sp->parm.capture.timeperframe.denominator) in vidioc_s_parm()
1312 sp->parm.capture.timeperframe.numerator = def_num; in vidioc_s_parm()
1313 else if (sp->parm.capture.timeperframe.numerator <= def_num) in vidioc_s_parm()
1314 sp->parm.capture.timeperframe.numerator = def_num; in vidioc_s_parm()
1315 else if (sp->parm.capture.timeperframe.numerator <= (def_num * 2)) { in vidioc_s_parm()
1316 sp->parm.capture.timeperframe.numerator = def_num * 2; in vidioc_s_parm()
1318 } else if (sp->parm.capture.timeperframe.numerator <= (def_num * 3)) { in vidioc_s_parm()
1319 sp->parm.capture.timeperframe.numerator = def_num * 3; in vidioc_s_parm()
1322 sp->parm.capture.timeperframe.numerator = def_num * 5; in vidioc_s_parm()
1326 sp->parm.capture.timeperframe.denominator = def_dem; in vidioc_s_parm()
1327 sp->parm.capture.readbuffers = S2255_MIN_BUFS; in vidioc_s_parm()
1329 dprintk(vc->dev, 4, "%s capture mode, %d timeperframe %d/%d, fdec %d\n", in vidioc_s_parm()
1331 sp->parm.capture.capturemode, in vidioc_s_parm()
1332 sp->parm.capture.timeperframe.numerator, in vidioc_s_parm()
1333 sp->parm.capture.timeperframe.denominator, fdec); in vidioc_s_parm()
1353 int is_ntsc = vc->std & V4L2_STD_525_60; in vidioc_enum_framesizes()
1356 if (fe->index >= NUM_SIZE_ENUMS) in vidioc_enum_framesizes()
1357 return -EINVAL; in vidioc_enum_framesizes()
1359 fmt = format_by_fourcc(fe->pixel_format); in vidioc_enum_framesizes()
1361 return -EINVAL; in vidioc_enum_framesizes()
1362 fe->type = V4L2_FRMSIZE_TYPE_DISCRETE; in vidioc_enum_framesizes()
1363 fe->discrete = is_ntsc ? ntsc_sizes[fe->index] : pal_sizes[fe->index]; in vidioc_enum_framesizes()
1373 int is_ntsc = vc->std & V4L2_STD_525_60; in vidioc_enum_frameintervals()
1378 if (fe->index >= NUM_FRAME_ENUMS) in vidioc_enum_frameintervals()
1379 return -EINVAL; in vidioc_enum_frameintervals()
1381 fmt = format_by_fourcc(fe->pixel_format); in vidioc_enum_frameintervals()
1383 return -EINVAL; in vidioc_enum_frameintervals()
1387 if (fe->width == sizes->width && in vidioc_enum_frameintervals()
1388 fe->height == sizes->height) in vidioc_enum_frameintervals()
1391 return -EINVAL; in vidioc_enum_frameintervals()
1393 fe->type = V4L2_FRMIVAL_TYPE_DISCRETE; in vidioc_enum_frameintervals()
1394 fe->discrete.denominator = is_ntsc ? 30000 : 25000; in vidioc_enum_frameintervals()
1395 fe->discrete.numerator = (is_ntsc ? 1001 : 1000) * frm_dec[fe->index]; in vidioc_enum_frameintervals()
1396 dprintk(vc->dev, 4, "%s discrete %d/%d\n", __func__, in vidioc_enum_frameintervals()
1397 fe->discrete.numerator, in vidioc_enum_frameintervals()
1398 fe->discrete.denominator); in vidioc_enum_frameintervals()
1405 struct s2255_dev *dev = vc->dev; in s2255_open()
1414 state = atomic_read(&dev->fw_data->fw_state); in s2255_open()
1417 return -ENODEV; in s2255_open()
1419 s2255_dev_err(&dev->udev->dev, in s2255_open()
1420 "firmware load failed. retrying.\n"); in s2255_open()
1422 wait_event_timeout(dev->fw_data->wait_fw, in s2255_open()
1423 ((atomic_read(&dev->fw_data->fw_state) in s2255_open()
1425 (atomic_read(&dev->fw_data->fw_state) in s2255_open()
1428 /* state may have changed, re-read */ in s2255_open()
1429 state = atomic_read(&dev->fw_data->fw_state); in s2255_open()
1433 /* give S2255_LOAD_TIMEOUT time for firmware to load in case in s2255_open()
1435 pr_info("%s waiting for firmware load\n", __func__); in s2255_open()
1436 wait_event_timeout(dev->fw_data->wait_fw, in s2255_open()
1437 ((atomic_read(&dev->fw_data->fw_state) in s2255_open()
1439 (atomic_read(&dev->fw_data->fw_state) in s2255_open()
1442 /* state may have changed, re-read */ in s2255_open()
1443 state = atomic_read(&dev->fw_data->fw_state); in s2255_open()
1454 pr_info("2255 firmware load failed.\n"); in s2255_open()
1455 return -ENODEV; in s2255_open()
1458 return -ENODEV; in s2255_open()
1461 pr_info("%s: firmware not loaded, please retry\n", in s2255_open()
1464 * Timeout on firmware load means device unusable. in s2255_open()
1465 * Set firmware failure state. in s2255_open()
1466 * On next s2255_open the firmware will be reloaded. in s2255_open()
1468 atomic_set(&dev->fw_data->fw_state, in s2255_open()
1470 return -EAGAIN; in s2255_open()
1473 return -EFAULT; in s2255_open()
1475 if (!vc->configured) { in s2255_open()
1477 vc->fmt = &formats[0]; in s2255_open()
1478 s2255_set_mode(vc, &vc->mode); in s2255_open()
1479 vc->configured = 1; in s2255_open()
1489 /* make sure firmware still not trying to load */ in s2255_destroy()
1490 timer_shutdown_sync(&dev->timer); /* only started in .probe and .open */ in s2255_destroy()
1491 if (dev->fw_data->fw_urb) { in s2255_destroy()
1492 usb_kill_urb(dev->fw_data->fw_urb); in s2255_destroy()
1493 usb_free_urb(dev->fw_data->fw_urb); in s2255_destroy()
1494 dev->fw_data->fw_urb = NULL; in s2255_destroy()
1496 release_firmware(dev->fw_data->fw); in s2255_destroy()
1497 kfree(dev->fw_data->pfw_data); in s2255_destroy()
1498 kfree(dev->fw_data); in s2255_destroy()
1499 /* reset the DSP so firmware can be reloaded next time */ in s2255_destroy()
1501 mutex_destroy(&dev->lock); in s2255_destroy()
1502 usb_put_dev(dev->udev); in s2255_destroy()
1503 v4l2_device_unregister(&dev->v4l2_dev); in s2255_destroy()
1504 kfree(dev->cmdbuf); in s2255_destroy()
1548 struct s2255_dev *dev = to_s2255_dev(vdev->v4l2_dev); in s2255_video_device_release()
1553 refcount_read(&dev->num_channels)); in s2255_video_device_release()
1555 v4l2_ctrl_handler_free(&vc->hdl); in s2255_video_device_release()
1557 if (refcount_dec_and_test(&dev->num_channels)) in s2255_video_device_release()
1592 ret = v4l2_device_register(&dev->interface->dev, &dev->v4l2_dev); in s2255_probe_v4l()
1595 /* initialize all video 4 linux */ in s2255_probe_v4l()
1596 /* register 4 video devices */ in s2255_probe_v4l()
1598 vc = &dev->vc[i]; in s2255_probe_v4l()
1599 INIT_LIST_HEAD(&vc->buf_list); in s2255_probe_v4l()
1601 v4l2_ctrl_handler_init(&vc->hdl, 6); in s2255_probe_v4l()
1602 v4l2_ctrl_new_std(&vc->hdl, &s2255_ctrl_ops, in s2255_probe_v4l()
1603 V4L2_CID_BRIGHTNESS, -127, 127, 1, DEF_BRIGHT); in s2255_probe_v4l()
1604 v4l2_ctrl_new_std(&vc->hdl, &s2255_ctrl_ops, in s2255_probe_v4l()
1606 v4l2_ctrl_new_std(&vc->hdl, &s2255_ctrl_ops, in s2255_probe_v4l()
1608 v4l2_ctrl_new_std(&vc->hdl, &s2255_ctrl_ops, in s2255_probe_v4l()
1610 vc->jpegqual_ctrl = v4l2_ctrl_new_std(&vc->hdl, in s2255_probe_v4l()
1614 if (dev->dsp_fw_ver >= S2255_MIN_DSP_COLORFILTER && in s2255_probe_v4l()
1615 (dev->pid != 0x2257 || vc->idx <= 1)) in s2255_probe_v4l()
1616 v4l2_ctrl_new_custom(&vc->hdl, &color_filter_ctrl, in s2255_probe_v4l()
1618 if (vc->hdl.error) { in s2255_probe_v4l()
1619 ret = vc->hdl.error; in s2255_probe_v4l()
1620 v4l2_ctrl_handler_free(&vc->hdl); in s2255_probe_v4l()
1621 dev_err(&dev->udev->dev, "couldn't register control\n"); in s2255_probe_v4l()
1624 q = &vc->vb_vidq; in s2255_probe_v4l()
1625 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in s2255_probe_v4l()
1626 q->io_modes = VB2_MMAP | VB2_READ | VB2_USERPTR; in s2255_probe_v4l()
1627 q->drv_priv = vc; in s2255_probe_v4l()
1628 q->lock = &vc->vb_lock; in s2255_probe_v4l()
1629 q->buf_struct_size = sizeof(struct s2255_buffer); in s2255_probe_v4l()
1630 q->mem_ops = &vb2_vmalloc_memops; in s2255_probe_v4l()
1631 q->ops = &s2255_video_qops; in s2255_probe_v4l()
1632 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in s2255_probe_v4l()
1635 dev_err(&dev->udev->dev, in s2255_probe_v4l()
1639 /* register video devices */ in s2255_probe_v4l()
1640 vc->vdev = template; in s2255_probe_v4l()
1641 vc->vdev.queue = q; in s2255_probe_v4l()
1642 vc->vdev.ctrl_handler = &vc->hdl; in s2255_probe_v4l()
1643 vc->vdev.lock = &dev->lock; in s2255_probe_v4l()
1644 vc->vdev.v4l2_dev = &dev->v4l2_dev; in s2255_probe_v4l()
1645 vc->vdev.device_caps = V4L2_CAP_VIDEO_CAPTURE | in s2255_probe_v4l()
1647 video_set_drvdata(&vc->vdev, vc); in s2255_probe_v4l()
1648 if (video_nr == -1) in s2255_probe_v4l()
1649 ret = video_register_device(&vc->vdev, in s2255_probe_v4l()
1653 ret = video_register_device(&vc->vdev, in s2255_probe_v4l()
1658 dev_err(&dev->udev->dev, in s2255_probe_v4l()
1659 "failed to register video device!\n"); in s2255_probe_v4l()
1662 refcount_inc(&dev->num_channels); in s2255_probe_v4l()
1663 v4l2_info(&dev->v4l2_dev, "V4L2 device registered as %s\n", in s2255_probe_v4l()
1664 video_device_node_name(&vc->vdev)); in s2255_probe_v4l()
1670 if (refcount_read(&dev->num_channels) == 0) { in s2255_probe_v4l()
1671 v4l2_device_unregister(&dev->v4l2_dev); in s2255_probe_v4l()
1674 if (refcount_read(&dev->num_channels) != MAX_CHANNELS) in s2255_probe_v4l()
1685 * bytes 0-3: marker : 0x2255DA4AL (S2255_MARKER_FRAME)
1686 * bytes 4-7: channel: 0-3
1687 * bytes 8-11: payload size: size of the frame
1688 * bytes 12-payloadsize+12: frame data
1698 s32 idx = -1; in save_frame()
1703 vc = &dev->vc[dev->cc]; in save_frame()
1704 idx = vc->cur_frame; in save_frame()
1705 frm = &vc->buffer.frame[idx]; in save_frame()
1706 if (frm->ulState == S2255_READ_IDLE) { in save_frame()
1712 pdata = (unsigned char *)pipe_info->transfer_buffer; in save_frame()
1714 for (jj = 0; jj < (pipe_info->cur_transfer_size - 12); jj++) { in save_frame()
1725 return -EINVAL; in save_frame()
1728 dev->cc = G_chnmap[cc]; in save_frame()
1729 vc = &dev->vc[dev->cc]; in save_frame()
1731 if (payload > vc->req_image_size) { in save_frame()
1732 vc->bad_payload++; in save_frame()
1734 return -EINVAL; in save_frame()
1736 vc->pkt_size = payload; in save_frame()
1737 vc->jpg_size = le32_to_cpu(pdword[4]); in save_frame()
1748 vc = &dev->vc[cc]; in save_frame()
1753 vc->setmode_ready = 1; in save_frame()
1754 wake_up(&vc->wait_setmode); in save_frame()
1758 dev->chn_ready |= (1 << cc); in save_frame()
1759 if ((dev->chn_ready & 0x0f) != 0x0f) in save_frame()
1763 atomic_set(&dev->fw_data->fw_state, in save_frame()
1765 wake_up(&dev->fw_data->wait_fw); in save_frame()
1768 vc->vidstatus = le32_to_cpu(pdword[3]); in save_frame()
1769 vc->vidstatus_ready = 1; in save_frame()
1770 wake_up(&vc->wait_vidstatus); in save_frame()
1787 return -EINVAL; in save_frame()
1789 vc = &dev->vc[dev->cc]; in save_frame()
1790 idx = vc->cur_frame; in save_frame()
1791 frm = &vc->buffer.frame[idx]; in save_frame()
1793 if (!vb2_is_streaming(&vc->vb_vidq)) { in save_frame()
1795 frm->ulState = S2255_READ_IDLE; in save_frame()
1796 return -EINVAL; in save_frame()
1799 if (frm->ulState == S2255_READ_IDLE) { in save_frame()
1800 frm->ulState = S2255_READ_FRAME; in save_frame()
1801 frm->cur_size = 0; in save_frame()
1805 psrc = (u8 *)pipe_info->transfer_buffer + offset; in save_frame()
1808 if (frm->lpvbits == NULL) { in save_frame()
1810 frm, dev, dev->cc, idx); in save_frame()
1811 return -ENOMEM; in save_frame()
1814 pdest = frm->lpvbits + frm->cur_size; in save_frame()
1816 copy_size = (pipe_info->cur_transfer_size - offset); in save_frame()
1818 size = vc->pkt_size - PREFIX_SIZE; in save_frame()
1821 if ((copy_size + frm->cur_size) < vc->req_image_size) in save_frame()
1824 frm->cur_size += copy_size; in save_frame()
1825 dprintk(dev, 4, "cur_size: %lu, size: %lu\n", frm->cur_size, size); in save_frame()
1827 if (frm->cur_size >= size) { in save_frame()
1829 dev->cc, idx); in save_frame()
1830 vc->last_frame = vc->cur_frame; in save_frame()
1831 vc->cur_frame++; in save_frame()
1833 if ((vc->cur_frame == SYS_FRAMES) || in save_frame()
1834 (vc->cur_frame == vc->buffer.dwFrames)) in save_frame()
1835 vc->cur_frame = 0; in save_frame()
1837 if (vb2_is_streaming(&vc->vb_vidq)) in save_frame()
1838 s2255_got_frame(vc, vc->jpg_size); in save_frame()
1839 vc->frame_count++; in save_frame()
1840 frm->ulState = S2255_READ_IDLE; in save_frame()
1841 frm->cur_size = 0; in save_frame()
1852 dprintk(dev, 50, "callback read video\n"); in s2255_read_video_callback()
1854 if (dev->cc >= MAX_CHANNELS) { in s2255_read_video_callback()
1855 dev->cc = 0; in s2255_read_video_callback()
1856 dev_err(&dev->udev->dev, "invalid channel\n"); in s2255_read_video_callback()
1864 dprintk(dev, 50, "callback read video done\n"); in s2255_read_video_callback()
1877 return -ENOMEM; in s2255_vendor_req()
1880 r = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0), in s2255_vendor_req()
1891 r = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), in s2255_vendor_req()
1901 * retrieve FX2 firmware version. future use.
1903 * @return -1 for fail, else returns firmware version as an int(16 bits)
1928 vc->buffer.dwFrames = SYS_FRAMES; in s2255_create_sys_buffers()
1937 vc->buffer.frame[i].lpvbits = vmalloc(reqsize); in s2255_create_sys_buffers()
1938 vc->buffer.frame[i].size = reqsize; in s2255_create_sys_buffers()
1939 if (vc->buffer.frame[i].lpvbits == NULL) { in s2255_create_sys_buffers()
1941 vc->buffer.dwFrames = i; in s2255_create_sys_buffers()
1948 vc->buffer.frame[i].ulState = 0; in s2255_create_sys_buffers()
1949 vc->buffer.frame[i].cur_size = 0; in s2255_create_sys_buffers()
1952 vc->cur_frame = 0; in s2255_create_sys_buffers()
1953 vc->last_frame = -1; in s2255_create_sys_buffers()
1961 vfree(vc->buffer.frame[i].lpvbits); in s2255_release_sys_buffers()
1962 vc->buffer.frame[i].lpvbits = NULL; in s2255_release_sys_buffers()
1972 struct s2255_pipeinfo *pipe = &dev->pipe; in s2255_board_init()
1975 pipe->dev = dev; in s2255_board_init()
1976 pipe->cur_transfer_size = S2255_USB_XFER_SIZE; in s2255_board_init()
1977 pipe->max_transfer_size = S2255_USB_XFER_SIZE; in s2255_board_init()
1979 pipe->transfer_buffer = kzalloc(pipe->max_transfer_size, in s2255_board_init()
1981 if (pipe->transfer_buffer == NULL) { in s2255_board_init()
1983 return -ENOMEM; in s2255_board_init()
1985 /* query the firmware */ in s2255_board_init()
1988 pr_info("s2255: usb firmware version %d.%d\n", in s2255_board_init()
1993 pr_info("s2255: newer USB firmware available\n"); in s2255_board_init()
1996 struct s2255_vc *vc = &dev->vc[j]; in s2255_board_init()
1997 vc->mode = mode_def; in s2255_board_init()
1998 if (dev->pid == 0x2257 && j > 1) in s2255_board_init()
1999 vc->mode.color |= (1 << 16); in s2255_board_init()
2000 vc->jpegqual = S2255_DEF_JPEG_QUAL; in s2255_board_init()
2001 vc->width = LINE_SZ_4CIFS_NTSC; in s2255_board_init()
2002 vc->height = NUM_LINES_4CIFS_NTSC * 2; in s2255_board_init()
2003 vc->std = V4L2_STD_NTSC_M; in s2255_board_init()
2004 vc->fmt = &formats[0]; in s2255_board_init()
2005 vc->mode.restart = 1; in s2255_board_init()
2006 vc->req_image_size = get_transfer_size(&mode_def); in s2255_board_init()
2007 vc->frame_count = 0; in s2255_board_init()
2023 if (vb2_is_streaming(&dev->vc[i].vb_vidq)) in s2255_board_shutdown()
2024 s2255_stop_acquire(&dev->vc[i]); in s2255_board_shutdown()
2028 s2255_release_sys_buffers(&dev->vc[i]); in s2255_board_shutdown()
2030 kfree(dev->pipe.transfer_buffer); in s2255_board_shutdown()
2040 pipe_info = purb->context; in read_pipe_completion()
2042 dev_err(&purb->dev->dev, "no context!\n"); in read_pipe_completion()
2045 dev = pipe_info->dev; in read_pipe_completion()
2047 dev_err(&purb->dev->dev, "no context!\n"); in read_pipe_completion()
2050 status = purb->status; in read_pipe_completion()
2052 if (status == -ESHUTDOWN) { in read_pipe_completion()
2054 pipe_info->err_count++; in read_pipe_completion()
2058 if (pipe_info->state == 0) { in read_pipe_completion()
2066 pipe_info->err_count++; in read_pipe_completion()
2070 pipe = usb_rcvbulkpipe(dev->udev, dev->read_endpoint); in read_pipe_completion()
2072 usb_fill_bulk_urb(pipe_info->stream_urb, dev->udev, in read_pipe_completion()
2074 pipe_info->transfer_buffer, in read_pipe_completion()
2075 pipe_info->cur_transfer_size, in read_pipe_completion()
2078 if (pipe_info->state != 0) { in read_pipe_completion()
2079 if (usb_submit_urb(pipe_info->stream_urb, GFP_ATOMIC)) in read_pipe_completion()
2080 dev_err(&dev->udev->dev, "error submitting urb\n"); in read_pipe_completion()
2091 struct s2255_pipeinfo *pipe_info = &dev->pipe; in s2255_start_readpipe()
2092 pipe = usb_rcvbulkpipe(dev->udev, dev->read_endpoint); in s2255_start_readpipe()
2093 dprintk(dev, 2, "%s: IN %d\n", __func__, dev->read_endpoint); in s2255_start_readpipe()
2094 pipe_info->state = 1; in s2255_start_readpipe()
2095 pipe_info->err_count = 0; in s2255_start_readpipe()
2096 pipe_info->stream_urb = usb_alloc_urb(0, GFP_KERNEL); in s2255_start_readpipe()
2097 if (!pipe_info->stream_urb) in s2255_start_readpipe()
2098 return -ENOMEM; in s2255_start_readpipe()
2100 usb_fill_bulk_urb(pipe_info->stream_urb, dev->udev, in s2255_start_readpipe()
2102 pipe_info->transfer_buffer, in s2255_start_readpipe()
2103 pipe_info->cur_transfer_size, in s2255_start_readpipe()
2105 retval = usb_submit_urb(pipe_info->stream_urb, GFP_KERNEL); in s2255_start_readpipe()
2119 struct s2255_dev *dev = to_s2255_dev(vc->vdev.v4l2_dev); in s2255_start_acquire()
2120 __le32 *buffer = dev->cmdbuf; in s2255_start_acquire()
2122 mutex_lock(&dev->cmdlock); in s2255_start_acquire()
2123 chn_rev = G_chnmap[vc->idx]; in s2255_start_acquire()
2124 vc->last_frame = -1; in s2255_start_acquire()
2125 vc->bad_payload = 0; in s2255_start_acquire()
2126 vc->cur_frame = 0; in s2255_start_acquire()
2128 vc->buffer.frame[j].ulState = 0; in s2255_start_acquire()
2129 vc->buffer.frame[j].cur_size = 0; in s2255_start_acquire()
2136 res = s2255_write_config(dev->udev, (unsigned char *)buffer, 512); in s2255_start_acquire()
2138 dev_err(&dev->udev->dev, "CMD_START error\n"); in s2255_start_acquire()
2140 dprintk(dev, 2, "start acquire exit[%d] %d\n", vc->idx, res); in s2255_start_acquire()
2141 mutex_unlock(&dev->cmdlock); in s2255_start_acquire()
2149 struct s2255_dev *dev = to_s2255_dev(vc->vdev.v4l2_dev); in s2255_stop_acquire()
2150 __le32 *buffer = dev->cmdbuf; in s2255_stop_acquire()
2152 mutex_lock(&dev->cmdlock); in s2255_stop_acquire()
2153 chn_rev = G_chnmap[vc->idx]; in s2255_stop_acquire()
2159 res = s2255_write_config(dev->udev, (unsigned char *)buffer, 512); in s2255_stop_acquire()
2161 dev_err(&dev->udev->dev, "CMD_STOP error\n"); in s2255_stop_acquire()
2163 dprintk(dev, 4, "%s: chn %d, res %d\n", __func__, vc->idx, res); in s2255_stop_acquire()
2164 mutex_unlock(&dev->cmdlock); in s2255_stop_acquire()
2170 struct s2255_pipeinfo *pipe = &dev->pipe; in s2255_stop_readpipe()
2172 pipe->state = 0; in s2255_stop_readpipe()
2173 if (pipe->stream_urb) { in s2255_stop_readpipe()
2175 usb_kill_urb(pipe->stream_urb); in s2255_stop_readpipe()
2176 usb_free_urb(pipe->stream_urb); in s2255_stop_readpipe()
2177 pipe->stream_urb = NULL; in s2255_stop_readpipe()
2186 dev->fw_data->fw_size = dev->fw_data->fw->size; in s2255_fwload_start()
2187 atomic_set(&dev->fw_data->fw_state, S2255_FW_NOTLOADED); in s2255_fwload_start()
2188 memcpy(dev->fw_data->pfw_data, in s2255_fwload_start()
2189 dev->fw_data->fw->data, CHUNK_SIZE); in s2255_fwload_start()
2190 dev->fw_data->fw_loaded = CHUNK_SIZE; in s2255_fwload_start()
2191 usb_fill_bulk_urb(dev->fw_data->fw_urb, dev->udev, in s2255_fwload_start()
2192 usb_sndbulkpipe(dev->udev, 2), in s2255_fwload_start()
2193 dev->fw_data->pfw_data, in s2255_fwload_start()
2195 dev->fw_data); in s2255_fwload_start()
2196 mod_timer(&dev->timer, jiffies + HZ); in s2255_fwload_start()
2207 int retval = -ENOMEM; in s2255_probe()
2214 s2255_dev_err(&interface->dev, "out of memory\n"); in s2255_probe()
2215 return -ENOMEM; in s2255_probe()
2218 dev->cmdbuf = kzalloc(S2255_CMDBUF_SIZE, GFP_KERNEL); in s2255_probe()
2219 if (dev->cmdbuf == NULL) { in s2255_probe()
2220 s2255_dev_err(&interface->dev, "out of memory\n"); in s2255_probe()
2224 refcount_set(&dev->num_channels, 0); in s2255_probe()
2225 dev->pid = id->idProduct; in s2255_probe()
2226 dev->fw_data = kzalloc(sizeof(struct s2255_fw), GFP_KERNEL); in s2255_probe()
2227 if (!dev->fw_data) in s2255_probe()
2229 mutex_init(&dev->lock); in s2255_probe()
2230 mutex_init(&dev->cmdlock); in s2255_probe()
2232 dev->udev = usb_get_dev(interface_to_usbdev(interface)); in s2255_probe()
2233 if (dev->udev == NULL) { in s2255_probe()
2234 dev_err(&interface->dev, "null usb device\n"); in s2255_probe()
2235 retval = -ENODEV; in s2255_probe()
2238 dev_dbg(&interface->dev, "dev: %p, udev %p interface %p\n", in s2255_probe()
2239 dev, dev->udev, interface); in s2255_probe()
2240 dev->interface = interface; in s2255_probe()
2242 iface_desc = interface->cur_altsetting; in s2255_probe()
2243 dev_dbg(&interface->dev, "num EP: %d\n", in s2255_probe()
2244 iface_desc->desc.bNumEndpoints); in s2255_probe()
2245 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { in s2255_probe()
2246 endpoint = &iface_desc->endpoint[i].desc; in s2255_probe()
2247 if (!dev->read_endpoint && usb_endpoint_is_bulk_in(endpoint)) { in s2255_probe()
2249 dev->read_endpoint = endpoint->bEndpointAddress; in s2255_probe()
2253 if (!dev->read_endpoint) { in s2255_probe()
2254 dev_err(&interface->dev, "Could not find bulk-in endpoint\n"); in s2255_probe()
2257 timer_setup(&dev->timer, s2255_timer, 0); in s2255_probe()
2258 init_waitqueue_head(&dev->fw_data->wait_fw); in s2255_probe()
2260 struct s2255_vc *vc = &dev->vc[i]; in s2255_probe()
2261 vc->idx = i; in s2255_probe()
2262 vc->dev = dev; in s2255_probe()
2263 init_waitqueue_head(&vc->wait_setmode); in s2255_probe()
2264 init_waitqueue_head(&vc->wait_vidstatus); in s2255_probe()
2265 spin_lock_init(&vc->qlock); in s2255_probe()
2266 mutex_init(&vc->vb_lock); in s2255_probe()
2269 dev->fw_data->fw_urb = usb_alloc_urb(0, GFP_KERNEL); in s2255_probe()
2270 if (!dev->fw_data->fw_urb) in s2255_probe()
2273 dev->fw_data->pfw_data = kzalloc(CHUNK_SIZE, GFP_KERNEL); in s2255_probe()
2274 if (!dev->fw_data->pfw_data) { in s2255_probe()
2275 dev_err(&interface->dev, "out of memory!\n"); in s2255_probe()
2279 if (request_firmware(&dev->fw_data->fw, in s2255_probe()
2280 FIRMWARE_FILE_NAME, &dev->udev->dev)) { in s2255_probe()
2281 dev_err(&interface->dev, "sensoray 2255 failed to get firmware\n"); in s2255_probe()
2284 /* check the firmware is valid */ in s2255_probe()
2285 fw_size = dev->fw_data->fw->size; in s2255_probe()
2286 pdata = (__le32 *) &dev->fw_data->fw->data[fw_size - 8]; in s2255_probe()
2289 dev_err(&interface->dev, "Firmware invalid.\n"); in s2255_probe()
2290 retval = -ENODEV; in s2255_probe()
2293 /* make sure firmware is the latest */ in s2255_probe()
2295 pRel = (__le32 *) &dev->fw_data->fw->data[fw_size - 4]; in s2255_probe()
2297 dev->dsp_fw_ver = le32_to_cpu(*pRel); in s2255_probe()
2298 if (dev->dsp_fw_ver < S2255_CUR_DSP_FWVER) in s2255_probe()
2300 if (dev->pid == 0x2257 && in s2255_probe()
2301 dev->dsp_fw_ver < S2255_MIN_DSP_COLORFILTER) in s2255_probe()
2302 pr_warn("2257 needs firmware %d or above.\n", in s2255_probe()
2305 usb_reset_device(dev->udev); in s2255_probe()
2315 dev_info(&interface->dev, "Sensoray 2255 detected\n"); in s2255_probe()
2320 release_firmware(dev->fw_data->fw); in s2255_probe()
2322 kfree(dev->fw_data->pfw_data); in s2255_probe()
2324 usb_free_urb(dev->fw_data->fw_urb); in s2255_probe()
2326 timer_shutdown_sync(&dev->timer); in s2255_probe()
2328 usb_put_dev(dev->udev); in s2255_probe()
2330 kfree(dev->fw_data); in s2255_probe()
2331 mutex_destroy(&dev->lock); in s2255_probe()
2333 kfree(dev->cmdbuf); in s2255_probe()
2344 int channels = refcount_read(&dev->num_channels); in s2255_disconnect()
2345 mutex_lock(&dev->lock); in s2255_disconnect()
2346 v4l2_device_disconnect(&dev->v4l2_dev); in s2255_disconnect()
2347 mutex_unlock(&dev->lock); in s2255_disconnect()
2349 refcount_inc(&dev->num_channels); in s2255_disconnect()
2350 /* unregister each video device. */ in s2255_disconnect()
2352 video_unregister_device(&dev->vc[i].vdev); in s2255_disconnect()
2354 atomic_set(&dev->fw_data->fw_state, S2255_FW_DISCONNECTING); in s2255_disconnect()
2355 wake_up(&dev->fw_data->wait_fw); in s2255_disconnect()
2357 dev->vc[i].setmode_ready = 1; in s2255_disconnect()
2358 wake_up(&dev->vc[i].wait_setmode); in s2255_disconnect()
2359 dev->vc[i].vidstatus_ready = 1; in s2255_disconnect()
2360 wake_up(&dev->vc[i].wait_vidstatus); in s2255_disconnect()
2362 if (refcount_dec_and_test(&dev->num_channels)) in s2255_disconnect()
2364 dev_info(&interface->dev, "%s\n", __func__); in s2255_disconnect()
2376 MODULE_DESCRIPTION("Sensoray 2255 Video for Linux driver");