]> err.no Git - linux-2.6/blobdiff - drivers/media/video/msp3400-driver.c
V4L/DVB (3569): PATCH: switch cpia2 to mutexes and use ioctl 32 compat lib func
[linux-2.6] / drivers / media / video / msp3400-driver.c
index 04a05d7dd470b809edc747decb76501914b8a341..11ea9765769c7df12e8181040502d4339e295fc8 100644 (file)
@@ -66,26 +66,26 @@ MODULE_LICENSE("GPL");
 
 /* module parameters */
 static int opmode   = OPMODE_AUTO;
-int debug    = 0;    /* debug output */
-int once     = 0;    /* no continous stereo monitoring */
-int amsound  = 0;    /* hard-wire AM sound at 6.5 Hz (france),
-                              the autoscan seems work well only with FM... */
-int standard = 1;    /* Override auto detect of audio standard, if needed. */
-int dolby    = 0;
-
-int stereo_threshold = 0x190; /* a2 threshold for stereo/bilingual
+int msp_debug;          /* msp_debug output */
+int msp_once;           /* no continous stereo monitoring */
+int msp_amsound;        /* hard-wire AM sound at 6.5 Hz (france),
+                           the autoscan seems work well only with FM... */
+int msp_standard = 1;    /* Override auto detect of audio msp_standard, if needed. */
+int msp_dolby;
+
+int msp_stereo_thresh = 0x190; /* a2 threshold for stereo/bilingual
                                        (msp34xxg only) 0x00a0-0x03c0 */
 
 /* read-only */
 module_param(opmode,           int, 0444);
 
 /* read-write */
-module_param(once,             bool, 0644);
-module_param(debug,            int, 0644);
-module_param(stereo_threshold, int, 0644);
-module_param(standard,         int, 0644);
-module_param(amsound,          bool, 0644);
-module_param(dolby,            bool, 0644);
+module_param_named(once,msp_once,                      bool, 0644);
+module_param_named(debug,msp_debug,                    int,  0644);
+module_param_named(stereo_threshold,msp_stereo_thresh, int,  0644);
+module_param_named(standard,msp_standard,              int,  0644);
+module_param_named(amsound,msp_amsound,                bool, 0644);
+module_param_named(dolby,msp_dolby,                    bool, 0644);
 
 MODULE_PARM_DESC(opmode, "Forces a MSP3400 opmode. 0=Manual, 1=Autodetect, 2=Autodetect and autoselect");
 MODULE_PARM_DESC(once, "No continuous stereo monitoring");
@@ -127,7 +127,7 @@ int msp_reset(struct i2c_client *client)
                { client->addr, I2C_M_RD, 2, read  },
        };
 
-       v4l_dbg(3, client, "msp_reset\n");
+       v4l_dbg(3, msp_debug, client, "msp_reset\n");
        if (i2c_transfer(client->adapter, &reset[0], 1) != 1 ||
            i2c_transfer(client->adapter, &reset[1], 1) != 1 ||
            i2c_transfer(client->adapter, test, 2) != 2) {
@@ -165,7 +165,7 @@ static int msp_read(struct i2c_client *client, int dev, int addr)
                return -1;
        }
        retval = read[0] << 8 | read[1];
-       v4l_dbg(3, client, "msp_read(0x%x, 0x%x): 0x%x\n", dev, addr, retval);
+       v4l_dbg(3, msp_debug, client, "msp_read(0x%x, 0x%x): 0x%x\n", dev, addr, retval);
        return retval;
 }
 
@@ -190,7 +190,7 @@ static int msp_write(struct i2c_client *client, int dev, int addr, int val)
        buffer[3] = val  >> 8;
        buffer[4] = val  &  0xff;
 
-       v4l_dbg(3, client, "msp_write(0x%x, 0x%x, 0x%x)\n", dev, addr, val);
+       v4l_dbg(3, msp_debug, client, "msp_write(0x%x, 0x%x, 0x%x)\n", dev, addr, val);
        for (err = 0; err < 3; err++) {
                if (i2c_master_send(client, buffer, 5) == 5)
                        break;
@@ -273,7 +273,7 @@ void msp_set_scart(struct i2c_client *client, int in, int out)
        } else
                state->acb = 0xf60; /* Mute Input and SCART 1 Output */
 
-       v4l_dbg(1, client, "scart switch: %s => %d (ACB=0x%04x)\n",
+       v4l_dbg(1, msp_debug, client, "scart switch: %s => %d (ACB=0x%04x)\n",
                                                scart_names[in], out, state->acb);
        msp_write_dsp(client, 0x13, state->acb);
 
@@ -285,7 +285,7 @@ void msp_set_mute(struct i2c_client *client)
 {
        struct msp_state *state = i2c_get_clientdata(client);
 
-       v4l_dbg(1, client, "mute audio\n");
+       v4l_dbg(1, msp_debug, client, "mute audio\n");
        msp_write_dsp(client, 0x0000, 0);
        msp_write_dsp(client, 0x0007, 1);
        if (state->has_scart2_out_volume)
@@ -303,7 +303,7 @@ void msp_set_audio(struct i2c_client *client)
        if (!state->muted)
                val = (state->volume * 0x7f / 65535) << 8;
 
-       v4l_dbg(1, client, "mute=%s volume=%d\n",
+       v4l_dbg(1, msp_debug, client, "mute=%s volume=%d\n",
                state->muted ? "on" : "off", state->volume);
 
        msp_write_dsp(client, 0x0000, val);
@@ -321,7 +321,7 @@ void msp_set_audio(struct i2c_client *client)
        treble = ((state->treble - 32768) * 0x60 / 65535) << 8;
        loudness = state->loudness ? ((5 * 4) << 8) : 0;
 
-       v4l_dbg(1, client, "balance=%d bass=%d treble=%d loudness=%d\n",
+       v4l_dbg(1, msp_debug, client, "balance=%d bass=%d treble=%d loudness=%d\n",
                state->balance, state->bass, state->treble, state->loudness);
 
        msp_write_dsp(client, 0x0001, bal << 8);
@@ -341,12 +341,12 @@ int msp_modus(struct i2c_client *client)
        struct msp_state *state = i2c_get_clientdata(client);
 
        if (state->radio) {
-               v4l_dbg(1, client, "video mode selected to Radio\n");
+               v4l_dbg(1, msp_debug, client, "video mode selected to Radio\n");
                return 0x0003;
        }
 
-       if (state->std & V4L2_STD_PAL) {
-               v4l_dbg(1, client, "video mode selected to PAL\n");
+       if (state->v4l2_std & V4L2_STD_PAL) {
+               v4l_dbg(1, msp_debug, client, "video mode selected to PAL\n");
 
 #if 1
                /* experimental: not sure this works with all chip versions */
@@ -356,12 +356,12 @@ int msp_modus(struct i2c_client *client)
                return 0x1003;
 #endif
        }
-       if (state->std & V4L2_STD_NTSC) {
-               v4l_dbg(1, client, "video mode selected to NTSC\n");
+       if (state->v4l2_std & V4L2_STD_NTSC) {
+               v4l_dbg(1, msp_debug, client, "video mode selected to NTSC\n");
                return 0x2003;
        }
-       if (state->std & V4L2_STD_SECAM) {
-               v4l_dbg(1, client, "video mode selected to SECAM\n");
+       if (state->v4l2_std & V4L2_STD_SECAM) {
+               v4l_dbg(1, msp_debug, client, "video mode selected to SECAM\n");
                return 0x0003;
        }
        return 0x0003;
@@ -411,9 +411,9 @@ static int msp_mode_v4l2_to_v4l1(int rxsubchans)
        if (rxsubchans & V4L2_TUNER_SUB_STEREO)
                mode |= VIDEO_SOUND_STEREO;
        if (rxsubchans & V4L2_TUNER_SUB_LANG2)
-               mode |= VIDEO_SOUND_LANG2;
+               mode |= VIDEO_SOUND_LANG2 | VIDEO_SOUND_STEREO;
        if (rxsubchans & V4L2_TUNER_SUB_LANG1)
-               mode |= VIDEO_SOUND_LANG1;
+               mode |= VIDEO_SOUND_LANG1 | VIDEO_SOUND_STEREO;
        if (mode == 0)
                mode |= VIDEO_SOUND_MONO;
        return mode;
@@ -430,21 +430,6 @@ static int msp_mode_v4l1_to_v4l2(int mode)
        return V4L2_TUNER_MODE_MONO;
 }
 
-static void msp_any_detect_stereo(struct i2c_client *client)
-{
-       struct msp_state *state  = i2c_get_clientdata(client);
-
-       switch (state->opmode) {
-       case OPMODE_MANUAL:
-       case OPMODE_AUTODETECT:
-               autodetect_stereo(client);
-               break;
-       case OPMODE_AUTOSELECT:
-               msp34xxg_detect_stereo(client);
-               break;
-       }
-}
-
 static struct v4l2_queryctrl msp_qctrl_std[] = {
        {
                .id            = V4L2_CID_AUDIO_VOLUME,
@@ -506,22 +491,6 @@ static struct v4l2_queryctrl msp_qctrl_sound_processing[] = {
 };
 
 
-static void msp_any_set_audmode(struct i2c_client *client, int audmode)
-{
-       struct msp_state *state = i2c_get_clientdata(client);
-
-       switch (state->opmode) {
-       case OPMODE_MANUAL:
-       case OPMODE_AUTODETECT:
-               state->watch_stereo = 0;
-               msp3400c_setstereo(client, audmode);
-               break;
-       case OPMODE_AUTOSELECT:
-               msp34xxg_set_audmode(client, audmode);
-               break;
-       }
-}
-
 static int msp_get_ctrl(struct i2c_client *client, struct v4l2_control *ctrl)
 {
        struct msp_state *state = i2c_get_clientdata(client);
@@ -619,7 +588,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
        u16 *sarg = arg;
        int scart = 0;
 
-       if (debug >= 2)
+       if (msp_debug >= 2)
                v4l_i2c_print_ioctl(client, cmd);
 
        switch (cmd) {
@@ -653,24 +622,25 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
                }
                if (scart) {
                        state->rxsubchans = V4L2_TUNER_SUB_STEREO;
-                       state->audmode = V4L2_TUNER_MODE_STEREO;
                        msp_set_scart(client, scart, 0);
                        msp_write_dsp(client, 0x000d, 0x1900);
                        if (state->opmode != OPMODE_AUTOSELECT)
-                               msp3400c_setstereo(client, state->audmode);
+                               msp_set_audmode(client);
                }
                msp_wake_thread(client);
                break;
 
        case AUDC_SET_RADIO:
+               if (state->radio)
+                       return 0;
                state->radio = 1;
-               v4l_dbg(1, client, "switching to radio mode\n");
+               v4l_dbg(1, msp_debug, client, "switching to radio mode\n");
                state->watch_stereo = 0;
                switch (state->opmode) {
                case OPMODE_MANUAL:
                        /* set msp3400 to FM radio mode */
-                       msp3400c_setmode(client, MSP_MODE_FM_RADIO);
-                       msp3400c_setcarrier(client, MSP_CARRIER(10.7),
+                       msp3400c_set_mode(client, MSP_MODE_FM_RADIO);
+                       msp3400c_set_carrier(client, MSP_CARRIER(10.7),
                                            MSP_CARRIER(10.7));
                        msp_set_audio(client);
                        break;
@@ -701,8 +671,10 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
                va->bass = state->bass;
                va->treble = state->treble;
 
+               if (state->radio)
+                       break;
                if (state->opmode == OPMODE_AUTOSELECT)
-                       msp_any_detect_stereo(client);
+                       msp_detect_stereo(client);
                va->mode = msp_mode_v4l2_to_v4l1(state->rxsubchans);
                break;
        }
@@ -718,8 +690,9 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
                state->treble = va->treble;
                msp_set_audio(client);
 
-               if (va->mode != 0 && state->radio == 0)
-                       msp_any_set_audmode(client, msp_mode_v4l1_to_v4l2(va->mode));
+               if (va->mode != 0 && state->radio == 0) {
+                       state->audmode = msp_mode_v4l1_to_v4l2(va->mode);
+               }
                break;
        }
 
@@ -738,8 +711,8 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
                        std = V4L2_STD_SECAM;
                else
                        std = V4L2_STD_NTSC;
-               if (std != state->std) {
-                       state->std = std;
+               if (std != state->v4l2_std) {
+                       state->v4l2_std = std;
                        update = 1;
                }
                if (update)
@@ -768,9 +741,9 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
        case VIDIOC_S_STD:
        {
                v4l2_std_id *id = arg;
-               int update = state->radio || state->std != *id;
+               int update = state->radio || state->v4l2_std != *id;
 
-               state->std = *id;
+               state->v4l2_std = *id;
                state->radio = 0;
                if (update)
                        msp_wake_thread(client);
@@ -827,11 +800,8 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
                        return -EINVAL;
                }
 
-               msp_any_detect_stereo(client);
-               if (state->audmode == V4L2_TUNER_MODE_STEREO) {
-                       a->capability = V4L2_AUDCAP_STEREO;
-               }
-
+               a->capability = V4L2_AUDCAP_STEREO;
+               a->mode = 0;  /* TODO: add support for AVL */
                break;
        }
 
@@ -861,16 +831,10 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
                }
                if (scart) {
                        state->rxsubchans = V4L2_TUNER_SUB_STEREO;
-                       state->audmode = V4L2_TUNER_MODE_STEREO;
                        msp_set_scart(client, scart, 0);
                        msp_write_dsp(client, 0x000d, 0x1900);
                }
-               if (sarg->capability == V4L2_AUDCAP_STEREO) {
-                       state->audmode = V4L2_TUNER_MODE_STEREO;
-               } else {
-                       state->audmode &= ~V4L2_TUNER_MODE_STEREO;
-               }
-               msp_any_set_audmode(client, state->audmode);
+               msp_set_audmode(client);
                msp_wake_thread(client);
                break;
        }
@@ -879,8 +843,10 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
        {
                struct v4l2_tuner *vt = arg;
 
+               if (state->radio)
+                       break;
                if (state->opmode == OPMODE_AUTOSELECT)
-                       msp_any_detect_stereo(client);
+                       msp_detect_stereo(client);
                vt->audmode    = state->audmode;
                vt->rxsubchans = state->rxsubchans;
                vt->capability = V4L2_TUNER_CAP_STEREO |
@@ -892,9 +858,11 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
        {
                struct v4l2_tuner *vt = (struct v4l2_tuner *)arg;
 
+               if (state->radio)  /* TODO: add mono/stereo support for radio */
+                       break;
+               state->audmode = vt->audmode;
                /* only set audmode */
-               if (vt->audmode != -1 && vt->audmode != 0)
-                       msp_any_set_audmode(client, vt->audmode);
+               msp_set_audmode(client);
                break;
        }
 
@@ -919,7 +887,6 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
                        return -EINVAL;
                }
                break;
-
        }
 
        case VIDIOC_S_AUDOUT:
@@ -929,7 +896,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
                if (a->index < 0 || a->index > 2)
                        return -EINVAL;
 
-               v4l_dbg(1, client, "Setting audio out on msp34xx to input %i\n", a->index);
+               v4l_dbg(1, msp_debug, client, "Setting audio out on msp34xx to input %i\n", a->index);
                msp_set_scart(client, state->in_scart, a->index + 1);
 
                break;
@@ -939,7 +906,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
        {
                u32 *a = (u32 *)arg;
 
-               v4l_dbg(1, client, "Setting I2S speed to %d\n", *a);
+               v4l_dbg(1, msp_debug, client, "Setting I2S speed to %d\n", *a);
 
                switch (*a) {
                        case 1024000:
@@ -981,26 +948,50 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
                return msp_set_ctrl(client, arg);
 
        case VIDIOC_LOG_STATUS:
+       {
+               const char *p;
+
                if (state->opmode == OPMODE_AUTOSELECT)
-                       msp_any_detect_stereo(client);
+                       msp_detect_stereo(client);
                v4l_info(client, "%s rev1 = 0x%04x rev2 = 0x%04x\n",
                                client->name, state->rev1, state->rev2);
-               v4l_info(client, "Audio:  volume %d%s\n",
+               v4l_info(client, "Audio:    volume %d%s\n",
                                state->volume, state->muted ? " (muted)" : "");
                if (state->has_sound_processing) {
-                       v4l_info(client, "Audio:  balance %d bass %d treble %d loudness %s\n",
+                       v4l_info(client, "Audio:    balance %d bass %d treble %d loudness %s\n",
                                        state->balance, state->bass, state->treble,
                                        state->loudness ? "on" : "off");
                }
-               v4l_info(client, "Mode:   %s (%s%s)\n", msp_standard_mode_name(state->mode),
-                       (state->rxsubchans & V4L2_TUNER_SUB_STEREO) ? "stereo" : "mono",
-                       (state->rxsubchans & V4L2_TUNER_SUB_LANG2) ? ", dual" : "");
-               v4l_info(client, "ACB:    0x%04x\n", state->acb);
+               switch (state->mode) {
+               case MSP_MODE_AM_DETECT: p = "AM (for carrier detect)"; break;
+               case MSP_MODE_FM_RADIO: p = "FM Radio"; break;
+               case MSP_MODE_FM_TERRA: p = "Terrestial FM-mono + FM-stereo"; break;
+               case MSP_MODE_FM_SAT: p = "Satellite FM-mono"; break;
+               case MSP_MODE_FM_NICAM1: p = "NICAM/FM (B/G, D/K)"; break;
+               case MSP_MODE_FM_NICAM2: p = "NICAM/FM (I)"; break;
+               case MSP_MODE_AM_NICAM: p = "NICAM/AM (L)"; break;
+               case MSP_MODE_BTSC: p = "BTSC"; break;
+               case MSP_MODE_EXTERN: p = "External input"; break;
+               default: p = "unknown"; break;
+               }
+               if (state->opmode == OPMODE_MANUAL) {
+                       v4l_info(client, "Mode:     %s (%s%s)\n", p,
+                               (state->rxsubchans & V4L2_TUNER_SUB_STEREO) ? "stereo" : "mono",
+                               (state->rxsubchans & V4L2_TUNER_SUB_LANG2) ? ", dual" : "");
+               } else {
+                       v4l_info(client, "Mode:     %s\n", p);
+                       v4l_info(client, "Standard: %s (%s%s)\n",
+                               msp_standard_std_name(state->std),
+                               (state->rxsubchans & V4L2_TUNER_SUB_STEREO) ? "stereo" : "mono",
+                               (state->rxsubchans & V4L2_TUNER_SUB_LANG2) ? ", dual" : "");
+               }
+               v4l_info(client, "ACB:      0x%04x\n", state->acb);
                break;
+       }
 
        default:
-               /* nothing */
-               break;
+               /* unknown */
+               return -EINVAL;
        }
        return 0;
 }
@@ -1009,7 +1000,7 @@ static int msp_suspend(struct device * dev, pm_message_t state)
 {
        struct i2c_client *client = container_of(dev, struct i2c_client, dev);
 
-       v4l_dbg(1, client, "suspend\n");
+       v4l_dbg(1, msp_debug, client, "suspend\n");
        msp_reset(client);
        return 0;
 }
@@ -1018,7 +1009,7 @@ static int msp_resume(struct device * dev)
 {
        struct i2c_client *client = container_of(dev, struct i2c_client, dev);
 
-       v4l_dbg(1, client, "resume\n");
+       v4l_dbg(1, msp_debug, client, "resume\n");
        msp_wake_thread(client);
        return 0;
 }
@@ -1048,7 +1039,7 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
        snprintf(client->name, sizeof(client->name) - 1, "msp3400");
 
        if (msp_reset(client) == -1) {
-               v4l_dbg(1, client, "msp3400 not found\n");
+               v4l_dbg(1, msp_debug, client, "msp3400 not found\n");
                kfree(client);
                return -1;
        }
@@ -1061,7 +1052,8 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
        i2c_set_clientdata(client, state);
 
        memset(state, 0, sizeof(*state));
-       state->std = V4L2_STD_NTSC;
+       state->v4l2_std = V4L2_STD_NTSC;
+       state->audmode = V4L2_TUNER_MODE_LANG1;
        state->volume = 58880;  /* 0db gain */
        state->balance = 32768; /* 0db gain */
        state->bass = 32768;
@@ -1075,9 +1067,9 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
        state->rev1 = msp_read_dsp(client, 0x1e);
        if (state->rev1 != -1)
                state->rev2 = msp_read_dsp(client, 0x1f);
-       v4l_dbg(1, client, "rev1=0x%04x, rev2=0x%04x\n", state->rev1, state->rev2);
+       v4l_dbg(1, msp_debug, client, "rev1=0x%04x, rev2=0x%04x\n", state->rev1, state->rev2);
        if (state->rev1 == -1 || (state->rev1 == 0 && state->rev2 == 0)) {
-               v4l_dbg(1, client, "not an msp3400 (cannot read chip version)\n");
+               v4l_dbg(1, msp_debug, client, "not an msp3400 (cannot read chip version)\n");
                kfree(state);
                kfree(client);
                return -1;
@@ -1109,6 +1101,8 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
        state->has_scart23_in_scart2_out = msp_family >= 4 || msp_prod_lo < 5;
        /* Has scart2 a volume control? Not in pre-D revisions. */
        state->has_scart2_out_volume = msp_revision > 'C' && state->has_scart23_in_scart2_out;
+       /* Has a configurable i2s out? */
+       state->has_i2s_conf = msp_revision >= 'G' && msp_prod_lo < 7;
        /* Has subwoofer output: not in pre-D revs and not in stripped down products */
        state->has_subwoofer = msp_revision >= 'D' && msp_prod_lo < 5;
        /* Has soundprocessing (bass/treble/balance/loudness/equalizer): not in