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>
12 #include <linux/delay.h>
13 #include <linux/math64.h>
14 #include <linux/pci.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>
20 #include <media/i2c/adv7604.h>
21 #include <media/i2c/adv7842.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"
30 static const struct v4l2_dv_timings cea1080p60
= V4L2_DV_BT_CEA_1920X1080P60
;
32 /* vb2 DMA streaming ops */
34 static int cobalt_queue_setup(struct vb2_queue
*q
,
35 unsigned int *num_buffers
, unsigned int *num_planes
,
36 unsigned int sizes
[], struct device
*alloc_devs
[])
38 struct cobalt_stream
*s
= q
->drv_priv
;
39 unsigned size
= s
->stride
* s
->height
;
43 if (*num_buffers
> NR_BUFS
)
44 *num_buffers
= NR_BUFS
;
46 return sizes
[0] < size
? -EINVAL
: 0;
52 static int cobalt_buf_init(struct vb2_buffer
*vb
)
54 struct cobalt_stream
*s
= vb
->vb2_queue
->drv_priv
;
55 struct cobalt
*cobalt
= s
->cobalt
;
56 const size_t max_pages_per_line
=
57 (COBALT_MAX_WIDTH
* COBALT_MAX_BPP
) / PAGE_SIZE
+ 2;
59 COBALT_MAX_HEIGHT
* max_pages_per_line
* 0x20;
60 const size_t audio_bytes
= ((1920 * 4) / PAGE_SIZE
+ 1) * 0x20;
61 struct sg_dma_desc_info
*desc
= &s
->dma_desc_info
[vb
->index
];
62 struct sg_table
*sg_desc
= vb2_dma_sg_plane_desc(vb
, 0);
66 size
= s
->stride
* s
->height
;
67 if (vb2_plane_size(vb
, 0) < size
) {
68 cobalt_info("data will not fit into plane (%lu < %u)\n",
69 vb2_plane_size(vb
, 0), size
);
73 if (desc
->virt
== NULL
) {
74 desc
->dev
= &cobalt
->pci_dev
->dev
;
75 descriptor_list_allocate(desc
,
76 s
->is_audio
? audio_bytes
: bytes
);
77 if (desc
->virt
== NULL
)
80 ret
= descriptor_list_create(cobalt
, sg_desc
->sgl
,
81 !s
->is_output
, sg_desc
->nents
, size
,
82 s
->width
* s
->bpp
, s
->stride
, desc
);
84 descriptor_list_free(desc
);
88 static void cobalt_buf_cleanup(struct vb2_buffer
*vb
)
90 struct cobalt_stream
*s
= vb
->vb2_queue
->drv_priv
;
91 struct sg_dma_desc_info
*desc
= &s
->dma_desc_info
[vb
->index
];
93 descriptor_list_free(desc
);
96 static int cobalt_buf_prepare(struct vb2_buffer
*vb
)
98 struct vb2_v4l2_buffer
*vbuf
= to_vb2_v4l2_buffer(vb
);
99 struct cobalt_stream
*s
= vb
->vb2_queue
->drv_priv
;
101 vb2_set_plane_payload(vb
, 0, s
->stride
* s
->height
);
102 vbuf
->field
= V4L2_FIELD_NONE
;
106 static void chain_all_buffers(struct cobalt_stream
*s
)
108 struct sg_dma_desc_info
*desc
[NR_BUFS
];
109 struct cobalt_buffer
*cb
;
113 list_for_each(p
, &s
->bufs
) {
114 cb
= list_entry(p
, struct cobalt_buffer
, list
);
115 desc
[i
] = &s
->dma_desc_info
[cb
->vb
.vb2_buf
.index
];
117 descriptor_list_chain(desc
[i
-1], desc
[i
]);
122 static void cobalt_buf_queue(struct vb2_buffer
*vb
)
124 struct vb2_v4l2_buffer
*vbuf
= to_vb2_v4l2_buffer(vb
);
125 struct vb2_queue
*q
= vb
->vb2_queue
;
126 struct cobalt_stream
*s
= q
->drv_priv
;
127 struct cobalt_buffer
*cb
= to_cobalt_buffer(vbuf
);
128 struct sg_dma_desc_info
*desc
= &s
->dma_desc_info
[vb
->index
];
131 /* Prepare new buffer */
132 descriptor_list_loopback(desc
);
133 descriptor_list_interrupt_disable(desc
);
135 spin_lock_irqsave(&s
->irqlock
, flags
);
136 list_add_tail(&cb
->list
, &s
->bufs
);
137 chain_all_buffers(s
);
138 spin_unlock_irqrestore(&s
->irqlock
, flags
);
141 static void cobalt_enable_output(struct cobalt_stream
*s
)
143 struct cobalt
*cobalt
= s
->cobalt
;
144 struct v4l2_bt_timings
*bt
= &s
->timings
.bt
;
145 struct m00514_syncgen_flow_evcnt_regmap __iomem
*vo
=
146 COBALT_TX_BASE(cobalt
);
147 unsigned fmt
= s
->pixfmt
!= V4L2_PIX_FMT_BGR32
?
148 M00514_CONTROL_BITMAP_FORMAT_16_BPP_MSK
: 0;
149 struct v4l2_subdev_format sd_fmt
= {
150 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
152 u64 clk
= bt
->pixelclock
;
154 if (bt
->flags
& V4L2_DV_FL_REDUCED_FPS
)
155 clk
= div_u64(clk
* 1000ULL, 1001);
156 if (!cobalt_cpld_set_freq(cobalt
, clk
)) {
157 cobalt_err("pixelclock out of range\n");
161 sd_fmt
.format
.colorspace
= s
->colorspace
;
162 sd_fmt
.format
.xfer_func
= s
->xfer_func
;
163 sd_fmt
.format
.ycbcr_enc
= s
->ycbcr_enc
;
164 sd_fmt
.format
.quantization
= s
->quantization
;
165 sd_fmt
.format
.width
= bt
->width
;
166 sd_fmt
.format
.height
= bt
->height
;
168 /* Set up FDMA packer */
170 case V4L2_PIX_FMT_YUYV
:
171 sd_fmt
.format
.code
= MEDIA_BUS_FMT_UYVY8_1X16
;
173 case V4L2_PIX_FMT_BGR32
:
174 sd_fmt
.format
.code
= MEDIA_BUS_FMT_RGB888_1X24
;
177 v4l2_subdev_call(s
->sd
, pad
, set_fmt
, NULL
, &sd_fmt
);
179 iowrite32(0, &vo
->control
);
181 iowrite32(bt
->hsync
, &vo
->sync_generator_h_sync_length
);
182 iowrite32(bt
->hbackporch
, &vo
->sync_generator_h_backporch_length
);
183 iowrite32(bt
->width
, &vo
->sync_generator_h_active_length
);
184 iowrite32(bt
->hfrontporch
, &vo
->sync_generator_h_frontporch_length
);
185 iowrite32(bt
->vsync
, &vo
->sync_generator_v_sync_length
);
186 iowrite32(bt
->vbackporch
, &vo
->sync_generator_v_backporch_length
);
187 iowrite32(bt
->height
, &vo
->sync_generator_v_active_length
);
188 iowrite32(bt
->vfrontporch
, &vo
->sync_generator_v_frontporch_length
);
189 iowrite32(0x9900c1, &vo
->error_color
);
191 iowrite32(M00514_CONTROL_BITMAP_SYNC_GENERATOR_LOAD_PARAM_MSK
| fmt
,
193 iowrite32(M00514_CONTROL_BITMAP_EVCNT_CLEAR_MSK
| fmt
, &vo
->control
);
194 iowrite32(M00514_CONTROL_BITMAP_SYNC_GENERATOR_ENABLE_MSK
|
195 M00514_CONTROL_BITMAP_FLOW_CTRL_OUTPUT_ENABLE_MSK
|
199 static void cobalt_enable_input(struct cobalt_stream
*s
)
201 struct cobalt
*cobalt
= s
->cobalt
;
202 int ch
= (int)s
->video_channel
;
203 struct m00235_fdma_packer_regmap __iomem
*packer
;
204 struct v4l2_subdev_format sd_fmt_yuyv
= {
205 .pad
= s
->pad_source
,
206 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
207 .format
.code
= MEDIA_BUS_FMT_YUYV8_1X16
,
209 struct v4l2_subdev_format sd_fmt_rgb
= {
210 .pad
= s
->pad_source
,
211 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
212 .format
.code
= MEDIA_BUS_FMT_RGB888_1X24
,
215 cobalt_dbg(1, "video_channel %d (%s, %s)\n",
217 s
->input
== 0 ? "hdmi" : "generator",
220 packer
= COBALT_CVI_PACKER(cobalt
, ch
);
222 /* Set up FDMA packer */
224 case V4L2_PIX_FMT_YUYV
:
225 iowrite32(M00235_CONTROL_BITMAP_ENABLE_MSK
|
226 (1 << M00235_CONTROL_BITMAP_PACK_FORMAT_OFST
),
228 v4l2_subdev_call(s
->sd
, pad
, set_fmt
, NULL
,
231 case V4L2_PIX_FMT_RGB24
:
232 iowrite32(M00235_CONTROL_BITMAP_ENABLE_MSK
|
233 (2 << M00235_CONTROL_BITMAP_PACK_FORMAT_OFST
),
235 v4l2_subdev_call(s
->sd
, pad
, set_fmt
, NULL
,
238 case V4L2_PIX_FMT_BGR32
:
239 iowrite32(M00235_CONTROL_BITMAP_ENABLE_MSK
|
240 M00235_CONTROL_BITMAP_ENDIAN_FORMAT_MSK
|
241 (3 << M00235_CONTROL_BITMAP_PACK_FORMAT_OFST
),
243 v4l2_subdev_call(s
->sd
, pad
, set_fmt
, NULL
,
249 static void cobalt_dma_start_streaming(struct cobalt_stream
*s
)
251 struct cobalt
*cobalt
= s
->cobalt
;
252 int rx
= s
->video_channel
;
253 struct m00460_evcnt_regmap __iomem
*evcnt
=
254 COBALT_CVI_EVCNT(cobalt
, rx
);
255 struct cobalt_buffer
*cb
;
258 spin_lock_irqsave(&s
->irqlock
, flags
);
260 iowrite32(M00460_CONTROL_BITMAP_CLEAR_MSK
, &evcnt
->control
);
261 iowrite32(M00460_CONTROL_BITMAP_ENABLE_MSK
, &evcnt
->control
);
263 struct m00514_syncgen_flow_evcnt_regmap __iomem
*vo
=
264 COBALT_TX_BASE(cobalt
);
265 u32 ctrl
= ioread32(&vo
->control
);
267 ctrl
&= ~(M00514_CONTROL_BITMAP_EVCNT_ENABLE_MSK
|
268 M00514_CONTROL_BITMAP_EVCNT_CLEAR_MSK
);
269 iowrite32(ctrl
| M00514_CONTROL_BITMAP_EVCNT_CLEAR_MSK
,
271 iowrite32(ctrl
| M00514_CONTROL_BITMAP_EVCNT_ENABLE_MSK
,
274 cb
= list_first_entry(&s
->bufs
, struct cobalt_buffer
, list
);
275 omni_sg_dma_start(s
, &s
->dma_desc_info
[cb
->vb
.vb2_buf
.index
]);
276 spin_unlock_irqrestore(&s
->irqlock
, flags
);
279 static int cobalt_start_streaming(struct vb2_queue
*q
, unsigned int count
)
281 struct cobalt_stream
*s
= q
->drv_priv
;
282 struct cobalt
*cobalt
= s
->cobalt
;
283 struct m00233_video_measure_regmap __iomem
*vmr
;
284 struct m00473_freewheel_regmap __iomem
*fw
;
285 struct m00479_clk_loss_detector_regmap __iomem
*clkloss
;
286 int rx
= s
->video_channel
;
287 struct m00389_cvi_regmap __iomem
*cvi
= COBALT_CVI(cobalt
, rx
);
288 struct m00460_evcnt_regmap __iomem
*evcnt
= COBALT_CVI_EVCNT(cobalt
, rx
);
289 struct v4l2_bt_timings
*bt
= &s
->timings
.bt
;
296 s
->unstable_frame
= false;
297 cobalt_enable_output(s
);
301 cobalt_enable_input(s
);
303 fw
= COBALT_CVI_FREEWHEEL(cobalt
, rx
);
304 vmr
= COBALT_CVI_VMR(cobalt
, rx
);
305 clkloss
= COBALT_CVI_CLK_LOSS(cobalt
, rx
);
307 iowrite32(M00460_CONTROL_BITMAP_CLEAR_MSK
, &evcnt
->control
);
308 iowrite32(M00460_CONTROL_BITMAP_ENABLE_MSK
, &evcnt
->control
);
309 iowrite32(bt
->width
, &cvi
->frame_width
);
310 iowrite32(bt
->height
, &cvi
->frame_height
);
311 tot_size
= V4L2_DV_BT_FRAME_WIDTH(bt
) * V4L2_DV_BT_FRAME_HEIGHT(bt
);
312 iowrite32(div_u64((u64
)V4L2_DV_BT_FRAME_WIDTH(bt
) * COBALT_CLK
* 4,
313 bt
->pixelclock
), &vmr
->hsync_timeout_val
);
314 iowrite32(M00233_CONTROL_BITMAP_ENABLE_MEASURE_MSK
, &vmr
->control
);
315 clk_freq
= ioread32(&fw
->clk_freq
);
316 iowrite32(clk_freq
/ 1000000, &clkloss
->ref_clk_cnt_val
);
317 /* The lower bound for the clock frequency is 0.5% lower as is
318 * allowed by the spec */
319 iowrite32(div_u64(bt
->pixelclock
* 995, 1000000000),
320 &clkloss
->test_clk_cnt_val
);
321 /* will be enabled after the first frame has been received */
322 iowrite32(bt
->width
* bt
->height
, &fw
->active_length
);
323 iowrite32(div_u64((u64
)clk_freq
* tot_size
, bt
->pixelclock
),
325 iowrite32(M00233_IRQ_TRIGGERS_BITMAP_VACTIVE_AREA_MSK
|
326 M00233_IRQ_TRIGGERS_BITMAP_HACTIVE_AREA_MSK
,
328 iowrite32(0, &cvi
->control
);
329 iowrite32(M00233_CONTROL_BITMAP_ENABLE_MEASURE_MSK
, &vmr
->control
);
331 iowrite32(0xff, &fw
->output_color
);
332 iowrite32(M00479_CTRL_BITMAP_ENABLE_MSK
, &clkloss
->ctrl
);
333 iowrite32(M00473_CTRL_BITMAP_ENABLE_MSK
|
334 M00473_CTRL_BITMAP_FORCE_FREEWHEEL_MODE_MSK
, &fw
->ctrl
);
335 s
->unstable_frame
= true;
336 s
->enable_freewheel
= false;
337 s
->enable_cvi
= false;
338 s
->skip_first_frames
= 0;
342 cobalt_dma_start_streaming(s
);
346 static void cobalt_dma_stop_streaming(struct cobalt_stream
*s
)
348 struct cobalt
*cobalt
= s
->cobalt
;
349 struct sg_dma_desc_info
*desc
;
350 struct cobalt_buffer
*cb
;
353 int timeout_msec
= 100;
354 int rx
= s
->video_channel
;
355 struct m00460_evcnt_regmap __iomem
*evcnt
=
356 COBALT_CVI_EVCNT(cobalt
, rx
);
359 iowrite32(0, &evcnt
->control
);
360 } else if (!s
->is_audio
) {
361 struct m00514_syncgen_flow_evcnt_regmap __iomem
*vo
=
362 COBALT_TX_BASE(cobalt
);
364 iowrite32(M00514_CONTROL_BITMAP_EVCNT_CLEAR_MSK
, &vo
->control
);
365 iowrite32(0, &vo
->control
);
368 /* Try to stop the DMA engine gracefully */
369 spin_lock_irqsave(&s
->irqlock
, flags
);
370 list_for_each(p
, &s
->bufs
) {
371 cb
= list_entry(p
, struct cobalt_buffer
, list
);
372 desc
= &s
->dma_desc_info
[cb
->vb
.vb2_buf
.index
];
373 /* Stop DMA after this descriptor chain */
374 descriptor_list_end_of_chain(desc
);
376 spin_unlock_irqrestore(&s
->irqlock
, flags
);
378 /* Wait 100 milisecond for DMA to finish, abort on timeout. */
379 if (!wait_event_timeout(s
->q
.done_wq
, is_dma_done(s
),
380 msecs_to_jiffies(timeout_msec
))) {
381 omni_sg_dma_abort_channel(s
);
382 pr_warn("aborted\n");
384 cobalt_write_bar0(cobalt
, DMA_INTERRUPT_STATUS_REG
,
385 1 << s
->dma_channel
);
388 static void cobalt_stop_streaming(struct vb2_queue
*q
)
390 struct cobalt_stream
*s
= q
->drv_priv
;
391 struct cobalt
*cobalt
= s
->cobalt
;
392 int rx
= s
->video_channel
;
393 struct m00233_video_measure_regmap __iomem
*vmr
;
394 struct m00473_freewheel_regmap __iomem
*fw
;
395 struct m00479_clk_loss_detector_regmap __iomem
*clkloss
;
396 struct cobalt_buffer
*cb
;
397 struct list_head
*p
, *safe
;
400 cobalt_dma_stop_streaming(s
);
402 /* Return all buffers to user space */
403 spin_lock_irqsave(&s
->irqlock
, flags
);
404 list_for_each_safe(p
, safe
, &s
->bufs
) {
405 cb
= list_entry(p
, struct cobalt_buffer
, list
);
407 vb2_buffer_done(&cb
->vb
.vb2_buf
, VB2_BUF_STATE_ERROR
);
409 spin_unlock_irqrestore(&s
->irqlock
, flags
);
411 if (s
->is_audio
|| s
->is_output
)
414 fw
= COBALT_CVI_FREEWHEEL(cobalt
, rx
);
415 vmr
= COBALT_CVI_VMR(cobalt
, rx
);
416 clkloss
= COBALT_CVI_CLK_LOSS(cobalt
, rx
);
417 iowrite32(0, &vmr
->control
);
418 iowrite32(M00233_CONTROL_BITMAP_ENABLE_MEASURE_MSK
, &vmr
->control
);
419 iowrite32(0, &fw
->ctrl
);
420 iowrite32(0, &clkloss
->ctrl
);
423 static const struct vb2_ops cobalt_qops
= {
424 .queue_setup
= cobalt_queue_setup
,
425 .buf_init
= cobalt_buf_init
,
426 .buf_cleanup
= cobalt_buf_cleanup
,
427 .buf_prepare
= cobalt_buf_prepare
,
428 .buf_queue
= cobalt_buf_queue
,
429 .start_streaming
= cobalt_start_streaming
,
430 .stop_streaming
= cobalt_stop_streaming
,
431 .wait_prepare
= vb2_ops_wait_prepare
,
432 .wait_finish
= vb2_ops_wait_finish
,
437 #ifdef CONFIG_VIDEO_ADV_DEBUG
438 static int cobalt_cobaltc(struct cobalt
*cobalt
, unsigned int cmd
, void *arg
)
440 struct v4l2_dbg_register
*regs
= arg
;
441 void __iomem
*adrs
= cobalt
->bar1
+ regs
->reg
;
443 cobalt_info("cobalt_cobaltc: adrs = %p\n", adrs
);
445 if (!capable(CAP_SYS_ADMIN
))
449 if (cmd
== VIDIOC_DBG_S_REGISTER
)
450 iowrite32(regs
->val
, adrs
);
452 regs
->val
= ioread32(adrs
);
456 static int cobalt_g_register(struct file
*file
, void *priv_fh
,
457 struct v4l2_dbg_register
*reg
)
459 struct cobalt_stream
*s
= video_drvdata(file
);
460 struct cobalt
*cobalt
= s
->cobalt
;
462 return cobalt_cobaltc(cobalt
, VIDIOC_DBG_G_REGISTER
, reg
);
465 static int cobalt_s_register(struct file
*file
, void *priv_fh
,
466 const struct v4l2_dbg_register
*reg
)
468 struct cobalt_stream
*s
= video_drvdata(file
);
469 struct cobalt
*cobalt
= s
->cobalt
;
471 return cobalt_cobaltc(cobalt
, VIDIOC_DBG_S_REGISTER
,
472 (struct v4l2_dbg_register
*)reg
);
476 static int cobalt_querycap(struct file
*file
, void *priv_fh
,
477 struct v4l2_capability
*vcap
)
479 struct cobalt_stream
*s
= video_drvdata(file
);
480 struct cobalt
*cobalt
= s
->cobalt
;
482 strlcpy(vcap
->driver
, "cobalt", sizeof(vcap
->driver
));
483 strlcpy(vcap
->card
, "cobalt", sizeof(vcap
->card
));
484 snprintf(vcap
->bus_info
, sizeof(vcap
->bus_info
),
485 "PCIe:%s", pci_name(cobalt
->pci_dev
));
486 vcap
->device_caps
= V4L2_CAP_STREAMING
| V4L2_CAP_READWRITE
;
488 vcap
->device_caps
|= V4L2_CAP_VIDEO_OUTPUT
;
490 vcap
->device_caps
|= V4L2_CAP_VIDEO_CAPTURE
;
491 vcap
->capabilities
= vcap
->device_caps
| V4L2_CAP_DEVICE_CAPS
|
492 V4L2_CAP_VIDEO_CAPTURE
;
493 if (cobalt
->have_hsma_tx
)
494 vcap
->capabilities
|= V4L2_CAP_VIDEO_OUTPUT
;
498 static void cobalt_video_input_status_show(struct cobalt_stream
*s
)
500 struct m00389_cvi_regmap __iomem
*cvi
;
501 struct m00233_video_measure_regmap __iomem
*vmr
;
502 struct m00473_freewheel_regmap __iomem
*fw
;
503 struct m00479_clk_loss_detector_regmap __iomem
*clkloss
;
504 struct m00235_fdma_packer_regmap __iomem
*packer
;
505 int rx
= s
->video_channel
;
506 struct cobalt
*cobalt
= s
->cobalt
;
507 u32 cvi_ctrl
, cvi_stat
;
508 u32 vmr_ctrl
, vmr_stat
;
510 cvi
= COBALT_CVI(cobalt
, rx
);
511 vmr
= COBALT_CVI_VMR(cobalt
, rx
);
512 fw
= COBALT_CVI_FREEWHEEL(cobalt
, rx
);
513 clkloss
= COBALT_CVI_CLK_LOSS(cobalt
, rx
);
514 packer
= COBALT_CVI_PACKER(cobalt
, rx
);
515 cvi_ctrl
= ioread32(&cvi
->control
);
516 cvi_stat
= ioread32(&cvi
->status
);
517 vmr_ctrl
= ioread32(&vmr
->control
);
518 vmr_stat
= ioread32(&vmr
->status
);
519 cobalt_info("rx%d: cvi resolution: %dx%d\n", rx
,
520 ioread32(&cvi
->frame_width
), ioread32(&cvi
->frame_height
));
521 cobalt_info("rx%d: cvi control: %s%s%s\n", rx
,
522 (cvi_ctrl
& M00389_CONTROL_BITMAP_ENABLE_MSK
) ?
523 "enable " : "disable ",
524 (cvi_ctrl
& M00389_CONTROL_BITMAP_HSYNC_POLARITY_LOW_MSK
) ?
525 "HSync- " : "HSync+ ",
526 (cvi_ctrl
& M00389_CONTROL_BITMAP_VSYNC_POLARITY_LOW_MSK
) ?
527 "VSync- " : "VSync+ ");
528 cobalt_info("rx%d: cvi status: %s%s\n", rx
,
529 (cvi_stat
& M00389_STATUS_BITMAP_LOCK_MSK
) ?
530 "lock " : "no-lock ",
531 (cvi_stat
& M00389_STATUS_BITMAP_ERROR_MSK
) ?
532 "error " : "no-error ");
534 cobalt_info("rx%d: Measurements: %s%s%s%s%s%s%s\n", rx
,
535 (vmr_ctrl
& M00233_CONTROL_BITMAP_HSYNC_POLARITY_LOW_MSK
) ?
536 "HSync- " : "HSync+ ",
537 (vmr_ctrl
& M00233_CONTROL_BITMAP_VSYNC_POLARITY_LOW_MSK
) ?
538 "VSync- " : "VSync+ ",
539 (vmr_ctrl
& M00233_CONTROL_BITMAP_ENABLE_MEASURE_MSK
) ?
540 "enabled " : "disabled ",
541 (vmr_ctrl
& M00233_CONTROL_BITMAP_ENABLE_INTERRUPT_MSK
) ?
542 "irq-enabled " : "irq-disabled ",
543 (vmr_ctrl
& M00233_CONTROL_BITMAP_UPDATE_ON_HSYNC_MSK
) ?
544 "update-on-hsync " : "",
545 (vmr_stat
& M00233_STATUS_BITMAP_HSYNC_TIMEOUT_MSK
) ?
546 "hsync-timeout " : "",
547 (vmr_stat
& M00233_STATUS_BITMAP_INIT_DONE_MSK
) ?
549 cobalt_info("rx%d: irq_status: 0x%02x irq_triggers: 0x%02x\n", rx
,
550 ioread32(&vmr
->irq_status
) & 0xff,
551 ioread32(&vmr
->irq_triggers
) & 0xff);
552 cobalt_info("rx%d: vsync: %d\n", rx
, ioread32(&vmr
->vsync_time
));
553 cobalt_info("rx%d: vbp: %d\n", rx
, ioread32(&vmr
->vback_porch
));
554 cobalt_info("rx%d: vact: %d\n", rx
, ioread32(&vmr
->vactive_area
));
555 cobalt_info("rx%d: vfb: %d\n", rx
, ioread32(&vmr
->vfront_porch
));
556 cobalt_info("rx%d: hsync: %d\n", rx
, ioread32(&vmr
->hsync_time
));
557 cobalt_info("rx%d: hbp: %d\n", rx
, ioread32(&vmr
->hback_porch
));
558 cobalt_info("rx%d: hact: %d\n", rx
, ioread32(&vmr
->hactive_area
));
559 cobalt_info("rx%d: hfb: %d\n", rx
, ioread32(&vmr
->hfront_porch
));
560 cobalt_info("rx%d: Freewheeling: %s%s%s\n", rx
,
561 (ioread32(&fw
->ctrl
) & M00473_CTRL_BITMAP_ENABLE_MSK
) ?
562 "enabled " : "disabled ",
563 (ioread32(&fw
->ctrl
) & M00473_CTRL_BITMAP_FORCE_FREEWHEEL_MODE_MSK
) ?
565 (ioread32(&fw
->status
) & M00473_STATUS_BITMAP_FREEWHEEL_MODE_MSK
) ?
566 "freewheeling " : "video-passthrough ");
567 iowrite32(0xff, &vmr
->irq_status
);
568 cobalt_info("rx%d: Clock Loss Detection: %s%s\n", rx
,
569 (ioread32(&clkloss
->ctrl
) & M00479_CTRL_BITMAP_ENABLE_MSK
) ?
570 "enabled " : "disabled ",
571 (ioread32(&clkloss
->status
) & M00479_STATUS_BITMAP_CLOCK_MISSING_MSK
) ?
572 "clock-missing " : "found-clock ");
573 cobalt_info("rx%d: Packer: %x\n", rx
, ioread32(&packer
->control
));
576 static int cobalt_log_status(struct file
*file
, void *priv_fh
)
578 struct cobalt_stream
*s
= video_drvdata(file
);
579 struct cobalt
*cobalt
= s
->cobalt
;
580 struct m00514_syncgen_flow_evcnt_regmap __iomem
*vo
=
581 COBALT_TX_BASE(cobalt
);
584 cobalt_info("%s", cobalt
->hdl_info
);
585 cobalt_info("sysctrl: %08x, sysstat: %08x\n",
586 cobalt_g_sysctrl(cobalt
),
587 cobalt_g_sysstat(cobalt
));
588 cobalt_info("dma channel: %d, video channel: %d\n",
589 s
->dma_channel
, s
->video_channel
);
590 cobalt_pcie_status_show(cobalt
);
591 cobalt_cpld_status(cobalt
);
592 cobalt_irq_log_status(cobalt
);
593 v4l2_subdev_call(s
->sd
, core
, log_status
);
595 cobalt_video_input_status_show(s
);
599 stat
= ioread32(&vo
->rd_status
);
601 cobalt_info("tx: status: %s%s\n",
602 (stat
& M00514_RD_STATUS_BITMAP_FLOW_CTRL_NO_DATA_ERROR_MSK
) ?
604 (stat
& M00514_RD_STATUS_BITMAP_READY_BUFFER_FULL_MSK
) ?
605 "ready_buffer_full " : "");
606 cobalt_info("tx: evcnt: %d\n", ioread32(&vo
->rd_evcnt_count
));
610 static int cobalt_enum_dv_timings(struct file
*file
, void *priv_fh
,
611 struct v4l2_enum_dv_timings
*timings
)
613 struct cobalt_stream
*s
= video_drvdata(file
);
618 memset(timings
->reserved
, 0, sizeof(timings
->reserved
));
619 timings
->timings
= cea1080p60
;
623 return v4l2_subdev_call(s
->sd
,
624 pad
, enum_dv_timings
, timings
);
627 static int cobalt_s_dv_timings(struct file
*file
, void *priv_fh
,
628 struct v4l2_dv_timings
*timings
)
630 struct cobalt_stream
*s
= video_drvdata(file
);
634 *timings
= cea1080p60
;
638 if (v4l2_match_dv_timings(timings
, &s
->timings
, 0, true))
641 if (vb2_is_busy(&s
->q
))
644 err
= v4l2_subdev_call(s
->sd
,
645 video
, s_dv_timings
, timings
);
647 s
->timings
= *timings
;
648 s
->width
= timings
->bt
.width
;
649 s
->height
= timings
->bt
.height
;
650 s
->stride
= timings
->bt
.width
* s
->bpp
;
655 static int cobalt_g_dv_timings(struct file
*file
, void *priv_fh
,
656 struct v4l2_dv_timings
*timings
)
658 struct cobalt_stream
*s
= video_drvdata(file
);
661 *timings
= cea1080p60
;
664 return v4l2_subdev_call(s
->sd
,
665 video
, g_dv_timings
, timings
);
668 static int cobalt_query_dv_timings(struct file
*file
, void *priv_fh
,
669 struct v4l2_dv_timings
*timings
)
671 struct cobalt_stream
*s
= video_drvdata(file
);
674 *timings
= cea1080p60
;
677 return v4l2_subdev_call(s
->sd
,
678 video
, query_dv_timings
, timings
);
681 static int cobalt_dv_timings_cap(struct file
*file
, void *priv_fh
,
682 struct v4l2_dv_timings_cap
*cap
)
684 struct cobalt_stream
*s
= video_drvdata(file
);
687 return v4l2_subdev_call(s
->sd
,
688 pad
, dv_timings_cap
, cap
);
691 static int cobalt_enum_fmt_vid_cap(struct file
*file
, void *priv_fh
,
692 struct v4l2_fmtdesc
*f
)
696 strlcpy(f
->description
, "YUV 4:2:2", sizeof(f
->description
));
697 f
->pixelformat
= V4L2_PIX_FMT_YUYV
;
700 strlcpy(f
->description
, "RGB24", sizeof(f
->description
));
701 f
->pixelformat
= V4L2_PIX_FMT_RGB24
;
704 strlcpy(f
->description
, "RGB32", sizeof(f
->description
));
705 f
->pixelformat
= V4L2_PIX_FMT_BGR32
;
714 static int cobalt_g_fmt_vid_cap(struct file
*file
, void *priv_fh
,
715 struct v4l2_format
*f
)
717 struct cobalt_stream
*s
= video_drvdata(file
);
718 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
719 struct v4l2_subdev_format sd_fmt
;
721 pix
->width
= s
->width
;
722 pix
->height
= s
->height
;
723 pix
->bytesperline
= s
->stride
;
724 pix
->field
= V4L2_FIELD_NONE
;
727 pix
->colorspace
= V4L2_COLORSPACE_SRGB
;
729 sd_fmt
.pad
= s
->pad_source
;
730 sd_fmt
.which
= V4L2_SUBDEV_FORMAT_ACTIVE
;
731 v4l2_subdev_call(s
->sd
, pad
, get_fmt
, NULL
, &sd_fmt
);
732 v4l2_fill_pix_format(pix
, &sd_fmt
.format
);
735 pix
->pixelformat
= s
->pixfmt
;
736 pix
->sizeimage
= pix
->bytesperline
* pix
->height
;
741 static int cobalt_try_fmt_vid_cap(struct file
*file
, void *priv_fh
,
742 struct v4l2_format
*f
)
744 struct cobalt_stream
*s
= video_drvdata(file
);
745 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
746 struct v4l2_subdev_format sd_fmt
;
748 /* Check for min (QCIF) and max (Full HD) size */
749 if ((pix
->width
< 176) || (pix
->height
< 144)) {
754 if ((pix
->width
> 1920) || (pix
->height
> 1080)) {
759 /* Make width multiple of 4 */
762 /* Make height multiple of 2 */
766 /* Generator => fixed format only */
769 pix
->colorspace
= V4L2_COLORSPACE_SRGB
;
771 sd_fmt
.pad
= s
->pad_source
;
772 sd_fmt
.which
= V4L2_SUBDEV_FORMAT_ACTIVE
;
773 v4l2_subdev_call(s
->sd
, pad
, get_fmt
, NULL
, &sd_fmt
);
774 v4l2_fill_pix_format(pix
, &sd_fmt
.format
);
777 switch (pix
->pixelformat
) {
778 case V4L2_PIX_FMT_YUYV
:
780 pix
->bytesperline
= max(pix
->bytesperline
& ~0x3,
781 pix
->width
* COBALT_BYTES_PER_PIXEL_YUYV
);
782 pix
->pixelformat
= V4L2_PIX_FMT_YUYV
;
784 case V4L2_PIX_FMT_RGB24
:
785 pix
->bytesperline
= max(pix
->bytesperline
& ~0x3,
786 pix
->width
* COBALT_BYTES_PER_PIXEL_RGB24
);
788 case V4L2_PIX_FMT_BGR32
:
789 pix
->bytesperline
= max(pix
->bytesperline
& ~0x3,
790 pix
->width
* COBALT_BYTES_PER_PIXEL_RGB32
);
794 pix
->sizeimage
= pix
->bytesperline
* pix
->height
;
795 pix
->field
= V4L2_FIELD_NONE
;
801 static int cobalt_s_fmt_vid_cap(struct file
*file
, void *priv_fh
,
802 struct v4l2_format
*f
)
804 struct cobalt_stream
*s
= video_drvdata(file
);
805 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
807 if (vb2_is_busy(&s
->q
))
810 if (cobalt_try_fmt_vid_cap(file
, priv_fh
, f
))
813 s
->width
= pix
->width
;
814 s
->height
= pix
->height
;
815 s
->stride
= pix
->bytesperline
;
816 switch (pix
->pixelformat
) {
817 case V4L2_PIX_FMT_YUYV
:
818 s
->bpp
= COBALT_BYTES_PER_PIXEL_YUYV
;
820 case V4L2_PIX_FMT_RGB24
:
821 s
->bpp
= COBALT_BYTES_PER_PIXEL_RGB24
;
823 case V4L2_PIX_FMT_BGR32
:
824 s
->bpp
= COBALT_BYTES_PER_PIXEL_RGB32
;
829 s
->pixfmt
= pix
->pixelformat
;
830 cobalt_enable_input(s
);
835 static int cobalt_try_fmt_vid_out(struct file
*file
, void *priv_fh
,
836 struct v4l2_format
*f
)
838 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
840 /* Check for min (QCIF) and max (Full HD) size */
841 if ((pix
->width
< 176) || (pix
->height
< 144)) {
846 if ((pix
->width
> 1920) || (pix
->height
> 1080)) {
851 /* Make width multiple of 4 */
854 /* Make height multiple of 2 */
857 switch (pix
->pixelformat
) {
858 case V4L2_PIX_FMT_YUYV
:
860 pix
->bytesperline
= max(pix
->bytesperline
& ~0x3,
861 pix
->width
* COBALT_BYTES_PER_PIXEL_YUYV
);
862 pix
->pixelformat
= V4L2_PIX_FMT_YUYV
;
864 case V4L2_PIX_FMT_BGR32
:
865 pix
->bytesperline
= max(pix
->bytesperline
& ~0x3,
866 pix
->width
* COBALT_BYTES_PER_PIXEL_RGB32
);
870 pix
->sizeimage
= pix
->bytesperline
* pix
->height
;
871 pix
->field
= V4L2_FIELD_NONE
;
876 static int cobalt_g_fmt_vid_out(struct file
*file
, void *priv_fh
,
877 struct v4l2_format
*f
)
879 struct cobalt_stream
*s
= video_drvdata(file
);
880 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
882 pix
->width
= s
->width
;
883 pix
->height
= s
->height
;
884 pix
->bytesperline
= s
->stride
;
885 pix
->field
= V4L2_FIELD_NONE
;
886 pix
->pixelformat
= s
->pixfmt
;
887 pix
->colorspace
= s
->colorspace
;
888 pix
->xfer_func
= s
->xfer_func
;
889 pix
->ycbcr_enc
= s
->ycbcr_enc
;
890 pix
->quantization
= s
->quantization
;
891 pix
->sizeimage
= pix
->bytesperline
* pix
->height
;
896 static int cobalt_enum_fmt_vid_out(struct file
*file
, void *priv_fh
,
897 struct v4l2_fmtdesc
*f
)
901 strlcpy(f
->description
, "YUV 4:2:2", sizeof(f
->description
));
902 f
->pixelformat
= V4L2_PIX_FMT_YUYV
;
905 strlcpy(f
->description
, "RGB32", sizeof(f
->description
));
906 f
->pixelformat
= V4L2_PIX_FMT_BGR32
;
915 static int cobalt_s_fmt_vid_out(struct file
*file
, void *priv_fh
,
916 struct v4l2_format
*f
)
918 struct cobalt_stream
*s
= video_drvdata(file
);
919 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
920 struct v4l2_subdev_format sd_fmt
= { 0 };
923 if (cobalt_try_fmt_vid_out(file
, priv_fh
, f
))
926 if (vb2_is_busy(&s
->q
) && (pix
->pixelformat
!= s
->pixfmt
||
927 pix
->width
!= s
->width
|| pix
->height
!= s
->height
||
928 pix
->bytesperline
!= s
->stride
))
931 switch (pix
->pixelformat
) {
932 case V4L2_PIX_FMT_YUYV
:
933 s
->bpp
= COBALT_BYTES_PER_PIXEL_YUYV
;
934 code
= MEDIA_BUS_FMT_UYVY8_1X16
;
936 case V4L2_PIX_FMT_BGR32
:
937 s
->bpp
= COBALT_BYTES_PER_PIXEL_RGB32
;
938 code
= MEDIA_BUS_FMT_RGB888_1X24
;
943 s
->width
= pix
->width
;
944 s
->height
= pix
->height
;
945 s
->stride
= pix
->bytesperline
;
946 s
->pixfmt
= pix
->pixelformat
;
947 s
->colorspace
= pix
->colorspace
;
948 s
->xfer_func
= pix
->xfer_func
;
949 s
->ycbcr_enc
= pix
->ycbcr_enc
;
950 s
->quantization
= pix
->quantization
;
951 sd_fmt
.which
= V4L2_SUBDEV_FORMAT_ACTIVE
;
952 v4l2_fill_mbus_format(&sd_fmt
.format
, pix
, code
);
953 v4l2_subdev_call(s
->sd
, pad
, set_fmt
, NULL
, &sd_fmt
);
957 static int cobalt_enum_input(struct file
*file
, void *priv_fh
,
958 struct v4l2_input
*inp
)
960 struct cobalt_stream
*s
= video_drvdata(file
);
965 snprintf(inp
->name
, sizeof(inp
->name
),
966 "HDMI-%d", s
->video_channel
);
968 snprintf(inp
->name
, sizeof(inp
->name
),
969 "Generator-%d", s
->video_channel
);
970 inp
->type
= V4L2_INPUT_TYPE_CAMERA
;
971 inp
->capabilities
= V4L2_IN_CAP_DV_TIMINGS
;
974 return v4l2_subdev_call(s
->sd
,
975 video
, g_input_status
, &inp
->status
);
978 static int cobalt_g_input(struct file
*file
, void *priv_fh
, unsigned int *i
)
980 struct cobalt_stream
*s
= video_drvdata(file
);
986 static int cobalt_s_input(struct file
*file
, void *priv_fh
, unsigned int i
)
988 struct cobalt_stream
*s
= video_drvdata(file
);
992 if (vb2_is_busy(&s
->q
))
996 cobalt_enable_input(s
);
998 if (s
->input
== 1) /* Test Pattern Generator */
1001 return v4l2_subdev_call(s
->sd
, video
, s_routing
,
1002 ADV76XX_PAD_HDMI_PORT_A
, 0, 0);
1005 static int cobalt_enum_output(struct file
*file
, void *priv_fh
,
1006 struct v4l2_output
*out
)
1010 snprintf(out
->name
, sizeof(out
->name
), "HDMI-%d", out
->index
);
1011 out
->type
= V4L2_OUTPUT_TYPE_ANALOG
;
1012 out
->capabilities
= V4L2_OUT_CAP_DV_TIMINGS
;
1016 static int cobalt_g_output(struct file
*file
, void *priv_fh
, unsigned int *i
)
1022 static int cobalt_s_output(struct file
*file
, void *priv_fh
, unsigned int i
)
1024 return i
? -EINVAL
: 0;
1027 static int cobalt_g_edid(struct file
*file
, void *fh
, struct v4l2_edid
*edid
)
1029 struct cobalt_stream
*s
= video_drvdata(file
);
1030 u32 pad
= edid
->pad
;
1033 if (edid
->pad
>= (s
->is_output
? 1 : 2))
1036 ret
= v4l2_subdev_call(s
->sd
, pad
, get_edid
, edid
);
1041 static int cobalt_s_edid(struct file
*file
, void *fh
, struct v4l2_edid
*edid
)
1043 struct cobalt_stream
*s
= video_drvdata(file
);
1044 u32 pad
= edid
->pad
;
1050 ret
= v4l2_subdev_call(s
->sd
, pad
, set_edid
, edid
);
1055 static int cobalt_subscribe_event(struct v4l2_fh
*fh
,
1056 const struct v4l2_event_subscription
*sub
)
1058 switch (sub
->type
) {
1059 case V4L2_EVENT_SOURCE_CHANGE
:
1060 return v4l2_event_subscribe(fh
, sub
, 4, NULL
);
1062 return v4l2_ctrl_subscribe_event(fh
, sub
);
1065 static int cobalt_g_parm(struct file
*file
, void *fh
, struct v4l2_streamparm
*a
)
1067 if (a
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1069 a
->parm
.capture
.timeperframe
.numerator
= 1;
1070 a
->parm
.capture
.timeperframe
.denominator
= 60;
1071 a
->parm
.capture
.readbuffers
= 3;
1075 static int cobalt_cropcap(struct file
*file
, void *fh
, struct v4l2_cropcap
*cc
)
1077 struct cobalt_stream
*s
= video_drvdata(file
);
1078 struct v4l2_dv_timings timings
;
1081 if (cc
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1084 timings
= cea1080p60
;
1086 err
= v4l2_subdev_call(s
->sd
, video
, g_dv_timings
, &timings
);
1088 cc
->bounds
.width
= cc
->defrect
.width
= timings
.bt
.width
;
1089 cc
->bounds
.height
= cc
->defrect
.height
= timings
.bt
.height
;
1090 cc
->pixelaspect
= v4l2_dv_timings_aspect_ratio(&timings
);
1095 static const struct v4l2_ioctl_ops cobalt_ioctl_ops
= {
1096 .vidioc_querycap
= cobalt_querycap
,
1097 .vidioc_g_parm
= cobalt_g_parm
,
1098 .vidioc_log_status
= cobalt_log_status
,
1099 .vidioc_streamon
= vb2_ioctl_streamon
,
1100 .vidioc_streamoff
= vb2_ioctl_streamoff
,
1101 .vidioc_cropcap
= cobalt_cropcap
,
1102 .vidioc_enum_input
= cobalt_enum_input
,
1103 .vidioc_g_input
= cobalt_g_input
,
1104 .vidioc_s_input
= cobalt_s_input
,
1105 .vidioc_enum_fmt_vid_cap
= cobalt_enum_fmt_vid_cap
,
1106 .vidioc_g_fmt_vid_cap
= cobalt_g_fmt_vid_cap
,
1107 .vidioc_s_fmt_vid_cap
= cobalt_s_fmt_vid_cap
,
1108 .vidioc_try_fmt_vid_cap
= cobalt_try_fmt_vid_cap
,
1109 .vidioc_enum_output
= cobalt_enum_output
,
1110 .vidioc_g_output
= cobalt_g_output
,
1111 .vidioc_s_output
= cobalt_s_output
,
1112 .vidioc_enum_fmt_vid_out
= cobalt_enum_fmt_vid_out
,
1113 .vidioc_g_fmt_vid_out
= cobalt_g_fmt_vid_out
,
1114 .vidioc_s_fmt_vid_out
= cobalt_s_fmt_vid_out
,
1115 .vidioc_try_fmt_vid_out
= cobalt_try_fmt_vid_out
,
1116 .vidioc_s_dv_timings
= cobalt_s_dv_timings
,
1117 .vidioc_g_dv_timings
= cobalt_g_dv_timings
,
1118 .vidioc_query_dv_timings
= cobalt_query_dv_timings
,
1119 .vidioc_enum_dv_timings
= cobalt_enum_dv_timings
,
1120 .vidioc_dv_timings_cap
= cobalt_dv_timings_cap
,
1121 .vidioc_g_edid
= cobalt_g_edid
,
1122 .vidioc_s_edid
= cobalt_s_edid
,
1123 .vidioc_subscribe_event
= cobalt_subscribe_event
,
1124 .vidioc_unsubscribe_event
= v4l2_event_unsubscribe
,
1125 .vidioc_reqbufs
= vb2_ioctl_reqbufs
,
1126 .vidioc_create_bufs
= vb2_ioctl_create_bufs
,
1127 .vidioc_querybuf
= vb2_ioctl_querybuf
,
1128 .vidioc_qbuf
= vb2_ioctl_qbuf
,
1129 .vidioc_dqbuf
= vb2_ioctl_dqbuf
,
1130 .vidioc_expbuf
= vb2_ioctl_expbuf
,
1131 #ifdef CONFIG_VIDEO_ADV_DEBUG
1132 .vidioc_g_register
= cobalt_g_register
,
1133 .vidioc_s_register
= cobalt_s_register
,
1137 static const struct v4l2_ioctl_ops cobalt_ioctl_empty_ops
= {
1138 #ifdef CONFIG_VIDEO_ADV_DEBUG
1139 .vidioc_g_register
= cobalt_g_register
,
1140 .vidioc_s_register
= cobalt_s_register
,
1144 /* Register device nodes */
1146 static const struct v4l2_file_operations cobalt_fops
= {
1147 .owner
= THIS_MODULE
,
1148 .open
= v4l2_fh_open
,
1149 .unlocked_ioctl
= video_ioctl2
,
1150 .release
= vb2_fop_release
,
1151 .poll
= vb2_fop_poll
,
1152 .mmap
= vb2_fop_mmap
,
1153 .read
= vb2_fop_read
,
1156 static const struct v4l2_file_operations cobalt_out_fops
= {
1157 .owner
= THIS_MODULE
,
1158 .open
= v4l2_fh_open
,
1159 .unlocked_ioctl
= video_ioctl2
,
1160 .release
= vb2_fop_release
,
1161 .poll
= vb2_fop_poll
,
1162 .mmap
= vb2_fop_mmap
,
1163 .write
= vb2_fop_write
,
1166 static const struct v4l2_file_operations cobalt_empty_fops
= {
1167 .owner
= THIS_MODULE
,
1168 .open
= v4l2_fh_open
,
1169 .unlocked_ioctl
= video_ioctl2
,
1170 .release
= v4l2_fh_release
,
1173 static int cobalt_node_register(struct cobalt
*cobalt
, int node
)
1175 static const struct v4l2_dv_timings dv1080p60
=
1176 V4L2_DV_BT_CEA_1920X1080P60
;
1177 struct cobalt_stream
*s
= cobalt
->streams
+ node
;
1178 struct video_device
*vdev
= &s
->vdev
;
1179 struct vb2_queue
*q
= &s
->q
;
1182 mutex_init(&s
->lock
);
1183 spin_lock_init(&s
->irqlock
);
1185 snprintf(vdev
->name
, sizeof(vdev
->name
),
1186 "%s-%d", cobalt
->v4l2_dev
.name
, node
);
1188 /* Audio frames are just 4 lines of 1920 bytes */
1189 s
->height
= s
->is_audio
? 4 : 1080;
1193 s
->pixfmt
= V4L2_PIX_FMT_GREY
;
1194 } else if (s
->is_output
) {
1195 s
->bpp
= COBALT_BYTES_PER_PIXEL_RGB32
;
1196 s
->pixfmt
= V4L2_PIX_FMT_BGR32
;
1198 s
->bpp
= COBALT_BYTES_PER_PIXEL_YUYV
;
1199 s
->pixfmt
= V4L2_PIX_FMT_YUYV
;
1201 s
->colorspace
= V4L2_COLORSPACE_SRGB
;
1202 s
->stride
= s
->width
* s
->bpp
;
1206 cobalt_warn("Setting up dummy video node %d\n", node
);
1207 vdev
->v4l2_dev
= &cobalt
->v4l2_dev
;
1209 vdev
->fops
= &cobalt_empty_fops
;
1211 vdev
->fops
= s
->is_output
? &cobalt_out_fops
:
1213 vdev
->release
= video_device_release_empty
;
1214 vdev
->vfl_dir
= s
->is_output
? VFL_DIR_TX
: VFL_DIR_RX
;
1215 vdev
->lock
= &s
->lock
;
1217 vdev
->ctrl_handler
= s
->sd
->ctrl_handler
;
1218 s
->timings
= dv1080p60
;
1219 v4l2_subdev_call(s
->sd
, video
, s_dv_timings
, &s
->timings
);
1220 if (!s
->is_output
&& s
->sd
)
1221 cobalt_enable_input(s
);
1222 vdev
->ioctl_ops
= s
->is_dummy
? &cobalt_ioctl_empty_ops
:
1226 INIT_LIST_HEAD(&s
->bufs
);
1227 q
->type
= s
->is_output
? V4L2_BUF_TYPE_VIDEO_OUTPUT
:
1228 V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1229 q
->io_modes
= VB2_MMAP
| VB2_USERPTR
| VB2_DMABUF
;
1230 q
->io_modes
|= s
->is_output
? VB2_WRITE
: VB2_READ
;
1232 q
->buf_struct_size
= sizeof(struct cobalt_buffer
);
1233 q
->ops
= &cobalt_qops
;
1234 q
->mem_ops
= &vb2_dma_sg_memops
;
1235 q
->timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
;
1236 q
->min_buffers_needed
= 2;
1238 q
->dev
= &cobalt
->pci_dev
->dev
;
1241 video_set_drvdata(vdev
, s
);
1242 ret
= vb2_queue_init(q
);
1243 if (!s
->is_audio
&& ret
== 0)
1244 ret
= video_register_device(vdev
, VFL_TYPE_GRABBER
, -1);
1245 else if (!s
->is_dummy
)
1246 ret
= cobalt_alsa_init(s
);
1250 cobalt_err("couldn't register v4l2 device node %d\n",
1254 cobalt_info("registered node %d\n", node
);
1258 /* Initialize v4l2 variables and register v4l2 devices */
1259 int cobalt_nodes_register(struct cobalt
*cobalt
)
1263 /* Setup V4L2 Devices */
1264 for (node
= 0; node
< COBALT_NUM_STREAMS
; node
++) {
1265 ret
= cobalt_node_register(cobalt
, node
);
1272 /* Unregister v4l2 devices */
1273 void cobalt_nodes_unregister(struct cobalt
*cobalt
)
1277 /* Teardown all streams */
1278 for (node
= 0; node
< COBALT_NUM_STREAMS
; node
++) {
1279 struct cobalt_stream
*s
= cobalt
->streams
+ node
;
1280 struct video_device
*vdev
= &s
->vdev
;
1283 video_unregister_device(vdev
);
1284 else if (!s
->is_dummy
)
1285 cobalt_alsa_exit(s
);