5 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
6 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/kernel.h>
24 #include <linux/version.h>
25 #include <linux/videodev.h>
26 #include "pvrusb2-context.h"
27 #include "pvrusb2-hdw.h"
29 #include "pvrusb2-debug.h"
30 #include "pvrusb2-v4l2.h"
31 #include "pvrusb2-ioread.h"
32 #include <linux/videodev2.h>
33 #include <media/v4l2-common.h>
35 /* Mike Isely <isely@pobox.com> 23-Sep-2006 - This function is prototyped
36 * only for V4L1 but is implemented regardless of the V4L1 compatibility
37 * option state. V4L2 has no replacement for this and we need it. For now
38 * copy the prototype here so we can avoid the compiler warning. */
39 extern struct video_device* video_devdata(struct file*);
46 struct pvr2_v4l2_dev {
47 struct pvr2_v4l2 *v4lp;
48 struct video_device *vdev;
49 struct pvr2_context_stream *stream;
50 enum pvr2_config config;
54 struct pvr2_channel channel;
55 struct pvr2_v4l2_dev *dev_info;
56 enum v4l2_priority prio;
57 struct pvr2_ioread *rhp;
59 struct pvr2_v4l2 *vhead;
60 struct pvr2_v4l2_fh *vnext;
61 struct pvr2_v4l2_fh *vprev;
62 wait_queue_head_t wait_data;
67 struct pvr2_channel channel;
68 struct pvr2_v4l2_fh *vfirst;
69 struct pvr2_v4l2_fh *vlast;
71 struct v4l2_prio_state prio;
74 struct pvr2_v4l2_dev video_dev;
77 static int video_nr[PVR_NUM] = {[0 ... PVR_NUM-1] = -1};
78 module_param_array(video_nr, int, NULL, 0444);
79 MODULE_PARM_DESC(video_nr, "Offset for device's minor");
81 static struct v4l2_capability pvr_capability ={
83 .card = "Hauppauge WinTV pvr-usb2",
85 .version = KERNEL_VERSION(0,8,0),
86 .capabilities = (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VBI_CAPTURE |
87 V4L2_CAP_TUNER | V4L2_CAP_AUDIO |
92 static struct v4l2_tuner pvr_v4l2_tuners[]= {
96 .type = V4L2_TUNER_ANALOG_TV,
97 .capability = (V4L2_TUNER_CAP_NORM |
98 V4L2_TUNER_CAP_STEREO |
99 V4L2_TUNER_CAP_LANG1 |
100 V4L2_TUNER_CAP_LANG2),
103 .rxsubchans = V4L2_TUNER_SUB_STEREO,
104 .audmode = V4L2_TUNER_MODE_STEREO,
107 .reserved = {0,0,0,0}
111 static struct v4l2_fmtdesc pvr_fmtdesc [] = {
114 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
115 .flags = V4L2_FMT_FLAG_COMPRESSED,
116 .description = "MPEG1/2",
117 // This should really be V4L2_PIX_FMT_MPEG, but xawtv
118 // breaks when I do that.
119 .pixelformat = 0, // V4L2_PIX_FMT_MPEG,
120 .reserved = { 0, 0, 0, 0 }
124 #define PVR_FORMAT_PIX 0
125 #define PVR_FORMAT_VBI 1
127 static struct v4l2_format pvr_format [] = {
129 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
134 // This should really be V4L2_PIX_FMT_MPEG,
135 // but xawtv breaks when I do that.
136 .pixelformat = 0, // V4L2_PIX_FMT_MPEG,
137 .field = V4L2_FIELD_INTERLACED,
138 .bytesperline = 0, // doesn't make sense
140 //FIXME : Don't know what to put here...
141 .sizeimage = (32*1024),
142 .colorspace = 0, // doesn't make sense here
148 .type = V4L2_BUF_TYPE_VBI_CAPTURE,
151 .sampling_rate = 27000000,
153 .samples_per_line = 1443,
154 .sample_format = V4L2_PIX_FMT_GREY,
167 * This is part of Video 4 Linux API. The procedure handles ioctl() calls.
170 static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
171 unsigned int cmd, void *arg)
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;
179 if (pvrusb2_debug & PVR2_TRACE_V4LIOCTL) {
180 v4l_print_ioctl(pvr2_hdw_get_driver_name(hdw),cmd);
183 if (!pvr2_hdw_dev_ok(hdw)) {
184 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
185 "ioctl failed - bad or no context");
195 case VIDIOC_S_FREQUENCY:
196 ret = v4l2_prio_check(&vp->prio, &fh->prio);
202 case VIDIOC_QUERYCAP:
204 struct v4l2_capability *cap = arg;
206 memcpy(cap, &pvr_capability, sizeof(struct v4l2_capability));
212 case VIDIOC_G_PRIORITY:
214 enum v4l2_priority *p = arg;
216 *p = v4l2_prio_max(&vp->prio);
221 case VIDIOC_S_PRIORITY:
223 enum v4l2_priority *prio = arg;
225 ret = v4l2_prio_change(&vp->prio, &fh->prio, *prio);
231 struct v4l2_standard *vs = (struct v4l2_standard *)arg;
233 ret = pvr2_hdw_get_stdenum_value(hdw,vs,idx+1);
240 ret = pvr2_ctrl_get_value(
241 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_STDCUR),&val);
242 *(v4l2_std_id *)arg = val;
248 ret = pvr2_ctrl_set_value(
249 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_STDCUR),
250 *(v4l2_std_id *)arg);
254 case VIDIOC_ENUMINPUT:
256 struct pvr2_ctrl *cptr;
257 struct v4l2_input *vi = (struct v4l2_input *)arg;
258 struct v4l2_input tmp;
261 cptr = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT);
263 memset(&tmp,0,sizeof(tmp));
264 tmp.index = vi->index;
267 case PVR2_CVAL_INPUT_TV:
268 case PVR2_CVAL_INPUT_RADIO:
269 tmp.type = V4L2_INPUT_TYPE_TUNER;
271 case PVR2_CVAL_INPUT_SVIDEO:
272 case PVR2_CVAL_INPUT_COMPOSITE:
273 tmp.type = V4L2_INPUT_TYPE_CAMERA;
282 pvr2_ctrl_get_valname(cptr,vi->index,
283 tmp.name,sizeof(tmp.name)-1,&cnt);
286 /* Don't bother with audioset, since this driver currently
287 always switches the audio whenever the video is
290 /* Handling std is a tougher problem. It doesn't make
291 sense in cases where a device might be multi-standard.
292 We could just copy out the current value for the
293 standard, but it can change over time. For now just
296 memcpy(vi, &tmp, sizeof(tmp));
304 struct pvr2_ctrl *cptr;
305 struct v4l2_input *vi = (struct v4l2_input *)arg;
307 cptr = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT);
309 ret = pvr2_ctrl_get_value(cptr,&val);
316 struct v4l2_input *vi = (struct v4l2_input *)arg;
317 ret = pvr2_ctrl_set_value(
318 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT),
323 case VIDIOC_ENUMAUDIO:
342 struct v4l2_tuner *vt = (struct v4l2_tuner *)arg;
343 unsigned int status_mask;
345 if (vt->index !=0) break;
347 status_mask = pvr2_hdw_get_signal_status(hdw);
349 memcpy(vt, &pvr_v4l2_tuners[vt->index],
350 sizeof(struct v4l2_tuner));
353 if (status_mask & PVR2_SIGNAL_OK) {
354 if (status_mask & PVR2_SIGNAL_STEREO) {
355 vt->rxsubchans = V4L2_TUNER_SUB_STEREO;
357 vt->rxsubchans = V4L2_TUNER_SUB_MONO;
359 if (status_mask & PVR2_SIGNAL_SAP) {
360 vt->rxsubchans |= (V4L2_TUNER_SUB_LANG1 |
361 V4L2_TUNER_SUB_LANG2);
367 ret = pvr2_ctrl_get_value(
368 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_AUDIOMODE),
376 struct v4l2_tuner *vt=(struct v4l2_tuner *)arg;
381 ret = pvr2_ctrl_set_value(
382 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_AUDIOMODE),
386 case VIDIOC_S_FREQUENCY:
388 const struct v4l2_frequency *vf = (struct v4l2_frequency *)arg;
389 ret = pvr2_ctrl_set_value(
390 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_FREQUENCY),
391 vf->frequency * 62500);
395 case VIDIOC_G_FREQUENCY:
397 struct v4l2_frequency *vf = (struct v4l2_frequency *)arg;
399 ret = pvr2_ctrl_get_value(
400 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_FREQUENCY),
407 case VIDIOC_ENUM_FMT:
409 struct v4l2_fmtdesc *fd = (struct v4l2_fmtdesc *)arg;
411 /* Only one format is supported : mpeg.*/
415 memcpy(fd, pvr_fmtdesc, sizeof(struct v4l2_fmtdesc));
422 struct v4l2_format *vf = (struct v4l2_format *)arg;
425 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
426 memcpy(vf, &pvr_format[PVR_FORMAT_PIX],
427 sizeof(struct v4l2_format));
430 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_HRES),
432 vf->fmt.pix.width = val;
435 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_VRES),
437 vf->fmt.pix.height = val;
440 case V4L2_BUF_TYPE_VBI_CAPTURE:
441 // ????? Still need to figure out to do VBI correctly
454 struct v4l2_format *vf = (struct v4l2_format *)arg;
458 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
460 struct pvr2_ctrl *hcp,*vcp;
461 int h = vf->fmt.pix.height;
462 int w = vf->fmt.pix.width;
463 hcp = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_HRES);
464 vcp = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_VRES);
466 lmin = pvr2_ctrl_get_min(hcp);
467 lmax = pvr2_ctrl_get_max(hcp);
470 } else if (w > lmax) {
473 lmin = pvr2_ctrl_get_min(vcp);
474 lmax = pvr2_ctrl_get_max(vcp);
477 } else if (h > lmax) {
481 memcpy(vf, &pvr_format[PVR_FORMAT_PIX],
482 sizeof(struct v4l2_format));
483 vf->fmt.pix.width = w;
484 vf->fmt.pix.height = h;
486 if (cmd == VIDIOC_S_FMT) {
487 pvr2_ctrl_set_value(hcp,vf->fmt.pix.width);
488 pvr2_ctrl_set_value(vcp,vf->fmt.pix.height);
491 case V4L2_BUF_TYPE_VBI_CAPTURE:
492 // ????? Still need to figure out to do VBI correctly
502 case VIDIOC_STREAMON:
504 ret = pvr2_hdw_set_stream_type(hdw,dev_info->config);
505 if (ret < 0) return ret;
506 ret = pvr2_hdw_set_streaming(hdw,!0);
510 case VIDIOC_STREAMOFF:
512 ret = pvr2_hdw_set_streaming(hdw,0);
516 case VIDIOC_QUERYCTRL:
518 struct pvr2_ctrl *cptr;
519 struct v4l2_queryctrl *vc = (struct v4l2_queryctrl *)arg;
521 if (vc->id & V4L2_CTRL_FLAG_NEXT_CTRL) {
522 cptr = pvr2_hdw_get_ctrl_nextv4l(
523 hdw,(vc->id & ~V4L2_CTRL_FLAG_NEXT_CTRL));
524 if (cptr) vc->id = pvr2_ctrl_get_v4lid(cptr);
526 cptr = pvr2_hdw_get_ctrl_v4l(hdw,vc->id);
529 pvr2_trace(PVR2_TRACE_V4LIOCTL,
530 "QUERYCTRL id=0x%x not implemented here",
536 pvr2_trace(PVR2_TRACE_V4LIOCTL,
537 "QUERYCTRL id=0x%x mapping name=%s (%s)",
538 vc->id,pvr2_ctrl_get_name(cptr),
539 pvr2_ctrl_get_desc(cptr));
540 strlcpy(vc->name,pvr2_ctrl_get_desc(cptr),sizeof(vc->name));
541 vc->flags = pvr2_ctrl_get_v4lflags(cptr);
542 vc->default_value = pvr2_ctrl_get_def(cptr);
543 switch (pvr2_ctrl_get_type(cptr)) {
545 vc->type = V4L2_CTRL_TYPE_MENU;
547 vc->maximum = pvr2_ctrl_get_cnt(cptr) - 1;
551 vc->type = V4L2_CTRL_TYPE_BOOLEAN;
557 vc->type = V4L2_CTRL_TYPE_INTEGER;
558 vc->minimum = pvr2_ctrl_get_min(cptr);
559 vc->maximum = pvr2_ctrl_get_max(cptr);
563 pvr2_trace(PVR2_TRACE_V4LIOCTL,
564 "QUERYCTRL id=0x%x name=%s not mappable",
565 vc->id,pvr2_ctrl_get_name(cptr));
572 case VIDIOC_QUERYMENU:
574 struct v4l2_querymenu *vm = (struct v4l2_querymenu *)arg;
575 unsigned int cnt = 0;
576 ret = pvr2_ctrl_get_valname(pvr2_hdw_get_ctrl_v4l(hdw,vm->id),
578 vm->name,sizeof(vm->name)-1,
586 struct v4l2_control *vc = (struct v4l2_control *)arg;
588 ret = pvr2_ctrl_get_value(pvr2_hdw_get_ctrl_v4l(hdw,vc->id),
596 struct v4l2_control *vc = (struct v4l2_control *)arg;
597 ret = pvr2_ctrl_set_value(pvr2_hdw_get_ctrl_v4l(hdw,vc->id),
602 case VIDIOC_G_EXT_CTRLS:
604 struct v4l2_ext_controls *ctls =
605 (struct v4l2_ext_controls *)arg;
606 struct v4l2_ext_control *ctrl;
609 for (idx = 0; idx < ctls->count; idx++) {
610 ctrl = ctls->controls + idx;
611 ret = pvr2_ctrl_get_value(
612 pvr2_hdw_get_ctrl_v4l(hdw,ctrl->id),&val);
614 ctls->error_idx = idx;
617 /* Ensure that if read as a 64 bit value, the user
618 will still get a hopefully sane value */
625 case VIDIOC_S_EXT_CTRLS:
627 struct v4l2_ext_controls *ctls =
628 (struct v4l2_ext_controls *)arg;
629 struct v4l2_ext_control *ctrl;
631 for (idx = 0; idx < ctls->count; idx++) {
632 ctrl = ctls->controls + idx;
633 ret = pvr2_ctrl_set_value(
634 pvr2_hdw_get_ctrl_v4l(hdw,ctrl->id),
637 ctls->error_idx = idx;
644 case VIDIOC_TRY_EXT_CTRLS:
646 struct v4l2_ext_controls *ctls =
647 (struct v4l2_ext_controls *)arg;
648 struct v4l2_ext_control *ctrl;
649 struct pvr2_ctrl *pctl;
651 /* For the moment just validate that the requested control
653 for (idx = 0; idx < ctls->count; idx++) {
654 ctrl = ctls->controls + idx;
655 pctl = pvr2_hdw_get_ctrl_v4l(hdw,ctrl->id);
658 ctls->error_idx = idx;
665 case VIDIOC_LOG_STATUS:
667 pvr2_hdw_trigger_module_log(hdw);
673 ret = v4l_compat_translate_ioctl(inode,file,cmd,
674 arg,pvr2_v4l2_do_ioctl);
677 pvr2_hdw_commit_ctl(hdw);
680 if (pvrusb2_debug & PVR2_TRACE_V4LIOCTL) {
681 pvr2_trace(PVR2_TRACE_V4LIOCTL,
682 "pvr2_v4l2_do_ioctl failure, ret=%d",ret);
684 if (pvrusb2_debug & PVR2_TRACE_V4LIOCTL) {
685 pvr2_trace(PVR2_TRACE_V4LIOCTL,
686 "pvr2_v4l2_do_ioctl failure, ret=%d"
687 " command was:",ret);
688 v4l_print_ioctl(pvr2_hdw_get_driver_name(hdw),
693 pvr2_trace(PVR2_TRACE_V4LIOCTL,
694 "pvr2_v4l2_do_ioctl complete, ret=%d (0x%x)",
701 static void pvr2_v4l2_dev_destroy(struct pvr2_v4l2_dev *dip)
703 printk(KERN_INFO "pvrusb2: unregistering device video%d [%s]\n",
704 dip->vdev->minor,pvr2_config_get_name(dip->config));
705 video_unregister_device(dip->vdev);
709 static void pvr2_v4l2_destroy_no_lock(struct pvr2_v4l2 *vp)
711 pvr2_hdw_v4l_store_minor_number(vp->channel.mc_head->hdw,-1);
712 pvr2_v4l2_dev_destroy(&vp->video_dev);
714 pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr2_v4l2 id=%p",vp);
715 pvr2_channel_done(&vp->channel);
720 static void pvr2_v4l2_internal_check(struct pvr2_channel *chp)
722 struct pvr2_v4l2 *vp;
723 vp = container_of(chp,struct pvr2_v4l2,channel);
724 if (!vp->channel.mc_head->disconnect_flag) return;
725 if (vp->vfirst) return;
726 pvr2_v4l2_destroy_no_lock(vp);
730 static int pvr2_v4l2_ioctl(struct inode *inode, struct file *file,
731 unsigned int cmd, unsigned long arg)
734 /* Temporary hack : use ivtv api until a v4l2 one is available. */
735 #define IVTV_IOC_G_CODEC 0xFFEE7703
736 #define IVTV_IOC_S_CODEC 0xFFEE7704
737 if (cmd == IVTV_IOC_G_CODEC || cmd == IVTV_IOC_S_CODEC) return 0;
738 return video_usercopy(inode, file, cmd, arg, pvr2_v4l2_do_ioctl);
742 static int pvr2_v4l2_release(struct inode *inode, struct file *file)
744 struct pvr2_v4l2_fh *fhp = file->private_data;
745 struct pvr2_v4l2 *vp = fhp->vhead;
746 struct pvr2_context *mp = fhp->vhead->channel.mc_head;
748 pvr2_trace(PVR2_TRACE_OPEN_CLOSE,"pvr2_v4l2_release");
751 struct pvr2_stream *sp;
752 struct pvr2_hdw *hdw;
753 hdw = fhp->channel.mc_head->hdw;
754 pvr2_hdw_set_streaming(hdw,0);
755 sp = pvr2_ioread_get_stream(fhp->rhp);
756 if (sp) pvr2_stream_set_callback(sp,NULL,NULL);
757 pvr2_ioread_destroy(fhp->rhp);
760 v4l2_prio_close(&vp->prio, &fhp->prio);
761 file->private_data = NULL;
763 pvr2_context_enter(mp); do {
765 fhp->vnext->vprev = fhp->vprev;
767 vp->vlast = fhp->vprev;
770 fhp->vprev->vnext = fhp->vnext;
772 vp->vfirst = fhp->vnext;
777 pvr2_channel_done(&fhp->channel);
778 pvr2_trace(PVR2_TRACE_STRUCT,
779 "Destroying pvr_v4l2_fh id=%p",fhp);
781 if (vp->channel.mc_head->disconnect_flag && !vp->vfirst) {
782 pvr2_v4l2_destroy_no_lock(vp);
784 } while (0); pvr2_context_exit(mp);
789 static int pvr2_v4l2_open(struct inode *inode, struct file *file)
791 struct pvr2_v4l2_dev *dip = NULL; /* Our own context pointer */
792 struct pvr2_v4l2_fh *fhp;
793 struct pvr2_v4l2 *vp;
794 struct pvr2_hdw *hdw;
797 struct video_device *vdev = video_devdata(file);
798 dip = (struct pvr2_v4l2_dev *)video_get_drvdata(vdev);
801 if (!dip) return -ENODEV; /* Should be impossible but I'm paranoid */
804 hdw = vp->channel.hdw;
806 pvr2_trace(PVR2_TRACE_OPEN_CLOSE,"pvr2_v4l2_open");
808 if (!pvr2_hdw_dev_ok(hdw)) {
809 pvr2_trace(PVR2_TRACE_OPEN_CLOSE,
810 "pvr2_v4l2_open: hardware not ready");
814 fhp = kmalloc(sizeof(*fhp),GFP_KERNEL);
818 memset(fhp,0,sizeof(*fhp));
820 init_waitqueue_head(&fhp->wait_data);
823 pvr2_context_enter(vp->channel.mc_head); do {
824 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr_v4l2_fh id=%p",fhp);
825 pvr2_channel_init(&fhp->channel,vp->channel.mc_head);
827 fhp->vprev = vp->vlast;
829 vp->vlast->vnext = fhp;
835 } while (0); pvr2_context_exit(vp->channel.mc_head);
838 file->private_data = fhp;
839 v4l2_prio_open(&vp->prio,&fhp->prio);
841 fhp->fw_mode_flag = pvr2_hdw_cpufw_get_enabled(hdw);
847 static void pvr2_v4l2_notify(struct pvr2_v4l2_fh *fhp)
849 wake_up(&fhp->wait_data);
852 static int pvr2_v4l2_iosetup(struct pvr2_v4l2_fh *fh)
855 struct pvr2_stream *sp;
856 struct pvr2_hdw *hdw;
857 if (fh->rhp) return 0;
859 /* First read() attempt. Try to claim the stream and start
861 if ((ret = pvr2_channel_claim_stream(&fh->channel,
862 fh->dev_info->stream)) != 0) {
863 /* Someone else must already have it */
867 fh->rhp = pvr2_channel_create_mpeg_stream(fh->dev_info->stream);
869 pvr2_channel_claim_stream(&fh->channel,NULL);
873 hdw = fh->channel.mc_head->hdw;
874 sp = fh->dev_info->stream->stream;
875 pvr2_stream_set_callback(sp,(pvr2_stream_callback)pvr2_v4l2_notify,fh);
876 pvr2_hdw_set_stream_type(hdw,fh->dev_info->config);
877 pvr2_hdw_set_streaming(hdw,!0);
878 ret = pvr2_ioread_set_enabled(fh->rhp,!0);
884 static ssize_t pvr2_v4l2_read(struct file *file,
885 char __user *buff, size_t count, loff_t *ppos)
887 struct pvr2_v4l2_fh *fh = file->private_data;
890 if (fh->fw_mode_flag) {
891 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
895 unsigned int offs = *ppos;
897 tbuf = kmalloc(PAGE_SIZE,GFP_KERNEL);
898 if (!tbuf) return -ENOMEM;
902 if (c1 > PAGE_SIZE) c1 = PAGE_SIZE;
903 c2 = pvr2_hdw_cpufw_get(hdw,offs,tbuf,c1);
909 if (copy_to_user(buff,tbuf,c2)) {
924 ret = pvr2_v4l2_iosetup(fh);
931 ret = pvr2_ioread_read(fh->rhp,buff,count);
933 if (ret != -EAGAIN) break;
934 if (file->f_flags & O_NONBLOCK) break;
935 /* Doing blocking I/O. Wait here. */
936 ret = wait_event_interruptible(
938 pvr2_ioread_avail(fh->rhp) >= 0);
946 static unsigned int pvr2_v4l2_poll(struct file *file, poll_table *wait)
948 unsigned int mask = 0;
949 struct pvr2_v4l2_fh *fh = file->private_data;
952 if (fh->fw_mode_flag) {
953 mask |= POLLIN | POLLRDNORM;
958 ret = pvr2_v4l2_iosetup(fh);
959 if (ret) return POLLERR;
962 poll_wait(file,&fh->wait_data,wait);
964 if (pvr2_ioread_avail(fh->rhp) >= 0) {
965 mask |= POLLIN | POLLRDNORM;
972 static struct file_operations vdev_fops = {
973 .owner = THIS_MODULE,
974 .open = pvr2_v4l2_open,
975 .release = pvr2_v4l2_release,
976 .read = pvr2_v4l2_read,
977 .ioctl = pvr2_v4l2_ioctl,
979 .poll = pvr2_v4l2_poll,
983 #define VID_HARDWARE_PVRUSB2 38 /* FIXME : need a good value */
985 static struct video_device vdev_template = {
986 .owner = THIS_MODULE,
987 .type = VID_TYPE_CAPTURE | VID_TYPE_TUNER,
988 .type2 = (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VBI_CAPTURE
989 | V4L2_CAP_TUNER | V4L2_CAP_AUDIO
990 | V4L2_CAP_READWRITE),
991 .hardware = VID_HARDWARE_PVRUSB2,
996 static void pvr2_v4l2_dev_init(struct pvr2_v4l2_dev *dip,
997 struct pvr2_v4l2 *vp,
998 enum pvr2_config cfg)
1008 case pvr2_config_mpeg:
1009 v4l_type = VFL_TYPE_GRABBER;
1010 dip->stream = &vp->channel.mc_head->video_stream;
1012 case pvr2_config_vbi:
1013 v4l_type = VFL_TYPE_VBI;
1015 case pvr2_config_radio:
1016 v4l_type = VFL_TYPE_RADIO;
1019 /* Bail out (this should be impossible) */
1020 err("Failed to set up pvrusb2 v4l dev"
1021 " due to unrecognized config");
1026 err("Failed to set up pvrusb2 v4l dev"
1027 " due to missing stream instance");
1031 dip->vdev = video_device_alloc();
1033 err("Alloc of pvrusb2 v4l video device failed");
1037 memcpy(dip->vdev,&vdev_template,sizeof(vdev_template));
1038 dip->vdev->release = video_device_release;
1039 video_set_drvdata(dip->vdev,dip);
1042 unit_number = pvr2_hdw_get_unit_number(vp->channel.mc_head->hdw);
1043 if ((unit_number >= 0) && (unit_number < PVR_NUM)) {
1044 mindevnum = video_nr[unit_number];
1046 if ((video_register_device(dip->vdev, v4l_type, mindevnum) < 0) &&
1047 (video_register_device(dip->vdev, v4l_type, -1) < 0)) {
1048 err("Failed to register pvrusb2 v4l video device");
1050 printk(KERN_INFO "pvrusb2: registered device video%d [%s]\n",
1051 dip->vdev->minor,pvr2_config_get_name(dip->config));
1055 pvr2_hdw_v4l_store_minor_number(vp->channel.mc_head->hdw,
1060 struct pvr2_v4l2 *pvr2_v4l2_create(struct pvr2_context *mnp)
1062 struct pvr2_v4l2 *vp;
1064 vp = kmalloc(sizeof(*vp),GFP_KERNEL);
1066 memset(vp,0,sizeof(*vp));
1067 pvr2_channel_init(&vp->channel,mnp);
1068 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_v4l2 id=%p",vp);
1070 vp->channel.check_func = pvr2_v4l2_internal_check;
1072 /* register streams */
1073 pvr2_v4l2_dev_init(&vp->video_dev,vp,pvr2_config_mpeg);
1080 Stuff for Emacs to see, in order to encourage consistent editing style:
1081 *** Local Variables: ***
1083 *** fill-column: 75 ***
1084 *** tab-width: 8 ***
1085 *** c-basic-offset: 8 ***