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