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