Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2019, The Linux Foundation. All rights reserved. |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 2 | |
| 3 | Redistribution and use in source and binary forms, with or without |
| 4 | modification, are permitted provided that the following conditions are |
| 5 | met: |
| 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 | |
| 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | IF 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> |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 34 | #include <log/log.h> |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 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 Chen | d253007 | 2014-11-24 12:39:14 -0800 | [diff] [blame] | 41 | #include "audio_extn.h" |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 42 | |
Revathi Uddaraju | 1eac8b0 | 2017-05-18 17:13:33 +0530 | [diff] [blame] | 43 | #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 Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 49 | #define AUDIO_PARAMETER_HFP_ENABLE "hfp_enable" |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 50 | #define AUDIO_PARAMETER_HFP_SET_SAMPLING_RATE "hfp_set_sampling_rate" |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 51 | #define AUDIO_PARAMETER_KEY_HFP_VOLUME "hfp_volume" |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 52 | #define AUDIO_PARAMETER_HFP_PCM_DEV_ID "hfp_pcm_dev_id" |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 53 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 54 | #define AUDIO_PARAMETER_KEY_HFP_MIC_VOLUME "hfp_mic_volume" |
| 55 | #define PLAYBACK_VOLUME_MAX 0x2000 |
| 56 | #define CAPTURE_VOLUME_DEFAULT (15.0) |
| 57 | |
Sudheer Papothi | 19e43d0 | 2014-07-16 02:34:41 +0530 | [diff] [blame] | 58 | #ifdef PLATFORM_MSM8994 |
| 59 | #define HFP_RX_VOLUME "SEC AUXPCM LOOPBACK Volume" |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 60 | #elif defined (PLATFORM_MSM8996) || defined (EXTERNAL_BT_SUPPORTED) |
Banajit Goswami | da77c45 | 2015-10-14 20:45:22 -0700 | [diff] [blame] | 61 | #define HFP_RX_VOLUME "PRI AUXPCM LOOPBACK Volume" |
Derek Chen | 3e5b30a | 2018-10-24 01:04:25 -0700 | [diff] [blame] | 62 | #elif defined PLATFORM_AUTO |
| 63 | #define HFP_RX_VOLUME "Playback 36 Volume" |
Meng Wang | ef2f6e1 | 2018-10-08 13:06:05 +0800 | [diff] [blame] | 64 | #elif defined (PLATFORM_MSM8998) || defined (PLATFORM_MSMFALCON) || \ |
| 65 | defined (PLATFORM_SDM845) || defined (PLATFORM_SDM710) || \ |
| 66 | defined (PLATFORM_QCS605) || defined (PLATFORM_MSMNILE) || \ |
| 67 | defined (PLATFORM_KONA) || defined (PLATFORM_MSMSTEPPE) || \ |
Manisha Agarwal | 888e976 | 2019-02-27 22:18:49 +0530 | [diff] [blame] | 68 | defined (PLATFORM_QCS405) || defined (PLATFORM_TRINKET) || \ |
Jaideep Sharma | de870aa | 2019-09-26 10:54:04 +0530 | [diff] [blame] | 69 | defined (PLATFORM_LITO) || defined(PLATFORM_ATOLL) || \ |
| 70 | defined (PLATFORM_BENGAL) |
Banajit Goswami | 4c0dff2 | 2016-03-04 18:31:22 -0800 | [diff] [blame] | 71 | #define HFP_RX_VOLUME "SLIMBUS_7 LOOPBACK Volume" |
Sudheer Papothi | 19e43d0 | 2014-07-16 02:34:41 +0530 | [diff] [blame] | 72 | #else |
| 73 | #define HFP_RX_VOLUME "Internal HFP RX Volume" |
| 74 | #endif |
| 75 | |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 76 | static int32_t start_hfp(struct audio_device *adev, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 77 | struct str_parms *parms); |
| 78 | |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 79 | static int32_t stop_hfp(struct audio_device *adev); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 80 | |
| 81 | struct hfp_module { |
| 82 | struct pcm *hfp_sco_rx; |
| 83 | struct pcm *hfp_sco_tx; |
| 84 | struct pcm *hfp_pcm_rx; |
| 85 | struct pcm *hfp_pcm_tx; |
Guodong Hu | f5e614d | 2019-06-24 18:42:03 +0800 | [diff] [blame^] | 86 | struct pcm *hfp_ext_ec_tx; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 87 | bool is_hfp_running; |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 88 | float hfp_volume; |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 89 | int32_t hfp_pcm_dev_id; |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 90 | audio_usecase_t ucid; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 91 | float mic_volume; |
| 92 | bool mic_mute; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | static struct hfp_module hfpmod = { |
| 96 | .hfp_sco_rx = NULL, |
| 97 | .hfp_sco_tx = NULL, |
| 98 | .hfp_pcm_rx = NULL, |
| 99 | .hfp_pcm_tx = NULL, |
Guodong Hu | f5e614d | 2019-06-24 18:42:03 +0800 | [diff] [blame^] | 100 | .hfp_ext_ec_tx = NULL, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 101 | .is_hfp_running = 0, |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 102 | .hfp_volume = 0, |
| 103 | .hfp_pcm_dev_id = HFP_ASM_RX_TX, |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 104 | .ucid = USECASE_AUDIO_HFP_SCO, |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 105 | .mic_volume = CAPTURE_VOLUME_DEFAULT, |
| 106 | .mic_mute = 0, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 107 | }; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 108 | |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 109 | static struct pcm_config pcm_config_hfp = { |
| 110 | .channels = 1, |
| 111 | .rate = 8000, |
| 112 | .period_size = 240, |
| 113 | .period_count = 2, |
| 114 | .format = PCM_FORMAT_S16_LE, |
| 115 | .start_threshold = 0, |
| 116 | .stop_threshold = INT_MAX, |
| 117 | .avail_min = 0, |
| 118 | }; |
| 119 | |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 120 | //external feature dependency |
| 121 | static fp_platform_set_mic_mute_t fp_platform_set_mic_mute; |
| 122 | static fp_platform_get_pcm_device_id_t fp_platform_get_pcm_device_id; |
| 123 | static fp_platform_set_echo_reference_t fp_platform_set_echo_reference; |
| 124 | static fp_select_devices_t fp_select_devices; |
| 125 | static fp_audio_extn_ext_hw_plugin_usecase_start_t fp_audio_extn_ext_hw_plugin_usecase_start; |
| 126 | static fp_audio_extn_ext_hw_plugin_usecase_stop_t fp_audio_extn_ext_hw_plugin_usecase_stop; |
| 127 | static fp_get_usecase_from_list_t fp_get_usecase_from_list; |
| 128 | static fp_disable_audio_route_t fp_disable_audio_route; |
| 129 | static fp_disable_snd_device_t fp_disable_snd_device; |
| 130 | static fp_voice_get_mic_mute_t fp_voice_get_mic_mute; |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 131 | static fp_audio_extn_auto_hal_start_hfp_downlink_t fp_audio_extn_auto_hal_start_hfp_downlink; |
| 132 | static fp_audio_extn_auto_hal_stop_hfp_downlink_t fp_audio_extn_auto_hal_stop_hfp_downlink; |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 133 | |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 134 | static int32_t hfp_set_volume(struct audio_device *adev, float value) |
| 135 | { |
| 136 | int32_t vol, ret = 0; |
| 137 | struct mixer_ctl *ctl; |
Sudheer Papothi | 19e43d0 | 2014-07-16 02:34:41 +0530 | [diff] [blame] | 138 | const char *mixer_ctl_name = HFP_RX_VOLUME; |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 139 | |
| 140 | ALOGV("%s: entry", __func__); |
| 141 | ALOGD("%s: (%f)\n", __func__, value); |
| 142 | |
Satya Krishna Pindiproli | 3ed6d79 | 2014-09-09 15:32:25 +0530 | [diff] [blame] | 143 | hfpmod.hfp_volume = value; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 144 | |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 145 | if (value < 0.0) { |
| 146 | ALOGW("%s: (%f) Under 0.0, assuming 0.0\n", __func__, value); |
| 147 | value = 0.0; |
| 148 | } else { |
| 149 | value = ((value > 15.000000) ? 1.0 : (value / 15)); |
| 150 | ALOGW("%s: Volume brought with in range (%f)\n", __func__, value); |
| 151 | } |
| 152 | vol = lrint((value * 0x2000) + 0.5); |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 153 | |
| 154 | if (!hfpmod.is_hfp_running) { |
| 155 | ALOGV("%s: HFP not active, ignoring set_hfp_volume call", __func__); |
| 156 | return -EIO; |
| 157 | } |
| 158 | |
| 159 | ALOGD("%s: Setting HFP volume to %d \n", __func__, vol); |
| 160 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 161 | if (!ctl) { |
| 162 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 163 | __func__, mixer_ctl_name); |
| 164 | return -EINVAL; |
| 165 | } |
| 166 | if(mixer_ctl_set_value(ctl, 0, vol) < 0) { |
| 167 | ALOGE("%s: Couldn't set HFP Volume: [%d]", __func__, vol); |
| 168 | return -EINVAL; |
| 169 | } |
| 170 | |
| 171 | ALOGV("%s: exit", __func__); |
| 172 | return ret; |
| 173 | } |
| 174 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 175 | /*Set mic volume to value. |
| 176 | * |
| 177 | * This interface is used for mic volume control, set mic volume as value(range 0 ~ 15). |
| 178 | */ |
| 179 | static int hfp_set_mic_volume(struct audio_device *adev, float value) |
| 180 | { |
| 181 | int volume, ret = 0; |
| 182 | char mixer_ctl_name[128]; |
| 183 | struct mixer_ctl *ctl; |
| 184 | int pcm_device_id = HFP_ASM_RX_TX; |
| 185 | |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 186 | ALOGD("%s: enter, value=%f", __func__, value); |
| 187 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 188 | if (!hfpmod.is_hfp_running) { |
| 189 | ALOGE("%s: HFP not active, ignoring set_hfp_mic_volume call", __func__); |
| 190 | return -EIO; |
| 191 | } |
| 192 | |
| 193 | if (value < 0.0) { |
| 194 | ALOGW("%s: (%f) Under 0.0, assuming 0.0\n", __func__, value); |
| 195 | value = 0.0; |
| 196 | } else if (value > CAPTURE_VOLUME_DEFAULT) { |
| 197 | value = CAPTURE_VOLUME_DEFAULT; |
| 198 | ALOGW("%s: Volume brought within range (%f)\n", __func__, value); |
| 199 | } |
| 200 | |
| 201 | value = value / CAPTURE_VOLUME_DEFAULT; |
| 202 | memset(mixer_ctl_name, 0, sizeof(mixer_ctl_name)); |
| 203 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), |
| 204 | "Playback %d Volume", pcm_device_id); |
| 205 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 206 | if (!ctl) { |
| 207 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 208 | __func__, mixer_ctl_name); |
| 209 | return -EINVAL; |
| 210 | } |
| 211 | volume = (int)(value * PLAYBACK_VOLUME_MAX); |
| 212 | |
| 213 | ALOGD("%s: Setting volume to %d (%s)\n", __func__, volume, mixer_ctl_name); |
| 214 | if (mixer_ctl_set_value(ctl, 0, volume) < 0) { |
| 215 | ALOGE("%s: Couldn't set HFP Volume: [%d]", __func__, volume); |
| 216 | return -EINVAL; |
| 217 | } |
| 218 | |
| 219 | return ret; |
| 220 | } |
| 221 | |
| 222 | static float hfp_get_mic_volume(struct audio_device *adev) |
| 223 | { |
| 224 | int volume; |
| 225 | char mixer_ctl_name[128]; |
| 226 | struct mixer_ctl *ctl; |
| 227 | int pcm_device_id = HFP_ASM_RX_TX; |
| 228 | float value = 0.0; |
| 229 | |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 230 | ALOGD("%s: enter", __func__); |
| 231 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 232 | if (!hfpmod.is_hfp_running) { |
| 233 | ALOGE("%s: HFP not active, ignoring set_hfp_mic_volume call", __func__); |
| 234 | return -EIO; |
| 235 | } |
| 236 | |
| 237 | memset(mixer_ctl_name, 0, sizeof(mixer_ctl_name)); |
| 238 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), |
| 239 | "Playback %d Volume", pcm_device_id); |
| 240 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 241 | if (!ctl) { |
| 242 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 243 | __func__, mixer_ctl_name); |
| 244 | return -EINVAL; |
| 245 | } |
| 246 | |
| 247 | volume = mixer_ctl_get_value(ctl, 0); |
| 248 | if ( volume < 0) { |
| 249 | ALOGE("%s: Couldn't set HFP Volume: [%d]", __func__, volume); |
| 250 | return -EINVAL; |
| 251 | } |
| 252 | ALOGD("%s: getting mic volume %d \n", __func__, volume); |
| 253 | |
| 254 | value = (volume / PLAYBACK_VOLUME_MAX) * CAPTURE_VOLUME_DEFAULT; |
| 255 | if (value < 0.0) { |
| 256 | ALOGW("%s: (%f) Under 0.0, assuming 0.0\n", __func__, value); |
| 257 | value = 0.0; |
| 258 | } else if (value > CAPTURE_VOLUME_DEFAULT) { |
| 259 | value = CAPTURE_VOLUME_DEFAULT; |
| 260 | ALOGW("%s: Volume brought within range (%f)\n", __func__, value); |
| 261 | } |
| 262 | |
| 263 | return value; |
| 264 | } |
| 265 | |
| 266 | /*Set mic mute state. |
| 267 | * |
| 268 | * This interface is used for mic mute state control |
| 269 | */ |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 270 | int hfp_set_mic_mute(struct audio_device *adev, bool state) |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 271 | { |
| 272 | int rc = 0; |
| 273 | |
| 274 | if (state == hfpmod.mic_mute) |
| 275 | return rc; |
| 276 | |
| 277 | if (state == true) { |
| 278 | hfpmod.mic_volume = hfp_get_mic_volume(adev); |
| 279 | } |
| 280 | rc = hfp_set_mic_volume(adev, (state == true) ? 0.0 : hfpmod.mic_volume); |
| 281 | adev->voice.mic_mute = state; |
| 282 | hfpmod.mic_mute = state; |
| 283 | ALOGD("%s: Setting mute state %d, rc %d\n", __func__, state, rc); |
| 284 | return rc; |
| 285 | } |
| 286 | |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 287 | static int32_t start_hfp(struct audio_device *adev, |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 288 | struct str_parms *parms __unused) |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 289 | { |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 290 | int32_t ret = 0; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 291 | struct audio_usecase *uc_info; |
| 292 | int32_t pcm_dev_rx_id, pcm_dev_tx_id, pcm_dev_asm_rx_id, pcm_dev_asm_tx_id; |
Guodong Hu | f5e614d | 2019-06-24 18:42:03 +0800 | [diff] [blame^] | 293 | int32_t pcm_ext_ec_ref_id; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 294 | |
| 295 | ALOGD("%s: enter", __func__); |
| 296 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 297 | if (adev->enable_hfp == true) { |
| 298 | ALOGD("%s: HFP is already active!\n", __func__); |
| 299 | return 0; |
| 300 | } |
| 301 | adev->enable_hfp = true; |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 302 | fp_platform_set_mic_mute(adev->platform, false); |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 303 | |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 304 | uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase)); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 305 | |
| 306 | if (!uc_info) |
| 307 | return -ENOMEM; |
| 308 | |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 309 | uc_info->id = hfpmod.ucid; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 310 | uc_info->type = PCM_HFP_CALL; |
| 311 | uc_info->stream.out = adev->primary_output; |
| 312 | uc_info->devices = adev->primary_output->devices; |
| 313 | uc_info->in_snd_device = SND_DEVICE_NONE; |
| 314 | uc_info->out_snd_device = SND_DEVICE_NONE; |
| 315 | |
| 316 | list_add_tail(&adev->usecase_list, &uc_info->list); |
| 317 | |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 318 | fp_select_devices(adev, hfpmod.ucid); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 319 | |
Derek Chen | d253007 | 2014-11-24 12:39:14 -0800 | [diff] [blame] | 320 | if ((uc_info->out_snd_device != SND_DEVICE_NONE) || |
| 321 | (uc_info->in_snd_device != SND_DEVICE_NONE)) { |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 322 | if (fp_audio_extn_ext_hw_plugin_usecase_start(adev->ext_hw_plugin, uc_info)) |
Derek Chen | d253007 | 2014-11-24 12:39:14 -0800 | [diff] [blame] | 323 | ALOGE("%s: failed to start ext hw plugin", __func__); |
| 324 | } |
| 325 | |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 326 | pcm_dev_rx_id = fp_platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK); |
| 327 | pcm_dev_tx_id = fp_platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE); |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 328 | pcm_dev_asm_rx_id = hfpmod.hfp_pcm_dev_id; |
| 329 | pcm_dev_asm_tx_id = hfpmod.hfp_pcm_dev_id; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 330 | if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0 || |
| 331 | pcm_dev_asm_rx_id < 0 || pcm_dev_asm_tx_id < 0 ) { |
| 332 | ALOGE("%s: Invalid PCM devices (rx: %d tx: %d asm: rx tx %d) for the usecase(%d)", |
| 333 | __func__, pcm_dev_rx_id, pcm_dev_tx_id, pcm_dev_asm_rx_id, uc_info->id); |
| 334 | ret = -EIO; |
| 335 | goto exit; |
| 336 | } |
| 337 | |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 338 | ALOGD("%s: HFP PCM devices (rx: %d tx: %d pcm dev id: %d) usecase(%d)", |
| 339 | __func__, pcm_dev_rx_id, pcm_dev_tx_id, hfpmod.hfp_pcm_dev_id, uc_info->id); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 340 | |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 341 | hfpmod.hfp_pcm_rx = pcm_open(adev->snd_card, |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 342 | pcm_dev_rx_id, |
| 343 | PCM_OUT, &pcm_config_hfp); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 344 | if (hfpmod.hfp_pcm_rx && !pcm_is_ready(hfpmod.hfp_pcm_rx)) { |
| 345 | ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_pcm_rx)); |
| 346 | ret = -EIO; |
| 347 | goto exit; |
| 348 | } |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 349 | |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 350 | hfpmod.hfp_pcm_tx = pcm_open(adev->snd_card, |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 351 | pcm_dev_tx_id, |
| 352 | PCM_IN, &pcm_config_hfp); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 353 | if (hfpmod.hfp_pcm_tx && !pcm_is_ready(hfpmod.hfp_pcm_tx)) { |
| 354 | ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_pcm_tx)); |
| 355 | ret = -EIO; |
| 356 | goto exit; |
| 357 | } |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 358 | |
Satya Krishna Pindiproli | ce903a0 | 2014-07-28 12:40:56 +0530 | [diff] [blame] | 359 | if (pcm_start(hfpmod.hfp_pcm_rx) < 0) { |
| 360 | ALOGE("%s: pcm start for hfp pcm rx failed", __func__); |
| 361 | ret = -EINVAL; |
| 362 | goto exit; |
| 363 | } |
| 364 | if (pcm_start(hfpmod.hfp_pcm_tx) < 0) { |
| 365 | ALOGE("%s: pcm start for hfp pcm tx failed", __func__); |
| 366 | ret = -EINVAL; |
| 367 | goto exit; |
| 368 | } |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 369 | |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 370 | if (fp_audio_extn_auto_hal_start_hfp_downlink(adev, uc_info)) |
| 371 | ALOGE("%s: start hfp downlink failed", __func__); |
| 372 | |
| 373 | hfpmod.hfp_sco_rx = pcm_open(adev->snd_card, |
| 374 | pcm_dev_asm_rx_id, |
| 375 | PCM_OUT, &pcm_config_hfp); |
| 376 | if (hfpmod.hfp_sco_rx && !pcm_is_ready(hfpmod.hfp_sco_rx)) { |
| 377 | ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_sco_rx)); |
| 378 | ret = -EIO; |
| 379 | goto exit; |
| 380 | } |
| 381 | |
| 382 | hfpmod.hfp_sco_tx = pcm_open(adev->snd_card, |
| 383 | pcm_dev_asm_tx_id, |
| 384 | PCM_IN, &pcm_config_hfp); |
| 385 | if (hfpmod.hfp_sco_tx && !pcm_is_ready(hfpmod.hfp_sco_tx)) { |
| 386 | ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_sco_tx)); |
| 387 | ret = -EIO; |
| 388 | goto exit; |
| 389 | } |
| 390 | |
| 391 | if (pcm_start(hfpmod.hfp_sco_rx) < 0) { |
| 392 | ALOGE("%s: pcm start for hfp sco rx failed", __func__); |
| 393 | ret = -EINVAL; |
| 394 | goto exit; |
| 395 | } |
| 396 | if (pcm_start(hfpmod.hfp_sco_tx) < 0) { |
| 397 | ALOGE("%s: pcm start for hfp sco tx failed", __func__); |
| 398 | ret = -EINVAL; |
| 399 | goto exit; |
| 400 | } |
| 401 | |
Guodong Hu | f5e614d | 2019-06-24 18:42:03 +0800 | [diff] [blame^] | 402 | #ifdef PLATFORM_AUTO |
| 403 | /* echo reference path for single-mic/multi-mic surround ECNS hfp calls */ |
| 404 | pcm_ext_ec_ref_id = HFP_EXT_EC_REF_TX; |
| 405 | ALOGD("%s: Opening PCM capture device card_id(%d) device_id(%d)", |
| 406 | __func__, adev->snd_card, pcm_ext_ec_ref_id); |
| 407 | hfpmod.hfp_ext_ec_tx = pcm_open(adev->snd_card, |
| 408 | pcm_ext_ec_ref_id, |
| 409 | PCM_IN, &pcm_config_hfp); |
| 410 | if (hfpmod.hfp_ext_ec_tx && !pcm_is_ready(hfpmod.hfp_ext_ec_tx)) { |
| 411 | ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_ext_ec_tx)); |
| 412 | ret = -EIO; |
| 413 | goto exit; |
| 414 | } |
| 415 | |
| 416 | if (pcm_start(hfpmod.hfp_ext_ec_tx) < 0) { |
| 417 | ALOGE("%s: pcm start for hfp ext ec tx failed", __func__); |
| 418 | ret = -EINVAL; |
| 419 | goto exit; |
| 420 | } |
| 421 | #endif |
| 422 | |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 423 | hfpmod.is_hfp_running = true; |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 424 | hfp_set_volume(adev, hfpmod.hfp_volume); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 425 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 426 | /* Set mic volume by mute status, we don't provide set mic volume in phone app, only |
| 427 | provide mute and unmute. */ |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 428 | hfp_set_mic_mute(adev, adev->mic_muted); |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 429 | |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 430 | ALOGD("%s: exit: status(%d)", __func__, ret); |
| 431 | return 0; |
| 432 | |
| 433 | exit: |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 434 | stop_hfp(adev); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 435 | ALOGE("%s: Problem in HFP start: status(%d)", __func__, ret); |
| 436 | return ret; |
| 437 | } |
| 438 | |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 439 | static int32_t stop_hfp(struct audio_device *adev) |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 440 | { |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 441 | int32_t ret = 0; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 442 | struct audio_usecase *uc_info; |
| 443 | |
| 444 | ALOGD("%s: enter", __func__); |
| 445 | hfpmod.is_hfp_running = false; |
| 446 | |
| 447 | /* 1. Close the PCM devices */ |
| 448 | if (hfpmod.hfp_sco_rx) { |
| 449 | pcm_close(hfpmod.hfp_sco_rx); |
| 450 | hfpmod.hfp_sco_rx = NULL; |
| 451 | } |
| 452 | if (hfpmod.hfp_sco_tx) { |
| 453 | pcm_close(hfpmod.hfp_sco_tx); |
| 454 | hfpmod.hfp_sco_tx = NULL; |
| 455 | } |
| 456 | if (hfpmod.hfp_pcm_rx) { |
| 457 | pcm_close(hfpmod.hfp_pcm_rx); |
| 458 | hfpmod.hfp_pcm_rx = NULL; |
| 459 | } |
| 460 | if (hfpmod.hfp_pcm_tx) { |
| 461 | pcm_close(hfpmod.hfp_pcm_tx); |
| 462 | hfpmod.hfp_pcm_tx = NULL; |
| 463 | } |
| 464 | |
Guodong Hu | f5e614d | 2019-06-24 18:42:03 +0800 | [diff] [blame^] | 465 | #ifdef PLATFORM_AUTO |
| 466 | /* echo reference path for single-mic/multi-mic surround ECNS hfp calls */ |
| 467 | if (hfpmod.hfp_ext_ec_tx) { |
| 468 | pcm_close(hfpmod.hfp_ext_ec_tx); |
| 469 | hfpmod.hfp_ext_ec_tx = NULL; |
| 470 | } |
| 471 | #endif |
| 472 | |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 473 | uc_info = fp_get_usecase_from_list(adev, hfpmod.ucid); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 474 | if (uc_info == NULL) { |
| 475 | ALOGE("%s: Could not find the usecase (%d) in the list", |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 476 | __func__, hfpmod.ucid); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 477 | return -EINVAL; |
| 478 | } |
| 479 | |
Derek Chen | d253007 | 2014-11-24 12:39:14 -0800 | [diff] [blame] | 480 | if ((uc_info->out_snd_device != SND_DEVICE_NONE) || |
| 481 | (uc_info->in_snd_device != SND_DEVICE_NONE)) { |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 482 | if (fp_audio_extn_ext_hw_plugin_usecase_stop(adev->ext_hw_plugin, uc_info)) |
Derek Chen | d253007 | 2014-11-24 12:39:14 -0800 | [diff] [blame] | 483 | ALOGE("%s: failed to stop ext hw plugin", __func__); |
| 484 | } |
| 485 | |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 486 | /* 2. Disable echo reference while stopping hfp */ |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 487 | fp_platform_set_echo_reference(adev, false, uc_info->devices); |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 488 | |
| 489 | /* 3. Get and set stream specific mixer controls */ |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 490 | fp_disable_audio_route(adev, uc_info); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 491 | |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 492 | /* 4. Disable the rx and tx devices */ |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 493 | fp_disable_snd_device(adev, uc_info->out_snd_device); |
| 494 | fp_disable_snd_device(adev, uc_info->in_snd_device); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 495 | |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 496 | if (fp_audio_extn_auto_hal_stop_hfp_downlink(adev, uc_info)) |
| 497 | ALOGE("%s: stop hfp downlink failed", __func__); |
| 498 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 499 | /* Set the unmute Tx mixer control */ |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 500 | if (fp_voice_get_mic_mute(adev)) { |
| 501 | fp_platform_set_mic_mute(adev->platform, false); |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 502 | ALOGD("%s: unMute HFP Tx", __func__); |
| 503 | } |
| 504 | adev->enable_hfp = false; |
| 505 | |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 506 | list_remove(&uc_info->list); |
| 507 | free(uc_info); |
| 508 | |
| 509 | ALOGD("%s: exit: status(%d)", __func__, ret); |
| 510 | return ret; |
| 511 | } |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 512 | |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 513 | void hfp_init(hfp_init_config_t init_config) |
| 514 | { |
| 515 | fp_platform_set_mic_mute = init_config.fp_platform_set_mic_mute; |
| 516 | fp_platform_get_pcm_device_id = init_config.fp_platform_get_pcm_device_id; |
| 517 | fp_platform_set_echo_reference = init_config.fp_platform_set_echo_reference; |
| 518 | fp_select_devices = init_config.fp_select_devices; |
| 519 | fp_audio_extn_ext_hw_plugin_usecase_start = |
| 520 | init_config.fp_audio_extn_ext_hw_plugin_usecase_start; |
| 521 | fp_audio_extn_ext_hw_plugin_usecase_stop = |
| 522 | init_config.fp_audio_extn_ext_hw_plugin_usecase_stop; |
| 523 | fp_get_usecase_from_list = init_config.fp_get_usecase_from_list; |
| 524 | fp_disable_audio_route = init_config.fp_disable_audio_route; |
| 525 | fp_disable_snd_device = init_config.fp_disable_snd_device; |
| 526 | fp_voice_get_mic_mute = init_config.fp_voice_get_mic_mute; |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 527 | fp_audio_extn_auto_hal_start_hfp_downlink = |
| 528 | init_config.fp_audio_extn_auto_hal_start_hfp_downlink; |
| 529 | fp_audio_extn_auto_hal_stop_hfp_downlink = |
| 530 | init_config.fp_audio_extn_auto_hal_stop_hfp_downlink; |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | bool hfp_is_active(struct audio_device *adev) |
Vimal Puthanveed | 37b4a1c | 2014-01-07 16:47:47 -0800 | [diff] [blame] | 534 | { |
| 535 | struct audio_usecase *hfp_usecase = NULL; |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 536 | hfp_usecase = fp_get_usecase_from_list(adev, hfpmod.ucid); |
Vimal Puthanveed | 37b4a1c | 2014-01-07 16:47:47 -0800 | [diff] [blame] | 537 | |
| 538 | if (hfp_usecase != NULL) |
| 539 | return true; |
| 540 | else |
| 541 | return false; |
| 542 | } |
| 543 | |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 544 | int hfp_set_mic_mute2(struct audio_device *adev, bool state) |
Dhanalakshmi Siddani | 823dc5a | 2016-09-28 14:47:26 +0530 | [diff] [blame] | 545 | { |
| 546 | struct mixer_ctl *ctl; |
| 547 | const char *mixer_ctl_name = "HFP TX Mute"; |
Manish Dewangan | 338c50a | 2017-09-12 15:22:03 +0530 | [diff] [blame] | 548 | long set_values[ ] = {0}; |
Dhanalakshmi Siddani | 823dc5a | 2016-09-28 14:47:26 +0530 | [diff] [blame] | 549 | |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 550 | ALOGD("%s: enter, state=%d", __func__, state); |
Dhanalakshmi Siddani | 823dc5a | 2016-09-28 14:47:26 +0530 | [diff] [blame] | 551 | |
| 552 | set_values[0] = state; |
| 553 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 554 | if (!ctl) { |
| 555 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 556 | __func__, mixer_ctl_name); |
| 557 | return -EINVAL; |
| 558 | } |
| 559 | mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
| 560 | ALOGV("%s: exit", __func__); |
| 561 | return 0; |
| 562 | } |
| 563 | |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 564 | audio_usecase_t hfp_get_usecase() |
Vimal Puthanveed | 41fcff2 | 2014-01-23 15:56:53 -0800 | [diff] [blame] | 565 | { |
| 566 | return hfpmod.ucid; |
| 567 | } |
| 568 | |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 569 | void hfp_set_parameters(struct audio_device *adev, struct str_parms *parms) |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 570 | { |
| 571 | int ret; |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 572 | int rate; |
Vimal Puthanveed | 21e5c76 | 2014-01-08 14:10:09 -0800 | [diff] [blame] | 573 | int val; |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 574 | float vol; |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 575 | char value[32]={0}; |
| 576 | |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 577 | ALOGD("%s: enter", __func__); |
| 578 | |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 579 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_HFP_ENABLE, value, |
| 580 | sizeof(value)); |
| 581 | if (ret >= 0) { |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 582 | if (!strncmp(value, "true", sizeof(value)) && !hfpmod.is_hfp_running) |
| 583 | ret = start_hfp(adev,parms); |
| 584 | else if (!strncmp(value, "false", sizeof(value)) && hfpmod.is_hfp_running) |
| 585 | stop_hfp(adev); |
| 586 | else |
| 587 | ALOGE("hfp_enable=%s is unsupported", value); |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 588 | } |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 589 | memset(value, 0, sizeof(value)); |
| 590 | ret = str_parms_get_str(parms,AUDIO_PARAMETER_HFP_SET_SAMPLING_RATE, value, |
| 591 | sizeof(value)); |
| 592 | if (ret >= 0) { |
| 593 | rate = atoi(value); |
| 594 | if (rate == 8000){ |
| 595 | hfpmod.ucid = USECASE_AUDIO_HFP_SCO; |
| 596 | pcm_config_hfp.rate = rate; |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 597 | } else if (rate == 16000){ |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 598 | hfpmod.ucid = USECASE_AUDIO_HFP_SCO_WB; |
| 599 | pcm_config_hfp.rate = rate; |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 600 | } else |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 601 | ALOGE("Unsupported rate.."); |
| 602 | } |
Vimal Puthanveed | 21e5c76 | 2014-01-08 14:10:09 -0800 | [diff] [blame] | 603 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 604 | if (hfpmod.is_hfp_running) { |
Vimal Puthanveed | 21e5c76 | 2014-01-08 14:10:09 -0800 | [diff] [blame] | 605 | memset(value, 0, sizeof(value)); |
| 606 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, |
| 607 | value, sizeof(value)); |
| 608 | if (ret >= 0) { |
| 609 | val = atoi(value); |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 610 | if (val > 0) |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 611 | fp_select_devices(adev, hfpmod.ucid); |
Vimal Puthanveed | 21e5c76 | 2014-01-08 14:10:09 -0800 | [diff] [blame] | 612 | } |
| 613 | } |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 614 | |
| 615 | memset(value, 0, sizeof(value)); |
| 616 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HFP_VOLUME, |
| 617 | value, sizeof(value)); |
| 618 | if (ret >= 0) { |
| 619 | if (sscanf(value, "%f", &vol) != 1){ |
| 620 | ALOGE("%s: error in retrieving hfp volume", __func__); |
| 621 | ret = -EIO; |
| 622 | goto exit; |
| 623 | } |
| 624 | ALOGD("%s: set_hfp_volume usecase, Vol: [%f]", __func__, vol); |
| 625 | hfp_set_volume(adev, vol); |
| 626 | } |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 627 | |
| 628 | memset(value, 0, sizeof(value)); |
| 629 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_HFP_PCM_DEV_ID, value, sizeof(value)); |
| 630 | if (ret >= 0) { |
| 631 | hfpmod.hfp_pcm_dev_id = atoi(value); |
| 632 | ALOGD("Updating HFP_PCM_DEV_ID as %d from platform XML", hfpmod.hfp_pcm_dev_id); |
| 633 | str_parms_del(parms, AUDIO_PARAMETER_HFP_PCM_DEV_ID); |
| 634 | } |
| 635 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 636 | memset(value, 0, sizeof(value)); |
| 637 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HFP_MIC_VOLUME, |
| 638 | value, sizeof(value)); |
| 639 | if (ret >= 0) { |
| 640 | if (sscanf(value, "%f", &vol) != 1){ |
| 641 | ALOGE("%s: error in retrieving hfp mic volume", __func__); |
| 642 | ret = -EIO; |
| 643 | goto exit; |
| 644 | } |
| 645 | ALOGD("%s: set_hfp_mic_volume usecase, Vol: [%f]", __func__, vol); |
| 646 | hfp_set_mic_volume(adev, vol); |
| 647 | } |
| 648 | |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 649 | exit: |
| 650 | ALOGV("%s Exit",__func__); |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 651 | } |