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