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