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