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);
427 (vc->width * vc->height * vc->format->depth) >> 3;
449 struct tw686x_video_channel *vc = vb2_get_drv_priv(vb->vb2_queue);
450 struct tw686x_dev *dev = vc->dev;
466 spin_lock_irqsave(&vc->qlock, flags);
467 list_add_tail(&buf->list, &vc->vidq_queued);
468 spin_unlock_irqrestore(&vc->qlock, flags);
471 static void tw686x_clear_queue(struct tw686x_video_channel *vc,
476 while (!list_empty(&vc->vidq_queued)) {
479 buf = list_first_entry(&vc->vidq_queued,
486 if (vc->curr_bufs[pb])
487 vb2_buffer_done(&vc->curr_bufs[pb]->vb.vb2_buf, state);
488 vc->curr_bufs[pb] = NULL;
494 struct tw686x_video_channel *vc = vb2_get_drv_priv(vq);
495 struct tw686x_dev *dev = vc->dev;
509 spin_lock_irqsave(&vc->qlock, flags);
513 (!vc->dma_descs[0].virt || !vc->dma_descs[1].virt)) {
514 spin_unlock_irqrestore(&vc->qlock, flags);
517 vc->num);
523 dev->dma_ops->buf_refill(vc, pb);
524 spin_unlock_irqrestore(&vc->qlock, flags);
526 vc->sequence = 0;
527 vc->pb = 0;
530 tw686x_enable_channel(dev, vc->ch);
538 spin_lock_irqsave(&vc->qlock, flags);
539 tw686x_clear_queue(vc, VB2_BUF_STATE_QUEUED);
540 spin_unlock_irqrestore(&vc->qlock, flags);
546 struct tw686x_video_channel *vc = vb2_get_drv_priv(vq);
547 struct tw686x_dev *dev = vc->dev;
556 tw686x_disable_channel(dev, vc->ch);
558 spin_lock_irqsave(&vc->qlock, flags);
559 tw686x_clear_queue(vc, VB2_BUF_STATE_ERROR);
560 spin_unlock_irqrestore(&vc->qlock, flags);
565 struct tw686x_video_channel *vc = vb2_get_drv_priv(vb->vb2_queue);
567 (vc->width * vc->height * vc->format->depth) >> 3;
587 struct tw686x_video_channel *vc;
591 vc = container_of(ctrl->handler, struct tw686x_video_channel,
593 dev = vc->dev;
594 ch = vc->ch;
625 struct tw686x_video_channel *vc = video_drvdata(file);
626 struct tw686x_dev *dev = vc->dev;
628 f->fmt.pix.width = vc->width;
629 f->fmt.pix.height = vc->height;
631 f->fmt.pix.pixelformat = vc->format->fourcc;
633 f->fmt.pix.bytesperline = (f->fmt.pix.width * vc->format->depth) / 8;
641 struct tw686x_video_channel *vc = video_drvdata(file);
642 struct tw686x_dev *dev = vc->dev;
643 unsigned int video_height = TW686X_VIDEO_HEIGHT(vc->video_standard);
670 static int tw686x_set_format(struct tw686x_video_channel *vc,
674 struct tw686x_dev *dev = vc->dev;
678 vc->format = format_by_fourcc(pixelformat);
679 vc->width = width;
680 vc->height = height;
685 dev->dma_ops->free(vc, pb);
688 err = dev->dma_ops->alloc(vc, pb);
691 dev->dma_ops->free(vc, 0);
697 val = reg_read(vc->dev, VDMA_CHANNEL_CONFIG[vc->ch]);
699 if (vc->width <= TW686X_VIDEO_WIDTH / 2)
704 if (vc->height <= TW686X_VIDEO_HEIGHT(vc->video_standard) / 2)
716 0 : vc->ch * TW686X_MAX_SG_DESC_COUNT;
723 val |= vc->format->mode << 20;
724 reg_write(vc->dev, VDMA_CHANNEL_CONFIG[vc->ch], val);
727 dma_width = (vc->width * 2) & 0x7ff;
728 dma_height = vc->height / 2;
729 dma_line_width = (vc->width * 2) & 0x7ff;
731 reg_write(vc->dev, VDMA_WHP[vc->ch], val);
738 struct tw686x_video_channel *vc = video_drvdata(file);
743 if (vb2_is_busy(&vc->vidq))
746 area = vc->width * vc->height;
752 return tw686x_set_format(vc, f->fmt.pix.pixelformat,
760 struct tw686x_video_channel *vc = video_drvdata(file);
761 struct tw686x_dev *dev = vc->dev;
768 static int tw686x_set_standard(struct tw686x_video_channel *vc, v4l2_std_id id)
789 vc->video_standard = id;
790 reg_write(vc->dev, SDT[vc->ch], val);
792 val = reg_read(vc->dev, VIDEO_CONTROL1);
794 val &= ~(1 << (SYS_MODE_DMA_SHIFT + vc->ch));
796 val |= (1 << (SYS_MODE_DMA_SHIFT + vc->ch));
797 reg_write(vc->dev, VIDEO_CONTROL1, val);
804 struct tw686x_video_channel *vc = video_drvdata(file);
808 if (vc->video_standard == id)
811 if (vb2_is_busy(&vc->vidq))
814 ret = tw686x_set_standard(vc, id);
829 tw686x_set_framerate(vc, vc->fps);
835 struct tw686x_video_channel *vc = video_drvdata(file);
836 struct tw686x_dev *dev = vc->dev;
840 if (vb2_is_streaming(&vc->vidq))
844 old_std = reg_read(dev, SDT[vc->ch]);
845 reg_write(dev, SDT[vc->ch], 0x7);
846 reg_write(dev, SDT_EN[vc->ch], 0xff);
851 detected_std = reg_read(dev, SDT[vc->ch]);
856 reg_write(dev, SDT[vc->ch], old_std);
893 struct tw686x_video_channel *vc = video_drvdata(file);
895 *id = vc->video_standard;
902 struct tw686x_video_channel *vc = video_drvdata(file);
910 fsize->stepwise.max_height = TW686X_VIDEO_HEIGHT(vc->video_standard);
919 struct tw686x_video_channel *vc = video_drvdata(file);
920 int max_fps = TW686X_MAX_FPS(vc->video_standard);
938 struct tw686x_video_channel *vc = video_drvdata(file);
947 cp->timeperframe.denominator = vc->fps;
954 struct tw686x_video_channel *vc = video_drvdata(file);
960 if (vb2_is_busy(&vc->vidq))
964 if (vc->fps != fps)
965 tw686x_set_framerate(vc, fps);
978 static void tw686x_set_input(struct tw686x_video_channel *vc, unsigned int i)
982 vc->input = i;
984 val = reg_read(vc->dev, VDMA_CHANNEL_CONFIG[vc->ch]);
987 reg_write(vc->dev, VDMA_CHANNEL_CONFIG[vc->ch], val);
992 struct tw686x_video_channel *vc = video_drvdata(file);
996 if (i == vc->input)
1001 if (vb2_is_busy(&vc->vidq))
1004 tw686x_set_input(vc, i);
1010 struct tw686x_video_channel *vc = video_drvdata(file);
1012 *i = vc->input;
1019 struct tw686x_video_channel *vc = video_drvdata(file);
1027 i->std = vc->device->tvnorms;
1030 vidstat = reg_read(vc->dev, VIDSTAT[vc->ch]);
1088 struct tw686x_video_channel *vc;
1093 vc = &dev->video_channels[ch];
1100 if (vc->no_signal && !(fifo_status & BIT(ch))) {
1102 "video%d: signal recovered\n", vc->num);
1103 vc->no_signal = false;
1105 vc->pb = 0;
1108 vc->no_signal = !!(fifo_status & BIT(ch));
1111 if (!vc->no_signal) {
1119 "video%d: FIFO error\n", vc->num);
1121 vc->pb = 0;
1127 if (vc->pb != pb) {
1131 vc->num);
1133 vc->pb = 0;
1137 spin_lock_irqsave(&vc->qlock, flags);
1138 tw686x_buf_done(vc, pb);
1139 dev->dma_ops->buf_refill(vc, pb);
1140 spin_unlock_irqrestore(&vc->qlock, flags);
1149 struct tw686x_video_channel *vc = &dev->video_channels[ch];
1151 video_unregister_device(vc->device);
1155 dev->dma_ops->free(vc, pb);
1183 /* Initialize vc->dev and vc->ch for the error path */
1185 struct tw686x_video_channel *vc = &dev->video_channels[ch];
1187 vc->dev = dev;
1188 vc->ch = ch;
1192 struct tw686x_video_channel *vc = &dev->video_channels[ch];
1195 mutex_init(&vc->vb_mutex);
1196 spin_lock_init(&vc->qlock);
1197 INIT_LIST_HEAD(&vc->vidq_queued);
1200 err = tw686x_set_standard(vc, V4L2_STD_NTSC);
1204 err = tw686x_set_format(vc, formats[0].fourcc,
1206 TW686X_VIDEO_HEIGHT(vc->video_standard),
1211 tw686x_set_input(vc, 0);
1212 tw686x_set_framerate(vc, 30);
1217 vc->vidq.io_modes = VB2_READ | VB2_MMAP | VB2_DMABUF;
1218 vc->vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1219 vc->vidq.drv_priv = vc;
1220 vc->vidq.buf_struct_size = sizeof(struct tw686x_v4l2_buf);
1221 vc->vidq.ops = &tw686x_video_qops;
1222 vc->vidq.mem_ops = dev->dma_ops->mem_ops;
1223 vc->vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1224 vc->vidq.min_buffers_needed = 2;
1225 vc->vidq.lock = &vc->vb_mutex;
1226 vc->vidq.gfp_flags = dev->dma_mode != TW686X_DMA_MODE_MEMCPY ?
1228 vc->vidq.dev = &dev->pci_dev->dev;
1230 err = vb2_queue_init(&vc->vidq);
1237 err = v4l2_ctrl_handler_init(&vc->ctrl_handler, 4);
1243 v4l2_ctrl_new_std(&vc->ctrl_handler, &ctrl_ops,
1245 v4l2_ctrl_new_std(&vc->ctrl_handler, &ctrl_ops,
1247 v4l2_ctrl_new_std(&vc->ctrl_handler, &ctrl_ops,
1249 v4l2_ctrl_new_std(&vc->ctrl_handler, &ctrl_ops,
1251 err = vc->ctrl_handler.error;
1255 err = v4l2_ctrl_handler_setup(&vc->ctrl_handler);
1272 vdev->queue = &vc->vidq;
1275 vdev->lock = &vc->vb_mutex;
1276 vdev->ctrl_handler = &vc->ctrl_handler;
1279 vc->device = vdev;
1280 video_set_drvdata(vdev, vc);
1287 vc->num = vdev->num;