1 // SPDX-License-Identifier: GPL-2.0-only
2 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
3 
4 #include <media/drv-intf/saa7146_vv.h>
5 #include <linux/module.h>
6 
7 /****************************************************************************/
8 /* resource management functions, shamelessly stolen from saa7134 driver */
9 
10 int saa7146_res_get(struct saa7146_fh *fh, unsigned int bit)
11 {
12 	struct saa7146_dev *dev = fh->dev;
13 	struct saa7146_vv *vv = dev->vv_data;
14 
15 	if (fh->resources & bit) {
16 		DEB_D("already allocated! want: 0x%02x, cur:0x%02x\n",
17 		      bit, vv->resources);
18 		/* have it already allocated */
19 		return 1;
20 	}
21 
22 	/* is it free? */
23 	if (vv->resources & bit) {
24 		DEB_D("locked! vv->resources:0x%02x, we want:0x%02x\n",
25 		      vv->resources, bit);
26 		/* no, someone else uses it */
27 		return 0;
28 	}
29 	/* it's free, grab it */
30 	fh->resources |= bit;
31 	vv->resources |= bit;
32 	DEB_D("res: get 0x%02x, cur:0x%02x\n", bit, vv->resources);
33 	return 1;
34 }
35 
36 void saa7146_res_free(struct saa7146_fh *fh, unsigned int bits)
37 {
38 	struct saa7146_dev *dev = fh->dev;
39 	struct saa7146_vv *vv = dev->vv_data;
40 
41 	BUG_ON((fh->resources & bits) != bits);
42 
43 	fh->resources &= ~bits;
44 	vv->resources &= ~bits;
45 	DEB_D("res: put 0x%02x, cur:0x%02x\n", bits, vv->resources);
46 }
47 
48 
49 /********************************************************************************/
50 /* common dma functions */
51 
52 void saa7146_dma_free(struct saa7146_dev *dev,struct videobuf_queue *q,
53 						struct saa7146_buf *buf)
54 {
55 	struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
56 	DEB_EE("dev:%p, buf:%p\n", dev, buf);
57 
58 	BUG_ON(in_interrupt());
59 
60 	videobuf_waiton(q, &buf->vb, 0, 0);
61 	videobuf_dma_unmap(q->dev, dma);
62 	videobuf_dma_free(dma);
63 	buf->vb.state = VIDEOBUF_NEEDS_INIT;
64 }
65 
66 
67 /********************************************************************************/
68 /* common buffer functions */
69 
70 int saa7146_buffer_queue(struct saa7146_dev *dev,
71 			 struct saa7146_dmaqueue *q,
72 			 struct saa7146_buf *buf)
73 {
74 	assert_spin_locked(&dev->slock);
75 	DEB_EE("dev:%p, dmaq:%p, buf:%p\n", dev, q, buf);
76 
77 	BUG_ON(!q);
78 
79 	if (NULL == q->curr) {
80 		q->curr = buf;
81 		DEB_D("immediately activating buffer %p\n", buf);
82 		buf->activate(dev,buf,NULL);
83 	} else {
84 		list_add_tail(&buf->vb.queue,&q->queue);
85 		buf->vb.state = VIDEOBUF_QUEUED;
86 		DEB_D("adding buffer %p to queue. (active buffer present)\n",
87 		      buf);
88 	}
89 	return 0;
90 }
91 
92 void saa7146_buffer_finish(struct saa7146_dev *dev,
93 			   struct saa7146_dmaqueue *q,
94 			   int state)
95 {
96 	assert_spin_locked(&dev->slock);
97 	DEB_EE("dev:%p, dmaq:%p, state:%d\n", dev, q, state);
98 	DEB_EE("q->curr:%p\n", q->curr);
99 
100 	/* finish current buffer */
101 	if (NULL == q->curr) {
102 		DEB_D("aiii. no current buffer\n");
103 		return;
104 	}
105 
106 	q->curr->vb.state = state;
107 	q->curr->vb.ts = ktime_get_ns();
108 	wake_up(&q->curr->vb.done);
109 
110 	q->curr = NULL;
111 }
112 
113 void saa7146_buffer_next(struct saa7146_dev *dev,
114 			 struct saa7146_dmaqueue *q, int vbi)
115 {
116 	struct saa7146_buf *buf,*next = NULL;
117 
118 	BUG_ON(!q);
119 
120 	DEB_INT("dev:%p, dmaq:%p, vbi:%d\n", dev, q, vbi);
121 
122 	assert_spin_locked(&dev->slock);
123 	if (!list_empty(&q->queue)) {
124 		/* activate next one from queue */
125 		buf = list_entry(q->queue.next,struct saa7146_buf,vb.queue);
126 		list_del(&buf->vb.queue);
127 		if (!list_empty(&q->queue))
128 			next = list_entry(q->queue.next,struct saa7146_buf, vb.queue);
129 		q->curr = buf;
130 		DEB_INT("next buffer: buf:%p, prev:%p, next:%p\n",
131 			buf, q->queue.prev, q->queue.next);
132 		buf->activate(dev,buf,next);
133 	} else {
134 		DEB_INT("no next buffer. stopping.\n");
135 		if( 0 != vbi ) {
136 			/* turn off video-dma3 */
137 			saa7146_write(dev,MC1, MASK_20);
138 		} else {
139 			/* nothing to do -- just prevent next video-dma1 transfer
140 			   by lowering the protection address */
141 
142 			// fixme: fix this for vflip != 0
143 
144 			saa7146_write(dev, PROT_ADDR1, 0);
145 			saa7146_write(dev, MC2, (MASK_02|MASK_18));
146 
147 			/* write the address of the rps-program */
148 			saa7146_write(dev, RPS_ADDR0, dev->d_rps0.dma_handle);
149 			/* turn on rps */
150 			saa7146_write(dev, MC1, (MASK_12 | MASK_28));
151 
152 /*
153 			printk("vdma%d.base_even:     0x%08x\n", 1,saa7146_read(dev,BASE_EVEN1));
154 			printk("vdma%d.base_odd:      0x%08x\n", 1,saa7146_read(dev,BASE_ODD1));
155 			printk("vdma%d.prot_addr:     0x%08x\n", 1,saa7146_read(dev,PROT_ADDR1));
156 			printk("vdma%d.base_page:     0x%08x\n", 1,saa7146_read(dev,BASE_PAGE1));
157 			printk("vdma%d.pitch:         0x%08x\n", 1,saa7146_read(dev,PITCH1));
158 			printk("vdma%d.num_line_byte: 0x%08x\n", 1,saa7146_read(dev,NUM_LINE_BYTE1));
159 */
160 		}
161 		del_timer(&q->timeout);
162 	}
163 }
164 
165 void saa7146_buffer_timeout(struct timer_list *t)
166 {
167 	struct saa7146_dmaqueue *q = from_timer(q, t, timeout);
168 	struct saa7146_dev *dev = q->dev;
169 	unsigned long flags;
170 
171 	DEB_EE("dev:%p, dmaq:%p\n", dev, q);
172 
173 	spin_lock_irqsave(&dev->slock,flags);
174 	if (q->curr) {
175 		DEB_D("timeout on %p\n", q->curr);
176 		saa7146_buffer_finish(dev,q,VIDEOBUF_ERROR);
177 	}
178 
179 	/* we don't restart the transfer here like other drivers do. when
180 	   a streaming capture is disabled, the timeout function will be
181 	   called for the current buffer. if we activate the next buffer now,
182 	   we mess up our capture logic. if a timeout occurs on another buffer,
183 	   then something is seriously broken before, so no need to buffer the
184 	   next capture IMHO... */
185 /*
186 	saa7146_buffer_next(dev,q);
187 */
188 	spin_unlock_irqrestore(&dev->slock,flags);
189 }
190 
191 /********************************************************************************/
192 /* file operations */
193 
194 static int fops_open(struct file *file)
195 {
196 	struct video_device *vdev = video_devdata(file);
197 	struct saa7146_dev *dev = video_drvdata(file);
198 	struct saa7146_fh *fh = NULL;
199 	int result = 0;
200 
201 	DEB_EE("file:%p, dev:%s\n", file, video_device_node_name(vdev));
202 
203 	if (mutex_lock_interruptible(vdev->lock))
204 		return -ERESTARTSYS;
205 
206 	DEB_D("using: %p\n", dev);
207 
208 	/* check if an extension is registered */
209 	if( NULL == dev->ext ) {
210 		DEB_S("no extension registered for this device\n");
211 		result = -ENODEV;
212 		goto out;
213 	}
214 
215 	/* allocate per open data */
216 	fh = kzalloc(sizeof(*fh),GFP_KERNEL);
217 	if (NULL == fh) {
218 		DEB_S("cannot allocate memory for per open data\n");
219 		result = -ENOMEM;
220 		goto out;
221 	}
222 
223 	v4l2_fh_init(&fh->fh, vdev);
224 
225 	file->private_data = &fh->fh;
226 	fh->dev = dev;
227 
228 	if (vdev->vfl_type == VFL_TYPE_VBI) {
229 		DEB_S("initializing vbi...\n");
230 		if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
231 			result = saa7146_vbi_uops.open(dev,file);
232 		if (dev->ext_vv_data->vbi_fops.open)
233 			dev->ext_vv_data->vbi_fops.open(file);
234 	} else {
235 		DEB_S("initializing video...\n");
236 		result = saa7146_video_uops.open(dev,file);
237 	}
238 
239 	if (0 != result) {
240 		goto out;
241 	}
242 
243 	if( 0 == try_module_get(dev->ext->module)) {
244 		result = -EINVAL;
245 		goto out;
246 	}
247 
248 	result = 0;
249 	v4l2_fh_add(&fh->fh);
250 out:
251 	if (fh && result != 0) {
252 		kfree(fh);
253 		file->private_data = NULL;
254 	}
255 	mutex_unlock(vdev->lock);
256 	return result;
257 }
258 
259 static int fops_release(struct file *file)
260 {
261 	struct video_device *vdev = video_devdata(file);
262 	struct saa7146_fh  *fh  = file->private_data;
263 	struct saa7146_dev *dev = fh->dev;
264 
265 	DEB_EE("file:%p\n", file);
266 
267 	mutex_lock(vdev->lock);
268 
269 	if (vdev->vfl_type == VFL_TYPE_VBI) {
270 		if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
271 			saa7146_vbi_uops.release(dev,file);
272 		if (dev->ext_vv_data->vbi_fops.release)
273 			dev->ext_vv_data->vbi_fops.release(file);
274 	} else {
275 		saa7146_video_uops.release(dev,file);
276 	}
277 
278 	v4l2_fh_del(&fh->fh);
279 	v4l2_fh_exit(&fh->fh);
280 	module_put(dev->ext->module);
281 	file->private_data = NULL;
282 	kfree(fh);
283 
284 	mutex_unlock(vdev->lock);
285 
286 	return 0;
287 }
288 
289 static int fops_mmap(struct file *file, struct vm_area_struct * vma)
290 {
291 	struct video_device *vdev = video_devdata(file);
292 	struct saa7146_fh *fh = file->private_data;
293 	struct videobuf_queue *q;
294 	int res;
295 
296 	switch (vdev->vfl_type) {
297 	case VFL_TYPE_VIDEO: {
298 		DEB_EE("V4L2_BUF_TYPE_VIDEO_CAPTURE: file:%p, vma:%p\n",
299 		       file, vma);
300 		q = &fh->video_q;
301 		break;
302 		}
303 	case VFL_TYPE_VBI: {
304 		DEB_EE("V4L2_BUF_TYPE_VBI_CAPTURE: file:%p, vma:%p\n",
305 		       file, vma);
306 		if (fh->dev->ext_vv_data->capabilities & V4L2_CAP_SLICED_VBI_OUTPUT)
307 			return -ENODEV;
308 		q = &fh->vbi_q;
309 		break;
310 		}
311 	default:
312 		BUG();
313 	}
314 
315 	if (mutex_lock_interruptible(vdev->lock))
316 		return -ERESTARTSYS;
317 	res = videobuf_mmap_mapper(q, vma);
318 	mutex_unlock(vdev->lock);
319 	return res;
320 }
321 
322 static __poll_t __fops_poll(struct file *file, struct poll_table_struct *wait)
323 {
324 	struct video_device *vdev = video_devdata(file);
325 	struct saa7146_fh *fh = file->private_data;
326 	struct videobuf_buffer *buf = NULL;
327 	struct videobuf_queue *q;
328 	__poll_t res = v4l2_ctrl_poll(file, wait);
329 
330 	DEB_EE("file:%p, poll:%p\n", file, wait);
331 
332 	if (vdev->vfl_type == VFL_TYPE_VBI) {
333 		if (fh->dev->ext_vv_data->capabilities & V4L2_CAP_SLICED_VBI_OUTPUT)
334 			return res | EPOLLOUT | EPOLLWRNORM;
335 		if( 0 == fh->vbi_q.streaming )
336 			return res | videobuf_poll_stream(file, &fh->vbi_q, wait);
337 		q = &fh->vbi_q;
338 	} else {
339 		DEB_D("using video queue\n");
340 		q = &fh->video_q;
341 	}
342 
343 	if (!list_empty(&q->stream))
344 		buf = list_entry(q->stream.next, struct videobuf_buffer, stream);
345 
346 	if (!buf) {
347 		DEB_D("buf == NULL!\n");
348 		return res | EPOLLERR;
349 	}
350 
351 	poll_wait(file, &buf->done, wait);
352 	if (buf->state == VIDEOBUF_DONE || buf->state == VIDEOBUF_ERROR) {
353 		DEB_D("poll succeeded!\n");
354 		return res | EPOLLIN | EPOLLRDNORM;
355 	}
356 
357 	DEB_D("nothing to poll for, buf->state:%d\n", buf->state);
358 	return res;
359 }
360 
361 static __poll_t fops_poll(struct file *file, struct poll_table_struct *wait)
362 {
363 	struct video_device *vdev = video_devdata(file);
364 	__poll_t res;
365 
366 	mutex_lock(vdev->lock);
367 	res = __fops_poll(file, wait);
368 	mutex_unlock(vdev->lock);
369 	return res;
370 }
371 
372 static ssize_t fops_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
373 {
374 	struct video_device *vdev = video_devdata(file);
375 	struct saa7146_fh *fh = file->private_data;
376 	int ret;
377 
378 	switch (vdev->vfl_type) {
379 	case VFL_TYPE_VIDEO:
380 /*
381 		DEB_EE("V4L2_BUF_TYPE_VIDEO_CAPTURE: file:%p, data:%p, count:%lun",
382 		       file, data, (unsigned long)count);
383 */
384 		return saa7146_video_uops.read(file,data,count,ppos);
385 	case VFL_TYPE_VBI:
386 /*
387 		DEB_EE("V4L2_BUF_TYPE_VBI_CAPTURE: file:%p, data:%p, count:%lu\n",
388 		       file, data, (unsigned long)count);
389 */
390 		if (fh->dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE) {
391 			if (mutex_lock_interruptible(vdev->lock))
392 				return -ERESTARTSYS;
393 			ret = saa7146_vbi_uops.read(file, data, count, ppos);
394 			mutex_unlock(vdev->lock);
395 			return ret;
396 		}
397 		return -EINVAL;
398 	default:
399 		BUG();
400 	}
401 }
402 
403 static ssize_t fops_write(struct file *file, const char __user *data, size_t count, loff_t *ppos)
404 {
405 	struct video_device *vdev = video_devdata(file);
406 	struct saa7146_fh *fh = file->private_data;
407 	int ret;
408 
409 	switch (vdev->vfl_type) {
410 	case VFL_TYPE_VIDEO:
411 		return -EINVAL;
412 	case VFL_TYPE_VBI:
413 		if (fh->dev->ext_vv_data->vbi_fops.write) {
414 			if (mutex_lock_interruptible(vdev->lock))
415 				return -ERESTARTSYS;
416 			ret = fh->dev->ext_vv_data->vbi_fops.write(file, data, count, ppos);
417 			mutex_unlock(vdev->lock);
418 			return ret;
419 		}
420 		return -EINVAL;
421 	default:
422 		BUG();
423 	}
424 }
425 
426 static const struct v4l2_file_operations video_fops =
427 {
428 	.owner		= THIS_MODULE,
429 	.open		= fops_open,
430 	.release	= fops_release,
431 	.read		= fops_read,
432 	.write		= fops_write,
433 	.poll		= fops_poll,
434 	.mmap		= fops_mmap,
435 	.unlocked_ioctl	= video_ioctl2,
436 };
437 
438 static void vv_callback(struct saa7146_dev *dev, unsigned long status)
439 {
440 	u32 isr = status;
441 
442 	DEB_INT("dev:%p, isr:0x%08x\n", dev, (u32)status);
443 
444 	if (0 != (isr & (MASK_27))) {
445 		DEB_INT("irq: RPS0 (0x%08x)\n", isr);
446 		saa7146_video_uops.irq_done(dev,isr);
447 	}
448 
449 	if (0 != (isr & (MASK_28))) {
450 		u32 mc2 = saa7146_read(dev, MC2);
451 		if( 0 != (mc2 & MASK_15)) {
452 			DEB_INT("irq: RPS1 vbi workaround (0x%08x)\n", isr);
453 			wake_up(&dev->vv_data->vbi_wq);
454 			saa7146_write(dev,MC2, MASK_31);
455 			return;
456 		}
457 		DEB_INT("irq: RPS1 (0x%08x)\n", isr);
458 		saa7146_vbi_uops.irq_done(dev,isr);
459 	}
460 }
461 
462 static const struct v4l2_ctrl_ops saa7146_ctrl_ops = {
463 	.s_ctrl = saa7146_s_ctrl,
464 };
465 
466 int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv)
467 {
468 	struct v4l2_ctrl_handler *hdl = &dev->ctrl_handler;
469 	struct v4l2_pix_format *fmt;
470 	struct v4l2_vbi_format *vbi;
471 	struct saa7146_vv *vv;
472 	int err;
473 
474 	err = v4l2_device_register(&dev->pci->dev, &dev->v4l2_dev);
475 	if (err)
476 		return err;
477 
478 	v4l2_ctrl_handler_init(hdl, 6);
479 	v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
480 		V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
481 	v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
482 		V4L2_CID_CONTRAST, 0, 127, 1, 64);
483 	v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
484 		V4L2_CID_SATURATION, 0, 127, 1, 64);
485 	v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
486 		V4L2_CID_VFLIP, 0, 1, 1, 0);
487 	v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
488 		V4L2_CID_HFLIP, 0, 1, 1, 0);
489 	if (hdl->error) {
490 		err = hdl->error;
491 		v4l2_ctrl_handler_free(hdl);
492 		return err;
493 	}
494 	dev->v4l2_dev.ctrl_handler = hdl;
495 
496 	vv = kzalloc(sizeof(struct saa7146_vv), GFP_KERNEL);
497 	if (vv == NULL) {
498 		ERR("out of memory. aborting.\n");
499 		v4l2_ctrl_handler_free(hdl);
500 		return -ENOMEM;
501 	}
502 	ext_vv->vid_ops = saa7146_video_ioctl_ops;
503 	ext_vv->vbi_ops = saa7146_vbi_ioctl_ops;
504 	ext_vv->core_ops = &saa7146_video_ioctl_ops;
505 
506 	DEB_EE("dev:%p\n", dev);
507 
508 	/* set default values for video parts of the saa7146 */
509 	saa7146_write(dev, BCS_CTRL, 0x80400040);
510 
511 	/* enable video-port pins */
512 	saa7146_write(dev, MC1, (MASK_10 | MASK_26));
513 
514 	/* save per-device extension data (one extension can
515 	   handle different devices that might need different
516 	   configuration data) */
517 	dev->ext_vv_data = ext_vv;
518 
519 	vv->d_clipping.cpu_addr =
520 		pci_zalloc_consistent(dev->pci, SAA7146_CLIPPING_MEM,
521 				      &vv->d_clipping.dma_handle);
522 	if( NULL == vv->d_clipping.cpu_addr ) {
523 		ERR("out of memory. aborting.\n");
524 		kfree(vv);
525 		v4l2_ctrl_handler_free(hdl);
526 		return -1;
527 	}
528 
529 	saa7146_video_uops.init(dev,vv);
530 	if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
531 		saa7146_vbi_uops.init(dev,vv);
532 
533 	vv->ov_fb.fmt.width = vv->standard->h_max_out;
534 	vv->ov_fb.fmt.height = vv->standard->v_max_out;
535 	vv->ov_fb.fmt.pixelformat = V4L2_PIX_FMT_RGB565;
536 	vv->ov_fb.fmt.bytesperline = 2 * vv->ov_fb.fmt.width;
537 	vv->ov_fb.fmt.sizeimage = vv->ov_fb.fmt.bytesperline * vv->ov_fb.fmt.height;
538 	vv->ov_fb.fmt.colorspace = V4L2_COLORSPACE_SRGB;
539 
540 	fmt = &vv->video_fmt;
541 	fmt->width = 384;
542 	fmt->height = 288;
543 	fmt->pixelformat = V4L2_PIX_FMT_BGR24;
544 	fmt->field = V4L2_FIELD_ANY;
545 	fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
546 	fmt->bytesperline = 3 * fmt->width;
547 	fmt->sizeimage = fmt->bytesperline * fmt->height;
548 
549 	vbi = &vv->vbi_fmt;
550 	vbi->sampling_rate	= 27000000;
551 	vbi->offset		= 248; /* todo */
552 	vbi->samples_per_line	= 720 * 2;
553 	vbi->sample_format	= V4L2_PIX_FMT_GREY;
554 
555 	/* fixme: this only works for PAL */
556 	vbi->start[0] = 5;
557 	vbi->count[0] = 16;
558 	vbi->start[1] = 312;
559 	vbi->count[1] = 16;
560 
561 	timer_setup(&vv->vbi_read_timeout, NULL, 0);
562 
563 	vv->ov_fb.capability = V4L2_FBUF_CAP_LIST_CLIPPING;
564 	vv->ov_fb.flags = V4L2_FBUF_FLAG_PRIMARY;
565 	dev->vv_data = vv;
566 	dev->vv_callback = &vv_callback;
567 
568 	return 0;
569 }
570 EXPORT_SYMBOL_GPL(saa7146_vv_init);
571 
572 int saa7146_vv_release(struct saa7146_dev* dev)
573 {
574 	struct saa7146_vv *vv = dev->vv_data;
575 
576 	DEB_EE("dev:%p\n", dev);
577 
578 	v4l2_device_unregister(&dev->v4l2_dev);
579 	pci_free_consistent(dev->pci, SAA7146_CLIPPING_MEM, vv->d_clipping.cpu_addr, vv->d_clipping.dma_handle);
580 	v4l2_ctrl_handler_free(&dev->ctrl_handler);
581 	kfree(vv);
582 	dev->vv_data = NULL;
583 	dev->vv_callback = NULL;
584 
585 	return 0;
586 }
587 EXPORT_SYMBOL_GPL(saa7146_vv_release);
588 
589 int saa7146_register_device(struct video_device *vfd, struct saa7146_dev *dev,
590 			    char *name, int type)
591 {
592 	int err;
593 	int i;
594 
595 	DEB_EE("dev:%p, name:'%s', type:%d\n", dev, name, type);
596 
597 	vfd->fops = &video_fops;
598 	if (type == VFL_TYPE_VIDEO)
599 		vfd->ioctl_ops = &dev->ext_vv_data->vid_ops;
600 	else
601 		vfd->ioctl_ops = &dev->ext_vv_data->vbi_ops;
602 	vfd->release = video_device_release_empty;
603 	vfd->lock = &dev->v4l2_lock;
604 	vfd->v4l2_dev = &dev->v4l2_dev;
605 	vfd->tvnorms = 0;
606 	for (i = 0; i < dev->ext_vv_data->num_stds; i++)
607 		vfd->tvnorms |= dev->ext_vv_data->stds[i].id;
608 	strscpy(vfd->name, name, sizeof(vfd->name));
609 	vfd->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OVERLAY |
610 			   V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
611 	vfd->device_caps |= dev->ext_vv_data->capabilities;
612 	if (type == VFL_TYPE_VIDEO)
613 		vfd->device_caps &=
614 			~(V4L2_CAP_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_OUTPUT);
615 	else
616 		vfd->device_caps &=
617 			~(V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OVERLAY | V4L2_CAP_AUDIO);
618 	video_set_drvdata(vfd, dev);
619 
620 	err = video_register_device(vfd, type, -1);
621 	if (err < 0) {
622 		ERR("cannot register v4l2 device. skipping.\n");
623 		return err;
624 	}
625 
626 	pr_info("%s: registered device %s [v4l2]\n",
627 		dev->name, video_device_node_name(vfd));
628 	return 0;
629 }
630 EXPORT_SYMBOL_GPL(saa7146_register_device);
631 
632 int saa7146_unregister_device(struct video_device *vfd, struct saa7146_dev *dev)
633 {
634 	DEB_EE("dev:%p\n", dev);
635 
636 	video_unregister_device(vfd);
637 	return 0;
638 }
639 EXPORT_SYMBOL_GPL(saa7146_unregister_device);
640 
641 static int __init saa7146_vv_init_module(void)
642 {
643 	return 0;
644 }
645 
646 
647 static void __exit saa7146_vv_cleanup_module(void)
648 {
649 }
650 
651 module_init(saa7146_vv_init_module);
652 module_exit(saa7146_vv_cleanup_module);
653 
654 MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
655 MODULE_DESCRIPTION("video4linux driver for saa7146-based hardware");
656 MODULE_LICENSE("GPL");
657