hal: Support for fm audio features

Added support for fm audio feature and hal single
instance fix

Change-Id: I189fd089b45a7e268e0af4ba4ef3eefd22a3f2ff
diff --git a/hal/Android.mk b/hal/Android.mk
index 649f6fe..9cb9817 100644
--- a/hal/Android.mk
+++ b/hal/Android.mk
@@ -29,6 +29,11 @@
     LOCAL_CFLAGS += -DAFE_PROXY_ENABLED
 endif
 
+ifneq ($(strip $(AUDIO_FEATURE_DISABLED_FM)),true)
+    LOCAL_CFLAGS += -DFM_ENABLED
+    LOCAL_SRC_FILES += audio_extn/fm.c
+endif
+
 LOCAL_SHARED_LIBRARIES := \
 	liblog \
 	libcutils \
diff --git a/hal/audio_extn/audio_extn.c b/hal/audio_extn/audio_extn.c
index 610e0d1..b10a5e9 100644
--- a/hal/audio_extn/audio_extn.c
+++ b/hal/audio_extn/audio_extn.c
@@ -44,6 +44,12 @@
 #define AUDIO_PARAMETER_KEY_ANC        "anc_enabled"
 #define AUDIO_PARAMETER_KEY_WFD        "wfd_channel_cap"
 #define AUDIO_PARAMETER_CAN_OPEN_PROXY "can_open_proxy"
+#ifndef FM_ENABLED
+#define audio_extn_fm_set_parameters(adev, parms) (0)
+#else
+void audio_extn_fm_set_parameters(struct audio_device *adev,
+                                   struct str_parms *parms);
+#endif
 
 #ifndef ANC_HEADSET_ENABLED
 #define audio_extn_set_anc_parameters(parms)       (0)
@@ -180,6 +186,7 @@
 {
    audio_extn_set_anc_parameters(parms);
    audio_extn_set_afe_proxy_parameters(parms);
+   audio_extn_fm_set_parameters(adev, parms);
 }
 
 char* audio_extn_get_parameters(const struct audio_hw_device *dev,
diff --git a/hal/audio_extn/fm.c b/hal/audio_extn/fm.c
new file mode 100644
index 0000000..53499b9
--- /dev/null
+++ b/hal/audio_extn/fm.c
@@ -0,0 +1,258 @@
+/*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Not a Contribution.
+ *
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "audio_hw_fm"
+/*#define LOG_NDEBUG 0*/
+#define LOG_NDDEBUG 0
+
+#include <errno.h>
+#include <math.h>
+#include <cutils/log.h>
+
+#include "audio_hw.h"
+#include "platform.h"
+#include "platform_api.h"
+#include <stdlib.h>
+#include <cutils/str_parms.h>
+
+#ifdef FM_ENABLED
+#define AUDIO_PARAMETER_KEY_HANDLE_FM "handle_fm"
+#define AUDIO_PARAMETER_KEY_FM_VOLUME "fm_volume"
+
+static struct pcm_config pcm_config_fm = {
+    .channels = 2,
+    .rate = 48000,
+    .period_size = 256,
+    .period_count = 4,
+    .format = PCM_FORMAT_S16_LE,
+    .start_threshold = 0,
+    .stop_threshold = INT_MAX,
+    .avail_min = 0,
+};
+
+struct fm_module {
+    struct pcm *fm_pcm_rx;
+    struct pcm *fm_pcm_tx;
+    bool is_fm_running;
+    int fm_volume;
+};
+
+static struct fm_module fmmod = {
+  .fm_pcm_rx = NULL,
+  .fm_pcm_tx = NULL,
+  .fm_volume = 0,
+  .is_fm_running = 0,
+};
+
+static int32_t fm_set_volume(struct audio_device *adev, float value)
+{
+    int32_t vol, ret = 0;
+    struct mixer_ctl *ctl;
+    const char *mixer_ctl_name = "Internal FM RX Volume";
+
+    ALOGD("%s: entry", __func__);
+    ALOGD("%s: (%f)\n", __func__, value);
+
+    if (value < 0.0) {
+        ALOGW("%s: (%f) Under 0.0, assuming 0.0\n", __func__, value);
+        value = 0.0;
+    } else if (value > 1.0) {
+        ALOGW("%s: (%f) Over 1.0, assuming 1.0\n", __func__, value);
+        value = 1.0;
+    }
+    vol  = lrint((value * 0x2000) + 0.5);
+
+    fmmod.fm_volume = vol;
+
+    if (!fmmod.is_fm_running) {
+        ALOGV("%s: FM not active, ignoring set_fm_volume call", __func__);
+        return -EIO;
+    }
+
+    ALOGD("%s: Setting FM volume to %d \n", __func__, vol);
+    ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
+    if (!ctl) {
+        ALOGE("%s: Could not get ctl for mixer cmd - %s",
+              __func__, mixer_ctl_name);
+        return -EINVAL;
+    }
+    mixer_ctl_set_value(ctl, 0, fmmod.fm_volume);
+
+    ALOGD("%s: exit", __func__);
+    return ret;
+}
+
+static int32_t fm_stop(struct audio_device *adev)
+{
+    int32_t i, ret = 0;
+    struct audio_usecase *uc_info;
+
+    ALOGD("%s: enter", __func__);
+    fmmod.is_fm_running = false;
+
+    /* 1. Close the PCM devices */
+    if (fmmod.fm_pcm_rx) {
+        pcm_close(fmmod.fm_pcm_rx);
+        fmmod.fm_pcm_rx = NULL;
+    }
+    if (fmmod.fm_pcm_tx) {
+        pcm_close(fmmod.fm_pcm_tx);
+        fmmod.fm_pcm_tx = NULL;
+    }
+
+    uc_info = get_usecase_from_list(adev, USECASE_AUDIO_PLAYBACK_FM);
+    if (uc_info == NULL) {
+        ALOGE("%s: Could not find the usecase (%d) in the list",
+              __func__, USECASE_VOICE_CALL);
+        return -EINVAL;
+    }
+
+    /* 2. Get and set stream specific mixer controls */
+    disable_audio_route(adev, uc_info, true);
+
+    /* 3. Disable the rx and tx devices */
+    disable_snd_device(adev, uc_info->out_snd_device, false);
+    disable_snd_device(adev, uc_info->in_snd_device, true);
+
+    list_remove(&uc_info->list);
+    free(uc_info);
+
+    ALOGD("%s: exit: status(%d)", __func__, ret);
+    return ret;
+}
+
+static int32_t fm_start(struct audio_device *adev)
+{
+    int32_t i, ret = 0;
+    struct audio_usecase *uc_info;
+    int32_t pcm_dev_rx_id, pcm_dev_tx_id;
+
+    ALOGD("%s: enter", __func__);
+
+    uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
+    uc_info->id = USECASE_AUDIO_PLAYBACK_FM;
+    uc_info->type = PCM_PLAYBACK;
+    uc_info->stream.out = adev->primary_output;
+    uc_info->devices = adev->primary_output->devices;
+    uc_info->in_snd_device = SND_DEVICE_NONE;
+    uc_info->out_snd_device = SND_DEVICE_NONE;
+
+    list_add_tail(&adev->usecase_list, &uc_info->list);
+
+    select_devices(adev, USECASE_AUDIO_PLAYBACK_FM);
+
+    pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK);
+    pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE);
+
+    if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0) {
+        ALOGE("%s: Invalid PCM devices (rx: %d tx: %d) for the usecase(%d)",
+              __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id);
+        ret = -EIO;
+        goto exit;
+    }
+
+    ALOGV("%s: FM PCM devices (rx: %d tx: %d) for the usecase(%d)",
+              __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id);
+
+    ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)",
+          __func__, SOUND_CARD, pcm_dev_rx_id);
+    fmmod.fm_pcm_rx = pcm_open(SOUND_CARD,
+                                  pcm_dev_rx_id,
+                                  PCM_OUT, &pcm_config_fm);
+    if (fmmod.fm_pcm_rx && !pcm_is_ready(fmmod.fm_pcm_rx)) {
+        ALOGE("%s: %s", __func__, pcm_get_error(fmmod.fm_pcm_rx));
+        ret = -EIO;
+        goto exit;
+    }
+
+    ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)",
+          __func__, SOUND_CARD, pcm_dev_tx_id);
+    fmmod.fm_pcm_tx = pcm_open(SOUND_CARD,
+                                   pcm_dev_tx_id,
+                                   PCM_IN, &pcm_config_fm);
+    if (fmmod.fm_pcm_tx && !pcm_is_ready(fmmod.fm_pcm_tx)) {
+        ALOGE("%s: %s", __func__, pcm_get_error(fmmod.fm_pcm_tx));
+        ret = -EIO;
+        goto exit;
+    }
+    pcm_start(fmmod.fm_pcm_rx);
+    pcm_start(fmmod.fm_pcm_tx);
+
+    fmmod.is_fm_running = true;
+    fm_set_volume(adev, fmmod.fm_volume);
+
+    ALOGD("%s: exit: status(%d)", __func__, ret);
+    return 0;
+
+exit:
+    fm_stop(adev);
+    ALOGE("%s: Problem in FM start: status(%d)", __func__, ret);
+    return ret;
+}
+
+void audio_extn_fm_set_parameters(struct audio_device *adev,
+                                  struct str_parms *parms)
+{
+    int ret, val;
+    char value[32]={0};
+    float vol =0.0;
+
+    ALOGV("%s: enter", __func__);
+    if(fmmod.is_fm_running) {
+        ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING,
+                                value, sizeof(value));
+        if (ret >= 0) {
+            val = atoi(value);
+            if(val > 0)
+                select_devices(adev, USECASE_AUDIO_PLAYBACK_FM);
+        }
+    }
+
+    ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HANDLE_FM,
+                            value, sizeof(value));
+    if (ret >= 0) {
+        val = atoi(value);
+        ALOGD("%s: FM usecase", __func__);
+        if (val != 0) {
+            if(val & AUDIO_DEVICE_OUT_FM
+               && fmmod.is_fm_running == false)
+                fm_start(adev);
+            else if (!(val & AUDIO_DEVICE_OUT_FM)
+                     && fmmod.is_fm_running == true)
+                fm_stop(adev);
+       }
+    }
+
+    memset(value, 0, sizeof(value));
+    ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_FM_VOLUME,
+                            value, sizeof(value));
+    if (ret >= 0) {
+        if (sscanf(value, "%f", &vol) != 1){
+            ALOGE("%s: error in retrieving fm volume", __func__);
+            ret = -EIO;
+            goto exit;
+        }
+        ALOGD("%s: set_fm_volume usecase", __func__);
+        fm_set_volume(adev, vol);
+    }
+
+exit:
+    ALOGV("%s: exit", __func__);
+}
+#endif /* FM_ENABLED end */
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 045f031..e80f88f 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -94,6 +94,7 @@
     [USECASE_AUDIO_RECORD] = "audio-record",
     [USECASE_AUDIO_RECORD_LOW_LATENCY] = "low-latency-record",
     [USECASE_VOICE_CALL] = "voice-call",
+    [USECASE_AUDIO_PLAYBACK_FM] = "play-fm",
 };
 
 
@@ -110,13 +111,16 @@
     STRING_TO_ENUM(AUDIO_CHANNEL_OUT_7POINT1),
 };
 
+static struct audio_device *adev = NULL;
+static pthread_mutex_t adev_init_lock;
+static bool is_adev_initialised = false;
 
 static int enable_audio_route(struct audio_device *adev,
                               struct audio_usecase *usecase,
                               bool update_mixer)
 {
     snd_device_t snd_device;
-    char mixer_path[50];
+    char mixer_path[MIXER_PATH_MAX_LENGTH];
 
     if (usecase == NULL)
         return -EINVAL;
@@ -139,12 +143,12 @@
     return 0;
 }
 
-static int disable_audio_route(struct audio_device *adev,
+int disable_audio_route(struct audio_device *adev,
                                struct audio_usecase *usecase,
                                bool update_mixer)
 {
     snd_device_t snd_device;
-    char mixer_path[50];
+    char mixer_path[MIXER_PATH_MAX_LENGTH];
 
     if (usecase == NULL)
         return -EINVAL;
@@ -196,7 +200,7 @@
     return 0;
 }
 
-static int disable_snd_device(struct audio_device *adev,
+int disable_snd_device(struct audio_device *adev,
                               snd_device_t snd_device,
                               bool update_mixer)
 {
@@ -384,7 +388,7 @@
     return ret;
 }
 
-static struct audio_usecase *get_usecase_from_list(struct audio_device *adev,
+struct audio_usecase *get_usecase_from_list(struct audio_device *adev,
                                                    audio_usecase_t uc_id)
 {
     struct audio_usecase *usecase;
@@ -398,7 +402,7 @@
     return NULL;
 }
 
-static int select_devices(struct audio_device *adev,
+int select_devices(struct audio_device *adev,
                           audio_usecase_t uc_id)
 {
     snd_device_t out_snd_device = SND_DEVICE_NONE;
@@ -970,6 +974,13 @@
         pthread_mutex_unlock(&adev->lock);
         pthread_mutex_unlock(&out->lock);
     }
+
+    if (out == adev->primary_output) {
+        pthread_mutex_lock(&adev->lock);
+        audio_extn_set_parameters(adev, parms);
+        pthread_mutex_unlock(&adev->lock);
+    }
+
     str_parms_destroy(parms);
     ALOGV("%s: exit: code(%d)", __func__, ret);
     return ret;
@@ -1710,12 +1721,20 @@
 static int adev_open(const hw_module_t *module, const char *name,
                      hw_device_t **device)
 {
-    struct audio_device *adev;
     int i, ret;
 
     ALOGD("%s: enter", __func__);
     if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) return -EINVAL;
 
+    pthread_mutex_lock(&adev_init_lock);
+    if (is_adev_initialised == true){
+            *device = &adev->device.common;
+            ALOGD("%s: returning existing instance of adev", __func__);
+            ALOGD("%s: exit", __func__);
+            pthread_mutex_unlock(&adev_init_lock);
+            return 0;
+    }
+
     adev = calloc(1, sizeof(struct audio_device));
 
     adev->device.common.tag = HARDWARE_DEVICE_TAG;
@@ -1742,7 +1761,6 @@
     adev->device.dump = adev_dump;
 
     /* Set the default route before the PCM stream is opened */
-    pthread_mutex_lock(&adev->lock);
     adev->mode = AUDIO_MODE_NORMAL;
     adev->active_input = NULL;
     adev->primary_output = NULL;
@@ -1756,7 +1774,6 @@
     adev->acdb_settings = TTY_MODE_OFF;
     adev->snd_dev_ref_cnt = calloc(SND_DEVICE_MAX, sizeof(int));
     list_init(&adev->usecase_list);
-    pthread_mutex_unlock(&adev->lock);
 
     /* Loads platform specific libraries dynamically */
     adev->platform = platform_init(adev);
@@ -1769,6 +1786,10 @@
     }
     *device = &adev->device.common;
 
+    /* update init flag*/
+    is_adev_initialised = true;
+    pthread_mutex_unlock(&adev_init_lock);
+
     ALOGV("%s: exit", __func__);
     return 0;
 }
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index ecb6245..59f82d2 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -50,6 +50,8 @@
     USECASE_AUDIO_PLAYBACK_DEEP_BUFFER = 0,
     USECASE_AUDIO_PLAYBACK_LOW_LATENCY,
     USECASE_AUDIO_PLAYBACK_MULTI_CH,
+    /* FM usecase */
+    USECASE_AUDIO_PLAYBACK_FM,
 
     /* Capture usecases */
     USECASE_AUDIO_RECORD,
@@ -151,6 +153,16 @@
     void *platform;
 };
 
+int select_devices(struct audio_device *adev,
+                          audio_usecase_t uc_id);
+int disable_audio_route(struct audio_device *adev,
+                               struct audio_usecase *usecase,
+                               bool update_mixer);
+int disable_snd_device(struct audio_device *adev,
+                              snd_device_t snd_device,
+                              bool update_mixer);
+struct audio_usecase *get_usecase_from_list(struct audio_device *adev,
+                                                   audio_usecase_t uc_id);
 /*
  * NOTE: when multiple mutexes have to be acquired, always take the
  * stream_in or stream_out mutex first, followed by the audio_device mutex.
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 85c57fc..02940b4 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -93,6 +93,7 @@
     [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
                                           LOWLATENCY_PCM_DEVICE},
     [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
+    [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
 };
 
 /* Array to store sound devices */
@@ -114,6 +115,7 @@
     [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
     [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
     [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
+    [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
     [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
     [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
     [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
@@ -142,6 +144,7 @@
     [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
     [SND_DEVICE_IN_VOICE_REC_DMIC] = "voice-rec-dmic-ef",
     [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
+    [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
     [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
 };
 
@@ -163,6 +166,7 @@
     [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
     [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
     [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
+    [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
     [SND_DEVICE_OUT_ANC_HEADSET] = 26,
     [SND_DEVICE_OUT_ANC_FB_HEADSET] = 26,
     [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
@@ -188,6 +192,7 @@
     [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
     [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
     [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
+    [SND_DEVICE_IN_CAPTURE_FM] = 0,
     [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
     /* TODO: Update with proper acdb ids */
     [SND_DEVICE_IN_VOICE_REC_DMIC] = 62,
@@ -361,6 +366,10 @@
         strcat(mixer_path, " hdmi");
     else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
         strcat(mixer_path, " speaker-and-hdmi");
+    else if (snd_device == SND_DEVICE_IN_CAPTURE_FM)
+        strlcat(mixer_path, " capture-fm", MIXER_PATH_MAX_LENGTH);
+    else if (snd_device == SND_DEVICE_OUT_TRANSMISSION_FM)
+        strlcat(mixer_path, " transmission-fm", MIXER_PATH_MAX_LENGTH);
 }
 
 int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
@@ -545,6 +554,8 @@
             snd_device = SND_DEVICE_OUT_BT_SCO;
         } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
             snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
+        } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
+            snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
         } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
             if (is_operator_tmus())
                 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
@@ -605,6 +616,8 @@
         snd_device = SND_DEVICE_OUT_BT_SCO;
     } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
         snd_device = SND_DEVICE_OUT_HDMI ;
+    } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
+        snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
     } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
         snd_device = SND_DEVICE_OUT_HANDSET;
     } else {
@@ -724,6 +737,10 @@
             } else
                 set_echo_reference(adev->mixer, "NONE");
         }
+    } else if (source == AUDIO_SOURCE_FM_RX) {
+        if (in_device & AUDIO_DEVICE_IN_FM_RX) {
+            snd_device = SND_DEVICE_IN_CAPTURE_FM;
+        }
     } else if (source == AUDIO_SOURCE_DEFAULT) {
         goto exit;
     }
@@ -746,6 +763,8 @@
             snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
         } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
             snd_device = SND_DEVICE_IN_HDMI_MIC;
+        } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
+            snd_device = SND_DEVICE_IN_CAPTURE_FM;
         } else {
             ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
             ALOGW("%s: Using default handset-mic", __func__);
diff --git a/hal/msm8974/platform.h b/hal/msm8974/platform.h
index bbbb821..1bc4fc4 100644
--- a/hal/msm8974/platform.h
+++ b/hal/msm8974/platform.h
@@ -60,6 +60,7 @@
     SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES,
     SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES,
     SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET,
+    SND_DEVICE_OUT_TRANSMISSION_FM,
     SND_DEVICE_OUT_ANC_HEADSET,
     SND_DEVICE_OUT_ANC_FB_HEADSET,
     SND_DEVICE_OUT_VOICE_ANC_HEADSET,
@@ -95,6 +96,7 @@
     SND_DEVICE_IN_VOICE_REC_MIC,
     SND_DEVICE_IN_VOICE_REC_DMIC,
     SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE,
+    SND_DEVICE_IN_CAPTURE_FM,
     SND_DEVICE_IN_AANC_HANDSET_MIC,
     SND_DEVICE_IN_END,
 
@@ -113,6 +115,7 @@
 #define VOLUME_SET 0
 #define MUTE_SET 1
 #define VOLUME_CTL_PARAM_NUM 3
+#define MIXER_PATH_MAX_LENGTH 100
 
 /*
  * tinyAlsa library interprets period size as number of frames
@@ -138,6 +141,8 @@
 #define DEEP_BUFFER_PCM_DEVICE 0
 #define MULTI_CHANNEL_PCM_DEVICE 1
 #define VOICE_CALL_PCM_DEVICE 2
+#define FM_PLAYBACK_PCM_DEVICE 5
+#define FM_CAPTURE_PCM_DEVICE  6
 
 #ifdef PLATFORM_MSM8610
 #define LOWLATENCY_PCM_DEVICE 12