Xiaoyu Ye | 91553e6 | 2017-11-21 17:35:50 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2018, 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> |
| 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> |
| 41 | |
Revathi Uddaraju | 1eac8b0 | 2017-05-18 17:13:33 +0530 | [diff] [blame] | 42 | #ifdef DYNAMIC_LOG_ENABLED |
| 43 | #include <log_xml_parser.h> |
| 44 | #define LOG_MASK HAL_MOD_FILE_HFP |
| 45 | #include <log_utils.h> |
| 46 | #endif |
| 47 | |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 48 | #ifdef HFP_ENABLED |
| 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 | |
Sudheer Papothi | 19e43d0 | 2014-07-16 02:34:41 +0530 | [diff] [blame] | 54 | #ifdef PLATFORM_MSM8994 |
| 55 | #define HFP_RX_VOLUME "SEC AUXPCM LOOPBACK Volume" |
Banajit Goswami | da77c45 | 2015-10-14 20:45:22 -0700 | [diff] [blame] | 56 | #elif defined PLATFORM_MSM8996 |
| 57 | #define HFP_RX_VOLUME "PRI AUXPCM LOOPBACK Volume" |
Derek Chen | 3e5b30a | 2018-10-24 01:04:25 -0700 | [diff] [blame^] | 58 | #elif defined PLATFORM_AUTO |
| 59 | #define HFP_RX_VOLUME "Playback 36 Volume" |
Naresh Tanniru | cb5b578 | 2018-10-12 20:42:07 +0530 | [diff] [blame] | 60 | #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 Goswami | 4c0dff2 | 2016-03-04 18:31:22 -0800 | [diff] [blame] | 61 | #define HFP_RX_VOLUME "SLIMBUS_7 LOOPBACK Volume" |
Sudheer Papothi | 19e43d0 | 2014-07-16 02:34:41 +0530 | [diff] [blame] | 62 | #else |
| 63 | #define HFP_RX_VOLUME "Internal HFP RX Volume" |
| 64 | #endif |
| 65 | |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 66 | static int32_t start_hfp(struct audio_device *adev, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 67 | struct str_parms *parms); |
| 68 | |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 69 | static int32_t stop_hfp(struct audio_device *adev); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 70 | |
| 71 | struct hfp_module { |
| 72 | struct pcm *hfp_sco_rx; |
| 73 | struct pcm *hfp_sco_tx; |
| 74 | struct pcm *hfp_pcm_rx; |
| 75 | struct pcm *hfp_pcm_tx; |
| 76 | bool is_hfp_running; |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 77 | float hfp_volume; |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 78 | int32_t hfp_pcm_dev_id; |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 79 | audio_usecase_t ucid; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | static struct hfp_module hfpmod = { |
| 83 | .hfp_sco_rx = NULL, |
| 84 | .hfp_sco_tx = NULL, |
| 85 | .hfp_pcm_rx = NULL, |
| 86 | .hfp_pcm_tx = NULL, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 87 | .is_hfp_running = 0, |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 88 | .hfp_volume = 0, |
| 89 | .hfp_pcm_dev_id = HFP_ASM_RX_TX, |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 90 | .ucid = USECASE_AUDIO_HFP_SCO, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 91 | }; |
| 92 | static struct pcm_config pcm_config_hfp = { |
| 93 | .channels = 1, |
| 94 | .rate = 8000, |
| 95 | .period_size = 240, |
| 96 | .period_count = 2, |
| 97 | .format = PCM_FORMAT_S16_LE, |
| 98 | .start_threshold = 0, |
| 99 | .stop_threshold = INT_MAX, |
| 100 | .avail_min = 0, |
| 101 | }; |
| 102 | |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 103 | static int32_t hfp_set_volume(struct audio_device *adev, float value) |
| 104 | { |
| 105 | int32_t vol, ret = 0; |
| 106 | struct mixer_ctl *ctl; |
Sudheer Papothi | 19e43d0 | 2014-07-16 02:34:41 +0530 | [diff] [blame] | 107 | const char *mixer_ctl_name = HFP_RX_VOLUME; |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 108 | |
| 109 | ALOGV("%s: entry", __func__); |
| 110 | ALOGD("%s: (%f)\n", __func__, value); |
| 111 | |
Satya Krishna Pindiproli | 3ed6d79 | 2014-09-09 15:32:25 +0530 | [diff] [blame] | 112 | hfpmod.hfp_volume = value; |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 113 | if (value < 0.0) { |
| 114 | ALOGW("%s: (%f) Under 0.0, assuming 0.0\n", __func__, value); |
| 115 | value = 0.0; |
| 116 | } else { |
| 117 | value = ((value > 15.000000) ? 1.0 : (value / 15)); |
| 118 | ALOGW("%s: Volume brought with in range (%f)\n", __func__, value); |
| 119 | } |
| 120 | vol = lrint((value * 0x2000) + 0.5); |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 121 | |
| 122 | if (!hfpmod.is_hfp_running) { |
| 123 | ALOGV("%s: HFP not active, ignoring set_hfp_volume call", __func__); |
| 124 | return -EIO; |
| 125 | } |
| 126 | |
| 127 | ALOGD("%s: Setting HFP volume to %d \n", __func__, vol); |
| 128 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 129 | if (!ctl) { |
| 130 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 131 | __func__, mixer_ctl_name); |
| 132 | return -EINVAL; |
| 133 | } |
| 134 | if(mixer_ctl_set_value(ctl, 0, vol) < 0) { |
| 135 | ALOGE("%s: Couldn't set HFP Volume: [%d]", __func__, vol); |
| 136 | return -EINVAL; |
| 137 | } |
| 138 | |
| 139 | ALOGV("%s: exit", __func__); |
| 140 | return ret; |
| 141 | } |
| 142 | |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 143 | static int32_t start_hfp(struct audio_device *adev, |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 144 | struct str_parms *parms __unused) |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 145 | { |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 146 | int32_t ret = 0; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 147 | struct audio_usecase *uc_info; |
| 148 | int32_t pcm_dev_rx_id, pcm_dev_tx_id, pcm_dev_asm_rx_id, pcm_dev_asm_tx_id; |
| 149 | |
| 150 | ALOGD("%s: enter", __func__); |
| 151 | |
| 152 | uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase)); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 153 | |
| 154 | if (!uc_info) |
| 155 | return -ENOMEM; |
| 156 | |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 157 | uc_info->id = hfpmod.ucid; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 158 | uc_info->type = PCM_HFP_CALL; |
| 159 | uc_info->stream.out = adev->primary_output; |
| 160 | uc_info->devices = adev->primary_output->devices; |
| 161 | uc_info->in_snd_device = SND_DEVICE_NONE; |
| 162 | uc_info->out_snd_device = SND_DEVICE_NONE; |
| 163 | |
| 164 | list_add_tail(&adev->usecase_list, &uc_info->list); |
| 165 | |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 166 | select_devices(adev, hfpmod.ucid); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 167 | |
| 168 | pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK); |
| 169 | pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE); |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 170 | pcm_dev_asm_rx_id = hfpmod.hfp_pcm_dev_id; |
| 171 | pcm_dev_asm_tx_id = hfpmod.hfp_pcm_dev_id; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 172 | if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0 || |
| 173 | pcm_dev_asm_rx_id < 0 || pcm_dev_asm_tx_id < 0 ) { |
| 174 | ALOGE("%s: Invalid PCM devices (rx: %d tx: %d asm: rx tx %d) for the usecase(%d)", |
| 175 | __func__, pcm_dev_rx_id, pcm_dev_tx_id, pcm_dev_asm_rx_id, uc_info->id); |
| 176 | ret = -EIO; |
| 177 | goto exit; |
| 178 | } |
| 179 | |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 180 | ALOGD("%s: HFP PCM devices (rx: %d tx: %d pcm dev id: %d) usecase(%d)", |
| 181 | __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] | 182 | |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 183 | hfpmod.hfp_sco_rx = pcm_open(adev->snd_card, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 184 | pcm_dev_asm_rx_id, |
| 185 | PCM_OUT, &pcm_config_hfp); |
| 186 | if (hfpmod.hfp_sco_rx && !pcm_is_ready(hfpmod.hfp_sco_rx)) { |
| 187 | ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_sco_rx)); |
| 188 | ret = -EIO; |
| 189 | goto exit; |
| 190 | } |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 191 | |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 192 | hfpmod.hfp_pcm_rx = pcm_open(adev->snd_card, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 193 | pcm_dev_rx_id, |
| 194 | PCM_OUT, &pcm_config_hfp); |
| 195 | if (hfpmod.hfp_pcm_rx && !pcm_is_ready(hfpmod.hfp_pcm_rx)) { |
| 196 | ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_pcm_rx)); |
| 197 | ret = -EIO; |
| 198 | goto exit; |
| 199 | } |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 200 | |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 201 | hfpmod.hfp_sco_tx = pcm_open(adev->snd_card, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 202 | pcm_dev_asm_tx_id, |
| 203 | PCM_IN, &pcm_config_hfp); |
| 204 | if (hfpmod.hfp_sco_tx && !pcm_is_ready(hfpmod.hfp_sco_tx)) { |
| 205 | ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_sco_tx)); |
| 206 | ret = -EIO; |
| 207 | goto exit; |
| 208 | } |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 209 | |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 210 | hfpmod.hfp_pcm_tx = pcm_open(adev->snd_card, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 211 | pcm_dev_tx_id, |
| 212 | PCM_IN, &pcm_config_hfp); |
| 213 | if (hfpmod.hfp_pcm_tx && !pcm_is_ready(hfpmod.hfp_pcm_tx)) { |
| 214 | ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_pcm_tx)); |
| 215 | ret = -EIO; |
| 216 | goto exit; |
| 217 | } |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 218 | |
Satya Krishna Pindiproli | ce903a0 | 2014-07-28 12:40:56 +0530 | [diff] [blame] | 219 | if (pcm_start(hfpmod.hfp_sco_rx) < 0) { |
| 220 | ALOGE("%s: pcm start for hfp sco rx failed", __func__); |
| 221 | ret = -EINVAL; |
| 222 | goto exit; |
| 223 | } |
| 224 | if (pcm_start(hfpmod.hfp_sco_tx) < 0) { |
| 225 | ALOGE("%s: pcm start for hfp sco tx failed", __func__); |
| 226 | ret = -EINVAL; |
| 227 | goto exit; |
| 228 | } |
| 229 | if (pcm_start(hfpmod.hfp_pcm_rx) < 0) { |
| 230 | ALOGE("%s: pcm start for hfp pcm rx failed", __func__); |
| 231 | ret = -EINVAL; |
| 232 | goto exit; |
| 233 | } |
| 234 | if (pcm_start(hfpmod.hfp_pcm_tx) < 0) { |
| 235 | ALOGE("%s: pcm start for hfp pcm tx failed", __func__); |
| 236 | ret = -EINVAL; |
| 237 | goto exit; |
| 238 | } |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 239 | |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 240 | hfpmod.is_hfp_running = true; |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 241 | hfp_set_volume(adev, hfpmod.hfp_volume); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 242 | |
| 243 | ALOGD("%s: exit: status(%d)", __func__, ret); |
| 244 | return 0; |
| 245 | |
| 246 | exit: |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 247 | stop_hfp(adev); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 248 | ALOGE("%s: Problem in HFP start: status(%d)", __func__, ret); |
| 249 | return ret; |
| 250 | } |
| 251 | |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 252 | static int32_t stop_hfp(struct audio_device *adev) |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 253 | { |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 254 | int32_t ret = 0; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 255 | struct audio_usecase *uc_info; |
| 256 | |
| 257 | ALOGD("%s: enter", __func__); |
| 258 | hfpmod.is_hfp_running = false; |
| 259 | |
| 260 | /* 1. Close the PCM devices */ |
| 261 | if (hfpmod.hfp_sco_rx) { |
| 262 | pcm_close(hfpmod.hfp_sco_rx); |
| 263 | hfpmod.hfp_sco_rx = NULL; |
| 264 | } |
| 265 | if (hfpmod.hfp_sco_tx) { |
| 266 | pcm_close(hfpmod.hfp_sco_tx); |
| 267 | hfpmod.hfp_sco_tx = NULL; |
| 268 | } |
| 269 | if (hfpmod.hfp_pcm_rx) { |
| 270 | pcm_close(hfpmod.hfp_pcm_rx); |
| 271 | hfpmod.hfp_pcm_rx = NULL; |
| 272 | } |
| 273 | if (hfpmod.hfp_pcm_tx) { |
| 274 | pcm_close(hfpmod.hfp_pcm_tx); |
| 275 | hfpmod.hfp_pcm_tx = NULL; |
| 276 | } |
| 277 | |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 278 | uc_info = get_usecase_from_list(adev, hfpmod.ucid); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 279 | if (uc_info == NULL) { |
| 280 | ALOGE("%s: Could not find the usecase (%d) in the list", |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 281 | __func__, hfpmod.ucid); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 282 | return -EINVAL; |
| 283 | } |
| 284 | |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 285 | /* 2. Disable echo reference while stopping hfp */ |
Apoorv Raghuvanshi | 924b302 | 2015-07-06 15:07:14 -0700 | [diff] [blame] | 286 | platform_set_echo_reference(adev, false, uc_info->devices); |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 287 | |
| 288 | /* 3. Get and set stream specific mixer controls */ |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 289 | disable_audio_route(adev, uc_info); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 290 | |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 291 | /* 4. Disable the rx and tx devices */ |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 292 | disable_snd_device(adev, uc_info->out_snd_device); |
| 293 | disable_snd_device(adev, uc_info->in_snd_device); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 294 | |
| 295 | list_remove(&uc_info->list); |
| 296 | free(uc_info); |
| 297 | |
| 298 | ALOGD("%s: exit: status(%d)", __func__, ret); |
| 299 | return ret; |
| 300 | } |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 301 | |
Vimal Puthanveed | 37b4a1c | 2014-01-07 16:47:47 -0800 | [diff] [blame] | 302 | bool audio_extn_hfp_is_active(struct audio_device *adev) |
| 303 | { |
| 304 | struct audio_usecase *hfp_usecase = NULL; |
Vimal Puthanveed | 41fcff2 | 2014-01-23 15:56:53 -0800 | [diff] [blame] | 305 | hfp_usecase = get_usecase_from_list(adev, hfpmod.ucid); |
Vimal Puthanveed | 37b4a1c | 2014-01-07 16:47:47 -0800 | [diff] [blame] | 306 | |
| 307 | if (hfp_usecase != NULL) |
| 308 | return true; |
| 309 | else |
| 310 | return false; |
| 311 | } |
| 312 | |
Dhanalakshmi Siddani | 823dc5a | 2016-09-28 14:47:26 +0530 | [diff] [blame] | 313 | int hfp_set_mic_mute(struct audio_device *adev, bool state) |
| 314 | { |
| 315 | struct mixer_ctl *ctl; |
| 316 | const char *mixer_ctl_name = "HFP TX Mute"; |
Manish Dewangan | 338c50a | 2017-09-12 15:22:03 +0530 | [diff] [blame] | 317 | long set_values[ ] = {0}; |
Dhanalakshmi Siddani | 823dc5a | 2016-09-28 14:47:26 +0530 | [diff] [blame] | 318 | |
| 319 | ALOGI("%s: enter, state=%d", __func__, state); |
| 320 | |
| 321 | set_values[0] = state; |
| 322 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 323 | if (!ctl) { |
| 324 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 325 | __func__, mixer_ctl_name); |
| 326 | return -EINVAL; |
| 327 | } |
| 328 | mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values)); |
| 329 | ALOGV("%s: exit", __func__); |
| 330 | return 0; |
| 331 | } |
| 332 | |
Vimal Puthanveed | 41fcff2 | 2014-01-23 15:56:53 -0800 | [diff] [blame] | 333 | audio_usecase_t audio_extn_hfp_get_usecase() |
| 334 | { |
| 335 | return hfpmod.ucid; |
| 336 | } |
| 337 | |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 338 | void audio_extn_hfp_set_parameters(struct audio_device *adev, struct str_parms *parms) |
| 339 | { |
| 340 | int ret; |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 341 | int rate; |
Vimal Puthanveed | 21e5c76 | 2014-01-08 14:10:09 -0800 | [diff] [blame] | 342 | int val; |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 343 | float vol; |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 344 | char value[32]={0}; |
| 345 | |
| 346 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_HFP_ENABLE, value, |
| 347 | sizeof(value)); |
| 348 | if (ret >= 0) { |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 349 | if (!strncmp(value, "true", sizeof(value)) && !hfpmod.is_hfp_running) |
| 350 | ret = start_hfp(adev,parms); |
| 351 | else if (!strncmp(value, "false", sizeof(value)) && hfpmod.is_hfp_running) |
| 352 | stop_hfp(adev); |
| 353 | else |
| 354 | ALOGE("hfp_enable=%s is unsupported", value); |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 355 | } |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 356 | memset(value, 0, sizeof(value)); |
| 357 | ret = str_parms_get_str(parms,AUDIO_PARAMETER_HFP_SET_SAMPLING_RATE, value, |
| 358 | sizeof(value)); |
| 359 | if (ret >= 0) { |
| 360 | rate = atoi(value); |
| 361 | if (rate == 8000){ |
| 362 | hfpmod.ucid = USECASE_AUDIO_HFP_SCO; |
| 363 | pcm_config_hfp.rate = rate; |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 364 | } else if (rate == 16000){ |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 365 | hfpmod.ucid = USECASE_AUDIO_HFP_SCO_WB; |
| 366 | pcm_config_hfp.rate = rate; |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 367 | } else |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 368 | ALOGE("Unsupported rate.."); |
| 369 | } |
Vimal Puthanveed | 21e5c76 | 2014-01-08 14:10:09 -0800 | [diff] [blame] | 370 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 371 | if (hfpmod.is_hfp_running) { |
Vimal Puthanveed | 21e5c76 | 2014-01-08 14:10:09 -0800 | [diff] [blame] | 372 | memset(value, 0, sizeof(value)); |
| 373 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, |
| 374 | value, sizeof(value)); |
| 375 | if (ret >= 0) { |
| 376 | val = atoi(value); |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 377 | if (val > 0) |
Vimal Puthanveed | 21e5c76 | 2014-01-08 14:10:09 -0800 | [diff] [blame] | 378 | select_devices(adev, hfpmod.ucid); |
| 379 | } |
| 380 | } |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 381 | |
| 382 | memset(value, 0, sizeof(value)); |
| 383 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HFP_VOLUME, |
| 384 | value, sizeof(value)); |
| 385 | if (ret >= 0) { |
| 386 | if (sscanf(value, "%f", &vol) != 1){ |
| 387 | ALOGE("%s: error in retrieving hfp volume", __func__); |
| 388 | ret = -EIO; |
| 389 | goto exit; |
| 390 | } |
| 391 | ALOGD("%s: set_hfp_volume usecase, Vol: [%f]", __func__, vol); |
| 392 | hfp_set_volume(adev, vol); |
| 393 | } |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 394 | |
| 395 | memset(value, 0, sizeof(value)); |
| 396 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_HFP_PCM_DEV_ID, value, sizeof(value)); |
| 397 | if (ret >= 0) { |
| 398 | hfpmod.hfp_pcm_dev_id = atoi(value); |
| 399 | ALOGD("Updating HFP_PCM_DEV_ID as %d from platform XML", hfpmod.hfp_pcm_dev_id); |
| 400 | str_parms_del(parms, AUDIO_PARAMETER_HFP_PCM_DEV_ID); |
| 401 | } |
| 402 | |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 403 | exit: |
| 404 | ALOGV("%s Exit",__func__); |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 405 | } |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 406 | #endif /*HFP_ENABLED*/ |