Alexander Martinz | ad585df | 2022-03-31 09:00:00 +0200 | [diff] [blame^] | 1 | /* Copyright (c) 2012-2019, The Linux Foundation. All rights reserved. |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/slab.h> |
| 14 | #include <linux/wait.h> |
| 15 | #include <linux/sched.h> |
| 16 | #include <linux/jiffies.h> |
| 17 | #include <linux/uaccess.h> |
| 18 | #include <linux/atomic.h> |
| 19 | #include <linux/wait.h> |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 20 | #include <sound/asound.h> |
Laxminath Kasam | 605b42f | 2017-08-01 22:02:15 +0530 | [diff] [blame] | 21 | #include <asoc/msm-dts-srs-tm-config.h> |
| 22 | #include <dsp/apr_audio-v2.h> |
| 23 | #include <dsp/q6adm-v2.h> |
| 24 | #include <dsp/q6audio-v2.h> |
| 25 | #include <dsp/q6afe-v2.h> |
| 26 | #include <dsp/audio_cal_utils.h> |
| 27 | #include <ipc/apr.h> |
| 28 | #include "adsp_err.h" |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 29 | |
| 30 | #define TIMEOUT_MS 1000 |
| 31 | |
| 32 | #define RESET_COPP_ID 99 |
| 33 | #define INVALID_COPP_ID 0xFF |
| 34 | /* Used for inband payload copy, max size is 4k */ |
| 35 | /* 2 is to account for module & param ID in payload */ |
| 36 | #define ADM_GET_PARAMETER_LENGTH (4096 - APR_HDR_SIZE - 2 * sizeof(uint32_t)) |
| 37 | |
| 38 | #define ULL_SUPPORTED_BITS_PER_SAMPLE 16 |
| 39 | #define ULL_SUPPORTED_SAMPLE_RATE 48000 |
| 40 | |
| 41 | #ifndef CONFIG_DOLBY_DAP |
| 42 | #undef DOLBY_ADM_COPP_TOPOLOGY_ID |
| 43 | #define DOLBY_ADM_COPP_TOPOLOGY_ID 0xFFFFFFFE |
| 44 | #endif |
| 45 | |
| 46 | #ifndef CONFIG_DOLBY_DS2 |
| 47 | #undef DS2_ADM_COPP_TOPOLOGY_ID |
| 48 | #define DS2_ADM_COPP_TOPOLOGY_ID 0xFFFFFFFF |
| 49 | #endif |
| 50 | |
| 51 | /* ENUM for adm_status */ |
| 52 | enum adm_cal_status { |
| 53 | ADM_STATUS_CALIBRATION_REQUIRED = 0, |
| 54 | ADM_STATUS_MAX, |
| 55 | }; |
| 56 | |
| 57 | struct adm_copp { |
| 58 | |
| 59 | atomic_t id[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 60 | atomic_t cnt[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 61 | atomic_t topology[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 62 | atomic_t mode[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 63 | atomic_t stat[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 64 | atomic_t rate[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 65 | atomic_t bit_width[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 66 | atomic_t channels[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 67 | atomic_t app_type[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 68 | atomic_t acdb_id[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 69 | wait_queue_head_t wait[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 70 | wait_queue_head_t adm_delay_wait[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 71 | atomic_t adm_delay_stat[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 72 | uint32_t adm_delay[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 73 | unsigned long adm_status[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 74 | }; |
| 75 | |
| 76 | struct source_tracking_data { |
| 77 | struct ion_client *ion_client; |
| 78 | struct ion_handle *ion_handle; |
| 79 | struct param_outband memmap; |
| 80 | int apr_cmd_status; |
| 81 | }; |
| 82 | |
| 83 | struct adm_ctl { |
| 84 | void *apr; |
| 85 | |
| 86 | struct adm_copp copp; |
| 87 | |
| 88 | atomic_t matrix_map_stat; |
| 89 | wait_queue_head_t matrix_map_wait; |
| 90 | |
| 91 | atomic_t adm_stat; |
| 92 | wait_queue_head_t adm_wait; |
| 93 | |
| 94 | struct cal_type_data *cal_data[ADM_MAX_CAL_TYPES]; |
| 95 | |
| 96 | atomic_t mem_map_handles[ADM_MEM_MAP_INDEX_MAX]; |
| 97 | atomic_t mem_map_index; |
| 98 | |
| 99 | struct param_outband outband_memmap; |
| 100 | struct source_tracking_data sourceTrackingData; |
| 101 | |
| 102 | int set_custom_topology; |
| 103 | int ec_ref_rx; |
| 104 | int num_ec_ref_rx_chans; |
| 105 | int ec_ref_rx_bit_width; |
| 106 | int ec_ref_rx_sampling_rate; |
| 107 | }; |
| 108 | |
| 109 | static struct adm_ctl this_adm; |
| 110 | |
| 111 | struct adm_multi_ch_map { |
| 112 | bool set_channel_map; |
| 113 | char channel_mapping[PCM_FORMAT_MAX_NUM_CHANNEL]; |
| 114 | }; |
| 115 | |
| 116 | #define ADM_MCH_MAP_IDX_PLAYBACK 0 |
| 117 | #define ADM_MCH_MAP_IDX_REC 1 |
| 118 | static struct adm_multi_ch_map multi_ch_maps[2] = { |
| 119 | { false, |
| 120 | {0, 0, 0, 0, 0, 0, 0, 0} |
| 121 | }, |
| 122 | { false, |
| 123 | {0, 0, 0, 0, 0, 0, 0, 0} |
| 124 | } |
| 125 | }; |
| 126 | |
| 127 | static int adm_get_parameters[MAX_COPPS_PER_PORT * ADM_GET_PARAMETER_LENGTH]; |
| 128 | static int adm_module_topo_list[ |
| 129 | MAX_COPPS_PER_PORT * ADM_GET_TOPO_MODULE_LIST_LENGTH]; |
| 130 | |
| 131 | int adm_validate_and_get_port_index(int port_id) |
| 132 | { |
| 133 | int index; |
| 134 | int ret; |
| 135 | |
| 136 | ret = q6audio_validate_port(port_id); |
| 137 | if (ret < 0) { |
| 138 | pr_err("%s: port validation failed id 0x%x ret %d\n", |
| 139 | __func__, port_id, ret); |
| 140 | return -EINVAL; |
| 141 | } |
| 142 | |
| 143 | index = afe_get_port_index(port_id); |
| 144 | if (index < 0 || index >= AFE_MAX_PORTS) { |
| 145 | pr_err("%s: Invalid port idx %d port_id 0x%x\n", |
| 146 | __func__, index, |
| 147 | port_id); |
| 148 | return -EINVAL; |
| 149 | } |
| 150 | pr_debug("%s: port_idx- %d\n", __func__, index); |
| 151 | return index; |
| 152 | } |
| 153 | |
| 154 | int adm_get_default_copp_idx(int port_id) |
| 155 | { |
| 156 | int port_idx = adm_validate_and_get_port_index(port_id), idx; |
| 157 | |
| 158 | if (port_idx < 0) { |
| 159 | pr_err("%s: Invalid port id: 0x%x", __func__, port_id); |
| 160 | return -EINVAL; |
| 161 | } |
| 162 | pr_debug("%s: port_idx:%d\n", __func__, port_idx); |
| 163 | for (idx = 0; idx < MAX_COPPS_PER_PORT; idx++) { |
| 164 | if (atomic_read(&this_adm.copp.id[port_idx][idx]) != |
| 165 | RESET_COPP_ID) |
| 166 | return idx; |
| 167 | } |
| 168 | return -EINVAL; |
| 169 | } |
| 170 | |
| 171 | int adm_get_topology_for_port_from_copp_id(int port_id, int copp_id) |
| 172 | { |
| 173 | int port_idx = adm_validate_and_get_port_index(port_id), idx; |
| 174 | |
| 175 | if (port_idx < 0) { |
| 176 | pr_err("%s: Invalid port id: 0x%x", __func__, port_id); |
| 177 | return 0; |
| 178 | } |
| 179 | for (idx = 0; idx < MAX_COPPS_PER_PORT; idx++) |
| 180 | if (atomic_read(&this_adm.copp.id[port_idx][idx]) == copp_id) |
| 181 | return atomic_read(&this_adm.copp.topology[port_idx] |
| 182 | [idx]); |
| 183 | pr_err("%s: Invalid copp_id %d port_id 0x%x\n", |
| 184 | __func__, copp_id, port_id); |
| 185 | return 0; |
| 186 | } |
| 187 | |
| 188 | int adm_get_topology_for_port_copp_idx(int port_id, int copp_idx) |
| 189 | { |
| 190 | int port_idx = adm_validate_and_get_port_index(port_id); |
| 191 | |
| 192 | if (port_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 193 | pr_err("%s: Invalid port: 0x%x copp id: 0x%x", |
| 194 | __func__, port_id, copp_idx); |
| 195 | return 0; |
| 196 | } |
| 197 | return atomic_read(&this_adm.copp.topology[port_idx][copp_idx]); |
| 198 | } |
| 199 | |
| 200 | int adm_get_indexes_from_copp_id(int copp_id, int *copp_idx, int *port_idx) |
| 201 | { |
| 202 | int p_idx, c_idx; |
| 203 | |
| 204 | for (p_idx = 0; p_idx < AFE_MAX_PORTS; p_idx++) { |
| 205 | for (c_idx = 0; c_idx < MAX_COPPS_PER_PORT; c_idx++) { |
| 206 | if (atomic_read(&this_adm.copp.id[p_idx][c_idx]) |
| 207 | == copp_id) { |
| 208 | if (copp_idx != NULL) |
| 209 | *copp_idx = c_idx; |
| 210 | if (port_idx != NULL) |
| 211 | *port_idx = p_idx; |
| 212 | return 0; |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | return -EINVAL; |
| 217 | } |
| 218 | |
| 219 | static int adm_get_copp_id(int port_idx, int copp_idx) |
| 220 | { |
| 221 | pr_debug("%s: port_idx:%d copp_idx:%d\n", __func__, port_idx, copp_idx); |
| 222 | |
| 223 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 224 | pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); |
| 225 | return -EINVAL; |
| 226 | } |
| 227 | return atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 228 | } |
| 229 | |
| 230 | static int adm_get_idx_if_copp_exists(int port_idx, int topology, int mode, |
| 231 | int rate, int bit_width, int app_type) |
| 232 | { |
| 233 | int idx; |
| 234 | |
| 235 | pr_debug("%s: port_idx-%d, topology-0x%x, mode-%d, rate-%d, bit_width-%d\n", |
| 236 | __func__, port_idx, topology, mode, rate, bit_width); |
| 237 | |
| 238 | for (idx = 0; idx < MAX_COPPS_PER_PORT; idx++) |
| 239 | if ((topology == |
| 240 | atomic_read(&this_adm.copp.topology[port_idx][idx])) && |
| 241 | (mode == atomic_read(&this_adm.copp.mode[port_idx][idx])) && |
| 242 | (rate == atomic_read(&this_adm.copp.rate[port_idx][idx])) && |
| 243 | (bit_width == |
| 244 | atomic_read(&this_adm.copp.bit_width[port_idx][idx])) && |
| 245 | (app_type == |
| 246 | atomic_read(&this_adm.copp.app_type[port_idx][idx]))) |
| 247 | return idx; |
| 248 | return -EINVAL; |
| 249 | } |
| 250 | |
| 251 | static int adm_get_next_available_copp(int port_idx) |
| 252 | { |
| 253 | int idx; |
| 254 | |
| 255 | pr_debug("%s:\n", __func__); |
| 256 | for (idx = 0; idx < MAX_COPPS_PER_PORT; idx++) { |
| 257 | pr_debug("%s: copp_id:0x%x port_idx:%d idx:%d\n", __func__, |
| 258 | atomic_read(&this_adm.copp.id[port_idx][idx]), |
| 259 | port_idx, idx); |
| 260 | if (atomic_read(&this_adm.copp.id[port_idx][idx]) == |
| 261 | RESET_COPP_ID) |
| 262 | break; |
| 263 | } |
| 264 | return idx; |
| 265 | } |
| 266 | |
| 267 | int srs_trumedia_open(int port_id, int copp_idx, __s32 srs_tech_id, |
| 268 | void *srs_params) |
| 269 | { |
| 270 | struct adm_cmd_set_pp_params_inband_v5 *adm_params = NULL; |
| 271 | struct adm_cmd_set_pp_params_v5 *adm_params_ = NULL; |
| 272 | __s32 sz = 0, param_id, module_id = SRS_TRUMEDIA_MODULE_ID, outband = 0; |
| 273 | int ret = 0, port_idx; |
| 274 | |
| 275 | pr_debug("SRS - %s", __func__); |
| 276 | |
| 277 | port_id = afe_convert_virtual_to_portid(port_id); |
| 278 | port_idx = adm_validate_and_get_port_index(port_id); |
| 279 | if (port_idx < 0) { |
| 280 | pr_err("%s: Invalid port_id %#x\n", __func__, port_id); |
| 281 | return -EINVAL; |
| 282 | } |
| 283 | switch (srs_tech_id) { |
| 284 | case SRS_ID_GLOBAL: { |
| 285 | struct srs_trumedia_params_GLOBAL *glb_params = NULL; |
| 286 | |
| 287 | sz = sizeof(struct adm_cmd_set_pp_params_inband_v5) + |
| 288 | sizeof(struct srs_trumedia_params_GLOBAL); |
| 289 | adm_params = kzalloc(sz, GFP_KERNEL); |
| 290 | if (!adm_params) { |
| 291 | pr_err("%s, adm params memory alloc failed\n", |
| 292 | __func__); |
| 293 | return -ENOMEM; |
| 294 | } |
| 295 | adm_params->payload_size = |
| 296 | sizeof(struct srs_trumedia_params_GLOBAL) + |
| 297 | sizeof(struct adm_param_data_v5); |
| 298 | param_id = SRS_TRUMEDIA_PARAMS; |
| 299 | adm_params->params.param_size = |
| 300 | sizeof(struct srs_trumedia_params_GLOBAL); |
| 301 | glb_params = (struct srs_trumedia_params_GLOBAL *) |
| 302 | ((u8 *)adm_params + |
| 303 | sizeof(struct adm_cmd_set_pp_params_inband_v5)); |
| 304 | memcpy(glb_params, srs_params, |
| 305 | sizeof(struct srs_trumedia_params_GLOBAL)); |
| 306 | break; |
| 307 | } |
| 308 | case SRS_ID_WOWHD: { |
| 309 | struct srs_trumedia_params_WOWHD *whd_params = NULL; |
| 310 | |
| 311 | sz = sizeof(struct adm_cmd_set_pp_params_inband_v5) + |
| 312 | sizeof(struct srs_trumedia_params_WOWHD); |
| 313 | adm_params = kzalloc(sz, GFP_KERNEL); |
| 314 | if (!adm_params) { |
| 315 | pr_err("%s, adm params memory alloc failed\n", |
| 316 | __func__); |
| 317 | return -ENOMEM; |
| 318 | } |
| 319 | adm_params->payload_size = |
| 320 | sizeof(struct srs_trumedia_params_WOWHD) + |
| 321 | sizeof(struct adm_param_data_v5); |
| 322 | param_id = SRS_TRUMEDIA_PARAMS_WOWHD; |
| 323 | adm_params->params.param_size = |
| 324 | sizeof(struct srs_trumedia_params_WOWHD); |
| 325 | whd_params = (struct srs_trumedia_params_WOWHD *) |
| 326 | ((u8 *)adm_params + |
| 327 | sizeof(struct adm_cmd_set_pp_params_inband_v5)); |
| 328 | memcpy(whd_params, srs_params, |
| 329 | sizeof(struct srs_trumedia_params_WOWHD)); |
| 330 | break; |
| 331 | } |
| 332 | case SRS_ID_CSHP: { |
| 333 | struct srs_trumedia_params_CSHP *chp_params = NULL; |
| 334 | |
| 335 | sz = sizeof(struct adm_cmd_set_pp_params_inband_v5) + |
| 336 | sizeof(struct srs_trumedia_params_CSHP); |
| 337 | adm_params = kzalloc(sz, GFP_KERNEL); |
| 338 | if (!adm_params) { |
| 339 | pr_err("%s, adm params memory alloc failed\n", |
| 340 | __func__); |
| 341 | return -ENOMEM; |
| 342 | } |
| 343 | adm_params->payload_size = |
| 344 | sizeof(struct srs_trumedia_params_CSHP) + |
| 345 | sizeof(struct adm_param_data_v5); |
| 346 | param_id = SRS_TRUMEDIA_PARAMS_CSHP; |
| 347 | adm_params->params.param_size = |
| 348 | sizeof(struct srs_trumedia_params_CSHP); |
| 349 | chp_params = (struct srs_trumedia_params_CSHP *) |
| 350 | ((u8 *)adm_params + |
| 351 | sizeof(struct adm_cmd_set_pp_params_inband_v5)); |
| 352 | memcpy(chp_params, srs_params, |
| 353 | sizeof(struct srs_trumedia_params_CSHP)); |
| 354 | break; |
| 355 | } |
| 356 | case SRS_ID_HPF: { |
| 357 | struct srs_trumedia_params_HPF *hpf_params = NULL; |
| 358 | |
| 359 | sz = sizeof(struct adm_cmd_set_pp_params_inband_v5) + |
| 360 | sizeof(struct srs_trumedia_params_HPF); |
| 361 | adm_params = kzalloc(sz, GFP_KERNEL); |
| 362 | if (!adm_params) { |
| 363 | pr_err("%s, adm params memory alloc failed\n", |
| 364 | __func__); |
| 365 | return -ENOMEM; |
| 366 | } |
| 367 | adm_params->payload_size = |
| 368 | sizeof(struct srs_trumedia_params_HPF) + |
| 369 | sizeof(struct adm_param_data_v5); |
| 370 | param_id = SRS_TRUMEDIA_PARAMS_HPF; |
| 371 | adm_params->params.param_size = |
| 372 | sizeof(struct srs_trumedia_params_HPF); |
| 373 | hpf_params = (struct srs_trumedia_params_HPF *) |
| 374 | ((u8 *)adm_params + |
| 375 | sizeof(struct adm_cmd_set_pp_params_inband_v5)); |
| 376 | memcpy(hpf_params, srs_params, |
| 377 | sizeof(struct srs_trumedia_params_HPF)); |
| 378 | break; |
| 379 | } |
| 380 | case SRS_ID_AEQ: { |
| 381 | int *update_params_ptr = (int *)this_adm.outband_memmap.kvaddr; |
| 382 | |
| 383 | outband = 1; |
| 384 | adm_params = kzalloc(sizeof(struct adm_cmd_set_pp_params_v5), |
| 385 | GFP_KERNEL); |
| 386 | adm_params_ = (struct adm_cmd_set_pp_params_v5 *)adm_params; |
| 387 | if (!adm_params_) { |
| 388 | pr_err("%s, adm params memory alloc failed\n", |
| 389 | __func__); |
| 390 | return -ENOMEM; |
| 391 | } |
| 392 | |
| 393 | sz = sizeof(struct srs_trumedia_params_AEQ); |
| 394 | if (update_params_ptr == NULL) { |
| 395 | pr_err("ADM_SRS_TRUMEDIA - %s: null memmap for AEQ params\n", |
| 396 | __func__); |
| 397 | ret = -EINVAL; |
| 398 | goto fail_cmd; |
| 399 | } |
| 400 | param_id = SRS_TRUMEDIA_PARAMS_AEQ; |
| 401 | *update_params_ptr++ = module_id; |
| 402 | *update_params_ptr++ = param_id; |
| 403 | *update_params_ptr++ = sz; |
| 404 | memcpy(update_params_ptr, srs_params, sz); |
| 405 | |
| 406 | adm_params_->payload_size = sz + 12; |
| 407 | |
| 408 | break; |
| 409 | } |
| 410 | case SRS_ID_HL: { |
| 411 | struct srs_trumedia_params_HL *hl_params = NULL; |
| 412 | |
| 413 | sz = sizeof(struct adm_cmd_set_pp_params_inband_v5) + |
| 414 | sizeof(struct srs_trumedia_params_HL); |
| 415 | adm_params = kzalloc(sz, GFP_KERNEL); |
| 416 | if (!adm_params) { |
| 417 | pr_err("%s, adm params memory alloc failed\n", |
| 418 | __func__); |
| 419 | return -ENOMEM; |
| 420 | } |
| 421 | adm_params->payload_size = |
| 422 | sizeof(struct srs_trumedia_params_HL) + |
| 423 | sizeof(struct adm_param_data_v5); |
| 424 | param_id = SRS_TRUMEDIA_PARAMS_HL; |
| 425 | adm_params->params.param_size = |
| 426 | sizeof(struct srs_trumedia_params_HL); |
| 427 | hl_params = (struct srs_trumedia_params_HL *) |
| 428 | ((u8 *)adm_params + |
| 429 | sizeof(struct adm_cmd_set_pp_params_inband_v5)); |
| 430 | memcpy(hl_params, srs_params, |
| 431 | sizeof(struct srs_trumedia_params_HL)); |
| 432 | break; |
| 433 | } |
| 434 | case SRS_ID_GEQ: { |
| 435 | struct srs_trumedia_params_GEQ *geq_params = NULL; |
| 436 | |
| 437 | sz = sizeof(struct adm_cmd_set_pp_params_inband_v5) + |
| 438 | sizeof(struct srs_trumedia_params_GEQ); |
| 439 | adm_params = kzalloc(sz, GFP_KERNEL); |
| 440 | if (!adm_params) { |
| 441 | pr_err("%s, adm params memory alloc failed\n", |
| 442 | __func__); |
| 443 | return -ENOMEM; |
| 444 | } |
| 445 | adm_params->payload_size = |
| 446 | sizeof(struct srs_trumedia_params_GEQ) + |
| 447 | sizeof(struct adm_param_data_v5); |
| 448 | param_id = SRS_TRUMEDIA_PARAMS_GEQ; |
| 449 | adm_params->params.param_size = |
| 450 | sizeof(struct srs_trumedia_params_GEQ); |
| 451 | geq_params = (struct srs_trumedia_params_GEQ *) |
| 452 | ((u8 *)adm_params + |
| 453 | sizeof(struct adm_cmd_set_pp_params_inband_v5)); |
| 454 | memcpy(geq_params, srs_params, |
| 455 | sizeof(struct srs_trumedia_params_GEQ)); |
| 456 | pr_debug("SRS - %s: GEQ params prepared\n", __func__); |
| 457 | break; |
| 458 | } |
| 459 | default: |
| 460 | goto fail_cmd; |
| 461 | } |
| 462 | |
| 463 | adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 464 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 465 | adm_params->hdr.src_svc = APR_SVC_ADM; |
| 466 | adm_params->hdr.src_domain = APR_DOMAIN_APPS; |
| 467 | adm_params->hdr.src_port = port_id; |
| 468 | adm_params->hdr.dest_svc = APR_SVC_ADM; |
| 469 | adm_params->hdr.dest_domain = APR_DOMAIN_ADSP; |
| 470 | adm_params->hdr.dest_port = |
| 471 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 472 | adm_params->hdr.token = port_idx << 16 | copp_idx; |
| 473 | adm_params->hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; |
| 474 | if (outband && this_adm.outband_memmap.paddr) { |
| 475 | adm_params->hdr.pkt_size = |
| 476 | sizeof(struct adm_cmd_set_pp_params_v5); |
| 477 | adm_params->payload_addr_lsw = lower_32_bits( |
| 478 | this_adm.outband_memmap.paddr); |
| 479 | adm_params->payload_addr_msw = msm_audio_populate_upper_32_bits( |
| 480 | this_adm.outband_memmap.paddr); |
| 481 | adm_params->mem_map_handle = atomic_read(&this_adm. |
| 482 | mem_map_handles[ADM_SRS_TRUMEDIA]); |
| 483 | } else { |
| 484 | adm_params->hdr.pkt_size = sz; |
| 485 | adm_params->payload_addr_lsw = 0; |
| 486 | adm_params->payload_addr_msw = 0; |
| 487 | adm_params->mem_map_handle = 0; |
| 488 | |
| 489 | adm_params->params.module_id = module_id; |
| 490 | adm_params->params.param_id = param_id; |
| 491 | adm_params->params.reserved = 0; |
| 492 | } |
| 493 | |
| 494 | pr_debug("SRS - %s: Command was sent now check Q6 - port id = %d, size %d, module id %x, param id %x.\n", |
| 495 | __func__, adm_params->hdr.dest_port, |
| 496 | adm_params->payload_size, module_id, param_id); |
| 497 | |
| 498 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 499 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params); |
| 500 | if (ret < 0) { |
| 501 | pr_err("SRS - %s: ADM enable for port %d failed\n", __func__, |
| 502 | port_id); |
| 503 | ret = -EINVAL; |
| 504 | goto fail_cmd; |
| 505 | } |
| 506 | /* Wait for the callback with copp id */ |
| 507 | ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 508 | atomic_read(&this_adm.copp.stat |
| 509 | [port_idx][copp_idx]) >= 0, |
| 510 | msecs_to_jiffies(TIMEOUT_MS)); |
| 511 | if (!ret) { |
| 512 | pr_err("%s: SRS set params timed out port = %d\n", |
| 513 | __func__, port_id); |
| 514 | ret = -EINVAL; |
| 515 | goto fail_cmd; |
| 516 | } else if (atomic_read(&this_adm.copp.stat |
| 517 | [port_idx][copp_idx]) > 0) { |
| 518 | pr_err("%s: DSP returned error[%s]\n", |
| 519 | __func__, adsp_err_get_err_str( |
| 520 | atomic_read(&this_adm.copp.stat |
| 521 | [port_idx][copp_idx]))); |
| 522 | ret = adsp_err_get_lnx_err_code( |
| 523 | atomic_read(&this_adm.copp.stat |
| 524 | [port_idx][copp_idx])); |
| 525 | goto fail_cmd; |
| 526 | } |
| 527 | |
| 528 | fail_cmd: |
| 529 | kfree(adm_params); |
| 530 | return ret; |
| 531 | } |
| 532 | |
| 533 | static int adm_populate_channel_weight(u16 *ptr, |
| 534 | struct msm_pcm_channel_mixer *ch_mixer, |
| 535 | int channel_index) |
| 536 | { |
| 537 | u16 i, j, start_index = 0; |
| 538 | |
| 539 | if (channel_index > ch_mixer->output_channel) { |
| 540 | pr_err("%s: channel index %d is larger than output_channel %d\n", |
| 541 | __func__, channel_index, ch_mixer->output_channel); |
| 542 | return -EINVAL; |
| 543 | } |
| 544 | |
| 545 | for (i = 0; i < ch_mixer->output_channel; i++) { |
| 546 | pr_debug("%s: weight for output %d:", __func__, i); |
| 547 | for (j = 0; j < ADM_MAX_CHANNELS; j++) |
| 548 | pr_debug(" %d", |
| 549 | ch_mixer->channel_weight[i][j]); |
| 550 | pr_debug("\n"); |
| 551 | } |
| 552 | |
| 553 | for (i = 0; i < channel_index; ++i) |
| 554 | start_index += ch_mixer->input_channels[i]; |
| 555 | |
| 556 | for (i = 0; i < ch_mixer->output_channel; ++i) { |
| 557 | for (j = start_index; |
| 558 | j < start_index + |
| 559 | ch_mixer->input_channels[channel_index]; j++) { |
| 560 | *ptr = ch_mixer->channel_weight[i][j]; |
| 561 | pr_debug("%s: ptr[%d][%d] = %d\n", |
| 562 | __func__, i, j, *ptr); |
| 563 | ptr++; |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | return 0; |
| 568 | } |
| 569 | |
| 570 | /* |
| 571 | * adm_programable_channel_mixer |
| 572 | * |
| 573 | * Receives port_id, copp_idx, session_id, session_type, ch_mixer |
| 574 | * and channel_index to send ADM command to mix COPP data. |
| 575 | * |
| 576 | * port_id - Passed value, port_id for which backend is wanted |
| 577 | * copp_idx - Passed value, copp_idx for which COPP is wanted |
| 578 | * session_id - Passed value, session_id for which session is needed |
| 579 | * session_type - Passed value, session_type for RX or TX |
| 580 | * ch_mixer - Passed value, ch_mixer for which channel mixer config is needed |
| 581 | * channel_index - Passed value, channel_index for which channel is needed |
| 582 | */ |
| 583 | int adm_programable_channel_mixer(int port_id, int copp_idx, int session_id, |
| 584 | int session_type, |
| 585 | struct msm_pcm_channel_mixer *ch_mixer, |
| 586 | int channel_index) |
| 587 | { |
| 588 | struct adm_cmd_set_pspd_mtmx_strtr_params_v5 *adm_params = NULL; |
| 589 | struct adm_param_data_v5 data_v5; |
| 590 | int ret = 0, port_idx, sz = 0, param_size = 0; |
| 591 | u16 *adm_pspd_params; |
| 592 | u16 *ptr; |
| 593 | int index = 0; |
| 594 | |
| 595 | pr_debug("%s: port_id = %d\n", __func__, port_id); |
| 596 | port_id = afe_convert_virtual_to_portid(port_id); |
| 597 | port_idx = adm_validate_and_get_port_index(port_id); |
| 598 | if (port_idx < 0) { |
| 599 | pr_err("%s: Invalid port_id %#x\n", __func__, port_id); |
| 600 | return -EINVAL; |
| 601 | } |
| 602 | /* |
| 603 | * First 8 bytes are 4 bytes as rule number, 2 bytes as output |
| 604 | * channel and 2 bytes as input channel. |
| 605 | * 2 * ch_mixer->output_channel means output channel mapping. |
| 606 | * 2 * ch_mixer->input_channels[channel_index]) means input |
| 607 | * channel mapping. |
| 608 | * 2 * ch_mixer->input_channels[channel_index] * |
| 609 | * ch_mixer->output_channel) means the channel mixer weighting |
| 610 | * coefficients. |
| 611 | * param_size needs to be a multiple of 4 bytes. |
| 612 | */ |
| 613 | |
| 614 | param_size = 2 * (4 + ch_mixer->output_channel + |
| 615 | ch_mixer->input_channels[channel_index] + |
| 616 | ch_mixer->input_channels[channel_index] * |
| 617 | ch_mixer->output_channel); |
| 618 | roundup(param_size, 4); |
| 619 | |
| 620 | sz = sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5) + |
| 621 | sizeof(struct default_chmixer_param_id_coeff) + |
| 622 | sizeof(struct adm_param_data_v5) + param_size; |
| 623 | pr_debug("%s: sz = %d\n", __func__, sz); |
| 624 | adm_params = kzalloc(sz, GFP_KERNEL); |
| 625 | if (!adm_params) |
| 626 | return -ENOMEM; |
| 627 | |
| 628 | adm_params->payload_addr_lsw = 0; |
| 629 | adm_params->payload_addr_msw = 0; |
| 630 | adm_params->mem_map_handle = 0; |
| 631 | adm_params->direction = session_type; |
| 632 | adm_params->sessionid = session_id; |
| 633 | pr_debug("%s: copp_id = %d, session id %d\n", __func__, |
| 634 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]), |
| 635 | session_id); |
| 636 | adm_params->deviceid = atomic_read( |
| 637 | &this_adm.copp.id[port_idx][copp_idx]); |
| 638 | adm_params->reserved = 0; |
| 639 | |
| 640 | data_v5.module_id = MTMX_MODULE_ID_DEFAULT_CHMIXER; |
| 641 | data_v5.param_id = DEFAULT_CHMIXER_PARAM_ID_COEFF; |
| 642 | data_v5.reserved = 0; |
| 643 | data_v5.param_size = param_size; |
| 644 | adm_params->payload_size = |
| 645 | sizeof(struct default_chmixer_param_id_coeff) + |
| 646 | sizeof(struct adm_param_data_v5) + data_v5.param_size; |
| 647 | adm_pspd_params = (u16 *)((u8 *)adm_params + |
| 648 | sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5)); |
| 649 | memcpy(adm_pspd_params, &data_v5, sizeof(data_v5)); |
| 650 | |
| 651 | adm_pspd_params = (u16 *)((u8 *)adm_params + |
| 652 | sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5) |
| 653 | + sizeof(data_v5)); |
| 654 | |
| 655 | adm_pspd_params[0] = ch_mixer->rule; |
| 656 | adm_pspd_params[2] = ch_mixer->output_channel; |
| 657 | adm_pspd_params[3] = ch_mixer->input_channels[channel_index]; |
| 658 | index = 4; |
| 659 | |
| 660 | if (ch_mixer->output_channel == 1) { |
| 661 | adm_pspd_params[index] = PCM_CHANNEL_FC; |
| 662 | } else if (ch_mixer->output_channel == 2) { |
| 663 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 664 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 665 | } else if (ch_mixer->output_channel == 3) { |
| 666 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 667 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 668 | adm_pspd_params[index + 2] = PCM_CHANNEL_FC; |
| 669 | } else if (ch_mixer->output_channel == 4) { |
| 670 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 671 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 672 | adm_pspd_params[index + 2] = PCM_CHANNEL_LS; |
| 673 | adm_pspd_params[index + 3] = PCM_CHANNEL_RS; |
| 674 | } else if (ch_mixer->output_channel == 5) { |
| 675 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 676 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 677 | adm_pspd_params[index + 2] = PCM_CHANNEL_FC; |
| 678 | adm_pspd_params[index + 3] = PCM_CHANNEL_LS; |
| 679 | adm_pspd_params[index + 4] = PCM_CHANNEL_RS; |
| 680 | } else if (ch_mixer->output_channel == 6) { |
| 681 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 682 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 683 | adm_pspd_params[index + 2] = PCM_CHANNEL_LFE; |
| 684 | adm_pspd_params[index + 3] = PCM_CHANNEL_FC; |
| 685 | adm_pspd_params[index + 4] = PCM_CHANNEL_LS; |
| 686 | adm_pspd_params[index + 5] = PCM_CHANNEL_RS; |
| 687 | } else if (ch_mixer->output_channel == 8) { |
| 688 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 689 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 690 | adm_pspd_params[index + 2] = PCM_CHANNEL_LFE; |
| 691 | adm_pspd_params[index + 3] = PCM_CHANNEL_FC; |
| 692 | adm_pspd_params[index + 4] = PCM_CHANNEL_LS; |
| 693 | adm_pspd_params[index + 5] = PCM_CHANNEL_RS; |
| 694 | adm_pspd_params[index + 6] = PCM_CHANNEL_LB; |
| 695 | adm_pspd_params[index + 7] = PCM_CHANNEL_RB; |
| 696 | } |
| 697 | |
| 698 | index = index + ch_mixer->output_channel; |
| 699 | if (ch_mixer->input_channels[channel_index] == 1) { |
| 700 | adm_pspd_params[index] = PCM_CHANNEL_FC; |
| 701 | } else if (ch_mixer->input_channels[channel_index] == 2) { |
| 702 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 703 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 704 | } else if (ch_mixer->input_channels[channel_index] == 3) { |
| 705 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 706 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 707 | adm_pspd_params[index + 2] = PCM_CHANNEL_FC; |
| 708 | } else if (ch_mixer->input_channels[channel_index] == 4) { |
| 709 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 710 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 711 | adm_pspd_params[index + 2] = PCM_CHANNEL_LS; |
| 712 | adm_pspd_params[index + 3] = PCM_CHANNEL_RS; |
| 713 | } else if (ch_mixer->input_channels[channel_index] == 5) { |
| 714 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 715 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 716 | adm_pspd_params[index + 2] = PCM_CHANNEL_FC; |
| 717 | adm_pspd_params[index + 3] = PCM_CHANNEL_LS; |
| 718 | adm_pspd_params[index + 4] = PCM_CHANNEL_RS; |
| 719 | } else if (ch_mixer->input_channels[channel_index] == 6) { |
| 720 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 721 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 722 | adm_pspd_params[index + 2] = PCM_CHANNEL_LFE; |
| 723 | adm_pspd_params[index + 3] = PCM_CHANNEL_FC; |
| 724 | adm_pspd_params[index + 4] = PCM_CHANNEL_LS; |
| 725 | adm_pspd_params[index + 5] = PCM_CHANNEL_RS; |
| 726 | } else if (ch_mixer->input_channels[channel_index] == 8) { |
| 727 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 728 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 729 | adm_pspd_params[index + 2] = PCM_CHANNEL_LFE; |
| 730 | adm_pspd_params[index + 3] = PCM_CHANNEL_FC; |
| 731 | adm_pspd_params[index + 4] = PCM_CHANNEL_LS; |
| 732 | adm_pspd_params[index + 5] = PCM_CHANNEL_RS; |
| 733 | adm_pspd_params[index + 6] = PCM_CHANNEL_LB; |
| 734 | adm_pspd_params[index + 7] = PCM_CHANNEL_RB; |
| 735 | } |
| 736 | |
| 737 | index = index + ch_mixer->input_channels[channel_index]; |
| 738 | ret = adm_populate_channel_weight(&adm_pspd_params[index], |
| 739 | ch_mixer, channel_index); |
Meng Wang | bd9254d | 2018-01-23 12:42:52 +0800 | [diff] [blame] | 740 | if (ret) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 741 | pr_err("%s: fail to get channel weight with error %d\n", |
| 742 | __func__, ret); |
| 743 | goto fail_cmd; |
| 744 | } |
| 745 | |
| 746 | adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 747 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 748 | adm_params->hdr.src_svc = APR_SVC_ADM; |
| 749 | adm_params->hdr.src_domain = APR_DOMAIN_APPS; |
| 750 | adm_params->hdr.src_port = port_id; |
| 751 | adm_params->hdr.dest_svc = APR_SVC_ADM; |
| 752 | adm_params->hdr.dest_domain = APR_DOMAIN_ADSP; |
| 753 | adm_params->hdr.dest_port = |
| 754 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 755 | adm_params->hdr.token = port_idx << 16 | copp_idx; |
| 756 | adm_params->hdr.opcode = ADM_CMD_SET_PSPD_MTMX_STRTR_PARAMS_V5; |
| 757 | adm_params->hdr.pkt_size = sz; |
| 758 | adm_params->payload_addr_lsw = 0; |
| 759 | adm_params->payload_addr_msw = 0; |
| 760 | adm_params->mem_map_handle = 0; |
| 761 | adm_params->reserved = 0; |
| 762 | |
| 763 | ptr = (u16 *)adm_params; |
| 764 | for (index = 0; index < (sz / 2); index++) |
| 765 | pr_debug("%s: adm_params[%d] = 0x%x\n", |
| 766 | __func__, index, (unsigned int)ptr[index]); |
| 767 | |
| 768 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], 0); |
| 769 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params); |
| 770 | if (ret < 0) { |
| 771 | pr_err("%s: Set params failed port %d rc %d\n", __func__, |
| 772 | port_id, ret); |
| 773 | ret = -EINVAL; |
| 774 | goto fail_cmd; |
| 775 | } |
| 776 | |
| 777 | ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 778 | atomic_read( |
| 779 | &this_adm.copp.stat[port_idx][copp_idx]) >= 0, |
| 780 | msecs_to_jiffies(TIMEOUT_MS)); |
| 781 | if (!ret) { |
| 782 | pr_err("%s: set params timed out port = %d\n", |
| 783 | __func__, port_id); |
| 784 | ret = -ETIMEDOUT; |
| 785 | goto fail_cmd; |
| 786 | } |
| 787 | ret = 0; |
| 788 | fail_cmd: |
| 789 | kfree(adm_params); |
| 790 | |
| 791 | return ret; |
| 792 | } |
| 793 | |
| 794 | int adm_set_stereo_to_custom_stereo(int port_id, int copp_idx, |
| 795 | unsigned int session_id, char *params, |
| 796 | uint32_t params_length) |
| 797 | { |
| 798 | struct adm_cmd_set_pspd_mtmx_strtr_params_v5 *adm_params = NULL; |
| 799 | int sz, rc = 0, port_idx; |
| 800 | |
| 801 | pr_debug("%s:\n", __func__); |
| 802 | port_id = afe_convert_virtual_to_portid(port_id); |
| 803 | port_idx = adm_validate_and_get_port_index(port_id); |
| 804 | if (port_idx < 0) { |
| 805 | pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); |
| 806 | return -EINVAL; |
| 807 | } |
| 808 | |
| 809 | sz = sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5) + |
| 810 | params_length; |
| 811 | adm_params = kzalloc(sz, GFP_KERNEL); |
| 812 | if (!adm_params) { |
| 813 | pr_err("%s, adm params memory alloc failed\n", __func__); |
| 814 | return -ENOMEM; |
| 815 | } |
| 816 | |
| 817 | memcpy(((u8 *)adm_params + |
| 818 | sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5)), |
| 819 | params, params_length); |
| 820 | adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 821 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 822 | adm_params->hdr.pkt_size = sz; |
| 823 | adm_params->hdr.src_svc = APR_SVC_ADM; |
| 824 | adm_params->hdr.src_domain = APR_DOMAIN_APPS; |
| 825 | adm_params->hdr.src_port = port_id; |
| 826 | adm_params->hdr.dest_svc = APR_SVC_ADM; |
| 827 | adm_params->hdr.dest_domain = APR_DOMAIN_ADSP; |
| 828 | adm_params->hdr.dest_port = 0; /* Ignored */; |
| 829 | adm_params->hdr.token = port_idx << 16 | copp_idx; |
| 830 | adm_params->hdr.opcode = ADM_CMD_SET_PSPD_MTMX_STRTR_PARAMS_V5; |
| 831 | adm_params->payload_addr_lsw = 0; |
| 832 | adm_params->payload_addr_msw = 0; |
| 833 | adm_params->mem_map_handle = 0; |
| 834 | adm_params->payload_size = params_length; |
| 835 | /* direction RX as 0 */ |
| 836 | adm_params->direction = ADM_MATRIX_ID_AUDIO_RX; |
| 837 | /* session id for this cmd to be applied on */ |
| 838 | adm_params->sessionid = session_id; |
| 839 | adm_params->deviceid = |
| 840 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 841 | adm_params->reserved = 0; |
| 842 | pr_debug("%s: deviceid %d, session_id %d, src_port %d, dest_port %d\n", |
| 843 | __func__, adm_params->deviceid, adm_params->sessionid, |
| 844 | adm_params->hdr.src_port, adm_params->hdr.dest_port); |
| 845 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 846 | rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params); |
| 847 | if (rc < 0) { |
| 848 | pr_err("%s: Set params failed port = 0x%x rc %d\n", |
| 849 | __func__, port_id, rc); |
| 850 | rc = -EINVAL; |
| 851 | goto set_stereo_to_custom_stereo_return; |
| 852 | } |
| 853 | /* Wait for the callback */ |
| 854 | rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 855 | atomic_read(&this_adm.copp.stat |
| 856 | [port_idx][copp_idx]) >= 0, |
| 857 | msecs_to_jiffies(TIMEOUT_MS)); |
| 858 | if (!rc) { |
| 859 | pr_err("%s: Set params timed out port = 0x%x\n", __func__, |
| 860 | port_id); |
| 861 | rc = -EINVAL; |
| 862 | goto set_stereo_to_custom_stereo_return; |
| 863 | } else if (atomic_read(&this_adm.copp.stat |
| 864 | [port_idx][copp_idx]) > 0) { |
| 865 | pr_err("%s: DSP returned error[%s]\n", __func__, |
| 866 | adsp_err_get_err_str(atomic_read( |
| 867 | &this_adm.copp.stat |
| 868 | [port_idx][copp_idx]))); |
| 869 | rc = adsp_err_get_lnx_err_code( |
| 870 | atomic_read(&this_adm.copp.stat |
| 871 | [port_idx][copp_idx])); |
| 872 | goto set_stereo_to_custom_stereo_return; |
| 873 | } |
| 874 | rc = 0; |
| 875 | set_stereo_to_custom_stereo_return: |
| 876 | kfree(adm_params); |
| 877 | return rc; |
| 878 | } |
| 879 | |
| 880 | int adm_dolby_dap_send_params(int port_id, int copp_idx, char *params, |
| 881 | uint32_t params_length) |
| 882 | { |
| 883 | struct adm_cmd_set_pp_params_v5 *adm_params = NULL; |
| 884 | int sz, rc = 0; |
| 885 | int port_idx; |
| 886 | |
| 887 | pr_debug("%s:\n", __func__); |
| 888 | port_id = afe_convert_virtual_to_portid(port_id); |
| 889 | port_idx = adm_validate_and_get_port_index(port_id); |
| 890 | if (port_idx < 0) { |
| 891 | pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); |
| 892 | return -EINVAL; |
| 893 | } |
| 894 | |
| 895 | sz = sizeof(struct adm_cmd_set_pp_params_v5) + params_length; |
| 896 | adm_params = kzalloc(sz, GFP_KERNEL); |
| 897 | if (!adm_params) { |
| 898 | pr_err("%s, adm params memory alloc failed", __func__); |
| 899 | return -ENOMEM; |
| 900 | } |
| 901 | |
| 902 | memcpy(((u8 *)adm_params + sizeof(struct adm_cmd_set_pp_params_v5)), |
| 903 | params, params_length); |
| 904 | adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 905 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 906 | adm_params->hdr.pkt_size = sz; |
| 907 | adm_params->hdr.src_svc = APR_SVC_ADM; |
| 908 | adm_params->hdr.src_domain = APR_DOMAIN_APPS; |
| 909 | adm_params->hdr.src_port = port_id; |
| 910 | adm_params->hdr.dest_svc = APR_SVC_ADM; |
| 911 | adm_params->hdr.dest_domain = APR_DOMAIN_ADSP; |
| 912 | adm_params->hdr.dest_port = |
| 913 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 914 | adm_params->hdr.token = port_idx << 16 | copp_idx; |
| 915 | adm_params->hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; |
| 916 | adm_params->payload_addr_lsw = 0; |
| 917 | adm_params->payload_addr_msw = 0; |
| 918 | adm_params->mem_map_handle = 0; |
| 919 | adm_params->payload_size = params_length; |
| 920 | |
| 921 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 922 | rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params); |
| 923 | if (rc < 0) { |
| 924 | pr_err("%s: Set params failed port = 0x%x rc %d\n", |
| 925 | __func__, port_id, rc); |
| 926 | rc = -EINVAL; |
| 927 | goto dolby_dap_send_param_return; |
| 928 | } |
| 929 | /* Wait for the callback */ |
| 930 | rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 931 | atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, |
| 932 | msecs_to_jiffies(TIMEOUT_MS)); |
| 933 | if (!rc) { |
| 934 | pr_err("%s: Set params timed out port = 0x%x\n", |
| 935 | __func__, port_id); |
| 936 | rc = -EINVAL; |
| 937 | goto dolby_dap_send_param_return; |
| 938 | } else if (atomic_read(&this_adm.copp.stat |
| 939 | [port_idx][copp_idx]) > 0) { |
| 940 | pr_err("%s: DSP returned error[%s]\n", |
| 941 | __func__, adsp_err_get_err_str( |
| 942 | atomic_read(&this_adm.copp.stat |
| 943 | [port_idx][copp_idx]))); |
| 944 | rc = adsp_err_get_lnx_err_code( |
| 945 | atomic_read(&this_adm.copp.stat |
| 946 | [port_idx][copp_idx])); |
| 947 | goto dolby_dap_send_param_return; |
| 948 | } |
| 949 | rc = 0; |
| 950 | dolby_dap_send_param_return: |
| 951 | kfree(adm_params); |
| 952 | return rc; |
| 953 | } |
| 954 | |
| 955 | int adm_send_params_v5(int port_id, int copp_idx, char *params, |
| 956 | uint32_t params_length) |
| 957 | { |
| 958 | struct adm_cmd_set_pp_params_v5 *adm_params = NULL; |
| 959 | int rc = 0; |
| 960 | int sz, port_idx; |
| 961 | |
| 962 | pr_debug("%s:\n", __func__); |
| 963 | port_id = afe_convert_virtual_to_portid(port_id); |
| 964 | port_idx = adm_validate_and_get_port_index(port_id); |
| 965 | if (port_idx < 0) { |
| 966 | pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); |
| 967 | return -EINVAL; |
| 968 | } |
| 969 | |
| 970 | sz = sizeof(struct adm_cmd_set_pp_params_v5) + params_length; |
| 971 | adm_params = kzalloc(sz, GFP_KERNEL); |
| 972 | if (!adm_params) { |
| 973 | pr_err("%s, adm params memory alloc failed", __func__); |
| 974 | return -ENOMEM; |
| 975 | } |
| 976 | |
| 977 | memcpy(((u8 *)adm_params + sizeof(struct adm_cmd_set_pp_params_v5)), |
| 978 | params, params_length); |
| 979 | adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 980 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 981 | adm_params->hdr.pkt_size = sz; |
| 982 | adm_params->hdr.src_svc = APR_SVC_ADM; |
| 983 | adm_params->hdr.src_domain = APR_DOMAIN_APPS; |
| 984 | adm_params->hdr.src_port = port_id; |
| 985 | adm_params->hdr.dest_svc = APR_SVC_ADM; |
| 986 | adm_params->hdr.dest_domain = APR_DOMAIN_ADSP; |
| 987 | adm_params->hdr.dest_port = |
| 988 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 989 | adm_params->hdr.token = port_idx << 16 | copp_idx; |
| 990 | adm_params->hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; |
| 991 | adm_params->payload_addr_lsw = 0; |
| 992 | adm_params->payload_addr_msw = 0; |
| 993 | adm_params->mem_map_handle = 0; |
| 994 | adm_params->payload_size = params_length; |
| 995 | |
| 996 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 997 | rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params); |
| 998 | if (rc < 0) { |
| 999 | pr_err("%s: Set params failed port = 0x%x rc %d\n", |
| 1000 | __func__, port_id, rc); |
| 1001 | rc = -EINVAL; |
| 1002 | goto send_param_return; |
| 1003 | } |
| 1004 | /* Wait for the callback */ |
| 1005 | rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 1006 | atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, |
| 1007 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1008 | if (!rc) { |
| 1009 | pr_err("%s: Set params timed out port = 0x%x\n", |
| 1010 | __func__, port_id); |
| 1011 | rc = -EINVAL; |
| 1012 | goto send_param_return; |
| 1013 | } else if (atomic_read(&this_adm.copp.stat |
| 1014 | [port_idx][copp_idx]) > 0) { |
| 1015 | pr_err("%s: DSP returned error[%s]\n", |
| 1016 | __func__, adsp_err_get_err_str( |
| 1017 | atomic_read(&this_adm.copp.stat |
| 1018 | [port_idx][copp_idx]))); |
| 1019 | rc = adsp_err_get_lnx_err_code( |
| 1020 | atomic_read(&this_adm.copp.stat |
| 1021 | [port_idx][copp_idx])); |
| 1022 | goto send_param_return; |
| 1023 | } |
| 1024 | rc = 0; |
| 1025 | send_param_return: |
| 1026 | kfree(adm_params); |
| 1027 | return rc; |
| 1028 | } |
| 1029 | |
| 1030 | int adm_get_params_v2(int port_id, int copp_idx, uint32_t module_id, |
| 1031 | uint32_t param_id, uint32_t params_length, |
| 1032 | char *params, uint32_t client_id) |
| 1033 | { |
| 1034 | struct adm_cmd_get_pp_params_v5 *adm_params = NULL; |
| 1035 | int rc = 0, i = 0; |
| 1036 | int port_idx, idx; |
| 1037 | int *params_data = (int *)params; |
| 1038 | uint64_t sz = 0; |
| 1039 | |
| 1040 | port_id = afe_convert_virtual_to_portid(port_id); |
| 1041 | port_idx = adm_validate_and_get_port_index(port_id); |
| 1042 | if (port_idx < 0) { |
| 1043 | pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); |
| 1044 | return -EINVAL; |
| 1045 | } |
| 1046 | |
| 1047 | sz = (uint64_t)sizeof(struct adm_cmd_get_pp_params_v5) + |
| 1048 | (uint64_t)params_length; |
| 1049 | /* |
| 1050 | * Check if the value of "sz" (which is ultimately assigned to |
| 1051 | * "hdr.pkt_size") crosses U16_MAX. |
| 1052 | */ |
| 1053 | if (sz > U16_MAX) { |
| 1054 | pr_err("%s: Invalid params_length\n", __func__); |
| 1055 | return -EINVAL; |
| 1056 | } |
| 1057 | adm_params = kzalloc(sz, GFP_KERNEL); |
| 1058 | if (!adm_params) { |
| 1059 | pr_err("%s: adm params memory alloc failed", __func__); |
| 1060 | return -ENOMEM; |
| 1061 | } |
| 1062 | |
| 1063 | memcpy(((u8 *)adm_params + sizeof(struct adm_cmd_get_pp_params_v5)), |
| 1064 | params, params_length); |
| 1065 | adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1066 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1067 | adm_params->hdr.pkt_size = sz; |
| 1068 | adm_params->hdr.src_svc = APR_SVC_ADM; |
| 1069 | adm_params->hdr.src_domain = APR_DOMAIN_APPS; |
| 1070 | adm_params->hdr.src_port = port_id; |
| 1071 | adm_params->hdr.dest_svc = APR_SVC_ADM; |
| 1072 | adm_params->hdr.dest_domain = APR_DOMAIN_ADSP; |
| 1073 | adm_params->hdr.dest_port = |
| 1074 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 1075 | adm_params->hdr.token = port_idx << 16 | client_id << 8 | copp_idx; |
| 1076 | adm_params->hdr.opcode = ADM_CMD_GET_PP_PARAMS_V5; |
| 1077 | adm_params->data_payload_addr_lsw = 0; |
| 1078 | adm_params->data_payload_addr_msw = 0; |
| 1079 | adm_params->mem_map_handle = 0; |
| 1080 | adm_params->module_id = module_id; |
| 1081 | adm_params->param_id = param_id; |
| 1082 | adm_params->param_max_size = params_length; |
| 1083 | adm_params->reserved = 0; |
| 1084 | |
| 1085 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 1086 | rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params); |
| 1087 | if (rc < 0) { |
| 1088 | pr_err("%s: Failed to Get Params on port_id 0x%x %d\n", |
| 1089 | __func__, port_id, rc); |
| 1090 | rc = -EINVAL; |
| 1091 | goto adm_get_param_return; |
| 1092 | } |
| 1093 | /* Wait for the callback with copp id */ |
| 1094 | rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 1095 | atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, |
| 1096 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1097 | if (!rc) { |
| 1098 | pr_err("%s: get params timed out port_id = 0x%x\n", __func__, |
| 1099 | port_id); |
| 1100 | rc = -EINVAL; |
| 1101 | goto adm_get_param_return; |
| 1102 | } else if (atomic_read(&this_adm.copp.stat |
| 1103 | [port_idx][copp_idx]) > 0) { |
| 1104 | pr_err("%s: DSP returned error[%s]\n", |
| 1105 | __func__, adsp_err_get_err_str( |
| 1106 | atomic_read(&this_adm.copp.stat |
| 1107 | [port_idx][copp_idx]))); |
| 1108 | rc = adsp_err_get_lnx_err_code( |
| 1109 | atomic_read(&this_adm.copp.stat |
| 1110 | [port_idx][copp_idx])); |
| 1111 | goto adm_get_param_return; |
| 1112 | } |
| 1113 | idx = ADM_GET_PARAMETER_LENGTH * copp_idx; |
| 1114 | |
| 1115 | if (adm_get_parameters[idx] < 0) { |
| 1116 | pr_err("%s: Size is invalid %d\n", __func__, |
| 1117 | adm_get_parameters[idx]); |
| 1118 | rc = -EINVAL; |
| 1119 | goto adm_get_param_return; |
| 1120 | } |
| 1121 | if ((params_data) && |
| 1122 | (ARRAY_SIZE(adm_get_parameters) > |
| 1123 | idx) && |
| 1124 | (ARRAY_SIZE(adm_get_parameters) >= |
| 1125 | 1+adm_get_parameters[idx]+idx) && |
| 1126 | (params_length/sizeof(uint32_t) >= |
| 1127 | adm_get_parameters[idx])) { |
| 1128 | for (i = 0; i < adm_get_parameters[idx]; i++) |
| 1129 | params_data[i] = adm_get_parameters[1+i+idx]; |
| 1130 | |
| 1131 | } else { |
| 1132 | pr_err("%s: Get param data not copied! get_param array size %zd, index %d, params array size %zd, index %d\n", |
| 1133 | __func__, ARRAY_SIZE(adm_get_parameters), |
| 1134 | (1+adm_get_parameters[idx]+idx), |
| 1135 | params_length/sizeof(int), |
| 1136 | adm_get_parameters[idx]); |
| 1137 | } |
| 1138 | rc = 0; |
| 1139 | adm_get_param_return: |
| 1140 | kfree(adm_params); |
| 1141 | |
| 1142 | return rc; |
| 1143 | } |
| 1144 | |
| 1145 | int adm_get_params(int port_id, int copp_idx, uint32_t module_id, |
| 1146 | uint32_t param_id, uint32_t params_length, char *params) |
| 1147 | { |
| 1148 | return adm_get_params_v2(port_id, copp_idx, module_id, param_id, |
| 1149 | params_length, params, 0); |
| 1150 | } |
| 1151 | |
| 1152 | int adm_get_pp_topo_module_list(int port_id, int copp_idx, int32_t param_length, |
| 1153 | char *params) |
| 1154 | { |
| 1155 | struct adm_cmd_get_pp_topo_module_list_t *adm_pp_module_list = NULL; |
| 1156 | int sz, rc = 0, i = 0; |
| 1157 | int port_idx, idx; |
| 1158 | int32_t *params_data = (int32_t *)params; |
| 1159 | int *topo_list; |
| 1160 | |
| 1161 | pr_debug("%s : port_id %x", __func__, port_id); |
| 1162 | port_id = afe_convert_virtual_to_portid(port_id); |
| 1163 | port_idx = adm_validate_and_get_port_index(port_id); |
| 1164 | if (port_idx < 0) { |
| 1165 | pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); |
| 1166 | return -EINVAL; |
| 1167 | } |
| 1168 | |
| 1169 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 1170 | pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); |
| 1171 | return -EINVAL; |
| 1172 | } |
| 1173 | |
| 1174 | sz = sizeof(struct adm_cmd_get_pp_topo_module_list_t) + param_length; |
| 1175 | adm_pp_module_list = kzalloc(sz, GFP_KERNEL); |
| 1176 | if (!adm_pp_module_list) { |
| 1177 | pr_err("%s, adm params memory alloc failed", __func__); |
| 1178 | return -ENOMEM; |
| 1179 | } |
| 1180 | |
| 1181 | memcpy(((u8 *)adm_pp_module_list + |
| 1182 | sizeof(struct adm_cmd_get_pp_topo_module_list_t)), |
| 1183 | params, param_length); |
| 1184 | adm_pp_module_list->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1185 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 1186 | adm_pp_module_list->hdr.pkt_size = sz; |
| 1187 | adm_pp_module_list->hdr.src_svc = APR_SVC_ADM; |
| 1188 | adm_pp_module_list->hdr.src_domain = APR_DOMAIN_APPS; |
| 1189 | adm_pp_module_list->hdr.src_port = port_id; |
| 1190 | adm_pp_module_list->hdr.dest_svc = APR_SVC_ADM; |
| 1191 | adm_pp_module_list->hdr.dest_domain = APR_DOMAIN_ADSP; |
| 1192 | adm_pp_module_list->hdr.dest_port = |
| 1193 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 1194 | adm_pp_module_list->hdr.token = port_idx << 16 | copp_idx; |
| 1195 | adm_pp_module_list->hdr.opcode = ADM_CMD_GET_PP_TOPO_MODULE_LIST; |
| 1196 | adm_pp_module_list->param_max_size = param_length; |
| 1197 | /* Payload address and mmap handle set to zero by kzalloc */ |
| 1198 | |
| 1199 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 1200 | |
| 1201 | rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_pp_module_list); |
| 1202 | if (rc < 0) { |
| 1203 | pr_err("%s: Failed to Get Params on port %d\n", __func__, |
| 1204 | port_id); |
| 1205 | rc = -EINVAL; |
| 1206 | goto adm_pp_module_list_l; |
| 1207 | } |
| 1208 | /* Wait for the callback with copp id */ |
| 1209 | rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 1210 | atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, |
| 1211 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1212 | if (!rc) { |
| 1213 | pr_err("%s: get params timed out port = %d\n", __func__, |
| 1214 | port_id); |
| 1215 | rc = -EINVAL; |
| 1216 | goto adm_pp_module_list_l; |
| 1217 | } else if (atomic_read(&this_adm.copp.stat |
| 1218 | [port_idx][copp_idx]) > 0) { |
| 1219 | pr_err("%s: DSP returned error[%s]\n", |
| 1220 | __func__, adsp_err_get_err_str( |
| 1221 | atomic_read(&this_adm.copp.stat |
| 1222 | [port_idx][copp_idx]))); |
| 1223 | rc = adsp_err_get_lnx_err_code( |
| 1224 | atomic_read(&this_adm.copp.stat |
| 1225 | [port_idx][copp_idx])); |
| 1226 | goto adm_pp_module_list_l; |
| 1227 | } |
| 1228 | if (params_data) { |
| 1229 | idx = ADM_GET_TOPO_MODULE_LIST_LENGTH * copp_idx; |
| 1230 | topo_list = (int *)(adm_module_topo_list + idx); |
| 1231 | if (param_length <= ADM_GET_TOPO_MODULE_LIST_LENGTH && |
| 1232 | idx < |
| 1233 | (MAX_COPPS_PER_PORT * ADM_GET_TOPO_MODULE_LIST_LENGTH)) |
| 1234 | memcpy(params_data, topo_list, param_length); |
| 1235 | else |
| 1236 | pr_debug("%s: i/p size:%d > MAX param size:%d\n", |
| 1237 | __func__, param_length, |
| 1238 | (int)ADM_GET_TOPO_MODULE_LIST_LENGTH); |
| 1239 | for (i = 1; i <= params_data[0]; i++) |
| 1240 | pr_debug("module = 0x%x\n", params_data[i]); |
| 1241 | } |
| 1242 | rc = 0; |
| 1243 | adm_pp_module_list_l: |
| 1244 | kfree(adm_pp_module_list); |
| 1245 | pr_debug("%s : rc = %d ", __func__, rc); |
| 1246 | return rc; |
| 1247 | } |
| 1248 | static void adm_callback_debug_print(struct apr_client_data *data) |
| 1249 | { |
| 1250 | uint32_t *payload; |
| 1251 | |
| 1252 | payload = data->payload; |
| 1253 | |
| 1254 | if (data->payload_size >= 8) |
| 1255 | pr_debug("%s: code = 0x%x PL#0[0x%x], PL#1[0x%x], size = %d\n", |
| 1256 | __func__, data->opcode, payload[0], payload[1], |
| 1257 | data->payload_size); |
| 1258 | else if (data->payload_size >= 4) |
| 1259 | pr_debug("%s: code = 0x%x PL#0[0x%x], size = %d\n", |
| 1260 | __func__, data->opcode, payload[0], |
| 1261 | data->payload_size); |
| 1262 | else |
| 1263 | pr_debug("%s: code = 0x%x, size = %d\n", |
| 1264 | __func__, data->opcode, data->payload_size); |
| 1265 | } |
| 1266 | |
| 1267 | int adm_set_multi_ch_map(char *channel_map, int path) |
| 1268 | { |
| 1269 | int idx; |
| 1270 | |
| 1271 | if (path == ADM_PATH_PLAYBACK) { |
| 1272 | idx = ADM_MCH_MAP_IDX_PLAYBACK; |
| 1273 | } else if (path == ADM_PATH_LIVE_REC) { |
| 1274 | idx = ADM_MCH_MAP_IDX_REC; |
| 1275 | } else { |
| 1276 | pr_err("%s: invalid attempt to set path %d\n", __func__, path); |
| 1277 | return -EINVAL; |
| 1278 | } |
| 1279 | |
| 1280 | memcpy(multi_ch_maps[idx].channel_mapping, channel_map, |
| 1281 | PCM_FORMAT_MAX_NUM_CHANNEL); |
| 1282 | multi_ch_maps[idx].set_channel_map = true; |
| 1283 | |
| 1284 | return 0; |
| 1285 | } |
| 1286 | |
| 1287 | int adm_get_multi_ch_map(char *channel_map, int path) |
| 1288 | { |
| 1289 | int idx; |
| 1290 | |
| 1291 | if (path == ADM_PATH_PLAYBACK) { |
| 1292 | idx = ADM_MCH_MAP_IDX_PLAYBACK; |
| 1293 | } else if (path == ADM_PATH_LIVE_REC) { |
| 1294 | idx = ADM_MCH_MAP_IDX_REC; |
| 1295 | } else { |
| 1296 | pr_err("%s: invalid attempt to get path %d\n", __func__, path); |
| 1297 | return -EINVAL; |
| 1298 | } |
| 1299 | |
| 1300 | if (multi_ch_maps[idx].set_channel_map) { |
| 1301 | memcpy(channel_map, multi_ch_maps[idx].channel_mapping, |
| 1302 | PCM_FORMAT_MAX_NUM_CHANNEL); |
| 1303 | } |
| 1304 | |
| 1305 | return 0; |
| 1306 | } |
| 1307 | |
| 1308 | static int32_t adm_callback(struct apr_client_data *data, void *priv) |
| 1309 | { |
| 1310 | uint32_t *payload; |
| 1311 | int i, j, port_idx, copp_idx, idx, client_id; |
| 1312 | |
| 1313 | if (data == NULL) { |
| 1314 | pr_err("%s: data parameter is null\n", __func__); |
| 1315 | return -EINVAL; |
| 1316 | } |
| 1317 | |
| 1318 | payload = data->payload; |
| 1319 | |
| 1320 | if (data->opcode == RESET_EVENTS) { |
| 1321 | pr_debug("%s: Reset event is received: %d %d apr[%pK]\n", |
| 1322 | __func__, |
| 1323 | data->reset_event, data->reset_proc, this_adm.apr); |
| 1324 | if (this_adm.apr) { |
| 1325 | apr_reset(this_adm.apr); |
| 1326 | for (i = 0; i < AFE_MAX_PORTS; i++) { |
| 1327 | for (j = 0; j < MAX_COPPS_PER_PORT; j++) { |
| 1328 | atomic_set(&this_adm.copp.id[i][j], |
| 1329 | RESET_COPP_ID); |
| 1330 | atomic_set(&this_adm.copp.cnt[i][j], 0); |
| 1331 | atomic_set( |
| 1332 | &this_adm.copp.topology[i][j], 0); |
| 1333 | atomic_set(&this_adm.copp.mode[i][j], |
| 1334 | 0); |
| 1335 | atomic_set(&this_adm.copp.stat[i][j], |
| 1336 | 0); |
| 1337 | atomic_set(&this_adm.copp.rate[i][j], |
| 1338 | 0); |
| 1339 | atomic_set( |
| 1340 | &this_adm.copp.channels[i][j], |
| 1341 | 0); |
| 1342 | atomic_set( |
| 1343 | &this_adm.copp.bit_width[i][j], 0); |
| 1344 | atomic_set( |
| 1345 | &this_adm.copp.app_type[i][j], 0); |
| 1346 | atomic_set( |
| 1347 | &this_adm.copp.acdb_id[i][j], 0); |
| 1348 | this_adm.copp.adm_status[i][j] = |
| 1349 | ADM_STATUS_CALIBRATION_REQUIRED; |
| 1350 | } |
| 1351 | } |
| 1352 | this_adm.apr = NULL; |
| 1353 | cal_utils_clear_cal_block_q6maps(ADM_MAX_CAL_TYPES, |
| 1354 | this_adm.cal_data); |
| 1355 | mutex_lock(&this_adm.cal_data |
| 1356 | [ADM_CUSTOM_TOP_CAL]->lock); |
| 1357 | this_adm.set_custom_topology = 1; |
| 1358 | mutex_unlock(&this_adm.cal_data[ |
| 1359 | ADM_CUSTOM_TOP_CAL]->lock); |
| 1360 | rtac_clear_mapping(ADM_RTAC_CAL); |
| 1361 | /* |
| 1362 | * Free the ION memory and clear the map handles |
| 1363 | * for Source Tracking |
| 1364 | */ |
| 1365 | if (this_adm.sourceTrackingData.memmap.paddr != 0) { |
| 1366 | msm_audio_ion_free( |
| 1367 | this_adm.sourceTrackingData.ion_client, |
| 1368 | this_adm.sourceTrackingData.ion_handle); |
| 1369 | this_adm.sourceTrackingData.ion_client = NULL; |
| 1370 | this_adm.sourceTrackingData.ion_handle = NULL; |
| 1371 | this_adm.sourceTrackingData.memmap.size = 0; |
| 1372 | this_adm.sourceTrackingData.memmap.kvaddr = |
| 1373 | NULL; |
| 1374 | this_adm.sourceTrackingData.memmap.paddr = 0; |
| 1375 | this_adm.sourceTrackingData.apr_cmd_status = -1; |
| 1376 | atomic_set(&this_adm.mem_map_handles[ |
| 1377 | ADM_MEM_MAP_INDEX_SOURCE_TRACKING], 0); |
| 1378 | } |
| 1379 | } |
| 1380 | return 0; |
| 1381 | } |
| 1382 | |
| 1383 | adm_callback_debug_print(data); |
Vignesh Kulothungan | 21d17b1 | 2019-01-22 11:13:09 -0800 | [diff] [blame] | 1384 | if (data->payload_size >= sizeof(uint32_t)) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1385 | copp_idx = (data->token) & 0XFF; |
| 1386 | port_idx = ((data->token) >> 16) & 0xFF; |
| 1387 | client_id = ((data->token) >> 8) & 0xFF; |
| 1388 | if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) { |
| 1389 | pr_err("%s: Invalid port idx %d token %d\n", |
| 1390 | __func__, port_idx, data->token); |
| 1391 | return 0; |
| 1392 | } |
| 1393 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 1394 | pr_err("%s: Invalid copp idx %d token %d\n", |
| 1395 | __func__, copp_idx, data->token); |
| 1396 | return 0; |
| 1397 | } |
| 1398 | if (client_id < 0 || client_id >= ADM_CLIENT_ID_MAX) { |
| 1399 | pr_err("%s: Invalid client id %d\n", __func__, |
| 1400 | client_id); |
| 1401 | return 0; |
| 1402 | } |
| 1403 | if (data->opcode == APR_BASIC_RSP_RESULT) { |
| 1404 | pr_debug("%s: APR_BASIC_RSP_RESULT id 0x%x\n", |
| 1405 | __func__, payload[0]); |
Vignesh Kulothungan | 21d17b1 | 2019-01-22 11:13:09 -0800 | [diff] [blame] | 1406 | if (!((client_id != ADM_CLIENT_ID_SOURCE_TRACKING) && |
| 1407 | (payload[0] == ADM_CMD_SET_PP_PARAMS_V5))) { |
| 1408 | if (data->payload_size < |
| 1409 | (2 * sizeof(uint32_t))) { |
| 1410 | pr_err("%s: Invalid payload size %d\n", |
| 1411 | __func__, data->payload_size); |
| 1412 | return 0; |
| 1413 | } |
| 1414 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1415 | if (payload[1] != 0) { |
| 1416 | pr_err("%s: cmd = 0x%x returned error = 0x%x\n", |
| 1417 | __func__, payload[0], payload[1]); |
| 1418 | } |
| 1419 | switch (payload[0]) { |
| 1420 | case ADM_CMD_SET_PP_PARAMS_V5: |
| 1421 | pr_debug("%s: ADM_CMD_SET_PP_PARAMS_V5\n", |
| 1422 | __func__); |
| 1423 | if (client_id == ADM_CLIENT_ID_SOURCE_TRACKING) |
| 1424 | this_adm.sourceTrackingData. |
| 1425 | apr_cmd_status = payload[1]; |
| 1426 | else if (rtac_make_adm_callback(payload, |
| 1427 | data->payload_size)) |
| 1428 | break; |
| 1429 | /* |
| 1430 | * if soft volume is called and already |
| 1431 | * interrupted break out of the sequence here |
| 1432 | */ |
| 1433 | case ADM_CMD_DEVICE_OPEN_V5: |
| 1434 | case ADM_CMD_DEVICE_CLOSE_V5: |
| 1435 | case ADM_CMD_DEVICE_OPEN_V6: |
| 1436 | pr_debug("%s: Basic callback received, wake up.\n", |
| 1437 | __func__); |
| 1438 | atomic_set(&this_adm.copp.stat[port_idx] |
| 1439 | [copp_idx], payload[1]); |
| 1440 | wake_up( |
| 1441 | &this_adm.copp.wait[port_idx][copp_idx]); |
| 1442 | break; |
| 1443 | case ADM_CMD_ADD_TOPOLOGIES: |
| 1444 | pr_debug("%s: callback received, ADM_CMD_ADD_TOPOLOGIES.\n", |
| 1445 | __func__); |
| 1446 | atomic_set(&this_adm.adm_stat, payload[1]); |
| 1447 | wake_up(&this_adm.adm_wait); |
| 1448 | break; |
| 1449 | case ADM_CMD_MATRIX_MAP_ROUTINGS_V5: |
| 1450 | case ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5: |
| 1451 | pr_debug("%s: Basic callback received, wake up.\n", |
| 1452 | __func__); |
| 1453 | atomic_set(&this_adm.matrix_map_stat, |
| 1454 | payload[1]); |
| 1455 | wake_up(&this_adm.matrix_map_wait); |
| 1456 | break; |
| 1457 | case ADM_CMD_SHARED_MEM_UNMAP_REGIONS: |
| 1458 | pr_debug("%s: ADM_CMD_SHARED_MEM_UNMAP_REGIONS\n", |
| 1459 | __func__); |
| 1460 | atomic_set(&this_adm.adm_stat, payload[1]); |
| 1461 | wake_up(&this_adm.adm_wait); |
| 1462 | break; |
| 1463 | case ADM_CMD_SHARED_MEM_MAP_REGIONS: |
| 1464 | pr_debug("%s: ADM_CMD_SHARED_MEM_MAP_REGIONS\n", |
| 1465 | __func__); |
| 1466 | /* Should only come here if there is an APR */ |
| 1467 | /* error or malformed APR packet. Otherwise */ |
| 1468 | /* response will be returned as */ |
| 1469 | if (payload[1] != 0) { |
| 1470 | pr_err("%s: ADM map error, resuming\n", |
| 1471 | __func__); |
| 1472 | atomic_set(&this_adm.adm_stat, |
| 1473 | payload[1]); |
| 1474 | wake_up(&this_adm.adm_wait); |
| 1475 | } |
| 1476 | break; |
| 1477 | case ADM_CMD_GET_PP_PARAMS_V5: |
| 1478 | pr_debug("%s: ADM_CMD_GET_PP_PARAMS_V5\n", |
| 1479 | __func__); |
| 1480 | /* Should only come here if there is an APR */ |
| 1481 | /* error or malformed APR packet. Otherwise */ |
| 1482 | /* response will be returned as */ |
| 1483 | /* ADM_CMDRSP_GET_PP_PARAMS_V5 */ |
| 1484 | if (client_id == |
| 1485 | ADM_CLIENT_ID_SOURCE_TRACKING) { |
| 1486 | this_adm.sourceTrackingData. |
| 1487 | apr_cmd_status = payload[1]; |
| 1488 | if (payload[1] != 0) |
| 1489 | pr_err("%s: ADM get param error = %d\n", |
| 1490 | __func__, payload[1]); |
| 1491 | |
| 1492 | atomic_set(&this_adm.copp.stat |
| 1493 | [port_idx][copp_idx], |
| 1494 | payload[1]); |
| 1495 | wake_up(&this_adm.copp.wait |
| 1496 | [port_idx][copp_idx]); |
| 1497 | } else { |
| 1498 | if (payload[1] != 0) { |
| 1499 | pr_err("%s: ADM get param error = %d, resuming\n", |
| 1500 | __func__, payload[1]); |
| 1501 | |
| 1502 | rtac_make_adm_callback(payload, |
| 1503 | data->payload_size); |
| 1504 | } |
| 1505 | } |
| 1506 | break; |
| 1507 | case ADM_CMD_SET_PSPD_MTMX_STRTR_PARAMS_V5: |
| 1508 | pr_debug("%s: ADM_CMD_SET_PSPD_MTMX_STRTR_PARAMS_V5\n", |
| 1509 | __func__); |
| 1510 | atomic_set(&this_adm.copp.stat[port_idx] |
| 1511 | [copp_idx], payload[1]); |
| 1512 | wake_up( |
| 1513 | &this_adm.copp.wait[port_idx][copp_idx]); |
| 1514 | break; |
| 1515 | case ADM_CMD_GET_PP_TOPO_MODULE_LIST: |
| 1516 | pr_debug("%s:ADM_CMD_GET_PP_TOPO_MODULE_LIST\n", |
| 1517 | __func__); |
| 1518 | if (payload[1] != 0) |
| 1519 | pr_err("%s: ADM get topo list error = %d,\n", |
| 1520 | __func__, payload[1]); |
| 1521 | break; |
| 1522 | default: |
| 1523 | pr_err("%s: Unknown Cmd: 0x%x\n", __func__, |
| 1524 | payload[0]); |
| 1525 | break; |
| 1526 | } |
| 1527 | return 0; |
| 1528 | } |
| 1529 | |
| 1530 | switch (data->opcode) { |
| 1531 | case ADM_CMDRSP_DEVICE_OPEN_V5: |
| 1532 | case ADM_CMDRSP_DEVICE_OPEN_V6: { |
Vignesh Kulothungan | 21d17b1 | 2019-01-22 11:13:09 -0800 | [diff] [blame] | 1533 | struct adm_cmd_rsp_device_open_v5 *open = NULL; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1534 | |
Vignesh Kulothungan | 21d17b1 | 2019-01-22 11:13:09 -0800 | [diff] [blame] | 1535 | if (data->payload_size < |
| 1536 | sizeof(struct adm_cmd_rsp_device_open_v5)) { |
| 1537 | pr_err("%s: Invalid payload size %d\n", |
| 1538 | __func__, data->payload_size); |
| 1539 | return 0; |
| 1540 | } |
| 1541 | open = |
| 1542 | (struct adm_cmd_rsp_device_open_v5 *)data->payload; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1543 | if (open->copp_id == INVALID_COPP_ID) { |
| 1544 | pr_err("%s: invalid coppid rxed %d\n", |
| 1545 | __func__, open->copp_id); |
| 1546 | atomic_set(&this_adm.copp.stat[port_idx] |
| 1547 | [copp_idx], ADSP_EBADPARAM); |
| 1548 | wake_up( |
| 1549 | &this_adm.copp.wait[port_idx][copp_idx]); |
| 1550 | break; |
| 1551 | } |
| 1552 | atomic_set(&this_adm.copp.stat |
| 1553 | [port_idx][copp_idx], payload[0]); |
| 1554 | atomic_set(&this_adm.copp.id[port_idx][copp_idx], |
| 1555 | open->copp_id); |
| 1556 | pr_debug("%s: coppid rxed=%d\n", __func__, |
| 1557 | open->copp_id); |
| 1558 | wake_up(&this_adm.copp.wait[port_idx][copp_idx]); |
| 1559 | } |
| 1560 | break; |
| 1561 | case ADM_CMDRSP_GET_PP_PARAMS_V5: |
| 1562 | pr_debug("%s: ADM_CMDRSP_GET_PP_PARAMS_V5\n", __func__); |
| 1563 | if (payload[0] != 0) |
| 1564 | pr_err("%s: ADM_CMDRSP_GET_PP_PARAMS_V5 returned error = 0x%x\n", |
| 1565 | __func__, payload[0]); |
| 1566 | if (client_id == ADM_CLIENT_ID_SOURCE_TRACKING) |
| 1567 | this_adm.sourceTrackingData.apr_cmd_status = |
| 1568 | payload[0]; |
| 1569 | else if (rtac_make_adm_callback(payload, |
| 1570 | data->payload_size)) |
| 1571 | break; |
| 1572 | |
| 1573 | idx = ADM_GET_PARAMETER_LENGTH * copp_idx; |
| 1574 | if ((payload[0] == 0) && (data->payload_size > |
| 1575 | (4 * sizeof(*payload))) && |
Sujin Panicker | f619a95 | 2019-09-26 18:08:51 +0530 | [diff] [blame] | 1576 | (data->payload_size - |
| 1577 | (4 * sizeof(*payload)) >= |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1578 | payload[3]) && |
| 1579 | (ARRAY_SIZE(adm_get_parameters) > |
| 1580 | idx) && |
| 1581 | (ARRAY_SIZE(adm_get_parameters)-idx-1 >= |
| 1582 | payload[3])) { |
| 1583 | adm_get_parameters[idx] = payload[3] / |
| 1584 | sizeof(uint32_t); |
| 1585 | /* |
| 1586 | * payload[3] is param_size which is |
| 1587 | * expressed in number of bytes |
| 1588 | */ |
| 1589 | pr_debug("%s: GET_PP PARAM:received parameter length: 0x%x\n", |
| 1590 | __func__, adm_get_parameters[idx]); |
| 1591 | /* storing param size then params */ |
| 1592 | for (i = 0; i < payload[3] / |
| 1593 | sizeof(uint32_t); i++) |
| 1594 | adm_get_parameters[idx+1+i] = |
| 1595 | payload[4+i]; |
| 1596 | } else if (payload[0] == 0) { |
| 1597 | adm_get_parameters[idx] = -1; |
| 1598 | pr_err("%s: Out of band case, setting size to %d\n", |
| 1599 | __func__, adm_get_parameters[idx]); |
| 1600 | } else { |
| 1601 | adm_get_parameters[idx] = -1; |
| 1602 | pr_err("%s: GET_PP_PARAMS failed, setting size to %d\n", |
| 1603 | __func__, adm_get_parameters[idx]); |
| 1604 | } |
| 1605 | atomic_set(&this_adm.copp.stat |
| 1606 | [port_idx][copp_idx], payload[0]); |
| 1607 | wake_up(&this_adm.copp.wait[port_idx][copp_idx]); |
| 1608 | break; |
| 1609 | case ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST: |
| 1610 | pr_debug("%s: ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST\n", |
| 1611 | __func__); |
| 1612 | if (payload[0] != 0) { |
| 1613 | pr_err("%s: ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST", |
| 1614 | __func__); |
| 1615 | pr_err(":err = 0x%x\n", payload[0]); |
Vignesh Kulothungan | 21d17b1 | 2019-01-22 11:13:09 -0800 | [diff] [blame] | 1616 | } else if (data->payload_size >= |
| 1617 | (2 * sizeof(uint32_t))) { |
Sujin Panicker | d97a389 | 2019-09-26 16:54:22 +0530 | [diff] [blame] | 1618 | if ((payload[1] > |
Vignesh Kulothungan | 21d17b1 | 2019-01-22 11:13:09 -0800 | [diff] [blame] | 1619 | ((ADM_GET_TOPO_MODULE_LIST_LENGTH / |
Sujin Panicker | d97a389 | 2019-09-26 16:54:22 +0530 | [diff] [blame] | 1620 | sizeof(uint32_t)) - 1)) || |
| 1621 | ((data->payload_size - |
| 1622 | (2 * sizeof(uint32_t))) < |
| 1623 | (payload[1] * sizeof(uint32_t)))) { |
Vignesh Kulothungan | 21d17b1 | 2019-01-22 11:13:09 -0800 | [diff] [blame] | 1624 | pr_err("%s: ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST", |
| 1625 | __func__); |
| 1626 | pr_err(":size = %d\n", payload[1]); |
| 1627 | } else { |
| 1628 | idx = ADM_GET_TOPO_MODULE_LIST_LENGTH * |
| 1629 | copp_idx; |
| 1630 | pr_debug("%s:Num modules payload[1] %d\n", |
| 1631 | __func__, payload[1]); |
| 1632 | adm_module_topo_list[idx] = payload[1]; |
| 1633 | for (i = 1; i <= payload[1]; i++) { |
| 1634 | adm_module_topo_list[idx+i] = |
| 1635 | payload[1+i]; |
| 1636 | pr_debug("%s:payload[%d] = %x\n", |
| 1637 | __func__, (i+1), |
| 1638 | payload[1+i]); |
| 1639 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1640 | } |
Vignesh Kulothungan | 21d17b1 | 2019-01-22 11:13:09 -0800 | [diff] [blame] | 1641 | } else |
| 1642 | pr_err("%s: Invalid payload size %d\n", |
| 1643 | __func__, data->payload_size); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1644 | atomic_set(&this_adm.copp.stat |
| 1645 | [port_idx][copp_idx], payload[0]); |
| 1646 | wake_up(&this_adm.copp.wait[port_idx][copp_idx]); |
| 1647 | break; |
| 1648 | case ADM_CMDRSP_SHARED_MEM_MAP_REGIONS: |
| 1649 | pr_debug("%s: ADM_CMDRSP_SHARED_MEM_MAP_REGIONS\n", |
| 1650 | __func__); |
| 1651 | atomic_set(&this_adm.mem_map_handles[ |
| 1652 | atomic_read(&this_adm.mem_map_index)], |
| 1653 | *payload); |
| 1654 | atomic_set(&this_adm.adm_stat, 0); |
| 1655 | wake_up(&this_adm.adm_wait); |
| 1656 | break; |
| 1657 | default: |
| 1658 | pr_err("%s: Unknown cmd:0x%x\n", __func__, |
| 1659 | data->opcode); |
| 1660 | break; |
| 1661 | } |
| 1662 | } |
| 1663 | return 0; |
| 1664 | } |
| 1665 | |
| 1666 | static int adm_memory_map_regions(phys_addr_t *buf_add, uint32_t mempool_id, |
| 1667 | uint32_t *bufsz, uint32_t bufcnt) |
| 1668 | { |
| 1669 | struct avs_cmd_shared_mem_map_regions *mmap_regions = NULL; |
| 1670 | struct avs_shared_map_region_payload *mregions = NULL; |
| 1671 | void *mmap_region_cmd = NULL; |
| 1672 | void *payload = NULL; |
| 1673 | int ret = 0; |
| 1674 | int i = 0; |
| 1675 | int cmd_size = 0; |
| 1676 | |
| 1677 | pr_debug("%s:\n", __func__); |
| 1678 | if (this_adm.apr == NULL) { |
| 1679 | this_adm.apr = apr_register("ADSP", "ADM", adm_callback, |
| 1680 | 0xFFFFFFFF, &this_adm); |
| 1681 | if (this_adm.apr == NULL) { |
| 1682 | pr_err("%s: Unable to register ADM\n", __func__); |
| 1683 | ret = -ENODEV; |
| 1684 | return ret; |
| 1685 | } |
| 1686 | rtac_set_adm_handle(this_adm.apr); |
| 1687 | } |
| 1688 | |
| 1689 | cmd_size = sizeof(struct avs_cmd_shared_mem_map_regions) |
| 1690 | + sizeof(struct avs_shared_map_region_payload) |
| 1691 | * bufcnt; |
| 1692 | |
| 1693 | mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL); |
| 1694 | if (!mmap_region_cmd) |
| 1695 | return -ENOMEM; |
| 1696 | |
| 1697 | mmap_regions = (struct avs_cmd_shared_mem_map_regions *)mmap_region_cmd; |
| 1698 | mmap_regions->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1699 | APR_HDR_LEN(APR_HDR_SIZE), |
| 1700 | APR_PKT_VER); |
| 1701 | mmap_regions->hdr.pkt_size = cmd_size; |
| 1702 | mmap_regions->hdr.src_port = 0; |
| 1703 | |
| 1704 | mmap_regions->hdr.dest_port = 0; |
| 1705 | mmap_regions->hdr.token = 0; |
| 1706 | mmap_regions->hdr.opcode = ADM_CMD_SHARED_MEM_MAP_REGIONS; |
| 1707 | mmap_regions->mem_pool_id = ADSP_MEMORY_MAP_SHMEM8_4K_POOL & 0x00ff; |
| 1708 | mmap_regions->num_regions = bufcnt & 0x00ff; |
| 1709 | mmap_regions->property_flag = 0x00; |
| 1710 | |
| 1711 | pr_debug("%s: map_regions->num_regions = %d\n", __func__, |
| 1712 | mmap_regions->num_regions); |
| 1713 | payload = ((u8 *) mmap_region_cmd + |
| 1714 | sizeof(struct avs_cmd_shared_mem_map_regions)); |
| 1715 | mregions = (struct avs_shared_map_region_payload *)payload; |
| 1716 | |
| 1717 | for (i = 0; i < bufcnt; i++) { |
| 1718 | mregions->shm_addr_lsw = lower_32_bits(buf_add[i]); |
| 1719 | mregions->shm_addr_msw = |
| 1720 | msm_audio_populate_upper_32_bits(buf_add[i]); |
| 1721 | mregions->mem_size_bytes = bufsz[i]; |
| 1722 | ++mregions; |
| 1723 | } |
| 1724 | |
| 1725 | atomic_set(&this_adm.adm_stat, -1); |
| 1726 | ret = apr_send_pkt(this_adm.apr, (uint32_t *) mmap_region_cmd); |
| 1727 | if (ret < 0) { |
| 1728 | pr_err("%s: mmap_regions op[0x%x]rc[%d]\n", __func__, |
| 1729 | mmap_regions->hdr.opcode, ret); |
| 1730 | ret = -EINVAL; |
| 1731 | goto fail_cmd; |
| 1732 | } |
| 1733 | |
| 1734 | ret = wait_event_timeout(this_adm.adm_wait, |
| 1735 | atomic_read(&this_adm.adm_stat) >= 0, |
| 1736 | 5 * HZ); |
| 1737 | if (!ret) { |
| 1738 | pr_err("%s: timeout. waited for memory_map\n", __func__); |
| 1739 | ret = -EINVAL; |
| 1740 | goto fail_cmd; |
| 1741 | } else if (atomic_read(&this_adm.adm_stat) > 0) { |
| 1742 | pr_err("%s: DSP returned error[%s]\n", |
| 1743 | __func__, adsp_err_get_err_str( |
| 1744 | atomic_read(&this_adm.adm_stat))); |
| 1745 | ret = adsp_err_get_lnx_err_code( |
| 1746 | atomic_read(&this_adm.adm_stat)); |
| 1747 | goto fail_cmd; |
| 1748 | } |
| 1749 | fail_cmd: |
| 1750 | kfree(mmap_region_cmd); |
| 1751 | return ret; |
| 1752 | } |
| 1753 | |
| 1754 | static int adm_memory_unmap_regions(void) |
| 1755 | { |
| 1756 | struct avs_cmd_shared_mem_unmap_regions unmap_regions; |
| 1757 | int ret = 0; |
| 1758 | |
| 1759 | pr_debug("%s:\n", __func__); |
| 1760 | if (this_adm.apr == NULL) { |
| 1761 | pr_err("%s: APR handle NULL\n", __func__); |
| 1762 | return -EINVAL; |
| 1763 | } |
| 1764 | |
| 1765 | unmap_regions.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1766 | APR_HDR_LEN(APR_HDR_SIZE), |
| 1767 | APR_PKT_VER); |
| 1768 | unmap_regions.hdr.pkt_size = sizeof(unmap_regions); |
| 1769 | unmap_regions.hdr.src_port = 0; |
| 1770 | unmap_regions.hdr.dest_port = 0; |
| 1771 | unmap_regions.hdr.token = 0; |
| 1772 | unmap_regions.hdr.opcode = ADM_CMD_SHARED_MEM_UNMAP_REGIONS; |
| 1773 | unmap_regions.mem_map_handle = atomic_read(&this_adm. |
| 1774 | mem_map_handles[atomic_read(&this_adm.mem_map_index)]); |
| 1775 | atomic_set(&this_adm.adm_stat, -1); |
| 1776 | ret = apr_send_pkt(this_adm.apr, (uint32_t *) &unmap_regions); |
| 1777 | if (ret < 0) { |
| 1778 | pr_err("%s: mmap_regions op[0x%x]rc[%d]\n", __func__, |
| 1779 | unmap_regions.hdr.opcode, ret); |
| 1780 | ret = -EINVAL; |
| 1781 | goto fail_cmd; |
| 1782 | } |
| 1783 | |
| 1784 | ret = wait_event_timeout(this_adm.adm_wait, |
| 1785 | atomic_read(&this_adm.adm_stat) >= 0, |
| 1786 | 5 * HZ); |
| 1787 | if (!ret) { |
| 1788 | pr_err("%s: timeout. waited for memory_unmap\n", |
| 1789 | __func__); |
| 1790 | ret = -EINVAL; |
| 1791 | goto fail_cmd; |
| 1792 | } else if (atomic_read(&this_adm.adm_stat) > 0) { |
| 1793 | pr_err("%s: DSP returned error[%s]\n", |
| 1794 | __func__, adsp_err_get_err_str( |
| 1795 | atomic_read(&this_adm.adm_stat))); |
| 1796 | ret = adsp_err_get_lnx_err_code( |
| 1797 | atomic_read(&this_adm.adm_stat)); |
| 1798 | goto fail_cmd; |
| 1799 | } else { |
| 1800 | pr_debug("%s: Unmap handle 0x%x succeeded\n", __func__, |
| 1801 | unmap_regions.mem_map_handle); |
| 1802 | } |
| 1803 | fail_cmd: |
| 1804 | return ret; |
| 1805 | } |
| 1806 | |
| 1807 | static int remap_cal_data(struct cal_block_data *cal_block, int cal_index) |
| 1808 | { |
| 1809 | int ret = 0; |
| 1810 | |
| 1811 | if (cal_block->map_data.ion_client == NULL) { |
| 1812 | pr_err("%s: No ION allocation for cal index %d!\n", |
| 1813 | __func__, cal_index); |
| 1814 | ret = -EINVAL; |
| 1815 | goto done; |
| 1816 | } |
| 1817 | |
| 1818 | if ((cal_block->map_data.map_size > 0) && |
| 1819 | (cal_block->map_data.q6map_handle == 0)) { |
| 1820 | atomic_set(&this_adm.mem_map_index, cal_index); |
| 1821 | ret = adm_memory_map_regions(&cal_block->cal_data.paddr, 0, |
| 1822 | (uint32_t *)&cal_block->map_data.map_size, 1); |
| 1823 | if (ret < 0) { |
| 1824 | pr_err("%s: ADM mmap did not work! size = %zd ret %d\n", |
| 1825 | __func__, |
| 1826 | cal_block->map_data.map_size, ret); |
| 1827 | pr_debug("%s: ADM mmap did not work! addr = 0x%pK, size = %zd ret %d\n", |
| 1828 | __func__, |
| 1829 | &cal_block->cal_data.paddr, |
| 1830 | cal_block->map_data.map_size, ret); |
| 1831 | goto done; |
| 1832 | } |
| 1833 | cal_block->map_data.q6map_handle = atomic_read(&this_adm. |
| 1834 | mem_map_handles[cal_index]); |
| 1835 | } |
| 1836 | done: |
| 1837 | return ret; |
| 1838 | } |
| 1839 | |
| 1840 | static void send_adm_custom_topology(void) |
| 1841 | { |
| 1842 | struct cal_block_data *cal_block = NULL; |
| 1843 | struct cmd_set_topologies adm_top; |
| 1844 | int cal_index = ADM_CUSTOM_TOP_CAL; |
| 1845 | int result; |
| 1846 | |
| 1847 | if (this_adm.cal_data[cal_index] == NULL) |
| 1848 | goto done; |
| 1849 | |
| 1850 | mutex_lock(&this_adm.cal_data[cal_index]->lock); |
| 1851 | if (!this_adm.set_custom_topology) |
| 1852 | goto unlock; |
| 1853 | this_adm.set_custom_topology = 0; |
| 1854 | |
| 1855 | cal_block = cal_utils_get_only_cal_block(this_adm.cal_data[cal_index]); |
Saurav Kumar | d6642ea | 2020-10-22 15:49:26 +0530 | [diff] [blame] | 1856 | if (cal_block == NULL || cal_utils_is_cal_stale(cal_block)) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1857 | goto unlock; |
| 1858 | |
| 1859 | pr_debug("%s: Sending cal_index %d\n", __func__, cal_index); |
| 1860 | |
| 1861 | result = remap_cal_data(cal_block, cal_index); |
| 1862 | if (result) { |
| 1863 | pr_err("%s: Remap_cal_data failed for cal %d!\n", |
| 1864 | __func__, cal_index); |
| 1865 | goto unlock; |
| 1866 | } |
| 1867 | atomic_set(&this_adm.mem_map_index, cal_index); |
| 1868 | atomic_set(&this_adm.mem_map_handles[cal_index], |
| 1869 | cal_block->map_data.q6map_handle); |
| 1870 | |
| 1871 | if (cal_block->cal_data.size == 0) { |
| 1872 | pr_debug("%s: No ADM cal to send\n", __func__); |
| 1873 | goto unlock; |
| 1874 | } |
| 1875 | |
| 1876 | adm_top.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1877 | APR_HDR_LEN(20), APR_PKT_VER); |
| 1878 | adm_top.hdr.pkt_size = sizeof(adm_top); |
| 1879 | adm_top.hdr.src_svc = APR_SVC_ADM; |
| 1880 | adm_top.hdr.src_domain = APR_DOMAIN_APPS; |
| 1881 | adm_top.hdr.src_port = 0; |
| 1882 | adm_top.hdr.dest_svc = APR_SVC_ADM; |
| 1883 | adm_top.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 1884 | adm_top.hdr.dest_port = 0; |
| 1885 | adm_top.hdr.token = 0; |
| 1886 | adm_top.hdr.opcode = ADM_CMD_ADD_TOPOLOGIES; |
| 1887 | adm_top.payload_addr_lsw = lower_32_bits(cal_block->cal_data.paddr); |
| 1888 | adm_top.payload_addr_msw = msm_audio_populate_upper_32_bits( |
| 1889 | cal_block->cal_data.paddr); |
| 1890 | adm_top.mem_map_handle = cal_block->map_data.q6map_handle; |
| 1891 | adm_top.payload_size = cal_block->cal_data.size; |
| 1892 | |
| 1893 | atomic_set(&this_adm.adm_stat, -1); |
| 1894 | pr_debug("%s: Sending ADM_CMD_ADD_TOPOLOGIES payload = 0x%pK, size = %d\n", |
| 1895 | __func__, &cal_block->cal_data.paddr, |
| 1896 | adm_top.payload_size); |
| 1897 | result = apr_send_pkt(this_adm.apr, (uint32_t *)&adm_top); |
| 1898 | if (result < 0) { |
| 1899 | pr_err("%s: Set topologies failed payload size = %zd result %d\n", |
| 1900 | __func__, cal_block->cal_data.size, result); |
| 1901 | goto unlock; |
| 1902 | } |
| 1903 | /* Wait for the callback */ |
| 1904 | result = wait_event_timeout(this_adm.adm_wait, |
| 1905 | atomic_read(&this_adm.adm_stat) >= 0, |
| 1906 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1907 | if (!result) { |
| 1908 | pr_err("%s: Set topologies timed out payload size = %zd\n", |
| 1909 | __func__, cal_block->cal_data.size); |
| 1910 | goto unlock; |
| 1911 | } else if (atomic_read(&this_adm.adm_stat) > 0) { |
| 1912 | pr_err("%s: DSP returned error[%s]\n", |
| 1913 | __func__, adsp_err_get_err_str( |
| 1914 | atomic_read(&this_adm.adm_stat))); |
| 1915 | result = adsp_err_get_lnx_err_code( |
| 1916 | atomic_read(&this_adm.adm_stat)); |
| 1917 | goto unlock; |
| 1918 | } |
| 1919 | unlock: |
| 1920 | mutex_unlock(&this_adm.cal_data[cal_index]->lock); |
| 1921 | done: |
| 1922 | return; |
| 1923 | } |
| 1924 | |
| 1925 | static int send_adm_cal_block(int port_id, int copp_idx, |
| 1926 | struct cal_block_data *cal_block, int perf_mode, |
| 1927 | int app_type, int acdb_id, int sample_rate) |
| 1928 | { |
| 1929 | s32 result = 0; |
| 1930 | struct adm_cmd_set_pp_params_v5 adm_params; |
| 1931 | int port_idx; |
| 1932 | |
| 1933 | pr_debug("%s: Port id 0x%x sample_rate %d ,\n", __func__, |
| 1934 | port_id, sample_rate); |
| 1935 | port_id = afe_convert_virtual_to_portid(port_id); |
| 1936 | port_idx = adm_validate_and_get_port_index(port_id); |
| 1937 | if (port_idx < 0) { |
| 1938 | pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); |
| 1939 | return -EINVAL; |
| 1940 | } |
| 1941 | if (!cal_block) { |
| 1942 | pr_debug("%s: No ADM cal to send for port_id = 0x%x!\n", |
| 1943 | __func__, port_id); |
| 1944 | result = -EINVAL; |
| 1945 | goto done; |
| 1946 | } |
| 1947 | if (cal_block->cal_data.size <= 0) { |
| 1948 | pr_debug("%s: No ADM cal send for port_id = 0x%x!\n", |
| 1949 | __func__, port_id); |
| 1950 | result = -EINVAL; |
| 1951 | goto done; |
| 1952 | } |
| 1953 | |
| 1954 | if (perf_mode == LEGACY_PCM_MODE && |
| 1955 | ((atomic_read(&this_adm.copp.topology[port_idx][copp_idx])) == |
| 1956 | DS2_ADM_COPP_TOPOLOGY_ID)) { |
| 1957 | pr_err("%s: perf_mode %d, topology 0x%x\n", __func__, perf_mode, |
| 1958 | atomic_read( |
| 1959 | &this_adm.copp.topology[port_idx][copp_idx])); |
| 1960 | goto done; |
| 1961 | } |
| 1962 | |
| 1963 | adm_params.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1964 | APR_HDR_LEN(20), APR_PKT_VER); |
| 1965 | adm_params.hdr.pkt_size = sizeof(adm_params); |
| 1966 | adm_params.hdr.src_svc = APR_SVC_ADM; |
| 1967 | adm_params.hdr.src_domain = APR_DOMAIN_APPS; |
| 1968 | adm_params.hdr.src_port = port_id; |
| 1969 | adm_params.hdr.dest_svc = APR_SVC_ADM; |
| 1970 | adm_params.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 1971 | |
| 1972 | adm_params.hdr.token = port_idx << 16 | copp_idx; |
| 1973 | adm_params.hdr.dest_port = |
| 1974 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 1975 | adm_params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; |
| 1976 | adm_params.payload_addr_lsw = lower_32_bits(cal_block->cal_data.paddr); |
| 1977 | adm_params.payload_addr_msw = msm_audio_populate_upper_32_bits( |
| 1978 | cal_block->cal_data.paddr); |
| 1979 | adm_params.mem_map_handle = cal_block->map_data.q6map_handle; |
| 1980 | adm_params.payload_size = cal_block->cal_data.size; |
| 1981 | |
| 1982 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 1983 | pr_debug("%s: Sending SET_PARAMS payload = 0x%pK, size = %d\n", |
| 1984 | __func__, &cal_block->cal_data.paddr, |
| 1985 | adm_params.payload_size); |
| 1986 | result = apr_send_pkt(this_adm.apr, (uint32_t *)&adm_params); |
| 1987 | if (result < 0) { |
| 1988 | pr_err("%s: Set params failed port 0x%x result %d\n", |
| 1989 | __func__, port_id, result); |
| 1990 | pr_debug("%s: Set params failed port = 0x%x payload = 0x%pK result %d\n", |
| 1991 | __func__, port_id, &cal_block->cal_data.paddr, result); |
| 1992 | result = -EINVAL; |
| 1993 | goto done; |
| 1994 | } |
| 1995 | /* Wait for the callback */ |
| 1996 | result = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 1997 | atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, |
| 1998 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1999 | if (!result) { |
| 2000 | pr_err("%s: Set params timed out port = 0x%x\n", |
| 2001 | __func__, port_id); |
| 2002 | pr_debug("%s: Set params timed out port = 0x%x, payload = 0x%pK\n", |
| 2003 | __func__, port_id, &cal_block->cal_data.paddr); |
| 2004 | result = -EINVAL; |
| 2005 | goto done; |
| 2006 | } else if (atomic_read(&this_adm.copp.stat |
| 2007 | [port_idx][copp_idx]) > 0) { |
| 2008 | pr_err("%s: DSP returned error[%s]\n", |
| 2009 | __func__, adsp_err_get_err_str( |
| 2010 | atomic_read(&this_adm.copp.stat |
| 2011 | [port_idx][copp_idx]))); |
| 2012 | result = adsp_err_get_lnx_err_code( |
| 2013 | atomic_read(&this_adm.copp.stat |
| 2014 | [port_idx][copp_idx])); |
| 2015 | goto done; |
| 2016 | } |
| 2017 | |
| 2018 | done: |
| 2019 | return result; |
| 2020 | } |
| 2021 | |
| 2022 | static struct cal_block_data *adm_find_cal_by_path(int cal_index, int path) |
| 2023 | { |
| 2024 | struct list_head *ptr, *next; |
| 2025 | struct cal_block_data *cal_block = NULL; |
| 2026 | struct audio_cal_info_audproc *audproc_cal_info = NULL; |
| 2027 | struct audio_cal_info_audvol *audvol_cal_info = NULL; |
| 2028 | |
| 2029 | pr_debug("%s:\n", __func__); |
| 2030 | |
| 2031 | list_for_each_safe(ptr, next, |
| 2032 | &this_adm.cal_data[cal_index]->cal_blocks) { |
| 2033 | |
| 2034 | cal_block = list_entry(ptr, |
| 2035 | struct cal_block_data, list); |
| 2036 | |
Saurav Kumar | d6642ea | 2020-10-22 15:49:26 +0530 | [diff] [blame] | 2037 | if (cal_utils_is_cal_stale(cal_block)) |
Vikram Panduranga | 284bff4 | 2017-09-27 12:17:36 -0700 | [diff] [blame] | 2038 | continue; |
| 2039 | |
Aditya Bavanari | b11ef71 | 2017-11-21 20:24:53 +0530 | [diff] [blame] | 2040 | if (cal_index == ADM_AUDPROC_CAL || |
Alexander Martinz | ad585df | 2022-03-31 09:00:00 +0200 | [diff] [blame^] | 2041 | cal_index == ADM_LSM_AUDPROC_CAL) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2042 | audproc_cal_info = cal_block->cal_info; |
| 2043 | if ((audproc_cal_info->path == path) && |
| 2044 | (cal_block->cal_data.size > 0)) |
| 2045 | return cal_block; |
| 2046 | } else if (cal_index == ADM_AUDVOL_CAL) { |
| 2047 | audvol_cal_info = cal_block->cal_info; |
| 2048 | if ((audvol_cal_info->path == path) && |
| 2049 | (cal_block->cal_data.size > 0)) |
| 2050 | return cal_block; |
| 2051 | } |
| 2052 | } |
| 2053 | pr_debug("%s: Can't find ADM cal for cal_index %d, path %d\n", |
| 2054 | __func__, cal_index, path); |
| 2055 | return NULL; |
| 2056 | } |
| 2057 | |
| 2058 | static struct cal_block_data *adm_find_cal_by_app_type(int cal_index, int path, |
| 2059 | int app_type) |
| 2060 | { |
| 2061 | struct list_head *ptr, *next; |
| 2062 | struct cal_block_data *cal_block = NULL; |
| 2063 | struct audio_cal_info_audproc *audproc_cal_info = NULL; |
| 2064 | struct audio_cal_info_audvol *audvol_cal_info = NULL; |
| 2065 | |
| 2066 | pr_debug("%s\n", __func__); |
| 2067 | |
| 2068 | list_for_each_safe(ptr, next, |
| 2069 | &this_adm.cal_data[cal_index]->cal_blocks) { |
| 2070 | |
| 2071 | cal_block = list_entry(ptr, |
| 2072 | struct cal_block_data, list); |
| 2073 | |
Saurav Kumar | d6642ea | 2020-10-22 15:49:26 +0530 | [diff] [blame] | 2074 | if (cal_utils_is_cal_stale(cal_block)) |
Vikram Panduranga | 284bff4 | 2017-09-27 12:17:36 -0700 | [diff] [blame] | 2075 | continue; |
| 2076 | |
Aditya Bavanari | b11ef71 | 2017-11-21 20:24:53 +0530 | [diff] [blame] | 2077 | if (cal_index == ADM_AUDPROC_CAL || |
Alexander Martinz | ad585df | 2022-03-31 09:00:00 +0200 | [diff] [blame^] | 2078 | cal_index == ADM_LSM_AUDPROC_CAL) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2079 | audproc_cal_info = cal_block->cal_info; |
| 2080 | if ((audproc_cal_info->path == path) && |
| 2081 | (audproc_cal_info->app_type == app_type) && |
| 2082 | (cal_block->cal_data.size > 0)) |
| 2083 | return cal_block; |
| 2084 | } else if (cal_index == ADM_AUDVOL_CAL) { |
| 2085 | audvol_cal_info = cal_block->cal_info; |
| 2086 | if ((audvol_cal_info->path == path) && |
| 2087 | (audvol_cal_info->app_type == app_type) && |
| 2088 | (cal_block->cal_data.size > 0)) |
| 2089 | return cal_block; |
| 2090 | } |
| 2091 | } |
| 2092 | pr_debug("%s: Can't find ADM cali for cal_index %d, path %d, app %d, defaulting to search by path\n", |
| 2093 | __func__, cal_index, path, app_type); |
| 2094 | return adm_find_cal_by_path(cal_index, path); |
| 2095 | } |
| 2096 | |
| 2097 | |
| 2098 | static struct cal_block_data *adm_find_cal(int cal_index, int path, |
| 2099 | int app_type, int acdb_id, |
| 2100 | int sample_rate) |
| 2101 | { |
| 2102 | struct list_head *ptr, *next; |
| 2103 | struct cal_block_data *cal_block = NULL; |
| 2104 | struct audio_cal_info_audproc *audproc_cal_info = NULL; |
| 2105 | struct audio_cal_info_audvol *audvol_cal_info = NULL; |
| 2106 | |
| 2107 | pr_debug("%s:\n", __func__); |
| 2108 | |
| 2109 | list_for_each_safe(ptr, next, |
| 2110 | &this_adm.cal_data[cal_index]->cal_blocks) { |
| 2111 | |
| 2112 | cal_block = list_entry(ptr, |
| 2113 | struct cal_block_data, list); |
Saurav Kumar | d6642ea | 2020-10-22 15:49:26 +0530 | [diff] [blame] | 2114 | if (cal_utils_is_cal_stale(cal_block)) |
Vikram Panduranga | 284bff4 | 2017-09-27 12:17:36 -0700 | [diff] [blame] | 2115 | continue; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2116 | |
Aditya Bavanari | b11ef71 | 2017-11-21 20:24:53 +0530 | [diff] [blame] | 2117 | if (cal_index == ADM_AUDPROC_CAL || |
Alexander Martinz | ad585df | 2022-03-31 09:00:00 +0200 | [diff] [blame^] | 2118 | cal_index == ADM_LSM_AUDPROC_CAL) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2119 | audproc_cal_info = cal_block->cal_info; |
| 2120 | if ((audproc_cal_info->path == path) && |
| 2121 | (audproc_cal_info->app_type == app_type) && |
| 2122 | (audproc_cal_info->acdb_id == acdb_id) && |
| 2123 | (audproc_cal_info->sample_rate == sample_rate) && |
| 2124 | (cal_block->cal_data.size > 0)) |
| 2125 | return cal_block; |
| 2126 | } else if (cal_index == ADM_AUDVOL_CAL) { |
| 2127 | audvol_cal_info = cal_block->cal_info; |
| 2128 | if ((audvol_cal_info->path == path) && |
| 2129 | (audvol_cal_info->app_type == app_type) && |
| 2130 | (audvol_cal_info->acdb_id == acdb_id) && |
| 2131 | (cal_block->cal_data.size > 0)) |
| 2132 | return cal_block; |
| 2133 | } |
| 2134 | } |
| 2135 | pr_debug("%s: Can't find ADM cal for cal_index %d, path %d, app %d, acdb_id %d sample_rate %d defaulting to search by app type\n", |
| 2136 | __func__, cal_index, path, app_type, acdb_id, sample_rate); |
| 2137 | return adm_find_cal_by_app_type(cal_index, path, app_type); |
| 2138 | } |
| 2139 | |
| 2140 | static int adm_remap_and_send_cal_block(int cal_index, int port_id, |
| 2141 | int copp_idx, struct cal_block_data *cal_block, int perf_mode, |
| 2142 | int app_type, int acdb_id, int sample_rate) |
| 2143 | { |
| 2144 | int ret = 0; |
| 2145 | |
| 2146 | pr_debug("%s: Sending cal_index cal %d\n", __func__, cal_index); |
| 2147 | ret = remap_cal_data(cal_block, cal_index); |
| 2148 | if (ret) { |
| 2149 | pr_err("%s: Remap_cal_data failed for cal %d!\n", |
| 2150 | __func__, cal_index); |
| 2151 | goto done; |
| 2152 | } |
| 2153 | ret = send_adm_cal_block(port_id, copp_idx, cal_block, perf_mode, |
| 2154 | app_type, acdb_id, sample_rate); |
| 2155 | if (ret < 0) |
| 2156 | pr_debug("%s: No cal sent for cal_index %d, port_id = 0x%x! ret %d sample_rate %d\n", |
| 2157 | __func__, cal_index, port_id, ret, sample_rate); |
| 2158 | done: |
| 2159 | return ret; |
| 2160 | } |
| 2161 | |
| 2162 | static void send_adm_cal_type(int cal_index, int path, int port_id, |
| 2163 | int copp_idx, int perf_mode, int app_type, |
| 2164 | int acdb_id, int sample_rate) |
| 2165 | { |
| 2166 | struct cal_block_data *cal_block = NULL; |
| 2167 | int ret; |
| 2168 | |
| 2169 | pr_debug("%s: cal index %d\n", __func__, cal_index); |
| 2170 | |
| 2171 | if (this_adm.cal_data[cal_index] == NULL) { |
| 2172 | pr_debug("%s: cal_index %d not allocated!\n", |
| 2173 | __func__, cal_index); |
| 2174 | goto done; |
| 2175 | } |
| 2176 | |
| 2177 | mutex_lock(&this_adm.cal_data[cal_index]->lock); |
| 2178 | cal_block = adm_find_cal(cal_index, path, app_type, acdb_id, |
| 2179 | sample_rate); |
| 2180 | if (cal_block == NULL) |
| 2181 | goto unlock; |
| 2182 | |
| 2183 | ret = adm_remap_and_send_cal_block(cal_index, port_id, copp_idx, |
| 2184 | cal_block, perf_mode, app_type, acdb_id, sample_rate); |
Vikram Panduranga | 284bff4 | 2017-09-27 12:17:36 -0700 | [diff] [blame] | 2185 | |
| 2186 | cal_utils_mark_cal_used(cal_block); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2187 | unlock: |
| 2188 | mutex_unlock(&this_adm.cal_data[cal_index]->lock); |
| 2189 | done: |
| 2190 | return; |
| 2191 | } |
| 2192 | |
| 2193 | static int get_cal_path(int path) |
| 2194 | { |
| 2195 | if (path == 0x1) |
| 2196 | return RX_DEVICE; |
| 2197 | else |
| 2198 | return TX_DEVICE; |
| 2199 | } |
| 2200 | |
| 2201 | static void send_adm_cal(int port_id, int copp_idx, int path, int perf_mode, |
Aditya Bavanari | 16b9713 | 2018-01-08 13:16:32 +0530 | [diff] [blame] | 2202 | int app_type, int acdb_id, int sample_rate, |
| 2203 | int passthr_mode) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2204 | { |
| 2205 | pr_debug("%s: port id 0x%x copp_idx %d\n", __func__, port_id, copp_idx); |
| 2206 | |
Alexander Martinz | ad585df | 2022-03-31 09:00:00 +0200 | [diff] [blame^] | 2207 | if (passthr_mode != LISTEN) |
Aditya Bavanari | b11ef71 | 2017-11-21 20:24:53 +0530 | [diff] [blame] | 2208 | send_adm_cal_type(ADM_AUDPROC_CAL, path, port_id, copp_idx, |
| 2209 | perf_mode, app_type, acdb_id, sample_rate); |
Alexander Martinz | ad585df | 2022-03-31 09:00:00 +0200 | [diff] [blame^] | 2210 | else |
Aditya Bavanari | b11ef71 | 2017-11-21 20:24:53 +0530 | [diff] [blame] | 2211 | send_adm_cal_type(ADM_LSM_AUDPROC_CAL, path, port_id, copp_idx, |
| 2212 | perf_mode, app_type, acdb_id, sample_rate); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2213 | send_adm_cal_type(ADM_AUDVOL_CAL, path, port_id, copp_idx, perf_mode, |
| 2214 | app_type, acdb_id, sample_rate); |
| 2215 | } |
| 2216 | |
| 2217 | int adm_connect_afe_port(int mode, int session_id, int port_id) |
| 2218 | { |
| 2219 | struct adm_cmd_connect_afe_port_v5 cmd; |
| 2220 | int ret = 0; |
| 2221 | int port_idx, copp_idx = 0; |
| 2222 | |
| 2223 | pr_debug("%s: port_id: 0x%x session id:%d mode:%d\n", __func__, |
| 2224 | port_id, session_id, mode); |
| 2225 | |
| 2226 | port_id = afe_convert_virtual_to_portid(port_id); |
| 2227 | port_idx = adm_validate_and_get_port_index(port_id); |
| 2228 | if (port_idx < 0) { |
| 2229 | pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); |
| 2230 | return -EINVAL; |
| 2231 | } |
| 2232 | |
| 2233 | if (this_adm.apr == NULL) { |
| 2234 | this_adm.apr = apr_register("ADSP", "ADM", adm_callback, |
| 2235 | 0xFFFFFFFF, &this_adm); |
| 2236 | if (this_adm.apr == NULL) { |
| 2237 | pr_err("%s: Unable to register ADM\n", __func__); |
| 2238 | ret = -ENODEV; |
| 2239 | return ret; |
| 2240 | } |
| 2241 | rtac_set_adm_handle(this_adm.apr); |
| 2242 | } |
| 2243 | pr_debug("%s: Port ID 0x%x, index %d\n", __func__, port_id, port_idx); |
| 2244 | |
| 2245 | cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 2246 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 2247 | cmd.hdr.pkt_size = sizeof(cmd); |
| 2248 | cmd.hdr.src_svc = APR_SVC_ADM; |
| 2249 | cmd.hdr.src_domain = APR_DOMAIN_APPS; |
| 2250 | cmd.hdr.src_port = port_id; |
| 2251 | cmd.hdr.dest_svc = APR_SVC_ADM; |
| 2252 | cmd.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 2253 | cmd.hdr.dest_port = 0; /* Ignored */ |
| 2254 | cmd.hdr.token = port_idx << 16 | copp_idx; |
| 2255 | cmd.hdr.opcode = ADM_CMD_CONNECT_AFE_PORT_V5; |
| 2256 | |
| 2257 | cmd.mode = mode; |
| 2258 | cmd.session_id = session_id; |
| 2259 | cmd.afe_port_id = port_id; |
| 2260 | |
| 2261 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 2262 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&cmd); |
| 2263 | if (ret < 0) { |
| 2264 | pr_err("%s: ADM enable for port_id: 0x%x failed ret %d\n", |
| 2265 | __func__, port_id, ret); |
| 2266 | ret = -EINVAL; |
| 2267 | goto fail_cmd; |
| 2268 | } |
| 2269 | /* Wait for the callback with copp id */ |
| 2270 | ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 2271 | atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, |
| 2272 | msecs_to_jiffies(TIMEOUT_MS)); |
| 2273 | if (!ret) { |
| 2274 | pr_err("%s: ADM connect timedout for port_id: 0x%x\n", |
| 2275 | __func__, port_id); |
| 2276 | ret = -EINVAL; |
| 2277 | goto fail_cmd; |
| 2278 | } else if (atomic_read(&this_adm.copp.stat |
| 2279 | [port_idx][copp_idx]) > 0) { |
| 2280 | pr_err("%s: DSP returned error[%s]\n", |
| 2281 | __func__, adsp_err_get_err_str( |
| 2282 | atomic_read(&this_adm.copp.stat |
| 2283 | [port_idx][copp_idx]))); |
| 2284 | ret = adsp_err_get_lnx_err_code( |
| 2285 | atomic_read(&this_adm.copp.stat |
| 2286 | [port_idx][copp_idx])); |
| 2287 | goto fail_cmd; |
| 2288 | } |
| 2289 | atomic_inc(&this_adm.copp.cnt[port_idx][copp_idx]); |
| 2290 | return 0; |
| 2291 | |
| 2292 | fail_cmd: |
| 2293 | |
| 2294 | return ret; |
| 2295 | } |
| 2296 | |
| 2297 | int adm_arrange_mch_map(struct adm_cmd_device_open_v5 *open, int path, |
| 2298 | int channel_mode) |
| 2299 | { |
| 2300 | int rc = 0, idx; |
| 2301 | |
| 2302 | memset(open->dev_channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL); |
| 2303 | switch (path) { |
| 2304 | case ADM_PATH_PLAYBACK: |
| 2305 | idx = ADM_MCH_MAP_IDX_PLAYBACK; |
| 2306 | break; |
| 2307 | case ADM_PATH_LIVE_REC: |
| 2308 | case ADM_PATH_NONLIVE_REC: |
| 2309 | idx = ADM_MCH_MAP_IDX_REC; |
| 2310 | break; |
| 2311 | default: |
| 2312 | goto non_mch_path; |
| 2313 | }; |
| 2314 | if ((open->dev_num_channel > 2) && multi_ch_maps[idx].set_channel_map) { |
| 2315 | memcpy(open->dev_channel_mapping, |
| 2316 | multi_ch_maps[idx].channel_mapping, |
| 2317 | PCM_FORMAT_MAX_NUM_CHANNEL); |
| 2318 | } else { |
| 2319 | if (channel_mode == 1) { |
| 2320 | open->dev_channel_mapping[0] = PCM_CHANNEL_FC; |
| 2321 | } else if (channel_mode == 2) { |
| 2322 | open->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2323 | open->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2324 | } else if (channel_mode == 3) { |
| 2325 | open->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2326 | open->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2327 | open->dev_channel_mapping[2] = PCM_CHANNEL_FC; |
| 2328 | } else if (channel_mode == 4) { |
| 2329 | open->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2330 | open->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2331 | open->dev_channel_mapping[2] = PCM_CHANNEL_LS; |
| 2332 | open->dev_channel_mapping[3] = PCM_CHANNEL_RS; |
| 2333 | } else if (channel_mode == 5) { |
| 2334 | open->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2335 | open->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2336 | open->dev_channel_mapping[2] = PCM_CHANNEL_FC; |
| 2337 | open->dev_channel_mapping[3] = PCM_CHANNEL_LS; |
| 2338 | open->dev_channel_mapping[4] = PCM_CHANNEL_RS; |
| 2339 | } else if (channel_mode == 6) { |
| 2340 | open->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2341 | open->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2342 | open->dev_channel_mapping[2] = PCM_CHANNEL_LFE; |
| 2343 | open->dev_channel_mapping[3] = PCM_CHANNEL_FC; |
| 2344 | open->dev_channel_mapping[4] = PCM_CHANNEL_LS; |
| 2345 | open->dev_channel_mapping[5] = PCM_CHANNEL_RS; |
| 2346 | } else if (channel_mode == 7) { |
| 2347 | open->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2348 | open->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2349 | open->dev_channel_mapping[2] = PCM_CHANNEL_FC; |
| 2350 | open->dev_channel_mapping[3] = PCM_CHANNEL_LFE; |
| 2351 | open->dev_channel_mapping[4] = PCM_CHANNEL_LB; |
| 2352 | open->dev_channel_mapping[5] = PCM_CHANNEL_RB; |
| 2353 | open->dev_channel_mapping[6] = PCM_CHANNEL_CS; |
| 2354 | } else if (channel_mode == 8) { |
| 2355 | open->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2356 | open->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2357 | open->dev_channel_mapping[2] = PCM_CHANNEL_LFE; |
| 2358 | open->dev_channel_mapping[3] = PCM_CHANNEL_FC; |
| 2359 | open->dev_channel_mapping[4] = PCM_CHANNEL_LS; |
| 2360 | open->dev_channel_mapping[5] = PCM_CHANNEL_RS; |
| 2361 | open->dev_channel_mapping[6] = PCM_CHANNEL_LB; |
| 2362 | open->dev_channel_mapping[7] = PCM_CHANNEL_RB; |
| 2363 | } else { |
| 2364 | pr_err("%s: invalid num_chan %d\n", __func__, |
| 2365 | channel_mode); |
| 2366 | rc = -EINVAL; |
| 2367 | goto inval_ch_mod; |
| 2368 | } |
| 2369 | } |
| 2370 | |
| 2371 | non_mch_path: |
| 2372 | inval_ch_mod: |
| 2373 | return rc; |
| 2374 | } |
| 2375 | |
| 2376 | int adm_arrange_mch_ep2_map(struct adm_cmd_device_open_v6 *open_v6, |
| 2377 | int channel_mode) |
| 2378 | { |
| 2379 | int rc = 0; |
| 2380 | |
| 2381 | memset(open_v6->dev_channel_mapping_eid2, 0, |
| 2382 | PCM_FORMAT_MAX_NUM_CHANNEL); |
| 2383 | |
| 2384 | if (channel_mode == 1) { |
| 2385 | open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FC; |
| 2386 | } else if (channel_mode == 2) { |
| 2387 | open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL; |
| 2388 | open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR; |
| 2389 | } else if (channel_mode == 3) { |
| 2390 | open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL; |
| 2391 | open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR; |
| 2392 | open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_FC; |
| 2393 | } else if (channel_mode == 4) { |
| 2394 | open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL; |
| 2395 | open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR; |
| 2396 | open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_LS; |
| 2397 | open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_RS; |
| 2398 | } else if (channel_mode == 5) { |
| 2399 | open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL; |
| 2400 | open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR; |
| 2401 | open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_FC; |
| 2402 | open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_LS; |
| 2403 | open_v6->dev_channel_mapping_eid2[4] = PCM_CHANNEL_RS; |
| 2404 | } else if (channel_mode == 6) { |
| 2405 | open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL; |
| 2406 | open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR; |
| 2407 | open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_LFE; |
| 2408 | open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_FC; |
| 2409 | open_v6->dev_channel_mapping_eid2[4] = PCM_CHANNEL_LS; |
| 2410 | open_v6->dev_channel_mapping_eid2[5] = PCM_CHANNEL_RS; |
| 2411 | } else if (channel_mode == 8) { |
| 2412 | open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL; |
| 2413 | open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR; |
| 2414 | open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_LFE; |
| 2415 | open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_FC; |
| 2416 | open_v6->dev_channel_mapping_eid2[4] = PCM_CHANNEL_LS; |
| 2417 | open_v6->dev_channel_mapping_eid2[5] = PCM_CHANNEL_RS; |
| 2418 | open_v6->dev_channel_mapping_eid2[6] = PCM_CHANNEL_LB; |
| 2419 | open_v6->dev_channel_mapping_eid2[7] = PCM_CHANNEL_RB; |
| 2420 | } else { |
| 2421 | pr_err("%s: invalid num_chan %d\n", __func__, |
| 2422 | channel_mode); |
| 2423 | rc = -EINVAL; |
| 2424 | } |
| 2425 | |
| 2426 | return rc; |
| 2427 | } |
| 2428 | |
| 2429 | int adm_open(int port_id, int path, int rate, int channel_mode, int topology, |
| 2430 | int perf_mode, uint16_t bit_width, int app_type, int acdb_id) |
| 2431 | { |
| 2432 | struct adm_cmd_device_open_v5 open; |
| 2433 | struct adm_cmd_device_open_v6 open_v6; |
| 2434 | int ret = 0; |
Asish Bhattacharya | 3450458 | 2017-08-08 12:55:01 +0530 | [diff] [blame] | 2435 | int port_idx, flags; |
| 2436 | int copp_idx = -1; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2437 | int tmp_port = q6audio_get_port_id(port_id); |
| 2438 | |
| 2439 | pr_debug("%s:port %#x path:%d rate:%d mode:%d perf_mode:%d,topo_id %d\n", |
| 2440 | __func__, port_id, path, rate, channel_mode, perf_mode, |
| 2441 | topology); |
| 2442 | |
| 2443 | port_id = q6audio_convert_virtual_to_portid(port_id); |
| 2444 | port_idx = adm_validate_and_get_port_index(port_id); |
| 2445 | if (port_idx < 0) { |
| 2446 | pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); |
| 2447 | return -EINVAL; |
| 2448 | } |
| 2449 | |
| 2450 | if (this_adm.apr == NULL) { |
| 2451 | this_adm.apr = apr_register("ADSP", "ADM", adm_callback, |
| 2452 | 0xFFFFFFFF, &this_adm); |
| 2453 | if (this_adm.apr == NULL) { |
| 2454 | pr_err("%s: Unable to register ADM\n", __func__); |
| 2455 | return -ENODEV; |
| 2456 | } |
| 2457 | rtac_set_adm_handle(this_adm.apr); |
| 2458 | } |
| 2459 | |
| 2460 | if (perf_mode == ULL_POST_PROCESSING_PCM_MODE) { |
| 2461 | flags = ADM_ULL_POST_PROCESSING_DEVICE_SESSION; |
| 2462 | if ((topology == DOLBY_ADM_COPP_TOPOLOGY_ID) || |
| 2463 | (topology == DS2_ADM_COPP_TOPOLOGY_ID) || |
| 2464 | (topology == SRS_TRUMEDIA_TOPOLOGY_ID)) |
| 2465 | topology = DEFAULT_COPP_TOPOLOGY; |
| 2466 | } else if (perf_mode == ULTRA_LOW_LATENCY_PCM_MODE) { |
| 2467 | flags = ADM_ULTRA_LOW_LATENCY_DEVICE_SESSION; |
| 2468 | topology = NULL_COPP_TOPOLOGY; |
| 2469 | rate = ULL_SUPPORTED_SAMPLE_RATE; |
| 2470 | bit_width = ULL_SUPPORTED_BITS_PER_SAMPLE; |
| 2471 | } else if (perf_mode == LOW_LATENCY_PCM_MODE) { |
| 2472 | flags = ADM_LOW_LATENCY_DEVICE_SESSION; |
| 2473 | if ((topology == DOLBY_ADM_COPP_TOPOLOGY_ID) || |
| 2474 | (topology == DS2_ADM_COPP_TOPOLOGY_ID) || |
| 2475 | (topology == SRS_TRUMEDIA_TOPOLOGY_ID)) |
| 2476 | topology = DEFAULT_COPP_TOPOLOGY; |
| 2477 | } else { |
| 2478 | if ((path == ADM_PATH_COMPRESSED_RX) || |
| 2479 | (path == ADM_PATH_COMPRESSED_TX)) |
| 2480 | flags = 0; |
| 2481 | else |
| 2482 | flags = ADM_LEGACY_DEVICE_SESSION; |
| 2483 | } |
| 2484 | |
Laxminath Kasam | 8f7ccc2 | 2017-08-28 17:35:04 +0530 | [diff] [blame] | 2485 | if ((topology == VPM_TX_SM_ECNS_V2_COPP_TOPOLOGY) || |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2486 | (topology == VPM_TX_DM_FLUENCE_COPP_TOPOLOGY) || |
| 2487 | (topology == VPM_TX_DM_RFECNS_COPP_TOPOLOGY)) |
| 2488 | rate = 16000; |
| 2489 | |
Asish Bhattacharya | 3450458 | 2017-08-08 12:55:01 +0530 | [diff] [blame] | 2490 | /* |
| 2491 | * Routing driver reuses the same adm for streams with the same |
| 2492 | * app_type, sample_rate etc. |
| 2493 | * This isn't allowed for ULL streams as per the DSP interface |
| 2494 | */ |
| 2495 | if (perf_mode != ULTRA_LOW_LATENCY_PCM_MODE) |
| 2496 | copp_idx = adm_get_idx_if_copp_exists(port_idx, topology, |
| 2497 | perf_mode, |
| 2498 | rate, bit_width, |
| 2499 | app_type); |
| 2500 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2501 | if (copp_idx < 0) { |
| 2502 | copp_idx = adm_get_next_available_copp(port_idx); |
| 2503 | if (copp_idx >= MAX_COPPS_PER_PORT) { |
| 2504 | pr_err("%s: exceeded copp id %d\n", |
| 2505 | __func__, copp_idx); |
| 2506 | return -EINVAL; |
| 2507 | } |
| 2508 | atomic_set(&this_adm.copp.cnt[port_idx][copp_idx], 0); |
| 2509 | atomic_set(&this_adm.copp.topology[port_idx][copp_idx], |
| 2510 | topology); |
| 2511 | atomic_set(&this_adm.copp.mode[port_idx][copp_idx], |
| 2512 | perf_mode); |
| 2513 | atomic_set(&this_adm.copp.rate[port_idx][copp_idx], |
| 2514 | rate); |
| 2515 | atomic_set(&this_adm.copp.channels[port_idx][copp_idx], |
| 2516 | channel_mode); |
| 2517 | atomic_set(&this_adm.copp.bit_width[port_idx][copp_idx], |
| 2518 | bit_width); |
| 2519 | atomic_set(&this_adm.copp.app_type[port_idx][copp_idx], |
| 2520 | app_type); |
| 2521 | atomic_set(&this_adm.copp.acdb_id[port_idx][copp_idx], |
| 2522 | acdb_id); |
| 2523 | set_bit(ADM_STATUS_CALIBRATION_REQUIRED, |
| 2524 | (void *)&this_adm.copp.adm_status[port_idx][copp_idx]); |
| 2525 | if ((path != ADM_PATH_COMPRESSED_RX) && |
| 2526 | (path != ADM_PATH_COMPRESSED_TX)) |
| 2527 | send_adm_custom_topology(); |
| 2528 | } |
| 2529 | |
| 2530 | if (this_adm.copp.adm_delay[port_idx][copp_idx] && |
| 2531 | perf_mode == LEGACY_PCM_MODE) { |
| 2532 | atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx], |
| 2533 | 1); |
| 2534 | this_adm.copp.adm_delay[port_idx][copp_idx] = 0; |
| 2535 | wake_up(&this_adm.copp.adm_delay_wait[port_idx][copp_idx]); |
| 2536 | } |
| 2537 | |
| 2538 | /* Create a COPP if port id are not enabled */ |
| 2539 | if (atomic_read(&this_adm.copp.cnt[port_idx][copp_idx]) == 0) { |
| 2540 | pr_debug("%s: open ADM: port_idx: %d, copp_idx: %d\n", __func__, |
| 2541 | port_idx, copp_idx); |
| 2542 | if ((topology == SRS_TRUMEDIA_TOPOLOGY_ID) && |
| 2543 | perf_mode == LEGACY_PCM_MODE) { |
| 2544 | int res; |
| 2545 | |
| 2546 | atomic_set(&this_adm.mem_map_index, ADM_SRS_TRUMEDIA); |
| 2547 | msm_dts_srs_tm_ion_memmap(&this_adm.outband_memmap); |
| 2548 | res = adm_memory_map_regions(&this_adm.outband_memmap.paddr, 0, |
| 2549 | (uint32_t *)&this_adm.outband_memmap.size, 1); |
| 2550 | if (res < 0) { |
| 2551 | pr_err("%s: SRS adm_memory_map_regions failed ! addr = 0x%pK, size = %d\n", |
| 2552 | __func__, (void *)this_adm.outband_memmap.paddr, |
| 2553 | (uint32_t)this_adm.outband_memmap.size); |
| 2554 | } |
| 2555 | } |
| 2556 | open.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 2557 | APR_HDR_LEN(APR_HDR_SIZE), |
| 2558 | APR_PKT_VER); |
| 2559 | open.hdr.pkt_size = sizeof(open); |
| 2560 | open.hdr.src_svc = APR_SVC_ADM; |
| 2561 | open.hdr.src_domain = APR_DOMAIN_APPS; |
| 2562 | open.hdr.src_port = tmp_port; |
| 2563 | open.hdr.dest_svc = APR_SVC_ADM; |
| 2564 | open.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 2565 | open.hdr.dest_port = tmp_port; |
| 2566 | open.hdr.token = port_idx << 16 | copp_idx; |
| 2567 | open.hdr.opcode = ADM_CMD_DEVICE_OPEN_V5; |
| 2568 | open.flags = flags; |
| 2569 | open.mode_of_operation = path; |
| 2570 | open.endpoint_id_1 = tmp_port; |
| 2571 | open.endpoint_id_2 = 0xFFFF; |
| 2572 | |
| 2573 | if (this_adm.ec_ref_rx && (path != 1)) { |
| 2574 | open.endpoint_id_2 = this_adm.ec_ref_rx; |
| 2575 | this_adm.ec_ref_rx = -1; |
| 2576 | } |
| 2577 | |
| 2578 | open.topology_id = topology; |
| 2579 | |
| 2580 | open.dev_num_channel = channel_mode & 0x00FF; |
| 2581 | open.bit_width = bit_width; |
| 2582 | WARN_ON((perf_mode == ULTRA_LOW_LATENCY_PCM_MODE) && |
| 2583 | (rate != ULL_SUPPORTED_SAMPLE_RATE)); |
| 2584 | open.sample_rate = rate; |
| 2585 | |
| 2586 | ret = adm_arrange_mch_map(&open, path, channel_mode); |
| 2587 | |
| 2588 | if (ret) |
| 2589 | return ret; |
| 2590 | |
| 2591 | pr_debug("%s: port_id=0x%x rate=%d topology_id=0x%X\n", |
| 2592 | __func__, open.endpoint_id_1, open.sample_rate, |
| 2593 | open.topology_id); |
| 2594 | |
| 2595 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 2596 | |
| 2597 | if ((this_adm.num_ec_ref_rx_chans != 0) && (path != 1) && |
| 2598 | (open.endpoint_id_2 != 0xFFFF)) { |
| 2599 | memset(&open_v6, 0, |
| 2600 | sizeof(struct adm_cmd_device_open_v6)); |
| 2601 | memcpy(&open_v6, &open, |
| 2602 | sizeof(struct adm_cmd_device_open_v5)); |
| 2603 | open_v6.hdr.opcode = ADM_CMD_DEVICE_OPEN_V6; |
| 2604 | open_v6.hdr.pkt_size = sizeof(open_v6); |
| 2605 | open_v6.dev_num_channel_eid2 = |
| 2606 | this_adm.num_ec_ref_rx_chans; |
| 2607 | this_adm.num_ec_ref_rx_chans = 0; |
| 2608 | |
| 2609 | if (this_adm.ec_ref_rx_bit_width != 0) { |
| 2610 | open_v6.bit_width_eid2 = |
| 2611 | this_adm.ec_ref_rx_bit_width; |
| 2612 | this_adm.ec_ref_rx_bit_width = 0; |
| 2613 | } else { |
| 2614 | open_v6.bit_width_eid2 = bit_width; |
| 2615 | } |
| 2616 | |
| 2617 | if (this_adm.ec_ref_rx_sampling_rate != 0) { |
| 2618 | open_v6.sample_rate_eid2 = |
| 2619 | this_adm.ec_ref_rx_sampling_rate; |
| 2620 | this_adm.ec_ref_rx_sampling_rate = 0; |
| 2621 | } else { |
| 2622 | open_v6.sample_rate_eid2 = rate; |
| 2623 | } |
| 2624 | |
| 2625 | pr_debug("%s: eid2_channels=%d eid2_bit_width=%d eid2_rate=%d\n", |
| 2626 | __func__, open_v6.dev_num_channel_eid2, |
| 2627 | open_v6.bit_width_eid2, |
| 2628 | open_v6.sample_rate_eid2); |
| 2629 | |
| 2630 | ret = adm_arrange_mch_ep2_map(&open_v6, |
| 2631 | open_v6.dev_num_channel_eid2); |
| 2632 | |
| 2633 | if (ret) |
| 2634 | return ret; |
| 2635 | |
| 2636 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&open_v6); |
| 2637 | } else { |
| 2638 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&open); |
| 2639 | } |
| 2640 | if (ret < 0) { |
| 2641 | pr_err("%s: port_id: 0x%x for[0x%x] failed %d\n", |
| 2642 | __func__, tmp_port, port_id, ret); |
| 2643 | return -EINVAL; |
| 2644 | } |
| 2645 | /* Wait for the callback with copp id */ |
| 2646 | ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 2647 | atomic_read(&this_adm.copp.stat |
| 2648 | [port_idx][copp_idx]) >= 0, |
| 2649 | msecs_to_jiffies(TIMEOUT_MS)); |
| 2650 | if (!ret) { |
| 2651 | pr_err("%s: ADM open timedout for port_id: 0x%x for [0x%x]\n", |
| 2652 | __func__, tmp_port, port_id); |
| 2653 | return -EINVAL; |
| 2654 | } else if (atomic_read(&this_adm.copp.stat |
| 2655 | [port_idx][copp_idx]) > 0) { |
| 2656 | pr_err("%s: DSP returned error[%s]\n", |
| 2657 | __func__, adsp_err_get_err_str( |
| 2658 | atomic_read(&this_adm.copp.stat |
| 2659 | [port_idx][copp_idx]))); |
| 2660 | return adsp_err_get_lnx_err_code( |
| 2661 | atomic_read(&this_adm.copp.stat |
| 2662 | [port_idx][copp_idx])); |
| 2663 | } |
| 2664 | } |
| 2665 | atomic_inc(&this_adm.copp.cnt[port_idx][copp_idx]); |
| 2666 | return copp_idx; |
| 2667 | } |
| 2668 | |
| 2669 | void adm_copp_mfc_cfg(int port_id, int copp_idx, int dst_sample_rate) |
| 2670 | { |
| 2671 | struct audproc_mfc_output_media_fmt mfc_cfg; |
| 2672 | struct adm_cmd_device_open_v5 open; |
| 2673 | int port_idx; |
| 2674 | int sz = 0; |
| 2675 | int rc = 0; |
| 2676 | int i = 0; |
| 2677 | |
| 2678 | port_id = q6audio_convert_virtual_to_portid(port_id); |
| 2679 | port_idx = adm_validate_and_get_port_index(port_id); |
| 2680 | |
| 2681 | if (port_idx < 0) { |
| 2682 | pr_err("%s: Invalid port_id %#x\n", __func__, port_id); |
| 2683 | goto fail_cmd; |
| 2684 | } |
| 2685 | |
| 2686 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 2687 | pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); |
| 2688 | goto fail_cmd; |
| 2689 | } |
| 2690 | |
| 2691 | sz = sizeof(struct audproc_mfc_output_media_fmt); |
| 2692 | |
| 2693 | mfc_cfg.params.hdr.hdr_field = |
| 2694 | APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 2695 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 2696 | mfc_cfg.params.hdr.pkt_size = sz; |
| 2697 | mfc_cfg.params.hdr.src_svc = APR_SVC_ADM; |
| 2698 | mfc_cfg.params.hdr.src_domain = APR_DOMAIN_APPS; |
| 2699 | mfc_cfg.params.hdr.src_port = port_id; |
| 2700 | mfc_cfg.params.hdr.dest_svc = APR_SVC_ADM; |
| 2701 | mfc_cfg.params.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 2702 | mfc_cfg.params.hdr.dest_port = |
| 2703 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 2704 | mfc_cfg.params.hdr.token = port_idx << 16 | copp_idx; |
| 2705 | mfc_cfg.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; |
| 2706 | mfc_cfg.params.payload_addr_lsw = 0; |
| 2707 | mfc_cfg.params.payload_addr_msw = 0; |
| 2708 | mfc_cfg.params.mem_map_handle = 0; |
| 2709 | mfc_cfg.params.payload_size = sizeof(mfc_cfg) - |
| 2710 | sizeof(mfc_cfg.params); |
| 2711 | mfc_cfg.data.module_id = AUDPROC_MODULE_ID_MFC; |
| 2712 | mfc_cfg.data.param_id = |
| 2713 | AUDPROC_PARAM_ID_MFC_OUTPUT_MEDIA_FORMAT; |
| 2714 | mfc_cfg.data.param_size = mfc_cfg.params.payload_size - |
| 2715 | sizeof(mfc_cfg.data); |
| 2716 | mfc_cfg.data.reserved = 0; |
| 2717 | mfc_cfg.sampling_rate = dst_sample_rate; |
| 2718 | mfc_cfg.bits_per_sample = |
| 2719 | atomic_read(&this_adm.copp.bit_width[port_idx][copp_idx]); |
| 2720 | open.dev_num_channel = mfc_cfg.num_channels = |
| 2721 | atomic_read(&this_adm.copp.channels[port_idx][copp_idx]); |
| 2722 | |
| 2723 | rc = adm_arrange_mch_map(&open, ADM_PATH_PLAYBACK, |
| 2724 | mfc_cfg.num_channels); |
| 2725 | if (rc < 0) { |
| 2726 | pr_err("%s: unable to get channal map\n", __func__); |
| 2727 | goto fail_cmd; |
| 2728 | } |
| 2729 | |
| 2730 | for (i = 0; i < mfc_cfg.num_channels; i++) |
| 2731 | mfc_cfg.channel_type[i] = |
| 2732 | (uint16_t) open.dev_channel_mapping[i]; |
| 2733 | |
| 2734 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 2735 | |
| 2736 | pr_debug("%s: mfc config: port_idx %d copp_idx %d copp SR %d copp BW %d copp chan %d o/p SR %d\n", |
| 2737 | __func__, port_idx, copp_idx, |
| 2738 | atomic_read(&this_adm.copp.rate[port_idx][copp_idx]), |
| 2739 | mfc_cfg.bits_per_sample, mfc_cfg.num_channels, |
| 2740 | mfc_cfg.sampling_rate); |
| 2741 | |
| 2742 | rc = apr_send_pkt(this_adm.apr, (uint32_t *)&mfc_cfg); |
| 2743 | |
| 2744 | if (rc < 0) { |
| 2745 | pr_err("%s: port_id: for[0x%x] failed %d\n", |
| 2746 | __func__, port_id, rc); |
| 2747 | goto fail_cmd; |
| 2748 | } |
| 2749 | /* Wait for the callback with copp id */ |
| 2750 | rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 2751 | atomic_read(&this_adm.copp.stat |
| 2752 | [port_idx][copp_idx]) >= 0, |
| 2753 | msecs_to_jiffies(TIMEOUT_MS)); |
| 2754 | if (!rc) { |
| 2755 | pr_err("%s: mfc_cfg Set params timed out for port_id: for [0x%x]\n", |
| 2756 | __func__, port_id); |
| 2757 | goto fail_cmd; |
| 2758 | } else if (atomic_read(&this_adm.copp.stat |
| 2759 | [port_idx][copp_idx]) > 0) { |
| 2760 | pr_err("%s: DSP returned error[%s]\n", |
| 2761 | __func__, adsp_err_get_err_str( |
| 2762 | atomic_read(&this_adm.copp.stat |
| 2763 | [port_idx][copp_idx]))); |
| 2764 | goto fail_cmd; |
| 2765 | } |
| 2766 | rc = 0; |
| 2767 | fail_cmd: |
| 2768 | return; |
| 2769 | } |
| 2770 | |
| 2771 | static void route_set_opcode_matrix_id( |
| 2772 | struct adm_cmd_matrix_map_routings_v5 **route_addr, |
| 2773 | int path, uint32_t passthr_mode) |
| 2774 | { |
| 2775 | struct adm_cmd_matrix_map_routings_v5 *route = *route_addr; |
| 2776 | |
| 2777 | switch (path) { |
| 2778 | case ADM_PATH_PLAYBACK: |
| 2779 | route->hdr.opcode = ADM_CMD_MATRIX_MAP_ROUTINGS_V5; |
| 2780 | route->matrix_id = ADM_MATRIX_ID_AUDIO_RX; |
| 2781 | break; |
| 2782 | case ADM_PATH_LIVE_REC: |
| 2783 | if (passthr_mode == LISTEN) { |
| 2784 | route->hdr.opcode = |
| 2785 | ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5; |
| 2786 | route->matrix_id = ADM_MATRIX_ID_LISTEN_TX; |
| 2787 | break; |
| 2788 | } |
| 2789 | /* fall through to set matrix id for non-listen case */ |
| 2790 | case ADM_PATH_NONLIVE_REC: |
| 2791 | route->hdr.opcode = ADM_CMD_MATRIX_MAP_ROUTINGS_V5; |
| 2792 | route->matrix_id = ADM_MATRIX_ID_AUDIO_TX; |
| 2793 | break; |
| 2794 | case ADM_PATH_COMPRESSED_RX: |
| 2795 | route->hdr.opcode = ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5; |
| 2796 | route->matrix_id = ADM_MATRIX_ID_COMPRESSED_AUDIO_RX; |
| 2797 | break; |
| 2798 | case ADM_PATH_COMPRESSED_TX: |
| 2799 | route->hdr.opcode = ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5; |
| 2800 | route->matrix_id = ADM_MATRIX_ID_COMPRESSED_AUDIO_TX; |
| 2801 | break; |
| 2802 | default: |
| 2803 | pr_err("%s: Wrong path set[%d]\n", __func__, path); |
| 2804 | break; |
| 2805 | } |
| 2806 | pr_debug("%s: opcode 0x%x, matrix id %d\n", |
| 2807 | __func__, route->hdr.opcode, route->matrix_id); |
| 2808 | } |
| 2809 | |
| 2810 | int adm_matrix_map(int path, struct route_payload payload_map, int perf_mode, |
| 2811 | uint32_t passthr_mode) |
| 2812 | { |
| 2813 | struct adm_cmd_matrix_map_routings_v5 *route; |
| 2814 | struct adm_session_map_node_v5 *node; |
| 2815 | uint16_t *copps_list; |
| 2816 | int cmd_size = 0; |
| 2817 | int ret = 0, i = 0; |
| 2818 | void *payload = NULL; |
| 2819 | void *matrix_map = NULL; |
| 2820 | int port_idx, copp_idx; |
| 2821 | |
| 2822 | /* Assumes port_ids have already been validated during adm_open */ |
| 2823 | cmd_size = (sizeof(struct adm_cmd_matrix_map_routings_v5) + |
| 2824 | sizeof(struct adm_session_map_node_v5) + |
| 2825 | (sizeof(uint32_t) * payload_map.num_copps)); |
| 2826 | matrix_map = kzalloc(cmd_size, GFP_KERNEL); |
| 2827 | if (matrix_map == NULL) { |
| 2828 | pr_err("%s: Mem alloc failed\n", __func__); |
| 2829 | ret = -EINVAL; |
| 2830 | return ret; |
| 2831 | } |
| 2832 | route = (struct adm_cmd_matrix_map_routings_v5 *)matrix_map; |
| 2833 | |
| 2834 | route->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 2835 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 2836 | route->hdr.pkt_size = cmd_size; |
| 2837 | route->hdr.src_svc = 0; |
| 2838 | route->hdr.src_domain = APR_DOMAIN_APPS; |
| 2839 | route->hdr.src_port = 0; /* Ignored */; |
| 2840 | route->hdr.dest_svc = APR_SVC_ADM; |
| 2841 | route->hdr.dest_domain = APR_DOMAIN_ADSP; |
| 2842 | route->hdr.dest_port = 0; /* Ignored */; |
| 2843 | route->hdr.token = 0; |
| 2844 | route->num_sessions = 1; |
| 2845 | route_set_opcode_matrix_id(&route, path, passthr_mode); |
| 2846 | |
| 2847 | payload = ((u8 *)matrix_map + |
| 2848 | sizeof(struct adm_cmd_matrix_map_routings_v5)); |
| 2849 | node = (struct adm_session_map_node_v5 *)payload; |
| 2850 | |
| 2851 | node->session_id = payload_map.session_id; |
| 2852 | node->num_copps = payload_map.num_copps; |
| 2853 | payload = (u8 *)node + sizeof(struct adm_session_map_node_v5); |
| 2854 | copps_list = (uint16_t *)payload; |
| 2855 | for (i = 0; i < payload_map.num_copps; i++) { |
| 2856 | port_idx = |
| 2857 | adm_validate_and_get_port_index(payload_map.port_id[i]); |
| 2858 | if (port_idx < 0) { |
| 2859 | pr_err("%s: Invalid port_id 0x%x\n", __func__, |
| 2860 | payload_map.port_id[i]); |
| 2861 | ret = -EINVAL; |
| 2862 | goto fail_cmd; |
| 2863 | } |
| 2864 | copp_idx = payload_map.copp_idx[i]; |
| 2865 | copps_list[i] = atomic_read(&this_adm.copp.id[port_idx] |
| 2866 | [copp_idx]); |
| 2867 | } |
| 2868 | atomic_set(&this_adm.matrix_map_stat, -1); |
| 2869 | |
| 2870 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)matrix_map); |
| 2871 | if (ret < 0) { |
| 2872 | pr_err("%s: routing for syream %d failed ret %d\n", |
| 2873 | __func__, payload_map.session_id, ret); |
| 2874 | ret = -EINVAL; |
| 2875 | goto fail_cmd; |
| 2876 | } |
| 2877 | ret = wait_event_timeout(this_adm.matrix_map_wait, |
| 2878 | atomic_read(&this_adm.matrix_map_stat) >= 0, |
| 2879 | msecs_to_jiffies(TIMEOUT_MS)); |
| 2880 | if (!ret) { |
| 2881 | pr_err("%s: routing for syream %d failed\n", __func__, |
| 2882 | payload_map.session_id); |
| 2883 | ret = -EINVAL; |
| 2884 | goto fail_cmd; |
| 2885 | } else if (atomic_read(&this_adm.matrix_map_stat) > 0) { |
| 2886 | pr_err("%s: DSP returned error[%s]\n", __func__, |
| 2887 | adsp_err_get_err_str(atomic_read( |
| 2888 | &this_adm.matrix_map_stat))); |
| 2889 | ret = adsp_err_get_lnx_err_code( |
| 2890 | atomic_read(&this_adm.matrix_map_stat)); |
| 2891 | goto fail_cmd; |
| 2892 | } |
| 2893 | |
| 2894 | if ((perf_mode != ULTRA_LOW_LATENCY_PCM_MODE) && |
| 2895 | (path != ADM_PATH_COMPRESSED_RX)) { |
| 2896 | for (i = 0; i < payload_map.num_copps; i++) { |
| 2897 | port_idx = afe_get_port_index(payload_map.port_id[i]); |
| 2898 | copp_idx = payload_map.copp_idx[i]; |
| 2899 | if (port_idx < 0 || copp_idx < 0 || |
| 2900 | (copp_idx > MAX_COPPS_PER_PORT - 1)) { |
| 2901 | pr_err("%s: Invalid idx port_idx %d copp_idx %d\n", |
| 2902 | __func__, port_idx, copp_idx); |
| 2903 | continue; |
| 2904 | } |
| 2905 | rtac_add_adm_device(payload_map.port_id[i], |
| 2906 | atomic_read(&this_adm.copp.id |
| 2907 | [port_idx][copp_idx]), |
| 2908 | get_cal_path(path), |
| 2909 | payload_map.session_id, |
| 2910 | payload_map.app_type[i], |
| 2911 | payload_map.acdb_dev_id[i]); |
| 2912 | |
| 2913 | if (!test_bit(ADM_STATUS_CALIBRATION_REQUIRED, |
| 2914 | (void *)&this_adm.copp.adm_status[port_idx] |
| 2915 | [copp_idx])) { |
| 2916 | pr_debug("%s: adm copp[0x%x][%d] already sent", |
| 2917 | __func__, port_idx, copp_idx); |
| 2918 | continue; |
| 2919 | } |
| 2920 | send_adm_cal(payload_map.port_id[i], copp_idx, |
| 2921 | get_cal_path(path), perf_mode, |
| 2922 | payload_map.app_type[i], |
| 2923 | payload_map.acdb_dev_id[i], |
Aditya Bavanari | 16b9713 | 2018-01-08 13:16:32 +0530 | [diff] [blame] | 2924 | payload_map.sample_rate[i], |
| 2925 | passthr_mode); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2926 | /* ADM COPP calibration is already sent */ |
| 2927 | clear_bit(ADM_STATUS_CALIBRATION_REQUIRED, |
| 2928 | (void *)&this_adm.copp. |
| 2929 | adm_status[port_idx][copp_idx]); |
| 2930 | pr_debug("%s: copp_id: %d\n", __func__, |
| 2931 | atomic_read(&this_adm.copp.id[port_idx] |
| 2932 | [copp_idx])); |
| 2933 | } |
| 2934 | } |
| 2935 | |
| 2936 | fail_cmd: |
| 2937 | kfree(matrix_map); |
| 2938 | return ret; |
| 2939 | } |
| 2940 | |
| 2941 | void adm_ec_ref_rx_id(int port_id) |
| 2942 | { |
| 2943 | this_adm.ec_ref_rx = port_id; |
| 2944 | pr_debug("%s: ec_ref_rx:%d\n", __func__, this_adm.ec_ref_rx); |
| 2945 | } |
| 2946 | |
| 2947 | void adm_num_ec_ref_rx_chans(int num_chans) |
| 2948 | { |
| 2949 | this_adm.num_ec_ref_rx_chans = num_chans; |
| 2950 | pr_debug("%s: num_ec_ref_rx_chans:%d\n", |
| 2951 | __func__, this_adm.num_ec_ref_rx_chans); |
| 2952 | } |
| 2953 | |
| 2954 | void adm_ec_ref_rx_bit_width(int bit_width) |
| 2955 | { |
| 2956 | this_adm.ec_ref_rx_bit_width = bit_width; |
| 2957 | pr_debug("%s: ec_ref_rx_bit_width:%d\n", |
| 2958 | __func__, this_adm.ec_ref_rx_bit_width); |
| 2959 | } |
| 2960 | |
| 2961 | void adm_ec_ref_rx_sampling_rate(int sampling_rate) |
| 2962 | { |
| 2963 | this_adm.ec_ref_rx_sampling_rate = sampling_rate; |
| 2964 | pr_debug("%s: ec_ref_rx_sampling_rate:%d\n", |
| 2965 | __func__, this_adm.ec_ref_rx_sampling_rate); |
| 2966 | } |
| 2967 | |
| 2968 | int adm_close(int port_id, int perf_mode, int copp_idx) |
| 2969 | { |
| 2970 | struct apr_hdr close; |
| 2971 | |
| 2972 | int ret = 0, port_idx; |
| 2973 | int copp_id = RESET_COPP_ID; |
| 2974 | |
| 2975 | pr_debug("%s: port_id=0x%x perf_mode: %d copp_idx: %d\n", __func__, |
| 2976 | port_id, perf_mode, copp_idx); |
| 2977 | |
| 2978 | port_id = q6audio_convert_virtual_to_portid(port_id); |
| 2979 | port_idx = adm_validate_and_get_port_index(port_id); |
| 2980 | if (port_idx < 0) { |
| 2981 | pr_err("%s: Invalid port_id 0x%x\n", |
| 2982 | __func__, port_id); |
| 2983 | return -EINVAL; |
| 2984 | } |
| 2985 | |
| 2986 | if ((copp_idx < 0) || (copp_idx >= MAX_COPPS_PER_PORT)) { |
| 2987 | pr_err("%s: Invalid copp idx: %d\n", __func__, copp_idx); |
| 2988 | return -EINVAL; |
| 2989 | } |
| 2990 | |
| 2991 | if (this_adm.copp.adm_delay[port_idx][copp_idx] && perf_mode |
| 2992 | == LEGACY_PCM_MODE) { |
| 2993 | atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx], |
| 2994 | 1); |
| 2995 | this_adm.copp.adm_delay[port_idx][copp_idx] = 0; |
| 2996 | wake_up(&this_adm.copp.adm_delay_wait[port_idx][copp_idx]); |
| 2997 | } |
| 2998 | |
| 2999 | atomic_dec(&this_adm.copp.cnt[port_idx][copp_idx]); |
| 3000 | if (!(atomic_read(&this_adm.copp.cnt[port_idx][copp_idx]))) { |
| 3001 | copp_id = adm_get_copp_id(port_idx, copp_idx); |
| 3002 | pr_debug("%s: Closing ADM port_idx:%d copp_idx:%d copp_id:0x%x\n", |
| 3003 | __func__, port_idx, copp_idx, copp_id); |
| 3004 | if ((!perf_mode) && (this_adm.outband_memmap.paddr != 0) && |
| 3005 | (atomic_read(&this_adm.copp.topology[port_idx][copp_idx]) == |
| 3006 | SRS_TRUMEDIA_TOPOLOGY_ID)) { |
| 3007 | atomic_set(&this_adm.mem_map_index, |
| 3008 | ADM_SRS_TRUMEDIA); |
| 3009 | ret = adm_memory_unmap_regions(); |
| 3010 | if (ret < 0) { |
| 3011 | pr_err("%s: adm mem unmmap err %d", |
| 3012 | __func__, ret); |
| 3013 | } else { |
| 3014 | atomic_set(&this_adm.mem_map_handles |
| 3015 | [ADM_SRS_TRUMEDIA], 0); |
| 3016 | } |
| 3017 | } |
| 3018 | |
| 3019 | |
| 3020 | if ((afe_get_port_type(port_id) == MSM_AFE_PORT_TYPE_TX) && |
| 3021 | this_adm.sourceTrackingData.memmap.paddr) { |
| 3022 | atomic_set(&this_adm.mem_map_index, |
| 3023 | ADM_MEM_MAP_INDEX_SOURCE_TRACKING); |
| 3024 | ret = adm_memory_unmap_regions(); |
| 3025 | if (ret < 0) { |
| 3026 | pr_err("%s: adm mem unmmap err %d", |
| 3027 | __func__, ret); |
| 3028 | } |
| 3029 | msm_audio_ion_free( |
| 3030 | this_adm.sourceTrackingData.ion_client, |
| 3031 | this_adm.sourceTrackingData.ion_handle); |
| 3032 | this_adm.sourceTrackingData.ion_client = NULL; |
| 3033 | this_adm.sourceTrackingData.ion_handle = NULL; |
| 3034 | this_adm.sourceTrackingData.memmap.size = 0; |
| 3035 | this_adm.sourceTrackingData.memmap.kvaddr = NULL; |
| 3036 | this_adm.sourceTrackingData.memmap.paddr = 0; |
| 3037 | this_adm.sourceTrackingData.apr_cmd_status = -1; |
| 3038 | atomic_set(&this_adm.mem_map_handles[ |
| 3039 | ADM_MEM_MAP_INDEX_SOURCE_TRACKING], 0); |
| 3040 | } |
| 3041 | |
| 3042 | close.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 3043 | APR_HDR_LEN(APR_HDR_SIZE), |
| 3044 | APR_PKT_VER); |
| 3045 | close.pkt_size = sizeof(close); |
| 3046 | close.src_svc = APR_SVC_ADM; |
| 3047 | close.src_domain = APR_DOMAIN_APPS; |
| 3048 | close.src_port = port_id; |
| 3049 | close.dest_svc = APR_SVC_ADM; |
| 3050 | close.dest_domain = APR_DOMAIN_ADSP; |
| 3051 | close.dest_port = copp_id; |
| 3052 | close.token = port_idx << 16 | copp_idx; |
| 3053 | close.opcode = ADM_CMD_DEVICE_CLOSE_V5; |
| 3054 | |
| 3055 | atomic_set(&this_adm.copp.id[port_idx][copp_idx], |
| 3056 | RESET_COPP_ID); |
| 3057 | atomic_set(&this_adm.copp.cnt[port_idx][copp_idx], 0); |
| 3058 | atomic_set(&this_adm.copp.topology[port_idx][copp_idx], 0); |
| 3059 | atomic_set(&this_adm.copp.mode[port_idx][copp_idx], 0); |
| 3060 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 3061 | atomic_set(&this_adm.copp.rate[port_idx][copp_idx], 0); |
| 3062 | atomic_set(&this_adm.copp.channels[port_idx][copp_idx], 0); |
| 3063 | atomic_set(&this_adm.copp.bit_width[port_idx][copp_idx], 0); |
| 3064 | atomic_set(&this_adm.copp.app_type[port_idx][copp_idx], 0); |
| 3065 | |
| 3066 | clear_bit(ADM_STATUS_CALIBRATION_REQUIRED, |
| 3067 | (void *)&this_adm.copp.adm_status[port_idx][copp_idx]); |
| 3068 | |
| 3069 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&close); |
| 3070 | if (ret < 0) { |
| 3071 | pr_err("%s: ADM close failed %d\n", __func__, ret); |
| 3072 | return -EINVAL; |
| 3073 | } |
| 3074 | |
| 3075 | ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 3076 | atomic_read(&this_adm.copp.stat |
| 3077 | [port_idx][copp_idx]) >= 0, |
| 3078 | msecs_to_jiffies(TIMEOUT_MS)); |
| 3079 | if (!ret) { |
| 3080 | pr_err("%s: ADM cmd Route timedout for port 0x%x\n", |
| 3081 | __func__, port_id); |
| 3082 | return -EINVAL; |
| 3083 | } else if (atomic_read(&this_adm.copp.stat |
| 3084 | [port_idx][copp_idx]) > 0) { |
| 3085 | pr_err("%s: DSP returned error[%s]\n", |
| 3086 | __func__, adsp_err_get_err_str( |
| 3087 | atomic_read(&this_adm.copp.stat |
| 3088 | [port_idx][copp_idx]))); |
| 3089 | return adsp_err_get_lnx_err_code( |
| 3090 | atomic_read(&this_adm.copp.stat |
| 3091 | [port_idx][copp_idx])); |
| 3092 | } |
| 3093 | } |
| 3094 | |
| 3095 | if (perf_mode != ULTRA_LOW_LATENCY_PCM_MODE) { |
| 3096 | pr_debug("%s: remove adm device from rtac\n", __func__); |
| 3097 | rtac_remove_adm_device(port_id, copp_id); |
| 3098 | } |
| 3099 | return 0; |
| 3100 | } |
| 3101 | |
| 3102 | int send_rtac_audvol_cal(void) |
| 3103 | { |
| 3104 | int ret = 0; |
| 3105 | int ret2 = 0; |
| 3106 | int i = 0; |
| 3107 | int copp_idx, port_idx, acdb_id, app_id, path; |
| 3108 | struct cal_block_data *cal_block = NULL; |
| 3109 | struct audio_cal_info_audvol *audvol_cal_info = NULL; |
| 3110 | struct rtac_adm rtac_adm_data; |
| 3111 | |
| 3112 | mutex_lock(&this_adm.cal_data[ADM_RTAC_AUDVOL_CAL]->lock); |
| 3113 | |
| 3114 | cal_block = cal_utils_get_only_cal_block( |
| 3115 | this_adm.cal_data[ADM_RTAC_AUDVOL_CAL]); |
Saurav Kumar | d6642ea | 2020-10-22 15:49:26 +0530 | [diff] [blame] | 3116 | if (cal_block == NULL || cal_utils_is_cal_stale(cal_block)) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3117 | pr_err("%s: can't find cal block!\n", __func__); |
| 3118 | goto unlock; |
| 3119 | } |
| 3120 | |
| 3121 | audvol_cal_info = cal_block->cal_info; |
| 3122 | if (audvol_cal_info == NULL) { |
| 3123 | pr_err("%s: audvol_cal_info is NULL!\n", __func__); |
| 3124 | goto unlock; |
| 3125 | } |
| 3126 | |
| 3127 | get_rtac_adm_data(&rtac_adm_data); |
| 3128 | for (; i < rtac_adm_data.num_of_dev; i++) { |
| 3129 | |
| 3130 | acdb_id = rtac_adm_data.device[i].acdb_dev_id; |
| 3131 | if (acdb_id == 0) |
| 3132 | acdb_id = audvol_cal_info->acdb_id; |
| 3133 | |
| 3134 | app_id = rtac_adm_data.device[i].app_type; |
| 3135 | if (app_id == 0) |
| 3136 | app_id = audvol_cal_info->app_type; |
| 3137 | |
| 3138 | path = afe_get_port_type(rtac_adm_data.device[i].afe_port); |
| 3139 | if ((acdb_id == audvol_cal_info->acdb_id) && |
| 3140 | (app_id == audvol_cal_info->app_type) && |
| 3141 | (path == audvol_cal_info->path)) { |
| 3142 | |
| 3143 | if (adm_get_indexes_from_copp_id(rtac_adm_data. |
| 3144 | device[i].copp, &copp_idx, &port_idx) != 0) { |
| 3145 | pr_debug("%s: Copp Id %d is not active\n", |
| 3146 | __func__, |
| 3147 | rtac_adm_data.device[i].copp); |
| 3148 | continue; |
| 3149 | } |
| 3150 | |
| 3151 | ret2 = adm_remap_and_send_cal_block(ADM_RTAC_AUDVOL_CAL, |
| 3152 | rtac_adm_data.device[i].afe_port, |
| 3153 | copp_idx, cal_block, |
| 3154 | atomic_read(&this_adm.copp. |
| 3155 | mode[port_idx][copp_idx]), |
| 3156 | audvol_cal_info->app_type, |
| 3157 | audvol_cal_info->acdb_id, |
| 3158 | atomic_read(&this_adm.copp. |
| 3159 | rate[port_idx][copp_idx])); |
| 3160 | if (ret2 < 0) { |
| 3161 | pr_debug("%s: remap and send failed for copp Id %d, acdb id %d, app type %d, path %d\n", |
| 3162 | __func__, rtac_adm_data.device[i].copp, |
| 3163 | audvol_cal_info->acdb_id, |
| 3164 | audvol_cal_info->app_type, |
| 3165 | audvol_cal_info->path); |
| 3166 | ret = ret2; |
| 3167 | } |
| 3168 | } |
| 3169 | } |
| 3170 | unlock: |
| 3171 | mutex_unlock(&this_adm.cal_data[ADM_RTAC_AUDVOL_CAL]->lock); |
| 3172 | return ret; |
| 3173 | } |
| 3174 | |
| 3175 | int adm_map_rtac_block(struct rtac_cal_block_data *cal_block) |
| 3176 | { |
| 3177 | int result = 0; |
| 3178 | |
| 3179 | pr_debug("%s:\n", __func__); |
| 3180 | |
| 3181 | if (cal_block == NULL) { |
| 3182 | pr_err("%s: cal_block is NULL!\n", |
| 3183 | __func__); |
| 3184 | result = -EINVAL; |
| 3185 | goto done; |
| 3186 | } |
| 3187 | |
| 3188 | if (cal_block->cal_data.paddr == 0) { |
| 3189 | pr_debug("%s: No address to map!\n", |
| 3190 | __func__); |
| 3191 | result = -EINVAL; |
| 3192 | goto done; |
| 3193 | } |
| 3194 | |
| 3195 | if (cal_block->map_data.map_size == 0) { |
| 3196 | pr_debug("%s: map size is 0!\n", |
| 3197 | __func__); |
| 3198 | result = -EINVAL; |
| 3199 | goto done; |
| 3200 | } |
| 3201 | |
| 3202 | /* valid port ID needed for callback use primary I2S */ |
| 3203 | atomic_set(&this_adm.mem_map_index, ADM_RTAC_APR_CAL); |
| 3204 | result = adm_memory_map_regions(&cal_block->cal_data.paddr, 0, |
| 3205 | &cal_block->map_data.map_size, 1); |
| 3206 | if (result < 0) { |
| 3207 | pr_err("%s: RTAC mmap did not work! size = %d result %d\n", |
| 3208 | __func__, |
| 3209 | cal_block->map_data.map_size, result); |
| 3210 | pr_debug("%s: RTAC mmap did not work! addr = 0x%pK, size = %d\n", |
| 3211 | __func__, |
| 3212 | &cal_block->cal_data.paddr, |
| 3213 | cal_block->map_data.map_size); |
| 3214 | goto done; |
| 3215 | } |
| 3216 | |
| 3217 | cal_block->map_data.map_handle = atomic_read( |
| 3218 | &this_adm.mem_map_handles[ADM_RTAC_APR_CAL]); |
| 3219 | done: |
| 3220 | return result; |
| 3221 | } |
| 3222 | |
| 3223 | int adm_unmap_rtac_block(uint32_t *mem_map_handle) |
| 3224 | { |
| 3225 | int result = 0; |
| 3226 | |
| 3227 | pr_debug("%s:\n", __func__); |
| 3228 | |
| 3229 | if (mem_map_handle == NULL) { |
| 3230 | pr_debug("%s: Map handle is NULL, nothing to unmap\n", |
| 3231 | __func__); |
| 3232 | goto done; |
| 3233 | } |
| 3234 | |
| 3235 | if (*mem_map_handle == 0) { |
| 3236 | pr_debug("%s: Map handle is 0, nothing to unmap\n", |
| 3237 | __func__); |
| 3238 | goto done; |
| 3239 | } |
| 3240 | |
| 3241 | if (*mem_map_handle != atomic_read( |
| 3242 | &this_adm.mem_map_handles[ADM_RTAC_APR_CAL])) { |
| 3243 | pr_err("%s: Map handles do not match! Unmapping RTAC, RTAC map 0x%x, ADM map 0x%x\n", |
| 3244 | __func__, *mem_map_handle, atomic_read( |
| 3245 | &this_adm.mem_map_handles[ADM_RTAC_APR_CAL])); |
| 3246 | |
| 3247 | /* if mismatch use handle passed in to unmap */ |
| 3248 | atomic_set(&this_adm.mem_map_handles[ADM_RTAC_APR_CAL], |
| 3249 | *mem_map_handle); |
| 3250 | } |
| 3251 | |
| 3252 | /* valid port ID needed for callback use primary I2S */ |
| 3253 | atomic_set(&this_adm.mem_map_index, ADM_RTAC_APR_CAL); |
| 3254 | result = adm_memory_unmap_regions(); |
| 3255 | if (result < 0) { |
| 3256 | pr_debug("%s: adm_memory_unmap_regions failed, error %d\n", |
| 3257 | __func__, result); |
| 3258 | } else { |
| 3259 | atomic_set(&this_adm.mem_map_handles[ADM_RTAC_APR_CAL], 0); |
| 3260 | *mem_map_handle = 0; |
| 3261 | } |
| 3262 | done: |
| 3263 | return result; |
| 3264 | } |
| 3265 | |
| 3266 | static int get_cal_type_index(int32_t cal_type) |
| 3267 | { |
| 3268 | int ret = -EINVAL; |
| 3269 | |
| 3270 | switch (cal_type) { |
| 3271 | case ADM_AUDPROC_CAL_TYPE: |
| 3272 | ret = ADM_AUDPROC_CAL; |
| 3273 | break; |
Aditya Bavanari | b11ef71 | 2017-11-21 20:24:53 +0530 | [diff] [blame] | 3274 | case ADM_LSM_AUDPROC_CAL_TYPE: |
| 3275 | ret = ADM_LSM_AUDPROC_CAL; |
| 3276 | break; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3277 | case ADM_AUDVOL_CAL_TYPE: |
| 3278 | ret = ADM_AUDVOL_CAL; |
| 3279 | break; |
| 3280 | case ADM_CUST_TOPOLOGY_CAL_TYPE: |
| 3281 | ret = ADM_CUSTOM_TOP_CAL; |
| 3282 | break; |
| 3283 | case ADM_RTAC_INFO_CAL_TYPE: |
| 3284 | ret = ADM_RTAC_INFO_CAL; |
| 3285 | break; |
| 3286 | case ADM_RTAC_APR_CAL_TYPE: |
| 3287 | ret = ADM_RTAC_APR_CAL; |
| 3288 | break; |
| 3289 | case ADM_RTAC_AUDVOL_CAL_TYPE: |
| 3290 | ret = ADM_RTAC_AUDVOL_CAL; |
| 3291 | break; |
| 3292 | default: |
| 3293 | pr_err("%s: invalid cal type %d!\n", __func__, cal_type); |
| 3294 | } |
| 3295 | return ret; |
| 3296 | } |
| 3297 | |
| 3298 | static int adm_alloc_cal(int32_t cal_type, size_t data_size, void *data) |
| 3299 | { |
| 3300 | int ret = 0; |
| 3301 | int cal_index; |
| 3302 | |
| 3303 | pr_debug("%s:\n", __func__); |
| 3304 | |
| 3305 | cal_index = get_cal_type_index(cal_type); |
| 3306 | if (cal_index < 0) { |
| 3307 | pr_err("%s: could not get cal index %d!\n", |
| 3308 | __func__, cal_index); |
| 3309 | ret = -EINVAL; |
| 3310 | goto done; |
| 3311 | } |
| 3312 | |
| 3313 | ret = cal_utils_alloc_cal(data_size, data, |
| 3314 | this_adm.cal_data[cal_index], 0, NULL); |
| 3315 | if (ret < 0) { |
| 3316 | pr_err("%s: cal_utils_alloc_block failed, ret = %d, cal type = %d!\n", |
| 3317 | __func__, ret, cal_type); |
| 3318 | ret = -EINVAL; |
| 3319 | goto done; |
| 3320 | } |
| 3321 | done: |
| 3322 | return ret; |
| 3323 | } |
| 3324 | |
| 3325 | static int adm_dealloc_cal(int32_t cal_type, size_t data_size, void *data) |
| 3326 | { |
| 3327 | int ret = 0; |
| 3328 | int cal_index; |
| 3329 | |
| 3330 | pr_debug("%s:\n", __func__); |
| 3331 | |
| 3332 | cal_index = get_cal_type_index(cal_type); |
| 3333 | if (cal_index < 0) { |
| 3334 | pr_err("%s: could not get cal index %d!\n", |
| 3335 | __func__, cal_index); |
| 3336 | ret = -EINVAL; |
| 3337 | goto done; |
| 3338 | } |
| 3339 | |
| 3340 | ret = cal_utils_dealloc_cal(data_size, data, |
| 3341 | this_adm.cal_data[cal_index]); |
| 3342 | if (ret < 0) { |
| 3343 | pr_err("%s: cal_utils_dealloc_block failed, ret = %d, cal type = %d!\n", |
| 3344 | __func__, ret, cal_type); |
| 3345 | ret = -EINVAL; |
| 3346 | goto done; |
| 3347 | } |
| 3348 | done: |
| 3349 | return ret; |
| 3350 | } |
| 3351 | |
| 3352 | static int adm_set_cal(int32_t cal_type, size_t data_size, void *data) |
| 3353 | { |
| 3354 | int ret = 0; |
| 3355 | int cal_index; |
| 3356 | |
| 3357 | pr_debug("%s:\n", __func__); |
| 3358 | |
| 3359 | cal_index = get_cal_type_index(cal_type); |
| 3360 | if (cal_index < 0) { |
| 3361 | pr_err("%s: could not get cal index %d!\n", |
| 3362 | __func__, cal_index); |
| 3363 | ret = -EINVAL; |
| 3364 | goto done; |
| 3365 | } |
| 3366 | |
| 3367 | ret = cal_utils_set_cal(data_size, data, |
| 3368 | this_adm.cal_data[cal_index], 0, NULL); |
| 3369 | if (ret < 0) { |
| 3370 | pr_err("%s: cal_utils_set_cal failed, ret = %d, cal type = %d!\n", |
| 3371 | __func__, ret, cal_type); |
| 3372 | ret = -EINVAL; |
| 3373 | goto done; |
| 3374 | } |
| 3375 | |
| 3376 | if (cal_index == ADM_CUSTOM_TOP_CAL) { |
| 3377 | mutex_lock(&this_adm.cal_data[ADM_CUSTOM_TOP_CAL]->lock); |
| 3378 | this_adm.set_custom_topology = 1; |
| 3379 | mutex_unlock(&this_adm.cal_data[ADM_CUSTOM_TOP_CAL]->lock); |
| 3380 | } else if (cal_index == ADM_RTAC_AUDVOL_CAL) { |
| 3381 | send_rtac_audvol_cal(); |
| 3382 | } |
| 3383 | done: |
| 3384 | return ret; |
| 3385 | } |
| 3386 | |
| 3387 | static int adm_map_cal_data(int32_t cal_type, |
| 3388 | struct cal_block_data *cal_block) |
| 3389 | { |
| 3390 | int ret = 0; |
| 3391 | int cal_index; |
| 3392 | |
| 3393 | pr_debug("%s:\n", __func__); |
| 3394 | |
| 3395 | cal_index = get_cal_type_index(cal_type); |
| 3396 | if (cal_index < 0) { |
| 3397 | pr_err("%s: could not get cal index %d!\n", |
| 3398 | __func__, cal_index); |
| 3399 | ret = -EINVAL; |
| 3400 | goto done; |
| 3401 | } |
| 3402 | |
| 3403 | atomic_set(&this_adm.mem_map_index, cal_index); |
| 3404 | ret = adm_memory_map_regions(&cal_block->cal_data.paddr, 0, |
| 3405 | (uint32_t *)&cal_block->map_data.map_size, 1); |
| 3406 | if (ret < 0) { |
| 3407 | pr_err("%s: map did not work! cal_type %i ret %d\n", |
| 3408 | __func__, cal_index, ret); |
| 3409 | ret = -ENODEV; |
| 3410 | goto done; |
| 3411 | } |
| 3412 | cal_block->map_data.q6map_handle = atomic_read(&this_adm. |
| 3413 | mem_map_handles[cal_index]); |
| 3414 | done: |
| 3415 | return ret; |
| 3416 | } |
| 3417 | |
| 3418 | static int adm_unmap_cal_data(int32_t cal_type, |
| 3419 | struct cal_block_data *cal_block) |
| 3420 | { |
| 3421 | int ret = 0; |
| 3422 | int cal_index; |
| 3423 | |
| 3424 | pr_debug("%s:\n", __func__); |
| 3425 | |
| 3426 | cal_index = get_cal_type_index(cal_type); |
| 3427 | if (cal_index < 0) { |
| 3428 | pr_err("%s: could not get cal index %d!\n", |
| 3429 | __func__, cal_index); |
| 3430 | ret = -EINVAL; |
| 3431 | goto done; |
| 3432 | } |
| 3433 | |
| 3434 | if (cal_block == NULL) { |
| 3435 | pr_err("%s: Cal block is NULL!\n", |
| 3436 | __func__); |
| 3437 | goto done; |
| 3438 | } |
| 3439 | |
| 3440 | if (cal_block->map_data.q6map_handle == 0) { |
| 3441 | pr_err("%s: Map handle is NULL, nothing to unmap\n", |
| 3442 | __func__); |
| 3443 | goto done; |
| 3444 | } |
| 3445 | |
| 3446 | atomic_set(&this_adm.mem_map_handles[cal_index], |
| 3447 | cal_block->map_data.q6map_handle); |
| 3448 | atomic_set(&this_adm.mem_map_index, cal_index); |
| 3449 | ret = adm_memory_unmap_regions(); |
| 3450 | if (ret < 0) { |
| 3451 | pr_err("%s: unmap did not work! cal_type %i ret %d\n", |
| 3452 | __func__, cal_index, ret); |
| 3453 | ret = -ENODEV; |
| 3454 | goto done; |
| 3455 | } |
| 3456 | cal_block->map_data.q6map_handle = 0; |
| 3457 | done: |
| 3458 | return ret; |
| 3459 | } |
| 3460 | |
| 3461 | static void adm_delete_cal_data(void) |
| 3462 | { |
| 3463 | pr_debug("%s:\n", __func__); |
| 3464 | |
| 3465 | cal_utils_destroy_cal_types(ADM_MAX_CAL_TYPES, this_adm.cal_data); |
| 3466 | } |
| 3467 | |
| 3468 | static int adm_init_cal_data(void) |
| 3469 | { |
| 3470 | int ret = 0; |
| 3471 | struct cal_type_info cal_type_info[] = { |
| 3472 | {{ADM_CUST_TOPOLOGY_CAL_TYPE, |
| 3473 | {adm_alloc_cal, adm_dealloc_cal, NULL, |
| 3474 | adm_set_cal, NULL, NULL} }, |
| 3475 | {adm_map_cal_data, adm_unmap_cal_data, |
| 3476 | cal_utils_match_buf_num} }, |
| 3477 | |
| 3478 | {{ADM_AUDPROC_CAL_TYPE, |
| 3479 | {adm_alloc_cal, adm_dealloc_cal, NULL, |
| 3480 | adm_set_cal, NULL, NULL} }, |
| 3481 | {adm_map_cal_data, adm_unmap_cal_data, |
| 3482 | cal_utils_match_buf_num} }, |
| 3483 | |
Aditya Bavanari | b11ef71 | 2017-11-21 20:24:53 +0530 | [diff] [blame] | 3484 | {{ADM_LSM_AUDPROC_CAL_TYPE, |
| 3485 | {adm_alloc_cal, adm_dealloc_cal, NULL, |
| 3486 | adm_set_cal, NULL, NULL} }, |
| 3487 | {adm_map_cal_data, adm_unmap_cal_data, |
| 3488 | cal_utils_match_buf_num} }, |
| 3489 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3490 | {{ADM_AUDVOL_CAL_TYPE, |
| 3491 | {adm_alloc_cal, adm_dealloc_cal, NULL, |
| 3492 | adm_set_cal, NULL, NULL} }, |
| 3493 | {adm_map_cal_data, adm_unmap_cal_data, |
| 3494 | cal_utils_match_buf_num} }, |
| 3495 | |
| 3496 | {{ADM_RTAC_INFO_CAL_TYPE, |
| 3497 | {NULL, NULL, NULL, NULL, NULL, NULL} }, |
| 3498 | {NULL, NULL, cal_utils_match_buf_num} }, |
| 3499 | |
| 3500 | {{ADM_RTAC_APR_CAL_TYPE, |
| 3501 | {NULL, NULL, NULL, NULL, NULL, NULL} }, |
| 3502 | {NULL, NULL, cal_utils_match_buf_num} }, |
| 3503 | |
| 3504 | {{SRS_TRUMEDIA_CAL_TYPE, |
| 3505 | {NULL, NULL, NULL, NULL, NULL, NULL} }, |
| 3506 | {NULL, NULL, cal_utils_match_buf_num} }, |
| 3507 | |
| 3508 | {{ADM_RTAC_AUDVOL_CAL_TYPE, |
| 3509 | {adm_alloc_cal, adm_dealloc_cal, NULL, |
| 3510 | adm_set_cal, NULL, NULL} }, |
| 3511 | {adm_map_cal_data, adm_unmap_cal_data, |
| 3512 | cal_utils_match_buf_num} }, |
| 3513 | }; |
| 3514 | pr_debug("%s:\n", __func__); |
| 3515 | |
| 3516 | ret = cal_utils_create_cal_types(ADM_MAX_CAL_TYPES, this_adm.cal_data, |
| 3517 | cal_type_info); |
| 3518 | if (ret < 0) { |
| 3519 | pr_err("%s: could not create cal type! ret %d\n", |
| 3520 | __func__, ret); |
| 3521 | ret = -EINVAL; |
| 3522 | goto err; |
| 3523 | } |
| 3524 | |
| 3525 | return ret; |
| 3526 | err: |
| 3527 | adm_delete_cal_data(); |
| 3528 | return ret; |
| 3529 | } |
| 3530 | |
| 3531 | int adm_set_volume(int port_id, int copp_idx, int volume) |
| 3532 | { |
| 3533 | struct audproc_volume_ctrl_master_gain audproc_vol; |
| 3534 | int sz = 0; |
| 3535 | int rc = 0; |
| 3536 | int port_idx; |
| 3537 | |
| 3538 | pr_debug("%s: port_id %d, volume %d\n", __func__, port_id, volume); |
| 3539 | port_id = afe_convert_virtual_to_portid(port_id); |
| 3540 | port_idx = adm_validate_and_get_port_index(port_id); |
| 3541 | if (port_idx < 0) { |
| 3542 | pr_err("%s: Invalid port_id %#x\n", __func__, port_id); |
| 3543 | rc = -EINVAL; |
| 3544 | goto fail_cmd; |
| 3545 | } |
| 3546 | |
| 3547 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 3548 | pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); |
| 3549 | return -EINVAL; |
| 3550 | } |
| 3551 | |
| 3552 | sz = sizeof(struct audproc_volume_ctrl_master_gain); |
| 3553 | audproc_vol.params.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 3554 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 3555 | audproc_vol.params.hdr.pkt_size = sz; |
| 3556 | audproc_vol.params.hdr.src_svc = APR_SVC_ADM; |
| 3557 | audproc_vol.params.hdr.src_domain = APR_DOMAIN_APPS; |
| 3558 | audproc_vol.params.hdr.src_port = port_id; |
| 3559 | audproc_vol.params.hdr.dest_svc = APR_SVC_ADM; |
| 3560 | audproc_vol.params.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 3561 | audproc_vol.params.hdr.dest_port = |
| 3562 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 3563 | audproc_vol.params.hdr.token = port_idx << 16 | copp_idx; |
| 3564 | audproc_vol.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; |
| 3565 | audproc_vol.params.payload_addr_lsw = 0; |
| 3566 | audproc_vol.params.payload_addr_msw = 0; |
| 3567 | audproc_vol.params.mem_map_handle = 0; |
| 3568 | audproc_vol.params.payload_size = sizeof(audproc_vol) - |
| 3569 | sizeof(audproc_vol.params); |
| 3570 | audproc_vol.data.module_id = AUDPROC_MODULE_ID_VOL_CTRL; |
| 3571 | audproc_vol.data.param_id = AUDPROC_PARAM_ID_VOL_CTRL_MASTER_GAIN; |
| 3572 | audproc_vol.data.param_size = audproc_vol.params.payload_size - |
| 3573 | sizeof(audproc_vol.data); |
| 3574 | audproc_vol.data.reserved = 0; |
| 3575 | audproc_vol.master_gain = volume; |
| 3576 | |
| 3577 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 3578 | rc = apr_send_pkt(this_adm.apr, (uint32_t *)&audproc_vol); |
| 3579 | if (rc < 0) { |
| 3580 | pr_err("%s: Set params failed port = %#x\n", |
| 3581 | __func__, port_id); |
| 3582 | rc = -EINVAL; |
| 3583 | goto fail_cmd; |
| 3584 | } |
| 3585 | /* Wait for the callback */ |
| 3586 | rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 3587 | atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, |
| 3588 | msecs_to_jiffies(TIMEOUT_MS)); |
| 3589 | if (!rc) { |
| 3590 | pr_err("%s: Vol cntrl Set params timed out port = %#x\n", |
| 3591 | __func__, port_id); |
| 3592 | rc = -EINVAL; |
| 3593 | goto fail_cmd; |
| 3594 | } else if (atomic_read(&this_adm.copp.stat |
| 3595 | [port_idx][copp_idx]) > 0) { |
| 3596 | pr_err("%s: DSP returned error[%s]\n", |
| 3597 | __func__, adsp_err_get_err_str( |
| 3598 | atomic_read(&this_adm.copp.stat |
| 3599 | [port_idx][copp_idx]))); |
| 3600 | rc = adsp_err_get_lnx_err_code( |
| 3601 | atomic_read(&this_adm.copp.stat |
| 3602 | [port_idx][copp_idx])); |
| 3603 | goto fail_cmd; |
| 3604 | } |
| 3605 | rc = 0; |
| 3606 | fail_cmd: |
| 3607 | return rc; |
| 3608 | } |
| 3609 | |
| 3610 | int adm_set_softvolume(int port_id, int copp_idx, |
| 3611 | struct audproc_softvolume_params *softvol_param) |
| 3612 | { |
| 3613 | struct audproc_soft_step_volume_params audproc_softvol; |
| 3614 | int sz = 0; |
| 3615 | int rc = 0; |
| 3616 | int port_idx; |
| 3617 | |
| 3618 | pr_debug("%s: period %d step %d curve %d\n", __func__, |
| 3619 | softvol_param->period, softvol_param->step, |
| 3620 | softvol_param->rampingcurve); |
| 3621 | |
| 3622 | port_id = afe_convert_virtual_to_portid(port_id); |
| 3623 | port_idx = adm_validate_and_get_port_index(port_id); |
| 3624 | if (port_idx < 0) { |
| 3625 | pr_err("%s: Invalid port_id %#x\n", __func__, port_id); |
| 3626 | rc = -EINVAL; |
| 3627 | goto fail_cmd; |
| 3628 | } |
| 3629 | |
| 3630 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 3631 | pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); |
| 3632 | return -EINVAL; |
| 3633 | } |
| 3634 | |
| 3635 | sz = sizeof(struct audproc_soft_step_volume_params); |
| 3636 | |
| 3637 | audproc_softvol.params.hdr.hdr_field = |
| 3638 | APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 3639 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 3640 | audproc_softvol.params.hdr.pkt_size = sz; |
| 3641 | audproc_softvol.params.hdr.src_svc = APR_SVC_ADM; |
| 3642 | audproc_softvol.params.hdr.src_domain = APR_DOMAIN_APPS; |
| 3643 | audproc_softvol.params.hdr.src_port = port_id; |
| 3644 | audproc_softvol.params.hdr.dest_svc = APR_SVC_ADM; |
| 3645 | audproc_softvol.params.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 3646 | audproc_softvol.params.hdr.dest_port = |
| 3647 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 3648 | audproc_softvol.params.hdr.token = port_idx << 16 | copp_idx; |
| 3649 | audproc_softvol.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; |
| 3650 | audproc_softvol.params.payload_addr_lsw = 0; |
| 3651 | audproc_softvol.params.payload_addr_msw = 0; |
| 3652 | audproc_softvol.params.mem_map_handle = 0; |
| 3653 | audproc_softvol.params.payload_size = sizeof(audproc_softvol) - |
| 3654 | sizeof(audproc_softvol.params); |
| 3655 | audproc_softvol.data.module_id = AUDPROC_MODULE_ID_VOL_CTRL; |
| 3656 | audproc_softvol.data.param_id = |
| 3657 | AUDPROC_PARAM_ID_SOFT_VOL_STEPPING_PARAMETERS; |
| 3658 | audproc_softvol.data.param_size = audproc_softvol.params.payload_size - |
| 3659 | sizeof(audproc_softvol.data); |
| 3660 | audproc_softvol.data.reserved = 0; |
| 3661 | audproc_softvol.period = softvol_param->period; |
| 3662 | audproc_softvol.step = softvol_param->step; |
| 3663 | audproc_softvol.ramping_curve = softvol_param->rampingcurve; |
| 3664 | |
| 3665 | pr_debug("%s: period %d, step %d, curve %d\n", __func__, |
| 3666 | audproc_softvol.period, audproc_softvol.step, |
| 3667 | audproc_softvol.ramping_curve); |
| 3668 | |
| 3669 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 3670 | rc = apr_send_pkt(this_adm.apr, (uint32_t *)&audproc_softvol); |
| 3671 | if (rc < 0) { |
| 3672 | pr_err("%s: Set params failed port = %#x\n", |
| 3673 | __func__, port_id); |
| 3674 | rc = -EINVAL; |
| 3675 | goto fail_cmd; |
| 3676 | } |
| 3677 | /* Wait for the callback */ |
| 3678 | rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 3679 | atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, |
| 3680 | msecs_to_jiffies(TIMEOUT_MS)); |
| 3681 | if (!rc) { |
| 3682 | pr_err("%s: Soft volume Set params timed out port = %#x\n", |
| 3683 | __func__, port_id); |
| 3684 | rc = -EINVAL; |
| 3685 | goto fail_cmd; |
| 3686 | } else if (atomic_read(&this_adm.copp.stat |
| 3687 | [port_idx][copp_idx]) > 0) { |
| 3688 | pr_err("%s: DSP returned error[%s]\n", |
| 3689 | __func__, adsp_err_get_err_str( |
| 3690 | atomic_read(&this_adm.copp.stat |
| 3691 | [port_idx][copp_idx]))); |
| 3692 | rc = adsp_err_get_lnx_err_code( |
| 3693 | atomic_read(&this_adm.copp.stat |
| 3694 | [port_idx][copp_idx])); |
| 3695 | goto fail_cmd; |
| 3696 | } |
| 3697 | rc = 0; |
| 3698 | fail_cmd: |
| 3699 | return rc; |
| 3700 | } |
| 3701 | |
| 3702 | int adm_set_mic_gain(int port_id, int copp_idx, int volume) |
| 3703 | { |
| 3704 | struct adm_set_mic_gain_params mic_gain_params; |
| 3705 | int rc = 0; |
| 3706 | int sz, port_idx; |
| 3707 | |
| 3708 | pr_debug("%s:\n", __func__); |
| 3709 | port_id = afe_convert_virtual_to_portid(port_id); |
| 3710 | port_idx = adm_validate_and_get_port_index(port_id); |
| 3711 | if (port_idx < 0) { |
| 3712 | pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); |
| 3713 | return -EINVAL; |
| 3714 | } |
| 3715 | |
| 3716 | sz = sizeof(struct adm_set_mic_gain_params); |
| 3717 | |
| 3718 | mic_gain_params.params.hdr.hdr_field = |
| 3719 | APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 3720 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 3721 | mic_gain_params.params.hdr.pkt_size = sz; |
| 3722 | mic_gain_params.params.hdr.src_svc = APR_SVC_ADM; |
| 3723 | mic_gain_params.params.hdr.src_domain = APR_DOMAIN_APPS; |
| 3724 | mic_gain_params.params.hdr.src_port = port_id; |
| 3725 | mic_gain_params.params.hdr.dest_svc = APR_SVC_ADM; |
| 3726 | mic_gain_params.params.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 3727 | mic_gain_params.params.hdr.dest_port = |
| 3728 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 3729 | mic_gain_params.params.hdr.token = port_idx << 16 | copp_idx; |
| 3730 | mic_gain_params.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; |
| 3731 | mic_gain_params.params.payload_addr_lsw = 0; |
| 3732 | mic_gain_params.params.payload_addr_msw = 0; |
| 3733 | mic_gain_params.params.mem_map_handle = 0; |
| 3734 | mic_gain_params.params.payload_size = |
| 3735 | sizeof(struct adm_param_data_v5) + |
| 3736 | sizeof(struct admx_mic_gain); |
| 3737 | mic_gain_params.data.module_id = ADM_MODULE_IDX_MIC_GAIN_CTRL; |
| 3738 | mic_gain_params.data.param_id = ADM_PARAM_IDX_MIC_GAIN; |
| 3739 | mic_gain_params.data.param_size = |
| 3740 | sizeof(struct admx_mic_gain); |
| 3741 | mic_gain_params.data.reserved = 0; |
| 3742 | mic_gain_params.mic_gain_data.tx_mic_gain = volume; |
| 3743 | mic_gain_params.mic_gain_data.reserved = 0; |
| 3744 | pr_debug("%s: Mic Gain set to %d at port_id 0x%x\n", |
| 3745 | __func__, volume, port_id); |
| 3746 | |
| 3747 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 3748 | rc = apr_send_pkt(this_adm.apr, (uint32_t *)&mic_gain_params); |
| 3749 | if (rc < 0) { |
| 3750 | pr_err("%s: Set params failed port = %#x\n", |
| 3751 | __func__, port_id); |
| 3752 | rc = -EINVAL; |
| 3753 | goto fail_cmd; |
| 3754 | } |
| 3755 | /* Wait for the callback */ |
| 3756 | rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 3757 | atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, |
| 3758 | msecs_to_jiffies(TIMEOUT_MS)); |
| 3759 | if (!rc) { |
| 3760 | pr_err("%s: Mic Gain Set params timed out port = %#x\n", |
| 3761 | __func__, port_id); |
| 3762 | rc = -EINVAL; |
| 3763 | goto fail_cmd; |
| 3764 | } else if (atomic_read(&this_adm.copp.stat |
| 3765 | [port_idx][copp_idx]) > 0) { |
| 3766 | pr_err("%s: DSP returned error[%s]\n", |
| 3767 | __func__, adsp_err_get_err_str( |
| 3768 | atomic_read(&this_adm.copp.stat |
| 3769 | [port_idx][copp_idx]))); |
| 3770 | rc = adsp_err_get_lnx_err_code( |
| 3771 | atomic_read(&this_adm.copp.stat |
| 3772 | [port_idx][copp_idx])); |
| 3773 | goto fail_cmd; |
| 3774 | } |
| 3775 | rc = 0; |
| 3776 | fail_cmd: |
| 3777 | return rc; |
| 3778 | } |
| 3779 | |
| 3780 | int adm_send_set_multichannel_ec_primary_mic_ch(int port_id, int copp_idx, |
| 3781 | int primary_mic_ch) |
| 3782 | { |
| 3783 | struct adm_set_sec_primary_ch_params sec_primary_ch_params; |
| 3784 | int rc = 0; |
| 3785 | int sz, port_idx; |
| 3786 | |
| 3787 | pr_debug("%s port_id 0x%x, copp_idx 0x%x, primary_mic_ch %d\n", |
| 3788 | __func__, port_id, copp_idx, primary_mic_ch); |
| 3789 | port_id = afe_convert_virtual_to_portid(port_id); |
| 3790 | port_idx = adm_validate_and_get_port_index(port_id); |
| 3791 | if (port_idx < 0) { |
| 3792 | pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); |
| 3793 | return -EINVAL; |
| 3794 | } |
| 3795 | |
| 3796 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 3797 | pr_err("%s: Invalid copp_idx 0x%x\n", __func__, copp_idx); |
| 3798 | return -EINVAL; |
| 3799 | } |
| 3800 | |
| 3801 | sz = sizeof(struct adm_set_sec_primary_ch_params); |
| 3802 | |
| 3803 | sec_primary_ch_params.params.hdr.hdr_field = |
| 3804 | APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 3805 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 3806 | sec_primary_ch_params.params.hdr.pkt_size = sz; |
| 3807 | sec_primary_ch_params.params.hdr.src_svc = APR_SVC_ADM; |
| 3808 | sec_primary_ch_params.params.hdr.src_domain = APR_DOMAIN_APPS; |
| 3809 | sec_primary_ch_params.params.hdr.src_port = port_id; |
| 3810 | sec_primary_ch_params.params.hdr.dest_svc = APR_SVC_ADM; |
| 3811 | sec_primary_ch_params.params.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 3812 | sec_primary_ch_params.params.hdr.dest_port = |
| 3813 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 3814 | sec_primary_ch_params.params.hdr.token = port_idx << 16 | copp_idx; |
| 3815 | sec_primary_ch_params.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; |
| 3816 | sec_primary_ch_params.params.payload_addr_lsw = 0; |
| 3817 | sec_primary_ch_params.params.payload_addr_msw = 0; |
| 3818 | sec_primary_ch_params.params.mem_map_handle = 0; |
| 3819 | sec_primary_ch_params.params.payload_size = |
| 3820 | sizeof(struct adm_param_data_v5) + |
| 3821 | sizeof(struct admx_sec_primary_mic_ch); |
| 3822 | sec_primary_ch_params.data.module_id = |
| 3823 | AUDPROC_MODULE_ID_VOICE_TX_SECNS; |
| 3824 | sec_primary_ch_params.data.param_id = |
| 3825 | AUDPROC_PARAM_IDX_SEC_PRIMARY_MIC_CH; |
| 3826 | sec_primary_ch_params.data.param_size = |
| 3827 | sizeof(struct admx_sec_primary_mic_ch); |
| 3828 | sec_primary_ch_params.data.reserved = 0; |
| 3829 | sec_primary_ch_params.sec_primary_mic_ch_data.version = 0; |
| 3830 | sec_primary_ch_params.sec_primary_mic_ch_data.reserved = 0; |
| 3831 | sec_primary_ch_params.sec_primary_mic_ch_data.sec_primary_mic_ch = |
| 3832 | primary_mic_ch; |
| 3833 | sec_primary_ch_params.sec_primary_mic_ch_data.reserved1 = 0; |
| 3834 | |
| 3835 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 3836 | rc = apr_send_pkt(this_adm.apr, (uint32_t *)&sec_primary_ch_params); |
| 3837 | if (rc < 0) { |
| 3838 | pr_err("%s: Set params failed port = %#x\n", |
| 3839 | __func__, port_id); |
| 3840 | rc = -EINVAL; |
| 3841 | goto fail_cmd; |
| 3842 | } |
| 3843 | /* Wait for the callback */ |
| 3844 | rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 3845 | atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, |
| 3846 | msecs_to_jiffies(TIMEOUT_MS)); |
| 3847 | if (!rc) { |
| 3848 | pr_err("%s: Mic Set params timed out port = %#x\n", |
| 3849 | __func__, port_id); |
| 3850 | rc = -EINVAL; |
| 3851 | goto fail_cmd; |
| 3852 | } else if (atomic_read(&this_adm.copp.stat |
| 3853 | [port_idx][copp_idx]) > 0) { |
| 3854 | pr_err("%s: DSP returned error[%s]\n", |
| 3855 | __func__, adsp_err_get_err_str( |
| 3856 | atomic_read(&this_adm.copp.stat |
| 3857 | [port_idx][copp_idx]))); |
| 3858 | rc = adsp_err_get_lnx_err_code( |
| 3859 | atomic_read(&this_adm.copp.stat |
| 3860 | [port_idx][copp_idx])); |
| 3861 | goto fail_cmd; |
| 3862 | } |
| 3863 | rc = 0; |
| 3864 | fail_cmd: |
| 3865 | return rc; |
| 3866 | } |
| 3867 | |
| 3868 | int adm_param_enable(int port_id, int copp_idx, int module_id, int enable) |
| 3869 | { |
| 3870 | struct audproc_enable_param_t adm_mod_enable; |
| 3871 | int sz = 0; |
| 3872 | int rc = 0; |
| 3873 | int port_idx; |
| 3874 | |
| 3875 | pr_debug("%s port_id %d, module_id 0x%x, enable %d\n", |
| 3876 | __func__, port_id, module_id, enable); |
| 3877 | port_id = afe_convert_virtual_to_portid(port_id); |
| 3878 | port_idx = adm_validate_and_get_port_index(port_id); |
| 3879 | if (port_idx < 0) { |
| 3880 | pr_err("%s: Invalid port_id %#x\n", __func__, port_id); |
| 3881 | rc = -EINVAL; |
| 3882 | goto fail_cmd; |
| 3883 | } |
| 3884 | |
| 3885 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 3886 | pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); |
| 3887 | return -EINVAL; |
| 3888 | } |
| 3889 | |
| 3890 | sz = sizeof(struct audproc_enable_param_t); |
| 3891 | |
| 3892 | adm_mod_enable.pp_params.hdr.hdr_field = |
| 3893 | APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 3894 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 3895 | adm_mod_enable.pp_params.hdr.pkt_size = sz; |
| 3896 | adm_mod_enable.pp_params.hdr.src_svc = APR_SVC_ADM; |
| 3897 | adm_mod_enable.pp_params.hdr.src_domain = APR_DOMAIN_APPS; |
| 3898 | adm_mod_enable.pp_params.hdr.src_port = port_id; |
| 3899 | adm_mod_enable.pp_params.hdr.dest_svc = APR_SVC_ADM; |
| 3900 | adm_mod_enable.pp_params.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 3901 | adm_mod_enable.pp_params.hdr.dest_port = |
| 3902 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 3903 | adm_mod_enable.pp_params.hdr.token = port_idx << 16 | copp_idx; |
| 3904 | adm_mod_enable.pp_params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; |
| 3905 | adm_mod_enable.pp_params.payload_addr_lsw = 0; |
| 3906 | adm_mod_enable.pp_params.payload_addr_msw = 0; |
| 3907 | adm_mod_enable.pp_params.mem_map_handle = 0; |
| 3908 | adm_mod_enable.pp_params.payload_size = sizeof(adm_mod_enable) - |
| 3909 | sizeof(adm_mod_enable.pp_params) + |
| 3910 | sizeof(adm_mod_enable.pp_params.params); |
| 3911 | adm_mod_enable.pp_params.params.module_id = module_id; |
| 3912 | adm_mod_enable.pp_params.params.param_id = AUDPROC_PARAM_ID_ENABLE; |
| 3913 | adm_mod_enable.pp_params.params.param_size = |
| 3914 | adm_mod_enable.pp_params.payload_size - |
| 3915 | sizeof(adm_mod_enable.pp_params.params); |
| 3916 | adm_mod_enable.pp_params.params.reserved = 0; |
| 3917 | adm_mod_enable.enable = enable; |
| 3918 | |
| 3919 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 3920 | |
| 3921 | rc = apr_send_pkt(this_adm.apr, (uint32_t *)&adm_mod_enable); |
| 3922 | if (rc < 0) { |
| 3923 | pr_err("%s: Set params failed port = %#x\n", |
| 3924 | __func__, port_id); |
| 3925 | rc = -EINVAL; |
| 3926 | goto fail_cmd; |
| 3927 | } |
| 3928 | /* Wait for the callback */ |
| 3929 | rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 3930 | atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, |
| 3931 | msecs_to_jiffies(TIMEOUT_MS)); |
| 3932 | if (!rc) { |
| 3933 | pr_err("%s: module %x enable %d timed out on port = %#x\n", |
| 3934 | __func__, module_id, enable, port_id); |
| 3935 | rc = -EINVAL; |
| 3936 | goto fail_cmd; |
| 3937 | } else if (atomic_read(&this_adm.copp.stat |
| 3938 | [port_idx][copp_idx]) > 0) { |
| 3939 | pr_err("%s: DSP returned error[%s]\n", |
| 3940 | __func__, adsp_err_get_err_str( |
| 3941 | atomic_read(&this_adm.copp.stat |
| 3942 | [port_idx][copp_idx]))); |
| 3943 | rc = adsp_err_get_lnx_err_code( |
| 3944 | atomic_read(&this_adm.copp.stat |
| 3945 | [port_idx][copp_idx])); |
| 3946 | goto fail_cmd; |
| 3947 | } |
| 3948 | rc = 0; |
| 3949 | fail_cmd: |
| 3950 | return rc; |
| 3951 | |
| 3952 | } |
| 3953 | |
| 3954 | int adm_send_calibration(int port_id, int copp_idx, int path, int perf_mode, |
| 3955 | int cal_type, char *params, int size) |
| 3956 | { |
| 3957 | |
| 3958 | struct adm_cmd_set_pp_params_v5 *adm_params = NULL; |
| 3959 | int sz, rc = 0; |
| 3960 | int port_idx; |
| 3961 | |
| 3962 | pr_debug("%s:port_id %d, path %d, perf_mode %d, cal_type %d, size %d\n", |
| 3963 | __func__, port_id, path, perf_mode, cal_type, size); |
| 3964 | |
| 3965 | port_id = afe_convert_virtual_to_portid(port_id); |
| 3966 | port_idx = adm_validate_and_get_port_index(port_id); |
| 3967 | if (port_idx < 0) { |
| 3968 | pr_err("%s: Invalid port_id %#x\n", __func__, port_id); |
| 3969 | rc = -EINVAL; |
| 3970 | goto end; |
| 3971 | } |
| 3972 | |
| 3973 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 3974 | pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); |
| 3975 | return -EINVAL; |
| 3976 | } |
| 3977 | |
| 3978 | /* Maps audio_dev_ctrl path definition to ACDB definition */ |
| 3979 | if (get_cal_path(path) != RX_DEVICE) { |
| 3980 | pr_err("%s: acdb_path %d\n", __func__, path); |
| 3981 | rc = -EINVAL; |
| 3982 | goto end; |
| 3983 | } |
| 3984 | |
| 3985 | sz = sizeof(struct adm_cmd_set_pp_params_v5) + size; |
| 3986 | adm_params = kzalloc(sz, GFP_KERNEL); |
| 3987 | if (!adm_params) { |
| 3988 | pr_err("%s, adm params memory alloc failed", __func__); |
| 3989 | rc = -ENOMEM; |
| 3990 | goto end; |
| 3991 | } |
| 3992 | |
| 3993 | memcpy(((u8 *)adm_params + sizeof(struct adm_cmd_set_pp_params_v5)), |
| 3994 | params, size); |
| 3995 | |
| 3996 | adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 3997 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 3998 | adm_params->hdr.pkt_size = sz; |
| 3999 | adm_params->hdr.src_svc = APR_SVC_ADM; |
| 4000 | adm_params->hdr.src_domain = APR_DOMAIN_APPS; |
| 4001 | adm_params->hdr.src_port = port_id; |
| 4002 | adm_params->hdr.dest_svc = APR_SVC_ADM; |
| 4003 | adm_params->hdr.dest_domain = APR_DOMAIN_ADSP; |
| 4004 | adm_params->hdr.dest_port = |
| 4005 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 4006 | adm_params->hdr.token = port_idx << 16 | copp_idx; |
| 4007 | adm_params->hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; |
| 4008 | /* payload address and mmap handle initialized to zero by kzalloc */ |
| 4009 | adm_params->payload_size = size; |
| 4010 | |
| 4011 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 4012 | rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params); |
| 4013 | if (rc < 0) { |
| 4014 | pr_err("%s: Set params failed port = %#x\n", |
| 4015 | __func__, port_id); |
| 4016 | rc = -EINVAL; |
| 4017 | goto end; |
| 4018 | } |
| 4019 | /* Wait for the callback */ |
| 4020 | rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 4021 | atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, |
| 4022 | msecs_to_jiffies(TIMEOUT_MS)); |
| 4023 | if (!rc) { |
| 4024 | pr_err("%s: Set params timed out port = %#x\n", |
| 4025 | __func__, port_id); |
| 4026 | rc = -EINVAL; |
| 4027 | goto end; |
| 4028 | } else if (atomic_read(&this_adm.copp.stat |
| 4029 | [port_idx][copp_idx]) > 0) { |
| 4030 | pr_err("%s: DSP returned error[%s]\n", |
| 4031 | __func__, adsp_err_get_err_str( |
| 4032 | atomic_read(&this_adm.copp.stat |
| 4033 | [port_idx][copp_idx]))); |
| 4034 | rc = adsp_err_get_lnx_err_code( |
| 4035 | atomic_read(&this_adm.copp.stat |
| 4036 | [port_idx][copp_idx])); |
| 4037 | goto end; |
| 4038 | } |
| 4039 | rc = 0; |
| 4040 | |
| 4041 | end: |
| 4042 | kfree(adm_params); |
| 4043 | return rc; |
| 4044 | } |
| 4045 | |
| 4046 | /* |
| 4047 | * adm_update_wait_parameters must be called with routing driver locks. |
| 4048 | * adm_reset_wait_parameters must be called with routing driver locks. |
| 4049 | * set and reset parmeters are separated to make sure it is always called |
| 4050 | * under routing driver lock. |
| 4051 | * adm_wait_timeout is to block until timeout or interrupted. Timeout is |
| 4052 | * not a an error. |
| 4053 | */ |
| 4054 | int adm_set_wait_parameters(int port_id, int copp_idx) |
| 4055 | { |
| 4056 | |
| 4057 | int ret = 0, port_idx; |
| 4058 | |
| 4059 | pr_debug("%s: port_id 0x%x, copp_idx %d\n", __func__, port_id, |
| 4060 | copp_idx); |
| 4061 | port_id = afe_convert_virtual_to_portid(port_id); |
| 4062 | port_idx = adm_validate_and_get_port_index(port_id); |
| 4063 | if (port_idx < 0) { |
| 4064 | pr_err("%s: Invalid port_id %#x\n", __func__, port_id); |
| 4065 | ret = -EINVAL; |
| 4066 | goto end; |
| 4067 | } |
| 4068 | |
| 4069 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 4070 | pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); |
| 4071 | return -EINVAL; |
| 4072 | } |
| 4073 | |
| 4074 | this_adm.copp.adm_delay[port_idx][copp_idx] = 1; |
| 4075 | atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx], 0); |
| 4076 | |
| 4077 | end: |
| 4078 | return ret; |
| 4079 | |
| 4080 | } |
| 4081 | |
| 4082 | int adm_reset_wait_parameters(int port_id, int copp_idx) |
| 4083 | { |
| 4084 | int ret = 0, port_idx; |
| 4085 | |
| 4086 | pr_debug("%s: port_id 0x%x copp_idx %d\n", __func__, port_id, |
| 4087 | copp_idx); |
| 4088 | port_id = afe_convert_virtual_to_portid(port_id); |
| 4089 | port_idx = adm_validate_and_get_port_index(port_id); |
| 4090 | if (port_idx < 0) { |
| 4091 | pr_err("%s: Invalid port_id %#x\n", __func__, port_id); |
| 4092 | ret = -EINVAL; |
| 4093 | goto end; |
| 4094 | } |
| 4095 | |
| 4096 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 4097 | pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); |
| 4098 | return -EINVAL; |
| 4099 | } |
| 4100 | |
| 4101 | atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx], 1); |
| 4102 | this_adm.copp.adm_delay[port_idx][copp_idx] = 0; |
| 4103 | |
| 4104 | end: |
| 4105 | return ret; |
| 4106 | } |
| 4107 | |
| 4108 | int adm_wait_timeout(int port_id, int copp_idx, int wait_time) |
| 4109 | { |
| 4110 | int ret = 0, port_idx; |
| 4111 | |
| 4112 | pr_debug("%s: port_id 0x%x, copp_idx %d, wait_time %d\n", __func__, |
| 4113 | port_id, copp_idx, wait_time); |
| 4114 | port_id = afe_convert_virtual_to_portid(port_id); |
| 4115 | port_idx = adm_validate_and_get_port_index(port_id); |
| 4116 | if (port_idx < 0) { |
| 4117 | pr_err("%s: Invalid port_id %#x\n", __func__, port_id); |
| 4118 | ret = -EINVAL; |
| 4119 | goto end; |
| 4120 | } |
| 4121 | |
| 4122 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 4123 | pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); |
| 4124 | return -EINVAL; |
| 4125 | } |
| 4126 | |
| 4127 | ret = wait_event_timeout( |
| 4128 | this_adm.copp.adm_delay_wait[port_idx][copp_idx], |
| 4129 | atomic_read(&this_adm.copp.adm_delay_stat[port_idx][copp_idx]), |
| 4130 | msecs_to_jiffies(wait_time)); |
| 4131 | pr_debug("%s: return %d\n", __func__, ret); |
| 4132 | if (ret != 0) |
| 4133 | ret = -EINTR; |
| 4134 | end: |
| 4135 | pr_debug("%s: return %d--\n", __func__, ret); |
| 4136 | return ret; |
| 4137 | } |
| 4138 | |
| 4139 | int adm_store_cal_data(int port_id, int copp_idx, int path, int perf_mode, |
| 4140 | int cal_index, char *params, int *size) |
| 4141 | { |
| 4142 | int rc = 0; |
| 4143 | struct cal_block_data *cal_block = NULL; |
| 4144 | int app_type, acdb_id, port_idx, sample_rate; |
| 4145 | |
| 4146 | if (this_adm.cal_data[cal_index] == NULL) { |
| 4147 | pr_debug("%s: cal_index %d not allocated!\n", |
| 4148 | __func__, cal_index); |
| 4149 | goto end; |
| 4150 | } |
| 4151 | |
| 4152 | if (get_cal_path(path) != RX_DEVICE) { |
| 4153 | pr_debug("%s: Invalid path to store calibration %d\n", |
| 4154 | __func__, path); |
| 4155 | rc = -EINVAL; |
| 4156 | goto end; |
| 4157 | } |
| 4158 | |
| 4159 | port_id = afe_convert_virtual_to_portid(port_id); |
| 4160 | port_idx = adm_validate_and_get_port_index(port_id); |
| 4161 | if (port_idx < 0) { |
| 4162 | pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); |
| 4163 | rc = -EINVAL; |
| 4164 | goto end; |
| 4165 | } |
| 4166 | |
| 4167 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 4168 | pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); |
| 4169 | return -EINVAL; |
| 4170 | } |
| 4171 | |
| 4172 | acdb_id = atomic_read(&this_adm.copp.acdb_id[port_idx][copp_idx]); |
| 4173 | app_type = atomic_read(&this_adm.copp.app_type[port_idx][copp_idx]); |
| 4174 | sample_rate = atomic_read(&this_adm.copp.rate[port_idx][copp_idx]); |
| 4175 | |
| 4176 | mutex_lock(&this_adm.cal_data[cal_index]->lock); |
| 4177 | cal_block = adm_find_cal(cal_index, get_cal_path(path), app_type, |
| 4178 | acdb_id, sample_rate); |
| 4179 | if (cal_block == NULL) |
| 4180 | goto unlock; |
| 4181 | |
| 4182 | if (cal_block->cal_data.size <= 0) { |
| 4183 | pr_debug("%s: No ADM cal send for port_id = 0x%x!\n", |
| 4184 | __func__, port_id); |
| 4185 | rc = -EINVAL; |
| 4186 | goto unlock; |
| 4187 | } |
| 4188 | |
Aditya Bavanari | b11ef71 | 2017-11-21 20:24:53 +0530 | [diff] [blame] | 4189 | if (cal_index == ADM_AUDPROC_CAL || cal_index == ADM_LSM_AUDPROC_CAL) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4190 | if (cal_block->cal_data.size > AUD_PROC_BLOCK_SIZE) { |
| 4191 | pr_err("%s:audproc:invalid size exp/actual[%zd, %d]\n", |
| 4192 | __func__, cal_block->cal_data.size, *size); |
| 4193 | rc = -ENOMEM; |
| 4194 | goto unlock; |
| 4195 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4196 | } else if (cal_index == ADM_AUDVOL_CAL) { |
| 4197 | if (cal_block->cal_data.size > AUD_VOL_BLOCK_SIZE) { |
| 4198 | pr_err("%s:aud_vol:invalid size exp/actual[%zd, %d]\n", |
| 4199 | __func__, cal_block->cal_data.size, *size); |
| 4200 | rc = -ENOMEM; |
| 4201 | goto unlock; |
| 4202 | } |
| 4203 | } else { |
| 4204 | pr_debug("%s: Not valid calibration for dolby topolgy\n", |
| 4205 | __func__); |
| 4206 | rc = -EINVAL; |
| 4207 | goto unlock; |
| 4208 | } |
| 4209 | memcpy(params, cal_block->cal_data.kvaddr, cal_block->cal_data.size); |
| 4210 | *size = cal_block->cal_data.size; |
| 4211 | |
| 4212 | pr_debug("%s:port_id %d, copp_idx %d, path %d", |
| 4213 | __func__, port_id, copp_idx, path); |
| 4214 | pr_debug("perf_mode %d, cal_type %d, size %d\n", |
| 4215 | perf_mode, cal_index, *size); |
| 4216 | |
| 4217 | unlock: |
| 4218 | mutex_unlock(&this_adm.cal_data[cal_index]->lock); |
| 4219 | end: |
| 4220 | return rc; |
| 4221 | } |
| 4222 | |
| 4223 | int adm_send_compressed_device_mute(int port_id, int copp_idx, bool mute_on) |
| 4224 | { |
| 4225 | struct adm_set_compressed_device_mute mute_params; |
| 4226 | int ret = 0; |
| 4227 | int port_idx; |
| 4228 | |
| 4229 | pr_debug("%s port_id: 0x%x, copp_idx %d, mute_on: %d\n", |
| 4230 | __func__, port_id, copp_idx, mute_on); |
| 4231 | port_id = afe_convert_virtual_to_portid(port_id); |
| 4232 | port_idx = adm_validate_and_get_port_index(port_id); |
| 4233 | if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) { |
| 4234 | pr_err("%s: Invalid port_id %#x copp_idx %d\n", |
| 4235 | __func__, port_id, copp_idx); |
| 4236 | ret = -EINVAL; |
| 4237 | goto end; |
| 4238 | } |
| 4239 | |
| 4240 | mute_params.command.hdr.hdr_field = |
| 4241 | APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 4242 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 4243 | mute_params.command.hdr.pkt_size = |
| 4244 | sizeof(struct adm_set_compressed_device_mute); |
| 4245 | mute_params.command.hdr.src_svc = APR_SVC_ADM; |
| 4246 | mute_params.command.hdr.src_domain = APR_DOMAIN_APPS; |
| 4247 | mute_params.command.hdr.src_port = port_id; |
| 4248 | mute_params.command.hdr.dest_svc = APR_SVC_ADM; |
| 4249 | mute_params.command.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 4250 | mute_params.command.hdr.dest_port = |
| 4251 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 4252 | mute_params.command.hdr.token = port_idx << 16 | copp_idx; |
| 4253 | mute_params.command.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; |
| 4254 | mute_params.command.payload_addr_lsw = 0; |
| 4255 | mute_params.command.payload_addr_msw = 0; |
| 4256 | mute_params.command.mem_map_handle = 0; |
| 4257 | mute_params.command.payload_size = sizeof(mute_params) - |
| 4258 | sizeof(mute_params.command); |
| 4259 | mute_params.params.module_id = AUDPROC_MODULE_ID_COMPRESSED_MUTE; |
| 4260 | mute_params.params.param_id = AUDPROC_PARAM_ID_COMPRESSED_MUTE; |
| 4261 | mute_params.params.param_size = mute_params.command.payload_size - |
| 4262 | sizeof(mute_params.params); |
| 4263 | mute_params.params.reserved = 0; |
| 4264 | mute_params.mute_on = mute_on; |
| 4265 | |
| 4266 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 4267 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&mute_params); |
| 4268 | if (ret < 0) { |
| 4269 | pr_err("%s: device mute for port %d copp %d failed, ret %d\n", |
| 4270 | __func__, port_id, copp_idx, ret); |
| 4271 | ret = -EINVAL; |
| 4272 | goto end; |
| 4273 | } |
| 4274 | |
| 4275 | /* Wait for the callback */ |
| 4276 | ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 4277 | atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, |
| 4278 | msecs_to_jiffies(TIMEOUT_MS)); |
| 4279 | if (!ret) { |
| 4280 | pr_err("%s: send device mute for port %d copp %d failed\n", |
| 4281 | __func__, port_id, copp_idx); |
| 4282 | ret = -EINVAL; |
| 4283 | goto end; |
| 4284 | } else if (atomic_read(&this_adm.copp.stat |
| 4285 | [port_idx][copp_idx]) > 0) { |
| 4286 | pr_err("%s: DSP returned error[%s]\n", |
| 4287 | __func__, adsp_err_get_err_str( |
| 4288 | atomic_read(&this_adm.copp.stat |
| 4289 | [port_idx][copp_idx]))); |
| 4290 | ret = adsp_err_get_lnx_err_code( |
| 4291 | atomic_read(&this_adm.copp.stat |
| 4292 | [port_idx][copp_idx])); |
| 4293 | goto end; |
| 4294 | } |
| 4295 | ret = 0; |
| 4296 | end: |
| 4297 | return ret; |
| 4298 | } |
| 4299 | |
| 4300 | int adm_send_compressed_device_latency(int port_id, int copp_idx, int latency) |
| 4301 | { |
| 4302 | struct adm_set_compressed_device_latency latency_params; |
| 4303 | int port_idx; |
| 4304 | int ret = 0; |
| 4305 | |
| 4306 | pr_debug("%s port_id: 0x%x, copp_idx %d latency: %d\n", __func__, |
| 4307 | port_id, copp_idx, latency); |
| 4308 | port_id = afe_convert_virtual_to_portid(port_id); |
| 4309 | port_idx = adm_validate_and_get_port_index(port_id); |
| 4310 | if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) { |
| 4311 | pr_err("%s: Invalid port_id %#x copp_idx %d\n", |
| 4312 | __func__, port_id, copp_idx); |
| 4313 | ret = -EINVAL; |
| 4314 | goto end; |
| 4315 | } |
| 4316 | |
| 4317 | latency_params.command.hdr.hdr_field = |
| 4318 | APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 4319 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 4320 | latency_params.command.hdr.pkt_size = |
| 4321 | sizeof(struct adm_set_compressed_device_latency); |
| 4322 | latency_params.command.hdr.src_svc = APR_SVC_ADM; |
| 4323 | latency_params.command.hdr.src_domain = APR_DOMAIN_APPS; |
| 4324 | latency_params.command.hdr.src_port = port_id; |
| 4325 | latency_params.command.hdr.dest_svc = APR_SVC_ADM; |
| 4326 | latency_params.command.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 4327 | latency_params.command.hdr.dest_port = |
| 4328 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 4329 | latency_params.command.hdr.token = port_idx << 16 | copp_idx; |
| 4330 | latency_params.command.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; |
| 4331 | latency_params.command.payload_addr_lsw = 0; |
| 4332 | latency_params.command.payload_addr_msw = 0; |
| 4333 | latency_params.command.mem_map_handle = 0; |
| 4334 | latency_params.command.payload_size = sizeof(latency_params) - |
| 4335 | sizeof(latency_params.command); |
| 4336 | latency_params.params.module_id = AUDPROC_MODULE_ID_COMPRESSED_LATENCY; |
| 4337 | latency_params.params.param_id = AUDPROC_PARAM_ID_COMPRESSED_LATENCY; |
| 4338 | latency_params.params.param_size = latency_params.command.payload_size - |
| 4339 | sizeof(latency_params.params); |
| 4340 | latency_params.params.reserved = 0; |
| 4341 | latency_params.latency = latency; |
| 4342 | |
| 4343 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 4344 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&latency_params); |
| 4345 | if (ret < 0) { |
| 4346 | pr_err("%s: send device latency err %d for port %d copp %d\n", |
| 4347 | __func__, port_id, copp_idx, ret); |
| 4348 | ret = -EINVAL; |
| 4349 | goto end; |
| 4350 | } |
| 4351 | |
| 4352 | /* Wait for the callback */ |
| 4353 | ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 4354 | atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, |
| 4355 | msecs_to_jiffies(TIMEOUT_MS)); |
| 4356 | if (!ret) { |
| 4357 | pr_err("%s: send device latency for port %d failed\n", __func__, |
| 4358 | port_id); |
| 4359 | ret = -EINVAL; |
| 4360 | goto end; |
| 4361 | } else if (atomic_read(&this_adm.copp.stat |
| 4362 | [port_idx][copp_idx]) > 0) { |
| 4363 | pr_err("%s: DSP returned error[%s]\n", |
| 4364 | __func__, adsp_err_get_err_str( |
| 4365 | atomic_read(&this_adm.copp.stat |
| 4366 | [port_idx][copp_idx]))); |
| 4367 | ret = adsp_err_get_lnx_err_code( |
| 4368 | atomic_read(&this_adm.copp.stat |
| 4369 | [port_idx][copp_idx])); |
| 4370 | goto end; |
| 4371 | } |
| 4372 | ret = 0; |
| 4373 | end: |
| 4374 | return ret; |
| 4375 | } |
| 4376 | |
| 4377 | /** |
| 4378 | * adm_swap_speaker_channels |
| 4379 | * |
| 4380 | * Receives port_id, copp_idx, sample rate, spk_swap and |
| 4381 | * send MFC command to swap speaker channel. |
| 4382 | * Return zero on success. On failure returns nonzero. |
| 4383 | * |
| 4384 | * port_id - Passed value, port_id for which channels swap is wanted |
| 4385 | * copp_idx - Passed value, copp_idx for which channels swap is wanted |
| 4386 | * sample_rate - Passed value, sample rate used by app type config |
| 4387 | * spk_swap - Passed value, spk_swap for check if swap flag is set |
| 4388 | */ |
| 4389 | int adm_swap_speaker_channels(int port_id, int copp_idx, |
| 4390 | int sample_rate, bool spk_swap) |
| 4391 | { |
| 4392 | struct audproc_mfc_output_media_fmt mfc_cfg; |
| 4393 | uint16_t num_channels; |
| 4394 | int port_idx; |
| 4395 | int ret = 0; |
| 4396 | |
| 4397 | pr_debug("%s: Enter, port_id %d, copp_idx %d\n", |
| 4398 | __func__, port_id, copp_idx); |
| 4399 | port_id = q6audio_convert_virtual_to_portid(port_id); |
| 4400 | port_idx = adm_validate_and_get_port_index(port_id); |
| 4401 | if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) { |
| 4402 | pr_err("%s: Invalid port_id %#x\n", __func__, port_id); |
| 4403 | ret = -EINVAL; |
| 4404 | goto done; |
| 4405 | } |
| 4406 | |
| 4407 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 4408 | pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); |
| 4409 | ret = -EINVAL; |
| 4410 | goto done; |
| 4411 | } |
| 4412 | |
| 4413 | num_channels = atomic_read( |
| 4414 | &this_adm.copp.channels[port_idx][copp_idx]); |
| 4415 | if (num_channels != 2) { |
| 4416 | pr_debug("%s: Invalid number of channels: %d\n", |
| 4417 | __func__, num_channels); |
| 4418 | ret = -EINVAL; |
| 4419 | goto done; |
| 4420 | } |
| 4421 | |
| 4422 | memset(&mfc_cfg, 0, sizeof(mfc_cfg)); |
| 4423 | mfc_cfg.params.hdr.hdr_field = |
| 4424 | APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 4425 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 4426 | mfc_cfg.params.hdr.pkt_size = |
| 4427 | sizeof(mfc_cfg); |
| 4428 | mfc_cfg.params.hdr.src_svc = APR_SVC_ADM; |
| 4429 | mfc_cfg.params.hdr.src_domain = APR_DOMAIN_APPS; |
| 4430 | mfc_cfg.params.hdr.src_port = port_id; |
| 4431 | mfc_cfg.params.hdr.dest_svc = APR_SVC_ADM; |
| 4432 | mfc_cfg.params.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 4433 | mfc_cfg.params.hdr.dest_port = |
| 4434 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 4435 | mfc_cfg.params.hdr.token = port_idx << 16 | copp_idx; |
| 4436 | mfc_cfg.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; |
| 4437 | mfc_cfg.params.payload_addr_lsw = 0; |
| 4438 | mfc_cfg.params.payload_addr_msw = 0; |
| 4439 | mfc_cfg.params.mem_map_handle = 0; |
| 4440 | mfc_cfg.params.payload_size = sizeof(mfc_cfg) - |
| 4441 | sizeof(mfc_cfg.params); |
| 4442 | mfc_cfg.data.module_id = AUDPROC_MODULE_ID_MFC; |
| 4443 | mfc_cfg.data.param_id = AUDPROC_PARAM_ID_MFC_OUTPUT_MEDIA_FORMAT; |
| 4444 | mfc_cfg.data.param_size = mfc_cfg.params.payload_size - |
| 4445 | sizeof(mfc_cfg.data); |
| 4446 | mfc_cfg.data.reserved = 0; |
| 4447 | mfc_cfg.sampling_rate = sample_rate; |
| 4448 | mfc_cfg.bits_per_sample = |
| 4449 | atomic_read(&this_adm.copp.bit_width[port_idx][copp_idx]); |
| 4450 | mfc_cfg.num_channels = num_channels; |
| 4451 | |
| 4452 | /* Currently applying speaker swap for only 2 channel use case */ |
| 4453 | if (spk_swap) { |
| 4454 | mfc_cfg.channel_type[0] = |
| 4455 | (uint16_t) PCM_CHANNEL_FR; |
| 4456 | mfc_cfg.channel_type[1] = |
| 4457 | (uint16_t) PCM_CHANNEL_FL; |
| 4458 | } else { |
| 4459 | mfc_cfg.channel_type[0] = |
| 4460 | (uint16_t) PCM_CHANNEL_FL; |
| 4461 | mfc_cfg.channel_type[1] = |
| 4462 | (uint16_t) PCM_CHANNEL_FR; |
| 4463 | } |
| 4464 | |
| 4465 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 4466 | pr_debug("%s: mfc config: port_idx %d copp_idx %d copp SR %d copp BW %d copp chan %d\n", |
| 4467 | __func__, port_idx, copp_idx, mfc_cfg.sampling_rate, |
| 4468 | mfc_cfg.bits_per_sample, mfc_cfg.num_channels); |
| 4469 | |
| 4470 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&mfc_cfg); |
| 4471 | if (ret < 0) { |
| 4472 | pr_err("%s: port_id: for[0x%x] failed %d\n", |
| 4473 | __func__, port_id, ret); |
| 4474 | goto done; |
| 4475 | } |
| 4476 | /* Wait for the callback with copp id */ |
| 4477 | ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 4478 | atomic_read(&this_adm.copp.stat |
| 4479 | [port_idx][copp_idx]) >= 0, |
| 4480 | msecs_to_jiffies(TIMEOUT_MS)); |
| 4481 | if (!ret) { |
| 4482 | pr_err("%s: mfc_cfg Set params timed out for port_id: for [0x%x]\n", |
| 4483 | __func__, port_id); |
| 4484 | ret = -ETIMEDOUT; |
| 4485 | goto done; |
| 4486 | } |
| 4487 | |
| 4488 | if (atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) > 0) { |
| 4489 | pr_err("%s: DSP returned error[%s]\n", |
| 4490 | __func__, adsp_err_get_err_str( |
| 4491 | atomic_read(&this_adm.copp.stat |
| 4492 | [port_idx][copp_idx]))); |
| 4493 | ret = adsp_err_get_lnx_err_code( |
| 4494 | atomic_read(&this_adm.copp.stat |
| 4495 | [port_idx][copp_idx])); |
| 4496 | goto done; |
| 4497 | } |
| 4498 | |
| 4499 | pr_debug("%s: mfc_cfg Set params returned success", __func__); |
| 4500 | ret = 0; |
| 4501 | |
| 4502 | done: |
| 4503 | return ret; |
| 4504 | } |
| 4505 | EXPORT_SYMBOL(adm_swap_speaker_channels); |
| 4506 | |
| 4507 | int adm_set_sound_focus(int port_id, int copp_idx, |
| 4508 | struct sound_focus_param soundFocusData) |
| 4509 | { |
| 4510 | struct adm_set_fluence_soundfocus_param soundfocus_params; |
| 4511 | int sz = 0; |
| 4512 | int ret = 0; |
| 4513 | int port_idx; |
| 4514 | int i; |
| 4515 | |
| 4516 | pr_debug("%s: Enter, port_id %d, copp_idx %d\n", |
| 4517 | __func__, port_id, copp_idx); |
| 4518 | |
| 4519 | port_id = afe_convert_virtual_to_portid(port_id); |
| 4520 | port_idx = adm_validate_and_get_port_index(port_id); |
| 4521 | if (port_idx < 0) { |
| 4522 | pr_err("%s: Invalid port_id %#x\n", __func__, port_id); |
| 4523 | |
| 4524 | ret = -EINVAL; |
| 4525 | goto done; |
| 4526 | } |
| 4527 | |
| 4528 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 4529 | pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); |
| 4530 | |
| 4531 | ret = -EINVAL; |
| 4532 | goto done; |
| 4533 | } |
| 4534 | |
| 4535 | sz = sizeof(struct adm_set_fluence_soundfocus_param); |
| 4536 | soundfocus_params.params.hdr.hdr_field = |
| 4537 | APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE), |
| 4538 | APR_PKT_VER); |
| 4539 | soundfocus_params.params.hdr.pkt_size = sz; |
| 4540 | soundfocus_params.params.hdr.src_svc = APR_SVC_ADM; |
| 4541 | soundfocus_params.params.hdr.src_domain = APR_DOMAIN_APPS; |
| 4542 | soundfocus_params.params.hdr.src_port = port_id; |
| 4543 | soundfocus_params.params.hdr.dest_svc = APR_SVC_ADM; |
| 4544 | soundfocus_params.params.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 4545 | soundfocus_params.params.hdr.dest_port = |
| 4546 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 4547 | soundfocus_params.params.hdr.token = port_idx << 16 | |
| 4548 | ADM_CLIENT_ID_SOURCE_TRACKING << 8 | copp_idx; |
| 4549 | soundfocus_params.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; |
| 4550 | soundfocus_params.params.payload_addr_lsw = 0; |
| 4551 | soundfocus_params.params.payload_addr_msw = 0; |
| 4552 | soundfocus_params.params.mem_map_handle = 0; |
| 4553 | soundfocus_params.params.payload_size = sizeof(soundfocus_params) - |
| 4554 | sizeof(soundfocus_params.params); |
| 4555 | soundfocus_params.data.module_id = VOICEPROC_MODULE_ID_GENERIC_TX; |
| 4556 | soundfocus_params.data.param_id = VOICEPROC_PARAM_ID_FLUENCE_SOUNDFOCUS; |
| 4557 | soundfocus_params.data.param_size = |
| 4558 | soundfocus_params.params.payload_size - |
| 4559 | sizeof(soundfocus_params.data); |
| 4560 | soundfocus_params.data.reserved = 0; |
| 4561 | |
| 4562 | memset(&(soundfocus_params.soundfocus_data), 0xFF, |
| 4563 | sizeof(struct adm_param_fluence_soundfocus_t)); |
| 4564 | for (i = 0; i < MAX_SECTORS; i++) { |
| 4565 | soundfocus_params.soundfocus_data.start_angles[i] = |
| 4566 | soundFocusData.start_angle[i]; |
| 4567 | soundfocus_params.soundfocus_data.enables[i] = |
| 4568 | soundFocusData.enable[i]; |
| 4569 | pr_debug("%s: start_angle[%d] = %d\n", |
| 4570 | __func__, i, soundFocusData.start_angle[i]); |
| 4571 | pr_debug("%s: enable[%d] = %d\n", |
| 4572 | __func__, i, soundFocusData.enable[i]); |
| 4573 | } |
| 4574 | soundfocus_params.soundfocus_data.gain_step = |
| 4575 | soundFocusData.gain_step; |
| 4576 | pr_debug("%s: gain_step = %d\n", __func__, soundFocusData.gain_step); |
| 4577 | |
| 4578 | soundfocus_params.soundfocus_data.reserved = 0; |
| 4579 | |
| 4580 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 4581 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&soundfocus_params); |
| 4582 | if (ret < 0) { |
| 4583 | pr_err("%s: Set params failed\n", __func__); |
| 4584 | |
| 4585 | ret = -EINVAL; |
| 4586 | goto done; |
| 4587 | } |
| 4588 | /* Wait for the callback */ |
| 4589 | ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 4590 | atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, |
| 4591 | msecs_to_jiffies(TIMEOUT_MS)); |
| 4592 | if (!ret) { |
| 4593 | pr_err("%s: Set params timed out\n", __func__); |
| 4594 | |
| 4595 | ret = -EINVAL; |
| 4596 | goto done; |
| 4597 | } |
| 4598 | |
| 4599 | if (this_adm.sourceTrackingData.apr_cmd_status != 0) { |
| 4600 | pr_err("%s - set params returned error [%s]\n", |
| 4601 | __func__, adsp_err_get_err_str( |
| 4602 | this_adm.sourceTrackingData.apr_cmd_status)); |
| 4603 | |
| 4604 | ret = adsp_err_get_lnx_err_code( |
| 4605 | this_adm.sourceTrackingData.apr_cmd_status); |
| 4606 | goto done; |
| 4607 | } |
| 4608 | |
| 4609 | ret = 0; |
| 4610 | |
| 4611 | done: |
| 4612 | pr_debug("%s: Exit, ret=%d\n", __func__, ret); |
| 4613 | |
| 4614 | return ret; |
| 4615 | } |
| 4616 | |
| 4617 | int adm_get_sound_focus(int port_id, int copp_idx, |
| 4618 | struct sound_focus_param *soundFocusData) |
| 4619 | { |
| 4620 | int ret = 0, i; |
| 4621 | char *params_value; |
| 4622 | uint32_t param_payload_len = sizeof(struct adm_param_data_v5) + |
| 4623 | sizeof(struct adm_param_fluence_soundfocus_t); |
| 4624 | struct adm_param_fluence_soundfocus_t *soundfocus_params; |
| 4625 | |
| 4626 | pr_debug("%s: Enter, port_id %d, copp_idx %d\n", |
| 4627 | __func__, port_id, copp_idx); |
| 4628 | |
| 4629 | params_value = kzalloc(param_payload_len, GFP_KERNEL); |
| 4630 | if (!params_value) { |
| 4631 | ret = -ENOMEM; |
| 4632 | goto done; |
| 4633 | } |
| 4634 | ret = adm_get_params_v2(port_id, copp_idx, |
| 4635 | VOICEPROC_MODULE_ID_GENERIC_TX, |
| 4636 | VOICEPROC_PARAM_ID_FLUENCE_SOUNDFOCUS, |
| 4637 | param_payload_len, |
| 4638 | params_value, |
| 4639 | ADM_CLIENT_ID_SOURCE_TRACKING); |
| 4640 | if (ret) { |
| 4641 | pr_err("%s: get parameters failed ret:%d\n", __func__, ret); |
| 4642 | |
| 4643 | kfree(params_value); |
| 4644 | ret = -EINVAL; |
| 4645 | goto done; |
| 4646 | } |
| 4647 | |
| 4648 | if (this_adm.sourceTrackingData.apr_cmd_status != 0) { |
| 4649 | pr_err("%s - get params returned error [%s]\n", |
| 4650 | __func__, adsp_err_get_err_str( |
| 4651 | this_adm.sourceTrackingData.apr_cmd_status)); |
| 4652 | |
| 4653 | kfree(params_value); |
| 4654 | ret = adsp_err_get_lnx_err_code( |
| 4655 | this_adm.sourceTrackingData.apr_cmd_status); |
| 4656 | goto done; |
| 4657 | } |
| 4658 | |
| 4659 | soundfocus_params = (struct adm_param_fluence_soundfocus_t *) |
| 4660 | params_value; |
| 4661 | for (i = 0; i < MAX_SECTORS; i++) { |
| 4662 | soundFocusData->start_angle[i] = |
| 4663 | soundfocus_params->start_angles[i]; |
| 4664 | soundFocusData->enable[i] = soundfocus_params->enables[i]; |
| 4665 | pr_debug("%s: start_angle[%d] = %d\n", |
| 4666 | __func__, i, soundFocusData->start_angle[i]); |
| 4667 | pr_debug("%s: enable[%d] = %d\n", |
| 4668 | __func__, i, soundFocusData->enable[i]); |
| 4669 | } |
| 4670 | soundFocusData->gain_step = soundfocus_params->gain_step; |
| 4671 | pr_debug("%s: gain_step = %d\n", __func__, soundFocusData->gain_step); |
| 4672 | |
| 4673 | kfree(params_value); |
| 4674 | |
| 4675 | done: |
| 4676 | pr_debug("%s: Exit, ret = %d\n", __func__, ret); |
| 4677 | |
| 4678 | return ret; |
| 4679 | } |
| 4680 | |
| 4681 | static int adm_source_tracking_alloc_map_memory(void) |
| 4682 | { |
| 4683 | int ret; |
| 4684 | |
| 4685 | pr_debug("%s: Enter\n", __func__); |
| 4686 | |
| 4687 | ret = msm_audio_ion_alloc("SOURCE_TRACKING", |
| 4688 | &this_adm.sourceTrackingData.ion_client, |
| 4689 | &this_adm.sourceTrackingData.ion_handle, |
| 4690 | AUD_PROC_BLOCK_SIZE, |
| 4691 | &this_adm.sourceTrackingData.memmap.paddr, |
| 4692 | &this_adm.sourceTrackingData.memmap.size, |
| 4693 | &this_adm.sourceTrackingData.memmap.kvaddr); |
| 4694 | if (ret) { |
| 4695 | pr_err("%s: failed to allocate memory\n", __func__); |
| 4696 | |
| 4697 | ret = -EINVAL; |
| 4698 | goto done; |
| 4699 | } |
| 4700 | |
| 4701 | atomic_set(&this_adm.mem_map_index, ADM_MEM_MAP_INDEX_SOURCE_TRACKING); |
| 4702 | ret = adm_memory_map_regions(&this_adm.sourceTrackingData.memmap.paddr, |
| 4703 | 0, |
| 4704 | (uint32_t *)&this_adm.sourceTrackingData.memmap.size, |
| 4705 | 1); |
| 4706 | if (ret < 0) { |
| 4707 | pr_err("%s: failed to map memory, paddr = 0x%pK, size = %d\n", |
| 4708 | __func__, |
| 4709 | (void *)this_adm.sourceTrackingData.memmap.paddr, |
| 4710 | (uint32_t)this_adm.sourceTrackingData.memmap.size); |
| 4711 | |
| 4712 | msm_audio_ion_free(this_adm.sourceTrackingData.ion_client, |
| 4713 | this_adm.sourceTrackingData.ion_handle); |
| 4714 | this_adm.sourceTrackingData.ion_client = NULL; |
| 4715 | this_adm.sourceTrackingData.ion_handle = NULL; |
| 4716 | this_adm.sourceTrackingData.memmap.size = 0; |
| 4717 | this_adm.sourceTrackingData.memmap.kvaddr = NULL; |
| 4718 | this_adm.sourceTrackingData.memmap.paddr = 0; |
| 4719 | this_adm.sourceTrackingData.apr_cmd_status = -1; |
| 4720 | atomic_set(&this_adm.mem_map_handles |
| 4721 | [ADM_MEM_MAP_INDEX_SOURCE_TRACKING], 0); |
| 4722 | |
| 4723 | ret = -EINVAL; |
| 4724 | goto done; |
| 4725 | } |
| 4726 | ret = 0; |
| 4727 | pr_debug("%s: paddr = 0x%pK, size = %d, mem_map_handle = 0x%x\n", |
| 4728 | __func__, (void *)this_adm.sourceTrackingData.memmap.paddr, |
| 4729 | (uint32_t)this_adm.sourceTrackingData.memmap.size, |
| 4730 | atomic_read(&this_adm.mem_map_handles |
| 4731 | [ADM_MEM_MAP_INDEX_SOURCE_TRACKING])); |
| 4732 | |
| 4733 | done: |
| 4734 | pr_debug("%s: Exit, ret = %d\n", __func__, ret); |
| 4735 | |
| 4736 | return ret; |
| 4737 | } |
| 4738 | |
| 4739 | int adm_get_source_tracking(int port_id, int copp_idx, |
| 4740 | struct source_tracking_param *sourceTrackingData) |
| 4741 | { |
| 4742 | struct adm_cmd_get_pp_params_v5 admp; |
| 4743 | int p_idx, ret = 0, i; |
| 4744 | struct adm_param_fluence_sourcetracking_t *source_tracking_params; |
| 4745 | |
| 4746 | pr_debug("%s: Enter, port_id %d, copp_idx %d\n", |
| 4747 | __func__, port_id, copp_idx); |
| 4748 | |
| 4749 | if (!this_adm.sourceTrackingData.memmap.paddr) { |
| 4750 | /* Allocate and map shared memory for out of band usage */ |
| 4751 | ret = adm_source_tracking_alloc_map_memory(); |
| 4752 | if (ret != 0) { |
| 4753 | ret = -EINVAL; |
| 4754 | goto done; |
| 4755 | } |
| 4756 | } |
| 4757 | |
| 4758 | port_id = afe_convert_virtual_to_portid(port_id); |
| 4759 | p_idx = adm_validate_and_get_port_index(port_id); |
| 4760 | if (p_idx < 0) { |
| 4761 | pr_err("%s - invalid port index %i, port id %i, copp idx %i\n", |
| 4762 | __func__, p_idx, port_id, copp_idx); |
| 4763 | |
| 4764 | ret = -EINVAL; |
| 4765 | goto done; |
| 4766 | } |
| 4767 | |
| 4768 | admp.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 4769 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 4770 | admp.hdr.pkt_size = sizeof(admp); |
| 4771 | admp.hdr.src_svc = APR_SVC_ADM; |
| 4772 | admp.hdr.src_domain = APR_DOMAIN_APPS; |
| 4773 | admp.hdr.src_port = port_id; |
| 4774 | admp.hdr.dest_svc = APR_SVC_ADM; |
| 4775 | admp.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 4776 | admp.hdr.dest_port = atomic_read(&this_adm.copp.id[p_idx][copp_idx]); |
| 4777 | admp.hdr.token = p_idx << 16 | ADM_CLIENT_ID_SOURCE_TRACKING << 8 | |
| 4778 | copp_idx; |
| 4779 | admp.hdr.opcode = ADM_CMD_GET_PP_PARAMS_V5; |
| 4780 | admp.data_payload_addr_lsw = |
| 4781 | lower_32_bits(this_adm.sourceTrackingData.memmap.paddr); |
| 4782 | admp.data_payload_addr_msw = |
| 4783 | msm_audio_populate_upper_32_bits( |
| 4784 | this_adm.sourceTrackingData.memmap.paddr); |
| 4785 | admp.mem_map_handle = atomic_read(&this_adm.mem_map_handles[ |
| 4786 | ADM_MEM_MAP_INDEX_SOURCE_TRACKING]); |
| 4787 | admp.module_id = VOICEPROC_MODULE_ID_GENERIC_TX; |
| 4788 | admp.param_id = VOICEPROC_PARAM_ID_FLUENCE_SOURCETRACKING; |
| 4789 | admp.param_max_size = sizeof(struct adm_param_fluence_sourcetracking_t) |
| 4790 | + sizeof(struct adm_param_data_v5); |
| 4791 | admp.reserved = 0; |
| 4792 | |
| 4793 | atomic_set(&this_adm.copp.stat[p_idx][copp_idx], -1); |
| 4794 | |
| 4795 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&admp); |
| 4796 | if (ret < 0) { |
| 4797 | pr_err("%s - failed to get Source Tracking Params\n", |
| 4798 | __func__); |
| 4799 | |
| 4800 | ret = -EINVAL; |
| 4801 | goto done; |
| 4802 | } |
| 4803 | ret = wait_event_timeout(this_adm.copp.wait[p_idx][copp_idx], |
| 4804 | atomic_read(&this_adm.copp.stat[p_idx][copp_idx]) >= 0, |
| 4805 | msecs_to_jiffies(TIMEOUT_MS)); |
| 4806 | if (!ret) { |
| 4807 | pr_err("%s - get params timed out\n", __func__); |
| 4808 | |
| 4809 | ret = -EINVAL; |
| 4810 | goto done; |
| 4811 | } else if (atomic_read(&this_adm.copp.stat |
| 4812 | [p_idx][copp_idx]) > 0) { |
| 4813 | pr_err("%s: DSP returned error[%s]\n", |
| 4814 | __func__, adsp_err_get_err_str( |
| 4815 | atomic_read(&this_adm.copp.stat |
| 4816 | [p_idx][copp_idx]))); |
| 4817 | ret = adsp_err_get_lnx_err_code( |
| 4818 | atomic_read(&this_adm.copp.stat |
| 4819 | [p_idx][copp_idx])); |
| 4820 | goto done; |
| 4821 | } |
| 4822 | |
| 4823 | if (this_adm.sourceTrackingData.apr_cmd_status != 0) { |
| 4824 | pr_err("%s - get params returned error [%s]\n", |
| 4825 | __func__, adsp_err_get_err_str( |
| 4826 | this_adm.sourceTrackingData.apr_cmd_status)); |
| 4827 | |
| 4828 | ret = adsp_err_get_lnx_err_code( |
| 4829 | this_adm.sourceTrackingData.apr_cmd_status); |
| 4830 | goto done; |
| 4831 | } |
| 4832 | |
| 4833 | source_tracking_params = (struct adm_param_fluence_sourcetracking_t *) |
| 4834 | (this_adm.sourceTrackingData.memmap.kvaddr + |
| 4835 | sizeof(struct adm_param_data_v5)); |
| 4836 | for (i = 0; i < MAX_SECTORS; i++) { |
| 4837 | sourceTrackingData->vad[i] = source_tracking_params->vad[i]; |
| 4838 | pr_debug("%s: vad[%d] = %d\n", |
| 4839 | __func__, i, sourceTrackingData->vad[i]); |
| 4840 | } |
| 4841 | sourceTrackingData->doa_speech = source_tracking_params->doa_speech; |
| 4842 | pr_debug("%s: doa_speech = %d\n", |
| 4843 | __func__, sourceTrackingData->doa_speech); |
| 4844 | |
| 4845 | for (i = 0; i < MAX_NOISE_SOURCE_INDICATORS; i++) { |
| 4846 | sourceTrackingData->doa_noise[i] = |
| 4847 | source_tracking_params->doa_noise[i]; |
| 4848 | pr_debug("%s: doa_noise[%d] = %d\n", |
| 4849 | __func__, i, sourceTrackingData->doa_noise[i]); |
| 4850 | } |
| 4851 | for (i = 0; i < MAX_POLAR_ACTIVITY_INDICATORS; i++) { |
| 4852 | sourceTrackingData->polar_activity[i] = |
| 4853 | source_tracking_params->polar_activity[i]; |
| 4854 | pr_debug("%s: polar_activity[%d] = %d\n", |
| 4855 | __func__, i, sourceTrackingData->polar_activity[i]); |
| 4856 | } |
| 4857 | |
| 4858 | ret = 0; |
| 4859 | |
| 4860 | done: |
| 4861 | pr_debug("%s: Exit, ret=%d\n", __func__, ret); |
| 4862 | |
| 4863 | return ret; |
| 4864 | } |
| 4865 | |
| 4866 | static int __init adm_init(void) |
| 4867 | { |
| 4868 | int i = 0, j; |
| 4869 | |
| 4870 | this_adm.apr = NULL; |
| 4871 | this_adm.ec_ref_rx = -1; |
| 4872 | this_adm.num_ec_ref_rx_chans = 0; |
| 4873 | this_adm.ec_ref_rx_bit_width = 0; |
| 4874 | this_adm.ec_ref_rx_sampling_rate = 0; |
| 4875 | atomic_set(&this_adm.matrix_map_stat, 0); |
| 4876 | init_waitqueue_head(&this_adm.matrix_map_wait); |
| 4877 | atomic_set(&this_adm.adm_stat, 0); |
| 4878 | init_waitqueue_head(&this_adm.adm_wait); |
| 4879 | |
| 4880 | for (i = 0; i < AFE_MAX_PORTS; i++) { |
| 4881 | for (j = 0; j < MAX_COPPS_PER_PORT; j++) { |
| 4882 | atomic_set(&this_adm.copp.id[i][j], RESET_COPP_ID); |
| 4883 | atomic_set(&this_adm.copp.cnt[i][j], 0); |
| 4884 | atomic_set(&this_adm.copp.topology[i][j], 0); |
| 4885 | atomic_set(&this_adm.copp.mode[i][j], 0); |
| 4886 | atomic_set(&this_adm.copp.stat[i][j], 0); |
| 4887 | atomic_set(&this_adm.copp.rate[i][j], 0); |
| 4888 | atomic_set(&this_adm.copp.channels[i][j], 0); |
| 4889 | atomic_set(&this_adm.copp.bit_width[i][j], 0); |
| 4890 | atomic_set(&this_adm.copp.app_type[i][j], 0); |
| 4891 | atomic_set(&this_adm.copp.acdb_id[i][j], 0); |
| 4892 | init_waitqueue_head(&this_adm.copp.wait[i][j]); |
| 4893 | atomic_set(&this_adm.copp.adm_delay_stat[i][j], 0); |
| 4894 | init_waitqueue_head( |
| 4895 | &this_adm.copp.adm_delay_wait[i][j]); |
| 4896 | atomic_set(&this_adm.copp.topology[i][j], 0); |
| 4897 | this_adm.copp.adm_delay[i][j] = 0; |
| 4898 | this_adm.copp.adm_status[i][j] = |
| 4899 | ADM_STATUS_CALIBRATION_REQUIRED; |
| 4900 | } |
| 4901 | } |
| 4902 | |
| 4903 | if (adm_init_cal_data()) |
| 4904 | pr_err("%s: could not init cal data!\n", __func__); |
| 4905 | |
| 4906 | this_adm.sourceTrackingData.ion_client = NULL; |
| 4907 | this_adm.sourceTrackingData.ion_handle = NULL; |
| 4908 | this_adm.sourceTrackingData.memmap.size = 0; |
| 4909 | this_adm.sourceTrackingData.memmap.kvaddr = NULL; |
| 4910 | this_adm.sourceTrackingData.memmap.paddr = 0; |
| 4911 | this_adm.sourceTrackingData.apr_cmd_status = -1; |
| 4912 | atomic_set(&this_adm.mem_map_handles[ADM_MEM_MAP_INDEX_SOURCE_TRACKING], |
| 4913 | 0); |
| 4914 | |
| 4915 | return 0; |
| 4916 | } |
| 4917 | |
| 4918 | static void __exit adm_exit(void) |
| 4919 | { |
| 4920 | adm_delete_cal_data(); |
| 4921 | } |
| 4922 | |
| 4923 | device_initcall(adm_init); |
| 4924 | module_exit(adm_exit); |