1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for the Conexant CX25821 PCIe bridge
5 * Copyright (C) 2009 Conexant Systems Inc.
6 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
7 * Based on Steven Toth <stoth@linuxtv.org> cx25821 driver
8 * Parts adapted/taken from Eduardo Moscoso Rubino
9 * Copyright (C) 2009 Eduardo Moscoso Rubino <moscoso@TopoLogica.com>
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 #include "cx25821-video.h"
16 MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards");
17 MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>");
18 MODULE_LICENSE("GPL");
20 static unsigned int video_nr[] = {[0 ... (CX25821_MAXBOARDS - 1)] = UNSET };
22 module_param_array(video_nr, int, NULL, 0444);
24 MODULE_PARM_DESC(video_nr, "video device numbers");
26 static unsigned int video_debug = VIDEO_DEBUG;
27 module_param(video_debug, int, 0644);
28 MODULE_PARM_DESC(video_debug, "enable debug messages [video]");
30 static unsigned int irq_debug;
31 module_param(irq_debug, int, 0644);
32 MODULE_PARM_DESC(irq_debug, "enable debug messages [IRQ handler]");
34 #define FORMAT_FLAGS_PACKED 0x01
36 static const struct cx25821_fmt formats[] = {
38 .name = "4:1:1, packed, Y41P",
39 .fourcc = V4L2_PIX_FMT_Y41P,
41 .flags = FORMAT_FLAGS_PACKED,
43 .name = "4:2:2, packed, YUYV",
44 .fourcc = V4L2_PIX_FMT_YUYV,
46 .flags = FORMAT_FLAGS_PACKED,
50 static const struct cx25821_fmt *cx25821_format_by_fourcc(unsigned int fourcc)
54 for (i = 0; i < ARRAY_SIZE(formats); i++)
55 if (formats[i].fourcc == fourcc)
60 int cx25821_start_video_dma(struct cx25821_dev *dev,
61 struct cx25821_dmaqueue *q,
62 struct cx25821_buffer *buf,
63 const struct sram_channel *channel)
67 /* setup fifo + format */
68 cx25821_sram_channel_setup(dev, channel, buf->bpl, buf->risc.dma);
71 cx_write(channel->gpcnt_ctl, 3);
74 cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << channel->i));
75 cx_set(channel->int_msk, 0x11);
78 cx_write(channel->dma_ctl, 0x11); /* FIFO and RISC enable */
80 /* make sure upstream setting if any is reversed */
81 tmp = cx_read(VID_CH_MODE_SEL);
82 cx_write(VID_CH_MODE_SEL, tmp & 0xFFFFFE00);
87 int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
91 const struct sram_channel *channel = dev->channels[chan_num].sram_channels;
93 mask = cx_read(channel->int_msk);
94 if (0 == (status & mask))
97 cx_write(channel->int_stat, status);
99 /* risc op code error */
100 if (status & (1 << 16)) {
101 pr_warn("%s, %s: video risc op code error\n",
102 dev->name, channel->name);
103 cx_clear(channel->dma_ctl, 0x11);
104 cx25821_sram_channel_dump(dev, channel);
108 if (status & FLD_VID_DST_RISC1) {
109 struct cx25821_dmaqueue *dmaq =
110 &dev->channels[channel->i].dma_vidq;
111 struct cx25821_buffer *buf;
113 spin_lock(&dev->slock);
114 if (!list_empty(&dmaq->active)) {
115 buf = list_entry(dmaq->active.next,
116 struct cx25821_buffer, queue);
118 buf->vb.vb2_buf.timestamp = ktime_get_ns();
119 buf->vb.sequence = dmaq->count++;
120 list_del(&buf->queue);
121 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
123 spin_unlock(&dev->slock);
129 static int cx25821_queue_setup(struct vb2_queue *q,
130 unsigned int *num_buffers, unsigned int *num_planes,
131 unsigned int sizes[], struct device *alloc_devs[])
133 struct cx25821_channel *chan = q->drv_priv;
134 unsigned size = (chan->fmt->depth * chan->width * chan->height) >> 3;
137 return sizes[0] < size ? -EINVAL : 0;
144 static int cx25821_buffer_prepare(struct vb2_buffer *vb)
146 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
147 struct cx25821_channel *chan = vb->vb2_queue->drv_priv;
148 struct cx25821_dev *dev = chan->dev;
149 struct cx25821_buffer *buf =
150 container_of(vbuf, struct cx25821_buffer, vb);
151 struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0);
153 int bpl_local = LINE_SIZE_D1;
156 if (chan->pixel_formats == PIXEL_FRMT_411)
157 buf->bpl = (chan->fmt->depth * chan->width) >> 3;
159 buf->bpl = (chan->fmt->depth >> 3) * chan->width;
161 if (vb2_plane_size(vb, 0) < chan->height * buf->bpl)
163 vb2_set_plane_payload(vb, 0, chan->height * buf->bpl);
164 buf->vb.field = chan->field;
166 if (chan->pixel_formats == PIXEL_FRMT_411) {
167 bpl_local = buf->bpl;
169 bpl_local = buf->bpl; /* Default */
171 if (chan->use_cif_resolution) {
172 if (dev->tvnorm & V4L2_STD_625_50)
173 bpl_local = 352 << 1;
175 bpl_local = chan->cif_width << 1;
179 switch (chan->field) {
181 ret = cx25821_risc_buffer(dev->pci, &buf->risc,
183 buf->bpl, 0, chan->height);
185 case V4L2_FIELD_BOTTOM:
186 ret = cx25821_risc_buffer(dev->pci, &buf->risc,
188 buf->bpl, 0, chan->height);
190 case V4L2_FIELD_INTERLACED:
191 /* All other formats are top field first */
193 dprintk(1, "top field first\n");
195 ret = cx25821_risc_buffer(dev->pci, &buf->risc,
196 sgt->sgl, line0_offset,
197 bpl_local, bpl_local, bpl_local,
200 case V4L2_FIELD_SEQ_TB:
201 ret = cx25821_risc_buffer(dev->pci, &buf->risc,
203 0, buf->bpl * (chan->height >> 1),
204 buf->bpl, 0, chan->height >> 1);
206 case V4L2_FIELD_SEQ_BT:
207 ret = cx25821_risc_buffer(dev->pci, &buf->risc,
209 buf->bpl * (chan->height >> 1), 0,
210 buf->bpl, 0, chan->height >> 1);
218 dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
219 buf, buf->vb.vb2_buf.index, chan->width, chan->height,
220 chan->fmt->depth, chan->fmt->name,
221 (unsigned long)buf->risc.dma);
226 static void cx25821_buffer_finish(struct vb2_buffer *vb)
228 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
229 struct cx25821_buffer *buf =
230 container_of(vbuf, struct cx25821_buffer, vb);
231 struct cx25821_channel *chan = vb->vb2_queue->drv_priv;
232 struct cx25821_dev *dev = chan->dev;
234 cx25821_free_buffer(dev, buf);
237 static void cx25821_buffer_queue(struct vb2_buffer *vb)
239 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
240 struct cx25821_buffer *buf =
241 container_of(vbuf, struct cx25821_buffer, vb);
242 struct cx25821_channel *chan = vb->vb2_queue->drv_priv;
243 struct cx25821_dev *dev = chan->dev;
244 struct cx25821_buffer *prev;
245 struct cx25821_dmaqueue *q = &dev->channels[chan->id].dma_vidq;
247 buf->risc.cpu[1] = cpu_to_le32(buf->risc.dma + 12);
248 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_CNT_INC);
249 buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma + 12);
250 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
252 if (list_empty(&q->active)) {
253 list_add_tail(&buf->queue, &q->active);
255 buf->risc.cpu[0] |= cpu_to_le32(RISC_IRQ1);
256 prev = list_entry(q->active.prev, struct cx25821_buffer,
258 list_add_tail(&buf->queue, &q->active);
259 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
263 static int cx25821_start_streaming(struct vb2_queue *q, unsigned int count)
265 struct cx25821_channel *chan = q->drv_priv;
266 struct cx25821_dev *dev = chan->dev;
267 struct cx25821_dmaqueue *dmaq = &dev->channels[chan->id].dma_vidq;
268 struct cx25821_buffer *buf = list_entry(dmaq->active.next,
269 struct cx25821_buffer, queue);
272 cx25821_start_video_dma(dev, dmaq, buf, chan->sram_channels);
276 static void cx25821_stop_streaming(struct vb2_queue *q)
278 struct cx25821_channel *chan = q->drv_priv;
279 struct cx25821_dev *dev = chan->dev;
280 struct cx25821_dmaqueue *dmaq = &dev->channels[chan->id].dma_vidq;
283 cx_write(chan->sram_channels->dma_ctl, 0); /* FIFO and RISC disable */
284 spin_lock_irqsave(&dev->slock, flags);
285 while (!list_empty(&dmaq->active)) {
286 struct cx25821_buffer *buf = list_entry(dmaq->active.next,
287 struct cx25821_buffer, queue);
289 list_del(&buf->queue);
290 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
292 spin_unlock_irqrestore(&dev->slock, flags);
295 static const struct vb2_ops cx25821_video_qops = {
296 .queue_setup = cx25821_queue_setup,
297 .buf_prepare = cx25821_buffer_prepare,
298 .buf_finish = cx25821_buffer_finish,
299 .buf_queue = cx25821_buffer_queue,
300 .wait_prepare = vb2_ops_wait_prepare,
301 .wait_finish = vb2_ops_wait_finish,
302 .start_streaming = cx25821_start_streaming,
303 .stop_streaming = cx25821_stop_streaming,
308 static int cx25821_vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
309 struct v4l2_fmtdesc *f)
311 if (unlikely(f->index >= ARRAY_SIZE(formats)))
314 strscpy(f->description, formats[f->index].name, sizeof(f->description));
315 f->pixelformat = formats[f->index].fourcc;
320 static int cx25821_vidioc_g_fmt_vid_cap(struct file *file, void *priv,
321 struct v4l2_format *f)
323 struct cx25821_channel *chan = video_drvdata(file);
325 f->fmt.pix.width = chan->width;
326 f->fmt.pix.height = chan->height;
327 f->fmt.pix.field = chan->field;
328 f->fmt.pix.pixelformat = chan->fmt->fourcc;
329 f->fmt.pix.bytesperline = (chan->width * chan->fmt->depth) >> 3;
330 f->fmt.pix.sizeimage = chan->height * f->fmt.pix.bytesperline;
331 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
336 static int cx25821_vidioc_try_fmt_vid_cap(struct file *file, void *priv,
337 struct v4l2_format *f)
339 struct cx25821_channel *chan = video_drvdata(file);
340 struct cx25821_dev *dev = chan->dev;
341 const struct cx25821_fmt *fmt;
342 enum v4l2_field field = f->fmt.pix.field;
346 fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat);
349 maxh = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480;
351 w = f->fmt.pix.width;
352 if (field != V4L2_FIELD_BOTTOM)
353 field = V4L2_FIELD_TOP;
356 f->fmt.pix.height = maxh / 4;
357 } else if (w < 720) {
359 f->fmt.pix.height = maxh / 2;
362 f->fmt.pix.height = maxh;
363 field = V4L2_FIELD_INTERLACED;
365 f->fmt.pix.field = field;
366 f->fmt.pix.width = w;
367 f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3;
368 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
369 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
374 static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
375 struct v4l2_format *f)
377 struct cx25821_channel *chan = video_drvdata(file);
378 struct cx25821_dev *dev = chan->dev;
379 int pix_format = PIXEL_FRMT_422;
382 err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
387 chan->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat);
388 chan->field = f->fmt.pix.field;
389 chan->width = f->fmt.pix.width;
390 chan->height = f->fmt.pix.height;
392 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P)
393 pix_format = PIXEL_FRMT_411;
395 pix_format = PIXEL_FRMT_422;
397 cx25821_set_pixel_format(dev, SRAM_CH00, pix_format);
399 /* check if cif resolution */
400 if (chan->width == 320 || chan->width == 352)
401 chan->use_cif_resolution = 1;
403 chan->use_cif_resolution = 0;
405 chan->cif_width = chan->width;
406 medusa_set_resolution(dev, chan->width, SRAM_CH00);
410 static int vidioc_log_status(struct file *file, void *priv)
412 struct cx25821_channel *chan = video_drvdata(file);
413 struct cx25821_dev *dev = chan->dev;
414 const struct sram_channel *sram_ch = chan->sram_channels;
417 tmp = cx_read(sram_ch->dma_ctl);
418 pr_info("Video input 0 is %s\n",
419 (tmp & 0x11) ? "streaming" : "stopped");
424 static int cx25821_vidioc_querycap(struct file *file, void *priv,
425 struct v4l2_capability *cap)
427 struct cx25821_channel *chan = video_drvdata(file);
428 struct cx25821_dev *dev = chan->dev;
429 const u32 cap_input = V4L2_CAP_VIDEO_CAPTURE |
430 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
431 const u32 cap_output = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_READWRITE;
433 strscpy(cap->driver, "cx25821", sizeof(cap->driver));
434 strscpy(cap->card, cx25821_boards[dev->board].name, sizeof(cap->card));
435 sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci));
436 if (chan->id >= VID_CHANNEL_NUM)
437 cap->device_caps = cap_output;
439 cap->device_caps = cap_input;
440 cap->capabilities = cap_input | cap_output | V4L2_CAP_DEVICE_CAPS;
444 static int cx25821_vidioc_g_std(struct file *file, void *priv, v4l2_std_id *tvnorms)
446 struct cx25821_channel *chan = video_drvdata(file);
448 *tvnorms = chan->dev->tvnorm;
452 static int cx25821_vidioc_s_std(struct file *file, void *priv,
455 struct cx25821_channel *chan = video_drvdata(file);
456 struct cx25821_dev *dev = chan->dev;
458 if (dev->tvnorm == tvnorms)
461 dev->tvnorm = tvnorms;
463 chan->height = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480;
465 medusa_set_videostandard(dev);
470 static int cx25821_vidioc_enum_input(struct file *file, void *priv,
471 struct v4l2_input *i)
476 i->type = V4L2_INPUT_TYPE_CAMERA;
477 i->std = CX25821_NORMS;
478 strscpy(i->name, "Composite", sizeof(i->name));
482 static int cx25821_vidioc_g_input(struct file *file, void *priv, unsigned int *i)
488 static int cx25821_vidioc_s_input(struct file *file, void *priv, unsigned int i)
490 return i ? -EINVAL : 0;
493 static int cx25821_s_ctrl(struct v4l2_ctrl *ctrl)
495 struct cx25821_channel *chan =
496 container_of(ctrl->handler, struct cx25821_channel, hdl);
497 struct cx25821_dev *dev = chan->dev;
500 case V4L2_CID_BRIGHTNESS:
501 medusa_set_brightness(dev, ctrl->val, chan->id);
504 medusa_set_hue(dev, ctrl->val, chan->id);
506 case V4L2_CID_CONTRAST:
507 medusa_set_contrast(dev, ctrl->val, chan->id);
509 case V4L2_CID_SATURATION:
510 medusa_set_saturation(dev, ctrl->val, chan->id);
518 static int cx25821_vidioc_enum_output(struct file *file, void *priv,
519 struct v4l2_output *o)
524 o->type = V4L2_INPUT_TYPE_CAMERA;
525 o->std = CX25821_NORMS;
526 strscpy(o->name, "Composite", sizeof(o->name));
530 static int cx25821_vidioc_g_output(struct file *file, void *priv, unsigned int *o)
536 static int cx25821_vidioc_s_output(struct file *file, void *priv, unsigned int o)
538 return o ? -EINVAL : 0;
541 static int cx25821_vidioc_try_fmt_vid_out(struct file *file, void *priv,
542 struct v4l2_format *f)
544 struct cx25821_channel *chan = video_drvdata(file);
545 struct cx25821_dev *dev = chan->dev;
546 const struct cx25821_fmt *fmt;
548 fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat);
551 f->fmt.pix.width = 720;
552 f->fmt.pix.height = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480;
553 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
554 f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3;
555 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
556 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
560 static int vidioc_s_fmt_vid_out(struct file *file, void *priv,
561 struct v4l2_format *f)
563 struct cx25821_channel *chan = video_drvdata(file);
566 err = cx25821_vidioc_try_fmt_vid_out(file, priv, f);
571 chan->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat);
572 chan->field = f->fmt.pix.field;
573 chan->width = f->fmt.pix.width;
574 chan->height = f->fmt.pix.height;
575 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P)
576 chan->pixel_formats = PIXEL_FRMT_411;
578 chan->pixel_formats = PIXEL_FRMT_422;
582 static const struct v4l2_ctrl_ops cx25821_ctrl_ops = {
583 .s_ctrl = cx25821_s_ctrl,
586 static const struct v4l2_file_operations video_fops = {
587 .owner = THIS_MODULE,
588 .open = v4l2_fh_open,
589 .release = vb2_fop_release,
590 .read = vb2_fop_read,
591 .poll = vb2_fop_poll,
592 .unlocked_ioctl = video_ioctl2,
593 .mmap = vb2_fop_mmap,
596 static const struct v4l2_ioctl_ops video_ioctl_ops = {
597 .vidioc_querycap = cx25821_vidioc_querycap,
598 .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
599 .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
600 .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
601 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
602 .vidioc_reqbufs = vb2_ioctl_reqbufs,
603 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
604 .vidioc_create_bufs = vb2_ioctl_create_bufs,
605 .vidioc_querybuf = vb2_ioctl_querybuf,
606 .vidioc_qbuf = vb2_ioctl_qbuf,
607 .vidioc_dqbuf = vb2_ioctl_dqbuf,
608 .vidioc_streamon = vb2_ioctl_streamon,
609 .vidioc_streamoff = vb2_ioctl_streamoff,
610 .vidioc_g_std = cx25821_vidioc_g_std,
611 .vidioc_s_std = cx25821_vidioc_s_std,
612 .vidioc_enum_input = cx25821_vidioc_enum_input,
613 .vidioc_g_input = cx25821_vidioc_g_input,
614 .vidioc_s_input = cx25821_vidioc_s_input,
615 .vidioc_log_status = vidioc_log_status,
616 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
617 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
620 static const struct video_device cx25821_video_device = {
621 .name = "cx25821-video",
623 .release = video_device_release_empty,
625 .ioctl_ops = &video_ioctl_ops,
626 .tvnorms = CX25821_NORMS,
629 static const struct v4l2_file_operations video_out_fops = {
630 .owner = THIS_MODULE,
631 .open = v4l2_fh_open,
632 .release = vb2_fop_release,
633 .write = vb2_fop_write,
634 .poll = vb2_fop_poll,
635 .unlocked_ioctl = video_ioctl2,
636 .mmap = vb2_fop_mmap,
639 static const struct v4l2_ioctl_ops video_out_ioctl_ops = {
640 .vidioc_querycap = cx25821_vidioc_querycap,
641 .vidioc_enum_fmt_vid_out = cx25821_vidioc_enum_fmt_vid_cap,
642 .vidioc_g_fmt_vid_out = cx25821_vidioc_g_fmt_vid_cap,
643 .vidioc_try_fmt_vid_out = cx25821_vidioc_try_fmt_vid_out,
644 .vidioc_s_fmt_vid_out = vidioc_s_fmt_vid_out,
645 .vidioc_g_std = cx25821_vidioc_g_std,
646 .vidioc_s_std = cx25821_vidioc_s_std,
647 .vidioc_enum_output = cx25821_vidioc_enum_output,
648 .vidioc_g_output = cx25821_vidioc_g_output,
649 .vidioc_s_output = cx25821_vidioc_s_output,
650 .vidioc_log_status = vidioc_log_status,
653 static const struct video_device cx25821_video_out_device = {
654 .name = "cx25821-video",
655 .fops = &video_out_fops,
656 .release = video_device_release_empty,
658 .ioctl_ops = &video_out_ioctl_ops,
659 .tvnorms = CX25821_NORMS,
662 void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num)
664 cx_clear(PCI_INT_MSK, 1);
666 if (video_is_registered(&dev->channels[chan_num].vdev)) {
667 video_unregister_device(&dev->channels[chan_num].vdev);
668 v4l2_ctrl_handler_free(&dev->channels[chan_num].hdl);
672 int cx25821_video_register(struct cx25821_dev *dev)
677 /* initial device configuration */
678 dev->tvnorm = V4L2_STD_NTSC_M;
680 spin_lock_init(&dev->slock);
682 for (i = 0; i < MAX_VID_CAP_CHANNEL_NUM - 1; ++i) {
683 struct cx25821_channel *chan = &dev->channels[i];
684 struct video_device *vdev = &chan->vdev;
685 struct v4l2_ctrl_handler *hdl = &chan->hdl;
687 bool is_output = i > SRAM_CH08;
689 if (i == SRAM_CH08) /* audio channel */
693 v4l2_ctrl_handler_init(hdl, 4);
694 v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops,
695 V4L2_CID_BRIGHTNESS, 0, 10000, 1, 6200);
696 v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops,
697 V4L2_CID_CONTRAST, 0, 10000, 1, 5000);
698 v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops,
699 V4L2_CID_SATURATION, 0, 10000, 1, 5000);
700 v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops,
701 V4L2_CID_HUE, 0, 10000, 1, 5000);
706 err = v4l2_ctrl_handler_setup(hdl);
710 chan->out = &dev->vid_out_data[i - SRAM_CH09];
711 chan->out->chan = chan;
714 chan->sram_channels = &cx25821_sram_channels[i];
716 chan->field = V4L2_FIELD_INTERLACED;
717 if (dev->tvnorm & V4L2_STD_625_50)
722 if (chan->pixel_formats == PIXEL_FRMT_411)
723 chan->fmt = cx25821_format_by_fourcc(V4L2_PIX_FMT_Y41P);
725 chan->fmt = cx25821_format_by_fourcc(V4L2_PIX_FMT_YUYV);
727 cx_write(chan->sram_channels->int_stat, 0xffffffff);
729 INIT_LIST_HEAD(&chan->dma_vidq.active);
733 q->type = is_output ? V4L2_BUF_TYPE_VIDEO_OUTPUT :
734 V4L2_BUF_TYPE_VIDEO_CAPTURE;
735 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
736 q->io_modes |= is_output ? VB2_WRITE : VB2_READ;
737 q->gfp_flags = GFP_DMA32;
738 q->min_buffers_needed = 2;
740 q->buf_struct_size = sizeof(struct cx25821_buffer);
741 q->ops = &cx25821_video_qops;
742 q->mem_ops = &vb2_dma_sg_memops;
743 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
744 q->lock = &dev->lock;
745 q->dev = &dev->pci->dev;
748 err = vb2_queue_init(q);
753 /* register v4l devices */
754 *vdev = is_output ? cx25821_video_out_device : cx25821_video_device;
755 vdev->v4l2_dev = &dev->v4l2_dev;
757 vdev->ctrl_handler = hdl;
759 vdev->vfl_dir = VFL_DIR_TX;
760 vdev->lock = &dev->lock;
762 snprintf(vdev->name, sizeof(vdev->name), "%s #%d", dev->name, i);
763 video_set_drvdata(vdev, chan);
765 err = video_register_device(vdev, VFL_TYPE_GRABBER,
772 /* set PCI interrupt */
773 cx_set(PCI_INT_MSK, 0xff);
779 cx25821_video_unregister(dev, i--);