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