blob: 0c105d0ae126be017fd01249f71201e5808c7e7b [file] [log] [blame]
Meng Wang74ace552018-10-08 13:06:05 +08001/* Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -08002
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions are
5met:
6 * Redistributions of source code must retain the above copyright
7 notice, this list of conditions and the following disclaimer.
8 * Redistributions in binary form must reproduce the above
9 copyright notice, this list of conditions and the following
10 disclaimer in the documentation and/or other materials provided
11 with the distribution.
12 * Neither the name of The Linux Foundation nor the names of its
13 contributors may be used to endorse or promote products derived
14 from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
27
28#define LOG_TAG "audio_hw_hfp"
29/*#define LOG_NDEBUG 0*/
30#define LOG_NDDEBUG 0
31
32#include <errno.h>
33#include <math.h>
34#include <cutils/log.h>
35
36#include "audio_hw.h"
37#include "platform.h"
38#include "platform_api.h"
39#include <stdlib.h>
40#include <cutils/str_parms.h>
Derek Chencdd17c72014-11-24 12:39:14 -080041#include "audio_extn.h"
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -080042
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053043#ifdef DYNAMIC_LOG_ENABLED
44#include <log_xml_parser.h>
45#define LOG_MASK HAL_MOD_FILE_HFP
46#include <log_utils.h>
47#endif
48
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -080049#ifdef HFP_ENABLED
50#define AUDIO_PARAMETER_HFP_ENABLE "hfp_enable"
Vimal Puthanveed47e64852013-12-20 13:23:39 -080051#define AUDIO_PARAMETER_HFP_SET_SAMPLING_RATE "hfp_set_sampling_rate"
Amit Shekhar967cab32014-02-07 17:03:21 -080052#define AUDIO_PARAMETER_KEY_HFP_VOLUME "hfp_volume"
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +053053#define AUDIO_PARAMETER_HFP_PCM_DEV_ID "hfp_pcm_dev_id"
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -080054
Sudheer Papothi19e43d02014-07-16 02:34:41 +053055#ifdef PLATFORM_MSM8994
56#define HFP_RX_VOLUME "SEC AUXPCM LOOPBACK Volume"
Banajit Goswamida77c452015-10-14 20:45:22 -070057#elif defined PLATFORM_MSM8996
58#define HFP_RX_VOLUME "PRI AUXPCM LOOPBACK Volume"
Derek Chen53e6dd62018-10-24 01:04:25 -070059#elif defined PLATFORM_AUTO
60#define HFP_RX_VOLUME "Playback 36 Volume"
Meng Wang74ace552018-10-08 13:06:05 +080061#elif defined (PLATFORM_MSM8998) || defined (PLATFORM_MSMFALCON) || \
62 defined (PLATFORM_SDM845) || defined (PLATFORM_SDM710) || \
63 defined (PLATFORM_QCS605) || defined (PLATFORM_MSMNILE) || \
64 defined (PLATFORM_MSMSTEPPE) || defined (PLATFORM_TRINKET) || \
65 defined (PLATFORM_KONA)
Banajit Goswami4c0dff22016-03-04 18:31:22 -080066#define HFP_RX_VOLUME "SLIMBUS_7 LOOPBACK Volume"
Sudheer Papothi19e43d02014-07-16 02:34:41 +053067#else
68#define HFP_RX_VOLUME "Internal HFP RX Volume"
69#endif
70
Vimal Puthanveed584048b2013-12-11 17:00:50 -080071static int32_t start_hfp(struct audio_device *adev,
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -080072 struct str_parms *parms);
73
Vimal Puthanveed584048b2013-12-11 17:00:50 -080074static int32_t stop_hfp(struct audio_device *adev);
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -080075
76struct hfp_module {
77 struct pcm *hfp_sco_rx;
78 struct pcm *hfp_sco_tx;
79 struct pcm *hfp_pcm_rx;
80 struct pcm *hfp_pcm_tx;
81 bool is_hfp_running;
Amit Shekhar967cab32014-02-07 17:03:21 -080082 float hfp_volume;
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +053083 int32_t hfp_pcm_dev_id;
Vimal Puthanveed47e64852013-12-20 13:23:39 -080084 audio_usecase_t ucid;
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -080085};
86
87static struct hfp_module hfpmod = {
88 .hfp_sco_rx = NULL,
89 .hfp_sco_tx = NULL,
90 .hfp_pcm_rx = NULL,
91 .hfp_pcm_tx = NULL,
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -080092 .is_hfp_running = 0,
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +053093 .hfp_volume = 0,
94 .hfp_pcm_dev_id = HFP_ASM_RX_TX,
Vimal Puthanveed47e64852013-12-20 13:23:39 -080095 .ucid = USECASE_AUDIO_HFP_SCO,
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -080096};
97static struct pcm_config pcm_config_hfp = {
98 .channels = 1,
99 .rate = 8000,
100 .period_size = 240,
101 .period_count = 2,
102 .format = PCM_FORMAT_S16_LE,
103 .start_threshold = 0,
104 .stop_threshold = INT_MAX,
105 .avail_min = 0,
106};
107
Amit Shekhar967cab32014-02-07 17:03:21 -0800108static int32_t hfp_set_volume(struct audio_device *adev, float value)
109{
110 int32_t vol, ret = 0;
111 struct mixer_ctl *ctl;
Sudheer Papothi19e43d02014-07-16 02:34:41 +0530112 const char *mixer_ctl_name = HFP_RX_VOLUME;
Amit Shekhar967cab32014-02-07 17:03:21 -0800113
114 ALOGV("%s: entry", __func__);
115 ALOGD("%s: (%f)\n", __func__, value);
116
Satya Krishna Pindiproli3ed6d792014-09-09 15:32:25 +0530117 hfpmod.hfp_volume = value;
Amit Shekhar967cab32014-02-07 17:03:21 -0800118 if (value < 0.0) {
119 ALOGW("%s: (%f) Under 0.0, assuming 0.0\n", __func__, value);
120 value = 0.0;
121 } else {
122 value = ((value > 15.000000) ? 1.0 : (value / 15));
123 ALOGW("%s: Volume brought with in range (%f)\n", __func__, value);
124 }
125 vol = lrint((value * 0x2000) + 0.5);
Amit Shekhar967cab32014-02-07 17:03:21 -0800126
127 if (!hfpmod.is_hfp_running) {
128 ALOGV("%s: HFP not active, ignoring set_hfp_volume call", __func__);
129 return -EIO;
130 }
131
132 ALOGD("%s: Setting HFP volume to %d \n", __func__, vol);
133 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
134 if (!ctl) {
135 ALOGE("%s: Could not get ctl for mixer cmd - %s",
136 __func__, mixer_ctl_name);
137 return -EINVAL;
138 }
139 if(mixer_ctl_set_value(ctl, 0, vol) < 0) {
140 ALOGE("%s: Couldn't set HFP Volume: [%d]", __func__, vol);
141 return -EINVAL;
142 }
143
144 ALOGV("%s: exit", __func__);
145 return ret;
146}
147
Vimal Puthanveed584048b2013-12-11 17:00:50 -0800148static int32_t start_hfp(struct audio_device *adev,
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700149 struct str_parms *parms __unused)
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800150{
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +0530151 int32_t ret = 0;
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800152 struct audio_usecase *uc_info;
153 int32_t pcm_dev_rx_id, pcm_dev_tx_id, pcm_dev_asm_rx_id, pcm_dev_asm_tx_id;
154
155 ALOGD("%s: enter", __func__);
156
157 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700158
159 if (!uc_info)
160 return -ENOMEM;
161
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800162 uc_info->id = hfpmod.ucid;
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800163 uc_info->type = PCM_HFP_CALL;
164 uc_info->stream.out = adev->primary_output;
165 uc_info->devices = adev->primary_output->devices;
166 uc_info->in_snd_device = SND_DEVICE_NONE;
167 uc_info->out_snd_device = SND_DEVICE_NONE;
168
169 list_add_tail(&adev->usecase_list, &uc_info->list);
170
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800171 select_devices(adev, hfpmod.ucid);
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800172
Derek Chencdd17c72014-11-24 12:39:14 -0800173 if ((uc_info->out_snd_device != SND_DEVICE_NONE) ||
174 (uc_info->in_snd_device != SND_DEVICE_NONE)) {
175 if (audio_extn_ext_hw_plugin_usecase_start(adev->ext_hw_plugin, uc_info))
176 ALOGE("%s: failed to start ext hw plugin", __func__);
177 }
178
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800179 pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK);
180 pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE);
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +0530181 pcm_dev_asm_rx_id = hfpmod.hfp_pcm_dev_id;
182 pcm_dev_asm_tx_id = hfpmod.hfp_pcm_dev_id;
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800183 if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0 ||
184 pcm_dev_asm_rx_id < 0 || pcm_dev_asm_tx_id < 0 ) {
185 ALOGE("%s: Invalid PCM devices (rx: %d tx: %d asm: rx tx %d) for the usecase(%d)",
186 __func__, pcm_dev_rx_id, pcm_dev_tx_id, pcm_dev_asm_rx_id, uc_info->id);
187 ret = -EIO;
188 goto exit;
189 }
190
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +0530191 ALOGD("%s: HFP PCM devices (rx: %d tx: %d pcm dev id: %d) usecase(%d)",
192 __func__, pcm_dev_rx_id, pcm_dev_tx_id, hfpmod.hfp_pcm_dev_id, uc_info->id);
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800193
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800194 hfpmod.hfp_sco_rx = pcm_open(adev->snd_card,
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800195 pcm_dev_asm_rx_id,
196 PCM_OUT, &pcm_config_hfp);
197 if (hfpmod.hfp_sco_rx && !pcm_is_ready(hfpmod.hfp_sco_rx)) {
198 ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_sco_rx));
199 ret = -EIO;
200 goto exit;
201 }
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +0530202
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800203 hfpmod.hfp_pcm_rx = pcm_open(adev->snd_card,
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800204 pcm_dev_rx_id,
205 PCM_OUT, &pcm_config_hfp);
206 if (hfpmod.hfp_pcm_rx && !pcm_is_ready(hfpmod.hfp_pcm_rx)) {
207 ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_pcm_rx));
208 ret = -EIO;
209 goto exit;
210 }
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +0530211
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800212 hfpmod.hfp_sco_tx = pcm_open(adev->snd_card,
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800213 pcm_dev_asm_tx_id,
214 PCM_IN, &pcm_config_hfp);
215 if (hfpmod.hfp_sco_tx && !pcm_is_ready(hfpmod.hfp_sco_tx)) {
216 ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_sco_tx));
217 ret = -EIO;
218 goto exit;
219 }
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +0530220
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800221 hfpmod.hfp_pcm_tx = pcm_open(adev->snd_card,
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800222 pcm_dev_tx_id,
223 PCM_IN, &pcm_config_hfp);
224 if (hfpmod.hfp_pcm_tx && !pcm_is_ready(hfpmod.hfp_pcm_tx)) {
225 ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_pcm_tx));
226 ret = -EIO;
227 goto exit;
228 }
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +0530229
Satya Krishna Pindiprolice903a02014-07-28 12:40:56 +0530230 if (pcm_start(hfpmod.hfp_sco_rx) < 0) {
231 ALOGE("%s: pcm start for hfp sco rx failed", __func__);
232 ret = -EINVAL;
233 goto exit;
234 }
235 if (pcm_start(hfpmod.hfp_sco_tx) < 0) {
236 ALOGE("%s: pcm start for hfp sco tx failed", __func__);
237 ret = -EINVAL;
238 goto exit;
239 }
240 if (pcm_start(hfpmod.hfp_pcm_rx) < 0) {
241 ALOGE("%s: pcm start for hfp pcm rx failed", __func__);
242 ret = -EINVAL;
243 goto exit;
244 }
245 if (pcm_start(hfpmod.hfp_pcm_tx) < 0) {
246 ALOGE("%s: pcm start for hfp pcm tx failed", __func__);
247 ret = -EINVAL;
248 goto exit;
249 }
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800250
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800251 hfpmod.is_hfp_running = true;
Amit Shekhar967cab32014-02-07 17:03:21 -0800252 hfp_set_volume(adev, hfpmod.hfp_volume);
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800253
254 ALOGD("%s: exit: status(%d)", __func__, ret);
255 return 0;
256
257exit:
Vimal Puthanveed584048b2013-12-11 17:00:50 -0800258 stop_hfp(adev);
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800259 ALOGE("%s: Problem in HFP start: status(%d)", __func__, ret);
260 return ret;
261}
262
Vimal Puthanveed584048b2013-12-11 17:00:50 -0800263static int32_t stop_hfp(struct audio_device *adev)
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800264{
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +0530265 int32_t ret = 0;
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800266 struct audio_usecase *uc_info;
267
268 ALOGD("%s: enter", __func__);
269 hfpmod.is_hfp_running = false;
270
271 /* 1. Close the PCM devices */
272 if (hfpmod.hfp_sco_rx) {
273 pcm_close(hfpmod.hfp_sco_rx);
274 hfpmod.hfp_sco_rx = NULL;
275 }
276 if (hfpmod.hfp_sco_tx) {
277 pcm_close(hfpmod.hfp_sco_tx);
278 hfpmod.hfp_sco_tx = NULL;
279 }
280 if (hfpmod.hfp_pcm_rx) {
281 pcm_close(hfpmod.hfp_pcm_rx);
282 hfpmod.hfp_pcm_rx = NULL;
283 }
284 if (hfpmod.hfp_pcm_tx) {
285 pcm_close(hfpmod.hfp_pcm_tx);
286 hfpmod.hfp_pcm_tx = NULL;
287 }
288
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800289 uc_info = get_usecase_from_list(adev, hfpmod.ucid);
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800290 if (uc_info == NULL) {
291 ALOGE("%s: Could not find the usecase (%d) in the list",
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800292 __func__, hfpmod.ucid);
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800293 return -EINVAL;
294 }
295
Derek Chencdd17c72014-11-24 12:39:14 -0800296 if ((uc_info->out_snd_device != SND_DEVICE_NONE) ||
297 (uc_info->in_snd_device != SND_DEVICE_NONE)) {
298 if (audio_extn_ext_hw_plugin_usecase_stop(adev->ext_hw_plugin, uc_info))
299 ALOGE("%s: failed to stop ext hw plugin", __func__);
300 }
301
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530302 /* 2. Disable echo reference while stopping hfp */
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -0700303 platform_set_echo_reference(adev, false, uc_info->devices);
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530304
305 /* 3. Get and set stream specific mixer controls */
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700306 disable_audio_route(adev, uc_info);
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800307
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530308 /* 4. Disable the rx and tx devices */
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700309 disable_snd_device(adev, uc_info->out_snd_device);
310 disable_snd_device(adev, uc_info->in_snd_device);
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800311
312 list_remove(&uc_info->list);
313 free(uc_info);
314
315 ALOGD("%s: exit: status(%d)", __func__, ret);
316 return ret;
317}
Vimal Puthanveed584048b2013-12-11 17:00:50 -0800318
Vimal Puthanveed37b4a1c2014-01-07 16:47:47 -0800319bool audio_extn_hfp_is_active(struct audio_device *adev)
320{
321 struct audio_usecase *hfp_usecase = NULL;
Vimal Puthanveed41fcff22014-01-23 15:56:53 -0800322 hfp_usecase = get_usecase_from_list(adev, hfpmod.ucid);
Vimal Puthanveed37b4a1c2014-01-07 16:47:47 -0800323
324 if (hfp_usecase != NULL)
325 return true;
326 else
327 return false;
328}
329
Dhanalakshmi Siddani823dc5a2016-09-28 14:47:26 +0530330int hfp_set_mic_mute(struct audio_device *adev, bool state)
331{
332 struct mixer_ctl *ctl;
333 const char *mixer_ctl_name = "HFP TX Mute";
Manish Dewangan338c50a2017-09-12 15:22:03 +0530334 long set_values[ ] = {0};
Dhanalakshmi Siddani823dc5a2016-09-28 14:47:26 +0530335
336 ALOGI("%s: enter, state=%d", __func__, state);
337
338 set_values[0] = state;
339 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
340 if (!ctl) {
341 ALOGE("%s: Could not get ctl for mixer cmd - %s",
342 __func__, mixer_ctl_name);
343 return -EINVAL;
344 }
345 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
346 ALOGV("%s: exit", __func__);
347 return 0;
348}
349
Vimal Puthanveed41fcff22014-01-23 15:56:53 -0800350audio_usecase_t audio_extn_hfp_get_usecase()
351{
352 return hfpmod.ucid;
353}
354
Vimal Puthanveed584048b2013-12-11 17:00:50 -0800355void audio_extn_hfp_set_parameters(struct audio_device *adev, struct str_parms *parms)
356{
357 int ret;
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800358 int rate;
Vimal Puthanveed21e5c762014-01-08 14:10:09 -0800359 int val;
Amit Shekhar967cab32014-02-07 17:03:21 -0800360 float vol;
Vimal Puthanveed584048b2013-12-11 17:00:50 -0800361 char value[32]={0};
362
363 ret = str_parms_get_str(parms, AUDIO_PARAMETER_HFP_ENABLE, value,
364 sizeof(value));
365 if (ret >= 0) {
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +0530366 if (!strncmp(value, "true", sizeof(value)) && !hfpmod.is_hfp_running)
367 ret = start_hfp(adev,parms);
368 else if (!strncmp(value, "false", sizeof(value)) && hfpmod.is_hfp_running)
369 stop_hfp(adev);
370 else
371 ALOGE("hfp_enable=%s is unsupported", value);
Vimal Puthanveed584048b2013-12-11 17:00:50 -0800372 }
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800373 memset(value, 0, sizeof(value));
374 ret = str_parms_get_str(parms,AUDIO_PARAMETER_HFP_SET_SAMPLING_RATE, value,
375 sizeof(value));
376 if (ret >= 0) {
377 rate = atoi(value);
378 if (rate == 8000){
379 hfpmod.ucid = USECASE_AUDIO_HFP_SCO;
380 pcm_config_hfp.rate = rate;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700381 } else if (rate == 16000){
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800382 hfpmod.ucid = USECASE_AUDIO_HFP_SCO_WB;
383 pcm_config_hfp.rate = rate;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700384 } else
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800385 ALOGE("Unsupported rate..");
386 }
Vimal Puthanveed21e5c762014-01-08 14:10:09 -0800387
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700388 if (hfpmod.is_hfp_running) {
Vimal Puthanveed21e5c762014-01-08 14:10:09 -0800389 memset(value, 0, sizeof(value));
390 ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING,
391 value, sizeof(value));
392 if (ret >= 0) {
393 val = atoi(value);
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700394 if (val > 0)
Vimal Puthanveed21e5c762014-01-08 14:10:09 -0800395 select_devices(adev, hfpmod.ucid);
396 }
397 }
Amit Shekhar967cab32014-02-07 17:03:21 -0800398
399 memset(value, 0, sizeof(value));
400 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HFP_VOLUME,
401 value, sizeof(value));
402 if (ret >= 0) {
403 if (sscanf(value, "%f", &vol) != 1){
404 ALOGE("%s: error in retrieving hfp volume", __func__);
405 ret = -EIO;
406 goto exit;
407 }
408 ALOGD("%s: set_hfp_volume usecase, Vol: [%f]", __func__, vol);
409 hfp_set_volume(adev, vol);
410 }
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +0530411
412 memset(value, 0, sizeof(value));
413 ret = str_parms_get_str(parms, AUDIO_PARAMETER_HFP_PCM_DEV_ID, value, sizeof(value));
414 if (ret >= 0) {
415 hfpmod.hfp_pcm_dev_id = atoi(value);
416 ALOGD("Updating HFP_PCM_DEV_ID as %d from platform XML", hfpmod.hfp_pcm_dev_id);
417 str_parms_del(parms, AUDIO_PARAMETER_HFP_PCM_DEV_ID);
418 }
419
Amit Shekhar967cab32014-02-07 17:03:21 -0800420exit:
421 ALOGV("%s Exit",__func__);
Vimal Puthanveed584048b2013-12-11 17:00:50 -0800422}
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800423#endif /*HFP_ENABLED*/