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