audio_hal: restart fm during device switch if analog wsa presents

afe clock is not enabled when device switched from headset
to wsa speaker, then no sound can be heard from speaker

When device changes, stop the fm to ensure pcm device closed
and restart fm to get the pcm device opened and started, then
afe clock can be enabled

CRs-Fixed: 853022
Change-Id: Ib110ce726c5eb73dd0c51ccfe1c3bd12e6503dc5
diff --git a/hal/audio_extn/fm.c b/hal/audio_extn/fm.c
index ed3776c..efc2307 100644
--- a/hal/audio_extn/fm.c
+++ b/hal/audio_extn/fm.c
@@ -243,7 +243,20 @@
         if (ret >= 0) {
             val = atoi(value);
             if(val > 0)
-                select_devices(adev, USECASE_AUDIO_PLAYBACK_FM);
+                /*
+                 * Only when wsa does present and is in analog mode,
+                 * fm will stop/start here.
+                 * To-do: when the kernel codec type query change
+                 * is ready, enum of wsa mode should be checked here.
+                 * Currently, platform_get_wsa_mode will directly return
+                 * 1 when wsa is in analog mode.
+                 */
+                if (platform_get_wsa_mode(adev->platform) == 1) {
+                    fm_stop(adev);
+                    fm_start(adev);
+                } else {
+                    select_devices(adev, USECASE_AUDIO_PLAYBACK_FM);
+                }
         }
     }
     if (fmmod.restart_fm && (fmmod.scard_state == SND_CARD_STATE_ONLINE)) {
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index 1c6fd1a..2666a00 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -4449,3 +4449,16 @@
 done:
     return ret;
 }
+
+int platform_get_wsa_mode(void *platform)
+{
+    struct platform_data *my_data = (struct platform_data *)platform;
+    char *snd_card_name;
+
+    snd_card_name = mixer_get_name(my_data->adev->mixer);
+    if ((!strcmp(snd_card_name, "msm8952-skum-snd-card")) ||
+        (!strcmp(snd_card_name, "msm8952-snd-card-mtp")))
+        return 1;
+    else
+        return 0;
+}
diff --git a/hal/msm8960/platform.c b/hal/msm8960/platform.c
index 2065b54..146fc7d 100644
--- a/hal/msm8960/platform.c
+++ b/hal/msm8960/platform.c
@@ -1175,3 +1175,8 @@
 {
     return -ENOSYS;
 }
+
+int platform_get_wsa_mode(void *platform)
+{
+    return 0;
+}
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 0a17a22..1e1a589 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -4075,3 +4075,8 @@
 done:
     return ret;
 }
+
+int platform_get_wsa_mode (void *platform)
+{
+    return 0;
+}
diff --git a/hal/platform_api.h b/hal/platform_api.h
index 5542a6d..dbcfec7 100644
--- a/hal/platform_api.h
+++ b/hal/platform_api.h
@@ -119,4 +119,5 @@
                                        const char *spkr_1_tz_name, const char *spkr_2_tz_name);
 const char *platform_get_spkr_1_tz_name(snd_device_t snd_device);
 const char *platform_get_spkr_2_tz_name(snd_device_t snd_device);
+int platform_get_wsa_mode(void *platform);
 #endif // AUDIO_PLATFORM_API_H