Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0003 
0004 #include <media/drv-intf/saa7146_vv.h>
0005 #include <linux/module.h>
0006 
0007 /****************************************************************************/
0008 /* resource management functions, shamelessly stolen from saa7134 driver */
0009 
0010 int saa7146_res_get(struct saa7146_fh *fh, unsigned int bit)
0011 {
0012     struct saa7146_dev *dev = fh->dev;
0013     struct saa7146_vv *vv = dev->vv_data;
0014 
0015     if (fh->resources & bit) {
0016         DEB_D("already allocated! want: 0x%02x, cur:0x%02x\n",
0017               bit, vv->resources);
0018         /* have it already allocated */
0019         return 1;
0020     }
0021 
0022     /* is it free? */
0023     if (vv->resources & bit) {
0024         DEB_D("locked! vv->resources:0x%02x, we want:0x%02x\n",
0025               vv->resources, bit);
0026         /* no, someone else uses it */
0027         return 0;
0028     }
0029     /* it's free, grab it */
0030     fh->resources |= bit;
0031     vv->resources |= bit;
0032     DEB_D("res: get 0x%02x, cur:0x%02x\n", bit, vv->resources);
0033     return 1;
0034 }
0035 
0036 void saa7146_res_free(struct saa7146_fh *fh, unsigned int bits)
0037 {
0038     struct saa7146_dev *dev = fh->dev;
0039     struct saa7146_vv *vv = dev->vv_data;
0040 
0041     BUG_ON((fh->resources & bits) != bits);
0042 
0043     fh->resources &= ~bits;
0044     vv->resources &= ~bits;
0045     DEB_D("res: put 0x%02x, cur:0x%02x\n", bits, vv->resources);
0046 }
0047 
0048 
0049 /********************************************************************************/
0050 /* common dma functions */
0051 
0052 void saa7146_dma_free(struct saa7146_dev *dev,struct videobuf_queue *q,
0053                         struct saa7146_buf *buf)
0054 {
0055     struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
0056     DEB_EE("dev:%p, buf:%p\n", dev, buf);
0057 
0058     videobuf_waiton(q, &buf->vb, 0, 0);
0059     videobuf_dma_unmap(q->dev, dma);
0060     videobuf_dma_free(dma);
0061     buf->vb.state = VIDEOBUF_NEEDS_INIT;
0062 }
0063 
0064 
0065 /********************************************************************************/
0066 /* common buffer functions */
0067 
0068 int saa7146_buffer_queue(struct saa7146_dev *dev,
0069              struct saa7146_dmaqueue *q,
0070              struct saa7146_buf *buf)
0071 {
0072     assert_spin_locked(&dev->slock);
0073     DEB_EE("dev:%p, dmaq:%p, buf:%p\n", dev, q, buf);
0074 
0075     BUG_ON(!q);
0076 
0077     if (NULL == q->curr) {
0078         q->curr = buf;
0079         DEB_D("immediately activating buffer %p\n", buf);
0080         buf->activate(dev,buf,NULL);
0081     } else {
0082         list_add_tail(&buf->vb.queue,&q->queue);
0083         buf->vb.state = VIDEOBUF_QUEUED;
0084         DEB_D("adding buffer %p to queue. (active buffer present)\n",
0085               buf);
0086     }
0087     return 0;
0088 }
0089 
0090 void saa7146_buffer_finish(struct saa7146_dev *dev,
0091                struct saa7146_dmaqueue *q,
0092                int state)
0093 {
0094     assert_spin_locked(&dev->slock);
0095     DEB_EE("dev:%p, dmaq:%p, state:%d\n", dev, q, state);
0096     DEB_EE("q->curr:%p\n", q->curr);
0097 
0098     /* finish current buffer */
0099     if (NULL == q->curr) {
0100         DEB_D("aiii. no current buffer\n");
0101         return;
0102     }
0103 
0104     q->curr->vb.state = state;
0105     q->curr->vb.ts = ktime_get_ns();
0106     wake_up(&q->curr->vb.done);
0107 
0108     q->curr = NULL;
0109 }
0110 
0111 void saa7146_buffer_next(struct saa7146_dev *dev,
0112              struct saa7146_dmaqueue *q, int vbi)
0113 {
0114     struct saa7146_buf *buf,*next = NULL;
0115 
0116     BUG_ON(!q);
0117 
0118     DEB_INT("dev:%p, dmaq:%p, vbi:%d\n", dev, q, vbi);
0119 
0120     assert_spin_locked(&dev->slock);
0121     if (!list_empty(&q->queue)) {
0122         /* activate next one from queue */
0123         buf = list_entry(q->queue.next,struct saa7146_buf,vb.queue);
0124         list_del(&buf->vb.queue);
0125         if (!list_empty(&q->queue))
0126             next = list_entry(q->queue.next,struct saa7146_buf, vb.queue);
0127         q->curr = buf;
0128         DEB_INT("next buffer: buf:%p, prev:%p, next:%p\n",
0129             buf, q->queue.prev, q->queue.next);
0130         buf->activate(dev,buf,next);
0131     } else {
0132         DEB_INT("no next buffer. stopping.\n");
0133         if( 0 != vbi ) {
0134             /* turn off video-dma3 */
0135             saa7146_write(dev,MC1, MASK_20);
0136         } else {
0137             /* nothing to do -- just prevent next video-dma1 transfer
0138                by lowering the protection address */
0139 
0140             // fixme: fix this for vflip != 0
0141 
0142             saa7146_write(dev, PROT_ADDR1, 0);
0143             saa7146_write(dev, MC2, (MASK_02|MASK_18));
0144 
0145             /* write the address of the rps-program */
0146             saa7146_write(dev, RPS_ADDR0, dev->d_rps0.dma_handle);
0147             /* turn on rps */
0148             saa7146_write(dev, MC1, (MASK_12 | MASK_28));
0149 
0150 /*
0151             printk("vdma%d.base_even:     0x%08x\n", 1,saa7146_read(dev,BASE_EVEN1));
0152             printk("vdma%d.base_odd:      0x%08x\n", 1,saa7146_read(dev,BASE_ODD1));
0153             printk("vdma%d.prot_addr:     0x%08x\n", 1,saa7146_read(dev,PROT_ADDR1));
0154             printk("vdma%d.base_page:     0x%08x\n", 1,saa7146_read(dev,BASE_PAGE1));
0155             printk("vdma%d.pitch:         0x%08x\n", 1,saa7146_read(dev,PITCH1));
0156             printk("vdma%d.num_line_byte: 0x%08x\n", 1,saa7146_read(dev,NUM_LINE_BYTE1));
0157 */
0158         }
0159         del_timer(&q->timeout);
0160     }
0161 }
0162 
0163 void saa7146_buffer_timeout(struct timer_list *t)
0164 {
0165     struct saa7146_dmaqueue *q = from_timer(q, t, timeout);
0166     struct saa7146_dev *dev = q->dev;
0167     unsigned long flags;
0168 
0169     DEB_EE("dev:%p, dmaq:%p\n", dev, q);
0170 
0171     spin_lock_irqsave(&dev->slock,flags);
0172     if (q->curr) {
0173         DEB_D("timeout on %p\n", q->curr);
0174         saa7146_buffer_finish(dev,q,VIDEOBUF_ERROR);
0175     }
0176 
0177     /* we don't restart the transfer here like other drivers do. when
0178        a streaming capture is disabled, the timeout function will be
0179        called for the current buffer. if we activate the next buffer now,
0180        we mess up our capture logic. if a timeout occurs on another buffer,
0181        then something is seriously broken before, so no need to buffer the
0182        next capture IMHO... */
0183 /*
0184     saa7146_buffer_next(dev,q);
0185 */
0186     spin_unlock_irqrestore(&dev->slock,flags);
0187 }
0188 
0189 /********************************************************************************/
0190 /* file operations */
0191 
0192 static int fops_open(struct file *file)
0193 {
0194     struct video_device *vdev = video_devdata(file);
0195     struct saa7146_dev *dev = video_drvdata(file);
0196     struct saa7146_fh *fh = NULL;
0197     int result = 0;
0198 
0199     DEB_EE("file:%p, dev:%s\n", file, video_device_node_name(vdev));
0200 
0201     if (mutex_lock_interruptible(vdev->lock))
0202         return -ERESTARTSYS;
0203 
0204     DEB_D("using: %p\n", dev);
0205 
0206     /* check if an extension is registered */
0207     if( NULL == dev->ext ) {
0208         DEB_S("no extension registered for this device\n");
0209         result = -ENODEV;
0210         goto out;
0211     }
0212 
0213     /* allocate per open data */
0214     fh = kzalloc(sizeof(*fh),GFP_KERNEL);
0215     if (NULL == fh) {
0216         DEB_S("cannot allocate memory for per open data\n");
0217         result = -ENOMEM;
0218         goto out;
0219     }
0220 
0221     v4l2_fh_init(&fh->fh, vdev);
0222 
0223     file->private_data = &fh->fh;
0224     fh->dev = dev;
0225 
0226     if (vdev->vfl_type == VFL_TYPE_VBI) {
0227         DEB_S("initializing vbi...\n");
0228         if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
0229             result = saa7146_vbi_uops.open(dev,file);
0230         if (dev->ext_vv_data->vbi_fops.open)
0231             dev->ext_vv_data->vbi_fops.open(file);
0232     } else {
0233         DEB_S("initializing video...\n");
0234         result = saa7146_video_uops.open(dev,file);
0235     }
0236 
0237     if (0 != result) {
0238         goto out;
0239     }
0240 
0241     if( 0 == try_module_get(dev->ext->module)) {
0242         result = -EINVAL;
0243         goto out;
0244     }
0245 
0246     result = 0;
0247     v4l2_fh_add(&fh->fh);
0248 out:
0249     if (fh && result != 0) {
0250         kfree(fh);
0251         file->private_data = NULL;
0252     }
0253     mutex_unlock(vdev->lock);
0254     return result;
0255 }
0256 
0257 static int fops_release(struct file *file)
0258 {
0259     struct video_device *vdev = video_devdata(file);
0260     struct saa7146_fh  *fh  = file->private_data;
0261     struct saa7146_dev *dev = fh->dev;
0262 
0263     DEB_EE("file:%p\n", file);
0264 
0265     mutex_lock(vdev->lock);
0266 
0267     if (vdev->vfl_type == VFL_TYPE_VBI) {
0268         if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
0269             saa7146_vbi_uops.release(dev,file);
0270         if (dev->ext_vv_data->vbi_fops.release)
0271             dev->ext_vv_data->vbi_fops.release(file);
0272     } else {
0273         saa7146_video_uops.release(dev,file);
0274     }
0275 
0276     v4l2_fh_del(&fh->fh);
0277     v4l2_fh_exit(&fh->fh);
0278     module_put(dev->ext->module);
0279     file->private_data = NULL;
0280     kfree(fh);
0281 
0282     mutex_unlock(vdev->lock);
0283 
0284     return 0;
0285 }
0286 
0287 static int fops_mmap(struct file *file, struct vm_area_struct * vma)
0288 {
0289     struct video_device *vdev = video_devdata(file);
0290     struct saa7146_fh *fh = file->private_data;
0291     struct videobuf_queue *q;
0292     int res;
0293 
0294     switch (vdev->vfl_type) {
0295     case VFL_TYPE_VIDEO: {
0296         DEB_EE("V4L2_BUF_TYPE_VIDEO_CAPTURE: file:%p, vma:%p\n",
0297                file, vma);
0298         q = &fh->video_q;
0299         break;
0300         }
0301     case VFL_TYPE_VBI: {
0302         DEB_EE("V4L2_BUF_TYPE_VBI_CAPTURE: file:%p, vma:%p\n",
0303                file, vma);
0304         if (fh->dev->ext_vv_data->capabilities & V4L2_CAP_SLICED_VBI_OUTPUT)
0305             return -ENODEV;
0306         q = &fh->vbi_q;
0307         break;
0308         }
0309     default:
0310         BUG();
0311     }
0312 
0313     if (mutex_lock_interruptible(vdev->lock))
0314         return -ERESTARTSYS;
0315     res = videobuf_mmap_mapper(q, vma);
0316     mutex_unlock(vdev->lock);
0317     return res;
0318 }
0319 
0320 static __poll_t __fops_poll(struct file *file, struct poll_table_struct *wait)
0321 {
0322     struct video_device *vdev = video_devdata(file);
0323     struct saa7146_fh *fh = file->private_data;
0324     struct videobuf_buffer *buf = NULL;
0325     struct videobuf_queue *q;
0326     __poll_t res = v4l2_ctrl_poll(file, wait);
0327 
0328     DEB_EE("file:%p, poll:%p\n", file, wait);
0329 
0330     if (vdev->vfl_type == VFL_TYPE_VBI) {
0331         if (fh->dev->ext_vv_data->capabilities & V4L2_CAP_SLICED_VBI_OUTPUT)
0332             return res | EPOLLOUT | EPOLLWRNORM;
0333         if( 0 == fh->vbi_q.streaming )
0334             return res | videobuf_poll_stream(file, &fh->vbi_q, wait);
0335         q = &fh->vbi_q;
0336     } else {
0337         DEB_D("using video queue\n");
0338         q = &fh->video_q;
0339     }
0340 
0341     if (!list_empty(&q->stream))
0342         buf = list_entry(q->stream.next, struct videobuf_buffer, stream);
0343 
0344     if (!buf) {
0345         DEB_D("buf == NULL!\n");
0346         return res | EPOLLERR;
0347     }
0348 
0349     poll_wait(file, &buf->done, wait);
0350     if (buf->state == VIDEOBUF_DONE || buf->state == VIDEOBUF_ERROR) {
0351         DEB_D("poll succeeded!\n");
0352         return res | EPOLLIN | EPOLLRDNORM;
0353     }
0354 
0355     DEB_D("nothing to poll for, buf->state:%d\n", buf->state);
0356     return res;
0357 }
0358 
0359 static __poll_t fops_poll(struct file *file, struct poll_table_struct *wait)
0360 {
0361     struct video_device *vdev = video_devdata(file);
0362     __poll_t res;
0363 
0364     mutex_lock(vdev->lock);
0365     res = __fops_poll(file, wait);
0366     mutex_unlock(vdev->lock);
0367     return res;
0368 }
0369 
0370 static ssize_t fops_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
0371 {
0372     struct video_device *vdev = video_devdata(file);
0373     struct saa7146_fh *fh = file->private_data;
0374     int ret;
0375 
0376     switch (vdev->vfl_type) {
0377     case VFL_TYPE_VIDEO:
0378 /*
0379         DEB_EE("V4L2_BUF_TYPE_VIDEO_CAPTURE: file:%p, data:%p, count:%lun",
0380                file, data, (unsigned long)count);
0381 */
0382         return saa7146_video_uops.read(file,data,count,ppos);
0383     case VFL_TYPE_VBI:
0384 /*
0385         DEB_EE("V4L2_BUF_TYPE_VBI_CAPTURE: file:%p, data:%p, count:%lu\n",
0386                file, data, (unsigned long)count);
0387 */
0388         if (fh->dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE) {
0389             if (mutex_lock_interruptible(vdev->lock))
0390                 return -ERESTARTSYS;
0391             ret = saa7146_vbi_uops.read(file, data, count, ppos);
0392             mutex_unlock(vdev->lock);
0393             return ret;
0394         }
0395         return -EINVAL;
0396     default:
0397         BUG();
0398     }
0399 }
0400 
0401 static ssize_t fops_write(struct file *file, const char __user *data, size_t count, loff_t *ppos)
0402 {
0403     struct video_device *vdev = video_devdata(file);
0404     struct saa7146_fh *fh = file->private_data;
0405     int ret;
0406 
0407     switch (vdev->vfl_type) {
0408     case VFL_TYPE_VIDEO:
0409         return -EINVAL;
0410     case VFL_TYPE_VBI:
0411         if (fh->dev->ext_vv_data->vbi_fops.write) {
0412             if (mutex_lock_interruptible(vdev->lock))
0413                 return -ERESTARTSYS;
0414             ret = fh->dev->ext_vv_data->vbi_fops.write(file, data, count, ppos);
0415             mutex_unlock(vdev->lock);
0416             return ret;
0417         }
0418         return -EINVAL;
0419     default:
0420         BUG();
0421     }
0422 }
0423 
0424 static const struct v4l2_file_operations video_fops =
0425 {
0426     .owner      = THIS_MODULE,
0427     .open       = fops_open,
0428     .release    = fops_release,
0429     .read       = fops_read,
0430     .write      = fops_write,
0431     .poll       = fops_poll,
0432     .mmap       = fops_mmap,
0433     .unlocked_ioctl = video_ioctl2,
0434 };
0435 
0436 static void vv_callback(struct saa7146_dev *dev, unsigned long status)
0437 {
0438     u32 isr = status;
0439 
0440     DEB_INT("dev:%p, isr:0x%08x\n", dev, (u32)status);
0441 
0442     if (0 != (isr & (MASK_27))) {
0443         DEB_INT("irq: RPS0 (0x%08x)\n", isr);
0444         saa7146_video_uops.irq_done(dev,isr);
0445     }
0446 
0447     if (0 != (isr & (MASK_28))) {
0448         u32 mc2 = saa7146_read(dev, MC2);
0449         if( 0 != (mc2 & MASK_15)) {
0450             DEB_INT("irq: RPS1 vbi workaround (0x%08x)\n", isr);
0451             wake_up(&dev->vv_data->vbi_wq);
0452             saa7146_write(dev,MC2, MASK_31);
0453             return;
0454         }
0455         DEB_INT("irq: RPS1 (0x%08x)\n", isr);
0456         saa7146_vbi_uops.irq_done(dev,isr);
0457     }
0458 }
0459 
0460 static const struct v4l2_ctrl_ops saa7146_ctrl_ops = {
0461     .s_ctrl = saa7146_s_ctrl,
0462 };
0463 
0464 int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv)
0465 {
0466     struct v4l2_ctrl_handler *hdl = &dev->ctrl_handler;
0467     struct v4l2_pix_format *fmt;
0468     struct v4l2_vbi_format *vbi;
0469     struct saa7146_vv *vv;
0470     int err;
0471 
0472     err = v4l2_device_register(&dev->pci->dev, &dev->v4l2_dev);
0473     if (err)
0474         return err;
0475 
0476     v4l2_ctrl_handler_init(hdl, 6);
0477     v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
0478         V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
0479     v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
0480         V4L2_CID_CONTRAST, 0, 127, 1, 64);
0481     v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
0482         V4L2_CID_SATURATION, 0, 127, 1, 64);
0483     v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
0484         V4L2_CID_VFLIP, 0, 1, 1, 0);
0485     v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
0486         V4L2_CID_HFLIP, 0, 1, 1, 0);
0487     if (hdl->error) {
0488         err = hdl->error;
0489         v4l2_ctrl_handler_free(hdl);
0490         v4l2_device_unregister(&dev->v4l2_dev);
0491         return err;
0492     }
0493     dev->v4l2_dev.ctrl_handler = hdl;
0494 
0495     vv = kzalloc(sizeof(struct saa7146_vv), GFP_KERNEL);
0496     if (vv == NULL) {
0497         ERR("out of memory. aborting.\n");
0498         v4l2_ctrl_handler_free(hdl);
0499         v4l2_device_unregister(&dev->v4l2_dev);
0500         return -ENOMEM;
0501     }
0502     ext_vv->vid_ops = saa7146_video_ioctl_ops;
0503     ext_vv->vbi_ops = saa7146_vbi_ioctl_ops;
0504     ext_vv->core_ops = &saa7146_video_ioctl_ops;
0505 
0506     DEB_EE("dev:%p\n", dev);
0507 
0508     /* set default values for video parts of the saa7146 */
0509     saa7146_write(dev, BCS_CTRL, 0x80400040);
0510 
0511     /* enable video-port pins */
0512     saa7146_write(dev, MC1, (MASK_10 | MASK_26));
0513 
0514     /* save per-device extension data (one extension can
0515        handle different devices that might need different
0516        configuration data) */
0517     dev->ext_vv_data = ext_vv;
0518 
0519     vv->d_clipping.cpu_addr =
0520         dma_alloc_coherent(&dev->pci->dev, SAA7146_CLIPPING_MEM,
0521                    &vv->d_clipping.dma_handle, GFP_KERNEL);
0522     if( NULL == vv->d_clipping.cpu_addr ) {
0523         ERR("out of memory. aborting.\n");
0524         kfree(vv);
0525         v4l2_ctrl_handler_free(hdl);
0526         v4l2_device_unregister(&dev->v4l2_dev);
0527         return -ENOMEM;
0528     }
0529 
0530     saa7146_video_uops.init(dev,vv);
0531     if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
0532         saa7146_vbi_uops.init(dev,vv);
0533 
0534     vv->ov_fb.fmt.width = vv->standard->h_max_out;
0535     vv->ov_fb.fmt.height = vv->standard->v_max_out;
0536     vv->ov_fb.fmt.pixelformat = V4L2_PIX_FMT_RGB565;
0537     vv->ov_fb.fmt.bytesperline = 2 * vv->ov_fb.fmt.width;
0538     vv->ov_fb.fmt.sizeimage = vv->ov_fb.fmt.bytesperline * vv->ov_fb.fmt.height;
0539     vv->ov_fb.fmt.colorspace = V4L2_COLORSPACE_SRGB;
0540 
0541     fmt = &vv->video_fmt;
0542     fmt->width = 384;
0543     fmt->height = 288;
0544     fmt->pixelformat = V4L2_PIX_FMT_BGR24;
0545     fmt->field = V4L2_FIELD_ANY;
0546     fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
0547     fmt->bytesperline = 3 * fmt->width;
0548     fmt->sizeimage = fmt->bytesperline * fmt->height;
0549 
0550     vbi = &vv->vbi_fmt;
0551     vbi->sampling_rate  = 27000000;
0552     vbi->offset     = 248; /* todo */
0553     vbi->samples_per_line   = 720 * 2;
0554     vbi->sample_format  = V4L2_PIX_FMT_GREY;
0555 
0556     /* fixme: this only works for PAL */
0557     vbi->start[0] = 5;
0558     vbi->count[0] = 16;
0559     vbi->start[1] = 312;
0560     vbi->count[1] = 16;
0561 
0562     timer_setup(&vv->vbi_read_timeout, NULL, 0);
0563 
0564     vv->ov_fb.capability = V4L2_FBUF_CAP_LIST_CLIPPING;
0565     vv->ov_fb.flags = V4L2_FBUF_FLAG_PRIMARY;
0566     dev->vv_data = vv;
0567     dev->vv_callback = &vv_callback;
0568 
0569     return 0;
0570 }
0571 EXPORT_SYMBOL_GPL(saa7146_vv_init);
0572 
0573 int saa7146_vv_release(struct saa7146_dev* dev)
0574 {
0575     struct saa7146_vv *vv = dev->vv_data;
0576 
0577     DEB_EE("dev:%p\n", dev);
0578 
0579     v4l2_device_unregister(&dev->v4l2_dev);
0580     dma_free_coherent(&dev->pci->dev, SAA7146_CLIPPING_MEM,
0581               vv->d_clipping.cpu_addr, vv->d_clipping.dma_handle);
0582     v4l2_ctrl_handler_free(&dev->ctrl_handler);
0583     kfree(vv);
0584     dev->vv_data = NULL;
0585     dev->vv_callback = NULL;
0586 
0587     return 0;
0588 }
0589 EXPORT_SYMBOL_GPL(saa7146_vv_release);
0590 
0591 int saa7146_register_device(struct video_device *vfd, struct saa7146_dev *dev,
0592                 char *name, int type)
0593 {
0594     int err;
0595     int i;
0596 
0597     DEB_EE("dev:%p, name:'%s', type:%d\n", dev, name, type);
0598 
0599     vfd->fops = &video_fops;
0600     if (type == VFL_TYPE_VIDEO)
0601         vfd->ioctl_ops = &dev->ext_vv_data->vid_ops;
0602     else
0603         vfd->ioctl_ops = &dev->ext_vv_data->vbi_ops;
0604     vfd->release = video_device_release_empty;
0605     vfd->lock = &dev->v4l2_lock;
0606     vfd->v4l2_dev = &dev->v4l2_dev;
0607     vfd->tvnorms = 0;
0608     for (i = 0; i < dev->ext_vv_data->num_stds; i++)
0609         vfd->tvnorms |= dev->ext_vv_data->stds[i].id;
0610     strscpy(vfd->name, name, sizeof(vfd->name));
0611     vfd->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OVERLAY |
0612                V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
0613     vfd->device_caps |= dev->ext_vv_data->capabilities;
0614     if (type == VFL_TYPE_VIDEO)
0615         vfd->device_caps &=
0616             ~(V4L2_CAP_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_OUTPUT);
0617     else
0618         vfd->device_caps &=
0619             ~(V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OVERLAY | V4L2_CAP_AUDIO);
0620     video_set_drvdata(vfd, dev);
0621 
0622     err = video_register_device(vfd, type, -1);
0623     if (err < 0) {
0624         ERR("cannot register v4l2 device. skipping.\n");
0625         return err;
0626     }
0627 
0628     pr_info("%s: registered device %s [v4l2]\n",
0629         dev->name, video_device_node_name(vfd));
0630     return 0;
0631 }
0632 EXPORT_SYMBOL_GPL(saa7146_register_device);
0633 
0634 int saa7146_unregister_device(struct video_device *vfd, struct saa7146_dev *dev)
0635 {
0636     DEB_EE("dev:%p\n", dev);
0637 
0638     video_unregister_device(vfd);
0639     return 0;
0640 }
0641 EXPORT_SYMBOL_GPL(saa7146_unregister_device);
0642 
0643 static int __init saa7146_vv_init_module(void)
0644 {
0645     return 0;
0646 }
0647 
0648 
0649 static void __exit saa7146_vv_cleanup_module(void)
0650 {
0651 }
0652 
0653 module_init(saa7146_vv_init_module);
0654 module_exit(saa7146_vv_cleanup_module);
0655 
0656 MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
0657 MODULE_DESCRIPTION("video4linux driver for saa7146-based hardware");
0658 MODULE_LICENSE("GPL");