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