Lines Matching full:vc

49 static void tw686x_buf_done(struct tw686x_video_channel *vc,  in tw686x_buf_done()  argument
52 struct tw686x_dma_desc *desc = &vc->dma_descs[pb]; in tw686x_buf_done()
53 struct tw686x_dev *dev = vc->dev; in tw686x_buf_done()
57 if (vc->curr_bufs[pb]) { in tw686x_buf_done()
58 vb = &vc->curr_bufs[pb]->vb; in tw686x_buf_done()
61 vb->sequence = vc->sequence++; in tw686x_buf_done()
71 vc->pb = !pb; in tw686x_buf_done()
77 static void tw686x_memcpy_dma_free(struct tw686x_video_channel *vc, in tw686x_memcpy_dma_free() argument
80 struct tw686x_dma_desc *desc = &vc->dma_descs[pb]; in tw686x_memcpy_dma_free()
81 struct tw686x_dev *dev = vc->dev; in tw686x_memcpy_dma_free()
101 static int tw686x_memcpy_dma_alloc(struct tw686x_video_channel *vc, in tw686x_memcpy_dma_alloc() argument
104 struct tw686x_dev *dev = vc->dev; in tw686x_memcpy_dma_alloc()
105 u32 reg = pb ? VDMA_B_ADDR[vc->ch] : VDMA_P_ADDR[vc->ch]; in tw686x_memcpy_dma_alloc()
109 WARN(vc->dma_descs[pb].virt, in tw686x_memcpy_dma_alloc()
112 len = (vc->width * vc->height * vc->format->depth) >> 3; in tw686x_memcpy_dma_alloc()
114 &vc->dma_descs[pb].phys, GFP_KERNEL); in tw686x_memcpy_dma_alloc()
118 vc->ch, pb ? "B" : "P"); in tw686x_memcpy_dma_alloc()
121 vc->dma_descs[pb].size = len; in tw686x_memcpy_dma_alloc()
122 vc->dma_descs[pb].virt = virt; in tw686x_memcpy_dma_alloc()
123 reg_write(dev, reg, vc->dma_descs[pb].phys); in tw686x_memcpy_dma_alloc()
128 static void tw686x_memcpy_buf_refill(struct tw686x_video_channel *vc, in tw686x_memcpy_buf_refill() argument
133 while (!list_empty(&vc->vidq_queued)) { in tw686x_memcpy_buf_refill()
135 buf = list_first_entry(&vc->vidq_queued, in tw686x_memcpy_buf_refill()
139 vc->curr_bufs[pb] = buf; in tw686x_memcpy_buf_refill()
142 vc->curr_bufs[pb] = NULL; in tw686x_memcpy_buf_refill()
154 static void tw686x_contig_buf_refill(struct tw686x_video_channel *vc, in tw686x_contig_buf_refill() argument
159 while (!list_empty(&vc->vidq_queued)) { in tw686x_contig_buf_refill()
160 u32 reg = pb ? VDMA_B_ADDR[vc->ch] : VDMA_P_ADDR[vc->ch]; in tw686x_contig_buf_refill()
163 buf = list_first_entry(&vc->vidq_queued, in tw686x_contig_buf_refill()
168 reg_write(vc->dev, reg, phys); in tw686x_contig_buf_refill()
171 vc->curr_bufs[pb] = buf; in tw686x_contig_buf_refill()
174 vc->curr_bufs[pb] = NULL; in tw686x_contig_buf_refill()
224 static void tw686x_sg_buf_refill(struct tw686x_video_channel *vc, in tw686x_sg_buf_refill() argument
227 struct tw686x_dev *dev = vc->dev; in tw686x_sg_buf_refill()
230 while (!list_empty(&vc->vidq_queued)) { in tw686x_sg_buf_refill()
233 buf = list_first_entry(&vc->vidq_queued, in tw686x_sg_buf_refill()
237 buf_len = (vc->width * vc->height * vc->format->depth) >> 3; in tw686x_sg_buf_refill()
238 if (tw686x_sg_desc_fill(vc->sg_descs[pb], buf, buf_len)) { in tw686x_sg_buf_refill()
241 vc->ch, pb ? "B" : "P"); in tw686x_sg_buf_refill()
247 vc->curr_bufs[pb] = buf; in tw686x_sg_buf_refill()
251 vc->curr_bufs[pb] = NULL; in tw686x_sg_buf_refill()
254 static void tw686x_sg_dma_free(struct tw686x_video_channel *vc, in tw686x_sg_dma_free() argument
257 struct tw686x_dma_desc *desc = &vc->dma_descs[pb]; in tw686x_sg_dma_free()
258 struct tw686x_dev *dev = vc->dev; in tw686x_sg_dma_free()
266 vc->sg_descs[pb] = NULL; in tw686x_sg_dma_free()
269 static int tw686x_sg_dma_alloc(struct tw686x_video_channel *vc, in tw686x_sg_dma_alloc() argument
272 struct tw686x_dma_desc *desc = &vc->dma_descs[pb]; in tw686x_sg_dma_alloc()
273 struct tw686x_dev *dev = vc->dev; in tw686x_sg_dma_alloc()
274 u32 reg = pb ? DMA_PAGE_TABLE1_ADDR[vc->ch] : in tw686x_sg_dma_alloc()
275 DMA_PAGE_TABLE0_ADDR[vc->ch]; in tw686x_sg_dma_alloc()
284 vc->ch, pb ? "B" : "P"); in tw686x_sg_dma_alloc()
291 vc->ch * TW686X_SG_TABLE_SIZE; in tw686x_sg_dma_alloc()
294 vc->sg_descs[pb] = virt; in tw686x_sg_dma_alloc()
320 struct tw686x_video_channel *vc = &dev->video_channels[ch]; in tw686x_sg_setup() local
323 vc->dma_descs[pb].size = sg_table_size; in tw686x_sg_setup()
401 static void tw686x_set_framerate(struct tw686x_video_channel *vc, in tw686x_set_framerate() argument
406 i = tw686x_fps_idx(fps, TW686X_MAX_FPS(vc->video_standard)); in tw686x_set_framerate()
407 reg_write(vc->dev, VIDEO_FIELD_CTRL[vc->ch], fps_map[i]); in tw686x_set_framerate()
408 vc->fps = tw686x_real_fps(i, TW686X_MAX_FPS(vc->video_standard)); in tw686x_set_framerate()
425 struct tw686x_video_channel *vc = vb2_get_drv_priv(vq); in tw686x_queue_setup() local
428 (vc->width * vc->height * vc->format->depth) >> 3; in tw686x_queue_setup()
450 struct tw686x_video_channel *vc = vb2_get_drv_priv(vb->vb2_queue); in tw686x_buf_queue() local
451 struct tw686x_dev *dev = vc->dev; in tw686x_buf_queue()
467 spin_lock_irqsave(&vc->qlock, flags); in tw686x_buf_queue()
468 list_add_tail(&buf->list, &vc->vidq_queued); in tw686x_buf_queue()
469 spin_unlock_irqrestore(&vc->qlock, flags); in tw686x_buf_queue()
472 static void tw686x_clear_queue(struct tw686x_video_channel *vc, in tw686x_clear_queue() argument
477 while (!list_empty(&vc->vidq_queued)) { in tw686x_clear_queue()
480 buf = list_first_entry(&vc->vidq_queued, in tw686x_clear_queue()
487 if (vc->curr_bufs[pb]) in tw686x_clear_queue()
488 vb2_buffer_done(&vc->curr_bufs[pb]->vb.vb2_buf, state); in tw686x_clear_queue()
489 vc->curr_bufs[pb] = NULL; in tw686x_clear_queue()
495 struct tw686x_video_channel *vc = vb2_get_drv_priv(vq); in tw686x_start_streaming() local
496 struct tw686x_dev *dev = vc->dev; in tw686x_start_streaming()
510 spin_lock_irqsave(&vc->qlock, flags); in tw686x_start_streaming()
514 (!vc->dma_descs[0].virt || !vc->dma_descs[1].virt)) { in tw686x_start_streaming()
515 spin_unlock_irqrestore(&vc->qlock, flags); in tw686x_start_streaming()
518 vc->num); in tw686x_start_streaming()
524 dev->dma_ops->buf_refill(vc, pb); in tw686x_start_streaming()
525 spin_unlock_irqrestore(&vc->qlock, flags); in tw686x_start_streaming()
527 vc->sequence = 0; in tw686x_start_streaming()
528 vc->pb = 0; in tw686x_start_streaming()
531 tw686x_enable_channel(dev, vc->ch); in tw686x_start_streaming()
539 spin_lock_irqsave(&vc->qlock, flags); in tw686x_start_streaming()
540 tw686x_clear_queue(vc, VB2_BUF_STATE_QUEUED); in tw686x_start_streaming()
541 spin_unlock_irqrestore(&vc->qlock, flags); in tw686x_start_streaming()
547 struct tw686x_video_channel *vc = vb2_get_drv_priv(vq); in tw686x_stop_streaming() local
548 struct tw686x_dev *dev = vc->dev; in tw686x_stop_streaming()
557 tw686x_disable_channel(dev, vc->ch); in tw686x_stop_streaming()
559 spin_lock_irqsave(&vc->qlock, flags); in tw686x_stop_streaming()
560 tw686x_clear_queue(vc, VB2_BUF_STATE_ERROR); in tw686x_stop_streaming()
561 spin_unlock_irqrestore(&vc->qlock, flags); in tw686x_stop_streaming()
566 struct tw686x_video_channel *vc = vb2_get_drv_priv(vb->vb2_queue); in tw686x_buf_prepare() local
568 (vc->width * vc->height * vc->format->depth) >> 3; in tw686x_buf_prepare()
586 struct tw686x_video_channel *vc; in tw686x_s_ctrl() local
590 vc = container_of(ctrl->handler, struct tw686x_video_channel, in tw686x_s_ctrl()
592 dev = vc->dev; in tw686x_s_ctrl()
593 ch = vc->ch; in tw686x_s_ctrl()
624 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_g_fmt_vid_cap() local
625 struct tw686x_dev *dev = vc->dev; in tw686x_g_fmt_vid_cap()
627 f->fmt.pix.width = vc->width; in tw686x_g_fmt_vid_cap()
628 f->fmt.pix.height = vc->height; in tw686x_g_fmt_vid_cap()
630 f->fmt.pix.pixelformat = vc->format->fourcc; in tw686x_g_fmt_vid_cap()
632 f->fmt.pix.bytesperline = (f->fmt.pix.width * vc->format->depth) / 8; in tw686x_g_fmt_vid_cap()
640 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_try_fmt_vid_cap() local
641 struct tw686x_dev *dev = vc->dev; in tw686x_try_fmt_vid_cap()
642 unsigned int video_height = TW686X_VIDEO_HEIGHT(vc->video_standard); in tw686x_try_fmt_vid_cap()
669 static int tw686x_set_format(struct tw686x_video_channel *vc, in tw686x_set_format() argument
673 struct tw686x_dev *dev = vc->dev; in tw686x_set_format()
677 vc->format = format_by_fourcc(pixelformat); in tw686x_set_format()
678 vc->width = width; in tw686x_set_format()
679 vc->height = height; in tw686x_set_format()
684 dev->dma_ops->free(vc, pb); in tw686x_set_format()
687 err = dev->dma_ops->alloc(vc, pb); in tw686x_set_format()
690 dev->dma_ops->free(vc, 0); in tw686x_set_format()
696 val = reg_read(vc->dev, VDMA_CHANNEL_CONFIG[vc->ch]); in tw686x_set_format()
698 if (vc->width <= TW686X_VIDEO_WIDTH / 2) in tw686x_set_format()
703 if (vc->height <= TW686X_VIDEO_HEIGHT(vc->video_standard) / 2) in tw686x_set_format()
715 0 : vc->ch * TW686X_MAX_SG_DESC_COUNT; in tw686x_set_format()
722 val |= vc->format->mode << 20; in tw686x_set_format()
723 reg_write(vc->dev, VDMA_CHANNEL_CONFIG[vc->ch], val); in tw686x_set_format()
726 dma_width = (vc->width * 2) & 0x7ff; in tw686x_set_format()
727 dma_height = vc->height / 2; in tw686x_set_format()
728 dma_line_width = (vc->width * 2) & 0x7ff; in tw686x_set_format()
730 reg_write(vc->dev, VDMA_WHP[vc->ch], val); in tw686x_set_format()
737 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_s_fmt_vid_cap() local
742 if (vb2_is_busy(&vc->vidq)) in tw686x_s_fmt_vid_cap()
745 area = vc->width * vc->height; in tw686x_s_fmt_vid_cap()
751 return tw686x_set_format(vc, f->fmt.pix.pixelformat, in tw686x_s_fmt_vid_cap()
759 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_querycap() local
760 struct tw686x_dev *dev = vc->dev; in tw686x_querycap()
767 static int tw686x_set_standard(struct tw686x_video_channel *vc, v4l2_std_id id) in tw686x_set_standard() argument
788 vc->video_standard = id; in tw686x_set_standard()
789 reg_write(vc->dev, SDT[vc->ch], val); in tw686x_set_standard()
791 val = reg_read(vc->dev, VIDEO_CONTROL1); in tw686x_set_standard()
793 val &= ~(1 << (SYS_MODE_DMA_SHIFT + vc->ch)); in tw686x_set_standard()
795 val |= (1 << (SYS_MODE_DMA_SHIFT + vc->ch)); in tw686x_set_standard()
796 reg_write(vc->dev, VIDEO_CONTROL1, val); in tw686x_set_standard()
803 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_s_std() local
807 if (vc->video_standard == id) in tw686x_s_std()
810 if (vb2_is_busy(&vc->vidq)) in tw686x_s_std()
813 ret = tw686x_set_standard(vc, id); in tw686x_s_std()
828 tw686x_set_framerate(vc, vc->fps); in tw686x_s_std()
834 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_querystd() local
835 struct tw686x_dev *dev = vc->dev; in tw686x_querystd()
839 if (vb2_is_streaming(&vc->vidq)) in tw686x_querystd()
843 old_std = reg_read(dev, SDT[vc->ch]); in tw686x_querystd()
844 reg_write(dev, SDT[vc->ch], 0x7); in tw686x_querystd()
845 reg_write(dev, SDT_EN[vc->ch], 0xff); in tw686x_querystd()
850 detected_std = reg_read(dev, SDT[vc->ch]); in tw686x_querystd()
855 reg_write(dev, SDT[vc->ch], old_std); in tw686x_querystd()
892 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_g_std() local
894 *id = vc->video_standard; in tw686x_g_std()
901 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_enum_framesizes() local
909 fsize->stepwise.max_height = TW686X_VIDEO_HEIGHT(vc->video_standard); in tw686x_enum_framesizes()
918 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_enum_frameintervals() local
919 int max_fps = TW686X_MAX_FPS(vc->video_standard); in tw686x_enum_frameintervals()
937 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_g_parm() local
946 cp->timeperframe.denominator = vc->fps; in tw686x_g_parm()
953 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_s_parm() local
959 if (vb2_is_busy(&vc->vidq)) in tw686x_s_parm()
963 if (vc->fps != fps) in tw686x_s_parm()
964 tw686x_set_framerate(vc, fps); in tw686x_s_parm()
977 static void tw686x_set_input(struct tw686x_video_channel *vc, unsigned int i) in tw686x_set_input() argument
981 vc->input = i; in tw686x_set_input()
983 val = reg_read(vc->dev, VDMA_CHANNEL_CONFIG[vc->ch]); in tw686x_set_input()
986 reg_write(vc->dev, VDMA_CHANNEL_CONFIG[vc->ch], val); in tw686x_set_input()
991 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_s_input() local
995 if (i == vc->input) in tw686x_s_input()
1000 if (vb2_is_busy(&vc->vidq)) in tw686x_s_input()
1003 tw686x_set_input(vc, i); in tw686x_s_input()
1009 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_g_input() local
1011 *i = vc->input; in tw686x_g_input()
1018 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_enum_input() local
1026 i->std = vc->device->tvnorms; in tw686x_enum_input()
1029 vidstat = reg_read(vc->dev, VIDSTAT[vc->ch]); in tw686x_enum_input()
1087 struct tw686x_video_channel *vc; in tw686x_video_irq() local
1092 vc = &dev->video_channels[ch]; in tw686x_video_irq()
1099 if (vc->no_signal && !(fifo_status & BIT(ch))) { in tw686x_video_irq()
1101 "video%d: signal recovered\n", vc->num); in tw686x_video_irq()
1102 vc->no_signal = false; in tw686x_video_irq()
1104 vc->pb = 0; in tw686x_video_irq()
1107 vc->no_signal = !!(fifo_status & BIT(ch)); in tw686x_video_irq()
1110 if (!vc->no_signal) { in tw686x_video_irq()
1118 "video%d: FIFO error\n", vc->num); in tw686x_video_irq()
1120 vc->pb = 0; in tw686x_video_irq()
1126 if (vc->pb != pb) { in tw686x_video_irq()
1130 vc->num); in tw686x_video_irq()
1132 vc->pb = 0; in tw686x_video_irq()
1136 spin_lock_irqsave(&vc->qlock, flags); in tw686x_video_irq()
1137 tw686x_buf_done(vc, pb); in tw686x_video_irq()
1138 dev->dma_ops->buf_refill(vc, pb); in tw686x_video_irq()
1139 spin_unlock_irqrestore(&vc->qlock, flags); in tw686x_video_irq()
1148 struct tw686x_video_channel *vc = &dev->video_channels[ch]; in tw686x_video_free() local
1150 video_unregister_device(vc->device); in tw686x_video_free()
1154 dev->dma_ops->free(vc, pb); in tw686x_video_free()
1182 /* Initialize vc->dev and vc->ch for the error path */ in tw686x_video_init()
1184 struct tw686x_video_channel *vc = &dev->video_channels[ch]; in tw686x_video_init() local
1186 vc->dev = dev; in tw686x_video_init()
1187 vc->ch = ch; in tw686x_video_init()
1191 struct tw686x_video_channel *vc = &dev->video_channels[ch]; in tw686x_video_init() local
1194 mutex_init(&vc->vb_mutex); in tw686x_video_init()
1195 spin_lock_init(&vc->qlock); in tw686x_video_init()
1196 INIT_LIST_HEAD(&vc->vidq_queued); in tw686x_video_init()
1199 err = tw686x_set_standard(vc, V4L2_STD_NTSC); in tw686x_video_init()
1203 err = tw686x_set_format(vc, formats[0].fourcc, in tw686x_video_init()
1205 TW686X_VIDEO_HEIGHT(vc->video_standard), in tw686x_video_init()
1210 tw686x_set_input(vc, 0); in tw686x_video_init()
1211 tw686x_set_framerate(vc, 30); in tw686x_video_init()
1216 vc->vidq.io_modes = VB2_READ | VB2_MMAP | VB2_DMABUF; in tw686x_video_init()
1217 vc->vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in tw686x_video_init()
1218 vc->vidq.drv_priv = vc; in tw686x_video_init()
1219 vc->vidq.buf_struct_size = sizeof(struct tw686x_v4l2_buf); in tw686x_video_init()
1220 vc->vidq.ops = &tw686x_video_qops; in tw686x_video_init()
1221 vc->vidq.mem_ops = dev->dma_ops->mem_ops; in tw686x_video_init()
1222 vc->vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in tw686x_video_init()
1223 vc->vidq.min_queued_buffers = 2; in tw686x_video_init()
1224 vc->vidq.lock = &vc->vb_mutex; in tw686x_video_init()
1225 vc->vidq.gfp_flags = dev->dma_mode != TW686X_DMA_MODE_MEMCPY ? in tw686x_video_init()
1227 vc->vidq.dev = &dev->pci_dev->dev; in tw686x_video_init()
1229 err = vb2_queue_init(&vc->vidq); in tw686x_video_init()
1236 err = v4l2_ctrl_handler_init(&vc->ctrl_handler, 4); in tw686x_video_init()
1242 v4l2_ctrl_new_std(&vc->ctrl_handler, &ctrl_ops, in tw686x_video_init()
1244 v4l2_ctrl_new_std(&vc->ctrl_handler, &ctrl_ops, in tw686x_video_init()
1246 v4l2_ctrl_new_std(&vc->ctrl_handler, &ctrl_ops, in tw686x_video_init()
1248 v4l2_ctrl_new_std(&vc->ctrl_handler, &ctrl_ops, in tw686x_video_init()
1250 err = vc->ctrl_handler.error; in tw686x_video_init()
1254 err = v4l2_ctrl_handler_setup(&vc->ctrl_handler); in tw686x_video_init()
1271 vdev->queue = &vc->vidq; in tw686x_video_init()
1274 vdev->lock = &vc->vb_mutex; in tw686x_video_init()
1275 vdev->ctrl_handler = &vc->ctrl_handler; in tw686x_video_init()
1278 vc->device = vdev; in tw686x_video_init()
1279 video_set_drvdata(vdev, vc); in tw686x_video_init()
1286 vc->num = vdev->num; in tw686x_video_init()