Back to home page

OSCL-LXR

 
 

    


0001 /*
0002     init/start/stop/exit stream functions
0003     Copyright (C) 2003-2004  Kevin Thayer <nufan_wfk at yahoo.com>
0004     Copyright (C) 2004  Chris Kennedy <c@groovy.org>
0005     Copyright (C) 2005-2007  Hans Verkuil <hverkuil@xs4all.nl>
0006 
0007     This program is free software; you can redistribute it and/or modify
0008     it under the terms of the GNU General Public License as published by
0009     the Free Software Foundation; either version 2 of the License, or
0010     (at your option) any later version.
0011 
0012     This program is distributed in the hope that it will be useful,
0013     but WITHOUT ANY WARRANTY; without even the implied warranty of
0014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0015     GNU General Public License for more details.
0016 
0017     You should have received a copy of the GNU General Public License
0018     along with this program; if not, write to the Free Software
0019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0020  */
0021 
0022 /* License: GPL
0023  * Author: Kevin Thayer <nufan_wfk at yahoo dot com>
0024  *
0025  * This file will hold API related functions, both internal (firmware api)
0026  * and external (v4l2, etc)
0027  *
0028  * -----
0029  * MPG600/MPG160 support by  T.Adachi <tadachi@tadachi-net.com>
0030  *                      and Takeru KOMORIYA<komoriya@paken.org>
0031  *
0032  * AVerMedia M179 GPIO info by Chris Pinkham <cpinkham@bc2va.org>
0033  *                using information provided by Jiun-Kuei Jung @ AVerMedia.
0034  */
0035 
0036 #include "ivtv-driver.h"
0037 #include "ivtv-fileops.h"
0038 #include "ivtv-queue.h"
0039 #include "ivtv-mailbox.h"
0040 #include "ivtv-ioctl.h"
0041 #include "ivtv-irq.h"
0042 #include "ivtv-yuv.h"
0043 #include "ivtv-cards.h"
0044 #include "ivtv-streams.h"
0045 #include "ivtv-firmware.h"
0046 #include <media/v4l2-event.h>
0047 
0048 static const struct v4l2_file_operations ivtv_v4l2_enc_fops = {
0049     .owner = THIS_MODULE,
0050     .read = ivtv_v4l2_read,
0051     .write = ivtv_v4l2_write,
0052     .open = ivtv_v4l2_open,
0053     .unlocked_ioctl = video_ioctl2,
0054 #ifdef CONFIG_COMPAT
0055     .compat_ioctl32 = video_ioctl2, /* for ivtv_default() */
0056 #endif
0057     .release = ivtv_v4l2_close,
0058     .poll = ivtv_v4l2_enc_poll,
0059 };
0060 
0061 static const struct v4l2_file_operations ivtv_v4l2_dec_fops = {
0062     .owner = THIS_MODULE,
0063     .read = ivtv_v4l2_read,
0064     .write = ivtv_v4l2_write,
0065     .open = ivtv_v4l2_open,
0066     .unlocked_ioctl = video_ioctl2,
0067 #ifdef CONFIG_COMPAT
0068     .compat_ioctl32 = video_ioctl2, /* for ivtv_default() */
0069 #endif
0070     .release = ivtv_v4l2_close,
0071     .poll = ivtv_v4l2_dec_poll,
0072 };
0073 
0074 static const struct v4l2_file_operations ivtv_v4l2_radio_fops = {
0075     .owner = THIS_MODULE,
0076     .open = ivtv_v4l2_open,
0077     .unlocked_ioctl = video_ioctl2,
0078 #ifdef CONFIG_COMPAT
0079     .compat_ioctl32 = video_ioctl2, /* for ivtv_default() */
0080 #endif
0081     .release = ivtv_v4l2_close,
0082     .poll = ivtv_v4l2_enc_poll,
0083 };
0084 
0085 #define IVTV_V4L2_DEC_MPG_OFFSET  16    /* offset from 0 to register decoder mpg v4l2 minors on */
0086 #define IVTV_V4L2_ENC_PCM_OFFSET  24    /* offset from 0 to register pcm v4l2 minors on */
0087 #define IVTV_V4L2_ENC_YUV_OFFSET  32    /* offset from 0 to register yuv v4l2 minors on */
0088 #define IVTV_V4L2_DEC_YUV_OFFSET  48    /* offset from 0 to register decoder yuv v4l2 minors on */
0089 #define IVTV_V4L2_DEC_VBI_OFFSET   8    /* offset from 0 to register decoder vbi input v4l2 minors on */
0090 #define IVTV_V4L2_DEC_VOUT_OFFSET 16    /* offset from 0 to register vbi output v4l2 minors on */
0091 
0092 static struct {
0093     const char *name;
0094     int vfl_type;
0095     int num_offset;
0096     int dma, pio;
0097     u32 v4l2_caps;
0098     const struct v4l2_file_operations *fops;
0099 } ivtv_stream_info[] = {
0100     {   /* IVTV_ENC_STREAM_TYPE_MPG */
0101         "encoder MPG",
0102         VFL_TYPE_VIDEO, 0,
0103         DMA_FROM_DEVICE, 0,
0104         V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TUNER |
0105             V4L2_CAP_AUDIO | V4L2_CAP_READWRITE,
0106         &ivtv_v4l2_enc_fops
0107     },
0108     {   /* IVTV_ENC_STREAM_TYPE_YUV */
0109         "encoder YUV",
0110         VFL_TYPE_VIDEO, IVTV_V4L2_ENC_YUV_OFFSET,
0111         DMA_FROM_DEVICE, 0,
0112         V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TUNER |
0113             V4L2_CAP_AUDIO | V4L2_CAP_READWRITE,
0114         &ivtv_v4l2_enc_fops
0115     },
0116     {   /* IVTV_ENC_STREAM_TYPE_VBI */
0117         "encoder VBI",
0118         VFL_TYPE_VBI, 0,
0119         DMA_FROM_DEVICE, 0,
0120         V4L2_CAP_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_CAPTURE | V4L2_CAP_TUNER |
0121             V4L2_CAP_AUDIO | V4L2_CAP_READWRITE,
0122         &ivtv_v4l2_enc_fops
0123     },
0124     {   /* IVTV_ENC_STREAM_TYPE_PCM */
0125         "encoder PCM",
0126         VFL_TYPE_VIDEO, IVTV_V4L2_ENC_PCM_OFFSET,
0127         DMA_FROM_DEVICE, 0,
0128         V4L2_CAP_TUNER | V4L2_CAP_AUDIO | V4L2_CAP_READWRITE,
0129         &ivtv_v4l2_enc_fops
0130     },
0131     {   /* IVTV_ENC_STREAM_TYPE_RAD */
0132         "encoder radio",
0133         VFL_TYPE_RADIO, 0,
0134         DMA_NONE, 1,
0135         V4L2_CAP_RADIO | V4L2_CAP_TUNER,
0136         &ivtv_v4l2_radio_fops
0137     },
0138     {   /* IVTV_DEC_STREAM_TYPE_MPG */
0139         "decoder MPG",
0140         VFL_TYPE_VIDEO, IVTV_V4L2_DEC_MPG_OFFSET,
0141         DMA_TO_DEVICE, 0,
0142         V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_AUDIO | V4L2_CAP_READWRITE,
0143         &ivtv_v4l2_dec_fops
0144     },
0145     {   /* IVTV_DEC_STREAM_TYPE_VBI */
0146         "decoder VBI",
0147         VFL_TYPE_VBI, IVTV_V4L2_DEC_VBI_OFFSET,
0148         DMA_NONE, 1,
0149         V4L2_CAP_SLICED_VBI_CAPTURE | V4L2_CAP_READWRITE,
0150         &ivtv_v4l2_enc_fops
0151     },
0152     {   /* IVTV_DEC_STREAM_TYPE_VOUT */
0153         "decoder VOUT",
0154         VFL_TYPE_VBI, IVTV_V4L2_DEC_VOUT_OFFSET,
0155         DMA_NONE, 1,
0156         V4L2_CAP_SLICED_VBI_OUTPUT | V4L2_CAP_AUDIO | V4L2_CAP_READWRITE,
0157         &ivtv_v4l2_dec_fops
0158     },
0159     {   /* IVTV_DEC_STREAM_TYPE_YUV */
0160         "decoder YUV",
0161         VFL_TYPE_VIDEO, IVTV_V4L2_DEC_YUV_OFFSET,
0162         DMA_TO_DEVICE, 0,
0163         V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_AUDIO | V4L2_CAP_READWRITE,
0164         &ivtv_v4l2_dec_fops
0165     }
0166 };
0167 
0168 static void ivtv_stream_init(struct ivtv *itv, int type)
0169 {
0170     struct ivtv_stream *s = &itv->streams[type];
0171 
0172     /* we need to keep vdev, so restore it afterwards */
0173     memset(s, 0, sizeof(*s));
0174 
0175     /* initialize ivtv_stream fields */
0176     s->itv = itv;
0177     s->type = type;
0178     s->name = ivtv_stream_info[type].name;
0179     s->vdev.device_caps = ivtv_stream_info[type].v4l2_caps;
0180 
0181     if (ivtv_stream_info[type].pio)
0182         s->dma = DMA_NONE;
0183     else
0184         s->dma = ivtv_stream_info[type].dma;
0185     s->buf_size = itv->stream_buf_size[type];
0186     if (s->buf_size)
0187         s->buffers = (itv->options.kilobytes[type] * 1024 + s->buf_size - 1) / s->buf_size;
0188     spin_lock_init(&s->qlock);
0189     init_waitqueue_head(&s->waitq);
0190     s->sg_handle = IVTV_DMA_UNMAPPED;
0191     ivtv_queue_init(&s->q_free);
0192     ivtv_queue_init(&s->q_full);
0193     ivtv_queue_init(&s->q_dma);
0194     ivtv_queue_init(&s->q_predma);
0195     ivtv_queue_init(&s->q_io);
0196 }
0197 
0198 static int ivtv_prep_dev(struct ivtv *itv, int type)
0199 {
0200     struct ivtv_stream *s = &itv->streams[type];
0201     int num_offset = ivtv_stream_info[type].num_offset;
0202     int num = itv->instance + ivtv_first_minor + num_offset;
0203 
0204     /* These four fields are always initialized. If vdev.v4l2_dev == NULL, then
0205        this stream is not in use. In that case no other fields but these
0206        four can be used. */
0207     s->vdev.v4l2_dev = NULL;
0208     s->itv = itv;
0209     s->type = type;
0210     s->name = ivtv_stream_info[type].name;
0211 
0212     /* Check whether the radio is supported */
0213     if (type == IVTV_ENC_STREAM_TYPE_RAD && !(itv->v4l2_cap & V4L2_CAP_RADIO))
0214         return 0;
0215     if (type >= IVTV_DEC_STREAM_TYPE_MPG && !(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
0216         return 0;
0217 
0218     /* User explicitly selected 0 buffers for these streams, so don't
0219        create them. */
0220     if (ivtv_stream_info[type].dma != DMA_NONE &&
0221         itv->options.kilobytes[type] == 0) {
0222         IVTV_INFO("Disabled %s device\n", ivtv_stream_info[type].name);
0223         return 0;
0224     }
0225 
0226     ivtv_stream_init(itv, type);
0227 
0228     snprintf(s->vdev.name, sizeof(s->vdev.name), "%s %s",
0229             itv->v4l2_dev.name, s->name);
0230 
0231     s->vdev.num = num;
0232     s->vdev.v4l2_dev = &itv->v4l2_dev;
0233     if (ivtv_stream_info[type].v4l2_caps &
0234             (V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_SLICED_VBI_OUTPUT))
0235         s->vdev.vfl_dir = VFL_DIR_TX;
0236     s->vdev.fops = ivtv_stream_info[type].fops;
0237     s->vdev.ctrl_handler = itv->v4l2_dev.ctrl_handler;
0238     s->vdev.release = video_device_release_empty;
0239     s->vdev.tvnorms = V4L2_STD_ALL;
0240     s->vdev.lock = &itv->serialize_lock;
0241     if (s->type == IVTV_DEC_STREAM_TYPE_VBI) {
0242         v4l2_disable_ioctl(&s->vdev, VIDIOC_S_AUDIO);
0243         v4l2_disable_ioctl(&s->vdev, VIDIOC_G_AUDIO);
0244         v4l2_disable_ioctl(&s->vdev, VIDIOC_ENUMAUDIO);
0245         v4l2_disable_ioctl(&s->vdev, VIDIOC_ENUMINPUT);
0246         v4l2_disable_ioctl(&s->vdev, VIDIOC_S_INPUT);
0247         v4l2_disable_ioctl(&s->vdev, VIDIOC_G_INPUT);
0248         v4l2_disable_ioctl(&s->vdev, VIDIOC_S_FREQUENCY);
0249         v4l2_disable_ioctl(&s->vdev, VIDIOC_G_FREQUENCY);
0250         v4l2_disable_ioctl(&s->vdev, VIDIOC_S_TUNER);
0251         v4l2_disable_ioctl(&s->vdev, VIDIOC_G_TUNER);
0252         v4l2_disable_ioctl(&s->vdev, VIDIOC_S_STD);
0253     }
0254     ivtv_set_funcs(&s->vdev);
0255     return 0;
0256 }
0257 
0258 /* Initialize v4l2 variables and prepare v4l2 devices */
0259 int ivtv_streams_setup(struct ivtv *itv)
0260 {
0261     int type;
0262 
0263     /* Setup V4L2 Devices */
0264     for (type = 0; type < IVTV_MAX_STREAMS; type++) {
0265         /* Prepare device */
0266         if (ivtv_prep_dev(itv, type))
0267             break;
0268 
0269         if (itv->streams[type].vdev.v4l2_dev == NULL)
0270             continue;
0271 
0272         /* Allocate Stream */
0273         if (ivtv_stream_alloc(&itv->streams[type]))
0274             break;
0275     }
0276     if (type == IVTV_MAX_STREAMS)
0277         return 0;
0278 
0279     /* One or more streams could not be initialized. Clean 'em all up. */
0280     ivtv_streams_cleanup(itv);
0281     return -ENOMEM;
0282 }
0283 
0284 static int ivtv_reg_dev(struct ivtv *itv, int type)
0285 {
0286     struct ivtv_stream *s = &itv->streams[type];
0287     int vfl_type = ivtv_stream_info[type].vfl_type;
0288     const char *name;
0289     int num;
0290 
0291     if (s->vdev.v4l2_dev == NULL)
0292         return 0;
0293 
0294     num = s->vdev.num;
0295     /* card number + user defined offset + device offset */
0296     if (type != IVTV_ENC_STREAM_TYPE_MPG) {
0297         struct ivtv_stream *s_mpg = &itv->streams[IVTV_ENC_STREAM_TYPE_MPG];
0298 
0299         if (s_mpg->vdev.v4l2_dev)
0300             num = s_mpg->vdev.num + ivtv_stream_info[type].num_offset;
0301     }
0302     if (itv->osd_video_pbase && (type == IVTV_DEC_STREAM_TYPE_YUV ||
0303                      type == IVTV_DEC_STREAM_TYPE_MPG)) {
0304         s->vdev.device_caps |= V4L2_CAP_VIDEO_OUTPUT_OVERLAY;
0305         itv->v4l2_cap |= V4L2_CAP_VIDEO_OUTPUT_OVERLAY;
0306     }
0307     video_set_drvdata(&s->vdev, s);
0308 
0309     /* Register device. First try the desired minor, then any free one. */
0310     if (video_register_device_no_warn(&s->vdev, vfl_type, num)) {
0311         IVTV_ERR("Couldn't register v4l2 device for %s (device node number %d)\n",
0312                 s->name, num);
0313         return -ENOMEM;
0314     }
0315     name = video_device_node_name(&s->vdev);
0316 
0317     switch (vfl_type) {
0318     case VFL_TYPE_VIDEO:
0319         IVTV_INFO("Registered device %s for %s (%d kB)\n",
0320             name, s->name, itv->options.kilobytes[type]);
0321         break;
0322     case VFL_TYPE_RADIO:
0323         IVTV_INFO("Registered device %s for %s\n",
0324             name, s->name);
0325         break;
0326     case VFL_TYPE_VBI:
0327         if (itv->options.kilobytes[type])
0328             IVTV_INFO("Registered device %s for %s (%d kB)\n",
0329                 name, s->name, itv->options.kilobytes[type]);
0330         else
0331             IVTV_INFO("Registered device %s for %s\n",
0332                 name, s->name);
0333         break;
0334     }
0335     return 0;
0336 }
0337 
0338 /* Register v4l2 devices */
0339 int ivtv_streams_register(struct ivtv *itv)
0340 {
0341     int type;
0342     int err = 0;
0343 
0344     /* Register V4L2 devices */
0345     for (type = 0; type < IVTV_MAX_STREAMS; type++)
0346         err |= ivtv_reg_dev(itv, type);
0347 
0348     if (err == 0)
0349         return 0;
0350 
0351     /* One or more streams could not be initialized. Clean 'em all up. */
0352     ivtv_streams_cleanup(itv);
0353     return -ENOMEM;
0354 }
0355 
0356 /* Unregister v4l2 devices */
0357 void ivtv_streams_cleanup(struct ivtv *itv)
0358 {
0359     int type;
0360 
0361     /* Teardown all streams */
0362     for (type = 0; type < IVTV_MAX_STREAMS; type++) {
0363         struct video_device *vdev = &itv->streams[type].vdev;
0364 
0365         if (vdev->v4l2_dev == NULL)
0366             continue;
0367 
0368         video_unregister_device(vdev);
0369         ivtv_stream_free(&itv->streams[type]);
0370         itv->streams[type].vdev.v4l2_dev = NULL;
0371     }
0372 }
0373 
0374 static void ivtv_vbi_setup(struct ivtv *itv)
0375 {
0376     int raw = ivtv_raw_vbi(itv);
0377     u32 data[CX2341X_MBOX_MAX_DATA];
0378     int lines;
0379     int i;
0380 
0381     /* Reset VBI */
0382     ivtv_vapi(itv, CX2341X_ENC_SET_VBI_LINE, 5, 0xffff , 0, 0, 0, 0);
0383 
0384     /* setup VBI registers */
0385     if (raw)
0386         v4l2_subdev_call(itv->sd_video, vbi, s_raw_fmt, &itv->vbi.in.fmt.vbi);
0387     else
0388         v4l2_subdev_call(itv->sd_video, vbi, s_sliced_fmt, &itv->vbi.in.fmt.sliced);
0389 
0390     /* determine number of lines and total number of VBI bytes.
0391        A raw line takes 1443 bytes: 2 * 720 + 4 byte frame header - 1
0392        The '- 1' byte is probably an unused U or V byte. Or something...
0393        A sliced line takes 51 bytes: 4 byte frame header, 4 byte internal
0394        header, 42 data bytes + checksum (to be confirmed) */
0395     if (raw) {
0396         lines = itv->vbi.count * 2;
0397     } else {
0398         lines = itv->is_60hz ? 24 : 38;
0399         if (itv->is_60hz && (itv->hw_flags & IVTV_HW_CX25840))
0400             lines += 2;
0401     }
0402 
0403     itv->vbi.enc_size = lines * (raw ? itv->vbi.raw_size : itv->vbi.sliced_size);
0404 
0405     /* Note: sliced vs raw flag doesn't seem to have any effect
0406        TODO: check mode (0x02) value with older ivtv versions. */
0407     data[0] = raw | 0x02 | (0xbd << 8);
0408 
0409     /* Every X number of frames a VBI interrupt arrives (frames as in 25 or 30 fps) */
0410     data[1] = 1;
0411     /* The VBI frames are stored in a ringbuffer with this size (with a VBI frame as unit) */
0412     data[2] = raw ? 4 : 4 * (itv->vbi.raw_size / itv->vbi.enc_size);
0413     /* The start/stop codes determine which VBI lines end up in the raw VBI data area.
0414        The codes are from table 24 in the saa7115 datasheet. Each raw/sliced/video line
0415        is framed with codes FF0000XX where XX is the SAV/EAV (Start/End of Active Video)
0416        code. These values for raw VBI are obtained from a driver disassembly. The sliced
0417        start/stop codes was deduced from this, but they do not appear in the driver.
0418        Other code pairs that I found are: 0x250E6249/0x13545454 and 0x25256262/0x38137F54.
0419        However, I have no idea what these values are for. */
0420     if (itv->hw_flags & IVTV_HW_CX25840) {
0421         /* Setup VBI for the cx25840 digitizer */
0422         if (raw) {
0423             data[3] = 0x20602060;
0424             data[4] = 0x30703070;
0425         } else {
0426             data[3] = 0xB0F0B0F0;
0427             data[4] = 0xA0E0A0E0;
0428         }
0429         /* Lines per frame */
0430         data[5] = lines;
0431         /* bytes per line */
0432         data[6] = (raw ? itv->vbi.raw_size : itv->vbi.sliced_size);
0433     } else {
0434         /* Setup VBI for the saa7115 digitizer */
0435         if (raw) {
0436             data[3] = 0x25256262;
0437             data[4] = 0x387F7F7F;
0438         } else {
0439             data[3] = 0xABABECEC;
0440             data[4] = 0xB6F1F1F1;
0441         }
0442         /* Lines per frame */
0443         data[5] = lines;
0444         /* bytes per line */
0445         data[6] = itv->vbi.enc_size / lines;
0446     }
0447 
0448     IVTV_DEBUG_INFO(
0449         "Setup VBI API header 0x%08x pkts %d buffs %d ln %d sz %d\n",
0450             data[0], data[1], data[2], data[5], data[6]);
0451 
0452     ivtv_api(itv, CX2341X_ENC_SET_VBI_CONFIG, 7, data);
0453 
0454     /* returns the VBI encoder memory area. */
0455     itv->vbi.enc_start = data[2];
0456     itv->vbi.fpi = data[0];
0457     if (!itv->vbi.fpi)
0458         itv->vbi.fpi = 1;
0459 
0460     IVTV_DEBUG_INFO("Setup VBI start 0x%08x frames %d fpi %d\n",
0461         itv->vbi.enc_start, data[1], itv->vbi.fpi);
0462 
0463     /* select VBI lines.
0464        Note that the sliced argument seems to have no effect. */
0465     for (i = 2; i <= 24; i++) {
0466         int valid;
0467 
0468         if (itv->is_60hz) {
0469             valid = i >= 10 && i < 22;
0470         } else {
0471             valid = i >= 6 && i < 24;
0472         }
0473         ivtv_vapi(itv, CX2341X_ENC_SET_VBI_LINE, 5, i - 1,
0474                 valid, 0 , 0, 0);
0475         ivtv_vapi(itv, CX2341X_ENC_SET_VBI_LINE, 5, (i - 1) | 0x80000000,
0476                 valid, 0, 0, 0);
0477     }
0478 
0479     /* Remaining VBI questions:
0480        - Is it possible to select particular VBI lines only for inclusion in the MPEG
0481        stream? Currently you can only get the first X lines.
0482        - Is mixed raw and sliced VBI possible?
0483        - What's the meaning of the raw/sliced flag?
0484        - What's the meaning of params 2, 3 & 4 of the Select VBI command? */
0485 }
0486 
0487 int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
0488 {
0489     u32 data[CX2341X_MBOX_MAX_DATA];
0490     struct ivtv *itv = s->itv;
0491     int captype = 0, subtype = 0;
0492     int enable_passthrough = 0;
0493 
0494     if (s->vdev.v4l2_dev == NULL)
0495         return -EINVAL;
0496 
0497     IVTV_DEBUG_INFO("Start encoder stream %s\n", s->name);
0498 
0499     switch (s->type) {
0500     case IVTV_ENC_STREAM_TYPE_MPG:
0501         captype = 0;
0502         subtype = 3;
0503 
0504         /* Stop Passthrough */
0505         if (itv->output_mode == OUT_PASSTHROUGH) {
0506             ivtv_passthrough_mode(itv, 0);
0507             enable_passthrough = 1;
0508         }
0509         itv->mpg_data_received = itv->vbi_data_inserted = 0;
0510         itv->dualwatch_jiffies = jiffies;
0511         itv->dualwatch_stereo_mode = v4l2_ctrl_g_ctrl(itv->cxhdl.audio_mode);
0512         itv->search_pack_header = 0;
0513         break;
0514 
0515     case IVTV_ENC_STREAM_TYPE_YUV:
0516         if (itv->output_mode == OUT_PASSTHROUGH) {
0517             captype = 2;
0518             subtype = 11;   /* video+audio+decoder */
0519             break;
0520         }
0521         captype = 1;
0522         subtype = 1;
0523         break;
0524     case IVTV_ENC_STREAM_TYPE_PCM:
0525         captype = 1;
0526         subtype = 2;
0527         break;
0528     case IVTV_ENC_STREAM_TYPE_VBI:
0529         captype = 1;
0530         subtype = 4;
0531 
0532         itv->vbi.frame = 0;
0533         itv->vbi.inserted_frame = 0;
0534         memset(itv->vbi.sliced_mpeg_size,
0535             0, sizeof(itv->vbi.sliced_mpeg_size));
0536         break;
0537     default:
0538         return -EINVAL;
0539     }
0540     s->subtype = subtype;
0541     s->buffers_stolen = 0;
0542 
0543     /* Clear Streamoff flags in case left from last capture */
0544     clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
0545 
0546     if (atomic_read(&itv->capturing) == 0) {
0547         int digitizer;
0548 
0549         /* Always use frame based mode. Experiments have demonstrated that byte
0550            stream based mode results in dropped frames and corruption. Not often,
0551            but occasionally. Many thanks go to Leonard Orb who spent a lot of
0552            effort and time trying to trace the cause of the drop outs. */
0553         /* 1 frame per DMA */
0554         /*ivtv_vapi(itv, CX2341X_ENC_SET_DMA_BLOCK_SIZE, 2, 128, 0); */
0555         ivtv_vapi(itv, CX2341X_ENC_SET_DMA_BLOCK_SIZE, 2, 1, 1);
0556 
0557         /* Stuff from Windows, we don't know what it is */
0558         ivtv_vapi(itv, CX2341X_ENC_SET_VERT_CROP_LINE, 1, 0);
0559         /* According to the docs, this should be correct. However, this is
0560            untested. I don't dare enable this without having tested it.
0561            Only very few old cards actually have this hardware combination.
0562         ivtv_vapi(itv, CX2341X_ENC_SET_VERT_CROP_LINE, 1,
0563             ((itv->hw_flags & IVTV_HW_SAA7114) && itv->is_60hz) ? 10001 : 0);
0564         */
0565         ivtv_vapi(itv, CX2341X_ENC_MISC, 2, 3, !itv->has_cx23415);
0566         ivtv_vapi(itv, CX2341X_ENC_MISC, 2, 8, 0);
0567         ivtv_vapi(itv, CX2341X_ENC_MISC, 2, 4, 1);
0568         ivtv_vapi(itv, CX2341X_ENC_MISC, 1, 12);
0569 
0570         /* assign placeholder */
0571         ivtv_vapi(itv, CX2341X_ENC_SET_PLACEHOLDER, 12,
0572             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
0573 
0574         if (itv->card->hw_all & (IVTV_HW_SAA7115 | IVTV_HW_SAA717X))
0575             digitizer = 0xF1;
0576         else if (itv->card->hw_all & IVTV_HW_SAA7114)
0577             digitizer = 0xEF;
0578         else /* cx25840 */
0579             digitizer = 0x140;
0580 
0581         ivtv_vapi(itv, CX2341X_ENC_SET_NUM_VSYNC_LINES, 2, digitizer, digitizer);
0582 
0583         /* Setup VBI */
0584         if (itv->v4l2_cap & V4L2_CAP_VBI_CAPTURE) {
0585             ivtv_vbi_setup(itv);
0586         }
0587 
0588         /* assign program index info. Mask 7: select I/P/B, Num_req: 400 max */
0589         ivtv_vapi_result(itv, data, CX2341X_ENC_SET_PGM_INDEX_INFO, 2, 7, 400);
0590         itv->pgm_info_offset = data[0];
0591         itv->pgm_info_num = data[1];
0592         itv->pgm_info_write_idx = 0;
0593         itv->pgm_info_read_idx = 0;
0594 
0595         IVTV_DEBUG_INFO("PGM Index at 0x%08x with %d elements\n",
0596                 itv->pgm_info_offset, itv->pgm_info_num);
0597 
0598         /* Setup API for Stream */
0599         cx2341x_handler_setup(&itv->cxhdl);
0600 
0601         /* mute if capturing radio */
0602         if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags))
0603             ivtv_vapi(itv, CX2341X_ENC_MUTE_VIDEO, 1,
0604                 1 | (v4l2_ctrl_g_ctrl(itv->cxhdl.video_mute_yuv) << 8));
0605     }
0606 
0607     /* Vsync Setup */
0608     if (itv->has_cx23415 && !test_and_set_bit(IVTV_F_I_DIG_RST, &itv->i_flags)) {
0609         /* event notification (on) */
0610         ivtv_vapi(itv, CX2341X_ENC_SET_EVENT_NOTIFICATION, 4, 0, 1, IVTV_IRQ_ENC_VIM_RST, -1);
0611         ivtv_clear_irq_mask(itv, IVTV_IRQ_ENC_VIM_RST);
0612     }
0613 
0614     if (atomic_read(&itv->capturing) == 0) {
0615         /* Clear all Pending Interrupts */
0616         ivtv_set_irq_mask(itv, IVTV_IRQ_MASK_CAPTURE);
0617 
0618         clear_bit(IVTV_F_I_EOS, &itv->i_flags);
0619 
0620         cx2341x_handler_set_busy(&itv->cxhdl, 1);
0621 
0622         /* Initialize Digitizer for Capture */
0623         /* Avoid tinny audio problem - ensure audio clocks are going */
0624         v4l2_subdev_call(itv->sd_audio, audio, s_stream, 1);
0625         /* Avoid unpredictable PCI bus hang - disable video clocks */
0626         v4l2_subdev_call(itv->sd_video, video, s_stream, 0);
0627         ivtv_msleep_timeout(300, 0);
0628         ivtv_vapi(itv, CX2341X_ENC_INITIALIZE_INPUT, 0);
0629         v4l2_subdev_call(itv->sd_video, video, s_stream, 1);
0630     }
0631 
0632     /* begin_capture */
0633     if (ivtv_vapi(itv, CX2341X_ENC_START_CAPTURE, 2, captype, subtype))
0634     {
0635         IVTV_DEBUG_WARN( "Error starting capture!\n");
0636         return -EINVAL;
0637     }
0638 
0639     /* Start Passthrough */
0640     if (enable_passthrough) {
0641         ivtv_passthrough_mode(itv, 1);
0642     }
0643 
0644     if (s->type == IVTV_ENC_STREAM_TYPE_VBI)
0645         ivtv_clear_irq_mask(itv, IVTV_IRQ_ENC_VBI_CAP);
0646     else
0647         ivtv_clear_irq_mask(itv, IVTV_IRQ_MASK_CAPTURE);
0648 
0649     /* you're live! sit back and await interrupts :) */
0650     atomic_inc(&itv->capturing);
0651     return 0;
0652 }
0653 EXPORT_SYMBOL(ivtv_start_v4l2_encode_stream);
0654 
0655 static int ivtv_setup_v4l2_decode_stream(struct ivtv_stream *s)
0656 {
0657     u32 data[CX2341X_MBOX_MAX_DATA];
0658     struct ivtv *itv = s->itv;
0659     int datatype;
0660     u16 width;
0661     u16 height;
0662 
0663     if (s->vdev.v4l2_dev == NULL)
0664         return -EINVAL;
0665 
0666     IVTV_DEBUG_INFO("Setting some initial decoder settings\n");
0667 
0668     width = itv->cxhdl.width;
0669     height = itv->cxhdl.height;
0670 
0671     /* set audio mode to left/stereo  for dual/stereo mode. */
0672     ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode);
0673 
0674     /* set number of internal decoder buffers */
0675     ivtv_vapi(itv, CX2341X_DEC_SET_DISPLAY_BUFFERS, 1, 0);
0676 
0677     /* prebuffering */
0678     ivtv_vapi(itv, CX2341X_DEC_SET_PREBUFFERING, 1, 1);
0679 
0680     /* extract from user packets */
0681     ivtv_vapi_result(itv, data, CX2341X_DEC_EXTRACT_VBI, 1, 1);
0682     itv->vbi.dec_start = data[0];
0683 
0684     IVTV_DEBUG_INFO("Decoder VBI RE-Insert start 0x%08x size 0x%08x\n",
0685         itv->vbi.dec_start, data[1]);
0686 
0687     /* set decoder source settings */
0688     /* Data type: 0 = mpeg from host,
0689        1 = yuv from encoder,
0690        2 = yuv_from_host */
0691     switch (s->type) {
0692     case IVTV_DEC_STREAM_TYPE_YUV:
0693         if (itv->output_mode == OUT_PASSTHROUGH) {
0694             datatype = 1;
0695         } else {
0696             /* Fake size to avoid switching video standard */
0697             datatype = 2;
0698             width = 720;
0699             height = itv->is_out_50hz ? 576 : 480;
0700         }
0701         IVTV_DEBUG_INFO("Setup DEC YUV Stream data[0] = %d\n", datatype);
0702         break;
0703     case IVTV_DEC_STREAM_TYPE_MPG:
0704     default:
0705         datatype = 0;
0706         break;
0707     }
0708     if (ivtv_vapi(itv, CX2341X_DEC_SET_DECODER_SOURCE, 4, datatype,
0709             width, height, itv->cxhdl.audio_properties)) {
0710         IVTV_DEBUG_WARN("Couldn't initialize decoder source\n");
0711     }
0712 
0713     /* Decoder sometimes dies here, so wait a moment */
0714     ivtv_msleep_timeout(10, 0);
0715 
0716     /* Known failure point for firmware, so check */
0717     return ivtv_firmware_check(itv, "ivtv_setup_v4l2_decode_stream");
0718 }
0719 
0720 int ivtv_start_v4l2_decode_stream(struct ivtv_stream *s, int gop_offset)
0721 {
0722     struct ivtv *itv = s->itv;
0723     int rc;
0724 
0725     if (s->vdev.v4l2_dev == NULL)
0726         return -EINVAL;
0727 
0728     if (test_and_set_bit(IVTV_F_S_STREAMING, &s->s_flags))
0729         return 0;   /* already started */
0730 
0731     IVTV_DEBUG_INFO("Starting decode stream %s (gop_offset %d)\n", s->name, gop_offset);
0732 
0733     rc = ivtv_setup_v4l2_decode_stream(s);
0734     if (rc < 0) {
0735         clear_bit(IVTV_F_S_STREAMING, &s->s_flags);
0736         return rc;
0737     }
0738 
0739     /* set dma size to 65536 bytes */
0740     ivtv_vapi(itv, CX2341X_DEC_SET_DMA_BLOCK_SIZE, 1, 65536);
0741 
0742     /* Clear Streamoff */
0743     clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
0744 
0745     /* Zero out decoder counters */
0746     writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_DMA_END].data[0]);
0747     writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_DMA_END].data[1]);
0748     writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_DMA_END].data[2]);
0749     writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_DMA_END].data[3]);
0750     writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_DMA].data[0]);
0751     writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_DMA].data[1]);
0752     writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_DMA].data[2]);
0753     writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_DMA].data[3]);
0754 
0755     /* turn on notification of dual/stereo mode change */
0756     ivtv_vapi(itv, CX2341X_DEC_SET_EVENT_NOTIFICATION, 4, 0, 1, IVTV_IRQ_DEC_AUD_MODE_CHG, -1);
0757 
0758     /* start playback */
0759     ivtv_vapi(itv, CX2341X_DEC_START_PLAYBACK, 2, gop_offset, 0);
0760 
0761     /* Let things settle before we actually start */
0762     ivtv_msleep_timeout(10, 0);
0763 
0764     /* Clear the following Interrupt mask bits for decoding */
0765     ivtv_clear_irq_mask(itv, IVTV_IRQ_MASK_DECODE);
0766     IVTV_DEBUG_IRQ("IRQ Mask is now: 0x%08x\n", itv->irqmask);
0767 
0768     /* you're live! sit back and await interrupts :) */
0769     atomic_inc(&itv->decoding);
0770     return 0;
0771 }
0772 
0773 void ivtv_stop_all_captures(struct ivtv *itv)
0774 {
0775     int i;
0776 
0777     for (i = IVTV_MAX_STREAMS - 1; i >= 0; i--) {
0778         struct ivtv_stream *s = &itv->streams[i];
0779 
0780         if (s->vdev.v4l2_dev == NULL)
0781             continue;
0782         if (test_bit(IVTV_F_S_STREAMING, &s->s_flags)) {
0783             ivtv_stop_v4l2_encode_stream(s, 0);
0784         }
0785     }
0786 }
0787 
0788 int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end)
0789 {
0790     struct ivtv *itv = s->itv;
0791     DECLARE_WAITQUEUE(wait, current);
0792     int cap_type;
0793     int stopmode;
0794 
0795     if (s->vdev.v4l2_dev == NULL)
0796         return -EINVAL;
0797 
0798     /* This function assumes that you are allowed to stop the capture
0799        and that we are actually capturing */
0800 
0801     IVTV_DEBUG_INFO("Stop Capture\n");
0802 
0803     if (s->type == IVTV_DEC_STREAM_TYPE_VOUT)
0804         return 0;
0805     if (atomic_read(&itv->capturing) == 0)
0806         return 0;
0807 
0808     switch (s->type) {
0809     case IVTV_ENC_STREAM_TYPE_YUV:
0810         cap_type = 1;
0811         break;
0812     case IVTV_ENC_STREAM_TYPE_PCM:
0813         cap_type = 1;
0814         break;
0815     case IVTV_ENC_STREAM_TYPE_VBI:
0816         cap_type = 1;
0817         break;
0818     case IVTV_ENC_STREAM_TYPE_MPG:
0819     default:
0820         cap_type = 0;
0821         break;
0822     }
0823 
0824     /* Stop Capture Mode */
0825     if (s->type == IVTV_ENC_STREAM_TYPE_MPG && gop_end) {
0826         stopmode = 0;
0827     } else {
0828         stopmode = 1;
0829     }
0830 
0831     /* end_capture */
0832     /* when: 0 =  end of GOP  1 = NOW!, type: 0 = mpeg, subtype: 3 = video+audio */
0833     ivtv_vapi(itv, CX2341X_ENC_STOP_CAPTURE, 3, stopmode, cap_type, s->subtype);
0834 
0835     if (!test_bit(IVTV_F_S_PASSTHROUGH, &s->s_flags)) {
0836         if (s->type == IVTV_ENC_STREAM_TYPE_MPG && gop_end) {
0837             /* only run these if we're shutting down the last cap */
0838             unsigned long duration;
0839             unsigned long then = jiffies;
0840 
0841             add_wait_queue(&itv->eos_waitq, &wait);
0842 
0843             set_current_state(TASK_INTERRUPTIBLE);
0844 
0845             /* wait 2s for EOS interrupt */
0846             while (!test_bit(IVTV_F_I_EOS, &itv->i_flags) &&
0847                 time_before(jiffies,
0848                         then + msecs_to_jiffies(2000))) {
0849                 schedule_timeout(msecs_to_jiffies(10));
0850             }
0851 
0852             /* To convert jiffies to ms, we must multiply by 1000
0853              * and divide by HZ.  To avoid runtime division, we
0854              * convert this to multiplication by 1000/HZ.
0855              * Since integer division truncates, we get the best
0856              * accuracy if we do a rounding calculation of the constant.
0857              * Think of the case where HZ is 1024.
0858              */
0859             duration = ((1000 + HZ / 2) / HZ) * (jiffies - then);
0860 
0861             if (!test_bit(IVTV_F_I_EOS, &itv->i_flags)) {
0862                 IVTV_DEBUG_WARN("%s: EOS interrupt not received! stopping anyway.\n", s->name);
0863                 IVTV_DEBUG_WARN("%s: waited %lu ms.\n", s->name, duration);
0864             } else {
0865                 IVTV_DEBUG_INFO("%s: EOS took %lu ms to occur.\n", s->name, duration);
0866             }
0867             set_current_state(TASK_RUNNING);
0868             remove_wait_queue(&itv->eos_waitq, &wait);
0869             set_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
0870         }
0871 
0872         /* Handle any pending interrupts */
0873         ivtv_msleep_timeout(100, 0);
0874     }
0875 
0876     atomic_dec(&itv->capturing);
0877 
0878     /* Clear capture and no-read bits */
0879     clear_bit(IVTV_F_S_STREAMING, &s->s_flags);
0880 
0881     if (s->type == IVTV_ENC_STREAM_TYPE_VBI)
0882         ivtv_set_irq_mask(itv, IVTV_IRQ_ENC_VBI_CAP);
0883 
0884     if (atomic_read(&itv->capturing) > 0) {
0885         return 0;
0886     }
0887 
0888     cx2341x_handler_set_busy(&itv->cxhdl, 0);
0889 
0890     /* Set the following Interrupt mask bits for capture */
0891     ivtv_set_irq_mask(itv, IVTV_IRQ_MASK_CAPTURE);
0892     del_timer(&itv->dma_timer);
0893 
0894     /* event notification (off) */
0895     if (test_and_clear_bit(IVTV_F_I_DIG_RST, &itv->i_flags)) {
0896         /* type: 0 = refresh */
0897         /* on/off: 0 = off, intr: 0x10000000, mbox_id: -1: none */
0898         ivtv_vapi(itv, CX2341X_ENC_SET_EVENT_NOTIFICATION, 4, 0, 0, IVTV_IRQ_ENC_VIM_RST, -1);
0899         ivtv_set_irq_mask(itv, IVTV_IRQ_ENC_VIM_RST);
0900     }
0901 
0902     /* Raw-passthrough is implied on start. Make sure it's stopped so
0903        the encoder will re-initialize when next started */
0904     ivtv_vapi(itv, CX2341X_ENC_STOP_CAPTURE, 3, 1, 2, 7);
0905 
0906     wake_up(&s->waitq);
0907 
0908     return 0;
0909 }
0910 EXPORT_SYMBOL(ivtv_stop_v4l2_encode_stream);
0911 
0912 int ivtv_stop_v4l2_decode_stream(struct ivtv_stream *s, int flags, u64 pts)
0913 {
0914     static const struct v4l2_event ev = {
0915         .type = V4L2_EVENT_EOS,
0916     };
0917     struct ivtv *itv = s->itv;
0918 
0919     if (s->vdev.v4l2_dev == NULL)
0920         return -EINVAL;
0921 
0922     if (s->type != IVTV_DEC_STREAM_TYPE_YUV && s->type != IVTV_DEC_STREAM_TYPE_MPG)
0923         return -EINVAL;
0924 
0925     if (!test_bit(IVTV_F_S_STREAMING, &s->s_flags))
0926         return 0;
0927 
0928     IVTV_DEBUG_INFO("Stop Decode at %llu, flags: %x\n", (unsigned long long)pts, flags);
0929 
0930     /* Stop Decoder */
0931     if (!(flags & V4L2_DEC_CMD_STOP_IMMEDIATELY) || pts) {
0932         u32 tmp = 0;
0933 
0934         /* Wait until the decoder is no longer running */
0935         if (pts) {
0936             ivtv_vapi(itv, CX2341X_DEC_STOP_PLAYBACK, 3,
0937                 0, (u32)(pts & 0xffffffff), (u32)(pts >> 32));
0938         }
0939         while (1) {
0940             u32 data[CX2341X_MBOX_MAX_DATA];
0941             ivtv_vapi_result(itv, data, CX2341X_DEC_GET_XFER_INFO, 0);
0942             if (s->q_full.buffers + s->q_dma.buffers == 0) {
0943                 if (tmp == data[3])
0944                     break;
0945                 tmp = data[3];
0946             }
0947             if (ivtv_msleep_timeout(100, 1))
0948                 break;
0949         }
0950     }
0951     ivtv_vapi(itv, CX2341X_DEC_STOP_PLAYBACK, 3, flags & V4L2_DEC_CMD_STOP_TO_BLACK, 0, 0);
0952 
0953     /* turn off notification of dual/stereo mode change */
0954     ivtv_vapi(itv, CX2341X_DEC_SET_EVENT_NOTIFICATION, 4, 0, 0, IVTV_IRQ_DEC_AUD_MODE_CHG, -1);
0955 
0956     ivtv_set_irq_mask(itv, IVTV_IRQ_MASK_DECODE);
0957     del_timer(&itv->dma_timer);
0958 
0959     clear_bit(IVTV_F_S_NEEDS_DATA, &s->s_flags);
0960     clear_bit(IVTV_F_S_STREAMING, &s->s_flags);
0961     ivtv_flush_queues(s);
0962 
0963     /* decoder needs time to settle */
0964     ivtv_msleep_timeout(40, 0);
0965 
0966     /* decrement decoding */
0967     atomic_dec(&itv->decoding);
0968 
0969     set_bit(IVTV_F_I_EV_DEC_STOPPED, &itv->i_flags);
0970     wake_up(&itv->event_waitq);
0971     v4l2_event_queue(&s->vdev, &ev);
0972 
0973     /* wake up wait queues */
0974     wake_up(&s->waitq);
0975 
0976     return 0;
0977 }
0978 
0979 int ivtv_passthrough_mode(struct ivtv *itv, int enable)
0980 {
0981     struct ivtv_stream *yuv_stream = &itv->streams[IVTV_ENC_STREAM_TYPE_YUV];
0982     struct ivtv_stream *dec_stream = &itv->streams[IVTV_DEC_STREAM_TYPE_YUV];
0983 
0984     if (yuv_stream->vdev.v4l2_dev == NULL || dec_stream->vdev.v4l2_dev == NULL)
0985         return -EINVAL;
0986 
0987     IVTV_DEBUG_INFO("ivtv ioctl: Select passthrough mode\n");
0988 
0989     /* Prevent others from starting/stopping streams while we
0990        initiate/terminate passthrough mode */
0991     if (enable) {
0992         if (itv->output_mode == OUT_PASSTHROUGH) {
0993             return 0;
0994         }
0995         if (ivtv_set_output_mode(itv, OUT_PASSTHROUGH) != OUT_PASSTHROUGH)
0996             return -EBUSY;
0997 
0998         /* Fully initialize stream, and then unflag init */
0999         set_bit(IVTV_F_S_PASSTHROUGH, &dec_stream->s_flags);
1000         set_bit(IVTV_F_S_STREAMING, &dec_stream->s_flags);
1001 
1002         /* Setup YUV Decoder */
1003         ivtv_setup_v4l2_decode_stream(dec_stream);
1004 
1005         /* Start Decoder */
1006         ivtv_vapi(itv, CX2341X_DEC_START_PLAYBACK, 2, 0, 1);
1007         atomic_inc(&itv->decoding);
1008 
1009         /* Setup capture if not already done */
1010         if (atomic_read(&itv->capturing) == 0) {
1011             cx2341x_handler_setup(&itv->cxhdl);
1012             cx2341x_handler_set_busy(&itv->cxhdl, 1);
1013         }
1014 
1015         /* Start Passthrough Mode */
1016         ivtv_vapi(itv, CX2341X_ENC_START_CAPTURE, 2, 2, 11);
1017         atomic_inc(&itv->capturing);
1018         return 0;
1019     }
1020 
1021     if (itv->output_mode != OUT_PASSTHROUGH)
1022         return 0;
1023 
1024     /* Stop Passthrough Mode */
1025     ivtv_vapi(itv, CX2341X_ENC_STOP_CAPTURE, 3, 1, 2, 11);
1026     ivtv_vapi(itv, CX2341X_DEC_STOP_PLAYBACK, 3, 1, 0, 0);
1027 
1028     atomic_dec(&itv->capturing);
1029     atomic_dec(&itv->decoding);
1030     clear_bit(IVTV_F_S_PASSTHROUGH, &dec_stream->s_flags);
1031     clear_bit(IVTV_F_S_STREAMING, &dec_stream->s_flags);
1032     itv->output_mode = OUT_NONE;
1033     if (atomic_read(&itv->capturing) == 0)
1034         cx2341x_handler_set_busy(&itv->cxhdl, 0);
1035 
1036     return 0;
1037 }