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