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, GFP_KERNEL);
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];
284 vc->ch, pb ? "B" : "P");
291 vc->ch * TW686X_SG_TABLE_SIZE;
294 vc->sg_descs[pb] = virt;
320 struct tw686x_video_channel *vc = &dev->video_channels[ch];
323 vc->dma_descs[pb].size = sg_table_size;
401 static void tw686x_set_framerate(struct tw686x_video_channel *vc,
406 i = tw686x_fps_idx(fps, TW686X_MAX_FPS(vc->video_standard));
407 reg_write(vc->dev, VIDEO_FIELD_CTRL[vc->ch], fps_map[i]);
408 vc->fps = tw686x_real_fps(i, TW686X_MAX_FPS(vc->video_standard));
425 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;
769 static int tw686x_set_standard(struct tw686x_video_channel *vc, v4l2_std_id id)
790 vc->video_standard = id;
791 reg_write(vc->dev, SDT[vc->ch], val);
793 val = reg_read(vc->dev, VIDEO_CONTROL1);
795 val &= ~(1 << (SYS_MODE_DMA_SHIFT + vc->ch));
797 val |= (1 << (SYS_MODE_DMA_SHIFT + vc->ch));
798 reg_write(vc->dev, VIDEO_CONTROL1, val);
805 struct tw686x_video_channel *vc = video_drvdata(file);
809 if (vc->video_standard == id)
812 if (vb2_is_busy(&vc->vidq))
815 ret = tw686x_set_standard(vc, id);
830 tw686x_set_framerate(vc, vc->fps);
836 struct tw686x_video_channel *vc = video_drvdata(file);
837 struct tw686x_dev *dev = vc->dev;
841 if (vb2_is_streaming(&vc->vidq))
845 old_std = reg_read(dev, SDT[vc->ch]);
846 reg_write(dev, SDT[vc->ch], 0x7);
847 reg_write(dev, SDT_EN[vc->ch], 0xff);
852 detected_std = reg_read(dev, SDT[vc->ch]);
857 reg_write(dev, SDT[vc->ch], old_std);
894 struct tw686x_video_channel *vc = video_drvdata(file);
896 *id = vc->video_standard;
903 struct tw686x_video_channel *vc = video_drvdata(file);
911 fsize->stepwise.max_height = TW686X_VIDEO_HEIGHT(vc->video_standard);
920 struct tw686x_video_channel *vc = video_drvdata(file);
921 int max_fps = TW686X_MAX_FPS(vc->video_standard);
939 struct tw686x_video_channel *vc = video_drvdata(file);
948 cp->timeperframe.denominator = vc->fps;
955 struct tw686x_video_channel *vc = video_drvdata(file);
961 if (vb2_is_busy(&vc->vidq))
965 if (vc->fps != fps)
966 tw686x_set_framerate(vc, fps);
979 static void tw686x_set_input(struct tw686x_video_channel *vc, unsigned int i)
983 vc->input = i;
985 val = reg_read(vc->dev, VDMA_CHANNEL_CONFIG[vc->ch]);
988 reg_write(vc->dev, VDMA_CHANNEL_CONFIG[vc->ch], val);
993 struct tw686x_video_channel *vc = video_drvdata(file);
997 if (i == vc->input)
1002 if (vb2_is_busy(&vc->vidq))
1005 tw686x_set_input(vc, i);
1011 struct tw686x_video_channel *vc = video_drvdata(file);
1013 *i = vc->input;
1020 struct tw686x_video_channel *vc = video_drvdata(file);
1028 i->std = vc->device->tvnorms;
1031 vidstat = reg_read(vc->dev, VIDSTAT[vc->ch]);
1089 struct tw686x_video_channel *vc;
1094 vc = &dev->video_channels[ch];
1101 if (vc->no_signal && !(fifo_status & BIT(ch))) {
1103 "video%d: signal recovered\n", vc->num);
1104 vc->no_signal = false;
1106 vc->pb = 0;
1109 vc->no_signal = !!(fifo_status & BIT(ch));
1112 if (!vc->no_signal) {
1120 "video%d: FIFO error\n", vc->num);
1122 vc->pb = 0;
1128 if (vc->pb != pb) {
1132 vc->num);
1134 vc->pb = 0;
1138 spin_lock_irqsave(&vc->qlock, flags);
1139 tw686x_buf_done(vc, pb);
1140 dev->dma_ops->buf_refill(vc, pb);
1141 spin_unlock_irqrestore(&vc->qlock, flags);
1150 struct tw686x_video_channel *vc = &dev->video_channels[ch];
1152 video_unregister_device(vc->device);
1156 dev->dma_ops->free(vc, pb);
1184 /* Initialize vc->dev and vc->ch for the error path */
1186 struct tw686x_video_channel *vc = &dev->video_channels[ch];
1188 vc->dev = dev;
1189 vc->ch = ch;
1193 struct tw686x_video_channel *vc = &dev->video_channels[ch];
1196 mutex_init(&vc->vb_mutex);
1197 spin_lock_init(&vc->qlock);
1198 INIT_LIST_HEAD(&vc->vidq_queued);
1201 err = tw686x_set_standard(vc, V4L2_STD_NTSC);
1205 err = tw686x_set_format(vc, formats[0].fourcc,
1207 TW686X_VIDEO_HEIGHT(vc->video_standard),
1212 tw686x_set_input(vc, 0);
1213 tw686x_set_framerate(vc, 30);
1218 vc->vidq.io_modes = VB2_READ | VB2_MMAP | VB2_DMABUF;
1219 vc->vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1220 vc->vidq.drv_priv = vc;
1221 vc->vidq.buf_struct_size = sizeof(struct tw686x_v4l2_buf);
1222 vc->vidq.ops = &tw686x_video_qops;
1223 vc->vidq.mem_ops = dev->dma_ops->mem_ops;
1224 vc->vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1225 vc->vidq.min_queued_buffers = 2;
1226 vc->vidq.lock = &vc->vb_mutex;
1227 vc->vidq.gfp_flags = dev->dma_mode != TW686X_DMA_MODE_MEMCPY ?
1229 vc->vidq.dev = &dev->pci_dev->dev;
1231 err = vb2_queue_init(&vc->vidq);
1238 err = v4l2_ctrl_handler_init(&vc->ctrl_handler, 4);
1244 v4l2_ctrl_new_std(&vc->ctrl_handler, &ctrl_ops,
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 err = vc->ctrl_handler.error;
1256 err = v4l2_ctrl_handler_setup(&vc->ctrl_handler);
1273 vdev->queue = &vc->vidq;
1276 vdev->lock = &vc->vb_mutex;
1277 vdev->ctrl_handler = &vc->ctrl_handler;
1280 vc->device = vdev;
1281 video_set_drvdata(vdev, vc);
1288 vc->num = vdev->num;