mfd: cpcap: audio: Fix loss of audio over headset
authorPraveen Bharathi <pbharathi@motorola.com>
Mon, 24 Jan 2011 14:01:11 +0000 (08:01 -0600)
committerRebecca Schultz Zavin <rebecca@android.com>
Wed, 26 Jan 2011 19:07:32 +0000 (11:07 -0800)
When the 3.5mm headset is unplugged and plugged back in, cpcap gets into a
wierd state and audio is not routed to any speaker, neither headset nor
main speaker. This is a solution from Droid days. The cpcap sends a callback
to audio driver when such a plug/unplug is detected and forces the audio path
setup back to headset.

Change-Id: I91afda628e14ec20d589fc9b3e844d29f9f96fca
Signed-off-by: Praveen Bharathi <pbharathi@motorola.com>
drivers/mfd/tegra-cpcap-audio.c

index 5838a7da77660b8008b00ddaddbb5ac5f60eb96f..dd5e917bfc7b1d30d2c464ff92fc17675b47c2f5 100644 (file)
@@ -467,6 +467,29 @@ void tegra_cpcap_audio_dock_state(bool connected)
 }
 EXPORT_SYMBOL(tegra_cpcap_audio_dock_state);
 
+static void cpcap_audio_callback(int status)
+{
+       mutex_lock(&cpcap_lock);
+       if (status == 1 || status == 2) {
+               if (pdata->state->stdac_primary_speaker ==
+                                       CPCAP_AUDIO_OUT_STEREO_HEADSET)
+                       tegra_setup_audio_out_headset_on();
+               if (pdata->state->microphone ==
+                                       CPCAP_AUDIO_IN_HEADSET)
+                       tegra_setup_audio_in_headset_on();
+       }
+       if (status == 0) {
+               if (pdata->state->stdac_primary_speaker ==
+                                       CPCAP_AUDIO_OUT_STEREO_HEADSET)
+                       tegra_setup_audio_output_off();
+               if (pdata->state->microphone ==
+                                       CPCAP_AUDIO_IN_HEADSET)
+                       tegra_setup_audio_in_mute();
+       }
+
+       mutex_unlock(&cpcap_lock);
+}
+
 static int cpcap_audio_probe(struct platform_device *pdev)
 {
        int rc;
@@ -503,6 +526,8 @@ static int cpcap_audio_probe(struct platform_device *pdev)
        if (cpcap_audio_init(pdata->state, pdata->regulator))
                goto fail3;
 
+       cpcap->h2w_new_state = &cpcap_audio_callback;
+
        rc = misc_register(&cpcap_audio_ctl);
        if (rc < 0) {
                pr_err("%s: failed to register misc device: %d\n", __func__,