V4L/DVB (7186): tda10086: make the 22kHz tone for DISEQC a config option
[safe/jmp/linux-2.6] / drivers / media / dvb / ttpci / av7110_av.c
index bbfad6d..3e6b650 100644 (file)
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/string.h>
-#include <linux/sched.h>
 #include <linux/delay.h>
-#include <linux/byteorder/swabb.h>
-#include <linux/smp_lock.h>
 #include <linux/fs.h>
 
 #include "av7110.h"
@@ -309,7 +306,7 @@ int av7110_set_volume(struct av7110 *av7110, int volleft, int volright)
                i2c_writereg(av7110, 0x20, 0x04, volright);
                return 0;
 
-       case DVB_ADAC_MSP:
+       case DVB_ADAC_MSP34x0:
                vol  = (volleft > volright) ? volleft : volright;
                val     = (vol * 0x73 / 255) << 8;
                if (vol > 0)
@@ -318,11 +315,21 @@ int av7110_set_volume(struct av7110 *av7110, int volleft, int volright)
                msp_writereg(av7110, MSP_WR_DSP, 0x0000, val); /* loudspeaker */
                msp_writereg(av7110, MSP_WR_DSP, 0x0006, val); /* headphonesr */
                return 0;
+
+       case DVB_ADAC_MSP34x5:
+               vol = (volleft > volright) ? volleft : volright;
+               val = (vol * 0x73 / 255) << 8;
+               if (vol > 0)
+                       balance = ((volright - volleft) * 127) / vol;
+               msp_writereg(av7110, MSP_WR_DSP, 0x0001, balance << 8);
+               msp_writereg(av7110, MSP_WR_DSP, 0x0000, val); /* loudspeaker */
+               return 0;
        }
+
        return 0;
 }
 
-int av7110_set_vidmode(struct av7110 *av7110, int mode)
+int av7110_set_vidmode(struct av7110 *av7110, enum av7110_video_mode mode)
 {
        int ret;
        dprintk(2, "av7110:%p, \n", av7110);
@@ -341,11 +348,15 @@ int av7110_set_vidmode(struct av7110 *av7110, int mode)
 }
 
 
-static int sw2mode[16] = {
-       VIDEO_MODE_PAL, VIDEO_MODE_NTSC, VIDEO_MODE_NTSC, VIDEO_MODE_PAL,
-       VIDEO_MODE_NTSC, VIDEO_MODE_NTSC, VIDEO_MODE_PAL, VIDEO_MODE_NTSC,
-       VIDEO_MODE_PAL, VIDEO_MODE_PAL, VIDEO_MODE_PAL, VIDEO_MODE_PAL,
-       VIDEO_MODE_PAL, VIDEO_MODE_PAL, VIDEO_MODE_PAL, VIDEO_MODE_PAL,
+static enum av7110_video_mode sw2mode[16] = {
+       AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_NTSC,
+       AV7110_VIDEO_MODE_NTSC, AV7110_VIDEO_MODE_PAL,
+       AV7110_VIDEO_MODE_NTSC, AV7110_VIDEO_MODE_NTSC,
+       AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_NTSC,
+       AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_PAL,
+       AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_PAL,
+       AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_PAL,
+       AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_PAL,
 };
 
 static int get_video_format(struct av7110 *av7110, u8 *buf, int count)
@@ -384,7 +395,7 @@ static int get_video_format(struct av7110 *av7110, u8 *buf, int count)
  ****************************************************************************/
 
 static inline long aux_ring_buffer_write(struct dvb_ringbuffer *rbuf,
-                                        const char *buf, unsigned long count)
+                                        const u8 *buf, unsigned long count)
 {
        unsigned long todo = count;
        int free;
@@ -429,7 +440,7 @@ 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 __user *buf,
+static ssize_t dvb_play(struct av7110 *av7110, const char __user *buf,
                        unsigned long count, int nonblock, int type)
 {
        unsigned long todo = count, n;
@@ -492,7 +503,7 @@ static ssize_t dvb_play_kernel(struct av7110 *av7110, const u8 *buf,
        return count - todo;
 }
 
-static ssize_t dvb_aplay(struct av7110 *av7110, const u8 __user *buf,
+static ssize_t dvb_aplay(struct av7110 *av7110, const char __user *buf,
                         unsigned long count, int nonblock, int type)
 {
        unsigned long todo = count, n;
@@ -872,8 +883,8 @@ static int dvb_video_get_event (struct av7110 *av7110, struct video_event *event
 
 static unsigned int dvb_video_poll(struct file *file, poll_table *wait)
 {
-       struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
-       struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
+       struct dvb_device *dvbdev = file->private_data;
+       struct av7110 *av7110 = dvbdev->priv;
        unsigned int mask = 0;
 
        dprintk(2, "av7110:%p, \n", av7110);
@@ -900,8 +911,8 @@ static unsigned int dvb_video_poll(struct file *file, poll_table *wait)
 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;
+       struct dvb_device *dvbdev = file->private_data;
+       struct av7110 *av7110 = dvbdev->priv;
 
        dprintk(2, "av7110:%p, \n", av7110);
 
@@ -916,8 +927,8 @@ static ssize_t dvb_video_write(struct file *file, const char __user *buf,
 
 static unsigned int dvb_audio_poll(struct file *file, poll_table *wait)
 {
-       struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
-       struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
+       struct dvb_device *dvbdev = file->private_data;
+       struct av7110 *av7110 = dvbdev->priv;
        unsigned int mask = 0;
 
        dprintk(2, "av7110:%p, \n", av7110);
@@ -936,8 +947,8 @@ static unsigned int dvb_audio_poll(struct file *file, poll_table *wait)
 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;
+       struct dvb_device *dvbdev = file->private_data;
+       struct av7110 *av7110 = dvbdev->priv;
 
        dprintk(2, "av7110:%p, \n", av7110);
 
@@ -952,9 +963,10 @@ static u8 iframe_header[] = { 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x80, 0x00, 0x
 
 #define MIN_IFRAME 400000
 
-static int play_iframe(struct av7110 *av7110, u8 __user *buf, unsigned int len, int nonblock)
+static int play_iframe(struct av7110 *av7110, char __user *buf, unsigned int len, int nonblock)
 {
        int i, n;
+       int progressive = 0;
 
        dprintk(2, "av7110:%p, \n", av7110);
 
@@ -963,6 +975,14 @@ static int play_iframe(struct av7110 *av7110, u8 __user *buf, unsigned int len,
                        return -EBUSY;
        }
 
+       for (i = 0; i < len - 5; i++) {
+               /* get progressive flag from picture extension */
+               if (buf[i] == 0x00 && buf[i+1] == 0x00 &&
+                   buf[i+2] == 0x01 && (unsigned char)buf[i+3] == 0xb5 &&
+                   (buf[i+4] & 0xf0) == 0x10)
+                       progressive = buf[i+5] & 0x08;
+       }
+
        /* setting n always > 1, fixes problems when playing stillframes
           consisting of I- and P-Frames */
        n = MIN_IFRAME / len + 1;
@@ -974,15 +994,19 @@ static int play_iframe(struct av7110 *av7110, u8 __user *buf, unsigned int len,
                dvb_play(av7110, buf, len, 0, 1);
 
        av7110_ipack_flush(&av7110->ipack[1]);
-       return 0;
+
+       if (progressive)
+               return vidcom(av7110, AV_VIDEO_CMD_FREEZE, 1);
+       else
+               return 0;
 }
 
 
 static int dvb_video_ioctl(struct inode *inode, struct file *file,
                           unsigned int cmd, void *parg)
 {
-       struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
-       struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
+       struct dvb_device *dvbdev = file->private_data;
+       struct av7110 *av7110 = dvbdev->priv;
        unsigned long arg = (unsigned long) parg;
        int ret = 0;
 
@@ -1001,7 +1025,7 @@ static int dvb_video_ioctl(struct inode *inode, struct file *file,
                if (av7110->videostate.stream_source == VIDEO_SOURCE_MEMORY)
                        ret = av7110_av_stop(av7110, RP_VIDEO);
                else
-                       ret = vidcom(av7110, VIDEO_CMD_STOP,
+                       ret = vidcom(av7110, AV_VIDEO_CMD_STOP,
                               av7110->videostate.video_blank ? 0 : 1);
                if (!ret)
                        av7110->trickmode = TRICK_NONE;
@@ -1011,7 +1035,7 @@ static int dvb_video_ioctl(struct inode *inode, struct file *file,
                av7110->trickmode = TRICK_NONE;
                if (av7110->videostate.play_state == VIDEO_FREEZED) {
                        av7110->videostate.play_state = VIDEO_PLAYING;
-                       ret = vidcom(av7110, VIDEO_CMD_PLAY, 0);
+                       ret = vidcom(av7110, AV_VIDEO_CMD_PLAY, 0);
                        if (ret)
                                break;
                }
@@ -1026,7 +1050,7 @@ static int dvb_video_ioctl(struct inode *inode, struct file *file,
                        ret = av7110_av_start_play(av7110, RP_VIDEO);
                }
                if (!ret)
-                       ret = vidcom(av7110, VIDEO_CMD_PLAY, 0);
+                       ret = vidcom(av7110, AV_VIDEO_CMD_PLAY, 0);
                if (!ret)
                        av7110->videostate.play_state = VIDEO_PLAYING;
                break;
@@ -1036,7 +1060,7 @@ static int dvb_video_ioctl(struct inode *inode, struct file *file,
                if (av7110->playing & RP_VIDEO)
                        ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Pause, 0);
                else
-                       ret = vidcom(av7110, VIDEO_CMD_FREEZE, 1);
+                       ret = vidcom(av7110, AV_VIDEO_CMD_FREEZE, 1);
                if (!ret)
                        av7110->trickmode = TRICK_FREEZE;
                break;
@@ -1045,7 +1069,7 @@ static int dvb_video_ioctl(struct inode *inode, struct file *file,
                if (av7110->playing & RP_VIDEO)
                        ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Continue, 0);
                if (!ret)
-                       ret = vidcom(av7110, VIDEO_CMD_PLAY, 0);
+                       ret = vidcom(av7110, AV_VIDEO_CMD_PLAY, 0);
                if (!ret) {
                        av7110->videostate.play_state = VIDEO_PLAYING;
                        av7110->trickmode = TRICK_NONE;
@@ -1075,19 +1099,18 @@ static int dvb_video_ioctl(struct inode *inode, struct file *file,
        case VIDEO_SET_DISPLAY_FORMAT:
        {
                video_displayformat_t format = (video_displayformat_t) arg;
-               u16 val = 0;
 
                switch (format) {
                case VIDEO_PAN_SCAN:
-                       val = VID_PAN_SCAN_PREF;
+                       av7110->display_panscan = VID_PAN_SCAN_PREF;
                        break;
 
                case VIDEO_LETTER_BOX:
-                       val = VID_VC_AND_PS_PREF;
+                       av7110->display_panscan = VID_VC_AND_PS_PREF;
                        break;
 
                case VIDEO_CENTER_CUT_OUT:
-                       val = VID_CENTRE_CUT_PREF;
+                       av7110->display_panscan = VID_CENTRE_CUT_PREF;
                        break;
 
                default:
@@ -1097,7 +1120,7 @@ static int dvb_video_ioctl(struct inode *inode, struct file *file,
                        break;
                av7110->videostate.display_format = format;
                ret = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetPanScanType,
-                                   1, (u16) val);
+                                   1, av7110->display_panscan);
                break;
        }
 
@@ -1126,9 +1149,9 @@ static int dvb_video_ioctl(struct inode *inode, struct file *file,
                //note: arg is ignored by firmware
                if (av7110->playing & RP_VIDEO)
                        ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
-                                     __Scan_I, 2, AV_PES, 0);
+                                           __Scan_I, 2, AV_PES, 0);
                else
-                       ret = vidcom(av7110, VIDEO_CMD_FFWD, arg);
+                       ret = vidcom(av7110, AV_VIDEO_CMD_FFWD, arg);
                if (!ret) {
                        av7110->trickmode = TRICK_FAST;
                        av7110->videostate.play_state = VIDEO_PLAYING;
@@ -1139,13 +1162,13 @@ static int dvb_video_ioctl(struct inode *inode, struct file *file,
                if (av7110->playing&RP_VIDEO) {
                        ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Slow, 2, 0, 0);
                        if (!ret)
-                               ret = vidcom(av7110, VIDEO_CMD_SLOW, arg);
+                               ret = vidcom(av7110, AV_VIDEO_CMD_SLOW, arg);
                } else {
-                       ret = vidcom(av7110, VIDEO_CMD_PLAY, 0);
+                       ret = vidcom(av7110, AV_VIDEO_CMD_PLAY, 0);
                        if (!ret)
-                               ret = vidcom(av7110, VIDEO_CMD_STOP, 0);
+                               ret = vidcom(av7110, AV_VIDEO_CMD_STOP, 0);
                        if (!ret)
-                               ret = vidcom(av7110, VIDEO_CMD_SLOW, arg);
+                               ret = vidcom(av7110, AV_VIDEO_CMD_SLOW, arg);
                }
                if (!ret) {
                        av7110->trickmode = TRICK_SLOW;
@@ -1164,20 +1187,20 @@ static int dvb_video_ioctl(struct inode *inode, struct file *file,
 
                if (av7110->playing == RP_AV) {
                        ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
-                                     __Play, 2, AV_PES, 0);
+                                           __Play, 2, AV_PES, 0);
                        if (ret)
                                break;
                        if (av7110->trickmode == TRICK_FAST)
                                ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
-                                             __Scan_I, 2, AV_PES, 0);
+                                                   __Scan_I, 2, AV_PES, 0);
                        if (av7110->trickmode == TRICK_SLOW) {
                                ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
-                                             __Slow, 2, 0, 0);
+                                                   __Slow, 2, 0, 0);
                                if (!ret)
-                                       ret = vidcom(av7110, VIDEO_CMD_SLOW, arg);
+                                       ret = vidcom(av7110, AV_VIDEO_CMD_SLOW, arg);
                        }
                        if (av7110->trickmode == TRICK_FREEZE)
-                               ret = vidcom(av7110, VIDEO_CMD_STOP, 1);
+                               ret = vidcom(av7110, AV_VIDEO_CMD_STOP, 1);
                }
                break;
 
@@ -1195,8 +1218,8 @@ static int dvb_video_ioctl(struct inode *inode, struct file *file,
 static int dvb_audio_ioctl(struct inode *inode, struct file *file,
                           unsigned int cmd, void *parg)
 {
-       struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
-       struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
+       struct dvb_device *dvbdev = file->private_data;
+       struct av7110 *av7110 = dvbdev->priv;
        unsigned long arg = (unsigned long) parg;
        int ret = 0;
 
@@ -1256,7 +1279,9 @@ static int dvb_audio_ioctl(struct inode *inode, struct file *file,
                break;
 
        case AUDIO_SET_BYPASS_MODE:
-               ret = -EINVAL;
+               if (FW_VERSION(av7110->arm_app) < 0x2621)
+                       ret = -EINVAL;
+               av7110->audiostate.bypass_mode = (int)arg;
                break;
 
        case AUDIO_CHANNEL_SELECT:
@@ -1265,23 +1290,32 @@ static int dvb_audio_ioctl(struct inode *inode, struct file *file,
                switch(av7110->audiostate.channel_select) {
                case AUDIO_STEREO:
                        ret = audcom(av7110, AUDIO_CMD_STEREO);
-                       if (!ret)
+                       if (!ret) {
                                if (av7110->adac_type == DVB_ADAC_CRYSTAL)
                                        i2c_writereg(av7110, 0x20, 0x02, 0x49);
+                               else if (av7110->adac_type == DVB_ADAC_MSP34x5)
+                                       msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0220);
+                       }
                        break;
 
                case AUDIO_MONO_LEFT:
                        ret = audcom(av7110, AUDIO_CMD_MONO_L);
-                       if (!ret)
+                       if (!ret) {
                                if (av7110->adac_type == DVB_ADAC_CRYSTAL)
                                        i2c_writereg(av7110, 0x20, 0x02, 0x4a);
+                               else if (av7110->adac_type == DVB_ADAC_MSP34x5)
+                                       msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0200);
+                       }
                        break;
 
                case AUDIO_MONO_RIGHT:
                        ret = audcom(av7110, AUDIO_CMD_MONO_R);
-                       if (!ret)
+                       if (!ret) {
                                if (av7110->adac_type == DVB_ADAC_CRYSTAL)
                                        i2c_writereg(av7110, 0x20, 0x02, 0x45);
+                               else if (av7110->adac_type == DVB_ADAC_MSP34x5)
+                                       msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0210);
+                       }
                        break;
 
                default:
@@ -1295,7 +1329,11 @@ static int dvb_audio_ioctl(struct inode *inode, struct file *file,
                break;
 
        case AUDIO_GET_CAPABILITIES:
-               *(int *)parg = AUDIO_CAP_LPCM | AUDIO_CAP_MP1 | AUDIO_CAP_MP2;
+               if (FW_VERSION(av7110->arm_app) < 0x2621)
+                       *(unsigned int *)parg = AUDIO_CAP_LPCM | AUDIO_CAP_MP1 | AUDIO_CAP_MP2;
+               else
+                       *(unsigned int *)parg = AUDIO_CAP_LPCM | AUDIO_CAP_DTS | AUDIO_CAP_AC3 |
+                                               AUDIO_CAP_MP1 | AUDIO_CAP_MP2;
                break;
 
        case AUDIO_CLEAR_BUFFER:
@@ -1303,7 +1341,7 @@ static int dvb_audio_ioctl(struct inode *inode, struct file *file,
                av7110_ipack_reset(&av7110->ipack[0]);
                if (av7110->playing == RP_AV)
                        ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
-                              __Play, 2, AV_PES, 0);
+                                           __Play, 2, AV_PES, 0);
                break;
        case AUDIO_SET_ID:
 
@@ -1326,8 +1364,8 @@ static int dvb_audio_ioctl(struct inode *inode, struct file *file,
 
 static int dvb_video_open(struct inode *inode, struct file *file)
 {
-       struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
-       struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
+       struct dvb_device *dvbdev = file->private_data;
+       struct av7110 *av7110 = dvbdev->priv;
        int err;
 
        dprintk(2, "av7110:%p, \n", av7110);
@@ -1351,8 +1389,8 @@ static int dvb_video_open(struct inode *inode, struct file *file)
 
 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;
+       struct dvb_device *dvbdev = file->private_data;
+       struct av7110 *av7110 = dvbdev->priv;
 
        dprintk(2, "av7110:%p, \n", av7110);
 
@@ -1365,9 +1403,9 @@ static int dvb_video_release(struct inode *inode, struct file *file)
 
 static int dvb_audio_open(struct inode *inode, struct file *file)
 {
-       struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
-       struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
-       int err=dvb_generic_open(inode, file);
+       struct dvb_device *dvbdev = file->private_data;
+       struct av7110 *av7110 = dvbdev->priv;
+       int err = dvb_generic_open(inode, file);
 
        dprintk(2, "av7110:%p, \n", av7110);
 
@@ -1380,8 +1418,8 @@ static int dvb_audio_open(struct inode *inode, struct file *file)
 
 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;
+       struct dvb_device *dvbdev = file->private_data;
+       struct av7110 *av7110 = dvbdev->priv;
 
        dprintk(2, "av7110:%p, \n", av7110);
 
@@ -1444,8 +1482,9 @@ int av7110_av_register(struct av7110 *av7110)
        av7110->videostate.play_state = VIDEO_STOPPED;
        av7110->videostate.stream_source = VIDEO_SOURCE_DEMUX;
        av7110->videostate.video_format = VIDEO_FORMAT_4_3;
-       av7110->videostate.display_format = VIDEO_CENTER_CUT_OUT;
+       av7110->videostate.display_format = VIDEO_LETTER_BOX;
        av7110->display_ar = VIDEO_FORMAT_4_3;
+       av7110->display_panscan = VID_VC_AND_PS_PREF;
 
        init_waitqueue_head(&av7110->video_events.wait_queue);
        spin_lock_init(&av7110->video_events.lock);
@@ -1473,8 +1512,6 @@ int av7110_av_init(struct av7110 *av7110)
        void (*play[])(u8 *, int, void *) = { play_audio_cb, play_video_cb };
        int i, ret;
 
-       av7110->vidmode = VIDEO_MODE_PAL;
-
        for (i = 0; i < 2; i++) {
                struct ipack *ipack = av7110->ipack + i;