blob: 89c42c8d003f8c12ae845a0882f8d61587931588 [file] [log] [blame]
Xiaoyu Ye91553e62017-11-21 17:35:50 -08001/* Copyright (c) 2012-2018, 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 Chend2530072014-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 Chen3e5b30a2018-10-24 01:04:25 -070059#elif defined PLATFORM_AUTO
60#define HFP_RX_VOLUME "Playback 36 Volume"
Naresh Tannirucb5b5782018-10-12 20:42:07 +053061#elif defined (PLATFORM_MSM8998) || defined (PLATFORM_MSMFALCON) || defined (PLATFORM_SDM845) || defined (PLATFORM_SDM710) || defined (PLATFORM_QCS605) || defined (PLATFORM_MSMNILE) || defined (PLATFORM_MSMSTEPPE) || defined (PLATFORM_QCS405)
Banajit Goswami4c0dff22016-03-04 18:31:22 -080062#define HFP_RX_VOLUME "SLIMBUS_7 LOOPBACK Volume"
Sudheer Papothi19e43d02014-07-16 02:34:41 +053063#else
64#define HFP_RX_VOLUME "Internal HFP RX Volume"
65#endif
66
Vimal Puthanveed584048b2013-12-11 17:00:50 -080067static int32_t start_hfp(struct audio_device *adev,
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -080068 struct str_parms *parms);
69
Vimal Puthanveed584048b2013-12-11 17:00:50 -080070static int32_t stop_hfp(struct audio_device *adev);
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -080071
72struct hfp_module {
73 struct pcm *hfp_sco_rx;
74 struct pcm *hfp_sco_tx;
75 struct pcm *hfp_pcm_rx;
76 struct pcm *hfp_pcm_tx;
77 bool is_hfp_running;
Amit Shekhar967cab32014-02-07 17:03:21 -080078 float hfp_volume;
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +053079 int32_t hfp_pcm_dev_id;
Vimal Puthanveed47e64852013-12-20 13:23:39 -080080 audio_usecase_t ucid;
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -080081};
82
83static struct hfp_module hfpmod = {
84 .hfp_sco_rx = NULL,
85 .hfp_sco_tx = NULL,
86 .hfp_pcm_rx = NULL,
87 .hfp_pcm_tx = NULL,
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -080088 .is_hfp_running = 0,
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +053089 .hfp_volume = 0,
90 .hfp_pcm_dev_id = HFP_ASM_RX_TX,
Vimal Puthanveed47e64852013-12-20 13:23:39 -080091 .ucid = USECASE_AUDIO_HFP_SCO,
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -080092};
93static struct pcm_config pcm_config_hfp = {
94 .channels = 1,
95 .rate = 8000,
96 .period_size = 240,
97 .period_count = 2,
98 .format = PCM_FORMAT_S16_LE,
99 .start_threshold = 0,
100 .stop_threshold = INT_MAX,
101 .avail_min = 0,
102};
103
Amit Shekhar967cab32014-02-07 17:03:21 -0800104static int32_t hfp_set_volume(struct audio_device *adev, float value)
105{
106 int32_t vol, ret = 0;
107 struct mixer_ctl *ctl;
Sudheer Papothi19e43d02014-07-16 02:34:41 +0530108 const char *mixer_ctl_name = HFP_RX_VOLUME;
Amit Shekhar967cab32014-02-07 17:03:21 -0800109
110 ALOGV("%s: entry", __func__);
111 ALOGD("%s: (%f)\n", __func__, value);
112
Satya Krishna Pindiproli3ed6d792014-09-09 15:32:25 +0530113 hfpmod.hfp_volume = value;
Amit Shekhar967cab32014-02-07 17:03:21 -0800114 if (value < 0.0) {
115 ALOGW("%s: (%f) Under 0.0, assuming 0.0\n", __func__, value);
116 value = 0.0;
117 } else {
118 value = ((value > 15.000000) ? 1.0 : (value / 15));
119 ALOGW("%s: Volume brought with in range (%f)\n", __func__, value);
120 }
121 vol = lrint((value * 0x2000) + 0.5);
Amit Shekhar967cab32014-02-07 17:03:21 -0800122
123 if (!hfpmod.is_hfp_running) {
124 ALOGV("%s: HFP not active, ignoring set_hfp_volume call", __func__);
125 return -EIO;
126 }
127
128 ALOGD("%s: Setting HFP volume to %d \n", __func__, vol);
129 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
130 if (!ctl) {
131 ALOGE("%s: Could not get ctl for mixer cmd - %s",
132 __func__, mixer_ctl_name);
133 return -EINVAL;
134 }
135 if(mixer_ctl_set_value(ctl, 0, vol) < 0) {
136 ALOGE("%s: Couldn't set HFP Volume: [%d]", __func__, vol);
137 return -EINVAL;
138 }
139
140 ALOGV("%s: exit", __func__);
141 return ret;
142}
143
Vimal Puthanveed584048b2013-12-11 17:00:50 -0800144static int32_t start_hfp(struct audio_device *adev,
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700145 struct str_parms *parms __unused)
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800146{
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +0530147 int32_t ret = 0;
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800148 struct audio_usecase *uc_info;
149 int32_t pcm_dev_rx_id, pcm_dev_tx_id, pcm_dev_asm_rx_id, pcm_dev_asm_tx_id;
150
151 ALOGD("%s: enter", __func__);
152
153 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700154
155 if (!uc_info)
156 return -ENOMEM;
157
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800158 uc_info->id = hfpmod.ucid;
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800159 uc_info->type = PCM_HFP_CALL;
160 uc_info->stream.out = adev->primary_output;
161 uc_info->devices = adev->primary_output->devices;
162 uc_info->in_snd_device = SND_DEVICE_NONE;
163 uc_info->out_snd_device = SND_DEVICE_NONE;
164
165 list_add_tail(&adev->usecase_list, &uc_info->list);
166
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800167 select_devices(adev, hfpmod.ucid);
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800168
Derek Chend2530072014-11-24 12:39:14 -0800169 if ((uc_info->out_snd_device != SND_DEVICE_NONE) ||
170 (uc_info->in_snd_device != SND_DEVICE_NONE)) {
171 if (audio_extn_ext_hw_plugin_usecase_start(adev->ext_hw_plugin, uc_info))
172 ALOGE("%s: failed to start ext hw plugin", __func__);
173 }
174
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800175 pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK);
176 pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE);
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +0530177 pcm_dev_asm_rx_id = hfpmod.hfp_pcm_dev_id;
178 pcm_dev_asm_tx_id = hfpmod.hfp_pcm_dev_id;
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800179 if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0 ||
180 pcm_dev_asm_rx_id < 0 || pcm_dev_asm_tx_id < 0 ) {
181 ALOGE("%s: Invalid PCM devices (rx: %d tx: %d asm: rx tx %d) for the usecase(%d)",
182 __func__, pcm_dev_rx_id, pcm_dev_tx_id, pcm_dev_asm_rx_id, uc_info->id);
183 ret = -EIO;
184 goto exit;
185 }
186
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +0530187 ALOGD("%s: HFP PCM devices (rx: %d tx: %d pcm dev id: %d) usecase(%d)",
188 __func__, pcm_dev_rx_id, pcm_dev_tx_id, hfpmod.hfp_pcm_dev_id, uc_info->id);
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800189
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800190 hfpmod.hfp_sco_rx = pcm_open(adev->snd_card,
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800191 pcm_dev_asm_rx_id,
192 PCM_OUT, &pcm_config_hfp);
193 if (hfpmod.hfp_sco_rx && !pcm_is_ready(hfpmod.hfp_sco_rx)) {
194 ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_sco_rx));
195 ret = -EIO;
196 goto exit;
197 }
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +0530198
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800199 hfpmod.hfp_pcm_rx = pcm_open(adev->snd_card,
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800200 pcm_dev_rx_id,
201 PCM_OUT, &pcm_config_hfp);
202 if (hfpmod.hfp_pcm_rx && !pcm_is_ready(hfpmod.hfp_pcm_rx)) {
203 ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_pcm_rx));
204 ret = -EIO;
205 goto exit;
206 }
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +0530207
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800208 hfpmod.hfp_sco_tx = pcm_open(adev->snd_card,
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800209 pcm_dev_asm_tx_id,
210 PCM_IN, &pcm_config_hfp);
211 if (hfpmod.hfp_sco_tx && !pcm_is_ready(hfpmod.hfp_sco_tx)) {
212 ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_sco_tx));
213 ret = -EIO;
214 goto exit;
215 }
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +0530216
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800217 hfpmod.hfp_pcm_tx = pcm_open(adev->snd_card,
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800218 pcm_dev_tx_id,
219 PCM_IN, &pcm_config_hfp);
220 if (hfpmod.hfp_pcm_tx && !pcm_is_ready(hfpmod.hfp_pcm_tx)) {
221 ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_pcm_tx));
222 ret = -EIO;
223 goto exit;
224 }
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +0530225
Satya Krishna Pindiprolice903a02014-07-28 12:40:56 +0530226 if (pcm_start(hfpmod.hfp_sco_rx) < 0) {
227 ALOGE("%s: pcm start for hfp sco rx failed", __func__);
228 ret = -EINVAL;
229 goto exit;
230 }
231 if (pcm_start(hfpmod.hfp_sco_tx) < 0) {
232 ALOGE("%s: pcm start for hfp sco tx failed", __func__);
233 ret = -EINVAL;
234 goto exit;
235 }
236 if (pcm_start(hfpmod.hfp_pcm_rx) < 0) {
237 ALOGE("%s: pcm start for hfp pcm rx failed", __func__);
238 ret = -EINVAL;
239 goto exit;
240 }
241 if (pcm_start(hfpmod.hfp_pcm_tx) < 0) {
242 ALOGE("%s: pcm start for hfp pcm tx failed", __func__);
243 ret = -EINVAL;
244 goto exit;
245 }
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800246
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800247 hfpmod.is_hfp_running = true;
Amit Shekhar967cab32014-02-07 17:03:21 -0800248 hfp_set_volume(adev, hfpmod.hfp_volume);
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800249
250 ALOGD("%s: exit: status(%d)", __func__, ret);
251 return 0;
252
253exit:
Vimal Puthanveed584048b2013-12-11 17:00:50 -0800254 stop_hfp(adev);
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800255 ALOGE("%s: Problem in HFP start: status(%d)", __func__, ret);
256 return ret;
257}
258
Vimal Puthanveed584048b2013-12-11 17:00:50 -0800259static int32_t stop_hfp(struct audio_device *adev)
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800260{
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +0530261 int32_t ret = 0;
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800262 struct audio_usecase *uc_info;
263
264 ALOGD("%s: enter", __func__);
265 hfpmod.is_hfp_running = false;
266
267 /* 1. Close the PCM devices */
268 if (hfpmod.hfp_sco_rx) {
269 pcm_close(hfpmod.hfp_sco_rx);
270 hfpmod.hfp_sco_rx = NULL;
271 }
272 if (hfpmod.hfp_sco_tx) {
273 pcm_close(hfpmod.hfp_sco_tx);
274 hfpmod.hfp_sco_tx = NULL;
275 }
276 if (hfpmod.hfp_pcm_rx) {
277 pcm_close(hfpmod.hfp_pcm_rx);
278 hfpmod.hfp_pcm_rx = NULL;
279 }
280 if (hfpmod.hfp_pcm_tx) {
281 pcm_close(hfpmod.hfp_pcm_tx);
282 hfpmod.hfp_pcm_tx = NULL;
283 }
284
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800285 uc_info = get_usecase_from_list(adev, hfpmod.ucid);
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800286 if (uc_info == NULL) {
287 ALOGE("%s: Could not find the usecase (%d) in the list",
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800288 __func__, hfpmod.ucid);
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800289 return -EINVAL;
290 }
291
Derek Chend2530072014-11-24 12:39:14 -0800292 if ((uc_info->out_snd_device != SND_DEVICE_NONE) ||
293 (uc_info->in_snd_device != SND_DEVICE_NONE)) {
294 if (audio_extn_ext_hw_plugin_usecase_stop(adev->ext_hw_plugin, uc_info))
295 ALOGE("%s: failed to stop ext hw plugin", __func__);
296 }
297
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530298 /* 2. Disable echo reference while stopping hfp */
Apoorv Raghuvanshi924b3022015-07-06 15:07:14 -0700299 platform_set_echo_reference(adev, false, uc_info->devices);
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530300
301 /* 3. Get and set stream specific mixer controls */
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700302 disable_audio_route(adev, uc_info);
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800303
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530304 /* 4. Disable the rx and tx devices */
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700305 disable_snd_device(adev, uc_info->out_snd_device);
306 disable_snd_device(adev, uc_info->in_snd_device);
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800307
308 list_remove(&uc_info->list);
309 free(uc_info);
310
311 ALOGD("%s: exit: status(%d)", __func__, ret);
312 return ret;
313}
Vimal Puthanveed584048b2013-12-11 17:00:50 -0800314
Vimal Puthanveed37b4a1c2014-01-07 16:47:47 -0800315bool audio_extn_hfp_is_active(struct audio_device *adev)
316{
317 struct audio_usecase *hfp_usecase = NULL;
Vimal Puthanveed41fcff22014-01-23 15:56:53 -0800318 hfp_usecase = get_usecase_from_list(adev, hfpmod.ucid);
Vimal Puthanveed37b4a1c2014-01-07 16:47:47 -0800319
320 if (hfp_usecase != NULL)
321 return true;
322 else
323 return false;
324}
325
Dhanalakshmi Siddani823dc5a2016-09-28 14:47:26 +0530326int hfp_set_mic_mute(struct audio_device *adev, bool state)
327{
328 struct mixer_ctl *ctl;
329 const char *mixer_ctl_name = "HFP TX Mute";
Manish Dewangan338c50a2017-09-12 15:22:03 +0530330 long set_values[ ] = {0};
Dhanalakshmi Siddani823dc5a2016-09-28 14:47:26 +0530331
332 ALOGI("%s: enter, state=%d", __func__, state);
333
334 set_values[0] = state;
335 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
336 if (!ctl) {
337 ALOGE("%s: Could not get ctl for mixer cmd - %s",
338 __func__, mixer_ctl_name);
339 return -EINVAL;
340 }
341 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
342 ALOGV("%s: exit", __func__);
343 return 0;
344}
345
Vimal Puthanveed41fcff22014-01-23 15:56:53 -0800346audio_usecase_t audio_extn_hfp_get_usecase()
347{
348 return hfpmod.ucid;
349}
350
Vimal Puthanveed584048b2013-12-11 17:00:50 -0800351void audio_extn_hfp_set_parameters(struct audio_device *adev, struct str_parms *parms)
352{
353 int ret;
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800354 int rate;
Vimal Puthanveed21e5c762014-01-08 14:10:09 -0800355 int val;
Amit Shekhar967cab32014-02-07 17:03:21 -0800356 float vol;
Vimal Puthanveed584048b2013-12-11 17:00:50 -0800357 char value[32]={0};
358
359 ret = str_parms_get_str(parms, AUDIO_PARAMETER_HFP_ENABLE, value,
360 sizeof(value));
361 if (ret >= 0) {
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +0530362 if (!strncmp(value, "true", sizeof(value)) && !hfpmod.is_hfp_running)
363 ret = start_hfp(adev,parms);
364 else if (!strncmp(value, "false", sizeof(value)) && hfpmod.is_hfp_running)
365 stop_hfp(adev);
366 else
367 ALOGE("hfp_enable=%s is unsupported", value);
Vimal Puthanveed584048b2013-12-11 17:00:50 -0800368 }
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800369 memset(value, 0, sizeof(value));
370 ret = str_parms_get_str(parms,AUDIO_PARAMETER_HFP_SET_SAMPLING_RATE, value,
371 sizeof(value));
372 if (ret >= 0) {
373 rate = atoi(value);
374 if (rate == 8000){
375 hfpmod.ucid = USECASE_AUDIO_HFP_SCO;
376 pcm_config_hfp.rate = rate;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700377 } else if (rate == 16000){
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800378 hfpmod.ucid = USECASE_AUDIO_HFP_SCO_WB;
379 pcm_config_hfp.rate = rate;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700380 } else
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800381 ALOGE("Unsupported rate..");
382 }
Vimal Puthanveed21e5c762014-01-08 14:10:09 -0800383
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700384 if (hfpmod.is_hfp_running) {
Vimal Puthanveed21e5c762014-01-08 14:10:09 -0800385 memset(value, 0, sizeof(value));
386 ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING,
387 value, sizeof(value));
388 if (ret >= 0) {
389 val = atoi(value);
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700390 if (val > 0)
Vimal Puthanveed21e5c762014-01-08 14:10:09 -0800391 select_devices(adev, hfpmod.ucid);
392 }
393 }
Amit Shekhar967cab32014-02-07 17:03:21 -0800394
395 memset(value, 0, sizeof(value));
396 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HFP_VOLUME,
397 value, sizeof(value));
398 if (ret >= 0) {
399 if (sscanf(value, "%f", &vol) != 1){
400 ALOGE("%s: error in retrieving hfp volume", __func__);
401 ret = -EIO;
402 goto exit;
403 }
404 ALOGD("%s: set_hfp_volume usecase, Vol: [%f]", __func__, vol);
405 hfp_set_volume(adev, vol);
406 }
Satya Krishna Pindiprolic6b0a742017-02-03 14:37:18 +0530407
408 memset(value, 0, sizeof(value));
409 ret = str_parms_get_str(parms, AUDIO_PARAMETER_HFP_PCM_DEV_ID, value, sizeof(value));
410 if (ret >= 0) {
411 hfpmod.hfp_pcm_dev_id = atoi(value);
412 ALOGD("Updating HFP_PCM_DEV_ID as %d from platform XML", hfpmod.hfp_pcm_dev_id);
413 str_parms_del(parms, AUDIO_PARAMETER_HFP_PCM_DEV_ID);
414 }
415
Amit Shekhar967cab32014-02-07 17:03:21 -0800416exit:
417 ALOGV("%s Exit",__func__);
Vimal Puthanveed584048b2013-12-11 17:00:50 -0800418}
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800419#endif /*HFP_ENABLED*/