Lines Matching refs:vc
49 static void tw686x_buf_done(struct tw686x_video_channel *vc,
52 struct tw686x_dma_desc *desc = &vc->dma_descs[pb];
53 struct tw686x_dev *dev = vc->dev;
57 if (vc->curr_bufs[pb]) {
58 vb = &vc->curr_bufs[pb]->vb;
61 vb->sequence = vc->sequence++;
71 vc->pb = !pb;
77 static void tw686x_memcpy_dma_free(struct tw686x_video_channel *vc,
80 struct tw686x_dma_desc *desc = &vc->dma_descs[pb];
81 struct tw686x_dev *dev = vc->dev;
101 static int tw686x_memcpy_dma_alloc(struct tw686x_video_channel *vc,
104 struct tw686x_dev *dev = vc->dev;
105 u32 reg = pb ? VDMA_B_ADDR[vc->ch] : VDMA_P_ADDR[vc->ch];
109 WARN(vc->dma_descs[pb].virt,
112 len = (vc->width * vc->height * vc->format->depth) >> 3;
114 &vc->dma_descs[pb].phys);
118 vc->ch, pb ? "B" : "P");
121 vc->dma_descs[pb].size = len;
122 vc->dma_descs[pb].virt = virt;
123 reg_write(dev, reg, vc->dma_descs[pb].phys);
128 static void tw686x_memcpy_buf_refill(struct tw686x_video_channel *vc,
133 while (!list_empty(&vc->vidq_queued)) {
135 buf = list_first_entry(&vc->vidq_queued,
139 vc->curr_bufs[pb] = buf;
142 vc->curr_bufs[pb] = NULL;
154 static void tw686x_contig_buf_refill(struct tw686x_video_channel *vc,
159 while (!list_empty(&vc->vidq_queued)) {
160 u32 reg = pb ? VDMA_B_ADDR[vc->ch] : VDMA_P_ADDR[vc->ch];
163 buf = list_first_entry(&vc->vidq_queued,
168 reg_write(vc->dev, reg, phys);
171 vc->curr_bufs[pb] = buf;
174 vc->curr_bufs[pb] = NULL;
224 static void tw686x_sg_buf_refill(struct tw686x_video_channel *vc,
227 struct tw686x_dev *dev = vc->dev;
230 while (!list_empty(&vc->vidq_queued)) {
233 buf = list_first_entry(&vc->vidq_queued,
237 buf_len = (vc->width * vc->height * vc->format->depth) >> 3;
238 if (tw686x_sg_desc_fill(vc->sg_descs[pb], buf, buf_len)) {
241 vc->ch, pb ? "B" : "P");
247 vc->curr_bufs[pb] = buf;
251 vc->curr_bufs[pb] = NULL;
254 static void tw686x_sg_dma_free(struct tw686x_video_channel *vc,
257 struct tw686x_dma_desc *desc = &vc->dma_descs[pb];
258 struct tw686x_dev *dev = vc->dev;
266 vc->sg_descs[pb] = NULL;
269 static int tw686x_sg_dma_alloc(struct tw686x_video_channel *vc,
272 struct tw686x_dma_desc *desc = &vc->dma_descs[pb];
273 struct tw686x_dev *dev = vc->dev;
274 u32 reg = pb ? DMA_PAGE_TABLE1_ADDR[vc->ch] :
275 DMA_PAGE_TABLE0_ADDR[vc->ch];
285 vc->ch, pb ? "B" : "P");
292 vc->ch * TW686X_SG_TABLE_SIZE;
295 vc->sg_descs[pb] = virt;
321 struct tw686x_video_channel *vc = &dev->video_channels[ch];
324 vc->dma_descs[pb].size = sg_table_size;
402 static void tw686x_set_framerate(struct tw686x_video_channel *vc,
407 i = tw686x_fps_idx(fps, TW686X_MAX_FPS(vc->video_standard));
408 reg_write(vc->dev, VIDEO_FIELD_CTRL[vc->ch], fps_map[i]);
409 vc->fps = tw686x_real_fps(i, TW686X_MAX_FPS(vc->video_standard));
426 struct tw686x_video_channel *vc = vb2_get_drv_priv(vq);
428 (vc->width * vc->height * vc->format->depth) >> 3;
450 struct tw686x_video_channel *vc = vb2_get_drv_priv(vb->vb2_queue);
451 struct tw686x_dev *dev = vc->dev;
467 spin_lock_irqsave(&vc->qlock, flags);
468 list_add_tail(&buf->list, &vc->vidq_queued);
469 spin_unlock_irqrestore(&vc->qlock, flags);
472 static void tw686x_clear_queue(struct tw686x_video_channel *vc,
477 while (!list_empty(&vc->vidq_queued)) {
480 buf = list_first_entry(&vc->vidq_queued,
487 if (vc->curr_bufs[pb])
488 vb2_buffer_done(&vc->curr_bufs[pb]->vb.vb2_buf, state);
489 vc->curr_bufs[pb] = NULL;
495 struct tw686x_video_channel *vc = vb2_get_drv_priv(vq);
496 struct tw686x_dev *dev = vc->dev;
510 spin_lock_irqsave(&vc->qlock, flags);
514 (!vc->dma_descs[0].virt || !vc->dma_descs[1].virt)) {
515 spin_unlock_irqrestore(&vc->qlock, flags);
518 vc->num);
524 dev->dma_ops->buf_refill(vc, pb);
525 spin_unlock_irqrestore(&vc->qlock, flags);
527 vc->sequence = 0;
528 vc->pb = 0;
531 tw686x_enable_channel(dev, vc->ch);
539 spin_lock_irqsave(&vc->qlock, flags);
540 tw686x_clear_queue(vc, VB2_BUF_STATE_QUEUED);
541 spin_unlock_irqrestore(&vc->qlock, flags);
547 struct tw686x_video_channel *vc = vb2_get_drv_priv(vq);
548 struct tw686x_dev *dev = vc->dev;
557 tw686x_disable_channel(dev, vc->ch);
559 spin_lock_irqsave(&vc->qlock, flags);
560 tw686x_clear_queue(vc, VB2_BUF_STATE_ERROR);
561 spin_unlock_irqrestore(&vc->qlock, flags);
566 struct tw686x_video_channel *vc = vb2_get_drv_priv(vb->vb2_queue);
568 (vc->width * vc->height * vc->format->depth) >> 3;
588 struct tw686x_video_channel *vc;
592 vc = container_of(ctrl->handler, struct tw686x_video_channel,
594 dev = vc->dev;
595 ch = vc->ch;
626 struct tw686x_video_channel *vc = video_drvdata(file);
627 struct tw686x_dev *dev = vc->dev;
629 f->fmt.pix.width = vc->width;
630 f->fmt.pix.height = vc->height;
632 f->fmt.pix.pixelformat = vc->format->fourcc;
634 f->fmt.pix.bytesperline = (f->fmt.pix.width * vc->format->depth) / 8;
642 struct tw686x_video_channel *vc = video_drvdata(file);
643 struct tw686x_dev *dev = vc->dev;
644 unsigned int video_height = TW686X_VIDEO_HEIGHT(vc->video_standard);
671 static int tw686x_set_format(struct tw686x_video_channel *vc,
675 struct tw686x_dev *dev = vc->dev;
679 vc->format = format_by_fourcc(pixelformat);
680 vc->width = width;
681 vc->height = height;
686 dev->dma_ops->free(vc, pb);
689 err = dev->dma_ops->alloc(vc, pb);
692 dev->dma_ops->free(vc, 0);
698 val = reg_read(vc->dev, VDMA_CHANNEL_CONFIG[vc->ch]);
700 if (vc->width <= TW686X_VIDEO_WIDTH / 2)
705 if (vc->height <= TW686X_VIDEO_HEIGHT(vc->video_standard) / 2)
717 0 : vc->ch * TW686X_MAX_SG_DESC_COUNT;
724 val |= vc->format->mode << 20;
725 reg_write(vc->dev, VDMA_CHANNEL_CONFIG[vc->ch], val);
728 dma_width = (vc->width * 2) & 0x7ff;
729 dma_height = vc->height / 2;
730 dma_line_width = (vc->width * 2) & 0x7ff;
732 reg_write(vc->dev, VDMA_WHP[vc->ch], val);
739 struct tw686x_video_channel *vc = video_drvdata(file);
744 if (vb2_is_busy(&vc->vidq))
747 area = vc->width * vc->height;
753 return tw686x_set_format(vc, f->fmt.pix.pixelformat,
761 struct tw686x_video_channel *vc = video_drvdata(file);
762 struct tw686x_dev *dev = vc->dev;
771 static int tw686x_set_standard(struct tw686x_video_channel *vc, v4l2_std_id id)
792 vc->video_standard = id;
793 reg_write(vc->dev, SDT[vc->ch], val);
795 val = reg_read(vc->dev, VIDEO_CONTROL1);
797 val &= ~(1 << (SYS_MODE_DMA_SHIFT + vc->ch));
799 val |= (1 << (SYS_MODE_DMA_SHIFT + vc->ch));
800 reg_write(vc->dev, VIDEO_CONTROL1, val);
807 struct tw686x_video_channel *vc = video_drvdata(file);
811 if (vc->video_standard == id)
814 if (vb2_is_busy(&vc->vidq))
817 ret = tw686x_set_standard(vc, id);
832 tw686x_set_framerate(vc, vc->fps);
838 struct tw686x_video_channel *vc = video_drvdata(file);
839 struct tw686x_dev *dev = vc->dev;
843 if (vb2_is_streaming(&vc->vidq))
847 old_std = reg_read(dev, SDT[vc->ch]);
848 reg_write(dev, SDT[vc->ch], 0x7);
849 reg_write(dev, SDT_EN[vc->ch], 0xff);
854 detected_std = reg_read(dev, SDT[vc->ch]);
859 reg_write(dev, SDT[vc->ch], old_std);
896 struct tw686x_video_channel *vc = video_drvdata(file);
898 *id = vc->video_standard;
905 struct tw686x_video_channel *vc = video_drvdata(file);
913 fsize->stepwise.max_height = TW686X_VIDEO_HEIGHT(vc->video_standard);
922 struct tw686x_video_channel *vc = video_drvdata(file);
923 int max_fps = TW686X_MAX_FPS(vc->video_standard);
941 struct tw686x_video_channel *vc = video_drvdata(file);
950 cp->timeperframe.denominator = vc->fps;
957 struct tw686x_video_channel *vc = video_drvdata(file);
963 if (vb2_is_busy(&vc->vidq))
967 if (vc->fps != fps)
968 tw686x_set_framerate(vc, fps);
981 static void tw686x_set_input(struct tw686x_video_channel *vc, unsigned int i)
985 vc->input = i;
987 val = reg_read(vc->dev, VDMA_CHANNEL_CONFIG[vc->ch]);
990 reg_write(vc->dev, VDMA_CHANNEL_CONFIG[vc->ch], val);
995 struct tw686x_video_channel *vc = video_drvdata(file);
999 if (i == vc->input)
1004 if (vb2_is_busy(&vc->vidq))
1007 tw686x_set_input(vc, i);
1013 struct tw686x_video_channel *vc = video_drvdata(file);
1015 *i = vc->input;
1022 struct tw686x_video_channel *vc = video_drvdata(file);
1030 i->std = vc->device->tvnorms;
1033 vidstat = reg_read(vc->dev, VIDSTAT[vc->ch]);
1091 struct tw686x_video_channel *vc;
1096 vc = &dev->video_channels[ch];
1103 if (vc->no_signal && !(fifo_status & BIT(ch))) {
1105 "video%d: signal recovered\n", vc->num);
1106 vc->no_signal = false;
1108 vc->pb = 0;
1111 vc->no_signal = !!(fifo_status & BIT(ch));
1114 if (!vc->no_signal) {
1122 "video%d: FIFO error\n", vc->num);
1124 vc->pb = 0;
1130 if (vc->pb != pb) {
1134 vc->num);
1136 vc->pb = 0;
1140 spin_lock_irqsave(&vc->qlock, flags);
1141 tw686x_buf_done(vc, pb);
1142 dev->dma_ops->buf_refill(vc, pb);
1143 spin_unlock_irqrestore(&vc->qlock, flags);
1152 struct tw686x_video_channel *vc = &dev->video_channels[ch];
1154 video_unregister_device(vc->device);
1158 dev->dma_ops->free(vc, pb);
1186 /* Initialize vc->dev and vc->ch for the error path */
1188 struct tw686x_video_channel *vc = &dev->video_channels[ch];
1190 vc->dev = dev;
1191 vc->ch = ch;
1195 struct tw686x_video_channel *vc = &dev->video_channels[ch];
1198 mutex_init(&vc->vb_mutex);
1199 spin_lock_init(&vc->qlock);
1200 INIT_LIST_HEAD(&vc->vidq_queued);
1203 err = tw686x_set_standard(vc, V4L2_STD_NTSC);
1207 err = tw686x_set_format(vc, formats[0].fourcc,
1209 TW686X_VIDEO_HEIGHT(vc->video_standard),
1214 tw686x_set_input(vc, 0);
1215 tw686x_set_framerate(vc, 30);
1220 vc->vidq.io_modes = VB2_READ | VB2_MMAP | VB2_DMABUF;
1221 vc->vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1222 vc->vidq.drv_priv = vc;
1223 vc->vidq.buf_struct_size = sizeof(struct tw686x_v4l2_buf);
1224 vc->vidq.ops = &tw686x_video_qops;
1225 vc->vidq.mem_ops = dev->dma_ops->mem_ops;
1226 vc->vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1227 vc->vidq.min_buffers_needed = 2;
1228 vc->vidq.lock = &vc->vb_mutex;
1229 vc->vidq.gfp_flags = dev->dma_mode != TW686X_DMA_MODE_MEMCPY ?
1231 vc->vidq.dev = &dev->pci_dev->dev;
1233 err = vb2_queue_init(&vc->vidq);
1240 err = v4l2_ctrl_handler_init(&vc->ctrl_handler, 4);
1246 v4l2_ctrl_new_std(&vc->ctrl_handler, &ctrl_ops,
1248 v4l2_ctrl_new_std(&vc->ctrl_handler, &ctrl_ops,
1250 v4l2_ctrl_new_std(&vc->ctrl_handler, &ctrl_ops,
1252 v4l2_ctrl_new_std(&vc->ctrl_handler, &ctrl_ops,
1254 err = vc->ctrl_handler.error;
1258 err = v4l2_ctrl_handler_setup(&vc->ctrl_handler);
1275 vdev->queue = &vc->vidq;
1278 vdev->lock = &vc->vb_mutex;
1279 vdev->ctrl_handler = &vc->ctrl_handler;
1282 vc->device = vdev;
1283 video_set_drvdata(vdev, vc);
1290 vc->num = vdev->num;