hal: HFP support for setting sampling rate

- Add support for setting sampling rate using setparameter. This
is to support 8000 or 16000 sampling rate set from BT

Change-Id: Ia6c7e530df0ba0226e492937e1c9acc70f6c6d13
diff --git a/hal/audio_extn/hfp.c b/hal/audio_extn/hfp.c
index 6b0546a..4eb9d37 100644
--- a/hal/audio_extn/hfp.c
+++ b/hal/audio_extn/hfp.c
@@ -42,6 +42,7 @@
 
 #ifdef HFP_ENABLED
 #define AUDIO_PARAMETER_HFP_ENABLE      "hfp_enable"
+#define AUDIO_PARAMETER_HFP_SET_SAMPLING_RATE "hfp_set_sampling_rate"
 
 static int32_t start_hfp(struct audio_device *adev,
                                struct str_parms *parms);
@@ -55,6 +56,7 @@
     struct pcm *hfp_pcm_tx;
     bool is_hfp_running;
     int hfp_volume;
+    audio_usecase_t ucid;
 };
 
 static struct hfp_module hfpmod = {
@@ -64,6 +66,7 @@
     .hfp_pcm_tx = NULL,
     .hfp_volume = 0,
     .is_hfp_running = 0,
+    .ucid = USECASE_AUDIO_HFP_SCO,
 };
 static struct pcm_config pcm_config_hfp = {
     .channels = 1,
@@ -86,7 +89,7 @@
     ALOGD("%s: enter", __func__);
 
     uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
-    uc_info->id = USECASE_AUDIO_HFP_SCO;
+    uc_info->id = hfpmod.ucid;
     uc_info->type = PCM_HFP_CALL;
     uc_info->stream.out = adev->primary_output;
     uc_info->devices = adev->primary_output->devices;
@@ -95,7 +98,7 @@
 
     list_add_tail(&adev->usecase_list, &uc_info->list);
 
-    select_devices(adev, USECASE_AUDIO_HFP_SCO);
+    select_devices(adev, hfpmod.ucid);
 
     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);
@@ -193,10 +196,10 @@
         hfpmod.hfp_pcm_tx = NULL;
     }
 
-    uc_info = get_usecase_from_list(adev, USECASE_AUDIO_HFP_SCO);
+    uc_info = get_usecase_from_list(adev, hfpmod.ucid);
     if (uc_info == NULL) {
         ALOGE("%s: Could not find the usecase (%d) in the list",
-              __func__, USECASE_AUDIO_HFP_SCO);
+              __func__, hfpmod.ucid);
         return -EINVAL;
     }
 
@@ -217,6 +220,7 @@
 void audio_extn_hfp_set_parameters(struct audio_device *adev, struct str_parms *parms)
 {
     int ret;
+    int rate;
     char value[32]={0};
 
     ret = str_parms_get_str(parms, AUDIO_PARAMETER_HFP_ENABLE, value,
@@ -227,5 +231,21 @@
            else
                stop_hfp(adev);
     }
+    memset(value, 0, sizeof(value));
+    ret = str_parms_get_str(parms,AUDIO_PARAMETER_HFP_SET_SAMPLING_RATE, value,
+                            sizeof(value));
+    if (ret >= 0) {
+           rate = atoi(value);
+           if (rate == 8000){
+               hfpmod.ucid = USECASE_AUDIO_HFP_SCO;
+               pcm_config_hfp.rate = rate;
+           }
+           else if (rate == 16000){
+               hfpmod.ucid = USECASE_AUDIO_HFP_SCO_WB;
+               pcm_config_hfp.rate = rate;
+           }
+           else
+               ALOGE("Unsupported rate..");
+    }
 }
 #endif /*HFP_ENABLED*/
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index fefbfa4..da128b3 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -113,6 +113,7 @@
     [USECASE_AUDIO_RECORD_FM_VIRTUAL] = "fm-virtual-record",
     [USECASE_AUDIO_PLAYBACK_FM] = "play-fm",
     [USECASE_AUDIO_HFP_SCO] = "hfp-sco",
+    [USECASE_AUDIO_HFP_SCO_WB] = "hfp-sco-wb",
     [USECASE_VOICE_CALL] = "voice-call",
     
     [USECASE_VOICE2_CALL] = "voice2-call",
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index 73575e8..205977b 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -65,6 +65,7 @@
 
     /* HFP Use case*/
     USECASE_AUDIO_HFP_SCO,
+    USECASE_AUDIO_HFP_SCO_WB,
 
     /* Capture usecases */
     USECASE_AUDIO_RECORD,
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 9ba3b94..ff9aeaa 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -120,6 +120,7 @@
                                   MULTIMEDIA2_PCM_DEVICE},
     [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
     [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
+    [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX},
     [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
     [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
     [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},