blob: fe31b278fbd7658c448efe9616d5f4e356964e5f [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);
Laxminath Kasam692c6542012-02-21 11:17:47 +0530830 if (ac->cb)
831 ac->cb(data->opcode, data->token,
832 (uint32_t *)data->payload, ac->priv);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700833 apr_reset(ac->apr);
834 return 0;
835 }
836
837 pr_debug("%s: session[%d]opcode[0x%x] \
838 token[0x%x]payload_s[%d] src[%d] dest[%d]\n", __func__,
839 ac->session, data->opcode,
840 data->token, data->payload_size, data->src_port,
841 data->dest_port);
842
843 if (data->opcode == APR_BASIC_RSP_RESULT) {
844 token = data->token;
845 switch (payload[0]) {
846 case ASM_STREAM_CMD_SET_PP_PARAMS:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700847 if (rtac_make_asm_callback(ac->session, payload,
848 data->payload_size))
849 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700850 case ASM_SESSION_CMD_PAUSE:
851 case ASM_DATA_CMD_EOS:
852 case ASM_STREAM_CMD_CLOSE:
853 case ASM_STREAM_CMD_FLUSH:
854 case ASM_SESSION_CMD_RUN:
855 case ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS:
856 case ASM_STREAM_CMD_FLUSH_READBUFS:
857 pr_debug("%s:Payload = [0x%x]\n", __func__, payload[0]);
858 if (token != ac->session) {
859 pr_err("%s:Invalid session[%d] rxed expected[%d]",
860 __func__, token, ac->session);
861 return -EINVAL;
862 }
863 case ASM_STREAM_CMD_OPEN_READ:
864 case ASM_STREAM_CMD_OPEN_WRITE:
865 case ASM_STREAM_CMD_OPEN_READWRITE:
866 case ASM_DATA_CMD_MEDIA_FORMAT_UPDATE:
867 case ASM_STREAM_CMD_SET_ENCDEC_PARAM:
868 if (atomic_read(&ac->cmd_state)) {
869 atomic_set(&ac->cmd_state, 0);
870 wake_up(&ac->cmd_wait);
871 }
872 if (ac->cb)
873 ac->cb(data->opcode, data->token,
874 (uint32_t *)data->payload, ac->priv);
875 break;
876 default:
877 pr_debug("%s:command[0x%x] not expecting rsp\n",
878 __func__, payload[0]);
879 break;
880 }
881 return 0;
882 }
883
884 switch (data->opcode) {
885 case ASM_DATA_EVENT_WRITE_DONE:{
886 struct audio_port_data *port = &ac->port[IN];
887 pr_debug("%s: Rxed opcode[0x%x] status[0x%x] token[%d]",
888 __func__, payload[0], payload[1],
889 data->token);
890 if (ac->io_mode == SYNC_IO_MODE) {
891 if (port->buf == NULL) {
892 pr_err("%s: Unexpected Write Done\n",
893 __func__);
894 return -EINVAL;
895 }
896 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
897 if (port->buf[data->token].phys !=
898 payload[0]) {
899 pr_err("Buf expected[%p]rxed[%p]\n",\
900 (void *)port->buf[data->token].phys,\
901 (void *)payload[0]);
902 spin_unlock_irqrestore(&port->dsp_lock,
903 dsp_flags);
904 return -EINVAL;
905 }
906 token = data->token;
907 port->buf[token].used = 1;
908 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
Rajesha Kini3498c932011-07-19 19:58:27 +0530909#ifdef CONFIG_DEBUG_FS
910 if (out_enable_flag) {
911 /* For first Write done log the time and reset
912 out_cold_index*/
913 if (out_cold_index != 1) {
914 do_gettimeofday(&out_cold_tv);
915 pr_debug("COLD: apr_send_pkt at %ld \
916 sec %ld microsec\n",\
917 out_cold_tv.tv_sec,\
918 out_cold_tv.tv_usec);
919 out_cold_index = 1;
920 }
921 pr_debug("out_enable_flag %ld",\
922 out_enable_flag);
923 }
924#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700925 for (i = 0; i < port->max_buf_cnt; i++)
926 pr_debug("%d ", port->buf[i].used);
927
928 }
929 break;
930 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700931 case ASM_STREAM_CMDRSP_GET_PP_PARAMS:
932 rtac_make_asm_callback(ac->session, payload,
933 data->payload_size);
934 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700935 case ASM_DATA_EVENT_READ_DONE:{
936
937 struct audio_port_data *port = &ac->port[OUT];
Rajesha Kini3498c932011-07-19 19:58:27 +0530938#ifdef CONFIG_DEBUG_FS
939 if (in_enable_flag) {
940 /* when in_cont_index == 7, DSP would be
941 * writing into the 8th 512 byte buffer and this
942 * timestamp is tapped here.Once done it then writes
943 * to 9th 512 byte buffer.These two buffers(8th, 9th)
944 * reach the test application in 5th iteration and that
945 * timestamp is tapped at user level. The difference
946 * of these two timestamps gives us the time between
947 * the time at which dsp started filling the sample
948 * required and when it reached the test application.
949 * Hence continuous input latency
950 */
951 if (in_cont_index == 7) {
952 do_gettimeofday(&in_cont_tv);
953 pr_err("In_CONT:previous read buffer done \
954 at %ld sec %ld microsec\n",\
Sriranjan Srikantam74753532011-10-03 14:48:37 -0700955 in_cont_tv.tv_sec, in_cont_tv.tv_usec);
Rajesha Kini3498c932011-07-19 19:58:27 +0530956 }
957 }
958#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700959 pr_debug("%s:R-D: status=%d buff_add=%x act_size=%d offset=%d\n",
960 __func__, payload[READDONE_IDX_STATUS],
961 payload[READDONE_IDX_BUFFER],
962 payload[READDONE_IDX_SIZE],
963 payload[READDONE_IDX_OFFSET]);
964 pr_debug("%s:R-D:msw_ts=%d lsw_ts=%d flags=%d id=%d num=%d\n",
965 __func__, payload[READDONE_IDX_MSW_TS],
966 payload[READDONE_IDX_LSW_TS],
967 payload[READDONE_IDX_FLAGS],
968 payload[READDONE_IDX_ID],
969 payload[READDONE_IDX_NUMFRAMES]);
Rajesha Kini3498c932011-07-19 19:58:27 +0530970#ifdef CONFIG_DEBUG_FS
971 if (in_enable_flag) {
972 in_cont_index++;
973 }
974#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700975 if (ac->io_mode == SYNC_IO_MODE) {
976 if (port->buf == NULL) {
977 pr_err("%s: Unexpected Write Done\n", __func__);
978 return -EINVAL;
979 }
980 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
981 token = data->token;
982 port->buf[token].used = 0;
983 if (port->buf[token].phys !=
984 payload[READDONE_IDX_BUFFER]) {
985 pr_err("Buf expected[%p]rxed[%p]\n",\
986 (void *)port->buf[token].phys,\
987 (void *)payload[READDONE_IDX_BUFFER]);
988 spin_unlock_irqrestore(&port->dsp_lock,
989 dsp_flags);
990 break;
991 }
992 port->buf[token].actual_size =
993 payload[READDONE_IDX_SIZE];
994 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
995 }
996 break;
997 }
998 case ASM_DATA_EVENT_EOS:
999 case ASM_DATA_CMDRSP_EOS:
1000 pr_debug("%s:EOS ACK received: rxed opcode[0x%x]\n",
1001 __func__, data->opcode);
1002 break;
1003 case ASM_STREAM_CMDRSP_GET_ENCDEC_PARAM:
1004 break;
1005 case ASM_SESSION_EVENT_TX_OVERFLOW:
1006 pr_err("ASM_SESSION_EVENT_TX_OVERFLOW\n");
1007 break;
1008 case ASM_SESSION_CMDRSP_GET_SESSION_TIME:
1009 pr_debug("%s: ASM_SESSION_CMDRSP_GET_SESSION_TIME, "
1010 "payload[0] = %d, payload[1] = %d, "
1011 "payload[2] = %d\n", __func__,
1012 payload[0], payload[1], payload[2]);
1013 ac->time_stamp = (uint64_t)(((uint64_t)payload[1] << 32) |
1014 payload[2]);
1015 if (atomic_read(&ac->time_flag)) {
1016 atomic_set(&ac->time_flag, 0);
1017 wake_up(&ac->time_wait);
1018 }
1019 break;
1020 case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY:
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301021 case ASM_DATA_EVENT_ENC_SR_CM_NOTIFY:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001022 pr_debug("%s: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, "
1023 "payload[0] = %d, payload[1] = %d, "
1024 "payload[2] = %d, payload[3] = %d\n", __func__,
1025 payload[0], payload[1], payload[2],
1026 payload[3]);
1027 break;
1028 }
1029 if (ac->cb)
1030 ac->cb(data->opcode, data->token,
1031 data->payload, ac->priv);
1032
1033 return 0;
1034}
1035
1036void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac, uint32_t *size,
1037 uint32_t *index)
1038{
1039 void *data;
1040 unsigned char idx;
1041 struct audio_port_data *port;
1042
1043 if (!ac || ((dir != IN) && (dir != OUT)))
1044 return NULL;
1045
1046 if (ac->io_mode == SYNC_IO_MODE) {
1047 port = &ac->port[dir];
1048
1049 mutex_lock(&port->lock);
1050 idx = port->cpu_buf;
1051 if (port->buf == NULL) {
1052 pr_debug("%s:Buffer pointer null\n", __func__);
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -08001053 mutex_unlock(&port->lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001054 return NULL;
1055 }
1056 /* dir 0: used = 0 means buf in use
1057 dir 1: used = 1 means buf in use */
1058 if (port->buf[idx].used == dir) {
1059 /* To make it more robust, we could loop and get the
1060 next avail buf, its risky though */
1061 pr_debug("%s:Next buf idx[0x%x] not available,\
1062 dir[%d]\n", __func__, idx, dir);
1063 mutex_unlock(&port->lock);
1064 return NULL;
1065 }
1066 *size = port->buf[idx].actual_size;
1067 *index = port->cpu_buf;
1068 data = port->buf[idx].data;
1069 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1070 __func__,
1071 ac->session,
1072 port->cpu_buf,
1073 data, *size);
1074 /* By default increase the cpu_buf cnt
1075 user accesses this function,increase cpu
1076 buf(to avoid another api)*/
1077 port->buf[idx].used = dir;
1078 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1079 mutex_unlock(&port->lock);
1080 return data;
1081 }
1082 return NULL;
1083}
1084
Jay Wang9cf59a02011-08-10 16:58:40 -07001085void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
1086 uint32_t *size, uint32_t *index)
1087{
1088 void *data;
1089 unsigned char idx;
1090 struct audio_port_data *port;
1091
1092 if (!ac || ((dir != IN) && (dir != OUT)))
1093 return NULL;
1094
1095 port = &ac->port[dir];
1096
1097 idx = port->cpu_buf;
1098 if (port->buf == NULL) {
1099 pr_debug("%s:Buffer pointer null\n", __func__);
1100 return NULL;
1101 }
1102 /*
1103 * dir 0: used = 0 means buf in use
1104 * dir 1: used = 1 means buf in use
1105 */
1106 if (port->buf[idx].used == dir) {
1107 /*
1108 * To make it more robust, we could loop and get the
1109 * next avail buf, its risky though
1110 */
1111 pr_debug("%s:Next buf idx[0x%x] not available,\
1112 dir[%d]\n", __func__, idx, dir);
1113 return NULL;
1114 }
1115 *size = port->buf[idx].actual_size;
1116 *index = port->cpu_buf;
1117 data = port->buf[idx].data;
1118 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1119 __func__, ac->session, port->cpu_buf,
1120 data, *size);
1121 /*
1122 * By default increase the cpu_buf cnt
1123 * user accesses this function,increase cpu
1124 * buf(to avoid another api)
1125 */
1126 port->buf[idx].used = dir;
1127 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1128 return data;
1129}
1130
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001131int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac)
1132{
1133 int ret = -1;
1134 struct audio_port_data *port;
1135 uint32_t idx;
1136
1137 if (!ac || (dir != OUT))
1138 return ret;
1139
1140 if (ac->io_mode == SYNC_IO_MODE) {
1141 port = &ac->port[dir];
1142
1143 mutex_lock(&port->lock);
1144 idx = port->dsp_buf;
1145
1146 if (port->buf[idx].used == (dir ^ 1)) {
1147 /* To make it more robust, we could loop and get the
1148 next avail buf, its risky though */
1149 pr_err("Next buf idx[0x%x] not available, dir[%d]\n",
1150 idx, dir);
1151 mutex_unlock(&port->lock);
1152 return ret;
1153 }
1154 pr_debug("%s: session[%d]dsp_buf=%d cpu_buf=%d\n", __func__,
1155 ac->session, port->dsp_buf, port->cpu_buf);
1156 ret = ((port->dsp_buf != port->cpu_buf) ? 0 : -1);
1157 mutex_unlock(&port->lock);
1158 }
1159 return ret;
1160}
1161
1162static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
1163 uint32_t pkt_size, uint32_t cmd_flg)
1164{
1165 pr_debug("%s:session=%d pkt size=%d cmd_flg=%d\n", __func__, pkt_size,
1166 cmd_flg, ac->session);
1167 mutex_lock(&ac->cmd_lock);
1168 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1169 APR_HDR_LEN(sizeof(struct apr_hdr)),\
1170 APR_PKT_VER);
1171 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
1172 hdr->src_domain = APR_DOMAIN_APPS;
1173 hdr->dest_svc = APR_SVC_ASM;
1174 hdr->dest_domain = APR_DOMAIN_ADSP;
1175 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
1176 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
1177 if (cmd_flg) {
1178 hdr->token = ac->session;
1179 atomic_set(&ac->cmd_state, 1);
1180 }
1181 hdr->pkt_size = pkt_size;
1182 mutex_unlock(&ac->cmd_lock);
1183 return;
1184}
1185
1186static void q6asm_add_mmaphdr(struct apr_hdr *hdr, uint32_t pkt_size,
1187 uint32_t cmd_flg)
1188{
1189 pr_debug("%s:pkt size=%d cmd_flg=%d\n", __func__, pkt_size, cmd_flg);
1190 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1191 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1192 hdr->src_port = 0;
1193 hdr->dest_port = 0;
1194 if (cmd_flg) {
1195 hdr->token = 0;
1196 atomic_set(&this_mmap.cmd_state, 1);
1197 }
1198 hdr->pkt_size = pkt_size;
1199 return;
1200}
1201
1202int q6asm_open_read(struct audio_client *ac,
1203 uint32_t format)
1204{
1205 int rc = 0x00;
1206 struct asm_stream_cmd_open_read open;
Rajesha Kini3498c932011-07-19 19:58:27 +05301207#ifdef CONFIG_DEBUG_FS
1208 in_cont_index = 0;
1209#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001210 if ((ac == NULL) || (ac->apr == NULL)) {
1211 pr_err("%s: APR handle NULL\n", __func__);
1212 return -EINVAL;
1213 }
1214 pr_debug("%s:session[%d]", __func__, ac->session);
1215
1216 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1217 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ;
1218 /* Stream prio : High, provide meta info with encoded frames */
1219 open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1220
1221 open.pre_proc_top = get_asm_topology();
1222 if (open.pre_proc_top == 0)
1223 open.pre_proc_top = DEFAULT_POPP_TOPOLOGY;
1224
1225 switch (format) {
1226 case FORMAT_LINEAR_PCM:
1227 open.uMode = STREAM_PRIORITY_HIGH;
1228 open.format = LINEAR_PCM;
1229 break;
1230 case FORMAT_MPEG4_AAC:
1231 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1232 open.format = MPEG4_AAC;
1233 break;
1234 case FORMAT_V13K:
1235 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1236 open.format = V13K_FS;
1237 break;
1238 case FORMAT_EVRC:
1239 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1240 open.format = EVRC_FS;
1241 break;
1242 case FORMAT_AMRNB:
1243 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1244 open.format = AMRNB_FS;
1245 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301246 case FORMAT_AMRWB:
1247 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1248 open.format = AMRWB_FS;
1249 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001250 default:
1251 pr_err("Invalid format[%d]\n", format);
1252 goto fail_cmd;
1253 }
1254 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1255 if (rc < 0) {
1256 pr_err("open failed op[0x%x]rc[%d]\n", \
1257 open.hdr.opcode, rc);
1258 goto fail_cmd;
1259 }
1260 rc = wait_event_timeout(ac->cmd_wait,
1261 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1262 if (!rc) {
1263 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1264 rc);
1265 goto fail_cmd;
1266 }
1267 return 0;
1268fail_cmd:
1269 return -EINVAL;
1270}
1271
1272int q6asm_open_write(struct audio_client *ac, uint32_t format)
1273{
1274 int rc = 0x00;
1275 struct asm_stream_cmd_open_write open;
1276
1277 if ((ac == NULL) || (ac->apr == NULL)) {
1278 pr_err("%s: APR handle NULL\n", __func__);
1279 return -EINVAL;
1280 }
1281 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1282 format);
1283
1284 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1285
1286 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE;
1287 open.uMode = STREAM_PRIORITY_HIGH;
1288 /* source endpoint : matrix */
1289 open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1290 open.stream_handle = 0x00;
1291
1292 open.post_proc_top = get_asm_topology();
1293 if (open.post_proc_top == 0)
1294 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1295
1296 switch (format) {
1297 case FORMAT_LINEAR_PCM:
1298 open.format = LINEAR_PCM;
1299 break;
Kiran Kandi5e809b02012-01-31 00:24:33 -08001300 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1301 open.format = MULTI_CHANNEL_PCM;
1302 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001303 case FORMAT_MPEG4_AAC:
1304 open.format = MPEG4_AAC;
1305 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001306 case FORMAT_MPEG4_MULTI_AAC:
1307 open.format = MPEG4_MULTI_AAC;
1308 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001309 case FORMAT_WMA_V9:
1310 open.format = WMA_V9;
1311 break;
1312 case FORMAT_WMA_V10PRO:
1313 open.format = WMA_V10PRO;
1314 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05301315 case FORMAT_MP3:
1316 open.format = MP3;
1317 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001318 default:
1319 pr_err("%s: Invalid format[%d]\n", __func__, format);
1320 goto fail_cmd;
1321 }
1322 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1323 if (rc < 0) {
1324 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1325 __func__, open.hdr.opcode, rc);
1326 goto fail_cmd;
1327 }
1328 rc = wait_event_timeout(ac->cmd_wait,
1329 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1330 if (!rc) {
1331 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1332 rc);
1333 goto fail_cmd;
1334 }
1335 return 0;
1336fail_cmd:
1337 return -EINVAL;
1338}
1339
1340int q6asm_open_read_write(struct audio_client *ac,
1341 uint32_t rd_format,
1342 uint32_t wr_format)
1343{
1344 int rc = 0x00;
1345 struct asm_stream_cmd_open_read_write open;
1346
1347 if ((ac == NULL) || (ac->apr == NULL)) {
1348 pr_err("APR handle NULL\n");
1349 return -EINVAL;
1350 }
1351 pr_debug("%s: session[%d]", __func__, ac->session);
1352 pr_debug("wr_format[0x%x]rd_format[0x%x]",
1353 wr_format, rd_format);
1354
1355 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1356 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE;
1357
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301358 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_NORMAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001359 /* source endpoint : matrix */
1360 open.post_proc_top = get_asm_topology();
1361 if (open.post_proc_top == 0)
1362 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1363
1364 switch (wr_format) {
1365 case FORMAT_LINEAR_PCM:
1366 open.write_format = LINEAR_PCM;
1367 break;
1368 case FORMAT_MPEG4_AAC:
1369 open.write_format = MPEG4_AAC;
1370 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001371 case FORMAT_MPEG4_MULTI_AAC:
1372 open.write_format = MPEG4_MULTI_AAC;
1373 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001374 case FORMAT_WMA_V9:
1375 open.write_format = WMA_V9;
1376 break;
1377 case FORMAT_WMA_V10PRO:
1378 open.write_format = WMA_V10PRO;
1379 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301380 case FORMAT_AMRNB:
1381 open.write_format = AMRNB_FS;
1382 break;
1383 case FORMAT_AMRWB:
1384 open.write_format = AMRWB_FS;
1385 break;
1386 case FORMAT_V13K:
1387 open.write_format = V13K_FS;
1388 break;
1389 case FORMAT_EVRC:
1390 open.write_format = EVRC_FS;
1391 break;
1392 case FORMAT_EVRCB:
1393 open.write_format = EVRCB_FS;
1394 break;
1395 case FORMAT_EVRCWB:
1396 open.write_format = EVRCWB_FS;
1397 break;
1398 case FORMAT_MP3:
1399 open.write_format = MP3;
1400 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001401 default:
1402 pr_err("Invalid format[%d]\n", wr_format);
1403 goto fail_cmd;
1404 }
1405
1406 switch (rd_format) {
1407 case FORMAT_LINEAR_PCM:
1408 open.read_format = LINEAR_PCM;
1409 break;
1410 case FORMAT_MPEG4_AAC:
1411 open.read_format = MPEG4_AAC;
1412 break;
1413 case FORMAT_V13K:
1414 open.read_format = V13K_FS;
1415 break;
1416 case FORMAT_EVRC:
1417 open.read_format = EVRC_FS;
1418 break;
1419 case FORMAT_AMRNB:
1420 open.read_format = AMRNB_FS;
1421 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301422 case FORMAT_AMRWB:
1423 open.read_format = AMRWB_FS;
1424 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001425 default:
1426 pr_err("Invalid format[%d]\n", rd_format);
1427 goto fail_cmd;
1428 }
1429 pr_debug("%s:rdformat[0x%x]wrformat[0x%x]\n", __func__,
1430 open.read_format, open.write_format);
1431
1432 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1433 if (rc < 0) {
1434 pr_err("open failed op[0x%x]rc[%d]\n", \
1435 open.hdr.opcode, rc);
1436 goto fail_cmd;
1437 }
1438 rc = wait_event_timeout(ac->cmd_wait,
1439 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1440 if (!rc) {
1441 pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc);
1442 goto fail_cmd;
1443 }
1444 return 0;
1445fail_cmd:
1446 return -EINVAL;
1447}
1448
1449int q6asm_run(struct audio_client *ac, uint32_t flags,
1450 uint32_t msw_ts, uint32_t lsw_ts)
1451{
1452 struct asm_stream_cmd_run run;
1453 int rc;
1454 if (!ac || ac->apr == NULL) {
1455 pr_err("APR handle NULL\n");
1456 return -EINVAL;
1457 }
1458 pr_debug("%s session[%d]", __func__, ac->session);
1459 q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
1460
1461 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1462 run.flags = flags;
1463 run.msw_ts = msw_ts;
1464 run.lsw_ts = lsw_ts;
Rajesha Kini3498c932011-07-19 19:58:27 +05301465#ifdef CONFIG_DEBUG_FS
1466 if (out_enable_flag) {
1467 do_gettimeofday(&out_cold_tv);
1468 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",\
1469 out_cold_tv.tv_sec, out_cold_tv.tv_usec);
1470 }
1471#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001472 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1473 if (rc < 0) {
1474 pr_err("Commmand run failed[%d]", rc);
1475 goto fail_cmd;
1476 }
1477
1478 rc = wait_event_timeout(ac->cmd_wait,
1479 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1480 if (!rc) {
1481 pr_err("timeout. waited for run success rc[%d]", rc);
1482 goto fail_cmd;
1483 }
1484
1485 return 0;
1486fail_cmd:
1487 return -EINVAL;
1488}
1489
1490int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
1491 uint32_t msw_ts, uint32_t lsw_ts)
1492{
1493 struct asm_stream_cmd_run run;
1494 int rc;
1495 if (!ac || ac->apr == NULL) {
1496 pr_err("%s:APR handle NULL\n", __func__);
1497 return -EINVAL;
1498 }
1499 pr_debug("session[%d]", ac->session);
1500 q6asm_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE);
1501
1502 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1503 run.flags = flags;
1504 run.msw_ts = msw_ts;
1505 run.lsw_ts = lsw_ts;
1506
1507 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1508 if (rc < 0) {
1509 pr_err("%s:Commmand run failed[%d]", __func__, rc);
1510 return -EINVAL;
1511 }
1512 return 0;
1513}
1514
1515
1516int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
1517 uint32_t frames_per_buf,
1518 uint32_t sample_rate, uint32_t channels,
1519 uint32_t bit_rate, uint32_t mode, uint32_t format)
1520{
1521 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1522 int rc = 0;
1523
1524 pr_debug("%s:session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d]"
1525 "format[%d]", __func__, ac->session, frames_per_buf,
1526 sample_rate, channels, bit_rate, mode, format);
1527
1528 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1529
1530 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1531 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1532 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1533 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1534 enc_cfg.enc_blk.format_id = MPEG4_AAC;
1535 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_aac_read_cfg);
1536 enc_cfg.enc_blk.cfg.aac.bitrate = bit_rate;
1537 enc_cfg.enc_blk.cfg.aac.enc_mode = mode;
1538 enc_cfg.enc_blk.cfg.aac.format = format;
1539 enc_cfg.enc_blk.cfg.aac.ch_cfg = channels;
1540 enc_cfg.enc_blk.cfg.aac.sample_rate = sample_rate;
1541
1542 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1543 if (rc < 0) {
1544 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1545 rc = -EINVAL;
1546 goto fail_cmd;
1547 }
1548 rc = wait_event_timeout(ac->cmd_wait,
1549 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1550 if (!rc) {
1551 pr_err("timeout. waited for FORMAT_UPDATE\n");
1552 goto fail_cmd;
1553 }
1554 return 0;
1555fail_cmd:
1556 return -EINVAL;
1557}
1558
1559int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
1560 uint32_t rate, uint32_t channels)
1561{
1562 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1563
1564 int rc = 0;
1565
1566 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1567 ac->session, rate, channels);
1568
1569 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1570
1571 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1572 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1573 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1574 enc_cfg.enc_blk.frames_per_buf = 1;
1575 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1576 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1577 enc_cfg.enc_blk.cfg.pcm.ch_cfg = channels;
1578 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1579 enc_cfg.enc_blk.cfg.pcm.sample_rate = rate;
1580 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1581 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1582
1583 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1584 if (rc < 0) {
1585 pr_err("Comamnd open failed\n");
1586 rc = -EINVAL;
1587 goto fail_cmd;
1588 }
1589 rc = wait_event_timeout(ac->cmd_wait,
1590 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1591 if (!rc) {
1592 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1593 goto fail_cmd;
1594 }
1595 return 0;
1596fail_cmd:
1597 return -EINVAL;
1598}
1599
1600int q6asm_enable_sbrps(struct audio_client *ac,
1601 uint32_t sbr_ps_enable)
1602{
1603 struct asm_stream_cmd_encdec_sbr sbrps;
1604
1605 int rc = 0;
1606
1607 pr_debug("%s: Session %d\n", __func__, ac->session);
1608
1609 q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
1610
1611 sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1612 sbrps.param_id = ASM_ENABLE_SBR_PS;
1613 sbrps.param_size = sizeof(struct asm_sbr_ps);
1614 sbrps.sbr_ps.enable = sbr_ps_enable;
1615
1616 rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
1617 if (rc < 0) {
1618 pr_err("Command opcode[0x%x]paramid[0x%x] failed\n",
1619 ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1620 ASM_ENABLE_SBR_PS);
1621 rc = -EINVAL;
1622 goto fail_cmd;
1623 }
1624 rc = wait_event_timeout(ac->cmd_wait,
1625 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1626 if (!rc) {
1627 pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode);
1628 goto fail_cmd;
1629 }
1630 return 0;
1631fail_cmd:
1632 return -EINVAL;
1633}
1634
Swaminathan Sathappan70765cd2011-07-19 18:42:47 -07001635int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
1636 uint16_t sce_left, uint16_t sce_right)
1637{
1638 struct asm_stream_cmd_encdec_dualmono dual_mono;
1639
1640 int rc = 0;
1641
1642 pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
1643 __func__, ac->session, sce_left, sce_right);
1644
1645 q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
1646
1647 dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1648 dual_mono.param_id = ASM_CONFIGURE_DUAL_MONO;
1649 dual_mono.param_size = sizeof(struct asm_dual_mono);
1650 dual_mono.channel_map.sce_left = sce_left;
1651 dual_mono.channel_map.sce_right = sce_right;
1652
1653 rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
1654 if (rc < 0) {
1655 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
1656 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1657 ASM_CONFIGURE_DUAL_MONO);
1658 rc = -EINVAL;
1659 goto fail_cmd;
1660 }
1661 rc = wait_event_timeout(ac->cmd_wait,
1662 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1663 if (!rc) {
1664 pr_err("%s:timeout opcode[0x%x]\n", __func__,
1665 dual_mono.hdr.opcode);
1666 goto fail_cmd;
1667 }
1668 return 0;
1669fail_cmd:
1670 return -EINVAL;
1671}
1672
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001673int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
1674 uint16_t min_rate, uint16_t max_rate,
1675 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
1676{
1677 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1678 int rc = 0;
1679
1680 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] \
1681 reduced_rate_level[0x%4x]rate_modulation_cmd[0x%4x]", __func__,
1682 ac->session, frames_per_buf, min_rate, max_rate,
1683 reduced_rate_level, rate_modulation_cmd);
1684
1685 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1686
1687 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1688
1689 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1690 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1691
1692 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1693 enc_cfg.enc_blk.format_id = V13K_FS;
1694 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg);
1695 enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate;
1696 enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate;
1697 enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level;
1698 enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_cmd = rate_modulation_cmd;
1699
1700 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1701 if (rc < 0) {
1702 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1703 goto fail_cmd;
1704 }
1705 rc = wait_event_timeout(ac->cmd_wait,
1706 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1707 if (!rc) {
1708 pr_err("timeout. waited for FORMAT_UPDATE\n");
1709 goto fail_cmd;
1710 }
1711 return 0;
1712fail_cmd:
1713 return -EINVAL;
1714}
1715
1716int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
1717 uint16_t min_rate, uint16_t max_rate,
1718 uint16_t rate_modulation_cmd)
1719{
1720 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1721 int rc = 0;
1722
1723 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] \
1724 rate_modulation_cmd[0x%4x]", __func__, ac->session,
1725 frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
1726
1727 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1728
1729 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1730
1731 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1732 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1733
1734 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1735 enc_cfg.enc_blk.format_id = EVRC_FS;
1736 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg);
1737 enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate;
1738 enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate;
1739 enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd;
1740 enc_cfg.enc_blk.cfg.evrc.reserved = 0;
1741
1742 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1743 if (rc < 0) {
1744 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1745 goto fail_cmd;
1746 }
1747 rc = wait_event_timeout(ac->cmd_wait,
1748 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1749 if (!rc) {
1750 pr_err("timeout. waited for FORMAT_UPDATE\n");
1751 goto fail_cmd;
1752 }
1753 return 0;
1754fail_cmd:
1755 return -EINVAL;
1756}
1757
1758int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
1759 uint16_t band_mode, uint16_t dtx_enable)
1760{
1761 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1762 int rc = 0;
1763
1764 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
1765 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
1766
1767 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1768
1769 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1770
1771 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1772 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1773
1774 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1775 enc_cfg.enc_blk.format_id = AMRNB_FS;
1776 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg);
1777 enc_cfg.enc_blk.cfg.amrnb.mode = band_mode;
1778 enc_cfg.enc_blk.cfg.amrnb.dtx_mode = dtx_enable;
1779
1780 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1781 if (rc < 0) {
1782 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1783 goto fail_cmd;
1784 }
1785 rc = wait_event_timeout(ac->cmd_wait,
1786 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1787 if (!rc) {
1788 pr_err("timeout. waited for FORMAT_UPDATE\n");
1789 goto fail_cmd;
1790 }
1791 return 0;
1792fail_cmd:
1793 return -EINVAL;
1794}
1795
Alex Wong2caeecc2011-10-28 10:52:15 +05301796int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
1797 uint16_t band_mode, uint16_t dtx_enable)
1798{
1799 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1800 int rc = 0;
1801
1802 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
1803 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
1804
1805 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1806
1807 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1808
1809 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1810 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1811
1812 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1813 enc_cfg.enc_blk.format_id = AMRWB_FS;
1814 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrwb_read_cfg);
1815 enc_cfg.enc_blk.cfg.amrwb.mode = band_mode;
1816 enc_cfg.enc_blk.cfg.amrwb.dtx_mode = dtx_enable;
1817
1818 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1819 if (rc < 0) {
1820 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1821 goto fail_cmd;
1822 }
1823 rc = wait_event_timeout(ac->cmd_wait,
1824 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1825 if (!rc) {
1826 pr_err("timeout. waited for FORMAT_UPDATE\n");
1827 goto fail_cmd;
1828 }
1829 return 0;
1830fail_cmd:
1831 return -EINVAL;
1832}
1833
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001834int q6asm_media_format_block_pcm(struct audio_client *ac,
1835 uint32_t rate, uint32_t channels)
1836{
1837 struct asm_stream_media_format_update fmt;
1838 int rc = 0;
1839
1840 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
1841 channels);
1842
1843 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
1844
1845 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
1846
1847 fmt.format = LINEAR_PCM;
1848 fmt.cfg_size = sizeof(struct asm_pcm_cfg);
1849 fmt.write_cfg.pcm_cfg.ch_cfg = channels;
1850 fmt.write_cfg.pcm_cfg.bits_per_sample = 16;
1851 fmt.write_cfg.pcm_cfg.sample_rate = rate;
1852 fmt.write_cfg.pcm_cfg.is_signed = 1;
1853 fmt.write_cfg.pcm_cfg.interleaved = 1;
1854
1855 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
1856 if (rc < 0) {
1857 pr_err("%s:Comamnd open failed\n", __func__);
1858 goto fail_cmd;
1859 }
1860 rc = wait_event_timeout(ac->cmd_wait,
1861 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1862 if (!rc) {
1863 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
1864 goto fail_cmd;
1865 }
1866 return 0;
1867fail_cmd:
1868 return -EINVAL;
1869}
1870
Kiran Kandi5e809b02012-01-31 00:24:33 -08001871int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
1872 uint32_t rate, uint32_t channels)
1873{
1874 struct asm_stream_media_format_update fmt;
1875 u8 *channel_mapping;
1876 int rc = 0;
1877
1878 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
1879 channels);
1880
1881 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
1882
1883 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
1884
1885 fmt.format = MULTI_CHANNEL_PCM;
1886 fmt.cfg_size = sizeof(struct asm_multi_channel_pcm_fmt_blk);
1887 fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels;
1888 fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = 16;
1889 fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate;
1890 fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1;
1891 fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1;
1892 channel_mapping =
1893 fmt.write_cfg.multi_ch_pcm_cfg.channel_mapping;
1894
1895 memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
1896
1897 if (channels == 1) {
1898 channel_mapping[0] = PCM_CHANNEL_FL;
1899 } else if (channels == 2) {
1900 channel_mapping[0] = PCM_CHANNEL_FL;
1901 channel_mapping[1] = PCM_CHANNEL_FR;
1902 } else if (channels == 6) {
1903 channel_mapping[0] = PCM_CHANNEL_FC;
1904 channel_mapping[1] = PCM_CHANNEL_FL;
1905 channel_mapping[2] = PCM_CHANNEL_FR;
1906 channel_mapping[3] = PCM_CHANNEL_LB;
1907 channel_mapping[4] = PCM_CHANNEL_RB;
1908 channel_mapping[5] = PCM_CHANNEL_LFE;
1909 } else {
1910 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
1911 channels);
1912 return -EINVAL;
1913 }
1914
1915 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
1916 if (rc < 0) {
1917 pr_err("%s:Comamnd open failed\n", __func__);
1918 goto fail_cmd;
1919 }
1920 rc = wait_event_timeout(ac->cmd_wait,
1921 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1922 if (!rc) {
1923 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
1924 goto fail_cmd;
1925 }
1926 return 0;
1927fail_cmd:
1928 return -EINVAL;
1929}
1930
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001931int q6asm_media_format_block_aac(struct audio_client *ac,
1932 struct asm_aac_cfg *cfg)
1933{
1934 struct asm_stream_media_format_update fmt;
1935 int rc = 0;
1936
1937 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
1938 cfg->sample_rate, cfg->ch_cfg);
1939
1940 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
1941
1942 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
1943
1944 fmt.format = MPEG4_AAC;
1945 fmt.cfg_size = sizeof(struct asm_aac_cfg);
1946 fmt.write_cfg.aac_cfg.format = cfg->format;
1947 fmt.write_cfg.aac_cfg.aot = cfg->aot;
1948 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
1949 fmt.write_cfg.aac_cfg.section_data_resilience =
1950 cfg->section_data_resilience;
1951 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
1952 cfg->scalefactor_data_resilience;
1953 fmt.write_cfg.aac_cfg.spectral_data_resilience =
1954 cfg->spectral_data_resilience;
1955 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
1956 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
1957 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
1958 __func__, fmt.format, fmt.cfg_size,
1959 fmt.write_cfg.aac_cfg.format,
1960 fmt.write_cfg.aac_cfg.aot,
1961 fmt.write_cfg.aac_cfg.ch_cfg,
1962 fmt.write_cfg.aac_cfg.sample_rate);
1963 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
1964 if (rc < 0) {
1965 pr_err("%s:Comamnd open failed\n", __func__);
1966 goto fail_cmd;
1967 }
1968 rc = wait_event_timeout(ac->cmd_wait,
1969 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1970 if (!rc) {
1971 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
1972 goto fail_cmd;
1973 }
1974 return 0;
1975fail_cmd:
1976 return -EINVAL;
1977}
1978
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001979
1980int q6asm_media_format_block_multi_aac(struct audio_client *ac,
1981 struct asm_aac_cfg *cfg)
1982{
1983 struct asm_stream_media_format_update fmt;
1984 int rc = 0;
1985
1986 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
1987 cfg->sample_rate, cfg->ch_cfg);
1988
1989 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
1990
1991 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
1992
1993 fmt.format = MPEG4_MULTI_AAC;
1994 fmt.cfg_size = sizeof(struct asm_aac_cfg);
1995 fmt.write_cfg.aac_cfg.format = cfg->format;
1996 fmt.write_cfg.aac_cfg.aot = cfg->aot;
1997 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
1998 fmt.write_cfg.aac_cfg.section_data_resilience =
1999 cfg->section_data_resilience;
2000 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2001 cfg->scalefactor_data_resilience;
2002 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2003 cfg->spectral_data_resilience;
2004 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2005 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2006 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2007 __func__, fmt.format, fmt.cfg_size,
2008 fmt.write_cfg.aac_cfg.format,
2009 fmt.write_cfg.aac_cfg.aot,
2010 fmt.write_cfg.aac_cfg.ch_cfg,
2011 fmt.write_cfg.aac_cfg.sample_rate);
2012 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2013 if (rc < 0) {
2014 pr_err("%s:Comamnd open failed\n", __func__);
2015 goto fail_cmd;
2016 }
2017 rc = wait_event_timeout(ac->cmd_wait,
2018 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2019 if (!rc) {
2020 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2021 goto fail_cmd;
2022 }
2023 return 0;
2024fail_cmd:
2025 return -EINVAL;
2026}
2027
2028
Alex Wong2caeecc2011-10-28 10:52:15 +05302029
2030int q6asm_media_format_block(struct audio_client *ac, uint32_t format)
2031{
2032
2033 struct asm_stream_media_format_update fmt;
2034 int rc = 0;
2035
2036 pr_debug("%s:session[%d] format[0x%x]\n", __func__,
2037 ac->session, format);
2038
2039 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2040 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302041 switch (format) {
2042 case FORMAT_V13K:
2043 fmt.format = V13K_FS;
2044 break;
2045 case FORMAT_EVRC:
2046 fmt.format = EVRC_FS;
2047 break;
2048 case FORMAT_AMRWB:
2049 fmt.format = AMRWB_FS;
2050 break;
2051 case FORMAT_AMRNB:
2052 fmt.format = AMRNB_FS;
2053 break;
2054 case FORMAT_MP3:
2055 fmt.format = MP3;
2056 break;
2057 default:
2058 pr_err("Invalid format[%d]\n", format);
2059 goto fail_cmd;
2060 }
Alex Wong2caeecc2011-10-28 10:52:15 +05302061 fmt.cfg_size = 0;
2062
2063 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2064 if (rc < 0) {
2065 pr_err("%s:Comamnd open failed\n", __func__);
2066 goto fail_cmd;
2067 }
2068 rc = wait_event_timeout(ac->cmd_wait,
2069 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2070 if (!rc) {
2071 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2072 goto fail_cmd;
2073 }
2074 return 0;
2075fail_cmd:
2076 return -EINVAL;
2077}
2078
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002079int q6asm_media_format_block_wma(struct audio_client *ac,
2080 void *cfg)
2081{
2082 struct asm_stream_media_format_update fmt;
2083 struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
2084 int rc = 0;
2085
2086 pr_debug("session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d],\
2087 balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x]\n",
2088 ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
2089 wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
2090 wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
2091 wma_cfg->ch_mask, wma_cfg->encode_opt);
2092
2093 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2094
2095 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2096
2097 fmt.format = WMA_V9;
2098 fmt.cfg_size = sizeof(struct asm_wma_cfg);
2099 fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag;
2100 fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg;
2101 fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate;
2102 fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
2103 fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align;
2104 fmt.write_cfg.wma_cfg.valid_bits_per_sample =
2105 wma_cfg->valid_bits_per_sample;
2106 fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask;
2107 fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt;
2108 fmt.write_cfg.wma_cfg.adv_encode_opt = 0;
2109 fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0;
2110 fmt.write_cfg.wma_cfg.drc_peak_ref = 0;
2111 fmt.write_cfg.wma_cfg.drc_peak_target = 0;
2112 fmt.write_cfg.wma_cfg.drc_ave_ref = 0;
2113 fmt.write_cfg.wma_cfg.drc_ave_target = 0;
2114
2115 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2116 if (rc < 0) {
2117 pr_err("%s:Comamnd open failed\n", __func__);
2118 goto fail_cmd;
2119 }
2120 rc = wait_event_timeout(ac->cmd_wait,
2121 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2122 if (!rc) {
2123 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2124 goto fail_cmd;
2125 }
2126 return 0;
2127fail_cmd:
2128 return -EINVAL;
2129}
2130
2131int q6asm_media_format_block_wmapro(struct audio_client *ac,
2132 void *cfg)
2133{
2134 struct asm_stream_media_format_update fmt;
2135 struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
2136 int rc = 0;
2137
2138 pr_debug("session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d],"
2139 "balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x],\
2140 adv_enc_opt[0x%4x], adv_enc_opt2[0x%8x]\n",
2141 ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
2142 wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
2143 wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
2144 wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
2145 wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
2146
2147 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2148
2149 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2150
2151 fmt.format = WMA_V10PRO;
2152 fmt.cfg_size = sizeof(struct asm_wmapro_cfg);
2153 fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag;
2154 fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg;
2155 fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate;
2156 fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec =
2157 wmapro_cfg->avg_bytes_per_sec;
2158 fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align;
2159 fmt.write_cfg.wmapro_cfg.valid_bits_per_sample =
2160 wmapro_cfg->valid_bits_per_sample;
2161 fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask;
2162 fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt;
2163 fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt;
2164 fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2;
2165 fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0;
2166 fmt.write_cfg.wmapro_cfg.drc_peak_target = 0;
2167 fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0;
2168 fmt.write_cfg.wmapro_cfg.drc_ave_target = 0;
2169
2170 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2171 if (rc < 0) {
2172 pr_err("%s:Comamnd open failed\n", __func__);
2173 goto fail_cmd;
2174 }
2175 rc = wait_event_timeout(ac->cmd_wait,
2176 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2177 if (!rc) {
2178 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2179 goto fail_cmd;
2180 }
2181 return 0;
2182fail_cmd:
2183 return -EINVAL;
2184}
2185
2186int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
2187 uint32_t bufsz, uint32_t bufcnt)
2188{
2189 struct asm_stream_cmd_memory_map mem_map;
2190 int rc = 0;
2191
2192 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2193 pr_err("APR handle NULL\n");
2194 return -EINVAL;
2195 }
2196
2197 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2198
2199 mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP;
2200
2201 mem_map.buf_add = buf_add;
2202 mem_map.buf_size = bufsz * bufcnt;
2203 mem_map.mempool_id = 0; /* EBI */
2204 mem_map.reserved = 0;
2205
2206 q6asm_add_mmaphdr(&mem_map.hdr,
2207 sizeof(struct asm_stream_cmd_memory_map), TRUE);
2208
2209 pr_debug("buf add[%x] buf_add_parameter[%x]\n",
2210 mem_map.buf_add, buf_add);
2211
2212 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map);
2213 if (rc < 0) {
2214 pr_err("mem_map op[0x%x]rc[%d]\n",
2215 mem_map.hdr.opcode, rc);
2216 rc = -EINVAL;
2217 goto fail_cmd;
2218 }
2219
2220 rc = wait_event_timeout(this_mmap.cmd_wait,
2221 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2222 if (!rc) {
2223 pr_err("timeout. waited for memory_map\n");
2224 rc = -EINVAL;
2225 goto fail_cmd;
2226 }
2227 rc = 0;
2228fail_cmd:
2229 return rc;
2230}
2231
2232int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
2233{
2234 struct asm_stream_cmd_memory_unmap mem_unmap;
2235 int rc = 0;
2236
2237 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2238 pr_err("APR handle NULL\n");
2239 return -EINVAL;
2240 }
2241 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2242
2243 q6asm_add_mmaphdr(&mem_unmap.hdr,
2244 sizeof(struct asm_stream_cmd_memory_unmap), TRUE);
2245 mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP;
2246 mem_unmap.buf_add = buf_add;
2247
2248 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_unmap);
2249 if (rc < 0) {
2250 pr_err("mem_unmap op[0x%x]rc[%d]\n",
2251 mem_unmap.hdr.opcode, rc);
2252 rc = -EINVAL;
2253 goto fail_cmd;
2254 }
2255
2256 rc = wait_event_timeout(this_mmap.cmd_wait,
2257 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2258 if (!rc) {
2259 pr_err("timeout. waited for memory_map\n");
2260 rc = -EINVAL;
2261 goto fail_cmd;
2262 }
2263 rc = 0;
2264fail_cmd:
2265 return rc;
2266}
2267
2268int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
2269{
2270 void *vol_cmd = NULL;
2271 void *payload = NULL;
2272 struct asm_pp_params_command *cmd = NULL;
2273 struct asm_lrchannel_gain_params *lrgain = NULL;
2274 int sz = 0;
2275 int rc = 0;
2276
2277 sz = sizeof(struct asm_pp_params_command) +
2278 + sizeof(struct asm_lrchannel_gain_params);
2279 vol_cmd = kzalloc(sz, GFP_KERNEL);
2280 if (vol_cmd == NULL) {
2281 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2282 rc = -EINVAL;
2283 return rc;
2284 }
2285 cmd = (struct asm_pp_params_command *)vol_cmd;
2286 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2287 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2288 cmd->payload = NULL;
2289 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2290 sizeof(struct asm_lrchannel_gain_params);
2291 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2292 cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID;
2293 cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params);
2294 cmd->params.reserved = 0;
2295
2296 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2297 lrgain = (struct asm_lrchannel_gain_params *)payload;
2298
2299 lrgain->left_gain = left_gain;
2300 lrgain->right_gain = right_gain;
2301 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2302 if (rc < 0) {
2303 pr_err("%s: Volume Command failed\n", __func__);
2304 rc = -EINVAL;
2305 goto fail_cmd;
2306 }
2307
2308 rc = wait_event_timeout(ac->cmd_wait,
2309 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2310 if (!rc) {
2311 pr_err("%s: timeout in sending volume command to apr\n",
2312 __func__);
2313 rc = -EINVAL;
2314 goto fail_cmd;
2315 }
2316 rc = 0;
2317fail_cmd:
2318 kfree(vol_cmd);
2319 return rc;
2320}
2321
2322static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
2323 uint32_t bufsz, uint32_t bufcnt)
2324{
2325 struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL;
2326 struct asm_memory_map_regions *mregions = NULL;
2327 struct audio_port_data *port = NULL;
2328 struct audio_buffer *ab = NULL;
2329 void *mmap_region_cmd = NULL;
2330 void *payload = NULL;
2331 int rc = 0;
2332 int i = 0;
2333 int cmd_size = 0;
2334
2335 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2336 pr_err("APR handle NULL\n");
2337 return -EINVAL;
2338 }
2339 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2340
2341 cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions)
2342 + sizeof(struct asm_memory_map_regions) * bufcnt;
2343
2344 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302345 if (mmap_region_cmd == NULL) {
2346 pr_err("%s: Mem alloc failed\n", __func__);
2347 rc = -EINVAL;
2348 return rc;
2349 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002350 mmap_regions = (struct asm_stream_cmd_memory_map_regions *)
2351 mmap_region_cmd;
2352 q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE);
2353 mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS;
2354 mmap_regions->mempool_id = 0;
2355 mmap_regions->nregions = bufcnt & 0x00ff;
2356 pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions);
2357 payload = ((u8 *) mmap_region_cmd +
2358 sizeof(struct asm_stream_cmd_memory_map_regions));
2359 mregions = (struct asm_memory_map_regions *)payload;
2360
2361 port = &ac->port[dir];
2362 for (i = 0; i < bufcnt; i++) {
2363 ab = &port->buf[i];
2364 mregions->phys = ab->phys;
2365 mregions->buf_size = ab->size;
2366 ++mregions;
2367 }
2368
2369 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) mmap_region_cmd);
2370 if (rc < 0) {
2371 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2372 mmap_regions->hdr.opcode, rc);
2373 rc = -EINVAL;
2374 goto fail_cmd;
2375 }
2376
2377 rc = wait_event_timeout(this_mmap.cmd_wait,
2378 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2379 if (!rc) {
2380 pr_err("timeout. waited for memory_map\n");
2381 rc = -EINVAL;
2382 goto fail_cmd;
2383 }
2384 rc = 0;
2385fail_cmd:
2386 kfree(mmap_region_cmd);
2387 return rc;
2388}
2389
2390static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
2391 uint32_t bufsz, uint32_t bufcnt)
2392{
2393 struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL;
2394 struct asm_memory_unmap_regions *mregions = NULL;
2395 struct audio_port_data *port = NULL;
2396 struct audio_buffer *ab = NULL;
2397 void *unmap_region_cmd = NULL;
2398 void *payload = NULL;
2399 int rc = 0;
2400 int i = 0;
2401 int cmd_size = 0;
2402
2403 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2404 pr_err("APR handle NULL\n");
2405 return -EINVAL;
2406 }
2407 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2408
2409 cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) +
2410 sizeof(struct asm_memory_unmap_regions) * bufcnt;
2411
2412 unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302413 if (unmap_region_cmd == NULL) {
2414 pr_err("%s: Mem alloc failed\n", __func__);
2415 rc = -EINVAL;
2416 return rc;
2417 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002418 unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *)
2419 unmap_region_cmd;
2420 q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE);
2421 unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS;
2422 unmap_regions->nregions = bufcnt & 0x00ff;
2423 pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions);
2424 payload = ((u8 *) unmap_region_cmd +
2425 sizeof(struct asm_stream_cmd_memory_unmap_regions));
2426 mregions = (struct asm_memory_unmap_regions *)payload;
2427 port = &ac->port[dir];
2428 for (i = 0; i < bufcnt; i++) {
2429 ab = &port->buf[i];
2430 mregions->phys = ab->phys;
2431 ++mregions;
2432 }
2433
2434 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd);
2435 if (rc < 0) {
2436 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2437 unmap_regions->hdr.opcode, rc);
2438 goto fail_cmd;
2439 }
2440
2441 rc = wait_event_timeout(this_mmap.cmd_wait,
2442 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2443 if (!rc) {
2444 pr_err("timeout. waited for memory_unmap\n");
2445 goto fail_cmd;
2446 }
2447 rc = 0;
2448
2449fail_cmd:
2450 kfree(unmap_region_cmd);
2451 return rc;
2452}
2453
2454int q6asm_set_mute(struct audio_client *ac, int muteflag)
2455{
2456 void *vol_cmd = NULL;
2457 void *payload = NULL;
2458 struct asm_pp_params_command *cmd = NULL;
2459 struct asm_mute_params *mute = NULL;
2460 int sz = 0;
2461 int rc = 0;
2462
2463 sz = sizeof(struct asm_pp_params_command) +
2464 + sizeof(struct asm_mute_params);
2465 vol_cmd = kzalloc(sz, GFP_KERNEL);
2466 if (vol_cmd == NULL) {
2467 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2468 rc = -EINVAL;
2469 return rc;
2470 }
2471 cmd = (struct asm_pp_params_command *)vol_cmd;
2472 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2473 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2474 cmd->payload = NULL;
2475 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2476 sizeof(struct asm_mute_params);
2477 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2478 cmd->params.param_id = MUTE_CONFIG_PARAM_ID;
2479 cmd->params.param_size = sizeof(struct asm_mute_params);
2480 cmd->params.reserved = 0;
2481
2482 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2483 mute = (struct asm_mute_params *)payload;
2484
2485 mute->muteflag = muteflag;
2486 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2487 if (rc < 0) {
2488 pr_err("%s: Mute Command failed\n", __func__);
2489 rc = -EINVAL;
2490 goto fail_cmd;
2491 }
2492
2493 rc = wait_event_timeout(ac->cmd_wait,
2494 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2495 if (!rc) {
2496 pr_err("%s: timeout in sending mute command to apr\n",
2497 __func__);
2498 rc = -EINVAL;
2499 goto fail_cmd;
2500 }
2501 rc = 0;
2502fail_cmd:
2503 kfree(vol_cmd);
2504 return rc;
2505}
2506
2507int q6asm_set_volume(struct audio_client *ac, int volume)
2508{
2509 void *vol_cmd = NULL;
2510 void *payload = NULL;
2511 struct asm_pp_params_command *cmd = NULL;
2512 struct asm_master_gain_params *mgain = NULL;
2513 int sz = 0;
2514 int rc = 0;
2515
2516 sz = sizeof(struct asm_pp_params_command) +
2517 + sizeof(struct asm_master_gain_params);
2518 vol_cmd = kzalloc(sz, GFP_KERNEL);
2519 if (vol_cmd == NULL) {
2520 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2521 rc = -EINVAL;
2522 return rc;
2523 }
2524 cmd = (struct asm_pp_params_command *)vol_cmd;
2525 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2526 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2527 cmd->payload = NULL;
2528 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2529 sizeof(struct asm_master_gain_params);
2530 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2531 cmd->params.param_id = MASTER_GAIN_PARAM_ID;
2532 cmd->params.param_size = sizeof(struct asm_master_gain_params);
2533 cmd->params.reserved = 0;
2534
2535 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2536 mgain = (struct asm_master_gain_params *)payload;
2537
2538 mgain->master_gain = volume;
2539 mgain->padding = 0x00;
2540 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2541 if (rc < 0) {
2542 pr_err("%s: Volume Command failed\n", __func__);
2543 rc = -EINVAL;
2544 goto fail_cmd;
2545 }
2546
2547 rc = wait_event_timeout(ac->cmd_wait,
2548 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2549 if (!rc) {
2550 pr_err("%s: timeout in sending volume command to apr\n",
2551 __func__);
2552 rc = -EINVAL;
2553 goto fail_cmd;
2554 }
2555 rc = 0;
2556fail_cmd:
2557 kfree(vol_cmd);
2558 return rc;
2559}
2560
2561int q6asm_set_softpause(struct audio_client *ac,
2562 struct asm_softpause_params *pause_param)
2563{
2564 void *vol_cmd = NULL;
2565 void *payload = NULL;
2566 struct asm_pp_params_command *cmd = NULL;
2567 struct asm_softpause_params *params = NULL;
2568 int sz = 0;
2569 int rc = 0;
2570
2571 sz = sizeof(struct asm_pp_params_command) +
2572 + sizeof(struct asm_softpause_params);
2573 vol_cmd = kzalloc(sz, GFP_KERNEL);
2574 if (vol_cmd == NULL) {
2575 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2576 rc = -EINVAL;
2577 return rc;
2578 }
2579 cmd = (struct asm_pp_params_command *)vol_cmd;
2580 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2581 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2582 cmd->payload = NULL;
2583 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2584 sizeof(struct asm_softpause_params);
2585 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2586 cmd->params.param_id = SOFT_PAUSE_PARAM_ID;
2587 cmd->params.param_size = sizeof(struct asm_softpause_params);
2588 cmd->params.reserved = 0;
2589
2590 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2591 params = (struct asm_softpause_params *)payload;
2592
2593 params->enable = pause_param->enable;
2594 params->period = pause_param->period;
2595 params->step = pause_param->step;
2596 params->rampingcurve = pause_param->rampingcurve;
2597 pr_debug("%s: soft Pause Command: enable = %d, period = %d,"
2598 "step = %d, curve = %d\n", __func__, params->enable,
2599 params->period, params->step, params->rampingcurve);
2600 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2601 if (rc < 0) {
2602 pr_err("%s: Volume Command(soft_pause) failed\n", __func__);
2603 rc = -EINVAL;
2604 goto fail_cmd;
2605 }
2606
2607 rc = wait_event_timeout(ac->cmd_wait,
2608 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2609 if (!rc) {
2610 pr_err("%s: timeout in sending volume command(soft_pause)"
2611 "to apr\n", __func__);
2612 rc = -EINVAL;
2613 goto fail_cmd;
2614 }
2615 rc = 0;
2616fail_cmd:
2617 kfree(vol_cmd);
2618 return rc;
2619}
2620
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07002621int q6asm_set_softvolume(struct audio_client *ac,
2622 struct asm_softvolume_params *softvol_param)
2623{
2624 void *vol_cmd = NULL;
2625 void *payload = NULL;
2626 struct asm_pp_params_command *cmd = NULL;
2627 struct asm_softvolume_params *params = NULL;
2628 int sz = 0;
2629 int rc = 0;
2630
2631 sz = sizeof(struct asm_pp_params_command) +
2632 + sizeof(struct asm_softvolume_params);
2633 vol_cmd = kzalloc(sz, GFP_KERNEL);
2634 if (vol_cmd == NULL) {
2635 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2636 rc = -EINVAL;
2637 return rc;
2638 }
2639 cmd = (struct asm_pp_params_command *)vol_cmd;
2640 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2641 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2642 cmd->payload = NULL;
2643 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2644 sizeof(struct asm_softvolume_params);
2645 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2646 cmd->params.param_id = SOFT_VOLUME_PARAM_ID;
2647 cmd->params.param_size = sizeof(struct asm_softvolume_params);
2648 cmd->params.reserved = 0;
2649
2650 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2651 params = (struct asm_softvolume_params *)payload;
2652
2653 params->period = softvol_param->period;
2654 params->step = softvol_param->step;
2655 params->rampingcurve = softvol_param->rampingcurve;
2656 pr_debug("%s: soft Volume:opcode = %d,payload_sz =%d,module_id =%d,"
2657 "param_id = %d, param_sz = %d\n", __func__,
2658 cmd->hdr.opcode, cmd->payload_size,
2659 cmd->params.module_id, cmd->params.param_id,
2660 cmd->params.param_size);
2661 pr_debug("%s: soft Volume Command: period = %d,"
2662 "step = %d, curve = %d\n", __func__, params->period,
2663 params->step, params->rampingcurve);
2664 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2665 if (rc < 0) {
2666 pr_err("%s: Volume Command(soft_volume) failed\n", __func__);
2667 rc = -EINVAL;
2668 goto fail_cmd;
2669 }
2670
2671 rc = wait_event_timeout(ac->cmd_wait,
2672 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2673 if (!rc) {
2674 pr_err("%s: timeout in sending volume command(soft_volume)"
2675 "to apr\n", __func__);
2676 rc = -EINVAL;
2677 goto fail_cmd;
2678 }
2679 rc = 0;
2680fail_cmd:
2681 kfree(vol_cmd);
2682 return rc;
2683}
2684
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002685int q6asm_equalizer(struct audio_client *ac, void *eq)
2686{
2687 void *eq_cmd = NULL;
2688 void *payload = NULL;
2689 struct asm_pp_params_command *cmd = NULL;
2690 struct asm_equalizer_params *equalizer = NULL;
2691 struct msm_audio_eq_stream_config *eq_params = NULL;
2692 int i = 0;
2693 int sz = 0;
2694 int rc = 0;
2695
2696 sz = sizeof(struct asm_pp_params_command) +
2697 + sizeof(struct asm_equalizer_params);
2698 eq_cmd = kzalloc(sz, GFP_KERNEL);
2699 if (eq_cmd == NULL) {
2700 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2701 rc = -EINVAL;
2702 goto fail_cmd;
2703 }
2704 eq_params = (struct msm_audio_eq_stream_config *) eq;
2705 cmd = (struct asm_pp_params_command *)eq_cmd;
2706 q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE);
2707 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2708 cmd->payload = NULL;
2709 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2710 sizeof(struct asm_equalizer_params);
2711 cmd->params.module_id = EQUALIZER_MODULE_ID;
2712 cmd->params.param_id = EQUALIZER_PARAM_ID;
2713 cmd->params.param_size = sizeof(struct asm_equalizer_params);
2714 cmd->params.reserved = 0;
2715 payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command));
2716 equalizer = (struct asm_equalizer_params *)payload;
2717
2718 equalizer->enable = eq_params->enable;
2719 equalizer->num_bands = eq_params->num_bands;
2720 pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
2721 eq_params->num_bands);
2722 for (i = 0; i < eq_params->num_bands; i++) {
2723 equalizer->eq_bands[i].band_idx =
2724 eq_params->eq_bands[i].band_idx;
2725 equalizer->eq_bands[i].filter_type =
2726 eq_params->eq_bands[i].filter_type;
2727 equalizer->eq_bands[i].center_freq_hz =
2728 eq_params->eq_bands[i].center_freq_hz;
2729 equalizer->eq_bands[i].filter_gain =
2730 eq_params->eq_bands[i].filter_gain;
2731 equalizer->eq_bands[i].q_factor =
2732 eq_params->eq_bands[i].q_factor;
2733 pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
2734 eq_params->eq_bands[i].filter_type, i);
2735 pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
2736 eq_params->eq_bands[i].center_freq_hz, i);
2737 pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
2738 eq_params->eq_bands[i].filter_gain, i);
2739 pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
2740 eq_params->eq_bands[i].q_factor, i);
2741 }
2742 rc = apr_send_pkt(ac->apr, (uint32_t *) eq_cmd);
2743 if (rc < 0) {
2744 pr_err("%s: Equalizer Command failed\n", __func__);
2745 rc = -EINVAL;
2746 goto fail_cmd;
2747 }
2748
2749 rc = wait_event_timeout(ac->cmd_wait,
2750 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2751 if (!rc) {
2752 pr_err("%s: timeout in sending equalizer command to apr\n",
2753 __func__);
2754 rc = -EINVAL;
2755 goto fail_cmd;
2756 }
2757 rc = 0;
2758fail_cmd:
2759 kfree(eq_cmd);
2760 return rc;
2761}
2762
2763int q6asm_read(struct audio_client *ac)
2764{
2765 struct asm_stream_cmd_read read;
2766 struct audio_buffer *ab;
2767 int dsp_buf;
2768 struct audio_port_data *port;
2769 int rc;
2770 if (!ac || ac->apr == NULL) {
2771 pr_err("APR handle NULL\n");
2772 return -EINVAL;
2773 }
2774 if (ac->io_mode == SYNC_IO_MODE) {
2775 port = &ac->port[OUT];
2776
2777 q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
2778
2779 mutex_lock(&port->lock);
2780
2781 dsp_buf = port->dsp_buf;
2782 ab = &port->buf[dsp_buf];
2783
2784 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
2785 __func__,
2786 ac->session,
2787 dsp_buf,
2788 (void *)port->buf[dsp_buf].data,
2789 port->cpu_buf,
2790 (void *)port->buf[port->cpu_buf].phys);
2791
2792 read.hdr.opcode = ASM_DATA_CMD_READ;
2793 read.buf_add = ab->phys;
2794 read.buf_size = ab->size;
2795 read.uid = port->dsp_buf;
2796 read.hdr.token = port->dsp_buf;
2797
2798 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
2799 mutex_unlock(&port->lock);
2800 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
2801 read.buf_add,
2802 read.hdr.token,
2803 read.uid);
2804 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
2805 if (rc < 0) {
2806 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
2807 goto fail_cmd;
2808 }
2809 return 0;
2810 }
2811fail_cmd:
2812 return -EINVAL;
2813}
2814
2815int q6asm_read_nolock(struct audio_client *ac)
2816{
2817 struct asm_stream_cmd_read read;
2818 struct audio_buffer *ab;
2819 int dsp_buf;
2820 struct audio_port_data *port;
2821 int rc;
2822 if (!ac || ac->apr == NULL) {
2823 pr_err("APR handle NULL\n");
2824 return -EINVAL;
2825 }
2826 if (ac->io_mode == SYNC_IO_MODE) {
2827 port = &ac->port[OUT];
2828
2829 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
2830
2831
2832 dsp_buf = port->dsp_buf;
2833 ab = &port->buf[dsp_buf];
2834
2835 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
2836 __func__,
2837 ac->session,
2838 dsp_buf,
2839 (void *)port->buf[dsp_buf].data,
2840 port->cpu_buf,
2841 (void *)port->buf[port->cpu_buf].phys);
2842
2843 read.hdr.opcode = ASM_DATA_CMD_READ;
2844 read.buf_add = ab->phys;
2845 read.buf_size = ab->size;
2846 read.uid = port->dsp_buf;
2847 read.hdr.token = port->dsp_buf;
2848
2849 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
2850 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
2851 read.buf_add,
2852 read.hdr.token,
2853 read.uid);
2854 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
2855 if (rc < 0) {
2856 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
2857 goto fail_cmd;
2858 }
2859 return 0;
2860 }
2861fail_cmd:
2862 return -EINVAL;
2863}
2864
2865
2866static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
2867 uint32_t pkt_size, uint32_t cmd_flg)
2868{
2869 pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg,
2870 ac->session);
2871 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
2872 APR_HDR_LEN(sizeof(struct apr_hdr)),\
2873 APR_PKT_VER);
2874 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
2875 hdr->src_domain = APR_DOMAIN_APPS;
2876 hdr->dest_svc = APR_SVC_ASM;
2877 hdr->dest_domain = APR_DOMAIN_ADSP;
2878 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
2879 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
2880 if (cmd_flg) {
2881 hdr->token = ac->session;
2882 atomic_set(&ac->cmd_state, 1);
2883 }
2884 hdr->pkt_size = pkt_size;
2885 return;
2886}
2887
2888int q6asm_async_write(struct audio_client *ac,
2889 struct audio_aio_write_param *param)
2890{
2891 int rc = 0;
2892 struct asm_stream_cmd_write write;
2893
2894 if (!ac || ac->apr == NULL) {
2895 pr_err("%s: APR handle NULL\n", __func__);
2896 return -EINVAL;
2897 }
2898
2899 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE);
2900
2901 /* Pass physical address as token for AIO scheme */
2902 write.hdr.token = param->uid;
2903 write.hdr.opcode = ASM_DATA_CMD_WRITE;
2904 write.buf_add = param->paddr;
2905 write.avail_bytes = param->len;
2906 write.uid = param->uid;
2907 write.msw_ts = param->msw_ts;
2908 write.lsw_ts = param->lsw_ts;
2909 /* Use 0xFF00 for disabling timestamps */
2910 if (param->flags == 0xFF00)
2911 write.uflags = (0x00000000 | (param->flags & 0x800000FF));
2912 else
2913 write.uflags = (0x80000000 | param->flags);
2914
2915 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
2916 write.buf_add, write.avail_bytes);
2917
2918 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
2919 if (rc < 0) {
2920 pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__,
2921 write.hdr.opcode, rc);
2922 goto fail_cmd;
2923 }
2924 return 0;
2925fail_cmd:
2926 return -EINVAL;
2927}
2928
2929int q6asm_async_read(struct audio_client *ac,
2930 struct audio_aio_read_param *param)
2931{
2932 int rc = 0;
2933 struct asm_stream_cmd_read read;
2934
2935 if (!ac || ac->apr == NULL) {
2936 pr_err("%s: APR handle NULL\n", __func__);
2937 return -EINVAL;
2938 }
2939
2940 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
2941
2942 /* Pass physical address as token for AIO scheme */
2943 read.hdr.token = param->paddr;
2944 read.hdr.opcode = ASM_DATA_CMD_READ;
2945 read.buf_add = param->paddr;
2946 read.buf_size = param->len;
2947 read.uid = param->uid;
2948
2949 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
2950 read.buf_add, read.buf_size);
2951
2952 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
2953 if (rc < 0) {
2954 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
2955 read.hdr.opcode, rc);
2956 goto fail_cmd;
2957 }
2958 return 0;
2959fail_cmd:
2960 return -EINVAL;
2961}
2962
2963int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
2964 uint32_t lsw_ts, uint32_t flags)
2965{
2966 int rc = 0;
2967 struct asm_stream_cmd_write write;
2968 struct audio_port_data *port;
2969 struct audio_buffer *ab;
2970 int dsp_buf = 0;
2971
2972 if (!ac || ac->apr == NULL) {
2973 pr_err("APR handle NULL\n");
2974 return -EINVAL;
2975 }
2976 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
2977 if (ac->io_mode == SYNC_IO_MODE) {
2978 port = &ac->port[IN];
2979
2980 q6asm_add_hdr(ac, &write.hdr, sizeof(write),
2981 FALSE);
2982 mutex_lock(&port->lock);
2983
2984 dsp_buf = port->dsp_buf;
2985 ab = &port->buf[dsp_buf];
2986
2987 write.hdr.token = port->dsp_buf;
2988 write.hdr.opcode = ASM_DATA_CMD_WRITE;
2989 write.buf_add = ab->phys;
2990 write.avail_bytes = len;
2991 write.uid = port->dsp_buf;
2992 write.msw_ts = msw_ts;
2993 write.lsw_ts = lsw_ts;
2994 /* Use 0xFF00 for disabling timestamps */
2995 if (flags == 0xFF00)
2996 write.uflags = (0x00000000 | (flags & 0x800000FF));
2997 else
2998 write.uflags = (0x80000000 | flags);
2999 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3000
3001 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3002 , __func__,
3003 ab->phys,
3004 write.buf_add,
3005 write.hdr.token,
3006 write.uid);
3007 mutex_unlock(&port->lock);
Rajesha Kini3498c932011-07-19 19:58:27 +05303008#ifdef CONFIG_DEBUG_FS
3009 if (out_enable_flag) {
3010 char zero_pattern[2] = {0x00, 0x00};
3011 /* If First two byte is non zero and last two byte
3012 is zero then it is warm output pattern */
3013 if ((strncmp(((char *)ab->data), zero_pattern, 2)) &&
3014 (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3015 do_gettimeofday(&out_warm_tv);
3016 pr_debug("WARM:apr_send_pkt at \
3017 %ld sec %ld microsec\n", out_warm_tv.tv_sec,\
3018 out_warm_tv.tv_usec);
3019 pr_debug("Warm Pattern Matched");
3020 }
3021 /* If First two byte is zero and last two byte is
3022 non zero then it is cont ouput pattern */
3023 else if ((!strncmp(((char *)ab->data), zero_pattern, 2))
3024 && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3025 do_gettimeofday(&out_cont_tv);
3026 pr_debug("CONT:apr_send_pkt at \
3027 %ld sec %ld microsec\n", out_cont_tv.tv_sec,\
3028 out_cont_tv.tv_usec);
3029 pr_debug("Cont Pattern Matched");
3030 }
3031 }
3032#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003033 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3034 if (rc < 0) {
3035 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3036 goto fail_cmd;
3037 }
3038 pr_debug("%s: WRITE SUCCESS\n", __func__);
3039 return 0;
3040 }
3041fail_cmd:
3042 return -EINVAL;
3043}
3044
3045int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3046 uint32_t lsw_ts, uint32_t flags)
3047{
3048 int rc = 0;
3049 struct asm_stream_cmd_write write;
3050 struct audio_port_data *port;
3051 struct audio_buffer *ab;
3052 int dsp_buf = 0;
3053
3054 if (!ac || ac->apr == NULL) {
3055 pr_err("APR handle NULL\n");
3056 return -EINVAL;
3057 }
3058 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3059 if (ac->io_mode == SYNC_IO_MODE) {
3060 port = &ac->port[IN];
3061
3062 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
3063 FALSE);
3064
3065 dsp_buf = port->dsp_buf;
3066 ab = &port->buf[dsp_buf];
3067
3068 write.hdr.token = port->dsp_buf;
3069 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3070 write.buf_add = ab->phys;
3071 write.avail_bytes = len;
3072 write.uid = port->dsp_buf;
3073 write.msw_ts = msw_ts;
3074 write.lsw_ts = lsw_ts;
3075 /* Use 0xFF00 for disabling timestamps */
3076 if (flags == 0xFF00)
3077 write.uflags = (0x00000000 | (flags & 0x800000FF));
3078 else
3079 write.uflags = (0x80000000 | flags);
3080 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3081
3082 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3083 , __func__,
3084 ab->phys,
3085 write.buf_add,
3086 write.hdr.token,
3087 write.uid);
3088
3089 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3090 if (rc < 0) {
3091 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3092 goto fail_cmd;
3093 }
3094 pr_debug("%s: WRITE SUCCESS\n", __func__);
3095 return 0;
3096 }
3097fail_cmd:
3098 return -EINVAL;
3099}
3100
3101uint64_t q6asm_get_session_time(struct audio_client *ac)
3102{
3103 struct apr_hdr hdr;
3104 int rc;
3105
3106 if (!ac || ac->apr == NULL) {
3107 pr_err("APR handle NULL\n");
3108 return -EINVAL;
3109 }
3110 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3111 hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME;
3112 atomic_set(&ac->time_flag, 1);
3113
3114 pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
3115 ac->session,
3116 hdr.opcode);
3117 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3118 if (rc < 0) {
3119 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3120 goto fail_cmd;
3121 }
3122 rc = wait_event_timeout(ac->time_wait,
3123 (atomic_read(&ac->time_flag) == 0), 5*HZ);
3124 if (!rc) {
3125 pr_err("%s: timeout in getting session time from DSP\n",
3126 __func__);
3127 goto fail_cmd;
3128 }
3129 return ac->time_stamp;
3130
3131fail_cmd:
3132 return -EINVAL;
3133}
3134
3135int q6asm_cmd(struct audio_client *ac, int cmd)
3136{
3137 struct apr_hdr hdr;
3138 int rc;
3139 atomic_t *state;
3140 int cnt = 0;
3141
3142 if (!ac || ac->apr == NULL) {
3143 pr_err("APR handle NULL\n");
3144 return -EINVAL;
3145 }
3146 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3147 switch (cmd) {
3148 case CMD_PAUSE:
3149 pr_debug("%s:CMD_PAUSE\n", __func__);
3150 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3151 state = &ac->cmd_state;
3152 break;
3153 case CMD_FLUSH:
3154 pr_debug("%s:CMD_FLUSH\n", __func__);
3155 hdr.opcode = ASM_STREAM_CMD_FLUSH;
3156 state = &ac->cmd_state;
3157 break;
3158 case CMD_OUT_FLUSH:
3159 pr_debug("%s:CMD_OUT_FLUSH\n", __func__);
3160 hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
3161 state = &ac->cmd_state;
3162 break;
3163 case CMD_EOS:
3164 pr_debug("%s:CMD_EOS\n", __func__);
3165 hdr.opcode = ASM_DATA_CMD_EOS;
3166 atomic_set(&ac->cmd_state, 0);
3167 state = &ac->cmd_state;
3168 break;
3169 case CMD_CLOSE:
3170 pr_debug("%s:CMD_CLOSE\n", __func__);
3171 hdr.opcode = ASM_STREAM_CMD_CLOSE;
3172 state = &ac->cmd_state;
3173 break;
3174 default:
3175 pr_err("Invalid format[%d]\n", cmd);
3176 goto fail_cmd;
3177 }
3178 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3179 ac->session,
3180 hdr.opcode);
3181 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3182 if (rc < 0) {
3183 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3184 goto fail_cmd;
3185 }
3186 rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ);
3187 if (!rc) {
3188 pr_err("timeout. waited for response opcode[0x%x]\n",
3189 hdr.opcode);
3190 goto fail_cmd;
3191 }
3192 if (cmd == CMD_FLUSH)
3193 q6asm_reset_buf_state(ac);
3194 if (cmd == CMD_CLOSE) {
3195 /* check if DSP return all buffers */
3196 if (ac->port[IN].buf) {
3197 for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
3198 cnt++) {
3199 if (ac->port[IN].buf[cnt].used == IN) {
3200 pr_debug("Write Buf[%d] not returned\n",
3201 cnt);
3202 }
3203 }
3204 }
3205 if (ac->port[OUT].buf) {
3206 for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
3207 if (ac->port[OUT].buf[cnt].used == OUT) {
3208 pr_debug("Read Buf[%d] not returned\n",
3209 cnt);
3210 }
3211 }
3212 }
3213 }
3214 return 0;
3215fail_cmd:
3216 return -EINVAL;
3217}
3218
3219int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
3220{
3221 struct apr_hdr hdr;
3222 int rc;
3223
3224 if (!ac || ac->apr == NULL) {
3225 pr_err("%s:APR handle NULL\n", __func__);
3226 return -EINVAL;
3227 }
3228 q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE);
3229 switch (cmd) {
3230 case CMD_PAUSE:
3231 pr_debug("%s:CMD_PAUSE\n", __func__);
3232 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3233 break;
3234 case CMD_EOS:
3235 pr_debug("%s:CMD_EOS\n", __func__);
3236 hdr.opcode = ASM_DATA_CMD_EOS;
3237 break;
3238 default:
3239 pr_err("%s:Invalid format[%d]\n", __func__, cmd);
3240 goto fail_cmd;
3241 }
3242 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3243 ac->session,
3244 hdr.opcode);
3245 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3246 if (rc < 0) {
3247 pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
3248 goto fail_cmd;
3249 }
3250 return 0;
3251fail_cmd:
3252 return -EINVAL;
3253}
3254
3255static void q6asm_reset_buf_state(struct audio_client *ac)
3256{
3257 int cnt = 0;
3258 int loopcnt = 0;
3259 struct audio_port_data *port = NULL;
3260
3261 if (ac->io_mode == SYNC_IO_MODE) {
3262 mutex_lock(&ac->cmd_lock);
3263 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
3264 port = &ac->port[loopcnt];
3265 cnt = port->max_buf_cnt - 1;
3266 port->dsp_buf = 0;
3267 port->cpu_buf = 0;
3268 while (cnt >= 0) {
3269 if (!port->buf)
3270 continue;
3271 port->buf[cnt].used = 1;
3272 cnt--;
3273 }
3274 }
3275 mutex_unlock(&ac->cmd_lock);
3276 }
3277}
3278
3279int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
3280{
3281 struct asm_stream_cmd_reg_tx_overflow_event tx_overflow;
3282 int rc;
3283
3284 if (!ac || ac->apr == NULL) {
3285 pr_err("APR handle NULL\n");
3286 return -EINVAL;
3287 }
3288 pr_debug("%s:session[%d]enable[%d]\n", __func__,
3289 ac->session, enable);
3290 q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
3291
3292 tx_overflow.hdr.opcode = \
3293 ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS;
3294 /* tx overflow event: enable */
3295 tx_overflow.enable = enable;
3296
3297 rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
3298 if (rc < 0) {
3299 pr_err("tx overflow op[0x%x]rc[%d]\n", \
3300 tx_overflow.hdr.opcode, rc);
3301 goto fail_cmd;
3302 }
3303 rc = wait_event_timeout(ac->cmd_wait,
3304 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3305 if (!rc) {
3306 pr_err("timeout. waited for tx overflow\n");
3307 goto fail_cmd;
3308 }
3309 return 0;
3310fail_cmd:
3311 return -EINVAL;
3312}
3313
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003314int q6asm_get_apr_service_id(int session_id)
3315{
3316 pr_debug("%s\n", __func__);
3317
Shiv Maliyappanahallia84982a2012-01-19 15:25:04 -08003318 if (session_id < 0 || session_id > SESSION_MAX) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003319 pr_err("%s: invalid session_id = %d\n", __func__, session_id);
3320 return -EINVAL;
3321 }
3322
3323 return ((struct apr_svc *)session[session_id]->apr)->id;
3324}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003325
3326
3327static int __init q6asm_init(void)
3328{
3329 pr_debug("%s\n", __func__);
3330 init_waitqueue_head(&this_mmap.cmd_wait);
3331 memset(session, 0, sizeof(session));
Rajesha Kini3498c932011-07-19 19:58:27 +05303332#ifdef CONFIG_DEBUG_FS
3333 out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
3334 out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
3335 S_IFREG | S_IRUGO | S_IWUGO,\
3336 NULL, NULL, &audio_output_latency_debug_fops);
3337 if (IS_ERR(out_dentry))
3338 pr_err("debugfs_create_file failed\n");
3339 in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
3340 in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
3341 S_IFREG | S_IRUGO | S_IWUGO,\
3342 NULL, NULL, &audio_input_latency_debug_fops);
3343 if (IS_ERR(in_dentry))
3344 pr_err("debugfs_create_file failed\n");
3345#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003346 return 0;
3347}
3348
3349device_initcall(q6asm_init);