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