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.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/kthread.h>
28 #include <linux/freezer.h>
30 #include <media/v4l2-ioctl.h>
31 #include <media/v4l2-common.h>
32 #include <media/v4l2-event.h>
33 #include <media/videobuf2-dma-sg.h>
36 #include "solo6x10-tw28.h"
37 #include "solo6x10-jpeg.h"
39 #define MIN_VID_BUFFERS 2
40 #define FRAME_BUF_SIZE (196 * 1024)
42 #define DMA_ALIGN 4096
45 static unsigned char vop_6010_ntsc_d1[] = {
46 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20,
47 0x02, 0x48, 0x1d, 0xc0, 0x00, 0x40, 0x00, 0x40,
48 0x00, 0x40, 0x00, 0x80, 0x00, 0x97, 0x53, 0x04,
49 0x1f, 0x4c, 0x58, 0x10, 0xf0, 0x71, 0x18, 0x3f,
52 static unsigned char vop_6010_ntsc_cif[] = {
53 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20,
54 0x02, 0x48, 0x1d, 0xc0, 0x00, 0x40, 0x00, 0x40,
55 0x00, 0x40, 0x00, 0x80, 0x00, 0x97, 0x53, 0x04,
56 0x1f, 0x4c, 0x2c, 0x10, 0x78, 0x51, 0x18, 0x3f,
59 static unsigned char vop_6010_pal_d1[] = {
60 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20,
61 0x02, 0x48, 0x15, 0xc0, 0x00, 0x40, 0x00, 0x40,
62 0x00, 0x40, 0x00, 0x80, 0x00, 0x97, 0x53, 0x04,
63 0x1f, 0x4c, 0x58, 0x11, 0x20, 0x71, 0x18, 0x3f,
66 static unsigned char vop_6010_pal_cif[] = {
67 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20,
68 0x02, 0x48, 0x15, 0xc0, 0x00, 0x40, 0x00, 0x40,
69 0x00, 0x40, 0x00, 0x80, 0x00, 0x97, 0x53, 0x04,
70 0x1f, 0x4c, 0x2c, 0x10, 0x90, 0x51, 0x18, 0x3f,
74 static unsigned char vop_6110_ntsc_d1[] = {
75 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x1e,
76 0x9a, 0x74, 0x05, 0x81, 0xec, 0x80, 0x00, 0x00,
77 0x00, 0x01, 0x68, 0xce, 0x32, 0x28, 0x00, 0x00,
80 static unsigned char vop_6110_ntsc_cif[] = {
81 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x1e,
82 0x9a, 0x74, 0x0b, 0x0f, 0xc8, 0x00, 0x00, 0x00,
83 0x01, 0x68, 0xce, 0x32, 0x28, 0x00, 0x00, 0x00,
86 static unsigned char vop_6110_pal_d1[] = {
87 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x1e,
88 0x9a, 0x74, 0x05, 0x80, 0x93, 0x20, 0x00, 0x00,
89 0x00, 0x01, 0x68, 0xce, 0x32, 0x28, 0x00, 0x00,
92 static unsigned char vop_6110_pal_cif[] = {
93 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x1e,
94 0x9a, 0x74, 0x0b, 0x04, 0xb2, 0x00, 0x00, 0x00,
95 0x01, 0x68, 0xce, 0x32, 0x28, 0x00, 0x00, 0x00,
98 typedef __le32 vop_header[16];
100 struct solo_enc_buf {
101 enum solo_enc_types type;
102 const vop_header *vh;
106 static int solo_is_motion_on(struct solo_enc_dev *solo_enc)
108 struct solo_dev *solo_dev = solo_enc->solo_dev;
110 return (solo_dev->motion_mask >> solo_enc->ch) & 1;
113 static int solo_motion_detected(struct solo_enc_dev *solo_enc)
115 struct solo_dev *solo_dev = solo_enc->solo_dev;
117 u32 ch_mask = 1 << solo_enc->ch;
120 spin_lock_irqsave(&solo_enc->motion_lock, flags);
121 if (solo_reg_read(solo_dev, SOLO_VI_MOT_STATUS) & ch_mask) {
122 solo_reg_write(solo_dev, SOLO_VI_MOT_CLEAR, ch_mask);
125 spin_unlock_irqrestore(&solo_enc->motion_lock, flags);
130 static void solo_motion_toggle(struct solo_enc_dev *solo_enc, int on)
132 struct solo_dev *solo_dev = solo_enc->solo_dev;
133 u32 mask = 1 << solo_enc->ch;
136 spin_lock_irqsave(&solo_enc->motion_lock, flags);
139 solo_dev->motion_mask |= mask;
141 solo_dev->motion_mask &= ~mask;
143 solo_reg_write(solo_dev, SOLO_VI_MOT_CLEAR, mask);
145 solo_reg_write(solo_dev, SOLO_VI_MOT_ADR,
146 SOLO_VI_MOTION_EN(solo_dev->motion_mask) |
147 (SOLO_MOTION_EXT_ADDR(solo_dev) >> 16));
149 spin_unlock_irqrestore(&solo_enc->motion_lock, flags);
152 void solo_update_mode(struct solo_enc_dev *solo_enc)
154 struct solo_dev *solo_dev = solo_enc->solo_dev;
158 solo_enc->interlaced = (solo_enc->mode & 0x08) ? 1 : 0;
159 solo_enc->bw_weight = max(solo_dev->fps / solo_enc->interval, 1);
161 if (solo_enc->mode == SOLO_ENC_MODE_CIF) {
162 solo_enc->width = solo_dev->video_hsize >> 1;
163 solo_enc->height = solo_dev->video_vsize;
164 if (solo_dev->type == SOLO_DEV_6110) {
165 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC) {
166 vop = vop_6110_ntsc_cif;
167 vop_len = sizeof(vop_6110_ntsc_cif);
169 vop = vop_6110_pal_cif;
170 vop_len = sizeof(vop_6110_pal_cif);
173 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC) {
174 vop = vop_6010_ntsc_cif;
175 vop_len = sizeof(vop_6010_ntsc_cif);
177 vop = vop_6010_pal_cif;
178 vop_len = sizeof(vop_6010_pal_cif);
182 solo_enc->width = solo_dev->video_hsize;
183 solo_enc->height = solo_dev->video_vsize << 1;
184 solo_enc->bw_weight <<= 2;
185 if (solo_dev->type == SOLO_DEV_6110) {
186 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC) {
187 vop = vop_6110_ntsc_d1;
188 vop_len = sizeof(vop_6110_ntsc_d1);
190 vop = vop_6110_pal_d1;
191 vop_len = sizeof(vop_6110_pal_d1);
194 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC) {
195 vop = vop_6010_ntsc_d1;
196 vop_len = sizeof(vop_6010_ntsc_d1);
198 vop = vop_6010_pal_d1;
199 vop_len = sizeof(vop_6010_pal_d1);
204 memcpy(solo_enc->vop, vop, vop_len);
206 /* Some fixups for 6010/M4V */
207 if (solo_dev->type == SOLO_DEV_6010) {
208 u16 fps = solo_dev->fps * 1000;
209 u16 interval = solo_enc->interval * 1000;
213 /* Frame rate and interval */
215 vop[23] = ((fps << 4) & 0xf0) | 0x0c
216 | ((interval >> 13) & 0x3);
217 vop[24] = (interval >> 5) & 0xff;
218 vop[25] = ((interval << 3) & 0xf8) | 0x04;
221 solo_enc->vop_len = vop_len;
223 /* Now handle the jpeg header */
224 vop = solo_enc->jpeg_header;
225 vop[SOF0_START + 5] = 0xff & (solo_enc->height >> 8);
226 vop[SOF0_START + 6] = 0xff & solo_enc->height;
227 vop[SOF0_START + 7] = 0xff & (solo_enc->width >> 8);
228 vop[SOF0_START + 8] = 0xff & solo_enc->width;
230 memcpy(vop + DQT_START,
231 jpeg_dqt[solo_g_jpeg_qp(solo_dev, solo_enc->ch)], DQT_LEN);
234 static int solo_enc_on(struct solo_enc_dev *solo_enc)
236 u8 ch = solo_enc->ch;
237 struct solo_dev *solo_dev = solo_enc->solo_dev;
240 solo_update_mode(solo_enc);
242 /* Make sure to do a bandwidth check */
243 if (solo_enc->bw_weight > solo_dev->enc_bw_remain)
245 solo_enc->sequence = 0;
246 solo_dev->enc_bw_remain -= solo_enc->bw_weight;
248 if (solo_enc->type == SOLO_ENC_TYPE_EXT)
249 solo_reg_write(solo_dev, SOLO_CAP_CH_COMP_ENA_E(ch), 1);
251 /* Disable all encoding for this channel */
252 solo_reg_write(solo_dev, SOLO_CAP_CH_SCALE(ch), 0);
254 /* Common for both std and ext encoding */
255 solo_reg_write(solo_dev, SOLO_VE_CH_INTL(ch),
256 solo_enc->interlaced ? 1 : 0);
258 if (solo_enc->interlaced)
259 interval = solo_enc->interval - 1;
261 interval = solo_enc->interval;
263 /* Standard encoding only */
264 solo_reg_write(solo_dev, SOLO_VE_CH_GOP(ch), solo_enc->gop);
265 solo_reg_write(solo_dev, SOLO_VE_CH_QP(ch), solo_enc->qp);
266 solo_reg_write(solo_dev, SOLO_CAP_CH_INTV(ch), interval);
268 /* Extended encoding only */
269 solo_reg_write(solo_dev, SOLO_VE_CH_GOP_E(ch), solo_enc->gop);
270 solo_reg_write(solo_dev, SOLO_VE_CH_QP_E(ch), solo_enc->qp);
271 solo_reg_write(solo_dev, SOLO_CAP_CH_INTV_E(ch), interval);
273 /* Enables the standard encoder */
274 solo_reg_write(solo_dev, SOLO_CAP_CH_SCALE(ch), solo_enc->mode);
279 static void solo_enc_off(struct solo_enc_dev *solo_enc)
281 struct solo_dev *solo_dev = solo_enc->solo_dev;
283 solo_dev->enc_bw_remain += solo_enc->bw_weight;
285 solo_reg_write(solo_dev, SOLO_CAP_CH_SCALE(solo_enc->ch), 0);
286 solo_reg_write(solo_dev, SOLO_CAP_CH_COMP_ENA_E(solo_enc->ch), 0);
289 static int enc_get_mpeg_dma(struct solo_dev *solo_dev, dma_addr_t dma,
290 unsigned int off, unsigned int size)
294 if (off > SOLO_MP4E_EXT_SIZE(solo_dev))
298 if (off + size <= SOLO_MP4E_EXT_SIZE(solo_dev)) {
299 return solo_p2m_dma_t(solo_dev, 0, dma,
300 SOLO_MP4E_EXT_ADDR(solo_dev) + off, size,
305 ret = solo_p2m_dma_t(solo_dev, 0, dma,
306 SOLO_MP4E_EXT_ADDR(solo_dev) + off,
307 SOLO_MP4E_EXT_SIZE(solo_dev) - off, 0, 0);
310 ret = solo_p2m_dma_t(solo_dev, 0,
311 dma + SOLO_MP4E_EXT_SIZE(solo_dev) - off,
312 SOLO_MP4E_EXT_ADDR(solo_dev),
313 size + off - SOLO_MP4E_EXT_SIZE(solo_dev), 0, 0);
319 /* Build a descriptor queue out of an SG list and send it to the P2M for
321 static int solo_send_desc(struct solo_enc_dev *solo_enc, int skip,
322 struct sg_table *vbuf, int off, int size,
323 unsigned int base, unsigned int base_size)
325 struct solo_dev *solo_dev = solo_enc->solo_dev;
326 struct scatterlist *sg;
330 if (WARN_ON_ONCE(size > FRAME_BUF_SIZE))
333 solo_enc->desc_count = 1;
335 for_each_sg(vbuf->sgl, sg, vbuf->nents, i) {
336 struct solo_p2m_desc *desc;
339 int left = base_size - off;
341 desc = &solo_enc->desc_items[solo_enc->desc_count++];
342 dma = sg_dma_address(sg);
343 len = sg_dma_len(sg);
345 /* We assume this is smaller than the scatter size */
354 len = min(len, size);
357 /* Single descriptor */
358 solo_p2m_fill_desc(desc, 0, dma, base + off,
362 /* XXX: Do these as separate DMA requests, to avoid
363 timeout errors triggered by awkwardly sized
365 <https://github.com/bluecherrydvr/solo6x10/issues/8>
367 ret = solo_p2m_dma_t(solo_dev, 0, dma, base + off,
372 ret = solo_p2m_dma_t(solo_dev, 0, dma + left, base,
377 solo_enc->desc_count--;
385 if (off >= base_size)
388 /* Because we may use two descriptors per loop */
389 if (solo_enc->desc_count >= (solo_enc->desc_nelts - 1)) {
390 ret = solo_p2m_dma_desc(solo_dev, solo_enc->desc_items,
392 solo_enc->desc_count - 1);
395 solo_enc->desc_count = 1;
399 if (solo_enc->desc_count <= 1)
402 return solo_p2m_dma_desc(solo_dev, solo_enc->desc_items, solo_enc->desc_dma,
403 solo_enc->desc_count - 1);
406 /* Extract values from VOP header - VE_STATUSxx */
407 static inline int vop_interlaced(const vop_header *vh)
409 return (__le32_to_cpu((*vh)[0]) >> 30) & 1;
412 static inline u8 vop_channel(const vop_header *vh)
414 return (__le32_to_cpu((*vh)[0]) >> 24) & 0x1F;
417 static inline u8 vop_type(const vop_header *vh)
419 return (__le32_to_cpu((*vh)[0]) >> 22) & 3;
422 static inline u32 vop_mpeg_size(const vop_header *vh)
424 return __le32_to_cpu((*vh)[0]) & 0xFFFFF;
427 static inline u8 vop_hsize(const vop_header *vh)
429 return (__le32_to_cpu((*vh)[1]) >> 8) & 0xFF;
432 static inline u8 vop_vsize(const vop_header *vh)
434 return __le32_to_cpu((*vh)[1]) & 0xFF;
437 static inline u32 vop_mpeg_offset(const vop_header *vh)
439 return __le32_to_cpu((*vh)[2]);
442 static inline u32 vop_jpeg_offset(const vop_header *vh)
444 return __le32_to_cpu((*vh)[3]);
447 static inline u32 vop_jpeg_size(const vop_header *vh)
449 return __le32_to_cpu((*vh)[4]) & 0xFFFFF;
452 static inline u32 vop_sec(const vop_header *vh)
454 return __le32_to_cpu((*vh)[5]);
457 static inline u32 vop_usec(const vop_header *vh)
459 return __le32_to_cpu((*vh)[6]);
462 static int solo_fill_jpeg(struct solo_enc_dev *solo_enc,
463 struct vb2_buffer *vb, const vop_header *vh)
465 struct solo_dev *solo_dev = solo_enc->solo_dev;
466 struct sg_table *vbuf = vb2_dma_sg_plane_desc(vb, 0);
470 vb->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME;
472 if (vb2_plane_size(vb, 0) < vop_jpeg_size(vh) + solo_enc->jpeg_len)
475 frame_size = (vop_jpeg_size(vh) + solo_enc->jpeg_len + (DMA_ALIGN - 1))
477 vb2_set_plane_payload(vb, 0, vop_jpeg_size(vh) + solo_enc->jpeg_len);
479 /* may discard all previous data in vbuf->sgl */
480 dma_map_sg(&solo_dev->pdev->dev, vbuf->sgl, vbuf->nents,
482 ret = solo_send_desc(solo_enc, solo_enc->jpeg_len, vbuf,
483 vop_jpeg_offset(vh) - SOLO_JPEG_EXT_ADDR(solo_dev),
484 frame_size, SOLO_JPEG_EXT_ADDR(solo_dev),
485 SOLO_JPEG_EXT_SIZE(solo_dev));
486 dma_unmap_sg(&solo_dev->pdev->dev, vbuf->sgl, vbuf->nents,
489 /* add the header only after dma_unmap_sg() */
490 sg_copy_from_buffer(vbuf->sgl, vbuf->nents,
491 solo_enc->jpeg_header, solo_enc->jpeg_len);
496 static int solo_fill_mpeg(struct solo_enc_dev *solo_enc,
497 struct vb2_buffer *vb, const vop_header *vh)
499 struct solo_dev *solo_dev = solo_enc->solo_dev;
500 struct sg_table *vbuf = vb2_dma_sg_plane_desc(vb, 0);
501 int frame_off, frame_size;
505 if (vb2_plane_size(vb, 0) < vop_mpeg_size(vh))
508 /* If this is a key frame, add extra header */
509 vb->v4l2_buf.flags &= ~(V4L2_BUF_FLAG_KEYFRAME | V4L2_BUF_FLAG_PFRAME | V4L2_BUF_FLAG_BFRAME);
511 skip = solo_enc->vop_len;
512 vb->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME;
513 vb2_set_plane_payload(vb, 0, vop_mpeg_size(vh) + solo_enc->vop_len);
515 vb->v4l2_buf.flags |= V4L2_BUF_FLAG_PFRAME;
516 vb2_set_plane_payload(vb, 0, vop_mpeg_size(vh));
519 /* Now get the actual mpeg payload */
520 frame_off = (vop_mpeg_offset(vh) - SOLO_MP4E_EXT_ADDR(solo_dev) + sizeof(*vh))
521 % SOLO_MP4E_EXT_SIZE(solo_dev);
522 frame_size = (vop_mpeg_size(vh) + skip + (DMA_ALIGN - 1))
525 /* may discard all previous data in vbuf->sgl */
526 dma_map_sg(&solo_dev->pdev->dev, vbuf->sgl, vbuf->nents,
528 ret = solo_send_desc(solo_enc, skip, vbuf, frame_off, frame_size,
529 SOLO_MP4E_EXT_ADDR(solo_dev),
530 SOLO_MP4E_EXT_SIZE(solo_dev));
531 dma_unmap_sg(&solo_dev->pdev->dev, vbuf->sgl, vbuf->nents,
534 /* add the header only after dma_unmap_sg() */
536 sg_copy_from_buffer(vbuf->sgl, vbuf->nents,
537 solo_enc->vop, solo_enc->vop_len);
541 static int solo_enc_fillbuf(struct solo_enc_dev *solo_enc,
542 struct vb2_buffer *vb, struct solo_enc_buf *enc_buf)
544 const vop_header *vh = enc_buf->vh;
547 /* Check for motion flags */
548 vb->v4l2_buf.flags &= ~(V4L2_BUF_FLAG_MOTION_ON |
549 V4L2_BUF_FLAG_MOTION_DETECTED);
550 if (solo_is_motion_on(solo_enc)) {
551 vb->v4l2_buf.flags |= V4L2_BUF_FLAG_MOTION_ON;
553 vb->v4l2_buf.flags |= V4L2_BUF_FLAG_MOTION_DETECTED;
556 switch (solo_enc->fmt) {
557 case V4L2_PIX_FMT_MPEG4:
558 case V4L2_PIX_FMT_H264:
559 ret = solo_fill_mpeg(solo_enc, vb, vh);
561 default: /* V4L2_PIX_FMT_MJPEG */
562 ret = solo_fill_jpeg(solo_enc, vb, vh);
567 vb->v4l2_buf.sequence = solo_enc->sequence++;
568 vb->v4l2_buf.timestamp.tv_sec = vop_sec(vh);
569 vb->v4l2_buf.timestamp.tv_usec = vop_usec(vh);
572 vb2_buffer_done(vb, ret ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
577 static void solo_enc_handle_one(struct solo_enc_dev *solo_enc,
578 struct solo_enc_buf *enc_buf)
580 struct solo_vb2_buf *vb;
583 mutex_lock(&solo_enc->lock);
584 if (solo_enc->type != enc_buf->type)
587 spin_lock_irqsave(&solo_enc->av_lock, flags);
588 if (list_empty(&solo_enc->vidq_active)) {
589 spin_unlock_irqrestore(&solo_enc->av_lock, flags);
592 vb = list_first_entry(&solo_enc->vidq_active, struct solo_vb2_buf, list);
594 spin_unlock_irqrestore(&solo_enc->av_lock, flags);
596 solo_enc_fillbuf(solo_enc, &vb->vb, enc_buf);
598 mutex_unlock(&solo_enc->lock);
601 void solo_enc_v4l2_isr(struct solo_dev *solo_dev)
603 wake_up_interruptible_all(&solo_dev->ring_thread_wait);
606 static void solo_handle_ring(struct solo_dev *solo_dev)
609 struct solo_enc_dev *solo_enc;
610 struct solo_enc_buf enc_buf;
611 u32 mpeg_current, off;
615 /* Check if the hardware has any new ones in the queue */
616 cur_q = solo_reg_read(solo_dev, SOLO_VE_STATE(11)) & 0xff;
617 if (cur_q == solo_dev->enc_idx)
620 mpeg_current = solo_reg_read(solo_dev,
621 SOLO_VE_MPEG4_QUE(solo_dev->enc_idx));
622 solo_dev->enc_idx = (solo_dev->enc_idx + 1) % MP4_QS;
624 ch = (mpeg_current >> 24) & 0x1f;
625 off = mpeg_current & 0x00ffffff;
627 if (ch >= SOLO_MAX_CHANNELS) {
628 ch -= SOLO_MAX_CHANNELS;
629 enc_buf.type = SOLO_ENC_TYPE_EXT;
631 enc_buf.type = SOLO_ENC_TYPE_STD;
633 solo_enc = solo_dev->v4l2_enc[ch];
634 if (solo_enc == NULL) {
635 dev_err(&solo_dev->pdev->dev,
636 "Got spurious packet for channel %d\n", ch);
641 if (enc_get_mpeg_dma(solo_dev, solo_dev->vh_dma, off,
645 enc_buf.vh = solo_dev->vh_buf;
648 if (vop_mpeg_offset(enc_buf.vh) != SOLO_MP4E_EXT_ADDR(solo_dev) + off)
651 if (solo_motion_detected(solo_enc))
656 solo_enc_handle_one(solo_enc, &enc_buf);
660 static int solo_ring_thread(void *data)
662 struct solo_dev *solo_dev = data;
663 DECLARE_WAITQUEUE(wait, current);
666 add_wait_queue(&solo_dev->ring_thread_wait, &wait);
669 long timeout = schedule_timeout_interruptible(HZ);
670 if (timeout == -ERESTARTSYS || kthread_should_stop())
672 solo_irq_off(solo_dev, SOLO_IRQ_ENCODER);
673 solo_handle_ring(solo_dev);
674 solo_irq_on(solo_dev, SOLO_IRQ_ENCODER);
678 remove_wait_queue(&solo_dev->ring_thread_wait, &wait);
683 static int solo_enc_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
684 unsigned int *num_buffers, unsigned int *num_planes,
685 unsigned int sizes[], void *alloc_ctxs[])
687 sizes[0] = FRAME_BUF_SIZE;
690 if (*num_buffers < MIN_VID_BUFFERS)
691 *num_buffers = MIN_VID_BUFFERS;
696 static void solo_enc_buf_queue(struct vb2_buffer *vb)
698 struct vb2_queue *vq = vb->vb2_queue;
699 struct solo_enc_dev *solo_enc = vb2_get_drv_priv(vq);
700 struct solo_vb2_buf *solo_vb =
701 container_of(vb, struct solo_vb2_buf, vb);
703 spin_lock(&solo_enc->av_lock);
704 list_add_tail(&solo_vb->list, &solo_enc->vidq_active);
705 spin_unlock(&solo_enc->av_lock);
708 static int solo_ring_start(struct solo_dev *solo_dev)
710 solo_dev->ring_thread = kthread_run(solo_ring_thread, solo_dev,
711 SOLO6X10_NAME "_ring");
712 if (IS_ERR(solo_dev->ring_thread)) {
713 int err = PTR_ERR(solo_dev->ring_thread);
714 solo_dev->ring_thread = NULL;
718 solo_irq_on(solo_dev, SOLO_IRQ_ENCODER);
723 static void solo_ring_stop(struct solo_dev *solo_dev)
725 if (solo_dev->ring_thread) {
726 kthread_stop(solo_dev->ring_thread);
727 solo_dev->ring_thread = NULL;
730 solo_irq_off(solo_dev, SOLO_IRQ_ENCODER);
733 static int solo_enc_start_streaming(struct vb2_queue *q, unsigned int count)
735 struct solo_enc_dev *solo_enc = vb2_get_drv_priv(q);
738 ret = solo_enc_on(solo_enc);
741 return solo_ring_start(solo_enc->solo_dev);
744 static int solo_enc_stop_streaming(struct vb2_queue *q)
746 struct solo_enc_dev *solo_enc = vb2_get_drv_priv(q);
748 solo_enc_off(solo_enc);
749 INIT_LIST_HEAD(&solo_enc->vidq_active);
750 solo_ring_stop(solo_enc->solo_dev);
754 static struct vb2_ops solo_enc_video_qops = {
755 .queue_setup = solo_enc_queue_setup,
756 .buf_queue = solo_enc_buf_queue,
757 .start_streaming = solo_enc_start_streaming,
758 .stop_streaming = solo_enc_stop_streaming,
759 .wait_prepare = vb2_ops_wait_prepare,
760 .wait_finish = vb2_ops_wait_finish,
763 static int solo_enc_querycap(struct file *file, void *priv,
764 struct v4l2_capability *cap)
766 struct solo_enc_dev *solo_enc = video_drvdata(file);
767 struct solo_dev *solo_dev = solo_enc->solo_dev;
769 strcpy(cap->driver, SOLO6X10_NAME);
770 snprintf(cap->card, sizeof(cap->card), "Softlogic 6x10 Enc %d",
772 snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s",
773 pci_name(solo_dev->pdev));
774 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE |
775 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
776 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
780 static int solo_enc_enum_input(struct file *file, void *priv,
781 struct v4l2_input *input)
783 struct solo_enc_dev *solo_enc = video_drvdata(file);
784 struct solo_dev *solo_dev = solo_enc->solo_dev;
789 snprintf(input->name, sizeof(input->name), "Encoder %d",
791 input->type = V4L2_INPUT_TYPE_CAMERA;
792 input->std = solo_enc->vfd->tvnorms;
794 if (!tw28_get_video_status(solo_dev, solo_enc->ch))
795 input->status = V4L2_IN_ST_NO_SIGNAL;
800 static int solo_enc_set_input(struct file *file, void *priv,
809 static int solo_enc_get_input(struct file *file, void *priv,
817 static int solo_enc_enum_fmt_cap(struct file *file, void *priv,
818 struct v4l2_fmtdesc *f)
820 struct solo_enc_dev *solo_enc = video_drvdata(file);
821 int dev_type = solo_enc->solo_dev->type;
827 f->pixelformat = V4L2_PIX_FMT_MPEG4;
828 strcpy(f->description, "MPEG-4 part 2");
831 f->pixelformat = V4L2_PIX_FMT_H264;
832 strcpy(f->description, "H.264");
837 f->pixelformat = V4L2_PIX_FMT_MJPEG;
838 strcpy(f->description, "MJPEG");
844 f->flags = V4L2_FMT_FLAG_COMPRESSED;
849 static inline int solo_valid_pixfmt(u32 pixfmt, int dev_type)
851 return (pixfmt == V4L2_PIX_FMT_H264 && dev_type == SOLO_DEV_6110)
852 || (pixfmt == V4L2_PIX_FMT_MPEG4 && dev_type == SOLO_DEV_6010)
853 || pixfmt == V4L2_PIX_FMT_MJPEG ? 0 : -EINVAL;
856 static int solo_enc_try_fmt_cap(struct file *file, void *priv,
857 struct v4l2_format *f)
859 struct solo_enc_dev *solo_enc = video_drvdata(file);
860 struct solo_dev *solo_dev = solo_enc->solo_dev;
861 struct v4l2_pix_format *pix = &f->fmt.pix;
863 if (solo_valid_pixfmt(pix->pixelformat, solo_dev->type))
866 if (pix->width < solo_dev->video_hsize ||
867 pix->height < solo_dev->video_vsize << 1) {
868 /* Default to CIF 1/2 size */
869 pix->width = solo_dev->video_hsize >> 1;
870 pix->height = solo_dev->video_vsize;
873 pix->width = solo_dev->video_hsize;
874 pix->height = solo_dev->video_vsize << 1;
877 switch (pix->field) {
878 case V4L2_FIELD_NONE:
879 case V4L2_FIELD_INTERLACED:
883 pix->field = V4L2_FIELD_INTERLACED;
888 pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
889 pix->sizeimage = FRAME_BUF_SIZE;
890 pix->bytesperline = 0;
896 static int solo_enc_set_fmt_cap(struct file *file, void *priv,
897 struct v4l2_format *f)
899 struct solo_enc_dev *solo_enc = video_drvdata(file);
900 struct solo_dev *solo_dev = solo_enc->solo_dev;
901 struct v4l2_pix_format *pix = &f->fmt.pix;
904 if (vb2_is_busy(&solo_enc->vidq))
907 ret = solo_enc_try_fmt_cap(file, priv, f);
911 if (pix->width == solo_dev->video_hsize)
912 solo_enc->mode = SOLO_ENC_MODE_D1;
914 solo_enc->mode = SOLO_ENC_MODE_CIF;
916 /* This does not change the encoder at all */
917 solo_enc->fmt = pix->pixelformat;
920 * More information is needed about these 'extended' types. As far
921 * as I can tell these are basically additional video streams with
922 * different MPEG encoding attributes that can run in parallel with
923 * the main stream. If so, then this should be implemented as a
924 * second video node. Abusing priv like this is certainly not the
927 solo_enc->type = SOLO_ENC_TYPE_EXT;
929 solo_update_mode(solo_enc);
933 static int solo_enc_get_fmt_cap(struct file *file, void *priv,
934 struct v4l2_format *f)
936 struct solo_enc_dev *solo_enc = video_drvdata(file);
937 struct v4l2_pix_format *pix = &f->fmt.pix;
939 pix->width = solo_enc->width;
940 pix->height = solo_enc->height;
941 pix->pixelformat = solo_enc->fmt;
942 pix->field = solo_enc->interlaced ? V4L2_FIELD_INTERLACED :
944 pix->sizeimage = FRAME_BUF_SIZE;
945 pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
951 static int solo_enc_g_std(struct file *file, void *priv, v4l2_std_id *i)
953 struct solo_enc_dev *solo_enc = video_drvdata(file);
954 struct solo_dev *solo_dev = solo_enc->solo_dev;
956 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC)
957 *i = V4L2_STD_NTSC_M;
963 static int solo_enc_s_std(struct file *file, void *priv, v4l2_std_id std)
965 struct solo_enc_dev *solo_enc = video_drvdata(file);
967 return solo_set_video_type(solo_enc->solo_dev, std & V4L2_STD_PAL);
970 static int solo_enum_framesizes(struct file *file, void *priv,
971 struct v4l2_frmsizeenum *fsize)
973 struct solo_enc_dev *solo_enc = video_drvdata(file);
974 struct solo_dev *solo_dev = solo_enc->solo_dev;
976 if (solo_valid_pixfmt(fsize->pixel_format, solo_dev->type))
979 switch (fsize->index) {
981 fsize->discrete.width = solo_dev->video_hsize >> 1;
982 fsize->discrete.height = solo_dev->video_vsize;
985 fsize->discrete.width = solo_dev->video_hsize;
986 fsize->discrete.height = solo_dev->video_vsize << 1;
992 fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
997 static int solo_enum_frameintervals(struct file *file, void *priv,
998 struct v4l2_frmivalenum *fintv)
1000 struct solo_enc_dev *solo_enc = video_drvdata(file);
1001 struct solo_dev *solo_dev = solo_enc->solo_dev;
1003 if (solo_valid_pixfmt(fintv->pixel_format, solo_dev->type))
1007 if ((fintv->width != solo_dev->video_hsize >> 1 ||
1008 fintv->height != solo_dev->video_vsize) &&
1009 (fintv->width != solo_dev->video_hsize ||
1010 fintv->height != solo_dev->video_vsize << 1))
1013 fintv->type = V4L2_FRMIVAL_TYPE_STEPWISE;
1015 fintv->stepwise.min.numerator = 1;
1016 fintv->stepwise.min.denominator = solo_dev->fps;
1018 fintv->stepwise.max.numerator = 15;
1019 fintv->stepwise.max.denominator = solo_dev->fps;
1021 fintv->stepwise.step.numerator = 1;
1022 fintv->stepwise.step.denominator = solo_dev->fps;
1027 static int solo_g_parm(struct file *file, void *priv,
1028 struct v4l2_streamparm *sp)
1030 struct solo_enc_dev *solo_enc = video_drvdata(file);
1031 struct v4l2_captureparm *cp = &sp->parm.capture;
1033 cp->capability = V4L2_CAP_TIMEPERFRAME;
1034 cp->timeperframe.numerator = solo_enc->interval;
1035 cp->timeperframe.denominator = solo_enc->solo_dev->fps;
1036 cp->capturemode = 0;
1037 /* XXX: Shouldn't we be able to get/set this from videobuf? */
1038 cp->readbuffers = 2;
1043 static inline int calc_interval(u8 fps, u32 n, u32 d)
1050 return min(15U, n / d + (n % d >= (fps >> 1)));
1053 static int solo_s_parm(struct file *file, void *priv,
1054 struct v4l2_streamparm *sp)
1056 struct solo_enc_dev *solo_enc = video_drvdata(file);
1057 struct v4l2_fract *t = &sp->parm.capture.timeperframe;
1058 u8 fps = solo_enc->solo_dev->fps;
1060 if (vb2_is_streaming(&solo_enc->vidq))
1063 solo_enc->interval = calc_interval(fps, t->numerator, t->denominator);
1064 solo_update_mode(solo_enc);
1065 return solo_g_parm(file, priv, sp);
1068 static long solo_enc_default(struct file *file, void *fh,
1069 bool valid_prio, unsigned int cmd, void *arg)
1071 struct solo_enc_dev *solo_enc = video_drvdata(file);
1072 struct solo_dev *solo_dev = solo_enc->solo_dev;
1073 struct solo_motion_thresholds *thresholds = arg;
1076 case SOLO_IOC_G_MOTION_THRESHOLDS:
1077 *thresholds = solo_enc->motion_thresholds;
1080 case SOLO_IOC_S_MOTION_THRESHOLDS:
1083 solo_enc->motion_thresholds = *thresholds;
1084 if (solo_enc->motion_enabled && !solo_enc->motion_global)
1085 return solo_set_motion_block(solo_dev, solo_enc->ch,
1086 &solo_enc->motion_thresholds);
1093 static int solo_s_ctrl(struct v4l2_ctrl *ctrl)
1095 struct solo_enc_dev *solo_enc =
1096 container_of(ctrl->handler, struct solo_enc_dev, hdl);
1097 struct solo_dev *solo_dev = solo_enc->solo_dev;
1101 case V4L2_CID_BRIGHTNESS:
1102 case V4L2_CID_CONTRAST:
1103 case V4L2_CID_SATURATION:
1105 case V4L2_CID_SHARPNESS:
1106 return tw28_set_ctrl_val(solo_dev, ctrl->id, solo_enc->ch,
1108 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
1109 solo_enc->gop = ctrl->val;
1111 case V4L2_CID_MOTION_THRESHOLD:
1112 solo_enc->motion_thresh = ctrl->val;
1113 if (!solo_enc->motion_global || !solo_enc->motion_enabled)
1115 return solo_set_motion_threshold(solo_dev, solo_enc->ch, ctrl->val);
1116 case V4L2_CID_MOTION_MODE:
1117 solo_enc->motion_global = ctrl->val == 1;
1118 solo_enc->motion_enabled = ctrl->val > 0;
1120 if (solo_enc->motion_global)
1121 solo_set_motion_threshold(solo_dev, solo_enc->ch,
1122 solo_enc->motion_thresh);
1124 solo_set_motion_block(solo_dev, solo_enc->ch,
1125 &solo_enc->motion_thresholds);
1127 solo_motion_toggle(solo_enc, ctrl->val);
1129 case V4L2_CID_OSD_TEXT:
1130 strcpy(solo_enc->osd_text, ctrl->string);
1131 err = solo_osd_print(solo_enc);
1140 static const struct v4l2_file_operations solo_enc_fops = {
1141 .owner = THIS_MODULE,
1142 .open = v4l2_fh_open,
1143 .release = vb2_fop_release,
1144 .read = vb2_fop_read,
1145 .poll = vb2_fop_poll,
1146 .mmap = vb2_fop_mmap,
1147 .unlocked_ioctl = video_ioctl2,
1150 static const struct v4l2_ioctl_ops solo_enc_ioctl_ops = {
1151 .vidioc_querycap = solo_enc_querycap,
1152 .vidioc_s_std = solo_enc_s_std,
1153 .vidioc_g_std = solo_enc_g_std,
1154 /* Input callbacks */
1155 .vidioc_enum_input = solo_enc_enum_input,
1156 .vidioc_s_input = solo_enc_set_input,
1157 .vidioc_g_input = solo_enc_get_input,
1158 /* Video capture format callbacks */
1159 .vidioc_enum_fmt_vid_cap = solo_enc_enum_fmt_cap,
1160 .vidioc_try_fmt_vid_cap = solo_enc_try_fmt_cap,
1161 .vidioc_s_fmt_vid_cap = solo_enc_set_fmt_cap,
1162 .vidioc_g_fmt_vid_cap = solo_enc_get_fmt_cap,
1164 .vidioc_reqbufs = vb2_ioctl_reqbufs,
1165 .vidioc_querybuf = vb2_ioctl_querybuf,
1166 .vidioc_qbuf = vb2_ioctl_qbuf,
1167 .vidioc_dqbuf = vb2_ioctl_dqbuf,
1168 .vidioc_streamon = vb2_ioctl_streamon,
1169 .vidioc_streamoff = vb2_ioctl_streamoff,
1170 /* Frame size and interval */
1171 .vidioc_enum_framesizes = solo_enum_framesizes,
1172 .vidioc_enum_frameintervals = solo_enum_frameintervals,
1173 /* Video capture parameters */
1174 .vidioc_s_parm = solo_s_parm,
1175 .vidioc_g_parm = solo_g_parm,
1176 /* Logging and events */
1177 .vidioc_log_status = v4l2_ctrl_log_status,
1178 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1179 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1180 .vidioc_default = solo_enc_default,
1183 static const struct video_device solo_enc_template = {
1184 .name = SOLO6X10_NAME,
1185 .fops = &solo_enc_fops,
1186 .ioctl_ops = &solo_enc_ioctl_ops,
1188 .release = video_device_release,
1189 .tvnorms = V4L2_STD_NTSC_M | V4L2_STD_PAL,
1192 static const struct v4l2_ctrl_ops solo_ctrl_ops = {
1193 .s_ctrl = solo_s_ctrl,
1196 static const struct v4l2_ctrl_config solo_motion_threshold_ctrl = {
1197 .ops = &solo_ctrl_ops,
1198 .id = V4L2_CID_MOTION_THRESHOLD,
1199 .name = "Motion Detection Threshold",
1200 .type = V4L2_CTRL_TYPE_INTEGER,
1202 .def = SOLO_DEF_MOT_THRESH,
1204 .flags = V4L2_CTRL_FLAG_SLIDER,
1207 static const char * const solo_motion_mode_menu[] = {
1210 "Regional Threshold",
1214 static const struct v4l2_ctrl_config solo_motion_enable_ctrl = {
1215 .ops = &solo_ctrl_ops,
1216 .id = V4L2_CID_MOTION_MODE,
1217 .name = "Motion Detection Mode",
1218 .type = V4L2_CTRL_TYPE_MENU,
1219 .qmenu = solo_motion_mode_menu,
1223 static const struct v4l2_ctrl_config solo_osd_text_ctrl = {
1224 .ops = &solo_ctrl_ops,
1225 .id = V4L2_CID_OSD_TEXT,
1227 .type = V4L2_CTRL_TYPE_STRING,
1228 .max = OSD_TEXT_MAX,
1232 static struct solo_enc_dev *solo_enc_alloc(struct solo_dev *solo_dev,
1235 struct solo_enc_dev *solo_enc;
1236 struct v4l2_ctrl_handler *hdl;
1240 solo_enc = kzalloc(sizeof(*solo_enc), GFP_KERNEL);
1242 return ERR_PTR(-ENOMEM);
1244 hdl = &solo_enc->hdl;
1245 v4l2_ctrl_handler_init(hdl, 10);
1246 v4l2_ctrl_new_std(hdl, &solo_ctrl_ops,
1247 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
1248 v4l2_ctrl_new_std(hdl, &solo_ctrl_ops,
1249 V4L2_CID_CONTRAST, 0, 255, 1, 128);
1250 v4l2_ctrl_new_std(hdl, &solo_ctrl_ops,
1251 V4L2_CID_SATURATION, 0, 255, 1, 128);
1252 v4l2_ctrl_new_std(hdl, &solo_ctrl_ops,
1253 V4L2_CID_HUE, 0, 255, 1, 128);
1254 if (tw28_has_sharpness(solo_dev, ch))
1255 v4l2_ctrl_new_std(hdl, &solo_ctrl_ops,
1256 V4L2_CID_SHARPNESS, 0, 15, 1, 0);
1257 v4l2_ctrl_new_std(hdl, &solo_ctrl_ops,
1258 V4L2_CID_MPEG_VIDEO_GOP_SIZE, 1, 255, 1, solo_dev->fps);
1259 v4l2_ctrl_new_custom(hdl, &solo_motion_threshold_ctrl, NULL);
1260 v4l2_ctrl_new_custom(hdl, &solo_motion_enable_ctrl, NULL);
1261 v4l2_ctrl_new_custom(hdl, &solo_osd_text_ctrl, NULL);
1267 solo_enc->solo_dev = solo_dev;
1269 mutex_init(&solo_enc->lock);
1270 spin_lock_init(&solo_enc->av_lock);
1271 INIT_LIST_HEAD(&solo_enc->vidq_active);
1272 solo_enc->fmt = (solo_dev->type == SOLO_DEV_6010) ?
1273 V4L2_PIX_FMT_MPEG4 : V4L2_PIX_FMT_H264;
1274 solo_enc->type = SOLO_ENC_TYPE_STD;
1276 solo_enc->qp = SOLO_DEFAULT_QP;
1277 solo_enc->gop = solo_dev->fps;
1278 solo_enc->interval = 1;
1279 solo_enc->mode = SOLO_ENC_MODE_CIF;
1280 solo_enc->motion_global = true;
1281 solo_enc->motion_thresh = SOLO_DEF_MOT_THRESH;
1282 for (y = 0; y < SOLO_MOTION_SZ; y++)
1283 for (x = 0; x < SOLO_MOTION_SZ; x++)
1284 solo_enc->motion_thresholds.thresholds[y][x] =
1285 SOLO_DEF_MOT_THRESH;
1287 solo_enc->vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1288 solo_enc->vidq.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
1289 solo_enc->vidq.ops = &solo_enc_video_qops;
1290 solo_enc->vidq.mem_ops = &vb2_dma_sg_memops;
1291 solo_enc->vidq.drv_priv = solo_enc;
1292 solo_enc->vidq.gfp_flags = __GFP_DMA32;
1293 solo_enc->vidq.timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1294 solo_enc->vidq.buf_struct_size = sizeof(struct solo_vb2_buf);
1295 solo_enc->vidq.lock = &solo_enc->lock;
1296 ret = vb2_queue_init(&solo_enc->vidq);
1299 solo_update_mode(solo_enc);
1301 spin_lock_init(&solo_enc->motion_lock);
1303 /* Initialize this per encoder */
1304 solo_enc->jpeg_len = sizeof(jpeg_header);
1305 memcpy(solo_enc->jpeg_header, jpeg_header, solo_enc->jpeg_len);
1307 solo_enc->desc_nelts = 32;
1308 solo_enc->desc_items = pci_alloc_consistent(solo_dev->pdev,
1309 sizeof(struct solo_p2m_desc) *
1310 solo_enc->desc_nelts, &solo_enc->desc_dma);
1312 if (solo_enc->desc_items == NULL)
1315 solo_enc->vfd = video_device_alloc();
1319 *solo_enc->vfd = solo_enc_template;
1320 solo_enc->vfd->v4l2_dev = &solo_dev->v4l2_dev;
1321 solo_enc->vfd->ctrl_handler = hdl;
1322 solo_enc->vfd->queue = &solo_enc->vidq;
1323 solo_enc->vfd->lock = &solo_enc->lock;
1324 set_bit(V4L2_FL_USE_FH_PRIO, &solo_enc->vfd->flags);
1325 video_set_drvdata(solo_enc->vfd, solo_enc);
1326 ret = video_register_device(solo_enc->vfd, VFL_TYPE_GRABBER, nr);
1330 snprintf(solo_enc->vfd->name, sizeof(solo_enc->vfd->name),
1331 "%s-enc (%i/%i)", SOLO6X10_NAME, solo_dev->vfd->num,
1332 solo_enc->vfd->num);
1337 video_device_release(solo_enc->vfd);
1339 pci_free_consistent(solo_enc->solo_dev->pdev,
1340 sizeof(struct solo_p2m_desc) * solo_enc->desc_nelts,
1341 solo_enc->desc_items, solo_enc->desc_dma);
1343 v4l2_ctrl_handler_free(hdl);
1345 return ERR_PTR(ret);
1348 static void solo_enc_free(struct solo_enc_dev *solo_enc)
1350 if (solo_enc == NULL)
1353 video_unregister_device(solo_enc->vfd);
1354 v4l2_ctrl_handler_free(&solo_enc->hdl);
1358 int solo_enc_v4l2_init(struct solo_dev *solo_dev, unsigned nr)
1362 init_waitqueue_head(&solo_dev->ring_thread_wait);
1364 solo_dev->vh_size = sizeof(vop_header);
1365 solo_dev->vh_buf = pci_alloc_consistent(solo_dev->pdev,
1368 if (solo_dev->vh_buf == NULL)
1371 for (i = 0; i < solo_dev->nr_chans; i++) {
1372 solo_dev->v4l2_enc[i] = solo_enc_alloc(solo_dev, i, nr);
1373 if (IS_ERR(solo_dev->v4l2_enc[i]))
1377 if (i != solo_dev->nr_chans) {
1378 int ret = PTR_ERR(solo_dev->v4l2_enc[i]);
1380 solo_enc_free(solo_dev->v4l2_enc[i]);
1381 pci_free_consistent(solo_dev->pdev, solo_dev->vh_size,
1382 solo_dev->vh_buf, solo_dev->vh_dma);
1383 solo_dev->vh_buf = NULL;
1387 if (solo_dev->type == SOLO_DEV_6010)
1388 solo_dev->enc_bw_remain = solo_dev->fps * 4 * 4;
1390 solo_dev->enc_bw_remain = solo_dev->fps * 4 * 5;
1392 dev_info(&solo_dev->pdev->dev, "Encoders as /dev/video%d-%d\n",
1393 solo_dev->v4l2_enc[0]->vfd->num,
1394 solo_dev->v4l2_enc[solo_dev->nr_chans - 1]->vfd->num);
1399 void solo_enc_v4l2_exit(struct solo_dev *solo_dev)
1403 for (i = 0; i < solo_dev->nr_chans; i++)
1404 solo_enc_free(solo_dev->v4l2_enc[i]);
1406 if (solo_dev->vh_buf)
1407 pci_free_consistent(solo_dev->pdev, solo_dev->vh_size,
1408 solo_dev->vh_buf, solo_dev->vh_dma);