V4L/DVB: ivtv: switch to new vbi subdev ops
[safe/jmp/linux-2.6] / drivers / media / video / ivtv / ivtv-ioctl.c
index 2192bc4..a17c659 100644 (file)
@@ -35,6 +35,7 @@
 #include <media/saa7127.h>
 #include <media/tveeprom.h>
 #include <media/v4l2-chip-ident.h>
+#include <media/v4l2-event.h>
 #include <linux/dvb/audio.h>
 #include <linux/i2c-id.h>
 
@@ -391,7 +392,7 @@ static int ivtv_g_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_fo
                return 0;
        }
 
-       v4l2_subdev_call(itv->sd_video, video, g_fmt, fmt);
+       v4l2_subdev_call(itv->sd_video, vbi, g_sliced_fmt, vbifmt);
        vbifmt->service_set = ivtv_get_service_set(vbifmt);
        return 0;
 }
@@ -597,7 +598,7 @@ static int ivtv_s_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f
                return -EBUSY;
        itv->vbi.sliced_in->service_set = 0;
        itv->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE;
-       v4l2_subdev_call(itv->sd_video, video, s_fmt, fmt);
+       v4l2_subdev_call(itv->sd_video, vbi, s_raw_fmt, &fmt->fmt.vbi);
        return ivtv_g_fmt_vbi_cap(file, fh, fmt);
 }
 
@@ -615,7 +616,7 @@ static int ivtv_s_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_fo
        if (ivtv_raw_vbi(itv) && atomic_read(&itv->capturing) > 0)
                return -EBUSY;
        itv->vbi.in.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
-       v4l2_subdev_call(itv->sd_video, video, s_fmt, fmt);
+       v4l2_subdev_call(itv->sd_video, vbi, s_sliced_fmt, vbifmt);
        memcpy(itv->vbi.sliced_in, vbifmt, sizeof(*itv->vbi.sliced_in));
        return 0;
 }
@@ -1140,7 +1141,7 @@ int ivtv_s_std(struct file *file, void *fh, v4l2_std_id *std)
                for (f = 0; f < 4; f++) {
                        prepare_to_wait(&itv->vsync_waitq, &wait,
                                        TASK_UNINTERRUPTIBLE);
-                       if ((read_reg(0x28c0) >> 16) < 100)
+                       if ((read_reg(IVTV_REG_DEC_LINE_FIELD) >> 16) < 100)
                                break;
                        schedule_timeout(msecs_to_jiffies(25));
                }
@@ -1452,6 +1453,18 @@ static int ivtv_overlay(struct file *file, void *fh, unsigned int on)
        return 0;
 }
 
+static int ivtv_subscribe_event(struct v4l2_fh *fh, struct v4l2_event_subscription *sub)
+{
+       switch (sub->type) {
+       case V4L2_EVENT_VSYNC:
+       case V4L2_EVENT_EOS:
+               break;
+       default:
+               return -EINVAL;
+       }
+       return v4l2_event_subscribe(fh, sub);
+}
+
 static int ivtv_log_status(struct file *file, void *fh)
 {
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
@@ -1560,10 +1573,11 @@ static int ivtv_log_status(struct file *file, void *fh)
 
 static int ivtv_decoder_ioctls(struct file *filp, unsigned int cmd, void *arg)
 {
-       struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data;
+       struct ivtv_open_id *id = fh2id(filp->private_data);
        struct ivtv *itv = id->itv;
        int nonblocking = filp->f_flags & O_NONBLOCK;
        struct ivtv_stream *s = &itv->streams[id->type];
+       unsigned long iarg = (unsigned long)arg;
 
        switch (cmd) {
        case IVTV_IOC_DMA_FRAME: {
@@ -1745,6 +1759,33 @@ static int ivtv_decoder_ioctls(struct file *filp, unsigned int cmd, void *arg)
                break;
        }
 
+       case VIDEO_SELECT_SOURCE:
+               IVTV_DEBUG_IOCTL("VIDEO_SELECT_SOURCE\n");
+               if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
+                       return -EINVAL;
+               return ivtv_passthrough_mode(itv, iarg == VIDEO_SOURCE_DEMUX);
+
+       case AUDIO_SET_MUTE:
+               IVTV_DEBUG_IOCTL("AUDIO_SET_MUTE\n");
+               itv->speed_mute_audio = iarg;
+               return 0;
+
+       case AUDIO_CHANNEL_SELECT:
+               IVTV_DEBUG_IOCTL("AUDIO_CHANNEL_SELECT\n");
+               if (iarg > AUDIO_STEREO_SWAPPED)
+                       return -EINVAL;
+               itv->audio_stereo_mode = iarg;
+               ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode);
+               return 0;
+
+       case AUDIO_BILINGUAL_CHANNEL_SELECT:
+               IVTV_DEBUG_IOCTL("AUDIO_BILINGUAL_CHANNEL_SELECT\n");
+               if (iarg > AUDIO_STEREO_SWAPPED)
+                       return -EINVAL;
+               itv->audio_bilingual_mode = iarg;
+               ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode);
+               return 0;
+
        default:
                return -EINVAL;
        }
@@ -1776,6 +1817,10 @@ static long ivtv_default(struct file *file, void *fh, int cmd, void *arg)
        case VIDEO_CONTINUE:
        case VIDEO_COMMAND:
        case VIDEO_TRY_COMMAND:
+       case VIDEO_SELECT_SOURCE:
+       case AUDIO_SET_MUTE:
+       case AUDIO_CHANNEL_SELECT:
+       case AUDIO_BILINGUAL_CHANNEL_SELECT:
                return ivtv_decoder_ioctls(file, cmd, (void *)arg);
 
        default:
@@ -1788,42 +1833,9 @@ static long ivtv_serialized_ioctl(struct ivtv *itv, struct file *filp,
                unsigned int cmd, unsigned long arg)
 {
        struct video_device *vfd = video_devdata(filp);
-       struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data;
+       struct ivtv_open_id *id = fh2id(filp->private_data);
        long ret;
 
-       /* Filter dvb ioctls that cannot be handled by the v4l ioctl framework */
-       switch (cmd) {
-       case VIDEO_SELECT_SOURCE:
-               IVTV_DEBUG_IOCTL("VIDEO_SELECT_SOURCE\n");
-               if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
-                       return -EINVAL;
-               return ivtv_passthrough_mode(itv, arg == VIDEO_SOURCE_DEMUX);
-
-       case AUDIO_SET_MUTE:
-               IVTV_DEBUG_IOCTL("AUDIO_SET_MUTE\n");
-               itv->speed_mute_audio = arg;
-               return 0;
-
-       case AUDIO_CHANNEL_SELECT:
-               IVTV_DEBUG_IOCTL("AUDIO_CHANNEL_SELECT\n");
-               if (arg > AUDIO_STEREO_SWAPPED)
-                       return -EINVAL;
-               itv->audio_stereo_mode = arg;
-               ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode);
-               return 0;
-
-       case AUDIO_BILINGUAL_CHANNEL_SELECT:
-               IVTV_DEBUG_IOCTL("AUDIO_BILINGUAL_CHANNEL_SELECT\n");
-               if (arg > AUDIO_STEREO_SWAPPED)
-                       return -EINVAL;
-               itv->audio_bilingual_mode = arg;
-               ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode);
-               return 0;
-
-       default:
-               break;
-       }
-
        /* check priority */
        switch (cmd) {
        case VIDIOC_S_CTRL:
@@ -1853,10 +1865,13 @@ static long ivtv_serialized_ioctl(struct ivtv *itv, struct file *filp,
 
 long ivtv_v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
-       struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data;
+       struct ivtv_open_id *id = fh2id(filp->private_data);
        struct ivtv *itv = id->itv;
        long res;
 
+       /* DQEVENT can block, so this should not run with the serialize lock */
+       if (cmd == VIDIOC_DQEVENT)
+               return ivtv_serialized_ioctl(itv, filp, cmd, arg);
        mutex_lock(&itv->serialize_lock);
        res = ivtv_serialized_ioctl(itv, filp, cmd, arg);
        mutex_unlock(&itv->serialize_lock);
@@ -1927,6 +1942,8 @@ static const struct v4l2_ioctl_ops ivtv_ioctl_ops = {
        .vidioc_g_ext_ctrls                 = ivtv_g_ext_ctrls,
        .vidioc_s_ext_ctrls                 = ivtv_s_ext_ctrls,
        .vidioc_try_ext_ctrls               = ivtv_try_ext_ctrls,
+       .vidioc_subscribe_event             = ivtv_subscribe_event,
+       .vidioc_unsubscribe_event           = v4l2_event_unsubscribe,
 };
 
 void ivtv_set_funcs(struct video_device *vdev)