0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/types.h>
0013 #include <linux/kernel.h>
0014 #include <linux/module.h>
0015 #include <linux/init.h>
0016 #include <linux/kmod.h>
0017 #include <linux/mutex.h>
0018 #include <linux/pci.h>
0019 #include <linux/interrupt.h>
0020 #include <linux/videodev2.h>
0021 #include <linux/v4l2-dv-timings.h>
0022 #include <media/v4l2-device.h>
0023 #include <media/v4l2-dev.h>
0024 #include <media/v4l2-ioctl.h>
0025 #include <media/v4l2-dv-timings.h>
0026 #include <media/v4l2-ctrls.h>
0027 #include <media/v4l2-event.h>
0028 #include <media/videobuf2-v4l2.h>
0029 #include <media/videobuf2-dma-contig.h>
0030
0031 MODULE_DESCRIPTION("V4L2 PCI Skeleton Driver");
0032 MODULE_AUTHOR("Hans Verkuil");
0033 MODULE_LICENSE("GPL v2");
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 struct skeleton {
0053 struct pci_dev *pdev;
0054 struct v4l2_device v4l2_dev;
0055 struct video_device vdev;
0056 struct v4l2_ctrl_handler ctrl_handler;
0057 struct mutex lock;
0058 v4l2_std_id std;
0059 struct v4l2_dv_timings timings;
0060 struct v4l2_pix_format format;
0061 unsigned input;
0062
0063 struct vb2_queue queue;
0064
0065 spinlock_t qlock;
0066 struct list_head buf_list;
0067 unsigned field;
0068 unsigned sequence;
0069 };
0070
0071 struct skel_buffer {
0072 struct vb2_v4l2_buffer vb;
0073 struct list_head list;
0074 };
0075
0076 static inline struct skel_buffer *to_skel_buffer(struct vb2_v4l2_buffer *vbuf)
0077 {
0078 return container_of(vbuf, struct skel_buffer, vb);
0079 }
0080
0081 static const struct pci_device_id skeleton_pci_tbl[] = {
0082
0083 { 0, }
0084 };
0085 MODULE_DEVICE_TABLE(pci, skeleton_pci_tbl);
0086
0087
0088
0089
0090
0091
0092 static const struct v4l2_dv_timings_cap skel_timings_cap = {
0093 .type = V4L2_DV_BT_656_1120,
0094
0095 .reserved = { 0 },
0096 V4L2_INIT_BT_TIMINGS(
0097 720, 1920,
0098 480, 1080,
0099 27000000, 74250000,
0100 V4L2_DV_BT_STD_CEA861,
0101
0102 V4L2_DV_BT_CAP_INTERLACED | V4L2_DV_BT_CAP_PROGRESSIVE
0103 )
0104 };
0105
0106
0107
0108
0109
0110 #define SKEL_TVNORMS V4L2_STD_ALL
0111
0112
0113
0114
0115
0116
0117
0118 static irqreturn_t skeleton_irq(int irq, void *dev_id)
0119 {
0120 #ifdef TODO
0121 struct skeleton *skel = dev_id;
0122
0123
0124
0125
0126 if (captured_new_frame) {
0127 ...
0128 spin_lock(&skel->qlock);
0129 list_del(&new_buf->list);
0130 spin_unlock(&skel->qlock);
0131 new_buf->vb.vb2_buf.timestamp = ktime_get_ns();
0132 new_buf->vb.sequence = skel->sequence++;
0133 new_buf->vb.field = skel->field;
0134 if (skel->format.field == V4L2_FIELD_ALTERNATE) {
0135 if (skel->field == V4L2_FIELD_BOTTOM)
0136 skel->field = V4L2_FIELD_TOP;
0137 else if (skel->field == V4L2_FIELD_TOP)
0138 skel->field = V4L2_FIELD_BOTTOM;
0139 }
0140 vb2_buffer_done(&new_buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
0141 }
0142 #endif
0143 return IRQ_HANDLED;
0144 }
0145
0146
0147
0148
0149
0150
0151
0152
0153 static int queue_setup(struct vb2_queue *vq,
0154 unsigned int *nbuffers, unsigned int *nplanes,
0155 unsigned int sizes[], struct device *alloc_devs[])
0156 {
0157 struct skeleton *skel = vb2_get_drv_priv(vq);
0158
0159 skel->field = skel->format.field;
0160 if (skel->field == V4L2_FIELD_ALTERNATE) {
0161
0162
0163
0164
0165 if (vb2_fileio_is_active(vq))
0166 return -EINVAL;
0167 skel->field = V4L2_FIELD_TOP;
0168 }
0169
0170 if (vq->num_buffers + *nbuffers < 3)
0171 *nbuffers = 3 - vq->num_buffers;
0172
0173 if (*nplanes)
0174 return sizes[0] < skel->format.sizeimage ? -EINVAL : 0;
0175 *nplanes = 1;
0176 sizes[0] = skel->format.sizeimage;
0177 return 0;
0178 }
0179
0180
0181
0182
0183
0184 static int buffer_prepare(struct vb2_buffer *vb)
0185 {
0186 struct skeleton *skel = vb2_get_drv_priv(vb->vb2_queue);
0187 unsigned long size = skel->format.sizeimage;
0188
0189 if (vb2_plane_size(vb, 0) < size) {
0190 dev_err(&skel->pdev->dev, "buffer too small (%lu < %lu)\n",
0191 vb2_plane_size(vb, 0), size);
0192 return -EINVAL;
0193 }
0194
0195 vb2_set_plane_payload(vb, 0, size);
0196 return 0;
0197 }
0198
0199
0200
0201
0202 static void buffer_queue(struct vb2_buffer *vb)
0203 {
0204 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
0205 struct skeleton *skel = vb2_get_drv_priv(vb->vb2_queue);
0206 struct skel_buffer *buf = to_skel_buffer(vbuf);
0207 unsigned long flags;
0208
0209 spin_lock_irqsave(&skel->qlock, flags);
0210 list_add_tail(&buf->list, &skel->buf_list);
0211
0212
0213
0214 spin_unlock_irqrestore(&skel->qlock, flags);
0215 }
0216
0217 static void return_all_buffers(struct skeleton *skel,
0218 enum vb2_buffer_state state)
0219 {
0220 struct skel_buffer *buf, *node;
0221 unsigned long flags;
0222
0223 spin_lock_irqsave(&skel->qlock, flags);
0224 list_for_each_entry_safe(buf, node, &skel->buf_list, list) {
0225 vb2_buffer_done(&buf->vb.vb2_buf, state);
0226 list_del(&buf->list);
0227 }
0228 spin_unlock_irqrestore(&skel->qlock, flags);
0229 }
0230
0231
0232
0233
0234
0235
0236
0237 static int start_streaming(struct vb2_queue *vq, unsigned int count)
0238 {
0239 struct skeleton *skel = vb2_get_drv_priv(vq);
0240 int ret = 0;
0241
0242 skel->sequence = 0;
0243
0244
0245
0246 if (ret) {
0247
0248
0249
0250
0251 return_all_buffers(skel, VB2_BUF_STATE_QUEUED);
0252 }
0253 return ret;
0254 }
0255
0256
0257
0258
0259
0260 static void stop_streaming(struct vb2_queue *vq)
0261 {
0262 struct skeleton *skel = vb2_get_drv_priv(vq);
0263
0264
0265
0266
0267 return_all_buffers(skel, VB2_BUF_STATE_ERROR);
0268 }
0269
0270
0271
0272
0273
0274
0275 static const struct vb2_ops skel_qops = {
0276 .queue_setup = queue_setup,
0277 .buf_prepare = buffer_prepare,
0278 .buf_queue = buffer_queue,
0279 .start_streaming = start_streaming,
0280 .stop_streaming = stop_streaming,
0281 .wait_prepare = vb2_ops_wait_prepare,
0282 .wait_finish = vb2_ops_wait_finish,
0283 };
0284
0285
0286
0287
0288
0289 static int skeleton_querycap(struct file *file, void *priv,
0290 struct v4l2_capability *cap)
0291 {
0292 struct skeleton *skel = video_drvdata(file);
0293
0294 strlcpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver));
0295 strlcpy(cap->card, "V4L2 PCI Skeleton", sizeof(cap->card));
0296 snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s",
0297 pci_name(skel->pdev));
0298 return 0;
0299 }
0300
0301
0302
0303
0304
0305
0306
0307 static void skeleton_fill_pix_format(struct skeleton *skel,
0308 struct v4l2_pix_format *pix)
0309 {
0310 pix->pixelformat = V4L2_PIX_FMT_YUYV;
0311 if (skel->input == 0) {
0312
0313 pix->width = 720;
0314 pix->height = (skel->std & V4L2_STD_525_60) ? 480 : 576;
0315 pix->field = V4L2_FIELD_INTERLACED;
0316 pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
0317 } else {
0318
0319 pix->width = skel->timings.bt.width;
0320 pix->height = skel->timings.bt.height;
0321 if (skel->timings.bt.interlaced) {
0322 pix->field = V4L2_FIELD_ALTERNATE;
0323 pix->height /= 2;
0324 } else {
0325 pix->field = V4L2_FIELD_NONE;
0326 }
0327 pix->colorspace = V4L2_COLORSPACE_REC709;
0328 }
0329
0330
0331
0332
0333
0334 pix->bytesperline = pix->width * 2;
0335 pix->sizeimage = pix->bytesperline * pix->height;
0336 pix->priv = 0;
0337 }
0338
0339 static int skeleton_try_fmt_vid_cap(struct file *file, void *priv,
0340 struct v4l2_format *f)
0341 {
0342 struct skeleton *skel = video_drvdata(file);
0343 struct v4l2_pix_format *pix = &f->fmt.pix;
0344
0345
0346
0347
0348
0349
0350
0351 if (pix->pixelformat != V4L2_PIX_FMT_YUYV)
0352 return -EINVAL;
0353 skeleton_fill_pix_format(skel, pix);
0354 return 0;
0355 }
0356
0357 static int skeleton_s_fmt_vid_cap(struct file *file, void *priv,
0358 struct v4l2_format *f)
0359 {
0360 struct skeleton *skel = video_drvdata(file);
0361 int ret;
0362
0363 ret = skeleton_try_fmt_vid_cap(file, priv, f);
0364 if (ret)
0365 return ret;
0366
0367
0368
0369
0370
0371 if (vb2_is_busy(&skel->queue))
0372 return -EBUSY;
0373
0374
0375 skel->format = f->fmt.pix;
0376 return 0;
0377 }
0378
0379 static int skeleton_g_fmt_vid_cap(struct file *file, void *priv,
0380 struct v4l2_format *f)
0381 {
0382 struct skeleton *skel = video_drvdata(file);
0383
0384 f->fmt.pix = skel->format;
0385 return 0;
0386 }
0387
0388 static int skeleton_enum_fmt_vid_cap(struct file *file, void *priv,
0389 struct v4l2_fmtdesc *f)
0390 {
0391 if (f->index != 0)
0392 return -EINVAL;
0393
0394 f->pixelformat = V4L2_PIX_FMT_YUYV;
0395 return 0;
0396 }
0397
0398 static int skeleton_s_std(struct file *file, void *priv, v4l2_std_id std)
0399 {
0400 struct skeleton *skel = video_drvdata(file);
0401
0402
0403 if (skel->input)
0404 return -ENODATA;
0405
0406
0407
0408
0409
0410
0411 if (std == skel->std)
0412 return 0;
0413
0414
0415
0416
0417
0418 if (vb2_is_busy(&skel->queue))
0419 return -EBUSY;
0420
0421
0422
0423 skel->std = std;
0424
0425
0426 skeleton_fill_pix_format(skel, &skel->format);
0427 return 0;
0428 }
0429
0430 static int skeleton_g_std(struct file *file, void *priv, v4l2_std_id *std)
0431 {
0432 struct skeleton *skel = video_drvdata(file);
0433
0434
0435 if (skel->input)
0436 return -ENODATA;
0437
0438 *std = skel->std;
0439 return 0;
0440 }
0441
0442
0443
0444
0445
0446
0447
0448
0449 static int skeleton_querystd(struct file *file, void *priv, v4l2_std_id *std)
0450 {
0451 struct skeleton *skel = video_drvdata(file);
0452
0453
0454 if (skel->input)
0455 return -ENODATA;
0456
0457 #ifdef TODO
0458
0459
0460
0461
0462 get_signal_info();
0463 if (no_signal) {
0464 *std = 0;
0465 return 0;
0466 }
0467
0468 if (signal_has_525_lines)
0469 *std &= V4L2_STD_525_60;
0470 else
0471 *std &= V4L2_STD_625_50;
0472 #endif
0473 return 0;
0474 }
0475
0476 static int skeleton_s_dv_timings(struct file *file, void *_fh,
0477 struct v4l2_dv_timings *timings)
0478 {
0479 struct skeleton *skel = video_drvdata(file);
0480
0481
0482 if (skel->input == 0)
0483 return -ENODATA;
0484
0485
0486 if (!v4l2_valid_dv_timings(timings, &skel_timings_cap, NULL, NULL))
0487 return -EINVAL;
0488
0489
0490 if (!v4l2_find_dv_timings_cap(timings, &skel_timings_cap,
0491 0, NULL, NULL))
0492 return -EINVAL;
0493
0494
0495 if (v4l2_match_dv_timings(timings, &skel->timings, 0, false))
0496 return 0;
0497
0498
0499
0500
0501
0502 if (vb2_is_busy(&skel->queue))
0503 return -EBUSY;
0504
0505
0506
0507
0508 skel->timings = *timings;
0509
0510
0511 skeleton_fill_pix_format(skel, &skel->format);
0512 return 0;
0513 }
0514
0515 static int skeleton_g_dv_timings(struct file *file, void *_fh,
0516 struct v4l2_dv_timings *timings)
0517 {
0518 struct skeleton *skel = video_drvdata(file);
0519
0520
0521 if (skel->input == 0)
0522 return -ENODATA;
0523
0524 *timings = skel->timings;
0525 return 0;
0526 }
0527
0528 static int skeleton_enum_dv_timings(struct file *file, void *_fh,
0529 struct v4l2_enum_dv_timings *timings)
0530 {
0531 struct skeleton *skel = video_drvdata(file);
0532
0533
0534 if (skel->input == 0)
0535 return -ENODATA;
0536
0537 return v4l2_enum_dv_timings_cap(timings, &skel_timings_cap,
0538 NULL, NULL);
0539 }
0540
0541
0542
0543
0544
0545
0546
0547
0548
0549
0550 static int skeleton_query_dv_timings(struct file *file, void *_fh,
0551 struct v4l2_dv_timings *timings)
0552 {
0553 struct skeleton *skel = video_drvdata(file);
0554
0555
0556 if (skel->input == 0)
0557 return -ENODATA;
0558
0559 #ifdef TODO
0560
0561
0562
0563
0564 detect_timings();
0565 if (no_signal)
0566 return -ENOLINK;
0567 if (cannot_lock_to_signal)
0568 return -ENOLCK;
0569 if (signal_out_of_range_of_capabilities)
0570 return -ERANGE;
0571
0572
0573 v4l2_print_dv_timings(skel->v4l2_dev.name, "query_dv_timings:",
0574 timings, true);
0575 #endif
0576 return 0;
0577 }
0578
0579 static int skeleton_dv_timings_cap(struct file *file, void *fh,
0580 struct v4l2_dv_timings_cap *cap)
0581 {
0582 struct skeleton *skel = video_drvdata(file);
0583
0584
0585 if (skel->input == 0)
0586 return -ENODATA;
0587 *cap = skel_timings_cap;
0588 return 0;
0589 }
0590
0591 static int skeleton_enum_input(struct file *file, void *priv,
0592 struct v4l2_input *i)
0593 {
0594 if (i->index > 1)
0595 return -EINVAL;
0596
0597 i->type = V4L2_INPUT_TYPE_CAMERA;
0598 if (i->index == 0) {
0599 i->std = SKEL_TVNORMS;
0600 strlcpy(i->name, "S-Video", sizeof(i->name));
0601 i->capabilities = V4L2_IN_CAP_STD;
0602 } else {
0603 i->std = 0;
0604 strlcpy(i->name, "HDMI", sizeof(i->name));
0605 i->capabilities = V4L2_IN_CAP_DV_TIMINGS;
0606 }
0607 return 0;
0608 }
0609
0610 static int skeleton_s_input(struct file *file, void *priv, unsigned int i)
0611 {
0612 struct skeleton *skel = video_drvdata(file);
0613
0614 if (i > 1)
0615 return -EINVAL;
0616
0617
0618
0619
0620
0621 if (vb2_is_busy(&skel->queue))
0622 return -EBUSY;
0623
0624 skel->input = i;
0625
0626
0627
0628
0629
0630 skel->vdev.tvnorms = i ? 0 : SKEL_TVNORMS;
0631
0632
0633 skeleton_fill_pix_format(skel, &skel->format);
0634 return 0;
0635 }
0636
0637 static int skeleton_g_input(struct file *file, void *priv, unsigned int *i)
0638 {
0639 struct skeleton *skel = video_drvdata(file);
0640
0641 *i = skel->input;
0642 return 0;
0643 }
0644
0645
0646 static int skeleton_s_ctrl(struct v4l2_ctrl *ctrl)
0647 {
0648
0649
0650
0651 switch (ctrl->id) {
0652 case V4L2_CID_BRIGHTNESS:
0653
0654 break;
0655 case V4L2_CID_CONTRAST:
0656
0657 break;
0658 case V4L2_CID_SATURATION:
0659
0660 break;
0661 case V4L2_CID_HUE:
0662
0663 break;
0664 default:
0665 return -EINVAL;
0666 }
0667 return 0;
0668 }
0669
0670
0671
0672
0673
0674 static const struct v4l2_ctrl_ops skel_ctrl_ops = {
0675 .s_ctrl = skeleton_s_ctrl,
0676 };
0677
0678
0679
0680
0681
0682
0683
0684
0685
0686
0687
0688 static const struct v4l2_ioctl_ops skel_ioctl_ops = {
0689 .vidioc_querycap = skeleton_querycap,
0690 .vidioc_try_fmt_vid_cap = skeleton_try_fmt_vid_cap,
0691 .vidioc_s_fmt_vid_cap = skeleton_s_fmt_vid_cap,
0692 .vidioc_g_fmt_vid_cap = skeleton_g_fmt_vid_cap,
0693 .vidioc_enum_fmt_vid_cap = skeleton_enum_fmt_vid_cap,
0694
0695 .vidioc_g_std = skeleton_g_std,
0696 .vidioc_s_std = skeleton_s_std,
0697 .vidioc_querystd = skeleton_querystd,
0698
0699 .vidioc_s_dv_timings = skeleton_s_dv_timings,
0700 .vidioc_g_dv_timings = skeleton_g_dv_timings,
0701 .vidioc_enum_dv_timings = skeleton_enum_dv_timings,
0702 .vidioc_query_dv_timings = skeleton_query_dv_timings,
0703 .vidioc_dv_timings_cap = skeleton_dv_timings_cap,
0704
0705 .vidioc_enum_input = skeleton_enum_input,
0706 .vidioc_g_input = skeleton_g_input,
0707 .vidioc_s_input = skeleton_s_input,
0708
0709 .vidioc_reqbufs = vb2_ioctl_reqbufs,
0710 .vidioc_create_bufs = vb2_ioctl_create_bufs,
0711 .vidioc_querybuf = vb2_ioctl_querybuf,
0712 .vidioc_qbuf = vb2_ioctl_qbuf,
0713 .vidioc_dqbuf = vb2_ioctl_dqbuf,
0714 .vidioc_expbuf = vb2_ioctl_expbuf,
0715 .vidioc_streamon = vb2_ioctl_streamon,
0716 .vidioc_streamoff = vb2_ioctl_streamoff,
0717
0718 .vidioc_log_status = v4l2_ctrl_log_status,
0719 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
0720 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
0721 };
0722
0723
0724
0725
0726
0727 static const struct v4l2_file_operations skel_fops = {
0728 .owner = THIS_MODULE,
0729 .open = v4l2_fh_open,
0730 .release = vb2_fop_release,
0731 .unlocked_ioctl = video_ioctl2,
0732 .read = vb2_fop_read,
0733 .mmap = vb2_fop_mmap,
0734 .poll = vb2_fop_poll,
0735 };
0736
0737
0738
0739
0740
0741
0742 static int skeleton_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
0743 {
0744
0745 static const struct v4l2_dv_timings timings_def =
0746 V4L2_DV_BT_CEA_1280X720P60;
0747 struct skeleton *skel;
0748 struct video_device *vdev;
0749 struct v4l2_ctrl_handler *hdl;
0750 struct vb2_queue *q;
0751 int ret;
0752
0753
0754 ret = pci_enable_device(pdev);
0755 if (ret)
0756 return ret;
0757 ret = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
0758 if (ret) {
0759 dev_err(&pdev->dev, "no suitable DMA available.\n");
0760 goto disable_pci;
0761 }
0762
0763
0764 skel = devm_kzalloc(&pdev->dev, sizeof(struct skeleton), GFP_KERNEL);
0765 if (!skel) {
0766 ret = -ENOMEM;
0767 goto disable_pci;
0768 }
0769
0770
0771 ret = devm_request_irq(&pdev->dev, pdev->irq,
0772 skeleton_irq, 0, KBUILD_MODNAME, skel);
0773 if (ret) {
0774 dev_err(&pdev->dev, "request_irq failed\n");
0775 goto disable_pci;
0776 }
0777 skel->pdev = pdev;
0778
0779
0780 skel->timings = timings_def;
0781 skel->std = V4L2_STD_625_50;
0782 skeleton_fill_pix_format(skel, &skel->format);
0783
0784
0785 ret = v4l2_device_register(&pdev->dev, &skel->v4l2_dev);
0786 if (ret)
0787 goto disable_pci;
0788
0789 mutex_init(&skel->lock);
0790
0791
0792 hdl = &skel->ctrl_handler;
0793 v4l2_ctrl_handler_init(hdl, 4);
0794 v4l2_ctrl_new_std(hdl, &skel_ctrl_ops,
0795 V4L2_CID_BRIGHTNESS, 0, 255, 1, 127);
0796 v4l2_ctrl_new_std(hdl, &skel_ctrl_ops,
0797 V4L2_CID_CONTRAST, 0, 255, 1, 16);
0798 v4l2_ctrl_new_std(hdl, &skel_ctrl_ops,
0799 V4L2_CID_SATURATION, 0, 255, 1, 127);
0800 v4l2_ctrl_new_std(hdl, &skel_ctrl_ops,
0801 V4L2_CID_HUE, -128, 127, 1, 0);
0802 if (hdl->error) {
0803 ret = hdl->error;
0804 goto free_hdl;
0805 }
0806 skel->v4l2_dev.ctrl_handler = hdl;
0807
0808
0809 q = &skel->queue;
0810 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
0811 q->io_modes = VB2_MMAP | VB2_DMABUF | VB2_READ;
0812 q->dev = &pdev->dev;
0813 q->drv_priv = skel;
0814 q->buf_struct_size = sizeof(struct skel_buffer);
0815 q->ops = &skel_qops;
0816 q->mem_ops = &vb2_dma_contig_memops;
0817 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
0818
0819
0820
0821
0822
0823 q->min_buffers_needed = 2;
0824
0825
0826
0827
0828
0829
0830
0831
0832
0833 q->lock = &skel->lock;
0834
0835
0836
0837
0838 q->gfp_flags = GFP_DMA32;
0839 ret = vb2_queue_init(q);
0840 if (ret)
0841 goto free_hdl;
0842
0843 INIT_LIST_HEAD(&skel->buf_list);
0844 spin_lock_init(&skel->qlock);
0845
0846
0847 vdev = &skel->vdev;
0848 strlcpy(vdev->name, KBUILD_MODNAME, sizeof(vdev->name));
0849
0850
0851
0852
0853 vdev->release = video_device_release_empty;
0854 vdev->fops = &skel_fops,
0855 vdev->ioctl_ops = &skel_ioctl_ops,
0856 vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
0857 V4L2_CAP_STREAMING;
0858
0859
0860
0861
0862
0863 vdev->lock = &skel->lock;
0864 vdev->queue = q;
0865 vdev->v4l2_dev = &skel->v4l2_dev;
0866
0867 vdev->tvnorms = SKEL_TVNORMS;
0868 video_set_drvdata(vdev, skel);
0869
0870 ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
0871 if (ret)
0872 goto free_hdl;
0873
0874 dev_info(&pdev->dev, "V4L2 PCI Skeleton Driver loaded\n");
0875 return 0;
0876
0877 free_hdl:
0878 v4l2_ctrl_handler_free(&skel->ctrl_handler);
0879 v4l2_device_unregister(&skel->v4l2_dev);
0880 disable_pci:
0881 pci_disable_device(pdev);
0882 return ret;
0883 }
0884
0885 static void skeleton_remove(struct pci_dev *pdev)
0886 {
0887 struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
0888 struct skeleton *skel = container_of(v4l2_dev, struct skeleton, v4l2_dev);
0889
0890 video_unregister_device(&skel->vdev);
0891 v4l2_ctrl_handler_free(&skel->ctrl_handler);
0892 v4l2_device_unregister(&skel->v4l2_dev);
0893 pci_disable_device(skel->pdev);
0894 }
0895
0896 static struct pci_driver skeleton_driver = {
0897 .name = KBUILD_MODNAME,
0898 .probe = skeleton_probe,
0899 .remove = skeleton_remove,
0900 .id_table = skeleton_pci_tbl,
0901 };
0902
0903 module_pci_driver(skeleton_driver);