blob: 512127cde3b9674029fdde0f77dd84ecd0e410ec [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/*
Patrick Lai3aabeae2013-01-06 00:52:34 -08002 * Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003 * Author: Brian Swetland <swetland@google.com>
4 *
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 */
15#include <linux/fs.h>
16#include <linux/mutex.h>
17#include <linux/wait.h>
18#include <linux/miscdevice.h>
19#include <linux/uaccess.h>
20#include <linux/sched.h>
21#include <linux/dma-mapping.h>
22#include <linux/miscdevice.h>
23#include <linux/delay.h>
24#include <linux/spinlock.h>
25#include <linux/slab.h>
26#include <linux/msm_audio.h>
27#include <linux/android_pmem.h>
28#include <linux/memory_alloc.h>
Ben Rombergerfce8f512011-07-18 16:46:09 -070029#include <linux/debugfs.h>
30#include <linux/time.h>
31#include <linux/atomic.h>
32
33#include <asm/ioctls.h>
34
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070035#include <mach/memory.h>
36#include <mach/debug_mm.h>
37#include <mach/peripheral-loader.h>
38#include <mach/qdsp6v2/audio_acdb.h>
39#include <mach/qdsp6v2/rtac.h>
Ben Rombergerfce8f512011-07-18 16:46:09 -070040
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070041#include <sound/apr_audio.h>
42#include <sound/q6asm.h>
Ben Rombergerfce8f512011-07-18 16:46:09 -070043
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070044
45#define TRUE 0x01
46#define FALSE 0x00
47#define READDONE_IDX_STATUS 0
48#define READDONE_IDX_BUFFER 1
49#define READDONE_IDX_SIZE 2
50#define READDONE_IDX_OFFSET 3
51#define READDONE_IDX_MSW_TS 4
52#define READDONE_IDX_LSW_TS 5
53#define READDONE_IDX_FLAGS 6
54#define READDONE_IDX_NUMFRAMES 7
55#define READDONE_IDX_ID 8
Rajesha Kini3498c932011-07-19 19:58:27 +053056#ifdef CONFIG_DEBUG_FS
57#define OUT_BUFFER_SIZE 56
58#define IN_BUFFER_SIZE 24
59#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070060static DEFINE_MUTEX(session_lock);
61
62/* session id: 0 reserved */
63static struct audio_client *session[SESSION_MAX+1];
64static int32_t q6asm_mmapcallback(struct apr_client_data *data, void *priv);
65static int32_t q6asm_callback(struct apr_client_data *data, void *priv);
66static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
67 uint32_t pkt_size, uint32_t cmd_flg);
68static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
69 uint32_t pkt_size, uint32_t cmd_flg);
70static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
71 uint32_t bufsz, uint32_t bufcnt);
72static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
73 uint32_t bufsz, uint32_t bufcnt);
74
75static void q6asm_reset_buf_state(struct audio_client *ac);
76
Rajesha Kini3498c932011-07-19 19:58:27 +053077#ifdef CONFIG_DEBUG_FS
78static struct timeval out_cold_tv;
79static struct timeval out_warm_tv;
80static struct timeval out_cont_tv;
81static struct timeval in_cont_tv;
82static long out_enable_flag;
83static long in_enable_flag;
84static struct dentry *out_dentry;
85static struct dentry *in_dentry;
86static int in_cont_index;
87/*This var is used to keep track of first write done for cold output latency */
88static int out_cold_index;
89static char *out_buffer;
90static char *in_buffer;
91static int audio_output_latency_dbgfs_open(struct inode *inode,
92 struct file *file)
93{
94 file->private_data = inode->i_private;
95 return 0;
96}
97static ssize_t audio_output_latency_dbgfs_read(struct file *file,
98 char __user *buf, size_t count, loff_t *ppos)
99{
100 snprintf(out_buffer, OUT_BUFFER_SIZE, "%ld,%ld,%ld,%ld,%ld,%ld,",\
101 out_cold_tv.tv_sec, out_cold_tv.tv_usec, out_warm_tv.tv_sec,\
102 out_warm_tv.tv_usec, out_cont_tv.tv_sec, out_cont_tv.tv_usec);
103 return simple_read_from_buffer(buf, OUT_BUFFER_SIZE, ppos,
104 out_buffer, OUT_BUFFER_SIZE);
105}
106static ssize_t audio_output_latency_dbgfs_write(struct file *file,
107 const char __user *buf, size_t count, loff_t *ppos)
108{
109 char *temp;
110
111 if (count > 2*sizeof(char))
112 return -EINVAL;
113 else
114 temp = kmalloc(2*sizeof(char), GFP_KERNEL);
115
116 out_cold_index = 0;
117
118 if (temp) {
119 if (copy_from_user(temp, buf, 2*sizeof(char))) {
120 kfree(temp);
121 return -EFAULT;
122 }
123 if (!strict_strtol(temp, 10, &out_enable_flag)) {
124 kfree(temp);
125 return count;
126 }
127 kfree(temp);
128 }
129 return -EINVAL;
130}
131static const struct file_operations audio_output_latency_debug_fops = {
132 .open = audio_output_latency_dbgfs_open,
133 .read = audio_output_latency_dbgfs_read,
134 .write = audio_output_latency_dbgfs_write
135};
136
137static int audio_input_latency_dbgfs_open(struct inode *inode,
138 struct file *file)
139{
140 file->private_data = inode->i_private;
141 return 0;
142}
143static ssize_t audio_input_latency_dbgfs_read(struct file *file,
144 char __user *buf, size_t count, loff_t *ppos)
145{
146 snprintf(in_buffer, IN_BUFFER_SIZE, "%ld,%ld,",\
147 in_cont_tv.tv_sec, in_cont_tv.tv_usec);
148 return simple_read_from_buffer(buf, IN_BUFFER_SIZE, ppos,
149 in_buffer, IN_BUFFER_SIZE);
150}
151static ssize_t audio_input_latency_dbgfs_write(struct file *file,
152 const char __user *buf, size_t count, loff_t *ppos)
153{
154 char *temp;
155
156 if (count > 2*sizeof(char))
157 return -EINVAL;
158 else
159 temp = kmalloc(2*sizeof(char), GFP_KERNEL);
160 if (temp) {
161 if (copy_from_user(temp, buf, 2*sizeof(char))) {
162 kfree(temp);
163 return -EFAULT;
164 }
165 if (!strict_strtol(temp, 10, &in_enable_flag)) {
166 kfree(temp);
167 return count;
168 }
169 kfree(temp);
170 }
171 return -EINVAL;
172}
173static const struct file_operations audio_input_latency_debug_fops = {
174 .open = audio_input_latency_dbgfs_open,
175 .read = audio_input_latency_dbgfs_read,
176 .write = audio_input_latency_dbgfs_write
177};
178#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700179struct asm_mmap {
180 atomic_t ref_cnt;
181 atomic_t cmd_state;
182 wait_queue_head_t cmd_wait;
183 void *apr;
184};
185
186static struct asm_mmap this_mmap;
187
188static int q6asm_session_alloc(struct audio_client *ac)
189{
190 int n;
191 mutex_lock(&session_lock);
192 for (n = 1; n <= SESSION_MAX; n++) {
193 if (!session[n]) {
194 session[n] = ac;
195 mutex_unlock(&session_lock);
196 return n;
197 }
198 }
199 mutex_unlock(&session_lock);
200 return -ENOMEM;
201}
202
203static void q6asm_session_free(struct audio_client *ac)
204{
205 pr_debug("%s: sessionid[%d]\n", __func__, ac->session);
Ben Romberger93d4d2d2011-10-19 23:04:02 -0700206 rtac_remove_popp_from_adm_devices(ac->session);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700207 mutex_lock(&session_lock);
208 session[ac->session] = 0;
209 mutex_unlock(&session_lock);
210 ac->session = 0;
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700211 ac->perf_mode = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700212 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);
Patrick Lai55f54c52012-11-17 00:29:07 -0800223 if (ac->io_mode & SYNC_IO_MODE) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700224 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);
Patrick Lai55f54c52012-11-17 00:29:07 -0800354 if (ac->io_mode & SYNC_IO_MODE) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700355 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 }
Patrick Lai55f54c52012-11-17 00:29:07 -0800389
390 if (mode == ASYNC_IO_MODE) {
391 ac->io_mode &= ~SYNC_IO_MODE;
392 ac->io_mode |= ASYNC_IO_MODE;
393 } else if (mode == SYNC_IO_MODE) {
394 ac->io_mode &= ~ASYNC_IO_MODE;
395 ac->io_mode |= SYNC_IO_MODE;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700396 } else {
397 pr_err("%s:Not an valid IO Mode:%d\n", __func__, ac->io_mode);
398 return -EINVAL;
399 }
Patrick Lai55f54c52012-11-17 00:29:07 -0800400
401 pr_debug("%s:Set Mode to %d\n", __func__, ac->io_mode);
402 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700403}
404
405struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv)
406{
407 struct audio_client *ac;
408 int n;
409 int lcnt = 0;
410
411 ac = kzalloc(sizeof(struct audio_client), GFP_KERNEL);
412 if (!ac)
413 return NULL;
414 n = q6asm_session_alloc(ac);
415 if (n <= 0)
416 goto fail_session;
417 ac->session = n;
418 ac->cb = cb;
419 ac->priv = priv;
420 ac->io_mode = SYNC_IO_MODE;
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700421 ac->perf_mode = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700422 ac->apr = apr_register("ADSP", "ASM", \
423 (apr_fn)q6asm_callback,\
424 ((ac->session) << 8 | 0x0001),\
425 ac);
426
427 if (ac->apr == NULL) {
428 pr_err("%s Registration with APR failed\n", __func__);
429 goto fail;
430 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700431 rtac_set_asm_handle(n, ac->apr);
Ben Rombergerfce8f512011-07-18 16:46:09 -0700432
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700433 pr_debug("%s Registering the common port with APR\n", __func__);
434 if (atomic_read(&this_mmap.ref_cnt) == 0) {
435 this_mmap.apr = apr_register("ADSP", "ASM", \
436 (apr_fn)q6asm_mmapcallback,\
437 0x0FFFFFFFF, &this_mmap);
438 if (this_mmap.apr == NULL) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700439 pr_debug("%s Unable to register APR ASM common port\n",
440 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700441 goto fail;
442 }
443 }
444
445 atomic_inc(&this_mmap.ref_cnt);
446 init_waitqueue_head(&ac->cmd_wait);
447 init_waitqueue_head(&ac->time_wait);
448 atomic_set(&ac->time_flag, 1);
449 mutex_init(&ac->cmd_lock);
450 for (lcnt = 0; lcnt <= OUT; lcnt++) {
451 mutex_init(&ac->port[lcnt].lock);
452 spin_lock_init(&ac->port[lcnt].dsp_lock);
453 }
454 atomic_set(&ac->cmd_state, 0);
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530455 atomic_set(&ac->cmd_response, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700456
457 pr_debug("%s: session[%d]\n", __func__, ac->session);
458
459 return ac;
460fail:
461 q6asm_audio_client_free(ac);
462 return NULL;
463fail_session:
464 kfree(ac);
465 return NULL;
466}
467
Ben Romberger61754dc2011-10-31 18:25:41 -0700468struct audio_client *q6asm_get_audio_client(int session_id)
469{
470 if ((session_id <= 0) || (session_id > SESSION_MAX)) {
471 pr_err("%s: invalid session: %d\n", __func__, session_id);
472 goto err;
473 }
474
475 if (!session[session_id]) {
476 pr_err("%s: session not active: %d\n", __func__, session_id);
477 goto err;
478 }
479
480 return session[session_id];
481err:
482 return NULL;
483}
484
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700485int q6asm_audio_client_buf_alloc(unsigned int dir,
486 struct audio_client *ac,
487 unsigned int bufsz,
488 unsigned int bufcnt)
489{
490 int cnt = 0;
491 int rc = 0;
492 struct audio_buffer *buf;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800493#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
494 int len;
495#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700496
497 if (!(ac) || ((dir != IN) && (dir != OUT)))
498 return -EINVAL;
499
500 pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n", __func__, ac->session,
501 bufsz, bufcnt);
502
503 if (ac->session <= 0 || ac->session > 8)
504 goto fail;
505
Patrick Lai55f54c52012-11-17 00:29:07 -0800506 if (ac->io_mode & SYNC_IO_MODE) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700507 if (ac->port[dir].buf) {
508 pr_debug("%s: buffer already allocated\n", __func__);
509 return 0;
510 }
511 mutex_lock(&ac->cmd_lock);
512 buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
513 GFP_KERNEL);
514
515 if (!buf) {
516 mutex_unlock(&ac->cmd_lock);
517 goto fail;
518 }
519
520 ac->port[dir].buf = buf;
521
522 while (cnt < bufcnt) {
523 if (bufsz > 0) {
524 if (!buf[cnt].data) {
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800525#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
526 buf[cnt].client = msm_ion_client_create
527 (UINT_MAX, "audio_client");
528 if (IS_ERR_OR_NULL((void *)
529 buf[cnt].client)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700530 pr_err("%s: ION create client for AUDIO failed\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800531 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700532 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800533 goto fail;
534 }
535 buf[cnt].handle = ion_alloc
536 (buf[cnt].client, bufsz, SZ_4K,
Hanumant Singh2ac41c92012-08-29 18:39:44 -0700537 (0x1 << ION_AUDIO_HEAP_ID), 0);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800538 if (IS_ERR_OR_NULL((void *)
539 buf[cnt].handle)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700540 pr_err("%s: ION memory allocation for AUDIO failed\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800541 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700542 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800543 goto fail;
544 }
545
546 rc = ion_phys(buf[cnt].client,
547 buf[cnt].handle,
548 (ion_phys_addr_t *)
549 &buf[cnt].phys,
550 (size_t *)&len);
551 if (rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700552 pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800553 __func__, rc);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700554 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800555 goto fail;
556 }
557
558 buf[cnt].data = ion_map_kernel
Mitchel Humpherys456e2682012-09-12 14:42:50 -0700559 (buf[cnt].client, buf[cnt].handle);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800560 if (IS_ERR_OR_NULL((void *)
561 buf[cnt].data)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700562 pr_err("%s: ION memory mapping for AUDIO failed\n",
563 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700564 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800565 goto fail;
566 }
567 memset((void *)buf[cnt].data, 0, bufsz);
568#else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700569 unsigned int flags = 0;
570 buf[cnt].phys =
571 allocate_contiguous_ebi_nomap(bufsz,
572 SZ_4K);
573 if (!buf[cnt].phys) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700574 pr_err("%s:Buf alloc failed size=%d\n",
575 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700576 bufsz);
577 mutex_unlock(&ac->cmd_lock);
578 goto fail;
579 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700580 buf[cnt].mem_buffer =
Laura Abbottea3e7b62012-04-30 15:59:21 -0700581 ioremap(buf[cnt].phys, bufsz);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700582 if (IS_ERR(
583 (void *)buf[cnt].mem_buffer)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700584 pr_err("%s:map_buffer failed, error = %ld\n",
585 __func__,
586 PTR_ERR((void *)buf[cnt].mem_buffer));
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -0800587 mutex_unlock(&ac->cmd_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700588 goto fail;
589 }
590 buf[cnt].data =
Laura Abbottea3e7b62012-04-30 15:59:21 -0700591 buf[cnt].mem_buffer;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700592 if (!buf[cnt].data) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700593 pr_err("%s:invalid vaddr, iomap failed\n",
594 __func__);
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -0800595 mutex_unlock(&ac->cmd_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700596 goto fail;
597 }
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800598#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700599 buf[cnt].used = 1;
600 buf[cnt].size = bufsz;
601 buf[cnt].actual_size = bufsz;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800602 pr_debug("%s data[%p]phys[%p][%p]\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700603 __func__,
604 (void *)buf[cnt].data,
605 (void *)buf[cnt].phys,
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800606 (void *)&buf[cnt].phys);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700607 cnt++;
608 }
609 }
610 }
611 ac->port[dir].max_buf_cnt = cnt;
612
613 mutex_unlock(&ac->cmd_lock);
614 rc = q6asm_memory_map_regions(ac, dir, bufsz, cnt);
615 if (rc < 0) {
616 pr_err("%s:CMD Memory_map_regions failed\n", __func__);
617 goto fail;
618 }
619 }
620 return 0;
621fail:
622 q6asm_audio_client_buf_free(dir, ac);
623 return -EINVAL;
624}
625
626int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir,
627 struct audio_client *ac,
628 unsigned int bufsz,
629 unsigned int bufcnt)
630{
631 int cnt = 0;
632 int rc = 0;
633 struct audio_buffer *buf;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800634#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
635 int len;
636#else
637 int flags = 0;
638#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700639 if (!(ac) || ((dir != IN) && (dir != OUT)))
640 return -EINVAL;
641
642 pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n",
643 __func__, ac->session,
644 bufsz, bufcnt);
645
646 if (ac->session <= 0 || ac->session > 8)
647 goto fail;
648
649 if (ac->port[dir].buf) {
650 pr_debug("%s: buffer already allocated\n", __func__);
651 return 0;
652 }
653 mutex_lock(&ac->cmd_lock);
654 buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
655 GFP_KERNEL);
656
657 if (!buf) {
658 mutex_unlock(&ac->cmd_lock);
659 goto fail;
660 }
661
662 ac->port[dir].buf = buf;
663
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800664#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
665 buf[0].client = msm_ion_client_create(UINT_MAX, "audio_client");
666 if (IS_ERR_OR_NULL((void *)buf[0].client)) {
667 pr_err("%s: ION create client for AUDIO failed\n", __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700668 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800669 goto fail;
670 }
671 buf[0].handle = ion_alloc(buf[0].client, bufsz * bufcnt, SZ_4K,
Hanumant Singh2ac41c92012-08-29 18:39:44 -0700672 (0x1 << ION_AUDIO_HEAP_ID), 0);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800673 if (IS_ERR_OR_NULL((void *) buf[0].handle)) {
674 pr_err("%s: ION memory allocation for AUDIO failed\n",
675 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700676 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800677 goto fail;
678 }
679
680 rc = ion_phys(buf[0].client, buf[0].handle,
681 (ion_phys_addr_t *)&buf[0].phys, (size_t *)&len);
682 if (rc) {
683 pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
684 __func__, rc);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700685 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800686 goto fail;
687 }
688
Mitchel Humpherys456e2682012-09-12 14:42:50 -0700689 buf[0].data = ion_map_kernel(buf[0].client, buf[0].handle);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800690 if (IS_ERR_OR_NULL((void *) buf[0].data)) {
691 pr_err("%s: ION memory mapping for AUDIO failed\n", __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700692 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800693 goto fail;
694 }
695 memset((void *)buf[0].data, 0, (bufsz * bufcnt));
696#else
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700697 buf[0].phys = allocate_contiguous_ebi_nomap(bufsz * bufcnt,
698 SZ_4K);
699 if (!buf[0].phys) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700700 pr_err("%s:Buf alloc failed size=%d, bufcnt=%d\n",
701 __func__, bufsz, bufcnt);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700702 mutex_unlock(&ac->cmd_lock);
703 goto fail;
704 }
705
Laura Abbottea3e7b62012-04-30 15:59:21 -0700706 buf[0].mem_buffer = ioremap(buf[0].phys, bufsz * bufcnt);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700707 if (IS_ERR((void *)buf[cnt].mem_buffer)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700708 pr_err("%s:map_buffer failed, error = %ld\n",
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700709 __func__, PTR_ERR((void *)buf[0].mem_buffer));
710
711 mutex_unlock(&ac->cmd_lock);
712 goto fail;
713 }
Laura Abbottea3e7b62012-04-30 15:59:21 -0700714 buf[0].data = buf[0].mem_buffer;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800715#endif
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700716 if (!buf[0].data) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700717 pr_err("%s:invalid vaddr, iomap failed\n", __func__);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700718 mutex_unlock(&ac->cmd_lock);
719 goto fail;
720 }
721
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700722 buf[0].used = dir ^ 1;
723 buf[0].size = bufsz;
724 buf[0].actual_size = bufsz;
725 cnt = 1;
726 while (cnt < bufcnt) {
727 if (bufsz > 0) {
728 buf[cnt].data = buf[0].data + (cnt * bufsz);
729 buf[cnt].phys = buf[0].phys + (cnt * bufsz);
730 if (!buf[cnt].data) {
731 pr_err("%s Buf alloc failed\n",
732 __func__);
733 mutex_unlock(&ac->cmd_lock);
734 goto fail;
735 }
736 buf[cnt].used = dir ^ 1;
737 buf[cnt].size = bufsz;
738 buf[cnt].actual_size = bufsz;
739 pr_debug("%s data[%p]phys[%p][%p]\n", __func__,
740 (void *)buf[cnt].data,
741 (void *)buf[cnt].phys,
742 (void *)&buf[cnt].phys);
743 }
744 cnt++;
745 }
746 ac->port[dir].max_buf_cnt = cnt;
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -0700747
748 pr_debug("%s ac->port[%d].max_buf_cnt[%d]\n", __func__, dir,
749 ac->port[dir].max_buf_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700750 mutex_unlock(&ac->cmd_lock);
751 rc = q6asm_memory_map(ac, buf[0].phys, dir, bufsz, cnt);
752 if (rc < 0) {
753 pr_err("%s:CMD Memory_map_regions failed\n", __func__);
754 goto fail;
755 }
756 return 0;
757fail:
758 q6asm_audio_client_buf_free_contiguous(dir, ac);
759 return -EINVAL;
760}
761
762static int32_t q6asm_mmapcallback(struct apr_client_data *data, void *priv)
763{
764 uint32_t token;
765 uint32_t *payload = data->payload;
766
767 if (data->opcode == RESET_EVENTS) {
768 pr_debug("%s: Reset event is received: %d %d apr[%p]\n",
769 __func__,
770 data->reset_event,
771 data->reset_proc,
772 this_mmap.apr);
773 apr_reset(this_mmap.apr);
774 this_mmap.apr = NULL;
775 atomic_set(&this_mmap.cmd_state, 0);
776 return 0;
777 }
778
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700779 pr_debug("%s:ptr0[0x%x]ptr1[0x%x]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n",
780 __func__, payload[0], payload[1], data->opcode, data->token,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700781 data->payload_size, data->src_port, data->dest_port);
782
783 if (data->opcode == APR_BASIC_RSP_RESULT) {
784 token = data->token;
785 switch (payload[0]) {
786 case ASM_SESSION_CMD_MEMORY_MAP:
787 case ASM_SESSION_CMD_MEMORY_UNMAP:
788 case ASM_SESSION_CMD_MEMORY_MAP_REGIONS:
789 case ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS:
790 pr_debug("%s:command[0x%x]success [0x%x]\n",
791 __func__, payload[0], payload[1]);
792 if (atomic_read(&this_mmap.cmd_state)) {
793 atomic_set(&this_mmap.cmd_state, 0);
794 wake_up(&this_mmap.cmd_wait);
795 }
796 break;
797 default:
798 pr_debug("%s:command[0x%x] not expecting rsp\n",
799 __func__, payload[0]);
800 break;
801 }
802 }
803 return 0;
804}
805
Jay Wangcd1d37d2012-10-03 16:17:18 -0700806static int32_t is_no_wait_cmd_rsp(uint32_t opcode, uint32_t *cmd_type)
807{
808 if (opcode == APR_BASIC_RSP_RESULT) {
809 if (cmd_type != NULL) {
810 switch (cmd_type[0]) {
811 case ASM_SESSION_CMD_RUN:
812 case ASM_SESSION_CMD_PAUSE:
813 case ASM_DATA_CMD_EOS:
814 return 1;
815 default:
816 break;
817 }
818 } else
819 pr_err("%s: null pointer!", __func__);
820 } else if (opcode == ASM_DATA_CMDRSP_EOS)
821 return 1;
822
823 return 0;
824}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700825
826static int32_t q6asm_callback(struct apr_client_data *data, void *priv)
827{
828 int i = 0;
829 struct audio_client *ac = (struct audio_client *)priv;
830 uint32_t token;
831 unsigned long dsp_flags;
832 uint32_t *payload;
Jay Wang0668d1062012-07-11 18:53:21 -0700833 uint32_t wakeup_flag = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700834
835
836 if ((ac == NULL) || (data == NULL)) {
837 pr_err("ac or priv NULL\n");
838 return -EINVAL;
839 }
840 if (ac->session <= 0 || ac->session > 8) {
841 pr_err("%s:Session ID is invalid, session = %d\n", __func__,
842 ac->session);
843 return -EINVAL;
844 }
Jay Wangcd1d37d2012-10-03 16:17:18 -0700845
846 payload = data->payload;
847 if ((atomic_read(&ac->nowait_cmd_cnt) > 0) &&
848 is_no_wait_cmd_rsp(data->opcode, payload)) {
Jay Wang0668d1062012-07-11 18:53:21 -0700849 pr_debug("%s: nowait_cmd_cnt %d\n",
850 __func__,
851 atomic_read(&ac->nowait_cmd_cnt));
852 atomic_dec(&ac->nowait_cmd_cnt);
853 wakeup_flag = 0;
854 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700855
856 if (data->opcode == RESET_EVENTS) {
857 pr_debug("q6asm_callback: Reset event is received: %d %d apr[%p]\n",
858 data->reset_event, data->reset_proc, ac->apr);
Laxminath Kasam692c6542012-02-21 11:17:47 +0530859 if (ac->cb)
860 ac->cb(data->opcode, data->token,
861 (uint32_t *)data->payload, ac->priv);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700862 apr_reset(ac->apr);
863 return 0;
864 }
865
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700866 pr_debug("%s: session[%d]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n",
867 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700868 ac->session, data->opcode,
869 data->token, data->payload_size, data->src_port,
870 data->dest_port);
871
872 if (data->opcode == APR_BASIC_RSP_RESULT) {
873 token = data->token;
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700874 pr_debug("%s payload[0]:%x", __func__, payload[0]);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700875 switch (payload[0]) {
876 case ASM_STREAM_CMD_SET_PP_PARAMS:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700877 if (rtac_make_asm_callback(ac->session, payload,
878 data->payload_size))
879 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700880 case ASM_SESSION_CMD_PAUSE:
881 case ASM_DATA_CMD_EOS:
882 case ASM_STREAM_CMD_CLOSE:
883 case ASM_STREAM_CMD_FLUSH:
884 case ASM_SESSION_CMD_RUN:
885 case ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS:
886 case ASM_STREAM_CMD_FLUSH_READBUFS:
887 pr_debug("%s:Payload = [0x%x]\n", __func__, payload[0]);
888 if (token != ac->session) {
889 pr_err("%s:Invalid session[%d] rxed expected[%d]",
890 __func__, token, ac->session);
891 return -EINVAL;
892 }
893 case ASM_STREAM_CMD_OPEN_READ:
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700894 case ASM_STREAM_CMD_OPEN_READ_V2_1:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700895 case ASM_STREAM_CMD_OPEN_WRITE:
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700896 case ASM_STREAM_CMD_OPEN_WRITE_V2_1:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700897 case ASM_STREAM_CMD_OPEN_READWRITE:
Laxminath Kasam20824502013-01-07 14:33:56 +0530898 case ASM_STREAM_CMD_OPEN_LOOPBACK:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700899 case ASM_DATA_CMD_MEDIA_FORMAT_UPDATE:
900 case ASM_STREAM_CMD_SET_ENCDEC_PARAM:
Santosh Mardi23321202012-03-22 04:33:25 +0530901 case ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED:
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -0700902 case ASM_STREAM_CMD_OPEN_READ_COMPRESSED:
Laxminath Kasamf16d3fd2012-12-19 14:54:14 +0530903 if (payload[0] == ASM_STREAM_CMD_CLOSE) {
904 atomic_set(&ac->cmd_close_state, 0);
905 wake_up(&ac->cmd_wait);
906 } else if (atomic_read(&ac->cmd_state) &&
907 wakeup_flag) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700908 atomic_set(&ac->cmd_state, 0);
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700909 if (payload[1] == ADSP_EUNSUPPORTED) {
910 pr_debug("paload[1]:%d unsupported",
911 payload[1]);
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530912 atomic_set(&ac->cmd_response, 1);
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700913 }
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530914 else
915 atomic_set(&ac->cmd_response, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700916 wake_up(&ac->cmd_wait);
917 }
918 if (ac->cb)
919 ac->cb(data->opcode, data->token,
920 (uint32_t *)data->payload, ac->priv);
921 break;
922 default:
923 pr_debug("%s:command[0x%x] not expecting rsp\n",
924 __func__, payload[0]);
925 break;
926 }
927 return 0;
928 }
929
930 switch (data->opcode) {
931 case ASM_DATA_EVENT_WRITE_DONE:{
932 struct audio_port_data *port = &ac->port[IN];
933 pr_debug("%s: Rxed opcode[0x%x] status[0x%x] token[%d]",
934 __func__, payload[0], payload[1],
935 data->token);
Patrick Lai55f54c52012-11-17 00:29:07 -0800936 if (ac->io_mode & SYNC_IO_MODE) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700937 if (port->buf == NULL) {
938 pr_err("%s: Unexpected Write Done\n",
939 __func__);
940 return -EINVAL;
941 }
942 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
943 if (port->buf[data->token].phys !=
944 payload[0]) {
945 pr_err("Buf expected[%p]rxed[%p]\n",\
946 (void *)port->buf[data->token].phys,\
947 (void *)payload[0]);
948 spin_unlock_irqrestore(&port->dsp_lock,
949 dsp_flags);
950 return -EINVAL;
951 }
952 token = data->token;
953 port->buf[token].used = 1;
954 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
Rajesha Kini3498c932011-07-19 19:58:27 +0530955#ifdef CONFIG_DEBUG_FS
956 if (out_enable_flag) {
957 /* For first Write done log the time and reset
958 out_cold_index*/
959 if (out_cold_index != 1) {
960 do_gettimeofday(&out_cold_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700961 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",
962 out_cold_tv.tv_sec,
Rajesha Kini3498c932011-07-19 19:58:27 +0530963 out_cold_tv.tv_usec);
964 out_cold_index = 1;
965 }
966 pr_debug("out_enable_flag %ld",\
967 out_enable_flag);
968 }
969#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700970 for (i = 0; i < port->max_buf_cnt; i++)
971 pr_debug("%d ", port->buf[i].used);
972
973 }
974 break;
975 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700976 case ASM_STREAM_CMDRSP_GET_PP_PARAMS:
977 rtac_make_asm_callback(ac->session, payload,
978 data->payload_size);
979 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700980 case ASM_DATA_EVENT_READ_DONE:{
981
982 struct audio_port_data *port = &ac->port[OUT];
Rajesha Kini3498c932011-07-19 19:58:27 +0530983#ifdef CONFIG_DEBUG_FS
984 if (in_enable_flag) {
985 /* when in_cont_index == 7, DSP would be
986 * writing into the 8th 512 byte buffer and this
987 * timestamp is tapped here.Once done it then writes
988 * to 9th 512 byte buffer.These two buffers(8th, 9th)
989 * reach the test application in 5th iteration and that
990 * timestamp is tapped at user level. The difference
991 * of these two timestamps gives us the time between
992 * the time at which dsp started filling the sample
993 * required and when it reached the test application.
994 * Hence continuous input latency
995 */
996 if (in_cont_index == 7) {
997 do_gettimeofday(&in_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700998 pr_err("In_CONT:previous read buffer done at %ld sec %ld microsec\n",
Sriranjan Srikantam74753532011-10-03 14:48:37 -0700999 in_cont_tv.tv_sec, in_cont_tv.tv_usec);
Rajesha Kini3498c932011-07-19 19:58:27 +05301000 }
1001 }
1002#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001003 pr_debug("%s:R-D: status=%d buff_add=%x act_size=%d offset=%d\n",
1004 __func__, payload[READDONE_IDX_STATUS],
1005 payload[READDONE_IDX_BUFFER],
1006 payload[READDONE_IDX_SIZE],
1007 payload[READDONE_IDX_OFFSET]);
1008 pr_debug("%s:R-D:msw_ts=%d lsw_ts=%d flags=%d id=%d num=%d\n",
1009 __func__, payload[READDONE_IDX_MSW_TS],
1010 payload[READDONE_IDX_LSW_TS],
1011 payload[READDONE_IDX_FLAGS],
1012 payload[READDONE_IDX_ID],
1013 payload[READDONE_IDX_NUMFRAMES]);
Rajesha Kini3498c932011-07-19 19:58:27 +05301014#ifdef CONFIG_DEBUG_FS
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001015 if (in_enable_flag)
Rajesha Kini3498c932011-07-19 19:58:27 +05301016 in_cont_index++;
Rajesha Kini3498c932011-07-19 19:58:27 +05301017#endif
Patrick Lai55f54c52012-11-17 00:29:07 -08001018 if (ac->io_mode & SYNC_IO_MODE) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001019 if (port->buf == NULL) {
1020 pr_err("%s: Unexpected Write Done\n", __func__);
1021 return -EINVAL;
1022 }
1023 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
1024 token = data->token;
1025 port->buf[token].used = 0;
1026 if (port->buf[token].phys !=
1027 payload[READDONE_IDX_BUFFER]) {
1028 pr_err("Buf expected[%p]rxed[%p]\n",\
1029 (void *)port->buf[token].phys,\
1030 (void *)payload[READDONE_IDX_BUFFER]);
1031 spin_unlock_irqrestore(&port->dsp_lock,
1032 dsp_flags);
1033 break;
1034 }
1035 port->buf[token].actual_size =
1036 payload[READDONE_IDX_SIZE];
1037 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
1038 }
1039 break;
1040 }
1041 case ASM_DATA_EVENT_EOS:
1042 case ASM_DATA_CMDRSP_EOS:
1043 pr_debug("%s:EOS ACK received: rxed opcode[0x%x]\n",
1044 __func__, data->opcode);
1045 break;
1046 case ASM_STREAM_CMDRSP_GET_ENCDEC_PARAM:
1047 break;
1048 case ASM_SESSION_EVENT_TX_OVERFLOW:
1049 pr_err("ASM_SESSION_EVENT_TX_OVERFLOW\n");
1050 break;
1051 case ASM_SESSION_CMDRSP_GET_SESSION_TIME:
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001052 pr_debug("%s: ASM_SESSION_CMDRSP_GET_SESSION_TIME, payload[0] = %d, payload[1] = %d, payload[2] = %d\n",
1053 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001054 payload[0], payload[1], payload[2]);
1055 ac->time_stamp = (uint64_t)(((uint64_t)payload[1] << 32) |
1056 payload[2]);
1057 if (atomic_read(&ac->time_flag)) {
1058 atomic_set(&ac->time_flag, 0);
1059 wake_up(&ac->time_wait);
1060 }
1061 break;
1062 case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY:
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301063 case ASM_DATA_EVENT_ENC_SR_CM_NOTIFY:
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001064 pr_debug("%s: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, payload[0] = %d, payload[1] = %d, payload[2] = %d, payload[3] = %d\n",
1065 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001066 payload[0], payload[1], payload[2],
1067 payload[3]);
1068 break;
1069 }
1070 if (ac->cb)
1071 ac->cb(data->opcode, data->token,
1072 data->payload, ac->priv);
1073
1074 return 0;
1075}
1076
1077void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac, uint32_t *size,
1078 uint32_t *index)
1079{
1080 void *data;
1081 unsigned char idx;
1082 struct audio_port_data *port;
1083
1084 if (!ac || ((dir != IN) && (dir != OUT)))
1085 return NULL;
1086
Patrick Lai55f54c52012-11-17 00:29:07 -08001087 if (ac->io_mode & SYNC_IO_MODE) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001088 port = &ac->port[dir];
1089
1090 mutex_lock(&port->lock);
1091 idx = port->cpu_buf;
1092 if (port->buf == NULL) {
1093 pr_debug("%s:Buffer pointer null\n", __func__);
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -08001094 mutex_unlock(&port->lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001095 return NULL;
1096 }
1097 /* dir 0: used = 0 means buf in use
1098 dir 1: used = 1 means buf in use */
1099 if (port->buf[idx].used == dir) {
1100 /* To make it more robust, we could loop and get the
1101 next avail buf, its risky though */
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);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001104 mutex_unlock(&port->lock);
1105 return NULL;
1106 }
1107 *size = port->buf[idx].actual_size;
1108 *index = port->cpu_buf;
1109 data = port->buf[idx].data;
1110 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1111 __func__,
1112 ac->session,
1113 port->cpu_buf,
1114 data, *size);
1115 /* By default increase the cpu_buf cnt
1116 user accesses this function,increase cpu
1117 buf(to avoid another api)*/
1118 port->buf[idx].used = dir;
1119 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1120 mutex_unlock(&port->lock);
1121 return data;
1122 }
1123 return NULL;
1124}
1125
Jay Wang9cf59a02011-08-10 16:58:40 -07001126void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
1127 uint32_t *size, uint32_t *index)
1128{
1129 void *data;
1130 unsigned char idx;
1131 struct audio_port_data *port;
1132
1133 if (!ac || ((dir != IN) && (dir != OUT)))
1134 return NULL;
1135
1136 port = &ac->port[dir];
1137
1138 idx = port->cpu_buf;
1139 if (port->buf == NULL) {
1140 pr_debug("%s:Buffer pointer null\n", __func__);
1141 return NULL;
1142 }
1143 /*
1144 * dir 0: used = 0 means buf in use
1145 * dir 1: used = 1 means buf in use
1146 */
1147 if (port->buf[idx].used == dir) {
1148 /*
1149 * To make it more robust, we could loop and get the
1150 * next avail buf, its risky though
1151 */
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001152 pr_debug("%s:Next buf idx[0x%x] not available, dir[%d]\n",
1153 __func__, idx, dir);
Jay Wang9cf59a02011-08-10 16:58:40 -07001154 return NULL;
1155 }
1156 *size = port->buf[idx].actual_size;
1157 *index = port->cpu_buf;
1158 data = port->buf[idx].data;
1159 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1160 __func__, ac->session, port->cpu_buf,
1161 data, *size);
1162 /*
1163 * By default increase the cpu_buf cnt
1164 * user accesses this function,increase cpu
1165 * buf(to avoid another api)
1166 */
1167 port->buf[idx].used = dir;
1168 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1169 return data;
1170}
1171
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001172int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac)
1173{
1174 int ret = -1;
1175 struct audio_port_data *port;
1176 uint32_t idx;
1177
1178 if (!ac || (dir != OUT))
1179 return ret;
1180
Patrick Lai55f54c52012-11-17 00:29:07 -08001181 if (ac->io_mode & SYNC_IO_MODE) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001182 port = &ac->port[dir];
1183
1184 mutex_lock(&port->lock);
1185 idx = port->dsp_buf;
1186
1187 if (port->buf[idx].used == (dir ^ 1)) {
1188 /* To make it more robust, we could loop and get the
1189 next avail buf, its risky though */
1190 pr_err("Next buf idx[0x%x] not available, dir[%d]\n",
1191 idx, dir);
1192 mutex_unlock(&port->lock);
1193 return ret;
1194 }
1195 pr_debug("%s: session[%d]dsp_buf=%d cpu_buf=%d\n", __func__,
1196 ac->session, port->dsp_buf, port->cpu_buf);
1197 ret = ((port->dsp_buf != port->cpu_buf) ? 0 : -1);
1198 mutex_unlock(&port->lock);
1199 }
1200 return ret;
1201}
1202
1203static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
1204 uint32_t pkt_size, uint32_t cmd_flg)
1205{
1206 pr_debug("%s:session=%d pkt size=%d cmd_flg=%d\n", __func__, pkt_size,
1207 cmd_flg, ac->session);
1208 mutex_lock(&ac->cmd_lock);
1209 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1210 APR_HDR_LEN(sizeof(struct apr_hdr)),\
1211 APR_PKT_VER);
1212 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
1213 hdr->src_domain = APR_DOMAIN_APPS;
1214 hdr->dest_svc = APR_SVC_ASM;
1215 hdr->dest_domain = APR_DOMAIN_ADSP;
1216 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
1217 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
1218 if (cmd_flg) {
1219 hdr->token = ac->session;
1220 atomic_set(&ac->cmd_state, 1);
1221 }
1222 hdr->pkt_size = pkt_size;
1223 mutex_unlock(&ac->cmd_lock);
1224 return;
1225}
1226
1227static void q6asm_add_mmaphdr(struct apr_hdr *hdr, uint32_t pkt_size,
1228 uint32_t cmd_flg)
1229{
1230 pr_debug("%s:pkt size=%d cmd_flg=%d\n", __func__, pkt_size, cmd_flg);
1231 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1232 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1233 hdr->src_port = 0;
1234 hdr->dest_port = 0;
1235 if (cmd_flg) {
1236 hdr->token = 0;
1237 atomic_set(&this_mmap.cmd_state, 1);
1238 }
1239 hdr->pkt_size = pkt_size;
1240 return;
1241}
1242
1243int q6asm_open_read(struct audio_client *ac,
1244 uint32_t format)
1245{
1246 int rc = 0x00;
1247 struct asm_stream_cmd_open_read open;
Rajesha Kini3498c932011-07-19 19:58:27 +05301248#ifdef CONFIG_DEBUG_FS
1249 in_cont_index = 0;
1250#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001251 if ((ac == NULL) || (ac->apr == NULL)) {
1252 pr_err("%s: APR handle NULL\n", __func__);
1253 return -EINVAL;
1254 }
1255 pr_debug("%s:session[%d]", __func__, ac->session);
1256
1257 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1258 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ;
1259 /* Stream prio : High, provide meta info with encoded frames */
1260 open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1261
1262 open.pre_proc_top = get_asm_topology();
1263 if (open.pre_proc_top == 0)
1264 open.pre_proc_top = DEFAULT_POPP_TOPOLOGY;
1265
1266 switch (format) {
1267 case FORMAT_LINEAR_PCM:
1268 open.uMode = STREAM_PRIORITY_HIGH;
1269 open.format = LINEAR_PCM;
1270 break;
Mingming Yin647e9ea2012-03-17 19:56:10 -07001271 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1272 open.uMode = STREAM_PRIORITY_HIGH;
1273 open.format = MULTI_CHANNEL_PCM;
1274 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001275 case FORMAT_MPEG4_AAC:
1276 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1277 open.format = MPEG4_AAC;
1278 break;
1279 case FORMAT_V13K:
1280 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1281 open.format = V13K_FS;
1282 break;
1283 case FORMAT_EVRC:
1284 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1285 open.format = EVRC_FS;
1286 break;
1287 case FORMAT_AMRNB:
1288 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1289 open.format = AMRNB_FS;
1290 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301291 case FORMAT_AMRWB:
1292 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1293 open.format = AMRWB_FS;
1294 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001295 default:
1296 pr_err("Invalid format[%d]\n", format);
1297 goto fail_cmd;
1298 }
1299 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1300 if (rc < 0) {
1301 pr_err("open failed op[0x%x]rc[%d]\n", \
1302 open.hdr.opcode, rc);
1303 goto fail_cmd;
1304 }
1305 rc = wait_event_timeout(ac->cmd_wait,
1306 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1307 if (!rc) {
1308 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1309 rc);
1310 goto fail_cmd;
1311 }
Patrick Lai55f54c52012-11-17 00:29:07 -08001312
1313 ac->io_mode |= TUN_READ_IO_MODE;
1314
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001315 return 0;
1316fail_cmd:
1317 return -EINVAL;
1318}
1319
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -07001320int q6asm_open_read_v2_1(struct audio_client *ac,
1321 uint32_t format)
1322{
1323 int rc = 0x00;
1324 struct asm_stream_cmd_open_read_v2_1 open;
1325#ifdef CONFIG_DEBUG_FS
1326 in_cont_index = 0;
1327#endif
1328 if ((ac == NULL) || (ac->apr == NULL)) {
1329 pr_err("%s: APR handle NULL\n", __func__);
1330 return -EINVAL;
1331 }
1332 pr_debug("%s:session[%d]", __func__, ac->session);
1333
1334 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1335 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_V2_1;
1336 open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1337 open.pre_proc_top = get_asm_topology();
1338 if (open.pre_proc_top == 0)
1339 open.pre_proc_top = DEFAULT_POPP_TOPOLOGY;
1340
1341 switch (format) {
1342 case FORMAT_LINEAR_PCM:
1343 open.uMode = STREAM_PRIORITY_HIGH;
1344 open.format = LINEAR_PCM;
1345 break;
1346 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1347 open.uMode = STREAM_PRIORITY_HIGH;
1348 open.format = MULTI_CHANNEL_PCM;
1349 break;
1350 case FORMAT_MPEG4_AAC:
1351 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1352 open.format = MPEG4_AAC;
1353 break;
1354 case FORMAT_V13K:
1355 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1356 open.format = V13K_FS;
1357 break;
1358 case FORMAT_EVRC:
1359 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1360 open.format = EVRC_FS;
1361 break;
1362 case FORMAT_AMRNB:
1363 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1364 open.format = AMRNB_FS;
1365 break;
1366 case FORMAT_AMRWB:
1367 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1368 open.format = AMRWB_FS;
1369 break;
1370 default:
1371 pr_err("Invalid format[%d]\n", format);
1372 goto fail_cmd;
1373 }
1374 open.uMode = ASM_OPEN_READ_PERF_MODE_BIT;
1375 open.bits_per_sample = PCM_BITS_PER_SAMPLE;
1376 open.reserved = 0;
1377 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1378 if (rc < 0) {
1379 pr_err("open failed op[0x%x]rc[%d]\n", \
1380 open.hdr.opcode, rc);
1381 goto fail_cmd;
1382 }
1383 rc = wait_event_timeout(ac->cmd_wait,
1384 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1385 if (!rc) {
1386 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1387 rc);
1388 goto fail_cmd;
1389 }
1390 return 0;
1391fail_cmd:
1392 return -EINVAL;
1393}
1394
1395
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07001396int q6asm_open_read_compressed(struct audio_client *ac,
1397 uint32_t frames_per_buffer, uint32_t meta_data_mode)
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -07001398{
1399 int rc = 0x00;
1400 struct asm_stream_cmd_open_read_compressed open;
1401#ifdef CONFIG_DEBUG_FS
1402 in_cont_index = 0;
1403#endif
1404 if ((ac == NULL) || (ac->apr == NULL)) {
1405 pr_err("%s: APR handle NULL\n", __func__);
1406 return -EINVAL;
1407 }
1408 pr_debug("%s:session[%d]", __func__, ac->session);
1409
1410 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1411 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_COMPRESSED;
1412 /* hardcoded as following*/
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07001413 open.frame_per_buf = frames_per_buffer;
1414 open.uMode = meta_data_mode;
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -07001415
1416 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1417 if (rc < 0) {
1418 pr_err("open failed op[0x%x]rc[%d]\n", open.hdr.opcode, rc);
1419 goto fail_cmd;
1420 }
1421 rc = wait_event_timeout(ac->cmd_wait,
1422 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1423 if (!rc) {
1424 pr_err("%s: timeout. waited for OPEN_READ_COMPRESSED rc[%d]\n",
1425 __func__, rc);
1426 goto fail_cmd;
1427 }
1428 return 0;
1429fail_cmd:
1430 return -EINVAL;
1431}
1432
Santosh Mardi23321202012-03-22 04:33:25 +05301433int q6asm_open_write_compressed(struct audio_client *ac, uint32_t format)
1434{
1435 int rc = 0x00;
1436 struct asm_stream_cmd_open_write_compressed open;
1437
1438 if ((ac == NULL) || (ac->apr == NULL)) {
1439 pr_err("%s: APR handle NULL\n", __func__);
1440 return -EINVAL;
1441 }
1442 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1443 format);
1444
1445 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1446
1447 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED;
1448
1449 switch (format) {
1450 case FORMAT_AC3:
1451 open.format = AC3_DECODER;
1452 break;
1453 case FORMAT_EAC3:
1454 open.format = EAC3_DECODER;
1455 break;
1456 case FORMAT_MP3:
1457 open.format = MP3;
1458 break;
1459 case FORMAT_DTS:
1460 open.format = DTS;
1461 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05301462 case FORMAT_DTS_LBR:
1463 open.format = DTS_LBR;
1464 break;
Santosh Mardi23321202012-03-22 04:33:25 +05301465 case FORMAT_AAC:
1466 open.format = MPEG4_AAC;
1467 break;
1468 case FORMAT_ATRAC:
1469 open.format = ATRAC;
1470 break;
1471 case FORMAT_WMA_V10PRO:
1472 open.format = WMA_V10PRO;
1473 break;
1474 case FORMAT_MAT:
1475 open.format = MAT;
1476 break;
1477 default:
1478 pr_err("%s: Invalid format[%d]\n", __func__, format);
1479 goto fail_cmd;
1480 }
1481 /*Below flag indicates the DSP that Compressed audio input
1482 stream is not IEC 61937 or IEC 60958 packetizied*/
1483 open.flags = 0x00000000;
1484 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1485 if (rc < 0) {
1486 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1487 __func__, open.hdr.opcode, rc);
1488 goto fail_cmd;
1489 }
1490 rc = wait_event_timeout(ac->cmd_wait,
1491 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1492 if (!rc) {
1493 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1494 rc);
1495 goto fail_cmd;
1496 }
1497 return 0;
1498fail_cmd:
1499 return -EINVAL;
1500}
1501
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001502int q6asm_open_write(struct audio_client *ac, uint32_t format)
1503{
1504 int rc = 0x00;
1505 struct asm_stream_cmd_open_write open;
1506
1507 if ((ac == NULL) || (ac->apr == NULL)) {
1508 pr_err("%s: APR handle NULL\n", __func__);
1509 return -EINVAL;
1510 }
1511 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1512 format);
1513
1514 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1515
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -07001516 if (ac->perf_mode) {
1517 pr_debug("%s In Performance/lowlatency mode", __func__);
1518 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_V2_1;
1519 open.uMode = ASM_OPEN_WRITE_PERF_MODE_BIT;
1520 /* source endpoint : matrix */
1521 open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1522 open.stream_handle = PCM_BITS_PER_SAMPLE;
1523 } else {
1524 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE;
1525 open.uMode = STREAM_PRIORITY_HIGH;
1526 /* source endpoint : matrix */
1527 open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1528 open.stream_handle = 0x00;
1529 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001530 open.post_proc_top = get_asm_topology();
1531 if (open.post_proc_top == 0)
1532 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1533
1534 switch (format) {
1535 case FORMAT_LINEAR_PCM:
1536 open.format = LINEAR_PCM;
1537 break;
Kiran Kandi5e809b02012-01-31 00:24:33 -08001538 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1539 open.format = MULTI_CHANNEL_PCM;
1540 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001541 case FORMAT_MPEG4_AAC:
1542 open.format = MPEG4_AAC;
1543 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001544 case FORMAT_MPEG4_MULTI_AAC:
1545 open.format = MPEG4_MULTI_AAC;
1546 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001547 case FORMAT_WMA_V9:
1548 open.format = WMA_V9;
1549 break;
1550 case FORMAT_WMA_V10PRO:
1551 open.format = WMA_V10PRO;
1552 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05301553 case FORMAT_MP3:
1554 open.format = MP3;
1555 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05301556 case FORMAT_DTS:
1557 open.format = DTS;
1558 break;
1559 case FORMAT_DTS_LBR:
1560 open.format = DTS_LBR;
1561 break;
Ajit Khare43fd8832012-08-07 13:19:44 -07001562 case FORMAT_AMRWB:
1563 open.format = AMRWB_FS;
1564 pr_debug("q6asm_open_write FORMAT_AMRWB");
1565 break;
1566 case FORMAT_AMR_WB_PLUS:
1567 open.format = AMR_WB_PLUS;
1568 pr_debug("q6asm_open_write FORMAT_AMR_WB_PLUS");
1569 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001570 default:
1571 pr_err("%s: Invalid format[%d]\n", __func__, format);
1572 goto fail_cmd;
1573 }
1574 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1575 if (rc < 0) {
1576 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1577 __func__, open.hdr.opcode, rc);
1578 goto fail_cmd;
1579 }
1580 rc = wait_event_timeout(ac->cmd_wait,
1581 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1582 if (!rc) {
1583 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1584 rc);
1585 goto fail_cmd;
1586 }
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +05301587 if (atomic_read(&ac->cmd_response)) {
1588 pr_err("%s: format = %x not supported\n", __func__, format);
1589 goto fail_cmd;
1590 }
Patrick Lai55f54c52012-11-17 00:29:07 -08001591
1592 ac->io_mode |= TUN_WRITE_IO_MODE;
1593
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001594 return 0;
1595fail_cmd:
1596 return -EINVAL;
1597}
1598
1599int q6asm_open_read_write(struct audio_client *ac,
1600 uint32_t rd_format,
1601 uint32_t wr_format)
1602{
1603 int rc = 0x00;
1604 struct asm_stream_cmd_open_read_write open;
1605
1606 if ((ac == NULL) || (ac->apr == NULL)) {
1607 pr_err("APR handle NULL\n");
1608 return -EINVAL;
1609 }
1610 pr_debug("%s: session[%d]", __func__, ac->session);
1611 pr_debug("wr_format[0x%x]rd_format[0x%x]",
1612 wr_format, rd_format);
1613
1614 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1615 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE;
1616
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301617 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_NORMAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001618 /* source endpoint : matrix */
1619 open.post_proc_top = get_asm_topology();
1620 if (open.post_proc_top == 0)
1621 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1622
1623 switch (wr_format) {
1624 case FORMAT_LINEAR_PCM:
1625 open.write_format = LINEAR_PCM;
1626 break;
1627 case FORMAT_MPEG4_AAC:
1628 open.write_format = MPEG4_AAC;
1629 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001630 case FORMAT_MPEG4_MULTI_AAC:
1631 open.write_format = MPEG4_MULTI_AAC;
1632 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001633 case FORMAT_WMA_V9:
1634 open.write_format = WMA_V9;
1635 break;
1636 case FORMAT_WMA_V10PRO:
1637 open.write_format = WMA_V10PRO;
1638 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301639 case FORMAT_AMRNB:
1640 open.write_format = AMRNB_FS;
1641 break;
1642 case FORMAT_AMRWB:
1643 open.write_format = AMRWB_FS;
1644 break;
Ajit Khare7277bb72012-10-31 16:34:22 -07001645 case FORMAT_AMR_WB_PLUS:
1646 open.write_format = AMR_WB_PLUS;
1647 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301648 case FORMAT_V13K:
1649 open.write_format = V13K_FS;
1650 break;
1651 case FORMAT_EVRC:
1652 open.write_format = EVRC_FS;
1653 break;
1654 case FORMAT_EVRCB:
1655 open.write_format = EVRCB_FS;
1656 break;
1657 case FORMAT_EVRCWB:
1658 open.write_format = EVRCWB_FS;
1659 break;
1660 case FORMAT_MP3:
1661 open.write_format = MP3;
1662 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001663 default:
1664 pr_err("Invalid format[%d]\n", wr_format);
1665 goto fail_cmd;
1666 }
1667
1668 switch (rd_format) {
1669 case FORMAT_LINEAR_PCM:
1670 open.read_format = LINEAR_PCM;
1671 break;
1672 case FORMAT_MPEG4_AAC:
1673 open.read_format = MPEG4_AAC;
1674 break;
1675 case FORMAT_V13K:
1676 open.read_format = V13K_FS;
1677 break;
1678 case FORMAT_EVRC:
1679 open.read_format = EVRC_FS;
1680 break;
1681 case FORMAT_AMRNB:
1682 open.read_format = AMRNB_FS;
1683 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301684 case FORMAT_AMRWB:
1685 open.read_format = AMRWB_FS;
1686 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001687 default:
1688 pr_err("Invalid format[%d]\n", rd_format);
1689 goto fail_cmd;
1690 }
1691 pr_debug("%s:rdformat[0x%x]wrformat[0x%x]\n", __func__,
1692 open.read_format, open.write_format);
1693
1694 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1695 if (rc < 0) {
1696 pr_err("open failed op[0x%x]rc[%d]\n", \
1697 open.hdr.opcode, rc);
1698 goto fail_cmd;
1699 }
1700 rc = wait_event_timeout(ac->cmd_wait,
1701 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1702 if (!rc) {
1703 pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc);
1704 goto fail_cmd;
1705 }
1706 return 0;
1707fail_cmd:
1708 return -EINVAL;
1709}
1710
Laxminath Kasam20824502013-01-07 14:33:56 +05301711int q6asm_open_loopack(struct audio_client *ac)
1712{
1713 int rc = 0x00;
1714 struct asm_stream_cmd_open_loopback open;
1715
1716 if ((ac == NULL) || (ac->apr == NULL)) {
1717 pr_err("APR handle NULL\n");
1718 return -EINVAL;
1719 }
1720 pr_debug("%s: session[%d]", __func__, ac->session);
1721
1722 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1723 open.hdr.opcode = ASM_STREAM_CMD_OPEN_LOOPBACK;
1724
1725 open.mode_flags = 0;
1726 open.src_endpointype = 0;
1727 open.sink_endpointype = 0;
1728 /* source endpoint : matrix */
1729 open.postprocopo_id = get_asm_topology();
1730 if (open.postprocopo_id == 0)
1731 open.postprocopo_id = DEFAULT_POPP_TOPOLOGY;
1732
1733 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1734 if (rc < 0) {
1735 pr_err("open failed op[0x%x]rc[%d]\n", \
1736 open.hdr.opcode, rc);
1737 goto fail_cmd;
1738 }
1739 rc = wait_event_timeout(ac->cmd_wait,
1740 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1741 if (!rc) {
1742 pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc);
1743 goto fail_cmd;
1744 }
1745 return 0;
1746fail_cmd:
1747 return -EINVAL;
1748}
1749
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001750int q6asm_run(struct audio_client *ac, uint32_t flags,
1751 uint32_t msw_ts, uint32_t lsw_ts)
1752{
1753 struct asm_stream_cmd_run run;
1754 int rc;
1755 if (!ac || ac->apr == NULL) {
1756 pr_err("APR handle NULL\n");
1757 return -EINVAL;
1758 }
1759 pr_debug("%s session[%d]", __func__, ac->session);
1760 q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
1761
1762 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1763 run.flags = flags;
1764 run.msw_ts = msw_ts;
1765 run.lsw_ts = lsw_ts;
Rajesha Kini3498c932011-07-19 19:58:27 +05301766#ifdef CONFIG_DEBUG_FS
1767 if (out_enable_flag) {
1768 do_gettimeofday(&out_cold_tv);
1769 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",\
1770 out_cold_tv.tv_sec, out_cold_tv.tv_usec);
1771 }
1772#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001773 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1774 if (rc < 0) {
1775 pr_err("Commmand run failed[%d]", rc);
1776 goto fail_cmd;
1777 }
1778
1779 rc = wait_event_timeout(ac->cmd_wait,
1780 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1781 if (!rc) {
1782 pr_err("timeout. waited for run success rc[%d]", rc);
1783 goto fail_cmd;
1784 }
1785
1786 return 0;
1787fail_cmd:
1788 return -EINVAL;
1789}
1790
1791int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
1792 uint32_t msw_ts, uint32_t lsw_ts)
1793{
1794 struct asm_stream_cmd_run run;
1795 int rc;
1796 if (!ac || ac->apr == NULL) {
1797 pr_err("%s:APR handle NULL\n", __func__);
1798 return -EINVAL;
1799 }
1800 pr_debug("session[%d]", ac->session);
1801 q6asm_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE);
1802
1803 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1804 run.flags = flags;
1805 run.msw_ts = msw_ts;
1806 run.lsw_ts = lsw_ts;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001807 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1808 if (rc < 0) {
1809 pr_err("%s:Commmand run failed[%d]", __func__, rc);
1810 return -EINVAL;
1811 }
Jay Wang0668d1062012-07-11 18:53:21 -07001812 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001813 return 0;
1814}
1815
1816
1817int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
1818 uint32_t frames_per_buf,
1819 uint32_t sample_rate, uint32_t channels,
1820 uint32_t bit_rate, uint32_t mode, uint32_t format)
1821{
1822 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1823 int rc = 0;
1824
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001825 pr_debug("%s:session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d] format[%d]",
1826 __func__, ac->session, frames_per_buf,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001827 sample_rate, channels, bit_rate, mode, format);
1828
1829 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1830
1831 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1832 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1833 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1834 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1835 enc_cfg.enc_blk.format_id = MPEG4_AAC;
1836 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_aac_read_cfg);
1837 enc_cfg.enc_blk.cfg.aac.bitrate = bit_rate;
1838 enc_cfg.enc_blk.cfg.aac.enc_mode = mode;
1839 enc_cfg.enc_blk.cfg.aac.format = format;
1840 enc_cfg.enc_blk.cfg.aac.ch_cfg = channels;
1841 enc_cfg.enc_blk.cfg.aac.sample_rate = sample_rate;
1842
1843 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1844 if (rc < 0) {
1845 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1846 rc = -EINVAL;
1847 goto fail_cmd;
1848 }
1849 rc = wait_event_timeout(ac->cmd_wait,
1850 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1851 if (!rc) {
1852 pr_err("timeout. waited for FORMAT_UPDATE\n");
1853 goto fail_cmd;
1854 }
1855 return 0;
1856fail_cmd:
1857 return -EINVAL;
1858}
1859
1860int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
1861 uint32_t rate, uint32_t channels)
1862{
1863 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1864
1865 int rc = 0;
1866
1867 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1868 ac->session, rate, channels);
1869
1870 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1871
1872 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1873 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1874 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1875 enc_cfg.enc_blk.frames_per_buf = 1;
1876 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1877 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1878 enc_cfg.enc_blk.cfg.pcm.ch_cfg = channels;
1879 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1880 enc_cfg.enc_blk.cfg.pcm.sample_rate = rate;
1881 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1882 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1883
1884 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1885 if (rc < 0) {
1886 pr_err("Comamnd open failed\n");
1887 rc = -EINVAL;
1888 goto fail_cmd;
1889 }
1890 rc = wait_event_timeout(ac->cmd_wait,
1891 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1892 if (!rc) {
1893 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1894 goto fail_cmd;
1895 }
1896 return 0;
1897fail_cmd:
1898 return -EINVAL;
1899}
1900
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001901int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac,
1902 uint32_t rate, uint32_t channels)
1903{
1904 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1905
1906 int rc = 0;
1907
1908 pr_debug("%s: Session %d, rate = %d, channels = %d, setting the rate and channels to 0 for native\n",
1909 __func__, ac->session, rate, channels);
1910
1911 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1912
1913 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1914 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1915 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1916 enc_cfg.enc_blk.frames_per_buf = 1;
1917 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1918 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1919 enc_cfg.enc_blk.cfg.pcm.ch_cfg = 0;/*channels;*/
1920 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1921 enc_cfg.enc_blk.cfg.pcm.sample_rate = 0;/*rate;*/
1922 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1923 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1924
1925 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1926 if (rc < 0) {
1927 pr_err("Comamnd open failed\n");
1928 rc = -EINVAL;
1929 goto fail_cmd;
1930 }
1931 rc = wait_event_timeout(ac->cmd_wait,
1932 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1933 if (!rc) {
1934 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1935 goto fail_cmd;
1936 }
1937 return 0;
1938fail_cmd:
1939 return -EINVAL;
1940}
1941
Mingming Yin647e9ea2012-03-17 19:56:10 -07001942int q6asm_enc_cfg_blk_multi_ch_pcm(struct audio_client *ac,
1943 uint32_t rate, uint32_t channels)
1944{
1945 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1946
1947 int rc = 0;
1948
1949 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1950 ac->session, rate, channels);
1951
1952 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1953
1954 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1955 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1956 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1957 enc_cfg.enc_blk.frames_per_buf = 1;
1958 enc_cfg.enc_blk.format_id = MULTI_CHANNEL_PCM;
1959 enc_cfg.enc_blk.cfg_size =
1960 sizeof(struct asm_multi_channel_pcm_fmt_blk);
1961 enc_cfg.enc_blk.cfg.mpcm.num_channels = channels;
1962 enc_cfg.enc_blk.cfg.mpcm.bits_per_sample = 16;
1963 enc_cfg.enc_blk.cfg.mpcm.sample_rate = rate;
1964 enc_cfg.enc_blk.cfg.mpcm.is_signed = 1;
1965 enc_cfg.enc_blk.cfg.mpcm.is_interleaved = 1;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07001966 if (channels == 1) {
1967 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1968 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = 0;
1969 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0;
1970 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
1971 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1972 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1973 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1974 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1975 } else if (channels == 2) {
Subhash Chandra Bose Naripeddy8477d222012-06-12 00:30:54 -07001976 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1977 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1978 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0;
1979 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
1980 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1981 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1982 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1983 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1984 } else if (channels == 4) {
1985 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1986 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1987 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_RB;
1988 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_LB;
1989 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1990 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1991 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1992 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1993 } else if (channels == 6) {
1994 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1995 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1996 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
1997 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
1998 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
1999 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
2000 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
2001 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
2002 } else if (channels == 8) {
2003 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
2004 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
2005 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
2006 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
2007 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
2008 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
2009 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = PCM_CHANNEL_FLC;
2010 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = PCM_CHANNEL_FRC;
2011 }
Mingming Yin647e9ea2012-03-17 19:56:10 -07002012
2013 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2014 if (rc < 0) {
2015 pr_err("Comamnd open failed\n");
2016 rc = -EINVAL;
2017 goto fail_cmd;
2018 }
2019 rc = wait_event_timeout(ac->cmd_wait,
2020 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2021 if (!rc) {
2022 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
2023 goto fail_cmd;
2024 }
2025 return 0;
2026fail_cmd:
2027 return -EINVAL;
2028}
2029
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002030int q6asm_enable_sbrps(struct audio_client *ac,
2031 uint32_t sbr_ps_enable)
2032{
2033 struct asm_stream_cmd_encdec_sbr sbrps;
2034
2035 int rc = 0;
2036
2037 pr_debug("%s: Session %d\n", __func__, ac->session);
2038
2039 q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
2040
2041 sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2042 sbrps.param_id = ASM_ENABLE_SBR_PS;
2043 sbrps.param_size = sizeof(struct asm_sbr_ps);
2044 sbrps.sbr_ps.enable = sbr_ps_enable;
2045
2046 rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
2047 if (rc < 0) {
2048 pr_err("Command opcode[0x%x]paramid[0x%x] failed\n",
2049 ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2050 ASM_ENABLE_SBR_PS);
2051 rc = -EINVAL;
2052 goto fail_cmd;
2053 }
2054 rc = wait_event_timeout(ac->cmd_wait,
2055 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2056 if (!rc) {
2057 pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode);
2058 goto fail_cmd;
2059 }
2060 return 0;
2061fail_cmd:
2062 return -EINVAL;
2063}
2064
Swaminathan Sathappan70765cd2011-07-19 18:42:47 -07002065int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
2066 uint16_t sce_left, uint16_t sce_right)
2067{
2068 struct asm_stream_cmd_encdec_dualmono dual_mono;
2069
2070 int rc = 0;
2071
2072 pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
2073 __func__, ac->session, sce_left, sce_right);
2074
2075 q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
2076
2077 dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2078 dual_mono.param_id = ASM_CONFIGURE_DUAL_MONO;
2079 dual_mono.param_size = sizeof(struct asm_dual_mono);
2080 dual_mono.channel_map.sce_left = sce_left;
2081 dual_mono.channel_map.sce_right = sce_right;
2082
2083 rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
2084 if (rc < 0) {
2085 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2086 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2087 ASM_CONFIGURE_DUAL_MONO);
2088 rc = -EINVAL;
2089 goto fail_cmd;
2090 }
2091 rc = wait_event_timeout(ac->cmd_wait,
2092 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2093 if (!rc) {
2094 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2095 dual_mono.hdr.opcode);
2096 goto fail_cmd;
2097 }
2098 return 0;
2099fail_cmd:
2100 return -EINVAL;
2101}
2102
Amal Paul6e0f7982013-02-21 19:36:35 -08002103int q6asm_cfg_aac_sel_mix_coef(struct audio_client *ac, uint32_t mix_coeff)
2104{
2105 struct asm_aac_stereo_mix_coeff_selection_param aac_mix_coeff;
2106 int rc = 0;
2107 q6asm_add_hdr(ac, &aac_mix_coeff.hdr, sizeof(aac_mix_coeff), TRUE);
2108 aac_mix_coeff.hdr.opcode =
2109 ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2110 aac_mix_coeff.param_id =
2111 ASM_PARAM_ID_AAC_STEREO_MIX_COEFF_SELECTION_FLAG;
2112 aac_mix_coeff.param_size =
2113 sizeof(struct asm_aac_stereo_mix_coeff_selection_param);
2114 aac_mix_coeff.aac_stereo_mix_coeff_flag = mix_coeff;
2115 pr_debug("%s, mix_coeff = %u", __func__, mix_coeff);
2116 rc = apr_send_pkt(ac->apr, (uint32_t *) &aac_mix_coeff);
2117 if (rc < 0) {
2118 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2119 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2120 ASM_PARAM_ID_AAC_STEREO_MIX_COEFF_SELECTION_FLAG);
2121 rc = -EINVAL;
2122 goto fail_cmd;
2123 }
2124 rc = wait_event_timeout(ac->cmd_wait,
2125 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2126 if (!rc) {
2127 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2128 aac_mix_coeff.hdr.opcode);
2129 goto fail_cmd;
2130 }
2131 return 0;
2132fail_cmd:
2133 return -EINVAL;
2134}
2135
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002136int q6asm_set_encdec_chan_map(struct audio_client *ac,
2137 uint32_t num_channels)
2138{
2139 struct asm_stream_cmd_encdec_channelmap chan_map;
2140 u8 *channel_mapping;
2141
2142 int rc = 0;
2143
2144 pr_debug("%s: Session %d, num_channels = %d\n",
2145 __func__, ac->session, num_channels);
2146
2147 q6asm_add_hdr(ac, &chan_map.hdr, sizeof(chan_map), TRUE);
2148
2149 chan_map.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2150 chan_map.param_id = ASM_ENCDEC_DEC_CHAN_MAP;
2151 chan_map.param_size = sizeof(struct asm_dec_chan_map);
2152 chan_map.chan_map.num_channels = num_channels;
2153
2154 channel_mapping =
2155 chan_map.chan_map.channel_mapping;
2156
2157 memset(channel_mapping, PCM_CHANNEL_NULL, MAX_CHAN_MAP_CHANNELS);
2158 if (num_channels == 1) {
2159 channel_mapping[0] = PCM_CHANNEL_FL;
2160 } else if (num_channels == 2) {
2161 channel_mapping[0] = PCM_CHANNEL_FL;
2162 channel_mapping[1] = PCM_CHANNEL_FR;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002163 } else if (num_channels == 4) {
2164 channel_mapping[0] = PCM_CHANNEL_FL;
2165 channel_mapping[1] = PCM_CHANNEL_FR;
2166 channel_mapping[1] = PCM_CHANNEL_LB;
2167 channel_mapping[1] = PCM_CHANNEL_RB;
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002168 } else if (num_channels == 6) {
2169 channel_mapping[0] = PCM_CHANNEL_FC;
2170 channel_mapping[1] = PCM_CHANNEL_FL;
2171 channel_mapping[2] = PCM_CHANNEL_FR;
2172 channel_mapping[3] = PCM_CHANNEL_LB;
2173 channel_mapping[4] = PCM_CHANNEL_RB;
2174 channel_mapping[5] = PCM_CHANNEL_LFE;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002175 } else if (num_channels == 8) {
2176 channel_mapping[0] = PCM_CHANNEL_FC;
2177 channel_mapping[1] = PCM_CHANNEL_FL;
2178 channel_mapping[2] = PCM_CHANNEL_FR;
2179 channel_mapping[3] = PCM_CHANNEL_LB;
2180 channel_mapping[4] = PCM_CHANNEL_RB;
2181 channel_mapping[5] = PCM_CHANNEL_LFE;
2182 channel_mapping[6] = PCM_CHANNEL_FLC;
2183 channel_mapping[7] = PCM_CHANNEL_FRC;
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002184 } else {
2185 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2186 num_channels);
2187 rc = -EINVAL;
2188 goto fail_cmd;
2189 }
2190
2191 rc = apr_send_pkt(ac->apr, (uint32_t *) &chan_map);
2192 if (rc < 0) {
2193 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2194 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2195 ASM_ENCDEC_DEC_CHAN_MAP);
2196 goto fail_cmd;
2197 }
2198 rc = wait_event_timeout(ac->cmd_wait,
2199 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2200 if (!rc) {
2201 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2202 chan_map.hdr.opcode);
2203 rc = -ETIMEDOUT;
2204 goto fail_cmd;
2205 }
2206 return 0;
2207fail_cmd:
2208 return rc;
2209}
2210
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002211int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
2212 uint16_t min_rate, uint16_t max_rate,
2213 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
2214{
2215 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2216 int rc = 0;
2217
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002218 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]",
2219 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002220 ac->session, frames_per_buf, min_rate, max_rate,
2221 reduced_rate_level, rate_modulation_cmd);
2222
2223 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2224
2225 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2226
2227 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2228 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2229
2230 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2231 enc_cfg.enc_blk.format_id = V13K_FS;
2232 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg);
2233 enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate;
2234 enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate;
2235 enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level;
2236 enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_cmd = rate_modulation_cmd;
2237
2238 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2239 if (rc < 0) {
2240 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2241 goto fail_cmd;
2242 }
2243 rc = wait_event_timeout(ac->cmd_wait,
2244 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2245 if (!rc) {
2246 pr_err("timeout. waited for FORMAT_UPDATE\n");
2247 goto fail_cmd;
2248 }
2249 return 0;
2250fail_cmd:
2251 return -EINVAL;
2252}
2253
2254int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
2255 uint16_t min_rate, uint16_t max_rate,
2256 uint16_t rate_modulation_cmd)
2257{
2258 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2259 int rc = 0;
2260
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002261 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] rate_modulation_cmd[0x%4x]",
2262 __func__, ac->session,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002263 frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
2264
2265 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2266
2267 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2268
2269 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2270 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2271
2272 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2273 enc_cfg.enc_blk.format_id = EVRC_FS;
2274 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg);
2275 enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate;
2276 enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate;
2277 enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd;
2278 enc_cfg.enc_blk.cfg.evrc.reserved = 0;
2279
2280 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2281 if (rc < 0) {
2282 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2283 goto fail_cmd;
2284 }
2285 rc = wait_event_timeout(ac->cmd_wait,
2286 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2287 if (!rc) {
2288 pr_err("timeout. waited for FORMAT_UPDATE\n");
2289 goto fail_cmd;
2290 }
2291 return 0;
2292fail_cmd:
2293 return -EINVAL;
2294}
2295
2296int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
2297 uint16_t band_mode, uint16_t dtx_enable)
2298{
2299 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2300 int rc = 0;
2301
2302 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2303 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2304
2305 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2306
2307 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2308
2309 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2310 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2311
2312 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2313 enc_cfg.enc_blk.format_id = AMRNB_FS;
2314 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg);
2315 enc_cfg.enc_blk.cfg.amrnb.mode = band_mode;
2316 enc_cfg.enc_blk.cfg.amrnb.dtx_mode = dtx_enable;
2317
2318 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2319 if (rc < 0) {
2320 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2321 goto fail_cmd;
2322 }
2323 rc = wait_event_timeout(ac->cmd_wait,
2324 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2325 if (!rc) {
2326 pr_err("timeout. waited for FORMAT_UPDATE\n");
2327 goto fail_cmd;
2328 }
2329 return 0;
2330fail_cmd:
2331 return -EINVAL;
2332}
2333
Alex Wong2caeecc2011-10-28 10:52:15 +05302334int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
2335 uint16_t band_mode, uint16_t dtx_enable)
2336{
2337 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2338 int rc = 0;
2339
2340 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2341 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2342
2343 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2344
2345 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2346
2347 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2348 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2349
2350 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2351 enc_cfg.enc_blk.format_id = AMRWB_FS;
2352 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrwb_read_cfg);
2353 enc_cfg.enc_blk.cfg.amrwb.mode = band_mode;
2354 enc_cfg.enc_blk.cfg.amrwb.dtx_mode = dtx_enable;
2355
2356 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2357 if (rc < 0) {
2358 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
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("timeout. waited for FORMAT_UPDATE\n");
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_pcm(struct audio_client *ac,
2373 uint32_t rate, uint32_t channels)
2374{
2375 struct asm_stream_media_format_update fmt;
2376 int rc = 0;
2377
2378 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2379 channels);
2380
2381 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2382
2383 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2384
2385 fmt.format = LINEAR_PCM;
2386 fmt.cfg_size = sizeof(struct asm_pcm_cfg);
2387 fmt.write_cfg.pcm_cfg.ch_cfg = channels;
2388 fmt.write_cfg.pcm_cfg.bits_per_sample = 16;
2389 fmt.write_cfg.pcm_cfg.sample_rate = rate;
2390 fmt.write_cfg.pcm_cfg.is_signed = 1;
2391 fmt.write_cfg.pcm_cfg.interleaved = 1;
2392
2393 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2394 if (rc < 0) {
2395 pr_err("%s:Comamnd open failed\n", __func__);
2396 goto fail_cmd;
2397 }
2398 rc = wait_event_timeout(ac->cmd_wait,
2399 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2400 if (!rc) {
2401 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2402 goto fail_cmd;
2403 }
2404 return 0;
2405fail_cmd:
2406 return -EINVAL;
2407}
2408
Kiran Kandi5e809b02012-01-31 00:24:33 -08002409int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
2410 uint32_t rate, uint32_t channels)
2411{
2412 struct asm_stream_media_format_update fmt;
2413 u8 *channel_mapping;
2414 int rc = 0;
2415
2416 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2417 channels);
2418
2419 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2420
2421 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2422
2423 fmt.format = MULTI_CHANNEL_PCM;
2424 fmt.cfg_size = sizeof(struct asm_multi_channel_pcm_fmt_blk);
2425 fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels;
2426 fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = 16;
2427 fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate;
2428 fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1;
2429 fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1;
2430 channel_mapping =
2431 fmt.write_cfg.multi_ch_pcm_cfg.channel_mapping;
2432
2433 memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
2434
2435 if (channels == 1) {
2436 channel_mapping[0] = PCM_CHANNEL_FL;
2437 } else if (channels == 2) {
2438 channel_mapping[0] = PCM_CHANNEL_FL;
2439 channel_mapping[1] = PCM_CHANNEL_FR;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002440 } else if (channels == 4) {
2441 channel_mapping[0] = PCM_CHANNEL_FL;
2442 channel_mapping[1] = PCM_CHANNEL_FR;
2443 channel_mapping[1] = PCM_CHANNEL_LB;
2444 channel_mapping[1] = PCM_CHANNEL_RB;
Kiran Kandi5e809b02012-01-31 00:24:33 -08002445 } else if (channels == 6) {
SathishKumar Mani6074b772012-09-26 13:49:49 -07002446 channel_mapping[0] = PCM_CHANNEL_FL;
2447 channel_mapping[1] = PCM_CHANNEL_FR;
2448 channel_mapping[2] = PCM_CHANNEL_FC;
2449 channel_mapping[3] = PCM_CHANNEL_LFE;
2450 channel_mapping[4] = PCM_CHANNEL_LB;
2451 channel_mapping[5] = PCM_CHANNEL_RB;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002452 } else if (channels == 8) {
2453 channel_mapping[0] = PCM_CHANNEL_FC;
2454 channel_mapping[1] = PCM_CHANNEL_FL;
2455 channel_mapping[2] = PCM_CHANNEL_FR;
2456 channel_mapping[3] = PCM_CHANNEL_LB;
2457 channel_mapping[4] = PCM_CHANNEL_RB;
2458 channel_mapping[5] = PCM_CHANNEL_LFE;
2459 channel_mapping[6] = PCM_CHANNEL_FLC;
2460 channel_mapping[7] = PCM_CHANNEL_FRC;
Kiran Kandi5e809b02012-01-31 00:24:33 -08002461 } else {
2462 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2463 channels);
2464 return -EINVAL;
2465 }
2466
2467 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2468 if (rc < 0) {
2469 pr_err("%s:Comamnd open failed\n", __func__);
2470 goto fail_cmd;
2471 }
2472 rc = wait_event_timeout(ac->cmd_wait,
2473 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2474 if (!rc) {
2475 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2476 goto fail_cmd;
2477 }
2478 return 0;
2479fail_cmd:
2480 return -EINVAL;
2481}
2482
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002483int q6asm_media_format_block_aac(struct audio_client *ac,
2484 struct asm_aac_cfg *cfg)
2485{
2486 struct asm_stream_media_format_update fmt;
2487 int rc = 0;
2488
2489 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2490 cfg->sample_rate, cfg->ch_cfg);
2491
2492 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2493
2494 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2495
2496 fmt.format = MPEG4_AAC;
2497 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2498 fmt.write_cfg.aac_cfg.format = cfg->format;
2499 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2500 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2501 fmt.write_cfg.aac_cfg.section_data_resilience =
2502 cfg->section_data_resilience;
2503 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2504 cfg->scalefactor_data_resilience;
2505 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2506 cfg->spectral_data_resilience;
2507 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2508 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2509 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2510 __func__, fmt.format, fmt.cfg_size,
2511 fmt.write_cfg.aac_cfg.format,
2512 fmt.write_cfg.aac_cfg.aot,
2513 fmt.write_cfg.aac_cfg.ch_cfg,
2514 fmt.write_cfg.aac_cfg.sample_rate);
2515 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2516 if (rc < 0) {
2517 pr_err("%s:Comamnd open failed\n", __func__);
2518 goto fail_cmd;
2519 }
2520 rc = wait_event_timeout(ac->cmd_wait,
2521 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2522 if (!rc) {
2523 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2524 goto fail_cmd;
2525 }
2526 return 0;
2527fail_cmd:
2528 return -EINVAL;
2529}
2530
Ajit Khare43fd8832012-08-07 13:19:44 -07002531int q6asm_media_format_block_amrwbplus(struct audio_client *ac,
2532 struct asm_amrwbplus_cfg *cfg)
2533{
2534 struct asm_stream_media_format_update fmt;
2535 int rc = 0;
2536 pr_debug("q6asm_media_format_block_amrwbplus");
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002537
Ajit Khare43fd8832012-08-07 13:19:44 -07002538 pr_debug("%s:session[%d]band-mode[%d]frame-fmt[%d]ch[%d]\n",
2539 __func__,
2540 ac->session,
2541 cfg->amr_band_mode,
2542 cfg->amr_frame_fmt,
2543 cfg->num_channels);
2544
2545 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2546
2547 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2548
2549 fmt.format = AMR_WB_PLUS;
2550 fmt.cfg_size = cfg->size_bytes;
2551
2552 fmt.write_cfg.amrwbplus_cfg.size_bytes = cfg->size_bytes;
2553 fmt.write_cfg.amrwbplus_cfg.version = cfg->version;
2554 fmt.write_cfg.amrwbplus_cfg.num_channels = cfg->num_channels;
2555 fmt.write_cfg.amrwbplus_cfg.amr_band_mode = cfg->amr_band_mode;
2556 fmt.write_cfg.amrwbplus_cfg.amr_dtx_mode = cfg->amr_dtx_mode;
2557 fmt.write_cfg.amrwbplus_cfg.amr_frame_fmt = cfg->amr_frame_fmt;
2558 fmt.write_cfg.amrwbplus_cfg.amr_lsf_idx = cfg->amr_lsf_idx;
2559
2560 pr_debug("%s: num_channels=%x amr_band_mode=%d amr_frame_fmt=%d\n",
2561 __func__,
2562 cfg->num_channels,
2563 cfg->amr_band_mode,
2564 cfg->amr_frame_fmt);
2565
2566 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2567 if (rc < 0) {
2568 pr_err("%s:Comamnd media format update failed..\n", __func__);
2569 goto fail_cmd;
2570 }
2571 rc = wait_event_timeout(ac->cmd_wait,
2572 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2573 if (!rc) {
2574 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2575 goto fail_cmd;
2576 }
2577 return 0;
2578fail_cmd:
2579 return -EINVAL;
2580}
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002581int q6asm_media_format_block_multi_aac(struct audio_client *ac,
2582 struct asm_aac_cfg *cfg)
2583{
2584 struct asm_stream_media_format_update fmt;
2585 int rc = 0;
2586
2587 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2588 cfg->sample_rate, cfg->ch_cfg);
2589
2590 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2591
2592 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2593
2594 fmt.format = MPEG4_MULTI_AAC;
2595 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2596 fmt.write_cfg.aac_cfg.format = cfg->format;
2597 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2598 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2599 fmt.write_cfg.aac_cfg.section_data_resilience =
2600 cfg->section_data_resilience;
2601 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2602 cfg->scalefactor_data_resilience;
2603 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2604 cfg->spectral_data_resilience;
2605 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2606 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2607 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2608 __func__, fmt.format, fmt.cfg_size,
2609 fmt.write_cfg.aac_cfg.format,
2610 fmt.write_cfg.aac_cfg.aot,
2611 fmt.write_cfg.aac_cfg.ch_cfg,
2612 fmt.write_cfg.aac_cfg.sample_rate);
2613 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2614 if (rc < 0) {
2615 pr_err("%s:Comamnd open failed\n", __func__);
2616 goto fail_cmd;
2617 }
2618 rc = wait_event_timeout(ac->cmd_wait,
2619 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2620 if (!rc) {
2621 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2622 goto fail_cmd;
2623 }
2624 return 0;
2625fail_cmd:
2626 return -EINVAL;
2627}
2628
2629
Alex Wong2caeecc2011-10-28 10:52:15 +05302630
2631int q6asm_media_format_block(struct audio_client *ac, uint32_t format)
2632{
2633
2634 struct asm_stream_media_format_update fmt;
2635 int rc = 0;
2636
2637 pr_debug("%s:session[%d] format[0x%x]\n", __func__,
2638 ac->session, format);
2639
2640 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2641 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302642 switch (format) {
2643 case FORMAT_V13K:
2644 fmt.format = V13K_FS;
2645 break;
2646 case FORMAT_EVRC:
2647 fmt.format = EVRC_FS;
2648 break;
2649 case FORMAT_AMRWB:
2650 fmt.format = AMRWB_FS;
2651 break;
Ajit Khare43fd8832012-08-07 13:19:44 -07002652 case FORMAT_AMR_WB_PLUS:
2653 fmt.format = AMR_WB_PLUS;
2654 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302655 case FORMAT_AMRNB:
2656 fmt.format = AMRNB_FS;
2657 break;
2658 case FORMAT_MP3:
2659 fmt.format = MP3;
2660 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05302661 case FORMAT_DTS:
2662 fmt.format = DTS;
2663 break;
2664 case FORMAT_DTS_LBR:
2665 fmt.format = DTS_LBR;
2666 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302667 default:
2668 pr_err("Invalid format[%d]\n", format);
2669 goto fail_cmd;
2670 }
Alex Wong2caeecc2011-10-28 10:52:15 +05302671 fmt.cfg_size = 0;
2672
2673 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2674 if (rc < 0) {
2675 pr_err("%s:Comamnd open failed\n", __func__);
2676 goto fail_cmd;
2677 }
2678 rc = wait_event_timeout(ac->cmd_wait,
2679 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2680 if (!rc) {
2681 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2682 goto fail_cmd;
2683 }
2684 return 0;
2685fail_cmd:
2686 return -EINVAL;
2687}
2688
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002689int q6asm_media_format_block_wma(struct audio_client *ac,
2690 void *cfg)
2691{
2692 struct asm_stream_media_format_update fmt;
2693 struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
2694 int rc = 0;
2695
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002696 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 -07002697 ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
2698 wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
2699 wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
2700 wma_cfg->ch_mask, wma_cfg->encode_opt);
2701
2702 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2703
2704 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2705
2706 fmt.format = WMA_V9;
2707 fmt.cfg_size = sizeof(struct asm_wma_cfg);
2708 fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag;
2709 fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg;
2710 fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate;
2711 fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
2712 fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align;
2713 fmt.write_cfg.wma_cfg.valid_bits_per_sample =
2714 wma_cfg->valid_bits_per_sample;
2715 fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask;
2716 fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt;
2717 fmt.write_cfg.wma_cfg.adv_encode_opt = 0;
2718 fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0;
2719 fmt.write_cfg.wma_cfg.drc_peak_ref = 0;
2720 fmt.write_cfg.wma_cfg.drc_peak_target = 0;
2721 fmt.write_cfg.wma_cfg.drc_ave_ref = 0;
2722 fmt.write_cfg.wma_cfg.drc_ave_target = 0;
2723
2724 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2725 if (rc < 0) {
2726 pr_err("%s:Comamnd open failed\n", __func__);
2727 goto fail_cmd;
2728 }
2729 rc = wait_event_timeout(ac->cmd_wait,
2730 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2731 if (!rc) {
2732 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2733 goto fail_cmd;
2734 }
2735 return 0;
2736fail_cmd:
2737 return -EINVAL;
2738}
2739
2740int q6asm_media_format_block_wmapro(struct audio_client *ac,
2741 void *cfg)
2742{
2743 struct asm_stream_media_format_update fmt;
2744 struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
2745 int rc = 0;
2746
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002747 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 -07002748 ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
2749 wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
2750 wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
2751 wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
2752 wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
2753
2754 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2755
2756 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2757
2758 fmt.format = WMA_V10PRO;
2759 fmt.cfg_size = sizeof(struct asm_wmapro_cfg);
2760 fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag;
2761 fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg;
2762 fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate;
2763 fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec =
2764 wmapro_cfg->avg_bytes_per_sec;
2765 fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align;
2766 fmt.write_cfg.wmapro_cfg.valid_bits_per_sample =
2767 wmapro_cfg->valid_bits_per_sample;
2768 fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask;
2769 fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt;
2770 fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt;
2771 fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2;
2772 fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0;
2773 fmt.write_cfg.wmapro_cfg.drc_peak_target = 0;
2774 fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0;
2775 fmt.write_cfg.wmapro_cfg.drc_ave_target = 0;
2776
2777 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2778 if (rc < 0) {
2779 pr_err("%s:Comamnd open failed\n", __func__);
2780 goto fail_cmd;
2781 }
2782 rc = wait_event_timeout(ac->cmd_wait,
2783 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2784 if (!rc) {
2785 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2786 goto fail_cmd;
2787 }
2788 return 0;
2789fail_cmd:
2790 return -EINVAL;
2791}
2792
2793int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
2794 uint32_t bufsz, uint32_t bufcnt)
2795{
2796 struct asm_stream_cmd_memory_map mem_map;
2797 int rc = 0;
2798
2799 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2800 pr_err("APR handle NULL\n");
2801 return -EINVAL;
2802 }
2803
2804 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2805
2806 mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP;
2807
2808 mem_map.buf_add = buf_add;
2809 mem_map.buf_size = bufsz * bufcnt;
2810 mem_map.mempool_id = 0; /* EBI */
2811 mem_map.reserved = 0;
2812
2813 q6asm_add_mmaphdr(&mem_map.hdr,
2814 sizeof(struct asm_stream_cmd_memory_map), TRUE);
2815
2816 pr_debug("buf add[%x] buf_add_parameter[%x]\n",
2817 mem_map.buf_add, buf_add);
2818
2819 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map);
2820 if (rc < 0) {
2821 pr_err("mem_map op[0x%x]rc[%d]\n",
2822 mem_map.hdr.opcode, rc);
2823 rc = -EINVAL;
2824 goto fail_cmd;
2825 }
2826
2827 rc = wait_event_timeout(this_mmap.cmd_wait,
2828 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2829 if (!rc) {
2830 pr_err("timeout. waited for memory_map\n");
2831 rc = -EINVAL;
2832 goto fail_cmd;
2833 }
2834 rc = 0;
2835fail_cmd:
2836 return rc;
2837}
2838
2839int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
2840{
2841 struct asm_stream_cmd_memory_unmap mem_unmap;
2842 int rc = 0;
2843
2844 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2845 pr_err("APR handle NULL\n");
2846 return -EINVAL;
2847 }
2848 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2849
2850 q6asm_add_mmaphdr(&mem_unmap.hdr,
2851 sizeof(struct asm_stream_cmd_memory_unmap), TRUE);
2852 mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP;
2853 mem_unmap.buf_add = buf_add;
2854
2855 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_unmap);
2856 if (rc < 0) {
2857 pr_err("mem_unmap op[0x%x]rc[%d]\n",
2858 mem_unmap.hdr.opcode, rc);
2859 rc = -EINVAL;
2860 goto fail_cmd;
2861 }
2862
2863 rc = wait_event_timeout(this_mmap.cmd_wait,
2864 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2865 if (!rc) {
2866 pr_err("timeout. waited for memory_map\n");
2867 rc = -EINVAL;
2868 goto fail_cmd;
2869 }
2870 rc = 0;
2871fail_cmd:
2872 return rc;
2873}
2874
2875int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
2876{
2877 void *vol_cmd = NULL;
2878 void *payload = NULL;
2879 struct asm_pp_params_command *cmd = NULL;
2880 struct asm_lrchannel_gain_params *lrgain = NULL;
2881 int sz = 0;
2882 int rc = 0;
2883
2884 sz = sizeof(struct asm_pp_params_command) +
2885 + sizeof(struct asm_lrchannel_gain_params);
2886 vol_cmd = kzalloc(sz, GFP_KERNEL);
2887 if (vol_cmd == NULL) {
2888 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2889 rc = -EINVAL;
2890 return rc;
2891 }
2892 cmd = (struct asm_pp_params_command *)vol_cmd;
2893 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2894 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2895 cmd->payload = NULL;
2896 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2897 sizeof(struct asm_lrchannel_gain_params);
2898 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2899 cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID;
2900 cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params);
2901 cmd->params.reserved = 0;
2902
2903 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2904 lrgain = (struct asm_lrchannel_gain_params *)payload;
2905
2906 lrgain->left_gain = left_gain;
2907 lrgain->right_gain = right_gain;
2908 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2909 if (rc < 0) {
2910 pr_err("%s: Volume Command failed\n", __func__);
2911 rc = -EINVAL;
2912 goto fail_cmd;
2913 }
2914
2915 rc = wait_event_timeout(ac->cmd_wait,
2916 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2917 if (!rc) {
2918 pr_err("%s: timeout in sending volume command to apr\n",
2919 __func__);
2920 rc = -EINVAL;
2921 goto fail_cmd;
2922 }
2923 rc = 0;
2924fail_cmd:
2925 kfree(vol_cmd);
2926 return rc;
2927}
2928
2929static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
2930 uint32_t bufsz, uint32_t bufcnt)
2931{
2932 struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL;
2933 struct asm_memory_map_regions *mregions = NULL;
2934 struct audio_port_data *port = NULL;
2935 struct audio_buffer *ab = NULL;
2936 void *mmap_region_cmd = NULL;
2937 void *payload = NULL;
2938 int rc = 0;
2939 int i = 0;
2940 int cmd_size = 0;
2941
2942 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2943 pr_err("APR handle NULL\n");
2944 return -EINVAL;
2945 }
2946 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2947
2948 cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions)
2949 + sizeof(struct asm_memory_map_regions) * bufcnt;
2950
2951 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302952 if (mmap_region_cmd == NULL) {
2953 pr_err("%s: Mem alloc failed\n", __func__);
2954 rc = -EINVAL;
2955 return rc;
2956 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002957 mmap_regions = (struct asm_stream_cmd_memory_map_regions *)
2958 mmap_region_cmd;
2959 q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE);
2960 mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS;
2961 mmap_regions->mempool_id = 0;
2962 mmap_regions->nregions = bufcnt & 0x00ff;
2963 pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions);
2964 payload = ((u8 *) mmap_region_cmd +
2965 sizeof(struct asm_stream_cmd_memory_map_regions));
2966 mregions = (struct asm_memory_map_regions *)payload;
2967
2968 port = &ac->port[dir];
2969 for (i = 0; i < bufcnt; i++) {
2970 ab = &port->buf[i];
2971 mregions->phys = ab->phys;
2972 mregions->buf_size = ab->size;
2973 ++mregions;
2974 }
2975
2976 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) mmap_region_cmd);
2977 if (rc < 0) {
2978 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2979 mmap_regions->hdr.opcode, rc);
2980 rc = -EINVAL;
2981 goto fail_cmd;
2982 }
2983
2984 rc = wait_event_timeout(this_mmap.cmd_wait,
2985 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2986 if (!rc) {
2987 pr_err("timeout. waited for memory_map\n");
2988 rc = -EINVAL;
2989 goto fail_cmd;
2990 }
2991 rc = 0;
2992fail_cmd:
2993 kfree(mmap_region_cmd);
2994 return rc;
2995}
2996
2997static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
2998 uint32_t bufsz, uint32_t bufcnt)
2999{
3000 struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL;
3001 struct asm_memory_unmap_regions *mregions = NULL;
3002 struct audio_port_data *port = NULL;
3003 struct audio_buffer *ab = NULL;
3004 void *unmap_region_cmd = NULL;
3005 void *payload = NULL;
3006 int rc = 0;
3007 int i = 0;
3008 int cmd_size = 0;
3009
3010 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
3011 pr_err("APR handle NULL\n");
3012 return -EINVAL;
3013 }
3014 pr_debug("%s: Session[%d]\n", __func__, ac->session);
3015
3016 cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) +
3017 sizeof(struct asm_memory_unmap_regions) * bufcnt;
3018
3019 unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05303020 if (unmap_region_cmd == NULL) {
3021 pr_err("%s: Mem alloc failed\n", __func__);
3022 rc = -EINVAL;
3023 return rc;
3024 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003025 unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *)
3026 unmap_region_cmd;
3027 q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE);
3028 unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS;
3029 unmap_regions->nregions = bufcnt & 0x00ff;
3030 pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions);
3031 payload = ((u8 *) unmap_region_cmd +
3032 sizeof(struct asm_stream_cmd_memory_unmap_regions));
3033 mregions = (struct asm_memory_unmap_regions *)payload;
3034 port = &ac->port[dir];
3035 for (i = 0; i < bufcnt; i++) {
3036 ab = &port->buf[i];
3037 mregions->phys = ab->phys;
3038 ++mregions;
3039 }
3040
3041 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd);
3042 if (rc < 0) {
3043 pr_err("mmap_regions op[0x%x]rc[%d]\n",
3044 unmap_regions->hdr.opcode, rc);
3045 goto fail_cmd;
3046 }
3047
3048 rc = wait_event_timeout(this_mmap.cmd_wait,
3049 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
3050 if (!rc) {
3051 pr_err("timeout. waited for memory_unmap\n");
3052 goto fail_cmd;
3053 }
3054 rc = 0;
3055
3056fail_cmd:
3057 kfree(unmap_region_cmd);
3058 return rc;
3059}
3060
3061int q6asm_set_mute(struct audio_client *ac, int muteflag)
3062{
3063 void *vol_cmd = NULL;
3064 void *payload = NULL;
3065 struct asm_pp_params_command *cmd = NULL;
3066 struct asm_mute_params *mute = NULL;
3067 int sz = 0;
3068 int rc = 0;
3069
3070 sz = sizeof(struct asm_pp_params_command) +
3071 + sizeof(struct asm_mute_params);
3072 vol_cmd = kzalloc(sz, GFP_KERNEL);
3073 if (vol_cmd == NULL) {
3074 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3075 rc = -EINVAL;
3076 return rc;
3077 }
3078 cmd = (struct asm_pp_params_command *)vol_cmd;
3079 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3080 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3081 cmd->payload = NULL;
3082 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3083 sizeof(struct asm_mute_params);
3084 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3085 cmd->params.param_id = MUTE_CONFIG_PARAM_ID;
3086 cmd->params.param_size = sizeof(struct asm_mute_params);
3087 cmd->params.reserved = 0;
3088
3089 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3090 mute = (struct asm_mute_params *)payload;
3091
3092 mute->muteflag = muteflag;
3093 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3094 if (rc < 0) {
3095 pr_err("%s: Mute Command failed\n", __func__);
3096 rc = -EINVAL;
3097 goto fail_cmd;
3098 }
3099
3100 rc = wait_event_timeout(ac->cmd_wait,
3101 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3102 if (!rc) {
3103 pr_err("%s: timeout in sending mute command to apr\n",
3104 __func__);
3105 rc = -EINVAL;
3106 goto fail_cmd;
3107 }
3108 rc = 0;
3109fail_cmd:
3110 kfree(vol_cmd);
3111 return rc;
3112}
3113
3114int q6asm_set_volume(struct audio_client *ac, int volume)
3115{
3116 void *vol_cmd = NULL;
3117 void *payload = NULL;
3118 struct asm_pp_params_command *cmd = NULL;
3119 struct asm_master_gain_params *mgain = NULL;
3120 int sz = 0;
3121 int rc = 0;
3122
3123 sz = sizeof(struct asm_pp_params_command) +
3124 + sizeof(struct asm_master_gain_params);
3125 vol_cmd = kzalloc(sz, GFP_KERNEL);
3126 if (vol_cmd == NULL) {
3127 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3128 rc = -EINVAL;
3129 return rc;
3130 }
3131 cmd = (struct asm_pp_params_command *)vol_cmd;
3132 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3133 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3134 cmd->payload = NULL;
3135 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3136 sizeof(struct asm_master_gain_params);
3137 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3138 cmd->params.param_id = MASTER_GAIN_PARAM_ID;
3139 cmd->params.param_size = sizeof(struct asm_master_gain_params);
3140 cmd->params.reserved = 0;
3141
3142 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3143 mgain = (struct asm_master_gain_params *)payload;
3144
3145 mgain->master_gain = volume;
3146 mgain->padding = 0x00;
3147 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3148 if (rc < 0) {
3149 pr_err("%s: Volume Command failed\n", __func__);
3150 rc = -EINVAL;
3151 goto fail_cmd;
3152 }
3153
3154 rc = wait_event_timeout(ac->cmd_wait,
3155 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3156 if (!rc) {
3157 pr_err("%s: timeout in sending volume command to apr\n",
3158 __func__);
3159 rc = -EINVAL;
3160 goto fail_cmd;
3161 }
3162 rc = 0;
3163fail_cmd:
3164 kfree(vol_cmd);
3165 return rc;
3166}
3167
3168int q6asm_set_softpause(struct audio_client *ac,
3169 struct asm_softpause_params *pause_param)
3170{
3171 void *vol_cmd = NULL;
3172 void *payload = NULL;
3173 struct asm_pp_params_command *cmd = NULL;
3174 struct asm_softpause_params *params = NULL;
3175 int sz = 0;
3176 int rc = 0;
3177
3178 sz = sizeof(struct asm_pp_params_command) +
3179 + sizeof(struct asm_softpause_params);
3180 vol_cmd = kzalloc(sz, GFP_KERNEL);
3181 if (vol_cmd == NULL) {
3182 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3183 rc = -EINVAL;
3184 return rc;
3185 }
3186 cmd = (struct asm_pp_params_command *)vol_cmd;
3187 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3188 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3189 cmd->payload = NULL;
3190 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3191 sizeof(struct asm_softpause_params);
3192 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3193 cmd->params.param_id = SOFT_PAUSE_PARAM_ID;
3194 cmd->params.param_size = sizeof(struct asm_softpause_params);
3195 cmd->params.reserved = 0;
3196
3197 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3198 params = (struct asm_softpause_params *)payload;
3199
3200 params->enable = pause_param->enable;
3201 params->period = pause_param->period;
3202 params->step = pause_param->step;
3203 params->rampingcurve = pause_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003204 pr_debug("%s: soft Pause Command: enable = %d, period = %d, step = %d, curve = %d\n",
3205 __func__, params->enable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003206 params->period, params->step, params->rampingcurve);
3207 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3208 if (rc < 0) {
3209 pr_err("%s: Volume Command(soft_pause) failed\n", __func__);
3210 rc = -EINVAL;
3211 goto fail_cmd;
3212 }
3213
3214 rc = wait_event_timeout(ac->cmd_wait,
3215 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3216 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003217 pr_err("%s: timeout in sending volume command(soft_pause) to apr\n",
3218 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003219 rc = -EINVAL;
3220 goto fail_cmd;
3221 }
3222 rc = 0;
3223fail_cmd:
3224 kfree(vol_cmd);
3225 return rc;
3226}
3227
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003228int q6asm_set_softvolume(struct audio_client *ac,
3229 struct asm_softvolume_params *softvol_param)
3230{
3231 void *vol_cmd = NULL;
3232 void *payload = NULL;
3233 struct asm_pp_params_command *cmd = NULL;
3234 struct asm_softvolume_params *params = NULL;
3235 int sz = 0;
3236 int rc = 0;
3237
3238 sz = sizeof(struct asm_pp_params_command) +
3239 + sizeof(struct asm_softvolume_params);
3240 vol_cmd = kzalloc(sz, GFP_KERNEL);
3241 if (vol_cmd == NULL) {
3242 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3243 rc = -EINVAL;
3244 return rc;
3245 }
3246 cmd = (struct asm_pp_params_command *)vol_cmd;
3247 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3248 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3249 cmd->payload = NULL;
3250 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3251 sizeof(struct asm_softvolume_params);
3252 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3253 cmd->params.param_id = SOFT_VOLUME_PARAM_ID;
3254 cmd->params.param_size = sizeof(struct asm_softvolume_params);
3255 cmd->params.reserved = 0;
3256
3257 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3258 params = (struct asm_softvolume_params *)payload;
3259
3260 params->period = softvol_param->period;
3261 params->step = softvol_param->step;
3262 params->rampingcurve = softvol_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003263 pr_debug("%s: soft Volume:opcode = %d,payload_sz =%d,module_id =%d, param_id = %d, param_sz = %d\n",
3264 __func__,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003265 cmd->hdr.opcode, cmd->payload_size,
3266 cmd->params.module_id, cmd->params.param_id,
3267 cmd->params.param_size);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003268 pr_debug("%s: soft Volume Command: period = %d, step = %d, curve = %d\n",
3269 __func__, params->period,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003270 params->step, params->rampingcurve);
3271 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3272 if (rc < 0) {
3273 pr_err("%s: Volume Command(soft_volume) failed\n", __func__);
3274 rc = -EINVAL;
3275 goto fail_cmd;
3276 }
3277
3278 rc = wait_event_timeout(ac->cmd_wait,
3279 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3280 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003281 pr_err("%s: timeout in sending volume command(soft_volume) to apr\n",
3282 __func__);
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003283 rc = -EINVAL;
3284 goto fail_cmd;
3285 }
3286 rc = 0;
3287fail_cmd:
3288 kfree(vol_cmd);
3289 return rc;
3290}
3291
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003292int q6asm_equalizer(struct audio_client *ac, void *eq)
3293{
3294 void *eq_cmd = NULL;
3295 void *payload = NULL;
3296 struct asm_pp_params_command *cmd = NULL;
3297 struct asm_equalizer_params *equalizer = NULL;
3298 struct msm_audio_eq_stream_config *eq_params = NULL;
3299 int i = 0;
3300 int sz = 0;
3301 int rc = 0;
3302
3303 sz = sizeof(struct asm_pp_params_command) +
3304 + sizeof(struct asm_equalizer_params);
3305 eq_cmd = kzalloc(sz, GFP_KERNEL);
3306 if (eq_cmd == NULL) {
3307 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3308 rc = -EINVAL;
3309 goto fail_cmd;
3310 }
3311 eq_params = (struct msm_audio_eq_stream_config *) eq;
3312 cmd = (struct asm_pp_params_command *)eq_cmd;
3313 q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE);
3314 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3315 cmd->payload = NULL;
3316 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3317 sizeof(struct asm_equalizer_params);
3318 cmd->params.module_id = EQUALIZER_MODULE_ID;
3319 cmd->params.param_id = EQUALIZER_PARAM_ID;
3320 cmd->params.param_size = sizeof(struct asm_equalizer_params);
3321 cmd->params.reserved = 0;
3322 payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command));
3323 equalizer = (struct asm_equalizer_params *)payload;
3324
3325 equalizer->enable = eq_params->enable;
3326 equalizer->num_bands = eq_params->num_bands;
3327 pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
3328 eq_params->num_bands);
3329 for (i = 0; i < eq_params->num_bands; i++) {
3330 equalizer->eq_bands[i].band_idx =
3331 eq_params->eq_bands[i].band_idx;
3332 equalizer->eq_bands[i].filter_type =
3333 eq_params->eq_bands[i].filter_type;
3334 equalizer->eq_bands[i].center_freq_hz =
3335 eq_params->eq_bands[i].center_freq_hz;
3336 equalizer->eq_bands[i].filter_gain =
3337 eq_params->eq_bands[i].filter_gain;
3338 equalizer->eq_bands[i].q_factor =
3339 eq_params->eq_bands[i].q_factor;
3340 pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
3341 eq_params->eq_bands[i].filter_type, i);
3342 pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
3343 eq_params->eq_bands[i].center_freq_hz, i);
3344 pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
3345 eq_params->eq_bands[i].filter_gain, i);
3346 pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
3347 eq_params->eq_bands[i].q_factor, i);
3348 }
3349 rc = apr_send_pkt(ac->apr, (uint32_t *) eq_cmd);
3350 if (rc < 0) {
3351 pr_err("%s: Equalizer Command failed\n", __func__);
3352 rc = -EINVAL;
3353 goto fail_cmd;
3354 }
3355
3356 rc = wait_event_timeout(ac->cmd_wait,
3357 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3358 if (!rc) {
3359 pr_err("%s: timeout in sending equalizer command to apr\n",
3360 __func__);
3361 rc = -EINVAL;
3362 goto fail_cmd;
3363 }
3364 rc = 0;
3365fail_cmd:
3366 kfree(eq_cmd);
3367 return rc;
3368}
3369
3370int q6asm_read(struct audio_client *ac)
3371{
3372 struct asm_stream_cmd_read read;
3373 struct audio_buffer *ab;
3374 int dsp_buf;
3375 struct audio_port_data *port;
3376 int rc;
3377 if (!ac || ac->apr == NULL) {
3378 pr_err("APR handle NULL\n");
3379 return -EINVAL;
3380 }
Patrick Lai55f54c52012-11-17 00:29:07 -08003381 if (ac->io_mode & SYNC_IO_MODE) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003382 port = &ac->port[OUT];
3383
3384 q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
3385
3386 mutex_lock(&port->lock);
3387
3388 dsp_buf = port->dsp_buf;
3389 ab = &port->buf[dsp_buf];
3390
3391 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3392 __func__,
3393 ac->session,
3394 dsp_buf,
3395 (void *)port->buf[dsp_buf].data,
3396 port->cpu_buf,
3397 (void *)port->buf[port->cpu_buf].phys);
3398
3399 read.hdr.opcode = ASM_DATA_CMD_READ;
3400 read.buf_add = ab->phys;
3401 read.buf_size = ab->size;
3402 read.uid = port->dsp_buf;
3403 read.hdr.token = port->dsp_buf;
3404
3405 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3406 mutex_unlock(&port->lock);
3407 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3408 read.buf_add,
3409 read.hdr.token,
3410 read.uid);
3411 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3412 if (rc < 0) {
3413 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3414 goto fail_cmd;
3415 }
3416 return 0;
3417 }
3418fail_cmd:
3419 return -EINVAL;
3420}
3421
3422int q6asm_read_nolock(struct audio_client *ac)
3423{
3424 struct asm_stream_cmd_read read;
3425 struct audio_buffer *ab;
3426 int dsp_buf;
3427 struct audio_port_data *port;
3428 int rc;
3429 if (!ac || ac->apr == NULL) {
3430 pr_err("APR handle NULL\n");
3431 return -EINVAL;
3432 }
Patrick Lai55f54c52012-11-17 00:29:07 -08003433 if (ac->io_mode & SYNC_IO_MODE) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003434 port = &ac->port[OUT];
3435
3436 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3437
3438
3439 dsp_buf = port->dsp_buf;
3440 ab = &port->buf[dsp_buf];
3441
3442 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3443 __func__,
3444 ac->session,
3445 dsp_buf,
3446 (void *)port->buf[dsp_buf].data,
3447 port->cpu_buf,
3448 (void *)port->buf[port->cpu_buf].phys);
3449
3450 read.hdr.opcode = ASM_DATA_CMD_READ;
3451 read.buf_add = ab->phys;
3452 read.buf_size = ab->size;
3453 read.uid = port->dsp_buf;
3454 read.hdr.token = port->dsp_buf;
3455
3456 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
Patrick Lai55f54c52012-11-17 00:29:07 -08003457 pr_info("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003458 read.buf_add,
3459 read.hdr.token,
3460 read.uid);
3461 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3462 if (rc < 0) {
3463 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3464 goto fail_cmd;
3465 }
3466 return 0;
3467 }
3468fail_cmd:
3469 return -EINVAL;
3470}
3471
3472
3473static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
3474 uint32_t pkt_size, uint32_t cmd_flg)
3475{
3476 pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg,
3477 ac->session);
3478 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
3479 APR_HDR_LEN(sizeof(struct apr_hdr)),\
3480 APR_PKT_VER);
3481 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
3482 hdr->src_domain = APR_DOMAIN_APPS;
3483 hdr->dest_svc = APR_SVC_ASM;
3484 hdr->dest_domain = APR_DOMAIN_ADSP;
3485 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
3486 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
3487 if (cmd_flg) {
3488 hdr->token = ac->session;
3489 atomic_set(&ac->cmd_state, 1);
3490 }
3491 hdr->pkt_size = pkt_size;
3492 return;
3493}
3494
3495int q6asm_async_write(struct audio_client *ac,
3496 struct audio_aio_write_param *param)
3497{
3498 int rc = 0;
3499 struct asm_stream_cmd_write write;
3500
3501 if (!ac || ac->apr == NULL) {
3502 pr_err("%s: APR handle NULL\n", __func__);
3503 return -EINVAL;
3504 }
3505
3506 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE);
3507
3508 /* Pass physical address as token for AIO scheme */
3509 write.hdr.token = param->uid;
3510 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3511 write.buf_add = param->paddr;
3512 write.avail_bytes = param->len;
3513 write.uid = param->uid;
3514 write.msw_ts = param->msw_ts;
3515 write.lsw_ts = param->lsw_ts;
3516 /* Use 0xFF00 for disabling timestamps */
3517 if (param->flags == 0xFF00)
3518 write.uflags = (0x00000000 | (param->flags & 0x800000FF));
3519 else
3520 write.uflags = (0x80000000 | param->flags);
3521
3522 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3523 write.buf_add, write.avail_bytes);
3524
3525 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3526 if (rc < 0) {
3527 pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__,
3528 write.hdr.opcode, rc);
3529 goto fail_cmd;
3530 }
3531 return 0;
3532fail_cmd:
3533 return -EINVAL;
3534}
3535
3536int q6asm_async_read(struct audio_client *ac,
3537 struct audio_aio_read_param *param)
3538{
3539 int rc = 0;
3540 struct asm_stream_cmd_read read;
3541
3542 if (!ac || ac->apr == NULL) {
3543 pr_err("%s: APR handle NULL\n", __func__);
3544 return -EINVAL;
3545 }
3546
3547 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3548
3549 /* Pass physical address as token for AIO scheme */
3550 read.hdr.token = param->paddr;
3551 read.hdr.opcode = ASM_DATA_CMD_READ;
3552 read.buf_add = param->paddr;
3553 read.buf_size = param->len;
3554 read.uid = param->uid;
3555
3556 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3557 read.buf_add, read.buf_size);
3558
3559 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3560 if (rc < 0) {
3561 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3562 read.hdr.opcode, rc);
3563 goto fail_cmd;
3564 }
3565 return 0;
3566fail_cmd:
3567 return -EINVAL;
3568}
3569
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07003570int q6asm_async_read_compressed(struct audio_client *ac,
3571 struct audio_aio_read_param *param)
3572{
3573 int rc = 0;
3574 struct asm_stream_cmd_read read;
3575
3576 if (!ac || ac->apr == NULL) {
3577 pr_err("%s: APR handle NULL\n", __func__);
3578 return -EINVAL;
3579 }
3580
3581 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3582
3583 /* Pass physical address as token for AIO scheme */
3584 read.hdr.token = param->paddr;
3585 read.hdr.opcode = ASM_DATA_CMD_READ_COMPRESSED;
3586 read.buf_add = param->paddr;
3587 read.buf_size = param->len;
3588 read.uid = param->uid;
3589
3590 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3591 read.buf_add, read.buf_size);
3592
3593 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3594 if (rc < 0) {
3595 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3596 read.hdr.opcode, rc);
3597 goto fail_cmd;
3598 }
3599 return 0;
3600fail_cmd:
3601 return -EINVAL;
3602}
3603
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003604int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3605 uint32_t lsw_ts, uint32_t flags)
3606{
3607 int rc = 0;
3608 struct asm_stream_cmd_write write;
3609 struct audio_port_data *port;
3610 struct audio_buffer *ab;
3611 int dsp_buf = 0;
3612
3613 if (!ac || ac->apr == NULL) {
3614 pr_err("APR handle NULL\n");
3615 return -EINVAL;
3616 }
3617 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
Patrick Lai55f54c52012-11-17 00:29:07 -08003618 if (ac->io_mode & SYNC_IO_MODE) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003619 port = &ac->port[IN];
3620
3621 q6asm_add_hdr(ac, &write.hdr, sizeof(write),
3622 FALSE);
3623 mutex_lock(&port->lock);
3624
3625 dsp_buf = port->dsp_buf;
3626 ab = &port->buf[dsp_buf];
3627
3628 write.hdr.token = port->dsp_buf;
3629 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3630 write.buf_add = ab->phys;
3631 write.avail_bytes = len;
3632 write.uid = port->dsp_buf;
3633 write.msw_ts = msw_ts;
3634 write.lsw_ts = lsw_ts;
3635 /* Use 0xFF00 for disabling timestamps */
3636 if (flags == 0xFF00)
3637 write.uflags = (0x00000000 | (flags & 0x800000FF));
3638 else
3639 write.uflags = (0x80000000 | flags);
3640 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3641
3642 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3643 , __func__,
3644 ab->phys,
3645 write.buf_add,
3646 write.hdr.token,
3647 write.uid);
3648 mutex_unlock(&port->lock);
Rajesha Kini3498c932011-07-19 19:58:27 +05303649#ifdef CONFIG_DEBUG_FS
3650 if (out_enable_flag) {
3651 char zero_pattern[2] = {0x00, 0x00};
3652 /* If First two byte is non zero and last two byte
3653 is zero then it is warm output pattern */
3654 if ((strncmp(((char *)ab->data), zero_pattern, 2)) &&
3655 (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3656 do_gettimeofday(&out_warm_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003657 pr_debug("WARM:apr_send_pkt at %ld sec %ld microsec\n",
3658 out_warm_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303659 out_warm_tv.tv_usec);
3660 pr_debug("Warm Pattern Matched");
3661 }
3662 /* If First two byte is zero and last two byte is
3663 non zero then it is cont ouput pattern */
3664 else if ((!strncmp(((char *)ab->data), zero_pattern, 2))
3665 && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3666 do_gettimeofday(&out_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003667 pr_debug("CONT:apr_send_pkt at %ld sec %ld microsec\n",
3668 out_cont_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303669 out_cont_tv.tv_usec);
3670 pr_debug("Cont Pattern Matched");
3671 }
3672 }
3673#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003674 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3675 if (rc < 0) {
3676 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3677 goto fail_cmd;
3678 }
3679 pr_debug("%s: WRITE SUCCESS\n", __func__);
3680 return 0;
3681 }
3682fail_cmd:
3683 return -EINVAL;
3684}
3685
3686int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3687 uint32_t lsw_ts, uint32_t flags)
3688{
3689 int rc = 0;
3690 struct asm_stream_cmd_write write;
3691 struct audio_port_data *port;
3692 struct audio_buffer *ab;
3693 int dsp_buf = 0;
3694
3695 if (!ac || ac->apr == NULL) {
3696 pr_err("APR handle NULL\n");
3697 return -EINVAL;
3698 }
3699 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
Patrick Lai55f54c52012-11-17 00:29:07 -08003700 if (ac->io_mode & SYNC_IO_MODE) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003701 port = &ac->port[IN];
3702
3703 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
3704 FALSE);
3705
3706 dsp_buf = port->dsp_buf;
3707 ab = &port->buf[dsp_buf];
3708
3709 write.hdr.token = port->dsp_buf;
3710 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3711 write.buf_add = ab->phys;
3712 write.avail_bytes = len;
3713 write.uid = port->dsp_buf;
3714 write.msw_ts = msw_ts;
3715 write.lsw_ts = lsw_ts;
3716 /* Use 0xFF00 for disabling timestamps */
3717 if (flags == 0xFF00)
3718 write.uflags = (0x00000000 | (flags & 0x800000FF));
3719 else
3720 write.uflags = (0x80000000 | flags);
3721 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3722
3723 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3724 , __func__,
3725 ab->phys,
3726 write.buf_add,
3727 write.hdr.token,
3728 write.uid);
3729
3730 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3731 if (rc < 0) {
3732 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3733 goto fail_cmd;
3734 }
3735 pr_debug("%s: WRITE SUCCESS\n", __func__);
3736 return 0;
3737 }
3738fail_cmd:
3739 return -EINVAL;
3740}
3741
Patrick Lai3aabeae2013-01-06 00:52:34 -08003742int q6asm_get_session_time(struct audio_client *ac, uint64_t *tstamp)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003743{
3744 struct apr_hdr hdr;
3745 int rc;
3746
Patrick Lai3aabeae2013-01-06 00:52:34 -08003747 if (!ac || ac->apr == NULL || tstamp == NULL) {
3748 pr_err("APR handle or tstamp NULL\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003749 return -EINVAL;
3750 }
Swaminathan Sathappanc7f98992012-07-09 11:07:12 -07003751 q6asm_add_hdr(ac, &hdr, sizeof(hdr), FALSE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003752 hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME;
3753 atomic_set(&ac->time_flag, 1);
3754
3755 pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
3756 ac->session,
3757 hdr.opcode);
3758 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3759 if (rc < 0) {
3760 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3761 goto fail_cmd;
3762 }
3763 rc = wait_event_timeout(ac->time_wait,
3764 (atomic_read(&ac->time_flag) == 0), 5*HZ);
3765 if (!rc) {
3766 pr_err("%s: timeout in getting session time from DSP\n",
3767 __func__);
3768 goto fail_cmd;
3769 }
Patrick Lai3aabeae2013-01-06 00:52:34 -08003770
3771 *tstamp = ac->time_stamp;
3772 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003773
3774fail_cmd:
3775 return -EINVAL;
3776}
3777
3778int q6asm_cmd(struct audio_client *ac, int cmd)
3779{
3780 struct apr_hdr hdr;
3781 int rc;
3782 atomic_t *state;
3783 int cnt = 0;
3784
3785 if (!ac || ac->apr == NULL) {
3786 pr_err("APR handle NULL\n");
3787 return -EINVAL;
3788 }
3789 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3790 switch (cmd) {
3791 case CMD_PAUSE:
3792 pr_debug("%s:CMD_PAUSE\n", __func__);
3793 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3794 state = &ac->cmd_state;
3795 break;
3796 case CMD_FLUSH:
3797 pr_debug("%s:CMD_FLUSH\n", __func__);
3798 hdr.opcode = ASM_STREAM_CMD_FLUSH;
3799 state = &ac->cmd_state;
3800 break;
3801 case CMD_OUT_FLUSH:
3802 pr_debug("%s:CMD_OUT_FLUSH\n", __func__);
3803 hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
3804 state = &ac->cmd_state;
3805 break;
3806 case CMD_EOS:
3807 pr_debug("%s:CMD_EOS\n", __func__);
3808 hdr.opcode = ASM_DATA_CMD_EOS;
3809 atomic_set(&ac->cmd_state, 0);
3810 state = &ac->cmd_state;
3811 break;
3812 case CMD_CLOSE:
3813 pr_debug("%s:CMD_CLOSE\n", __func__);
3814 hdr.opcode = ASM_STREAM_CMD_CLOSE;
Laxminath Kasamf16d3fd2012-12-19 14:54:14 +05303815 atomic_set(&ac->cmd_close_state, 1);
3816 state = &ac->cmd_close_state;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003817 break;
3818 default:
3819 pr_err("Invalid format[%d]\n", cmd);
3820 goto fail_cmd;
3821 }
3822 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3823 ac->session,
3824 hdr.opcode);
3825 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3826 if (rc < 0) {
3827 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3828 goto fail_cmd;
3829 }
3830 rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ);
3831 if (!rc) {
3832 pr_err("timeout. waited for response opcode[0x%x]\n",
3833 hdr.opcode);
3834 goto fail_cmd;
3835 }
3836 if (cmd == CMD_FLUSH)
3837 q6asm_reset_buf_state(ac);
3838 if (cmd == CMD_CLOSE) {
3839 /* check if DSP return all buffers */
3840 if (ac->port[IN].buf) {
3841 for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
3842 cnt++) {
3843 if (ac->port[IN].buf[cnt].used == IN) {
3844 pr_debug("Write Buf[%d] not returned\n",
3845 cnt);
3846 }
3847 }
3848 }
3849 if (ac->port[OUT].buf) {
3850 for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
3851 if (ac->port[OUT].buf[cnt].used == OUT) {
3852 pr_debug("Read Buf[%d] not returned\n",
3853 cnt);
3854 }
3855 }
3856 }
3857 }
3858 return 0;
3859fail_cmd:
3860 return -EINVAL;
3861}
3862
3863int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
3864{
3865 struct apr_hdr hdr;
3866 int rc;
3867
3868 if (!ac || ac->apr == NULL) {
3869 pr_err("%s:APR handle NULL\n", __func__);
3870 return -EINVAL;
3871 }
3872 q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE);
3873 switch (cmd) {
3874 case CMD_PAUSE:
3875 pr_debug("%s:CMD_PAUSE\n", __func__);
3876 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3877 break;
3878 case CMD_EOS:
3879 pr_debug("%s:CMD_EOS\n", __func__);
3880 hdr.opcode = ASM_DATA_CMD_EOS;
3881 break;
3882 default:
3883 pr_err("%s:Invalid format[%d]\n", __func__, cmd);
3884 goto fail_cmd;
3885 }
3886 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3887 ac->session,
3888 hdr.opcode);
Jay Wang0668d1062012-07-11 18:53:21 -07003889
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003890 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3891 if (rc < 0) {
3892 pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
3893 goto fail_cmd;
3894 }
Jay Wang0668d1062012-07-11 18:53:21 -07003895 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003896 return 0;
3897fail_cmd:
3898 return -EINVAL;
3899}
3900
3901static void q6asm_reset_buf_state(struct audio_client *ac)
3902{
3903 int cnt = 0;
3904 int loopcnt = 0;
Patrick Lai55f54c52012-11-17 00:29:07 -08003905 int used;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003906 struct audio_port_data *port = NULL;
3907
Patrick Lai55f54c52012-11-17 00:29:07 -08003908 if (ac->io_mode & SYNC_IO_MODE) {
3909 used = (ac->io_mode & TUN_WRITE_IO_MODE ? 1 : 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003910 mutex_lock(&ac->cmd_lock);
3911 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
3912 port = &ac->port[loopcnt];
3913 cnt = port->max_buf_cnt - 1;
3914 port->dsp_buf = 0;
3915 port->cpu_buf = 0;
3916 while (cnt >= 0) {
3917 if (!port->buf)
3918 continue;
Patrick Lai55f54c52012-11-17 00:29:07 -08003919 port->buf[cnt].used = used;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003920 cnt--;
3921 }
3922 }
3923 mutex_unlock(&ac->cmd_lock);
3924 }
3925}
3926
3927int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
3928{
3929 struct asm_stream_cmd_reg_tx_overflow_event tx_overflow;
3930 int rc;
3931
3932 if (!ac || ac->apr == NULL) {
3933 pr_err("APR handle NULL\n");
3934 return -EINVAL;
3935 }
3936 pr_debug("%s:session[%d]enable[%d]\n", __func__,
3937 ac->session, enable);
3938 q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
3939
3940 tx_overflow.hdr.opcode = \
3941 ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS;
3942 /* tx overflow event: enable */
3943 tx_overflow.enable = enable;
3944
3945 rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
3946 if (rc < 0) {
3947 pr_err("tx overflow op[0x%x]rc[%d]\n", \
3948 tx_overflow.hdr.opcode, rc);
3949 goto fail_cmd;
3950 }
3951 rc = wait_event_timeout(ac->cmd_wait,
3952 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3953 if (!rc) {
3954 pr_err("timeout. waited for tx overflow\n");
3955 goto fail_cmd;
3956 }
3957 return 0;
3958fail_cmd:
3959 return -EINVAL;
3960}
3961
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003962int q6asm_get_apr_service_id(int session_id)
3963{
3964 pr_debug("%s\n", __func__);
3965
Shiv Maliyappanahallia84982a2012-01-19 15:25:04 -08003966 if (session_id < 0 || session_id > SESSION_MAX) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003967 pr_err("%s: invalid session_id = %d\n", __func__, session_id);
3968 return -EINVAL;
3969 }
3970
3971 return ((struct apr_svc *)session[session_id]->apr)->id;
3972}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003973
3974
3975static int __init q6asm_init(void)
3976{
3977 pr_debug("%s\n", __func__);
3978 init_waitqueue_head(&this_mmap.cmd_wait);
3979 memset(session, 0, sizeof(session));
Rajesha Kini3498c932011-07-19 19:58:27 +05303980#ifdef CONFIG_DEBUG_FS
3981 out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
3982 out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
Glenn Kasten5dfda802012-10-04 16:40:27 -07003983 0664,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303984 NULL, NULL, &audio_output_latency_debug_fops);
3985 if (IS_ERR(out_dentry))
3986 pr_err("debugfs_create_file failed\n");
3987 in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
3988 in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
Glenn Kasten5dfda802012-10-04 16:40:27 -07003989 0664,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303990 NULL, NULL, &audio_input_latency_debug_fops);
3991 if (IS_ERR(in_dentry))
3992 pr_err("debugfs_create_file failed\n");
3993#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003994 return 0;
3995}
3996
3997device_initcall(q6asm_init);