vserver 1.9.5.x5
[linux-2.6.git] / drivers / media / dvb / ttpci / av7110_av.c
index 054e2e9..f875efc 100644 (file)
 #include <linux/smp_lock.h>
 #include <linux/fs.h>
 
-#define DEBUG_VARIABLE av7110_debug
-extern int av7110_debug;
-
 #include "av7110.h"
 #include "av7110_hw.h"
 #include "av7110_av.h"
 #include "av7110_ipack.h"
-#include "dvb_functions.h"
 
 /* MPEG-2 (ISO 13818 / H.222.0) stream types */
 #define PROG_STREAM_MAP  0xBC
@@ -102,14 +98,12 @@ int av7110_record_cb(struct dvb_filter_pes2ts *p2t, u8 *buf, size_t len)
 {
        struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) p2t->priv;
 
-//     DEB_EE(("struct dvb_filter_pes2ts:%p\n", p2t));
-
        if (!(dvbdmxfeed->ts_type & TS_PACKET))
                return 0;
        if (buf[3] == 0xe0)      // video PES do not have a length in TS
                buf[4] = buf[5] = 0;
        if (dvbdmxfeed->ts_type & TS_PAYLOAD_ONLY)
-               return dvbdmxfeed->cb.ts(buf, len, 0, 0,
+               return dvbdmxfeed->cb.ts(buf, len, NULL, 0,
                                         &dvbdmxfeed->feed.ts, DMX_OK);
        else
                return dvb_filter_pes2ts(p2t, buf, len, 1);
@@ -119,9 +113,7 @@ static int dvb_filter_pes2ts_cb(void *priv, unsigned char *data)
 {
        struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) priv;
 
-//     DEB_EE(("dvb_demux_feed:%p\n", dvbdmxfeed));
-
-       dvbdmxfeed->cb.ts(data, 188, 0, 0,
+       dvbdmxfeed->cb.ts(data, 188, NULL, 0,
                          &dvbdmxfeed->feed.ts, DMX_OK);
        return 0;
 }
@@ -131,7 +123,7 @@ int av7110_av_start_record(struct av7110 *av7110, int av,
 {
        struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
 
-       DEB_EE(("av7110: %p, dvb_demux_feed:%p\n", av7110, dvbdmxfeed));
+       dprintk(2, "av7110:%p, , dvb_demux_feed:%p\n", av7110, dvbdmxfeed);
 
        if (av7110->playing || (av7110->rec_mode & av))
                return -EBUSY;
@@ -173,7 +165,7 @@ int av7110_av_start_record(struct av7110 *av7110, int av,
 
 int av7110_av_start_play(struct av7110 *av7110, int av)
 {
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
 
        if (av7110->rec_mode)
                return -EBUSY;
@@ -206,7 +198,7 @@ int av7110_av_start_play(struct av7110 *av7110, int av)
 
 void av7110_av_stop(struct av7110 *av7110, int av)
 {
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
 
        if (!(av7110->playing & av) && !(av7110->rec_mode & av))
                return;
@@ -247,8 +239,6 @@ int av7110_pes_play(void *dest, struct dvb_ringbuffer *buf, int dlen)
        u32 sync;
        u16 blen;
 
-       DEB_EE(("dvb_ring_buffer_t: %p\n", buf));
-
        if (!dlen) {
                wake_up(&buf->queue);
                return -1;
@@ -279,8 +269,8 @@ int av7110_pes_play(void *dest, struct dvb_ringbuffer *buf, int dlen)
 
        dvb_ringbuffer_read(buf, dest, (size_t) blen, 0);
 
-       DEB_S(("pread=0x%08lx, pwrite=0x%08lx\n",
-              (unsigned long) buf->pread, (unsigned long) buf->pwrite));
+       dprintk(2, "pread=0x%08lx, pwrite=0x%08lx\n",
+              (unsigned long) buf->pread, (unsigned long) buf->pwrite);
        wake_up(&buf->queue);
        return blen;
 }
@@ -290,7 +280,10 @@ int av7110_set_volume(struct av7110 *av7110, int volleft, int volright)
 {
        int err, vol, val, balance = 0;
 
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
+
+       av7110->mixer.volume_left = volleft;
+       av7110->mixer.volume_right = volright;
 
        switch (av7110->adac_type) {
        case DVB_ADAC_TI:
@@ -326,7 +319,7 @@ int av7110_set_volume(struct av7110 *av7110, int volleft, int volright)
 
 void av7110_set_vidmode(struct av7110 *av7110, int mode)
 {
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
 
        av7110_fw_cmd(av7110, COMTYPE_ENCODER, LoadVidCode, 1, mode);
 
@@ -354,7 +347,7 @@ static void get_video_format(struct av7110 *av7110, u8 *buf, int count)
        int sw;
        u8 *p;
 
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
 
        if (av7110->sinfo)
                return;
@@ -367,7 +360,7 @@ static void get_video_format(struct av7110 *av7110, u8 *buf, int count)
                vsize = ((p[1] &0x0F) << 8) | (p[2]);
                sw = (p[3] & 0x0F);
                av7110_set_vidmode(av7110, sw2mode[sw]);
-               DEB_S(("dvb: playback %dx%d fr=%d\n", hsize, vsize, sw));
+               dprintk(2, "playback %dx%d fr=%d\n", hsize, vsize, sw);
                av7110->sinfo = 1;
                break;
        }
@@ -393,7 +386,7 @@ static inline long aux_ring_buffer_write(struct dvb_ringbuffer *rbuf,
                free = dvb_ringbuffer_free(rbuf);
                if (free > todo)
                        free = todo;
-               dvb_ringbuffer_write(rbuf, buf, free, 0);
+               dvb_ringbuffer_write(rbuf, buf, free);
                todo -= free;
                buf += free;
        }
@@ -404,7 +397,7 @@ static inline long aux_ring_buffer_write(struct dvb_ringbuffer *rbuf,
 static void play_video_cb(u8 *buf, int count, void *priv)
 {
        struct av7110 *av7110 = (struct av7110 *) priv;
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
 
        if ((buf[3] & 0xe0) == 0xe0) {
                get_video_format(av7110, buf, count);
@@ -416,7 +409,7 @@ static void play_video_cb(u8 *buf, int count, void *priv)
 static void play_audio_cb(u8 *buf, int count, void *priv)
 {
        struct av7110 *av7110 = (struct av7110 *) priv;
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
 
        aux_ring_buffer_write(&av7110->aout, buf, count);
 }
@@ -424,11 +417,11 @@ static void play_audio_cb(u8 *buf, int count, void *priv)
 #define FREE_COND (dvb_ringbuffer_free(&av7110->avout) >= 20 * 1024 && \
                   dvb_ringbuffer_free(&av7110->aout) >= 20 * 1024)
 
-static ssize_t dvb_play(struct av7110 *av7110, const u8 *buf,
-                       unsigned long count, int nonblock, int type, int umem)
+static ssize_t dvb_play(struct av7110 *av7110, const u8 __user *buf,
+                       unsigned long count, int nonblock, int type)
 {
        unsigned long todo = count, n;
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
 
        if (!av7110->kbuf[type])
                return -ENOBUFS;
@@ -447,26 +440,51 @@ static ssize_t dvb_play(struct av7110 *av7110, const u8 *buf,
                n = todo;
                if (n > IPACKS * 2)
                        n = IPACKS * 2;
-               if (umem) {
-                       if (copy_from_user(av7110->kbuf[type], buf, n))
-                               return -EFAULT;
-                       av7110_ipack_instant_repack(av7110->kbuf[type], n,
-                                                   &av7110->ipack[type]);
-               } else {
-                       av7110_ipack_instant_repack(buf, n,
-                                                   &av7110->ipack[type]);
+               if (copy_from_user(av7110->kbuf[type], buf, n))
+                       return -EFAULT;
+               av7110_ipack_instant_repack(av7110->kbuf[type], n,
+                                           &av7110->ipack[type]);
+               todo -= n;
+               buf += n;
+       }
+       return count - todo;
+}
+
+static ssize_t dvb_play_kernel(struct av7110 *av7110, const u8 *buf,
+                       unsigned long count, int nonblock, int type)
+{
+       unsigned long todo = count, n;
+       dprintk(2, "av7110:%p, \n", av7110);
+
+       if (!av7110->kbuf[type])
+               return -ENOBUFS;
+
+       if (nonblock && !FREE_COND)
+               return -EWOULDBLOCK;
+
+       while (todo > 0) {
+               if (!FREE_COND) {
+                       if (nonblock)
+                               return count - todo;
+                       if (wait_event_interruptible(av7110->avout.queue,
+                                                    FREE_COND))
+                               return count - todo;
                }
+               n = todo;
+               if (n > IPACKS * 2)
+                       n = IPACKS * 2;
+               av7110_ipack_instant_repack(buf, n, &av7110->ipack[type]);
                todo -= n;
                buf += n;
        }
        return count - todo;
 }
 
-static ssize_t dvb_aplay(struct av7110 *av7110, const u8 *buf,
+static ssize_t dvb_aplay(struct av7110 *av7110, const u8 __user *buf,
                         unsigned long count, int nonblock, int type)
 {
        unsigned long todo = count, n;
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
 
        if (!av7110->kbuf[type])
                return -ENOBUFS;
@@ -656,7 +674,7 @@ void av7110_p2t_write(u8 const *buf, long int length, u16 pid, struct av7110_p2t
 }
 
 
-int write_ts_header2(u16 pid, u8 *counter, int pes_start, u8 *buf, u8 length)
+static int write_ts_header2(u16 pid, u8 *counter, int pes_start, u8 *buf, u8 length)
 {
        int i;
        int c = 0;
@@ -733,7 +751,7 @@ static void p_to_t(u8 const *buf, long int length, u16 pid, u8 *counter,
                        memcpy(obuf + l, buf + c, TS_SIZE - l);
                        c = length;
                }
-               feed->cb.ts(obuf, 188, 0, 0, &feed->feed.ts, DMX_OK);
+               feed->cb.ts(obuf, 188, NULL, 0, &feed->feed.ts, DMX_OK);
                pes_start = 0;
        }
 }
@@ -745,7 +763,7 @@ int av7110_write_to_decoder(struct dvb_demux_feed *feed, const u8 *buf, size_t l
        struct av7110 *av7110 = (struct av7110 *) demux->priv;
        struct ipack *ipack = &av7110->ipack[feed->pes_type];
 
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
 
        switch (feed->pes_type) {
        case 0:
@@ -786,8 +804,6 @@ void dvb_video_add_event(struct av7110 *av7110, struct video_event *event)
        struct dvb_video_events *events = &av7110->video_events;
        int wp;
 
-       DEB_D(("\n"));
-
        spin_lock_bh(&events->lock);
 
        wp = (events->eventw + 1) % MAX_VIDEO_EVENT;
@@ -810,8 +826,6 @@ static int dvb_video_get_event (struct av7110 *av7110, struct video_event *event
 {
        struct dvb_video_events *events = &av7110->video_events;
 
-       DEB_D(("\n"));
-
        if (events->overflow) {
                events->overflow = 0;
                return -EOVERFLOW;
@@ -850,7 +864,7 @@ static unsigned int dvb_video_poll(struct file *file, poll_table *wait)
        struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
        unsigned int mask = 0;
 
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
 
        if ((file->f_flags & O_ACCMODE) != O_RDONLY)
                poll_wait(file, &av7110->avout.queue, wait);
@@ -871,13 +885,13 @@ static unsigned int dvb_video_poll(struct file *file, poll_table *wait)
        return mask;
 }
 
-static ssize_t dvb_video_write(struct file *file, const char *buf,
+static ssize_t dvb_video_write(struct file *file, const char __user *buf,
                               size_t count, loff_t *ppos)
 {
        struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
        struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
 
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
 
        if ((file->f_flags & O_ACCMODE) == O_RDONLY)
                return -EPERM;
@@ -885,7 +899,7 @@ static ssize_t dvb_video_write(struct file *file, const char *buf,
        if (av7110->videostate.stream_source != VIDEO_SOURCE_MEMORY)
                return -EPERM;
 
-       return dvb_play(av7110, buf, count, file->f_flags & O_NONBLOCK, 1, 1);
+       return dvb_play(av7110, buf, count, file->f_flags & O_NONBLOCK, 1);
 }
 
 static unsigned int dvb_audio_poll(struct file *file, poll_table *wait)
@@ -894,7 +908,7 @@ static unsigned int dvb_audio_poll(struct file *file, poll_table *wait)
        struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
        unsigned int mask = 0;
 
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
 
        poll_wait(file, &av7110->aout.queue, wait);
 
@@ -907,13 +921,13 @@ static unsigned int dvb_audio_poll(struct file *file, poll_table *wait)
        return mask;
 }
 
-static ssize_t dvb_audio_write(struct file *file, const char *buf,
+static ssize_t dvb_audio_write(struct file *file, const char __user *buf,
                               size_t count, loff_t *ppos)
 {
        struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
        struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
 
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
 
        if (av7110->audiostate.stream_source != AUDIO_SOURCE_MEMORY) {
                printk(KERN_ERR "not audio source memory\n");
@@ -922,15 +936,15 @@ static ssize_t dvb_audio_write(struct file *file, const char *buf,
        return dvb_aplay(av7110, buf, count, file->f_flags & O_NONBLOCK, 0);
 }
 
-u8 iframe_header[] = { 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x80, 0x00, 0x00 };
+static u8 iframe_header[] = { 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x80, 0x00, 0x00 };
 
 #define MIN_IFRAME 400000
 
-static int play_iframe(struct av7110 *av7110, u8 *buf, unsigned int len, int nonblock)
+static int play_iframe(struct av7110 *av7110, u8 __user *buf, unsigned int len, int nonblock)
 {
        int i, n;
 
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
 
        if (!(av7110->playing & RP_VIDEO)) {
                if (av7110_av_start_play(av7110, RP_VIDEO) < 0)
@@ -942,10 +956,10 @@ static int play_iframe(struct av7110 *av7110, u8 *buf, unsigned int len, int non
        n = MIN_IFRAME / len + 1;
 
        /* FIXME: nonblock? */
-       dvb_play(av7110, iframe_header, sizeof(iframe_header), 0, 1, 0);
+       dvb_play_kernel(av7110, iframe_header, sizeof(iframe_header), 0, 1);
 
        for (i = 0; i < n; i++)
-               dvb_play(av7110, buf, len, 0, 1, 1);
+               dvb_play(av7110, buf, len, 0, 1);
 
        av7110_ipack_flush(&av7110->ipack[1]);
        return 0;
@@ -960,7 +974,7 @@ static int dvb_video_ioctl(struct inode *inode, struct file *file,
        unsigned long arg = (unsigned long) parg;
        int ret = 0;
 
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
 
        if ((file->f_flags & O_ACCMODE) == O_RDONLY) {
                if ( cmd != VIDEO_GET_STATUS && cmd != VIDEO_GET_EVENT &&
@@ -1156,7 +1170,7 @@ static int dvb_audio_ioctl(struct inode *inode, struct file *file,
        unsigned long arg = (unsigned long) parg;
        int ret = 0;
 
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
 
        if (((file->f_flags & O_ACCMODE) == O_RDONLY) &&
            (cmd != AUDIO_GET_STATUS))
@@ -1272,7 +1286,7 @@ static int dvb_video_open(struct inode *inode, struct file *file)
        struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
        int err;
 
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
 
        if ((err = dvb_generic_open(inode, file)) < 0)
                return err;
@@ -1296,7 +1310,7 @@ static int dvb_video_release(struct inode *inode, struct file *file)
        struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
        struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
 
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
 
        if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
                av7110_av_stop(av7110, RP_VIDEO);
@@ -1311,7 +1325,7 @@ static int dvb_audio_open(struct inode *inode, struct file *file)
        struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
        int err=dvb_generic_open(inode, file);
 
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
 
        if (err < 0)
                return err;
@@ -1325,7 +1339,7 @@ static int dvb_audio_release(struct inode *inode, struct file *file)
        struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
        struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
 
-       DEB_EE(("av7110: %p\n", av7110));
+       dprintk(2, "av7110:%p, \n", av7110);
 
        av7110_av_stop(av7110, RP_AUDIO);
        return dvb_generic_release(inode, file);
@@ -1347,7 +1361,7 @@ static struct file_operations dvb_video_fops = {
 };
 
 static struct dvb_device dvbdev_video = {
-       .priv           = 0,
+       .priv           = NULL,
        .users          = 6,
        .readers        = 5,    /* arbitrary */
        .writers        = 1,
@@ -1365,7 +1379,7 @@ static struct file_operations dvb_audio_fops = {
 };
 
 static struct dvb_device dvbdev_audio = {
-       .priv           = 0,
+       .priv           = NULL,
        .users          = 1,
        .writers        = 1,
        .fops           = &dvb_audio_fops,