blob: ba5c79d72cae467ed8bbd2ef0dd0ae4c83890a76 [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
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07001794int q6asm_set_encdec_chan_map(struct audio_client *ac,
1795 uint32_t num_channels)
1796{
1797 struct asm_stream_cmd_encdec_channelmap chan_map;
1798 u8 *channel_mapping;
1799
1800 int rc = 0;
1801
1802 pr_debug("%s: Session %d, num_channels = %d\n",
1803 __func__, ac->session, num_channels);
1804
1805 q6asm_add_hdr(ac, &chan_map.hdr, sizeof(chan_map), TRUE);
1806
1807 chan_map.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1808 chan_map.param_id = ASM_ENCDEC_DEC_CHAN_MAP;
1809 chan_map.param_size = sizeof(struct asm_dec_chan_map);
1810 chan_map.chan_map.num_channels = num_channels;
1811
1812 channel_mapping =
1813 chan_map.chan_map.channel_mapping;
1814
1815 memset(channel_mapping, PCM_CHANNEL_NULL, MAX_CHAN_MAP_CHANNELS);
1816 if (num_channels == 1) {
1817 channel_mapping[0] = PCM_CHANNEL_FL;
1818 } else if (num_channels == 2) {
1819 channel_mapping[0] = PCM_CHANNEL_FL;
1820 channel_mapping[1] = PCM_CHANNEL_FR;
1821 } else if (num_channels == 6) {
1822 channel_mapping[0] = PCM_CHANNEL_FC;
1823 channel_mapping[1] = PCM_CHANNEL_FL;
1824 channel_mapping[2] = PCM_CHANNEL_FR;
1825 channel_mapping[3] = PCM_CHANNEL_LB;
1826 channel_mapping[4] = PCM_CHANNEL_RB;
1827 channel_mapping[5] = PCM_CHANNEL_LFE;
1828 } else {
1829 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
1830 num_channels);
1831 rc = -EINVAL;
1832 goto fail_cmd;
1833 }
1834
1835 rc = apr_send_pkt(ac->apr, (uint32_t *) &chan_map);
1836 if (rc < 0) {
1837 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
1838 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1839 ASM_ENCDEC_DEC_CHAN_MAP);
1840 goto fail_cmd;
1841 }
1842 rc = wait_event_timeout(ac->cmd_wait,
1843 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1844 if (!rc) {
1845 pr_err("%s:timeout opcode[0x%x]\n", __func__,
1846 chan_map.hdr.opcode);
1847 rc = -ETIMEDOUT;
1848 goto fail_cmd;
1849 }
1850 return 0;
1851fail_cmd:
1852 return rc;
1853}
1854
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001855int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
1856 uint16_t min_rate, uint16_t max_rate,
1857 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
1858{
1859 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1860 int rc = 0;
1861
1862 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] \
1863 reduced_rate_level[0x%4x]rate_modulation_cmd[0x%4x]", __func__,
1864 ac->session, frames_per_buf, min_rate, max_rate,
1865 reduced_rate_level, rate_modulation_cmd);
1866
1867 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1868
1869 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1870
1871 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1872 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1873
1874 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1875 enc_cfg.enc_blk.format_id = V13K_FS;
1876 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg);
1877 enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate;
1878 enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate;
1879 enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level;
1880 enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_cmd = rate_modulation_cmd;
1881
1882 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1883 if (rc < 0) {
1884 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1885 goto fail_cmd;
1886 }
1887 rc = wait_event_timeout(ac->cmd_wait,
1888 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1889 if (!rc) {
1890 pr_err("timeout. waited for FORMAT_UPDATE\n");
1891 goto fail_cmd;
1892 }
1893 return 0;
1894fail_cmd:
1895 return -EINVAL;
1896}
1897
1898int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
1899 uint16_t min_rate, uint16_t max_rate,
1900 uint16_t rate_modulation_cmd)
1901{
1902 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1903 int rc = 0;
1904
1905 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] \
1906 rate_modulation_cmd[0x%4x]", __func__, ac->session,
1907 frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
1908
1909 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1910
1911 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1912
1913 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1914 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1915
1916 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1917 enc_cfg.enc_blk.format_id = EVRC_FS;
1918 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg);
1919 enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate;
1920 enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate;
1921 enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd;
1922 enc_cfg.enc_blk.cfg.evrc.reserved = 0;
1923
1924 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1925 if (rc < 0) {
1926 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1927 goto fail_cmd;
1928 }
1929 rc = wait_event_timeout(ac->cmd_wait,
1930 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1931 if (!rc) {
1932 pr_err("timeout. waited for FORMAT_UPDATE\n");
1933 goto fail_cmd;
1934 }
1935 return 0;
1936fail_cmd:
1937 return -EINVAL;
1938}
1939
1940int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
1941 uint16_t band_mode, uint16_t dtx_enable)
1942{
1943 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1944 int rc = 0;
1945
1946 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
1947 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
1948
1949 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1950
1951 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1952
1953 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1954 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1955
1956 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1957 enc_cfg.enc_blk.format_id = AMRNB_FS;
1958 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg);
1959 enc_cfg.enc_blk.cfg.amrnb.mode = band_mode;
1960 enc_cfg.enc_blk.cfg.amrnb.dtx_mode = dtx_enable;
1961
1962 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1963 if (rc < 0) {
1964 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1965 goto fail_cmd;
1966 }
1967 rc = wait_event_timeout(ac->cmd_wait,
1968 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1969 if (!rc) {
1970 pr_err("timeout. waited for FORMAT_UPDATE\n");
1971 goto fail_cmd;
1972 }
1973 return 0;
1974fail_cmd:
1975 return -EINVAL;
1976}
1977
Alex Wong2caeecc2011-10-28 10:52:15 +05301978int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
1979 uint16_t band_mode, uint16_t dtx_enable)
1980{
1981 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1982 int rc = 0;
1983
1984 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
1985 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
1986
1987 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1988
1989 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1990
1991 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1992 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1993
1994 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1995 enc_cfg.enc_blk.format_id = AMRWB_FS;
1996 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrwb_read_cfg);
1997 enc_cfg.enc_blk.cfg.amrwb.mode = band_mode;
1998 enc_cfg.enc_blk.cfg.amrwb.dtx_mode = dtx_enable;
1999
2000 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2001 if (rc < 0) {
2002 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2003 goto fail_cmd;
2004 }
2005 rc = wait_event_timeout(ac->cmd_wait,
2006 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2007 if (!rc) {
2008 pr_err("timeout. waited for FORMAT_UPDATE\n");
2009 goto fail_cmd;
2010 }
2011 return 0;
2012fail_cmd:
2013 return -EINVAL;
2014}
2015
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002016int q6asm_media_format_block_pcm(struct audio_client *ac,
2017 uint32_t rate, uint32_t channels)
2018{
2019 struct asm_stream_media_format_update fmt;
2020 int rc = 0;
2021
2022 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2023 channels);
2024
2025 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2026
2027 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2028
2029 fmt.format = LINEAR_PCM;
2030 fmt.cfg_size = sizeof(struct asm_pcm_cfg);
2031 fmt.write_cfg.pcm_cfg.ch_cfg = channels;
2032 fmt.write_cfg.pcm_cfg.bits_per_sample = 16;
2033 fmt.write_cfg.pcm_cfg.sample_rate = rate;
2034 fmt.write_cfg.pcm_cfg.is_signed = 1;
2035 fmt.write_cfg.pcm_cfg.interleaved = 1;
2036
2037 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2038 if (rc < 0) {
2039 pr_err("%s:Comamnd open failed\n", __func__);
2040 goto fail_cmd;
2041 }
2042 rc = wait_event_timeout(ac->cmd_wait,
2043 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2044 if (!rc) {
2045 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2046 goto fail_cmd;
2047 }
2048 return 0;
2049fail_cmd:
2050 return -EINVAL;
2051}
2052
Kiran Kandi5e809b02012-01-31 00:24:33 -08002053int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
2054 uint32_t rate, uint32_t channels)
2055{
2056 struct asm_stream_media_format_update fmt;
2057 u8 *channel_mapping;
2058 int rc = 0;
2059
2060 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2061 channels);
2062
2063 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2064
2065 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2066
2067 fmt.format = MULTI_CHANNEL_PCM;
2068 fmt.cfg_size = sizeof(struct asm_multi_channel_pcm_fmt_blk);
2069 fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels;
2070 fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = 16;
2071 fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate;
2072 fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1;
2073 fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1;
2074 channel_mapping =
2075 fmt.write_cfg.multi_ch_pcm_cfg.channel_mapping;
2076
2077 memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
2078
2079 if (channels == 1) {
2080 channel_mapping[0] = PCM_CHANNEL_FL;
2081 } else if (channels == 2) {
2082 channel_mapping[0] = PCM_CHANNEL_FL;
2083 channel_mapping[1] = PCM_CHANNEL_FR;
2084 } else if (channels == 6) {
2085 channel_mapping[0] = PCM_CHANNEL_FC;
2086 channel_mapping[1] = PCM_CHANNEL_FL;
2087 channel_mapping[2] = PCM_CHANNEL_FR;
2088 channel_mapping[3] = PCM_CHANNEL_LB;
2089 channel_mapping[4] = PCM_CHANNEL_RB;
2090 channel_mapping[5] = PCM_CHANNEL_LFE;
2091 } else {
2092 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2093 channels);
2094 return -EINVAL;
2095 }
2096
2097 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2098 if (rc < 0) {
2099 pr_err("%s:Comamnd open failed\n", __func__);
2100 goto fail_cmd;
2101 }
2102 rc = wait_event_timeout(ac->cmd_wait,
2103 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2104 if (!rc) {
2105 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2106 goto fail_cmd;
2107 }
2108 return 0;
2109fail_cmd:
2110 return -EINVAL;
2111}
2112
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002113int q6asm_media_format_block_aac(struct audio_client *ac,
2114 struct asm_aac_cfg *cfg)
2115{
2116 struct asm_stream_media_format_update fmt;
2117 int rc = 0;
2118
2119 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2120 cfg->sample_rate, cfg->ch_cfg);
2121
2122 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2123
2124 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2125
2126 fmt.format = MPEG4_AAC;
2127 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2128 fmt.write_cfg.aac_cfg.format = cfg->format;
2129 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2130 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2131 fmt.write_cfg.aac_cfg.section_data_resilience =
2132 cfg->section_data_resilience;
2133 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2134 cfg->scalefactor_data_resilience;
2135 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2136 cfg->spectral_data_resilience;
2137 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2138 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2139 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2140 __func__, fmt.format, fmt.cfg_size,
2141 fmt.write_cfg.aac_cfg.format,
2142 fmt.write_cfg.aac_cfg.aot,
2143 fmt.write_cfg.aac_cfg.ch_cfg,
2144 fmt.write_cfg.aac_cfg.sample_rate);
2145 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2146 if (rc < 0) {
2147 pr_err("%s:Comamnd open failed\n", __func__);
2148 goto fail_cmd;
2149 }
2150 rc = wait_event_timeout(ac->cmd_wait,
2151 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2152 if (!rc) {
2153 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2154 goto fail_cmd;
2155 }
2156 return 0;
2157fail_cmd:
2158 return -EINVAL;
2159}
2160
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002161
2162int q6asm_media_format_block_multi_aac(struct audio_client *ac,
2163 struct asm_aac_cfg *cfg)
2164{
2165 struct asm_stream_media_format_update fmt;
2166 int rc = 0;
2167
2168 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2169 cfg->sample_rate, cfg->ch_cfg);
2170
2171 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2172
2173 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2174
2175 fmt.format = MPEG4_MULTI_AAC;
2176 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2177 fmt.write_cfg.aac_cfg.format = cfg->format;
2178 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2179 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2180 fmt.write_cfg.aac_cfg.section_data_resilience =
2181 cfg->section_data_resilience;
2182 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2183 cfg->scalefactor_data_resilience;
2184 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2185 cfg->spectral_data_resilience;
2186 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2187 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2188 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2189 __func__, fmt.format, fmt.cfg_size,
2190 fmt.write_cfg.aac_cfg.format,
2191 fmt.write_cfg.aac_cfg.aot,
2192 fmt.write_cfg.aac_cfg.ch_cfg,
2193 fmt.write_cfg.aac_cfg.sample_rate);
2194 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2195 if (rc < 0) {
2196 pr_err("%s:Comamnd open failed\n", __func__);
2197 goto fail_cmd;
2198 }
2199 rc = wait_event_timeout(ac->cmd_wait,
2200 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2201 if (!rc) {
2202 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2203 goto fail_cmd;
2204 }
2205 return 0;
2206fail_cmd:
2207 return -EINVAL;
2208}
2209
2210
Alex Wong2caeecc2011-10-28 10:52:15 +05302211
2212int q6asm_media_format_block(struct audio_client *ac, uint32_t format)
2213{
2214
2215 struct asm_stream_media_format_update fmt;
2216 int rc = 0;
2217
2218 pr_debug("%s:session[%d] format[0x%x]\n", __func__,
2219 ac->session, format);
2220
2221 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2222 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302223 switch (format) {
2224 case FORMAT_V13K:
2225 fmt.format = V13K_FS;
2226 break;
2227 case FORMAT_EVRC:
2228 fmt.format = EVRC_FS;
2229 break;
2230 case FORMAT_AMRWB:
2231 fmt.format = AMRWB_FS;
2232 break;
2233 case FORMAT_AMRNB:
2234 fmt.format = AMRNB_FS;
2235 break;
2236 case FORMAT_MP3:
2237 fmt.format = MP3;
2238 break;
2239 default:
2240 pr_err("Invalid format[%d]\n", format);
2241 goto fail_cmd;
2242 }
Alex Wong2caeecc2011-10-28 10:52:15 +05302243 fmt.cfg_size = 0;
2244
2245 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2246 if (rc < 0) {
2247 pr_err("%s:Comamnd open failed\n", __func__);
2248 goto fail_cmd;
2249 }
2250 rc = wait_event_timeout(ac->cmd_wait,
2251 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2252 if (!rc) {
2253 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2254 goto fail_cmd;
2255 }
2256 return 0;
2257fail_cmd:
2258 return -EINVAL;
2259}
2260
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002261int q6asm_media_format_block_wma(struct audio_client *ac,
2262 void *cfg)
2263{
2264 struct asm_stream_media_format_update fmt;
2265 struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
2266 int rc = 0;
2267
2268 pr_debug("session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d],\
2269 balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x]\n",
2270 ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
2271 wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
2272 wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
2273 wma_cfg->ch_mask, wma_cfg->encode_opt);
2274
2275 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2276
2277 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2278
2279 fmt.format = WMA_V9;
2280 fmt.cfg_size = sizeof(struct asm_wma_cfg);
2281 fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag;
2282 fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg;
2283 fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate;
2284 fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
2285 fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align;
2286 fmt.write_cfg.wma_cfg.valid_bits_per_sample =
2287 wma_cfg->valid_bits_per_sample;
2288 fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask;
2289 fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt;
2290 fmt.write_cfg.wma_cfg.adv_encode_opt = 0;
2291 fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0;
2292 fmt.write_cfg.wma_cfg.drc_peak_ref = 0;
2293 fmt.write_cfg.wma_cfg.drc_peak_target = 0;
2294 fmt.write_cfg.wma_cfg.drc_ave_ref = 0;
2295 fmt.write_cfg.wma_cfg.drc_ave_target = 0;
2296
2297 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2298 if (rc < 0) {
2299 pr_err("%s:Comamnd open failed\n", __func__);
2300 goto fail_cmd;
2301 }
2302 rc = wait_event_timeout(ac->cmd_wait,
2303 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2304 if (!rc) {
2305 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2306 goto fail_cmd;
2307 }
2308 return 0;
2309fail_cmd:
2310 return -EINVAL;
2311}
2312
2313int q6asm_media_format_block_wmapro(struct audio_client *ac,
2314 void *cfg)
2315{
2316 struct asm_stream_media_format_update fmt;
2317 struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
2318 int rc = 0;
2319
2320 pr_debug("session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d],"
2321 "balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x],\
2322 adv_enc_opt[0x%4x], adv_enc_opt2[0x%8x]\n",
2323 ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
2324 wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
2325 wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
2326 wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
2327 wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
2328
2329 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2330
2331 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2332
2333 fmt.format = WMA_V10PRO;
2334 fmt.cfg_size = sizeof(struct asm_wmapro_cfg);
2335 fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag;
2336 fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg;
2337 fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate;
2338 fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec =
2339 wmapro_cfg->avg_bytes_per_sec;
2340 fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align;
2341 fmt.write_cfg.wmapro_cfg.valid_bits_per_sample =
2342 wmapro_cfg->valid_bits_per_sample;
2343 fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask;
2344 fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt;
2345 fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt;
2346 fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2;
2347 fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0;
2348 fmt.write_cfg.wmapro_cfg.drc_peak_target = 0;
2349 fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0;
2350 fmt.write_cfg.wmapro_cfg.drc_ave_target = 0;
2351
2352 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2353 if (rc < 0) {
2354 pr_err("%s:Comamnd open failed\n", __func__);
2355 goto fail_cmd;
2356 }
2357 rc = wait_event_timeout(ac->cmd_wait,
2358 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2359 if (!rc) {
2360 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2361 goto fail_cmd;
2362 }
2363 return 0;
2364fail_cmd:
2365 return -EINVAL;
2366}
2367
2368int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
2369 uint32_t bufsz, uint32_t bufcnt)
2370{
2371 struct asm_stream_cmd_memory_map mem_map;
2372 int rc = 0;
2373
2374 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2375 pr_err("APR handle NULL\n");
2376 return -EINVAL;
2377 }
2378
2379 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2380
2381 mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP;
2382
2383 mem_map.buf_add = buf_add;
2384 mem_map.buf_size = bufsz * bufcnt;
2385 mem_map.mempool_id = 0; /* EBI */
2386 mem_map.reserved = 0;
2387
2388 q6asm_add_mmaphdr(&mem_map.hdr,
2389 sizeof(struct asm_stream_cmd_memory_map), TRUE);
2390
2391 pr_debug("buf add[%x] buf_add_parameter[%x]\n",
2392 mem_map.buf_add, buf_add);
2393
2394 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map);
2395 if (rc < 0) {
2396 pr_err("mem_map op[0x%x]rc[%d]\n",
2397 mem_map.hdr.opcode, rc);
2398 rc = -EINVAL;
2399 goto fail_cmd;
2400 }
2401
2402 rc = wait_event_timeout(this_mmap.cmd_wait,
2403 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2404 if (!rc) {
2405 pr_err("timeout. waited for memory_map\n");
2406 rc = -EINVAL;
2407 goto fail_cmd;
2408 }
2409 rc = 0;
2410fail_cmd:
2411 return rc;
2412}
2413
2414int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
2415{
2416 struct asm_stream_cmd_memory_unmap mem_unmap;
2417 int rc = 0;
2418
2419 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2420 pr_err("APR handle NULL\n");
2421 return -EINVAL;
2422 }
2423 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2424
2425 q6asm_add_mmaphdr(&mem_unmap.hdr,
2426 sizeof(struct asm_stream_cmd_memory_unmap), TRUE);
2427 mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP;
2428 mem_unmap.buf_add = buf_add;
2429
2430 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_unmap);
2431 if (rc < 0) {
2432 pr_err("mem_unmap op[0x%x]rc[%d]\n",
2433 mem_unmap.hdr.opcode, rc);
2434 rc = -EINVAL;
2435 goto fail_cmd;
2436 }
2437
2438 rc = wait_event_timeout(this_mmap.cmd_wait,
2439 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2440 if (!rc) {
2441 pr_err("timeout. waited for memory_map\n");
2442 rc = -EINVAL;
2443 goto fail_cmd;
2444 }
2445 rc = 0;
2446fail_cmd:
2447 return rc;
2448}
2449
2450int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
2451{
2452 void *vol_cmd = NULL;
2453 void *payload = NULL;
2454 struct asm_pp_params_command *cmd = NULL;
2455 struct asm_lrchannel_gain_params *lrgain = NULL;
2456 int sz = 0;
2457 int rc = 0;
2458
2459 sz = sizeof(struct asm_pp_params_command) +
2460 + sizeof(struct asm_lrchannel_gain_params);
2461 vol_cmd = kzalloc(sz, GFP_KERNEL);
2462 if (vol_cmd == NULL) {
2463 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2464 rc = -EINVAL;
2465 return rc;
2466 }
2467 cmd = (struct asm_pp_params_command *)vol_cmd;
2468 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2469 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2470 cmd->payload = NULL;
2471 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2472 sizeof(struct asm_lrchannel_gain_params);
2473 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2474 cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID;
2475 cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params);
2476 cmd->params.reserved = 0;
2477
2478 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2479 lrgain = (struct asm_lrchannel_gain_params *)payload;
2480
2481 lrgain->left_gain = left_gain;
2482 lrgain->right_gain = right_gain;
2483 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2484 if (rc < 0) {
2485 pr_err("%s: Volume Command failed\n", __func__);
2486 rc = -EINVAL;
2487 goto fail_cmd;
2488 }
2489
2490 rc = wait_event_timeout(ac->cmd_wait,
2491 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2492 if (!rc) {
2493 pr_err("%s: timeout in sending volume command to apr\n",
2494 __func__);
2495 rc = -EINVAL;
2496 goto fail_cmd;
2497 }
2498 rc = 0;
2499fail_cmd:
2500 kfree(vol_cmd);
2501 return rc;
2502}
2503
2504static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
2505 uint32_t bufsz, uint32_t bufcnt)
2506{
2507 struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL;
2508 struct asm_memory_map_regions *mregions = NULL;
2509 struct audio_port_data *port = NULL;
2510 struct audio_buffer *ab = NULL;
2511 void *mmap_region_cmd = NULL;
2512 void *payload = NULL;
2513 int rc = 0;
2514 int i = 0;
2515 int cmd_size = 0;
2516
2517 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2518 pr_err("APR handle NULL\n");
2519 return -EINVAL;
2520 }
2521 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2522
2523 cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions)
2524 + sizeof(struct asm_memory_map_regions) * bufcnt;
2525
2526 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302527 if (mmap_region_cmd == NULL) {
2528 pr_err("%s: Mem alloc failed\n", __func__);
2529 rc = -EINVAL;
2530 return rc;
2531 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002532 mmap_regions = (struct asm_stream_cmd_memory_map_regions *)
2533 mmap_region_cmd;
2534 q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE);
2535 mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS;
2536 mmap_regions->mempool_id = 0;
2537 mmap_regions->nregions = bufcnt & 0x00ff;
2538 pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions);
2539 payload = ((u8 *) mmap_region_cmd +
2540 sizeof(struct asm_stream_cmd_memory_map_regions));
2541 mregions = (struct asm_memory_map_regions *)payload;
2542
2543 port = &ac->port[dir];
2544 for (i = 0; i < bufcnt; i++) {
2545 ab = &port->buf[i];
2546 mregions->phys = ab->phys;
2547 mregions->buf_size = ab->size;
2548 ++mregions;
2549 }
2550
2551 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) mmap_region_cmd);
2552 if (rc < 0) {
2553 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2554 mmap_regions->hdr.opcode, rc);
2555 rc = -EINVAL;
2556 goto fail_cmd;
2557 }
2558
2559 rc = wait_event_timeout(this_mmap.cmd_wait,
2560 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2561 if (!rc) {
2562 pr_err("timeout. waited for memory_map\n");
2563 rc = -EINVAL;
2564 goto fail_cmd;
2565 }
2566 rc = 0;
2567fail_cmd:
2568 kfree(mmap_region_cmd);
2569 return rc;
2570}
2571
2572static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
2573 uint32_t bufsz, uint32_t bufcnt)
2574{
2575 struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL;
2576 struct asm_memory_unmap_regions *mregions = NULL;
2577 struct audio_port_data *port = NULL;
2578 struct audio_buffer *ab = NULL;
2579 void *unmap_region_cmd = NULL;
2580 void *payload = NULL;
2581 int rc = 0;
2582 int i = 0;
2583 int cmd_size = 0;
2584
2585 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2586 pr_err("APR handle NULL\n");
2587 return -EINVAL;
2588 }
2589 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2590
2591 cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) +
2592 sizeof(struct asm_memory_unmap_regions) * bufcnt;
2593
2594 unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302595 if (unmap_region_cmd == NULL) {
2596 pr_err("%s: Mem alloc failed\n", __func__);
2597 rc = -EINVAL;
2598 return rc;
2599 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002600 unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *)
2601 unmap_region_cmd;
2602 q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE);
2603 unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS;
2604 unmap_regions->nregions = bufcnt & 0x00ff;
2605 pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions);
2606 payload = ((u8 *) unmap_region_cmd +
2607 sizeof(struct asm_stream_cmd_memory_unmap_regions));
2608 mregions = (struct asm_memory_unmap_regions *)payload;
2609 port = &ac->port[dir];
2610 for (i = 0; i < bufcnt; i++) {
2611 ab = &port->buf[i];
2612 mregions->phys = ab->phys;
2613 ++mregions;
2614 }
2615
2616 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd);
2617 if (rc < 0) {
2618 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2619 unmap_regions->hdr.opcode, rc);
2620 goto fail_cmd;
2621 }
2622
2623 rc = wait_event_timeout(this_mmap.cmd_wait,
2624 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2625 if (!rc) {
2626 pr_err("timeout. waited for memory_unmap\n");
2627 goto fail_cmd;
2628 }
2629 rc = 0;
2630
2631fail_cmd:
2632 kfree(unmap_region_cmd);
2633 return rc;
2634}
2635
2636int q6asm_set_mute(struct audio_client *ac, int muteflag)
2637{
2638 void *vol_cmd = NULL;
2639 void *payload = NULL;
2640 struct asm_pp_params_command *cmd = NULL;
2641 struct asm_mute_params *mute = NULL;
2642 int sz = 0;
2643 int rc = 0;
2644
2645 sz = sizeof(struct asm_pp_params_command) +
2646 + sizeof(struct asm_mute_params);
2647 vol_cmd = kzalloc(sz, GFP_KERNEL);
2648 if (vol_cmd == NULL) {
2649 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2650 rc = -EINVAL;
2651 return rc;
2652 }
2653 cmd = (struct asm_pp_params_command *)vol_cmd;
2654 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2655 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2656 cmd->payload = NULL;
2657 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2658 sizeof(struct asm_mute_params);
2659 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2660 cmd->params.param_id = MUTE_CONFIG_PARAM_ID;
2661 cmd->params.param_size = sizeof(struct asm_mute_params);
2662 cmd->params.reserved = 0;
2663
2664 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2665 mute = (struct asm_mute_params *)payload;
2666
2667 mute->muteflag = muteflag;
2668 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2669 if (rc < 0) {
2670 pr_err("%s: Mute Command failed\n", __func__);
2671 rc = -EINVAL;
2672 goto fail_cmd;
2673 }
2674
2675 rc = wait_event_timeout(ac->cmd_wait,
2676 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2677 if (!rc) {
2678 pr_err("%s: timeout in sending mute command to apr\n",
2679 __func__);
2680 rc = -EINVAL;
2681 goto fail_cmd;
2682 }
2683 rc = 0;
2684fail_cmd:
2685 kfree(vol_cmd);
2686 return rc;
2687}
2688
2689int q6asm_set_volume(struct audio_client *ac, int volume)
2690{
2691 void *vol_cmd = NULL;
2692 void *payload = NULL;
2693 struct asm_pp_params_command *cmd = NULL;
2694 struct asm_master_gain_params *mgain = NULL;
2695 int sz = 0;
2696 int rc = 0;
2697
2698 sz = sizeof(struct asm_pp_params_command) +
2699 + sizeof(struct asm_master_gain_params);
2700 vol_cmd = kzalloc(sz, GFP_KERNEL);
2701 if (vol_cmd == NULL) {
2702 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2703 rc = -EINVAL;
2704 return rc;
2705 }
2706 cmd = (struct asm_pp_params_command *)vol_cmd;
2707 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2708 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2709 cmd->payload = NULL;
2710 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2711 sizeof(struct asm_master_gain_params);
2712 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2713 cmd->params.param_id = MASTER_GAIN_PARAM_ID;
2714 cmd->params.param_size = sizeof(struct asm_master_gain_params);
2715 cmd->params.reserved = 0;
2716
2717 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2718 mgain = (struct asm_master_gain_params *)payload;
2719
2720 mgain->master_gain = volume;
2721 mgain->padding = 0x00;
2722 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2723 if (rc < 0) {
2724 pr_err("%s: Volume Command failed\n", __func__);
2725 rc = -EINVAL;
2726 goto fail_cmd;
2727 }
2728
2729 rc = wait_event_timeout(ac->cmd_wait,
2730 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2731 if (!rc) {
2732 pr_err("%s: timeout in sending volume command to apr\n",
2733 __func__);
2734 rc = -EINVAL;
2735 goto fail_cmd;
2736 }
2737 rc = 0;
2738fail_cmd:
2739 kfree(vol_cmd);
2740 return rc;
2741}
2742
2743int q6asm_set_softpause(struct audio_client *ac,
2744 struct asm_softpause_params *pause_param)
2745{
2746 void *vol_cmd = NULL;
2747 void *payload = NULL;
2748 struct asm_pp_params_command *cmd = NULL;
2749 struct asm_softpause_params *params = NULL;
2750 int sz = 0;
2751 int rc = 0;
2752
2753 sz = sizeof(struct asm_pp_params_command) +
2754 + sizeof(struct asm_softpause_params);
2755 vol_cmd = kzalloc(sz, GFP_KERNEL);
2756 if (vol_cmd == NULL) {
2757 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2758 rc = -EINVAL;
2759 return rc;
2760 }
2761 cmd = (struct asm_pp_params_command *)vol_cmd;
2762 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2763 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2764 cmd->payload = NULL;
2765 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2766 sizeof(struct asm_softpause_params);
2767 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2768 cmd->params.param_id = SOFT_PAUSE_PARAM_ID;
2769 cmd->params.param_size = sizeof(struct asm_softpause_params);
2770 cmd->params.reserved = 0;
2771
2772 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2773 params = (struct asm_softpause_params *)payload;
2774
2775 params->enable = pause_param->enable;
2776 params->period = pause_param->period;
2777 params->step = pause_param->step;
2778 params->rampingcurve = pause_param->rampingcurve;
2779 pr_debug("%s: soft Pause Command: enable = %d, period = %d,"
2780 "step = %d, curve = %d\n", __func__, params->enable,
2781 params->period, params->step, params->rampingcurve);
2782 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2783 if (rc < 0) {
2784 pr_err("%s: Volume Command(soft_pause) failed\n", __func__);
2785 rc = -EINVAL;
2786 goto fail_cmd;
2787 }
2788
2789 rc = wait_event_timeout(ac->cmd_wait,
2790 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2791 if (!rc) {
2792 pr_err("%s: timeout in sending volume command(soft_pause)"
2793 "to apr\n", __func__);
2794 rc = -EINVAL;
2795 goto fail_cmd;
2796 }
2797 rc = 0;
2798fail_cmd:
2799 kfree(vol_cmd);
2800 return rc;
2801}
2802
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07002803int q6asm_set_softvolume(struct audio_client *ac,
2804 struct asm_softvolume_params *softvol_param)
2805{
2806 void *vol_cmd = NULL;
2807 void *payload = NULL;
2808 struct asm_pp_params_command *cmd = NULL;
2809 struct asm_softvolume_params *params = NULL;
2810 int sz = 0;
2811 int rc = 0;
2812
2813 sz = sizeof(struct asm_pp_params_command) +
2814 + sizeof(struct asm_softvolume_params);
2815 vol_cmd = kzalloc(sz, GFP_KERNEL);
2816 if (vol_cmd == NULL) {
2817 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2818 rc = -EINVAL;
2819 return rc;
2820 }
2821 cmd = (struct asm_pp_params_command *)vol_cmd;
2822 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2823 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2824 cmd->payload = NULL;
2825 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2826 sizeof(struct asm_softvolume_params);
2827 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2828 cmd->params.param_id = SOFT_VOLUME_PARAM_ID;
2829 cmd->params.param_size = sizeof(struct asm_softvolume_params);
2830 cmd->params.reserved = 0;
2831
2832 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2833 params = (struct asm_softvolume_params *)payload;
2834
2835 params->period = softvol_param->period;
2836 params->step = softvol_param->step;
2837 params->rampingcurve = softvol_param->rampingcurve;
2838 pr_debug("%s: soft Volume:opcode = %d,payload_sz =%d,module_id =%d,"
2839 "param_id = %d, param_sz = %d\n", __func__,
2840 cmd->hdr.opcode, cmd->payload_size,
2841 cmd->params.module_id, cmd->params.param_id,
2842 cmd->params.param_size);
2843 pr_debug("%s: soft Volume Command: period = %d,"
2844 "step = %d, curve = %d\n", __func__, params->period,
2845 params->step, params->rampingcurve);
2846 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2847 if (rc < 0) {
2848 pr_err("%s: Volume Command(soft_volume) failed\n", __func__);
2849 rc = -EINVAL;
2850 goto fail_cmd;
2851 }
2852
2853 rc = wait_event_timeout(ac->cmd_wait,
2854 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2855 if (!rc) {
2856 pr_err("%s: timeout in sending volume command(soft_volume)"
2857 "to apr\n", __func__);
2858 rc = -EINVAL;
2859 goto fail_cmd;
2860 }
2861 rc = 0;
2862fail_cmd:
2863 kfree(vol_cmd);
2864 return rc;
2865}
2866
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002867int q6asm_equalizer(struct audio_client *ac, void *eq)
2868{
2869 void *eq_cmd = NULL;
2870 void *payload = NULL;
2871 struct asm_pp_params_command *cmd = NULL;
2872 struct asm_equalizer_params *equalizer = NULL;
2873 struct msm_audio_eq_stream_config *eq_params = NULL;
2874 int i = 0;
2875 int sz = 0;
2876 int rc = 0;
2877
2878 sz = sizeof(struct asm_pp_params_command) +
2879 + sizeof(struct asm_equalizer_params);
2880 eq_cmd = kzalloc(sz, GFP_KERNEL);
2881 if (eq_cmd == NULL) {
2882 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2883 rc = -EINVAL;
2884 goto fail_cmd;
2885 }
2886 eq_params = (struct msm_audio_eq_stream_config *) eq;
2887 cmd = (struct asm_pp_params_command *)eq_cmd;
2888 q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE);
2889 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2890 cmd->payload = NULL;
2891 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2892 sizeof(struct asm_equalizer_params);
2893 cmd->params.module_id = EQUALIZER_MODULE_ID;
2894 cmd->params.param_id = EQUALIZER_PARAM_ID;
2895 cmd->params.param_size = sizeof(struct asm_equalizer_params);
2896 cmd->params.reserved = 0;
2897 payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command));
2898 equalizer = (struct asm_equalizer_params *)payload;
2899
2900 equalizer->enable = eq_params->enable;
2901 equalizer->num_bands = eq_params->num_bands;
2902 pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
2903 eq_params->num_bands);
2904 for (i = 0; i < eq_params->num_bands; i++) {
2905 equalizer->eq_bands[i].band_idx =
2906 eq_params->eq_bands[i].band_idx;
2907 equalizer->eq_bands[i].filter_type =
2908 eq_params->eq_bands[i].filter_type;
2909 equalizer->eq_bands[i].center_freq_hz =
2910 eq_params->eq_bands[i].center_freq_hz;
2911 equalizer->eq_bands[i].filter_gain =
2912 eq_params->eq_bands[i].filter_gain;
2913 equalizer->eq_bands[i].q_factor =
2914 eq_params->eq_bands[i].q_factor;
2915 pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
2916 eq_params->eq_bands[i].filter_type, i);
2917 pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
2918 eq_params->eq_bands[i].center_freq_hz, i);
2919 pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
2920 eq_params->eq_bands[i].filter_gain, i);
2921 pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
2922 eq_params->eq_bands[i].q_factor, i);
2923 }
2924 rc = apr_send_pkt(ac->apr, (uint32_t *) eq_cmd);
2925 if (rc < 0) {
2926 pr_err("%s: Equalizer Command failed\n", __func__);
2927 rc = -EINVAL;
2928 goto fail_cmd;
2929 }
2930
2931 rc = wait_event_timeout(ac->cmd_wait,
2932 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2933 if (!rc) {
2934 pr_err("%s: timeout in sending equalizer command to apr\n",
2935 __func__);
2936 rc = -EINVAL;
2937 goto fail_cmd;
2938 }
2939 rc = 0;
2940fail_cmd:
2941 kfree(eq_cmd);
2942 return rc;
2943}
2944
2945int q6asm_read(struct audio_client *ac)
2946{
2947 struct asm_stream_cmd_read read;
2948 struct audio_buffer *ab;
2949 int dsp_buf;
2950 struct audio_port_data *port;
2951 int rc;
2952 if (!ac || ac->apr == NULL) {
2953 pr_err("APR handle NULL\n");
2954 return -EINVAL;
2955 }
2956 if (ac->io_mode == SYNC_IO_MODE) {
2957 port = &ac->port[OUT];
2958
2959 q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
2960
2961 mutex_lock(&port->lock);
2962
2963 dsp_buf = port->dsp_buf;
2964 ab = &port->buf[dsp_buf];
2965
2966 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
2967 __func__,
2968 ac->session,
2969 dsp_buf,
2970 (void *)port->buf[dsp_buf].data,
2971 port->cpu_buf,
2972 (void *)port->buf[port->cpu_buf].phys);
2973
2974 read.hdr.opcode = ASM_DATA_CMD_READ;
2975 read.buf_add = ab->phys;
2976 read.buf_size = ab->size;
2977 read.uid = port->dsp_buf;
2978 read.hdr.token = port->dsp_buf;
2979
2980 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
2981 mutex_unlock(&port->lock);
2982 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
2983 read.buf_add,
2984 read.hdr.token,
2985 read.uid);
2986 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
2987 if (rc < 0) {
2988 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
2989 goto fail_cmd;
2990 }
2991 return 0;
2992 }
2993fail_cmd:
2994 return -EINVAL;
2995}
2996
2997int q6asm_read_nolock(struct audio_client *ac)
2998{
2999 struct asm_stream_cmd_read read;
3000 struct audio_buffer *ab;
3001 int dsp_buf;
3002 struct audio_port_data *port;
3003 int rc;
3004 if (!ac || ac->apr == NULL) {
3005 pr_err("APR handle NULL\n");
3006 return -EINVAL;
3007 }
3008 if (ac->io_mode == SYNC_IO_MODE) {
3009 port = &ac->port[OUT];
3010
3011 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3012
3013
3014 dsp_buf = port->dsp_buf;
3015 ab = &port->buf[dsp_buf];
3016
3017 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3018 __func__,
3019 ac->session,
3020 dsp_buf,
3021 (void *)port->buf[dsp_buf].data,
3022 port->cpu_buf,
3023 (void *)port->buf[port->cpu_buf].phys);
3024
3025 read.hdr.opcode = ASM_DATA_CMD_READ;
3026 read.buf_add = ab->phys;
3027 read.buf_size = ab->size;
3028 read.uid = port->dsp_buf;
3029 read.hdr.token = port->dsp_buf;
3030
3031 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3032 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3033 read.buf_add,
3034 read.hdr.token,
3035 read.uid);
3036 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3037 if (rc < 0) {
3038 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3039 goto fail_cmd;
3040 }
3041 return 0;
3042 }
3043fail_cmd:
3044 return -EINVAL;
3045}
3046
3047
3048static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
3049 uint32_t pkt_size, uint32_t cmd_flg)
3050{
3051 pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg,
3052 ac->session);
3053 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
3054 APR_HDR_LEN(sizeof(struct apr_hdr)),\
3055 APR_PKT_VER);
3056 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
3057 hdr->src_domain = APR_DOMAIN_APPS;
3058 hdr->dest_svc = APR_SVC_ASM;
3059 hdr->dest_domain = APR_DOMAIN_ADSP;
3060 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
3061 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
3062 if (cmd_flg) {
3063 hdr->token = ac->session;
3064 atomic_set(&ac->cmd_state, 1);
3065 }
3066 hdr->pkt_size = pkt_size;
3067 return;
3068}
3069
3070int q6asm_async_write(struct audio_client *ac,
3071 struct audio_aio_write_param *param)
3072{
3073 int rc = 0;
3074 struct asm_stream_cmd_write write;
3075
3076 if (!ac || ac->apr == NULL) {
3077 pr_err("%s: APR handle NULL\n", __func__);
3078 return -EINVAL;
3079 }
3080
3081 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE);
3082
3083 /* Pass physical address as token for AIO scheme */
3084 write.hdr.token = param->uid;
3085 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3086 write.buf_add = param->paddr;
3087 write.avail_bytes = param->len;
3088 write.uid = param->uid;
3089 write.msw_ts = param->msw_ts;
3090 write.lsw_ts = param->lsw_ts;
3091 /* Use 0xFF00 for disabling timestamps */
3092 if (param->flags == 0xFF00)
3093 write.uflags = (0x00000000 | (param->flags & 0x800000FF));
3094 else
3095 write.uflags = (0x80000000 | param->flags);
3096
3097 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3098 write.buf_add, write.avail_bytes);
3099
3100 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3101 if (rc < 0) {
3102 pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__,
3103 write.hdr.opcode, rc);
3104 goto fail_cmd;
3105 }
3106 return 0;
3107fail_cmd:
3108 return -EINVAL;
3109}
3110
3111int q6asm_async_read(struct audio_client *ac,
3112 struct audio_aio_read_param *param)
3113{
3114 int rc = 0;
3115 struct asm_stream_cmd_read read;
3116
3117 if (!ac || ac->apr == NULL) {
3118 pr_err("%s: APR handle NULL\n", __func__);
3119 return -EINVAL;
3120 }
3121
3122 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3123
3124 /* Pass physical address as token for AIO scheme */
3125 read.hdr.token = param->paddr;
3126 read.hdr.opcode = ASM_DATA_CMD_READ;
3127 read.buf_add = param->paddr;
3128 read.buf_size = param->len;
3129 read.uid = param->uid;
3130
3131 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3132 read.buf_add, read.buf_size);
3133
3134 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3135 if (rc < 0) {
3136 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3137 read.hdr.opcode, rc);
3138 goto fail_cmd;
3139 }
3140 return 0;
3141fail_cmd:
3142 return -EINVAL;
3143}
3144
3145int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3146 uint32_t lsw_ts, uint32_t flags)
3147{
3148 int rc = 0;
3149 struct asm_stream_cmd_write write;
3150 struct audio_port_data *port;
3151 struct audio_buffer *ab;
3152 int dsp_buf = 0;
3153
3154 if (!ac || ac->apr == NULL) {
3155 pr_err("APR handle NULL\n");
3156 return -EINVAL;
3157 }
3158 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3159 if (ac->io_mode == SYNC_IO_MODE) {
3160 port = &ac->port[IN];
3161
3162 q6asm_add_hdr(ac, &write.hdr, sizeof(write),
3163 FALSE);
3164 mutex_lock(&port->lock);
3165
3166 dsp_buf = port->dsp_buf;
3167 ab = &port->buf[dsp_buf];
3168
3169 write.hdr.token = port->dsp_buf;
3170 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3171 write.buf_add = ab->phys;
3172 write.avail_bytes = len;
3173 write.uid = port->dsp_buf;
3174 write.msw_ts = msw_ts;
3175 write.lsw_ts = lsw_ts;
3176 /* Use 0xFF00 for disabling timestamps */
3177 if (flags == 0xFF00)
3178 write.uflags = (0x00000000 | (flags & 0x800000FF));
3179 else
3180 write.uflags = (0x80000000 | flags);
3181 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3182
3183 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3184 , __func__,
3185 ab->phys,
3186 write.buf_add,
3187 write.hdr.token,
3188 write.uid);
3189 mutex_unlock(&port->lock);
Rajesha Kini3498c932011-07-19 19:58:27 +05303190#ifdef CONFIG_DEBUG_FS
3191 if (out_enable_flag) {
3192 char zero_pattern[2] = {0x00, 0x00};
3193 /* If First two byte is non zero and last two byte
3194 is zero then it is warm output pattern */
3195 if ((strncmp(((char *)ab->data), zero_pattern, 2)) &&
3196 (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3197 do_gettimeofday(&out_warm_tv);
3198 pr_debug("WARM:apr_send_pkt at \
3199 %ld sec %ld microsec\n", out_warm_tv.tv_sec,\
3200 out_warm_tv.tv_usec);
3201 pr_debug("Warm Pattern Matched");
3202 }
3203 /* If First two byte is zero and last two byte is
3204 non zero then it is cont ouput pattern */
3205 else if ((!strncmp(((char *)ab->data), zero_pattern, 2))
3206 && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3207 do_gettimeofday(&out_cont_tv);
3208 pr_debug("CONT:apr_send_pkt at \
3209 %ld sec %ld microsec\n", out_cont_tv.tv_sec,\
3210 out_cont_tv.tv_usec);
3211 pr_debug("Cont Pattern Matched");
3212 }
3213 }
3214#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003215 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3216 if (rc < 0) {
3217 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3218 goto fail_cmd;
3219 }
3220 pr_debug("%s: WRITE SUCCESS\n", __func__);
3221 return 0;
3222 }
3223fail_cmd:
3224 return -EINVAL;
3225}
3226
3227int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3228 uint32_t lsw_ts, uint32_t flags)
3229{
3230 int rc = 0;
3231 struct asm_stream_cmd_write write;
3232 struct audio_port_data *port;
3233 struct audio_buffer *ab;
3234 int dsp_buf = 0;
3235
3236 if (!ac || ac->apr == NULL) {
3237 pr_err("APR handle NULL\n");
3238 return -EINVAL;
3239 }
3240 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3241 if (ac->io_mode == SYNC_IO_MODE) {
3242 port = &ac->port[IN];
3243
3244 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
3245 FALSE);
3246
3247 dsp_buf = port->dsp_buf;
3248 ab = &port->buf[dsp_buf];
3249
3250 write.hdr.token = port->dsp_buf;
3251 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3252 write.buf_add = ab->phys;
3253 write.avail_bytes = len;
3254 write.uid = port->dsp_buf;
3255 write.msw_ts = msw_ts;
3256 write.lsw_ts = lsw_ts;
3257 /* Use 0xFF00 for disabling timestamps */
3258 if (flags == 0xFF00)
3259 write.uflags = (0x00000000 | (flags & 0x800000FF));
3260 else
3261 write.uflags = (0x80000000 | flags);
3262 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3263
3264 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3265 , __func__,
3266 ab->phys,
3267 write.buf_add,
3268 write.hdr.token,
3269 write.uid);
3270
3271 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3272 if (rc < 0) {
3273 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3274 goto fail_cmd;
3275 }
3276 pr_debug("%s: WRITE SUCCESS\n", __func__);
3277 return 0;
3278 }
3279fail_cmd:
3280 return -EINVAL;
3281}
3282
3283uint64_t q6asm_get_session_time(struct audio_client *ac)
3284{
3285 struct apr_hdr hdr;
3286 int rc;
3287
3288 if (!ac || ac->apr == NULL) {
3289 pr_err("APR handle NULL\n");
3290 return -EINVAL;
3291 }
3292 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3293 hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME;
3294 atomic_set(&ac->time_flag, 1);
3295
3296 pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
3297 ac->session,
3298 hdr.opcode);
3299 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3300 if (rc < 0) {
3301 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3302 goto fail_cmd;
3303 }
3304 rc = wait_event_timeout(ac->time_wait,
3305 (atomic_read(&ac->time_flag) == 0), 5*HZ);
3306 if (!rc) {
3307 pr_err("%s: timeout in getting session time from DSP\n",
3308 __func__);
3309 goto fail_cmd;
3310 }
3311 return ac->time_stamp;
3312
3313fail_cmd:
3314 return -EINVAL;
3315}
3316
3317int q6asm_cmd(struct audio_client *ac, int cmd)
3318{
3319 struct apr_hdr hdr;
3320 int rc;
3321 atomic_t *state;
3322 int cnt = 0;
3323
3324 if (!ac || ac->apr == NULL) {
3325 pr_err("APR handle NULL\n");
3326 return -EINVAL;
3327 }
3328 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3329 switch (cmd) {
3330 case CMD_PAUSE:
3331 pr_debug("%s:CMD_PAUSE\n", __func__);
3332 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3333 state = &ac->cmd_state;
3334 break;
3335 case CMD_FLUSH:
3336 pr_debug("%s:CMD_FLUSH\n", __func__);
3337 hdr.opcode = ASM_STREAM_CMD_FLUSH;
3338 state = &ac->cmd_state;
3339 break;
3340 case CMD_OUT_FLUSH:
3341 pr_debug("%s:CMD_OUT_FLUSH\n", __func__);
3342 hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
3343 state = &ac->cmd_state;
3344 break;
3345 case CMD_EOS:
3346 pr_debug("%s:CMD_EOS\n", __func__);
3347 hdr.opcode = ASM_DATA_CMD_EOS;
3348 atomic_set(&ac->cmd_state, 0);
3349 state = &ac->cmd_state;
3350 break;
3351 case CMD_CLOSE:
3352 pr_debug("%s:CMD_CLOSE\n", __func__);
3353 hdr.opcode = ASM_STREAM_CMD_CLOSE;
3354 state = &ac->cmd_state;
3355 break;
3356 default:
3357 pr_err("Invalid format[%d]\n", cmd);
3358 goto fail_cmd;
3359 }
3360 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3361 ac->session,
3362 hdr.opcode);
3363 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3364 if (rc < 0) {
3365 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3366 goto fail_cmd;
3367 }
3368 rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ);
3369 if (!rc) {
3370 pr_err("timeout. waited for response opcode[0x%x]\n",
3371 hdr.opcode);
3372 goto fail_cmd;
3373 }
3374 if (cmd == CMD_FLUSH)
3375 q6asm_reset_buf_state(ac);
3376 if (cmd == CMD_CLOSE) {
3377 /* check if DSP return all buffers */
3378 if (ac->port[IN].buf) {
3379 for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
3380 cnt++) {
3381 if (ac->port[IN].buf[cnt].used == IN) {
3382 pr_debug("Write Buf[%d] not returned\n",
3383 cnt);
3384 }
3385 }
3386 }
3387 if (ac->port[OUT].buf) {
3388 for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
3389 if (ac->port[OUT].buf[cnt].used == OUT) {
3390 pr_debug("Read Buf[%d] not returned\n",
3391 cnt);
3392 }
3393 }
3394 }
3395 }
3396 return 0;
3397fail_cmd:
3398 return -EINVAL;
3399}
3400
3401int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
3402{
3403 struct apr_hdr hdr;
3404 int rc;
3405
3406 if (!ac || ac->apr == NULL) {
3407 pr_err("%s:APR handle NULL\n", __func__);
3408 return -EINVAL;
3409 }
3410 q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE);
3411 switch (cmd) {
3412 case CMD_PAUSE:
3413 pr_debug("%s:CMD_PAUSE\n", __func__);
3414 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3415 break;
3416 case CMD_EOS:
3417 pr_debug("%s:CMD_EOS\n", __func__);
3418 hdr.opcode = ASM_DATA_CMD_EOS;
3419 break;
3420 default:
3421 pr_err("%s:Invalid format[%d]\n", __func__, cmd);
3422 goto fail_cmd;
3423 }
3424 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3425 ac->session,
3426 hdr.opcode);
3427 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3428 if (rc < 0) {
3429 pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
3430 goto fail_cmd;
3431 }
3432 return 0;
3433fail_cmd:
3434 return -EINVAL;
3435}
3436
3437static void q6asm_reset_buf_state(struct audio_client *ac)
3438{
3439 int cnt = 0;
3440 int loopcnt = 0;
3441 struct audio_port_data *port = NULL;
3442
3443 if (ac->io_mode == SYNC_IO_MODE) {
3444 mutex_lock(&ac->cmd_lock);
3445 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
3446 port = &ac->port[loopcnt];
3447 cnt = port->max_buf_cnt - 1;
3448 port->dsp_buf = 0;
3449 port->cpu_buf = 0;
3450 while (cnt >= 0) {
3451 if (!port->buf)
3452 continue;
3453 port->buf[cnt].used = 1;
3454 cnt--;
3455 }
3456 }
3457 mutex_unlock(&ac->cmd_lock);
3458 }
3459}
3460
3461int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
3462{
3463 struct asm_stream_cmd_reg_tx_overflow_event tx_overflow;
3464 int rc;
3465
3466 if (!ac || ac->apr == NULL) {
3467 pr_err("APR handle NULL\n");
3468 return -EINVAL;
3469 }
3470 pr_debug("%s:session[%d]enable[%d]\n", __func__,
3471 ac->session, enable);
3472 q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
3473
3474 tx_overflow.hdr.opcode = \
3475 ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS;
3476 /* tx overflow event: enable */
3477 tx_overflow.enable = enable;
3478
3479 rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
3480 if (rc < 0) {
3481 pr_err("tx overflow op[0x%x]rc[%d]\n", \
3482 tx_overflow.hdr.opcode, rc);
3483 goto fail_cmd;
3484 }
3485 rc = wait_event_timeout(ac->cmd_wait,
3486 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3487 if (!rc) {
3488 pr_err("timeout. waited for tx overflow\n");
3489 goto fail_cmd;
3490 }
3491 return 0;
3492fail_cmd:
3493 return -EINVAL;
3494}
3495
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003496int q6asm_get_apr_service_id(int session_id)
3497{
3498 pr_debug("%s\n", __func__);
3499
Shiv Maliyappanahallia84982a2012-01-19 15:25:04 -08003500 if (session_id < 0 || session_id > SESSION_MAX) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003501 pr_err("%s: invalid session_id = %d\n", __func__, session_id);
3502 return -EINVAL;
3503 }
3504
3505 return ((struct apr_svc *)session[session_id]->apr)->id;
3506}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003507
3508
3509static int __init q6asm_init(void)
3510{
3511 pr_debug("%s\n", __func__);
3512 init_waitqueue_head(&this_mmap.cmd_wait);
3513 memset(session, 0, sizeof(session));
Rajesha Kini3498c932011-07-19 19:58:27 +05303514#ifdef CONFIG_DEBUG_FS
3515 out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
3516 out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
3517 S_IFREG | S_IRUGO | S_IWUGO,\
3518 NULL, NULL, &audio_output_latency_debug_fops);
3519 if (IS_ERR(out_dentry))
3520 pr_err("debugfs_create_file failed\n");
3521 in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
3522 in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
3523 S_IFREG | S_IRUGO | S_IWUGO,\
3524 NULL, NULL, &audio_input_latency_debug_fops);
3525 if (IS_ERR(in_dentry))
3526 pr_err("debugfs_create_file failed\n");
3527#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003528 return 0;
3529}
3530
3531device_initcall(q6asm_init);