Lines Matching +full:chan +full:- +full:name
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 };
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()
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()
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() local
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()
145 struct cx25821_channel *chan = vb->vb2_queue->drv_priv; in cx25821_buffer_prepare() local
146 struct cx25821_dev *dev = chan->dev; 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()
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() local
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() local
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() local
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()
276 struct cx25821_channel *chan = q->drv_priv; in cx25821_stop_streaming() local
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()
309 if (unlikely(f->index >= ARRAY_SIZE(formats))) in cx25821_vidioc_enum_fmt_vid_cap()
310 return -EINVAL; in cx25821_vidioc_enum_fmt_vid_cap()
312 f->pixelformat = formats[f->index].fourcc; in cx25821_vidioc_enum_fmt_vid_cap()
320 struct cx25821_channel *chan = video_drvdata(file); in cx25821_vidioc_g_fmt_vid_cap() local
322 f->fmt.pix.width = chan->width; in cx25821_vidioc_g_fmt_vid_cap()
323 f->fmt.pix.height = chan->height; in cx25821_vidioc_g_fmt_vid_cap()
324 f->fmt.pix.field = chan->field; in cx25821_vidioc_g_fmt_vid_cap()
325 f->fmt.pix.pixelformat = chan->fmt->fourcc; in cx25821_vidioc_g_fmt_vid_cap()
326 f->fmt.pix.bytesperline = (chan->width * chan->fmt->depth) >> 3; in cx25821_vidioc_g_fmt_vid_cap()
327 f->fmt.pix.sizeimage = chan->height * f->fmt.pix.bytesperline; in cx25821_vidioc_g_fmt_vid_cap()
328 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; in cx25821_vidioc_g_fmt_vid_cap()
336 struct cx25821_channel *chan = video_drvdata(file); in cx25821_vidioc_try_fmt_vid_cap() local
337 struct cx25821_dev *dev = chan->dev; in cx25821_vidioc_try_fmt_vid_cap()
339 enum v4l2_field field = f->fmt.pix.field; in cx25821_vidioc_try_fmt_vid_cap()
343 fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); in cx25821_vidioc_try_fmt_vid_cap()
345 return -EINVAL; in cx25821_vidioc_try_fmt_vid_cap()
346 maxh = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480; in cx25821_vidioc_try_fmt_vid_cap()
348 w = f->fmt.pix.width; in cx25821_vidioc_try_fmt_vid_cap()
353 f->fmt.pix.height = maxh / 4; in cx25821_vidioc_try_fmt_vid_cap()
356 f->fmt.pix.height = maxh / 2; in cx25821_vidioc_try_fmt_vid_cap()
359 f->fmt.pix.height = maxh; in cx25821_vidioc_try_fmt_vid_cap()
362 f->fmt.pix.field = field; in cx25821_vidioc_try_fmt_vid_cap()
363 f->fmt.pix.width = w; in cx25821_vidioc_try_fmt_vid_cap()
364 f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3; in cx25821_vidioc_try_fmt_vid_cap()
365 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; in cx25821_vidioc_try_fmt_vid_cap()
366 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; in cx25821_vidioc_try_fmt_vid_cap()
374 struct cx25821_channel *chan = video_drvdata(file); in vidioc_s_fmt_vid_cap() local
375 struct cx25821_dev *dev = chan->dev; in vidioc_s_fmt_vid_cap()
384 chan->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); in vidioc_s_fmt_vid_cap()
385 chan->field = f->fmt.pix.field; in vidioc_s_fmt_vid_cap()
386 chan->width = f->fmt.pix.width; in vidioc_s_fmt_vid_cap()
387 chan->height = f->fmt.pix.height; in vidioc_s_fmt_vid_cap()
389 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P) in vidioc_s_fmt_vid_cap()
397 if (chan->width == 320 || chan->width == 352) in vidioc_s_fmt_vid_cap()
398 chan->use_cif_resolution = 1; in vidioc_s_fmt_vid_cap()
400 chan->use_cif_resolution = 0; in vidioc_s_fmt_vid_cap()
402 chan->cif_width = chan->width; in vidioc_s_fmt_vid_cap()
403 medusa_set_resolution(dev, chan->width, SRAM_CH00); in vidioc_s_fmt_vid_cap()
409 struct cx25821_channel *chan = video_drvdata(file); in vidioc_log_status() local
410 struct cx25821_dev *dev = chan->dev; in vidioc_log_status()
411 const struct sram_channel *sram_ch = chan->sram_channels; in vidioc_log_status()
414 tmp = cx_read(sram_ch->dma_ctl); in vidioc_log_status()
424 struct cx25821_channel *chan = video_drvdata(file); in cx25821_vidioc_querycap() local
425 struct cx25821_dev *dev = chan->dev; in cx25821_vidioc_querycap()
427 strscpy(cap->driver, "cx25821", sizeof(cap->driver)); in cx25821_vidioc_querycap()
428 strscpy(cap->card, cx25821_boards[dev->board].name, sizeof(cap->card)); in cx25821_vidioc_querycap()
429 sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci)); in cx25821_vidioc_querycap()
430 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT | in cx25821_vidioc_querycap()
438 struct cx25821_channel *chan = video_drvdata(file); in cx25821_vidioc_g_std() local
440 *tvnorms = chan->dev->tvnorm; in cx25821_vidioc_g_std()
447 struct cx25821_channel *chan = video_drvdata(file); in cx25821_vidioc_s_std() local
448 struct cx25821_dev *dev = chan->dev; in cx25821_vidioc_s_std()
450 if (dev->tvnorm == tvnorms) in cx25821_vidioc_s_std()
453 dev->tvnorm = tvnorms; in cx25821_vidioc_s_std()
454 chan->width = 720; in cx25821_vidioc_s_std()
455 chan->height = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480; in cx25821_vidioc_s_std()
465 if (i->index) in cx25821_vidioc_enum_input()
466 return -EINVAL; in cx25821_vidioc_enum_input()
468 i->type = V4L2_INPUT_TYPE_CAMERA; in cx25821_vidioc_enum_input()
469 i->std = CX25821_NORMS; in cx25821_vidioc_enum_input()
470 strscpy(i->name, "Composite", sizeof(i->name)); in cx25821_vidioc_enum_input()
482 return i ? -EINVAL : 0; in cx25821_vidioc_s_input()
487 struct cx25821_channel *chan = in cx25821_s_ctrl() local
488 container_of(ctrl->handler, struct cx25821_channel, hdl); in cx25821_s_ctrl()
489 struct cx25821_dev *dev = chan->dev; in cx25821_s_ctrl()
491 switch (ctrl->id) { in cx25821_s_ctrl()
493 medusa_set_brightness(dev, ctrl->val, chan->id); in cx25821_s_ctrl()
496 medusa_set_hue(dev, ctrl->val, chan->id); in cx25821_s_ctrl()
499 medusa_set_contrast(dev, ctrl->val, chan->id); in cx25821_s_ctrl()
502 medusa_set_saturation(dev, ctrl->val, chan->id); in cx25821_s_ctrl()
505 return -EINVAL; in cx25821_s_ctrl()
513 if (o->index) in cx25821_vidioc_enum_output()
514 return -EINVAL; in cx25821_vidioc_enum_output()
516 o->type = V4L2_INPUT_TYPE_CAMERA; in cx25821_vidioc_enum_output()
517 o->std = CX25821_NORMS; in cx25821_vidioc_enum_output()
518 strscpy(o->name, "Composite", sizeof(o->name)); in cx25821_vidioc_enum_output()
530 return o ? -EINVAL : 0; in cx25821_vidioc_s_output()
536 struct cx25821_channel *chan = video_drvdata(file); in cx25821_vidioc_try_fmt_vid_out() local
537 struct cx25821_dev *dev = chan->dev; in cx25821_vidioc_try_fmt_vid_out()
540 fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); in cx25821_vidioc_try_fmt_vid_out()
542 return -EINVAL; in cx25821_vidioc_try_fmt_vid_out()
543 f->fmt.pix.width = 720; in cx25821_vidioc_try_fmt_vid_out()
544 f->fmt.pix.height = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480; in cx25821_vidioc_try_fmt_vid_out()
545 f->fmt.pix.field = V4L2_FIELD_INTERLACED; in cx25821_vidioc_try_fmt_vid_out()
546 f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3; in cx25821_vidioc_try_fmt_vid_out()
547 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; in cx25821_vidioc_try_fmt_vid_out()
548 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; in cx25821_vidioc_try_fmt_vid_out()
555 struct cx25821_channel *chan = video_drvdata(file); in vidioc_s_fmt_vid_out() local
563 chan->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); in vidioc_s_fmt_vid_out()
564 chan->field = f->fmt.pix.field; in vidioc_s_fmt_vid_out()
565 chan->width = f->fmt.pix.width; in vidioc_s_fmt_vid_out()
566 chan->height = f->fmt.pix.height; in vidioc_s_fmt_vid_out()
567 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P) in vidioc_s_fmt_vid_out()
568 chan->pixel_formats = PIXEL_FRMT_411; in vidioc_s_fmt_vid_out()
570 chan->pixel_formats = PIXEL_FRMT_422; in vidioc_s_fmt_vid_out()
613 .name = "cx25821-video",
616 .minor = -1,
648 .name = "cx25821-video",
651 .minor = -1,
661 if (video_is_registered(&dev->channels[chan_num].vdev)) { in cx25821_video_unregister()
662 video_unregister_device(&dev->channels[chan_num].vdev); in cx25821_video_unregister()
663 v4l2_ctrl_handler_free(&dev->channels[chan_num].hdl); in cx25821_video_unregister()
673 dev->tvnorm = V4L2_STD_NTSC_M; in cx25821_video_register()
675 spin_lock_init(&dev->slock); in cx25821_video_register()
677 for (i = 0; i < MAX_VID_CAP_CHANNEL_NUM - 1; ++i) { in cx25821_video_register()
678 struct cx25821_channel *chan = &dev->channels[i]; in cx25821_video_register() local
679 struct video_device *vdev = &chan->vdev; in cx25821_video_register()
680 struct v4l2_ctrl_handler *hdl = &chan->hdl; in cx25821_video_register()
697 if (hdl->error) { in cx25821_video_register()
698 err = hdl->error; in cx25821_video_register()
705 chan->out = &dev->vid_out_data[i - SRAM_CH09]; in cx25821_video_register()
706 chan->out->chan = chan; in cx25821_video_register()
709 chan->sram_channels = &cx25821_sram_channels[i]; in cx25821_video_register()
710 chan->width = 720; in cx25821_video_register()
711 chan->field = V4L2_FIELD_INTERLACED; in cx25821_video_register()
712 if (dev->tvnorm & V4L2_STD_625_50) in cx25821_video_register()
713 chan->height = 576; in cx25821_video_register()
715 chan->height = 480; in cx25821_video_register()
717 if (chan->pixel_formats == PIXEL_FRMT_411) in cx25821_video_register()
718 chan->fmt = cx25821_format_by_fourcc(V4L2_PIX_FMT_Y41P); in cx25821_video_register()
720 chan->fmt = cx25821_format_by_fourcc(V4L2_PIX_FMT_YUYV); in cx25821_video_register()
722 cx_write(chan->sram_channels->int_stat, 0xffffffff); in cx25821_video_register()
724 INIT_LIST_HEAD(&chan->dma_vidq.active); in cx25821_video_register()
726 q = &chan->vidq; in cx25821_video_register()
728 q->type = is_output ? V4L2_BUF_TYPE_VIDEO_OUTPUT : in cx25821_video_register()
730 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; in cx25821_video_register()
731 q->io_modes |= is_output ? VB2_WRITE : VB2_READ; in cx25821_video_register()
732 q->gfp_flags = GFP_DMA32; in cx25821_video_register()
733 q->min_buffers_needed = 2; in cx25821_video_register()
734 q->drv_priv = chan; in cx25821_video_register()
735 q->buf_struct_size = sizeof(struct cx25821_buffer); in cx25821_video_register()
736 q->ops = &cx25821_video_qops; in cx25821_video_register()
737 q->mem_ops = &vb2_dma_sg_memops; in cx25821_video_register()
738 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in cx25821_video_register()
739 q->lock = &dev->lock; in cx25821_video_register()
740 q->dev = &dev->pci->dev; in cx25821_video_register()
750 vdev->v4l2_dev = &dev->v4l2_dev; in cx25821_video_register()
752 vdev->ctrl_handler = hdl; in cx25821_video_register()
754 vdev->vfl_dir = VFL_DIR_TX; in cx25821_video_register()
755 vdev->lock = &dev->lock; in cx25821_video_register()
756 vdev->queue = q; in cx25821_video_register()
757 snprintf(vdev->name, sizeof(vdev->name), "%s #%d", dev->name, i); in cx25821_video_register()
758 video_set_drvdata(vdev, chan); in cx25821_video_register()
761 video_nr[dev->nr]); in cx25821_video_register()
774 cx25821_video_unregister(dev, i--); in cx25821_video_register()