Lines Matching +full:min +full:- +full:pix +full:- +full:sizes

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Derived from ivtv-ioctl.c and cx18-fileops.c
7 * Copyright 2012-2015 Cisco Systems, Inc. and/or its affiliates.
11 #include <linux/dma-mapping.h>
15 #include <linux/v4l2-dv-timings.h>
17 #include <media/v4l2-ctrls.h>
18 #include <media/v4l2-event.h>
19 #include <media/v4l2-dv-timings.h>
23 #include "cobalt-alsa.h"
24 #include "cobalt-cpld.h"
25 #include "cobalt-driver.h"
26 #include "cobalt-v4l2.h"
27 #include "cobalt-irq.h"
28 #include "cobalt-omnitek.h"
36 unsigned int sizes[], struct device *alloc_devs[]) in cobalt_queue_setup() argument
38 struct cobalt_stream *s = q->drv_priv; in cobalt_queue_setup()
39 unsigned size = s->stride * s->height; in cobalt_queue_setup()
46 return sizes[0] < size ? -EINVAL : 0; in cobalt_queue_setup()
48 sizes[0] = size; in cobalt_queue_setup()
54 struct cobalt_stream *s = vb->vb2_queue->drv_priv; in cobalt_buf_init()
55 struct cobalt *cobalt = s->cobalt; in cobalt_buf_init()
61 struct sg_dma_desc_info *desc = &s->dma_desc_info[vb->index]; in cobalt_buf_init()
66 size = s->stride * s->height; in cobalt_buf_init()
70 return -EINVAL; in cobalt_buf_init()
73 if (desc->virt == NULL) { in cobalt_buf_init()
74 desc->dev = &cobalt->pci_dev->dev; in cobalt_buf_init()
76 s->is_audio ? audio_bytes : bytes); in cobalt_buf_init()
77 if (desc->virt == NULL) in cobalt_buf_init()
78 return -ENOMEM; in cobalt_buf_init()
80 ret = descriptor_list_create(cobalt, sg_desc->sgl, in cobalt_buf_init()
81 !s->is_output, sg_desc->nents, size, in cobalt_buf_init()
82 s->width * s->bpp, s->stride, desc); in cobalt_buf_init()
90 struct cobalt_stream *s = vb->vb2_queue->drv_priv; in cobalt_buf_cleanup()
91 struct sg_dma_desc_info *desc = &s->dma_desc_info[vb->index]; in cobalt_buf_cleanup()
99 struct cobalt_stream *s = vb->vb2_queue->drv_priv; in cobalt_buf_prepare()
101 vb2_set_plane_payload(vb, 0, s->stride * s->height); in cobalt_buf_prepare()
102 vbuf->field = V4L2_FIELD_NONE; in cobalt_buf_prepare()
112 list_for_each_entry(cb, &s->bufs, list) { in chain_all_buffers()
113 desc[i] = &s->dma_desc_info[cb->vb.vb2_buf.index]; in chain_all_buffers()
115 descriptor_list_chain(desc[i-1], desc[i]); in chain_all_buffers()
123 struct vb2_queue *q = vb->vb2_queue; in cobalt_buf_queue()
124 struct cobalt_stream *s = q->drv_priv; in cobalt_buf_queue()
126 struct sg_dma_desc_info *desc = &s->dma_desc_info[vb->index]; in cobalt_buf_queue()
133 spin_lock_irqsave(&s->irqlock, flags); in cobalt_buf_queue()
134 list_add_tail(&cb->list, &s->bufs); in cobalt_buf_queue()
136 spin_unlock_irqrestore(&s->irqlock, flags); in cobalt_buf_queue()
141 struct cobalt *cobalt = s->cobalt; in cobalt_enable_output()
142 struct v4l2_bt_timings *bt = &s->timings.bt; in cobalt_enable_output()
145 unsigned fmt = s->pixfmt != V4L2_PIX_FMT_BGR32 ? in cobalt_enable_output()
150 u64 clk = bt->pixelclock; in cobalt_enable_output()
152 if (bt->flags & V4L2_DV_FL_REDUCED_FPS) in cobalt_enable_output()
159 sd_fmt.format.colorspace = s->colorspace; in cobalt_enable_output()
160 sd_fmt.format.xfer_func = s->xfer_func; in cobalt_enable_output()
161 sd_fmt.format.ycbcr_enc = s->ycbcr_enc; in cobalt_enable_output()
162 sd_fmt.format.quantization = s->quantization; in cobalt_enable_output()
163 sd_fmt.format.width = bt->width; in cobalt_enable_output()
164 sd_fmt.format.height = bt->height; in cobalt_enable_output()
167 switch (s->pixfmt) { in cobalt_enable_output()
175 v4l2_subdev_call(s->sd, pad, set_fmt, NULL, &sd_fmt); in cobalt_enable_output()
177 iowrite32(0, &vo->control); in cobalt_enable_output()
179 iowrite32(bt->hsync, &vo->sync_generator_h_sync_length); in cobalt_enable_output()
180 iowrite32(bt->hbackporch, &vo->sync_generator_h_backporch_length); in cobalt_enable_output()
181 iowrite32(bt->width, &vo->sync_generator_h_active_length); in cobalt_enable_output()
182 iowrite32(bt->hfrontporch, &vo->sync_generator_h_frontporch_length); in cobalt_enable_output()
183 iowrite32(bt->vsync, &vo->sync_generator_v_sync_length); in cobalt_enable_output()
184 iowrite32(bt->vbackporch, &vo->sync_generator_v_backporch_length); in cobalt_enable_output()
185 iowrite32(bt->height, &vo->sync_generator_v_active_length); in cobalt_enable_output()
186 iowrite32(bt->vfrontporch, &vo->sync_generator_v_frontporch_length); in cobalt_enable_output()
187 iowrite32(0x9900c1, &vo->error_color); in cobalt_enable_output()
190 &vo->control); in cobalt_enable_output()
191 iowrite32(M00514_CONTROL_BITMAP_EVCNT_CLEAR_MSK | fmt, &vo->control); in cobalt_enable_output()
194 fmt, &vo->control); in cobalt_enable_output()
199 struct cobalt *cobalt = s->cobalt; in cobalt_enable_input()
200 int ch = (int)s->video_channel; in cobalt_enable_input()
203 .pad = s->pad_source, in cobalt_enable_input()
208 .pad = s->pad_source, in cobalt_enable_input()
214 s->video_channel, in cobalt_enable_input()
215 s->input == 0 ? "hdmi" : "generator", in cobalt_enable_input()
221 switch (s->pixfmt) { in cobalt_enable_input()
225 &packer->control); in cobalt_enable_input()
226 v4l2_subdev_call(s->sd, pad, set_fmt, NULL, in cobalt_enable_input()
232 &packer->control); in cobalt_enable_input()
233 v4l2_subdev_call(s->sd, pad, set_fmt, NULL, in cobalt_enable_input()
240 &packer->control); in cobalt_enable_input()
241 v4l2_subdev_call(s->sd, pad, set_fmt, NULL, in cobalt_enable_input()
249 struct cobalt *cobalt = s->cobalt; in cobalt_dma_start_streaming()
250 int rx = s->video_channel; in cobalt_dma_start_streaming()
256 spin_lock_irqsave(&s->irqlock, flags); in cobalt_dma_start_streaming()
257 if (!s->is_output) { in cobalt_dma_start_streaming()
258 iowrite32(M00460_CONTROL_BITMAP_CLEAR_MSK, &evcnt->control); in cobalt_dma_start_streaming()
259 iowrite32(M00460_CONTROL_BITMAP_ENABLE_MSK, &evcnt->control); in cobalt_dma_start_streaming()
263 u32 ctrl = ioread32(&vo->control); in cobalt_dma_start_streaming()
268 &vo->control); in cobalt_dma_start_streaming()
270 &vo->control); in cobalt_dma_start_streaming()
272 cb = list_first_entry(&s->bufs, struct cobalt_buffer, list); in cobalt_dma_start_streaming()
273 omni_sg_dma_start(s, &s->dma_desc_info[cb->vb.vb2_buf.index]); in cobalt_dma_start_streaming()
274 spin_unlock_irqrestore(&s->irqlock, flags); in cobalt_dma_start_streaming()
279 struct cobalt_stream *s = q->drv_priv; in cobalt_start_streaming()
280 struct cobalt *cobalt = s->cobalt; in cobalt_start_streaming()
284 int rx = s->video_channel; in cobalt_start_streaming()
287 struct v4l2_bt_timings *bt = &s->timings.bt; in cobalt_start_streaming()
291 if (s->is_audio) in cobalt_start_streaming()
293 if (s->is_output) { in cobalt_start_streaming()
294 s->unstable_frame = false; in cobalt_start_streaming()
305 iowrite32(M00460_CONTROL_BITMAP_CLEAR_MSK, &evcnt->control); in cobalt_start_streaming()
306 iowrite32(M00460_CONTROL_BITMAP_ENABLE_MSK, &evcnt->control); in cobalt_start_streaming()
307 iowrite32(bt->width, &cvi->frame_width); in cobalt_start_streaming()
308 iowrite32(bt->height, &cvi->frame_height); in cobalt_start_streaming()
311 bt->pixelclock), &vmr->hsync_timeout_val); in cobalt_start_streaming()
312 iowrite32(M00233_CONTROL_BITMAP_ENABLE_MEASURE_MSK, &vmr->control); in cobalt_start_streaming()
313 clk_freq = ioread32(&fw->clk_freq); in cobalt_start_streaming()
314 iowrite32(clk_freq / 1000000, &clkloss->ref_clk_cnt_val); in cobalt_start_streaming()
317 iowrite32(div_u64(bt->pixelclock * 995, 1000000000), in cobalt_start_streaming()
318 &clkloss->test_clk_cnt_val); in cobalt_start_streaming()
320 iowrite32(bt->width * bt->height, &fw->active_length); in cobalt_start_streaming()
321 iowrite32(div_u64((u64)clk_freq * tot_size, bt->pixelclock), in cobalt_start_streaming()
322 &fw->total_length); in cobalt_start_streaming()
325 &vmr->irq_triggers); in cobalt_start_streaming()
326 iowrite32(0, &cvi->control); in cobalt_start_streaming()
327 iowrite32(M00233_CONTROL_BITMAP_ENABLE_MEASURE_MSK, &vmr->control); in cobalt_start_streaming()
329 iowrite32(0xff, &fw->output_color); in cobalt_start_streaming()
330 iowrite32(M00479_CTRL_BITMAP_ENABLE_MSK, &clkloss->ctrl); in cobalt_start_streaming()
332 M00473_CTRL_BITMAP_FORCE_FREEWHEEL_MODE_MSK, &fw->ctrl); in cobalt_start_streaming()
333 s->unstable_frame = true; in cobalt_start_streaming()
334 s->enable_freewheel = false; in cobalt_start_streaming()
335 s->enable_cvi = false; in cobalt_start_streaming()
336 s->skip_first_frames = 0; in cobalt_start_streaming()
339 s->sequence = 0; in cobalt_start_streaming()
346 struct cobalt *cobalt = s->cobalt; in cobalt_dma_stop_streaming()
351 int rx = s->video_channel; in cobalt_dma_stop_streaming()
355 if (!s->is_output) { in cobalt_dma_stop_streaming()
356 iowrite32(0, &evcnt->control); in cobalt_dma_stop_streaming()
357 } else if (!s->is_audio) { in cobalt_dma_stop_streaming()
361 iowrite32(M00514_CONTROL_BITMAP_EVCNT_CLEAR_MSK, &vo->control); in cobalt_dma_stop_streaming()
362 iowrite32(0, &vo->control); in cobalt_dma_stop_streaming()
366 spin_lock_irqsave(&s->irqlock, flags); in cobalt_dma_stop_streaming()
367 list_for_each_entry(cb, &s->bufs, list) { in cobalt_dma_stop_streaming()
368 desc = &s->dma_desc_info[cb->vb.vb2_buf.index]; in cobalt_dma_stop_streaming()
372 spin_unlock_irqrestore(&s->irqlock, flags); in cobalt_dma_stop_streaming()
375 if (!wait_event_timeout(s->q.done_wq, is_dma_done(s), in cobalt_dma_stop_streaming()
381 1 << s->dma_channel); in cobalt_dma_stop_streaming()
386 struct cobalt_stream *s = q->drv_priv; in cobalt_stop_streaming()
387 struct cobalt *cobalt = s->cobalt; in cobalt_stop_streaming()
388 int rx = s->video_channel; in cobalt_stop_streaming()
399 spin_lock_irqsave(&s->irqlock, flags); in cobalt_stop_streaming()
400 list_for_each_safe(p, safe, &s->bufs) { in cobalt_stop_streaming()
402 list_del(&cb->list); in cobalt_stop_streaming()
403 vb2_buffer_done(&cb->vb.vb2_buf, VB2_BUF_STATE_ERROR); in cobalt_stop_streaming()
405 spin_unlock_irqrestore(&s->irqlock, flags); in cobalt_stop_streaming()
407 if (s->is_audio || s->is_output) in cobalt_stop_streaming()
413 iowrite32(0, &vmr->control); in cobalt_stop_streaming()
414 iowrite32(M00233_CONTROL_BITMAP_ENABLE_MEASURE_MSK, &vmr->control); in cobalt_stop_streaming()
415 iowrite32(0, &fw->ctrl); in cobalt_stop_streaming()
416 iowrite32(0, &clkloss->ctrl); in cobalt_stop_streaming()
437 void __iomem *adrs = cobalt->bar1 + regs->reg; in cobalt_cobaltc()
442 return -EPERM; in cobalt_cobaltc()
444 regs->size = 4; in cobalt_cobaltc()
446 iowrite32(regs->val, adrs); in cobalt_cobaltc()
448 regs->val = ioread32(adrs); in cobalt_cobaltc()
456 struct cobalt *cobalt = s->cobalt; in cobalt_g_register()
465 struct cobalt *cobalt = s->cobalt; in cobalt_s_register()
476 struct cobalt *cobalt = s->cobalt; in cobalt_querycap()
478 strscpy(vcap->driver, "cobalt", sizeof(vcap->driver)); in cobalt_querycap()
479 strscpy(vcap->card, "cobalt", sizeof(vcap->card)); in cobalt_querycap()
480 snprintf(vcap->bus_info, sizeof(vcap->bus_info), in cobalt_querycap()
481 "PCIe:%s", pci_name(cobalt->pci_dev)); in cobalt_querycap()
482 vcap->capabilities = V4L2_CAP_STREAMING | V4L2_CAP_READWRITE | in cobalt_querycap()
484 if (cobalt->have_hsma_tx) in cobalt_querycap()
485 vcap->capabilities |= V4L2_CAP_VIDEO_OUTPUT; in cobalt_querycap()
496 int rx = s->video_channel; in cobalt_video_input_status_show()
497 struct cobalt *cobalt = s->cobalt; in cobalt_video_input_status_show()
506 cvi_ctrl = ioread32(&cvi->control); in cobalt_video_input_status_show()
507 cvi_stat = ioread32(&cvi->status); in cobalt_video_input_status_show()
508 vmr_ctrl = ioread32(&vmr->control); in cobalt_video_input_status_show()
509 vmr_stat = ioread32(&vmr->status); in cobalt_video_input_status_show()
511 ioread32(&cvi->frame_width), ioread32(&cvi->frame_height)); in cobalt_video_input_status_show()
516 "HSync- " : "HSync+ ", in cobalt_video_input_status_show()
518 "VSync- " : "VSync+ "); in cobalt_video_input_status_show()
521 "lock " : "no-lock ", in cobalt_video_input_status_show()
523 "error " : "no-error "); in cobalt_video_input_status_show()
527 "HSync- " : "HSync+ ", in cobalt_video_input_status_show()
529 "VSync- " : "VSync+ ", in cobalt_video_input_status_show()
533 "irq-enabled " : "irq-disabled ", in cobalt_video_input_status_show()
535 "update-on-hsync " : "", in cobalt_video_input_status_show()
537 "hsync-timeout " : "", in cobalt_video_input_status_show()
539 "init-done" : ""); in cobalt_video_input_status_show()
541 ioread32(&vmr->irq_status) & 0xff, in cobalt_video_input_status_show()
542 ioread32(&vmr->irq_triggers) & 0xff); in cobalt_video_input_status_show()
543 cobalt_info("rx%d: vsync: %d\n", rx, ioread32(&vmr->vsync_time)); in cobalt_video_input_status_show()
544 cobalt_info("rx%d: vbp: %d\n", rx, ioread32(&vmr->vback_porch)); in cobalt_video_input_status_show()
545 cobalt_info("rx%d: vact: %d\n", rx, ioread32(&vmr->vactive_area)); in cobalt_video_input_status_show()
546 cobalt_info("rx%d: vfb: %d\n", rx, ioread32(&vmr->vfront_porch)); in cobalt_video_input_status_show()
547 cobalt_info("rx%d: hsync: %d\n", rx, ioread32(&vmr->hsync_time)); in cobalt_video_input_status_show()
548 cobalt_info("rx%d: hbp: %d\n", rx, ioread32(&vmr->hback_porch)); in cobalt_video_input_status_show()
549 cobalt_info("rx%d: hact: %d\n", rx, ioread32(&vmr->hactive_area)); in cobalt_video_input_status_show()
550 cobalt_info("rx%d: hfb: %d\n", rx, ioread32(&vmr->hfront_porch)); in cobalt_video_input_status_show()
552 (ioread32(&fw->ctrl) & M00473_CTRL_BITMAP_ENABLE_MSK) ? in cobalt_video_input_status_show()
554 (ioread32(&fw->ctrl) & M00473_CTRL_BITMAP_FORCE_FREEWHEEL_MODE_MSK) ? in cobalt_video_input_status_show()
556 (ioread32(&fw->status) & M00473_STATUS_BITMAP_FREEWHEEL_MODE_MSK) ? in cobalt_video_input_status_show()
557 "freewheeling " : "video-passthrough "); in cobalt_video_input_status_show()
558 iowrite32(0xff, &vmr->irq_status); in cobalt_video_input_status_show()
560 (ioread32(&clkloss->ctrl) & M00479_CTRL_BITMAP_ENABLE_MSK) ? in cobalt_video_input_status_show()
562 (ioread32(&clkloss->status) & M00479_STATUS_BITMAP_CLOCK_MISSING_MSK) ? in cobalt_video_input_status_show()
563 "clock-missing " : "found-clock "); in cobalt_video_input_status_show()
564 cobalt_info("rx%d: Packer: %x\n", rx, ioread32(&packer->control)); in cobalt_video_input_status_show()
570 struct cobalt *cobalt = s->cobalt; in cobalt_log_status()
575 cobalt_info("%s", cobalt->hdl_info); in cobalt_log_status()
580 s->dma_channel, s->video_channel); in cobalt_log_status()
584 v4l2_subdev_call(s->sd, core, log_status); in cobalt_log_status()
585 if (!s->is_output) { in cobalt_log_status()
590 stat = ioread32(&vo->rd_status); in cobalt_log_status()
597 cobalt_info("tx: evcnt: %d\n", ioread32(&vo->rd_evcnt_count)); in cobalt_log_status()
606 if (s->input == 1) { in cobalt_enum_dv_timings()
607 if (timings->index) in cobalt_enum_dv_timings()
608 return -EINVAL; in cobalt_enum_dv_timings()
609 memset(timings->reserved, 0, sizeof(timings->reserved)); in cobalt_enum_dv_timings()
610 timings->timings = cea1080p60; in cobalt_enum_dv_timings()
613 timings->pad = 0; in cobalt_enum_dv_timings()
614 return v4l2_subdev_call(s->sd, in cobalt_enum_dv_timings()
624 if (s->input == 1) { in cobalt_s_dv_timings()
629 if (v4l2_match_dv_timings(timings, &s->timings, 0, true)) in cobalt_s_dv_timings()
632 if (vb2_is_busy(&s->q)) in cobalt_s_dv_timings()
633 return -EBUSY; in cobalt_s_dv_timings()
635 err = v4l2_subdev_call(s->sd, in cobalt_s_dv_timings()
638 s->timings = *timings; in cobalt_s_dv_timings()
639 s->width = timings->bt.width; in cobalt_s_dv_timings()
640 s->height = timings->bt.height; in cobalt_s_dv_timings()
641 s->stride = timings->bt.width * s->bpp; in cobalt_s_dv_timings()
651 if (s->input == 1) { in cobalt_g_dv_timings()
655 return v4l2_subdev_call(s->sd, in cobalt_g_dv_timings()
664 if (s->input == 1) { in cobalt_query_dv_timings()
668 return v4l2_subdev_call(s->sd, in cobalt_query_dv_timings()
677 cap->pad = 0; in cobalt_dv_timings_cap()
678 return v4l2_subdev_call(s->sd, in cobalt_dv_timings_cap()
685 switch (f->index) { in cobalt_enum_fmt_vid_cap()
687 f->pixelformat = V4L2_PIX_FMT_YUYV; in cobalt_enum_fmt_vid_cap()
690 f->pixelformat = V4L2_PIX_FMT_RGB24; in cobalt_enum_fmt_vid_cap()
693 f->pixelformat = V4L2_PIX_FMT_BGR32; in cobalt_enum_fmt_vid_cap()
696 return -EINVAL; in cobalt_enum_fmt_vid_cap()
706 struct v4l2_pix_format *pix = &f->fmt.pix; in cobalt_g_fmt_vid_cap() local
708 pix->width = s->width; in cobalt_g_fmt_vid_cap()
709 pix->height = s->height; in cobalt_g_fmt_vid_cap()
710 pix->bytesperline = s->stride; in cobalt_g_fmt_vid_cap()
711 pix->field = V4L2_FIELD_NONE; in cobalt_g_fmt_vid_cap()
713 if (s->input == 1) { in cobalt_g_fmt_vid_cap()
714 pix->colorspace = V4L2_COLORSPACE_SRGB; in cobalt_g_fmt_vid_cap()
717 .pad = s->pad_source, in cobalt_g_fmt_vid_cap()
721 v4l2_subdev_call(s->sd, pad, get_fmt, NULL, &sd_fmt); in cobalt_g_fmt_vid_cap()
722 v4l2_fill_pix_format(pix, &sd_fmt.format); in cobalt_g_fmt_vid_cap()
725 pix->pixelformat = s->pixfmt; in cobalt_g_fmt_vid_cap()
726 pix->sizeimage = pix->bytesperline * pix->height; in cobalt_g_fmt_vid_cap()
735 struct v4l2_pix_format *pix = &f->fmt.pix; in cobalt_try_fmt_vid_cap() local
737 /* Check for min (QCIF) and max (Full HD) size */ in cobalt_try_fmt_vid_cap()
738 if ((pix->width < 176) || (pix->height < 144)) { in cobalt_try_fmt_vid_cap()
739 pix->width = 176; in cobalt_try_fmt_vid_cap()
740 pix->height = 144; in cobalt_try_fmt_vid_cap()
743 if ((pix->width > 1920) || (pix->height > 1080)) { in cobalt_try_fmt_vid_cap()
744 pix->width = 1920; in cobalt_try_fmt_vid_cap()
745 pix->height = 1080; in cobalt_try_fmt_vid_cap()
749 pix->width &= ~0x3; in cobalt_try_fmt_vid_cap()
752 pix->height &= ~0x1; in cobalt_try_fmt_vid_cap()
754 if (s->input == 1) { in cobalt_try_fmt_vid_cap()
756 pix->width = 1920; in cobalt_try_fmt_vid_cap()
757 pix->height = 1080; in cobalt_try_fmt_vid_cap()
758 pix->colorspace = V4L2_COLORSPACE_SRGB; in cobalt_try_fmt_vid_cap()
761 .pad = s->pad_source, in cobalt_try_fmt_vid_cap()
765 v4l2_subdev_call(s->sd, pad, get_fmt, NULL, &sd_fmt); in cobalt_try_fmt_vid_cap()
766 v4l2_fill_pix_format(pix, &sd_fmt.format); in cobalt_try_fmt_vid_cap()
769 switch (pix->pixelformat) { in cobalt_try_fmt_vid_cap()
772 pix->bytesperline = max(pix->bytesperline & ~0x3, in cobalt_try_fmt_vid_cap()
773 pix->width * COBALT_BYTES_PER_PIXEL_YUYV); in cobalt_try_fmt_vid_cap()
774 pix->pixelformat = V4L2_PIX_FMT_YUYV; in cobalt_try_fmt_vid_cap()
777 pix->bytesperline = max(pix->bytesperline & ~0x3, in cobalt_try_fmt_vid_cap()
778 pix->width * COBALT_BYTES_PER_PIXEL_RGB24); in cobalt_try_fmt_vid_cap()
781 pix->bytesperline = max(pix->bytesperline & ~0x3, in cobalt_try_fmt_vid_cap()
782 pix->width * COBALT_BYTES_PER_PIXEL_RGB32); in cobalt_try_fmt_vid_cap()
786 pix->sizeimage = pix->bytesperline * pix->height; in cobalt_try_fmt_vid_cap()
787 pix->field = V4L2_FIELD_NONE; in cobalt_try_fmt_vid_cap()
796 struct v4l2_pix_format *pix = &f->fmt.pix; in cobalt_s_fmt_vid_cap() local
798 if (vb2_is_busy(&s->q)) in cobalt_s_fmt_vid_cap()
799 return -EBUSY; in cobalt_s_fmt_vid_cap()
802 return -EINVAL; in cobalt_s_fmt_vid_cap()
804 s->width = pix->width; in cobalt_s_fmt_vid_cap()
805 s->height = pix->height; in cobalt_s_fmt_vid_cap()
806 s->stride = pix->bytesperline; in cobalt_s_fmt_vid_cap()
807 switch (pix->pixelformat) { in cobalt_s_fmt_vid_cap()
809 s->bpp = COBALT_BYTES_PER_PIXEL_YUYV; in cobalt_s_fmt_vid_cap()
812 s->bpp = COBALT_BYTES_PER_PIXEL_RGB24; in cobalt_s_fmt_vid_cap()
815 s->bpp = COBALT_BYTES_PER_PIXEL_RGB32; in cobalt_s_fmt_vid_cap()
818 return -EINVAL; in cobalt_s_fmt_vid_cap()
820 s->pixfmt = pix->pixelformat; in cobalt_s_fmt_vid_cap()
829 struct v4l2_pix_format *pix = &f->fmt.pix; in cobalt_try_fmt_vid_out() local
831 /* Check for min (QCIF) and max (Full HD) size */ in cobalt_try_fmt_vid_out()
832 if ((pix->width < 176) || (pix->height < 144)) { in cobalt_try_fmt_vid_out()
833 pix->width = 176; in cobalt_try_fmt_vid_out()
834 pix->height = 144; in cobalt_try_fmt_vid_out()
837 if ((pix->width > 1920) || (pix->height > 1080)) { in cobalt_try_fmt_vid_out()
838 pix->width = 1920; in cobalt_try_fmt_vid_out()
839 pix->height = 1080; in cobalt_try_fmt_vid_out()
843 pix->width &= ~0x3; in cobalt_try_fmt_vid_out()
846 pix->height &= ~0x1; in cobalt_try_fmt_vid_out()
848 switch (pix->pixelformat) { in cobalt_try_fmt_vid_out()
851 pix->bytesperline = max(pix->bytesperline & ~0x3, in cobalt_try_fmt_vid_out()
852 pix->width * COBALT_BYTES_PER_PIXEL_YUYV); in cobalt_try_fmt_vid_out()
853 pix->pixelformat = V4L2_PIX_FMT_YUYV; in cobalt_try_fmt_vid_out()
856 pix->bytesperline = max(pix->bytesperline & ~0x3, in cobalt_try_fmt_vid_out()
857 pix->width * COBALT_BYTES_PER_PIXEL_RGB32); in cobalt_try_fmt_vid_out()
861 pix->sizeimage = pix->bytesperline * pix->height; in cobalt_try_fmt_vid_out()
862 pix->field = V4L2_FIELD_NONE; in cobalt_try_fmt_vid_out()
871 struct v4l2_pix_format *pix = &f->fmt.pix; in cobalt_g_fmt_vid_out() local
873 pix->width = s->width; in cobalt_g_fmt_vid_out()
874 pix->height = s->height; in cobalt_g_fmt_vid_out()
875 pix->bytesperline = s->stride; in cobalt_g_fmt_vid_out()
876 pix->field = V4L2_FIELD_NONE; in cobalt_g_fmt_vid_out()
877 pix->pixelformat = s->pixfmt; in cobalt_g_fmt_vid_out()
878 pix->colorspace = s->colorspace; in cobalt_g_fmt_vid_out()
879 pix->xfer_func = s->xfer_func; in cobalt_g_fmt_vid_out()
880 pix->ycbcr_enc = s->ycbcr_enc; in cobalt_g_fmt_vid_out()
881 pix->quantization = s->quantization; in cobalt_g_fmt_vid_out()
882 pix->sizeimage = pix->bytesperline * pix->height; in cobalt_g_fmt_vid_out()
890 switch (f->index) { in cobalt_enum_fmt_vid_out()
892 f->pixelformat = V4L2_PIX_FMT_YUYV; in cobalt_enum_fmt_vid_out()
895 f->pixelformat = V4L2_PIX_FMT_BGR32; in cobalt_enum_fmt_vid_out()
898 return -EINVAL; in cobalt_enum_fmt_vid_out()
908 struct v4l2_pix_format *pix = &f->fmt.pix; in cobalt_s_fmt_vid_out() local
915 return -EINVAL; in cobalt_s_fmt_vid_out()
917 if (vb2_is_busy(&s->q) && (pix->pixelformat != s->pixfmt || in cobalt_s_fmt_vid_out()
918 pix->width != s->width || pix->height != s->height || in cobalt_s_fmt_vid_out()
919 pix->bytesperline != s->stride)) in cobalt_s_fmt_vid_out()
920 return -EBUSY; in cobalt_s_fmt_vid_out()
922 switch (pix->pixelformat) { in cobalt_s_fmt_vid_out()
924 s->bpp = COBALT_BYTES_PER_PIXEL_YUYV; in cobalt_s_fmt_vid_out()
928 s->bpp = COBALT_BYTES_PER_PIXEL_RGB32; in cobalt_s_fmt_vid_out()
932 return -EINVAL; in cobalt_s_fmt_vid_out()
934 s->width = pix->width; in cobalt_s_fmt_vid_out()
935 s->height = pix->height; in cobalt_s_fmt_vid_out()
936 s->stride = pix->bytesperline; in cobalt_s_fmt_vid_out()
937 s->pixfmt = pix->pixelformat; in cobalt_s_fmt_vid_out()
938 s->colorspace = pix->colorspace; in cobalt_s_fmt_vid_out()
939 s->xfer_func = pix->xfer_func; in cobalt_s_fmt_vid_out()
940 s->ycbcr_enc = pix->ycbcr_enc; in cobalt_s_fmt_vid_out()
941 s->quantization = pix->quantization; in cobalt_s_fmt_vid_out()
942 v4l2_fill_mbus_format(&sd_fmt.format, pix, code); in cobalt_s_fmt_vid_out()
943 v4l2_subdev_call(s->sd, pad, set_fmt, NULL, &sd_fmt); in cobalt_s_fmt_vid_out()
952 if (inp->index > 1) in cobalt_enum_input()
953 return -EINVAL; in cobalt_enum_input()
954 if (inp->index == 0) in cobalt_enum_input()
955 snprintf(inp->name, sizeof(inp->name), in cobalt_enum_input()
956 "HDMI-%d", s->video_channel); in cobalt_enum_input()
958 snprintf(inp->name, sizeof(inp->name), in cobalt_enum_input()
959 "Generator-%d", s->video_channel); in cobalt_enum_input()
960 inp->type = V4L2_INPUT_TYPE_CAMERA; in cobalt_enum_input()
961 inp->capabilities = V4L2_IN_CAP_DV_TIMINGS; in cobalt_enum_input()
962 if (inp->index == 1) in cobalt_enum_input()
964 return v4l2_subdev_call(s->sd, in cobalt_enum_input()
965 video, g_input_status, &inp->status); in cobalt_enum_input()
972 *i = s->input; in cobalt_g_input()
981 return -EINVAL; in cobalt_s_input()
982 if (vb2_is_busy(&s->q)) in cobalt_s_input()
983 return -EBUSY; in cobalt_s_input()
984 s->input = i; in cobalt_s_input()
988 if (s->input == 1) /* Test Pattern Generator */ in cobalt_s_input()
991 return v4l2_subdev_call(s->sd, video, s_routing, in cobalt_s_input()
998 if (out->index) in cobalt_enum_output()
999 return -EINVAL; in cobalt_enum_output()
1000 snprintf(out->name, sizeof(out->name), "HDMI-%d", out->index); in cobalt_enum_output()
1001 out->type = V4L2_OUTPUT_TYPE_ANALOG; in cobalt_enum_output()
1002 out->capabilities = V4L2_OUT_CAP_DV_TIMINGS; in cobalt_enum_output()
1014 return i ? -EINVAL : 0; in cobalt_s_output()
1020 u32 pad = edid->pad; in cobalt_g_edid()
1023 if (edid->pad >= (s->is_output ? 1 : 2)) in cobalt_g_edid()
1024 return -EINVAL; in cobalt_g_edid()
1025 edid->pad = 0; in cobalt_g_edid()
1026 ret = v4l2_subdev_call(s->sd, pad, get_edid, edid); in cobalt_g_edid()
1027 edid->pad = pad; in cobalt_g_edid()
1034 u32 pad = edid->pad; in cobalt_s_edid()
1037 if (edid->pad >= 2) in cobalt_s_edid()
1038 return -EINVAL; in cobalt_s_edid()
1039 edid->pad = 0; in cobalt_s_edid()
1040 ret = v4l2_subdev_call(s->sd, pad, set_edid, edid); in cobalt_s_edid()
1041 edid->pad = pad; in cobalt_s_edid()
1048 switch (sub->type) { in cobalt_subscribe_event()
1060 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) in cobalt_g_parm()
1061 return -EINVAL; in cobalt_g_parm()
1063 fps = v4l2_calc_timeperframe(&s->timings); in cobalt_g_parm()
1064 a->parm.capture.timeperframe.numerator = fps.numerator; in cobalt_g_parm()
1065 a->parm.capture.timeperframe.denominator = fps.denominator; in cobalt_g_parm()
1066 a->parm.capture.readbuffers = 3; in cobalt_g_parm()
1078 return -EINVAL; in cobalt_g_pixelaspect()
1080 if (s->input == 1) in cobalt_g_pixelaspect()
1083 err = v4l2_subdev_call(s->sd, pad, g_dv_timings, 0, &timings); in cobalt_g_pixelaspect()
1096 if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) in cobalt_g_selection()
1097 return -EINVAL; in cobalt_g_selection()
1099 if (s->input == 1) in cobalt_g_selection()
1102 err = v4l2_subdev_call(s->sd, pad, g_dv_timings, 0, &timings); in cobalt_g_selection()
1107 switch (sel->target) { in cobalt_g_selection()
1110 sel->r.top = 0; in cobalt_g_selection()
1111 sel->r.left = 0; in cobalt_g_selection()
1112 sel->r.width = timings.bt.width; in cobalt_g_selection()
1113 sel->r.height = timings.bt.height; in cobalt_g_selection()
1116 return -EINVAL; in cobalt_g_selection()
1204 struct cobalt_stream *s = cobalt->streams + node; in cobalt_node_register()
1205 struct video_device *vdev = &s->vdev; in cobalt_node_register()
1206 struct vb2_queue *q = &s->q; in cobalt_node_register()
1209 mutex_init(&s->lock); in cobalt_node_register()
1210 spin_lock_init(&s->irqlock); in cobalt_node_register()
1212 snprintf(vdev->name, sizeof(vdev->name), in cobalt_node_register()
1213 "%s-%d", cobalt->v4l2_dev.name, node); in cobalt_node_register()
1214 s->width = 1920; in cobalt_node_register()
1216 s->height = s->is_audio ? 4 : 1080; in cobalt_node_register()
1218 if (s->is_audio) { in cobalt_node_register()
1219 s->bpp = 1; in cobalt_node_register()
1220 s->pixfmt = V4L2_PIX_FMT_GREY; in cobalt_node_register()
1221 } else if (s->is_output) { in cobalt_node_register()
1222 s->bpp = COBALT_BYTES_PER_PIXEL_RGB32; in cobalt_node_register()
1223 s->pixfmt = V4L2_PIX_FMT_BGR32; in cobalt_node_register()
1225 s->bpp = COBALT_BYTES_PER_PIXEL_YUYV; in cobalt_node_register()
1226 s->pixfmt = V4L2_PIX_FMT_YUYV; in cobalt_node_register()
1228 s->colorspace = V4L2_COLORSPACE_SRGB; in cobalt_node_register()
1229 s->stride = s->width * s->bpp; in cobalt_node_register()
1231 if (!s->is_audio) { in cobalt_node_register()
1232 if (s->is_dummy) in cobalt_node_register()
1234 vdev->v4l2_dev = &cobalt->v4l2_dev; in cobalt_node_register()
1235 if (s->is_dummy) in cobalt_node_register()
1236 vdev->fops = &cobalt_empty_fops; in cobalt_node_register()
1238 vdev->fops = s->is_output ? &cobalt_out_fops : in cobalt_node_register()
1240 vdev->release = video_device_release_empty; in cobalt_node_register()
1241 vdev->vfl_dir = s->is_output ? VFL_DIR_TX : VFL_DIR_RX; in cobalt_node_register()
1242 vdev->lock = &s->lock; in cobalt_node_register()
1243 if (s->sd) in cobalt_node_register()
1244 vdev->ctrl_handler = s->sd->ctrl_handler; in cobalt_node_register()
1245 s->timings = dv1080p60; in cobalt_node_register()
1246 v4l2_subdev_call(s->sd, pad, s_dv_timings, 0, &s->timings); in cobalt_node_register()
1247 if (!s->is_output && s->sd) in cobalt_node_register()
1249 vdev->ioctl_ops = s->is_dummy ? &cobalt_ioctl_empty_ops : in cobalt_node_register()
1253 INIT_LIST_HEAD(&s->bufs); in cobalt_node_register()
1254 q->type = s->is_output ? V4L2_BUF_TYPE_VIDEO_OUTPUT : in cobalt_node_register()
1256 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; in cobalt_node_register()
1257 q->io_modes |= s->is_output ? VB2_WRITE : VB2_READ; in cobalt_node_register()
1258 q->drv_priv = s; in cobalt_node_register()
1259 q->buf_struct_size = sizeof(struct cobalt_buffer); in cobalt_node_register()
1260 q->ops = &cobalt_qops; in cobalt_node_register()
1261 q->mem_ops = &vb2_dma_sg_memops; in cobalt_node_register()
1262 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in cobalt_node_register()
1263 q->min_queued_buffers = 2; in cobalt_node_register()
1264 q->lock = &s->lock; in cobalt_node_register()
1265 q->dev = &cobalt->pci_dev->dev; in cobalt_node_register()
1266 vdev->queue = q; in cobalt_node_register()
1267 vdev->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_READWRITE; in cobalt_node_register()
1268 if (s->is_output) in cobalt_node_register()
1269 vdev->device_caps |= V4L2_CAP_VIDEO_OUTPUT; in cobalt_node_register()
1271 vdev->device_caps |= V4L2_CAP_VIDEO_CAPTURE; in cobalt_node_register()
1275 if (!s->is_audio && ret == 0) in cobalt_node_register()
1276 ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1); in cobalt_node_register()
1277 else if (!s->is_dummy) in cobalt_node_register()
1281 if (!s->is_audio) in cobalt_node_register()
1311 struct cobalt_stream *s = cobalt->streams + node; in cobalt_nodes_unregister()
1312 struct video_device *vdev = &s->vdev; in cobalt_nodes_unregister()
1314 if (!s->is_audio) in cobalt_nodes_unregister()
1316 else if (!s->is_dummy) in cobalt_nodes_unregister()