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