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