CHROMIUM: ALSA: hda/ca0132: Stop streaming when turning on/off Crystal Voice.
authorChih-Chung Chang <chihchung@chromium.org>
Tue, 23 Oct 2012 03:57:00 +0000 (11:57 +0800)
committerGerrit <chrome-bot@google.com>
Tue, 23 Oct 2012 06:05:02 +0000 (23:05 -0700)
Similar to the previous fix for switching between microphones, if an
active recording stream is running, it has to be stopped before turning
on/off Crystal Voice, otherwise the parameters won't be applied correctly.

The patch is provided by Creative.

BUG=chrome-os-partner:14920
TEST=use "arecord -f cd -B 10000 -d 20 1.wav"
to record audio, and plug/unplug headphone while recording.

Signed-off-by: Chih-Chung Chang <chihchung@chromium.org>
Change-Id: Ic9296b07942cfaeb66c58cc1024dd20bf924a231
Reviewed-on: https://gerrit.chromium.org/gerrit/36314
Reviewed-by: Dylan Reid <dgreid@chromium.org>
sound/pci/hda/patch_ca0132.c

index 37b67ed..45fdbbd 100644 (file)
@@ -3435,11 +3435,36 @@ static int ca0132_pe_switch_set(struct hda_codec *codec)
        return ret;
 }
 
+/* Check if Mic1 is streaming, if so, stop streaming */
+static int stop_mic1(struct hda_codec *codec)
+{
+       struct ca0132_spec *spec = codec->spec;
+       unsigned int oldval = snd_hda_codec_read(codec, spec->adcs[0], 0,
+                                                AC_VERB_GET_CONV, 0);
+       if (oldval != 0)
+               snd_hda_codec_write(codec, spec->adcs[0], 0,
+                               AC_VERB_SET_CHANNEL_STREAMID,
+                               0);
+       return oldval;
+}
+
+/* Resume Mic1 streaming if it was stopped. */
+static int resume_mic1(struct hda_codec *codec, unsigned int oldval)
+{
+       struct ca0132_spec *spec = codec->spec;
+       /* Restore the previous stream and channel */
+       if (oldval != 0)
+               snd_hda_codec_write(codec, spec->adcs[0], 0,
+                                   AC_VERB_SET_CHANNEL_STREAMID,
+                                   oldval);
+}
+
 static int ca0132_cvoice_switch_set(struct hda_codec *codec)
 {
        struct ca0132_spec *spec = codec->spec;
        hda_nid_t nid;
        int i, ret = 0;
+       unsigned int oldval;
 
        CA0132_LOG("ca0132_cvoice_switch_set: val=%ld\n",
                   spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID]);
@@ -3454,7 +3479,9 @@ static int ca0132_cvoice_switch_set(struct hda_codec *codec)
        ret |= ca0132_voicefx_set(codec, (spec->voicefx_val ? 1 : 0));
 
        /* set correct vipsource */
+       oldval = stop_mic1(codec);
        ret |= ca0132_set_vipsource(codec, 1);
+       resume_mic1(codec, oldval);
        return ret;
 }
 
@@ -4051,14 +4078,7 @@ static void ca0132_set_dmic(struct hda_codec *codec, int enable)
 
        CA0132_LOG("ca0132_set_dmic: enable=%d\n", enable);
 
-       /* Check if Mic1 is streaming, if so, stop streaming */
-       oldval = snd_hda_codec_read(codec, spec->adcs[0], 0,
-                                   AC_VERB_GET_CONV, 0);
-       if (oldval != 0)
-               snd_hda_codec_write(codec, spec->adcs[0], 0,
-                                   AC_VERB_SET_CHANNEL_STREAMID,
-                                   0);
-
+       oldval = stop_mic1(codec);
        ca0132_set_vipsource(codec, 0);
        if (enable) {
                /* set DMic input as 2-ch */
@@ -4087,12 +4107,7 @@ static void ca0132_set_dmic(struct hda_codec *codec, int enable)
                        chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 0);
        }
        ca0132_set_vipsource(codec, 1);
-
-       /* Restore the previous stream and channel */
-       if (oldval != 0)
-               snd_hda_codec_write(codec, spec->adcs[0], 0,
-                                   AC_VERB_SET_CHANNEL_STREAMID,
-                                   oldval);
+       resume_mic1(codec, oldval);
 }
 
 static void ca0132_init_dmic(struct hda_codec *codec)