blob: f3a238357174efad15d5366cf296a4ac3bc46b22 [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;
Mingming Yin647e9ea2012-03-17 19:56:10 -07001231 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1232 open.uMode = STREAM_PRIORITY_HIGH;
1233 open.format = MULTI_CHANNEL_PCM;
1234 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001235 case FORMAT_MPEG4_AAC:
1236 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1237 open.format = MPEG4_AAC;
1238 break;
1239 case FORMAT_V13K:
1240 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1241 open.format = V13K_FS;
1242 break;
1243 case FORMAT_EVRC:
1244 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1245 open.format = EVRC_FS;
1246 break;
1247 case FORMAT_AMRNB:
1248 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1249 open.format = AMRNB_FS;
1250 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301251 case FORMAT_AMRWB:
1252 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1253 open.format = AMRWB_FS;
1254 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001255 default:
1256 pr_err("Invalid format[%d]\n", format);
1257 goto fail_cmd;
1258 }
1259 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1260 if (rc < 0) {
1261 pr_err("open failed op[0x%x]rc[%d]\n", \
1262 open.hdr.opcode, rc);
1263 goto fail_cmd;
1264 }
1265 rc = wait_event_timeout(ac->cmd_wait,
1266 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1267 if (!rc) {
1268 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1269 rc);
1270 goto fail_cmd;
1271 }
1272 return 0;
1273fail_cmd:
1274 return -EINVAL;
1275}
1276
Santosh Mardi23321202012-03-22 04:33:25 +05301277int q6asm_open_write_compressed(struct audio_client *ac, uint32_t format)
1278{
1279 int rc = 0x00;
1280 struct asm_stream_cmd_open_write_compressed open;
1281
1282 if ((ac == NULL) || (ac->apr == NULL)) {
1283 pr_err("%s: APR handle NULL\n", __func__);
1284 return -EINVAL;
1285 }
1286 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1287 format);
1288
1289 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1290
1291 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED;
1292
1293 switch (format) {
1294 case FORMAT_AC3:
1295 open.format = AC3_DECODER;
1296 break;
1297 case FORMAT_EAC3:
1298 open.format = EAC3_DECODER;
1299 break;
1300 case FORMAT_MP3:
1301 open.format = MP3;
1302 break;
1303 case FORMAT_DTS:
1304 open.format = DTS;
1305 break;
1306 case FORMAT_AAC:
1307 open.format = MPEG4_AAC;
1308 break;
1309 case FORMAT_ATRAC:
1310 open.format = ATRAC;
1311 break;
1312 case FORMAT_WMA_V10PRO:
1313 open.format = WMA_V10PRO;
1314 break;
1315 case FORMAT_MAT:
1316 open.format = MAT;
1317 break;
1318 default:
1319 pr_err("%s: Invalid format[%d]\n", __func__, format);
1320 goto fail_cmd;
1321 }
1322 /*Below flag indicates the DSP that Compressed audio input
1323 stream is not IEC 61937 or IEC 60958 packetizied*/
1324 open.flags = 0x00000000;
1325 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1326 if (rc < 0) {
1327 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1328 __func__, open.hdr.opcode, rc);
1329 goto fail_cmd;
1330 }
1331 rc = wait_event_timeout(ac->cmd_wait,
1332 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1333 if (!rc) {
1334 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1335 rc);
1336 goto fail_cmd;
1337 }
1338 return 0;
1339fail_cmd:
1340 return -EINVAL;
1341}
1342
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001343int q6asm_open_write(struct audio_client *ac, uint32_t format)
1344{
1345 int rc = 0x00;
1346 struct asm_stream_cmd_open_write open;
1347
1348 if ((ac == NULL) || (ac->apr == NULL)) {
1349 pr_err("%s: APR handle NULL\n", __func__);
1350 return -EINVAL;
1351 }
1352 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1353 format);
1354
1355 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1356
1357 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE;
1358 open.uMode = STREAM_PRIORITY_HIGH;
1359 /* source endpoint : matrix */
1360 open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1361 open.stream_handle = 0x00;
1362
1363 open.post_proc_top = get_asm_topology();
1364 if (open.post_proc_top == 0)
1365 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1366
1367 switch (format) {
1368 case FORMAT_LINEAR_PCM:
1369 open.format = LINEAR_PCM;
1370 break;
Kiran Kandi5e809b02012-01-31 00:24:33 -08001371 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1372 open.format = MULTI_CHANNEL_PCM;
1373 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001374 case FORMAT_MPEG4_AAC:
1375 open.format = MPEG4_AAC;
1376 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001377 case FORMAT_MPEG4_MULTI_AAC:
1378 open.format = MPEG4_MULTI_AAC;
1379 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001380 case FORMAT_WMA_V9:
1381 open.format = WMA_V9;
1382 break;
1383 case FORMAT_WMA_V10PRO:
1384 open.format = WMA_V10PRO;
1385 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05301386 case FORMAT_MP3:
1387 open.format = MP3;
1388 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001389 default:
1390 pr_err("%s: Invalid format[%d]\n", __func__, format);
1391 goto fail_cmd;
1392 }
1393 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1394 if (rc < 0) {
1395 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1396 __func__, open.hdr.opcode, rc);
1397 goto fail_cmd;
1398 }
1399 rc = wait_event_timeout(ac->cmd_wait,
1400 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1401 if (!rc) {
1402 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1403 rc);
1404 goto fail_cmd;
1405 }
1406 return 0;
1407fail_cmd:
1408 return -EINVAL;
1409}
1410
1411int q6asm_open_read_write(struct audio_client *ac,
1412 uint32_t rd_format,
1413 uint32_t wr_format)
1414{
1415 int rc = 0x00;
1416 struct asm_stream_cmd_open_read_write open;
1417
1418 if ((ac == NULL) || (ac->apr == NULL)) {
1419 pr_err("APR handle NULL\n");
1420 return -EINVAL;
1421 }
1422 pr_debug("%s: session[%d]", __func__, ac->session);
1423 pr_debug("wr_format[0x%x]rd_format[0x%x]",
1424 wr_format, rd_format);
1425
1426 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1427 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE;
1428
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301429 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_NORMAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001430 /* source endpoint : matrix */
1431 open.post_proc_top = get_asm_topology();
1432 if (open.post_proc_top == 0)
1433 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1434
1435 switch (wr_format) {
1436 case FORMAT_LINEAR_PCM:
1437 open.write_format = LINEAR_PCM;
1438 break;
1439 case FORMAT_MPEG4_AAC:
1440 open.write_format = MPEG4_AAC;
1441 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001442 case FORMAT_MPEG4_MULTI_AAC:
1443 open.write_format = MPEG4_MULTI_AAC;
1444 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001445 case FORMAT_WMA_V9:
1446 open.write_format = WMA_V9;
1447 break;
1448 case FORMAT_WMA_V10PRO:
1449 open.write_format = WMA_V10PRO;
1450 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301451 case FORMAT_AMRNB:
1452 open.write_format = AMRNB_FS;
1453 break;
1454 case FORMAT_AMRWB:
1455 open.write_format = AMRWB_FS;
1456 break;
1457 case FORMAT_V13K:
1458 open.write_format = V13K_FS;
1459 break;
1460 case FORMAT_EVRC:
1461 open.write_format = EVRC_FS;
1462 break;
1463 case FORMAT_EVRCB:
1464 open.write_format = EVRCB_FS;
1465 break;
1466 case FORMAT_EVRCWB:
1467 open.write_format = EVRCWB_FS;
1468 break;
1469 case FORMAT_MP3:
1470 open.write_format = MP3;
1471 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001472 default:
1473 pr_err("Invalid format[%d]\n", wr_format);
1474 goto fail_cmd;
1475 }
1476
1477 switch (rd_format) {
1478 case FORMAT_LINEAR_PCM:
1479 open.read_format = LINEAR_PCM;
1480 break;
1481 case FORMAT_MPEG4_AAC:
1482 open.read_format = MPEG4_AAC;
1483 break;
1484 case FORMAT_V13K:
1485 open.read_format = V13K_FS;
1486 break;
1487 case FORMAT_EVRC:
1488 open.read_format = EVRC_FS;
1489 break;
1490 case FORMAT_AMRNB:
1491 open.read_format = AMRNB_FS;
1492 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301493 case FORMAT_AMRWB:
1494 open.read_format = AMRWB_FS;
1495 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001496 default:
1497 pr_err("Invalid format[%d]\n", rd_format);
1498 goto fail_cmd;
1499 }
1500 pr_debug("%s:rdformat[0x%x]wrformat[0x%x]\n", __func__,
1501 open.read_format, open.write_format);
1502
1503 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1504 if (rc < 0) {
1505 pr_err("open failed op[0x%x]rc[%d]\n", \
1506 open.hdr.opcode, rc);
1507 goto fail_cmd;
1508 }
1509 rc = wait_event_timeout(ac->cmd_wait,
1510 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1511 if (!rc) {
1512 pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc);
1513 goto fail_cmd;
1514 }
1515 return 0;
1516fail_cmd:
1517 return -EINVAL;
1518}
1519
1520int q6asm_run(struct audio_client *ac, uint32_t flags,
1521 uint32_t msw_ts, uint32_t lsw_ts)
1522{
1523 struct asm_stream_cmd_run run;
1524 int rc;
1525 if (!ac || ac->apr == NULL) {
1526 pr_err("APR handle NULL\n");
1527 return -EINVAL;
1528 }
1529 pr_debug("%s session[%d]", __func__, ac->session);
1530 q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
1531
1532 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1533 run.flags = flags;
1534 run.msw_ts = msw_ts;
1535 run.lsw_ts = lsw_ts;
Rajesha Kini3498c932011-07-19 19:58:27 +05301536#ifdef CONFIG_DEBUG_FS
1537 if (out_enable_flag) {
1538 do_gettimeofday(&out_cold_tv);
1539 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",\
1540 out_cold_tv.tv_sec, out_cold_tv.tv_usec);
1541 }
1542#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001543 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1544 if (rc < 0) {
1545 pr_err("Commmand run failed[%d]", rc);
1546 goto fail_cmd;
1547 }
1548
1549 rc = wait_event_timeout(ac->cmd_wait,
1550 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1551 if (!rc) {
1552 pr_err("timeout. waited for run success rc[%d]", rc);
1553 goto fail_cmd;
1554 }
1555
1556 return 0;
1557fail_cmd:
1558 return -EINVAL;
1559}
1560
1561int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
1562 uint32_t msw_ts, uint32_t lsw_ts)
1563{
1564 struct asm_stream_cmd_run run;
1565 int rc;
1566 if (!ac || ac->apr == NULL) {
1567 pr_err("%s:APR handle NULL\n", __func__);
1568 return -EINVAL;
1569 }
1570 pr_debug("session[%d]", ac->session);
1571 q6asm_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE);
1572
1573 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1574 run.flags = flags;
1575 run.msw_ts = msw_ts;
1576 run.lsw_ts = lsw_ts;
1577
1578 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1579 if (rc < 0) {
1580 pr_err("%s:Commmand run failed[%d]", __func__, rc);
1581 return -EINVAL;
1582 }
1583 return 0;
1584}
1585
1586
1587int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
1588 uint32_t frames_per_buf,
1589 uint32_t sample_rate, uint32_t channels,
1590 uint32_t bit_rate, uint32_t mode, uint32_t format)
1591{
1592 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1593 int rc = 0;
1594
1595 pr_debug("%s:session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d]"
1596 "format[%d]", __func__, ac->session, frames_per_buf,
1597 sample_rate, channels, bit_rate, mode, format);
1598
1599 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1600
1601 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1602 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1603 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1604 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1605 enc_cfg.enc_blk.format_id = MPEG4_AAC;
1606 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_aac_read_cfg);
1607 enc_cfg.enc_blk.cfg.aac.bitrate = bit_rate;
1608 enc_cfg.enc_blk.cfg.aac.enc_mode = mode;
1609 enc_cfg.enc_blk.cfg.aac.format = format;
1610 enc_cfg.enc_blk.cfg.aac.ch_cfg = channels;
1611 enc_cfg.enc_blk.cfg.aac.sample_rate = sample_rate;
1612
1613 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1614 if (rc < 0) {
1615 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1616 rc = -EINVAL;
1617 goto fail_cmd;
1618 }
1619 rc = wait_event_timeout(ac->cmd_wait,
1620 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1621 if (!rc) {
1622 pr_err("timeout. waited for FORMAT_UPDATE\n");
1623 goto fail_cmd;
1624 }
1625 return 0;
1626fail_cmd:
1627 return -EINVAL;
1628}
1629
1630int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
1631 uint32_t rate, uint32_t channels)
1632{
1633 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1634
1635 int rc = 0;
1636
1637 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1638 ac->session, rate, channels);
1639
1640 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1641
1642 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1643 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1644 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1645 enc_cfg.enc_blk.frames_per_buf = 1;
1646 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1647 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1648 enc_cfg.enc_blk.cfg.pcm.ch_cfg = channels;
1649 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1650 enc_cfg.enc_blk.cfg.pcm.sample_rate = rate;
1651 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1652 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1653
1654 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1655 if (rc < 0) {
1656 pr_err("Comamnd open failed\n");
1657 rc = -EINVAL;
1658 goto fail_cmd;
1659 }
1660 rc = wait_event_timeout(ac->cmd_wait,
1661 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1662 if (!rc) {
1663 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1664 goto fail_cmd;
1665 }
1666 return 0;
1667fail_cmd:
1668 return -EINVAL;
1669}
1670
Mingming Yin647e9ea2012-03-17 19:56:10 -07001671int q6asm_enc_cfg_blk_multi_ch_pcm(struct audio_client *ac,
1672 uint32_t rate, uint32_t channels)
1673{
1674 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1675
1676 int rc = 0;
1677
1678 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1679 ac->session, rate, channels);
1680
1681 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1682
1683 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1684 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1685 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1686 enc_cfg.enc_blk.frames_per_buf = 1;
1687 enc_cfg.enc_blk.format_id = MULTI_CHANNEL_PCM;
1688 enc_cfg.enc_blk.cfg_size =
1689 sizeof(struct asm_multi_channel_pcm_fmt_blk);
1690 enc_cfg.enc_blk.cfg.mpcm.num_channels = channels;
1691 enc_cfg.enc_blk.cfg.mpcm.bits_per_sample = 16;
1692 enc_cfg.enc_blk.cfg.mpcm.sample_rate = rate;
1693 enc_cfg.enc_blk.cfg.mpcm.is_signed = 1;
1694 enc_cfg.enc_blk.cfg.mpcm.is_interleaved = 1;
1695 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1696 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1697 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_RB;
1698 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_LB;
1699 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1700 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1701 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1702 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1703
1704 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1705 if (rc < 0) {
1706 pr_err("Comamnd open failed\n");
1707 rc = -EINVAL;
1708 goto fail_cmd;
1709 }
1710 rc = wait_event_timeout(ac->cmd_wait,
1711 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1712 if (!rc) {
1713 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1714 goto fail_cmd;
1715 }
1716 return 0;
1717fail_cmd:
1718 return -EINVAL;
1719}
1720
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001721int q6asm_enable_sbrps(struct audio_client *ac,
1722 uint32_t sbr_ps_enable)
1723{
1724 struct asm_stream_cmd_encdec_sbr sbrps;
1725
1726 int rc = 0;
1727
1728 pr_debug("%s: Session %d\n", __func__, ac->session);
1729
1730 q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
1731
1732 sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1733 sbrps.param_id = ASM_ENABLE_SBR_PS;
1734 sbrps.param_size = sizeof(struct asm_sbr_ps);
1735 sbrps.sbr_ps.enable = sbr_ps_enable;
1736
1737 rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
1738 if (rc < 0) {
1739 pr_err("Command opcode[0x%x]paramid[0x%x] failed\n",
1740 ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1741 ASM_ENABLE_SBR_PS);
1742 rc = -EINVAL;
1743 goto fail_cmd;
1744 }
1745 rc = wait_event_timeout(ac->cmd_wait,
1746 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1747 if (!rc) {
1748 pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode);
1749 goto fail_cmd;
1750 }
1751 return 0;
1752fail_cmd:
1753 return -EINVAL;
1754}
1755
Swaminathan Sathappan70765cd2011-07-19 18:42:47 -07001756int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
1757 uint16_t sce_left, uint16_t sce_right)
1758{
1759 struct asm_stream_cmd_encdec_dualmono dual_mono;
1760
1761 int rc = 0;
1762
1763 pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
1764 __func__, ac->session, sce_left, sce_right);
1765
1766 q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
1767
1768 dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1769 dual_mono.param_id = ASM_CONFIGURE_DUAL_MONO;
1770 dual_mono.param_size = sizeof(struct asm_dual_mono);
1771 dual_mono.channel_map.sce_left = sce_left;
1772 dual_mono.channel_map.sce_right = sce_right;
1773
1774 rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
1775 if (rc < 0) {
1776 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
1777 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1778 ASM_CONFIGURE_DUAL_MONO);
1779 rc = -EINVAL;
1780 goto fail_cmd;
1781 }
1782 rc = wait_event_timeout(ac->cmd_wait,
1783 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1784 if (!rc) {
1785 pr_err("%s:timeout opcode[0x%x]\n", __func__,
1786 dual_mono.hdr.opcode);
1787 goto fail_cmd;
1788 }
1789 return 0;
1790fail_cmd:
1791 return -EINVAL;
1792}
1793
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001794int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
1795 uint16_t min_rate, uint16_t max_rate,
1796 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
1797{
1798 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1799 int rc = 0;
1800
1801 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] \
1802 reduced_rate_level[0x%4x]rate_modulation_cmd[0x%4x]", __func__,
1803 ac->session, frames_per_buf, min_rate, max_rate,
1804 reduced_rate_level, rate_modulation_cmd);
1805
1806 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1807
1808 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1809
1810 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1811 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1812
1813 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1814 enc_cfg.enc_blk.format_id = V13K_FS;
1815 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg);
1816 enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate;
1817 enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate;
1818 enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level;
1819 enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_cmd = rate_modulation_cmd;
1820
1821 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1822 if (rc < 0) {
1823 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1824 goto fail_cmd;
1825 }
1826 rc = wait_event_timeout(ac->cmd_wait,
1827 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1828 if (!rc) {
1829 pr_err("timeout. waited for FORMAT_UPDATE\n");
1830 goto fail_cmd;
1831 }
1832 return 0;
1833fail_cmd:
1834 return -EINVAL;
1835}
1836
1837int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
1838 uint16_t min_rate, uint16_t max_rate,
1839 uint16_t rate_modulation_cmd)
1840{
1841 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1842 int rc = 0;
1843
1844 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] \
1845 rate_modulation_cmd[0x%4x]", __func__, ac->session,
1846 frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
1847
1848 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1849
1850 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1851
1852 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1853 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1854
1855 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1856 enc_cfg.enc_blk.format_id = EVRC_FS;
1857 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg);
1858 enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate;
1859 enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate;
1860 enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd;
1861 enc_cfg.enc_blk.cfg.evrc.reserved = 0;
1862
1863 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1864 if (rc < 0) {
1865 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1866 goto fail_cmd;
1867 }
1868 rc = wait_event_timeout(ac->cmd_wait,
1869 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1870 if (!rc) {
1871 pr_err("timeout. waited for FORMAT_UPDATE\n");
1872 goto fail_cmd;
1873 }
1874 return 0;
1875fail_cmd:
1876 return -EINVAL;
1877}
1878
1879int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
1880 uint16_t band_mode, uint16_t dtx_enable)
1881{
1882 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1883 int rc = 0;
1884
1885 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
1886 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
1887
1888 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1889
1890 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1891
1892 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1893 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1894
1895 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1896 enc_cfg.enc_blk.format_id = AMRNB_FS;
1897 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg);
1898 enc_cfg.enc_blk.cfg.amrnb.mode = band_mode;
1899 enc_cfg.enc_blk.cfg.amrnb.dtx_mode = dtx_enable;
1900
1901 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1902 if (rc < 0) {
1903 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1904 goto fail_cmd;
1905 }
1906 rc = wait_event_timeout(ac->cmd_wait,
1907 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1908 if (!rc) {
1909 pr_err("timeout. waited for FORMAT_UPDATE\n");
1910 goto fail_cmd;
1911 }
1912 return 0;
1913fail_cmd:
1914 return -EINVAL;
1915}
1916
Alex Wong2caeecc2011-10-28 10:52:15 +05301917int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
1918 uint16_t band_mode, uint16_t dtx_enable)
1919{
1920 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1921 int rc = 0;
1922
1923 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
1924 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
1925
1926 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1927
1928 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1929
1930 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1931 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1932
1933 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1934 enc_cfg.enc_blk.format_id = AMRWB_FS;
1935 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrwb_read_cfg);
1936 enc_cfg.enc_blk.cfg.amrwb.mode = band_mode;
1937 enc_cfg.enc_blk.cfg.amrwb.dtx_mode = dtx_enable;
1938
1939 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1940 if (rc < 0) {
1941 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1942 goto fail_cmd;
1943 }
1944 rc = wait_event_timeout(ac->cmd_wait,
1945 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1946 if (!rc) {
1947 pr_err("timeout. waited for FORMAT_UPDATE\n");
1948 goto fail_cmd;
1949 }
1950 return 0;
1951fail_cmd:
1952 return -EINVAL;
1953}
1954
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001955int q6asm_media_format_block_pcm(struct audio_client *ac,
1956 uint32_t rate, uint32_t channels)
1957{
1958 struct asm_stream_media_format_update fmt;
1959 int rc = 0;
1960
1961 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
1962 channels);
1963
1964 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
1965
1966 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
1967
1968 fmt.format = LINEAR_PCM;
1969 fmt.cfg_size = sizeof(struct asm_pcm_cfg);
1970 fmt.write_cfg.pcm_cfg.ch_cfg = channels;
1971 fmt.write_cfg.pcm_cfg.bits_per_sample = 16;
1972 fmt.write_cfg.pcm_cfg.sample_rate = rate;
1973 fmt.write_cfg.pcm_cfg.is_signed = 1;
1974 fmt.write_cfg.pcm_cfg.interleaved = 1;
1975
1976 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
1977 if (rc < 0) {
1978 pr_err("%s:Comamnd open failed\n", __func__);
1979 goto fail_cmd;
1980 }
1981 rc = wait_event_timeout(ac->cmd_wait,
1982 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1983 if (!rc) {
1984 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
1985 goto fail_cmd;
1986 }
1987 return 0;
1988fail_cmd:
1989 return -EINVAL;
1990}
1991
Kiran Kandi5e809b02012-01-31 00:24:33 -08001992int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
1993 uint32_t rate, uint32_t channels)
1994{
1995 struct asm_stream_media_format_update fmt;
1996 u8 *channel_mapping;
1997 int rc = 0;
1998
1999 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2000 channels);
2001
2002 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2003
2004 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2005
2006 fmt.format = MULTI_CHANNEL_PCM;
2007 fmt.cfg_size = sizeof(struct asm_multi_channel_pcm_fmt_blk);
2008 fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels;
2009 fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = 16;
2010 fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate;
2011 fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1;
2012 fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1;
2013 channel_mapping =
2014 fmt.write_cfg.multi_ch_pcm_cfg.channel_mapping;
2015
2016 memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
2017
2018 if (channels == 1) {
2019 channel_mapping[0] = PCM_CHANNEL_FL;
2020 } else if (channels == 2) {
2021 channel_mapping[0] = PCM_CHANNEL_FL;
2022 channel_mapping[1] = PCM_CHANNEL_FR;
2023 } else if (channels == 6) {
2024 channel_mapping[0] = PCM_CHANNEL_FC;
2025 channel_mapping[1] = PCM_CHANNEL_FL;
2026 channel_mapping[2] = PCM_CHANNEL_FR;
2027 channel_mapping[3] = PCM_CHANNEL_LB;
2028 channel_mapping[4] = PCM_CHANNEL_RB;
2029 channel_mapping[5] = PCM_CHANNEL_LFE;
2030 } else {
2031 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2032 channels);
2033 return -EINVAL;
2034 }
2035
2036 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2037 if (rc < 0) {
2038 pr_err("%s:Comamnd open failed\n", __func__);
2039 goto fail_cmd;
2040 }
2041 rc = wait_event_timeout(ac->cmd_wait,
2042 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2043 if (!rc) {
2044 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2045 goto fail_cmd;
2046 }
2047 return 0;
2048fail_cmd:
2049 return -EINVAL;
2050}
2051
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002052int q6asm_media_format_block_aac(struct audio_client *ac,
2053 struct asm_aac_cfg *cfg)
2054{
2055 struct asm_stream_media_format_update fmt;
2056 int rc = 0;
2057
2058 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2059 cfg->sample_rate, cfg->ch_cfg);
2060
2061 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2062
2063 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2064
2065 fmt.format = MPEG4_AAC;
2066 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2067 fmt.write_cfg.aac_cfg.format = cfg->format;
2068 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2069 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2070 fmt.write_cfg.aac_cfg.section_data_resilience =
2071 cfg->section_data_resilience;
2072 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2073 cfg->scalefactor_data_resilience;
2074 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2075 cfg->spectral_data_resilience;
2076 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2077 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2078 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2079 __func__, fmt.format, fmt.cfg_size,
2080 fmt.write_cfg.aac_cfg.format,
2081 fmt.write_cfg.aac_cfg.aot,
2082 fmt.write_cfg.aac_cfg.ch_cfg,
2083 fmt.write_cfg.aac_cfg.sample_rate);
2084 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2085 if (rc < 0) {
2086 pr_err("%s:Comamnd open failed\n", __func__);
2087 goto fail_cmd;
2088 }
2089 rc = wait_event_timeout(ac->cmd_wait,
2090 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2091 if (!rc) {
2092 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2093 goto fail_cmd;
2094 }
2095 return 0;
2096fail_cmd:
2097 return -EINVAL;
2098}
2099
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002100
2101int q6asm_media_format_block_multi_aac(struct audio_client *ac,
2102 struct asm_aac_cfg *cfg)
2103{
2104 struct asm_stream_media_format_update fmt;
2105 int rc = 0;
2106
2107 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2108 cfg->sample_rate, cfg->ch_cfg);
2109
2110 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2111
2112 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2113
2114 fmt.format = MPEG4_MULTI_AAC;
2115 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2116 fmt.write_cfg.aac_cfg.format = cfg->format;
2117 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2118 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2119 fmt.write_cfg.aac_cfg.section_data_resilience =
2120 cfg->section_data_resilience;
2121 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2122 cfg->scalefactor_data_resilience;
2123 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2124 cfg->spectral_data_resilience;
2125 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2126 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2127 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2128 __func__, fmt.format, fmt.cfg_size,
2129 fmt.write_cfg.aac_cfg.format,
2130 fmt.write_cfg.aac_cfg.aot,
2131 fmt.write_cfg.aac_cfg.ch_cfg,
2132 fmt.write_cfg.aac_cfg.sample_rate);
2133 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2134 if (rc < 0) {
2135 pr_err("%s:Comamnd open failed\n", __func__);
2136 goto fail_cmd;
2137 }
2138 rc = wait_event_timeout(ac->cmd_wait,
2139 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2140 if (!rc) {
2141 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2142 goto fail_cmd;
2143 }
2144 return 0;
2145fail_cmd:
2146 return -EINVAL;
2147}
2148
2149
Alex Wong2caeecc2011-10-28 10:52:15 +05302150
2151int q6asm_media_format_block(struct audio_client *ac, uint32_t format)
2152{
2153
2154 struct asm_stream_media_format_update fmt;
2155 int rc = 0;
2156
2157 pr_debug("%s:session[%d] format[0x%x]\n", __func__,
2158 ac->session, format);
2159
2160 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2161 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302162 switch (format) {
2163 case FORMAT_V13K:
2164 fmt.format = V13K_FS;
2165 break;
2166 case FORMAT_EVRC:
2167 fmt.format = EVRC_FS;
2168 break;
2169 case FORMAT_AMRWB:
2170 fmt.format = AMRWB_FS;
2171 break;
2172 case FORMAT_AMRNB:
2173 fmt.format = AMRNB_FS;
2174 break;
2175 case FORMAT_MP3:
2176 fmt.format = MP3;
2177 break;
2178 default:
2179 pr_err("Invalid format[%d]\n", format);
2180 goto fail_cmd;
2181 }
Alex Wong2caeecc2011-10-28 10:52:15 +05302182 fmt.cfg_size = 0;
2183
2184 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2185 if (rc < 0) {
2186 pr_err("%s:Comamnd open failed\n", __func__);
2187 goto fail_cmd;
2188 }
2189 rc = wait_event_timeout(ac->cmd_wait,
2190 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2191 if (!rc) {
2192 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2193 goto fail_cmd;
2194 }
2195 return 0;
2196fail_cmd:
2197 return -EINVAL;
2198}
2199
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002200int q6asm_media_format_block_wma(struct audio_client *ac,
2201 void *cfg)
2202{
2203 struct asm_stream_media_format_update fmt;
2204 struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
2205 int rc = 0;
2206
2207 pr_debug("session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d],\
2208 balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x]\n",
2209 ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
2210 wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
2211 wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
2212 wma_cfg->ch_mask, wma_cfg->encode_opt);
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_V9;
2219 fmt.cfg_size = sizeof(struct asm_wma_cfg);
2220 fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag;
2221 fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg;
2222 fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate;
2223 fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
2224 fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align;
2225 fmt.write_cfg.wma_cfg.valid_bits_per_sample =
2226 wma_cfg->valid_bits_per_sample;
2227 fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask;
2228 fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt;
2229 fmt.write_cfg.wma_cfg.adv_encode_opt = 0;
2230 fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0;
2231 fmt.write_cfg.wma_cfg.drc_peak_ref = 0;
2232 fmt.write_cfg.wma_cfg.drc_peak_target = 0;
2233 fmt.write_cfg.wma_cfg.drc_ave_ref = 0;
2234 fmt.write_cfg.wma_cfg.drc_ave_target = 0;
2235
2236 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2237 if (rc < 0) {
2238 pr_err("%s:Comamnd open failed\n", __func__);
2239 goto fail_cmd;
2240 }
2241 rc = wait_event_timeout(ac->cmd_wait,
2242 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2243 if (!rc) {
2244 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2245 goto fail_cmd;
2246 }
2247 return 0;
2248fail_cmd:
2249 return -EINVAL;
2250}
2251
2252int q6asm_media_format_block_wmapro(struct audio_client *ac,
2253 void *cfg)
2254{
2255 struct asm_stream_media_format_update fmt;
2256 struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
2257 int rc = 0;
2258
2259 pr_debug("session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d],"
2260 "balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x],\
2261 adv_enc_opt[0x%4x], adv_enc_opt2[0x%8x]\n",
2262 ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
2263 wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
2264 wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
2265 wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
2266 wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
2267
2268 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2269
2270 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2271
2272 fmt.format = WMA_V10PRO;
2273 fmt.cfg_size = sizeof(struct asm_wmapro_cfg);
2274 fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag;
2275 fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg;
2276 fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate;
2277 fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec =
2278 wmapro_cfg->avg_bytes_per_sec;
2279 fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align;
2280 fmt.write_cfg.wmapro_cfg.valid_bits_per_sample =
2281 wmapro_cfg->valid_bits_per_sample;
2282 fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask;
2283 fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt;
2284 fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt;
2285 fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2;
2286 fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0;
2287 fmt.write_cfg.wmapro_cfg.drc_peak_target = 0;
2288 fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0;
2289 fmt.write_cfg.wmapro_cfg.drc_ave_target = 0;
2290
2291 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2292 if (rc < 0) {
2293 pr_err("%s:Comamnd open failed\n", __func__);
2294 goto fail_cmd;
2295 }
2296 rc = wait_event_timeout(ac->cmd_wait,
2297 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2298 if (!rc) {
2299 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2300 goto fail_cmd;
2301 }
2302 return 0;
2303fail_cmd:
2304 return -EINVAL;
2305}
2306
2307int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
2308 uint32_t bufsz, uint32_t bufcnt)
2309{
2310 struct asm_stream_cmd_memory_map mem_map;
2311 int rc = 0;
2312
2313 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2314 pr_err("APR handle NULL\n");
2315 return -EINVAL;
2316 }
2317
2318 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2319
2320 mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP;
2321
2322 mem_map.buf_add = buf_add;
2323 mem_map.buf_size = bufsz * bufcnt;
2324 mem_map.mempool_id = 0; /* EBI */
2325 mem_map.reserved = 0;
2326
2327 q6asm_add_mmaphdr(&mem_map.hdr,
2328 sizeof(struct asm_stream_cmd_memory_map), TRUE);
2329
2330 pr_debug("buf add[%x] buf_add_parameter[%x]\n",
2331 mem_map.buf_add, buf_add);
2332
2333 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map);
2334 if (rc < 0) {
2335 pr_err("mem_map op[0x%x]rc[%d]\n",
2336 mem_map.hdr.opcode, rc);
2337 rc = -EINVAL;
2338 goto fail_cmd;
2339 }
2340
2341 rc = wait_event_timeout(this_mmap.cmd_wait,
2342 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2343 if (!rc) {
2344 pr_err("timeout. waited for memory_map\n");
2345 rc = -EINVAL;
2346 goto fail_cmd;
2347 }
2348 rc = 0;
2349fail_cmd:
2350 return rc;
2351}
2352
2353int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
2354{
2355 struct asm_stream_cmd_memory_unmap mem_unmap;
2356 int rc = 0;
2357
2358 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2359 pr_err("APR handle NULL\n");
2360 return -EINVAL;
2361 }
2362 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2363
2364 q6asm_add_mmaphdr(&mem_unmap.hdr,
2365 sizeof(struct asm_stream_cmd_memory_unmap), TRUE);
2366 mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP;
2367 mem_unmap.buf_add = buf_add;
2368
2369 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_unmap);
2370 if (rc < 0) {
2371 pr_err("mem_unmap op[0x%x]rc[%d]\n",
2372 mem_unmap.hdr.opcode, rc);
2373 rc = -EINVAL;
2374 goto fail_cmd;
2375 }
2376
2377 rc = wait_event_timeout(this_mmap.cmd_wait,
2378 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2379 if (!rc) {
2380 pr_err("timeout. waited for memory_map\n");
2381 rc = -EINVAL;
2382 goto fail_cmd;
2383 }
2384 rc = 0;
2385fail_cmd:
2386 return rc;
2387}
2388
2389int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
2390{
2391 void *vol_cmd = NULL;
2392 void *payload = NULL;
2393 struct asm_pp_params_command *cmd = NULL;
2394 struct asm_lrchannel_gain_params *lrgain = NULL;
2395 int sz = 0;
2396 int rc = 0;
2397
2398 sz = sizeof(struct asm_pp_params_command) +
2399 + sizeof(struct asm_lrchannel_gain_params);
2400 vol_cmd = kzalloc(sz, GFP_KERNEL);
2401 if (vol_cmd == NULL) {
2402 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2403 rc = -EINVAL;
2404 return rc;
2405 }
2406 cmd = (struct asm_pp_params_command *)vol_cmd;
2407 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2408 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2409 cmd->payload = NULL;
2410 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2411 sizeof(struct asm_lrchannel_gain_params);
2412 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2413 cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID;
2414 cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params);
2415 cmd->params.reserved = 0;
2416
2417 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2418 lrgain = (struct asm_lrchannel_gain_params *)payload;
2419
2420 lrgain->left_gain = left_gain;
2421 lrgain->right_gain = right_gain;
2422 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2423 if (rc < 0) {
2424 pr_err("%s: Volume Command failed\n", __func__);
2425 rc = -EINVAL;
2426 goto fail_cmd;
2427 }
2428
2429 rc = wait_event_timeout(ac->cmd_wait,
2430 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2431 if (!rc) {
2432 pr_err("%s: timeout in sending volume command to apr\n",
2433 __func__);
2434 rc = -EINVAL;
2435 goto fail_cmd;
2436 }
2437 rc = 0;
2438fail_cmd:
2439 kfree(vol_cmd);
2440 return rc;
2441}
2442
2443static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
2444 uint32_t bufsz, uint32_t bufcnt)
2445{
2446 struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL;
2447 struct asm_memory_map_regions *mregions = NULL;
2448 struct audio_port_data *port = NULL;
2449 struct audio_buffer *ab = NULL;
2450 void *mmap_region_cmd = NULL;
2451 void *payload = NULL;
2452 int rc = 0;
2453 int i = 0;
2454 int cmd_size = 0;
2455
2456 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2457 pr_err("APR handle NULL\n");
2458 return -EINVAL;
2459 }
2460 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2461
2462 cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions)
2463 + sizeof(struct asm_memory_map_regions) * bufcnt;
2464
2465 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302466 if (mmap_region_cmd == NULL) {
2467 pr_err("%s: Mem alloc failed\n", __func__);
2468 rc = -EINVAL;
2469 return rc;
2470 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002471 mmap_regions = (struct asm_stream_cmd_memory_map_regions *)
2472 mmap_region_cmd;
2473 q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE);
2474 mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS;
2475 mmap_regions->mempool_id = 0;
2476 mmap_regions->nregions = bufcnt & 0x00ff;
2477 pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions);
2478 payload = ((u8 *) mmap_region_cmd +
2479 sizeof(struct asm_stream_cmd_memory_map_regions));
2480 mregions = (struct asm_memory_map_regions *)payload;
2481
2482 port = &ac->port[dir];
2483 for (i = 0; i < bufcnt; i++) {
2484 ab = &port->buf[i];
2485 mregions->phys = ab->phys;
2486 mregions->buf_size = ab->size;
2487 ++mregions;
2488 }
2489
2490 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) mmap_region_cmd);
2491 if (rc < 0) {
2492 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2493 mmap_regions->hdr.opcode, rc);
2494 rc = -EINVAL;
2495 goto fail_cmd;
2496 }
2497
2498 rc = wait_event_timeout(this_mmap.cmd_wait,
2499 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2500 if (!rc) {
2501 pr_err("timeout. waited for memory_map\n");
2502 rc = -EINVAL;
2503 goto fail_cmd;
2504 }
2505 rc = 0;
2506fail_cmd:
2507 kfree(mmap_region_cmd);
2508 return rc;
2509}
2510
2511static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
2512 uint32_t bufsz, uint32_t bufcnt)
2513{
2514 struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL;
2515 struct asm_memory_unmap_regions *mregions = NULL;
2516 struct audio_port_data *port = NULL;
2517 struct audio_buffer *ab = NULL;
2518 void *unmap_region_cmd = NULL;
2519 void *payload = NULL;
2520 int rc = 0;
2521 int i = 0;
2522 int cmd_size = 0;
2523
2524 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2525 pr_err("APR handle NULL\n");
2526 return -EINVAL;
2527 }
2528 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2529
2530 cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) +
2531 sizeof(struct asm_memory_unmap_regions) * bufcnt;
2532
2533 unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302534 if (unmap_region_cmd == NULL) {
2535 pr_err("%s: Mem alloc failed\n", __func__);
2536 rc = -EINVAL;
2537 return rc;
2538 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002539 unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *)
2540 unmap_region_cmd;
2541 q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE);
2542 unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS;
2543 unmap_regions->nregions = bufcnt & 0x00ff;
2544 pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions);
2545 payload = ((u8 *) unmap_region_cmd +
2546 sizeof(struct asm_stream_cmd_memory_unmap_regions));
2547 mregions = (struct asm_memory_unmap_regions *)payload;
2548 port = &ac->port[dir];
2549 for (i = 0; i < bufcnt; i++) {
2550 ab = &port->buf[i];
2551 mregions->phys = ab->phys;
2552 ++mregions;
2553 }
2554
2555 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd);
2556 if (rc < 0) {
2557 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2558 unmap_regions->hdr.opcode, rc);
2559 goto fail_cmd;
2560 }
2561
2562 rc = wait_event_timeout(this_mmap.cmd_wait,
2563 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2564 if (!rc) {
2565 pr_err("timeout. waited for memory_unmap\n");
2566 goto fail_cmd;
2567 }
2568 rc = 0;
2569
2570fail_cmd:
2571 kfree(unmap_region_cmd);
2572 return rc;
2573}
2574
2575int q6asm_set_mute(struct audio_client *ac, int muteflag)
2576{
2577 void *vol_cmd = NULL;
2578 void *payload = NULL;
2579 struct asm_pp_params_command *cmd = NULL;
2580 struct asm_mute_params *mute = NULL;
2581 int sz = 0;
2582 int rc = 0;
2583
2584 sz = sizeof(struct asm_pp_params_command) +
2585 + sizeof(struct asm_mute_params);
2586 vol_cmd = kzalloc(sz, GFP_KERNEL);
2587 if (vol_cmd == NULL) {
2588 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2589 rc = -EINVAL;
2590 return rc;
2591 }
2592 cmd = (struct asm_pp_params_command *)vol_cmd;
2593 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2594 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2595 cmd->payload = NULL;
2596 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2597 sizeof(struct asm_mute_params);
2598 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2599 cmd->params.param_id = MUTE_CONFIG_PARAM_ID;
2600 cmd->params.param_size = sizeof(struct asm_mute_params);
2601 cmd->params.reserved = 0;
2602
2603 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2604 mute = (struct asm_mute_params *)payload;
2605
2606 mute->muteflag = muteflag;
2607 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2608 if (rc < 0) {
2609 pr_err("%s: Mute 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 mute 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_volume(struct audio_client *ac, int volume)
2629{
2630 void *vol_cmd = NULL;
2631 void *payload = NULL;
2632 struct asm_pp_params_command *cmd = NULL;
2633 struct asm_master_gain_params *mgain = NULL;
2634 int sz = 0;
2635 int rc = 0;
2636
2637 sz = sizeof(struct asm_pp_params_command) +
2638 + sizeof(struct asm_master_gain_params);
2639 vol_cmd = kzalloc(sz, GFP_KERNEL);
2640 if (vol_cmd == NULL) {
2641 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2642 rc = -EINVAL;
2643 return rc;
2644 }
2645 cmd = (struct asm_pp_params_command *)vol_cmd;
2646 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2647 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2648 cmd->payload = NULL;
2649 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2650 sizeof(struct asm_master_gain_params);
2651 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2652 cmd->params.param_id = MASTER_GAIN_PARAM_ID;
2653 cmd->params.param_size = sizeof(struct asm_master_gain_params);
2654 cmd->params.reserved = 0;
2655
2656 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2657 mgain = (struct asm_master_gain_params *)payload;
2658
2659 mgain->master_gain = volume;
2660 mgain->padding = 0x00;
2661 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2662 if (rc < 0) {
2663 pr_err("%s: Volume Command failed\n", __func__);
2664 rc = -EINVAL;
2665 goto fail_cmd;
2666 }
2667
2668 rc = wait_event_timeout(ac->cmd_wait,
2669 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2670 if (!rc) {
2671 pr_err("%s: timeout in sending volume command to apr\n",
2672 __func__);
2673 rc = -EINVAL;
2674 goto fail_cmd;
2675 }
2676 rc = 0;
2677fail_cmd:
2678 kfree(vol_cmd);
2679 return rc;
2680}
2681
2682int q6asm_set_softpause(struct audio_client *ac,
2683 struct asm_softpause_params *pause_param)
2684{
2685 void *vol_cmd = NULL;
2686 void *payload = NULL;
2687 struct asm_pp_params_command *cmd = NULL;
2688 struct asm_softpause_params *params = NULL;
2689 int sz = 0;
2690 int rc = 0;
2691
2692 sz = sizeof(struct asm_pp_params_command) +
2693 + sizeof(struct asm_softpause_params);
2694 vol_cmd = kzalloc(sz, GFP_KERNEL);
2695 if (vol_cmd == NULL) {
2696 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2697 rc = -EINVAL;
2698 return rc;
2699 }
2700 cmd = (struct asm_pp_params_command *)vol_cmd;
2701 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2702 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2703 cmd->payload = NULL;
2704 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2705 sizeof(struct asm_softpause_params);
2706 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2707 cmd->params.param_id = SOFT_PAUSE_PARAM_ID;
2708 cmd->params.param_size = sizeof(struct asm_softpause_params);
2709 cmd->params.reserved = 0;
2710
2711 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2712 params = (struct asm_softpause_params *)payload;
2713
2714 params->enable = pause_param->enable;
2715 params->period = pause_param->period;
2716 params->step = pause_param->step;
2717 params->rampingcurve = pause_param->rampingcurve;
2718 pr_debug("%s: soft Pause Command: enable = %d, period = %d,"
2719 "step = %d, curve = %d\n", __func__, params->enable,
2720 params->period, params->step, params->rampingcurve);
2721 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2722 if (rc < 0) {
2723 pr_err("%s: Volume Command(soft_pause) failed\n", __func__);
2724 rc = -EINVAL;
2725 goto fail_cmd;
2726 }
2727
2728 rc = wait_event_timeout(ac->cmd_wait,
2729 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2730 if (!rc) {
2731 pr_err("%s: timeout in sending volume command(soft_pause)"
2732 "to apr\n", __func__);
2733 rc = -EINVAL;
2734 goto fail_cmd;
2735 }
2736 rc = 0;
2737fail_cmd:
2738 kfree(vol_cmd);
2739 return rc;
2740}
2741
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07002742int q6asm_set_softvolume(struct audio_client *ac,
2743 struct asm_softvolume_params *softvol_param)
2744{
2745 void *vol_cmd = NULL;
2746 void *payload = NULL;
2747 struct asm_pp_params_command *cmd = NULL;
2748 struct asm_softvolume_params *params = NULL;
2749 int sz = 0;
2750 int rc = 0;
2751
2752 sz = sizeof(struct asm_pp_params_command) +
2753 + sizeof(struct asm_softvolume_params);
2754 vol_cmd = kzalloc(sz, GFP_KERNEL);
2755 if (vol_cmd == NULL) {
2756 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2757 rc = -EINVAL;
2758 return rc;
2759 }
2760 cmd = (struct asm_pp_params_command *)vol_cmd;
2761 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2762 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2763 cmd->payload = NULL;
2764 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2765 sizeof(struct asm_softvolume_params);
2766 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2767 cmd->params.param_id = SOFT_VOLUME_PARAM_ID;
2768 cmd->params.param_size = sizeof(struct asm_softvolume_params);
2769 cmd->params.reserved = 0;
2770
2771 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2772 params = (struct asm_softvolume_params *)payload;
2773
2774 params->period = softvol_param->period;
2775 params->step = softvol_param->step;
2776 params->rampingcurve = softvol_param->rampingcurve;
2777 pr_debug("%s: soft Volume:opcode = %d,payload_sz =%d,module_id =%d,"
2778 "param_id = %d, param_sz = %d\n", __func__,
2779 cmd->hdr.opcode, cmd->payload_size,
2780 cmd->params.module_id, cmd->params.param_id,
2781 cmd->params.param_size);
2782 pr_debug("%s: soft Volume Command: period = %d,"
2783 "step = %d, curve = %d\n", __func__, params->period,
2784 params->step, params->rampingcurve);
2785 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2786 if (rc < 0) {
2787 pr_err("%s: Volume Command(soft_volume) failed\n", __func__);
2788 rc = -EINVAL;
2789 goto fail_cmd;
2790 }
2791
2792 rc = wait_event_timeout(ac->cmd_wait,
2793 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2794 if (!rc) {
2795 pr_err("%s: timeout in sending volume command(soft_volume)"
2796 "to apr\n", __func__);
2797 rc = -EINVAL;
2798 goto fail_cmd;
2799 }
2800 rc = 0;
2801fail_cmd:
2802 kfree(vol_cmd);
2803 return rc;
2804}
2805
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002806int q6asm_equalizer(struct audio_client *ac, void *eq)
2807{
2808 void *eq_cmd = NULL;
2809 void *payload = NULL;
2810 struct asm_pp_params_command *cmd = NULL;
2811 struct asm_equalizer_params *equalizer = NULL;
2812 struct msm_audio_eq_stream_config *eq_params = NULL;
2813 int i = 0;
2814 int sz = 0;
2815 int rc = 0;
2816
2817 sz = sizeof(struct asm_pp_params_command) +
2818 + sizeof(struct asm_equalizer_params);
2819 eq_cmd = kzalloc(sz, GFP_KERNEL);
2820 if (eq_cmd == NULL) {
2821 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2822 rc = -EINVAL;
2823 goto fail_cmd;
2824 }
2825 eq_params = (struct msm_audio_eq_stream_config *) eq;
2826 cmd = (struct asm_pp_params_command *)eq_cmd;
2827 q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE);
2828 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2829 cmd->payload = NULL;
2830 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2831 sizeof(struct asm_equalizer_params);
2832 cmd->params.module_id = EQUALIZER_MODULE_ID;
2833 cmd->params.param_id = EQUALIZER_PARAM_ID;
2834 cmd->params.param_size = sizeof(struct asm_equalizer_params);
2835 cmd->params.reserved = 0;
2836 payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command));
2837 equalizer = (struct asm_equalizer_params *)payload;
2838
2839 equalizer->enable = eq_params->enable;
2840 equalizer->num_bands = eq_params->num_bands;
2841 pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
2842 eq_params->num_bands);
2843 for (i = 0; i < eq_params->num_bands; i++) {
2844 equalizer->eq_bands[i].band_idx =
2845 eq_params->eq_bands[i].band_idx;
2846 equalizer->eq_bands[i].filter_type =
2847 eq_params->eq_bands[i].filter_type;
2848 equalizer->eq_bands[i].center_freq_hz =
2849 eq_params->eq_bands[i].center_freq_hz;
2850 equalizer->eq_bands[i].filter_gain =
2851 eq_params->eq_bands[i].filter_gain;
2852 equalizer->eq_bands[i].q_factor =
2853 eq_params->eq_bands[i].q_factor;
2854 pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
2855 eq_params->eq_bands[i].filter_type, i);
2856 pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
2857 eq_params->eq_bands[i].center_freq_hz, i);
2858 pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
2859 eq_params->eq_bands[i].filter_gain, i);
2860 pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
2861 eq_params->eq_bands[i].q_factor, i);
2862 }
2863 rc = apr_send_pkt(ac->apr, (uint32_t *) eq_cmd);
2864 if (rc < 0) {
2865 pr_err("%s: Equalizer Command failed\n", __func__);
2866 rc = -EINVAL;
2867 goto fail_cmd;
2868 }
2869
2870 rc = wait_event_timeout(ac->cmd_wait,
2871 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2872 if (!rc) {
2873 pr_err("%s: timeout in sending equalizer command to apr\n",
2874 __func__);
2875 rc = -EINVAL;
2876 goto fail_cmd;
2877 }
2878 rc = 0;
2879fail_cmd:
2880 kfree(eq_cmd);
2881 return rc;
2882}
2883
2884int q6asm_read(struct audio_client *ac)
2885{
2886 struct asm_stream_cmd_read read;
2887 struct audio_buffer *ab;
2888 int dsp_buf;
2889 struct audio_port_data *port;
2890 int rc;
2891 if (!ac || ac->apr == NULL) {
2892 pr_err("APR handle NULL\n");
2893 return -EINVAL;
2894 }
2895 if (ac->io_mode == SYNC_IO_MODE) {
2896 port = &ac->port[OUT];
2897
2898 q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
2899
2900 mutex_lock(&port->lock);
2901
2902 dsp_buf = port->dsp_buf;
2903 ab = &port->buf[dsp_buf];
2904
2905 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
2906 __func__,
2907 ac->session,
2908 dsp_buf,
2909 (void *)port->buf[dsp_buf].data,
2910 port->cpu_buf,
2911 (void *)port->buf[port->cpu_buf].phys);
2912
2913 read.hdr.opcode = ASM_DATA_CMD_READ;
2914 read.buf_add = ab->phys;
2915 read.buf_size = ab->size;
2916 read.uid = port->dsp_buf;
2917 read.hdr.token = port->dsp_buf;
2918
2919 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
2920 mutex_unlock(&port->lock);
2921 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
2922 read.buf_add,
2923 read.hdr.token,
2924 read.uid);
2925 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
2926 if (rc < 0) {
2927 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
2928 goto fail_cmd;
2929 }
2930 return 0;
2931 }
2932fail_cmd:
2933 return -EINVAL;
2934}
2935
2936int q6asm_read_nolock(struct audio_client *ac)
2937{
2938 struct asm_stream_cmd_read read;
2939 struct audio_buffer *ab;
2940 int dsp_buf;
2941 struct audio_port_data *port;
2942 int rc;
2943 if (!ac || ac->apr == NULL) {
2944 pr_err("APR handle NULL\n");
2945 return -EINVAL;
2946 }
2947 if (ac->io_mode == SYNC_IO_MODE) {
2948 port = &ac->port[OUT];
2949
2950 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
2951
2952
2953 dsp_buf = port->dsp_buf;
2954 ab = &port->buf[dsp_buf];
2955
2956 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
2957 __func__,
2958 ac->session,
2959 dsp_buf,
2960 (void *)port->buf[dsp_buf].data,
2961 port->cpu_buf,
2962 (void *)port->buf[port->cpu_buf].phys);
2963
2964 read.hdr.opcode = ASM_DATA_CMD_READ;
2965 read.buf_add = ab->phys;
2966 read.buf_size = ab->size;
2967 read.uid = port->dsp_buf;
2968 read.hdr.token = port->dsp_buf;
2969
2970 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
2971 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
2972 read.buf_add,
2973 read.hdr.token,
2974 read.uid);
2975 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
2976 if (rc < 0) {
2977 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
2978 goto fail_cmd;
2979 }
2980 return 0;
2981 }
2982fail_cmd:
2983 return -EINVAL;
2984}
2985
2986
2987static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
2988 uint32_t pkt_size, uint32_t cmd_flg)
2989{
2990 pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg,
2991 ac->session);
2992 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
2993 APR_HDR_LEN(sizeof(struct apr_hdr)),\
2994 APR_PKT_VER);
2995 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
2996 hdr->src_domain = APR_DOMAIN_APPS;
2997 hdr->dest_svc = APR_SVC_ASM;
2998 hdr->dest_domain = APR_DOMAIN_ADSP;
2999 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
3000 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
3001 if (cmd_flg) {
3002 hdr->token = ac->session;
3003 atomic_set(&ac->cmd_state, 1);
3004 }
3005 hdr->pkt_size = pkt_size;
3006 return;
3007}
3008
3009int q6asm_async_write(struct audio_client *ac,
3010 struct audio_aio_write_param *param)
3011{
3012 int rc = 0;
3013 struct asm_stream_cmd_write write;
3014
3015 if (!ac || ac->apr == NULL) {
3016 pr_err("%s: APR handle NULL\n", __func__);
3017 return -EINVAL;
3018 }
3019
3020 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE);
3021
3022 /* Pass physical address as token for AIO scheme */
3023 write.hdr.token = param->uid;
3024 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3025 write.buf_add = param->paddr;
3026 write.avail_bytes = param->len;
3027 write.uid = param->uid;
3028 write.msw_ts = param->msw_ts;
3029 write.lsw_ts = param->lsw_ts;
3030 /* Use 0xFF00 for disabling timestamps */
3031 if (param->flags == 0xFF00)
3032 write.uflags = (0x00000000 | (param->flags & 0x800000FF));
3033 else
3034 write.uflags = (0x80000000 | param->flags);
3035
3036 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3037 write.buf_add, write.avail_bytes);
3038
3039 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3040 if (rc < 0) {
3041 pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__,
3042 write.hdr.opcode, rc);
3043 goto fail_cmd;
3044 }
3045 return 0;
3046fail_cmd:
3047 return -EINVAL;
3048}
3049
3050int q6asm_async_read(struct audio_client *ac,
3051 struct audio_aio_read_param *param)
3052{
3053 int rc = 0;
3054 struct asm_stream_cmd_read read;
3055
3056 if (!ac || ac->apr == NULL) {
3057 pr_err("%s: APR handle NULL\n", __func__);
3058 return -EINVAL;
3059 }
3060
3061 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3062
3063 /* Pass physical address as token for AIO scheme */
3064 read.hdr.token = param->paddr;
3065 read.hdr.opcode = ASM_DATA_CMD_READ;
3066 read.buf_add = param->paddr;
3067 read.buf_size = param->len;
3068 read.uid = param->uid;
3069
3070 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3071 read.buf_add, read.buf_size);
3072
3073 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3074 if (rc < 0) {
3075 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3076 read.hdr.opcode, rc);
3077 goto fail_cmd;
3078 }
3079 return 0;
3080fail_cmd:
3081 return -EINVAL;
3082}
3083
3084int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3085 uint32_t lsw_ts, uint32_t flags)
3086{
3087 int rc = 0;
3088 struct asm_stream_cmd_write write;
3089 struct audio_port_data *port;
3090 struct audio_buffer *ab;
3091 int dsp_buf = 0;
3092
3093 if (!ac || ac->apr == NULL) {
3094 pr_err("APR handle NULL\n");
3095 return -EINVAL;
3096 }
3097 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3098 if (ac->io_mode == SYNC_IO_MODE) {
3099 port = &ac->port[IN];
3100
3101 q6asm_add_hdr(ac, &write.hdr, sizeof(write),
3102 FALSE);
3103 mutex_lock(&port->lock);
3104
3105 dsp_buf = port->dsp_buf;
3106 ab = &port->buf[dsp_buf];
3107
3108 write.hdr.token = port->dsp_buf;
3109 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3110 write.buf_add = ab->phys;
3111 write.avail_bytes = len;
3112 write.uid = port->dsp_buf;
3113 write.msw_ts = msw_ts;
3114 write.lsw_ts = lsw_ts;
3115 /* Use 0xFF00 for disabling timestamps */
3116 if (flags == 0xFF00)
3117 write.uflags = (0x00000000 | (flags & 0x800000FF));
3118 else
3119 write.uflags = (0x80000000 | flags);
3120 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3121
3122 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3123 , __func__,
3124 ab->phys,
3125 write.buf_add,
3126 write.hdr.token,
3127 write.uid);
3128 mutex_unlock(&port->lock);
Rajesha Kini3498c932011-07-19 19:58:27 +05303129#ifdef CONFIG_DEBUG_FS
3130 if (out_enable_flag) {
3131 char zero_pattern[2] = {0x00, 0x00};
3132 /* If First two byte is non zero and last two byte
3133 is zero then it is warm output pattern */
3134 if ((strncmp(((char *)ab->data), zero_pattern, 2)) &&
3135 (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3136 do_gettimeofday(&out_warm_tv);
3137 pr_debug("WARM:apr_send_pkt at \
3138 %ld sec %ld microsec\n", out_warm_tv.tv_sec,\
3139 out_warm_tv.tv_usec);
3140 pr_debug("Warm Pattern Matched");
3141 }
3142 /* If First two byte is zero and last two byte is
3143 non zero then it is cont ouput pattern */
3144 else if ((!strncmp(((char *)ab->data), zero_pattern, 2))
3145 && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3146 do_gettimeofday(&out_cont_tv);
3147 pr_debug("CONT:apr_send_pkt at \
3148 %ld sec %ld microsec\n", out_cont_tv.tv_sec,\
3149 out_cont_tv.tv_usec);
3150 pr_debug("Cont Pattern Matched");
3151 }
3152 }
3153#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003154 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3155 if (rc < 0) {
3156 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3157 goto fail_cmd;
3158 }
3159 pr_debug("%s: WRITE SUCCESS\n", __func__);
3160 return 0;
3161 }
3162fail_cmd:
3163 return -EINVAL;
3164}
3165
3166int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3167 uint32_t lsw_ts, uint32_t flags)
3168{
3169 int rc = 0;
3170 struct asm_stream_cmd_write write;
3171 struct audio_port_data *port;
3172 struct audio_buffer *ab;
3173 int dsp_buf = 0;
3174
3175 if (!ac || ac->apr == NULL) {
3176 pr_err("APR handle NULL\n");
3177 return -EINVAL;
3178 }
3179 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3180 if (ac->io_mode == SYNC_IO_MODE) {
3181 port = &ac->port[IN];
3182
3183 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
3184 FALSE);
3185
3186 dsp_buf = port->dsp_buf;
3187 ab = &port->buf[dsp_buf];
3188
3189 write.hdr.token = port->dsp_buf;
3190 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3191 write.buf_add = ab->phys;
3192 write.avail_bytes = len;
3193 write.uid = port->dsp_buf;
3194 write.msw_ts = msw_ts;
3195 write.lsw_ts = lsw_ts;
3196 /* Use 0xFF00 for disabling timestamps */
3197 if (flags == 0xFF00)
3198 write.uflags = (0x00000000 | (flags & 0x800000FF));
3199 else
3200 write.uflags = (0x80000000 | flags);
3201 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3202
3203 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3204 , __func__,
3205 ab->phys,
3206 write.buf_add,
3207 write.hdr.token,
3208 write.uid);
3209
3210 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3211 if (rc < 0) {
3212 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3213 goto fail_cmd;
3214 }
3215 pr_debug("%s: WRITE SUCCESS\n", __func__);
3216 return 0;
3217 }
3218fail_cmd:
3219 return -EINVAL;
3220}
3221
3222uint64_t q6asm_get_session_time(struct audio_client *ac)
3223{
3224 struct apr_hdr hdr;
3225 int rc;
3226
3227 if (!ac || ac->apr == NULL) {
3228 pr_err("APR handle NULL\n");
3229 return -EINVAL;
3230 }
3231 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3232 hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME;
3233 atomic_set(&ac->time_flag, 1);
3234
3235 pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
3236 ac->session,
3237 hdr.opcode);
3238 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3239 if (rc < 0) {
3240 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3241 goto fail_cmd;
3242 }
3243 rc = wait_event_timeout(ac->time_wait,
3244 (atomic_read(&ac->time_flag) == 0), 5*HZ);
3245 if (!rc) {
3246 pr_err("%s: timeout in getting session time from DSP\n",
3247 __func__);
3248 goto fail_cmd;
3249 }
3250 return ac->time_stamp;
3251
3252fail_cmd:
3253 return -EINVAL;
3254}
3255
3256int q6asm_cmd(struct audio_client *ac, int cmd)
3257{
3258 struct apr_hdr hdr;
3259 int rc;
3260 atomic_t *state;
3261 int cnt = 0;
3262
3263 if (!ac || ac->apr == NULL) {
3264 pr_err("APR handle NULL\n");
3265 return -EINVAL;
3266 }
3267 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3268 switch (cmd) {
3269 case CMD_PAUSE:
3270 pr_debug("%s:CMD_PAUSE\n", __func__);
3271 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3272 state = &ac->cmd_state;
3273 break;
3274 case CMD_FLUSH:
3275 pr_debug("%s:CMD_FLUSH\n", __func__);
3276 hdr.opcode = ASM_STREAM_CMD_FLUSH;
3277 state = &ac->cmd_state;
3278 break;
3279 case CMD_OUT_FLUSH:
3280 pr_debug("%s:CMD_OUT_FLUSH\n", __func__);
3281 hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
3282 state = &ac->cmd_state;
3283 break;
3284 case CMD_EOS:
3285 pr_debug("%s:CMD_EOS\n", __func__);
3286 hdr.opcode = ASM_DATA_CMD_EOS;
3287 atomic_set(&ac->cmd_state, 0);
3288 state = &ac->cmd_state;
3289 break;
3290 case CMD_CLOSE:
3291 pr_debug("%s:CMD_CLOSE\n", __func__);
3292 hdr.opcode = ASM_STREAM_CMD_CLOSE;
3293 state = &ac->cmd_state;
3294 break;
3295 default:
3296 pr_err("Invalid format[%d]\n", cmd);
3297 goto fail_cmd;
3298 }
3299 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3300 ac->session,
3301 hdr.opcode);
3302 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3303 if (rc < 0) {
3304 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3305 goto fail_cmd;
3306 }
3307 rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ);
3308 if (!rc) {
3309 pr_err("timeout. waited for response opcode[0x%x]\n",
3310 hdr.opcode);
3311 goto fail_cmd;
3312 }
3313 if (cmd == CMD_FLUSH)
3314 q6asm_reset_buf_state(ac);
3315 if (cmd == CMD_CLOSE) {
3316 /* check if DSP return all buffers */
3317 if (ac->port[IN].buf) {
3318 for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
3319 cnt++) {
3320 if (ac->port[IN].buf[cnt].used == IN) {
3321 pr_debug("Write Buf[%d] not returned\n",
3322 cnt);
3323 }
3324 }
3325 }
3326 if (ac->port[OUT].buf) {
3327 for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
3328 if (ac->port[OUT].buf[cnt].used == OUT) {
3329 pr_debug("Read Buf[%d] not returned\n",
3330 cnt);
3331 }
3332 }
3333 }
3334 }
3335 return 0;
3336fail_cmd:
3337 return -EINVAL;
3338}
3339
3340int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
3341{
3342 struct apr_hdr hdr;
3343 int rc;
3344
3345 if (!ac || ac->apr == NULL) {
3346 pr_err("%s:APR handle NULL\n", __func__);
3347 return -EINVAL;
3348 }
3349 q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE);
3350 switch (cmd) {
3351 case CMD_PAUSE:
3352 pr_debug("%s:CMD_PAUSE\n", __func__);
3353 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3354 break;
3355 case CMD_EOS:
3356 pr_debug("%s:CMD_EOS\n", __func__);
3357 hdr.opcode = ASM_DATA_CMD_EOS;
3358 break;
3359 default:
3360 pr_err("%s:Invalid format[%d]\n", __func__, cmd);
3361 goto fail_cmd;
3362 }
3363 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3364 ac->session,
3365 hdr.opcode);
3366 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3367 if (rc < 0) {
3368 pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
3369 goto fail_cmd;
3370 }
3371 return 0;
3372fail_cmd:
3373 return -EINVAL;
3374}
3375
3376static void q6asm_reset_buf_state(struct audio_client *ac)
3377{
3378 int cnt = 0;
3379 int loopcnt = 0;
3380 struct audio_port_data *port = NULL;
3381
3382 if (ac->io_mode == SYNC_IO_MODE) {
3383 mutex_lock(&ac->cmd_lock);
3384 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
3385 port = &ac->port[loopcnt];
3386 cnt = port->max_buf_cnt - 1;
3387 port->dsp_buf = 0;
3388 port->cpu_buf = 0;
3389 while (cnt >= 0) {
3390 if (!port->buf)
3391 continue;
3392 port->buf[cnt].used = 1;
3393 cnt--;
3394 }
3395 }
3396 mutex_unlock(&ac->cmd_lock);
3397 }
3398}
3399
3400int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
3401{
3402 struct asm_stream_cmd_reg_tx_overflow_event tx_overflow;
3403 int rc;
3404
3405 if (!ac || ac->apr == NULL) {
3406 pr_err("APR handle NULL\n");
3407 return -EINVAL;
3408 }
3409 pr_debug("%s:session[%d]enable[%d]\n", __func__,
3410 ac->session, enable);
3411 q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
3412
3413 tx_overflow.hdr.opcode = \
3414 ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS;
3415 /* tx overflow event: enable */
3416 tx_overflow.enable = enable;
3417
3418 rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
3419 if (rc < 0) {
3420 pr_err("tx overflow op[0x%x]rc[%d]\n", \
3421 tx_overflow.hdr.opcode, rc);
3422 goto fail_cmd;
3423 }
3424 rc = wait_event_timeout(ac->cmd_wait,
3425 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3426 if (!rc) {
3427 pr_err("timeout. waited for tx overflow\n");
3428 goto fail_cmd;
3429 }
3430 return 0;
3431fail_cmd:
3432 return -EINVAL;
3433}
3434
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003435int q6asm_get_apr_service_id(int session_id)
3436{
3437 pr_debug("%s\n", __func__);
3438
Shiv Maliyappanahallia84982a2012-01-19 15:25:04 -08003439 if (session_id < 0 || session_id > SESSION_MAX) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003440 pr_err("%s: invalid session_id = %d\n", __func__, session_id);
3441 return -EINVAL;
3442 }
3443
3444 return ((struct apr_svc *)session[session_id]->apr)->id;
3445}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003446
3447
3448static int __init q6asm_init(void)
3449{
3450 pr_debug("%s\n", __func__);
3451 init_waitqueue_head(&this_mmap.cmd_wait);
3452 memset(session, 0, sizeof(session));
Rajesha Kini3498c932011-07-19 19:58:27 +05303453#ifdef CONFIG_DEBUG_FS
3454 out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
3455 out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
3456 S_IFREG | S_IRUGO | S_IWUGO,\
3457 NULL, NULL, &audio_output_latency_debug_fops);
3458 if (IS_ERR(out_dentry))
3459 pr_err("debugfs_create_file failed\n");
3460 in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
3461 in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
3462 S_IFREG | S_IRUGO | S_IWUGO,\
3463 NULL, NULL, &audio_input_latency_debug_fops);
3464 if (IS_ERR(in_dentry))
3465 pr_err("debugfs_create_file failed\n");
3466#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003467 return 0;
3468}
3469
3470device_initcall(q6asm_init);