Meng Wang | 74ace55 | 2018-10-08 13:06:05 +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> |
| 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 Chen | cdd17c7 | 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 | #ifdef HFP_ENABLED |
| 50 | #define AUDIO_PARAMETER_HFP_ENABLE "hfp_enable" |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 51 | #define AUDIO_PARAMETER_HFP_SET_SAMPLING_RATE "hfp_set_sampling_rate" |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 52 | #define AUDIO_PARAMETER_KEY_HFP_VOLUME "hfp_volume" |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 53 | #define AUDIO_PARAMETER_HFP_PCM_DEV_ID "hfp_pcm_dev_id" |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 54 | |
Sudheer Papothi | 19e43d0 | 2014-07-16 02:34:41 +0530 | [diff] [blame] | 55 | #ifdef PLATFORM_MSM8994 |
| 56 | #define HFP_RX_VOLUME "SEC AUXPCM LOOPBACK Volume" |
Banajit Goswami | da77c45 | 2015-10-14 20:45:22 -0700 | [diff] [blame] | 57 | #elif defined PLATFORM_MSM8996 |
| 58 | #define HFP_RX_VOLUME "PRI AUXPCM LOOPBACK Volume" |
Derek Chen | 53e6dd6 | 2018-10-24 01:04:25 -0700 | [diff] [blame] | 59 | #elif defined PLATFORM_AUTO |
| 60 | #define HFP_RX_VOLUME "Playback 36 Volume" |
Meng Wang | 74ace55 | 2018-10-08 13:06:05 +0800 | [diff] [blame] | 61 | #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 Goswami | 4c0dff2 | 2016-03-04 18:31:22 -0800 | [diff] [blame] | 66 | #define HFP_RX_VOLUME "SLIMBUS_7 LOOPBACK Volume" |
Sudheer Papothi | 19e43d0 | 2014-07-16 02:34:41 +0530 | [diff] [blame] | 67 | #else |
| 68 | #define HFP_RX_VOLUME "Internal HFP RX Volume" |
| 69 | #endif |
| 70 | |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 71 | static int32_t start_hfp(struct audio_device *adev, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 72 | struct str_parms *parms); |
| 73 | |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 74 | static int32_t stop_hfp(struct audio_device *adev); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 75 | |
| 76 | struct 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 Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 82 | float hfp_volume; |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 83 | int32_t hfp_pcm_dev_id; |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 84 | audio_usecase_t ucid; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | static 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 Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 92 | .is_hfp_running = 0, |
Satya Krishna Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 93 | .hfp_volume = 0, |
| 94 | .hfp_pcm_dev_id = HFP_ASM_RX_TX, |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 95 | .ucid = USECASE_AUDIO_HFP_SCO, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 96 | }; |
| 97 | static 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 Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 108 | static int32_t hfp_set_volume(struct audio_device *adev, float value) |
| 109 | { |
| 110 | int32_t vol, ret = 0; |
| 111 | struct mixer_ctl *ctl; |
Sudheer Papothi | 19e43d0 | 2014-07-16 02:34:41 +0530 | [diff] [blame] | 112 | const char *mixer_ctl_name = HFP_RX_VOLUME; |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 113 | |
| 114 | ALOGV("%s: entry", __func__); |
| 115 | ALOGD("%s: (%f)\n", __func__, value); |
| 116 | |
Satya Krishna Pindiproli | 3ed6d79 | 2014-09-09 15:32:25 +0530 | [diff] [blame] | 117 | hfpmod.hfp_volume = value; |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 118 | 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 Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 126 | |
| 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 Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 148 | static int32_t start_hfp(struct audio_device *adev, |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 149 | struct str_parms *parms __unused) |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 150 | { |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 151 | int32_t ret = 0; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 152 | 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 George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 158 | |
| 159 | if (!uc_info) |
| 160 | return -ENOMEM; |
| 161 | |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 162 | uc_info->id = hfpmod.ucid; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 163 | 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 Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 171 | select_devices(adev, hfpmod.ucid); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 172 | |
Derek Chen | cdd17c7 | 2014-11-24 12:39:14 -0800 | [diff] [blame] | 173 | 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 Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 179 | 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 Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 181 | pcm_dev_asm_rx_id = hfpmod.hfp_pcm_dev_id; |
| 182 | pcm_dev_asm_tx_id = hfpmod.hfp_pcm_dev_id; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 183 | 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 Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 191 | 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 Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 193 | |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 194 | hfpmod.hfp_sco_rx = pcm_open(adev->snd_card, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 195 | 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 Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 202 | |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 203 | hfpmod.hfp_pcm_rx = pcm_open(adev->snd_card, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 204 | 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 Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 211 | |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 212 | hfpmod.hfp_sco_tx = pcm_open(adev->snd_card, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 213 | 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 Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 220 | |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 221 | hfpmod.hfp_pcm_tx = pcm_open(adev->snd_card, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 222 | 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 Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 229 | |
Satya Krishna Pindiproli | ce903a0 | 2014-07-28 12:40:56 +0530 | [diff] [blame] | 230 | 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 Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 250 | |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 251 | hfpmod.is_hfp_running = true; |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 252 | hfp_set_volume(adev, hfpmod.hfp_volume); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 253 | |
| 254 | ALOGD("%s: exit: status(%d)", __func__, ret); |
| 255 | return 0; |
| 256 | |
| 257 | exit: |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 258 | stop_hfp(adev); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 259 | ALOGE("%s: Problem in HFP start: status(%d)", __func__, ret); |
| 260 | return ret; |
| 261 | } |
| 262 | |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 263 | static int32_t stop_hfp(struct audio_device *adev) |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 264 | { |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 265 | int32_t ret = 0; |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 266 | 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 Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 289 | uc_info = get_usecase_from_list(adev, hfpmod.ucid); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 290 | if (uc_info == NULL) { |
| 291 | ALOGE("%s: Could not find the usecase (%d) in the list", |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 292 | __func__, hfpmod.ucid); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 293 | return -EINVAL; |
| 294 | } |
| 295 | |
Derek Chen | cdd17c7 | 2014-11-24 12:39:14 -0800 | [diff] [blame] | 296 | 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 Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 302 | /* 2. Disable echo reference while stopping hfp */ |
Apoorv Raghuvanshi | 924b302 | 2015-07-06 15:07:14 -0700 | [diff] [blame] | 303 | platform_set_echo_reference(adev, false, uc_info->devices); |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 304 | |
| 305 | /* 3. Get and set stream specific mixer controls */ |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 306 | disable_audio_route(adev, uc_info); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 307 | |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 308 | /* 4. Disable the rx and tx devices */ |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 309 | disable_snd_device(adev, uc_info->out_snd_device); |
| 310 | disable_snd_device(adev, uc_info->in_snd_device); |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 311 | |
| 312 | list_remove(&uc_info->list); |
| 313 | free(uc_info); |
| 314 | |
| 315 | ALOGD("%s: exit: status(%d)", __func__, ret); |
| 316 | return ret; |
| 317 | } |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 318 | |
Vimal Puthanveed | 37b4a1c | 2014-01-07 16:47:47 -0800 | [diff] [blame] | 319 | bool audio_extn_hfp_is_active(struct audio_device *adev) |
| 320 | { |
| 321 | struct audio_usecase *hfp_usecase = NULL; |
Vimal Puthanveed | 41fcff2 | 2014-01-23 15:56:53 -0800 | [diff] [blame] | 322 | hfp_usecase = get_usecase_from_list(adev, hfpmod.ucid); |
Vimal Puthanveed | 37b4a1c | 2014-01-07 16:47:47 -0800 | [diff] [blame] | 323 | |
| 324 | if (hfp_usecase != NULL) |
| 325 | return true; |
| 326 | else |
| 327 | return false; |
| 328 | } |
| 329 | |
Dhanalakshmi Siddani | 823dc5a | 2016-09-28 14:47:26 +0530 | [diff] [blame] | 330 | int 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 Dewangan | 338c50a | 2017-09-12 15:22:03 +0530 | [diff] [blame] | 334 | long set_values[ ] = {0}; |
Dhanalakshmi Siddani | 823dc5a | 2016-09-28 14:47:26 +0530 | [diff] [blame] | 335 | |
| 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 Puthanveed | 41fcff2 | 2014-01-23 15:56:53 -0800 | [diff] [blame] | 350 | audio_usecase_t audio_extn_hfp_get_usecase() |
| 351 | { |
| 352 | return hfpmod.ucid; |
| 353 | } |
| 354 | |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 355 | void audio_extn_hfp_set_parameters(struct audio_device *adev, struct str_parms *parms) |
| 356 | { |
| 357 | int ret; |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 358 | int rate; |
Vimal Puthanveed | 21e5c76 | 2014-01-08 14:10:09 -0800 | [diff] [blame] | 359 | int val; |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 360 | float vol; |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 361 | 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 Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 366 | 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 Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 372 | } |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 373 | 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 Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 381 | } else if (rate == 16000){ |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 382 | hfpmod.ucid = USECASE_AUDIO_HFP_SCO_WB; |
| 383 | pcm_config_hfp.rate = rate; |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 384 | } else |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 385 | ALOGE("Unsupported rate.."); |
| 386 | } |
Vimal Puthanveed | 21e5c76 | 2014-01-08 14:10:09 -0800 | [diff] [blame] | 387 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 388 | if (hfpmod.is_hfp_running) { |
Vimal Puthanveed | 21e5c76 | 2014-01-08 14:10:09 -0800 | [diff] [blame] | 389 | 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 Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 394 | if (val > 0) |
Vimal Puthanveed | 21e5c76 | 2014-01-08 14:10:09 -0800 | [diff] [blame] | 395 | select_devices(adev, hfpmod.ucid); |
| 396 | } |
| 397 | } |
Amit Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 398 | |
| 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 Pindiproli | c6b0a74 | 2017-02-03 14:37:18 +0530 | [diff] [blame] | 411 | |
| 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 Shekhar | 967cab3 | 2014-02-07 17:03:21 -0800 | [diff] [blame] | 420 | exit: |
| 421 | ALOGV("%s Exit",__func__); |
Vimal Puthanveed | 584048b | 2013-12-11 17:00:50 -0800 | [diff] [blame] | 422 | } |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 423 | #endif /*HFP_ENABLED*/ |