blob: 96d49a33741f7bd14b9589db4e32b3b311292faf [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001
2/*
3 * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
4 * Author: Brian Swetland <swetland@google.com>
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16#include <linux/fs.h>
17#include <linux/mutex.h>
18#include <linux/wait.h>
19#include <linux/miscdevice.h>
20#include <linux/uaccess.h>
21#include <linux/sched.h>
22#include <linux/dma-mapping.h>
23#include <linux/miscdevice.h>
24#include <linux/delay.h>
25#include <linux/spinlock.h>
26#include <linux/slab.h>
27#include <linux/msm_audio.h>
28#include <linux/android_pmem.h>
29#include <linux/memory_alloc.h>
Ben Rombergerfce8f512011-07-18 16:46:09 -070030#include <linux/debugfs.h>
31#include <linux/time.h>
32#include <linux/atomic.h>
33
34#include <asm/ioctls.h>
35
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070036#include <mach/memory.h>
37#include <mach/debug_mm.h>
38#include <mach/peripheral-loader.h>
39#include <mach/qdsp6v2/audio_acdb.h>
40#include <mach/qdsp6v2/rtac.h>
41#include <mach/msm_subsystem_map.h>
Ben Rombergerfce8f512011-07-18 16:46:09 -070042
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070043#include <sound/apr_audio.h>
44#include <sound/q6asm.h>
Ben Rombergerfce8f512011-07-18 16:46:09 -070045
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070046
47#define TRUE 0x01
48#define FALSE 0x00
49#define READDONE_IDX_STATUS 0
50#define READDONE_IDX_BUFFER 1
51#define READDONE_IDX_SIZE 2
52#define READDONE_IDX_OFFSET 3
53#define READDONE_IDX_MSW_TS 4
54#define READDONE_IDX_LSW_TS 5
55#define READDONE_IDX_FLAGS 6
56#define READDONE_IDX_NUMFRAMES 7
57#define READDONE_IDX_ID 8
Rajesha Kini3498c932011-07-19 19:58:27 +053058#ifdef CONFIG_DEBUG_FS
59#define OUT_BUFFER_SIZE 56
60#define IN_BUFFER_SIZE 24
61#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070062static DEFINE_MUTEX(session_lock);
63
64/* session id: 0 reserved */
65static struct audio_client *session[SESSION_MAX+1];
66static int32_t q6asm_mmapcallback(struct apr_client_data *data, void *priv);
67static int32_t q6asm_callback(struct apr_client_data *data, void *priv);
68static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
69 uint32_t pkt_size, uint32_t cmd_flg);
70static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
71 uint32_t pkt_size, uint32_t cmd_flg);
72static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
73 uint32_t bufsz, uint32_t bufcnt);
74static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
75 uint32_t bufsz, uint32_t bufcnt);
76
77static void q6asm_reset_buf_state(struct audio_client *ac);
78
Rajesha Kini3498c932011-07-19 19:58:27 +053079#ifdef CONFIG_DEBUG_FS
80static struct timeval out_cold_tv;
81static struct timeval out_warm_tv;
82static struct timeval out_cont_tv;
83static struct timeval in_cont_tv;
84static long out_enable_flag;
85static long in_enable_flag;
86static struct dentry *out_dentry;
87static struct dentry *in_dentry;
88static int in_cont_index;
89/*This var is used to keep track of first write done for cold output latency */
90static int out_cold_index;
91static char *out_buffer;
92static char *in_buffer;
93static int audio_output_latency_dbgfs_open(struct inode *inode,
94 struct file *file)
95{
96 file->private_data = inode->i_private;
97 return 0;
98}
99static ssize_t audio_output_latency_dbgfs_read(struct file *file,
100 char __user *buf, size_t count, loff_t *ppos)
101{
102 snprintf(out_buffer, OUT_BUFFER_SIZE, "%ld,%ld,%ld,%ld,%ld,%ld,",\
103 out_cold_tv.tv_sec, out_cold_tv.tv_usec, out_warm_tv.tv_sec,\
104 out_warm_tv.tv_usec, out_cont_tv.tv_sec, out_cont_tv.tv_usec);
105 return simple_read_from_buffer(buf, OUT_BUFFER_SIZE, ppos,
106 out_buffer, OUT_BUFFER_SIZE);
107}
108static ssize_t audio_output_latency_dbgfs_write(struct file *file,
109 const char __user *buf, size_t count, loff_t *ppos)
110{
111 char *temp;
112
113 if (count > 2*sizeof(char))
114 return -EINVAL;
115 else
116 temp = kmalloc(2*sizeof(char), GFP_KERNEL);
117
118 out_cold_index = 0;
119
120 if (temp) {
121 if (copy_from_user(temp, buf, 2*sizeof(char))) {
122 kfree(temp);
123 return -EFAULT;
124 }
125 if (!strict_strtol(temp, 10, &out_enable_flag)) {
126 kfree(temp);
127 return count;
128 }
129 kfree(temp);
130 }
131 return -EINVAL;
132}
133static const struct file_operations audio_output_latency_debug_fops = {
134 .open = audio_output_latency_dbgfs_open,
135 .read = audio_output_latency_dbgfs_read,
136 .write = audio_output_latency_dbgfs_write
137};
138
139static int audio_input_latency_dbgfs_open(struct inode *inode,
140 struct file *file)
141{
142 file->private_data = inode->i_private;
143 return 0;
144}
145static ssize_t audio_input_latency_dbgfs_read(struct file *file,
146 char __user *buf, size_t count, loff_t *ppos)
147{
148 snprintf(in_buffer, IN_BUFFER_SIZE, "%ld,%ld,",\
149 in_cont_tv.tv_sec, in_cont_tv.tv_usec);
150 return simple_read_from_buffer(buf, IN_BUFFER_SIZE, ppos,
151 in_buffer, IN_BUFFER_SIZE);
152}
153static ssize_t audio_input_latency_dbgfs_write(struct file *file,
154 const char __user *buf, size_t count, loff_t *ppos)
155{
156 char *temp;
157
158 if (count > 2*sizeof(char))
159 return -EINVAL;
160 else
161 temp = kmalloc(2*sizeof(char), GFP_KERNEL);
162 if (temp) {
163 if (copy_from_user(temp, buf, 2*sizeof(char))) {
164 kfree(temp);
165 return -EFAULT;
166 }
167 if (!strict_strtol(temp, 10, &in_enable_flag)) {
168 kfree(temp);
169 return count;
170 }
171 kfree(temp);
172 }
173 return -EINVAL;
174}
175static const struct file_operations audio_input_latency_debug_fops = {
176 .open = audio_input_latency_dbgfs_open,
177 .read = audio_input_latency_dbgfs_read,
178 .write = audio_input_latency_dbgfs_write
179};
180#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700181struct asm_mmap {
182 atomic_t ref_cnt;
183 atomic_t cmd_state;
184 wait_queue_head_t cmd_wait;
185 void *apr;
186};
187
188static struct asm_mmap this_mmap;
189
190static int q6asm_session_alloc(struct audio_client *ac)
191{
192 int n;
193 mutex_lock(&session_lock);
194 for (n = 1; n <= SESSION_MAX; n++) {
195 if (!session[n]) {
196 session[n] = ac;
197 mutex_unlock(&session_lock);
198 return n;
199 }
200 }
201 mutex_unlock(&session_lock);
202 return -ENOMEM;
203}
204
205static void q6asm_session_free(struct audio_client *ac)
206{
207 pr_debug("%s: sessionid[%d]\n", __func__, ac->session);
208 mutex_lock(&session_lock);
209 session[ac->session] = 0;
210 mutex_unlock(&session_lock);
211 ac->session = 0;
212 return;
213}
214
215int q6asm_audio_client_buf_free(unsigned int dir,
216 struct audio_client *ac)
217{
218 struct audio_port_data *port;
219 int cnt = 0;
220 int rc = 0;
221 pr_debug("%s: Session id %d\n", __func__, ac->session);
222 mutex_lock(&ac->cmd_lock);
223 if (ac->io_mode == SYNC_IO_MODE) {
224 port = &ac->port[dir];
225 if (!port->buf) {
226 mutex_unlock(&ac->cmd_lock);
227 return 0;
228 }
229 cnt = port->max_buf_cnt - 1;
230
231 if (cnt >= 0) {
232 rc = q6asm_memory_unmap_regions(ac, dir,
233 port->buf[0].size,
234 port->max_buf_cnt);
235 if (rc < 0)
236 pr_err("%s CMD Memory_unmap_regions failed\n",
237 __func__);
238 }
239
240 while (cnt >= 0) {
241 if (port->buf[cnt].data) {
242 pr_debug("%s:data[%p]phys[%p][%p] cnt[%d]"
243 "mem_buffer[%p]\n",
244 __func__, (void *)port->buf[cnt].data,
245 (void *)port->buf[cnt].phys,
246 (void *)&port->buf[cnt].phys, cnt,
247 (void *)port->buf[cnt].mem_buffer);
248 if (IS_ERR((void *)port->buf[cnt].mem_buffer))
249 pr_err("%s:mem buffer invalid, error ="
250 "%ld\n", __func__,
251 PTR_ERR((void *)port->buf[cnt].mem_buffer));
252 else {
253 if (msm_subsystem_unmap_buffer(
254 port->buf[cnt].mem_buffer) < 0)
255 pr_err("%s: unmap buffer"
256 " failed\n", __func__);
257 }
258 free_contiguous_memory_by_paddr(
259 port->buf[cnt].phys);
260
261 port->buf[cnt].data = NULL;
262 port->buf[cnt].phys = 0;
263 --(port->max_buf_cnt);
264 }
265 --cnt;
266 }
267 kfree(port->buf);
268 port->buf = NULL;
269 }
270 mutex_unlock(&ac->cmd_lock);
271 return 0;
272}
273
274int q6asm_audio_client_buf_free_contiguous(unsigned int dir,
275 struct audio_client *ac)
276{
277 struct audio_port_data *port;
278 int cnt = 0;
279 int rc = 0;
280 pr_debug("%s: Session id %d\n", __func__, ac->session);
281 mutex_lock(&ac->cmd_lock);
282 port = &ac->port[dir];
283 if (!port->buf) {
284 mutex_unlock(&ac->cmd_lock);
285 return 0;
286 }
287 cnt = port->max_buf_cnt - 1;
288
289 if (cnt >= 0) {
Deepa Madiregama7d52a402011-07-13 20:28:36 +0530290 rc = q6asm_memory_unmap(ac, port->buf[0].phys, dir);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700291 if (rc < 0)
292 pr_err("%s CMD Memory_unmap_regions failed\n",
293 __func__);
294 }
295
296 if (port->buf[0].data) {
297 pr_debug("%s:data[%p]phys[%p][%p] cnt[%d]\n",
298 __func__,
299 (void *)port->buf[0].data,
300 (void *)port->buf[0].phys,
301 (void *)&port->buf[0].phys, cnt);
302 dma_free_coherent(NULL,
303 port->buf[0].size * port->max_buf_cnt,
304 port->buf[0].data,
305 port->buf[0].phys);
306 }
307 while (cnt >= 0) {
308 port->buf[cnt].data = NULL;
309 port->buf[cnt].phys = 0;
310 cnt--;
311 }
312 port->max_buf_cnt = 0;
313 kfree(port->buf);
314 port->buf = NULL;
315 mutex_unlock(&ac->cmd_lock);
316 return 0;
317}
318
319void q6asm_audio_client_free(struct audio_client *ac)
320{
321 int loopcnt;
322 struct audio_port_data *port;
323 if (!ac || !ac->session)
324 return;
325 pr_debug("%s: Session id %d\n", __func__, ac->session);
326 if (ac->io_mode == SYNC_IO_MODE) {
327 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
328 port = &ac->port[loopcnt];
329 if (!port->buf)
330 continue;
331 pr_debug("%s:loopcnt = %d\n", __func__, loopcnt);
332 q6asm_audio_client_buf_free(loopcnt, ac);
333 }
334 }
335
336 apr_deregister(ac->apr);
337 q6asm_session_free(ac);
338
339 pr_debug("%s: APR De-Register\n", __func__);
340 if (atomic_read(&this_mmap.ref_cnt) <= 0) {
341 pr_err("%s: APR Common Port Already Closed\n", __func__);
342 goto done;
343 }
344
345 atomic_dec(&this_mmap.ref_cnt);
346 if (atomic_read(&this_mmap.ref_cnt) == 0) {
347 apr_deregister(this_mmap.apr);
348 pr_debug("%s:APR De-Register common port\n", __func__);
349 }
350done:
351 kfree(ac);
352 return;
353}
354
355int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode)
356{
357 if (ac == NULL) {
358 pr_err("%s APR handle NULL\n", __func__);
359 return -EINVAL;
360 }
361 if ((mode == ASYNC_IO_MODE) || (mode == SYNC_IO_MODE)) {
362 ac->io_mode = mode;
363 pr_debug("%s:Set Mode to %d\n", __func__, ac->io_mode);
364 return 0;
365 } else {
366 pr_err("%s:Not an valid IO Mode:%d\n", __func__, ac->io_mode);
367 return -EINVAL;
368 }
369}
370
371struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv)
372{
373 struct audio_client *ac;
374 int n;
375 int lcnt = 0;
376
377 ac = kzalloc(sizeof(struct audio_client), GFP_KERNEL);
378 if (!ac)
379 return NULL;
380 n = q6asm_session_alloc(ac);
381 if (n <= 0)
382 goto fail_session;
383 ac->session = n;
384 ac->cb = cb;
385 ac->priv = priv;
386 ac->io_mode = SYNC_IO_MODE;
387 ac->apr = apr_register("ADSP", "ASM", \
388 (apr_fn)q6asm_callback,\
389 ((ac->session) << 8 | 0x0001),\
390 ac);
391
392 if (ac->apr == NULL) {
393 pr_err("%s Registration with APR failed\n", __func__);
394 goto fail;
395 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700396 rtac_set_asm_handle(n, ac->apr);
Ben Rombergerfce8f512011-07-18 16:46:09 -0700397
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700398 pr_debug("%s Registering the common port with APR\n", __func__);
399 if (atomic_read(&this_mmap.ref_cnt) == 0) {
400 this_mmap.apr = apr_register("ADSP", "ASM", \
401 (apr_fn)q6asm_mmapcallback,\
402 0x0FFFFFFFF, &this_mmap);
403 if (this_mmap.apr == NULL) {
404 pr_debug("%s Unable to register \
405 APR ASM common port \n", __func__);
406 goto fail;
407 }
408 }
409
410 atomic_inc(&this_mmap.ref_cnt);
411 init_waitqueue_head(&ac->cmd_wait);
412 init_waitqueue_head(&ac->time_wait);
413 atomic_set(&ac->time_flag, 1);
414 mutex_init(&ac->cmd_lock);
415 for (lcnt = 0; lcnt <= OUT; lcnt++) {
416 mutex_init(&ac->port[lcnt].lock);
417 spin_lock_init(&ac->port[lcnt].dsp_lock);
418 }
419 atomic_set(&ac->cmd_state, 0);
420
421 pr_debug("%s: session[%d]\n", __func__, ac->session);
422
423 return ac;
424fail:
425 q6asm_audio_client_free(ac);
426 return NULL;
427fail_session:
428 kfree(ac);
429 return NULL;
430}
431
432int q6asm_audio_client_buf_alloc(unsigned int dir,
433 struct audio_client *ac,
434 unsigned int bufsz,
435 unsigned int bufcnt)
436{
437 int cnt = 0;
438 int rc = 0;
439 struct audio_buffer *buf;
440
441 if (!(ac) || ((dir != IN) && (dir != OUT)))
442 return -EINVAL;
443
444 pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n", __func__, ac->session,
445 bufsz, bufcnt);
446
447 if (ac->session <= 0 || ac->session > 8)
448 goto fail;
449
450 if (ac->io_mode == SYNC_IO_MODE) {
451 if (ac->port[dir].buf) {
452 pr_debug("%s: buffer already allocated\n", __func__);
453 return 0;
454 }
455 mutex_lock(&ac->cmd_lock);
456 buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
457 GFP_KERNEL);
458
459 if (!buf) {
460 mutex_unlock(&ac->cmd_lock);
461 goto fail;
462 }
463
464 ac->port[dir].buf = buf;
465
466 while (cnt < bufcnt) {
467 if (bufsz > 0) {
468 if (!buf[cnt].data) {
469 unsigned int flags = 0;
470 buf[cnt].phys =
471 allocate_contiguous_ebi_nomap(bufsz,
472 SZ_4K);
473 if (!buf[cnt].phys) {
474 pr_err("%s:Buf alloc failed "
475 " size=%d\n", __func__,
476 bufsz);
477 mutex_unlock(&ac->cmd_lock);
478 goto fail;
479 }
480 flags = MSM_SUBSYSTEM_MAP_KADDR |
481 MSM_SUBSYSTEM_MAP_CACHED;
482 buf[cnt].mem_buffer =
483 msm_subsystem_map_buffer(buf[cnt].phys,
484 bufsz, flags, NULL, 0);
485 if (IS_ERR(
486 (void *)buf[cnt].mem_buffer)) {
487 pr_err("%s:map_buffer failed,"
488 "error = %ld\n",
489 __func__, PTR_ERR((void *)buf[cnt].mem_buffer));
490 goto fail;
491 }
492 buf[cnt].data =
493 buf[cnt].mem_buffer->vaddr;
494 if (!buf[cnt].data) {
495 pr_err("%s:invalid vaddr,"
496 " iomap failed\n", __func__);
497 goto fail;
498 }
499 buf[cnt].used = 1;
500 buf[cnt].size = bufsz;
501 buf[cnt].actual_size = bufsz;
502 pr_debug("%s data[%p]phys[%p][%p]"
503 "mem_buffer[%p]\n",
504 __func__,
505 (void *)buf[cnt].data,
506 (void *)buf[cnt].phys,
507 (void *)&buf[cnt].phys,
508 (void *)buf[cnt].mem_buffer);
509 cnt++;
510 }
511 }
512 }
513 ac->port[dir].max_buf_cnt = cnt;
514
515 mutex_unlock(&ac->cmd_lock);
516 rc = q6asm_memory_map_regions(ac, dir, bufsz, cnt);
517 if (rc < 0) {
518 pr_err("%s:CMD Memory_map_regions failed\n", __func__);
519 goto fail;
520 }
521 }
522 return 0;
523fail:
524 q6asm_audio_client_buf_free(dir, ac);
525 return -EINVAL;
526}
527
528int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir,
529 struct audio_client *ac,
530 unsigned int bufsz,
531 unsigned int bufcnt)
532{
533 int cnt = 0;
534 int rc = 0;
535 struct audio_buffer *buf;
536
537 if (!(ac) || ((dir != IN) && (dir != OUT)))
538 return -EINVAL;
539
540 pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n",
541 __func__, ac->session,
542 bufsz, bufcnt);
543
544 if (ac->session <= 0 || ac->session > 8)
545 goto fail;
546
547 if (ac->port[dir].buf) {
548 pr_debug("%s: buffer already allocated\n", __func__);
549 return 0;
550 }
551 mutex_lock(&ac->cmd_lock);
552 buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
553 GFP_KERNEL);
554
555 if (!buf) {
556 mutex_unlock(&ac->cmd_lock);
557 goto fail;
558 }
559
560 ac->port[dir].buf = buf;
561
562 buf[0].data = dma_alloc_coherent(NULL, bufsz * bufcnt,
563 &buf[0].phys, GFP_KERNEL);
564 buf[0].used = dir ^ 1;
565 buf[0].size = bufsz;
566 buf[0].actual_size = bufsz;
567 cnt = 1;
568 while (cnt < bufcnt) {
569 if (bufsz > 0) {
570 buf[cnt].data = buf[0].data + (cnt * bufsz);
571 buf[cnt].phys = buf[0].phys + (cnt * bufsz);
572 if (!buf[cnt].data) {
573 pr_err("%s Buf alloc failed\n",
574 __func__);
575 mutex_unlock(&ac->cmd_lock);
576 goto fail;
577 }
578 buf[cnt].used = dir ^ 1;
579 buf[cnt].size = bufsz;
580 buf[cnt].actual_size = bufsz;
581 pr_debug("%s data[%p]phys[%p][%p]\n", __func__,
582 (void *)buf[cnt].data,
583 (void *)buf[cnt].phys,
584 (void *)&buf[cnt].phys);
585 }
586 cnt++;
587 }
588 ac->port[dir].max_buf_cnt = cnt;
589 mutex_unlock(&ac->cmd_lock);
590 rc = q6asm_memory_map(ac, buf[0].phys, dir, bufsz, cnt);
591 if (rc < 0) {
592 pr_err("%s:CMD Memory_map_regions failed\n", __func__);
593 goto fail;
594 }
595 return 0;
596fail:
597 q6asm_audio_client_buf_free_contiguous(dir, ac);
598 return -EINVAL;
599}
600
601static int32_t q6asm_mmapcallback(struct apr_client_data *data, void *priv)
602{
603 uint32_t token;
604 uint32_t *payload = data->payload;
605
606 if (data->opcode == RESET_EVENTS) {
607 pr_debug("%s: Reset event is received: %d %d apr[%p]\n",
608 __func__,
609 data->reset_event,
610 data->reset_proc,
611 this_mmap.apr);
612 apr_reset(this_mmap.apr);
613 this_mmap.apr = NULL;
614 atomic_set(&this_mmap.cmd_state, 0);
615 return 0;
616 }
617
618 pr_debug("%s:ptr0[0x%x]ptr1[0x%x]opcode[0x%x]"
619 "token[0x%x]payload_s[%d] src[%d] dest[%d]\n", __func__,
620 payload[0], payload[1], data->opcode, data->token,
621 data->payload_size, data->src_port, data->dest_port);
622
623 if (data->opcode == APR_BASIC_RSP_RESULT) {
624 token = data->token;
625 switch (payload[0]) {
626 case ASM_SESSION_CMD_MEMORY_MAP:
627 case ASM_SESSION_CMD_MEMORY_UNMAP:
628 case ASM_SESSION_CMD_MEMORY_MAP_REGIONS:
629 case ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS:
630 pr_debug("%s:command[0x%x]success [0x%x]\n",
631 __func__, payload[0], payload[1]);
632 if (atomic_read(&this_mmap.cmd_state)) {
633 atomic_set(&this_mmap.cmd_state, 0);
634 wake_up(&this_mmap.cmd_wait);
635 }
636 break;
637 default:
638 pr_debug("%s:command[0x%x] not expecting rsp\n",
639 __func__, payload[0]);
640 break;
641 }
642 }
643 return 0;
644}
645
646
647static int32_t q6asm_callback(struct apr_client_data *data, void *priv)
648{
649 int i = 0;
650 struct audio_client *ac = (struct audio_client *)priv;
651 uint32_t token;
652 unsigned long dsp_flags;
653 uint32_t *payload;
654
655
656 if ((ac == NULL) || (data == NULL)) {
657 pr_err("ac or priv NULL\n");
658 return -EINVAL;
659 }
660 if (ac->session <= 0 || ac->session > 8) {
661 pr_err("%s:Session ID is invalid, session = %d\n", __func__,
662 ac->session);
663 return -EINVAL;
664 }
665
666 payload = data->payload;
667
668 if (data->opcode == RESET_EVENTS) {
669 pr_debug("q6asm_callback: Reset event is received: %d %d apr[%p]\n",
670 data->reset_event, data->reset_proc, ac->apr);
671 apr_reset(ac->apr);
672 return 0;
673 }
674
675 pr_debug("%s: session[%d]opcode[0x%x] \
676 token[0x%x]payload_s[%d] src[%d] dest[%d]\n", __func__,
677 ac->session, data->opcode,
678 data->token, data->payload_size, data->src_port,
679 data->dest_port);
680
681 if (data->opcode == APR_BASIC_RSP_RESULT) {
682 token = data->token;
683 switch (payload[0]) {
684 case ASM_STREAM_CMD_SET_PP_PARAMS:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700685 if (rtac_make_asm_callback(ac->session, payload,
686 data->payload_size))
687 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700688 case ASM_SESSION_CMD_PAUSE:
689 case ASM_DATA_CMD_EOS:
690 case ASM_STREAM_CMD_CLOSE:
691 case ASM_STREAM_CMD_FLUSH:
692 case ASM_SESSION_CMD_RUN:
693 case ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS:
694 case ASM_STREAM_CMD_FLUSH_READBUFS:
695 pr_debug("%s:Payload = [0x%x]\n", __func__, payload[0]);
696 if (token != ac->session) {
697 pr_err("%s:Invalid session[%d] rxed expected[%d]",
698 __func__, token, ac->session);
699 return -EINVAL;
700 }
701 case ASM_STREAM_CMD_OPEN_READ:
702 case ASM_STREAM_CMD_OPEN_WRITE:
703 case ASM_STREAM_CMD_OPEN_READWRITE:
704 case ASM_DATA_CMD_MEDIA_FORMAT_UPDATE:
705 case ASM_STREAM_CMD_SET_ENCDEC_PARAM:
706 if (atomic_read(&ac->cmd_state)) {
707 atomic_set(&ac->cmd_state, 0);
708 wake_up(&ac->cmd_wait);
709 }
710 if (ac->cb)
711 ac->cb(data->opcode, data->token,
712 (uint32_t *)data->payload, ac->priv);
713 break;
714 default:
715 pr_debug("%s:command[0x%x] not expecting rsp\n",
716 __func__, payload[0]);
717 break;
718 }
719 return 0;
720 }
721
722 switch (data->opcode) {
723 case ASM_DATA_EVENT_WRITE_DONE:{
724 struct audio_port_data *port = &ac->port[IN];
725 pr_debug("%s: Rxed opcode[0x%x] status[0x%x] token[%d]",
726 __func__, payload[0], payload[1],
727 data->token);
728 if (ac->io_mode == SYNC_IO_MODE) {
729 if (port->buf == NULL) {
730 pr_err("%s: Unexpected Write Done\n",
731 __func__);
732 return -EINVAL;
733 }
734 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
735 if (port->buf[data->token].phys !=
736 payload[0]) {
737 pr_err("Buf expected[%p]rxed[%p]\n",\
738 (void *)port->buf[data->token].phys,\
739 (void *)payload[0]);
740 spin_unlock_irqrestore(&port->dsp_lock,
741 dsp_flags);
742 return -EINVAL;
743 }
744 token = data->token;
745 port->buf[token].used = 1;
746 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
Rajesha Kini3498c932011-07-19 19:58:27 +0530747#ifdef CONFIG_DEBUG_FS
748 if (out_enable_flag) {
749 /* For first Write done log the time and reset
750 out_cold_index*/
751 if (out_cold_index != 1) {
752 do_gettimeofday(&out_cold_tv);
753 pr_debug("COLD: apr_send_pkt at %ld \
754 sec %ld microsec\n",\
755 out_cold_tv.tv_sec,\
756 out_cold_tv.tv_usec);
757 out_cold_index = 1;
758 }
759 pr_debug("out_enable_flag %ld",\
760 out_enable_flag);
761 }
762#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700763 for (i = 0; i < port->max_buf_cnt; i++)
764 pr_debug("%d ", port->buf[i].used);
765
766 }
767 break;
768 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700769 case ASM_STREAM_CMDRSP_GET_PP_PARAMS:
770 rtac_make_asm_callback(ac->session, payload,
771 data->payload_size);
772 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700773 case ASM_DATA_EVENT_READ_DONE:{
774
775 struct audio_port_data *port = &ac->port[OUT];
Rajesha Kini3498c932011-07-19 19:58:27 +0530776#ifdef CONFIG_DEBUG_FS
777 if (in_enable_flag) {
778 /* when in_cont_index == 7, DSP would be
779 * writing into the 8th 512 byte buffer and this
780 * timestamp is tapped here.Once done it then writes
781 * to 9th 512 byte buffer.These two buffers(8th, 9th)
782 * reach the test application in 5th iteration and that
783 * timestamp is tapped at user level. The difference
784 * of these two timestamps gives us the time between
785 * the time at which dsp started filling the sample
786 * required and when it reached the test application.
787 * Hence continuous input latency
788 */
789 if (in_cont_index == 7) {
790 do_gettimeofday(&in_cont_tv);
791 pr_err("In_CONT:previous read buffer done \
792 at %ld sec %ld microsec\n",\
793 out_cont_tv.tv_sec, out_cont_tv.tv_usec);
794 }
795 }
796#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700797 pr_debug("%s:R-D: status=%d buff_add=%x act_size=%d offset=%d\n",
798 __func__, payload[READDONE_IDX_STATUS],
799 payload[READDONE_IDX_BUFFER],
800 payload[READDONE_IDX_SIZE],
801 payload[READDONE_IDX_OFFSET]);
802 pr_debug("%s:R-D:msw_ts=%d lsw_ts=%d flags=%d id=%d num=%d\n",
803 __func__, payload[READDONE_IDX_MSW_TS],
804 payload[READDONE_IDX_LSW_TS],
805 payload[READDONE_IDX_FLAGS],
806 payload[READDONE_IDX_ID],
807 payload[READDONE_IDX_NUMFRAMES]);
Rajesha Kini3498c932011-07-19 19:58:27 +0530808#ifdef CONFIG_DEBUG_FS
809 if (in_enable_flag) {
810 in_cont_index++;
811 }
812#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700813 if (ac->io_mode == SYNC_IO_MODE) {
814 if (port->buf == NULL) {
815 pr_err("%s: Unexpected Write Done\n", __func__);
816 return -EINVAL;
817 }
818 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
819 token = data->token;
820 port->buf[token].used = 0;
821 if (port->buf[token].phys !=
822 payload[READDONE_IDX_BUFFER]) {
823 pr_err("Buf expected[%p]rxed[%p]\n",\
824 (void *)port->buf[token].phys,\
825 (void *)payload[READDONE_IDX_BUFFER]);
826 spin_unlock_irqrestore(&port->dsp_lock,
827 dsp_flags);
828 break;
829 }
830 port->buf[token].actual_size =
831 payload[READDONE_IDX_SIZE];
832 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
833 }
834 break;
835 }
836 case ASM_DATA_EVENT_EOS:
837 case ASM_DATA_CMDRSP_EOS:
838 pr_debug("%s:EOS ACK received: rxed opcode[0x%x]\n",
839 __func__, data->opcode);
840 break;
841 case ASM_STREAM_CMDRSP_GET_ENCDEC_PARAM:
842 break;
843 case ASM_SESSION_EVENT_TX_OVERFLOW:
844 pr_err("ASM_SESSION_EVENT_TX_OVERFLOW\n");
845 break;
846 case ASM_SESSION_CMDRSP_GET_SESSION_TIME:
847 pr_debug("%s: ASM_SESSION_CMDRSP_GET_SESSION_TIME, "
848 "payload[0] = %d, payload[1] = %d, "
849 "payload[2] = %d\n", __func__,
850 payload[0], payload[1], payload[2]);
851 ac->time_stamp = (uint64_t)(((uint64_t)payload[1] << 32) |
852 payload[2]);
853 if (atomic_read(&ac->time_flag)) {
854 atomic_set(&ac->time_flag, 0);
855 wake_up(&ac->time_wait);
856 }
857 break;
858 case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY:
859 pr_debug("%s: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, "
860 "payload[0] = %d, payload[1] = %d, "
861 "payload[2] = %d, payload[3] = %d\n", __func__,
862 payload[0], payload[1], payload[2],
863 payload[3]);
864 break;
865 }
866 if (ac->cb)
867 ac->cb(data->opcode, data->token,
868 data->payload, ac->priv);
869
870 return 0;
871}
872
873void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac, uint32_t *size,
874 uint32_t *index)
875{
876 void *data;
877 unsigned char idx;
878 struct audio_port_data *port;
879
880 if (!ac || ((dir != IN) && (dir != OUT)))
881 return NULL;
882
883 if (ac->io_mode == SYNC_IO_MODE) {
884 port = &ac->port[dir];
885
886 mutex_lock(&port->lock);
887 idx = port->cpu_buf;
888 if (port->buf == NULL) {
889 pr_debug("%s:Buffer pointer null\n", __func__);
890 return NULL;
891 }
892 /* dir 0: used = 0 means buf in use
893 dir 1: used = 1 means buf in use */
894 if (port->buf[idx].used == dir) {
895 /* To make it more robust, we could loop and get the
896 next avail buf, its risky though */
897 pr_debug("%s:Next buf idx[0x%x] not available,\
898 dir[%d]\n", __func__, idx, dir);
899 mutex_unlock(&port->lock);
900 return NULL;
901 }
902 *size = port->buf[idx].actual_size;
903 *index = port->cpu_buf;
904 data = port->buf[idx].data;
905 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
906 __func__,
907 ac->session,
908 port->cpu_buf,
909 data, *size);
910 /* By default increase the cpu_buf cnt
911 user accesses this function,increase cpu
912 buf(to avoid another api)*/
913 port->buf[idx].used = dir;
914 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
915 mutex_unlock(&port->lock);
916 return data;
917 }
918 return NULL;
919}
920
Jay Wang9cf59a02011-08-10 16:58:40 -0700921void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
922 uint32_t *size, uint32_t *index)
923{
924 void *data;
925 unsigned char idx;
926 struct audio_port_data *port;
927
928 if (!ac || ((dir != IN) && (dir != OUT)))
929 return NULL;
930
931 port = &ac->port[dir];
932
933 idx = port->cpu_buf;
934 if (port->buf == NULL) {
935 pr_debug("%s:Buffer pointer null\n", __func__);
936 return NULL;
937 }
938 /*
939 * dir 0: used = 0 means buf in use
940 * dir 1: used = 1 means buf in use
941 */
942 if (port->buf[idx].used == dir) {
943 /*
944 * To make it more robust, we could loop and get the
945 * next avail buf, its risky though
946 */
947 pr_debug("%s:Next buf idx[0x%x] not available,\
948 dir[%d]\n", __func__, idx, dir);
949 return NULL;
950 }
951 *size = port->buf[idx].actual_size;
952 *index = port->cpu_buf;
953 data = port->buf[idx].data;
954 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
955 __func__, ac->session, port->cpu_buf,
956 data, *size);
957 /*
958 * By default increase the cpu_buf cnt
959 * user accesses this function,increase cpu
960 * buf(to avoid another api)
961 */
962 port->buf[idx].used = dir;
963 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
964 return data;
965}
966
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700967int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac)
968{
969 int ret = -1;
970 struct audio_port_data *port;
971 uint32_t idx;
972
973 if (!ac || (dir != OUT))
974 return ret;
975
976 if (ac->io_mode == SYNC_IO_MODE) {
977 port = &ac->port[dir];
978
979 mutex_lock(&port->lock);
980 idx = port->dsp_buf;
981
982 if (port->buf[idx].used == (dir ^ 1)) {
983 /* To make it more robust, we could loop and get the
984 next avail buf, its risky though */
985 pr_err("Next buf idx[0x%x] not available, dir[%d]\n",
986 idx, dir);
987 mutex_unlock(&port->lock);
988 return ret;
989 }
990 pr_debug("%s: session[%d]dsp_buf=%d cpu_buf=%d\n", __func__,
991 ac->session, port->dsp_buf, port->cpu_buf);
992 ret = ((port->dsp_buf != port->cpu_buf) ? 0 : -1);
993 mutex_unlock(&port->lock);
994 }
995 return ret;
996}
997
998static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
999 uint32_t pkt_size, uint32_t cmd_flg)
1000{
1001 pr_debug("%s:session=%d pkt size=%d cmd_flg=%d\n", __func__, pkt_size,
1002 cmd_flg, ac->session);
1003 mutex_lock(&ac->cmd_lock);
1004 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1005 APR_HDR_LEN(sizeof(struct apr_hdr)),\
1006 APR_PKT_VER);
1007 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
1008 hdr->src_domain = APR_DOMAIN_APPS;
1009 hdr->dest_svc = APR_SVC_ASM;
1010 hdr->dest_domain = APR_DOMAIN_ADSP;
1011 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
1012 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
1013 if (cmd_flg) {
1014 hdr->token = ac->session;
1015 atomic_set(&ac->cmd_state, 1);
1016 }
1017 hdr->pkt_size = pkt_size;
1018 mutex_unlock(&ac->cmd_lock);
1019 return;
1020}
1021
1022static void q6asm_add_mmaphdr(struct apr_hdr *hdr, uint32_t pkt_size,
1023 uint32_t cmd_flg)
1024{
1025 pr_debug("%s:pkt size=%d cmd_flg=%d\n", __func__, pkt_size, cmd_flg);
1026 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1027 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1028 hdr->src_port = 0;
1029 hdr->dest_port = 0;
1030 if (cmd_flg) {
1031 hdr->token = 0;
1032 atomic_set(&this_mmap.cmd_state, 1);
1033 }
1034 hdr->pkt_size = pkt_size;
1035 return;
1036}
1037
1038int q6asm_open_read(struct audio_client *ac,
1039 uint32_t format)
1040{
1041 int rc = 0x00;
1042 struct asm_stream_cmd_open_read open;
Rajesha Kini3498c932011-07-19 19:58:27 +05301043#ifdef CONFIG_DEBUG_FS
1044 in_cont_index = 0;
1045#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001046 if ((ac == NULL) || (ac->apr == NULL)) {
1047 pr_err("%s: APR handle NULL\n", __func__);
1048 return -EINVAL;
1049 }
1050 pr_debug("%s:session[%d]", __func__, ac->session);
1051
1052 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1053 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ;
1054 /* Stream prio : High, provide meta info with encoded frames */
1055 open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1056
1057 open.pre_proc_top = get_asm_topology();
1058 if (open.pre_proc_top == 0)
1059 open.pre_proc_top = DEFAULT_POPP_TOPOLOGY;
1060
1061 switch (format) {
1062 case FORMAT_LINEAR_PCM:
1063 open.uMode = STREAM_PRIORITY_HIGH;
1064 open.format = LINEAR_PCM;
1065 break;
1066 case FORMAT_MPEG4_AAC:
1067 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1068 open.format = MPEG4_AAC;
1069 break;
1070 case FORMAT_V13K:
1071 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1072 open.format = V13K_FS;
1073 break;
1074 case FORMAT_EVRC:
1075 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1076 open.format = EVRC_FS;
1077 break;
1078 case FORMAT_AMRNB:
1079 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1080 open.format = AMRNB_FS;
1081 break;
1082 default:
1083 pr_err("Invalid format[%d]\n", format);
1084 goto fail_cmd;
1085 }
1086 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1087 if (rc < 0) {
1088 pr_err("open failed op[0x%x]rc[%d]\n", \
1089 open.hdr.opcode, rc);
1090 goto fail_cmd;
1091 }
1092 rc = wait_event_timeout(ac->cmd_wait,
1093 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1094 if (!rc) {
1095 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1096 rc);
1097 goto fail_cmd;
1098 }
1099 return 0;
1100fail_cmd:
1101 return -EINVAL;
1102}
1103
1104int q6asm_open_write(struct audio_client *ac, uint32_t format)
1105{
1106 int rc = 0x00;
1107 struct asm_stream_cmd_open_write open;
1108
1109 if ((ac == NULL) || (ac->apr == NULL)) {
1110 pr_err("%s: APR handle NULL\n", __func__);
1111 return -EINVAL;
1112 }
1113 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1114 format);
1115
1116 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1117
1118 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE;
1119 open.uMode = STREAM_PRIORITY_HIGH;
1120 /* source endpoint : matrix */
1121 open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1122 open.stream_handle = 0x00;
1123
1124 open.post_proc_top = get_asm_topology();
1125 if (open.post_proc_top == 0)
1126 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1127
1128 switch (format) {
1129 case FORMAT_LINEAR_PCM:
1130 open.format = LINEAR_PCM;
1131 break;
1132 case FORMAT_MPEG4_AAC:
1133 open.format = MPEG4_AAC;
1134 break;
1135 case FORMAT_WMA_V9:
1136 open.format = WMA_V9;
1137 break;
1138 case FORMAT_WMA_V10PRO:
1139 open.format = WMA_V10PRO;
1140 break;
1141 default:
1142 pr_err("%s: Invalid format[%d]\n", __func__, format);
1143 goto fail_cmd;
1144 }
1145 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1146 if (rc < 0) {
1147 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1148 __func__, open.hdr.opcode, rc);
1149 goto fail_cmd;
1150 }
1151 rc = wait_event_timeout(ac->cmd_wait,
1152 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1153 if (!rc) {
1154 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1155 rc);
1156 goto fail_cmd;
1157 }
1158 return 0;
1159fail_cmd:
1160 return -EINVAL;
1161}
1162
1163int q6asm_open_read_write(struct audio_client *ac,
1164 uint32_t rd_format,
1165 uint32_t wr_format)
1166{
1167 int rc = 0x00;
1168 struct asm_stream_cmd_open_read_write open;
1169
1170 if ((ac == NULL) || (ac->apr == NULL)) {
1171 pr_err("APR handle NULL\n");
1172 return -EINVAL;
1173 }
1174 pr_debug("%s: session[%d]", __func__, ac->session);
1175 pr_debug("wr_format[0x%x]rd_format[0x%x]",
1176 wr_format, rd_format);
1177
1178 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1179 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE;
1180
1181 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_NORMAL |
1182 SR_CM_NOTIFY_ENABLE;
1183 /* source endpoint : matrix */
1184 open.post_proc_top = get_asm_topology();
1185 if (open.post_proc_top == 0)
1186 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1187
1188 switch (wr_format) {
1189 case FORMAT_LINEAR_PCM:
1190 open.write_format = LINEAR_PCM;
1191 break;
1192 case FORMAT_MPEG4_AAC:
1193 open.write_format = MPEG4_AAC;
1194 break;
1195 case FORMAT_WMA_V9:
1196 open.write_format = WMA_V9;
1197 break;
1198 case FORMAT_WMA_V10PRO:
1199 open.write_format = WMA_V10PRO;
1200 break;
1201 default:
1202 pr_err("Invalid format[%d]\n", wr_format);
1203 goto fail_cmd;
1204 }
1205
1206 switch (rd_format) {
1207 case FORMAT_LINEAR_PCM:
1208 open.read_format = LINEAR_PCM;
1209 break;
1210 case FORMAT_MPEG4_AAC:
1211 open.read_format = MPEG4_AAC;
1212 break;
1213 case FORMAT_V13K:
1214 open.read_format = V13K_FS;
1215 break;
1216 case FORMAT_EVRC:
1217 open.read_format = EVRC_FS;
1218 break;
1219 case FORMAT_AMRNB:
1220 open.read_format = AMRNB_FS;
1221 break;
1222 default:
1223 pr_err("Invalid format[%d]\n", rd_format);
1224 goto fail_cmd;
1225 }
1226 pr_debug("%s:rdformat[0x%x]wrformat[0x%x]\n", __func__,
1227 open.read_format, open.write_format);
1228
1229 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1230 if (rc < 0) {
1231 pr_err("open failed op[0x%x]rc[%d]\n", \
1232 open.hdr.opcode, rc);
1233 goto fail_cmd;
1234 }
1235 rc = wait_event_timeout(ac->cmd_wait,
1236 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1237 if (!rc) {
1238 pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc);
1239 goto fail_cmd;
1240 }
1241 return 0;
1242fail_cmd:
1243 return -EINVAL;
1244}
1245
1246int q6asm_run(struct audio_client *ac, uint32_t flags,
1247 uint32_t msw_ts, uint32_t lsw_ts)
1248{
1249 struct asm_stream_cmd_run run;
1250 int rc;
1251 if (!ac || ac->apr == NULL) {
1252 pr_err("APR handle NULL\n");
1253 return -EINVAL;
1254 }
1255 pr_debug("%s session[%d]", __func__, ac->session);
1256 q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
1257
1258 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1259 run.flags = flags;
1260 run.msw_ts = msw_ts;
1261 run.lsw_ts = lsw_ts;
Rajesha Kini3498c932011-07-19 19:58:27 +05301262#ifdef CONFIG_DEBUG_FS
1263 if (out_enable_flag) {
1264 do_gettimeofday(&out_cold_tv);
1265 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",\
1266 out_cold_tv.tv_sec, out_cold_tv.tv_usec);
1267 }
1268#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001269 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1270 if (rc < 0) {
1271 pr_err("Commmand run failed[%d]", rc);
1272 goto fail_cmd;
1273 }
1274
1275 rc = wait_event_timeout(ac->cmd_wait,
1276 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1277 if (!rc) {
1278 pr_err("timeout. waited for run success rc[%d]", rc);
1279 goto fail_cmd;
1280 }
1281
1282 return 0;
1283fail_cmd:
1284 return -EINVAL;
1285}
1286
1287int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
1288 uint32_t msw_ts, uint32_t lsw_ts)
1289{
1290 struct asm_stream_cmd_run run;
1291 int rc;
1292 if (!ac || ac->apr == NULL) {
1293 pr_err("%s:APR handle NULL\n", __func__);
1294 return -EINVAL;
1295 }
1296 pr_debug("session[%d]", ac->session);
1297 q6asm_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE);
1298
1299 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1300 run.flags = flags;
1301 run.msw_ts = msw_ts;
1302 run.lsw_ts = lsw_ts;
1303
1304 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1305 if (rc < 0) {
1306 pr_err("%s:Commmand run failed[%d]", __func__, rc);
1307 return -EINVAL;
1308 }
1309 return 0;
1310}
1311
1312
1313int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
1314 uint32_t frames_per_buf,
1315 uint32_t sample_rate, uint32_t channels,
1316 uint32_t bit_rate, uint32_t mode, uint32_t format)
1317{
1318 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1319 int rc = 0;
1320
1321 pr_debug("%s:session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d]"
1322 "format[%d]", __func__, ac->session, frames_per_buf,
1323 sample_rate, channels, bit_rate, mode, format);
1324
1325 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1326
1327 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1328 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1329 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1330 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1331 enc_cfg.enc_blk.format_id = MPEG4_AAC;
1332 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_aac_read_cfg);
1333 enc_cfg.enc_blk.cfg.aac.bitrate = bit_rate;
1334 enc_cfg.enc_blk.cfg.aac.enc_mode = mode;
1335 enc_cfg.enc_blk.cfg.aac.format = format;
1336 enc_cfg.enc_blk.cfg.aac.ch_cfg = channels;
1337 enc_cfg.enc_blk.cfg.aac.sample_rate = sample_rate;
1338
1339 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1340 if (rc < 0) {
1341 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1342 rc = -EINVAL;
1343 goto fail_cmd;
1344 }
1345 rc = wait_event_timeout(ac->cmd_wait,
1346 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1347 if (!rc) {
1348 pr_err("timeout. waited for FORMAT_UPDATE\n");
1349 goto fail_cmd;
1350 }
1351 return 0;
1352fail_cmd:
1353 return -EINVAL;
1354}
1355
1356int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
1357 uint32_t rate, uint32_t channels)
1358{
1359 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1360
1361 int rc = 0;
1362
1363 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1364 ac->session, rate, channels);
1365
1366 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1367
1368 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1369 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1370 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1371 enc_cfg.enc_blk.frames_per_buf = 1;
1372 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1373 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1374 enc_cfg.enc_blk.cfg.pcm.ch_cfg = channels;
1375 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1376 enc_cfg.enc_blk.cfg.pcm.sample_rate = rate;
1377 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1378 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1379
1380 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1381 if (rc < 0) {
1382 pr_err("Comamnd open failed\n");
1383 rc = -EINVAL;
1384 goto fail_cmd;
1385 }
1386 rc = wait_event_timeout(ac->cmd_wait,
1387 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1388 if (!rc) {
1389 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1390 goto fail_cmd;
1391 }
1392 return 0;
1393fail_cmd:
1394 return -EINVAL;
1395}
1396
1397int q6asm_enable_sbrps(struct audio_client *ac,
1398 uint32_t sbr_ps_enable)
1399{
1400 struct asm_stream_cmd_encdec_sbr sbrps;
1401
1402 int rc = 0;
1403
1404 pr_debug("%s: Session %d\n", __func__, ac->session);
1405
1406 q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
1407
1408 sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1409 sbrps.param_id = ASM_ENABLE_SBR_PS;
1410 sbrps.param_size = sizeof(struct asm_sbr_ps);
1411 sbrps.sbr_ps.enable = sbr_ps_enable;
1412
1413 rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
1414 if (rc < 0) {
1415 pr_err("Command opcode[0x%x]paramid[0x%x] failed\n",
1416 ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1417 ASM_ENABLE_SBR_PS);
1418 rc = -EINVAL;
1419 goto fail_cmd;
1420 }
1421 rc = wait_event_timeout(ac->cmd_wait,
1422 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1423 if (!rc) {
1424 pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode);
1425 goto fail_cmd;
1426 }
1427 return 0;
1428fail_cmd:
1429 return -EINVAL;
1430}
1431
Swaminathan Sathappan70765cd2011-07-19 18:42:47 -07001432int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
1433 uint16_t sce_left, uint16_t sce_right)
1434{
1435 struct asm_stream_cmd_encdec_dualmono dual_mono;
1436
1437 int rc = 0;
1438
1439 pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
1440 __func__, ac->session, sce_left, sce_right);
1441
1442 q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
1443
1444 dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1445 dual_mono.param_id = ASM_CONFIGURE_DUAL_MONO;
1446 dual_mono.param_size = sizeof(struct asm_dual_mono);
1447 dual_mono.channel_map.sce_left = sce_left;
1448 dual_mono.channel_map.sce_right = sce_right;
1449
1450 rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
1451 if (rc < 0) {
1452 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
1453 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1454 ASM_CONFIGURE_DUAL_MONO);
1455 rc = -EINVAL;
1456 goto fail_cmd;
1457 }
1458 rc = wait_event_timeout(ac->cmd_wait,
1459 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1460 if (!rc) {
1461 pr_err("%s:timeout opcode[0x%x]\n", __func__,
1462 dual_mono.hdr.opcode);
1463 goto fail_cmd;
1464 }
1465 return 0;
1466fail_cmd:
1467 return -EINVAL;
1468}
1469
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001470int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
1471 uint16_t min_rate, uint16_t max_rate,
1472 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
1473{
1474 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1475 int rc = 0;
1476
1477 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] \
1478 reduced_rate_level[0x%4x]rate_modulation_cmd[0x%4x]", __func__,
1479 ac->session, frames_per_buf, min_rate, max_rate,
1480 reduced_rate_level, rate_modulation_cmd);
1481
1482 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1483
1484 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1485
1486 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1487 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1488
1489 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1490 enc_cfg.enc_blk.format_id = V13K_FS;
1491 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg);
1492 enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate;
1493 enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate;
1494 enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level;
1495 enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_cmd = rate_modulation_cmd;
1496
1497 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1498 if (rc < 0) {
1499 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1500 goto fail_cmd;
1501 }
1502 rc = wait_event_timeout(ac->cmd_wait,
1503 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1504 if (!rc) {
1505 pr_err("timeout. waited for FORMAT_UPDATE\n");
1506 goto fail_cmd;
1507 }
1508 return 0;
1509fail_cmd:
1510 return -EINVAL;
1511}
1512
1513int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
1514 uint16_t min_rate, uint16_t max_rate,
1515 uint16_t rate_modulation_cmd)
1516{
1517 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1518 int rc = 0;
1519
1520 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] \
1521 rate_modulation_cmd[0x%4x]", __func__, ac->session,
1522 frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
1523
1524 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1525
1526 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1527
1528 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1529 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1530
1531 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1532 enc_cfg.enc_blk.format_id = EVRC_FS;
1533 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg);
1534 enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate;
1535 enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate;
1536 enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd;
1537 enc_cfg.enc_blk.cfg.evrc.reserved = 0;
1538
1539 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1540 if (rc < 0) {
1541 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1542 goto fail_cmd;
1543 }
1544 rc = wait_event_timeout(ac->cmd_wait,
1545 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1546 if (!rc) {
1547 pr_err("timeout. waited for FORMAT_UPDATE\n");
1548 goto fail_cmd;
1549 }
1550 return 0;
1551fail_cmd:
1552 return -EINVAL;
1553}
1554
1555int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
1556 uint16_t band_mode, uint16_t dtx_enable)
1557{
1558 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1559 int rc = 0;
1560
1561 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
1562 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
1563
1564 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1565
1566 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1567
1568 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1569 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1570
1571 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1572 enc_cfg.enc_blk.format_id = AMRNB_FS;
1573 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg);
1574 enc_cfg.enc_blk.cfg.amrnb.mode = band_mode;
1575 enc_cfg.enc_blk.cfg.amrnb.dtx_mode = dtx_enable;
1576
1577 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1578 if (rc < 0) {
1579 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1580 goto fail_cmd;
1581 }
1582 rc = wait_event_timeout(ac->cmd_wait,
1583 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1584 if (!rc) {
1585 pr_err("timeout. waited for FORMAT_UPDATE\n");
1586 goto fail_cmd;
1587 }
1588 return 0;
1589fail_cmd:
1590 return -EINVAL;
1591}
1592
1593int q6asm_media_format_block_pcm(struct audio_client *ac,
1594 uint32_t rate, uint32_t channels)
1595{
1596 struct asm_stream_media_format_update fmt;
1597 int rc = 0;
1598
1599 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
1600 channels);
1601
1602 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
1603
1604 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
1605
1606 fmt.format = LINEAR_PCM;
1607 fmt.cfg_size = sizeof(struct asm_pcm_cfg);
1608 fmt.write_cfg.pcm_cfg.ch_cfg = channels;
1609 fmt.write_cfg.pcm_cfg.bits_per_sample = 16;
1610 fmt.write_cfg.pcm_cfg.sample_rate = rate;
1611 fmt.write_cfg.pcm_cfg.is_signed = 1;
1612 fmt.write_cfg.pcm_cfg.interleaved = 1;
1613
1614 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
1615 if (rc < 0) {
1616 pr_err("%s:Comamnd open failed\n", __func__);
1617 goto fail_cmd;
1618 }
1619 rc = wait_event_timeout(ac->cmd_wait,
1620 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1621 if (!rc) {
1622 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
1623 goto fail_cmd;
1624 }
1625 return 0;
1626fail_cmd:
1627 return -EINVAL;
1628}
1629
1630int q6asm_media_format_block_aac(struct audio_client *ac,
1631 struct asm_aac_cfg *cfg)
1632{
1633 struct asm_stream_media_format_update fmt;
1634 int rc = 0;
1635
1636 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
1637 cfg->sample_rate, cfg->ch_cfg);
1638
1639 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
1640
1641 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
1642
1643 fmt.format = MPEG4_AAC;
1644 fmt.cfg_size = sizeof(struct asm_aac_cfg);
1645 fmt.write_cfg.aac_cfg.format = cfg->format;
1646 fmt.write_cfg.aac_cfg.aot = cfg->aot;
1647 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
1648 fmt.write_cfg.aac_cfg.section_data_resilience =
1649 cfg->section_data_resilience;
1650 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
1651 cfg->scalefactor_data_resilience;
1652 fmt.write_cfg.aac_cfg.spectral_data_resilience =
1653 cfg->spectral_data_resilience;
1654 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
1655 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
1656 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
1657 __func__, fmt.format, fmt.cfg_size,
1658 fmt.write_cfg.aac_cfg.format,
1659 fmt.write_cfg.aac_cfg.aot,
1660 fmt.write_cfg.aac_cfg.ch_cfg,
1661 fmt.write_cfg.aac_cfg.sample_rate);
1662 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
1663 if (rc < 0) {
1664 pr_err("%s:Comamnd open failed\n", __func__);
1665 goto fail_cmd;
1666 }
1667 rc = wait_event_timeout(ac->cmd_wait,
1668 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1669 if (!rc) {
1670 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
1671 goto fail_cmd;
1672 }
1673 return 0;
1674fail_cmd:
1675 return -EINVAL;
1676}
1677
1678int q6asm_media_format_block_wma(struct audio_client *ac,
1679 void *cfg)
1680{
1681 struct asm_stream_media_format_update fmt;
1682 struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
1683 int rc = 0;
1684
1685 pr_debug("session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d],\
1686 balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x]\n",
1687 ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
1688 wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
1689 wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
1690 wma_cfg->ch_mask, wma_cfg->encode_opt);
1691
1692 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
1693
1694 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
1695
1696 fmt.format = WMA_V9;
1697 fmt.cfg_size = sizeof(struct asm_wma_cfg);
1698 fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag;
1699 fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg;
1700 fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate;
1701 fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
1702 fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align;
1703 fmt.write_cfg.wma_cfg.valid_bits_per_sample =
1704 wma_cfg->valid_bits_per_sample;
1705 fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask;
1706 fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt;
1707 fmt.write_cfg.wma_cfg.adv_encode_opt = 0;
1708 fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0;
1709 fmt.write_cfg.wma_cfg.drc_peak_ref = 0;
1710 fmt.write_cfg.wma_cfg.drc_peak_target = 0;
1711 fmt.write_cfg.wma_cfg.drc_ave_ref = 0;
1712 fmt.write_cfg.wma_cfg.drc_ave_target = 0;
1713
1714 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
1715 if (rc < 0) {
1716 pr_err("%s:Comamnd open failed\n", __func__);
1717 goto fail_cmd;
1718 }
1719 rc = wait_event_timeout(ac->cmd_wait,
1720 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1721 if (!rc) {
1722 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
1723 goto fail_cmd;
1724 }
1725 return 0;
1726fail_cmd:
1727 return -EINVAL;
1728}
1729
1730int q6asm_media_format_block_wmapro(struct audio_client *ac,
1731 void *cfg)
1732{
1733 struct asm_stream_media_format_update fmt;
1734 struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
1735 int rc = 0;
1736
1737 pr_debug("session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d],"
1738 "balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x],\
1739 adv_enc_opt[0x%4x], adv_enc_opt2[0x%8x]\n",
1740 ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
1741 wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
1742 wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
1743 wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
1744 wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
1745
1746 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
1747
1748 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
1749
1750 fmt.format = WMA_V10PRO;
1751 fmt.cfg_size = sizeof(struct asm_wmapro_cfg);
1752 fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag;
1753 fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg;
1754 fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate;
1755 fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec =
1756 wmapro_cfg->avg_bytes_per_sec;
1757 fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align;
1758 fmt.write_cfg.wmapro_cfg.valid_bits_per_sample =
1759 wmapro_cfg->valid_bits_per_sample;
1760 fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask;
1761 fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt;
1762 fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt;
1763 fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2;
1764 fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0;
1765 fmt.write_cfg.wmapro_cfg.drc_peak_target = 0;
1766 fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0;
1767 fmt.write_cfg.wmapro_cfg.drc_ave_target = 0;
1768
1769 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
1770 if (rc < 0) {
1771 pr_err("%s:Comamnd open failed\n", __func__);
1772 goto fail_cmd;
1773 }
1774 rc = wait_event_timeout(ac->cmd_wait,
1775 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1776 if (!rc) {
1777 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
1778 goto fail_cmd;
1779 }
1780 return 0;
1781fail_cmd:
1782 return -EINVAL;
1783}
1784
1785int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
1786 uint32_t bufsz, uint32_t bufcnt)
1787{
1788 struct asm_stream_cmd_memory_map mem_map;
1789 int rc = 0;
1790
1791 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
1792 pr_err("APR handle NULL\n");
1793 return -EINVAL;
1794 }
1795
1796 pr_debug("%s: Session[%d]\n", __func__, ac->session);
1797
1798 mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP;
1799
1800 mem_map.buf_add = buf_add;
1801 mem_map.buf_size = bufsz * bufcnt;
1802 mem_map.mempool_id = 0; /* EBI */
1803 mem_map.reserved = 0;
1804
1805 q6asm_add_mmaphdr(&mem_map.hdr,
1806 sizeof(struct asm_stream_cmd_memory_map), TRUE);
1807
1808 pr_debug("buf add[%x] buf_add_parameter[%x]\n",
1809 mem_map.buf_add, buf_add);
1810
1811 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map);
1812 if (rc < 0) {
1813 pr_err("mem_map op[0x%x]rc[%d]\n",
1814 mem_map.hdr.opcode, rc);
1815 rc = -EINVAL;
1816 goto fail_cmd;
1817 }
1818
1819 rc = wait_event_timeout(this_mmap.cmd_wait,
1820 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
1821 if (!rc) {
1822 pr_err("timeout. waited for memory_map\n");
1823 rc = -EINVAL;
1824 goto fail_cmd;
1825 }
1826 rc = 0;
1827fail_cmd:
1828 return rc;
1829}
1830
1831int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
1832{
1833 struct asm_stream_cmd_memory_unmap mem_unmap;
1834 int rc = 0;
1835
1836 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
1837 pr_err("APR handle NULL\n");
1838 return -EINVAL;
1839 }
1840 pr_debug("%s: Session[%d]\n", __func__, ac->session);
1841
1842 q6asm_add_mmaphdr(&mem_unmap.hdr,
1843 sizeof(struct asm_stream_cmd_memory_unmap), TRUE);
1844 mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP;
1845 mem_unmap.buf_add = buf_add;
1846
1847 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_unmap);
1848 if (rc < 0) {
1849 pr_err("mem_unmap op[0x%x]rc[%d]\n",
1850 mem_unmap.hdr.opcode, rc);
1851 rc = -EINVAL;
1852 goto fail_cmd;
1853 }
1854
1855 rc = wait_event_timeout(this_mmap.cmd_wait,
1856 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
1857 if (!rc) {
1858 pr_err("timeout. waited for memory_map\n");
1859 rc = -EINVAL;
1860 goto fail_cmd;
1861 }
1862 rc = 0;
1863fail_cmd:
1864 return rc;
1865}
1866
1867int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
1868{
1869 void *vol_cmd = NULL;
1870 void *payload = NULL;
1871 struct asm_pp_params_command *cmd = NULL;
1872 struct asm_lrchannel_gain_params *lrgain = NULL;
1873 int sz = 0;
1874 int rc = 0;
1875
1876 sz = sizeof(struct asm_pp_params_command) +
1877 + sizeof(struct asm_lrchannel_gain_params);
1878 vol_cmd = kzalloc(sz, GFP_KERNEL);
1879 if (vol_cmd == NULL) {
1880 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
1881 rc = -EINVAL;
1882 return rc;
1883 }
1884 cmd = (struct asm_pp_params_command *)vol_cmd;
1885 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
1886 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
1887 cmd->payload = NULL;
1888 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
1889 sizeof(struct asm_lrchannel_gain_params);
1890 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
1891 cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID;
1892 cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params);
1893 cmd->params.reserved = 0;
1894
1895 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
1896 lrgain = (struct asm_lrchannel_gain_params *)payload;
1897
1898 lrgain->left_gain = left_gain;
1899 lrgain->right_gain = right_gain;
1900 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
1901 if (rc < 0) {
1902 pr_err("%s: Volume Command failed\n", __func__);
1903 rc = -EINVAL;
1904 goto fail_cmd;
1905 }
1906
1907 rc = wait_event_timeout(ac->cmd_wait,
1908 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1909 if (!rc) {
1910 pr_err("%s: timeout in sending volume command to apr\n",
1911 __func__);
1912 rc = -EINVAL;
1913 goto fail_cmd;
1914 }
1915 rc = 0;
1916fail_cmd:
1917 kfree(vol_cmd);
1918 return rc;
1919}
1920
1921static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
1922 uint32_t bufsz, uint32_t bufcnt)
1923{
1924 struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL;
1925 struct asm_memory_map_regions *mregions = NULL;
1926 struct audio_port_data *port = NULL;
1927 struct audio_buffer *ab = NULL;
1928 void *mmap_region_cmd = NULL;
1929 void *payload = NULL;
1930 int rc = 0;
1931 int i = 0;
1932 int cmd_size = 0;
1933
1934 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
1935 pr_err("APR handle NULL\n");
1936 return -EINVAL;
1937 }
1938 pr_debug("%s: Session[%d]\n", __func__, ac->session);
1939
1940 cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions)
1941 + sizeof(struct asm_memory_map_regions) * bufcnt;
1942
1943 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05301944 if (mmap_region_cmd == NULL) {
1945 pr_err("%s: Mem alloc failed\n", __func__);
1946 rc = -EINVAL;
1947 return rc;
1948 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001949 mmap_regions = (struct asm_stream_cmd_memory_map_regions *)
1950 mmap_region_cmd;
1951 q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE);
1952 mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS;
1953 mmap_regions->mempool_id = 0;
1954 mmap_regions->nregions = bufcnt & 0x00ff;
1955 pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions);
1956 payload = ((u8 *) mmap_region_cmd +
1957 sizeof(struct asm_stream_cmd_memory_map_regions));
1958 mregions = (struct asm_memory_map_regions *)payload;
1959
1960 port = &ac->port[dir];
1961 for (i = 0; i < bufcnt; i++) {
1962 ab = &port->buf[i];
1963 mregions->phys = ab->phys;
1964 mregions->buf_size = ab->size;
1965 ++mregions;
1966 }
1967
1968 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) mmap_region_cmd);
1969 if (rc < 0) {
1970 pr_err("mmap_regions op[0x%x]rc[%d]\n",
1971 mmap_regions->hdr.opcode, rc);
1972 rc = -EINVAL;
1973 goto fail_cmd;
1974 }
1975
1976 rc = wait_event_timeout(this_mmap.cmd_wait,
1977 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
1978 if (!rc) {
1979 pr_err("timeout. waited for memory_map\n");
1980 rc = -EINVAL;
1981 goto fail_cmd;
1982 }
1983 rc = 0;
1984fail_cmd:
1985 kfree(mmap_region_cmd);
1986 return rc;
1987}
1988
1989static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
1990 uint32_t bufsz, uint32_t bufcnt)
1991{
1992 struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL;
1993 struct asm_memory_unmap_regions *mregions = NULL;
1994 struct audio_port_data *port = NULL;
1995 struct audio_buffer *ab = NULL;
1996 void *unmap_region_cmd = NULL;
1997 void *payload = NULL;
1998 int rc = 0;
1999 int i = 0;
2000 int cmd_size = 0;
2001
2002 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2003 pr_err("APR handle NULL\n");
2004 return -EINVAL;
2005 }
2006 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2007
2008 cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) +
2009 sizeof(struct asm_memory_unmap_regions) * bufcnt;
2010
2011 unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302012 if (unmap_region_cmd == NULL) {
2013 pr_err("%s: Mem alloc failed\n", __func__);
2014 rc = -EINVAL;
2015 return rc;
2016 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002017 unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *)
2018 unmap_region_cmd;
2019 q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE);
2020 unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS;
2021 unmap_regions->nregions = bufcnt & 0x00ff;
2022 pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions);
2023 payload = ((u8 *) unmap_region_cmd +
2024 sizeof(struct asm_stream_cmd_memory_unmap_regions));
2025 mregions = (struct asm_memory_unmap_regions *)payload;
2026 port = &ac->port[dir];
2027 for (i = 0; i < bufcnt; i++) {
2028 ab = &port->buf[i];
2029 mregions->phys = ab->phys;
2030 ++mregions;
2031 }
2032
2033 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd);
2034 if (rc < 0) {
2035 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2036 unmap_regions->hdr.opcode, rc);
2037 goto fail_cmd;
2038 }
2039
2040 rc = wait_event_timeout(this_mmap.cmd_wait,
2041 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2042 if (!rc) {
2043 pr_err("timeout. waited for memory_unmap\n");
2044 goto fail_cmd;
2045 }
2046 rc = 0;
2047
2048fail_cmd:
2049 kfree(unmap_region_cmd);
2050 return rc;
2051}
2052
2053int q6asm_set_mute(struct audio_client *ac, int muteflag)
2054{
2055 void *vol_cmd = NULL;
2056 void *payload = NULL;
2057 struct asm_pp_params_command *cmd = NULL;
2058 struct asm_mute_params *mute = NULL;
2059 int sz = 0;
2060 int rc = 0;
2061
2062 sz = sizeof(struct asm_pp_params_command) +
2063 + sizeof(struct asm_mute_params);
2064 vol_cmd = kzalloc(sz, GFP_KERNEL);
2065 if (vol_cmd == NULL) {
2066 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2067 rc = -EINVAL;
2068 return rc;
2069 }
2070 cmd = (struct asm_pp_params_command *)vol_cmd;
2071 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2072 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2073 cmd->payload = NULL;
2074 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2075 sizeof(struct asm_mute_params);
2076 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2077 cmd->params.param_id = MUTE_CONFIG_PARAM_ID;
2078 cmd->params.param_size = sizeof(struct asm_mute_params);
2079 cmd->params.reserved = 0;
2080
2081 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2082 mute = (struct asm_mute_params *)payload;
2083
2084 mute->muteflag = muteflag;
2085 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2086 if (rc < 0) {
2087 pr_err("%s: Mute Command failed\n", __func__);
2088 rc = -EINVAL;
2089 goto fail_cmd;
2090 }
2091
2092 rc = wait_event_timeout(ac->cmd_wait,
2093 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2094 if (!rc) {
2095 pr_err("%s: timeout in sending mute command to apr\n",
2096 __func__);
2097 rc = -EINVAL;
2098 goto fail_cmd;
2099 }
2100 rc = 0;
2101fail_cmd:
2102 kfree(vol_cmd);
2103 return rc;
2104}
2105
2106int q6asm_set_volume(struct audio_client *ac, int volume)
2107{
2108 void *vol_cmd = NULL;
2109 void *payload = NULL;
2110 struct asm_pp_params_command *cmd = NULL;
2111 struct asm_master_gain_params *mgain = NULL;
2112 int sz = 0;
2113 int rc = 0;
2114
2115 sz = sizeof(struct asm_pp_params_command) +
2116 + sizeof(struct asm_master_gain_params);
2117 vol_cmd = kzalloc(sz, GFP_KERNEL);
2118 if (vol_cmd == NULL) {
2119 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2120 rc = -EINVAL;
2121 return rc;
2122 }
2123 cmd = (struct asm_pp_params_command *)vol_cmd;
2124 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2125 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2126 cmd->payload = NULL;
2127 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2128 sizeof(struct asm_master_gain_params);
2129 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2130 cmd->params.param_id = MASTER_GAIN_PARAM_ID;
2131 cmd->params.param_size = sizeof(struct asm_master_gain_params);
2132 cmd->params.reserved = 0;
2133
2134 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2135 mgain = (struct asm_master_gain_params *)payload;
2136
2137 mgain->master_gain = volume;
2138 mgain->padding = 0x00;
2139 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2140 if (rc < 0) {
2141 pr_err("%s: Volume Command failed\n", __func__);
2142 rc = -EINVAL;
2143 goto fail_cmd;
2144 }
2145
2146 rc = wait_event_timeout(ac->cmd_wait,
2147 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2148 if (!rc) {
2149 pr_err("%s: timeout in sending volume command to apr\n",
2150 __func__);
2151 rc = -EINVAL;
2152 goto fail_cmd;
2153 }
2154 rc = 0;
2155fail_cmd:
2156 kfree(vol_cmd);
2157 return rc;
2158}
2159
2160int q6asm_set_softpause(struct audio_client *ac,
2161 struct asm_softpause_params *pause_param)
2162{
2163 void *vol_cmd = NULL;
2164 void *payload = NULL;
2165 struct asm_pp_params_command *cmd = NULL;
2166 struct asm_softpause_params *params = NULL;
2167 int sz = 0;
2168 int rc = 0;
2169
2170 sz = sizeof(struct asm_pp_params_command) +
2171 + sizeof(struct asm_softpause_params);
2172 vol_cmd = kzalloc(sz, GFP_KERNEL);
2173 if (vol_cmd == NULL) {
2174 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2175 rc = -EINVAL;
2176 return rc;
2177 }
2178 cmd = (struct asm_pp_params_command *)vol_cmd;
2179 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2180 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2181 cmd->payload = NULL;
2182 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2183 sizeof(struct asm_softpause_params);
2184 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2185 cmd->params.param_id = SOFT_PAUSE_PARAM_ID;
2186 cmd->params.param_size = sizeof(struct asm_softpause_params);
2187 cmd->params.reserved = 0;
2188
2189 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2190 params = (struct asm_softpause_params *)payload;
2191
2192 params->enable = pause_param->enable;
2193 params->period = pause_param->period;
2194 params->step = pause_param->step;
2195 params->rampingcurve = pause_param->rampingcurve;
2196 pr_debug("%s: soft Pause Command: enable = %d, period = %d,"
2197 "step = %d, curve = %d\n", __func__, params->enable,
2198 params->period, params->step, params->rampingcurve);
2199 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2200 if (rc < 0) {
2201 pr_err("%s: Volume Command(soft_pause) failed\n", __func__);
2202 rc = -EINVAL;
2203 goto fail_cmd;
2204 }
2205
2206 rc = wait_event_timeout(ac->cmd_wait,
2207 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2208 if (!rc) {
2209 pr_err("%s: timeout in sending volume command(soft_pause)"
2210 "to apr\n", __func__);
2211 rc = -EINVAL;
2212 goto fail_cmd;
2213 }
2214 rc = 0;
2215fail_cmd:
2216 kfree(vol_cmd);
2217 return rc;
2218}
2219
2220int q6asm_equalizer(struct audio_client *ac, void *eq)
2221{
2222 void *eq_cmd = NULL;
2223 void *payload = NULL;
2224 struct asm_pp_params_command *cmd = NULL;
2225 struct asm_equalizer_params *equalizer = NULL;
2226 struct msm_audio_eq_stream_config *eq_params = NULL;
2227 int i = 0;
2228 int sz = 0;
2229 int rc = 0;
2230
2231 sz = sizeof(struct asm_pp_params_command) +
2232 + sizeof(struct asm_equalizer_params);
2233 eq_cmd = kzalloc(sz, GFP_KERNEL);
2234 if (eq_cmd == NULL) {
2235 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2236 rc = -EINVAL;
2237 goto fail_cmd;
2238 }
2239 eq_params = (struct msm_audio_eq_stream_config *) eq;
2240 cmd = (struct asm_pp_params_command *)eq_cmd;
2241 q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE);
2242 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2243 cmd->payload = NULL;
2244 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2245 sizeof(struct asm_equalizer_params);
2246 cmd->params.module_id = EQUALIZER_MODULE_ID;
2247 cmd->params.param_id = EQUALIZER_PARAM_ID;
2248 cmd->params.param_size = sizeof(struct asm_equalizer_params);
2249 cmd->params.reserved = 0;
2250 payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command));
2251 equalizer = (struct asm_equalizer_params *)payload;
2252
2253 equalizer->enable = eq_params->enable;
2254 equalizer->num_bands = eq_params->num_bands;
2255 pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
2256 eq_params->num_bands);
2257 for (i = 0; i < eq_params->num_bands; i++) {
2258 equalizer->eq_bands[i].band_idx =
2259 eq_params->eq_bands[i].band_idx;
2260 equalizer->eq_bands[i].filter_type =
2261 eq_params->eq_bands[i].filter_type;
2262 equalizer->eq_bands[i].center_freq_hz =
2263 eq_params->eq_bands[i].center_freq_hz;
2264 equalizer->eq_bands[i].filter_gain =
2265 eq_params->eq_bands[i].filter_gain;
2266 equalizer->eq_bands[i].q_factor =
2267 eq_params->eq_bands[i].q_factor;
2268 pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
2269 eq_params->eq_bands[i].filter_type, i);
2270 pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
2271 eq_params->eq_bands[i].center_freq_hz, i);
2272 pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
2273 eq_params->eq_bands[i].filter_gain, i);
2274 pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
2275 eq_params->eq_bands[i].q_factor, i);
2276 }
2277 rc = apr_send_pkt(ac->apr, (uint32_t *) eq_cmd);
2278 if (rc < 0) {
2279 pr_err("%s: Equalizer Command failed\n", __func__);
2280 rc = -EINVAL;
2281 goto fail_cmd;
2282 }
2283
2284 rc = wait_event_timeout(ac->cmd_wait,
2285 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2286 if (!rc) {
2287 pr_err("%s: timeout in sending equalizer command to apr\n",
2288 __func__);
2289 rc = -EINVAL;
2290 goto fail_cmd;
2291 }
2292 rc = 0;
2293fail_cmd:
2294 kfree(eq_cmd);
2295 return rc;
2296}
2297
2298int q6asm_read(struct audio_client *ac)
2299{
2300 struct asm_stream_cmd_read read;
2301 struct audio_buffer *ab;
2302 int dsp_buf;
2303 struct audio_port_data *port;
2304 int rc;
2305 if (!ac || ac->apr == NULL) {
2306 pr_err("APR handle NULL\n");
2307 return -EINVAL;
2308 }
2309 if (ac->io_mode == SYNC_IO_MODE) {
2310 port = &ac->port[OUT];
2311
2312 q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
2313
2314 mutex_lock(&port->lock);
2315
2316 dsp_buf = port->dsp_buf;
2317 ab = &port->buf[dsp_buf];
2318
2319 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
2320 __func__,
2321 ac->session,
2322 dsp_buf,
2323 (void *)port->buf[dsp_buf].data,
2324 port->cpu_buf,
2325 (void *)port->buf[port->cpu_buf].phys);
2326
2327 read.hdr.opcode = ASM_DATA_CMD_READ;
2328 read.buf_add = ab->phys;
2329 read.buf_size = ab->size;
2330 read.uid = port->dsp_buf;
2331 read.hdr.token = port->dsp_buf;
2332
2333 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
2334 mutex_unlock(&port->lock);
2335 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
2336 read.buf_add,
2337 read.hdr.token,
2338 read.uid);
2339 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
2340 if (rc < 0) {
2341 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
2342 goto fail_cmd;
2343 }
2344 return 0;
2345 }
2346fail_cmd:
2347 return -EINVAL;
2348}
2349
2350int q6asm_read_nolock(struct audio_client *ac)
2351{
2352 struct asm_stream_cmd_read read;
2353 struct audio_buffer *ab;
2354 int dsp_buf;
2355 struct audio_port_data *port;
2356 int rc;
2357 if (!ac || ac->apr == NULL) {
2358 pr_err("APR handle NULL\n");
2359 return -EINVAL;
2360 }
2361 if (ac->io_mode == SYNC_IO_MODE) {
2362 port = &ac->port[OUT];
2363
2364 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
2365
2366
2367 dsp_buf = port->dsp_buf;
2368 ab = &port->buf[dsp_buf];
2369
2370 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
2371 __func__,
2372 ac->session,
2373 dsp_buf,
2374 (void *)port->buf[dsp_buf].data,
2375 port->cpu_buf,
2376 (void *)port->buf[port->cpu_buf].phys);
2377
2378 read.hdr.opcode = ASM_DATA_CMD_READ;
2379 read.buf_add = ab->phys;
2380 read.buf_size = ab->size;
2381 read.uid = port->dsp_buf;
2382 read.hdr.token = port->dsp_buf;
2383
2384 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
2385 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
2386 read.buf_add,
2387 read.hdr.token,
2388 read.uid);
2389 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
2390 if (rc < 0) {
2391 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
2392 goto fail_cmd;
2393 }
2394 return 0;
2395 }
2396fail_cmd:
2397 return -EINVAL;
2398}
2399
2400
2401static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
2402 uint32_t pkt_size, uint32_t cmd_flg)
2403{
2404 pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg,
2405 ac->session);
2406 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
2407 APR_HDR_LEN(sizeof(struct apr_hdr)),\
2408 APR_PKT_VER);
2409 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
2410 hdr->src_domain = APR_DOMAIN_APPS;
2411 hdr->dest_svc = APR_SVC_ASM;
2412 hdr->dest_domain = APR_DOMAIN_ADSP;
2413 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
2414 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
2415 if (cmd_flg) {
2416 hdr->token = ac->session;
2417 atomic_set(&ac->cmd_state, 1);
2418 }
2419 hdr->pkt_size = pkt_size;
2420 return;
2421}
2422
2423int q6asm_async_write(struct audio_client *ac,
2424 struct audio_aio_write_param *param)
2425{
2426 int rc = 0;
2427 struct asm_stream_cmd_write write;
2428
2429 if (!ac || ac->apr == NULL) {
2430 pr_err("%s: APR handle NULL\n", __func__);
2431 return -EINVAL;
2432 }
2433
2434 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE);
2435
2436 /* Pass physical address as token for AIO scheme */
2437 write.hdr.token = param->uid;
2438 write.hdr.opcode = ASM_DATA_CMD_WRITE;
2439 write.buf_add = param->paddr;
2440 write.avail_bytes = param->len;
2441 write.uid = param->uid;
2442 write.msw_ts = param->msw_ts;
2443 write.lsw_ts = param->lsw_ts;
2444 /* Use 0xFF00 for disabling timestamps */
2445 if (param->flags == 0xFF00)
2446 write.uflags = (0x00000000 | (param->flags & 0x800000FF));
2447 else
2448 write.uflags = (0x80000000 | param->flags);
2449
2450 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
2451 write.buf_add, write.avail_bytes);
2452
2453 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
2454 if (rc < 0) {
2455 pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__,
2456 write.hdr.opcode, rc);
2457 goto fail_cmd;
2458 }
2459 return 0;
2460fail_cmd:
2461 return -EINVAL;
2462}
2463
2464int q6asm_async_read(struct audio_client *ac,
2465 struct audio_aio_read_param *param)
2466{
2467 int rc = 0;
2468 struct asm_stream_cmd_read read;
2469
2470 if (!ac || ac->apr == NULL) {
2471 pr_err("%s: APR handle NULL\n", __func__);
2472 return -EINVAL;
2473 }
2474
2475 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
2476
2477 /* Pass physical address as token for AIO scheme */
2478 read.hdr.token = param->paddr;
2479 read.hdr.opcode = ASM_DATA_CMD_READ;
2480 read.buf_add = param->paddr;
2481 read.buf_size = param->len;
2482 read.uid = param->uid;
2483
2484 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
2485 read.buf_add, read.buf_size);
2486
2487 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
2488 if (rc < 0) {
2489 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
2490 read.hdr.opcode, rc);
2491 goto fail_cmd;
2492 }
2493 return 0;
2494fail_cmd:
2495 return -EINVAL;
2496}
2497
2498int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
2499 uint32_t lsw_ts, uint32_t flags)
2500{
2501 int rc = 0;
2502 struct asm_stream_cmd_write write;
2503 struct audio_port_data *port;
2504 struct audio_buffer *ab;
2505 int dsp_buf = 0;
2506
2507 if (!ac || ac->apr == NULL) {
2508 pr_err("APR handle NULL\n");
2509 return -EINVAL;
2510 }
2511 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
2512 if (ac->io_mode == SYNC_IO_MODE) {
2513 port = &ac->port[IN];
2514
2515 q6asm_add_hdr(ac, &write.hdr, sizeof(write),
2516 FALSE);
2517 mutex_lock(&port->lock);
2518
2519 dsp_buf = port->dsp_buf;
2520 ab = &port->buf[dsp_buf];
2521
2522 write.hdr.token = port->dsp_buf;
2523 write.hdr.opcode = ASM_DATA_CMD_WRITE;
2524 write.buf_add = ab->phys;
2525 write.avail_bytes = len;
2526 write.uid = port->dsp_buf;
2527 write.msw_ts = msw_ts;
2528 write.lsw_ts = lsw_ts;
2529 /* Use 0xFF00 for disabling timestamps */
2530 if (flags == 0xFF00)
2531 write.uflags = (0x00000000 | (flags & 0x800000FF));
2532 else
2533 write.uflags = (0x80000000 | flags);
2534 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
2535
2536 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
2537 , __func__,
2538 ab->phys,
2539 write.buf_add,
2540 write.hdr.token,
2541 write.uid);
2542 mutex_unlock(&port->lock);
Rajesha Kini3498c932011-07-19 19:58:27 +05302543#ifdef CONFIG_DEBUG_FS
2544 if (out_enable_flag) {
2545 char zero_pattern[2] = {0x00, 0x00};
2546 /* If First two byte is non zero and last two byte
2547 is zero then it is warm output pattern */
2548 if ((strncmp(((char *)ab->data), zero_pattern, 2)) &&
2549 (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
2550 do_gettimeofday(&out_warm_tv);
2551 pr_debug("WARM:apr_send_pkt at \
2552 %ld sec %ld microsec\n", out_warm_tv.tv_sec,\
2553 out_warm_tv.tv_usec);
2554 pr_debug("Warm Pattern Matched");
2555 }
2556 /* If First two byte is zero and last two byte is
2557 non zero then it is cont ouput pattern */
2558 else if ((!strncmp(((char *)ab->data), zero_pattern, 2))
2559 && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
2560 do_gettimeofday(&out_cont_tv);
2561 pr_debug("CONT:apr_send_pkt at \
2562 %ld sec %ld microsec\n", out_cont_tv.tv_sec,\
2563 out_cont_tv.tv_usec);
2564 pr_debug("Cont Pattern Matched");
2565 }
2566 }
2567#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002568 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
2569 if (rc < 0) {
2570 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
2571 goto fail_cmd;
2572 }
2573 pr_debug("%s: WRITE SUCCESS\n", __func__);
2574 return 0;
2575 }
2576fail_cmd:
2577 return -EINVAL;
2578}
2579
2580int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
2581 uint32_t lsw_ts, uint32_t flags)
2582{
2583 int rc = 0;
2584 struct asm_stream_cmd_write write;
2585 struct audio_port_data *port;
2586 struct audio_buffer *ab;
2587 int dsp_buf = 0;
2588
2589 if (!ac || ac->apr == NULL) {
2590 pr_err("APR handle NULL\n");
2591 return -EINVAL;
2592 }
2593 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
2594 if (ac->io_mode == SYNC_IO_MODE) {
2595 port = &ac->port[IN];
2596
2597 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
2598 FALSE);
2599
2600 dsp_buf = port->dsp_buf;
2601 ab = &port->buf[dsp_buf];
2602
2603 write.hdr.token = port->dsp_buf;
2604 write.hdr.opcode = ASM_DATA_CMD_WRITE;
2605 write.buf_add = ab->phys;
2606 write.avail_bytes = len;
2607 write.uid = port->dsp_buf;
2608 write.msw_ts = msw_ts;
2609 write.lsw_ts = lsw_ts;
2610 /* Use 0xFF00 for disabling timestamps */
2611 if (flags == 0xFF00)
2612 write.uflags = (0x00000000 | (flags & 0x800000FF));
2613 else
2614 write.uflags = (0x80000000 | flags);
2615 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
2616
2617 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
2618 , __func__,
2619 ab->phys,
2620 write.buf_add,
2621 write.hdr.token,
2622 write.uid);
2623
2624 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
2625 if (rc < 0) {
2626 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
2627 goto fail_cmd;
2628 }
2629 pr_debug("%s: WRITE SUCCESS\n", __func__);
2630 return 0;
2631 }
2632fail_cmd:
2633 return -EINVAL;
2634}
2635
2636uint64_t q6asm_get_session_time(struct audio_client *ac)
2637{
2638 struct apr_hdr hdr;
2639 int rc;
2640
2641 if (!ac || ac->apr == NULL) {
2642 pr_err("APR handle NULL\n");
2643 return -EINVAL;
2644 }
2645 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
2646 hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME;
2647 atomic_set(&ac->time_flag, 1);
2648
2649 pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
2650 ac->session,
2651 hdr.opcode);
2652 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
2653 if (rc < 0) {
2654 pr_err("Commmand 0x%x failed\n", hdr.opcode);
2655 goto fail_cmd;
2656 }
2657 rc = wait_event_timeout(ac->time_wait,
2658 (atomic_read(&ac->time_flag) == 0), 5*HZ);
2659 if (!rc) {
2660 pr_err("%s: timeout in getting session time from DSP\n",
2661 __func__);
2662 goto fail_cmd;
2663 }
2664 return ac->time_stamp;
2665
2666fail_cmd:
2667 return -EINVAL;
2668}
2669
2670int q6asm_cmd(struct audio_client *ac, int cmd)
2671{
2672 struct apr_hdr hdr;
2673 int rc;
2674 atomic_t *state;
2675 int cnt = 0;
2676
2677 if (!ac || ac->apr == NULL) {
2678 pr_err("APR handle NULL\n");
2679 return -EINVAL;
2680 }
2681 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
2682 switch (cmd) {
2683 case CMD_PAUSE:
2684 pr_debug("%s:CMD_PAUSE\n", __func__);
2685 hdr.opcode = ASM_SESSION_CMD_PAUSE;
2686 state = &ac->cmd_state;
2687 break;
2688 case CMD_FLUSH:
2689 pr_debug("%s:CMD_FLUSH\n", __func__);
2690 hdr.opcode = ASM_STREAM_CMD_FLUSH;
2691 state = &ac->cmd_state;
2692 break;
2693 case CMD_OUT_FLUSH:
2694 pr_debug("%s:CMD_OUT_FLUSH\n", __func__);
2695 hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
2696 state = &ac->cmd_state;
2697 break;
2698 case CMD_EOS:
2699 pr_debug("%s:CMD_EOS\n", __func__);
2700 hdr.opcode = ASM_DATA_CMD_EOS;
2701 atomic_set(&ac->cmd_state, 0);
2702 state = &ac->cmd_state;
2703 break;
2704 case CMD_CLOSE:
2705 pr_debug("%s:CMD_CLOSE\n", __func__);
2706 hdr.opcode = ASM_STREAM_CMD_CLOSE;
2707 state = &ac->cmd_state;
2708 break;
2709 default:
2710 pr_err("Invalid format[%d]\n", cmd);
2711 goto fail_cmd;
2712 }
2713 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
2714 ac->session,
2715 hdr.opcode);
2716 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
2717 if (rc < 0) {
2718 pr_err("Commmand 0x%x failed\n", hdr.opcode);
2719 goto fail_cmd;
2720 }
2721 rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ);
2722 if (!rc) {
2723 pr_err("timeout. waited for response opcode[0x%x]\n",
2724 hdr.opcode);
2725 goto fail_cmd;
2726 }
2727 if (cmd == CMD_FLUSH)
2728 q6asm_reset_buf_state(ac);
2729 if (cmd == CMD_CLOSE) {
2730 /* check if DSP return all buffers */
2731 if (ac->port[IN].buf) {
2732 for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
2733 cnt++) {
2734 if (ac->port[IN].buf[cnt].used == IN) {
2735 pr_debug("Write Buf[%d] not returned\n",
2736 cnt);
2737 }
2738 }
2739 }
2740 if (ac->port[OUT].buf) {
2741 for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
2742 if (ac->port[OUT].buf[cnt].used == OUT) {
2743 pr_debug("Read Buf[%d] not returned\n",
2744 cnt);
2745 }
2746 }
2747 }
2748 }
2749 return 0;
2750fail_cmd:
2751 return -EINVAL;
2752}
2753
2754int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
2755{
2756 struct apr_hdr hdr;
2757 int rc;
2758
2759 if (!ac || ac->apr == NULL) {
2760 pr_err("%s:APR handle NULL\n", __func__);
2761 return -EINVAL;
2762 }
2763 q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE);
2764 switch (cmd) {
2765 case CMD_PAUSE:
2766 pr_debug("%s:CMD_PAUSE\n", __func__);
2767 hdr.opcode = ASM_SESSION_CMD_PAUSE;
2768 break;
2769 case CMD_EOS:
2770 pr_debug("%s:CMD_EOS\n", __func__);
2771 hdr.opcode = ASM_DATA_CMD_EOS;
2772 break;
2773 default:
2774 pr_err("%s:Invalid format[%d]\n", __func__, cmd);
2775 goto fail_cmd;
2776 }
2777 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
2778 ac->session,
2779 hdr.opcode);
2780 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
2781 if (rc < 0) {
2782 pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
2783 goto fail_cmd;
2784 }
2785 return 0;
2786fail_cmd:
2787 return -EINVAL;
2788}
2789
2790static void q6asm_reset_buf_state(struct audio_client *ac)
2791{
2792 int cnt = 0;
2793 int loopcnt = 0;
2794 struct audio_port_data *port = NULL;
2795
2796 if (ac->io_mode == SYNC_IO_MODE) {
2797 mutex_lock(&ac->cmd_lock);
2798 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
2799 port = &ac->port[loopcnt];
2800 cnt = port->max_buf_cnt - 1;
2801 port->dsp_buf = 0;
2802 port->cpu_buf = 0;
2803 while (cnt >= 0) {
2804 if (!port->buf)
2805 continue;
2806 port->buf[cnt].used = 1;
2807 cnt--;
2808 }
2809 }
2810 mutex_unlock(&ac->cmd_lock);
2811 }
2812}
2813
2814int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
2815{
2816 struct asm_stream_cmd_reg_tx_overflow_event tx_overflow;
2817 int rc;
2818
2819 if (!ac || ac->apr == NULL) {
2820 pr_err("APR handle NULL\n");
2821 return -EINVAL;
2822 }
2823 pr_debug("%s:session[%d]enable[%d]\n", __func__,
2824 ac->session, enable);
2825 q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
2826
2827 tx_overflow.hdr.opcode = \
2828 ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS;
2829 /* tx overflow event: enable */
2830 tx_overflow.enable = enable;
2831
2832 rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
2833 if (rc < 0) {
2834 pr_err("tx overflow op[0x%x]rc[%d]\n", \
2835 tx_overflow.hdr.opcode, rc);
2836 goto fail_cmd;
2837 }
2838 rc = wait_event_timeout(ac->cmd_wait,
2839 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2840 if (!rc) {
2841 pr_err("timeout. waited for tx overflow\n");
2842 goto fail_cmd;
2843 }
2844 return 0;
2845fail_cmd:
2846 return -EINVAL;
2847}
2848
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002849int q6asm_get_apr_service_id(int session_id)
2850{
2851 pr_debug("%s\n", __func__);
2852
2853 if (session_id < 0) {
2854 pr_err("%s: invalid session_id = %d\n", __func__, session_id);
2855 return -EINVAL;
2856 }
2857
2858 return ((struct apr_svc *)session[session_id]->apr)->id;
2859}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002860
2861
2862static int __init q6asm_init(void)
2863{
2864 pr_debug("%s\n", __func__);
2865 init_waitqueue_head(&this_mmap.cmd_wait);
2866 memset(session, 0, sizeof(session));
Rajesha Kini3498c932011-07-19 19:58:27 +05302867#ifdef CONFIG_DEBUG_FS
2868 out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
2869 out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
2870 S_IFREG | S_IRUGO | S_IWUGO,\
2871 NULL, NULL, &audio_output_latency_debug_fops);
2872 if (IS_ERR(out_dentry))
2873 pr_err("debugfs_create_file failed\n");
2874 in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
2875 in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
2876 S_IFREG | S_IRUGO | S_IWUGO,\
2877 NULL, NULL, &audio_input_latency_debug_fops);
2878 if (IS_ERR(in_dentry))
2879 pr_err("debugfs_create_file failed\n");
2880#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002881 return 0;
2882}
2883
2884device_initcall(q6asm_init);