V4L/DVB (4609): Improved i2c performance on software bitbang algoritm
[safe/jmp/linux-2.6] / drivers / media / video / tvaudio.c
index 4cc0497..936e3f7 100644 (file)
@@ -14,7 +14,6 @@
  *
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/kernel.h>
@@ -30,7 +29,7 @@
 #include <linux/init.h>
 #include <linux/smp_lock.h>
 
-#include <media/audiochip.h>
+#include <media/tvaudio.h>
 #include <media/v4l2-common.h>
 
 #include <media/i2c-addr.h>
@@ -102,7 +101,7 @@ struct CHIPDESC {
 
        /* input switch register + values for v4l inputs */
        int  inputreg;
-       int  inputmap[8];
+       int  inputmap[4];
        int  inputmute;
        int  inputmask;
 };
@@ -119,9 +118,10 @@ struct CHIPSTATE {
        audiocmd   shadow;
 
        /* current settings */
-       __u16 left,right,treble,bass,mode;
+       __u16 left,right,treble,bass,muted,mode;
        int prevmode;
        int radio;
+       int input;
 
        /* thread */
        pid_t                tpid;
@@ -1101,9 +1101,8 @@ static int tda8425_shift12(int val) { return (val >> 12) | 0xf0; }
 static int tda8425_initialize(struct CHIPSTATE *chip)
 {
        struct CHIPDESC *desc = chiplist + chip->type;
-       int inputmap[8] = { /* tuner    */ TDA8425_S1_CH2, /* radio  */ TDA8425_S1_CH1,
-                           /* extern   */ TDA8425_S1_CH1, /* intern */ TDA8425_S1_OFF,
-                           /* off      */ TDA8425_S1_OFF, /* on     */ TDA8425_S1_CH2};
+       int inputmap[4] = { /* tuner    */ TDA8425_S1_CH2, /* radio  */ TDA8425_S1_CH1,
+                           /* extern   */ TDA8425_S1_CH1, /* intern */ TDA8425_S1_OFF};
 
        if (chip->c.adapter->id == I2C_HW_B_RIVA) {
                memcpy (desc->inputmap, inputmap, sizeof (inputmap));
@@ -1298,7 +1297,7 @@ static struct CHIPDESC chiplist[] = {
                .init       = { 4, { TDA9873_SW, 0xa4, 0x06, 0x03 } },
                .inputreg   = TDA9873_SW,
                .inputmute  = TDA9873_MUTE | TDA9873_AUTOMUTE,
-               .inputmap   = {0xa0, 0xa2, 0xa0, 0xa0, 0xc0},
+               .inputmap   = {0xa0, 0xa2, 0xa0, 0xa0},
                .inputmask  = TDA9873_INP_MASK|TDA9873_MUTE|TDA9873_AUTOMUTE,
 
        },
@@ -1446,8 +1445,7 @@ static struct CHIPDESC chiplist[] = {
                .inputmap   = {PIC16C54_MISC_SND_NOTMUTE|PIC16C54_MISC_SWITCH_TUNER,
                             PIC16C54_MISC_SND_NOTMUTE|PIC16C54_MISC_SWITCH_LINE,
                             PIC16C54_MISC_SND_NOTMUTE|PIC16C54_MISC_SWITCH_LINE,
-                            PIC16C54_MISC_SND_MUTE,PIC16C54_MISC_SND_MUTE,
-                            PIC16C54_MISC_SND_NOTMUTE},
+                            PIC16C54_MISC_SND_MUTE},
                .inputmute  = PIC16C54_MISC_SND_MUTE,
        },
        {
@@ -1583,28 +1581,40 @@ static int chip_detach(struct i2c_client *client)
        return 0;
 }
 
+static int tvaudio_set_ctrl(struct CHIPSTATE *chip, struct v4l2_control *ctrl)
+{
+       struct CHIPDESC *desc = chiplist + chip->type;
+
+       switch (ctrl->id) {
+       case V4L2_CID_AUDIO_MUTE:
+               if (ctrl->value < 0 || ctrl->value >= 2)
+                       return -ERANGE;
+               chip->muted = ctrl->value;
+               if (chip->muted)
+                       chip_write_masked(chip,desc->inputreg,desc->inputmute,desc->inputmask);
+               else
+                       chip_write_masked(chip,desc->inputreg,
+                                       desc->inputmap[chip->input],desc->inputmask);
+               break;
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+
+
 /* ---------------------------------------------------------------------- */
 /* video4linux interface                                                  */
 
 static int chip_command(struct i2c_client *client,
                        unsigned int cmd, void *arg)
 {
-       __u16 *sarg = arg;
        struct CHIPSTATE *chip = i2c_get_clientdata(client);
        struct CHIPDESC  *desc = chiplist + chip->type;
 
        v4l_dbg(1, debug, &chip->c, "%s: chip_command 0x%x\n", chip->c.name, cmd);
 
        switch (cmd) {
-       case AUDC_SET_INPUT:
-               if (desc->flags & CHIP_HAS_INPUTSEL) {
-                       if (*sarg & 0x80)
-                               chip_write_masked(chip,desc->inputreg,desc->inputmute,desc->inputmask);
-                       else
-                               chip_write_masked(chip,desc->inputreg,desc->inputmap[*sarg],desc->inputmask);
-               }
-               break;
-
        case AUDC_SET_RADIO:
                chip->radio = 1;
                chip->watch_stereo = 0;
@@ -1668,6 +1678,33 @@ static int chip_command(struct i2c_client *client,
                break;
        }
 
+       case VIDIOC_S_CTRL:
+               return tvaudio_set_ctrl(chip, arg);
+
+       case VIDIOC_INT_G_AUDIO_ROUTING:
+       {
+               struct v4l2_routing *rt = arg;
+
+               rt->input = chip->input;
+               rt->output = 0;
+               break;
+       }
+
+       case VIDIOC_INT_S_AUDIO_ROUTING:
+       {
+               struct v4l2_routing *rt = arg;
+
+               if (!(desc->flags & CHIP_HAS_INPUTSEL) || rt->input >= 4)
+                               return -EINVAL;
+               /* There are four inputs: tuner, radio, extern and intern. */
+               chip->input = rt->input;
+               if (chip->muted)
+                       break;
+               chip_write_masked(chip, desc->inputreg,
+                               desc->inputmap[chip->input], desc->inputmask);
+               break;
+       }
+
        case VIDIOC_S_TUNER:
        {
                struct v4l2_tuner *vt = arg;
@@ -1680,6 +1717,7 @@ static int chip_command(struct i2c_client *client,
                        mode = VIDEO_SOUND_MONO;
                        break;
                case V4L2_TUNER_MODE_STEREO:
+               case V4L2_TUNER_MODE_LANG1_LANG2:
                        mode = VIDEO_SOUND_STEREO;
                        break;
                case V4L2_TUNER_MODE_LANG1: