blob: d822af5c6188084488f20146b09ac1d895555609 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001
2/*
Kiran Kandi5e809b02012-01-31 00:24:33 -08003 * Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004 * 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;
Kiran Kandi5e809b02012-01-31 00:24:33 -08001196 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1197 open.format = MULTI_CHANNEL_PCM;
1198 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001199 case FORMAT_MPEG4_AAC:
1200 open.format = MPEG4_AAC;
1201 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001202 case FORMAT_MPEG4_MULTI_AAC:
1203 open.format = MPEG4_MULTI_AAC;
1204 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001205 case FORMAT_WMA_V9:
1206 open.format = WMA_V9;
1207 break;
1208 case FORMAT_WMA_V10PRO:
1209 open.format = WMA_V10PRO;
1210 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05301211 case FORMAT_MP3:
1212 open.format = MP3;
1213 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001214 default:
1215 pr_err("%s: Invalid format[%d]\n", __func__, format);
1216 goto fail_cmd;
1217 }
1218 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1219 if (rc < 0) {
1220 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1221 __func__, open.hdr.opcode, rc);
1222 goto fail_cmd;
1223 }
1224 rc = wait_event_timeout(ac->cmd_wait,
1225 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1226 if (!rc) {
1227 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1228 rc);
1229 goto fail_cmd;
1230 }
1231 return 0;
1232fail_cmd:
1233 return -EINVAL;
1234}
1235
1236int q6asm_open_read_write(struct audio_client *ac,
1237 uint32_t rd_format,
1238 uint32_t wr_format)
1239{
1240 int rc = 0x00;
1241 struct asm_stream_cmd_open_read_write open;
1242
1243 if ((ac == NULL) || (ac->apr == NULL)) {
1244 pr_err("APR handle NULL\n");
1245 return -EINVAL;
1246 }
1247 pr_debug("%s: session[%d]", __func__, ac->session);
1248 pr_debug("wr_format[0x%x]rd_format[0x%x]",
1249 wr_format, rd_format);
1250
1251 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1252 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE;
1253
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301254 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_NORMAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001255 /* source endpoint : matrix */
1256 open.post_proc_top = get_asm_topology();
1257 if (open.post_proc_top == 0)
1258 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1259
1260 switch (wr_format) {
1261 case FORMAT_LINEAR_PCM:
1262 open.write_format = LINEAR_PCM;
1263 break;
1264 case FORMAT_MPEG4_AAC:
1265 open.write_format = MPEG4_AAC;
1266 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001267 case FORMAT_MPEG4_MULTI_AAC:
1268 open.write_format = MPEG4_MULTI_AAC;
1269 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001270 case FORMAT_WMA_V9:
1271 open.write_format = WMA_V9;
1272 break;
1273 case FORMAT_WMA_V10PRO:
1274 open.write_format = WMA_V10PRO;
1275 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301276 case FORMAT_AMRNB:
1277 open.write_format = AMRNB_FS;
1278 break;
1279 case FORMAT_AMRWB:
1280 open.write_format = AMRWB_FS;
1281 break;
1282 case FORMAT_V13K:
1283 open.write_format = V13K_FS;
1284 break;
1285 case FORMAT_EVRC:
1286 open.write_format = EVRC_FS;
1287 break;
1288 case FORMAT_EVRCB:
1289 open.write_format = EVRCB_FS;
1290 break;
1291 case FORMAT_EVRCWB:
1292 open.write_format = EVRCWB_FS;
1293 break;
1294 case FORMAT_MP3:
1295 open.write_format = MP3;
1296 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001297 default:
1298 pr_err("Invalid format[%d]\n", wr_format);
1299 goto fail_cmd;
1300 }
1301
1302 switch (rd_format) {
1303 case FORMAT_LINEAR_PCM:
1304 open.read_format = LINEAR_PCM;
1305 break;
1306 case FORMAT_MPEG4_AAC:
1307 open.read_format = MPEG4_AAC;
1308 break;
1309 case FORMAT_V13K:
1310 open.read_format = V13K_FS;
1311 break;
1312 case FORMAT_EVRC:
1313 open.read_format = EVRC_FS;
1314 break;
1315 case FORMAT_AMRNB:
1316 open.read_format = AMRNB_FS;
1317 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301318 case FORMAT_AMRWB:
1319 open.read_format = AMRWB_FS;
1320 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001321 default:
1322 pr_err("Invalid format[%d]\n", rd_format);
1323 goto fail_cmd;
1324 }
1325 pr_debug("%s:rdformat[0x%x]wrformat[0x%x]\n", __func__,
1326 open.read_format, open.write_format);
1327
1328 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1329 if (rc < 0) {
1330 pr_err("open failed op[0x%x]rc[%d]\n", \
1331 open.hdr.opcode, rc);
1332 goto fail_cmd;
1333 }
1334 rc = wait_event_timeout(ac->cmd_wait,
1335 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1336 if (!rc) {
1337 pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc);
1338 goto fail_cmd;
1339 }
1340 return 0;
1341fail_cmd:
1342 return -EINVAL;
1343}
1344
1345int q6asm_run(struct audio_client *ac, uint32_t flags,
1346 uint32_t msw_ts, uint32_t lsw_ts)
1347{
1348 struct asm_stream_cmd_run run;
1349 int rc;
1350 if (!ac || ac->apr == NULL) {
1351 pr_err("APR handle NULL\n");
1352 return -EINVAL;
1353 }
1354 pr_debug("%s session[%d]", __func__, ac->session);
1355 q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
1356
1357 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1358 run.flags = flags;
1359 run.msw_ts = msw_ts;
1360 run.lsw_ts = lsw_ts;
Rajesha Kini3498c932011-07-19 19:58:27 +05301361#ifdef CONFIG_DEBUG_FS
1362 if (out_enable_flag) {
1363 do_gettimeofday(&out_cold_tv);
1364 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",\
1365 out_cold_tv.tv_sec, out_cold_tv.tv_usec);
1366 }
1367#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001368 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1369 if (rc < 0) {
1370 pr_err("Commmand run failed[%d]", rc);
1371 goto fail_cmd;
1372 }
1373
1374 rc = wait_event_timeout(ac->cmd_wait,
1375 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1376 if (!rc) {
1377 pr_err("timeout. waited for run success rc[%d]", rc);
1378 goto fail_cmd;
1379 }
1380
1381 return 0;
1382fail_cmd:
1383 return -EINVAL;
1384}
1385
1386int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
1387 uint32_t msw_ts, uint32_t lsw_ts)
1388{
1389 struct asm_stream_cmd_run run;
1390 int rc;
1391 if (!ac || ac->apr == NULL) {
1392 pr_err("%s:APR handle NULL\n", __func__);
1393 return -EINVAL;
1394 }
1395 pr_debug("session[%d]", ac->session);
1396 q6asm_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE);
1397
1398 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1399 run.flags = flags;
1400 run.msw_ts = msw_ts;
1401 run.lsw_ts = lsw_ts;
1402
1403 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1404 if (rc < 0) {
1405 pr_err("%s:Commmand run failed[%d]", __func__, rc);
1406 return -EINVAL;
1407 }
1408 return 0;
1409}
1410
1411
1412int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
1413 uint32_t frames_per_buf,
1414 uint32_t sample_rate, uint32_t channels,
1415 uint32_t bit_rate, uint32_t mode, uint32_t format)
1416{
1417 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1418 int rc = 0;
1419
1420 pr_debug("%s:session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d]"
1421 "format[%d]", __func__, ac->session, frames_per_buf,
1422 sample_rate, channels, bit_rate, mode, format);
1423
1424 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1425
1426 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1427 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1428 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1429 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1430 enc_cfg.enc_blk.format_id = MPEG4_AAC;
1431 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_aac_read_cfg);
1432 enc_cfg.enc_blk.cfg.aac.bitrate = bit_rate;
1433 enc_cfg.enc_blk.cfg.aac.enc_mode = mode;
1434 enc_cfg.enc_blk.cfg.aac.format = format;
1435 enc_cfg.enc_blk.cfg.aac.ch_cfg = channels;
1436 enc_cfg.enc_blk.cfg.aac.sample_rate = sample_rate;
1437
1438 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1439 if (rc < 0) {
1440 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1441 rc = -EINVAL;
1442 goto fail_cmd;
1443 }
1444 rc = wait_event_timeout(ac->cmd_wait,
1445 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1446 if (!rc) {
1447 pr_err("timeout. waited for FORMAT_UPDATE\n");
1448 goto fail_cmd;
1449 }
1450 return 0;
1451fail_cmd:
1452 return -EINVAL;
1453}
1454
1455int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
1456 uint32_t rate, uint32_t channels)
1457{
1458 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1459
1460 int rc = 0;
1461
1462 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1463 ac->session, rate, channels);
1464
1465 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1466
1467 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1468 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1469 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1470 enc_cfg.enc_blk.frames_per_buf = 1;
1471 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1472 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1473 enc_cfg.enc_blk.cfg.pcm.ch_cfg = channels;
1474 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1475 enc_cfg.enc_blk.cfg.pcm.sample_rate = rate;
1476 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1477 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1478
1479 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1480 if (rc < 0) {
1481 pr_err("Comamnd open failed\n");
1482 rc = -EINVAL;
1483 goto fail_cmd;
1484 }
1485 rc = wait_event_timeout(ac->cmd_wait,
1486 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1487 if (!rc) {
1488 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1489 goto fail_cmd;
1490 }
1491 return 0;
1492fail_cmd:
1493 return -EINVAL;
1494}
1495
1496int q6asm_enable_sbrps(struct audio_client *ac,
1497 uint32_t sbr_ps_enable)
1498{
1499 struct asm_stream_cmd_encdec_sbr sbrps;
1500
1501 int rc = 0;
1502
1503 pr_debug("%s: Session %d\n", __func__, ac->session);
1504
1505 q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
1506
1507 sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1508 sbrps.param_id = ASM_ENABLE_SBR_PS;
1509 sbrps.param_size = sizeof(struct asm_sbr_ps);
1510 sbrps.sbr_ps.enable = sbr_ps_enable;
1511
1512 rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
1513 if (rc < 0) {
1514 pr_err("Command opcode[0x%x]paramid[0x%x] failed\n",
1515 ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1516 ASM_ENABLE_SBR_PS);
1517 rc = -EINVAL;
1518 goto fail_cmd;
1519 }
1520 rc = wait_event_timeout(ac->cmd_wait,
1521 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1522 if (!rc) {
1523 pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode);
1524 goto fail_cmd;
1525 }
1526 return 0;
1527fail_cmd:
1528 return -EINVAL;
1529}
1530
Swaminathan Sathappan70765cd2011-07-19 18:42:47 -07001531int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
1532 uint16_t sce_left, uint16_t sce_right)
1533{
1534 struct asm_stream_cmd_encdec_dualmono dual_mono;
1535
1536 int rc = 0;
1537
1538 pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
1539 __func__, ac->session, sce_left, sce_right);
1540
1541 q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
1542
1543 dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1544 dual_mono.param_id = ASM_CONFIGURE_DUAL_MONO;
1545 dual_mono.param_size = sizeof(struct asm_dual_mono);
1546 dual_mono.channel_map.sce_left = sce_left;
1547 dual_mono.channel_map.sce_right = sce_right;
1548
1549 rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
1550 if (rc < 0) {
1551 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
1552 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1553 ASM_CONFIGURE_DUAL_MONO);
1554 rc = -EINVAL;
1555 goto fail_cmd;
1556 }
1557 rc = wait_event_timeout(ac->cmd_wait,
1558 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1559 if (!rc) {
1560 pr_err("%s:timeout opcode[0x%x]\n", __func__,
1561 dual_mono.hdr.opcode);
1562 goto fail_cmd;
1563 }
1564 return 0;
1565fail_cmd:
1566 return -EINVAL;
1567}
1568
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001569int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
1570 uint16_t min_rate, uint16_t max_rate,
1571 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
1572{
1573 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1574 int rc = 0;
1575
1576 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] \
1577 reduced_rate_level[0x%4x]rate_modulation_cmd[0x%4x]", __func__,
1578 ac->session, frames_per_buf, min_rate, max_rate,
1579 reduced_rate_level, rate_modulation_cmd);
1580
1581 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1582
1583 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1584
1585 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1586 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1587
1588 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1589 enc_cfg.enc_blk.format_id = V13K_FS;
1590 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg);
1591 enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate;
1592 enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate;
1593 enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level;
1594 enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_cmd = rate_modulation_cmd;
1595
1596 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1597 if (rc < 0) {
1598 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1599 goto fail_cmd;
1600 }
1601 rc = wait_event_timeout(ac->cmd_wait,
1602 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1603 if (!rc) {
1604 pr_err("timeout. waited for FORMAT_UPDATE\n");
1605 goto fail_cmd;
1606 }
1607 return 0;
1608fail_cmd:
1609 return -EINVAL;
1610}
1611
1612int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
1613 uint16_t min_rate, uint16_t max_rate,
1614 uint16_t rate_modulation_cmd)
1615{
1616 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1617 int rc = 0;
1618
1619 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] \
1620 rate_modulation_cmd[0x%4x]", __func__, ac->session,
1621 frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
1622
1623 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1624
1625 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1626
1627 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1628 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1629
1630 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1631 enc_cfg.enc_blk.format_id = EVRC_FS;
1632 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg);
1633 enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate;
1634 enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate;
1635 enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd;
1636 enc_cfg.enc_blk.cfg.evrc.reserved = 0;
1637
1638 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1639 if (rc < 0) {
1640 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1641 goto fail_cmd;
1642 }
1643 rc = wait_event_timeout(ac->cmd_wait,
1644 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1645 if (!rc) {
1646 pr_err("timeout. waited for FORMAT_UPDATE\n");
1647 goto fail_cmd;
1648 }
1649 return 0;
1650fail_cmd:
1651 return -EINVAL;
1652}
1653
1654int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
1655 uint16_t band_mode, uint16_t dtx_enable)
1656{
1657 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1658 int rc = 0;
1659
1660 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
1661 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
1662
1663 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1664
1665 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1666
1667 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1668 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1669
1670 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1671 enc_cfg.enc_blk.format_id = AMRNB_FS;
1672 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg);
1673 enc_cfg.enc_blk.cfg.amrnb.mode = band_mode;
1674 enc_cfg.enc_blk.cfg.amrnb.dtx_mode = dtx_enable;
1675
1676 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1677 if (rc < 0) {
1678 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1679 goto fail_cmd;
1680 }
1681 rc = wait_event_timeout(ac->cmd_wait,
1682 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1683 if (!rc) {
1684 pr_err("timeout. waited for FORMAT_UPDATE\n");
1685 goto fail_cmd;
1686 }
1687 return 0;
1688fail_cmd:
1689 return -EINVAL;
1690}
1691
Alex Wong2caeecc2011-10-28 10:52:15 +05301692int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
1693 uint16_t band_mode, uint16_t dtx_enable)
1694{
1695 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1696 int rc = 0;
1697
1698 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
1699 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
1700
1701 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1702
1703 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1704
1705 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1706 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1707
1708 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1709 enc_cfg.enc_blk.format_id = AMRWB_FS;
1710 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrwb_read_cfg);
1711 enc_cfg.enc_blk.cfg.amrwb.mode = band_mode;
1712 enc_cfg.enc_blk.cfg.amrwb.dtx_mode = dtx_enable;
1713
1714 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1715 if (rc < 0) {
1716 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1717 goto fail_cmd;
1718 }
1719 rc = wait_event_timeout(ac->cmd_wait,
1720 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1721 if (!rc) {
1722 pr_err("timeout. waited for FORMAT_UPDATE\n");
1723 goto fail_cmd;
1724 }
1725 return 0;
1726fail_cmd:
1727 return -EINVAL;
1728}
1729
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001730int q6asm_media_format_block_pcm(struct audio_client *ac,
1731 uint32_t rate, uint32_t channels)
1732{
1733 struct asm_stream_media_format_update fmt;
1734 int rc = 0;
1735
1736 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
1737 channels);
1738
1739 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
1740
1741 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
1742
1743 fmt.format = LINEAR_PCM;
1744 fmt.cfg_size = sizeof(struct asm_pcm_cfg);
1745 fmt.write_cfg.pcm_cfg.ch_cfg = channels;
1746 fmt.write_cfg.pcm_cfg.bits_per_sample = 16;
1747 fmt.write_cfg.pcm_cfg.sample_rate = rate;
1748 fmt.write_cfg.pcm_cfg.is_signed = 1;
1749 fmt.write_cfg.pcm_cfg.interleaved = 1;
1750
1751 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
1752 if (rc < 0) {
1753 pr_err("%s:Comamnd open failed\n", __func__);
1754 goto fail_cmd;
1755 }
1756 rc = wait_event_timeout(ac->cmd_wait,
1757 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1758 if (!rc) {
1759 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
1760 goto fail_cmd;
1761 }
1762 return 0;
1763fail_cmd:
1764 return -EINVAL;
1765}
1766
Kiran Kandi5e809b02012-01-31 00:24:33 -08001767int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
1768 uint32_t rate, uint32_t channels)
1769{
1770 struct asm_stream_media_format_update fmt;
1771 u8 *channel_mapping;
1772 int rc = 0;
1773
1774 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
1775 channels);
1776
1777 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
1778
1779 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
1780
1781 fmt.format = MULTI_CHANNEL_PCM;
1782 fmt.cfg_size = sizeof(struct asm_multi_channel_pcm_fmt_blk);
1783 fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels;
1784 fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = 16;
1785 fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate;
1786 fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1;
1787 fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1;
1788 channel_mapping =
1789 fmt.write_cfg.multi_ch_pcm_cfg.channel_mapping;
1790
1791 memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
1792
1793 if (channels == 1) {
1794 channel_mapping[0] = PCM_CHANNEL_FL;
1795 } else if (channels == 2) {
1796 channel_mapping[0] = PCM_CHANNEL_FL;
1797 channel_mapping[1] = PCM_CHANNEL_FR;
1798 } else if (channels == 6) {
1799 channel_mapping[0] = PCM_CHANNEL_FC;
1800 channel_mapping[1] = PCM_CHANNEL_FL;
1801 channel_mapping[2] = PCM_CHANNEL_FR;
1802 channel_mapping[3] = PCM_CHANNEL_LB;
1803 channel_mapping[4] = PCM_CHANNEL_RB;
1804 channel_mapping[5] = PCM_CHANNEL_LFE;
1805 } else {
1806 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
1807 channels);
1808 return -EINVAL;
1809 }
1810
1811 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
1812 if (rc < 0) {
1813 pr_err("%s:Comamnd open failed\n", __func__);
1814 goto fail_cmd;
1815 }
1816 rc = wait_event_timeout(ac->cmd_wait,
1817 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1818 if (!rc) {
1819 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
1820 goto fail_cmd;
1821 }
1822 return 0;
1823fail_cmd:
1824 return -EINVAL;
1825}
1826
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001827int q6asm_media_format_block_aac(struct audio_client *ac,
1828 struct asm_aac_cfg *cfg)
1829{
1830 struct asm_stream_media_format_update fmt;
1831 int rc = 0;
1832
1833 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
1834 cfg->sample_rate, cfg->ch_cfg);
1835
1836 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
1837
1838 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
1839
1840 fmt.format = MPEG4_AAC;
1841 fmt.cfg_size = sizeof(struct asm_aac_cfg);
1842 fmt.write_cfg.aac_cfg.format = cfg->format;
1843 fmt.write_cfg.aac_cfg.aot = cfg->aot;
1844 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
1845 fmt.write_cfg.aac_cfg.section_data_resilience =
1846 cfg->section_data_resilience;
1847 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
1848 cfg->scalefactor_data_resilience;
1849 fmt.write_cfg.aac_cfg.spectral_data_resilience =
1850 cfg->spectral_data_resilience;
1851 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
1852 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
1853 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
1854 __func__, fmt.format, fmt.cfg_size,
1855 fmt.write_cfg.aac_cfg.format,
1856 fmt.write_cfg.aac_cfg.aot,
1857 fmt.write_cfg.aac_cfg.ch_cfg,
1858 fmt.write_cfg.aac_cfg.sample_rate);
1859 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
1860 if (rc < 0) {
1861 pr_err("%s:Comamnd open failed\n", __func__);
1862 goto fail_cmd;
1863 }
1864 rc = wait_event_timeout(ac->cmd_wait,
1865 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1866 if (!rc) {
1867 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
1868 goto fail_cmd;
1869 }
1870 return 0;
1871fail_cmd:
1872 return -EINVAL;
1873}
1874
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001875
1876int q6asm_media_format_block_multi_aac(struct audio_client *ac,
1877 struct asm_aac_cfg *cfg)
1878{
1879 struct asm_stream_media_format_update fmt;
1880 int rc = 0;
1881
1882 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
1883 cfg->sample_rate, cfg->ch_cfg);
1884
1885 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
1886
1887 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
1888
1889 fmt.format = MPEG4_MULTI_AAC;
1890 fmt.cfg_size = sizeof(struct asm_aac_cfg);
1891 fmt.write_cfg.aac_cfg.format = cfg->format;
1892 fmt.write_cfg.aac_cfg.aot = cfg->aot;
1893 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
1894 fmt.write_cfg.aac_cfg.section_data_resilience =
1895 cfg->section_data_resilience;
1896 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
1897 cfg->scalefactor_data_resilience;
1898 fmt.write_cfg.aac_cfg.spectral_data_resilience =
1899 cfg->spectral_data_resilience;
1900 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
1901 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
1902 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
1903 __func__, fmt.format, fmt.cfg_size,
1904 fmt.write_cfg.aac_cfg.format,
1905 fmt.write_cfg.aac_cfg.aot,
1906 fmt.write_cfg.aac_cfg.ch_cfg,
1907 fmt.write_cfg.aac_cfg.sample_rate);
1908 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
1909 if (rc < 0) {
1910 pr_err("%s:Comamnd open failed\n", __func__);
1911 goto fail_cmd;
1912 }
1913 rc = wait_event_timeout(ac->cmd_wait,
1914 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1915 if (!rc) {
1916 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
1917 goto fail_cmd;
1918 }
1919 return 0;
1920fail_cmd:
1921 return -EINVAL;
1922}
1923
1924
Alex Wong2caeecc2011-10-28 10:52:15 +05301925
1926int q6asm_media_format_block(struct audio_client *ac, uint32_t format)
1927{
1928
1929 struct asm_stream_media_format_update fmt;
1930 int rc = 0;
1931
1932 pr_debug("%s:session[%d] format[0x%x]\n", __func__,
1933 ac->session, format);
1934
1935 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
1936 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05301937 switch (format) {
1938 case FORMAT_V13K:
1939 fmt.format = V13K_FS;
1940 break;
1941 case FORMAT_EVRC:
1942 fmt.format = EVRC_FS;
1943 break;
1944 case FORMAT_AMRWB:
1945 fmt.format = AMRWB_FS;
1946 break;
1947 case FORMAT_AMRNB:
1948 fmt.format = AMRNB_FS;
1949 break;
1950 case FORMAT_MP3:
1951 fmt.format = MP3;
1952 break;
1953 default:
1954 pr_err("Invalid format[%d]\n", format);
1955 goto fail_cmd;
1956 }
Alex Wong2caeecc2011-10-28 10:52:15 +05301957 fmt.cfg_size = 0;
1958
1959 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
1960 if (rc < 0) {
1961 pr_err("%s:Comamnd open failed\n", __func__);
1962 goto fail_cmd;
1963 }
1964 rc = wait_event_timeout(ac->cmd_wait,
1965 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1966 if (!rc) {
1967 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
1968 goto fail_cmd;
1969 }
1970 return 0;
1971fail_cmd:
1972 return -EINVAL;
1973}
1974
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001975int q6asm_media_format_block_wma(struct audio_client *ac,
1976 void *cfg)
1977{
1978 struct asm_stream_media_format_update fmt;
1979 struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
1980 int rc = 0;
1981
1982 pr_debug("session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d],\
1983 balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x]\n",
1984 ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
1985 wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
1986 wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
1987 wma_cfg->ch_mask, wma_cfg->encode_opt);
1988
1989 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
1990
1991 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
1992
1993 fmt.format = WMA_V9;
1994 fmt.cfg_size = sizeof(struct asm_wma_cfg);
1995 fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag;
1996 fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg;
1997 fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate;
1998 fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
1999 fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align;
2000 fmt.write_cfg.wma_cfg.valid_bits_per_sample =
2001 wma_cfg->valid_bits_per_sample;
2002 fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask;
2003 fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt;
2004 fmt.write_cfg.wma_cfg.adv_encode_opt = 0;
2005 fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0;
2006 fmt.write_cfg.wma_cfg.drc_peak_ref = 0;
2007 fmt.write_cfg.wma_cfg.drc_peak_target = 0;
2008 fmt.write_cfg.wma_cfg.drc_ave_ref = 0;
2009 fmt.write_cfg.wma_cfg.drc_ave_target = 0;
2010
2011 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2012 if (rc < 0) {
2013 pr_err("%s:Comamnd open failed\n", __func__);
2014 goto fail_cmd;
2015 }
2016 rc = wait_event_timeout(ac->cmd_wait,
2017 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2018 if (!rc) {
2019 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2020 goto fail_cmd;
2021 }
2022 return 0;
2023fail_cmd:
2024 return -EINVAL;
2025}
2026
2027int q6asm_media_format_block_wmapro(struct audio_client *ac,
2028 void *cfg)
2029{
2030 struct asm_stream_media_format_update fmt;
2031 struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
2032 int rc = 0;
2033
2034 pr_debug("session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d],"
2035 "balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x],\
2036 adv_enc_opt[0x%4x], adv_enc_opt2[0x%8x]\n",
2037 ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
2038 wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
2039 wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
2040 wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
2041 wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
2042
2043 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2044
2045 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2046
2047 fmt.format = WMA_V10PRO;
2048 fmt.cfg_size = sizeof(struct asm_wmapro_cfg);
2049 fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag;
2050 fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg;
2051 fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate;
2052 fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec =
2053 wmapro_cfg->avg_bytes_per_sec;
2054 fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align;
2055 fmt.write_cfg.wmapro_cfg.valid_bits_per_sample =
2056 wmapro_cfg->valid_bits_per_sample;
2057 fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask;
2058 fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt;
2059 fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt;
2060 fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2;
2061 fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0;
2062 fmt.write_cfg.wmapro_cfg.drc_peak_target = 0;
2063 fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0;
2064 fmt.write_cfg.wmapro_cfg.drc_ave_target = 0;
2065
2066 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2067 if (rc < 0) {
2068 pr_err("%s:Comamnd open failed\n", __func__);
2069 goto fail_cmd;
2070 }
2071 rc = wait_event_timeout(ac->cmd_wait,
2072 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2073 if (!rc) {
2074 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2075 goto fail_cmd;
2076 }
2077 return 0;
2078fail_cmd:
2079 return -EINVAL;
2080}
2081
2082int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
2083 uint32_t bufsz, uint32_t bufcnt)
2084{
2085 struct asm_stream_cmd_memory_map mem_map;
2086 int rc = 0;
2087
2088 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2089 pr_err("APR handle NULL\n");
2090 return -EINVAL;
2091 }
2092
2093 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2094
2095 mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP;
2096
2097 mem_map.buf_add = buf_add;
2098 mem_map.buf_size = bufsz * bufcnt;
2099 mem_map.mempool_id = 0; /* EBI */
2100 mem_map.reserved = 0;
2101
2102 q6asm_add_mmaphdr(&mem_map.hdr,
2103 sizeof(struct asm_stream_cmd_memory_map), TRUE);
2104
2105 pr_debug("buf add[%x] buf_add_parameter[%x]\n",
2106 mem_map.buf_add, buf_add);
2107
2108 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map);
2109 if (rc < 0) {
2110 pr_err("mem_map op[0x%x]rc[%d]\n",
2111 mem_map.hdr.opcode, rc);
2112 rc = -EINVAL;
2113 goto fail_cmd;
2114 }
2115
2116 rc = wait_event_timeout(this_mmap.cmd_wait,
2117 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2118 if (!rc) {
2119 pr_err("timeout. waited for memory_map\n");
2120 rc = -EINVAL;
2121 goto fail_cmd;
2122 }
2123 rc = 0;
2124fail_cmd:
2125 return rc;
2126}
2127
2128int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
2129{
2130 struct asm_stream_cmd_memory_unmap mem_unmap;
2131 int rc = 0;
2132
2133 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2134 pr_err("APR handle NULL\n");
2135 return -EINVAL;
2136 }
2137 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2138
2139 q6asm_add_mmaphdr(&mem_unmap.hdr,
2140 sizeof(struct asm_stream_cmd_memory_unmap), TRUE);
2141 mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP;
2142 mem_unmap.buf_add = buf_add;
2143
2144 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_unmap);
2145 if (rc < 0) {
2146 pr_err("mem_unmap op[0x%x]rc[%d]\n",
2147 mem_unmap.hdr.opcode, rc);
2148 rc = -EINVAL;
2149 goto fail_cmd;
2150 }
2151
2152 rc = wait_event_timeout(this_mmap.cmd_wait,
2153 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2154 if (!rc) {
2155 pr_err("timeout. waited for memory_map\n");
2156 rc = -EINVAL;
2157 goto fail_cmd;
2158 }
2159 rc = 0;
2160fail_cmd:
2161 return rc;
2162}
2163
2164int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
2165{
2166 void *vol_cmd = NULL;
2167 void *payload = NULL;
2168 struct asm_pp_params_command *cmd = NULL;
2169 struct asm_lrchannel_gain_params *lrgain = NULL;
2170 int sz = 0;
2171 int rc = 0;
2172
2173 sz = sizeof(struct asm_pp_params_command) +
2174 + sizeof(struct asm_lrchannel_gain_params);
2175 vol_cmd = kzalloc(sz, GFP_KERNEL);
2176 if (vol_cmd == NULL) {
2177 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2178 rc = -EINVAL;
2179 return rc;
2180 }
2181 cmd = (struct asm_pp_params_command *)vol_cmd;
2182 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2183 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2184 cmd->payload = NULL;
2185 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2186 sizeof(struct asm_lrchannel_gain_params);
2187 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2188 cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID;
2189 cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params);
2190 cmd->params.reserved = 0;
2191
2192 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2193 lrgain = (struct asm_lrchannel_gain_params *)payload;
2194
2195 lrgain->left_gain = left_gain;
2196 lrgain->right_gain = right_gain;
2197 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2198 if (rc < 0) {
2199 pr_err("%s: Volume Command failed\n", __func__);
2200 rc = -EINVAL;
2201 goto fail_cmd;
2202 }
2203
2204 rc = wait_event_timeout(ac->cmd_wait,
2205 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2206 if (!rc) {
2207 pr_err("%s: timeout in sending volume command to apr\n",
2208 __func__);
2209 rc = -EINVAL;
2210 goto fail_cmd;
2211 }
2212 rc = 0;
2213fail_cmd:
2214 kfree(vol_cmd);
2215 return rc;
2216}
2217
2218static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
2219 uint32_t bufsz, uint32_t bufcnt)
2220{
2221 struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL;
2222 struct asm_memory_map_regions *mregions = NULL;
2223 struct audio_port_data *port = NULL;
2224 struct audio_buffer *ab = NULL;
2225 void *mmap_region_cmd = NULL;
2226 void *payload = NULL;
2227 int rc = 0;
2228 int i = 0;
2229 int cmd_size = 0;
2230
2231 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2232 pr_err("APR handle NULL\n");
2233 return -EINVAL;
2234 }
2235 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2236
2237 cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions)
2238 + sizeof(struct asm_memory_map_regions) * bufcnt;
2239
2240 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302241 if (mmap_region_cmd == NULL) {
2242 pr_err("%s: Mem alloc failed\n", __func__);
2243 rc = -EINVAL;
2244 return rc;
2245 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002246 mmap_regions = (struct asm_stream_cmd_memory_map_regions *)
2247 mmap_region_cmd;
2248 q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE);
2249 mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS;
2250 mmap_regions->mempool_id = 0;
2251 mmap_regions->nregions = bufcnt & 0x00ff;
2252 pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions);
2253 payload = ((u8 *) mmap_region_cmd +
2254 sizeof(struct asm_stream_cmd_memory_map_regions));
2255 mregions = (struct asm_memory_map_regions *)payload;
2256
2257 port = &ac->port[dir];
2258 for (i = 0; i < bufcnt; i++) {
2259 ab = &port->buf[i];
2260 mregions->phys = ab->phys;
2261 mregions->buf_size = ab->size;
2262 ++mregions;
2263 }
2264
2265 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) mmap_region_cmd);
2266 if (rc < 0) {
2267 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2268 mmap_regions->hdr.opcode, rc);
2269 rc = -EINVAL;
2270 goto fail_cmd;
2271 }
2272
2273 rc = wait_event_timeout(this_mmap.cmd_wait,
2274 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2275 if (!rc) {
2276 pr_err("timeout. waited for memory_map\n");
2277 rc = -EINVAL;
2278 goto fail_cmd;
2279 }
2280 rc = 0;
2281fail_cmd:
2282 kfree(mmap_region_cmd);
2283 return rc;
2284}
2285
2286static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
2287 uint32_t bufsz, uint32_t bufcnt)
2288{
2289 struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL;
2290 struct asm_memory_unmap_regions *mregions = NULL;
2291 struct audio_port_data *port = NULL;
2292 struct audio_buffer *ab = NULL;
2293 void *unmap_region_cmd = NULL;
2294 void *payload = NULL;
2295 int rc = 0;
2296 int i = 0;
2297 int cmd_size = 0;
2298
2299 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2300 pr_err("APR handle NULL\n");
2301 return -EINVAL;
2302 }
2303 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2304
2305 cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) +
2306 sizeof(struct asm_memory_unmap_regions) * bufcnt;
2307
2308 unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302309 if (unmap_region_cmd == NULL) {
2310 pr_err("%s: Mem alloc failed\n", __func__);
2311 rc = -EINVAL;
2312 return rc;
2313 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002314 unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *)
2315 unmap_region_cmd;
2316 q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE);
2317 unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS;
2318 unmap_regions->nregions = bufcnt & 0x00ff;
2319 pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions);
2320 payload = ((u8 *) unmap_region_cmd +
2321 sizeof(struct asm_stream_cmd_memory_unmap_regions));
2322 mregions = (struct asm_memory_unmap_regions *)payload;
2323 port = &ac->port[dir];
2324 for (i = 0; i < bufcnt; i++) {
2325 ab = &port->buf[i];
2326 mregions->phys = ab->phys;
2327 ++mregions;
2328 }
2329
2330 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd);
2331 if (rc < 0) {
2332 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2333 unmap_regions->hdr.opcode, rc);
2334 goto fail_cmd;
2335 }
2336
2337 rc = wait_event_timeout(this_mmap.cmd_wait,
2338 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2339 if (!rc) {
2340 pr_err("timeout. waited for memory_unmap\n");
2341 goto fail_cmd;
2342 }
2343 rc = 0;
2344
2345fail_cmd:
2346 kfree(unmap_region_cmd);
2347 return rc;
2348}
2349
2350int q6asm_set_mute(struct audio_client *ac, int muteflag)
2351{
2352 void *vol_cmd = NULL;
2353 void *payload = NULL;
2354 struct asm_pp_params_command *cmd = NULL;
2355 struct asm_mute_params *mute = NULL;
2356 int sz = 0;
2357 int rc = 0;
2358
2359 sz = sizeof(struct asm_pp_params_command) +
2360 + sizeof(struct asm_mute_params);
2361 vol_cmd = kzalloc(sz, GFP_KERNEL);
2362 if (vol_cmd == NULL) {
2363 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2364 rc = -EINVAL;
2365 return rc;
2366 }
2367 cmd = (struct asm_pp_params_command *)vol_cmd;
2368 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2369 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2370 cmd->payload = NULL;
2371 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2372 sizeof(struct asm_mute_params);
2373 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2374 cmd->params.param_id = MUTE_CONFIG_PARAM_ID;
2375 cmd->params.param_size = sizeof(struct asm_mute_params);
2376 cmd->params.reserved = 0;
2377
2378 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2379 mute = (struct asm_mute_params *)payload;
2380
2381 mute->muteflag = muteflag;
2382 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2383 if (rc < 0) {
2384 pr_err("%s: Mute Command failed\n", __func__);
2385 rc = -EINVAL;
2386 goto fail_cmd;
2387 }
2388
2389 rc = wait_event_timeout(ac->cmd_wait,
2390 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2391 if (!rc) {
2392 pr_err("%s: timeout in sending mute command to apr\n",
2393 __func__);
2394 rc = -EINVAL;
2395 goto fail_cmd;
2396 }
2397 rc = 0;
2398fail_cmd:
2399 kfree(vol_cmd);
2400 return rc;
2401}
2402
2403int q6asm_set_volume(struct audio_client *ac, int volume)
2404{
2405 void *vol_cmd = NULL;
2406 void *payload = NULL;
2407 struct asm_pp_params_command *cmd = NULL;
2408 struct asm_master_gain_params *mgain = NULL;
2409 int sz = 0;
2410 int rc = 0;
2411
2412 sz = sizeof(struct asm_pp_params_command) +
2413 + sizeof(struct asm_master_gain_params);
2414 vol_cmd = kzalloc(sz, GFP_KERNEL);
2415 if (vol_cmd == NULL) {
2416 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2417 rc = -EINVAL;
2418 return rc;
2419 }
2420 cmd = (struct asm_pp_params_command *)vol_cmd;
2421 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2422 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2423 cmd->payload = NULL;
2424 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2425 sizeof(struct asm_master_gain_params);
2426 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2427 cmd->params.param_id = MASTER_GAIN_PARAM_ID;
2428 cmd->params.param_size = sizeof(struct asm_master_gain_params);
2429 cmd->params.reserved = 0;
2430
2431 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2432 mgain = (struct asm_master_gain_params *)payload;
2433
2434 mgain->master_gain = volume;
2435 mgain->padding = 0x00;
2436 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2437 if (rc < 0) {
2438 pr_err("%s: Volume Command failed\n", __func__);
2439 rc = -EINVAL;
2440 goto fail_cmd;
2441 }
2442
2443 rc = wait_event_timeout(ac->cmd_wait,
2444 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2445 if (!rc) {
2446 pr_err("%s: timeout in sending volume command to apr\n",
2447 __func__);
2448 rc = -EINVAL;
2449 goto fail_cmd;
2450 }
2451 rc = 0;
2452fail_cmd:
2453 kfree(vol_cmd);
2454 return rc;
2455}
2456
2457int q6asm_set_softpause(struct audio_client *ac,
2458 struct asm_softpause_params *pause_param)
2459{
2460 void *vol_cmd = NULL;
2461 void *payload = NULL;
2462 struct asm_pp_params_command *cmd = NULL;
2463 struct asm_softpause_params *params = NULL;
2464 int sz = 0;
2465 int rc = 0;
2466
2467 sz = sizeof(struct asm_pp_params_command) +
2468 + sizeof(struct asm_softpause_params);
2469 vol_cmd = kzalloc(sz, GFP_KERNEL);
2470 if (vol_cmd == NULL) {
2471 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2472 rc = -EINVAL;
2473 return rc;
2474 }
2475 cmd = (struct asm_pp_params_command *)vol_cmd;
2476 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2477 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2478 cmd->payload = NULL;
2479 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2480 sizeof(struct asm_softpause_params);
2481 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2482 cmd->params.param_id = SOFT_PAUSE_PARAM_ID;
2483 cmd->params.param_size = sizeof(struct asm_softpause_params);
2484 cmd->params.reserved = 0;
2485
2486 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2487 params = (struct asm_softpause_params *)payload;
2488
2489 params->enable = pause_param->enable;
2490 params->period = pause_param->period;
2491 params->step = pause_param->step;
2492 params->rampingcurve = pause_param->rampingcurve;
2493 pr_debug("%s: soft Pause Command: enable = %d, period = %d,"
2494 "step = %d, curve = %d\n", __func__, params->enable,
2495 params->period, params->step, params->rampingcurve);
2496 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2497 if (rc < 0) {
2498 pr_err("%s: Volume Command(soft_pause) failed\n", __func__);
2499 rc = -EINVAL;
2500 goto fail_cmd;
2501 }
2502
2503 rc = wait_event_timeout(ac->cmd_wait,
2504 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2505 if (!rc) {
2506 pr_err("%s: timeout in sending volume command(soft_pause)"
2507 "to apr\n", __func__);
2508 rc = -EINVAL;
2509 goto fail_cmd;
2510 }
2511 rc = 0;
2512fail_cmd:
2513 kfree(vol_cmd);
2514 return rc;
2515}
2516
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07002517int q6asm_set_softvolume(struct audio_client *ac,
2518 struct asm_softvolume_params *softvol_param)
2519{
2520 void *vol_cmd = NULL;
2521 void *payload = NULL;
2522 struct asm_pp_params_command *cmd = NULL;
2523 struct asm_softvolume_params *params = NULL;
2524 int sz = 0;
2525 int rc = 0;
2526
2527 sz = sizeof(struct asm_pp_params_command) +
2528 + sizeof(struct asm_softvolume_params);
2529 vol_cmd = kzalloc(sz, GFP_KERNEL);
2530 if (vol_cmd == NULL) {
2531 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2532 rc = -EINVAL;
2533 return rc;
2534 }
2535 cmd = (struct asm_pp_params_command *)vol_cmd;
2536 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2537 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2538 cmd->payload = NULL;
2539 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2540 sizeof(struct asm_softvolume_params);
2541 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2542 cmd->params.param_id = SOFT_VOLUME_PARAM_ID;
2543 cmd->params.param_size = sizeof(struct asm_softvolume_params);
2544 cmd->params.reserved = 0;
2545
2546 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2547 params = (struct asm_softvolume_params *)payload;
2548
2549 params->period = softvol_param->period;
2550 params->step = softvol_param->step;
2551 params->rampingcurve = softvol_param->rampingcurve;
2552 pr_debug("%s: soft Volume:opcode = %d,payload_sz =%d,module_id =%d,"
2553 "param_id = %d, param_sz = %d\n", __func__,
2554 cmd->hdr.opcode, cmd->payload_size,
2555 cmd->params.module_id, cmd->params.param_id,
2556 cmd->params.param_size);
2557 pr_debug("%s: soft Volume Command: period = %d,"
2558 "step = %d, curve = %d\n", __func__, params->period,
2559 params->step, params->rampingcurve);
2560 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2561 if (rc < 0) {
2562 pr_err("%s: Volume Command(soft_volume) failed\n", __func__);
2563 rc = -EINVAL;
2564 goto fail_cmd;
2565 }
2566
2567 rc = wait_event_timeout(ac->cmd_wait,
2568 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2569 if (!rc) {
2570 pr_err("%s: timeout in sending volume command(soft_volume)"
2571 "to apr\n", __func__);
2572 rc = -EINVAL;
2573 goto fail_cmd;
2574 }
2575 rc = 0;
2576fail_cmd:
2577 kfree(vol_cmd);
2578 return rc;
2579}
2580
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002581int q6asm_equalizer(struct audio_client *ac, void *eq)
2582{
2583 void *eq_cmd = NULL;
2584 void *payload = NULL;
2585 struct asm_pp_params_command *cmd = NULL;
2586 struct asm_equalizer_params *equalizer = NULL;
2587 struct msm_audio_eq_stream_config *eq_params = NULL;
2588 int i = 0;
2589 int sz = 0;
2590 int rc = 0;
2591
2592 sz = sizeof(struct asm_pp_params_command) +
2593 + sizeof(struct asm_equalizer_params);
2594 eq_cmd = kzalloc(sz, GFP_KERNEL);
2595 if (eq_cmd == NULL) {
2596 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2597 rc = -EINVAL;
2598 goto fail_cmd;
2599 }
2600 eq_params = (struct msm_audio_eq_stream_config *) eq;
2601 cmd = (struct asm_pp_params_command *)eq_cmd;
2602 q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE);
2603 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2604 cmd->payload = NULL;
2605 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2606 sizeof(struct asm_equalizer_params);
2607 cmd->params.module_id = EQUALIZER_MODULE_ID;
2608 cmd->params.param_id = EQUALIZER_PARAM_ID;
2609 cmd->params.param_size = sizeof(struct asm_equalizer_params);
2610 cmd->params.reserved = 0;
2611 payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command));
2612 equalizer = (struct asm_equalizer_params *)payload;
2613
2614 equalizer->enable = eq_params->enable;
2615 equalizer->num_bands = eq_params->num_bands;
2616 pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
2617 eq_params->num_bands);
2618 for (i = 0; i < eq_params->num_bands; i++) {
2619 equalizer->eq_bands[i].band_idx =
2620 eq_params->eq_bands[i].band_idx;
2621 equalizer->eq_bands[i].filter_type =
2622 eq_params->eq_bands[i].filter_type;
2623 equalizer->eq_bands[i].center_freq_hz =
2624 eq_params->eq_bands[i].center_freq_hz;
2625 equalizer->eq_bands[i].filter_gain =
2626 eq_params->eq_bands[i].filter_gain;
2627 equalizer->eq_bands[i].q_factor =
2628 eq_params->eq_bands[i].q_factor;
2629 pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
2630 eq_params->eq_bands[i].filter_type, i);
2631 pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
2632 eq_params->eq_bands[i].center_freq_hz, i);
2633 pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
2634 eq_params->eq_bands[i].filter_gain, i);
2635 pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
2636 eq_params->eq_bands[i].q_factor, i);
2637 }
2638 rc = apr_send_pkt(ac->apr, (uint32_t *) eq_cmd);
2639 if (rc < 0) {
2640 pr_err("%s: Equalizer Command failed\n", __func__);
2641 rc = -EINVAL;
2642 goto fail_cmd;
2643 }
2644
2645 rc = wait_event_timeout(ac->cmd_wait,
2646 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2647 if (!rc) {
2648 pr_err("%s: timeout in sending equalizer command to apr\n",
2649 __func__);
2650 rc = -EINVAL;
2651 goto fail_cmd;
2652 }
2653 rc = 0;
2654fail_cmd:
2655 kfree(eq_cmd);
2656 return rc;
2657}
2658
2659int q6asm_read(struct audio_client *ac)
2660{
2661 struct asm_stream_cmd_read read;
2662 struct audio_buffer *ab;
2663 int dsp_buf;
2664 struct audio_port_data *port;
2665 int rc;
2666 if (!ac || ac->apr == NULL) {
2667 pr_err("APR handle NULL\n");
2668 return -EINVAL;
2669 }
2670 if (ac->io_mode == SYNC_IO_MODE) {
2671 port = &ac->port[OUT];
2672
2673 q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
2674
2675 mutex_lock(&port->lock);
2676
2677 dsp_buf = port->dsp_buf;
2678 ab = &port->buf[dsp_buf];
2679
2680 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
2681 __func__,
2682 ac->session,
2683 dsp_buf,
2684 (void *)port->buf[dsp_buf].data,
2685 port->cpu_buf,
2686 (void *)port->buf[port->cpu_buf].phys);
2687
2688 read.hdr.opcode = ASM_DATA_CMD_READ;
2689 read.buf_add = ab->phys;
2690 read.buf_size = ab->size;
2691 read.uid = port->dsp_buf;
2692 read.hdr.token = port->dsp_buf;
2693
2694 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
2695 mutex_unlock(&port->lock);
2696 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
2697 read.buf_add,
2698 read.hdr.token,
2699 read.uid);
2700 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
2701 if (rc < 0) {
2702 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
2703 goto fail_cmd;
2704 }
2705 return 0;
2706 }
2707fail_cmd:
2708 return -EINVAL;
2709}
2710
2711int q6asm_read_nolock(struct audio_client *ac)
2712{
2713 struct asm_stream_cmd_read read;
2714 struct audio_buffer *ab;
2715 int dsp_buf;
2716 struct audio_port_data *port;
2717 int rc;
2718 if (!ac || ac->apr == NULL) {
2719 pr_err("APR handle NULL\n");
2720 return -EINVAL;
2721 }
2722 if (ac->io_mode == SYNC_IO_MODE) {
2723 port = &ac->port[OUT];
2724
2725 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
2726
2727
2728 dsp_buf = port->dsp_buf;
2729 ab = &port->buf[dsp_buf];
2730
2731 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
2732 __func__,
2733 ac->session,
2734 dsp_buf,
2735 (void *)port->buf[dsp_buf].data,
2736 port->cpu_buf,
2737 (void *)port->buf[port->cpu_buf].phys);
2738
2739 read.hdr.opcode = ASM_DATA_CMD_READ;
2740 read.buf_add = ab->phys;
2741 read.buf_size = ab->size;
2742 read.uid = port->dsp_buf;
2743 read.hdr.token = port->dsp_buf;
2744
2745 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
2746 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
2747 read.buf_add,
2748 read.hdr.token,
2749 read.uid);
2750 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
2751 if (rc < 0) {
2752 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
2753 goto fail_cmd;
2754 }
2755 return 0;
2756 }
2757fail_cmd:
2758 return -EINVAL;
2759}
2760
2761
2762static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
2763 uint32_t pkt_size, uint32_t cmd_flg)
2764{
2765 pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg,
2766 ac->session);
2767 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
2768 APR_HDR_LEN(sizeof(struct apr_hdr)),\
2769 APR_PKT_VER);
2770 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
2771 hdr->src_domain = APR_DOMAIN_APPS;
2772 hdr->dest_svc = APR_SVC_ASM;
2773 hdr->dest_domain = APR_DOMAIN_ADSP;
2774 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
2775 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
2776 if (cmd_flg) {
2777 hdr->token = ac->session;
2778 atomic_set(&ac->cmd_state, 1);
2779 }
2780 hdr->pkt_size = pkt_size;
2781 return;
2782}
2783
2784int q6asm_async_write(struct audio_client *ac,
2785 struct audio_aio_write_param *param)
2786{
2787 int rc = 0;
2788 struct asm_stream_cmd_write write;
2789
2790 if (!ac || ac->apr == NULL) {
2791 pr_err("%s: APR handle NULL\n", __func__);
2792 return -EINVAL;
2793 }
2794
2795 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE);
2796
2797 /* Pass physical address as token for AIO scheme */
2798 write.hdr.token = param->uid;
2799 write.hdr.opcode = ASM_DATA_CMD_WRITE;
2800 write.buf_add = param->paddr;
2801 write.avail_bytes = param->len;
2802 write.uid = param->uid;
2803 write.msw_ts = param->msw_ts;
2804 write.lsw_ts = param->lsw_ts;
2805 /* Use 0xFF00 for disabling timestamps */
2806 if (param->flags == 0xFF00)
2807 write.uflags = (0x00000000 | (param->flags & 0x800000FF));
2808 else
2809 write.uflags = (0x80000000 | param->flags);
2810
2811 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
2812 write.buf_add, write.avail_bytes);
2813
2814 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
2815 if (rc < 0) {
2816 pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__,
2817 write.hdr.opcode, rc);
2818 goto fail_cmd;
2819 }
2820 return 0;
2821fail_cmd:
2822 return -EINVAL;
2823}
2824
2825int q6asm_async_read(struct audio_client *ac,
2826 struct audio_aio_read_param *param)
2827{
2828 int rc = 0;
2829 struct asm_stream_cmd_read read;
2830
2831 if (!ac || ac->apr == NULL) {
2832 pr_err("%s: APR handle NULL\n", __func__);
2833 return -EINVAL;
2834 }
2835
2836 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
2837
2838 /* Pass physical address as token for AIO scheme */
2839 read.hdr.token = param->paddr;
2840 read.hdr.opcode = ASM_DATA_CMD_READ;
2841 read.buf_add = param->paddr;
2842 read.buf_size = param->len;
2843 read.uid = param->uid;
2844
2845 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
2846 read.buf_add, read.buf_size);
2847
2848 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
2849 if (rc < 0) {
2850 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
2851 read.hdr.opcode, rc);
2852 goto fail_cmd;
2853 }
2854 return 0;
2855fail_cmd:
2856 return -EINVAL;
2857}
2858
2859int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
2860 uint32_t lsw_ts, uint32_t flags)
2861{
2862 int rc = 0;
2863 struct asm_stream_cmd_write write;
2864 struct audio_port_data *port;
2865 struct audio_buffer *ab;
2866 int dsp_buf = 0;
2867
2868 if (!ac || ac->apr == NULL) {
2869 pr_err("APR handle NULL\n");
2870 return -EINVAL;
2871 }
2872 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
2873 if (ac->io_mode == SYNC_IO_MODE) {
2874 port = &ac->port[IN];
2875
2876 q6asm_add_hdr(ac, &write.hdr, sizeof(write),
2877 FALSE);
2878 mutex_lock(&port->lock);
2879
2880 dsp_buf = port->dsp_buf;
2881 ab = &port->buf[dsp_buf];
2882
2883 write.hdr.token = port->dsp_buf;
2884 write.hdr.opcode = ASM_DATA_CMD_WRITE;
2885 write.buf_add = ab->phys;
2886 write.avail_bytes = len;
2887 write.uid = port->dsp_buf;
2888 write.msw_ts = msw_ts;
2889 write.lsw_ts = lsw_ts;
2890 /* Use 0xFF00 for disabling timestamps */
2891 if (flags == 0xFF00)
2892 write.uflags = (0x00000000 | (flags & 0x800000FF));
2893 else
2894 write.uflags = (0x80000000 | flags);
2895 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
2896
2897 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
2898 , __func__,
2899 ab->phys,
2900 write.buf_add,
2901 write.hdr.token,
2902 write.uid);
2903 mutex_unlock(&port->lock);
Rajesha Kini3498c932011-07-19 19:58:27 +05302904#ifdef CONFIG_DEBUG_FS
2905 if (out_enable_flag) {
2906 char zero_pattern[2] = {0x00, 0x00};
2907 /* If First two byte is non zero and last two byte
2908 is zero then it is warm output pattern */
2909 if ((strncmp(((char *)ab->data), zero_pattern, 2)) &&
2910 (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
2911 do_gettimeofday(&out_warm_tv);
2912 pr_debug("WARM:apr_send_pkt at \
2913 %ld sec %ld microsec\n", out_warm_tv.tv_sec,\
2914 out_warm_tv.tv_usec);
2915 pr_debug("Warm Pattern Matched");
2916 }
2917 /* If First two byte is zero and last two byte is
2918 non zero then it is cont ouput pattern */
2919 else if ((!strncmp(((char *)ab->data), zero_pattern, 2))
2920 && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
2921 do_gettimeofday(&out_cont_tv);
2922 pr_debug("CONT:apr_send_pkt at \
2923 %ld sec %ld microsec\n", out_cont_tv.tv_sec,\
2924 out_cont_tv.tv_usec);
2925 pr_debug("Cont Pattern Matched");
2926 }
2927 }
2928#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002929 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
2930 if (rc < 0) {
2931 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
2932 goto fail_cmd;
2933 }
2934 pr_debug("%s: WRITE SUCCESS\n", __func__);
2935 return 0;
2936 }
2937fail_cmd:
2938 return -EINVAL;
2939}
2940
2941int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
2942 uint32_t lsw_ts, uint32_t flags)
2943{
2944 int rc = 0;
2945 struct asm_stream_cmd_write write;
2946 struct audio_port_data *port;
2947 struct audio_buffer *ab;
2948 int dsp_buf = 0;
2949
2950 if (!ac || ac->apr == NULL) {
2951 pr_err("APR handle NULL\n");
2952 return -EINVAL;
2953 }
2954 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
2955 if (ac->io_mode == SYNC_IO_MODE) {
2956 port = &ac->port[IN];
2957
2958 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
2959 FALSE);
2960
2961 dsp_buf = port->dsp_buf;
2962 ab = &port->buf[dsp_buf];
2963
2964 write.hdr.token = port->dsp_buf;
2965 write.hdr.opcode = ASM_DATA_CMD_WRITE;
2966 write.buf_add = ab->phys;
2967 write.avail_bytes = len;
2968 write.uid = port->dsp_buf;
2969 write.msw_ts = msw_ts;
2970 write.lsw_ts = lsw_ts;
2971 /* Use 0xFF00 for disabling timestamps */
2972 if (flags == 0xFF00)
2973 write.uflags = (0x00000000 | (flags & 0x800000FF));
2974 else
2975 write.uflags = (0x80000000 | flags);
2976 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
2977
2978 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
2979 , __func__,
2980 ab->phys,
2981 write.buf_add,
2982 write.hdr.token,
2983 write.uid);
2984
2985 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
2986 if (rc < 0) {
2987 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
2988 goto fail_cmd;
2989 }
2990 pr_debug("%s: WRITE SUCCESS\n", __func__);
2991 return 0;
2992 }
2993fail_cmd:
2994 return -EINVAL;
2995}
2996
2997uint64_t q6asm_get_session_time(struct audio_client *ac)
2998{
2999 struct apr_hdr hdr;
3000 int rc;
3001
3002 if (!ac || ac->apr == NULL) {
3003 pr_err("APR handle NULL\n");
3004 return -EINVAL;
3005 }
3006 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3007 hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME;
3008 atomic_set(&ac->time_flag, 1);
3009
3010 pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
3011 ac->session,
3012 hdr.opcode);
3013 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3014 if (rc < 0) {
3015 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3016 goto fail_cmd;
3017 }
3018 rc = wait_event_timeout(ac->time_wait,
3019 (atomic_read(&ac->time_flag) == 0), 5*HZ);
3020 if (!rc) {
3021 pr_err("%s: timeout in getting session time from DSP\n",
3022 __func__);
3023 goto fail_cmd;
3024 }
3025 return ac->time_stamp;
3026
3027fail_cmd:
3028 return -EINVAL;
3029}
3030
3031int q6asm_cmd(struct audio_client *ac, int cmd)
3032{
3033 struct apr_hdr hdr;
3034 int rc;
3035 atomic_t *state;
3036 int cnt = 0;
3037
3038 if (!ac || ac->apr == NULL) {
3039 pr_err("APR handle NULL\n");
3040 return -EINVAL;
3041 }
3042 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3043 switch (cmd) {
3044 case CMD_PAUSE:
3045 pr_debug("%s:CMD_PAUSE\n", __func__);
3046 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3047 state = &ac->cmd_state;
3048 break;
3049 case CMD_FLUSH:
3050 pr_debug("%s:CMD_FLUSH\n", __func__);
3051 hdr.opcode = ASM_STREAM_CMD_FLUSH;
3052 state = &ac->cmd_state;
3053 break;
3054 case CMD_OUT_FLUSH:
3055 pr_debug("%s:CMD_OUT_FLUSH\n", __func__);
3056 hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
3057 state = &ac->cmd_state;
3058 break;
3059 case CMD_EOS:
3060 pr_debug("%s:CMD_EOS\n", __func__);
3061 hdr.opcode = ASM_DATA_CMD_EOS;
3062 atomic_set(&ac->cmd_state, 0);
3063 state = &ac->cmd_state;
3064 break;
3065 case CMD_CLOSE:
3066 pr_debug("%s:CMD_CLOSE\n", __func__);
3067 hdr.opcode = ASM_STREAM_CMD_CLOSE;
3068 state = &ac->cmd_state;
3069 break;
3070 default:
3071 pr_err("Invalid format[%d]\n", cmd);
3072 goto fail_cmd;
3073 }
3074 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3075 ac->session,
3076 hdr.opcode);
3077 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3078 if (rc < 0) {
3079 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3080 goto fail_cmd;
3081 }
3082 rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ);
3083 if (!rc) {
3084 pr_err("timeout. waited for response opcode[0x%x]\n",
3085 hdr.opcode);
3086 goto fail_cmd;
3087 }
3088 if (cmd == CMD_FLUSH)
3089 q6asm_reset_buf_state(ac);
3090 if (cmd == CMD_CLOSE) {
3091 /* check if DSP return all buffers */
3092 if (ac->port[IN].buf) {
3093 for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
3094 cnt++) {
3095 if (ac->port[IN].buf[cnt].used == IN) {
3096 pr_debug("Write Buf[%d] not returned\n",
3097 cnt);
3098 }
3099 }
3100 }
3101 if (ac->port[OUT].buf) {
3102 for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
3103 if (ac->port[OUT].buf[cnt].used == OUT) {
3104 pr_debug("Read Buf[%d] not returned\n",
3105 cnt);
3106 }
3107 }
3108 }
3109 }
3110 return 0;
3111fail_cmd:
3112 return -EINVAL;
3113}
3114
3115int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
3116{
3117 struct apr_hdr hdr;
3118 int rc;
3119
3120 if (!ac || ac->apr == NULL) {
3121 pr_err("%s:APR handle NULL\n", __func__);
3122 return -EINVAL;
3123 }
3124 q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE);
3125 switch (cmd) {
3126 case CMD_PAUSE:
3127 pr_debug("%s:CMD_PAUSE\n", __func__);
3128 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3129 break;
3130 case CMD_EOS:
3131 pr_debug("%s:CMD_EOS\n", __func__);
3132 hdr.opcode = ASM_DATA_CMD_EOS;
3133 break;
3134 default:
3135 pr_err("%s:Invalid format[%d]\n", __func__, cmd);
3136 goto fail_cmd;
3137 }
3138 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3139 ac->session,
3140 hdr.opcode);
3141 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3142 if (rc < 0) {
3143 pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
3144 goto fail_cmd;
3145 }
3146 return 0;
3147fail_cmd:
3148 return -EINVAL;
3149}
3150
3151static void q6asm_reset_buf_state(struct audio_client *ac)
3152{
3153 int cnt = 0;
3154 int loopcnt = 0;
3155 struct audio_port_data *port = NULL;
3156
3157 if (ac->io_mode == SYNC_IO_MODE) {
3158 mutex_lock(&ac->cmd_lock);
3159 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
3160 port = &ac->port[loopcnt];
3161 cnt = port->max_buf_cnt - 1;
3162 port->dsp_buf = 0;
3163 port->cpu_buf = 0;
3164 while (cnt >= 0) {
3165 if (!port->buf)
3166 continue;
3167 port->buf[cnt].used = 1;
3168 cnt--;
3169 }
3170 }
3171 mutex_unlock(&ac->cmd_lock);
3172 }
3173}
3174
3175int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
3176{
3177 struct asm_stream_cmd_reg_tx_overflow_event tx_overflow;
3178 int rc;
3179
3180 if (!ac || ac->apr == NULL) {
3181 pr_err("APR handle NULL\n");
3182 return -EINVAL;
3183 }
3184 pr_debug("%s:session[%d]enable[%d]\n", __func__,
3185 ac->session, enable);
3186 q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
3187
3188 tx_overflow.hdr.opcode = \
3189 ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS;
3190 /* tx overflow event: enable */
3191 tx_overflow.enable = enable;
3192
3193 rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
3194 if (rc < 0) {
3195 pr_err("tx overflow op[0x%x]rc[%d]\n", \
3196 tx_overflow.hdr.opcode, rc);
3197 goto fail_cmd;
3198 }
3199 rc = wait_event_timeout(ac->cmd_wait,
3200 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3201 if (!rc) {
3202 pr_err("timeout. waited for tx overflow\n");
3203 goto fail_cmd;
3204 }
3205 return 0;
3206fail_cmd:
3207 return -EINVAL;
3208}
3209
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003210int q6asm_get_apr_service_id(int session_id)
3211{
3212 pr_debug("%s\n", __func__);
3213
Shiv Maliyappanahallia84982a2012-01-19 15:25:04 -08003214 if (session_id < 0 || session_id > SESSION_MAX) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003215 pr_err("%s: invalid session_id = %d\n", __func__, session_id);
3216 return -EINVAL;
3217 }
3218
3219 return ((struct apr_svc *)session[session_id]->apr)->id;
3220}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003221
3222
3223static int __init q6asm_init(void)
3224{
3225 pr_debug("%s\n", __func__);
3226 init_waitqueue_head(&this_mmap.cmd_wait);
3227 memset(session, 0, sizeof(session));
Rajesha Kini3498c932011-07-19 19:58:27 +05303228#ifdef CONFIG_DEBUG_FS
3229 out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
3230 out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
3231 S_IFREG | S_IRUGO | S_IWUGO,\
3232 NULL, NULL, &audio_output_latency_debug_fops);
3233 if (IS_ERR(out_dentry))
3234 pr_err("debugfs_create_file failed\n");
3235 in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
3236 in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
3237 S_IFREG | S_IRUGO | S_IWUGO,\
3238 NULL, NULL, &audio_input_latency_debug_fops);
3239 if (IS_ERR(in_dentry))
3240 pr_err("debugfs_create_file failed\n");
3241#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003242 return 0;
3243}
3244
3245device_initcall(q6asm_init);