22 #include <linux/kernel.h>
23 #include <linux/slab.h>
24 #include <linux/version.h>
31 #include <linux/videodev2.h>
32 #include <linux/module.h>
93 .card =
"Hauppauge WinTV pvr-usb2",
95 .version = LINUX_VERSION_CODE,
106 .description =
"MPEG1/2",
113 #define PVR_FORMAT_PIX 0
114 #define PVR_FORMAT_VBI 1
130 .sizeimage = (32*1024),
140 .sampling_rate = 27000000,
142 .samples_per_line = 1443,
169 static int pvr2_g_priority(
struct file *file,
void *priv,
enum v4l2_priority *
p)
178 static int pvr2_s_priority(
struct file *file,
void *priv,
enum v4l2_priority prio)
186 static int pvr2_g_std(
struct file *file,
void *priv,
v4l2_std_id *
std)
208 static int pvr2_querystd(
struct file *file,
void *priv,
v4l2_std_id *std)
221 static int pvr2_enum_input(
struct file *file,
void *priv,
struct v4l2_input *vi)
269 static int pvr2_g_input(
struct file *file,
void *priv,
unsigned int *
i)
282 for (idx = 0; idx < fh->
input_cnt; idx++) {
291 static int pvr2_s_input(
struct file *file,
void *priv,
unsigned int inp)
303 static int pvr2_enumaudio(
struct file *file,
void *priv,
struct v4l2_audio *
vin)
327 static int pvr2_g_audio(
struct file *file,
void *priv,
struct v4l2_audio *vin)
336 static int pvr2_s_audio(
struct file *file,
void *priv,
const struct v4l2_audio *vout)
343 static int pvr2_g_tuner(
struct file *file,
void *priv,
struct v4l2_tuner *vt)
355 static int pvr2_s_tuner(
struct file *file,
void *priv,
struct v4l2_tuner *vt)
401 static int pvr2_g_frequency(
struct file *file,
void *priv,
struct v4l2_frequency *
vf)
426 val = (val * 2) / 125;
433 static int pvr2_enum_fmt_vid_cap(
struct file *file,
void *priv,
struct v4l2_fmtdesc *
fd)
443 static int pvr2_g_fmt_vid_cap(
struct file *file,
void *priv,
struct v4l2_format *vf)
463 static int pvr2_try_fmt_vid_cap(
struct file *file,
void *priv,
struct v4l2_format *vf)
467 int lmin, lmax, ldef;
494 memcpy(vf, &pvr_format[PVR_FORMAT_PIX],
501 static int pvr2_s_fmt_vid_cap(
struct file *file,
void *priv,
struct v4l2_format *vf)
506 int ret = pvr2_try_fmt_vid_cap(file, fh, vf);
517 static int pvr2_streamon(
struct file *file,
void *priv,
enum v4l2_buf_type i)
524 if (!fh->
pdi->stream) {
536 static int pvr2_streamoff(
struct file *file,
void *priv,
enum v4l2_buf_type i)
541 if (!fh->
pdi->stream) {
550 static int pvr2_queryctrl(
struct file *file,
void *priv,
568 "QUERYCTRL id=0x%x not implemented here",
574 "QUERYCTRL id=0x%x mapping name=%s (%s)",
602 "QUERYCTRL id=0x%x name=%s not mappable",
609 static int pvr2_querymenu(
struct file *file,
void *priv,
struct v4l2_querymenu *
vm)
613 unsigned int cnt = 0;
624 static int pvr2_g_ctrl(
struct file *file,
void *priv,
struct v4l2_control *vc)
637 static int pvr2_s_ctrl(
struct file *file,
void *priv,
struct v4l2_control *vc)
646 static int pvr2_g_ext_ctrls(
struct file *file,
void *priv,
657 for (idx = 0; idx < ctls->
count; idx++) {
673 static int pvr2_s_ext_ctrls(
struct file *file,
void *priv,
683 for (idx = 0; idx < ctls->
count; idx++) {
696 static int pvr2_try_ext_ctrls(
struct file *file,
void *priv,
707 for (idx = 0; idx < ctls->
count; idx++) {
718 static int pvr2_cropcap(
struct file *file,
void *priv,
struct v4l2_cropcap *cap)
731 static int pvr2_g_crop(
struct file *file,
void *priv,
struct v4l2_crop *crop)
759 crop->
c.height =
val;
763 static int pvr2_s_crop(
struct file *file,
void *priv,
const struct v4l2_crop *crop)
794 static int pvr2_log_status(
struct file *file,
void *priv)
803 #ifdef CONFIG_VIDEO_ADV_DEBUG
834 .vidioc_querycap = pvr2_querycap,
835 .vidioc_g_priority = pvr2_g_priority,
836 .vidioc_s_priority = pvr2_s_priority,
837 .vidioc_s_audio = pvr2_s_audio,
838 .vidioc_g_audio = pvr2_g_audio,
839 .vidioc_enumaudio = pvr2_enumaudio,
840 .vidioc_enum_input = pvr2_enum_input,
841 .vidioc_cropcap = pvr2_cropcap,
842 .vidioc_s_crop = pvr2_s_crop,
843 .vidioc_g_crop = pvr2_g_crop,
844 .vidioc_g_input = pvr2_g_input,
845 .vidioc_s_input = pvr2_s_input,
846 .vidioc_g_frequency = pvr2_g_frequency,
848 .vidioc_s_tuner = pvr2_s_tuner,
849 .vidioc_g_tuner = pvr2_g_tuner,
850 .vidioc_g_std = pvr2_g_std,
852 .vidioc_querystd = pvr2_querystd,
853 .vidioc_log_status = pvr2_log_status,
854 .vidioc_enum_fmt_vid_cap = pvr2_enum_fmt_vid_cap,
855 .vidioc_g_fmt_vid_cap = pvr2_g_fmt_vid_cap,
856 .vidioc_s_fmt_vid_cap = pvr2_s_fmt_vid_cap,
857 .vidioc_try_fmt_vid_cap = pvr2_try_fmt_vid_cap,
858 .vidioc_streamon = pvr2_streamon,
859 .vidioc_streamoff = pvr2_streamoff,
860 .vidioc_queryctrl = pvr2_queryctrl,
861 .vidioc_querymenu = pvr2_querymenu,
862 .vidioc_g_ctrl = pvr2_g_ctrl,
863 .vidioc_s_ctrl = pvr2_s_ctrl,
864 .vidioc_g_ext_ctrls = pvr2_g_ext_ctrls,
865 .vidioc_s_ext_ctrls = pvr2_s_ext_ctrls,
866 .vidioc_try_ext_ctrls = pvr2_try_ext_ctrls,
867 #ifdef CONFIG_VIDEO_ADV_DEBUG
868 .vidioc_g_register = pvr2_g_register,
869 .vidioc_s_register = pvr2_s_register,
884 "pvrusb2: unregistered device %s [%s]",
885 video_device_node_name(&dip->
devbase),
904 static void pvr2_v4l2_dev_disassociate_parent(
struct pvr2_v4l2_dev *dip)
907 if (!dip->
devbase.parent)
return;
913 static void pvr2_v4l2_destroy_no_lock(
struct pvr2_v4l2 *vp)
930 static void pvr2_video_device_release(
struct video_device *vdev)
938 static void pvr2_v4l2_internal_check(
struct pvr2_channel *chp)
942 if (!vp->
channel.mc_head->disconnect_flag)
return;
943 pvr2_v4l2_dev_disassociate_parent(vp->
dev_video);
944 pvr2_v4l2_dev_disassociate_parent(vp->
dev_radio);
946 pvr2_v4l2_destroy_no_lock(vp);
950 static long pvr2_v4l2_ioctl(
struct file *file,
951 unsigned int cmd,
unsigned long arg)
964 "ioctl failed - bad or no context");
987 "pvr2_v4l2_do_ioctl failure, ret=%ld", ret);
991 "pvr2_v4l2_do_ioctl failure, ret=%ld"
992 " command was:", ret);
999 "pvr2_v4l2_do_ioctl complete, ret=%ld (0x%lx)",
1007 static int pvr2_v4l2_release(
struct file *file)
1042 "Destroying pvr_v4l2_fh id=%p",fhp);
1049 pvr2_v4l2_destroy_no_lock(vp);
1055 static int pvr2_v4l2_open(
struct file *file)
1061 unsigned int input_mask = 0;
1062 unsigned int input_cnt,
idx;
1074 "pvr2_v4l2_open: hardware not ready");
1105 "Destroying pvr_v4l2_fh id=%p (input mask error)",
1114 for (idx = 0; idx < (
sizeof(input_mask) << 3); idx++) {
1115 if (input_mask & (1 << idx)) input_cnt++;
1122 "Destroying pvr_v4l2_fh id=%p (input map failure)",
1128 for (idx = 0; idx < (
sizeof(input_mask) << 3); idx++) {
1129 if (!(input_mask & (1 << idx)))
continue;
1136 vp->
vlast->vnext = fhp;
1163 if (fh->
rhp)
return 0;
1165 if (!fh->
pdi->stream) {
1174 fh->
pdi->stream)) != 0) {
1185 hdw = fh->
channel.mc_head->hdw;
1186 sp = fh->
pdi->stream->stream;
1194 static ssize_t pvr2_v4l2_read(
struct file *file,
1195 char __user *buff,
size_t count, loff_t *ppos)
1205 unsigned int offs = *ppos;
1208 if (!tbuf)
return -
ENOMEM;
1234 ret = pvr2_v4l2_iosetup(fh);
1242 if (ret >= 0)
break;
1243 if (ret != -
EAGAIN)
break;
1256 static unsigned int pvr2_v4l2_poll(
struct file *file,
poll_table *
wait)
1258 unsigned int mask = 0;
1268 ret = pvr2_v4l2_iosetup(fh);
1284 .open = pvr2_v4l2_open,
1285 .release = pvr2_v4l2_release,
1286 .read = pvr2_v4l2_read,
1287 .ioctl = pvr2_v4l2_ioctl,
1288 .poll = pvr2_v4l2_poll,
1301 struct usb_device *usbdev;
1308 hdw = vp->
channel.mc_head->hdw;
1319 ": Failed to set up pvrusb2 v4l video dev"
1320 " due to missing stream instance\n");
1337 pr_err(KBUILD_MODNAME
": Failed to set up pvrusb2 v4l dev"
1338 " due to unrecognized config\n");
1343 dip->
devbase.release = pvr2_video_device_release;
1344 dip->
devbase.ioctl_ops = &pvr2_ioctl_ops;
1355 if (nr_ptr && (unit_number >= 0) && (unit_number <
PVR_NUM)) {
1358 dip->
devbase.parent = &usbdev->dev;
1359 if ((video_register_device(&dip->
devbase,
1361 (video_register_device(&dip->
devbase,
1364 ": Failed to register pvrusb2 v4l device\n");
1368 video_device_node_name(&dip->
devbase),
1385 vp->
channel.check_func = pvr2_v4l2_internal_check;
1401 pvr2_v4l2_destroy_no_lock(vp);