]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/media/pci/sta2x11/sta2x11_vip.c
media: sta2x11: Add video_device and vb2_queue locks
[linux.git] / drivers / media / pci / sta2x11 / sta2x11_vip.c
1 /*
2  * This is the driver for the STA2x11 Video Input Port.
3  *
4  * Copyright (C) 2012       ST Microelectronics
5  *     author: Federico Vaga <federico.vaga@gmail.com>
6  * Copyright (C) 2010       WindRiver Systems, Inc.
7  *     authors: Andreas Kies <andreas.kies@windriver.com>
8  *              Vlad Lungu   <vlad.lungu@windriver.com>
9  *
10  * This program is free software; you can redistribute it and/or modify it
11  * under the terms and conditions of the GNU General Public License,
12  * version 2, as published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
17  * more details.
18  *
19  * You should have received a copy of the GNU General Public License along with
20  * this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
22  *
23  * The full GNU General Public License is included in this distribution in
24  * the file called "COPYING".
25  *
26  */
27
28 #include <linux/types.h>
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/init.h>
32 #include <linux/videodev2.h>
33 #include <linux/kmod.h>
34 #include <linux/pci.h>
35 #include <linux/interrupt.h>
36 #include <linux/io.h>
37 #include <linux/gpio.h>
38 #include <linux/i2c.h>
39 #include <linux/delay.h>
40 #include <media/v4l2-common.h>
41 #include <media/v4l2-device.h>
42 #include <media/v4l2-ctrls.h>
43 #include <media/v4l2-ioctl.h>
44 #include <media/v4l2-fh.h>
45 #include <media/v4l2-event.h>
46 #include <media/videobuf2-dma-contig.h>
47
48 #include "sta2x11_vip.h"
49
50 #define DRV_VERSION "1.3"
51
52 #ifndef PCI_DEVICE_ID_STMICRO_VIP
53 #define PCI_DEVICE_ID_STMICRO_VIP 0xCC0D
54 #endif
55
56 #define MAX_FRAMES 4
57
58 /*Register offsets*/
59 #define DVP_CTL         0x00
60 #define DVP_TFO         0x04
61 #define DVP_TFS         0x08
62 #define DVP_BFO         0x0C
63 #define DVP_BFS         0x10
64 #define DVP_VTP         0x14
65 #define DVP_VBP         0x18
66 #define DVP_VMP         0x1C
67 #define DVP_ITM         0x98
68 #define DVP_ITS         0x9C
69 #define DVP_STA         0xA0
70 #define DVP_HLFLN       0xA8
71 #define DVP_RGB         0xC0
72 #define DVP_PKZ         0xF0
73
74 /*Register fields*/
75 #define DVP_CTL_ENA     0x00000001
76 #define DVP_CTL_RST     0x80000000
77 #define DVP_CTL_DIS     (~0x00040001)
78
79 #define DVP_IT_VSB      0x00000008
80 #define DVP_IT_VST      0x00000010
81 #define DVP_IT_FIFO     0x00000020
82
83 #define DVP_HLFLN_SD    0x00000001
84
85 #define SAVE_COUNT 8
86 #define AUX_COUNT 3
87 #define IRQ_COUNT 1
88
89
90 struct vip_buffer {
91         struct vb2_v4l2_buffer vb;
92         struct list_head        list;
93         dma_addr_t              dma;
94 };
95 static inline struct vip_buffer *to_vip_buffer(struct vb2_v4l2_buffer *vb2)
96 {
97         return container_of(vb2, struct vip_buffer, vb);
98 }
99
100 /**
101  * struct sta2x11_vip - All internal data for one instance of device
102  * @v4l2_dev: device registered in v4l layer
103  * @video_dev: properties of our device
104  * @pdev: PCI device
105  * @adapter: contains I2C adapter information
106  * @register_save_area: All relevant register are saved here during suspend
107  * @decoder: contains information about video DAC
108  * @ctrl_hdl: handler for control framework
109  * @format: pixel format, fixed UYVY
110  * @std: video standard (e.g. PAL/NTSC)
111  * @input: input line for video signal ( 0 or 1 )
112  * @disabled: Device is in power down state
113  * @slock: for excluse acces of registers
114  * @vb_vidq: queue maintained by videobuf2 layer
115  * @buffer_list: list of buffer in use
116  * @sequence: sequence number of acquired buffer
117  * @active: current active buffer
118  * @lock: used in videobuf2 callback
119  * @tcount: Number of top frames
120  * @bcount: Number of bottom frames
121  * @overflow: Number of FIFO overflows
122  * @iomem: hardware base address
123  * @config: I2C and gpio config from platform
124  *
125  * All non-local data is accessed via this structure.
126  */
127 struct sta2x11_vip {
128         struct v4l2_device v4l2_dev;
129         struct video_device video_dev;
130         struct pci_dev *pdev;
131         struct i2c_adapter *adapter;
132         unsigned int register_save_area[IRQ_COUNT + SAVE_COUNT + AUX_COUNT];
133         struct v4l2_subdev *decoder;
134         struct v4l2_ctrl_handler ctrl_hdl;
135
136
137         struct v4l2_pix_format format;
138         v4l2_std_id std;
139         unsigned int input;
140         int disabled;
141         spinlock_t slock;
142
143         struct vb2_queue vb_vidq;
144         struct list_head buffer_list;
145         unsigned int sequence;
146         struct vip_buffer *active; /* current active buffer */
147         spinlock_t lock; /* Used in videobuf2 callback */
148         struct mutex v4l_lock;
149
150         /* Interrupt counters */
151         int tcount, bcount;
152         int overflow;
153
154         void __iomem *iomem;    /* I/O Memory */
155         struct vip_config *config;
156 };
157
158 static const unsigned int registers_to_save[AUX_COUNT] = {
159         DVP_HLFLN, DVP_RGB, DVP_PKZ
160 };
161
162 static struct v4l2_pix_format formats_50[] = {
163         {                       /*PAL interlaced */
164          .width = 720,
165          .height = 576,
166          .pixelformat = V4L2_PIX_FMT_UYVY,
167          .field = V4L2_FIELD_INTERLACED,
168          .bytesperline = 720 * 2,
169          .sizeimage = 720 * 2 * 576,
170          .colorspace = V4L2_COLORSPACE_SMPTE170M},
171         {                       /*PAL top */
172          .width = 720,
173          .height = 288,
174          .pixelformat = V4L2_PIX_FMT_UYVY,
175          .field = V4L2_FIELD_TOP,
176          .bytesperline = 720 * 2,
177          .sizeimage = 720 * 2 * 288,
178          .colorspace = V4L2_COLORSPACE_SMPTE170M},
179         {                       /*PAL bottom */
180          .width = 720,
181          .height = 288,
182          .pixelformat = V4L2_PIX_FMT_UYVY,
183          .field = V4L2_FIELD_BOTTOM,
184          .bytesperline = 720 * 2,
185          .sizeimage = 720 * 2 * 288,
186          .colorspace = V4L2_COLORSPACE_SMPTE170M},
187
188 };
189
190 static struct v4l2_pix_format formats_60[] = {
191         {                       /*NTSC interlaced */
192          .width = 720,
193          .height = 480,
194          .pixelformat = V4L2_PIX_FMT_UYVY,
195          .field = V4L2_FIELD_INTERLACED,
196          .bytesperline = 720 * 2,
197          .sizeimage = 720 * 2 * 480,
198          .colorspace = V4L2_COLORSPACE_SMPTE170M},
199         {                       /*NTSC top */
200          .width = 720,
201          .height = 240,
202          .pixelformat = V4L2_PIX_FMT_UYVY,
203          .field = V4L2_FIELD_TOP,
204          .bytesperline = 720 * 2,
205          .sizeimage = 720 * 2 * 240,
206          .colorspace = V4L2_COLORSPACE_SMPTE170M},
207         {                       /*NTSC bottom */
208          .width = 720,
209          .height = 240,
210          .pixelformat = V4L2_PIX_FMT_UYVY,
211          .field = V4L2_FIELD_BOTTOM,
212          .bytesperline = 720 * 2,
213          .sizeimage = 720 * 2 * 240,
214          .colorspace = V4L2_COLORSPACE_SMPTE170M},
215 };
216
217 /* Write VIP register */
218 static inline void reg_write(struct sta2x11_vip *vip, unsigned int reg, u32 val)
219 {
220         iowrite32((val), (vip->iomem)+(reg));
221 }
222 /* Read VIP register */
223 static inline u32 reg_read(struct sta2x11_vip *vip, unsigned int reg)
224 {
225         return  ioread32((vip->iomem)+(reg));
226 }
227 /* Start DMA acquisition */
228 static void start_dma(struct sta2x11_vip *vip, struct vip_buffer *vip_buf)
229 {
230         unsigned long offset = 0;
231
232         if (vip->format.field == V4L2_FIELD_INTERLACED)
233                 offset = vip->format.width * 2;
234
235         spin_lock_irq(&vip->slock);
236         /* Enable acquisition */
237         reg_write(vip, DVP_CTL, reg_read(vip, DVP_CTL) | DVP_CTL_ENA);
238         /* Set Top and Bottom Field memory address */
239         reg_write(vip, DVP_VTP, (u32)vip_buf->dma);
240         reg_write(vip, DVP_VBP, (u32)vip_buf->dma + offset);
241         spin_unlock_irq(&vip->slock);
242 }
243
244 /* Fetch the next buffer to activate */
245 static void vip_active_buf_next(struct sta2x11_vip *vip)
246 {
247         /* Get the next buffer */
248         spin_lock(&vip->lock);
249         if (list_empty(&vip->buffer_list)) {/* No available buffer */
250                 spin_unlock(&vip->lock);
251                 return;
252         }
253         vip->active = list_first_entry(&vip->buffer_list,
254                                        struct vip_buffer,
255                                        list);
256         /* Reset Top and Bottom counter */
257         vip->tcount = 0;
258         vip->bcount = 0;
259         spin_unlock(&vip->lock);
260         if (vb2_is_streaming(&vip->vb_vidq)) {  /* streaming is on */
261                 start_dma(vip, vip->active);    /* start dma capture */
262         }
263 }
264
265
266 /* Videobuf2 Operations */
267 static int queue_setup(struct vb2_queue *vq,
268                        unsigned int *nbuffers, unsigned int *nplanes,
269                        unsigned int sizes[], struct device *alloc_devs[])
270 {
271         struct sta2x11_vip *vip = vb2_get_drv_priv(vq);
272
273         if (!(*nbuffers) || *nbuffers < MAX_FRAMES)
274                 *nbuffers = MAX_FRAMES;
275
276         *nplanes = 1;
277         sizes[0] = vip->format.sizeimage;
278
279         vip->sequence = 0;
280         vip->active = NULL;
281         vip->tcount = 0;
282         vip->bcount = 0;
283
284         return 0;
285 };
286 static int buffer_init(struct vb2_buffer *vb)
287 {
288         struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
289         struct vip_buffer *vip_buf = to_vip_buffer(vbuf);
290
291         vip_buf->dma = vb2_dma_contig_plane_dma_addr(vb, 0);
292         INIT_LIST_HEAD(&vip_buf->list);
293         return 0;
294 }
295
296 static int buffer_prepare(struct vb2_buffer *vb)
297 {
298         struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
299         struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue);
300         struct vip_buffer *vip_buf = to_vip_buffer(vbuf);
301         unsigned long size;
302
303         size = vip->format.sizeimage;
304         if (vb2_plane_size(vb, 0) < size) {
305                 v4l2_err(&vip->v4l2_dev, "buffer too small (%lu < %lu)\n",
306                          vb2_plane_size(vb, 0), size);
307                 return -EINVAL;
308         }
309
310         vb2_set_plane_payload(&vip_buf->vb.vb2_buf, 0, size);
311
312         return 0;
313 }
314 static void buffer_queue(struct vb2_buffer *vb)
315 {
316         struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
317         struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue);
318         struct vip_buffer *vip_buf = to_vip_buffer(vbuf);
319
320         spin_lock(&vip->lock);
321         list_add_tail(&vip_buf->list, &vip->buffer_list);
322         if (!vip->active) {     /* No active buffer, active the first one */
323                 vip->active = list_first_entry(&vip->buffer_list,
324                                                struct vip_buffer,
325                                                list);
326                 if (vb2_is_streaming(&vip->vb_vidq))    /* streaming is on */
327                         start_dma(vip, vip_buf);        /* start dma capture */
328         }
329         spin_unlock(&vip->lock);
330 }
331 static void buffer_finish(struct vb2_buffer *vb)
332 {
333         struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
334         struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue);
335         struct vip_buffer *vip_buf = to_vip_buffer(vbuf);
336
337         /* Buffer handled, remove it from the list */
338         spin_lock(&vip->lock);
339         list_del_init(&vip_buf->list);
340         spin_unlock(&vip->lock);
341
342         if (vb2_is_streaming(vb->vb2_queue))
343                 vip_active_buf_next(vip);
344 }
345
346 static int start_streaming(struct vb2_queue *vq, unsigned int count)
347 {
348         struct sta2x11_vip *vip = vb2_get_drv_priv(vq);
349
350         spin_lock_irq(&vip->slock);
351         /* Enable interrupt VSYNC Top and Bottom*/
352         reg_write(vip, DVP_ITM, DVP_IT_VSB | DVP_IT_VST);
353         spin_unlock_irq(&vip->slock);
354
355         if (count)
356                 start_dma(vip, vip->active);
357
358         return 0;
359 }
360
361 /* abort streaming and wait for last buffer */
362 static void stop_streaming(struct vb2_queue *vq)
363 {
364         struct sta2x11_vip *vip = vb2_get_drv_priv(vq);
365         struct vip_buffer *vip_buf, *node;
366
367         /* Disable acquisition */
368         reg_write(vip, DVP_CTL, reg_read(vip, DVP_CTL) & ~DVP_CTL_ENA);
369         /* Disable all interrupts */
370         reg_write(vip, DVP_ITM, 0);
371
372         /* Release all active buffers */
373         spin_lock(&vip->lock);
374         list_for_each_entry_safe(vip_buf, node, &vip->buffer_list, list) {
375                 vb2_buffer_done(&vip_buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
376                 list_del(&vip_buf->list);
377         }
378         spin_unlock(&vip->lock);
379 }
380
381 static const struct vb2_ops vip_video_qops = {
382         .queue_setup            = queue_setup,
383         .buf_init               = buffer_init,
384         .buf_prepare            = buffer_prepare,
385         .buf_finish             = buffer_finish,
386         .buf_queue              = buffer_queue,
387         .start_streaming        = start_streaming,
388         .stop_streaming         = stop_streaming,
389         .wait_prepare           = vb2_ops_wait_prepare,
390         .wait_finish            = vb2_ops_wait_finish,
391 };
392
393
394 /* File Operations */
395 static const struct v4l2_file_operations vip_fops = {
396         .owner = THIS_MODULE,
397         .open = v4l2_fh_open,
398         .release = vb2_fop_release,
399         .unlocked_ioctl = video_ioctl2,
400         .read = vb2_fop_read,
401         .mmap = vb2_fop_mmap,
402         .poll = vb2_fop_poll
403 };
404
405
406 /**
407  * vidioc_querycap - return capabilities of device
408  * @file: descriptor of device
409  * @cap: contains return values
410  * @priv: unused
411  *
412  * the capabilities of the device are returned
413  *
414  * return value: 0, no error.
415  */
416 static int vidioc_querycap(struct file *file, void *priv,
417                            struct v4l2_capability *cap)
418 {
419         struct sta2x11_vip *vip = video_drvdata(file);
420
421         strcpy(cap->driver, KBUILD_MODNAME);
422         strcpy(cap->card, KBUILD_MODNAME);
423         snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s",
424                  pci_name(vip->pdev));
425         cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
426                            V4L2_CAP_STREAMING;
427         cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
428
429         return 0;
430 }
431
432 /**
433  * vidioc_s_std - set video standard
434  * @file: descriptor of device
435  * @std: contains standard to be set
436  * @priv: unused
437  *
438  * the video standard is set
439  *
440  * return value: 0, no error.
441  *
442  * -EIO, no input signal detected
443  *
444  * other, returned from video DAC.
445  */
446 static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id std)
447 {
448         struct sta2x11_vip *vip = video_drvdata(file);
449
450         /*
451          * This is here for backwards compatibility only.
452          * The use of V4L2_STD_ALL to trigger a querystd is non-standard.
453          */
454         if (std == V4L2_STD_ALL) {
455                 v4l2_subdev_call(vip->decoder, video, querystd, &std);
456                 if (std == V4L2_STD_UNKNOWN)
457                         return -EIO;
458         }
459
460         if (vip->std != std) {
461                 vip->std = std;
462                 if (V4L2_STD_525_60 & std)
463                         vip->format = formats_60[0];
464                 else
465                         vip->format = formats_50[0];
466         }
467
468         return v4l2_subdev_call(vip->decoder, video, s_std, std);
469 }
470
471 /**
472  * vidioc_g_std - get video standard
473  * @file: descriptor of device
474  * @priv: unused
475  * @std: contains return values
476  *
477  * the current video standard is returned
478  *
479  * return value: 0, no error.
480  */
481 static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *std)
482 {
483         struct sta2x11_vip *vip = video_drvdata(file);
484
485         *std = vip->std;
486         return 0;
487 }
488
489 /**
490  * vidioc_querystd - get possible video standards
491  * @file: descriptor of device
492  * @priv: unused
493  * @std: contains return values
494  *
495  * all possible video standards are returned
496  *
497  * return value: delivered by video DAC routine.
498  */
499 static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *std)
500 {
501         struct sta2x11_vip *vip = video_drvdata(file);
502
503         return v4l2_subdev_call(vip->decoder, video, querystd, std);
504 }
505
506 static int vidioc_enum_input(struct file *file, void *priv,
507                              struct v4l2_input *inp)
508 {
509         if (inp->index > 1)
510                 return -EINVAL;
511
512         inp->type = V4L2_INPUT_TYPE_CAMERA;
513         inp->std = V4L2_STD_ALL;
514         sprintf(inp->name, "Camera %u", inp->index);
515
516         return 0;
517 }
518
519 /**
520  * vidioc_s_input - set input line
521  * @file: descriptor of device
522  * @priv: unused
523  * @i: new input line number
524  *
525  * the current active input line is set
526  *
527  * return value: 0, no error.
528  *
529  * -EINVAL, line number out of range
530  */
531 static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
532 {
533         struct sta2x11_vip *vip = video_drvdata(file);
534         int ret;
535
536         if (i > 1)
537                 return -EINVAL;
538         ret = v4l2_subdev_call(vip->decoder, video, s_routing, i, 0, 0);
539
540         if (!ret)
541                 vip->input = i;
542
543         return 0;
544 }
545
546 /**
547  * vidioc_g_input - return input line
548  * @file: descriptor of device
549  * @priv: unused
550  * @i: returned input line number
551  *
552  * the current active input line is returned
553  *
554  * return value: always 0.
555  */
556 static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
557 {
558         struct sta2x11_vip *vip = video_drvdata(file);
559
560         *i = vip->input;
561         return 0;
562 }
563
564 /**
565  * vidioc_enum_fmt_vid_cap - return video capture format
566  * @file: descriptor of device
567  * @priv: unused
568  * @f: returned format information
569  *
570  * returns name and format of video capture
571  * Only UYVY is supported by hardware.
572  *
573  * return value: always 0.
574  */
575 static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
576                                    struct v4l2_fmtdesc *f)
577 {
578
579         if (f->index != 0)
580                 return -EINVAL;
581
582         strcpy(f->description, "4:2:2, packed, UYVY");
583         f->pixelformat = V4L2_PIX_FMT_UYVY;
584         f->flags = 0;
585         return 0;
586 }
587
588 /**
589  * vidioc_try_fmt_vid_cap - set video capture format
590  * @file: descriptor of device
591  * @priv: unused
592  * @f: new format
593  *
594  * new video format is set which includes width and
595  * field type. width is fixed to 720, no scaling.
596  * Only UYVY is supported by this hardware.
597  * the minimum height is 200, the maximum is 576 (PAL)
598  *
599  * return value: 0, no error
600  *
601  * -EINVAL, pixel or field format not supported
602  *
603  */
604 static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
605                                   struct v4l2_format *f)
606 {
607         struct sta2x11_vip *vip = video_drvdata(file);
608         int interlace_lim;
609
610         if (V4L2_PIX_FMT_UYVY != f->fmt.pix.pixelformat) {
611                 v4l2_warn(&vip->v4l2_dev, "Invalid format, only UYVY supported\n");
612                 return -EINVAL;
613         }
614
615         if (V4L2_STD_525_60 & vip->std)
616                 interlace_lim = 240;
617         else
618                 interlace_lim = 288;
619
620         switch (f->fmt.pix.field) {
621         default:
622         case V4L2_FIELD_ANY:
623                 if (interlace_lim < f->fmt.pix.height)
624                         f->fmt.pix.field = V4L2_FIELD_INTERLACED;
625                 else
626                         f->fmt.pix.field = V4L2_FIELD_BOTTOM;
627                 break;
628         case V4L2_FIELD_TOP:
629         case V4L2_FIELD_BOTTOM:
630                 if (interlace_lim < f->fmt.pix.height)
631                         f->fmt.pix.height = interlace_lim;
632                 break;
633         case V4L2_FIELD_INTERLACED:
634                 break;
635         }
636
637         /* It is the only supported format */
638         f->fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY;
639         f->fmt.pix.height &= ~1;
640         if (2 * interlace_lim < f->fmt.pix.height)
641                 f->fmt.pix.height = 2 * interlace_lim;
642         if (200 > f->fmt.pix.height)
643                 f->fmt.pix.height = 200;
644         f->fmt.pix.width = 720;
645         f->fmt.pix.bytesperline = f->fmt.pix.width * 2;
646         f->fmt.pix.sizeimage = f->fmt.pix.width * 2 * f->fmt.pix.height;
647         f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
648         return 0;
649 }
650
651 /**
652  * vidioc_s_fmt_vid_cap - set current video format parameters
653  * @file: descriptor of device
654  * @priv: unused
655  * @f: returned format information
656  *
657  * set new capture format
658  * return value: 0, no error
659  *
660  * other, delivered by video DAC routine.
661  */
662 static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
663                                 struct v4l2_format *f)
664 {
665         struct sta2x11_vip *vip = video_drvdata(file);
666         unsigned int t_stop, b_stop, pitch;
667         int ret;
668
669         ret = vidioc_try_fmt_vid_cap(file, priv, f);
670         if (ret)
671                 return ret;
672
673         if (vb2_is_busy(&vip->vb_vidq)) {
674                 /* Can't change format during acquisition */
675                 v4l2_err(&vip->v4l2_dev, "device busy\n");
676                 return -EBUSY;
677         }
678         vip->format = f->fmt.pix;
679         switch (vip->format.field) {
680         case V4L2_FIELD_INTERLACED:
681                 t_stop = ((vip->format.height / 2 - 1) << 16) |
682                          (2 * vip->format.width - 1);
683                 b_stop = t_stop;
684                 pitch = 4 * vip->format.width;
685                 break;
686         case V4L2_FIELD_TOP:
687                 t_stop = ((vip->format.height - 1) << 16) |
688                          (2 * vip->format.width - 1);
689                 b_stop = (0 << 16) | (2 * vip->format.width - 1);
690                 pitch = 2 * vip->format.width;
691                 break;
692         case V4L2_FIELD_BOTTOM:
693                 t_stop = (0 << 16) | (2 * vip->format.width - 1);
694                 b_stop = (vip->format.height << 16) |
695                          (2 * vip->format.width - 1);
696                 pitch = 2 * vip->format.width;
697                 break;
698         default:
699                 v4l2_err(&vip->v4l2_dev, "unknown field format\n");
700                 return -EINVAL;
701         }
702
703         spin_lock_irq(&vip->slock);
704         /* Y-X Top Field Offset */
705         reg_write(vip, DVP_TFO, 0);
706         /* Y-X Bottom Field Offset */
707         reg_write(vip, DVP_BFO, 0);
708         /* Y-X Top Field Stop*/
709         reg_write(vip, DVP_TFS, t_stop);
710         /* Y-X Bottom Field Stop */
711         reg_write(vip, DVP_BFS, b_stop);
712         /* Video Memory Pitch */
713         reg_write(vip, DVP_VMP, pitch);
714         spin_unlock_irq(&vip->slock);
715
716         return 0;
717 }
718
719 /**
720  * vidioc_g_fmt_vid_cap - get current video format parameters
721  * @file: descriptor of device
722  * @priv: unused
723  * @f: contains format information
724  *
725  * returns current video format parameters
726  *
727  * return value: 0, always successful
728  */
729 static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
730                                 struct v4l2_format *f)
731 {
732         struct sta2x11_vip *vip = video_drvdata(file);
733
734         f->fmt.pix = vip->format;
735
736         return 0;
737 }
738
739 static const struct v4l2_ioctl_ops vip_ioctl_ops = {
740         .vidioc_querycap = vidioc_querycap,
741         /* FMT handling */
742         .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
743         .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
744         .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
745         .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
746         /* Buffer handlers */
747         .vidioc_create_bufs = vb2_ioctl_create_bufs,
748         .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
749         .vidioc_reqbufs = vb2_ioctl_reqbufs,
750         .vidioc_querybuf = vb2_ioctl_querybuf,
751         .vidioc_qbuf = vb2_ioctl_qbuf,
752         .vidioc_dqbuf = vb2_ioctl_dqbuf,
753         /* Stream on/off */
754         .vidioc_streamon = vb2_ioctl_streamon,
755         .vidioc_streamoff = vb2_ioctl_streamoff,
756         /* Standard handling */
757         .vidioc_g_std = vidioc_g_std,
758         .vidioc_s_std = vidioc_s_std,
759         .vidioc_querystd = vidioc_querystd,
760         /* Input handling */
761         .vidioc_enum_input = vidioc_enum_input,
762         .vidioc_g_input = vidioc_g_input,
763         .vidioc_s_input = vidioc_s_input,
764         /* Log status ioctl */
765         .vidioc_log_status = v4l2_ctrl_log_status,
766         /* Event handling */
767         .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
768         .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
769 };
770
771 static const struct video_device video_dev_template = {
772         .name = KBUILD_MODNAME,
773         .release = video_device_release_empty,
774         .fops = &vip_fops,
775         .ioctl_ops = &vip_ioctl_ops,
776         .tvnorms = V4L2_STD_ALL,
777 };
778
779 /**
780  * vip_irq - interrupt routine
781  * @irq: Number of interrupt ( not used, correct number is assumed )
782  * @vip: local data structure containing all information
783  *
784  * check for both frame interrupts set ( top and bottom ).
785  * check FIFO overflow, but limit number of log messages after open.
786  * signal a complete buffer if done
787  *
788  * return value: IRQ_NONE, interrupt was not generated by VIP
789  *
790  * IRQ_HANDLED, interrupt done.
791  */
792 static irqreturn_t vip_irq(int irq, struct sta2x11_vip *vip)
793 {
794         unsigned int status;
795
796         status = reg_read(vip, DVP_ITS);
797
798         if (!status)            /* No interrupt to handle */
799                 return IRQ_NONE;
800
801         if (status & DVP_IT_FIFO)
802                 if (vip->overflow++ > 5)
803                         pr_info("VIP: fifo overflow\n");
804
805         if ((status & DVP_IT_VST) && (status & DVP_IT_VSB)) {
806                 /* this is bad, we are too slow, hope the condition is gone
807                  * on the next frame */
808                 return IRQ_HANDLED;
809         }
810
811         if (status & DVP_IT_VST)
812                 if ((++vip->tcount) < 2)
813                         return IRQ_HANDLED;
814         if (status & DVP_IT_VSB) {
815                 vip->bcount++;
816                 return IRQ_HANDLED;
817         }
818
819         if (vip->active) { /* Acquisition is over on this buffer */
820                 /* Disable acquisition */
821                 reg_write(vip, DVP_CTL, reg_read(vip, DVP_CTL) & ~DVP_CTL_ENA);
822                 /* Remove the active buffer from the list */
823                 vip->active->vb.vb2_buf.timestamp = ktime_get_ns();
824                 vip->active->vb.sequence = vip->sequence++;
825                 vb2_buffer_done(&vip->active->vb.vb2_buf, VB2_BUF_STATE_DONE);
826         }
827
828         return IRQ_HANDLED;
829 }
830
831 static void sta2x11_vip_init_register(struct sta2x11_vip *vip)
832 {
833         /* Register initialization */
834         spin_lock_irq(&vip->slock);
835         /* Clean interrupt */
836         reg_read(vip, DVP_ITS);
837         /* Enable Half Line per vertical */
838         reg_write(vip, DVP_HLFLN, DVP_HLFLN_SD);
839         /* Reset VIP control */
840         reg_write(vip, DVP_CTL, DVP_CTL_RST);
841         /* Clear VIP control */
842         reg_write(vip, DVP_CTL, 0);
843         spin_unlock_irq(&vip->slock);
844 }
845 static void sta2x11_vip_clear_register(struct sta2x11_vip *vip)
846 {
847         spin_lock_irq(&vip->slock);
848         /* Disable interrupt */
849         reg_write(vip, DVP_ITM, 0);
850         /* Reset VIP Control */
851         reg_write(vip, DVP_CTL, DVP_CTL_RST);
852         /* Clear VIP Control */
853         reg_write(vip, DVP_CTL, 0);
854         /* Clean VIP Interrupt */
855         reg_read(vip, DVP_ITS);
856         spin_unlock_irq(&vip->slock);
857 }
858 static int sta2x11_vip_init_buffer(struct sta2x11_vip *vip)
859 {
860         int err;
861
862         err = dma_set_coherent_mask(&vip->pdev->dev, DMA_BIT_MASK(29));
863         if (err) {
864                 v4l2_err(&vip->v4l2_dev, "Cannot configure coherent mask");
865                 return err;
866         }
867         memset(&vip->vb_vidq, 0, sizeof(struct vb2_queue));
868         vip->vb_vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
869         vip->vb_vidq.io_modes = VB2_MMAP | VB2_READ;
870         vip->vb_vidq.drv_priv = vip;
871         vip->vb_vidq.buf_struct_size = sizeof(struct vip_buffer);
872         vip->vb_vidq.ops = &vip_video_qops;
873         vip->vb_vidq.mem_ops = &vb2_dma_contig_memops;
874         vip->vb_vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
875         vip->vb_vidq.dev = &vip->pdev->dev;
876         vip->vb_vidq.lock = &vip->v4l_lock;
877         err = vb2_queue_init(&vip->vb_vidq);
878         if (err)
879                 return err;
880         INIT_LIST_HEAD(&vip->buffer_list);
881         spin_lock_init(&vip->lock);
882         return 0;
883 }
884
885 static int sta2x11_vip_init_controls(struct sta2x11_vip *vip)
886 {
887         /*
888          * Inititialize an empty control so VIP can inerithing controls
889          * from ADV7180
890          */
891         v4l2_ctrl_handler_init(&vip->ctrl_hdl, 0);
892
893         vip->v4l2_dev.ctrl_handler = &vip->ctrl_hdl;
894         if (vip->ctrl_hdl.error) {
895                 int err = vip->ctrl_hdl.error;
896
897                 v4l2_ctrl_handler_free(&vip->ctrl_hdl);
898                 return err;
899         }
900
901         return 0;
902 }
903
904 /**
905  * vip_gpio_reserve - reserve gpio pin
906  * @dev: device
907  * @pin: GPIO pin number
908  * @dir: direction, input or output
909  * @name: GPIO pin name
910  *
911  */
912 static int vip_gpio_reserve(struct device *dev, int pin, int dir,
913                             const char *name)
914 {
915         int ret = -ENODEV;
916
917         if (!gpio_is_valid(pin))
918                 return ret;
919
920         ret = gpio_request(pin, name);
921         if (ret) {
922                 dev_err(dev, "Failed to allocate pin %d (%s)\n", pin, name);
923                 return ret;
924         }
925
926         ret = gpio_direction_output(pin, dir);
927         if (ret) {
928                 dev_err(dev, "Failed to set direction for pin %d (%s)\n",
929                         pin, name);
930                 gpio_free(pin);
931                 return ret;
932         }
933
934         ret = gpio_export(pin, false);
935         if (ret) {
936                 dev_err(dev, "Failed to export pin %d (%s)\n", pin, name);
937                 gpio_free(pin);
938                 return ret;
939         }
940
941         return 0;
942 }
943
944 /**
945  * vip_gpio_release - release gpio pin
946  * @dev: device
947  * @pin: GPIO pin number
948  * @name: GPIO pin name
949  *
950  */
951 static void vip_gpio_release(struct device *dev, int pin, const char *name)
952 {
953         if (gpio_is_valid(pin)) {
954                 dev_dbg(dev, "releasing pin %d (%s)\n", pin, name);
955                 gpio_unexport(pin);
956                 gpio_free(pin);
957         }
958 }
959
960 /**
961  * sta2x11_vip_init_one - init one instance of video device
962  * @pdev: PCI device
963  * @ent: (not used)
964  *
965  * allocate reset pins for DAC.
966  * Reset video DAC, this is done via reset line.
967  * allocate memory for managing device
968  * request interrupt
969  * map IO region
970  * register device
971  * find and initialize video DAC
972  *
973  * return value: 0, no error
974  *
975  * -ENOMEM, no memory
976  *
977  * -ENODEV, device could not be detected or registered
978  */
979 static int sta2x11_vip_init_one(struct pci_dev *pdev,
980                                 const struct pci_device_id *ent)
981 {
982         int ret;
983         struct sta2x11_vip *vip;
984         struct vip_config *config;
985
986         /* Check if hardware support 26-bit DMA */
987         if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(26))) {
988                 dev_err(&pdev->dev, "26-bit DMA addressing not available\n");
989                 return -EINVAL;
990         }
991         /* Enable PCI */
992         ret = pci_enable_device(pdev);
993         if (ret)
994                 return ret;
995
996         /* Get VIP platform data */
997         config = dev_get_platdata(&pdev->dev);
998         if (!config) {
999                 dev_info(&pdev->dev, "VIP slot disabled\n");
1000                 ret = -EINVAL;
1001                 goto disable;
1002         }
1003
1004         /* Power configuration */
1005         ret = vip_gpio_reserve(&pdev->dev, config->pwr_pin, 0,
1006                                config->pwr_name);
1007         if (ret)
1008                 goto disable;
1009
1010         ret = vip_gpio_reserve(&pdev->dev, config->reset_pin, 0,
1011                                config->reset_name);
1012         if (ret) {
1013                 vip_gpio_release(&pdev->dev, config->pwr_pin,
1014                                  config->pwr_name);
1015                 goto disable;
1016         }
1017
1018         if (gpio_is_valid(config->pwr_pin)) {
1019                 /* Datasheet says 5ms between PWR and RST */
1020                 usleep_range(5000, 25000);
1021                 gpio_direction_output(config->pwr_pin, 1);
1022         }
1023
1024         if (gpio_is_valid(config->reset_pin)) {
1025                 /* Datasheet says 5ms between PWR and RST */
1026                 usleep_range(5000, 25000);
1027                 gpio_direction_output(config->reset_pin, 1);
1028         }
1029         usleep_range(5000, 25000);
1030
1031         /* Allocate a new VIP instance */
1032         vip = kzalloc(sizeof(struct sta2x11_vip), GFP_KERNEL);
1033         if (!vip) {
1034                 ret = -ENOMEM;
1035                 goto release_gpios;
1036         }
1037         vip->pdev = pdev;
1038         vip->std = V4L2_STD_PAL;
1039         vip->format = formats_50[0];
1040         vip->config = config;
1041         mutex_init(&vip->v4l_lock);
1042
1043         ret = sta2x11_vip_init_controls(vip);
1044         if (ret)
1045                 goto free_mem;
1046         ret = v4l2_device_register(&pdev->dev, &vip->v4l2_dev);
1047         if (ret)
1048                 goto free_mem;
1049
1050         dev_dbg(&pdev->dev, "BAR #0 at 0x%lx 0x%lx irq %d\n",
1051                 (unsigned long)pci_resource_start(pdev, 0),
1052                 (unsigned long)pci_resource_len(pdev, 0), pdev->irq);
1053
1054         pci_set_master(pdev);
1055
1056         ret = pci_request_regions(pdev, KBUILD_MODNAME);
1057         if (ret)
1058                 goto unreg;
1059
1060         vip->iomem = pci_iomap(pdev, 0, 0x100);
1061         if (!vip->iomem) {
1062                 ret = -ENOMEM;
1063                 goto release;
1064         }
1065
1066         pci_enable_msi(pdev);
1067
1068         /* Initialize buffer */
1069         ret = sta2x11_vip_init_buffer(vip);
1070         if (ret)
1071                 goto unmap;
1072
1073         spin_lock_init(&vip->slock);
1074
1075         ret = request_irq(pdev->irq,
1076                           (irq_handler_t) vip_irq,
1077                           IRQF_SHARED, KBUILD_MODNAME, vip);
1078         if (ret) {
1079                 dev_err(&pdev->dev, "request_irq failed\n");
1080                 ret = -ENODEV;
1081                 goto release_buf;
1082         }
1083
1084         /* Initialize and register video device */
1085         vip->video_dev = video_dev_template;
1086         vip->video_dev.v4l2_dev = &vip->v4l2_dev;
1087         vip->video_dev.queue = &vip->vb_vidq;
1088         vip->video_dev.lock = &vip->v4l_lock;
1089         video_set_drvdata(&vip->video_dev, vip);
1090
1091         ret = video_register_device(&vip->video_dev, VFL_TYPE_GRABBER, -1);
1092         if (ret)
1093                 goto vrelease;
1094
1095         /* Get ADV7180 subdevice */
1096         vip->adapter = i2c_get_adapter(vip->config->i2c_id);
1097         if (!vip->adapter) {
1098                 ret = -ENODEV;
1099                 dev_err(&pdev->dev, "no I2C adapter found\n");
1100                 goto vunreg;
1101         }
1102
1103         vip->decoder = v4l2_i2c_new_subdev(&vip->v4l2_dev, vip->adapter,
1104                                            "adv7180", vip->config->i2c_addr,
1105                                            NULL);
1106         if (!vip->decoder) {
1107                 ret = -ENODEV;
1108                 dev_err(&pdev->dev, "no decoder found\n");
1109                 goto vunreg;
1110         }
1111
1112         i2c_put_adapter(vip->adapter);
1113         v4l2_subdev_call(vip->decoder, core, init, 0);
1114
1115         sta2x11_vip_init_register(vip);
1116
1117         dev_info(&pdev->dev, "STA2X11 Video Input Port (VIP) loaded\n");
1118         return 0;
1119
1120 vunreg:
1121         video_set_drvdata(&vip->video_dev, NULL);
1122 vrelease:
1123         video_unregister_device(&vip->video_dev);
1124         free_irq(pdev->irq, vip);
1125 release_buf:
1126         pci_disable_msi(pdev);
1127 unmap:
1128         vb2_queue_release(&vip->vb_vidq);
1129         pci_iounmap(pdev, vip->iomem);
1130 release:
1131         pci_release_regions(pdev);
1132 unreg:
1133         v4l2_device_unregister(&vip->v4l2_dev);
1134 free_mem:
1135         kfree(vip);
1136 release_gpios:
1137         vip_gpio_release(&pdev->dev, config->reset_pin, config->reset_name);
1138         vip_gpio_release(&pdev->dev, config->pwr_pin, config->pwr_name);
1139 disable:
1140         /*
1141          * do not call pci_disable_device on sta2x11 because it break all
1142          * other Bus masters on this EP
1143          */
1144         return ret;
1145 }
1146
1147 /**
1148  * sta2x11_vip_remove_one - release device
1149  * @pdev: PCI device
1150  *
1151  * Undo everything done in .._init_one
1152  *
1153  * unregister video device
1154  * free interrupt
1155  * unmap ioadresses
1156  * free memory
1157  * free GPIO pins
1158  */
1159 static void sta2x11_vip_remove_one(struct pci_dev *pdev)
1160 {
1161         struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
1162         struct sta2x11_vip *vip =
1163             container_of(v4l2_dev, struct sta2x11_vip, v4l2_dev);
1164
1165         sta2x11_vip_clear_register(vip);
1166
1167         video_set_drvdata(&vip->video_dev, NULL);
1168         video_unregister_device(&vip->video_dev);
1169         free_irq(pdev->irq, vip);
1170         pci_disable_msi(pdev);
1171         vb2_queue_release(&vip->vb_vidq);
1172         pci_iounmap(pdev, vip->iomem);
1173         pci_release_regions(pdev);
1174
1175         v4l2_device_unregister(&vip->v4l2_dev);
1176
1177         vip_gpio_release(&pdev->dev, vip->config->pwr_pin,
1178                          vip->config->pwr_name);
1179         vip_gpio_release(&pdev->dev, vip->config->reset_pin,
1180                          vip->config->reset_name);
1181
1182         kfree(vip);
1183         /*
1184          * do not call pci_disable_device on sta2x11 because it break all
1185          * other Bus masters on this EP
1186          */
1187 }
1188
1189 #ifdef CONFIG_PM
1190
1191 /**
1192  * sta2x11_vip_suspend - set device into power save mode
1193  * @pdev: PCI device
1194  * @state: new state of device
1195  *
1196  * all relevant registers are saved and an attempt to set a new state is made.
1197  *
1198  * return value: 0 always indicate success,
1199  * even if device could not be disabled. (workaround for hardware problem)
1200  */
1201 static int sta2x11_vip_suspend(struct pci_dev *pdev, pm_message_t state)
1202 {
1203         struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
1204         struct sta2x11_vip *vip =
1205             container_of(v4l2_dev, struct sta2x11_vip, v4l2_dev);
1206         unsigned long flags;
1207         int i;
1208
1209         spin_lock_irqsave(&vip->slock, flags);
1210         vip->register_save_area[0] = reg_read(vip, DVP_CTL);
1211         reg_write(vip, DVP_CTL, vip->register_save_area[0] & DVP_CTL_DIS);
1212         vip->register_save_area[SAVE_COUNT] = reg_read(vip, DVP_ITM);
1213         reg_write(vip, DVP_ITM, 0);
1214         for (i = 1; i < SAVE_COUNT; i++)
1215                 vip->register_save_area[i] = reg_read(vip, 4 * i);
1216         for (i = 0; i < AUX_COUNT; i++)
1217                 vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i] =
1218                     reg_read(vip, registers_to_save[i]);
1219         spin_unlock_irqrestore(&vip->slock, flags);
1220         /* save pci state */
1221         pci_save_state(pdev);
1222         if (pci_set_power_state(pdev, pci_choose_state(pdev, state))) {
1223                 /*
1224                  * do not call pci_disable_device on sta2x11 because it
1225                  * break all other Bus masters on this EP
1226                  */
1227                 vip->disabled = 1;
1228         }
1229
1230         pr_info("VIP: suspend\n");
1231         return 0;
1232 }
1233
1234 /**
1235  * sta2x11_vip_resume - resume device operation
1236  * @pdev : PCI device
1237  *
1238  * re-enable device, set PCI state to powered and restore registers.
1239  * resume normal device operation afterwards.
1240  *
1241  * return value: 0, no error.
1242  *
1243  * other, could not set device to power on state.
1244  */
1245 static int sta2x11_vip_resume(struct pci_dev *pdev)
1246 {
1247         struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
1248         struct sta2x11_vip *vip =
1249             container_of(v4l2_dev, struct sta2x11_vip, v4l2_dev);
1250         unsigned long flags;
1251         int ret, i;
1252
1253         pr_info("VIP: resume\n");
1254         /* restore pci state */
1255         if (vip->disabled) {
1256                 ret = pci_enable_device(pdev);
1257                 if (ret) {
1258                         pr_warn("VIP: Can't enable device.\n");
1259                         return ret;
1260                 }
1261                 vip->disabled = 0;
1262         }
1263         ret = pci_set_power_state(pdev, PCI_D0);
1264         if (ret) {
1265                 /*
1266                  * do not call pci_disable_device on sta2x11 because it
1267                  * break all other Bus masters on this EP
1268                  */
1269                 pr_warn("VIP: Can't enable device.\n");
1270                 vip->disabled = 1;
1271                 return ret;
1272         }
1273
1274         pci_restore_state(pdev);
1275
1276         spin_lock_irqsave(&vip->slock, flags);
1277         for (i = 1; i < SAVE_COUNT; i++)
1278                 reg_write(vip, 4 * i, vip->register_save_area[i]);
1279         for (i = 0; i < AUX_COUNT; i++)
1280                 reg_write(vip, registers_to_save[i],
1281                           vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i]);
1282         reg_write(vip, DVP_CTL, vip->register_save_area[0]);
1283         reg_write(vip, DVP_ITM, vip->register_save_area[SAVE_COUNT]);
1284         spin_unlock_irqrestore(&vip->slock, flags);
1285         return 0;
1286 }
1287
1288 #endif
1289
1290 static const struct pci_device_id sta2x11_vip_pci_tbl[] = {
1291         {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_VIP)},
1292         {0,}
1293 };
1294
1295 static struct pci_driver sta2x11_vip_driver = {
1296         .name = KBUILD_MODNAME,
1297         .probe = sta2x11_vip_init_one,
1298         .remove = sta2x11_vip_remove_one,
1299         .id_table = sta2x11_vip_pci_tbl,
1300 #ifdef CONFIG_PM
1301         .suspend = sta2x11_vip_suspend,
1302         .resume = sta2x11_vip_resume,
1303 #endif
1304 };
1305
1306 static int __init sta2x11_vip_init_module(void)
1307 {
1308         return pci_register_driver(&sta2x11_vip_driver);
1309 }
1310
1311 static void __exit sta2x11_vip_exit_module(void)
1312 {
1313         pci_unregister_driver(&sta2x11_vip_driver);
1314 }
1315
1316 #ifdef MODULE
1317 module_init(sta2x11_vip_init_module);
1318 module_exit(sta2x11_vip_exit_module);
1319 #else
1320 late_initcall_sync(sta2x11_vip_init_module);
1321 #endif
1322
1323 MODULE_DESCRIPTION("STA2X11 Video Input Port driver");
1324 MODULE_AUTHOR("Wind River");
1325 MODULE_LICENSE("GPL v2");
1326 MODULE_SUPPORTED_DEVICE("sta2x11 video input");
1327 MODULE_VERSION(DRV_VERSION);
1328 MODULE_DEVICE_TABLE(pci, sta2x11_vip_pci_tbl);