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