4 * Derived from ivtv-ioctl.c and cx18-fileops.c
6 * Copyright 2012-2015 Cisco Systems, Inc. and/or its affiliates.
9 * This program is free software; you may redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
17 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #include <linux/dma-mapping.h>
24 #include <linux/delay.h>
25 #include <linux/math64.h>
26 #include <linux/pci.h>
27 #include <linux/v4l2-dv-timings.h>
29 #include <media/v4l2-ctrls.h>
30 #include <media/v4l2-event.h>
31 #include <media/v4l2-dv-timings.h>
32 #include <media/i2c/adv7604.h>
33 #include <media/i2c/adv7842.h>
35 #include "cobalt-alsa.h"
36 #include "cobalt-cpld.h"
37 #include "cobalt-driver.h"
38 #include "cobalt-v4l2.h"
39 #include "cobalt-irq.h"
40 #include "cobalt-omnitek.h"
42 static const struct v4l2_dv_timings cea1080p60
= V4L2_DV_BT_CEA_1920X1080P60
;
44 /* vb2 DMA streaming ops */
46 static int cobalt_queue_setup(struct vb2_queue
*q
,
47 unsigned int *num_buffers
, unsigned int *num_planes
,
48 unsigned int sizes
[], struct device
*alloc_devs
[])
50 struct cobalt_stream
*s
= q
->drv_priv
;
51 unsigned size
= s
->stride
* s
->height
;
55 if (*num_buffers
> NR_BUFS
)
56 *num_buffers
= NR_BUFS
;
58 return sizes
[0] < size
? -EINVAL
: 0;
64 static int cobalt_buf_init(struct vb2_buffer
*vb
)
66 struct cobalt_stream
*s
= vb
->vb2_queue
->drv_priv
;
67 struct cobalt
*cobalt
= s
->cobalt
;
68 const size_t max_pages_per_line
=
69 (COBALT_MAX_WIDTH
* COBALT_MAX_BPP
) / PAGE_SIZE
+ 2;
71 COBALT_MAX_HEIGHT
* max_pages_per_line
* 0x20;
72 const size_t audio_bytes
= ((1920 * 4) / PAGE_SIZE
+ 1) * 0x20;
73 struct sg_dma_desc_info
*desc
= &s
->dma_desc_info
[vb
->index
];
74 struct sg_table
*sg_desc
= vb2_dma_sg_plane_desc(vb
, 0);
78 size
= s
->stride
* s
->height
;
79 if (vb2_plane_size(vb
, 0) < size
) {
80 cobalt_info("data will not fit into plane (%lu < %u)\n",
81 vb2_plane_size(vb
, 0), size
);
85 if (desc
->virt
== NULL
) {
86 desc
->dev
= &cobalt
->pci_dev
->dev
;
87 descriptor_list_allocate(desc
,
88 s
->is_audio
? audio_bytes
: bytes
);
89 if (desc
->virt
== NULL
)
92 ret
= descriptor_list_create(cobalt
, sg_desc
->sgl
,
93 !s
->is_output
, sg_desc
->nents
, size
,
94 s
->width
* s
->bpp
, s
->stride
, desc
);
96 descriptor_list_free(desc
);
100 static void cobalt_buf_cleanup(struct vb2_buffer
*vb
)
102 struct cobalt_stream
*s
= vb
->vb2_queue
->drv_priv
;
103 struct sg_dma_desc_info
*desc
= &s
->dma_desc_info
[vb
->index
];
105 descriptor_list_free(desc
);
108 static int cobalt_buf_prepare(struct vb2_buffer
*vb
)
110 struct vb2_v4l2_buffer
*vbuf
= to_vb2_v4l2_buffer(vb
);
111 struct cobalt_stream
*s
= vb
->vb2_queue
->drv_priv
;
113 vb2_set_plane_payload(vb
, 0, s
->stride
* s
->height
);
114 vbuf
->field
= V4L2_FIELD_NONE
;
118 static void chain_all_buffers(struct cobalt_stream
*s
)
120 struct sg_dma_desc_info
*desc
[NR_BUFS
];
121 struct cobalt_buffer
*cb
;
125 list_for_each(p
, &s
->bufs
) {
126 cb
= list_entry(p
, struct cobalt_buffer
, list
);
127 desc
[i
] = &s
->dma_desc_info
[cb
->vb
.vb2_buf
.index
];
129 descriptor_list_chain(desc
[i
-1], desc
[i
]);
134 static void cobalt_buf_queue(struct vb2_buffer
*vb
)
136 struct vb2_v4l2_buffer
*vbuf
= to_vb2_v4l2_buffer(vb
);
137 struct vb2_queue
*q
= vb
->vb2_queue
;
138 struct cobalt_stream
*s
= q
->drv_priv
;
139 struct cobalt_buffer
*cb
= to_cobalt_buffer(vbuf
);
140 struct sg_dma_desc_info
*desc
= &s
->dma_desc_info
[vb
->index
];
143 /* Prepare new buffer */
144 descriptor_list_loopback(desc
);
145 descriptor_list_interrupt_disable(desc
);
147 spin_lock_irqsave(&s
->irqlock
, flags
);
148 list_add_tail(&cb
->list
, &s
->bufs
);
149 chain_all_buffers(s
);
150 spin_unlock_irqrestore(&s
->irqlock
, flags
);
153 static void cobalt_enable_output(struct cobalt_stream
*s
)
155 struct cobalt
*cobalt
= s
->cobalt
;
156 struct v4l2_bt_timings
*bt
= &s
->timings
.bt
;
157 struct m00514_syncgen_flow_evcnt_regmap __iomem
*vo
=
158 COBALT_TX_BASE(cobalt
);
159 unsigned fmt
= s
->pixfmt
!= V4L2_PIX_FMT_BGR32
?
160 M00514_CONTROL_BITMAP_FORMAT_16_BPP_MSK
: 0;
161 struct v4l2_subdev_format sd_fmt
= {
162 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
164 u64 clk
= bt
->pixelclock
;
166 if (bt
->flags
& V4L2_DV_FL_REDUCED_FPS
)
167 clk
= div_u64(clk
* 1000ULL, 1001);
168 if (!cobalt_cpld_set_freq(cobalt
, clk
)) {
169 cobalt_err("pixelclock out of range\n");
173 sd_fmt
.format
.colorspace
= s
->colorspace
;
174 sd_fmt
.format
.xfer_func
= s
->xfer_func
;
175 sd_fmt
.format
.ycbcr_enc
= s
->ycbcr_enc
;
176 sd_fmt
.format
.quantization
= s
->quantization
;
177 sd_fmt
.format
.width
= bt
->width
;
178 sd_fmt
.format
.height
= bt
->height
;
180 /* Set up FDMA packer */
182 case V4L2_PIX_FMT_YUYV
:
183 sd_fmt
.format
.code
= MEDIA_BUS_FMT_UYVY8_1X16
;
185 case V4L2_PIX_FMT_BGR32
:
186 sd_fmt
.format
.code
= MEDIA_BUS_FMT_RGB888_1X24
;
189 v4l2_subdev_call(s
->sd
, pad
, set_fmt
, NULL
, &sd_fmt
);
191 iowrite32(0, &vo
->control
);
193 iowrite32(bt
->hsync
, &vo
->sync_generator_h_sync_length
);
194 iowrite32(bt
->hbackporch
, &vo
->sync_generator_h_backporch_length
);
195 iowrite32(bt
->width
, &vo
->sync_generator_h_active_length
);
196 iowrite32(bt
->hfrontporch
, &vo
->sync_generator_h_frontporch_length
);
197 iowrite32(bt
->vsync
, &vo
->sync_generator_v_sync_length
);
198 iowrite32(bt
->vbackporch
, &vo
->sync_generator_v_backporch_length
);
199 iowrite32(bt
->height
, &vo
->sync_generator_v_active_length
);
200 iowrite32(bt
->vfrontporch
, &vo
->sync_generator_v_frontporch_length
);
201 iowrite32(0x9900c1, &vo
->error_color
);
203 iowrite32(M00514_CONTROL_BITMAP_SYNC_GENERATOR_LOAD_PARAM_MSK
| fmt
,
205 iowrite32(M00514_CONTROL_BITMAP_EVCNT_CLEAR_MSK
| fmt
, &vo
->control
);
206 iowrite32(M00514_CONTROL_BITMAP_SYNC_GENERATOR_ENABLE_MSK
|
207 M00514_CONTROL_BITMAP_FLOW_CTRL_OUTPUT_ENABLE_MSK
|
211 static void cobalt_enable_input(struct cobalt_stream
*s
)
213 struct cobalt
*cobalt
= s
->cobalt
;
214 int ch
= (int)s
->video_channel
;
215 struct m00235_fdma_packer_regmap __iomem
*packer
;
216 struct v4l2_subdev_format sd_fmt_yuyv
= {
217 .pad
= s
->pad_source
,
218 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
219 .format
.code
= MEDIA_BUS_FMT_YUYV8_1X16
,
221 struct v4l2_subdev_format sd_fmt_rgb
= {
222 .pad
= s
->pad_source
,
223 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
224 .format
.code
= MEDIA_BUS_FMT_RGB888_1X24
,
227 cobalt_dbg(1, "video_channel %d (%s, %s)\n",
229 s
->input
== 0 ? "hdmi" : "generator",
232 packer
= COBALT_CVI_PACKER(cobalt
, ch
);
234 /* Set up FDMA packer */
236 case V4L2_PIX_FMT_YUYV
:
237 iowrite32(M00235_CONTROL_BITMAP_ENABLE_MSK
|
238 (1 << M00235_CONTROL_BITMAP_PACK_FORMAT_OFST
),
240 v4l2_subdev_call(s
->sd
, pad
, set_fmt
, NULL
,
243 case V4L2_PIX_FMT_RGB24
:
244 iowrite32(M00235_CONTROL_BITMAP_ENABLE_MSK
|
245 (2 << M00235_CONTROL_BITMAP_PACK_FORMAT_OFST
),
247 v4l2_subdev_call(s
->sd
, pad
, set_fmt
, NULL
,
250 case V4L2_PIX_FMT_BGR32
:
251 iowrite32(M00235_CONTROL_BITMAP_ENABLE_MSK
|
252 M00235_CONTROL_BITMAP_ENDIAN_FORMAT_MSK
|
253 (3 << M00235_CONTROL_BITMAP_PACK_FORMAT_OFST
),
255 v4l2_subdev_call(s
->sd
, pad
, set_fmt
, NULL
,
261 static void cobalt_dma_start_streaming(struct cobalt_stream
*s
)
263 struct cobalt
*cobalt
= s
->cobalt
;
264 int rx
= s
->video_channel
;
265 struct m00460_evcnt_regmap __iomem
*evcnt
=
266 COBALT_CVI_EVCNT(cobalt
, rx
);
267 struct cobalt_buffer
*cb
;
270 spin_lock_irqsave(&s
->irqlock
, flags
);
272 iowrite32(M00460_CONTROL_BITMAP_CLEAR_MSK
, &evcnt
->control
);
273 iowrite32(M00460_CONTROL_BITMAP_ENABLE_MSK
, &evcnt
->control
);
275 struct m00514_syncgen_flow_evcnt_regmap __iomem
*vo
=
276 COBALT_TX_BASE(cobalt
);
277 u32 ctrl
= ioread32(&vo
->control
);
279 ctrl
&= ~(M00514_CONTROL_BITMAP_EVCNT_ENABLE_MSK
|
280 M00514_CONTROL_BITMAP_EVCNT_CLEAR_MSK
);
281 iowrite32(ctrl
| M00514_CONTROL_BITMAP_EVCNT_CLEAR_MSK
,
283 iowrite32(ctrl
| M00514_CONTROL_BITMAP_EVCNT_ENABLE_MSK
,
286 cb
= list_first_entry(&s
->bufs
, struct cobalt_buffer
, list
);
287 omni_sg_dma_start(s
, &s
->dma_desc_info
[cb
->vb
.vb2_buf
.index
]);
288 spin_unlock_irqrestore(&s
->irqlock
, flags
);
291 static int cobalt_start_streaming(struct vb2_queue
*q
, unsigned int count
)
293 struct cobalt_stream
*s
= q
->drv_priv
;
294 struct cobalt
*cobalt
= s
->cobalt
;
295 struct m00233_video_measure_regmap __iomem
*vmr
;
296 struct m00473_freewheel_regmap __iomem
*fw
;
297 struct m00479_clk_loss_detector_regmap __iomem
*clkloss
;
298 int rx
= s
->video_channel
;
299 struct m00389_cvi_regmap __iomem
*cvi
= COBALT_CVI(cobalt
, rx
);
300 struct m00460_evcnt_regmap __iomem
*evcnt
= COBALT_CVI_EVCNT(cobalt
, rx
);
301 struct v4l2_bt_timings
*bt
= &s
->timings
.bt
;
308 s
->unstable_frame
= false;
309 cobalt_enable_output(s
);
313 cobalt_enable_input(s
);
315 fw
= COBALT_CVI_FREEWHEEL(cobalt
, rx
);
316 vmr
= COBALT_CVI_VMR(cobalt
, rx
);
317 clkloss
= COBALT_CVI_CLK_LOSS(cobalt
, rx
);
319 iowrite32(M00460_CONTROL_BITMAP_CLEAR_MSK
, &evcnt
->control
);
320 iowrite32(M00460_CONTROL_BITMAP_ENABLE_MSK
, &evcnt
->control
);
321 iowrite32(bt
->width
, &cvi
->frame_width
);
322 iowrite32(bt
->height
, &cvi
->frame_height
);
323 tot_size
= V4L2_DV_BT_FRAME_WIDTH(bt
) * V4L2_DV_BT_FRAME_HEIGHT(bt
);
324 iowrite32(div_u64((u64
)V4L2_DV_BT_FRAME_WIDTH(bt
) * COBALT_CLK
* 4,
325 bt
->pixelclock
), &vmr
->hsync_timeout_val
);
326 iowrite32(M00233_CONTROL_BITMAP_ENABLE_MEASURE_MSK
, &vmr
->control
);
327 clk_freq
= ioread32(&fw
->clk_freq
);
328 iowrite32(clk_freq
/ 1000000, &clkloss
->ref_clk_cnt_val
);
329 /* The lower bound for the clock frequency is 0.5% lower as is
330 * allowed by the spec */
331 iowrite32(div_u64(bt
->pixelclock
* 995, 1000000000),
332 &clkloss
->test_clk_cnt_val
);
333 /* will be enabled after the first frame has been received */
334 iowrite32(bt
->width
* bt
->height
, &fw
->active_length
);
335 iowrite32(div_u64((u64
)clk_freq
* tot_size
, bt
->pixelclock
),
337 iowrite32(M00233_IRQ_TRIGGERS_BITMAP_VACTIVE_AREA_MSK
|
338 M00233_IRQ_TRIGGERS_BITMAP_HACTIVE_AREA_MSK
,
340 iowrite32(0, &cvi
->control
);
341 iowrite32(M00233_CONTROL_BITMAP_ENABLE_MEASURE_MSK
, &vmr
->control
);
343 iowrite32(0xff, &fw
->output_color
);
344 iowrite32(M00479_CTRL_BITMAP_ENABLE_MSK
, &clkloss
->ctrl
);
345 iowrite32(M00473_CTRL_BITMAP_ENABLE_MSK
|
346 M00473_CTRL_BITMAP_FORCE_FREEWHEEL_MODE_MSK
, &fw
->ctrl
);
347 s
->unstable_frame
= true;
348 s
->enable_freewheel
= false;
349 s
->enable_cvi
= false;
350 s
->skip_first_frames
= 0;
354 cobalt_dma_start_streaming(s
);
358 static void cobalt_dma_stop_streaming(struct cobalt_stream
*s
)
360 struct cobalt
*cobalt
= s
->cobalt
;
361 struct sg_dma_desc_info
*desc
;
362 struct cobalt_buffer
*cb
;
365 int timeout_msec
= 100;
366 int rx
= s
->video_channel
;
367 struct m00460_evcnt_regmap __iomem
*evcnt
=
368 COBALT_CVI_EVCNT(cobalt
, rx
);
371 iowrite32(0, &evcnt
->control
);
372 } else if (!s
->is_audio
) {
373 struct m00514_syncgen_flow_evcnt_regmap __iomem
*vo
=
374 COBALT_TX_BASE(cobalt
);
376 iowrite32(M00514_CONTROL_BITMAP_EVCNT_CLEAR_MSK
, &vo
->control
);
377 iowrite32(0, &vo
->control
);
380 /* Try to stop the DMA engine gracefully */
381 spin_lock_irqsave(&s
->irqlock
, flags
);
382 list_for_each(p
, &s
->bufs
) {
383 cb
= list_entry(p
, struct cobalt_buffer
, list
);
384 desc
= &s
->dma_desc_info
[cb
->vb
.vb2_buf
.index
];
385 /* Stop DMA after this descriptor chain */
386 descriptor_list_end_of_chain(desc
);
388 spin_unlock_irqrestore(&s
->irqlock
, flags
);
390 /* Wait 100 milisecond for DMA to finish, abort on timeout. */
391 if (!wait_event_timeout(s
->q
.done_wq
, is_dma_done(s
),
392 msecs_to_jiffies(timeout_msec
))) {
393 omni_sg_dma_abort_channel(s
);
394 pr_warn("aborted\n");
396 cobalt_write_bar0(cobalt
, DMA_INTERRUPT_STATUS_REG
,
397 1 << s
->dma_channel
);
400 static void cobalt_stop_streaming(struct vb2_queue
*q
)
402 struct cobalt_stream
*s
= q
->drv_priv
;
403 struct cobalt
*cobalt
= s
->cobalt
;
404 int rx
= s
->video_channel
;
405 struct m00233_video_measure_regmap __iomem
*vmr
;
406 struct m00473_freewheel_regmap __iomem
*fw
;
407 struct m00479_clk_loss_detector_regmap __iomem
*clkloss
;
408 struct cobalt_buffer
*cb
;
409 struct list_head
*p
, *safe
;
412 cobalt_dma_stop_streaming(s
);
414 /* Return all buffers to user space */
415 spin_lock_irqsave(&s
->irqlock
, flags
);
416 list_for_each_safe(p
, safe
, &s
->bufs
) {
417 cb
= list_entry(p
, struct cobalt_buffer
, list
);
419 vb2_buffer_done(&cb
->vb
.vb2_buf
, VB2_BUF_STATE_ERROR
);
421 spin_unlock_irqrestore(&s
->irqlock
, flags
);
423 if (s
->is_audio
|| s
->is_output
)
426 fw
= COBALT_CVI_FREEWHEEL(cobalt
, rx
);
427 vmr
= COBALT_CVI_VMR(cobalt
, rx
);
428 clkloss
= COBALT_CVI_CLK_LOSS(cobalt
, rx
);
429 iowrite32(0, &vmr
->control
);
430 iowrite32(M00233_CONTROL_BITMAP_ENABLE_MEASURE_MSK
, &vmr
->control
);
431 iowrite32(0, &fw
->ctrl
);
432 iowrite32(0, &clkloss
->ctrl
);
435 static const struct vb2_ops cobalt_qops
= {
436 .queue_setup
= cobalt_queue_setup
,
437 .buf_init
= cobalt_buf_init
,
438 .buf_cleanup
= cobalt_buf_cleanup
,
439 .buf_prepare
= cobalt_buf_prepare
,
440 .buf_queue
= cobalt_buf_queue
,
441 .start_streaming
= cobalt_start_streaming
,
442 .stop_streaming
= cobalt_stop_streaming
,
443 .wait_prepare
= vb2_ops_wait_prepare
,
444 .wait_finish
= vb2_ops_wait_finish
,
449 #ifdef CONFIG_VIDEO_ADV_DEBUG
450 static int cobalt_cobaltc(struct cobalt
*cobalt
, unsigned int cmd
, void *arg
)
452 struct v4l2_dbg_register
*regs
= arg
;
453 void __iomem
*adrs
= cobalt
->bar1
+ regs
->reg
;
455 cobalt_info("cobalt_cobaltc: adrs = %p\n", adrs
);
457 if (!capable(CAP_SYS_ADMIN
))
461 if (cmd
== VIDIOC_DBG_S_REGISTER
)
462 iowrite32(regs
->val
, adrs
);
464 regs
->val
= ioread32(adrs
);
468 static int cobalt_g_register(struct file
*file
, void *priv_fh
,
469 struct v4l2_dbg_register
*reg
)
471 struct cobalt_stream
*s
= video_drvdata(file
);
472 struct cobalt
*cobalt
= s
->cobalt
;
474 return cobalt_cobaltc(cobalt
, VIDIOC_DBG_G_REGISTER
, reg
);
477 static int cobalt_s_register(struct file
*file
, void *priv_fh
,
478 const struct v4l2_dbg_register
*reg
)
480 struct cobalt_stream
*s
= video_drvdata(file
);
481 struct cobalt
*cobalt
= s
->cobalt
;
483 return cobalt_cobaltc(cobalt
, VIDIOC_DBG_S_REGISTER
,
484 (struct v4l2_dbg_register
*)reg
);
488 static int cobalt_querycap(struct file
*file
, void *priv_fh
,
489 struct v4l2_capability
*vcap
)
491 struct cobalt_stream
*s
= video_drvdata(file
);
492 struct cobalt
*cobalt
= s
->cobalt
;
494 strlcpy(vcap
->driver
, "cobalt", sizeof(vcap
->driver
));
495 strlcpy(vcap
->card
, "cobalt", sizeof(vcap
->card
));
496 snprintf(vcap
->bus_info
, sizeof(vcap
->bus_info
),
497 "PCIe:%s", pci_name(cobalt
->pci_dev
));
498 vcap
->device_caps
= V4L2_CAP_STREAMING
| V4L2_CAP_READWRITE
;
500 vcap
->device_caps
|= V4L2_CAP_VIDEO_OUTPUT
;
502 vcap
->device_caps
|= V4L2_CAP_VIDEO_CAPTURE
;
503 vcap
->capabilities
= vcap
->device_caps
| V4L2_CAP_DEVICE_CAPS
|
504 V4L2_CAP_VIDEO_CAPTURE
;
505 if (cobalt
->have_hsma_tx
)
506 vcap
->capabilities
|= V4L2_CAP_VIDEO_OUTPUT
;
510 static void cobalt_video_input_status_show(struct cobalt_stream
*s
)
512 struct m00389_cvi_regmap __iomem
*cvi
;
513 struct m00233_video_measure_regmap __iomem
*vmr
;
514 struct m00473_freewheel_regmap __iomem
*fw
;
515 struct m00479_clk_loss_detector_regmap __iomem
*clkloss
;
516 struct m00235_fdma_packer_regmap __iomem
*packer
;
517 int rx
= s
->video_channel
;
518 struct cobalt
*cobalt
= s
->cobalt
;
519 u32 cvi_ctrl
, cvi_stat
;
520 u32 vmr_ctrl
, vmr_stat
;
522 cvi
= COBALT_CVI(cobalt
, rx
);
523 vmr
= COBALT_CVI_VMR(cobalt
, rx
);
524 fw
= COBALT_CVI_FREEWHEEL(cobalt
, rx
);
525 clkloss
= COBALT_CVI_CLK_LOSS(cobalt
, rx
);
526 packer
= COBALT_CVI_PACKER(cobalt
, rx
);
527 cvi_ctrl
= ioread32(&cvi
->control
);
528 cvi_stat
= ioread32(&cvi
->status
);
529 vmr_ctrl
= ioread32(&vmr
->control
);
530 vmr_stat
= ioread32(&vmr
->status
);
531 cobalt_info("rx%d: cvi resolution: %dx%d\n", rx
,
532 ioread32(&cvi
->frame_width
), ioread32(&cvi
->frame_height
));
533 cobalt_info("rx%d: cvi control: %s%s%s\n", rx
,
534 (cvi_ctrl
& M00389_CONTROL_BITMAP_ENABLE_MSK
) ?
535 "enable " : "disable ",
536 (cvi_ctrl
& M00389_CONTROL_BITMAP_HSYNC_POLARITY_LOW_MSK
) ?
537 "HSync- " : "HSync+ ",
538 (cvi_ctrl
& M00389_CONTROL_BITMAP_VSYNC_POLARITY_LOW_MSK
) ?
539 "VSync- " : "VSync+ ");
540 cobalt_info("rx%d: cvi status: %s%s\n", rx
,
541 (cvi_stat
& M00389_STATUS_BITMAP_LOCK_MSK
) ?
542 "lock " : "no-lock ",
543 (cvi_stat
& M00389_STATUS_BITMAP_ERROR_MSK
) ?
544 "error " : "no-error ");
546 cobalt_info("rx%d: Measurements: %s%s%s%s%s%s%s\n", rx
,
547 (vmr_ctrl
& M00233_CONTROL_BITMAP_HSYNC_POLARITY_LOW_MSK
) ?
548 "HSync- " : "HSync+ ",
549 (vmr_ctrl
& M00233_CONTROL_BITMAP_VSYNC_POLARITY_LOW_MSK
) ?
550 "VSync- " : "VSync+ ",
551 (vmr_ctrl
& M00233_CONTROL_BITMAP_ENABLE_MEASURE_MSK
) ?
552 "enabled " : "disabled ",
553 (vmr_ctrl
& M00233_CONTROL_BITMAP_ENABLE_INTERRUPT_MSK
) ?
554 "irq-enabled " : "irq-disabled ",
555 (vmr_ctrl
& M00233_CONTROL_BITMAP_UPDATE_ON_HSYNC_MSK
) ?
556 "update-on-hsync " : "",
557 (vmr_stat
& M00233_STATUS_BITMAP_HSYNC_TIMEOUT_MSK
) ?
558 "hsync-timeout " : "",
559 (vmr_stat
& M00233_STATUS_BITMAP_INIT_DONE_MSK
) ?
561 cobalt_info("rx%d: irq_status: 0x%02x irq_triggers: 0x%02x\n", rx
,
562 ioread32(&vmr
->irq_status
) & 0xff,
563 ioread32(&vmr
->irq_triggers
) & 0xff);
564 cobalt_info("rx%d: vsync: %d\n", rx
, ioread32(&vmr
->vsync_time
));
565 cobalt_info("rx%d: vbp: %d\n", rx
, ioread32(&vmr
->vback_porch
));
566 cobalt_info("rx%d: vact: %d\n", rx
, ioread32(&vmr
->vactive_area
));
567 cobalt_info("rx%d: vfb: %d\n", rx
, ioread32(&vmr
->vfront_porch
));
568 cobalt_info("rx%d: hsync: %d\n", rx
, ioread32(&vmr
->hsync_time
));
569 cobalt_info("rx%d: hbp: %d\n", rx
, ioread32(&vmr
->hback_porch
));
570 cobalt_info("rx%d: hact: %d\n", rx
, ioread32(&vmr
->hactive_area
));
571 cobalt_info("rx%d: hfb: %d\n", rx
, ioread32(&vmr
->hfront_porch
));
572 cobalt_info("rx%d: Freewheeling: %s%s%s\n", rx
,
573 (ioread32(&fw
->ctrl
) & M00473_CTRL_BITMAP_ENABLE_MSK
) ?
574 "enabled " : "disabled ",
575 (ioread32(&fw
->ctrl
) & M00473_CTRL_BITMAP_FORCE_FREEWHEEL_MODE_MSK
) ?
577 (ioread32(&fw
->status
) & M00473_STATUS_BITMAP_FREEWHEEL_MODE_MSK
) ?
578 "freewheeling " : "video-passthrough ");
579 iowrite32(0xff, &vmr
->irq_status
);
580 cobalt_info("rx%d: Clock Loss Detection: %s%s\n", rx
,
581 (ioread32(&clkloss
->ctrl
) & M00479_CTRL_BITMAP_ENABLE_MSK
) ?
582 "enabled " : "disabled ",
583 (ioread32(&clkloss
->status
) & M00479_STATUS_BITMAP_CLOCK_MISSING_MSK
) ?
584 "clock-missing " : "found-clock ");
585 cobalt_info("rx%d: Packer: %x\n", rx
, ioread32(&packer
->control
));
588 static int cobalt_log_status(struct file
*file
, void *priv_fh
)
590 struct cobalt_stream
*s
= video_drvdata(file
);
591 struct cobalt
*cobalt
= s
->cobalt
;
592 struct m00514_syncgen_flow_evcnt_regmap __iomem
*vo
=
593 COBALT_TX_BASE(cobalt
);
596 cobalt_info("%s", cobalt
->hdl_info
);
597 cobalt_info("sysctrl: %08x, sysstat: %08x\n",
598 cobalt_g_sysctrl(cobalt
),
599 cobalt_g_sysstat(cobalt
));
600 cobalt_info("dma channel: %d, video channel: %d\n",
601 s
->dma_channel
, s
->video_channel
);
602 cobalt_pcie_status_show(cobalt
);
603 cobalt_cpld_status(cobalt
);
604 cobalt_irq_log_status(cobalt
);
605 v4l2_subdev_call(s
->sd
, core
, log_status
);
607 cobalt_video_input_status_show(s
);
611 stat
= ioread32(&vo
->rd_status
);
613 cobalt_info("tx: status: %s%s\n",
614 (stat
& M00514_RD_STATUS_BITMAP_FLOW_CTRL_NO_DATA_ERROR_MSK
) ?
616 (stat
& M00514_RD_STATUS_BITMAP_READY_BUFFER_FULL_MSK
) ?
617 "ready_buffer_full " : "");
618 cobalt_info("tx: evcnt: %d\n", ioread32(&vo
->rd_evcnt_count
));
622 static int cobalt_enum_dv_timings(struct file
*file
, void *priv_fh
,
623 struct v4l2_enum_dv_timings
*timings
)
625 struct cobalt_stream
*s
= video_drvdata(file
);
630 memset(timings
->reserved
, 0, sizeof(timings
->reserved
));
631 timings
->timings
= cea1080p60
;
635 return v4l2_subdev_call(s
->sd
,
636 pad
, enum_dv_timings
, timings
);
639 static int cobalt_s_dv_timings(struct file
*file
, void *priv_fh
,
640 struct v4l2_dv_timings
*timings
)
642 struct cobalt_stream
*s
= video_drvdata(file
);
646 *timings
= cea1080p60
;
650 if (v4l2_match_dv_timings(timings
, &s
->timings
, 0, true))
653 if (vb2_is_busy(&s
->q
))
656 err
= v4l2_subdev_call(s
->sd
,
657 video
, s_dv_timings
, timings
);
659 s
->timings
= *timings
;
660 s
->width
= timings
->bt
.width
;
661 s
->height
= timings
->bt
.height
;
662 s
->stride
= timings
->bt
.width
* s
->bpp
;
667 static int cobalt_g_dv_timings(struct file
*file
, void *priv_fh
,
668 struct v4l2_dv_timings
*timings
)
670 struct cobalt_stream
*s
= video_drvdata(file
);
673 *timings
= cea1080p60
;
676 return v4l2_subdev_call(s
->sd
,
677 video
, g_dv_timings
, timings
);
680 static int cobalt_query_dv_timings(struct file
*file
, void *priv_fh
,
681 struct v4l2_dv_timings
*timings
)
683 struct cobalt_stream
*s
= video_drvdata(file
);
686 *timings
= cea1080p60
;
689 return v4l2_subdev_call(s
->sd
,
690 video
, query_dv_timings
, timings
);
693 static int cobalt_dv_timings_cap(struct file
*file
, void *priv_fh
,
694 struct v4l2_dv_timings_cap
*cap
)
696 struct cobalt_stream
*s
= video_drvdata(file
);
699 return v4l2_subdev_call(s
->sd
,
700 pad
, dv_timings_cap
, cap
);
703 static int cobalt_enum_fmt_vid_cap(struct file
*file
, void *priv_fh
,
704 struct v4l2_fmtdesc
*f
)
708 strlcpy(f
->description
, "YUV 4:2:2", sizeof(f
->description
));
709 f
->pixelformat
= V4L2_PIX_FMT_YUYV
;
712 strlcpy(f
->description
, "RGB24", sizeof(f
->description
));
713 f
->pixelformat
= V4L2_PIX_FMT_RGB24
;
716 strlcpy(f
->description
, "RGB32", sizeof(f
->description
));
717 f
->pixelformat
= V4L2_PIX_FMT_BGR32
;
726 static int cobalt_g_fmt_vid_cap(struct file
*file
, void *priv_fh
,
727 struct v4l2_format
*f
)
729 struct cobalt_stream
*s
= video_drvdata(file
);
730 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
731 struct v4l2_subdev_format sd_fmt
;
733 pix
->width
= s
->width
;
734 pix
->height
= s
->height
;
735 pix
->bytesperline
= s
->stride
;
736 pix
->field
= V4L2_FIELD_NONE
;
739 pix
->colorspace
= V4L2_COLORSPACE_SRGB
;
741 sd_fmt
.pad
= s
->pad_source
;
742 sd_fmt
.which
= V4L2_SUBDEV_FORMAT_ACTIVE
;
743 v4l2_subdev_call(s
->sd
, pad
, get_fmt
, NULL
, &sd_fmt
);
744 v4l2_fill_pix_format(pix
, &sd_fmt
.format
);
747 pix
->pixelformat
= s
->pixfmt
;
748 pix
->sizeimage
= pix
->bytesperline
* pix
->height
;
753 static int cobalt_try_fmt_vid_cap(struct file
*file
, void *priv_fh
,
754 struct v4l2_format
*f
)
756 struct cobalt_stream
*s
= video_drvdata(file
);
757 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
758 struct v4l2_subdev_format sd_fmt
;
760 /* Check for min (QCIF) and max (Full HD) size */
761 if ((pix
->width
< 176) || (pix
->height
< 144)) {
766 if ((pix
->width
> 1920) || (pix
->height
> 1080)) {
771 /* Make width multiple of 4 */
774 /* Make height multiple of 2 */
778 /* Generator => fixed format only */
781 pix
->colorspace
= V4L2_COLORSPACE_SRGB
;
783 sd_fmt
.pad
= s
->pad_source
;
784 sd_fmt
.which
= V4L2_SUBDEV_FORMAT_ACTIVE
;
785 v4l2_subdev_call(s
->sd
, pad
, get_fmt
, NULL
, &sd_fmt
);
786 v4l2_fill_pix_format(pix
, &sd_fmt
.format
);
789 switch (pix
->pixelformat
) {
790 case V4L2_PIX_FMT_YUYV
:
792 pix
->bytesperline
= max(pix
->bytesperline
& ~0x3,
793 pix
->width
* COBALT_BYTES_PER_PIXEL_YUYV
);
794 pix
->pixelformat
= V4L2_PIX_FMT_YUYV
;
796 case V4L2_PIX_FMT_RGB24
:
797 pix
->bytesperline
= max(pix
->bytesperline
& ~0x3,
798 pix
->width
* COBALT_BYTES_PER_PIXEL_RGB24
);
800 case V4L2_PIX_FMT_BGR32
:
801 pix
->bytesperline
= max(pix
->bytesperline
& ~0x3,
802 pix
->width
* COBALT_BYTES_PER_PIXEL_RGB32
);
806 pix
->sizeimage
= pix
->bytesperline
* pix
->height
;
807 pix
->field
= V4L2_FIELD_NONE
;
813 static int cobalt_s_fmt_vid_cap(struct file
*file
, void *priv_fh
,
814 struct v4l2_format
*f
)
816 struct cobalt_stream
*s
= video_drvdata(file
);
817 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
819 if (vb2_is_busy(&s
->q
))
822 if (cobalt_try_fmt_vid_cap(file
, priv_fh
, f
))
825 s
->width
= pix
->width
;
826 s
->height
= pix
->height
;
827 s
->stride
= pix
->bytesperline
;
828 switch (pix
->pixelformat
) {
829 case V4L2_PIX_FMT_YUYV
:
830 s
->bpp
= COBALT_BYTES_PER_PIXEL_YUYV
;
832 case V4L2_PIX_FMT_RGB24
:
833 s
->bpp
= COBALT_BYTES_PER_PIXEL_RGB24
;
835 case V4L2_PIX_FMT_BGR32
:
836 s
->bpp
= COBALT_BYTES_PER_PIXEL_RGB32
;
841 s
->pixfmt
= pix
->pixelformat
;
842 cobalt_enable_input(s
);
847 static int cobalt_try_fmt_vid_out(struct file
*file
, void *priv_fh
,
848 struct v4l2_format
*f
)
850 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
852 /* Check for min (QCIF) and max (Full HD) size */
853 if ((pix
->width
< 176) || (pix
->height
< 144)) {
858 if ((pix
->width
> 1920) || (pix
->height
> 1080)) {
863 /* Make width multiple of 4 */
866 /* Make height multiple of 2 */
869 switch (pix
->pixelformat
) {
870 case V4L2_PIX_FMT_YUYV
:
872 pix
->bytesperline
= max(pix
->bytesperline
& ~0x3,
873 pix
->width
* COBALT_BYTES_PER_PIXEL_YUYV
);
874 pix
->pixelformat
= V4L2_PIX_FMT_YUYV
;
876 case V4L2_PIX_FMT_BGR32
:
877 pix
->bytesperline
= max(pix
->bytesperline
& ~0x3,
878 pix
->width
* COBALT_BYTES_PER_PIXEL_RGB32
);
882 pix
->sizeimage
= pix
->bytesperline
* pix
->height
;
883 pix
->field
= V4L2_FIELD_NONE
;
888 static int cobalt_g_fmt_vid_out(struct file
*file
, void *priv_fh
,
889 struct v4l2_format
*f
)
891 struct cobalt_stream
*s
= video_drvdata(file
);
892 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
894 pix
->width
= s
->width
;
895 pix
->height
= s
->height
;
896 pix
->bytesperline
= s
->stride
;
897 pix
->field
= V4L2_FIELD_NONE
;
898 pix
->pixelformat
= s
->pixfmt
;
899 pix
->colorspace
= s
->colorspace
;
900 pix
->xfer_func
= s
->xfer_func
;
901 pix
->ycbcr_enc
= s
->ycbcr_enc
;
902 pix
->quantization
= s
->quantization
;
903 pix
->sizeimage
= pix
->bytesperline
* pix
->height
;
908 static int cobalt_enum_fmt_vid_out(struct file
*file
, void *priv_fh
,
909 struct v4l2_fmtdesc
*f
)
913 strlcpy(f
->description
, "YUV 4:2:2", sizeof(f
->description
));
914 f
->pixelformat
= V4L2_PIX_FMT_YUYV
;
917 strlcpy(f
->description
, "RGB32", sizeof(f
->description
));
918 f
->pixelformat
= V4L2_PIX_FMT_BGR32
;
927 static int cobalt_s_fmt_vid_out(struct file
*file
, void *priv_fh
,
928 struct v4l2_format
*f
)
930 struct cobalt_stream
*s
= video_drvdata(file
);
931 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
932 struct v4l2_subdev_format sd_fmt
= { 0 };
935 if (cobalt_try_fmt_vid_out(file
, priv_fh
, f
))
938 if (vb2_is_busy(&s
->q
) && (pix
->pixelformat
!= s
->pixfmt
||
939 pix
->width
!= s
->width
|| pix
->height
!= s
->height
||
940 pix
->bytesperline
!= s
->stride
))
943 switch (pix
->pixelformat
) {
944 case V4L2_PIX_FMT_YUYV
:
945 s
->bpp
= COBALT_BYTES_PER_PIXEL_YUYV
;
946 code
= MEDIA_BUS_FMT_UYVY8_1X16
;
948 case V4L2_PIX_FMT_BGR32
:
949 s
->bpp
= COBALT_BYTES_PER_PIXEL_RGB32
;
950 code
= MEDIA_BUS_FMT_RGB888_1X24
;
955 s
->width
= pix
->width
;
956 s
->height
= pix
->height
;
957 s
->stride
= pix
->bytesperline
;
958 s
->pixfmt
= pix
->pixelformat
;
959 s
->colorspace
= pix
->colorspace
;
960 s
->xfer_func
= pix
->xfer_func
;
961 s
->ycbcr_enc
= pix
->ycbcr_enc
;
962 s
->quantization
= pix
->quantization
;
963 sd_fmt
.which
= V4L2_SUBDEV_FORMAT_ACTIVE
;
964 v4l2_fill_mbus_format(&sd_fmt
.format
, pix
, code
);
965 v4l2_subdev_call(s
->sd
, pad
, set_fmt
, NULL
, &sd_fmt
);
969 static int cobalt_enum_input(struct file
*file
, void *priv_fh
,
970 struct v4l2_input
*inp
)
972 struct cobalt_stream
*s
= video_drvdata(file
);
977 snprintf(inp
->name
, sizeof(inp
->name
),
978 "HDMI-%d", s
->video_channel
);
980 snprintf(inp
->name
, sizeof(inp
->name
),
981 "Generator-%d", s
->video_channel
);
982 inp
->type
= V4L2_INPUT_TYPE_CAMERA
;
983 inp
->capabilities
= V4L2_IN_CAP_DV_TIMINGS
;
986 return v4l2_subdev_call(s
->sd
,
987 video
, g_input_status
, &inp
->status
);
990 static int cobalt_g_input(struct file
*file
, void *priv_fh
, unsigned int *i
)
992 struct cobalt_stream
*s
= video_drvdata(file
);
998 static int cobalt_s_input(struct file
*file
, void *priv_fh
, unsigned int i
)
1000 struct cobalt_stream
*s
= video_drvdata(file
);
1004 if (vb2_is_busy(&s
->q
))
1008 cobalt_enable_input(s
);
1010 if (s
->input
== 1) /* Test Pattern Generator */
1013 return v4l2_subdev_call(s
->sd
, video
, s_routing
,
1014 ADV76XX_PAD_HDMI_PORT_A
, 0, 0);
1017 static int cobalt_enum_output(struct file
*file
, void *priv_fh
,
1018 struct v4l2_output
*out
)
1022 snprintf(out
->name
, sizeof(out
->name
), "HDMI-%d", out
->index
);
1023 out
->type
= V4L2_OUTPUT_TYPE_ANALOG
;
1024 out
->capabilities
= V4L2_OUT_CAP_DV_TIMINGS
;
1028 static int cobalt_g_output(struct file
*file
, void *priv_fh
, unsigned int *i
)
1034 static int cobalt_s_output(struct file
*file
, void *priv_fh
, unsigned int i
)
1036 return i
? -EINVAL
: 0;
1039 static int cobalt_g_edid(struct file
*file
, void *fh
, struct v4l2_edid
*edid
)
1041 struct cobalt_stream
*s
= video_drvdata(file
);
1042 u32 pad
= edid
->pad
;
1045 if (edid
->pad
>= (s
->is_output
? 1 : 2))
1048 ret
= v4l2_subdev_call(s
->sd
, pad
, get_edid
, edid
);
1053 static int cobalt_s_edid(struct file
*file
, void *fh
, struct v4l2_edid
*edid
)
1055 struct cobalt_stream
*s
= video_drvdata(file
);
1056 u32 pad
= edid
->pad
;
1062 ret
= v4l2_subdev_call(s
->sd
, pad
, set_edid
, edid
);
1067 static int cobalt_subscribe_event(struct v4l2_fh
*fh
,
1068 const struct v4l2_event_subscription
*sub
)
1070 switch (sub
->type
) {
1071 case V4L2_EVENT_SOURCE_CHANGE
:
1072 return v4l2_event_subscribe(fh
, sub
, 4, NULL
);
1074 return v4l2_ctrl_subscribe_event(fh
, sub
);
1077 static int cobalt_g_parm(struct file
*file
, void *fh
, struct v4l2_streamparm
*a
)
1079 if (a
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1081 a
->parm
.capture
.timeperframe
.numerator
= 1;
1082 a
->parm
.capture
.timeperframe
.denominator
= 60;
1083 a
->parm
.capture
.readbuffers
= 3;
1087 static int cobalt_cropcap(struct file
*file
, void *fh
, struct v4l2_cropcap
*cc
)
1089 struct cobalt_stream
*s
= video_drvdata(file
);
1090 struct v4l2_dv_timings timings
;
1093 if (cc
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1096 timings
= cea1080p60
;
1098 err
= v4l2_subdev_call(s
->sd
, video
, g_dv_timings
, &timings
);
1100 cc
->bounds
.width
= cc
->defrect
.width
= timings
.bt
.width
;
1101 cc
->bounds
.height
= cc
->defrect
.height
= timings
.bt
.height
;
1102 cc
->pixelaspect
= v4l2_dv_timings_aspect_ratio(&timings
);
1107 static const struct v4l2_ioctl_ops cobalt_ioctl_ops
= {
1108 .vidioc_querycap
= cobalt_querycap
,
1109 .vidioc_g_parm
= cobalt_g_parm
,
1110 .vidioc_log_status
= cobalt_log_status
,
1111 .vidioc_streamon
= vb2_ioctl_streamon
,
1112 .vidioc_streamoff
= vb2_ioctl_streamoff
,
1113 .vidioc_cropcap
= cobalt_cropcap
,
1114 .vidioc_enum_input
= cobalt_enum_input
,
1115 .vidioc_g_input
= cobalt_g_input
,
1116 .vidioc_s_input
= cobalt_s_input
,
1117 .vidioc_enum_fmt_vid_cap
= cobalt_enum_fmt_vid_cap
,
1118 .vidioc_g_fmt_vid_cap
= cobalt_g_fmt_vid_cap
,
1119 .vidioc_s_fmt_vid_cap
= cobalt_s_fmt_vid_cap
,
1120 .vidioc_try_fmt_vid_cap
= cobalt_try_fmt_vid_cap
,
1121 .vidioc_enum_output
= cobalt_enum_output
,
1122 .vidioc_g_output
= cobalt_g_output
,
1123 .vidioc_s_output
= cobalt_s_output
,
1124 .vidioc_enum_fmt_vid_out
= cobalt_enum_fmt_vid_out
,
1125 .vidioc_g_fmt_vid_out
= cobalt_g_fmt_vid_out
,
1126 .vidioc_s_fmt_vid_out
= cobalt_s_fmt_vid_out
,
1127 .vidioc_try_fmt_vid_out
= cobalt_try_fmt_vid_out
,
1128 .vidioc_s_dv_timings
= cobalt_s_dv_timings
,
1129 .vidioc_g_dv_timings
= cobalt_g_dv_timings
,
1130 .vidioc_query_dv_timings
= cobalt_query_dv_timings
,
1131 .vidioc_enum_dv_timings
= cobalt_enum_dv_timings
,
1132 .vidioc_dv_timings_cap
= cobalt_dv_timings_cap
,
1133 .vidioc_g_edid
= cobalt_g_edid
,
1134 .vidioc_s_edid
= cobalt_s_edid
,
1135 .vidioc_subscribe_event
= cobalt_subscribe_event
,
1136 .vidioc_unsubscribe_event
= v4l2_event_unsubscribe
,
1137 .vidioc_reqbufs
= vb2_ioctl_reqbufs
,
1138 .vidioc_create_bufs
= vb2_ioctl_create_bufs
,
1139 .vidioc_querybuf
= vb2_ioctl_querybuf
,
1140 .vidioc_qbuf
= vb2_ioctl_qbuf
,
1141 .vidioc_dqbuf
= vb2_ioctl_dqbuf
,
1142 .vidioc_expbuf
= vb2_ioctl_expbuf
,
1143 #ifdef CONFIG_VIDEO_ADV_DEBUG
1144 .vidioc_g_register
= cobalt_g_register
,
1145 .vidioc_s_register
= cobalt_s_register
,
1149 static const struct v4l2_ioctl_ops cobalt_ioctl_empty_ops
= {
1150 #ifdef CONFIG_VIDEO_ADV_DEBUG
1151 .vidioc_g_register
= cobalt_g_register
,
1152 .vidioc_s_register
= cobalt_s_register
,
1156 /* Register device nodes */
1158 static const struct v4l2_file_operations cobalt_fops
= {
1159 .owner
= THIS_MODULE
,
1160 .open
= v4l2_fh_open
,
1161 .unlocked_ioctl
= video_ioctl2
,
1162 .release
= vb2_fop_release
,
1163 .poll
= vb2_fop_poll
,
1164 .mmap
= vb2_fop_mmap
,
1165 .read
= vb2_fop_read
,
1168 static const struct v4l2_file_operations cobalt_out_fops
= {
1169 .owner
= THIS_MODULE
,
1170 .open
= v4l2_fh_open
,
1171 .unlocked_ioctl
= video_ioctl2
,
1172 .release
= vb2_fop_release
,
1173 .poll
= vb2_fop_poll
,
1174 .mmap
= vb2_fop_mmap
,
1175 .write
= vb2_fop_write
,
1178 static const struct v4l2_file_operations cobalt_empty_fops
= {
1179 .owner
= THIS_MODULE
,
1180 .open
= v4l2_fh_open
,
1181 .unlocked_ioctl
= video_ioctl2
,
1182 .release
= v4l2_fh_release
,
1185 static int cobalt_node_register(struct cobalt
*cobalt
, int node
)
1187 static const struct v4l2_dv_timings dv1080p60
=
1188 V4L2_DV_BT_CEA_1920X1080P60
;
1189 struct cobalt_stream
*s
= cobalt
->streams
+ node
;
1190 struct video_device
*vdev
= &s
->vdev
;
1191 struct vb2_queue
*q
= &s
->q
;
1194 mutex_init(&s
->lock
);
1195 spin_lock_init(&s
->irqlock
);
1197 snprintf(vdev
->name
, sizeof(vdev
->name
),
1198 "%s-%d", cobalt
->v4l2_dev
.name
, node
);
1200 /* Audio frames are just 4 lines of 1920 bytes */
1201 s
->height
= s
->is_audio
? 4 : 1080;
1205 s
->pixfmt
= V4L2_PIX_FMT_GREY
;
1206 } else if (s
->is_output
) {
1207 s
->bpp
= COBALT_BYTES_PER_PIXEL_RGB32
;
1208 s
->pixfmt
= V4L2_PIX_FMT_BGR32
;
1210 s
->bpp
= COBALT_BYTES_PER_PIXEL_YUYV
;
1211 s
->pixfmt
= V4L2_PIX_FMT_YUYV
;
1213 s
->colorspace
= V4L2_COLORSPACE_SRGB
;
1214 s
->stride
= s
->width
* s
->bpp
;
1218 cobalt_warn("Setting up dummy video node %d\n", node
);
1219 vdev
->v4l2_dev
= &cobalt
->v4l2_dev
;
1221 vdev
->fops
= &cobalt_empty_fops
;
1223 vdev
->fops
= s
->is_output
? &cobalt_out_fops
:
1225 vdev
->release
= video_device_release_empty
;
1226 vdev
->vfl_dir
= s
->is_output
? VFL_DIR_TX
: VFL_DIR_RX
;
1227 vdev
->lock
= &s
->lock
;
1229 vdev
->ctrl_handler
= s
->sd
->ctrl_handler
;
1230 s
->timings
= dv1080p60
;
1231 v4l2_subdev_call(s
->sd
, video
, s_dv_timings
, &s
->timings
);
1232 if (!s
->is_output
&& s
->sd
)
1233 cobalt_enable_input(s
);
1234 vdev
->ioctl_ops
= s
->is_dummy
? &cobalt_ioctl_empty_ops
:
1238 INIT_LIST_HEAD(&s
->bufs
);
1239 q
->type
= s
->is_output
? V4L2_BUF_TYPE_VIDEO_OUTPUT
:
1240 V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1241 q
->io_modes
= VB2_MMAP
| VB2_USERPTR
| VB2_DMABUF
;
1242 q
->io_modes
|= s
->is_output
? VB2_WRITE
: VB2_READ
;
1244 q
->buf_struct_size
= sizeof(struct cobalt_buffer
);
1245 q
->ops
= &cobalt_qops
;
1246 q
->mem_ops
= &vb2_dma_sg_memops
;
1247 q
->timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
;
1248 q
->min_buffers_needed
= 2;
1250 q
->dev
= &cobalt
->pci_dev
->dev
;
1253 video_set_drvdata(vdev
, s
);
1254 ret
= vb2_queue_init(q
);
1255 if (!s
->is_audio
&& ret
== 0)
1256 ret
= video_register_device(vdev
, VFL_TYPE_GRABBER
, -1);
1257 else if (!s
->is_dummy
)
1258 ret
= cobalt_alsa_init(s
);
1262 cobalt_err("couldn't register v4l2 device node %d\n",
1266 cobalt_info("registered node %d\n", node
);
1270 /* Initialize v4l2 variables and register v4l2 devices */
1271 int cobalt_nodes_register(struct cobalt
*cobalt
)
1275 /* Setup V4L2 Devices */
1276 for (node
= 0; node
< COBALT_NUM_STREAMS
; node
++) {
1277 ret
= cobalt_node_register(cobalt
, node
);
1284 /* Unregister v4l2 devices */
1285 void cobalt_nodes_unregister(struct cobalt
*cobalt
)
1289 /* Teardown all streams */
1290 for (node
= 0; node
< COBALT_NUM_STREAMS
; node
++) {
1291 struct cobalt_stream
*s
= cobalt
->streams
+ node
;
1292 struct video_device
*vdev
= &s
->vdev
;
1295 video_unregister_device(vdev
);
1296 else if (!s
->is_dummy
)
1297 cobalt_alsa_exit(s
);