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