2 * Copyright (C) 2010-2013 Bluecherry, LLC <http://www.bluecherrydvr.com>
5 * Ben Collins <bcollins@ubuntu.com>
8 * John Brooks <john.brooks@bluecherry.net>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/kthread.h>
24 #include <linux/freezer.h>
26 #include <media/v4l2-ioctl.h>
27 #include <media/v4l2-common.h>
28 #include <media/v4l2-event.h>
29 #include <media/videobuf2-v4l2.h>
30 #include <media/videobuf2-dma-contig.h>
33 #include "solo6x10-tw28.h"
35 /* Image size is two fields, SOLO_HW_BPL is one horizontal line in hardware */
36 #define SOLO_HW_BPL 2048
37 #define solo_vlines(__solo) (__solo->video_vsize * 2)
38 #define solo_image_size(__solo) (solo_bytesperline(__solo) * \
40 #define solo_bytesperline(__solo) (__solo->video_hsize * 2)
42 #define MIN_VID_BUFFERS 2
44 static inline void erase_on(struct solo_dev
*solo_dev
)
46 solo_reg_write(solo_dev
, SOLO_VO_DISP_ERASE
, SOLO_VO_DISP_ERASE_ON
);
47 solo_dev
->erasing
= 1;
48 solo_dev
->frame_blank
= 0;
51 static inline int erase_off(struct solo_dev
*solo_dev
)
53 if (!solo_dev
->erasing
)
56 /* First time around, assert erase off */
57 if (!solo_dev
->frame_blank
)
58 solo_reg_write(solo_dev
, SOLO_VO_DISP_ERASE
, 0);
59 /* Keep the erasing flag on for 8 frames minimum */
60 if (solo_dev
->frame_blank
++ >= 8)
61 solo_dev
->erasing
= 0;
66 void solo_video_in_isr(struct solo_dev
*solo_dev
)
68 wake_up_interruptible_all(&solo_dev
->disp_thread_wait
);
71 static void solo_win_setup(struct solo_dev
*solo_dev
, u8 ch
,
72 int sx
, int sy
, int ex
, int ey
, int scale
)
74 if (ch
>= solo_dev
->nr_chans
)
77 /* Here, we just keep window/channel the same */
78 solo_reg_write(solo_dev
, SOLO_VI_WIN_CTRL0(ch
),
79 SOLO_VI_WIN_CHANNEL(ch
) |
82 SOLO_VI_WIN_SCALE(scale
));
84 solo_reg_write(solo_dev
, SOLO_VI_WIN_CTRL1(ch
),
89 static int solo_v4l2_ch_ext_4up(struct solo_dev
*solo_dev
, u8 idx
, int on
)
93 if (ch
>= solo_dev
->nr_chans
)
99 for (i
= ch
; i
< ch
+ 4; i
++)
100 solo_win_setup(solo_dev
, i
, solo_dev
->video_hsize
,
101 solo_vlines(solo_dev
),
102 solo_dev
->video_hsize
,
103 solo_vlines(solo_dev
), 0);
108 solo_win_setup(solo_dev
, ch
, 0, 0, solo_dev
->video_hsize
/ 2,
109 solo_vlines(solo_dev
) / 2, 3);
110 solo_win_setup(solo_dev
, ch
+ 1, solo_dev
->video_hsize
/ 2, 0,
111 solo_dev
->video_hsize
, solo_vlines(solo_dev
) / 2, 3);
113 solo_win_setup(solo_dev
, ch
+ 2, 0, solo_vlines(solo_dev
) / 2,
114 solo_dev
->video_hsize
/ 2, solo_vlines(solo_dev
), 3);
115 solo_win_setup(solo_dev
, ch
+ 3, solo_dev
->video_hsize
/ 2,
116 solo_vlines(solo_dev
) / 2, solo_dev
->video_hsize
,
117 solo_vlines(solo_dev
), 3);
122 static int solo_v4l2_ch_ext_16up(struct solo_dev
*solo_dev
, int on
)
124 int sy
, ysize
, hsize
, i
;
127 for (i
= 0; i
< 16; i
++)
128 solo_win_setup(solo_dev
, i
, solo_dev
->video_hsize
,
129 solo_vlines(solo_dev
),
130 solo_dev
->video_hsize
,
131 solo_vlines(solo_dev
), 0);
135 ysize
= solo_vlines(solo_dev
) / 4;
136 hsize
= solo_dev
->video_hsize
/ 4;
138 for (sy
= 0, i
= 0; i
< 4; i
++, sy
+= ysize
) {
139 solo_win_setup(solo_dev
, i
* 4, 0, sy
, hsize
,
141 solo_win_setup(solo_dev
, (i
* 4) + 1, hsize
, sy
,
142 hsize
* 2, sy
+ ysize
, 5);
143 solo_win_setup(solo_dev
, (i
* 4) + 2, hsize
* 2, sy
,
144 hsize
* 3, sy
+ ysize
, 5);
145 solo_win_setup(solo_dev
, (i
* 4) + 3, hsize
* 3, sy
,
146 solo_dev
->video_hsize
, sy
+ ysize
, 5);
152 static int solo_v4l2_ch(struct solo_dev
*solo_dev
, u8 ch
, int on
)
156 if (ch
< solo_dev
->nr_chans
) {
157 solo_win_setup(solo_dev
, ch
, on
? 0 : solo_dev
->video_hsize
,
158 on
? 0 : solo_vlines(solo_dev
),
159 solo_dev
->video_hsize
, solo_vlines(solo_dev
),
164 if (ch
>= solo_dev
->nr_chans
+ solo_dev
->nr_ext
)
167 ext_ch
= ch
- solo_dev
->nr_chans
;
171 return solo_v4l2_ch_ext_4up(solo_dev
, ext_ch
, on
);
173 /* Remaining case is 16up for 16-port */
174 return solo_v4l2_ch_ext_16up(solo_dev
, on
);
177 static int solo_v4l2_set_ch(struct solo_dev
*solo_dev
, u8 ch
)
179 if (ch
>= solo_dev
->nr_chans
+ solo_dev
->nr_ext
)
184 solo_v4l2_ch(solo_dev
, solo_dev
->cur_disp_ch
, 0);
185 solo_v4l2_ch(solo_dev
, ch
, 1);
187 solo_dev
->cur_disp_ch
= ch
;
192 static void solo_fillbuf(struct solo_dev
*solo_dev
,
193 struct vb2_buffer
*vb
)
195 struct vb2_v4l2_buffer
*vbuf
= to_vb2_v4l2_buffer(vb
);
197 unsigned int fdma_addr
;
201 addr
= vb2_dma_contig_plane_dma_addr(vb
, 0);
205 if (erase_off(solo_dev
)) {
206 void *p
= vb2_plane_vaddr(vb
, 0);
207 int image_size
= solo_image_size(solo_dev
);
209 for (i
= 0; i
< image_size
; i
+= 2) {
211 ((u8
*)p
)[i
+ 1] = 0x00;
215 fdma_addr
= SOLO_DISP_EXT_ADDR
+ (solo_dev
->old_write
*
216 (SOLO_HW_BPL
* solo_vlines(solo_dev
)));
218 error
= solo_p2m_dma_t(solo_dev
, 0, addr
, fdma_addr
,
219 solo_bytesperline(solo_dev
),
220 solo_vlines(solo_dev
), SOLO_HW_BPL
);
225 vb2_set_plane_payload(vb
, 0,
226 solo_vlines(solo_dev
) * solo_bytesperline(solo_dev
));
227 vbuf
->sequence
= solo_dev
->sequence
++;
228 v4l2_get_timestamp(&vbuf
->timestamp
);
231 vb2_buffer_done(vb
, error
? VB2_BUF_STATE_ERROR
: VB2_BUF_STATE_DONE
);
234 static void solo_thread_try(struct solo_dev
*solo_dev
)
236 struct solo_vb2_buf
*vb
;
238 /* Only "break" from this loop if slock is held, otherwise
241 unsigned int cur_write
;
243 cur_write
= SOLO_VI_STATUS0_PAGE(
244 solo_reg_read(solo_dev
, SOLO_VI_STATUS0
));
245 if (cur_write
== solo_dev
->old_write
)
248 spin_lock(&solo_dev
->slock
);
250 if (list_empty(&solo_dev
->vidq_active
))
253 vb
= list_first_entry(&solo_dev
->vidq_active
, struct solo_vb2_buf
,
256 solo_dev
->old_write
= cur_write
;
259 spin_unlock(&solo_dev
->slock
);
261 solo_fillbuf(solo_dev
, &vb
->vb
.vb2_buf
);
264 assert_spin_locked(&solo_dev
->slock
);
265 spin_unlock(&solo_dev
->slock
);
268 static int solo_thread(void *data
)
270 struct solo_dev
*solo_dev
= data
;
271 DECLARE_WAITQUEUE(wait
, current
);
274 add_wait_queue(&solo_dev
->disp_thread_wait
, &wait
);
277 long timeout
= schedule_timeout_interruptible(HZ
);
279 if (timeout
== -ERESTARTSYS
|| kthread_should_stop())
281 solo_thread_try(solo_dev
);
285 remove_wait_queue(&solo_dev
->disp_thread_wait
, &wait
);
290 static int solo_start_thread(struct solo_dev
*solo_dev
)
294 solo_dev
->kthread
= kthread_run(solo_thread
, solo_dev
, SOLO6X10_NAME
"_disp");
296 if (IS_ERR(solo_dev
->kthread
)) {
297 ret
= PTR_ERR(solo_dev
->kthread
);
298 solo_dev
->kthread
= NULL
;
301 solo_irq_on(solo_dev
, SOLO_IRQ_VIDEO_IN
);
306 static void solo_stop_thread(struct solo_dev
*solo_dev
)
308 if (!solo_dev
->kthread
)
311 solo_irq_off(solo_dev
, SOLO_IRQ_VIDEO_IN
);
312 kthread_stop(solo_dev
->kthread
);
313 solo_dev
->kthread
= NULL
;
316 static int solo_queue_setup(struct vb2_queue
*q
, const void *parg
,
317 unsigned int *num_buffers
, unsigned int *num_planes
,
318 unsigned int sizes
[], void *alloc_ctxs
[])
320 struct solo_dev
*solo_dev
= vb2_get_drv_priv(q
);
322 sizes
[0] = solo_image_size(solo_dev
);
323 alloc_ctxs
[0] = solo_dev
->alloc_ctx
;
326 if (*num_buffers
< MIN_VID_BUFFERS
)
327 *num_buffers
= MIN_VID_BUFFERS
;
332 static int solo_start_streaming(struct vb2_queue
*q
, unsigned int count
)
334 struct solo_dev
*solo_dev
= vb2_get_drv_priv(q
);
336 solo_dev
->sequence
= 0;
337 return solo_start_thread(solo_dev
);
340 static void solo_stop_streaming(struct vb2_queue
*q
)
342 struct solo_dev
*solo_dev
= vb2_get_drv_priv(q
);
344 solo_stop_thread(solo_dev
);
345 INIT_LIST_HEAD(&solo_dev
->vidq_active
);
348 static void solo_buf_queue(struct vb2_buffer
*vb
)
350 struct vb2_v4l2_buffer
*vbuf
= to_vb2_v4l2_buffer(vb
);
351 struct vb2_queue
*vq
= vb
->vb2_queue
;
352 struct solo_dev
*solo_dev
= vb2_get_drv_priv(vq
);
353 struct solo_vb2_buf
*solo_vb
=
354 container_of(vbuf
, struct solo_vb2_buf
, vb
);
356 spin_lock(&solo_dev
->slock
);
357 list_add_tail(&solo_vb
->list
, &solo_dev
->vidq_active
);
358 spin_unlock(&solo_dev
->slock
);
359 wake_up_interruptible(&solo_dev
->disp_thread_wait
);
362 static const struct vb2_ops solo_video_qops
= {
363 .queue_setup
= solo_queue_setup
,
364 .buf_queue
= solo_buf_queue
,
365 .start_streaming
= solo_start_streaming
,
366 .stop_streaming
= solo_stop_streaming
,
367 .wait_prepare
= vb2_ops_wait_prepare
,
368 .wait_finish
= vb2_ops_wait_finish
,
371 static int solo_querycap(struct file
*file
, void *priv
,
372 struct v4l2_capability
*cap
)
374 struct solo_dev
*solo_dev
= video_drvdata(file
);
376 strcpy(cap
->driver
, SOLO6X10_NAME
);
377 strcpy(cap
->card
, "Softlogic 6x10");
378 snprintf(cap
->bus_info
, sizeof(cap
->bus_info
), "PCI:%s",
379 pci_name(solo_dev
->pdev
));
380 cap
->device_caps
= V4L2_CAP_VIDEO_CAPTURE
|
381 V4L2_CAP_READWRITE
| V4L2_CAP_STREAMING
;
382 cap
->capabilities
= cap
->device_caps
| V4L2_CAP_DEVICE_CAPS
;
386 static int solo_enum_ext_input(struct solo_dev
*solo_dev
,
387 struct v4l2_input
*input
)
389 static const char * const dispnames_1
[] = { "4UP" };
390 static const char * const dispnames_2
[] = { "4UP-1", "4UP-2" };
391 static const char * const dispnames_5
[] = {
392 "4UP-1", "4UP-2", "4UP-3", "4UP-4", "16UP"
394 const char * const *dispnames
;
396 if (input
->index
>= (solo_dev
->nr_chans
+ solo_dev
->nr_ext
))
399 if (solo_dev
->nr_ext
== 5)
400 dispnames
= dispnames_5
;
401 else if (solo_dev
->nr_ext
== 2)
402 dispnames
= dispnames_2
;
404 dispnames
= dispnames_1
;
406 snprintf(input
->name
, sizeof(input
->name
), "Multi %s",
407 dispnames
[input
->index
- solo_dev
->nr_chans
]);
412 static int solo_enum_input(struct file
*file
, void *priv
,
413 struct v4l2_input
*input
)
415 struct solo_dev
*solo_dev
= video_drvdata(file
);
417 if (input
->index
>= solo_dev
->nr_chans
) {
418 int ret
= solo_enum_ext_input(solo_dev
, input
);
423 snprintf(input
->name
, sizeof(input
->name
), "Camera %d",
426 /* We can only check this for normal inputs */
427 if (!tw28_get_video_status(solo_dev
, input
->index
))
428 input
->status
= V4L2_IN_ST_NO_SIGNAL
;
431 input
->type
= V4L2_INPUT_TYPE_CAMERA
;
432 input
->std
= solo_dev
->vfd
->tvnorms
;
436 static int solo_set_input(struct file
*file
, void *priv
, unsigned int index
)
438 struct solo_dev
*solo_dev
= video_drvdata(file
);
439 int ret
= solo_v4l2_set_ch(solo_dev
, index
);
442 while (erase_off(solo_dev
))
449 static int solo_get_input(struct file
*file
, void *priv
, unsigned int *index
)
451 struct solo_dev
*solo_dev
= video_drvdata(file
);
453 *index
= solo_dev
->cur_disp_ch
;
458 static int solo_enum_fmt_cap(struct file
*file
, void *priv
,
459 struct v4l2_fmtdesc
*f
)
464 f
->pixelformat
= V4L2_PIX_FMT_UYVY
;
465 strlcpy(f
->description
, "UYUV 4:2:2 Packed", sizeof(f
->description
));
470 static int solo_try_fmt_cap(struct file
*file
, void *priv
,
471 struct v4l2_format
*f
)
473 struct solo_dev
*solo_dev
= video_drvdata(file
);
474 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
475 int image_size
= solo_image_size(solo_dev
);
477 if (pix
->pixelformat
!= V4L2_PIX_FMT_UYVY
)
480 pix
->width
= solo_dev
->video_hsize
;
481 pix
->height
= solo_vlines(solo_dev
);
482 pix
->sizeimage
= image_size
;
483 pix
->field
= V4L2_FIELD_INTERLACED
;
484 pix
->pixelformat
= V4L2_PIX_FMT_UYVY
;
485 pix
->colorspace
= V4L2_COLORSPACE_SMPTE170M
;
490 static int solo_set_fmt_cap(struct file
*file
, void *priv
,
491 struct v4l2_format
*f
)
493 struct solo_dev
*solo_dev
= video_drvdata(file
);
495 if (vb2_is_busy(&solo_dev
->vidq
))
498 /* For right now, if it doesn't match our running config,
500 return solo_try_fmt_cap(file
, priv
, f
);
503 static int solo_get_fmt_cap(struct file
*file
, void *priv
,
504 struct v4l2_format
*f
)
506 struct solo_dev
*solo_dev
= video_drvdata(file
);
507 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
509 pix
->width
= solo_dev
->video_hsize
;
510 pix
->height
= solo_vlines(solo_dev
);
511 pix
->pixelformat
= V4L2_PIX_FMT_UYVY
;
512 pix
->field
= V4L2_FIELD_INTERLACED
;
513 pix
->sizeimage
= solo_image_size(solo_dev
);
514 pix
->colorspace
= V4L2_COLORSPACE_SMPTE170M
;
515 pix
->bytesperline
= solo_bytesperline(solo_dev
);
521 static int solo_g_std(struct file
*file
, void *priv
, v4l2_std_id
*i
)
523 struct solo_dev
*solo_dev
= video_drvdata(file
);
525 if (solo_dev
->video_type
== SOLO_VO_FMT_TYPE_NTSC
)
526 *i
= V4L2_STD_NTSC_M
;
532 int solo_set_video_type(struct solo_dev
*solo_dev
, bool is_50hz
)
536 /* Make sure all video nodes are idle */
537 if (vb2_is_busy(&solo_dev
->vidq
))
539 for (i
= 0; i
< solo_dev
->nr_chans
; i
++)
540 if (vb2_is_busy(&solo_dev
->v4l2_enc
[i
]->vidq
))
542 solo_dev
->video_type
= is_50hz
? SOLO_VO_FMT_TYPE_PAL
:
543 SOLO_VO_FMT_TYPE_NTSC
;
544 /* Reconfigure for the new standard */
545 solo_disp_init(solo_dev
);
546 solo_enc_init(solo_dev
);
547 solo_tw28_init(solo_dev
);
548 for (i
= 0; i
< solo_dev
->nr_chans
; i
++)
549 solo_update_mode(solo_dev
->v4l2_enc
[i
]);
550 return solo_v4l2_set_ch(solo_dev
, solo_dev
->cur_disp_ch
);
553 static int solo_s_std(struct file
*file
, void *priv
, v4l2_std_id std
)
555 struct solo_dev
*solo_dev
= video_drvdata(file
);
557 return solo_set_video_type(solo_dev
, std
& V4L2_STD_625_50
);
560 static int solo_s_ctrl(struct v4l2_ctrl
*ctrl
)
562 struct solo_dev
*solo_dev
=
563 container_of(ctrl
->handler
, struct solo_dev
, disp_hdl
);
566 case V4L2_CID_MOTION_TRACE
:
568 solo_reg_write(solo_dev
, SOLO_VI_MOTION_BORDER
,
569 SOLO_VI_MOTION_Y_ADD
|
570 SOLO_VI_MOTION_Y_VALUE(0x20) |
571 SOLO_VI_MOTION_CB_VALUE(0x10) |
572 SOLO_VI_MOTION_CR_VALUE(0x10));
573 solo_reg_write(solo_dev
, SOLO_VI_MOTION_BAR
,
574 SOLO_VI_MOTION_CR_ADD
|
575 SOLO_VI_MOTION_Y_VALUE(0x10) |
576 SOLO_VI_MOTION_CB_VALUE(0x80) |
577 SOLO_VI_MOTION_CR_VALUE(0x10));
579 solo_reg_write(solo_dev
, SOLO_VI_MOTION_BORDER
, 0);
580 solo_reg_write(solo_dev
, SOLO_VI_MOTION_BAR
, 0);
589 static const struct v4l2_file_operations solo_v4l2_fops
= {
590 .owner
= THIS_MODULE
,
591 .open
= v4l2_fh_open
,
592 .release
= vb2_fop_release
,
593 .read
= vb2_fop_read
,
594 .poll
= vb2_fop_poll
,
595 .mmap
= vb2_fop_mmap
,
596 .unlocked_ioctl
= video_ioctl2
,
599 static const struct v4l2_ioctl_ops solo_v4l2_ioctl_ops
= {
600 .vidioc_querycap
= solo_querycap
,
601 .vidioc_s_std
= solo_s_std
,
602 .vidioc_g_std
= solo_g_std
,
603 /* Input callbacks */
604 .vidioc_enum_input
= solo_enum_input
,
605 .vidioc_s_input
= solo_set_input
,
606 .vidioc_g_input
= solo_get_input
,
607 /* Video capture format callbacks */
608 .vidioc_enum_fmt_vid_cap
= solo_enum_fmt_cap
,
609 .vidioc_try_fmt_vid_cap
= solo_try_fmt_cap
,
610 .vidioc_s_fmt_vid_cap
= solo_set_fmt_cap
,
611 .vidioc_g_fmt_vid_cap
= solo_get_fmt_cap
,
613 .vidioc_reqbufs
= vb2_ioctl_reqbufs
,
614 .vidioc_querybuf
= vb2_ioctl_querybuf
,
615 .vidioc_qbuf
= vb2_ioctl_qbuf
,
616 .vidioc_dqbuf
= vb2_ioctl_dqbuf
,
617 .vidioc_streamon
= vb2_ioctl_streamon
,
618 .vidioc_streamoff
= vb2_ioctl_streamoff
,
619 /* Logging and events */
620 .vidioc_log_status
= v4l2_ctrl_log_status
,
621 .vidioc_subscribe_event
= v4l2_ctrl_subscribe_event
,
622 .vidioc_unsubscribe_event
= v4l2_event_unsubscribe
,
625 static struct video_device solo_v4l2_template
= {
626 .name
= SOLO6X10_NAME
,
627 .fops
= &solo_v4l2_fops
,
628 .ioctl_ops
= &solo_v4l2_ioctl_ops
,
630 .release
= video_device_release
,
631 .tvnorms
= V4L2_STD_NTSC_M
| V4L2_STD_PAL
,
634 static const struct v4l2_ctrl_ops solo_ctrl_ops
= {
635 .s_ctrl
= solo_s_ctrl
,
638 static const struct v4l2_ctrl_config solo_motion_trace_ctrl
= {
639 .ops
= &solo_ctrl_ops
,
640 .id
= V4L2_CID_MOTION_TRACE
,
641 .name
= "Motion Detection Trace",
642 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
647 int solo_v4l2_init(struct solo_dev
*solo_dev
, unsigned nr
)
652 init_waitqueue_head(&solo_dev
->disp_thread_wait
);
653 spin_lock_init(&solo_dev
->slock
);
654 mutex_init(&solo_dev
->lock
);
655 INIT_LIST_HEAD(&solo_dev
->vidq_active
);
657 solo_dev
->vfd
= video_device_alloc();
661 *solo_dev
->vfd
= solo_v4l2_template
;
662 solo_dev
->vfd
->v4l2_dev
= &solo_dev
->v4l2_dev
;
663 solo_dev
->vfd
->queue
= &solo_dev
->vidq
;
664 solo_dev
->vfd
->lock
= &solo_dev
->lock
;
665 v4l2_ctrl_handler_init(&solo_dev
->disp_hdl
, 1);
666 v4l2_ctrl_new_custom(&solo_dev
->disp_hdl
, &solo_motion_trace_ctrl
, NULL
);
667 if (solo_dev
->disp_hdl
.error
) {
668 ret
= solo_dev
->disp_hdl
.error
;
671 solo_dev
->vfd
->ctrl_handler
= &solo_dev
->disp_hdl
;
673 video_set_drvdata(solo_dev
->vfd
, solo_dev
);
675 solo_dev
->vidq
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
676 solo_dev
->vidq
.io_modes
= VB2_MMAP
| VB2_USERPTR
| VB2_READ
;
677 solo_dev
->vidq
.ops
= &solo_video_qops
;
678 solo_dev
->vidq
.mem_ops
= &vb2_dma_contig_memops
;
679 solo_dev
->vidq
.drv_priv
= solo_dev
;
680 solo_dev
->vidq
.timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
;
681 solo_dev
->vidq
.gfp_flags
= __GFP_DMA32
| __GFP_KSWAPD_RECLAIM
;
682 solo_dev
->vidq
.buf_struct_size
= sizeof(struct solo_vb2_buf
);
683 solo_dev
->vidq
.lock
= &solo_dev
->lock
;
684 ret
= vb2_queue_init(&solo_dev
->vidq
);
688 solo_dev
->alloc_ctx
= vb2_dma_contig_init_ctx(&solo_dev
->pdev
->dev
);
689 if (IS_ERR(solo_dev
->alloc_ctx
)) {
690 dev_err(&solo_dev
->pdev
->dev
, "Can't allocate buffer context");
691 return PTR_ERR(solo_dev
->alloc_ctx
);
694 /* Cycle all the channels and clear */
695 for (i
= 0; i
< solo_dev
->nr_chans
; i
++) {
696 solo_v4l2_set_ch(solo_dev
, i
);
697 while (erase_off(solo_dev
))
701 /* Set the default display channel */
702 solo_v4l2_set_ch(solo_dev
, 0);
703 while (erase_off(solo_dev
))
706 ret
= video_register_device(solo_dev
->vfd
, VFL_TYPE_GRABBER
, nr
);
710 snprintf(solo_dev
->vfd
->name
, sizeof(solo_dev
->vfd
->name
), "%s (%i)",
711 SOLO6X10_NAME
, solo_dev
->vfd
->num
);
713 dev_info(&solo_dev
->pdev
->dev
, "Display as /dev/video%d with "
714 "%d inputs (%d extended)\n", solo_dev
->vfd
->num
,
715 solo_dev
->nr_chans
, solo_dev
->nr_ext
);
720 video_device_release(solo_dev
->vfd
);
721 vb2_dma_contig_cleanup_ctx(solo_dev
->alloc_ctx
);
722 v4l2_ctrl_handler_free(&solo_dev
->disp_hdl
);
723 solo_dev
->vfd
= NULL
;
727 void solo_v4l2_exit(struct solo_dev
*solo_dev
)
729 if (solo_dev
->vfd
== NULL
)
732 video_unregister_device(solo_dev
->vfd
);
733 vb2_dma_contig_cleanup_ctx(solo_dev
->alloc_ctx
);
734 v4l2_ctrl_handler_free(&solo_dev
->disp_hdl
);
735 solo_dev
->vfd
= NULL
;