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