blob: 82b92aa9217c1d7f53798d74d88acc010a2c721b [file] [log] [blame]
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07001/*
Patrick Lai3aabeae2013-01-06 00:52:34 -08002 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07003 * Author: Brian Swetland <swetland@google.com>
4 *
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 */
15#include <linux/fs.h>
16#include <linux/mutex.h>
17#include <linux/wait.h>
18#include <linux/miscdevice.h>
19#include <linux/uaccess.h>
20#include <linux/sched.h>
21#include <linux/dma-mapping.h>
22#include <linux/miscdevice.h>
23#include <linux/delay.h>
24#include <linux/spinlock.h>
25#include <linux/slab.h>
26#include <linux/msm_audio.h>
27#include <linux/android_pmem.h>
28#include <linux/memory_alloc.h>
29#include <linux/debugfs.h>
30#include <linux/time.h>
31#include <linux/atomic.h>
32
33#include <asm/ioctls.h>
34
35#include <mach/memory.h>
36#include <mach/debug_mm.h>
37#include <mach/peripheral-loader.h>
38#include <mach/qdsp6v2/audio_acdb.h>
39#include <mach/qdsp6v2/rtac.h>
40#include <mach/msm_subsystem_map.h>
41
42#include <sound/apr_audio-v2.h>
43#include <sound/q6asm-v2.h>
44
45#define TRUE 0x01
46#define FALSE 0x00
47#define READDONE_IDX_STATUS 0
48#define READDONE_IDX_BUFADD_LSW 1
49#define READDONE_IDX_BUFADD_MSW 2
50#define READDONE_IDX_MEMMAP_HDL 3
51#define READDONE_IDX_SIZE 4
52#define READDONE_IDX_OFFSET 5
53#define READDONE_IDX_LSW_TS 6
54#define READDONE_IDX_MSW_TS 7
55#define READDONE_IDX_FLAGS 8
56#define READDONE_IDX_NUMFRAMES 9
57#define READDONE_IDX_SEQ_ID 10
58
59/* TODO, combine them together */
60static DEFINE_MUTEX(session_lock);
61struct asm_mmap {
62 atomic_t ref_cnt;
63 void *apr;
64};
65
66static struct asm_mmap this_mmap;
67/* session id: 0 reserved */
68static struct audio_client *session[SESSION_MAX+1];
69
70struct asm_buffer_node {
71 struct list_head list;
72 uint32_t buf_addr_lsw;
73 uint32_t mmap_hdl;
74};
75static int32_t q6asm_mmapcallback(struct apr_client_data *data, void *priv);
76static int32_t q6asm_callback(struct apr_client_data *data, void *priv);
77static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
78 uint32_t pkt_size, uint32_t cmd_flg);
79static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
80 uint32_t pkt_size, uint32_t cmd_flg);
81static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
82 uint32_t bufsz, uint32_t bufcnt);
83static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
84 uint32_t bufsz, uint32_t bufcnt);
85static void q6asm_reset_buf_state(struct audio_client *ac);
86
Harmandeep Singheaf59b42012-06-05 21:46:02 -070087static int q6asm_map_channels(u8 *channel_mapping, uint32_t channels);
88
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -070089
90#ifdef CONFIG_DEBUG_FS
91#define OUT_BUFFER_SIZE 56
92#define IN_BUFFER_SIZE 24
93
94static struct timeval out_cold_tv;
95static struct timeval out_warm_tv;
96static struct timeval out_cont_tv;
97static struct timeval in_cont_tv;
98static long out_enable_flag;
99static long in_enable_flag;
100static struct dentry *out_dentry;
101static struct dentry *in_dentry;
102static int in_cont_index;
103/*This var is used to keep track of first write done for cold output latency */
104static int out_cold_index;
105static char *out_buffer;
106static char *in_buffer;
107static int audio_output_latency_dbgfs_open(struct inode *inode,
108 struct file *file)
109{
110 file->private_data = inode->i_private;
111 return 0;
112}
113static ssize_t audio_output_latency_dbgfs_read(struct file *file,
114 char __user *buf, size_t count, loff_t *ppos)
115{
116 snprintf(out_buffer, OUT_BUFFER_SIZE, "%ld,%ld,%ld,%ld,%ld,%ld,",\
117 out_cold_tv.tv_sec, out_cold_tv.tv_usec, out_warm_tv.tv_sec,\
118 out_warm_tv.tv_usec, out_cont_tv.tv_sec, out_cont_tv.tv_usec);
119 return simple_read_from_buffer(buf, OUT_BUFFER_SIZE, ppos,
120 out_buffer, OUT_BUFFER_SIZE);
121}
122static ssize_t audio_output_latency_dbgfs_write(struct file *file,
123 const char __user *buf, size_t count, loff_t *ppos)
124{
125 char *temp;
126
127 if (count > 2*sizeof(char))
128 return -EINVAL;
129 else
130 temp = kmalloc(2*sizeof(char), GFP_KERNEL);
131
132 out_cold_index = 0;
133
134 if (temp) {
135 if (copy_from_user(temp, buf, 2*sizeof(char))) {
136 kfree(temp);
137 return -EFAULT;
138 }
139 if (!strict_strtol(temp, 10, &out_enable_flag)) {
140 kfree(temp);
141 return count;
142 }
143 kfree(temp);
144 }
145 return -EINVAL;
146}
147static const struct file_operations audio_output_latency_debug_fops = {
148 .open = audio_output_latency_dbgfs_open,
149 .read = audio_output_latency_dbgfs_read,
150 .write = audio_output_latency_dbgfs_write
151};
152static int audio_input_latency_dbgfs_open(struct inode *inode,
153 struct file *file)
154{
155 file->private_data = inode->i_private;
156 return 0;
157}
158static ssize_t audio_input_latency_dbgfs_read(struct file *file,
159 char __user *buf, size_t count, loff_t *ppos)
160{
161 snprintf(in_buffer, IN_BUFFER_SIZE, "%ld,%ld,",\
162 in_cont_tv.tv_sec, in_cont_tv.tv_usec);
163 return simple_read_from_buffer(buf, IN_BUFFER_SIZE, ppos,
164 in_buffer, IN_BUFFER_SIZE);
165}
166static ssize_t audio_input_latency_dbgfs_write(struct file *file,
167 const char __user *buf, size_t count, loff_t *ppos)
168{
169 char *temp;
170
171 if (count > 2*sizeof(char))
172 return -EINVAL;
173 else
174 temp = kmalloc(2*sizeof(char), GFP_KERNEL);
175 if (temp) {
176 if (copy_from_user(temp, buf, 2*sizeof(char))) {
177 kfree(temp);
178 return -EFAULT;
179 }
180 if (!strict_strtol(temp, 10, &in_enable_flag)) {
181 kfree(temp);
182 return count;
183 }
184 kfree(temp);
185 }
186 return -EINVAL;
187}
188static const struct file_operations audio_input_latency_debug_fops = {
189 .open = audio_input_latency_dbgfs_open,
190 .read = audio_input_latency_dbgfs_read,
191 .write = audio_input_latency_dbgfs_write
192};
193
194static void config_debug_fs_write_cb(void)
195{
196 if (out_enable_flag) {
197 /* For first Write done log the time and reset
198 out_cold_index*/
199 if (out_cold_index != 1) {
200 do_gettimeofday(&out_cold_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700201 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700202 out_cold_tv.tv_sec,\
203 out_cold_tv.tv_usec);
204 out_cold_index = 1;
205 }
206 pr_debug("out_enable_flag %ld",\
207 out_enable_flag);
208 }
209}
210static void config_debug_fs_read_cb(void)
211{
212 if (in_enable_flag) {
213 /* when in_cont_index == 7, DSP would be
214 * writing into the 8th 512 byte buffer and this
215 * timestamp is tapped here.Once done it then writes
216 * to 9th 512 byte buffer.These two buffers(8th, 9th)
217 * reach the test application in 5th iteration and that
218 * timestamp is tapped at user level. The difference
219 * of these two timestamps gives us the time between
220 * the time at which dsp started filling the sample
221 * required and when it reached the test application.
222 * Hence continuous input latency
223 */
224 if (in_cont_index == 7) {
225 do_gettimeofday(&in_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700226 pr_err("In_CONT:previous read buffer done at %ld sec %ld microsec\n",
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700227 in_cont_tv.tv_sec, in_cont_tv.tv_usec);
228 }
229 in_cont_index++;
230 }
231}
232
233static void config_debug_fs_reset_index(void)
234{
235 in_cont_index = 0;
236}
237
238static void config_debug_fs_run(void)
239{
240 if (out_enable_flag) {
241 do_gettimeofday(&out_cold_tv);
242 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",\
243 out_cold_tv.tv_sec, out_cold_tv.tv_usec);
244 }
245}
246
247static void config_debug_fs_write(struct audio_buffer *ab)
248{
249 if (out_enable_flag) {
250 char zero_pattern[2] = {0x00, 0x00};
251 /* If First two byte is non zero and last two byte
252 is zero then it is warm output pattern */
253 if ((strncmp(((char *)ab->data), zero_pattern, 2)) &&
254 (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
255 do_gettimeofday(&out_warm_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700256 pr_debug("WARM:apr_send_pkt at %ld sec %ld microsec\n",
257 out_warm_tv.tv_sec,\
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700258 out_warm_tv.tv_usec);
259 pr_debug("Warm Pattern Matched");
260 }
261 /* If First two byte is zero and last two byte is
262 non zero then it is cont ouput pattern */
263 else if ((!strncmp(((char *)ab->data), zero_pattern, 2))
264 && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
265 do_gettimeofday(&out_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700266 pr_debug("CONT:apr_send_pkt at %ld sec %ld microsec\n",
267 out_cont_tv.tv_sec,\
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700268 out_cont_tv.tv_usec);
269 pr_debug("Cont Pattern Matched");
270 }
271 }
272}
273static void config_debug_fs_init(void)
274{
275 out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
276 out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
277 S_IFREG | S_IRUGO | S_IWUGO,\
278 NULL, NULL, &audio_output_latency_debug_fops);
279 if (IS_ERR(out_dentry))
280 pr_err("debugfs_create_file failed\n");
281 in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
282 in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
283 S_IFREG | S_IRUGO | S_IWUGO,\
284 NULL, NULL, &audio_input_latency_debug_fops);
285 if (IS_ERR(in_dentry))
286 pr_err("debugfs_create_file failed\n");
287}
288#else
289static void config_debug_fs_write(struct audio_buffer *ab)
290{
291 return;
292}
293static void config_debug_fs_run(void)
294{
295 return;
296}
297static void config_debug_fs_reset_index(void)
298{
299 return;
300}
301static void config_debug_fs_read_cb(void)
302{
303 return;
304}
305static void config_debug_fs_write_cb(void)
306{
307 return;
308}
309static void config_debug_fs_init(void)
310{
311 return;
312}
313#endif
314
315
316static int q6asm_session_alloc(struct audio_client *ac)
317{
318 int n;
319 mutex_lock(&session_lock);
320 for (n = 1; n <= SESSION_MAX; n++) {
321 if (!session[n]) {
322 session[n] = ac;
323 mutex_unlock(&session_lock);
324 return n;
325 }
326 }
327 mutex_unlock(&session_lock);
328 return -ENOMEM;
329}
330
331static void q6asm_session_free(struct audio_client *ac)
332{
333 pr_debug("%s: sessionid[%d]\n", __func__, ac->session);
334 rtac_remove_popp_from_adm_devices(ac->session);
335 mutex_lock(&session_lock);
336 session[ac->session] = 0;
337 mutex_unlock(&session_lock);
338 ac->session = 0;
339 return;
340}
341
342int q6asm_audio_client_buf_free(unsigned int dir,
343 struct audio_client *ac)
344{
345 struct audio_port_data *port;
346 int cnt = 0;
347 int rc = 0;
348 pr_debug("%s: Session id %d\n", __func__, ac->session);
349 mutex_lock(&ac->cmd_lock);
350 if (ac->io_mode == SYNC_IO_MODE) {
351 port = &ac->port[dir];
352 if (!port->buf) {
353 mutex_unlock(&ac->cmd_lock);
354 return 0;
355 }
356 cnt = port->max_buf_cnt - 1;
357
358 if (cnt >= 0) {
359 rc = q6asm_memory_unmap_regions(ac, dir,
360 port->buf[0].size,
361 port->max_buf_cnt);
362 if (rc < 0)
363 pr_err("%s CMD Memory_unmap_regions failed\n",
364 __func__);
365 }
366
367 while (cnt >= 0) {
368 if (port->buf[cnt].data) {
369 ion_unmap_kernel(port->buf[cnt].client,
370 port->buf[cnt].handle);
371 ion_free(port->buf[cnt].client,
372 port->buf[cnt].handle);
373 ion_client_destroy(port->buf[cnt].client);
374 port->buf[cnt].data = NULL;
375 port->buf[cnt].phys = 0;
376 --(port->max_buf_cnt);
377 }
378 --cnt;
379 }
380 kfree(port->buf);
381 port->buf = NULL;
382 }
383 mutex_unlock(&ac->cmd_lock);
384 return 0;
385}
386
387int q6asm_audio_client_buf_free_contiguous(unsigned int dir,
388 struct audio_client *ac)
389{
390 struct audio_port_data *port;
391 int cnt = 0;
392 int rc = 0;
393 pr_debug("%s: Session id %d\n", __func__, ac->session);
394 mutex_lock(&ac->cmd_lock);
395 port = &ac->port[dir];
396 if (!port->buf) {
397 mutex_unlock(&ac->cmd_lock);
398 return 0;
399 }
400 cnt = port->max_buf_cnt - 1;
401
402 if (cnt >= 0) {
403 rc = q6asm_memory_unmap(ac, port->buf[0].phys, dir);
404 if (rc < 0)
405 pr_err("%s CMD Memory_unmap_regions failed\n",
406 __func__);
407 }
408
409 if (port->buf[0].data) {
410 ion_unmap_kernel(port->buf[0].client, port->buf[0].handle);
411 ion_free(port->buf[0].client, port->buf[0].handle);
412 ion_client_destroy(port->buf[0].client);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700413 pr_debug("%s:data[%p]phys[%p][%p] , client[%p] handle[%p]\n",
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700414 __func__,
415 (void *)port->buf[0].data,
416 (void *)port->buf[0].phys,
417 (void *)&port->buf[0].phys,
418 (void *)port->buf[0].client,
419 (void *)port->buf[0].handle);
420 }
421
422 while (cnt >= 0) {
423 port->buf[cnt].data = NULL;
424 port->buf[cnt].phys = 0;
425 cnt--;
426 }
427 port->max_buf_cnt = 0;
428 kfree(port->buf);
429 port->buf = NULL;
430 mutex_unlock(&ac->cmd_lock);
431 return 0;
432}
433
434int q6asm_mmap_apr_dereg(void)
435{
436 if (atomic_read(&this_mmap.ref_cnt) <= 0) {
437 pr_err("%s: APR Common Port Already Closed\n", __func__);
438 goto done;
439 }
440 atomic_dec(&this_mmap.ref_cnt);
441 if (atomic_read(&this_mmap.ref_cnt) == 0) {
442 apr_deregister(this_mmap.apr);
443 pr_debug("%s:APR De-Register common port\n", __func__);
444 }
445done:
446 return 0;
447}
448
449
450void q6asm_audio_client_free(struct audio_client *ac)
451{
452 int loopcnt;
453 struct audio_port_data *port;
454 if (!ac || !ac->session)
455 return;
456 pr_debug("%s: Session id %d\n", __func__, ac->session);
457 if (ac->io_mode == SYNC_IO_MODE) {
458 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
459 port = &ac->port[loopcnt];
460 if (!port->buf)
461 continue;
462 pr_debug("%s:loopcnt = %d\n", __func__, loopcnt);
463 q6asm_audio_client_buf_free(loopcnt, ac);
464 }
465 }
466
467 apr_deregister(ac->apr);
468 ac->mmap_apr = NULL;
469 q6asm_session_free(ac);
470 q6asm_mmap_apr_dereg();
471
472 pr_debug("%s: APR De-Register\n", __func__);
473
474/*done:*/
475 kfree(ac);
476 return;
477}
478
479int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode)
480{
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700481 ac->io_mode &= 0xFF00;
482 pr_debug("%s ac->mode after anding with FF00:0x[%x],\n",
483 __func__, ac->io_mode);
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700484 if (ac == NULL) {
485 pr_err("%s APR handle NULL\n", __func__);
486 return -EINVAL;
487 }
488 if ((mode == ASYNC_IO_MODE) || (mode == SYNC_IO_MODE)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700489 ac->io_mode |= mode;
490 pr_debug("%s:Set Mode to 0x[%x]\n", __func__, ac->io_mode);
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700491 return 0;
492 } else {
493 pr_err("%s:Not an valid IO Mode:%d\n", __func__, ac->io_mode);
494 return -EINVAL;
495 }
496}
497
498void *q6asm_mmap_apr_reg(void)
499{
500 if (atomic_read(&this_mmap.ref_cnt) == 0) {
501 this_mmap.apr = apr_register("ADSP", "ASM", \
502 (apr_fn)q6asm_mmapcallback,\
503 0x0FFFFFFFF, &this_mmap);
504 if (this_mmap.apr == NULL) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700505 pr_debug("%s Unable to register APR ASM common port\n",
506 __func__);
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700507 goto fail;
508 }
509 }
510 atomic_inc(&this_mmap.ref_cnt);
511 return this_mmap.apr;
512fail:
513 return NULL;
514}
515
516struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv)
517{
518 struct audio_client *ac;
519 int n;
520 int lcnt = 0;
521
522 ac = kzalloc(sizeof(struct audio_client), GFP_KERNEL);
523 if (!ac)
524 return NULL;
525 n = q6asm_session_alloc(ac);
526 if (n <= 0)
527 goto fail_session;
528 ac->session = n;
529 ac->cb = cb;
530 ac->priv = priv;
531 ac->io_mode = SYNC_IO_MODE;
532 ac->apr = apr_register("ADSP", "ASM", \
533 (apr_fn)q6asm_callback,\
534 ((ac->session) << 8 | 0x0001),\
535 ac);
536
537 if (ac->apr == NULL) {
538 pr_err("%s Registration with APR failed\n", __func__);
539 goto fail;
540 }
541 rtac_set_asm_handle(n, ac->apr);
542
543 pr_debug("%s Registering the common port with APR\n", __func__);
544 ac->mmap_apr = q6asm_mmap_apr_reg();
545 if (ac->mmap_apr == NULL)
546 goto fail;
547
548 init_waitqueue_head(&ac->cmd_wait);
549 INIT_LIST_HEAD(&ac->port[0].mem_map_handle);
550 INIT_LIST_HEAD(&ac->port[1].mem_map_handle);
551 pr_debug("%s: mem_map_handle list init'ed\n", __func__);
552 mutex_init(&ac->cmd_lock);
553 for (lcnt = 0; lcnt <= OUT; lcnt++) {
554 mutex_init(&ac->port[lcnt].lock);
555 spin_lock_init(&ac->port[lcnt].dsp_lock);
556 }
557 atomic_set(&ac->cmd_state, 0);
558
559 pr_debug("%s: session[%d]\n", __func__, ac->session);
560
561 return ac;
562fail:
563 q6asm_audio_client_free(ac);
564 return NULL;
565fail_session:
566 kfree(ac);
567 return NULL;
568}
569
570struct audio_client *q6asm_get_audio_client(int session_id)
571{
572 if ((session_id <= 0) || (session_id > SESSION_MAX)) {
573 pr_err("%s: invalid session: %d\n", __func__, session_id);
574 goto err;
575 }
576
577 if (!session[session_id]) {
578 pr_err("%s: session not active: %d\n", __func__, session_id);
579 goto err;
580 }
581
582 return session[session_id];
583err:
584 return NULL;
585}
586
587int q6asm_audio_client_buf_alloc(unsigned int dir,
588 struct audio_client *ac,
589 unsigned int bufsz,
590 unsigned int bufcnt)
591{
592 int cnt = 0;
593 int rc = 0;
594 struct audio_buffer *buf;
595 int len;
596
597 if (!(ac) || ((dir != IN) && (dir != OUT)))
598 return -EINVAL;
599
600 pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n", __func__, ac->session,
601 bufsz, bufcnt);
602
603 if (ac->session <= 0 || ac->session > 8)
604 goto fail;
605
606 if (ac->io_mode == SYNC_IO_MODE) {
607 if (ac->port[dir].buf) {
608 pr_debug("%s: buffer already allocated\n", __func__);
609 return 0;
610 }
611 mutex_lock(&ac->cmd_lock);
612 buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
613 GFP_KERNEL);
614
615 if (!buf) {
616 mutex_unlock(&ac->cmd_lock);
617 goto fail;
618 }
619
620 ac->port[dir].buf = buf;
621
622 while (cnt < bufcnt) {
623 if (bufsz > 0) {
624 if (!buf[cnt].data) {
625 buf[cnt].client = msm_ion_client_create
626 (UINT_MAX, "audio_client");
627 if (IS_ERR_OR_NULL((void *)
628 buf[cnt].client)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700629 pr_err("%s: ION create client for AUDIO failed\n",
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700630 __func__);
631 goto fail;
632 }
633 buf[cnt].handle = ion_alloc
634 (buf[cnt].client, bufsz, SZ_4K,
Hanumant Singh2ac41c92012-08-29 18:39:44 -0700635 (0x1 << ION_AUDIO_HEAP_ID), 0);
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700636 if (IS_ERR_OR_NULL((void *)
637 buf[cnt].handle)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700638 pr_err("%s: ION memory allocation for AUDIO failed\n",
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700639 __func__);
640 goto fail;
641 }
642
643 rc = ion_phys(buf[cnt].client,
644 buf[cnt].handle,
645 (ion_phys_addr_t *)
646 &buf[cnt].phys,
647 (size_t *)&len);
648 if (rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700649 pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700650 __func__, rc);
651 goto fail;
652 }
653
654 buf[cnt].data = ion_map_kernel
Mitchel Humpherys456e2682012-09-12 14:42:50 -0700655 (buf[cnt].client, buf[cnt].handle);
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700656 if (IS_ERR_OR_NULL((void *)
657 buf[cnt].data)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700658 pr_err("%s: ION memory mapping for AUDIO failed\n",
659 __func__);
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700660 goto fail;
661 }
662 memset((void *)buf[cnt].data, 0, bufsz);
663 buf[cnt].used = 1;
664 buf[cnt].size = bufsz;
665 buf[cnt].actual_size = bufsz;
666 pr_debug("%s data[%p]phys[%p][%p]\n",
667 __func__,
668 (void *)buf[cnt].data,
669 (void *)buf[cnt].phys,
670 (void *)&buf[cnt].phys);
671 cnt++;
672 }
673 }
674 }
675 ac->port[dir].max_buf_cnt = cnt;
676
677 mutex_unlock(&ac->cmd_lock);
678 rc = q6asm_memory_map_regions(ac, dir, bufsz, cnt);
679 if (rc < 0) {
680 pr_err("%s:CMD Memory_map_regions failed\n", __func__);
681 goto fail;
682 }
683 }
684 return 0;
685fail:
686 q6asm_audio_client_buf_free(dir, ac);
687 return -EINVAL;
688}
689
690int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir,
691 struct audio_client *ac,
692 unsigned int bufsz,
693 unsigned int bufcnt)
694{
695 int cnt = 0;
696 int rc = 0;
697 struct audio_buffer *buf;
698 int len;
699
700 if (!(ac) || ((dir != IN) && (dir != OUT)))
701 return -EINVAL;
702
703 pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n",
704 __func__, ac->session,
705 bufsz, bufcnt);
706
707 if (ac->session <= 0 || ac->session > 8)
708 goto fail;
709
710 if (ac->port[dir].buf) {
711 pr_debug("%s: buffer already allocated\n", __func__);
712 return 0;
713 }
714 mutex_lock(&ac->cmd_lock);
715 buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
716 GFP_KERNEL);
717
718 if (!buf) {
719 mutex_unlock(&ac->cmd_lock);
720 goto fail;
721 }
722
723 ac->port[dir].buf = buf;
724
725 buf[0].client = msm_ion_client_create(UINT_MAX, "audio_client");
726 if (IS_ERR_OR_NULL((void *)buf[0].client)) {
727 pr_err("%s: ION create client for AUDIO failed\n", __func__);
728 goto fail;
729 }
730 buf[0].handle = ion_alloc(buf[0].client, bufsz * bufcnt, SZ_4K,
Hanumant Singh2ac41c92012-08-29 18:39:44 -0700731 (0x1 << ION_AUDIO_HEAP_ID), 0);
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700732 if (IS_ERR_OR_NULL((void *) buf[0].handle)) {
733 pr_err("%s: ION memory allocation for AUDIO failed\n",
734 __func__);
735 goto fail;
736 }
737
738 rc = ion_phys(buf[0].client, buf[0].handle,
739 (ion_phys_addr_t *)&buf[0].phys, (size_t *)&len);
740 if (rc) {
741 pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
742 __func__, rc);
743 goto fail;
744 }
745
Mitchel Humpherys456e2682012-09-12 14:42:50 -0700746 buf[0].data = ion_map_kernel(buf[0].client, buf[0].handle);
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700747 if (IS_ERR_OR_NULL((void *) buf[0].data)) {
748 pr_err("%s: ION memory mapping for AUDIO failed\n", __func__);
749 goto fail;
750 }
751 memset((void *)buf[0].data, 0, (bufsz * bufcnt));
752 if (!buf[0].data) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700753 pr_err("%s:invalid vaddr, iomap failed\n", __func__);
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700754 mutex_unlock(&ac->cmd_lock);
755 goto fail;
756 }
757
758 buf[0].used = dir ^ 1;
759 buf[0].size = bufsz;
760 buf[0].actual_size = bufsz;
761 cnt = 1;
762 while (cnt < bufcnt) {
763 if (bufsz > 0) {
764 buf[cnt].data = buf[0].data + (cnt * bufsz);
765 buf[cnt].phys = buf[0].phys + (cnt * bufsz);
766 if (!buf[cnt].data) {
767 pr_err("%s Buf alloc failed\n",
768 __func__);
769 mutex_unlock(&ac->cmd_lock);
770 goto fail;
771 }
772 buf[cnt].used = dir ^ 1;
773 buf[cnt].size = bufsz;
774 buf[cnt].actual_size = bufsz;
775 pr_debug("%s data[%p]phys[%p][%p]\n", __func__,
776 (void *)buf[cnt].data,
777 (void *)buf[cnt].phys,
778 (void *)&buf[cnt].phys);
779 }
780 cnt++;
781 }
782 ac->port[dir].max_buf_cnt = cnt;
783 mutex_unlock(&ac->cmd_lock);
784 rc = q6asm_memory_map_regions(ac, dir, bufsz, cnt);
785 if (rc < 0) {
786 pr_err("%s:CMD Memory_map_regions failed\n", __func__);
787 goto fail;
788 }
789 return 0;
790fail:
791 q6asm_audio_client_buf_free_contiguous(dir, ac);
792 return -EINVAL;
793}
794
795static int32_t q6asm_mmapcallback(struct apr_client_data *data, void *priv)
796{
797 uint32_t sid = 0;
798 uint32_t dir = 0;
799 uint32_t *payload = data->payload;
800 unsigned long dsp_flags;
801
802 struct audio_client *ac = NULL;
803 struct audio_port_data *port;
804
805 if (!data) {
806 pr_err("%s: Invalid CB\n", __func__);
807 return 0;
808 }
809 if (data->opcode == RESET_EVENTS) {
810 pr_debug("%s: Reset event is received: %d %d apr[%p]\n",
811 __func__,
812 data->reset_event,
813 data->reset_proc,
814 this_mmap.apr);
815 apr_reset(this_mmap.apr);
816 atomic_set(&this_mmap.ref_cnt, 0);
817 this_mmap.apr = NULL;
818 return 0;
819 }
820 sid = (data->token >> 8) & 0x0F;
821 ac = q6asm_get_audio_client(sid);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700822 pr_debug("%s:ptr0[0x%x]ptr1[0x%x]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]sid[%d]dir[%d]\n",
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700823 __func__, payload[0], payload[1], data->opcode, data->token,
824 data->payload_size, data->src_port, data->dest_port, sid, dir);
825 pr_debug("%s:Payload = [0x%x] status[0x%x]\n",
826 __func__, payload[0], payload[1]);
827
828 if (data->opcode == APR_BASIC_RSP_RESULT) {
829 switch (payload[0]) {
830 case ASM_CMD_SHARED_MEM_MAP_REGIONS:
831 case ASM_CMD_SHARED_MEM_UNMAP_REGIONS:
832 if (atomic_read(&ac->cmd_state)) {
833 atomic_set(&ac->cmd_state, 0);
834 wake_up(&ac->cmd_wait);
835 }
836 pr_debug("%s:Payload = [0x%x] status[0x%x]\n",
837 __func__, payload[0], payload[1]);
838 break;
839 default:
840 pr_debug("%s:command[0x%x] not expecting rsp\n",
841 __func__, payload[0]);
842 break;
843 }
844 return 0;
845 }
846
847 dir = (data->token & 0x0F);
848 port = &ac->port[dir];
849
850 switch (data->opcode) {
851 case ASM_CMDRSP_SHARED_MEM_MAP_REGIONS:{
852 pr_debug("%s:PL#0[0x%x]PL#1 [0x%x] dir=%x s_id=%x\n",
853 __func__, payload[0], payload[1], dir, sid);
854 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
855 if (atomic_read(&ac->cmd_state)) {
856 ac->port[dir].tmp_hdl = payload[0];
857 atomic_set(&ac->cmd_state, 0);
858 wake_up(&ac->cmd_wait);
859 }
860 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
861 break;
862 }
863 case ASM_CMD_SHARED_MEM_UNMAP_REGIONS:{
864 pr_debug("%s:PL#0[0x%x]PL#1 [0x%x]\n",
865 __func__, payload[0], payload[1]);
866 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
867 if (atomic_read(&ac->cmd_state)) {
868 atomic_set(&ac->cmd_state, 0);
869 wake_up(&ac->cmd_wait);
870 }
871 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
872
873 break;
874 }
875 default:
876 pr_debug("%s:command[0x%x]success [0x%x]\n",
877 __func__, payload[0], payload[1]);
878 }
879 if (ac->cb)
880 ac->cb(data->opcode, data->token,
881 data->payload, ac->priv);
882 return 0;
883}
884
885
886static int32_t q6asm_callback(struct apr_client_data *data, void *priv)
887{
888 int i = 0;
889 struct audio_client *ac = (struct audio_client *)priv;
890 uint32_t token;
891 unsigned long dsp_flags;
892 uint32_t *payload;
893
894
895 if ((ac == NULL) || (data == NULL)) {
896 pr_err("ac or priv NULL\n");
897 return -EINVAL;
898 }
899 if (ac->session <= 0 || ac->session > 8) {
900 pr_err("%s:Session ID is invalid, session = %d\n", __func__,
901 ac->session);
902 return -EINVAL;
903 }
904
905 payload = data->payload;
906
907 if (data->opcode == RESET_EVENTS) {
908 pr_debug("q6asm_callback: Reset event is received: %d %d apr[%p]\n",
909 data->reset_event, data->reset_proc, ac->apr);
910 if (ac->cb)
911 ac->cb(data->opcode, data->token,
912 (uint32_t *)data->payload, ac->priv);
913 apr_reset(ac->apr);
914 return 0;
915 }
916
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700917 pr_debug("%s: session[%d]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n",
918 __func__,
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -0700919 ac->session, data->opcode,
920 data->token, data->payload_size, data->src_port,
921 data->dest_port);
922 if ((data->opcode != ASM_DATA_EVENT_RENDERED_EOS) &&
923 (data->opcode != ASM_DATA_EVENT_EOS))
924 pr_debug("%s:Payload = [0x%x] status[0x%x]\n",
925 __func__, payload[0], payload[1]);
926 if (data->opcode == APR_BASIC_RSP_RESULT) {
927 token = data->token;
928 switch (payload[0]) {
929 case ASM_STREAM_CMD_SET_PP_PARAMS_V2:
930 if (rtac_make_asm_callback(ac->session, payload,
931 data->payload_size))
932 break;
933 case ASM_SESSION_CMD_PAUSE:
934 case ASM_DATA_CMD_EOS:
935 case ASM_STREAM_CMD_CLOSE:
936 case ASM_STREAM_CMD_FLUSH:
937 case ASM_SESSION_CMD_RUN_V2:
938 case ASM_SESSION_CMD_REGISTER_FORX_OVERFLOW_EVENTS:
939 case ASM_STREAM_CMD_FLUSH_READBUFS:
940 pr_debug("%s:Payload = [0x%x]\n", __func__, payload[0]);
941 if (token != ac->session) {
942 pr_err("%s:Invalid session[%d] rxed expected[%d]",
943 __func__, token, ac->session);
944 return -EINVAL;
945 }
946 case ASM_STREAM_CMD_OPEN_READ_V2:
947 case ASM_STREAM_CMD_OPEN_WRITE_V2:
948 case ASM_STREAM_CMD_OPEN_READWRITE_V2:
949 case ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2:
950 case ASM_STREAM_CMD_SET_ENCDEC_PARAM:
951 pr_debug("%s:Payload = [0x%x]stat[0x%x]\n",
952 __func__, payload[0], payload[1]);
953 if (atomic_read(&ac->cmd_state)) {
954 atomic_set(&ac->cmd_state, 0);
955 wake_up(&ac->cmd_wait);
956 }
957 if (ac->cb)
958 ac->cb(data->opcode, data->token,
959 (uint32_t *)data->payload, ac->priv);
960 break;
961 default:
962 pr_debug("%s:command[0x%x] not expecting rsp\n",
963 __func__, payload[0]);
964 break;
965 }
966 return 0;
967 }
968
969 switch (data->opcode) {
970 case ASM_DATA_EVENT_WRITE_DONE_V2:{
971 struct audio_port_data *port = &ac->port[IN];
972 pr_debug("%s: Rxed opcode[0x%x] status[0x%x] token[%d]",
973 __func__, payload[0], payload[1],
974 data->token);
975 if (ac->io_mode == SYNC_IO_MODE) {
976 if (port->buf == NULL) {
977 pr_err("%s: Unexpected Write Done\n",
978 __func__);
979 return -EINVAL;
980 }
981 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
982 if (port->buf[data->token].phys !=
983 payload[0]) {
984 pr_err("Buf expected[%p]rxed[%p]\n",\
985 (void *)port->buf[data->token].phys,\
986 (void *)payload[0]);
987 spin_unlock_irqrestore(&port->dsp_lock,
988 dsp_flags);
989 return -EINVAL;
990 }
991 token = data->token;
992 port->buf[token].used = 1;
993 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
994
995 config_debug_fs_write_cb();
996
997 for (i = 0; i < port->max_buf_cnt; i++)
998 pr_debug("%d ", port->buf[i].used);
999
1000 }
1001 break;
1002 }
1003 case ASM_STREAM_CMDRSP_GET_PP_PARAMS_V2:
1004 rtac_make_asm_callback(ac->session, payload,
1005 data->payload_size);
1006 break;
1007 case ASM_DATA_EVENT_READ_DONE_V2:{
1008
1009 struct audio_port_data *port = &ac->port[OUT];
1010
1011 config_debug_fs_read_cb();
1012
1013 pr_debug("%s:R-D: status=%d buff_add=%x act_size=%d offset=%d\n",
1014 __func__, payload[READDONE_IDX_STATUS],
1015 payload[READDONE_IDX_BUFADD_LSW],
1016 payload[READDONE_IDX_SIZE],
1017 payload[READDONE_IDX_OFFSET]);
1018
1019 pr_debug("%s:R-D:msw_ts=%d lsw_ts=%d memmap_hdl=%x flags=%d id=%d num=%d\n",
1020 __func__, payload[READDONE_IDX_MSW_TS],
1021 payload[READDONE_IDX_LSW_TS],
1022 payload[READDONE_IDX_MEMMAP_HDL],
1023 payload[READDONE_IDX_FLAGS],
1024 payload[READDONE_IDX_SEQ_ID],
1025 payload[READDONE_IDX_NUMFRAMES]);
1026
1027 if (ac->io_mode == SYNC_IO_MODE) {
1028 if (port->buf == NULL) {
1029 pr_err("%s: Unexpected Write Done\n", __func__);
1030 return -EINVAL;
1031 }
1032 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
1033 token = data->token;
1034 port->buf[token].used = 0;
1035 if (port->buf[token].phys !=
1036 payload[READDONE_IDX_BUFADD_LSW]) {
1037 pr_err("Buf expected[%p]rxed[%p]\n",\
1038 (void *)port->buf[token].phys,\
1039 (void *)payload[READDONE_IDX_BUFADD_LSW]);
1040 spin_unlock_irqrestore(&port->dsp_lock,
1041 dsp_flags);
1042 break;
1043 }
1044 port->buf[token].actual_size =
1045 payload[READDONE_IDX_SIZE];
1046 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
1047 }
1048 break;
1049 }
1050 case ASM_DATA_EVENT_EOS:
1051 case ASM_DATA_EVENT_RENDERED_EOS:
1052 pr_debug("%s:EOS ACK received: rxed opcode[0x%x]\n",
1053 __func__, data->opcode);
1054 break;
1055 case ASM_SESSION_EVENTX_OVERFLOW:
1056 pr_err("ASM_SESSION_EVENTX_OVERFLOW\n");
1057 break;
1058 case ASM_SESSION_CMDRSP_GET_SESSIONTIME_V3:
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001059 pr_debug("%s: ASM_SESSION_CMDRSP_GET_SESSIONTIME_V3, payload[0] = %d, payload[1] = %d, payload[2] = %d\n",
1060 __func__,
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07001061 payload[0], payload[1], payload[2]);
Harmandeep Singh1b712ec2012-08-31 16:28:38 -07001062 ac->time_stamp = (uint64_t)(((uint64_t)payload[2] << 32) |
1063 payload[1]);
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07001064 if (atomic_read(&ac->cmd_state)) {
1065 atomic_set(&ac->cmd_state, 0);
1066 wake_up(&ac->cmd_wait);
1067 }
1068 break;
1069 case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY:
1070 case ASM_DATA_EVENT_ENC_SR_CM_CHANGE_NOTIFY:
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001071 pr_debug("%s: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, payload[0] = %d, payload[1] = %d, payload[2] = %d, payload[3] = %d\n",
1072 __func__,
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07001073 payload[0], payload[1], payload[2],
1074 payload[3]);
1075 break;
1076 }
1077 if (ac->cb)
1078 ac->cb(data->opcode, data->token,
1079 data->payload, ac->priv);
1080
1081 return 0;
1082}
1083
1084void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac, uint32_t *size,
1085 uint32_t *index)
1086{
1087 void *data;
1088 unsigned char idx;
1089 struct audio_port_data *port;
1090
1091 if (!ac || ((dir != IN) && (dir != OUT)))
1092 return NULL;
1093
1094 if (ac->io_mode == SYNC_IO_MODE) {
1095 port = &ac->port[dir];
1096
1097 mutex_lock(&port->lock);
1098 idx = port->cpu_buf;
1099 if (port->buf == NULL) {
1100 pr_debug("%s:Buffer pointer null\n", __func__);
1101 mutex_unlock(&port->lock);
1102 return NULL;
1103 }
1104 /* dir 0: used = 0 means buf in use
1105 dir 1: used = 1 means buf in use */
1106 if (port->buf[idx].used == dir) {
1107 /* To make it more robust, we could loop and get the
1108 next avail buf, its risky though */
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001109 pr_debug("%s:Next buf idx[0x%x] not available, dir[%d]\n",
1110 __func__, idx, dir);
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07001111 mutex_unlock(&port->lock);
1112 return NULL;
1113 }
1114 *size = port->buf[idx].actual_size;
1115 *index = port->cpu_buf;
1116 data = port->buf[idx].data;
1117 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1118 __func__,
1119 ac->session,
1120 port->cpu_buf,
1121 data, *size);
1122 /* By default increase the cpu_buf cnt
1123 user accesses this function,increase cpu
1124 buf(to avoid another api)*/
1125 port->buf[idx].used = dir;
1126 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1127 mutex_unlock(&port->lock);
1128 return data;
1129 }
1130 return NULL;
1131}
1132
1133void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
1134 uint32_t *size, uint32_t *index)
1135{
1136 void *data;
1137 unsigned char idx;
1138 struct audio_port_data *port;
1139
1140 if (!ac || ((dir != IN) && (dir != OUT)))
1141 return NULL;
1142
1143 port = &ac->port[dir];
1144
1145 idx = port->cpu_buf;
1146 if (port->buf == NULL) {
1147 pr_debug("%s:Buffer pointer null\n", __func__);
1148 return NULL;
1149 }
1150 /*
1151 * dir 0: used = 0 means buf in use
1152 * dir 1: used = 1 means buf in use
1153 */
1154 if (port->buf[idx].used == dir) {
1155 /*
1156 * To make it more robust, we could loop and get the
1157 * next avail buf, its risky though
1158 */
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001159 pr_debug("%s:Next buf idx[0x%x] not available, dir[%d]\n",
1160 __func__, idx, dir);
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07001161 return NULL;
1162 }
1163 *size = port->buf[idx].actual_size;
1164 *index = port->cpu_buf;
1165 data = port->buf[idx].data;
1166 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1167 __func__, ac->session, port->cpu_buf,
1168 data, *size);
1169 /*
1170 * By default increase the cpu_buf cnt
1171 * user accesses this function,increase cpu
1172 * buf(to avoid another api)
1173 */
1174 port->buf[idx].used = dir;
1175 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1176 return data;
1177}
1178
1179int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac)
1180{
1181 int ret = -1;
1182 struct audio_port_data *port;
1183 uint32_t idx;
1184
1185 if (!ac || (dir != OUT))
1186 return ret;
1187
1188 if (ac->io_mode == SYNC_IO_MODE) {
1189 port = &ac->port[dir];
1190
1191 mutex_lock(&port->lock);
1192 idx = port->dsp_buf;
1193
1194 if (port->buf[idx].used == (dir ^ 1)) {
1195 /* To make it more robust, we could loop and get the
1196 next avail buf, its risky though */
1197 pr_err("Next buf idx[0x%x] not available, dir[%d]\n",
1198 idx, dir);
1199 mutex_unlock(&port->lock);
1200 return ret;
1201 }
1202 pr_debug("%s: session[%d]dsp_buf=%d cpu_buf=%d\n", __func__,
1203 ac->session, port->dsp_buf, port->cpu_buf);
1204 ret = ((port->dsp_buf != port->cpu_buf) ? 0 : -1);
1205 mutex_unlock(&port->lock);
1206 }
1207 return ret;
1208}
1209
1210static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
1211 uint32_t pkt_size, uint32_t cmd_flg)
1212{
1213 pr_debug("%s:pkt_size=%d cmd_flg=%d session=%d\n", __func__, pkt_size,
1214 cmd_flg, ac->session);
1215 mutex_lock(&ac->cmd_lock);
1216 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1217 APR_HDR_LEN(sizeof(struct apr_hdr)),\
1218 APR_PKT_VER);
1219 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
1220 hdr->src_domain = APR_DOMAIN_APPS;
1221 hdr->dest_svc = APR_SVC_ASM;
1222 hdr->dest_domain = APR_DOMAIN_ADSP;
1223 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
1224 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
1225 if (cmd_flg) {
1226 hdr->token = ac->session;
1227 atomic_set(&ac->cmd_state, 1);
1228 }
1229 hdr->pkt_size = pkt_size;
1230 mutex_unlock(&ac->cmd_lock);
1231 return;
1232}
1233
1234static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
1235 uint32_t pkt_size, uint32_t cmd_flg)
1236{
1237 pr_debug("pkt_size = %d, cmd_flg = %d, session = %d\n",
1238 pkt_size, cmd_flg, ac->session);
1239 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1240 APR_HDR_LEN(sizeof(struct apr_hdr)),\
1241 APR_PKT_VER);
1242 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
1243 hdr->src_domain = APR_DOMAIN_APPS;
1244 hdr->dest_svc = APR_SVC_ASM;
1245 hdr->dest_domain = APR_DOMAIN_ADSP;
1246 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
1247 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
1248 if (cmd_flg) {
1249 hdr->token = ac->session;
1250 atomic_set(&ac->cmd_state, 1);
1251 }
1252 hdr->pkt_size = pkt_size;
1253 return;
1254}
1255
1256static void q6asm_add_mmaphdr(struct audio_client *ac, struct apr_hdr *hdr,
1257 u32 pkt_size, u32 cmd_flg, u32 token)
1258{
1259 pr_debug("%s:pkt size=%d cmd_flg=%d\n", __func__, pkt_size, cmd_flg);
1260 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1261 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1262 hdr->src_port = 0;
1263 hdr->dest_port = 0;
1264 if (cmd_flg) {
1265 hdr->token = token;
1266 atomic_set(&ac->cmd_state, 1);
1267 }
1268 hdr->pkt_size = pkt_size;
1269 return;
1270}
1271int q6asm_open_read(struct audio_client *ac,
1272 uint32_t format)
1273{
1274 int rc = 0x00;
1275 struct asm_stream_cmd_open_read_v2 open;
1276
1277 uint16_t bits_per_sample = 16;
1278
1279
1280 config_debug_fs_reset_index();
1281
1282 if ((ac == NULL) || (ac->apr == NULL)) {
1283 pr_err("%s: APR handle NULL\n", __func__);
1284 return -EINVAL;
1285 }
1286 pr_debug("%s:session[%d]", __func__, ac->session);
1287
1288 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1289 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_V2;
1290 /* Stream prio : High, provide meta info with encoded frames */
1291 open.src_endpointype = ASM_END_POINT_DEVICE_MATRIX;
1292
1293 open.preprocopo_id = get_asm_topology();
1294 if (open.preprocopo_id == 0)
1295 open.preprocopo_id = ASM_STREAM_POSTPROC_TOPO_ID_DEFAULT;
1296 open.bits_per_sample = bits_per_sample;
1297
1298 switch (format) {
1299 case FORMAT_LINEAR_PCM:
1300 open.mode_flags = 0x00;
1301 open.enc_cfg_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V2;
1302 break;
1303 case FORMAT_MPEG4_AAC:
1304 open.mode_flags = BUFFER_META_ENABLE;
1305 open.enc_cfg_id = ASM_MEDIA_FMT_AAC_V2;
1306 break;
1307 case FORMAT_V13K:
1308 open.mode_flags = BUFFER_META_ENABLE;
1309 open.enc_cfg_id = ASM_MEDIA_FMT_V13K_FS;
1310 break;
1311 case FORMAT_EVRC:
1312 open.mode_flags = BUFFER_META_ENABLE;
1313 open.enc_cfg_id = ASM_MEDIA_FMT_EVRC_FS;
1314 break;
1315 case FORMAT_AMRNB:
1316 open.mode_flags = BUFFER_META_ENABLE ;
1317 open.enc_cfg_id = ASM_MEDIA_FMT_AMRNB_FS;
1318 break;
1319 case FORMAT_AMRWB:
1320 open.mode_flags = BUFFER_META_ENABLE ;
1321 open.enc_cfg_id = ASM_MEDIA_FMT_AMRWB_FS;
1322 break;
1323 default:
1324 pr_err("Invalid format[%d]\n", format);
1325 goto fail_cmd;
1326 }
1327 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1328 if (rc < 0) {
1329 pr_err("open failed op[0x%x]rc[%d]\n", \
1330 open.hdr.opcode, rc);
1331 goto fail_cmd;
1332 }
1333 rc = wait_event_timeout(ac->cmd_wait,
1334 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1335 if (!rc) {
1336 pr_err("%s: timeout. waited for open read rc[%d]\n", __func__,
1337 rc);
1338 goto fail_cmd;
1339 }
1340 return 0;
1341fail_cmd:
1342 return -EINVAL;
1343}
1344int q6asm_open_write(struct audio_client *ac, uint32_t format)
1345{
1346 int rc = 0x00;
1347 struct asm_stream_cmd_open_write_v2 open;
1348
1349 if ((ac == NULL) || (ac->apr == NULL)) {
1350 pr_err("%s: APR handle NULL\n", __func__);
1351 return -EINVAL;
1352 }
1353 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1354 format);
1355
1356 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1357
1358 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_V2;
1359 open.mode_flags = 0x00;
1360 /* source endpoint : matrix */
1361 open.sink_endpointype = ASM_END_POINT_DEVICE_MATRIX;
1362 open.bits_per_sample = 16;
1363
1364 open.postprocopo_id = get_asm_topology();
1365 if (open.postprocopo_id == 0)
1366 open.postprocopo_id = ASM_STREAM_POSTPROC_TOPO_ID_DEFAULT;
1367
1368 switch (format) {
1369 case FORMAT_LINEAR_PCM:
1370 open.dec_fmt_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V2;
1371 break;
1372 case FORMAT_MPEG4_AAC:
1373 open.dec_fmt_id = ASM_MEDIA_FMT_AAC_V2;
1374 break;
1375 case FORMAT_MPEG4_MULTI_AAC:
1376 open.dec_fmt_id = ASM_MEDIA_FMT_DOLBY_AAC;
1377 break;
1378 case FORMAT_WMA_V9:
1379 open.dec_fmt_id = ASM_MEDIA_FMT_WMA_V9_V2;
1380 break;
1381 case FORMAT_WMA_V10PRO:
1382 open.dec_fmt_id = ASM_MEDIA_FMT_WMA_V10PRO_V2;
1383 break;
1384 case FORMAT_MP3:
1385 open.dec_fmt_id = ASM_MEDIA_FMT_MP3;
1386 break;
1387 default:
1388 pr_err("%s: Invalid format[%d]\n", __func__, format);
1389 goto fail_cmd;
1390 }
1391 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1392 if (rc < 0) {
1393 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1394 __func__, open.hdr.opcode, rc);
1395 goto fail_cmd;
1396 }
1397 rc = wait_event_timeout(ac->cmd_wait,
1398 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1399 if (!rc) {
1400 pr_err("%s: timeout. waited for open write rc[%d]\n", __func__,
1401 rc);
1402 goto fail_cmd;
1403 }
1404 return 0;
1405fail_cmd:
1406 return -EINVAL;
1407}
1408
1409int q6asm_open_read_write(struct audio_client *ac,
1410 uint32_t rd_format,
1411 uint32_t wr_format)
1412{
1413 int rc = 0x00;
1414 struct asm_stream_cmd_open_readwrite_v2 open;
1415
1416 if ((ac == NULL) || (ac->apr == NULL)) {
1417 pr_err("APR handle NULL\n");
1418 return -EINVAL;
1419 }
1420 pr_debug("%s: session[%d]", __func__, ac->session);
1421 pr_debug("wr_format[0x%x]rd_format[0x%x]",
1422 wr_format, rd_format);
1423
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001424 ac->io_mode |= NT_MODE;
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07001425 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1426 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE_V2;
1427
1428 open.mode_flags = BUFFER_META_ENABLE;
1429 open.bits_per_sample = 16;
1430 /* source endpoint : matrix */
1431 open.postprocopo_id = get_asm_topology();
1432 if (open.postprocopo_id == 0)
1433 open.postprocopo_id = ASM_STREAM_POSTPROC_TOPO_ID_DEFAULT;
1434
1435 switch (wr_format) {
1436 case FORMAT_LINEAR_PCM:
1437 open.dec_fmt_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V2;
1438 break;
1439 case FORMAT_MPEG4_AAC:
1440 open.dec_fmt_id = ASM_MEDIA_FMT_AAC_V2;
1441 break;
1442 case FORMAT_MPEG4_MULTI_AAC:
1443 open.dec_fmt_id = ASM_MEDIA_FMT_DOLBY_AAC;
1444 break;
1445 case FORMAT_WMA_V9:
1446 open.dec_fmt_id = ASM_MEDIA_FMT_WMA_V9_V2;
1447 break;
1448 case FORMAT_WMA_V10PRO:
1449 open.dec_fmt_id = ASM_MEDIA_FMT_WMA_V10PRO_V2;
1450 break;
1451 case FORMAT_AMRNB:
1452 open.dec_fmt_id = ASM_MEDIA_FMT_AMRNB_FS;
1453 break;
1454 case FORMAT_AMRWB:
1455 open.dec_fmt_id = ASM_MEDIA_FMT_AMRWB_FS;
1456 break;
1457 case FORMAT_V13K:
1458 open.dec_fmt_id = ASM_MEDIA_FMT_V13K_FS;
1459 break;
1460 case FORMAT_EVRC:
1461 open.dec_fmt_id = ASM_MEDIA_FMT_EVRC_FS;
1462 break;
1463 case FORMAT_EVRCB:
1464 open.dec_fmt_id = ASM_MEDIA_FMT_EVRCB_FS;
1465 break;
1466 case FORMAT_EVRCWB:
1467 open.dec_fmt_id = ASM_MEDIA_FMT_EVRCWB_FS;
1468 break;
1469 case FORMAT_MP3:
1470 open.dec_fmt_id = ASM_MEDIA_FMT_MP3;
1471 break;
1472 default:
1473 pr_err("Invalid format[%d]\n", wr_format);
1474 goto fail_cmd;
1475 }
1476
1477 switch (rd_format) {
1478 case FORMAT_LINEAR_PCM:
1479 open.enc_cfg_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V2;
1480 break;
1481 case FORMAT_MPEG4_AAC:
1482 open.enc_cfg_id = ASM_MEDIA_FMT_AAC_V2;
1483 break;
1484 case FORMAT_V13K:
1485 open.enc_cfg_id = ASM_MEDIA_FMT_V13K_FS;
1486 break;
1487 case FORMAT_EVRC:
1488 open.enc_cfg_id = ASM_MEDIA_FMT_EVRC_FS;
1489 break;
1490 case FORMAT_AMRNB:
1491 open.enc_cfg_id = ASM_MEDIA_FMT_AMRNB_FS;
1492 break;
1493 case FORMAT_AMRWB:
1494 open.enc_cfg_id = ASM_MEDIA_FMT_AMRWB_FS;
1495 break;
1496 default:
1497 pr_err("Invalid format[%d]\n", rd_format);
1498 goto fail_cmd;
1499 }
1500 pr_debug("%s:rdformat[0x%x]wrformat[0x%x]\n", __func__,
1501 open.enc_cfg_id, open.dec_fmt_id);
1502
1503 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1504 if (rc < 0) {
1505 pr_err("open failed op[0x%x]rc[%d]\n", \
1506 open.hdr.opcode, rc);
1507 goto fail_cmd;
1508 }
1509 rc = wait_event_timeout(ac->cmd_wait,
1510 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1511 if (!rc) {
1512 pr_err("timeout. waited for open read-write rc[%d]\n", rc);
1513 goto fail_cmd;
1514 }
1515 return 0;
1516fail_cmd:
1517 return -EINVAL;
1518}
1519
1520int q6asm_run(struct audio_client *ac, uint32_t flags,
1521 uint32_t msw_ts, uint32_t lsw_ts)
1522{
1523 struct asm_session_cmd_run_v2 run;
1524 int rc;
1525 if (!ac || ac->apr == NULL) {
1526 pr_err("APR handle NULL\n");
1527 return -EINVAL;
1528 }
1529 pr_debug("%s session[%d]", __func__, ac->session);
1530 q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
1531
1532 run.hdr.opcode = ASM_SESSION_CMD_RUN_V2;
1533 run.flags = flags;
1534 run.time_lsw = lsw_ts;
1535 run.time_msw = msw_ts;
1536
1537 config_debug_fs_run();
1538
1539 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1540 if (rc < 0) {
1541 pr_err("Commmand run failed[%d]", rc);
1542 goto fail_cmd;
1543 }
1544
1545 rc = wait_event_timeout(ac->cmd_wait,
1546 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1547 if (!rc) {
1548 pr_err("timeout. waited for run success rc[%d]", rc);
1549 goto fail_cmd;
1550 }
1551
1552 return 0;
1553fail_cmd:
1554 return -EINVAL;
1555}
1556
1557int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
1558 uint32_t msw_ts, uint32_t lsw_ts)
1559{
1560 struct asm_session_cmd_run_v2 run;
1561 int rc;
1562 if (!ac || ac->apr == NULL) {
1563 pr_err("%s:APR handle NULL\n", __func__);
1564 return -EINVAL;
1565 }
1566 pr_debug("session[%d]", ac->session);
1567 q6asm_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE);
1568
1569 run.hdr.opcode = ASM_SESSION_CMD_RUN_V2;
1570 run.flags = flags;
1571 run.time_lsw = lsw_ts;
1572 run.time_msw = msw_ts;
1573
1574 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1575 if (rc < 0) {
1576 pr_err("%s:Commmand run failed[%d]", __func__, rc);
1577 return -EINVAL;
1578 }
1579 return 0;
1580}
1581
1582
1583int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
1584 uint32_t frames_per_buf,
1585 uint32_t sample_rate, uint32_t channels,
1586 uint32_t bit_rate, uint32_t mode, uint32_t format)
1587{
1588 struct asm_aac_enc_cfg_v2 enc_cfg;
1589 int rc = 0;
1590
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001591 pr_debug("%s:session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d] format[%d]",
1592 __func__, ac->session, frames_per_buf,
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07001593 sample_rate, channels, bit_rate, mode, format);
1594
1595 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1596
1597 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1598 enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
1599 enc_cfg.encdec.param_size = sizeof(struct asm_aac_enc_cfg_v2) -
1600 sizeof(struct asm_stream_cmd_set_encdec_param);
1601 enc_cfg.encblk.frames_per_buf = frames_per_buf;
1602 enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
1603 sizeof(struct asm_enc_cfg_blk_param_v2);
1604 enc_cfg.bit_rate = bit_rate;
1605 enc_cfg.enc_mode = mode;
1606 enc_cfg.aac_fmt_flag = format;
1607 enc_cfg.channel_cfg = channels;
1608 enc_cfg.sample_rate = sample_rate;
1609
1610 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1611 if (rc < 0) {
1612 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1613 rc = -EINVAL;
1614 goto fail_cmd;
1615 }
1616 rc = wait_event_timeout(ac->cmd_wait,
1617 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1618 if (!rc) {
1619 pr_err("timeout. waited for FORMAT_UPDATE\n");
1620 goto fail_cmd;
1621 }
1622 return 0;
1623fail_cmd:
1624 return -EINVAL;
1625}
1626
1627int q6asm_set_encdec_chan_map(struct audio_client *ac,
1628 uint32_t num_channels)
1629{
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001630 struct asm_dec_out_chan_map_param chan_map;
1631 u8 *channel_mapping;
1632 int rc = 0;
1633 pr_debug("%s: Session %d, num_channels = %d\n",
1634 __func__, ac->session, num_channels);
1635 q6asm_add_hdr(ac, &chan_map.hdr, sizeof(chan_map), TRUE);
1636 chan_map.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1637 chan_map.encdec.param_id = ASM_PARAM_ID_DEC_OUTPUT_CHAN_MAP;
1638 chan_map.encdec.param_size = sizeof(struct asm_dec_out_chan_map_param) -
1639 (sizeof(struct apr_hdr) +
1640 sizeof(struct asm_stream_cmd_set_encdec_param));
1641 chan_map.num_channels = num_channels;
1642 channel_mapping = chan_map.channel_mapping;
1643 memset(channel_mapping, PCM_CHANNEL_NULL, MAX_CHAN_MAP_CHANNELS);
1644 if (q6asm_map_channels(channel_mapping, num_channels))
1645 return -EINVAL;
1646
1647 rc = apr_send_pkt(ac->apr, (uint32_t *) &chan_map);
1648 if (rc < 0) {
1649 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
1650 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1651 ASM_PARAM_ID_DEC_OUTPUT_CHAN_MAP);
1652 goto fail_cmd;
1653 }
1654 rc = wait_event_timeout(ac->cmd_wait,
1655 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1656 if (!rc) {
1657 pr_err("%s:timeout opcode[0x%x]\n", __func__,
1658 chan_map.hdr.opcode);
1659 rc = -ETIMEDOUT;
1660 goto fail_cmd;
1661 }
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07001662 return 0;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001663fail_cmd:
1664 return rc;
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07001665}
1666
1667int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
1668 uint32_t rate, uint32_t channels)
1669{
1670 struct asm_multi_channel_pcm_enc_cfg_v2 enc_cfg;
1671 u8 *channel_mapping;
1672 u32 frames_per_buf = 0;
1673
1674 int rc = 0;
1675
1676 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1677 ac->session, rate, channels);
1678
1679 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1680 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1681 enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
1682 enc_cfg.encdec.param_size = sizeof(enc_cfg) - sizeof(enc_cfg.hdr) -
1683 sizeof(enc_cfg.encdec);
1684 enc_cfg.encblk.frames_per_buf = frames_per_buf;
1685 enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
1686 sizeof(struct asm_enc_cfg_blk_param_v2);
1687
1688 enc_cfg.num_channels = channels;
1689 enc_cfg.bits_per_sample = 16;
1690 enc_cfg.sample_rate = rate;
1691 enc_cfg.is_signed = 1;
1692 channel_mapping = enc_cfg.channel_mapping; /* ??? PHANI */
1693
1694 memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
1695
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001696 if (q6asm_map_channels(channel_mapping, channels))
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07001697 return -EINVAL;
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07001698
1699 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1700 if (rc < 0) {
1701 pr_err("Comamnd open failed\n");
1702 rc = -EINVAL;
1703 goto fail_cmd;
1704 }
1705 rc = wait_event_timeout(ac->cmd_wait,
1706 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1707 if (!rc) {
1708 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1709 goto fail_cmd;
1710 }
1711 return 0;
1712fail_cmd:
1713 return -EINVAL;
1714}
1715
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001716int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac,
1717 uint32_t rate, uint32_t channels)
1718{
1719 struct asm_multi_channel_pcm_enc_cfg_v2 enc_cfg;
1720 u8 *channel_mapping;
1721 u32 frames_per_buf = 0;
1722
1723 int rc = 0;
1724
1725 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1726 ac->session, rate, channels);
1727
1728 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1729
1730 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1731 enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
1732 enc_cfg.encdec.param_size = sizeof(enc_cfg) - sizeof(enc_cfg.hdr) -
1733 sizeof(enc_cfg.encdec);
1734 enc_cfg.encblk.frames_per_buf = frames_per_buf;
1735 enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
1736 sizeof(struct asm_enc_cfg_blk_param_v2);
1737
1738 enc_cfg.num_channels = 0;/*channels;*/
1739 enc_cfg.bits_per_sample = 16;
1740 enc_cfg.sample_rate = 0;/*rate;*/
1741 enc_cfg.is_signed = 1;
1742 channel_mapping = enc_cfg.channel_mapping; /* ??? PHANI */
1743
1744 memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
1745
1746 if (q6asm_map_channels(channel_mapping, channels))
1747 return -EINVAL;
1748
1749 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1750 if (rc < 0) {
1751 pr_err("Comamnd open failed\n");
1752 rc = -EINVAL;
1753 goto fail_cmd;
1754 }
1755 rc = wait_event_timeout(ac->cmd_wait,
1756 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1757 if (!rc) {
1758 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1759 goto fail_cmd;
1760 }
1761 return 0;
1762fail_cmd:
1763 return -EINVAL;
1764}
1765
1766static int q6asm_map_channels(u8 *channel_mapping, uint32_t channels)
1767{
1768 u8 *lchannel_mapping;
1769 lchannel_mapping = channel_mapping;
1770 pr_debug("%s channels passed: %d\n", __func__, channels);
1771 if (channels == 1) {
1772 lchannel_mapping[0] = PCM_CHANNEL_FC;
1773 } else if (channels == 2) {
1774 lchannel_mapping[0] = PCM_CHANNEL_FL;
1775 lchannel_mapping[1] = PCM_CHANNEL_FR;
1776 } else if (channels == 3) {
1777 lchannel_mapping[0] = PCM_CHANNEL_FC;
1778 lchannel_mapping[1] = PCM_CHANNEL_FL;
1779 lchannel_mapping[2] = PCM_CHANNEL_FR;
1780 } else if (channels == 4) {
1781 lchannel_mapping[0] = PCM_CHANNEL_FC;
1782 lchannel_mapping[1] = PCM_CHANNEL_FL;
1783 lchannel_mapping[2] = PCM_CHANNEL_FR;
1784 lchannel_mapping[3] = PCM_CHANNEL_LB;
1785 } else if (channels == 5) {
1786 lchannel_mapping[0] = PCM_CHANNEL_FC;
1787 lchannel_mapping[1] = PCM_CHANNEL_FL;
1788 lchannel_mapping[2] = PCM_CHANNEL_FR;
1789 lchannel_mapping[3] = PCM_CHANNEL_LB;
1790 lchannel_mapping[4] = PCM_CHANNEL_RB;
1791 } else if (channels == 6) {
1792 lchannel_mapping[0] = PCM_CHANNEL_FC;
1793 lchannel_mapping[1] = PCM_CHANNEL_FL;
1794 lchannel_mapping[2] = PCM_CHANNEL_FR;
1795 lchannel_mapping[3] = PCM_CHANNEL_LB;
1796 lchannel_mapping[4] = PCM_CHANNEL_RB;
1797 lchannel_mapping[5] = PCM_CHANNEL_LFE;
1798 } else {
1799 pr_err("%s: ERROR.unsupported num_ch = %u\n",
1800 __func__, channels);
1801 return -EINVAL;
1802 }
1803 return 0;
1804}
1805
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07001806int q6asm_enable_sbrps(struct audio_client *ac,
1807 uint32_t sbr_ps_enable)
1808{
1809 struct asm_aac_sbr_ps_flag_param sbrps;
1810 u32 frames_per_buf = 0;
1811
1812 int rc = 0;
1813
1814 pr_debug("%s: Session %d\n", __func__, ac->session);
1815
1816 q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
1817
1818 sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1819 sbrps.encdec.param_id = ASM_PARAM_ID_AAC_SBR_PS_FLAG;
1820 sbrps.encdec.param_size = sizeof(struct asm_aac_sbr_ps_flag_param) -
1821 sizeof(struct asm_stream_cmd_set_encdec_param);
1822 sbrps.encblk.frames_per_buf = frames_per_buf;
1823 sbrps.encblk.enc_cfg_blk_size = sbrps.encdec.param_size -
1824 sizeof(struct asm_enc_cfg_blk_param_v2);
1825
1826 sbrps.sbr_ps_flag = sbr_ps_enable;
1827
1828 rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
1829 if (rc < 0) {
1830 pr_err("Command opcode[0x%x]paramid[0x%x] failed\n",
1831 ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1832 ASM_PARAM_ID_AAC_SBR_PS_FLAG);
1833 rc = -EINVAL;
1834 goto fail_cmd;
1835 }
1836 rc = wait_event_timeout(ac->cmd_wait,
1837 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1838 if (!rc) {
1839 pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode);
1840 goto fail_cmd;
1841 }
1842 return 0;
1843fail_cmd:
1844 return -EINVAL;
1845}
1846
1847int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
1848 uint16_t sce_left, uint16_t sce_right)
1849{
1850 struct asm_aac_dual_mono_mapping_param dual_mono;
1851 u32 frames_per_buf = 0;
1852
1853 int rc = 0;
1854
1855 pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
1856 __func__, ac->session, sce_left, sce_right);
1857
1858 q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
1859
1860 dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1861 dual_mono.encdec.param_id = ASM_PARAM_ID_AAC_DUAL_MONO_MAPPING;
1862 dual_mono.encdec.param_size = sizeof(struct asm_aac_enc_cfg_v2) -
1863 sizeof(struct asm_stream_cmd_set_encdec_param);
1864 dual_mono.encblk.frames_per_buf = frames_per_buf;
1865 dual_mono.encblk.enc_cfg_blk_size = dual_mono.encdec.param_size -
1866 sizeof(struct asm_enc_cfg_blk_param_v2);
1867 dual_mono.left_channel_sce = sce_left;
1868 dual_mono.right_channel_sce = sce_right;
1869
1870 rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
1871 if (rc < 0) {
1872 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
1873 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1874 ASM_PARAM_ID_AAC_DUAL_MONO_MAPPING);
1875 rc = -EINVAL;
1876 goto fail_cmd;
1877 }
1878 rc = wait_event_timeout(ac->cmd_wait,
1879 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1880 if (!rc) {
1881 pr_err("%s:timeout opcode[0x%x]\n", __func__,
1882 dual_mono.hdr.opcode);
1883 goto fail_cmd;
1884 }
1885 return 0;
1886fail_cmd:
1887 return -EINVAL;
1888}
1889
Amal Paul6e0f7982013-02-21 19:36:35 -08001890/* Support for selecting stereo mixing coefficients for B family not done */
1891int q6asm_cfg_aac_sel_mix_coef(struct audio_client *ac, uint32_t mix_coeff)
1892{
1893 /* To Be Done */
1894 return 0;
1895}
1896
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07001897int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
1898 uint16_t min_rate, uint16_t max_rate,
1899 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
1900{
1901 struct asm_v13k_enc_cfg enc_cfg;
1902 int rc = 0;
1903
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001904 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] reduced_rate_level[0x%4x]rate_modulation_cmd[0x%4x]",
1905 __func__,
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07001906 ac->session, frames_per_buf, min_rate, max_rate,
1907 reduced_rate_level, rate_modulation_cmd);
1908
1909 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1910 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1911 enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
1912 enc_cfg.encdec.param_size = sizeof(struct asm_v13k_enc_cfg) -
1913 sizeof(struct asm_stream_cmd_set_encdec_param);
1914 enc_cfg.encblk.frames_per_buf = frames_per_buf;
1915 enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
1916 sizeof(struct asm_enc_cfg_blk_param_v2);
1917
1918 enc_cfg.min_rate = min_rate;
1919 enc_cfg.max_rate = max_rate;
1920 enc_cfg.reduced_rate_cmd = reduced_rate_level;
1921 enc_cfg.rate_mod_cmd = rate_modulation_cmd;
1922
1923 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1924 if (rc < 0) {
1925 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1926 goto fail_cmd;
1927 }
1928 rc = wait_event_timeout(ac->cmd_wait,
1929 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1930 if (!rc) {
1931 pr_err("timeout. waited for setencdec v13k resp\n");
1932 goto fail_cmd;
1933 }
1934 return 0;
1935fail_cmd:
1936 return -EINVAL;
1937}
1938
1939int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
1940 uint16_t min_rate, uint16_t max_rate,
1941 uint16_t rate_modulation_cmd)
1942{
1943 struct asm_evrc_enc_cfg enc_cfg;
1944 int rc = 0;
1945
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001946 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] rate_modulation_cmd[0x%4x]",
1947 __func__, ac->session,
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07001948 frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
1949
1950 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1951 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1952 enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
1953 enc_cfg.encdec.param_size = sizeof(struct asm_evrc_enc_cfg) -
1954 sizeof(struct asm_stream_cmd_set_encdec_param);
1955 enc_cfg.encblk.frames_per_buf = frames_per_buf;
1956 enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
1957 sizeof(struct asm_enc_cfg_blk_param_v2);
1958
1959 enc_cfg.min_rate = min_rate;
1960 enc_cfg.max_rate = max_rate;
1961 enc_cfg.rate_mod_cmd = rate_modulation_cmd;
1962 enc_cfg.reserved = 0;
1963
1964 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1965 if (rc < 0) {
1966 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1967 goto fail_cmd;
1968 }
1969 rc = wait_event_timeout(ac->cmd_wait,
1970 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1971 if (!rc) {
1972 pr_err("timeout. waited for encdec evrc\n");
1973 goto fail_cmd;
1974 }
1975 return 0;
1976fail_cmd:
1977 return -EINVAL;
1978}
1979
1980int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
1981 uint16_t band_mode, uint16_t dtx_enable)
1982{
1983 struct asm_amrnb_enc_cfg enc_cfg;
1984 int rc = 0;
1985
1986 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
1987 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
1988
1989 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1990 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1991 enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
1992 enc_cfg.encdec.param_size = sizeof(struct asm_amrnb_enc_cfg) -
1993 sizeof(struct asm_stream_cmd_set_encdec_param);
1994 enc_cfg.encblk.frames_per_buf = frames_per_buf;
1995 enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
1996 sizeof(struct asm_enc_cfg_blk_param_v2);
1997
1998 enc_cfg.enc_mode = band_mode;
1999 enc_cfg.dtx_mode = dtx_enable;
2000
2001 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2002 if (rc < 0) {
2003 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2004 goto fail_cmd;
2005 }
2006 rc = wait_event_timeout(ac->cmd_wait,
2007 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2008 if (!rc) {
2009 pr_err("timeout. waited for set encdec amrnb\n");
2010 goto fail_cmd;
2011 }
2012 return 0;
2013fail_cmd:
2014 return -EINVAL;
2015}
2016
2017int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
2018 uint16_t band_mode, uint16_t dtx_enable)
2019{
2020 struct asm_amrwb_enc_cfg enc_cfg;
2021 int rc = 0;
2022
2023 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2024 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2025
2026 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2027 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2028 enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
2029 enc_cfg.encdec.param_size = sizeof(struct asm_amrwb_enc_cfg) -
2030 sizeof(struct asm_stream_cmd_set_encdec_param);
2031 enc_cfg.encblk.frames_per_buf = frames_per_buf;
2032 enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
2033 sizeof(struct asm_enc_cfg_blk_param_v2);
2034
2035 enc_cfg.enc_mode = band_mode;
2036 enc_cfg.dtx_mode = dtx_enable;
2037
2038 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2039 if (rc < 0) {
2040 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2041 goto fail_cmd;
2042 }
2043 rc = wait_event_timeout(ac->cmd_wait,
2044 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2045 if (!rc) {
2046 pr_err("timeout. waited for FORMAT_UPDATE\n");
2047 goto fail_cmd;
2048 }
2049 return 0;
2050fail_cmd:
2051 return -EINVAL;
2052}
2053
2054
2055int q6asm_media_format_block_aac(struct audio_client *ac,
2056 struct asm_aac_cfg *cfg)
2057{
2058 return q6asm_media_format_block_multi_aac(ac, cfg);
2059}
2060
2061int q6asm_media_format_block_pcm(struct audio_client *ac,
2062 uint32_t rate, uint32_t channels)
2063{
2064 struct asm_multi_channel_pcm_fmt_blk_v2 fmt;
2065 u8 *channel_mapping;
2066 int rc = 0;
2067
2068 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2069 channels);
2070
2071 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2072
2073 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
2074 fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
2075 sizeof(fmt.fmt_blk);
2076 fmt.num_channels = channels;
2077 fmt.bits_per_sample = 16;
2078 fmt.sample_rate = rate;
2079 fmt.is_signed = 1;
2080
2081 channel_mapping = fmt.channel_mapping;
2082
2083 memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
2084
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002085 if (q6asm_map_channels(channel_mapping, channels))
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07002086 return -EINVAL;
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07002087
2088 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2089 if (rc < 0) {
2090 pr_err("%s:Comamnd open failed\n", __func__);
2091 goto fail_cmd;
2092 }
2093 rc = wait_event_timeout(ac->cmd_wait,
2094 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2095 if (!rc) {
2096 pr_err("%s:timeout. waited for format update\n", __func__);
2097 goto fail_cmd;
2098 }
2099 return 0;
2100fail_cmd:
2101 return -EINVAL;
2102}
2103
2104int q6asm_media_format_block_multi_aac(struct audio_client *ac,
2105 struct asm_aac_cfg *cfg)
2106{
2107 struct asm_aac_fmt_blk_v2 fmt;
2108 int rc = 0;
2109
2110 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2111 cfg->sample_rate, cfg->ch_cfg);
2112
2113 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2114
2115 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
2116 fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
2117 sizeof(fmt.fmt_blk);
2118 fmt.aac_fmt_flag = cfg->format;
2119 fmt.audio_objype = cfg->aot;
2120 /* If zero, PCE is assumed to be available in bitstream*/
2121 fmt.total_size_of_PCE_bits = 0;
2122 fmt.channel_config = cfg->ch_cfg;
2123 fmt.sample_rate = cfg->sample_rate;
2124
2125 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2126 __func__, fmt.aac_fmt_flag, fmt.fmt_blk.fmt_blk_size,
2127 fmt.aac_fmt_flag,
2128 fmt.audio_objype,
2129 fmt.channel_config,
2130 fmt.sample_rate);
2131 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2132 if (rc < 0) {
2133 pr_err("%s:Comamnd open failed\n", __func__);
2134 goto fail_cmd;
2135 }
2136 rc = wait_event_timeout(ac->cmd_wait,
2137 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2138 if (!rc) {
2139 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2140 goto fail_cmd;
2141 }
2142 return 0;
2143fail_cmd:
2144 return -EINVAL;
2145}
2146
2147int q6asm_media_format_block_wma(struct audio_client *ac,
2148 void *cfg)
2149{
2150 struct asm_wmastdv9_fmt_blk_v2 fmt;
2151 struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
2152 int rc = 0;
2153
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002154 pr_debug("session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d], balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x]\n",
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07002155 ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
2156 wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
2157 wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
2158 wma_cfg->ch_mask, wma_cfg->encode_opt);
2159
2160 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2161
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002162 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
2163 fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
2164 sizeof(fmt.fmtblk);
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07002165 fmt.fmtag = wma_cfg->format_tag;
2166 fmt.num_channels = wma_cfg->ch_cfg;
2167 fmt.sample_rate = wma_cfg->sample_rate;
2168 fmt.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
2169 fmt.blk_align = wma_cfg->block_align;
2170 fmt.bits_per_sample =
2171 wma_cfg->valid_bits_per_sample;
2172 fmt.channel_mask = wma_cfg->ch_mask;
2173 fmt.enc_options = wma_cfg->encode_opt;
2174
2175 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2176 if (rc < 0) {
2177 pr_err("%s:Comamnd open failed\n", __func__);
2178 goto fail_cmd;
2179 }
2180 rc = wait_event_timeout(ac->cmd_wait,
2181 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2182 if (!rc) {
2183 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2184 goto fail_cmd;
2185 }
2186 return 0;
2187fail_cmd:
2188 return -EINVAL;
2189}
2190
2191int q6asm_media_format_block_wmapro(struct audio_client *ac,
2192 void *cfg)
2193{
2194 struct asm_wmaprov10_fmt_blk_v2 fmt;
2195 struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
2196 int rc = 0;
2197
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002198 pr_debug("session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d], balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x], adv_enc_opt[0x%4x], adv_enc_opt2[0x%8x]\n",
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07002199 ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
2200 wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
2201 wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
2202 wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
2203 wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
2204
2205 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2206
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002207 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
2208 fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
2209 sizeof(fmt.fmtblk);
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07002210
2211 fmt.fmtag = wmapro_cfg->format_tag;
2212 fmt.num_channels = wmapro_cfg->ch_cfg;
2213 fmt.sample_rate = wmapro_cfg->sample_rate;
2214 fmt.avg_bytes_per_sec =
2215 wmapro_cfg->avg_bytes_per_sec;
2216 fmt.blk_align = wmapro_cfg->block_align;
2217 fmt.bits_per_sample = wmapro_cfg->valid_bits_per_sample;
2218 fmt.channel_mask = wmapro_cfg->ch_mask;
2219 fmt.enc_options = wmapro_cfg->encode_opt;
2220 fmt.usAdvancedEncodeOpt = wmapro_cfg->adv_encode_opt;
2221 fmt.advanced_enc_options2 = wmapro_cfg->adv_encode_opt2;
2222
2223 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2224 if (rc < 0) {
2225 pr_err("%s:Comamnd open failed\n", __func__);
2226 goto fail_cmd;
2227 }
2228 rc = wait_event_timeout(ac->cmd_wait,
2229 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2230 if (!rc) {
2231 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2232 goto fail_cmd;
2233 }
2234 return 0;
2235fail_cmd:
2236 return -EINVAL;
2237}
2238
2239int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
2240 uint32_t bufsz, uint32_t bufcnt)
2241{
2242 struct avs_cmd_shared_mem_map_regions *mmap_regions = NULL;
2243 struct avs_shared_map_region_payload *mregions = NULL;
2244 struct audio_port_data *port = NULL;
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07002245 void *mmap_region_cmd = NULL;
2246 void *payload = NULL;
2247 struct asm_buffer_node *buffer_node = NULL;
2248 int rc = 0;
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07002249 int cmd_size = 0;
2250
2251 if (!ac || ac->apr == NULL || ac->mmap_apr == NULL) {
2252 pr_err("APR handle NULL\n");
2253 return -EINVAL;
2254 }
2255 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2256
2257 buffer_node = kmalloc(sizeof(struct asm_buffer_node), GFP_KERNEL);
2258 if (!buffer_node)
2259 return -ENOMEM;
2260 cmd_size = sizeof(struct avs_cmd_shared_mem_map_regions)
2261 + sizeof(struct avs_shared_map_region_payload) * bufcnt;
2262
2263 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
2264 if (mmap_region_cmd == NULL) {
2265 pr_err("%s: Mem alloc failed\n", __func__);
2266 rc = -EINVAL;
2267 return rc;
2268 }
2269 mmap_regions = (struct avs_cmd_shared_mem_map_regions *)
2270 mmap_region_cmd;
2271 q6asm_add_mmaphdr(ac, &mmap_regions->hdr, cmd_size,
2272 TRUE, ((ac->session << 8) | dir));
2273 mmap_regions->hdr.opcode = ASM_CMD_SHARED_MEM_MAP_REGIONS;
Harmandeep Singhac1671b2012-06-22 15:34:45 -07002274 mmap_regions->mem_pool_id = ADSP_MEMORY_MAP_SHMEM8_4K_POOL;
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07002275 mmap_regions->num_regions = bufcnt & 0x00ff;
2276 mmap_regions->property_flag = 0x00;
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07002277 payload = ((u8 *) mmap_region_cmd +
2278 sizeof(struct avs_cmd_shared_mem_map_regions));
2279 mregions = (struct avs_shared_map_region_payload *)payload;
2280
2281 ac->port[dir].tmp_hdl = 0;
2282 port = &ac->port[dir];
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002283 pr_debug("%s, buf_add 0x%x, bufsz: %d\n", __func__, buf_add, bufsz);
2284 mregions->shm_addr_lsw = buf_add;
2285 /* Using only 32 bit address */
2286 mregions->shm_addr_msw = 0;
2287 mregions->mem_size_bytes = bufsz;
2288 ++mregions;
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07002289
2290 rc = apr_send_pkt(ac->mmap_apr, (uint32_t *) mmap_region_cmd);
2291 if (rc < 0) {
2292 pr_err("mmap op[0x%x]rc[%d]\n",
2293 mmap_regions->hdr.opcode, rc);
2294 rc = -EINVAL;
2295 goto fail_cmd;
2296 }
2297
2298 rc = wait_event_timeout(ac->cmd_wait,
2299 (atomic_read(&ac->cmd_state) == 0 &&
2300 ac->port[dir].tmp_hdl), 5*HZ);
2301 if (!rc) {
2302 pr_err("timeout. waited for memory_map\n");
2303 rc = -EINVAL;
2304 goto fail_cmd;
2305 }
2306 buffer_node->buf_addr_lsw = buf_add;
2307 buffer_node->mmap_hdl = ac->port[dir].tmp_hdl;
2308 list_add_tail(&buffer_node->list, &ac->port[dir].mem_map_handle);
2309 ac->port[dir].tmp_hdl = 0;
2310 rc = 0;
2311
2312fail_cmd:
2313 kfree(mmap_region_cmd);
2314 return rc;
2315}
2316
2317int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
2318{
2319 struct avs_cmd_shared_mem_unmap_regions mem_unmap;
2320 struct asm_buffer_node *buf_node = NULL;
2321 struct list_head *ptr, *next;
2322
2323 int rc = 0;
2324
2325 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2326 pr_err("APR handle NULL\n");
2327 return -EINVAL;
2328 }
2329 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2330
2331 q6asm_add_mmaphdr(ac, &mem_unmap.hdr,
2332 sizeof(struct avs_cmd_shared_mem_unmap_regions),
2333 TRUE, ((ac->session << 8) | dir));
2334
2335 mem_unmap.hdr.opcode = ASM_CMD_SHARED_MEM_UNMAP_REGIONS;
2336 list_for_each_safe(ptr, next, &ac->port[dir].mem_map_handle) {
2337 buf_node = list_entry(ptr, struct asm_buffer_node,
2338 list);
2339 if (buf_node->buf_addr_lsw == buf_add) {
2340 pr_info("%s: Found the element\n", __func__);
2341 mem_unmap.mem_map_handle = buf_node->mmap_hdl;
2342 break;
2343 }
2344 }
2345 pr_debug("%s: mem_unmap-mem_map_handle: 0x%x",
2346 __func__, mem_unmap.mem_map_handle);
2347 rc = apr_send_pkt(ac->mmap_apr, (uint32_t *) &mem_unmap);
2348 if (rc < 0) {
2349 pr_err("mem_unmap op[0x%x]rc[%d]\n",
2350 mem_unmap.hdr.opcode, rc);
2351 rc = -EINVAL;
2352 goto fail_cmd;
2353 }
2354
2355 rc = wait_event_timeout(ac->cmd_wait,
2356 (atomic_read(&ac->cmd_state) == 0), 5 * HZ);
2357 if (!rc) {
2358 pr_err("timeout. waited for memory_map\n");
2359 rc = -EINVAL;
2360 goto fail_cmd;
2361 }
2362 list_for_each_safe(ptr, next, &ac->port[dir].mem_map_handle) {
2363 buf_node = list_entry(ptr, struct asm_buffer_node,
2364 list);
2365 if (buf_node->buf_addr_lsw == buf_add) {
2366 list_del(&buf_node->list);
2367 kfree(buf_node);
2368 }
2369 }
2370
2371 rc = 0;
2372fail_cmd:
2373 return rc;
2374}
2375
2376
2377static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
2378 uint32_t bufsz, uint32_t bufcnt)
2379{
2380 struct avs_cmd_shared_mem_map_regions *mmap_regions = NULL;
2381 struct avs_shared_map_region_payload *mregions = NULL;
2382 struct audio_port_data *port = NULL;
2383 struct audio_buffer *ab = NULL;
2384 void *mmap_region_cmd = NULL;
2385 void *payload = NULL;
2386 struct asm_buffer_node *buffer_node = NULL;
2387 int rc = 0;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002388 int i = 0;
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07002389 int cmd_size = 0;
2390
2391 if (!ac || ac->apr == NULL || ac->mmap_apr == NULL) {
2392 pr_err("APR handle NULL\n");
2393 return -EINVAL;
2394 }
2395 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2396
2397 cmd_size = sizeof(struct avs_cmd_shared_mem_map_regions)
2398 + (sizeof(struct avs_shared_map_region_payload));
2399
2400 buffer_node = kzalloc(sizeof(struct asm_buffer_node) * bufcnt,
2401 GFP_KERNEL);
2402
2403 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
2404 if ((mmap_region_cmd == NULL) || (buffer_node == NULL)) {
2405 pr_err("%s: Mem alloc failed\n", __func__);
2406 rc = -EINVAL;
2407 return rc;
2408 }
2409 mmap_regions = (struct avs_cmd_shared_mem_map_regions *)
2410 mmap_region_cmd;
2411 q6asm_add_mmaphdr(ac, &mmap_regions->hdr, cmd_size, TRUE,
2412 ((ac->session << 8) | dir));
2413 pr_debug("mmap_region=0x%p token=0x%x\n",
2414 mmap_regions, ((ac->session << 8) | dir));
2415
2416 mmap_regions->hdr.opcode = ASM_CMD_SHARED_MEM_MAP_REGIONS;
Harmandeep Singhac1671b2012-06-22 15:34:45 -07002417 mmap_regions->mem_pool_id = ADSP_MEMORY_MAP_SHMEM8_4K_POOL;
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07002418 mmap_regions->num_regions = 1; /*bufcnt & 0x00ff; */
2419 mmap_regions->property_flag = 0x00;
2420 pr_debug("map_regions->nregions = %d\n", mmap_regions->num_regions);
2421 payload = ((u8 *) mmap_region_cmd +
2422 sizeof(struct avs_cmd_shared_mem_map_regions));
2423 mregions = (struct avs_shared_map_region_payload *)payload;
2424
2425 ac->port[dir].tmp_hdl = 0;
2426 port = &ac->port[dir];
2427 ab = &port->buf[0];
2428 mregions->shm_addr_lsw = ab->phys;
2429 /* Using only 32 bit address */
2430 mregions->shm_addr_msw = 0;
2431 mregions->mem_size_bytes = (bufsz * bufcnt);
2432
2433 rc = apr_send_pkt(ac->mmap_apr, (uint32_t *) mmap_region_cmd);
2434 if (rc < 0) {
2435 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2436 mmap_regions->hdr.opcode, rc);
2437 rc = -EINVAL;
2438 goto fail_cmd;
2439 }
2440
2441 rc = wait_event_timeout(ac->cmd_wait,
2442 (atomic_read(&ac->cmd_state) == 0)
2443 , 5*HZ);
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07002444 if (!rc) {
2445 pr_err("timeout. waited for memory_map\n");
2446 rc = -EINVAL;
2447 goto fail_cmd;
2448 }
2449 mutex_lock(&ac->cmd_lock);
2450
2451 for (i = 0; i < bufcnt; i++) {
2452 ab = &port->buf[i];
2453 buffer_node[i].buf_addr_lsw = ab->phys;
2454 buffer_node[i].mmap_hdl = ac->port[dir].tmp_hdl;
2455 list_add_tail(&buffer_node[i].list,
2456 &ac->port[dir].mem_map_handle);
2457 pr_debug("%s: i=%d, bufadd[i] = 0x%x, maphdl[i] = 0x%x\n",
2458 __func__, i, buffer_node[i].buf_addr_lsw,
2459 buffer_node[i].mmap_hdl);
2460 }
2461 ac->port[dir].tmp_hdl = 0;
2462 mutex_unlock(&ac->cmd_lock);
2463 rc = 0;
2464 pr_debug("%s: exit\n", __func__);
2465fail_cmd:
2466 kfree(mmap_region_cmd);
2467 return rc;
2468}
2469
2470static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
2471 uint32_t bufsz, uint32_t bufcnt)
2472{
2473 struct avs_cmd_shared_mem_unmap_regions mem_unmap;
2474 struct audio_port_data *port = NULL;
2475 struct asm_buffer_node *buf_node = NULL;
2476 struct list_head *ptr, *next;
2477 uint32_t buf_add;
2478 int rc = 0;
2479 int cmd_size = 0;
2480
2481 if (!ac || ac->apr == NULL || ac->mmap_apr == NULL) {
2482 pr_err("APR handle NULL\n");
2483 return -EINVAL;
2484 }
2485 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2486
2487 cmd_size = sizeof(struct avs_cmd_shared_mem_unmap_regions);
2488 q6asm_add_mmaphdr(ac, &mem_unmap.hdr, cmd_size,
2489 TRUE, ((ac->session << 8) | dir));
2490 port = &ac->port[dir];
2491 buf_add = (uint32_t)port->buf->phys;
2492 mem_unmap.hdr.opcode = ASM_CMD_SHARED_MEM_UNMAP_REGIONS;
2493 list_for_each_safe(ptr, next, &ac->port[dir].mem_map_handle) {
2494 buf_node = list_entry(ptr, struct asm_buffer_node,
2495 list);
2496 if (buf_node->buf_addr_lsw == buf_add) {
2497 pr_debug("%s: Found the element\n", __func__);
2498 mem_unmap.mem_map_handle = buf_node->mmap_hdl;
2499 break;
2500 }
2501 }
2502
2503 pr_debug("%s: mem_unmap-mem_map_handle: 0x%x",
2504 __func__, mem_unmap.mem_map_handle);
2505 rc = apr_send_pkt(ac->mmap_apr, (uint32_t *) &mem_unmap);
2506 if (rc < 0) {
2507 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2508 mem_unmap.hdr.opcode, rc);
2509 goto fail_cmd;
2510 }
2511
2512 rc = wait_event_timeout(ac->cmd_wait,
2513 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2514 if (!rc) {
2515 pr_err("timeout. waited for memory_unmap\n");
2516 goto fail_cmd;
2517 }
2518 list_for_each_safe(ptr, next, &ac->port[dir].mem_map_handle) {
2519 buf_node = list_entry(ptr, struct asm_buffer_node,
2520 list);
2521 if (buf_node->buf_addr_lsw == buf_add) {
2522 list_del(&buf_node->list);
2523 kfree(buf_node);
2524 }
2525 }
2526 rc = 0;
2527
2528fail_cmd:
2529 return rc;
2530}
2531
2532int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
2533{
2534 struct asm_volume_ctrl_lr_chan_gain lrgain;
2535 int sz = 0;
2536 int rc = 0;
2537
2538 sz = sizeof(struct asm_volume_ctrl_lr_chan_gain);
2539 q6asm_add_hdr_async(ac, &lrgain.hdr, sz, TRUE);
2540 lrgain.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
2541 lrgain.param.data_payload_addr_lsw = 0;
2542 lrgain.param.data_payload_addr_msw = 0;
2543 lrgain.param.mem_map_handle = 0;
2544 lrgain.param.data_payload_size = sizeof(lrgain) -
2545 sizeof(lrgain.hdr) - sizeof(lrgain.param);
2546 lrgain.data.module_id = ASM_MODULE_ID_VOL_CTRL;
2547 lrgain.data.param_id = ASM_PARAM_ID_VOL_CTRL_LR_CHANNEL_GAIN;
2548 lrgain.data.param_size = lrgain.param.data_payload_size -
2549 sizeof(lrgain.data);
2550 lrgain.data.reserved = 0;
2551 lrgain.l_chan_gain = left_gain;
2552 lrgain.r_chan_gain = right_gain;
2553 rc = apr_send_pkt(ac->apr, (uint32_t *) &lrgain);
2554 if (rc < 0) {
2555 pr_err("%s: set-params send failed paramid[0x%x]\n", __func__,
2556 lrgain.data.param_id);
2557 rc = -EINVAL;
2558 goto fail_cmd;
2559 }
2560
2561 rc = wait_event_timeout(ac->cmd_wait,
2562 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2563 if (!rc) {
2564 pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
2565 lrgain.data.param_id);
2566 rc = -EINVAL;
2567 goto fail_cmd;
2568 }
2569 rc = 0;
2570fail_cmd:
2571 return rc;
2572}
2573
2574int q6asm_set_mute(struct audio_client *ac, int muteflag)
2575{
2576 struct asm_volume_ctrl_mute_config mute;
2577 int sz = 0;
2578 int rc = 0;
2579
2580 sz = sizeof(struct asm_volume_ctrl_mute_config);
2581 q6asm_add_hdr_async(ac, &mute.hdr, sz, TRUE);
2582 mute.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
2583 mute.param.data_payload_addr_lsw = 0;
2584 mute.param.data_payload_addr_msw = 0;
2585 mute.param.mem_map_handle = 0;
2586 mute.param.data_payload_size = sizeof(mute) -
2587 sizeof(mute.hdr) - sizeof(mute.param);
2588 mute.data.module_id = ASM_MODULE_ID_VOL_CTRL;
2589 mute.data.param_id = ASM_PARAM_ID_VOL_CTRL_MUTE_CONFIG;
2590 mute.data.param_size = mute.param.data_payload_size - sizeof(mute.data);
2591 mute.data.reserved = 0;
2592 mute.mute_flag = muteflag;
2593
2594 rc = apr_send_pkt(ac->apr, (uint32_t *) &mute);
2595 if (rc < 0) {
2596 pr_err("%s: set-params send failed paramid[0x%x]\n", __func__,
2597 mute.data.param_id);
2598 rc = -EINVAL;
2599 goto fail_cmd;
2600 }
2601
2602 rc = wait_event_timeout(ac->cmd_wait,
2603 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2604 if (!rc) {
2605 pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
2606 mute.data.param_id);
2607 rc = -EINVAL;
2608 goto fail_cmd;
2609 }
2610 rc = 0;
2611fail_cmd:
2612 return rc;
2613}
2614
2615int q6asm_set_volume(struct audio_client *ac, int volume)
2616{
2617 struct asm_volume_ctrl_master_gain vol;
2618 int sz = 0;
2619 int rc = 0;
2620
2621 sz = sizeof(struct asm_volume_ctrl_master_gain);
2622 q6asm_add_hdr_async(ac, &vol.hdr, sz, TRUE);
2623 vol.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
2624 vol.param.data_payload_addr_lsw = 0;
2625 vol.param.data_payload_addr_msw = 0;
2626
2627
2628 vol.param.mem_map_handle = 0;
2629 vol.param.data_payload_size = sizeof(vol) -
2630 sizeof(vol.hdr) - sizeof(vol.param);
2631 vol.data.module_id = ASM_MODULE_ID_VOL_CTRL;
2632 vol.data.param_id = ASM_PARAM_ID_VOL_CTRL_MASTER_GAIN;
2633 vol.data.param_size = vol.param.data_payload_size - sizeof(vol.data);
2634 vol.data.reserved = 0;
2635 vol.master_gain = volume;
2636
2637 rc = apr_send_pkt(ac->apr, (uint32_t *) &vol);
2638 if (rc < 0) {
2639 pr_err("%s: set-params send failed paramid[0x%x]\n", __func__,
2640 vol.data.param_id);
2641 rc = -EINVAL;
2642 goto fail_cmd;
2643 }
2644
2645 rc = wait_event_timeout(ac->cmd_wait,
2646 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2647 if (!rc) {
2648 pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
2649 vol.data.param_id);
2650 rc = -EINVAL;
2651 goto fail_cmd;
2652 }
2653 rc = 0;
2654fail_cmd:
2655 return rc;
2656}
2657int q6asm_set_softpause(struct audio_client *ac,
2658 struct asm_softpause_params *pause_param)
2659{
2660 struct asm_soft_pause_params softpause;
2661 int sz = 0;
2662 int rc = 0;
2663
2664 sz = sizeof(struct asm_soft_pause_params);
2665 q6asm_add_hdr_async(ac, &softpause.hdr, sz, TRUE);
2666 softpause.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
2667
2668 softpause.param.data_payload_addr_lsw = 0;
2669 softpause.param.data_payload_addr_msw = 0;
2670 softpause.param.mem_map_handle = 0;
2671 softpause.param.data_payload_size = sizeof(softpause) -
2672 sizeof(softpause.hdr) - sizeof(softpause.param);
2673 softpause.data.module_id = ASM_MODULE_ID_VOL_CTRL;
2674 softpause.data.param_id = ASM_PARAM_ID_SOFT_PAUSE_PARAMETERS;
2675 softpause.data.param_size = softpause.param.data_payload_size -
2676 sizeof(softpause.data);
2677 softpause.data.reserved = 0;
2678 softpause.enable_flag = pause_param->enable;
2679 softpause.period = pause_param->period;
2680 softpause.step = pause_param->step;
2681 softpause.ramping_curve = pause_param->rampingcurve;
2682
2683 rc = apr_send_pkt(ac->apr, (uint32_t *) &softpause);
2684 if (rc < 0) {
2685 pr_err("%s: set-params send failed paramid[0x%x]\n", __func__,
2686 softpause.data.param_id);
2687 rc = -EINVAL;
2688 goto fail_cmd;
2689 }
2690
2691 rc = wait_event_timeout(ac->cmd_wait,
2692 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2693 if (!rc) {
2694 pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
2695 softpause.data.param_id);
2696 rc = -EINVAL;
2697 goto fail_cmd;
2698 }
2699 rc = 0;
2700fail_cmd:
2701 return rc;
2702}
2703
2704int q6asm_set_softvolume(struct audio_client *ac,
2705 struct asm_softvolume_params *softvol_param)
2706{
2707 struct asm_soft_step_volume_params softvol;
2708 int sz = 0;
2709 int rc = 0;
2710
2711 sz = sizeof(struct asm_soft_step_volume_params);
2712 q6asm_add_hdr_async(ac, &softvol.hdr, sz, TRUE);
2713 softvol.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
2714 softvol.param.data_payload_addr_lsw = 0;
2715 softvol.param.data_payload_addr_msw = 0;
2716 softvol.param.mem_map_handle = 0;
2717 softvol.param.data_payload_size = sizeof(softvol) -
2718 sizeof(softvol.hdr) - sizeof(softvol.param);
2719 softvol.data.module_id = ASM_MODULE_ID_VOL_CTRL;
2720 softvol.data.param_id = ASM_PARAM_ID_SOFT_VOL_STEPPING_PARAMETERS;
2721 softvol.data.param_size = softvol.param.data_payload_size -
2722 sizeof(softvol.data);
2723 softvol.data.reserved = 0;
2724 softvol.period = softvol_param->period;
2725 softvol.step = softvol_param->step;
2726 softvol.ramping_curve = softvol_param->rampingcurve;
2727
2728 rc = apr_send_pkt(ac->apr, (uint32_t *) &softvol);
2729 if (rc < 0) {
2730 pr_err("%s: set-params send failed paramid[0x%x]\n", __func__,
2731 softvol.data.param_id);
2732 rc = -EINVAL;
2733 goto fail_cmd;
2734 }
2735
2736 rc = wait_event_timeout(ac->cmd_wait,
2737 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2738 if (!rc) {
2739 pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
2740 softvol.data.param_id);
2741 rc = -EINVAL;
2742 goto fail_cmd;
2743 }
2744 rc = 0;
2745fail_cmd:
2746 return rc;
2747}
2748
2749int q6asm_equalizer(struct audio_client *ac, void *eq_p)
2750{
2751 struct asm_eq_params eq;
2752 struct msm_audio_eq_stream_config *eq_params = NULL;
2753 int i = 0;
2754 int sz = 0;
2755 int rc = 0;
2756
2757 if (eq_p == NULL) {
2758 pr_err("%s[%d]: Invalid Eq param\n", __func__, ac->session);
2759 rc = -EINVAL;
2760 goto fail_cmd;
2761 }
2762 sz = sizeof(struct asm_eq_params);
2763 eq_params = (struct msm_audio_eq_stream_config *) eq_p;
2764 q6asm_add_hdr(ac, &eq.hdr, sz, TRUE);
2765
2766 eq.hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
2767 eq.param.data_payload_addr_lsw = 0;
2768 eq.param.data_payload_addr_msw = 0;
2769 eq.param.mem_map_handle = 0;
2770 eq.param.data_payload_size = sizeof(eq) -
2771 sizeof(eq.hdr) - sizeof(eq.param);
2772 eq.data.module_id = ASM_MODULE_ID_EQUALIZER;
2773 eq.data.param_id = ASM_PARAM_ID_EQUALIZER_PARAMETERS;
2774 eq.data.param_size = eq.param.data_payload_size - sizeof(eq.data);
2775 eq.enable_flag = eq_params->enable;
2776 eq.num_bands = eq_params->num_bands;
2777
2778 pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
2779 eq_params->num_bands);
2780 for (i = 0; i < eq_params->num_bands; i++) {
2781 eq.eq_bands[i].band_idx =
2782 eq_params->eq_bands[i].band_idx;
2783 eq.eq_bands[i].filterype =
2784 eq_params->eq_bands[i].filter_type;
2785 eq.eq_bands[i].center_freq_hz =
2786 eq_params->eq_bands[i].center_freq_hz;
2787 eq.eq_bands[i].filter_gain =
2788 eq_params->eq_bands[i].filter_gain;
2789 eq.eq_bands[i].q_factor =
2790 eq_params->eq_bands[i].q_factor;
2791 pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
2792 eq_params->eq_bands[i].filter_type, i);
2793 pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
2794 eq_params->eq_bands[i].center_freq_hz, i);
2795 pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
2796 eq_params->eq_bands[i].filter_gain, i);
2797 pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
2798 eq_params->eq_bands[i].q_factor, i);
2799 }
2800 rc = apr_send_pkt(ac->apr, (uint32_t *)&eq);
2801 if (rc < 0) {
2802 pr_err("%s: set-params send failed paramid[0x%x]\n", __func__,
2803 eq.data.param_id);
2804 rc = -EINVAL;
2805 goto fail_cmd;
2806 }
2807
2808 rc = wait_event_timeout(ac->cmd_wait,
2809 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2810 if (!rc) {
2811 pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
2812 eq.data.param_id);
2813 rc = -EINVAL;
2814 goto fail_cmd;
2815 }
2816 rc = 0;
2817fail_cmd:
2818 return rc;
2819}
2820
2821int q6asm_read(struct audio_client *ac)
2822{
2823 struct asm_data_cmd_read_v2 read;
2824 struct asm_buffer_node *buf_node = NULL;
2825 struct list_head *ptr, *next;
2826 struct audio_buffer *ab;
2827 int dsp_buf;
2828 struct audio_port_data *port;
2829 int rc;
2830 if (!ac || ac->apr == NULL) {
2831 pr_err("APR handle NULL\n");
2832 return -EINVAL;
2833 }
2834 if (ac->io_mode == SYNC_IO_MODE) {
2835 port = &ac->port[OUT];
2836
2837 q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
2838
2839 mutex_lock(&port->lock);
2840
2841 dsp_buf = port->dsp_buf;
2842 ab = &port->buf[dsp_buf];
2843
2844 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
2845 __func__,
2846 ac->session,
2847 dsp_buf,
2848 (void *)port->buf[dsp_buf].data,
2849 port->cpu_buf,
2850 (void *)port->buf[port->cpu_buf].phys);
2851
2852 read.hdr.opcode = ASM_DATA_CMD_READ_V2;
2853 read.buf_addr_lsw = ab->phys;
2854 read.buf_addr_msw = 0;
2855
2856 list_for_each_safe(ptr, next, &ac->port[OUT].mem_map_handle) {
2857 buf_node = list_entry(ptr, struct asm_buffer_node,
2858 list);
2859 if (buf_node->buf_addr_lsw == (uint32_t) ab->phys)
2860 read.mem_map_handle = buf_node->mmap_hdl;
2861 }
2862 pr_debug("memory_map handle in q6asm_read: [%0x]:",
2863 read.mem_map_handle);
2864 read.buf_size = ab->size;
2865 read.seq_id = port->dsp_buf;
2866 read.hdr.token = port->dsp_buf;
2867 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
2868 mutex_unlock(&port->lock);
2869 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
2870 read.buf_addr_lsw,
2871 read.hdr.token,
2872 read.seq_id);
2873 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
2874 if (rc < 0) {
2875 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
2876 goto fail_cmd;
2877 }
2878 return 0;
2879 }
2880fail_cmd:
2881 return -EINVAL;
2882}
2883
2884int q6asm_read_nolock(struct audio_client *ac)
2885{
2886 struct asm_data_cmd_read_v2 read;
2887 struct asm_buffer_node *buf_node = NULL;
2888 struct list_head *ptr, *next;
2889 struct audio_buffer *ab;
2890 int dsp_buf;
2891 struct audio_port_data *port;
2892 int rc;
2893 if (!ac || ac->apr == NULL) {
2894 pr_err("APR handle NULL\n");
2895 return -EINVAL;
2896 }
2897 if (ac->io_mode == SYNC_IO_MODE) {
2898 port = &ac->port[OUT];
2899
2900 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
2901
2902
2903 dsp_buf = port->dsp_buf;
2904 ab = &port->buf[dsp_buf];
2905
2906 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
2907 __func__,
2908 ac->session,
2909 dsp_buf,
2910 (void *)port->buf[dsp_buf].data,
2911 port->cpu_buf,
2912 (void *)port->buf[port->cpu_buf].phys);
2913
2914 read.hdr.opcode = ASM_DATA_CMD_READ_V2;
2915 read.buf_addr_lsw = ab->phys;
2916 read.buf_addr_msw = 0;
2917 read.buf_size = ab->size;
2918 read.seq_id = port->dsp_buf;
2919 read.hdr.token = port->dsp_buf;
2920
2921 list_for_each_safe(ptr, next, &ac->port[OUT].mem_map_handle) {
2922 buf_node = list_entry(ptr, struct asm_buffer_node,
2923 list);
2924 if (buf_node->buf_addr_lsw == (uint32_t)ab->phys) {
2925 read.mem_map_handle = buf_node->mmap_hdl;
2926 break;
2927 }
2928 }
2929
2930 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
2931 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
2932 read.buf_addr_lsw,
2933 read.hdr.token,
2934 read.seq_id);
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07002935 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
2936 if (rc < 0) {
2937 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
2938 goto fail_cmd;
2939 }
2940 return 0;
2941 }
2942fail_cmd:
2943 return -EINVAL;
2944}
2945
2946int q6asm_async_write(struct audio_client *ac,
2947 struct audio_aio_write_param *param)
2948{
2949 int rc = 0;
2950 struct asm_data_cmd_write_v2 write;
2951 struct asm_buffer_node *buf_node = NULL;
2952 struct list_head *ptr, *next;
2953 struct audio_buffer *ab;
2954 struct audio_port_data *port;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002955 u32 lbuf_addr_lsw;
2956 u32 liomode;
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07002957
2958 if (!ac || ac->apr == NULL) {
2959 pr_err("%s: APR handle NULL\n", __func__);
2960 return -EINVAL;
2961 }
2962
2963 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE);
2964
2965 port = &ac->port[IN];
2966 ab = &port->buf[port->dsp_buf];
2967
2968 /* Pass physical address as token for AIO scheme */
2969 write.hdr.token = param->uid;
2970 write.hdr.opcode = ASM_DATA_CMD_WRITE_V2;
2971 write.buf_addr_lsw = param->paddr;
2972 write.buf_addr_msw = 0x00;
2973 write.buf_size = param->len;
2974 write.timestamp_msw = param->msw_ts;
2975 write.timestamp_lsw = param->lsw_ts;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002976 liomode = (ASYNC_IO_MODE | NT_MODE);
2977
2978 if (ac->io_mode == liomode) {
2979 pr_info("%s: subtracting 32 for header\n", __func__);
2980 lbuf_addr_lsw = (write.buf_addr_lsw - 32);
2981 } else{
2982 lbuf_addr_lsw = write.buf_addr_lsw;
2983 }
2984
2985 pr_debug("%s: token[0x%x], buf_addr_lsw[0x%x], buf_size[0x%x], ts_msw[0x%x], ts_lsw[0x%x], lbuf_addr_lsw: 0x[%x]\n",
2986 __func__,
2987 write.hdr.token, write.buf_addr_lsw,
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07002988 write.buf_size, write.timestamp_msw,
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002989 write.timestamp_lsw, lbuf_addr_lsw);
2990
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07002991 /* Use 0xFF00 for disabling timestamps */
2992 if (param->flags == 0xFF00)
2993 write.flags = (0x00000000 | (param->flags & 0x800000FF));
2994 else
2995 write.flags = (0x80000000 | param->flags);
2996
2997 write.seq_id = param->uid;
2998 list_for_each_safe(ptr, next, &ac->port[IN].mem_map_handle) {
2999 buf_node = list_entry(ptr, struct asm_buffer_node,
3000 list);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003001 if (buf_node->buf_addr_lsw == lbuf_addr_lsw) {
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07003002 write.mem_map_handle = buf_node->mmap_hdl;
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07003003 break;
3004 }
3005 }
3006
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07003007 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3008 if (rc < 0) {
3009 pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__,
3010 write.hdr.opcode, rc);
3011 goto fail_cmd;
3012 }
3013 return 0;
3014fail_cmd:
3015 return -EINVAL;
3016}
3017
3018int q6asm_async_read(struct audio_client *ac,
3019 struct audio_aio_read_param *param)
3020{
3021 int rc = 0;
3022 struct asm_data_cmd_read_v2 read;
3023 struct asm_buffer_node *buf_node = NULL;
3024 struct list_head *ptr, *next;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003025 u32 lbuf_addr_lsw;
3026 u32 liomode;
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07003027
3028 if (!ac || ac->apr == NULL) {
3029 pr_err("%s: APR handle NULL\n", __func__);
3030 return -EINVAL;
3031 }
3032
3033 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3034
3035 /* Pass physical address as token for AIO scheme */
3036 read.hdr.token = param->paddr;
3037 read.hdr.opcode = ASM_DATA_CMD_READ_V2;
3038 read.buf_addr_lsw = param->paddr;
3039 read.buf_addr_msw = 0;
3040 read.buf_size = param->len;
3041 read.seq_id = param->uid;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003042 liomode = (NT_MODE | ASYNC_IO_MODE);
3043 if (ac->io_mode == liomode) {
3044 pr_info("%s: subtracting 32 for header\n", __func__);
3045 lbuf_addr_lsw = (read.buf_addr_lsw - 32);
3046 } else{
3047 lbuf_addr_lsw = read.buf_addr_lsw;
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07003048 }
3049
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003050 list_for_each_safe(ptr, next, &ac->port[IN].mem_map_handle) {
3051 buf_node = list_entry(ptr, struct asm_buffer_node, list);
3052 if (buf_node->buf_addr_lsw == lbuf_addr_lsw) {
3053 read.mem_map_handle = buf_node->mmap_hdl;
3054 break;
3055 }
3056 }
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07003057
3058 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3059 if (rc < 0) {
3060 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3061 read.hdr.opcode, rc);
3062 goto fail_cmd;
3063 }
3064 return 0;
3065fail_cmd:
3066 return -EINVAL;
3067}
3068
3069int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3070 uint32_t lsw_ts, uint32_t flags)
3071{
3072 int rc = 0;
3073 struct asm_data_cmd_write_v2 write;
3074 struct asm_buffer_node *buf_node = NULL;
3075 struct audio_port_data *port;
3076 struct audio_buffer *ab;
3077 int dsp_buf = 0;
3078
3079 if (!ac || ac->apr == NULL) {
3080 pr_err("APR handle NULL\n");
3081 return -EINVAL;
3082 }
3083 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3084 if (ac->io_mode == SYNC_IO_MODE) {
3085 port = &ac->port[IN];
3086
3087 q6asm_add_hdr(ac, &write.hdr, sizeof(write),
3088 FALSE);
3089 mutex_lock(&port->lock);
3090
3091 dsp_buf = port->dsp_buf;
3092 ab = &port->buf[dsp_buf];
3093
3094 write.hdr.token = port->dsp_buf;
3095 write.hdr.opcode = ASM_DATA_CMD_WRITE_V2;
3096 write.buf_addr_lsw = ab->phys;
3097 write.buf_addr_msw = 0;
3098 write.buf_size = len;
3099 write.seq_id = port->dsp_buf;
3100 write.timestamp_lsw = lsw_ts;
3101 write.timestamp_msw = msw_ts;
3102 /* Use 0xFF00 for disabling timestamps */
3103 if (flags == 0xFF00)
3104 write.flags = (0x00000000 | (flags & 0x800000FF));
3105 else
3106 write.flags = (0x80000000 | flags);
3107 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3108 buf_node = list_first_entry(&ac->port[IN].mem_map_handle,
3109 struct asm_buffer_node,
3110 list);
3111 write.mem_map_handle = buf_node->mmap_hdl;
3112
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003113 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x] token[0x%x]buf_id[0x%x]buf_size[0x%x]mmaphdl[0x%x]"
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07003114 , __func__,
3115 ab->phys,
3116 write.buf_addr_lsw,
3117 write.hdr.token,
3118 write.seq_id,
3119 write.buf_size,
3120 write.mem_map_handle);
3121 mutex_unlock(&port->lock);
3122
3123 config_debug_fs_write(ab);
3124
3125 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3126 if (rc < 0) {
3127 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3128 goto fail_cmd;
3129 }
3130 pr_debug("%s: WRITE SUCCESS\n", __func__);
3131 return 0;
3132 }
3133fail_cmd:
3134 return -EINVAL;
3135}
3136
3137int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3138 uint32_t lsw_ts, uint32_t flags)
3139{
3140 int rc = 0;
3141 struct asm_data_cmd_write_v2 write;
3142 struct asm_buffer_node *buf_node = NULL;
3143 struct audio_port_data *port;
3144 struct audio_buffer *ab;
3145 int dsp_buf = 0;
3146
3147 if (!ac || ac->apr == NULL) {
3148 pr_err("APR handle NULL\n");
3149 return -EINVAL;
3150 }
3151 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3152 if (ac->io_mode == SYNC_IO_MODE) {
3153 port = &ac->port[IN];
3154
3155 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
3156 FALSE);
3157
3158 dsp_buf = port->dsp_buf;
3159 ab = &port->buf[dsp_buf];
3160
3161 write.hdr.token = port->dsp_buf;
3162 write.hdr.opcode = ASM_DATA_CMD_WRITE_V2;
3163 write.buf_addr_lsw = ab->phys;
3164 write.buf_addr_msw = 0;
3165 write.buf_size = len;
3166 write.seq_id = port->dsp_buf;
3167 write.timestamp_lsw = lsw_ts;
3168 write.timestamp_msw = msw_ts;
3169 buf_node = list_first_entry(&ac->port[IN].mem_map_handle,
3170 struct asm_buffer_node,
3171 list);
3172 write.mem_map_handle = buf_node->mmap_hdl;
3173 /* Use 0xFF00 for disabling timestamps */
3174 if (flags == 0xFF00)
3175 write.flags = (0x00000000 | (flags & 0x800000FF));
3176 else
3177 write.flags = (0x80000000 | flags);
3178 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3179
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003180 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x] buf_id[0x%x]buf_size[0x%x]mmaphdl[0x%x]"
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07003181 , __func__,
3182 ab->phys,
3183 write.buf_addr_lsw,
3184 write.hdr.token,
3185 write.seq_id,
3186 write.buf_size,
3187 write.mem_map_handle);
3188
3189 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3190 if (rc < 0) {
3191 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3192 goto fail_cmd;
3193 }
3194 pr_debug("%s: WRITE SUCCESS\n", __func__);
3195 return 0;
3196 }
3197fail_cmd:
3198 return -EINVAL;
3199}
3200
Patrick Lai3aabeae2013-01-06 00:52:34 -08003201int q6asm_get_session_time(struct audio_client *ac, uint64_t *tstamp)
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07003202{
3203 struct apr_hdr hdr;
3204 int rc;
3205
Patrick Lai3aabeae2013-01-06 00:52:34 -08003206 if (!ac || ac->apr == NULL || tstamp == NULL) {
3207 pr_err("APR handle NULL or tstamp NULL\n");
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07003208 return -EINVAL;
3209 }
3210 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3211 hdr.opcode = ASM_SESSION_CMD_GET_SESSIONTIME_V3;
3212 atomic_set(&ac->cmd_state, 1);
3213
3214 pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
3215 ac->session,
3216 hdr.opcode);
3217 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3218 if (rc < 0) {
3219 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3220 goto fail_cmd;
3221 }
3222 rc = wait_event_timeout(ac->cmd_wait,
3223 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3224 if (!rc) {
3225 pr_err("%s: timeout in getting session time from DSP\n",
3226 __func__);
3227 goto fail_cmd;
3228 }
Patrick Lai3aabeae2013-01-06 00:52:34 -08003229
3230 *tstamp = ac->time_stamp;
3231 return 0;
Bharath Ramachandramurthy2e3168f2012-05-03 16:29:09 -07003232
3233fail_cmd:
3234 return -EINVAL;
3235}
3236
3237int q6asm_cmd(struct audio_client *ac, int cmd)
3238{
3239 struct apr_hdr hdr;
3240 int rc;
3241 atomic_t *state;
3242 int cnt = 0;
3243
3244 if (!ac || ac->apr == NULL) {
3245 pr_err("APR handle NULL\n");
3246 return -EINVAL;
3247 }
3248 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3249 switch (cmd) {
3250 case CMD_PAUSE:
3251 pr_debug("%s:CMD_PAUSE\n", __func__);
3252 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3253 state = &ac->cmd_state;
3254 break;
3255 case CMD_FLUSH:
3256 pr_debug("%s:CMD_FLUSH\n", __func__);
3257 hdr.opcode = ASM_STREAM_CMD_FLUSH;
3258 state = &ac->cmd_state;
3259 break;
3260 case CMD_OUT_FLUSH:
3261 pr_debug("%s:CMD_OUT_FLUSH\n", __func__);
3262 hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
3263 state = &ac->cmd_state;
3264 break;
3265 case CMD_EOS:
3266 pr_debug("%s:CMD_EOS\n", __func__);
3267 hdr.opcode = ASM_DATA_CMD_EOS;
3268 atomic_set(&ac->cmd_state, 0);
3269 state = &ac->cmd_state;
3270 break;
3271 case CMD_CLOSE:
3272 pr_debug("%s:CMD_CLOSE\n", __func__);
3273 hdr.opcode = ASM_STREAM_CMD_CLOSE;
3274 state = &ac->cmd_state;
3275 break;
3276 default:
3277 pr_err("Invalid format[%d]\n", cmd);
3278 goto fail_cmd;
3279 }
3280 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3281 ac->session,
3282 hdr.opcode);
3283 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3284 if (rc < 0) {
3285 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3286 goto fail_cmd;
3287 }
3288 rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ);
3289 if (!rc) {
3290 pr_err("timeout. waited for response opcode[0x%x]\n",
3291 hdr.opcode);
3292 goto fail_cmd;
3293 }
3294 if (cmd == CMD_FLUSH)
3295 q6asm_reset_buf_state(ac);
3296 if (cmd == CMD_CLOSE) {
3297 /* check if DSP return all buffers */
3298 if (ac->port[IN].buf) {
3299 for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
3300 cnt++) {
3301 if (ac->port[IN].buf[cnt].used == IN) {
3302 pr_debug("Write Buf[%d] not returned\n",
3303 cnt);
3304 }
3305 }
3306 }
3307 if (ac->port[OUT].buf) {
3308 for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
3309 if (ac->port[OUT].buf[cnt].used == OUT) {
3310 pr_debug("Read Buf[%d] not returned\n",
3311 cnt);
3312 }
3313 }
3314 }
3315 }
3316 return 0;
3317fail_cmd:
3318 return -EINVAL;
3319}
3320
3321int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
3322{
3323 struct apr_hdr hdr;
3324 int rc;
3325
3326 if (!ac || ac->apr == NULL) {
3327 pr_err("%s:APR handle NULL\n", __func__);
3328 return -EINVAL;
3329 }
3330 q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE);
3331 switch (cmd) {
3332 case CMD_PAUSE:
3333 pr_debug("%s:CMD_PAUSE\n", __func__);
3334 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3335 break;
3336 case CMD_EOS:
3337 pr_debug("%s:CMD_EOS\n", __func__);
3338 hdr.opcode = ASM_DATA_CMD_EOS;
3339 break;
3340 default:
3341 pr_err("%s:Invalid format[%d]\n", __func__, cmd);
3342 goto fail_cmd;
3343 }
3344 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3345 ac->session,
3346 hdr.opcode);
3347 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3348 if (rc < 0) {
3349 pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
3350 goto fail_cmd;
3351 }
3352 return 0;
3353fail_cmd:
3354 return -EINVAL;
3355}
3356
3357static void q6asm_reset_buf_state(struct audio_client *ac)
3358{
3359 int cnt = 0;
3360 int loopcnt = 0;
3361 struct audio_port_data *port = NULL;
3362
3363 if (ac->io_mode == SYNC_IO_MODE) {
3364 mutex_lock(&ac->cmd_lock);
3365 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
3366 port = &ac->port[loopcnt];
3367 cnt = port->max_buf_cnt - 1;
3368 port->dsp_buf = 0;
3369 port->cpu_buf = 0;
3370 while (cnt >= 0) {
3371 if (!port->buf)
3372 continue;
3373 port->buf[cnt].used = 1;
3374 cnt--;
3375 }
3376 }
3377 mutex_unlock(&ac->cmd_lock);
3378 }
3379}
3380
3381int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
3382{
3383 struct asm_session_cmd_regx_overflow tx_overflow;
3384 int rc;
3385
3386 if (!ac || ac->apr == NULL) {
3387 pr_err("APR handle NULL\n");
3388 return -EINVAL;
3389 }
3390 pr_debug("%s:session[%d]enable[%d]\n", __func__,
3391 ac->session, enable);
3392 q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
3393
3394 tx_overflow.hdr.opcode = \
3395 ASM_SESSION_CMD_REGISTER_FORX_OVERFLOW_EVENTS;
3396 /* tx overflow event: enable */
3397 tx_overflow.enable_flag = enable;
3398
3399 rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
3400 if (rc < 0) {
3401 pr_err("tx overflow op[0x%x]rc[%d]\n", \
3402 tx_overflow.hdr.opcode, rc);
3403 goto fail_cmd;
3404 }
3405 rc = wait_event_timeout(ac->cmd_wait,
3406 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3407 if (!rc) {
3408 pr_err("timeout. waited for tx overflow\n");
3409 goto fail_cmd;
3410 }
3411 return 0;
3412fail_cmd:
3413 return -EINVAL;
3414}
3415
3416int q6asm_get_apr_service_id(int session_id)
3417{
3418 pr_debug("%s\n", __func__);
3419
3420 if (session_id < 0 || session_id > SESSION_MAX) {
3421 pr_err("%s: invalid session_id = %d\n", __func__, session_id);
3422 return -EINVAL;
3423 }
3424
3425 return ((struct apr_svc *)session[session_id]->apr)->id;
3426}
3427
3428
3429static int __init q6asm_init(void)
3430{
3431 pr_debug("%s\n", __func__);
3432 memset(session, 0, sizeof(session));
3433
3434 config_debug_fs_init();
3435
3436 return 0;
3437}
3438
3439device_initcall(q6asm_init);