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