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