Lines Matching refs: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()
588 struct tw686x_video_channel *vc; in tw686x_s_ctrl() local
592 vc = container_of(ctrl->handler, struct tw686x_video_channel, in tw686x_s_ctrl()
594 dev = vc->dev; in tw686x_s_ctrl()
595 ch = vc->ch; in tw686x_s_ctrl()
626 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_g_fmt_vid_cap() local
627 struct tw686x_dev *dev = vc->dev; in tw686x_g_fmt_vid_cap()
629 f->fmt.pix.width = vc->width; in tw686x_g_fmt_vid_cap()
630 f->fmt.pix.height = vc->height; in tw686x_g_fmt_vid_cap()
632 f->fmt.pix.pixelformat = vc->format->fourcc; in tw686x_g_fmt_vid_cap()
634 f->fmt.pix.bytesperline = (f->fmt.pix.width * vc->format->depth) / 8; in tw686x_g_fmt_vid_cap()
642 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_try_fmt_vid_cap() local
643 struct tw686x_dev *dev = vc->dev; in tw686x_try_fmt_vid_cap()
644 unsigned int video_height = TW686X_VIDEO_HEIGHT(vc->video_standard); in tw686x_try_fmt_vid_cap()
671 static int tw686x_set_format(struct tw686x_video_channel *vc, in tw686x_set_format() argument
675 struct tw686x_dev *dev = vc->dev; in tw686x_set_format()
679 vc->format = format_by_fourcc(pixelformat); in tw686x_set_format()
680 vc->width = width; in tw686x_set_format()
681 vc->height = height; in tw686x_set_format()
686 dev->dma_ops->free(vc, pb); in tw686x_set_format()
689 err = dev->dma_ops->alloc(vc, pb); in tw686x_set_format()
692 dev->dma_ops->free(vc, 0); in tw686x_set_format()
698 val = reg_read(vc->dev, VDMA_CHANNEL_CONFIG[vc->ch]); in tw686x_set_format()
700 if (vc->width <= TW686X_VIDEO_WIDTH / 2) in tw686x_set_format()
705 if (vc->height <= TW686X_VIDEO_HEIGHT(vc->video_standard) / 2) in tw686x_set_format()
717 0 : vc->ch * TW686X_MAX_SG_DESC_COUNT; in tw686x_set_format()
724 val |= vc->format->mode << 20; in tw686x_set_format()
725 reg_write(vc->dev, VDMA_CHANNEL_CONFIG[vc->ch], val); in tw686x_set_format()
728 dma_width = (vc->width * 2) & 0x7ff; in tw686x_set_format()
729 dma_height = vc->height / 2; in tw686x_set_format()
730 dma_line_width = (vc->width * 2) & 0x7ff; in tw686x_set_format()
732 reg_write(vc->dev, VDMA_WHP[vc->ch], val); in tw686x_set_format()
739 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_s_fmt_vid_cap() local
744 if (vb2_is_busy(&vc->vidq)) in tw686x_s_fmt_vid_cap()
747 area = vc->width * vc->height; in tw686x_s_fmt_vid_cap()
753 return tw686x_set_format(vc, f->fmt.pix.pixelformat, in tw686x_s_fmt_vid_cap()
761 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_querycap() local
762 struct tw686x_dev *dev = vc->dev; in tw686x_querycap()
769 static int tw686x_set_standard(struct tw686x_video_channel *vc, v4l2_std_id id) in tw686x_set_standard() argument
790 vc->video_standard = id; in tw686x_set_standard()
791 reg_write(vc->dev, SDT[vc->ch], val); in tw686x_set_standard()
793 val = reg_read(vc->dev, VIDEO_CONTROL1); in tw686x_set_standard()
795 val &= ~(1 << (SYS_MODE_DMA_SHIFT + vc->ch)); in tw686x_set_standard()
797 val |= (1 << (SYS_MODE_DMA_SHIFT + vc->ch)); in tw686x_set_standard()
798 reg_write(vc->dev, VIDEO_CONTROL1, val); in tw686x_set_standard()
805 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_s_std() local
809 if (vc->video_standard == id) in tw686x_s_std()
812 if (vb2_is_busy(&vc->vidq)) in tw686x_s_std()
815 ret = tw686x_set_standard(vc, id); in tw686x_s_std()
830 tw686x_set_framerate(vc, vc->fps); in tw686x_s_std()
836 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_querystd() local
837 struct tw686x_dev *dev = vc->dev; in tw686x_querystd()
841 if (vb2_is_streaming(&vc->vidq)) in tw686x_querystd()
845 old_std = reg_read(dev, SDT[vc->ch]); in tw686x_querystd()
846 reg_write(dev, SDT[vc->ch], 0x7); in tw686x_querystd()
847 reg_write(dev, SDT_EN[vc->ch], 0xff); in tw686x_querystd()
852 detected_std = reg_read(dev, SDT[vc->ch]); in tw686x_querystd()
857 reg_write(dev, SDT[vc->ch], old_std); in tw686x_querystd()
894 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_g_std() local
896 *id = vc->video_standard; in tw686x_g_std()
903 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_enum_framesizes() local
911 fsize->stepwise.max_height = TW686X_VIDEO_HEIGHT(vc->video_standard); in tw686x_enum_framesizes()
920 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_enum_frameintervals() local
921 int max_fps = TW686X_MAX_FPS(vc->video_standard); in tw686x_enum_frameintervals()
939 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_g_parm() local
948 cp->timeperframe.denominator = vc->fps; in tw686x_g_parm()
955 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_s_parm() local
961 if (vb2_is_busy(&vc->vidq)) in tw686x_s_parm()
965 if (vc->fps != fps) in tw686x_s_parm()
966 tw686x_set_framerate(vc, fps); in tw686x_s_parm()
979 static void tw686x_set_input(struct tw686x_video_channel *vc, unsigned int i) in tw686x_set_input() argument
983 vc->input = i; in tw686x_set_input()
985 val = reg_read(vc->dev, VDMA_CHANNEL_CONFIG[vc->ch]); in tw686x_set_input()
988 reg_write(vc->dev, VDMA_CHANNEL_CONFIG[vc->ch], val); in tw686x_set_input()
993 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_s_input() local
997 if (i == vc->input) in tw686x_s_input()
1002 if (vb2_is_busy(&vc->vidq)) in tw686x_s_input()
1005 tw686x_set_input(vc, i); in tw686x_s_input()
1011 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_g_input() local
1013 *i = vc->input; in tw686x_g_input()
1020 struct tw686x_video_channel *vc = video_drvdata(file); in tw686x_enum_input() local
1028 i->std = vc->device->tvnorms; in tw686x_enum_input()
1031 vidstat = reg_read(vc->dev, VIDSTAT[vc->ch]); in tw686x_enum_input()
1089 struct tw686x_video_channel *vc; in tw686x_video_irq() local
1094 vc = &dev->video_channels[ch]; in tw686x_video_irq()
1101 if (vc->no_signal && !(fifo_status & BIT(ch))) { in tw686x_video_irq()
1103 "video%d: signal recovered\n", vc->num); in tw686x_video_irq()
1104 vc->no_signal = false; in tw686x_video_irq()
1106 vc->pb = 0; in tw686x_video_irq()
1109 vc->no_signal = !!(fifo_status & BIT(ch)); in tw686x_video_irq()
1112 if (!vc->no_signal) { in tw686x_video_irq()
1120 "video%d: FIFO error\n", vc->num); in tw686x_video_irq()
1122 vc->pb = 0; in tw686x_video_irq()
1128 if (vc->pb != pb) { in tw686x_video_irq()
1132 vc->num); in tw686x_video_irq()
1134 vc->pb = 0; in tw686x_video_irq()
1138 spin_lock_irqsave(&vc->qlock, flags); in tw686x_video_irq()
1139 tw686x_buf_done(vc, pb); in tw686x_video_irq()
1140 dev->dma_ops->buf_refill(vc, pb); in tw686x_video_irq()
1141 spin_unlock_irqrestore(&vc->qlock, flags); in tw686x_video_irq()
1150 struct tw686x_video_channel *vc = &dev->video_channels[ch]; in tw686x_video_free() local
1152 video_unregister_device(vc->device); in tw686x_video_free()
1156 dev->dma_ops->free(vc, pb); in tw686x_video_free()
1186 struct tw686x_video_channel *vc = &dev->video_channels[ch]; in tw686x_video_init() local
1188 vc->dev = dev; in tw686x_video_init()
1189 vc->ch = ch; in tw686x_video_init()
1193 struct tw686x_video_channel *vc = &dev->video_channels[ch]; in tw686x_video_init() local
1196 mutex_init(&vc->vb_mutex); in tw686x_video_init()
1197 spin_lock_init(&vc->qlock); in tw686x_video_init()
1198 INIT_LIST_HEAD(&vc->vidq_queued); in tw686x_video_init()
1201 err = tw686x_set_standard(vc, V4L2_STD_NTSC); in tw686x_video_init()
1205 err = tw686x_set_format(vc, formats[0].fourcc, in tw686x_video_init()
1207 TW686X_VIDEO_HEIGHT(vc->video_standard), in tw686x_video_init()
1212 tw686x_set_input(vc, 0); in tw686x_video_init()
1213 tw686x_set_framerate(vc, 30); in tw686x_video_init()
1218 vc->vidq.io_modes = VB2_READ | VB2_MMAP | VB2_DMABUF; in tw686x_video_init()
1219 vc->vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in tw686x_video_init()
1220 vc->vidq.drv_priv = vc; in tw686x_video_init()
1221 vc->vidq.buf_struct_size = sizeof(struct tw686x_v4l2_buf); in tw686x_video_init()
1222 vc->vidq.ops = &tw686x_video_qops; in tw686x_video_init()
1223 vc->vidq.mem_ops = dev->dma_ops->mem_ops; in tw686x_video_init()
1224 vc->vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in tw686x_video_init()
1225 vc->vidq.min_queued_buffers = 2; in tw686x_video_init()
1226 vc->vidq.lock = &vc->vb_mutex; in tw686x_video_init()
1227 vc->vidq.gfp_flags = dev->dma_mode != TW686X_DMA_MODE_MEMCPY ? in tw686x_video_init()
1229 vc->vidq.dev = &dev->pci_dev->dev; in tw686x_video_init()
1231 err = vb2_queue_init(&vc->vidq); in tw686x_video_init()
1238 err = v4l2_ctrl_handler_init(&vc->ctrl_handler, 4); 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 v4l2_ctrl_new_std(&vc->ctrl_handler, &ctrl_ops, in tw686x_video_init()
1252 err = vc->ctrl_handler.error; in tw686x_video_init()
1256 err = v4l2_ctrl_handler_setup(&vc->ctrl_handler); in tw686x_video_init()
1273 vdev->queue = &vc->vidq; in tw686x_video_init()
1276 vdev->lock = &vc->vb_mutex; in tw686x_video_init()
1277 vdev->ctrl_handler = &vc->ctrl_handler; in tw686x_video_init()
1280 vc->device = vdev; in tw686x_video_init()
1281 video_set_drvdata(vdev, vc); in tw686x_video_init()
1288 vc->num = vdev->num; in tw686x_video_init()