]> err.no Git - linux-2.6/blob - drivers/media/video/pvrusb2/pvrusb2-v4l2.c
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6
[linux-2.6] / drivers / media / video / pvrusb2 / pvrusb2-v4l2.c
1 /*
2  *
3  *
4  *  Copyright (C) 2005 Mike Isely <isely@pobox.com>
5  *  Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include <linux/kernel.h>
23 #include <linux/version.h>
24 #include "pvrusb2-context.h"
25 #include "pvrusb2-hdw.h"
26 #include "pvrusb2.h"
27 #include "pvrusb2-debug.h"
28 #include "pvrusb2-v4l2.h"
29 #include "pvrusb2-ioread.h"
30 #include <linux/videodev2.h>
31 #include <media/v4l2-dev.h>
32 #include <media/v4l2-common.h>
33
34 struct pvr2_v4l2_dev;
35 struct pvr2_v4l2_fh;
36 struct pvr2_v4l2;
37
38 struct pvr2_v4l2_dev {
39         struct video_device devbase; /* MUST be first! */
40         struct pvr2_v4l2 *v4lp;
41         struct pvr2_context_stream *stream;
42         /* Information about this device: */
43         enum pvr2_config config; /* Expected stream format */
44         int v4l_type; /* V4L defined type for this device node */
45         enum pvr2_v4l_type minor_type; /* pvr2-understood minor device type */
46 };
47
48 struct pvr2_v4l2_fh {
49         struct pvr2_channel channel;
50         struct pvr2_v4l2_dev *dev_info;
51         enum v4l2_priority prio;
52         struct pvr2_ioread *rhp;
53         struct file *file;
54         struct pvr2_v4l2 *vhead;
55         struct pvr2_v4l2_fh *vnext;
56         struct pvr2_v4l2_fh *vprev;
57         wait_queue_head_t wait_data;
58         int fw_mode_flag;
59         /* Map contiguous ordinal value to input id */
60         unsigned char *input_map;
61         unsigned int input_cnt;
62 };
63
64 struct pvr2_v4l2 {
65         struct pvr2_channel channel;
66         struct pvr2_v4l2_fh *vfirst;
67         struct pvr2_v4l2_fh *vlast;
68
69         struct v4l2_prio_state prio;
70
71         /* streams - Note that these must be separately, individually,
72          * allocated pointers.  This is because the v4l core is going to
73          * manage their deletion - separately, individually...  */
74         struct pvr2_v4l2_dev *dev_video;
75         struct pvr2_v4l2_dev *dev_radio;
76 };
77
78 static int video_nr[PVR_NUM] = {[0 ... PVR_NUM-1] = -1};
79 module_param_array(video_nr, int, NULL, 0444);
80 MODULE_PARM_DESC(video_nr, "Offset for device's video dev minor");
81 static int radio_nr[PVR_NUM] = {[0 ... PVR_NUM-1] = -1};
82 module_param_array(radio_nr, int, NULL, 0444);
83 MODULE_PARM_DESC(radio_nr, "Offset for device's radio dev minor");
84 static int vbi_nr[PVR_NUM] = {[0 ... PVR_NUM-1] = -1};
85 module_param_array(vbi_nr, int, NULL, 0444);
86 MODULE_PARM_DESC(vbi_nr, "Offset for device's vbi dev minor");
87
88 static struct v4l2_capability pvr_capability ={
89         .driver         = "pvrusb2",
90         .card           = "Hauppauge WinTV pvr-usb2",
91         .bus_info       = "usb",
92         .version        = KERNEL_VERSION(0,8,0),
93         .capabilities   = (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VBI_CAPTURE |
94                            V4L2_CAP_TUNER | V4L2_CAP_AUDIO | V4L2_CAP_RADIO |
95                            V4L2_CAP_READWRITE),
96         .reserved       = {0,0,0,0}
97 };
98
99 static struct v4l2_fmtdesc pvr_fmtdesc [] = {
100         {
101                 .index          = 0,
102                 .type           = V4L2_BUF_TYPE_VIDEO_CAPTURE,
103                 .flags          = V4L2_FMT_FLAG_COMPRESSED,
104                 .description    = "MPEG1/2",
105                 // This should really be V4L2_PIX_FMT_MPEG, but xawtv
106                 // breaks when I do that.
107                 .pixelformat    = 0, // V4L2_PIX_FMT_MPEG,
108                 .reserved       = { 0, 0, 0, 0 }
109         }
110 };
111
112 #define PVR_FORMAT_PIX  0
113 #define PVR_FORMAT_VBI  1
114
115 static struct v4l2_format pvr_format [] = {
116         [PVR_FORMAT_PIX] = {
117                 .type   = V4L2_BUF_TYPE_VIDEO_CAPTURE,
118                 .fmt    = {
119                         .pix        = {
120                                 .width          = 720,
121                                 .height             = 576,
122                                 // This should really be V4L2_PIX_FMT_MPEG,
123                                 // but xawtv breaks when I do that.
124                                 .pixelformat    = 0, // V4L2_PIX_FMT_MPEG,
125                                 .field          = V4L2_FIELD_INTERLACED,
126                                 .bytesperline   = 0,  // doesn't make sense
127                                                       // here
128                                 //FIXME : Don't know what to put here...
129                                 .sizeimage          = (32*1024),
130                                 .colorspace     = 0, // doesn't make sense here
131                                 .priv           = 0
132                         }
133                 }
134         },
135         [PVR_FORMAT_VBI] = {
136                 .type   = V4L2_BUF_TYPE_VBI_CAPTURE,
137                 .fmt    = {
138                         .vbi        = {
139                                 .sampling_rate = 27000000,
140                                 .offset = 248,
141                                 .samples_per_line = 1443,
142                                 .sample_format = V4L2_PIX_FMT_GREY,
143                                 .start = { 0, 0 },
144                                 .count = { 0, 0 },
145                                 .flags = 0,
146                                 .reserved = { 0, 0 }
147                         }
148                 }
149         }
150 };
151
152
153 static const char *get_v4l_name(int v4l_type)
154 {
155         switch (v4l_type) {
156         case VFL_TYPE_GRABBER: return "video";
157         case VFL_TYPE_RADIO: return "radio";
158         case VFL_TYPE_VBI: return "vbi";
159         default: return "?";
160         }
161 }
162
163
164 /*
165  * pvr_ioctl()
166  *
167  * This is part of Video 4 Linux API. The procedure handles ioctl() calls.
168  *
169  */
170 static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
171                               unsigned int cmd, void *arg)
172 {
173         struct pvr2_v4l2_fh *fh = file->private_data;
174         struct pvr2_v4l2 *vp = fh->vhead;
175         struct pvr2_v4l2_dev *dev_info = fh->dev_info;
176         struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
177         int ret = -EINVAL;
178
179         if (pvrusb2_debug & PVR2_TRACE_V4LIOCTL) {
180                 v4l_print_ioctl(pvr2_hdw_get_driver_name(hdw),cmd);
181         }
182
183         if (!pvr2_hdw_dev_ok(hdw)) {
184                 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
185                            "ioctl failed - bad or no context");
186                 return -EFAULT;
187         }
188
189         /* check priority */
190         switch (cmd) {
191         case VIDIOC_S_CTRL:
192         case VIDIOC_S_STD:
193         case VIDIOC_S_INPUT:
194         case VIDIOC_S_TUNER:
195         case VIDIOC_S_FREQUENCY:
196                 ret = v4l2_prio_check(&vp->prio, &fh->prio);
197                 if (ret)
198                         return ret;
199         }
200
201         switch (cmd) {
202         case VIDIOC_QUERYCAP:
203         {
204                 struct v4l2_capability *cap = arg;
205
206                 memcpy(cap, &pvr_capability, sizeof(struct v4l2_capability));
207                 strlcpy(cap->bus_info,pvr2_hdw_get_bus_info(hdw),
208                         sizeof(cap->bus_info));
209                 strlcpy(cap->card,pvr2_hdw_get_desc(hdw),sizeof(cap->card));
210
211                 ret = 0;
212                 break;
213         }
214
215         case VIDIOC_G_PRIORITY:
216         {
217                 enum v4l2_priority *p = arg;
218
219                 *p = v4l2_prio_max(&vp->prio);
220                 ret = 0;
221                 break;
222         }
223
224         case VIDIOC_S_PRIORITY:
225         {
226                 enum v4l2_priority *prio = arg;
227
228                 ret = v4l2_prio_change(&vp->prio, &fh->prio, *prio);
229                 break;
230         }
231
232         case VIDIOC_ENUMSTD:
233         {
234                 struct v4l2_standard *vs = (struct v4l2_standard *)arg;
235                 int idx = vs->index;
236                 ret = pvr2_hdw_get_stdenum_value(hdw,vs,idx+1);
237                 break;
238         }
239
240         case VIDIOC_G_STD:
241         {
242                 int val = 0;
243                 ret = pvr2_ctrl_get_value(
244                         pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_STDCUR),&val);
245                 *(v4l2_std_id *)arg = val;
246                 break;
247         }
248
249         case VIDIOC_S_STD:
250         {
251                 ret = pvr2_ctrl_set_value(
252                         pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_STDCUR),
253                         *(v4l2_std_id *)arg);
254                 break;
255         }
256
257         case VIDIOC_ENUMINPUT:
258         {
259                 struct pvr2_ctrl *cptr;
260                 struct v4l2_input *vi = (struct v4l2_input *)arg;
261                 struct v4l2_input tmp;
262                 unsigned int cnt;
263                 int val;
264
265                 cptr = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT);
266
267                 memset(&tmp,0,sizeof(tmp));
268                 tmp.index = vi->index;
269                 ret = 0;
270                 if ((vi->index < 0) || (vi->index >= fh->input_cnt)) {
271                         ret = -EINVAL;
272                         break;
273                 }
274                 val = fh->input_map[vi->index];
275                 switch (val) {
276                 case PVR2_CVAL_INPUT_TV:
277                 case PVR2_CVAL_INPUT_DTV:
278                 case PVR2_CVAL_INPUT_RADIO:
279                         tmp.type = V4L2_INPUT_TYPE_TUNER;
280                         break;
281                 case PVR2_CVAL_INPUT_SVIDEO:
282                 case PVR2_CVAL_INPUT_COMPOSITE:
283                         tmp.type = V4L2_INPUT_TYPE_CAMERA;
284                         break;
285                 default:
286                         ret = -EINVAL;
287                         break;
288                 }
289                 if (ret < 0) break;
290
291                 cnt = 0;
292                 pvr2_ctrl_get_valname(cptr,val,
293                                       tmp.name,sizeof(tmp.name)-1,&cnt);
294                 tmp.name[cnt] = 0;
295
296                 /* Don't bother with audioset, since this driver currently
297                    always switches the audio whenever the video is
298                    switched. */
299
300                 /* Handling std is a tougher problem.  It doesn't make
301                    sense in cases where a device might be multi-standard.
302                    We could just copy out the current value for the
303                    standard, but it can change over time.  For now just
304                    leave it zero. */
305
306                 memcpy(vi, &tmp, sizeof(tmp));
307
308                 ret = 0;
309                 break;
310         }
311
312         case VIDIOC_G_INPUT:
313         {
314                 unsigned int idx;
315                 struct pvr2_ctrl *cptr;
316                 struct v4l2_input *vi = (struct v4l2_input *)arg;
317                 int val;
318                 cptr = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT);
319                 val = 0;
320                 ret = pvr2_ctrl_get_value(cptr,&val);
321                 vi->index = 0;
322                 for (idx = 0; idx < fh->input_cnt; idx++) {
323                         if (fh->input_map[idx] == val) {
324                                 vi->index = idx;
325                                 break;
326                         }
327                 }
328                 break;
329         }
330
331         case VIDIOC_S_INPUT:
332         {
333                 struct v4l2_input *vi = (struct v4l2_input *)arg;
334                 if ((vi->index < 0) || (vi->index >= fh->input_cnt)) {
335                         ret = -ERANGE;
336                         break;
337                 }
338                 ret = pvr2_ctrl_set_value(
339                         pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT),
340                         fh->input_map[vi->index]);
341                 break;
342         }
343
344         case VIDIOC_ENUMAUDIO:
345         {
346                 /* pkt: FIXME: We are returning one "fake" input here
347                    which could very well be called "whatever_we_like".
348                    This is for apps that want to see an audio input
349                    just to feel comfortable, as well as to test if
350                    it can do stereo or sth. There is actually no guarantee
351                    that the actual audio input cannot change behind the app's
352                    back, but most applications should not mind that either.
353
354                    Hopefully, mplayer people will work with us on this (this
355                    whole mess is to support mplayer pvr://), or Hans will come
356                    up with a more standard way to say "we have inputs but we
357                    don 't want you to change them independent of video" which
358                    will sort this mess.
359                  */
360                 struct v4l2_audio *vin = arg;
361                 ret = -EINVAL;
362                 if (vin->index > 0) break;
363                 strncpy(vin->name, "PVRUSB2 Audio",14);
364                 vin->capability = V4L2_AUDCAP_STEREO;
365                 ret = 0;
366                 break;
367                 break;
368         }
369
370         case VIDIOC_G_AUDIO:
371         {
372                 /* pkt: FIXME: see above comment (VIDIOC_ENUMAUDIO) */
373                 struct v4l2_audio *vin = arg;
374                 memset(vin,0,sizeof(*vin));
375                 vin->index = 0;
376                 strncpy(vin->name, "PVRUSB2 Audio",14);
377                 vin->capability = V4L2_AUDCAP_STEREO;
378                 ret = 0;
379                 break;
380         }
381
382         case VIDIOC_S_AUDIO:
383         {
384                 ret = -EINVAL;
385                 break;
386         }
387         case VIDIOC_G_TUNER:
388         {
389                 struct v4l2_tuner *vt = (struct v4l2_tuner *)arg;
390
391                 if (vt->index != 0) break; /* Only answer for the 1st tuner */
392
393                 pvr2_hdw_execute_tuner_poll(hdw);
394                 ret = pvr2_hdw_get_tuner_status(hdw,vt);
395                 break;
396         }
397
398         case VIDIOC_S_TUNER:
399         {
400                 struct v4l2_tuner *vt=(struct v4l2_tuner *)arg;
401
402                 if (vt->index != 0)
403                         break;
404
405                 ret = pvr2_ctrl_set_value(
406                         pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_AUDIOMODE),
407                         vt->audmode);
408                 break;
409         }
410
411         case VIDIOC_S_FREQUENCY:
412         {
413                 const struct v4l2_frequency *vf = (struct v4l2_frequency *)arg;
414                 unsigned long fv;
415                 struct v4l2_tuner vt;
416                 int cur_input;
417                 struct pvr2_ctrl *ctrlp;
418                 ret = pvr2_hdw_get_tuner_status(hdw,&vt);
419                 if (ret != 0) break;
420                 ctrlp = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT);
421                 ret = pvr2_ctrl_get_value(ctrlp,&cur_input);
422                 if (ret != 0) break;
423                 if (vf->type == V4L2_TUNER_RADIO) {
424                         if (cur_input != PVR2_CVAL_INPUT_RADIO) {
425                                 pvr2_ctrl_set_value(ctrlp,
426                                                     PVR2_CVAL_INPUT_RADIO);
427                         }
428                 } else {
429                         if (cur_input == PVR2_CVAL_INPUT_RADIO) {
430                                 pvr2_ctrl_set_value(ctrlp,
431                                                     PVR2_CVAL_INPUT_TV);
432                         }
433                 }
434                 fv = vf->frequency;
435                 if (vt.capability & V4L2_TUNER_CAP_LOW) {
436                         fv = (fv * 125) / 2;
437                 } else {
438                         fv = fv * 62500;
439                 }
440                 ret = pvr2_ctrl_set_value(
441                         pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_FREQUENCY),fv);
442                 break;
443         }
444
445         case VIDIOC_G_FREQUENCY:
446         {
447                 struct v4l2_frequency *vf = (struct v4l2_frequency *)arg;
448                 int val = 0;
449                 int cur_input;
450                 struct v4l2_tuner vt;
451                 ret = pvr2_hdw_get_tuner_status(hdw,&vt);
452                 if (ret != 0) break;
453                 ret = pvr2_ctrl_get_value(
454                         pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_FREQUENCY),
455                         &val);
456                 if (ret != 0) break;
457                 pvr2_ctrl_get_value(
458                         pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT),
459                         &cur_input);
460                 if (cur_input == PVR2_CVAL_INPUT_RADIO) {
461                         vf->type = V4L2_TUNER_RADIO;
462                 } else {
463                         vf->type = V4L2_TUNER_ANALOG_TV;
464                 }
465                 if (vt.capability & V4L2_TUNER_CAP_LOW) {
466                         val = (val * 2) / 125;
467                 } else {
468                         val /= 62500;
469                 }
470                 vf->frequency = val;
471                 break;
472         }
473
474         case VIDIOC_ENUM_FMT:
475         {
476                 struct v4l2_fmtdesc *fd = (struct v4l2_fmtdesc *)arg;
477
478                 /* Only one format is supported : mpeg.*/
479                 if (fd->index != 0)
480                         break;
481
482                 memcpy(fd, pvr_fmtdesc, sizeof(struct v4l2_fmtdesc));
483                 ret = 0;
484                 break;
485         }
486
487         case VIDIOC_G_FMT:
488         {
489                 struct v4l2_format *vf = (struct v4l2_format *)arg;
490                 int val;
491                 switch(vf->type) {
492                 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
493                         memcpy(vf, &pvr_format[PVR_FORMAT_PIX],
494                                sizeof(struct v4l2_format));
495                         val = 0;
496                         pvr2_ctrl_get_value(
497                                 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_HRES),
498                                 &val);
499                         vf->fmt.pix.width = val;
500                         val = 0;
501                         pvr2_ctrl_get_value(
502                                 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_VRES),
503                                 &val);
504                         vf->fmt.pix.height = val;
505                         ret = 0;
506                         break;
507                 case V4L2_BUF_TYPE_VBI_CAPTURE:
508                         // ????? Still need to figure out to do VBI correctly
509                         ret = -EINVAL;
510                         break;
511                 default:
512                         ret = -EINVAL;
513                         break;
514                 }
515                 break;
516         }
517
518         case VIDIOC_TRY_FMT:
519         case VIDIOC_S_FMT:
520         {
521                 struct v4l2_format *vf = (struct v4l2_format *)arg;
522
523                 ret = 0;
524                 switch(vf->type) {
525                 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
526                         int lmin,lmax,ldef;
527                         struct pvr2_ctrl *hcp,*vcp;
528                         int h = vf->fmt.pix.height;
529                         int w = vf->fmt.pix.width;
530                         hcp = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_HRES);
531                         vcp = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_VRES);
532
533                         lmin = pvr2_ctrl_get_min(hcp);
534                         lmax = pvr2_ctrl_get_max(hcp);
535                         ldef = pvr2_ctrl_get_def(hcp);
536                         if (w == -1) {
537                                 w = ldef;
538                         } else if (w < lmin) {
539                                 w = lmin;
540                         } else if (w > lmax) {
541                                 w = lmax;
542                         }
543                         lmin = pvr2_ctrl_get_min(vcp);
544                         lmax = pvr2_ctrl_get_max(vcp);
545                         ldef = pvr2_ctrl_get_def(vcp);
546                         if (h == -1) {
547                                 h = ldef;
548                         } else if (h < lmin) {
549                                 h = lmin;
550                         } else if (h > lmax) {
551                                 h = lmax;
552                         }
553
554                         memcpy(vf, &pvr_format[PVR_FORMAT_PIX],
555                                sizeof(struct v4l2_format));
556                         vf->fmt.pix.width = w;
557                         vf->fmt.pix.height = h;
558
559                         if (cmd == VIDIOC_S_FMT) {
560                                 pvr2_ctrl_set_value(hcp,vf->fmt.pix.width);
561                                 pvr2_ctrl_set_value(vcp,vf->fmt.pix.height);
562                         }
563                 } break;
564                 case V4L2_BUF_TYPE_VBI_CAPTURE:
565                         // ????? Still need to figure out to do VBI correctly
566                         ret = -EINVAL;
567                         break;
568                 default:
569                         ret = -EINVAL;
570                         break;
571                 }
572                 break;
573         }
574
575         case VIDIOC_STREAMON:
576         {
577                 if (!fh->dev_info->stream) {
578                         /* No stream defined for this node.  This means
579                            that we're not currently allowed to stream from
580                            this node. */
581                         ret = -EPERM;
582                         break;
583                 }
584                 ret = pvr2_hdw_set_stream_type(hdw,dev_info->config);
585                 if (ret < 0) return ret;
586                 ret = pvr2_hdw_set_streaming(hdw,!0);
587                 break;
588         }
589
590         case VIDIOC_STREAMOFF:
591         {
592                 if (!fh->dev_info->stream) {
593                         /* No stream defined for this node.  This means
594                            that we're not currently allowed to stream from
595                            this node. */
596                         ret = -EPERM;
597                         break;
598                 }
599                 ret = pvr2_hdw_set_streaming(hdw,0);
600                 break;
601         }
602
603         case VIDIOC_QUERYCTRL:
604         {
605                 struct pvr2_ctrl *cptr;
606                 struct v4l2_queryctrl *vc = (struct v4l2_queryctrl *)arg;
607                 ret = 0;
608                 if (vc->id & V4L2_CTRL_FLAG_NEXT_CTRL) {
609                         cptr = pvr2_hdw_get_ctrl_nextv4l(
610                                 hdw,(vc->id & ~V4L2_CTRL_FLAG_NEXT_CTRL));
611                         if (cptr) vc->id = pvr2_ctrl_get_v4lid(cptr);
612                 } else {
613                         cptr = pvr2_hdw_get_ctrl_v4l(hdw,vc->id);
614                 }
615                 if (!cptr) {
616                         pvr2_trace(PVR2_TRACE_V4LIOCTL,
617                                    "QUERYCTRL id=0x%x not implemented here",
618                                    vc->id);
619                         ret = -EINVAL;
620                         break;
621                 }
622
623                 pvr2_trace(PVR2_TRACE_V4LIOCTL,
624                            "QUERYCTRL id=0x%x mapping name=%s (%s)",
625                            vc->id,pvr2_ctrl_get_name(cptr),
626                            pvr2_ctrl_get_desc(cptr));
627                 strlcpy(vc->name,pvr2_ctrl_get_desc(cptr),sizeof(vc->name));
628                 vc->flags = pvr2_ctrl_get_v4lflags(cptr);
629                 vc->default_value = pvr2_ctrl_get_def(cptr);
630                 switch (pvr2_ctrl_get_type(cptr)) {
631                 case pvr2_ctl_enum:
632                         vc->type = V4L2_CTRL_TYPE_MENU;
633                         vc->minimum = 0;
634                         vc->maximum = pvr2_ctrl_get_cnt(cptr) - 1;
635                         vc->step = 1;
636                         break;
637                 case pvr2_ctl_bool:
638                         vc->type = V4L2_CTRL_TYPE_BOOLEAN;
639                         vc->minimum = 0;
640                         vc->maximum = 1;
641                         vc->step = 1;
642                         break;
643                 case pvr2_ctl_int:
644                         vc->type = V4L2_CTRL_TYPE_INTEGER;
645                         vc->minimum = pvr2_ctrl_get_min(cptr);
646                         vc->maximum = pvr2_ctrl_get_max(cptr);
647                         vc->step = 1;
648                         break;
649                 default:
650                         pvr2_trace(PVR2_TRACE_V4LIOCTL,
651                                    "QUERYCTRL id=0x%x name=%s not mappable",
652                                    vc->id,pvr2_ctrl_get_name(cptr));
653                         ret = -EINVAL;
654                         break;
655                 }
656                 break;
657         }
658
659         case VIDIOC_QUERYMENU:
660         {
661                 struct v4l2_querymenu *vm = (struct v4l2_querymenu *)arg;
662                 unsigned int cnt = 0;
663                 ret = pvr2_ctrl_get_valname(pvr2_hdw_get_ctrl_v4l(hdw,vm->id),
664                                             vm->index,
665                                             vm->name,sizeof(vm->name)-1,
666                                             &cnt);
667                 vm->name[cnt] = 0;
668                 break;
669         }
670
671         case VIDIOC_G_CTRL:
672         {
673                 struct v4l2_control *vc = (struct v4l2_control *)arg;
674                 int val = 0;
675                 ret = pvr2_ctrl_get_value(pvr2_hdw_get_ctrl_v4l(hdw,vc->id),
676                                           &val);
677                 vc->value = val;
678                 break;
679         }
680
681         case VIDIOC_S_CTRL:
682         {
683                 struct v4l2_control *vc = (struct v4l2_control *)arg;
684                 ret = pvr2_ctrl_set_value(pvr2_hdw_get_ctrl_v4l(hdw,vc->id),
685                                           vc->value);
686                 break;
687         }
688
689         case VIDIOC_G_EXT_CTRLS:
690         {
691                 struct v4l2_ext_controls *ctls =
692                         (struct v4l2_ext_controls *)arg;
693                 struct v4l2_ext_control *ctrl;
694                 unsigned int idx;
695                 int val;
696                 ret = 0;
697                 for (idx = 0; idx < ctls->count; idx++) {
698                         ctrl = ctls->controls + idx;
699                         ret = pvr2_ctrl_get_value(
700                                 pvr2_hdw_get_ctrl_v4l(hdw,ctrl->id),&val);
701                         if (ret) {
702                                 ctls->error_idx = idx;
703                                 break;
704                         }
705                         /* Ensure that if read as a 64 bit value, the user
706                            will still get a hopefully sane value */
707                         ctrl->value64 = 0;
708                         ctrl->value = val;
709                 }
710                 break;
711         }
712
713         case VIDIOC_S_EXT_CTRLS:
714         {
715                 struct v4l2_ext_controls *ctls =
716                         (struct v4l2_ext_controls *)arg;
717                 struct v4l2_ext_control *ctrl;
718                 unsigned int idx;
719                 ret = 0;
720                 for (idx = 0; idx < ctls->count; idx++) {
721                         ctrl = ctls->controls + idx;
722                         ret = pvr2_ctrl_set_value(
723                                 pvr2_hdw_get_ctrl_v4l(hdw,ctrl->id),
724                                 ctrl->value);
725                         if (ret) {
726                                 ctls->error_idx = idx;
727                                 break;
728                         }
729                 }
730                 break;
731         }
732
733         case VIDIOC_TRY_EXT_CTRLS:
734         {
735                 struct v4l2_ext_controls *ctls =
736                         (struct v4l2_ext_controls *)arg;
737                 struct v4l2_ext_control *ctrl;
738                 struct pvr2_ctrl *pctl;
739                 unsigned int idx;
740                 /* For the moment just validate that the requested control
741                    actually exists. */
742                 ret = 0;
743                 for (idx = 0; idx < ctls->count; idx++) {
744                         ctrl = ctls->controls + idx;
745                         pctl = pvr2_hdw_get_ctrl_v4l(hdw,ctrl->id);
746                         if (!pctl) {
747                                 ret = -EINVAL;
748                                 ctls->error_idx = idx;
749                                 break;
750                         }
751                 }
752                 break;
753         }
754
755         case VIDIOC_LOG_STATUS:
756         {
757                 pvr2_hdw_trigger_module_log(hdw);
758                 ret = 0;
759                 break;
760         }
761 #ifdef CONFIG_VIDEO_ADV_DEBUG
762         case VIDIOC_DBG_S_REGISTER:
763         case VIDIOC_DBG_G_REGISTER:
764         {
765                 u64 val;
766                 struct v4l2_register *req = (struct v4l2_register *)arg;
767                 if (cmd == VIDIOC_DBG_S_REGISTER) val = req->val;
768                 ret = pvr2_hdw_register_access(
769                         hdw,req->match_type,req->match_chip,req->reg,
770                         cmd == VIDIOC_DBG_S_REGISTER,&val);
771                 if (cmd == VIDIOC_DBG_G_REGISTER) req->val = val;
772                 break;
773         }
774 #endif
775
776         default :
777                 ret = v4l_compat_translate_ioctl(inode,file,cmd,
778                                                  arg,pvr2_v4l2_do_ioctl);
779         }
780
781         pvr2_hdw_commit_ctl(hdw);
782
783         if (ret < 0) {
784                 if (pvrusb2_debug & PVR2_TRACE_V4LIOCTL) {
785                         pvr2_trace(PVR2_TRACE_V4LIOCTL,
786                                    "pvr2_v4l2_do_ioctl failure, ret=%d",ret);
787                 } else {
788                         if (pvrusb2_debug & PVR2_TRACE_V4LIOCTL) {
789                                 pvr2_trace(PVR2_TRACE_V4LIOCTL,
790                                            "pvr2_v4l2_do_ioctl failure, ret=%d"
791                                            " command was:",ret);
792                                 v4l_print_ioctl(pvr2_hdw_get_driver_name(hdw),
793                                                 cmd);
794                         }
795                 }
796         } else {
797                 pvr2_trace(PVR2_TRACE_V4LIOCTL,
798                            "pvr2_v4l2_do_ioctl complete, ret=%d (0x%x)",
799                            ret,ret);
800         }
801         return ret;
802 }
803
804
805 static void pvr2_v4l2_dev_destroy(struct pvr2_v4l2_dev *dip)
806 {
807         int minor_id = dip->devbase.minor;
808         struct pvr2_hdw *hdw = dip->v4lp->channel.mc_head->hdw;
809         enum pvr2_config cfg = dip->config;
810         int v4l_type = dip->v4l_type;
811
812         pvr2_hdw_v4l_store_minor_number(hdw,dip->minor_type,-1);
813
814         /* Paranoia */
815         dip->v4lp = NULL;
816         dip->stream = NULL;
817
818         /* Actual deallocation happens later when all internal references
819            are gone. */
820         video_unregister_device(&dip->devbase);
821
822         printk(KERN_INFO "pvrusb2: unregistered device %s%u [%s]\n",
823                get_v4l_name(v4l_type),minor_id & 0x1f,
824                pvr2_config_get_name(cfg));
825
826 }
827
828
829 static void pvr2_v4l2_destroy_no_lock(struct pvr2_v4l2 *vp)
830 {
831         if (vp->dev_video) {
832                 pvr2_v4l2_dev_destroy(vp->dev_video);
833                 vp->dev_video = NULL;
834         }
835         if (vp->dev_radio) {
836                 pvr2_v4l2_dev_destroy(vp->dev_radio);
837                 vp->dev_radio = NULL;
838         }
839
840         pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr2_v4l2 id=%p",vp);
841         pvr2_channel_done(&vp->channel);
842         kfree(vp);
843 }
844
845
846 static void pvr2_video_device_release(struct video_device *vdev)
847 {
848         struct pvr2_v4l2_dev *dev;
849         dev = container_of(vdev,struct pvr2_v4l2_dev,devbase);
850         kfree(dev);
851 }
852
853
854 static void pvr2_v4l2_internal_check(struct pvr2_channel *chp)
855 {
856         struct pvr2_v4l2 *vp;
857         vp = container_of(chp,struct pvr2_v4l2,channel);
858         if (!vp->channel.mc_head->disconnect_flag) return;
859         if (vp->vfirst) return;
860         pvr2_v4l2_destroy_no_lock(vp);
861 }
862
863
864 static int pvr2_v4l2_ioctl(struct inode *inode, struct file *file,
865                            unsigned int cmd, unsigned long arg)
866 {
867
868 /* Temporary hack : use ivtv api until a v4l2 one is available. */
869 #define IVTV_IOC_G_CODEC        0xFFEE7703
870 #define IVTV_IOC_S_CODEC        0xFFEE7704
871         if (cmd == IVTV_IOC_G_CODEC || cmd == IVTV_IOC_S_CODEC) return 0;
872         return video_usercopy(inode, file, cmd, arg, pvr2_v4l2_do_ioctl);
873 }
874
875
876 static int pvr2_v4l2_release(struct inode *inode, struct file *file)
877 {
878         struct pvr2_v4l2_fh *fhp = file->private_data;
879         struct pvr2_v4l2 *vp = fhp->vhead;
880         struct pvr2_hdw *hdw = fhp->channel.mc_head->hdw;
881
882         pvr2_trace(PVR2_TRACE_OPEN_CLOSE,"pvr2_v4l2_release");
883
884         if (fhp->rhp) {
885                 struct pvr2_stream *sp;
886                 pvr2_hdw_set_streaming(hdw,0);
887                 sp = pvr2_ioread_get_stream(fhp->rhp);
888                 if (sp) pvr2_stream_set_callback(sp,NULL,NULL);
889                 pvr2_ioread_destroy(fhp->rhp);
890                 fhp->rhp = NULL;
891         }
892
893         v4l2_prio_close(&vp->prio, &fhp->prio);
894         file->private_data = NULL;
895
896         if (fhp->vnext) {
897                 fhp->vnext->vprev = fhp->vprev;
898         } else {
899                 vp->vlast = fhp->vprev;
900         }
901         if (fhp->vprev) {
902                 fhp->vprev->vnext = fhp->vnext;
903         } else {
904                 vp->vfirst = fhp->vnext;
905         }
906         fhp->vnext = NULL;
907         fhp->vprev = NULL;
908         fhp->vhead = NULL;
909         pvr2_channel_done(&fhp->channel);
910         pvr2_trace(PVR2_TRACE_STRUCT,
911                    "Destroying pvr_v4l2_fh id=%p",fhp);
912         if (fhp->input_map) {
913                 kfree(fhp->input_map);
914                 fhp->input_map = NULL;
915         }
916         kfree(fhp);
917         if (vp->channel.mc_head->disconnect_flag && !vp->vfirst) {
918                 pvr2_v4l2_destroy_no_lock(vp);
919         }
920         return 0;
921 }
922
923
924 static int pvr2_v4l2_open(struct inode *inode, struct file *file)
925 {
926         struct pvr2_v4l2_dev *dip; /* Our own context pointer */
927         struct pvr2_v4l2_fh *fhp;
928         struct pvr2_v4l2 *vp;
929         struct pvr2_hdw *hdw;
930         unsigned int input_mask = 0;
931         unsigned int input_cnt,idx;
932         int ret = 0;
933
934         dip = container_of(video_devdata(file),struct pvr2_v4l2_dev,devbase);
935
936         vp = dip->v4lp;
937         hdw = vp->channel.hdw;
938
939         pvr2_trace(PVR2_TRACE_OPEN_CLOSE,"pvr2_v4l2_open");
940
941         if (!pvr2_hdw_dev_ok(hdw)) {
942                 pvr2_trace(PVR2_TRACE_OPEN_CLOSE,
943                            "pvr2_v4l2_open: hardware not ready");
944                 return -EIO;
945         }
946
947         fhp = kzalloc(sizeof(*fhp),GFP_KERNEL);
948         if (!fhp) {
949                 return -ENOMEM;
950         }
951
952         init_waitqueue_head(&fhp->wait_data);
953         fhp->dev_info = dip;
954
955         pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr_v4l2_fh id=%p",fhp);
956         pvr2_channel_init(&fhp->channel,vp->channel.mc_head);
957
958         if (dip->v4l_type == VFL_TYPE_RADIO) {
959                 /* Opening device as a radio, legal input selection subset
960                    is just the radio. */
961                 input_mask = (1 << PVR2_CVAL_INPUT_RADIO);
962         } else {
963                 /* Opening the main V4L device, legal input selection
964                    subset includes all analog inputs. */
965                 input_mask = ((1 << PVR2_CVAL_INPUT_RADIO) |
966                               (1 << PVR2_CVAL_INPUT_TV) |
967                               (1 << PVR2_CVAL_INPUT_COMPOSITE) |
968                               (1 << PVR2_CVAL_INPUT_SVIDEO));
969         }
970         ret = pvr2_channel_limit_inputs(&fhp->channel,input_mask);
971         if (ret) {
972                 pvr2_channel_done(&fhp->channel);
973                 pvr2_trace(PVR2_TRACE_STRUCT,
974                            "Destroying pvr_v4l2_fh id=%p (input mask error)",
975                            fhp);
976
977                 kfree(fhp);
978                 return ret;
979         }
980
981         input_mask &= pvr2_hdw_get_input_available(hdw);
982         input_cnt = 0;
983         for (idx = 0; idx < (sizeof(input_mask) << 3); idx++) {
984                 if (input_mask & (1 << idx)) input_cnt++;
985         }
986         fhp->input_cnt = input_cnt;
987         fhp->input_map = kzalloc(input_cnt,GFP_KERNEL);
988         if (!fhp->input_map) {
989                 pvr2_channel_done(&fhp->channel);
990                 pvr2_trace(PVR2_TRACE_STRUCT,
991                            "Destroying pvr_v4l2_fh id=%p (input map failure)",
992                            fhp);
993                 kfree(fhp);
994                 return -ENOMEM;
995         }
996         input_cnt = 0;
997         for (idx = 0; idx < (sizeof(input_mask) << 3); idx++) {
998                 if (!(input_mask & (1 << idx))) continue;
999                 fhp->input_map[input_cnt++] = idx;
1000         }
1001
1002         fhp->vnext = NULL;
1003         fhp->vprev = vp->vlast;
1004         if (vp->vlast) {
1005                 vp->vlast->vnext = fhp;
1006         } else {
1007                 vp->vfirst = fhp;
1008         }
1009         vp->vlast = fhp;
1010         fhp->vhead = vp;
1011
1012         fhp->file = file;
1013         file->private_data = fhp;
1014         v4l2_prio_open(&vp->prio,&fhp->prio);
1015
1016         fhp->fw_mode_flag = pvr2_hdw_cpufw_get_enabled(hdw);
1017
1018         return 0;
1019 }
1020
1021
1022 static void pvr2_v4l2_notify(struct pvr2_v4l2_fh *fhp)
1023 {
1024         wake_up(&fhp->wait_data);
1025 }
1026
1027 static int pvr2_v4l2_iosetup(struct pvr2_v4l2_fh *fh)
1028 {
1029         int ret;
1030         struct pvr2_stream *sp;
1031         struct pvr2_hdw *hdw;
1032         if (fh->rhp) return 0;
1033
1034         if (!fh->dev_info->stream) {
1035                 /* No stream defined for this node.  This means that we're
1036                    not currently allowed to stream from this node. */
1037                 return -EPERM;
1038         }
1039
1040         /* First read() attempt.  Try to claim the stream and start
1041            it... */
1042         if ((ret = pvr2_channel_claim_stream(&fh->channel,
1043                                              fh->dev_info->stream)) != 0) {
1044                 /* Someone else must already have it */
1045                 return ret;
1046         }
1047
1048         fh->rhp = pvr2_channel_create_mpeg_stream(fh->dev_info->stream);
1049         if (!fh->rhp) {
1050                 pvr2_channel_claim_stream(&fh->channel,NULL);
1051                 return -ENOMEM;
1052         }
1053
1054         hdw = fh->channel.mc_head->hdw;
1055         sp = fh->dev_info->stream->stream;
1056         pvr2_stream_set_callback(sp,(pvr2_stream_callback)pvr2_v4l2_notify,fh);
1057         pvr2_hdw_set_stream_type(hdw,fh->dev_info->config);
1058         if ((ret = pvr2_hdw_set_streaming(hdw,!0)) < 0) return ret;
1059         return pvr2_ioread_set_enabled(fh->rhp,!0);
1060 }
1061
1062
1063 static ssize_t pvr2_v4l2_read(struct file *file,
1064                               char __user *buff, size_t count, loff_t *ppos)
1065 {
1066         struct pvr2_v4l2_fh *fh = file->private_data;
1067         int ret;
1068
1069         if (fh->fw_mode_flag) {
1070                 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
1071                 char *tbuf;
1072                 int c1,c2;
1073                 int tcnt = 0;
1074                 unsigned int offs = *ppos;
1075
1076                 tbuf = kmalloc(PAGE_SIZE,GFP_KERNEL);
1077                 if (!tbuf) return -ENOMEM;
1078
1079                 while (count) {
1080                         c1 = count;
1081                         if (c1 > PAGE_SIZE) c1 = PAGE_SIZE;
1082                         c2 = pvr2_hdw_cpufw_get(hdw,offs,tbuf,c1);
1083                         if (c2 < 0) {
1084                                 tcnt = c2;
1085                                 break;
1086                         }
1087                         if (!c2) break;
1088                         if (copy_to_user(buff,tbuf,c2)) {
1089                                 tcnt = -EFAULT;
1090                                 break;
1091                         }
1092                         offs += c2;
1093                         tcnt += c2;
1094                         buff += c2;
1095                         count -= c2;
1096                         *ppos += c2;
1097                 }
1098                 kfree(tbuf);
1099                 return tcnt;
1100         }
1101
1102         if (!fh->rhp) {
1103                 ret = pvr2_v4l2_iosetup(fh);
1104                 if (ret) {
1105                         return ret;
1106                 }
1107         }
1108
1109         for (;;) {
1110                 ret = pvr2_ioread_read(fh->rhp,buff,count);
1111                 if (ret >= 0) break;
1112                 if (ret != -EAGAIN) break;
1113                 if (file->f_flags & O_NONBLOCK) break;
1114                 /* Doing blocking I/O.  Wait here. */
1115                 ret = wait_event_interruptible(
1116                         fh->wait_data,
1117                         pvr2_ioread_avail(fh->rhp) >= 0);
1118                 if (ret < 0) break;
1119         }
1120
1121         return ret;
1122 }
1123
1124
1125 static unsigned int pvr2_v4l2_poll(struct file *file, poll_table *wait)
1126 {
1127         unsigned int mask = 0;
1128         struct pvr2_v4l2_fh *fh = file->private_data;
1129         int ret;
1130
1131         if (fh->fw_mode_flag) {
1132                 mask |= POLLIN | POLLRDNORM;
1133                 return mask;
1134         }
1135
1136         if (!fh->rhp) {
1137                 ret = pvr2_v4l2_iosetup(fh);
1138                 if (ret) return POLLERR;
1139         }
1140
1141         poll_wait(file,&fh->wait_data,wait);
1142
1143         if (pvr2_ioread_avail(fh->rhp) >= 0) {
1144                 mask |= POLLIN | POLLRDNORM;
1145         }
1146
1147         return mask;
1148 }
1149
1150
1151 static const struct file_operations vdev_fops = {
1152         .owner      = THIS_MODULE,
1153         .open       = pvr2_v4l2_open,
1154         .release    = pvr2_v4l2_release,
1155         .read       = pvr2_v4l2_read,
1156         .ioctl      = pvr2_v4l2_ioctl,
1157         .llseek     = no_llseek,
1158         .poll       = pvr2_v4l2_poll,
1159 };
1160
1161
1162 static struct video_device vdev_template = {
1163         .owner      = THIS_MODULE,
1164         .type       = VID_TYPE_CAPTURE | VID_TYPE_TUNER,
1165         .type2      = (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VBI_CAPTURE
1166                        | V4L2_CAP_TUNER | V4L2_CAP_AUDIO
1167                        | V4L2_CAP_READWRITE),
1168         .fops       = &vdev_fops,
1169 };
1170
1171
1172 static void pvr2_v4l2_dev_init(struct pvr2_v4l2_dev *dip,
1173                                struct pvr2_v4l2 *vp,
1174                                int v4l_type)
1175 {
1176         int mindevnum;
1177         int unit_number;
1178         int *nr_ptr = NULL;
1179         dip->v4lp = vp;
1180
1181
1182         dip->v4l_type = v4l_type;
1183         switch (v4l_type) {
1184         case VFL_TYPE_GRABBER:
1185                 dip->stream = &vp->channel.mc_head->video_stream;
1186                 dip->config = pvr2_config_mpeg;
1187                 dip->minor_type = pvr2_v4l_type_video;
1188                 nr_ptr = video_nr;
1189                 if (!dip->stream) {
1190                         err("Failed to set up pvrusb2 v4l video dev"
1191                             " due to missing stream instance");
1192                         return;
1193                 }
1194                 break;
1195         case VFL_TYPE_VBI:
1196                 dip->config = pvr2_config_vbi;
1197                 dip->minor_type = pvr2_v4l_type_vbi;
1198                 nr_ptr = vbi_nr;
1199                 break;
1200         case VFL_TYPE_RADIO:
1201                 dip->stream = &vp->channel.mc_head->video_stream;
1202                 dip->config = pvr2_config_mpeg;
1203                 dip->minor_type = pvr2_v4l_type_radio;
1204                 nr_ptr = radio_nr;
1205                 break;
1206         default:
1207                 /* Bail out (this should be impossible) */
1208                 err("Failed to set up pvrusb2 v4l dev"
1209                     " due to unrecognized config");
1210                 return;
1211         }
1212
1213         memcpy(&dip->devbase,&vdev_template,sizeof(vdev_template));
1214         dip->devbase.release = pvr2_video_device_release;
1215
1216         mindevnum = -1;
1217         unit_number = pvr2_hdw_get_unit_number(vp->channel.mc_head->hdw);
1218         if (nr_ptr && (unit_number >= 0) && (unit_number < PVR_NUM)) {
1219                 mindevnum = nr_ptr[unit_number];
1220         }
1221         if ((video_register_device(&dip->devbase,
1222                                    dip->v4l_type, mindevnum) < 0) &&
1223             (video_register_device(&dip->devbase,
1224                                    dip->v4l_type, -1) < 0)) {
1225                 err("Failed to register pvrusb2 v4l device");
1226         }
1227
1228         printk(KERN_INFO "pvrusb2: registered device %s%u [%s]\n",
1229                get_v4l_name(dip->v4l_type),dip->devbase.minor & 0x1f,
1230                pvr2_config_get_name(dip->config));
1231
1232         pvr2_hdw_v4l_store_minor_number(vp->channel.mc_head->hdw,
1233                                         dip->minor_type,dip->devbase.minor);
1234 }
1235
1236
1237 struct pvr2_v4l2 *pvr2_v4l2_create(struct pvr2_context *mnp)
1238 {
1239         struct pvr2_v4l2 *vp;
1240
1241         vp = kzalloc(sizeof(*vp),GFP_KERNEL);
1242         if (!vp) return vp;
1243         pvr2_channel_init(&vp->channel,mnp);
1244         pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_v4l2 id=%p",vp);
1245
1246         vp->channel.check_func = pvr2_v4l2_internal_check;
1247
1248         /* register streams */
1249         vp->dev_video = kzalloc(sizeof(*vp->dev_video),GFP_KERNEL);
1250         if (!vp->dev_video) goto fail;
1251         pvr2_v4l2_dev_init(vp->dev_video,vp,VFL_TYPE_GRABBER);
1252         if (pvr2_hdw_get_input_available(vp->channel.mc_head->hdw) &
1253             (1 << PVR2_CVAL_INPUT_RADIO)) {
1254                 vp->dev_radio = kzalloc(sizeof(*vp->dev_radio),GFP_KERNEL);
1255                 if (!vp->dev_radio) goto fail;
1256                 pvr2_v4l2_dev_init(vp->dev_radio,vp,VFL_TYPE_RADIO);
1257         }
1258
1259         return vp;
1260  fail:
1261         pvr2_trace(PVR2_TRACE_STRUCT,"Failure creating pvr2_v4l2 id=%p",vp);
1262         pvr2_v4l2_destroy_no_lock(vp);
1263         return NULL;
1264 }
1265
1266 /*
1267   Stuff for Emacs to see, in order to encourage consistent editing style:
1268   *** Local Variables: ***
1269   *** mode: c ***
1270   *** fill-column: 75 ***
1271   *** tab-width: 8 ***
1272   *** c-basic-offset: 8 ***
1273   *** End: ***
1274   */