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 "pvrusb2-context.h"
26 #include "pvrusb2-hdw.h"
28 #include "pvrusb2-debug.h"
29 #include "pvrusb2-v4l2.h"
30 #include "pvrusb2-ioread.h"
31 #include <linux/videodev2.h>
32 #include <media/v4l2-dev.h>
33 #include <media/v4l2-common.h>
39 struct pvr2_v4l2_dev {
40 struct video_device devbase; /* MUST be first! */
41 struct pvr2_v4l2 *v4lp;
42 struct pvr2_context_stream *stream;
43 enum pvr2_config config;
47 struct pvr2_channel channel;
48 struct pvr2_v4l2_dev *dev_info;
49 enum v4l2_priority prio;
50 struct pvr2_ioread *rhp;
52 struct pvr2_v4l2 *vhead;
53 struct pvr2_v4l2_fh *vnext;
54 struct pvr2_v4l2_fh *vprev;
55 wait_queue_head_t wait_data;
60 struct pvr2_channel channel;
61 struct pvr2_v4l2_fh *vfirst;
62 struct pvr2_v4l2_fh *vlast;
64 struct v4l2_prio_state prio;
67 struct pvr2_v4l2_dev *vdev;
70 static int video_nr[PVR_NUM] = {[0 ... PVR_NUM-1] = -1};
71 module_param_array(video_nr, int, NULL, 0444);
72 MODULE_PARM_DESC(video_nr, "Offset for device's minor");
74 static struct v4l2_capability pvr_capability ={
76 .card = "Hauppauge WinTV pvr-usb2",
78 .version = KERNEL_VERSION(0,8,0),
79 .capabilities = (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VBI_CAPTURE |
80 V4L2_CAP_TUNER | V4L2_CAP_AUDIO |
85 static struct v4l2_tuner pvr_v4l2_tuners[]= {
89 .type = V4L2_TUNER_ANALOG_TV,
90 .capability = (V4L2_TUNER_CAP_NORM |
91 V4L2_TUNER_CAP_STEREO |
92 V4L2_TUNER_CAP_LANG1 |
93 V4L2_TUNER_CAP_LANG2),
96 .rxsubchans = V4L2_TUNER_SUB_STEREO,
97 .audmode = V4L2_TUNER_MODE_STEREO,
100 .reserved = {0,0,0,0}
104 static struct v4l2_fmtdesc pvr_fmtdesc [] = {
107 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
108 .flags = V4L2_FMT_FLAG_COMPRESSED,
109 .description = "MPEG1/2",
110 // This should really be V4L2_PIX_FMT_MPEG, but xawtv
111 // breaks when I do that.
112 .pixelformat = 0, // V4L2_PIX_FMT_MPEG,
113 .reserved = { 0, 0, 0, 0 }
117 #define PVR_FORMAT_PIX 0
118 #define PVR_FORMAT_VBI 1
120 static struct v4l2_format pvr_format [] = {
122 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
127 // This should really be V4L2_PIX_FMT_MPEG,
128 // but xawtv breaks when I do that.
129 .pixelformat = 0, // V4L2_PIX_FMT_MPEG,
130 .field = V4L2_FIELD_INTERLACED,
131 .bytesperline = 0, // doesn't make sense
133 //FIXME : Don't know what to put here...
134 .sizeimage = (32*1024),
135 .colorspace = 0, // doesn't make sense here
141 .type = V4L2_BUF_TYPE_VBI_CAPTURE,
144 .sampling_rate = 27000000,
146 .samples_per_line = 1443,
147 .sample_format = V4L2_PIX_FMT_GREY,
160 * This is part of Video 4 Linux API. The procedure handles ioctl() calls.
163 static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
164 unsigned int cmd, void *arg)
166 struct pvr2_v4l2_fh *fh = file->private_data;
167 struct pvr2_v4l2 *vp = fh->vhead;
168 struct pvr2_v4l2_dev *dev_info = fh->dev_info;
169 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
172 if (pvrusb2_debug & PVR2_TRACE_V4LIOCTL) {
173 v4l_print_ioctl(pvr2_hdw_get_driver_name(hdw),cmd);
176 if (!pvr2_hdw_dev_ok(hdw)) {
177 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
178 "ioctl failed - bad or no context");
188 case VIDIOC_S_FREQUENCY:
189 ret = v4l2_prio_check(&vp->prio, &fh->prio);
195 case VIDIOC_QUERYCAP:
197 struct v4l2_capability *cap = arg;
199 memcpy(cap, &pvr_capability, sizeof(struct v4l2_capability));
205 case VIDIOC_G_PRIORITY:
207 enum v4l2_priority *p = arg;
209 *p = v4l2_prio_max(&vp->prio);
214 case VIDIOC_S_PRIORITY:
216 enum v4l2_priority *prio = arg;
218 ret = v4l2_prio_change(&vp->prio, &fh->prio, *prio);
224 struct v4l2_standard *vs = (struct v4l2_standard *)arg;
226 ret = pvr2_hdw_get_stdenum_value(hdw,vs,idx+1);
233 ret = pvr2_ctrl_get_value(
234 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_STDCUR),&val);
235 *(v4l2_std_id *)arg = val;
241 ret = pvr2_ctrl_set_value(
242 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_STDCUR),
243 *(v4l2_std_id *)arg);
247 case VIDIOC_ENUMINPUT:
249 struct pvr2_ctrl *cptr;
250 struct v4l2_input *vi = (struct v4l2_input *)arg;
251 struct v4l2_input tmp;
254 cptr = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT);
256 memset(&tmp,0,sizeof(tmp));
257 tmp.index = vi->index;
260 case PVR2_CVAL_INPUT_TV:
261 case PVR2_CVAL_INPUT_RADIO:
262 tmp.type = V4L2_INPUT_TYPE_TUNER;
264 case PVR2_CVAL_INPUT_SVIDEO:
265 case PVR2_CVAL_INPUT_COMPOSITE:
266 tmp.type = V4L2_INPUT_TYPE_CAMERA;
275 pvr2_ctrl_get_valname(cptr,vi->index,
276 tmp.name,sizeof(tmp.name)-1,&cnt);
279 /* Don't bother with audioset, since this driver currently
280 always switches the audio whenever the video is
283 /* Handling std is a tougher problem. It doesn't make
284 sense in cases where a device might be multi-standard.
285 We could just copy out the current value for the
286 standard, but it can change over time. For now just
289 memcpy(vi, &tmp, sizeof(tmp));
297 struct pvr2_ctrl *cptr;
298 struct v4l2_input *vi = (struct v4l2_input *)arg;
300 cptr = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT);
302 ret = pvr2_ctrl_get_value(cptr,&val);
309 struct v4l2_input *vi = (struct v4l2_input *)arg;
310 ret = pvr2_ctrl_set_value(
311 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT),
316 case VIDIOC_ENUMAUDIO:
335 struct v4l2_tuner *vt = (struct v4l2_tuner *)arg;
336 unsigned int status_mask;
338 if (vt->index !=0) break;
340 status_mask = pvr2_hdw_get_signal_status(hdw);
342 memcpy(vt, &pvr_v4l2_tuners[vt->index],
343 sizeof(struct v4l2_tuner));
346 if (status_mask & PVR2_SIGNAL_OK) {
347 if (status_mask & PVR2_SIGNAL_STEREO) {
348 vt->rxsubchans = V4L2_TUNER_SUB_STEREO;
350 vt->rxsubchans = V4L2_TUNER_SUB_MONO;
352 if (status_mask & PVR2_SIGNAL_SAP) {
353 vt->rxsubchans |= (V4L2_TUNER_SUB_LANG1 |
354 V4L2_TUNER_SUB_LANG2);
360 ret = pvr2_ctrl_get_value(
361 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_AUDIOMODE),
369 struct v4l2_tuner *vt=(struct v4l2_tuner *)arg;
374 ret = pvr2_ctrl_set_value(
375 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_AUDIOMODE),
379 case VIDIOC_S_FREQUENCY:
381 const struct v4l2_frequency *vf = (struct v4l2_frequency *)arg;
382 ret = pvr2_ctrl_set_value(
383 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_FREQUENCY),
384 vf->frequency * 62500);
388 case VIDIOC_G_FREQUENCY:
390 struct v4l2_frequency *vf = (struct v4l2_frequency *)arg;
392 ret = pvr2_ctrl_get_value(
393 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_FREQUENCY),
400 case VIDIOC_ENUM_FMT:
402 struct v4l2_fmtdesc *fd = (struct v4l2_fmtdesc *)arg;
404 /* Only one format is supported : mpeg.*/
408 memcpy(fd, pvr_fmtdesc, sizeof(struct v4l2_fmtdesc));
415 struct v4l2_format *vf = (struct v4l2_format *)arg;
418 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
419 memcpy(vf, &pvr_format[PVR_FORMAT_PIX],
420 sizeof(struct v4l2_format));
423 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_HRES),
425 vf->fmt.pix.width = val;
428 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_VRES),
430 vf->fmt.pix.height = val;
433 case V4L2_BUF_TYPE_VBI_CAPTURE:
434 // ????? Still need to figure out to do VBI correctly
447 struct v4l2_format *vf = (struct v4l2_format *)arg;
451 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
453 struct pvr2_ctrl *hcp,*vcp;
454 int h = vf->fmt.pix.height;
455 int w = vf->fmt.pix.width;
456 hcp = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_HRES);
457 vcp = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_VRES);
459 lmin = pvr2_ctrl_get_min(hcp);
460 lmax = pvr2_ctrl_get_max(hcp);
463 } else if (w > lmax) {
466 lmin = pvr2_ctrl_get_min(vcp);
467 lmax = pvr2_ctrl_get_max(vcp);
470 } else if (h > lmax) {
474 memcpy(vf, &pvr_format[PVR_FORMAT_PIX],
475 sizeof(struct v4l2_format));
476 vf->fmt.pix.width = w;
477 vf->fmt.pix.height = h;
479 if (cmd == VIDIOC_S_FMT) {
480 pvr2_ctrl_set_value(hcp,vf->fmt.pix.width);
481 pvr2_ctrl_set_value(vcp,vf->fmt.pix.height);
484 case V4L2_BUF_TYPE_VBI_CAPTURE:
485 // ????? Still need to figure out to do VBI correctly
495 case VIDIOC_STREAMON:
497 ret = pvr2_hdw_set_stream_type(hdw,dev_info->config);
498 if (ret < 0) return ret;
499 ret = pvr2_hdw_set_streaming(hdw,!0);
503 case VIDIOC_STREAMOFF:
505 ret = pvr2_hdw_set_streaming(hdw,0);
509 case VIDIOC_QUERYCTRL:
511 struct pvr2_ctrl *cptr;
512 struct v4l2_queryctrl *vc = (struct v4l2_queryctrl *)arg;
514 if (vc->id & V4L2_CTRL_FLAG_NEXT_CTRL) {
515 cptr = pvr2_hdw_get_ctrl_nextv4l(
516 hdw,(vc->id & ~V4L2_CTRL_FLAG_NEXT_CTRL));
517 if (cptr) vc->id = pvr2_ctrl_get_v4lid(cptr);
519 cptr = pvr2_hdw_get_ctrl_v4l(hdw,vc->id);
522 pvr2_trace(PVR2_TRACE_V4LIOCTL,
523 "QUERYCTRL id=0x%x not implemented here",
529 pvr2_trace(PVR2_TRACE_V4LIOCTL,
530 "QUERYCTRL id=0x%x mapping name=%s (%s)",
531 vc->id,pvr2_ctrl_get_name(cptr),
532 pvr2_ctrl_get_desc(cptr));
533 strlcpy(vc->name,pvr2_ctrl_get_desc(cptr),sizeof(vc->name));
534 vc->flags = pvr2_ctrl_get_v4lflags(cptr);
535 vc->default_value = pvr2_ctrl_get_def(cptr);
536 switch (pvr2_ctrl_get_type(cptr)) {
538 vc->type = V4L2_CTRL_TYPE_MENU;
540 vc->maximum = pvr2_ctrl_get_cnt(cptr) - 1;
544 vc->type = V4L2_CTRL_TYPE_BOOLEAN;
550 vc->type = V4L2_CTRL_TYPE_INTEGER;
551 vc->minimum = pvr2_ctrl_get_min(cptr);
552 vc->maximum = pvr2_ctrl_get_max(cptr);
556 pvr2_trace(PVR2_TRACE_V4LIOCTL,
557 "QUERYCTRL id=0x%x name=%s not mappable",
558 vc->id,pvr2_ctrl_get_name(cptr));
565 case VIDIOC_QUERYMENU:
567 struct v4l2_querymenu *vm = (struct v4l2_querymenu *)arg;
568 unsigned int cnt = 0;
569 ret = pvr2_ctrl_get_valname(pvr2_hdw_get_ctrl_v4l(hdw,vm->id),
571 vm->name,sizeof(vm->name)-1,
579 struct v4l2_control *vc = (struct v4l2_control *)arg;
581 ret = pvr2_ctrl_get_value(pvr2_hdw_get_ctrl_v4l(hdw,vc->id),
589 struct v4l2_control *vc = (struct v4l2_control *)arg;
590 ret = pvr2_ctrl_set_value(pvr2_hdw_get_ctrl_v4l(hdw,vc->id),
595 case VIDIOC_G_EXT_CTRLS:
597 struct v4l2_ext_controls *ctls =
598 (struct v4l2_ext_controls *)arg;
599 struct v4l2_ext_control *ctrl;
602 for (idx = 0; idx < ctls->count; idx++) {
603 ctrl = ctls->controls + idx;
604 ret = pvr2_ctrl_get_value(
605 pvr2_hdw_get_ctrl_v4l(hdw,ctrl->id),&val);
607 ctls->error_idx = idx;
610 /* Ensure that if read as a 64 bit value, the user
611 will still get a hopefully sane value */
618 case VIDIOC_S_EXT_CTRLS:
620 struct v4l2_ext_controls *ctls =
621 (struct v4l2_ext_controls *)arg;
622 struct v4l2_ext_control *ctrl;
624 for (idx = 0; idx < ctls->count; idx++) {
625 ctrl = ctls->controls + idx;
626 ret = pvr2_ctrl_set_value(
627 pvr2_hdw_get_ctrl_v4l(hdw,ctrl->id),
630 ctls->error_idx = idx;
637 case VIDIOC_TRY_EXT_CTRLS:
639 struct v4l2_ext_controls *ctls =
640 (struct v4l2_ext_controls *)arg;
641 struct v4l2_ext_control *ctrl;
642 struct pvr2_ctrl *pctl;
644 /* For the moment just validate that the requested control
646 for (idx = 0; idx < ctls->count; idx++) {
647 ctrl = ctls->controls + idx;
648 pctl = pvr2_hdw_get_ctrl_v4l(hdw,ctrl->id);
651 ctls->error_idx = idx;
658 case VIDIOC_LOG_STATUS:
660 pvr2_hdw_trigger_module_log(hdw);
664 #ifdef CONFIG_VIDEO_ADV_DEBUG
665 case VIDIOC_INT_G_REGISTER:
666 case VIDIOC_INT_S_REGISTER:
669 struct v4l2_register *req = (struct v4l2_register *)arg;
670 if (cmd == VIDIOC_INT_S_REGISTER) val = req->val;
671 ret = pvr2_hdw_register_access(
672 hdw,req->i2c_id,req->reg,
673 cmd == VIDIOC_INT_S_REGISTER,&val);
674 if (cmd == VIDIOC_INT_G_REGISTER) req->val = val;
680 ret = v4l_compat_translate_ioctl(inode,file,cmd,
681 arg,pvr2_v4l2_do_ioctl);
684 pvr2_hdw_commit_ctl(hdw);
687 if (pvrusb2_debug & PVR2_TRACE_V4LIOCTL) {
688 pvr2_trace(PVR2_TRACE_V4LIOCTL,
689 "pvr2_v4l2_do_ioctl failure, ret=%d",ret);
691 if (pvrusb2_debug & PVR2_TRACE_V4LIOCTL) {
692 pvr2_trace(PVR2_TRACE_V4LIOCTL,
693 "pvr2_v4l2_do_ioctl failure, ret=%d"
694 " command was:",ret);
695 v4l_print_ioctl(pvr2_hdw_get_driver_name(hdw),
700 pvr2_trace(PVR2_TRACE_V4LIOCTL,
701 "pvr2_v4l2_do_ioctl complete, ret=%d (0x%x)",
708 static void pvr2_v4l2_dev_destroy(struct pvr2_v4l2_dev *dip)
710 printk(KERN_INFO "pvrusb2: unregistering device video%d [%s]\n",
711 dip->devbase.minor,pvr2_config_get_name(dip->config));
717 /* Actual deallocation happens later when all internal references
719 video_unregister_device(&dip->devbase);
723 static void pvr2_v4l2_destroy_no_lock(struct pvr2_v4l2 *vp)
725 pvr2_hdw_v4l_store_minor_number(vp->channel.mc_head->hdw,-1);
726 pvr2_v4l2_dev_destroy(vp->vdev);
728 pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr2_v4l2 id=%p",vp);
729 pvr2_channel_done(&vp->channel);
734 static void pvr2_video_device_release(struct video_device *vdev)
736 struct pvr2_v4l2_dev *dev;
737 dev = container_of(vdev,struct pvr2_v4l2_dev,devbase);
742 static void pvr2_v4l2_internal_check(struct pvr2_channel *chp)
744 struct pvr2_v4l2 *vp;
745 vp = container_of(chp,struct pvr2_v4l2,channel);
746 if (!vp->channel.mc_head->disconnect_flag) return;
747 if (vp->vfirst) return;
748 pvr2_v4l2_destroy_no_lock(vp);
752 static int pvr2_v4l2_ioctl(struct inode *inode, struct file *file,
753 unsigned int cmd, unsigned long arg)
756 /* Temporary hack : use ivtv api until a v4l2 one is available. */
757 #define IVTV_IOC_G_CODEC 0xFFEE7703
758 #define IVTV_IOC_S_CODEC 0xFFEE7704
759 if (cmd == IVTV_IOC_G_CODEC || cmd == IVTV_IOC_S_CODEC) return 0;
760 return video_usercopy(inode, file, cmd, arg, pvr2_v4l2_do_ioctl);
764 static int pvr2_v4l2_release(struct inode *inode, struct file *file)
766 struct pvr2_v4l2_fh *fhp = file->private_data;
767 struct pvr2_v4l2 *vp = fhp->vhead;
768 struct pvr2_context *mp = fhp->vhead->channel.mc_head;
770 pvr2_trace(PVR2_TRACE_OPEN_CLOSE,"pvr2_v4l2_release");
773 struct pvr2_stream *sp;
774 struct pvr2_hdw *hdw;
775 hdw = fhp->channel.mc_head->hdw;
776 pvr2_hdw_set_streaming(hdw,0);
777 sp = pvr2_ioread_get_stream(fhp->rhp);
778 if (sp) pvr2_stream_set_callback(sp,NULL,NULL);
779 pvr2_ioread_destroy(fhp->rhp);
782 v4l2_prio_close(&vp->prio, &fhp->prio);
783 file->private_data = NULL;
785 pvr2_context_enter(mp); do {
787 fhp->vnext->vprev = fhp->vprev;
789 vp->vlast = fhp->vprev;
792 fhp->vprev->vnext = fhp->vnext;
794 vp->vfirst = fhp->vnext;
799 pvr2_channel_done(&fhp->channel);
800 pvr2_trace(PVR2_TRACE_STRUCT,
801 "Destroying pvr_v4l2_fh id=%p",fhp);
803 if (vp->channel.mc_head->disconnect_flag && !vp->vfirst) {
804 pvr2_v4l2_destroy_no_lock(vp);
806 } while (0); pvr2_context_exit(mp);
811 static int pvr2_v4l2_open(struct inode *inode, struct file *file)
813 struct pvr2_v4l2_dev *dip; /* Our own context pointer */
814 struct pvr2_v4l2_fh *fhp;
815 struct pvr2_v4l2 *vp;
816 struct pvr2_hdw *hdw;
818 dip = container_of(video_devdata(file),struct pvr2_v4l2_dev,devbase);
821 hdw = vp->channel.hdw;
823 pvr2_trace(PVR2_TRACE_OPEN_CLOSE,"pvr2_v4l2_open");
825 if (!pvr2_hdw_dev_ok(hdw)) {
826 pvr2_trace(PVR2_TRACE_OPEN_CLOSE,
827 "pvr2_v4l2_open: hardware not ready");
831 fhp = kmalloc(sizeof(*fhp),GFP_KERNEL);
835 memset(fhp,0,sizeof(*fhp));
837 init_waitqueue_head(&fhp->wait_data);
840 pvr2_context_enter(vp->channel.mc_head); do {
841 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr_v4l2_fh id=%p",fhp);
842 pvr2_channel_init(&fhp->channel,vp->channel.mc_head);
844 fhp->vprev = vp->vlast;
846 vp->vlast->vnext = fhp;
852 } while (0); pvr2_context_exit(vp->channel.mc_head);
855 file->private_data = fhp;
856 v4l2_prio_open(&vp->prio,&fhp->prio);
858 fhp->fw_mode_flag = pvr2_hdw_cpufw_get_enabled(hdw);
864 static void pvr2_v4l2_notify(struct pvr2_v4l2_fh *fhp)
866 wake_up(&fhp->wait_data);
869 static int pvr2_v4l2_iosetup(struct pvr2_v4l2_fh *fh)
872 struct pvr2_stream *sp;
873 struct pvr2_hdw *hdw;
874 if (fh->rhp) return 0;
876 /* First read() attempt. Try to claim the stream and start
878 if ((ret = pvr2_channel_claim_stream(&fh->channel,
879 fh->dev_info->stream)) != 0) {
880 /* Someone else must already have it */
884 fh->rhp = pvr2_channel_create_mpeg_stream(fh->dev_info->stream);
886 pvr2_channel_claim_stream(&fh->channel,NULL);
890 hdw = fh->channel.mc_head->hdw;
891 sp = fh->dev_info->stream->stream;
892 pvr2_stream_set_callback(sp,(pvr2_stream_callback)pvr2_v4l2_notify,fh);
893 pvr2_hdw_set_stream_type(hdw,fh->dev_info->config);
894 pvr2_hdw_set_streaming(hdw,!0);
895 ret = pvr2_ioread_set_enabled(fh->rhp,!0);
901 static ssize_t pvr2_v4l2_read(struct file *file,
902 char __user *buff, size_t count, loff_t *ppos)
904 struct pvr2_v4l2_fh *fh = file->private_data;
907 if (fh->fw_mode_flag) {
908 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
912 unsigned int offs = *ppos;
914 tbuf = kmalloc(PAGE_SIZE,GFP_KERNEL);
915 if (!tbuf) return -ENOMEM;
919 if (c1 > PAGE_SIZE) c1 = PAGE_SIZE;
920 c2 = pvr2_hdw_cpufw_get(hdw,offs,tbuf,c1);
926 if (copy_to_user(buff,tbuf,c2)) {
941 ret = pvr2_v4l2_iosetup(fh);
948 ret = pvr2_ioread_read(fh->rhp,buff,count);
950 if (ret != -EAGAIN) break;
951 if (file->f_flags & O_NONBLOCK) break;
952 /* Doing blocking I/O. Wait here. */
953 ret = wait_event_interruptible(
955 pvr2_ioread_avail(fh->rhp) >= 0);
963 static unsigned int pvr2_v4l2_poll(struct file *file, poll_table *wait)
965 unsigned int mask = 0;
966 struct pvr2_v4l2_fh *fh = file->private_data;
969 if (fh->fw_mode_flag) {
970 mask |= POLLIN | POLLRDNORM;
975 ret = pvr2_v4l2_iosetup(fh);
976 if (ret) return POLLERR;
979 poll_wait(file,&fh->wait_data,wait);
981 if (pvr2_ioread_avail(fh->rhp) >= 0) {
982 mask |= POLLIN | POLLRDNORM;
989 static const struct file_operations vdev_fops = {
990 .owner = THIS_MODULE,
991 .open = pvr2_v4l2_open,
992 .release = pvr2_v4l2_release,
993 .read = pvr2_v4l2_read,
994 .ioctl = pvr2_v4l2_ioctl,
996 .poll = pvr2_v4l2_poll,
1000 #define VID_HARDWARE_PVRUSB2 38 /* FIXME : need a good value */
1002 static struct video_device vdev_template = {
1003 .owner = THIS_MODULE,
1004 .type = VID_TYPE_CAPTURE | VID_TYPE_TUNER,
1005 .type2 = (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VBI_CAPTURE
1006 | V4L2_CAP_TUNER | V4L2_CAP_AUDIO
1007 | V4L2_CAP_READWRITE),
1008 .hardware = VID_HARDWARE_PVRUSB2,
1013 static void pvr2_v4l2_dev_init(struct pvr2_v4l2_dev *dip,
1014 struct pvr2_v4l2 *vp,
1015 enum pvr2_config cfg)
1025 case pvr2_config_mpeg:
1026 v4l_type = VFL_TYPE_GRABBER;
1027 dip->stream = &vp->channel.mc_head->video_stream;
1029 case pvr2_config_vbi:
1030 v4l_type = VFL_TYPE_VBI;
1032 case pvr2_config_radio:
1033 v4l_type = VFL_TYPE_RADIO;
1036 /* Bail out (this should be impossible) */
1037 err("Failed to set up pvrusb2 v4l dev"
1038 " due to unrecognized config");
1043 err("Failed to set up pvrusb2 v4l dev"
1044 " due to missing stream instance");
1048 memcpy(&dip->devbase,&vdev_template,sizeof(vdev_template));
1049 dip->devbase.release = pvr2_video_device_release;
1052 unit_number = pvr2_hdw_get_unit_number(vp->channel.mc_head->hdw);
1053 if ((unit_number >= 0) && (unit_number < PVR_NUM)) {
1054 mindevnum = video_nr[unit_number];
1056 if ((video_register_device(&dip->devbase, v4l_type, mindevnum) < 0) &&
1057 (video_register_device(&dip->devbase, v4l_type, -1) < 0)) {
1058 err("Failed to register pvrusb2 v4l video device");
1060 printk(KERN_INFO "pvrusb2: registered device video%d [%s]\n",
1061 dip->devbase.minor,pvr2_config_get_name(dip->config));
1064 pvr2_hdw_v4l_store_minor_number(vp->channel.mc_head->hdw,
1065 dip->devbase.minor);
1069 struct pvr2_v4l2 *pvr2_v4l2_create(struct pvr2_context *mnp)
1071 struct pvr2_v4l2 *vp;
1073 vp = kmalloc(sizeof(*vp),GFP_KERNEL);
1075 memset(vp,0,sizeof(*vp));
1076 vp->vdev = kmalloc(sizeof(*vp->vdev),GFP_KERNEL);
1081 memset(vp->vdev,0,sizeof(*vp->vdev));
1082 pvr2_channel_init(&vp->channel,mnp);
1083 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_v4l2 id=%p",vp);
1085 vp->channel.check_func = pvr2_v4l2_internal_check;
1087 /* register streams */
1088 pvr2_v4l2_dev_init(vp->vdev,vp,pvr2_config_mpeg);
1094 Stuff for Emacs to see, in order to encourage consistent editing style:
1095 *** Local Variables: ***
1097 *** fill-column: 75 ***
1098 *** tab-width: 8 ***
1099 *** c-basic-offset: 8 ***