Lines Matching +full:0 +full:- +full:576
1 // SPDX-License-Identifier: GPL-2.0-or-later
14 #include "cx25821-video.h"
20 static unsigned int video_nr[] = {[0 ... (CX25821_MAXBOARDS - 1)] = UNSET };
34 #define FORMAT_FLAGS_PACKED 0x01
52 for (i = 0; i < ARRAY_SIZE(formats); i++) in cx25821_format_by_fourcc()
63 int tmp = 0; in cx25821_start_video_dma()
66 cx25821_sram_channel_setup(dev, channel, buf->bpl, buf->risc.dma); in cx25821_start_video_dma()
69 cx_write(channel->gpcnt_ctl, 3); in cx25821_start_video_dma()
72 cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << channel->i)); in cx25821_start_video_dma()
73 cx_set(channel->int_msk, 0x11); in cx25821_start_video_dma()
76 cx_write(channel->dma_ctl, 0x11); /* FIFO and RISC enable */ in cx25821_start_video_dma()
80 cx_write(VID_CH_MODE_SEL, tmp & 0xFFFFFE00); in cx25821_start_video_dma()
82 return 0; in cx25821_start_video_dma()
87 int handled = 0; in cx25821_video_irq()
89 const struct sram_channel *channel = dev->channels[chan_num].sram_channels; in cx25821_video_irq()
91 mask = cx_read(channel->int_msk); in cx25821_video_irq()
92 if (0 == (status & mask)) in cx25821_video_irq()
95 cx_write(channel->int_stat, status); in cx25821_video_irq()
100 dev->name, channel->name); in cx25821_video_irq()
101 cx_clear(channel->dma_ctl, 0x11); in cx25821_video_irq()
108 &dev->channels[channel->i].dma_vidq; in cx25821_video_irq()
111 spin_lock(&dev->slock); in cx25821_video_irq()
112 if (!list_empty(&dmaq->active)) { in cx25821_video_irq()
113 buf = list_entry(dmaq->active.next, in cx25821_video_irq()
116 buf->vb.vb2_buf.timestamp = ktime_get_ns(); in cx25821_video_irq()
117 buf->vb.sequence = dmaq->count++; in cx25821_video_irq()
118 list_del(&buf->queue); in cx25821_video_irq()
119 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE); in cx25821_video_irq()
121 spin_unlock(&dev->slock); in cx25821_video_irq()
131 struct cx25821_channel *chan = q->drv_priv; in cx25821_queue_setup()
132 unsigned size = (chan->fmt->depth * chan->width * chan->height) >> 3; in cx25821_queue_setup()
135 return sizes[0] < size ? -EINVAL : 0; in cx25821_queue_setup()
138 sizes[0] = size; in cx25821_queue_setup()
139 return 0; in cx25821_queue_setup()
145 struct cx25821_channel *chan = vb->vb2_queue->drv_priv; in cx25821_buffer_prepare()
146 struct cx25821_dev *dev = chan->dev; in cx25821_buffer_prepare()
149 struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0); in cx25821_buffer_prepare()
154 if (chan->pixel_formats == PIXEL_FRMT_411) in cx25821_buffer_prepare()
155 buf->bpl = (chan->fmt->depth * chan->width) >> 3; in cx25821_buffer_prepare()
157 buf->bpl = (chan->fmt->depth >> 3) * chan->width; in cx25821_buffer_prepare()
159 if (vb2_plane_size(vb, 0) < chan->height * buf->bpl) in cx25821_buffer_prepare()
160 return -EINVAL; in cx25821_buffer_prepare()
161 vb2_set_plane_payload(vb, 0, chan->height * buf->bpl); in cx25821_buffer_prepare()
162 buf->vb.field = chan->field; in cx25821_buffer_prepare()
164 if (chan->pixel_formats == PIXEL_FRMT_411) { in cx25821_buffer_prepare()
165 bpl_local = buf->bpl; in cx25821_buffer_prepare()
167 bpl_local = buf->bpl; /* Default */ in cx25821_buffer_prepare()
169 if (chan->use_cif_resolution) { in cx25821_buffer_prepare()
170 if (dev->tvnorm & V4L2_STD_625_50) in cx25821_buffer_prepare()
173 bpl_local = chan->cif_width << 1; in cx25821_buffer_prepare()
177 switch (chan->field) { in cx25821_buffer_prepare()
179 ret = cx25821_risc_buffer(dev->pci, &buf->risc, in cx25821_buffer_prepare()
180 sgt->sgl, 0, UNSET, in cx25821_buffer_prepare()
181 buf->bpl, 0, chan->height); in cx25821_buffer_prepare()
184 ret = cx25821_risc_buffer(dev->pci, &buf->risc, in cx25821_buffer_prepare()
185 sgt->sgl, UNSET, 0, in cx25821_buffer_prepare()
186 buf->bpl, 0, chan->height); in cx25821_buffer_prepare()
190 line0_offset = 0; in cx25821_buffer_prepare()
193 ret = cx25821_risc_buffer(dev->pci, &buf->risc, in cx25821_buffer_prepare()
194 sgt->sgl, line0_offset, in cx25821_buffer_prepare()
196 chan->height >> 1); in cx25821_buffer_prepare()
199 ret = cx25821_risc_buffer(dev->pci, &buf->risc, in cx25821_buffer_prepare()
200 sgt->sgl, in cx25821_buffer_prepare()
201 0, buf->bpl * (chan->height >> 1), in cx25821_buffer_prepare()
202 buf->bpl, 0, chan->height >> 1); in cx25821_buffer_prepare()
205 ret = cx25821_risc_buffer(dev->pci, &buf->risc, in cx25821_buffer_prepare()
206 sgt->sgl, in cx25821_buffer_prepare()
207 buf->bpl * (chan->height >> 1), 0, in cx25821_buffer_prepare()
208 buf->bpl, 0, chan->height >> 1); in cx25821_buffer_prepare()
212 ret = -EINVAL; in cx25821_buffer_prepare()
216 dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp 0x%08x - dma=0x%08lx\n", in cx25821_buffer_prepare()
217 buf, buf->vb.vb2_buf.index, chan->width, chan->height, in cx25821_buffer_prepare()
218 chan->fmt->depth, chan->fmt->fourcc, in cx25821_buffer_prepare()
219 (unsigned long)buf->risc.dma); in cx25821_buffer_prepare()
229 struct cx25821_channel *chan = vb->vb2_queue->drv_priv; in cx25821_buffer_finish()
230 struct cx25821_dev *dev = chan->dev; in cx25821_buffer_finish()
240 struct cx25821_channel *chan = vb->vb2_queue->drv_priv; in cx25821_buffer_queue()
241 struct cx25821_dev *dev = chan->dev; in cx25821_buffer_queue()
243 struct cx25821_dmaqueue *q = &dev->channels[chan->id].dma_vidq; in cx25821_buffer_queue()
245 buf->risc.cpu[1] = cpu_to_le32(buf->risc.dma + 12); in cx25821_buffer_queue()
246 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_CNT_INC); in cx25821_buffer_queue()
247 buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma + 12); in cx25821_buffer_queue()
248 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */ in cx25821_buffer_queue()
250 if (list_empty(&q->active)) { in cx25821_buffer_queue()
251 list_add_tail(&buf->queue, &q->active); in cx25821_buffer_queue()
253 buf->risc.cpu[0] |= cpu_to_le32(RISC_IRQ1); in cx25821_buffer_queue()
254 prev = list_entry(q->active.prev, struct cx25821_buffer, in cx25821_buffer_queue()
256 list_add_tail(&buf->queue, &q->active); in cx25821_buffer_queue()
257 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); in cx25821_buffer_queue()
263 struct cx25821_channel *chan = q->drv_priv; in cx25821_start_streaming()
264 struct cx25821_dev *dev = chan->dev; in cx25821_start_streaming()
265 struct cx25821_dmaqueue *dmaq = &dev->channels[chan->id].dma_vidq; in cx25821_start_streaming()
266 struct cx25821_buffer *buf = list_entry(dmaq->active.next, in cx25821_start_streaming()
269 dmaq->count = 0; in cx25821_start_streaming()
270 cx25821_start_video_dma(dev, dmaq, buf, chan->sram_channels); in cx25821_start_streaming()
271 return 0; in cx25821_start_streaming()
276 struct cx25821_channel *chan = q->drv_priv; in cx25821_stop_streaming()
277 struct cx25821_dev *dev = chan->dev; in cx25821_stop_streaming()
278 struct cx25821_dmaqueue *dmaq = &dev->channels[chan->id].dma_vidq; in cx25821_stop_streaming()
281 cx_write(chan->sram_channels->dma_ctl, 0); /* FIFO and RISC disable */ in cx25821_stop_streaming()
282 spin_lock_irqsave(&dev->slock, flags); in cx25821_stop_streaming()
283 while (!list_empty(&dmaq->active)) { in cx25821_stop_streaming()
284 struct cx25821_buffer *buf = list_entry(dmaq->active.next, in cx25821_stop_streaming()
287 list_del(&buf->queue); in cx25821_stop_streaming()
288 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); in cx25821_stop_streaming()
290 spin_unlock_irqrestore(&dev->slock, flags); in cx25821_stop_streaming()
307 if (unlikely(f->index >= ARRAY_SIZE(formats))) in cx25821_vidioc_enum_fmt_vid_cap()
308 return -EINVAL; in cx25821_vidioc_enum_fmt_vid_cap()
310 f->pixelformat = formats[f->index].fourcc; in cx25821_vidioc_enum_fmt_vid_cap()
312 return 0; in cx25821_vidioc_enum_fmt_vid_cap()
320 f->fmt.pix.width = chan->width; in cx25821_vidioc_g_fmt_vid_cap()
321 f->fmt.pix.height = chan->height; in cx25821_vidioc_g_fmt_vid_cap()
322 f->fmt.pix.field = chan->field; in cx25821_vidioc_g_fmt_vid_cap()
323 f->fmt.pix.pixelformat = chan->fmt->fourcc; in cx25821_vidioc_g_fmt_vid_cap()
324 f->fmt.pix.bytesperline = (chan->width * chan->fmt->depth) >> 3; in cx25821_vidioc_g_fmt_vid_cap()
325 f->fmt.pix.sizeimage = chan->height * f->fmt.pix.bytesperline; in cx25821_vidioc_g_fmt_vid_cap()
326 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; in cx25821_vidioc_g_fmt_vid_cap()
328 return 0; in cx25821_vidioc_g_fmt_vid_cap()
335 struct cx25821_dev *dev = chan->dev; in cx25821_vidioc_try_fmt_vid_cap()
337 enum v4l2_field field = f->fmt.pix.field; in cx25821_vidioc_try_fmt_vid_cap()
341 fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); in cx25821_vidioc_try_fmt_vid_cap()
343 return -EINVAL; in cx25821_vidioc_try_fmt_vid_cap()
344 maxh = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480; in cx25821_vidioc_try_fmt_vid_cap()
346 w = f->fmt.pix.width; in cx25821_vidioc_try_fmt_vid_cap()
351 f->fmt.pix.height = maxh / 4; in cx25821_vidioc_try_fmt_vid_cap()
354 f->fmt.pix.height = maxh / 2; in cx25821_vidioc_try_fmt_vid_cap()
357 f->fmt.pix.height = maxh; in cx25821_vidioc_try_fmt_vid_cap()
360 f->fmt.pix.field = field; in cx25821_vidioc_try_fmt_vid_cap()
361 f->fmt.pix.width = w; in cx25821_vidioc_try_fmt_vid_cap()
362 f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3; in cx25821_vidioc_try_fmt_vid_cap()
363 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; in cx25821_vidioc_try_fmt_vid_cap()
364 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; in cx25821_vidioc_try_fmt_vid_cap()
366 return 0; in cx25821_vidioc_try_fmt_vid_cap()
373 struct cx25821_dev *dev = chan->dev; in vidioc_s_fmt_vid_cap()
379 if (0 != err) in vidioc_s_fmt_vid_cap()
382 chan->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); in vidioc_s_fmt_vid_cap()
383 chan->field = f->fmt.pix.field; in vidioc_s_fmt_vid_cap()
384 chan->width = f->fmt.pix.width; in vidioc_s_fmt_vid_cap()
385 chan->height = f->fmt.pix.height; in vidioc_s_fmt_vid_cap()
387 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P) in vidioc_s_fmt_vid_cap()
395 if (chan->width == 320 || chan->width == 352) in vidioc_s_fmt_vid_cap()
396 chan->use_cif_resolution = 1; in vidioc_s_fmt_vid_cap()
398 chan->use_cif_resolution = 0; in vidioc_s_fmt_vid_cap()
400 chan->cif_width = chan->width; in vidioc_s_fmt_vid_cap()
401 medusa_set_resolution(dev, chan->width, SRAM_CH00); in vidioc_s_fmt_vid_cap()
402 return 0; in vidioc_s_fmt_vid_cap()
408 struct cx25821_dev *dev = chan->dev; in vidioc_log_status()
409 const struct sram_channel *sram_ch = chan->sram_channels; in vidioc_log_status()
410 u32 tmp = 0; in vidioc_log_status()
412 tmp = cx_read(sram_ch->dma_ctl); in vidioc_log_status()
413 pr_info("Video input 0 is %s\n", in vidioc_log_status()
414 (tmp & 0x11) ? "streaming" : "stopped"); in vidioc_log_status()
415 return 0; in vidioc_log_status()
423 struct cx25821_dev *dev = chan->dev; in cx25821_vidioc_querycap()
425 strscpy(cap->driver, "cx25821", sizeof(cap->driver)); in cx25821_vidioc_querycap()
426 strscpy(cap->card, cx25821_boards[dev->board].name, sizeof(cap->card)); in cx25821_vidioc_querycap()
427 sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci)); in cx25821_vidioc_querycap()
428 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT | in cx25821_vidioc_querycap()
431 return 0; in cx25821_vidioc_querycap()
438 *tvnorms = chan->dev->tvnorm; in cx25821_vidioc_g_std()
439 return 0; in cx25821_vidioc_g_std()
446 struct cx25821_dev *dev = chan->dev; in cx25821_vidioc_s_std()
448 if (dev->tvnorm == tvnorms) in cx25821_vidioc_s_std()
449 return 0; in cx25821_vidioc_s_std()
451 dev->tvnorm = tvnorms; in cx25821_vidioc_s_std()
452 chan->width = 720; in cx25821_vidioc_s_std()
453 chan->height = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480; in cx25821_vidioc_s_std()
457 return 0; in cx25821_vidioc_s_std()
463 if (i->index) in cx25821_vidioc_enum_input()
464 return -EINVAL; in cx25821_vidioc_enum_input()
466 i->type = V4L2_INPUT_TYPE_CAMERA; in cx25821_vidioc_enum_input()
467 i->std = CX25821_NORMS; in cx25821_vidioc_enum_input()
468 strscpy(i->name, "Composite", sizeof(i->name)); in cx25821_vidioc_enum_input()
469 return 0; in cx25821_vidioc_enum_input()
474 *i = 0; in cx25821_vidioc_g_input()
475 return 0; in cx25821_vidioc_g_input()
480 return i ? -EINVAL : 0; in cx25821_vidioc_s_input()
486 container_of(ctrl->handler, struct cx25821_channel, hdl); in cx25821_s_ctrl()
487 struct cx25821_dev *dev = chan->dev; in cx25821_s_ctrl()
489 switch (ctrl->id) { in cx25821_s_ctrl()
491 medusa_set_brightness(dev, ctrl->val, chan->id); in cx25821_s_ctrl()
494 medusa_set_hue(dev, ctrl->val, chan->id); in cx25821_s_ctrl()
497 medusa_set_contrast(dev, ctrl->val, chan->id); in cx25821_s_ctrl()
500 medusa_set_saturation(dev, ctrl->val, chan->id); in cx25821_s_ctrl()
503 return -EINVAL; in cx25821_s_ctrl()
505 return 0; in cx25821_s_ctrl()
511 if (o->index) in cx25821_vidioc_enum_output()
512 return -EINVAL; in cx25821_vidioc_enum_output()
514 o->type = V4L2_INPUT_TYPE_CAMERA; in cx25821_vidioc_enum_output()
515 o->std = CX25821_NORMS; in cx25821_vidioc_enum_output()
516 strscpy(o->name, "Composite", sizeof(o->name)); in cx25821_vidioc_enum_output()
517 return 0; in cx25821_vidioc_enum_output()
522 *o = 0; in cx25821_vidioc_g_output()
523 return 0; in cx25821_vidioc_g_output()
528 return o ? -EINVAL : 0; in cx25821_vidioc_s_output()
535 struct cx25821_dev *dev = chan->dev; in cx25821_vidioc_try_fmt_vid_out()
538 fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); in cx25821_vidioc_try_fmt_vid_out()
540 return -EINVAL; in cx25821_vidioc_try_fmt_vid_out()
541 f->fmt.pix.width = 720; in cx25821_vidioc_try_fmt_vid_out()
542 f->fmt.pix.height = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480; in cx25821_vidioc_try_fmt_vid_out()
543 f->fmt.pix.field = V4L2_FIELD_INTERLACED; in cx25821_vidioc_try_fmt_vid_out()
544 f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3; in cx25821_vidioc_try_fmt_vid_out()
545 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; in cx25821_vidioc_try_fmt_vid_out()
546 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; in cx25821_vidioc_try_fmt_vid_out()
547 return 0; in cx25821_vidioc_try_fmt_vid_out()
558 if (0 != err) in vidioc_s_fmt_vid_out()
561 chan->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); in vidioc_s_fmt_vid_out()
562 chan->field = f->fmt.pix.field; in vidioc_s_fmt_vid_out()
563 chan->width = f->fmt.pix.width; in vidioc_s_fmt_vid_out()
564 chan->height = f->fmt.pix.height; in vidioc_s_fmt_vid_out()
565 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P) in vidioc_s_fmt_vid_out()
566 chan->pixel_formats = PIXEL_FRMT_411; in vidioc_s_fmt_vid_out()
568 chan->pixel_formats = PIXEL_FRMT_422; in vidioc_s_fmt_vid_out()
569 return 0; in vidioc_s_fmt_vid_out()
611 .name = "cx25821-video",
614 .minor = -1,
646 .name = "cx25821-video",
649 .minor = -1,
659 if (video_is_registered(&dev->channels[chan_num].vdev)) { in cx25821_video_unregister()
660 video_unregister_device(&dev->channels[chan_num].vdev); in cx25821_video_unregister()
661 v4l2_ctrl_handler_free(&dev->channels[chan_num].hdl); in cx25821_video_unregister()
671 dev->tvnorm = V4L2_STD_NTSC_M; in cx25821_video_register()
673 spin_lock_init(&dev->slock); in cx25821_video_register()
675 for (i = 0; i < MAX_VID_CAP_CHANNEL_NUM - 1; ++i) { in cx25821_video_register()
676 struct cx25821_channel *chan = &dev->channels[i]; in cx25821_video_register()
677 struct video_device *vdev = &chan->vdev; in cx25821_video_register()
678 struct v4l2_ctrl_handler *hdl = &chan->hdl; in cx25821_video_register()
688 V4L2_CID_BRIGHTNESS, 0, 10000, 1, 6200); in cx25821_video_register()
690 V4L2_CID_CONTRAST, 0, 10000, 1, 5000); in cx25821_video_register()
692 V4L2_CID_SATURATION, 0, 10000, 1, 5000); in cx25821_video_register()
694 V4L2_CID_HUE, 0, 10000, 1, 5000); in cx25821_video_register()
695 if (hdl->error) { in cx25821_video_register()
696 err = hdl->error; in cx25821_video_register()
703 chan->out = &dev->vid_out_data[i - SRAM_CH09]; in cx25821_video_register()
704 chan->out->chan = chan; in cx25821_video_register()
707 chan->sram_channels = &cx25821_sram_channels[i]; in cx25821_video_register()
708 chan->width = 720; in cx25821_video_register()
709 chan->field = V4L2_FIELD_INTERLACED; in cx25821_video_register()
710 if (dev->tvnorm & V4L2_STD_625_50) in cx25821_video_register()
711 chan->height = 576; in cx25821_video_register()
713 chan->height = 480; in cx25821_video_register()
715 if (chan->pixel_formats == PIXEL_FRMT_411) in cx25821_video_register()
716 chan->fmt = cx25821_format_by_fourcc(V4L2_PIX_FMT_Y41P); in cx25821_video_register()
718 chan->fmt = cx25821_format_by_fourcc(V4L2_PIX_FMT_YUYV); in cx25821_video_register()
720 cx_write(chan->sram_channels->int_stat, 0xffffffff); in cx25821_video_register()
722 INIT_LIST_HEAD(&chan->dma_vidq.active); in cx25821_video_register()
724 q = &chan->vidq; in cx25821_video_register()
726 q->type = is_output ? V4L2_BUF_TYPE_VIDEO_OUTPUT : in cx25821_video_register()
728 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; in cx25821_video_register()
729 q->io_modes |= is_output ? VB2_WRITE : VB2_READ; in cx25821_video_register()
730 q->gfp_flags = GFP_DMA32; in cx25821_video_register()
731 q->min_queued_buffers = 2; in cx25821_video_register()
732 q->drv_priv = chan; in cx25821_video_register()
733 q->buf_struct_size = sizeof(struct cx25821_buffer); in cx25821_video_register()
734 q->ops = &cx25821_video_qops; in cx25821_video_register()
735 q->mem_ops = &vb2_dma_sg_memops; in cx25821_video_register()
736 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in cx25821_video_register()
737 q->lock = &dev->lock; in cx25821_video_register()
738 q->dev = &dev->pci->dev; in cx25821_video_register()
742 if (err < 0) in cx25821_video_register()
748 vdev->v4l2_dev = &dev->v4l2_dev; in cx25821_video_register()
750 vdev->ctrl_handler = hdl; in cx25821_video_register()
752 vdev->vfl_dir = VFL_DIR_TX; in cx25821_video_register()
753 vdev->lock = &dev->lock; in cx25821_video_register()
754 vdev->queue = q; in cx25821_video_register()
755 snprintf(vdev->name, sizeof(vdev->name), "%s #%d", dev->name, i); in cx25821_video_register()
759 video_nr[dev->nr]); in cx25821_video_register()
761 if (err < 0) in cx25821_video_register()
766 cx_set(PCI_INT_MSK, 0xff); in cx25821_video_register()
768 return 0; in cx25821_video_register()
771 while (i >= 0) in cx25821_video_register()
772 cx25821_video_unregister(dev, i--); in cx25821_video_register()