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