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