blob: 2280fd1e21e9baf0cf56a4bc043698e886a8e64a [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);
223 if (ac->io_mode == SYNC_IO_MODE) {
224 port = &ac->port[dir];
225 if (!port->buf) {
226 mutex_unlock(&ac->cmd_lock);
227 return 0;
228 }
229 cnt = port->max_buf_cnt - 1;
230
231 if (cnt >= 0) {
232 rc = q6asm_memory_unmap_regions(ac, dir,
233 port->buf[0].size,
234 port->max_buf_cnt);
235 if (rc < 0)
236 pr_err("%s CMD Memory_unmap_regions failed\n",
237 __func__);
238 }
239
240 while (cnt >= 0) {
241 if (port->buf[cnt].data) {
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800242#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
243 ion_unmap_kernel(port->buf[cnt].client,
244 port->buf[cnt].handle);
245 ion_free(port->buf[cnt].client,
246 port->buf[cnt].handle);
247 ion_client_destroy(port->buf[cnt].client);
248#else
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700249 pr_debug("%s:data[%p]phys[%p][%p] cnt[%d] mem_buffer[%p]\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700250 __func__, (void *)port->buf[cnt].data,
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700251 (void *)port->buf[cnt].phys,
252 (void *)&port->buf[cnt].phys, cnt,
253 (void *)port->buf[cnt].mem_buffer);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700254 if (IS_ERR((void *)port->buf[cnt].mem_buffer))
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700255 pr_err("%s:mem buffer invalid, error = %ld\n",
256 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700257 PTR_ERR((void *)port->buf[cnt].mem_buffer));
258 else {
Laura Abbottea3e7b62012-04-30 15:59:21 -0700259 if (iounmap(
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700260 port->buf[cnt].mem_buffer) < 0)
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700261 pr_err("%s: unmap buffer failed\n",
262 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700263 }
264 free_contiguous_memory_by_paddr(
265 port->buf[cnt].phys);
266
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800267#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700268 port->buf[cnt].data = NULL;
269 port->buf[cnt].phys = 0;
270 --(port->max_buf_cnt);
271 }
272 --cnt;
273 }
274 kfree(port->buf);
275 port->buf = NULL;
276 }
277 mutex_unlock(&ac->cmd_lock);
278 return 0;
279}
280
281int q6asm_audio_client_buf_free_contiguous(unsigned int dir,
282 struct audio_client *ac)
283{
284 struct audio_port_data *port;
285 int cnt = 0;
286 int rc = 0;
287 pr_debug("%s: Session id %d\n", __func__, ac->session);
288 mutex_lock(&ac->cmd_lock);
289 port = &ac->port[dir];
290 if (!port->buf) {
291 mutex_unlock(&ac->cmd_lock);
292 return 0;
293 }
294 cnt = port->max_buf_cnt - 1;
295
296 if (cnt >= 0) {
Deepa Madiregama7d52a402011-07-13 20:28:36 +0530297 rc = q6asm_memory_unmap(ac, port->buf[0].phys, dir);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700298 if (rc < 0)
299 pr_err("%s CMD Memory_unmap_regions failed\n",
300 __func__);
301 }
302
303 if (port->buf[0].data) {
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800304#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
305 ion_unmap_kernel(port->buf[0].client, port->buf[0].handle);
306 ion_free(port->buf[0].client, port->buf[0].handle);
307 ion_client_destroy(port->buf[0].client);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700308 pr_debug("%s:data[%p]phys[%p][%p], client[%p] handle[%p]\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800309 __func__,
310 (void *)port->buf[0].data,
311 (void *)port->buf[0].phys,
312 (void *)&port->buf[0].phys,
313 (void *)port->buf[0].client,
314 (void *)port->buf[0].handle);
315#else
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700316 pr_debug("%s:data[%p]phys[%p][%p] mem_buffer[%p]\n",
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700317 __func__,
318 (void *)port->buf[0].data,
319 (void *)port->buf[0].phys,
320 (void *)&port->buf[0].phys,
321 (void *)port->buf[0].mem_buffer);
322 if (IS_ERR((void *)port->buf[0].mem_buffer))
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700323 pr_err("%s:mem buffer invalid, error = %ld\n",
324 __func__,
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700325 PTR_ERR((void *)port->buf[0].mem_buffer));
326 else {
Laura Abbottea3e7b62012-04-30 15:59:21 -0700327 if (iounmap(
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700328 port->buf[0].mem_buffer) < 0)
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700329 pr_err("%s: unmap buffer failed\n", __func__);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700330 }
331 free_contiguous_memory_by_paddr(port->buf[0].phys);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800332#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700333 }
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700334
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700335 while (cnt >= 0) {
336 port->buf[cnt].data = NULL;
337 port->buf[cnt].phys = 0;
338 cnt--;
339 }
340 port->max_buf_cnt = 0;
341 kfree(port->buf);
342 port->buf = NULL;
343 mutex_unlock(&ac->cmd_lock);
344 return 0;
345}
346
347void q6asm_audio_client_free(struct audio_client *ac)
348{
349 int loopcnt;
350 struct audio_port_data *port;
351 if (!ac || !ac->session)
352 return;
353 pr_debug("%s: Session id %d\n", __func__, ac->session);
354 if (ac->io_mode == SYNC_IO_MODE) {
355 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
356 port = &ac->port[loopcnt];
357 if (!port->buf)
358 continue;
359 pr_debug("%s:loopcnt = %d\n", __func__, loopcnt);
360 q6asm_audio_client_buf_free(loopcnt, ac);
361 }
362 }
363
364 apr_deregister(ac->apr);
365 q6asm_session_free(ac);
366
367 pr_debug("%s: APR De-Register\n", __func__);
368 if (atomic_read(&this_mmap.ref_cnt) <= 0) {
369 pr_err("%s: APR Common Port Already Closed\n", __func__);
370 goto done;
371 }
372
373 atomic_dec(&this_mmap.ref_cnt);
374 if (atomic_read(&this_mmap.ref_cnt) == 0) {
375 apr_deregister(this_mmap.apr);
376 pr_debug("%s:APR De-Register common port\n", __func__);
377 }
378done:
379 kfree(ac);
380 return;
381}
382
383int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode)
384{
385 if (ac == NULL) {
386 pr_err("%s APR handle NULL\n", __func__);
387 return -EINVAL;
388 }
389 if ((mode == ASYNC_IO_MODE) || (mode == SYNC_IO_MODE)) {
390 ac->io_mode = mode;
391 pr_debug("%s:Set Mode to %d\n", __func__, ac->io_mode);
392 return 0;
393 } else {
394 pr_err("%s:Not an valid IO Mode:%d\n", __func__, ac->io_mode);
395 return -EINVAL;
396 }
397}
398
399struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv)
400{
401 struct audio_client *ac;
402 int n;
403 int lcnt = 0;
404
405 ac = kzalloc(sizeof(struct audio_client), GFP_KERNEL);
406 if (!ac)
407 return NULL;
408 n = q6asm_session_alloc(ac);
409 if (n <= 0)
410 goto fail_session;
411 ac->session = n;
412 ac->cb = cb;
413 ac->priv = priv;
414 ac->io_mode = SYNC_IO_MODE;
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700415 ac->perf_mode = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700416 ac->apr = apr_register("ADSP", "ASM", \
417 (apr_fn)q6asm_callback,\
418 ((ac->session) << 8 | 0x0001),\
419 ac);
420
421 if (ac->apr == NULL) {
422 pr_err("%s Registration with APR failed\n", __func__);
423 goto fail;
424 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700425 rtac_set_asm_handle(n, ac->apr);
Ben Rombergerfce8f512011-07-18 16:46:09 -0700426
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700427 pr_debug("%s Registering the common port with APR\n", __func__);
428 if (atomic_read(&this_mmap.ref_cnt) == 0) {
429 this_mmap.apr = apr_register("ADSP", "ASM", \
430 (apr_fn)q6asm_mmapcallback,\
431 0x0FFFFFFFF, &this_mmap);
432 if (this_mmap.apr == NULL) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700433 pr_debug("%s Unable to register APR ASM common port\n",
434 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700435 goto fail;
436 }
437 }
438
439 atomic_inc(&this_mmap.ref_cnt);
440 init_waitqueue_head(&ac->cmd_wait);
441 init_waitqueue_head(&ac->time_wait);
442 atomic_set(&ac->time_flag, 1);
443 mutex_init(&ac->cmd_lock);
444 for (lcnt = 0; lcnt <= OUT; lcnt++) {
445 mutex_init(&ac->port[lcnt].lock);
446 spin_lock_init(&ac->port[lcnt].dsp_lock);
447 }
448 atomic_set(&ac->cmd_state, 0);
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530449 atomic_set(&ac->cmd_response, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700450
451 pr_debug("%s: session[%d]\n", __func__, ac->session);
452
453 return ac;
454fail:
455 q6asm_audio_client_free(ac);
456 return NULL;
457fail_session:
458 kfree(ac);
459 return NULL;
460}
461
Ben Romberger61754dc2011-10-31 18:25:41 -0700462struct audio_client *q6asm_get_audio_client(int session_id)
463{
464 if ((session_id <= 0) || (session_id > SESSION_MAX)) {
465 pr_err("%s: invalid session: %d\n", __func__, session_id);
466 goto err;
467 }
468
469 if (!session[session_id]) {
470 pr_err("%s: session not active: %d\n", __func__, session_id);
471 goto err;
472 }
473
474 return session[session_id];
475err:
476 return NULL;
477}
478
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700479int q6asm_audio_client_buf_alloc(unsigned int dir,
480 struct audio_client *ac,
481 unsigned int bufsz,
482 unsigned int bufcnt)
483{
484 int cnt = 0;
485 int rc = 0;
486 struct audio_buffer *buf;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800487#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
488 int len;
489#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700490
491 if (!(ac) || ((dir != IN) && (dir != OUT)))
492 return -EINVAL;
493
494 pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n", __func__, ac->session,
495 bufsz, bufcnt);
496
497 if (ac->session <= 0 || ac->session > 8)
498 goto fail;
499
500 if (ac->io_mode == SYNC_IO_MODE) {
501 if (ac->port[dir].buf) {
502 pr_debug("%s: buffer already allocated\n", __func__);
503 return 0;
504 }
505 mutex_lock(&ac->cmd_lock);
506 buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
507 GFP_KERNEL);
508
509 if (!buf) {
510 mutex_unlock(&ac->cmd_lock);
511 goto fail;
512 }
513
514 ac->port[dir].buf = buf;
515
516 while (cnt < bufcnt) {
517 if (bufsz > 0) {
518 if (!buf[cnt].data) {
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800519#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
520 buf[cnt].client = msm_ion_client_create
521 (UINT_MAX, "audio_client");
522 if (IS_ERR_OR_NULL((void *)
523 buf[cnt].client)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700524 pr_err("%s: ION create client for AUDIO failed\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800525 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700526 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800527 goto fail;
528 }
529 buf[cnt].handle = ion_alloc
530 (buf[cnt].client, bufsz, SZ_4K,
Hanumant Singh2ac41c92012-08-29 18:39:44 -0700531 (0x1 << ION_AUDIO_HEAP_ID), 0);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800532 if (IS_ERR_OR_NULL((void *)
533 buf[cnt].handle)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700534 pr_err("%s: ION memory allocation for AUDIO failed\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800535 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700536 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800537 goto fail;
538 }
539
540 rc = ion_phys(buf[cnt].client,
541 buf[cnt].handle,
542 (ion_phys_addr_t *)
543 &buf[cnt].phys,
544 (size_t *)&len);
545 if (rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700546 pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800547 __func__, rc);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700548 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800549 goto fail;
550 }
551
552 buf[cnt].data = ion_map_kernel
Mitchel Humpherys456e2682012-09-12 14:42:50 -0700553 (buf[cnt].client, buf[cnt].handle);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800554 if (IS_ERR_OR_NULL((void *)
555 buf[cnt].data)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700556 pr_err("%s: ION memory mapping for AUDIO failed\n",
557 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700558 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800559 goto fail;
560 }
561 memset((void *)buf[cnt].data, 0, bufsz);
562#else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700563 unsigned int flags = 0;
564 buf[cnt].phys =
565 allocate_contiguous_ebi_nomap(bufsz,
566 SZ_4K);
567 if (!buf[cnt].phys) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700568 pr_err("%s:Buf alloc failed size=%d\n",
569 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700570 bufsz);
571 mutex_unlock(&ac->cmd_lock);
572 goto fail;
573 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700574 buf[cnt].mem_buffer =
Laura Abbottea3e7b62012-04-30 15:59:21 -0700575 ioremap(buf[cnt].phys, bufsz);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700576 if (IS_ERR(
577 (void *)buf[cnt].mem_buffer)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700578 pr_err("%s:map_buffer failed, error = %ld\n",
579 __func__,
580 PTR_ERR((void *)buf[cnt].mem_buffer));
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -0800581 mutex_unlock(&ac->cmd_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700582 goto fail;
583 }
584 buf[cnt].data =
Laura Abbottea3e7b62012-04-30 15:59:21 -0700585 buf[cnt].mem_buffer;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700586 if (!buf[cnt].data) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700587 pr_err("%s:invalid vaddr, iomap failed\n",
588 __func__);
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -0800589 mutex_unlock(&ac->cmd_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700590 goto fail;
591 }
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800592#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700593 buf[cnt].used = 1;
594 buf[cnt].size = bufsz;
595 buf[cnt].actual_size = bufsz;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800596 pr_debug("%s data[%p]phys[%p][%p]\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700597 __func__,
598 (void *)buf[cnt].data,
599 (void *)buf[cnt].phys,
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800600 (void *)&buf[cnt].phys);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700601 cnt++;
602 }
603 }
604 }
605 ac->port[dir].max_buf_cnt = cnt;
606
607 mutex_unlock(&ac->cmd_lock);
608 rc = q6asm_memory_map_regions(ac, dir, bufsz, cnt);
609 if (rc < 0) {
610 pr_err("%s:CMD Memory_map_regions failed\n", __func__);
611 goto fail;
612 }
613 }
614 return 0;
615fail:
616 q6asm_audio_client_buf_free(dir, ac);
617 return -EINVAL;
618}
619
620int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir,
621 struct audio_client *ac,
622 unsigned int bufsz,
623 unsigned int bufcnt)
624{
625 int cnt = 0;
626 int rc = 0;
627 struct audio_buffer *buf;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800628#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
629 int len;
630#else
631 int flags = 0;
632#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700633 if (!(ac) || ((dir != IN) && (dir != OUT)))
634 return -EINVAL;
635
636 pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n",
637 __func__, ac->session,
638 bufsz, bufcnt);
639
640 if (ac->session <= 0 || ac->session > 8)
641 goto fail;
642
643 if (ac->port[dir].buf) {
644 pr_debug("%s: buffer already allocated\n", __func__);
645 return 0;
646 }
647 mutex_lock(&ac->cmd_lock);
648 buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
649 GFP_KERNEL);
650
651 if (!buf) {
652 mutex_unlock(&ac->cmd_lock);
653 goto fail;
654 }
655
656 ac->port[dir].buf = buf;
657
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800658#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
659 buf[0].client = msm_ion_client_create(UINT_MAX, "audio_client");
660 if (IS_ERR_OR_NULL((void *)buf[0].client)) {
661 pr_err("%s: ION create client for AUDIO failed\n", __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700662 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800663 goto fail;
664 }
665 buf[0].handle = ion_alloc(buf[0].client, bufsz * bufcnt, SZ_4K,
Hanumant Singh2ac41c92012-08-29 18:39:44 -0700666 (0x1 << ION_AUDIO_HEAP_ID), 0);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800667 if (IS_ERR_OR_NULL((void *) buf[0].handle)) {
668 pr_err("%s: ION memory allocation for AUDIO failed\n",
669 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700670 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800671 goto fail;
672 }
673
674 rc = ion_phys(buf[0].client, buf[0].handle,
675 (ion_phys_addr_t *)&buf[0].phys, (size_t *)&len);
676 if (rc) {
677 pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
678 __func__, rc);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700679 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800680 goto fail;
681 }
682
Mitchel Humpherys456e2682012-09-12 14:42:50 -0700683 buf[0].data = ion_map_kernel(buf[0].client, buf[0].handle);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800684 if (IS_ERR_OR_NULL((void *) buf[0].data)) {
685 pr_err("%s: ION memory mapping for AUDIO failed\n", __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700686 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800687 goto fail;
688 }
689 memset((void *)buf[0].data, 0, (bufsz * bufcnt));
690#else
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700691 buf[0].phys = allocate_contiguous_ebi_nomap(bufsz * bufcnt,
692 SZ_4K);
693 if (!buf[0].phys) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700694 pr_err("%s:Buf alloc failed size=%d, bufcnt=%d\n",
695 __func__, bufsz, bufcnt);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700696 mutex_unlock(&ac->cmd_lock);
697 goto fail;
698 }
699
Laura Abbottea3e7b62012-04-30 15:59:21 -0700700 buf[0].mem_buffer = ioremap(buf[0].phys, bufsz * bufcnt);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700701 if (IS_ERR((void *)buf[cnt].mem_buffer)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700702 pr_err("%s:map_buffer failed, error = %ld\n",
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700703 __func__, PTR_ERR((void *)buf[0].mem_buffer));
704
705 mutex_unlock(&ac->cmd_lock);
706 goto fail;
707 }
Laura Abbottea3e7b62012-04-30 15:59:21 -0700708 buf[0].data = buf[0].mem_buffer;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800709#endif
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700710 if (!buf[0].data) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700711 pr_err("%s:invalid vaddr, iomap failed\n", __func__);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700712 mutex_unlock(&ac->cmd_lock);
713 goto fail;
714 }
715
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700716 buf[0].used = dir ^ 1;
717 buf[0].size = bufsz;
718 buf[0].actual_size = bufsz;
719 cnt = 1;
720 while (cnt < bufcnt) {
721 if (bufsz > 0) {
722 buf[cnt].data = buf[0].data + (cnt * bufsz);
723 buf[cnt].phys = buf[0].phys + (cnt * bufsz);
724 if (!buf[cnt].data) {
725 pr_err("%s Buf alloc failed\n",
726 __func__);
727 mutex_unlock(&ac->cmd_lock);
728 goto fail;
729 }
730 buf[cnt].used = dir ^ 1;
731 buf[cnt].size = bufsz;
732 buf[cnt].actual_size = bufsz;
733 pr_debug("%s data[%p]phys[%p][%p]\n", __func__,
734 (void *)buf[cnt].data,
735 (void *)buf[cnt].phys,
736 (void *)&buf[cnt].phys);
737 }
738 cnt++;
739 }
740 ac->port[dir].max_buf_cnt = cnt;
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -0700741
742 pr_debug("%s ac->port[%d].max_buf_cnt[%d]\n", __func__, dir,
743 ac->port[dir].max_buf_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700744 mutex_unlock(&ac->cmd_lock);
745 rc = q6asm_memory_map(ac, buf[0].phys, dir, bufsz, cnt);
746 if (rc < 0) {
747 pr_err("%s:CMD Memory_map_regions failed\n", __func__);
748 goto fail;
749 }
750 return 0;
751fail:
752 q6asm_audio_client_buf_free_contiguous(dir, ac);
753 return -EINVAL;
754}
755
756static int32_t q6asm_mmapcallback(struct apr_client_data *data, void *priv)
757{
758 uint32_t token;
759 uint32_t *payload = data->payload;
760
761 if (data->opcode == RESET_EVENTS) {
762 pr_debug("%s: Reset event is received: %d %d apr[%p]\n",
763 __func__,
764 data->reset_event,
765 data->reset_proc,
766 this_mmap.apr);
767 apr_reset(this_mmap.apr);
768 this_mmap.apr = NULL;
769 atomic_set(&this_mmap.cmd_state, 0);
770 return 0;
771 }
772
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700773 pr_debug("%s:ptr0[0x%x]ptr1[0x%x]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n",
774 __func__, payload[0], payload[1], data->opcode, data->token,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700775 data->payload_size, data->src_port, data->dest_port);
776
777 if (data->opcode == APR_BASIC_RSP_RESULT) {
778 token = data->token;
779 switch (payload[0]) {
780 case ASM_SESSION_CMD_MEMORY_MAP:
781 case ASM_SESSION_CMD_MEMORY_UNMAP:
782 case ASM_SESSION_CMD_MEMORY_MAP_REGIONS:
783 case ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS:
784 pr_debug("%s:command[0x%x]success [0x%x]\n",
785 __func__, payload[0], payload[1]);
786 if (atomic_read(&this_mmap.cmd_state)) {
787 atomic_set(&this_mmap.cmd_state, 0);
788 wake_up(&this_mmap.cmd_wait);
789 }
790 break;
791 default:
792 pr_debug("%s:command[0x%x] not expecting rsp\n",
793 __func__, payload[0]);
794 break;
795 }
796 }
797 return 0;
798}
799
Jay Wangcd1d37d2012-10-03 16:17:18 -0700800static int32_t is_no_wait_cmd_rsp(uint32_t opcode, uint32_t *cmd_type)
801{
802 if (opcode == APR_BASIC_RSP_RESULT) {
803 if (cmd_type != NULL) {
804 switch (cmd_type[0]) {
805 case ASM_SESSION_CMD_RUN:
806 case ASM_SESSION_CMD_PAUSE:
807 case ASM_DATA_CMD_EOS:
808 return 1;
809 default:
810 break;
811 }
812 } else
813 pr_err("%s: null pointer!", __func__);
814 } else if (opcode == ASM_DATA_CMDRSP_EOS)
815 return 1;
816
817 return 0;
818}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700819
820static int32_t q6asm_callback(struct apr_client_data *data, void *priv)
821{
822 int i = 0;
823 struct audio_client *ac = (struct audio_client *)priv;
824 uint32_t token;
825 unsigned long dsp_flags;
826 uint32_t *payload;
Jay Wang0668d1062012-07-11 18:53:21 -0700827 uint32_t wakeup_flag = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700828
829
830 if ((ac == NULL) || (data == NULL)) {
831 pr_err("ac or priv NULL\n");
832 return -EINVAL;
833 }
834 if (ac->session <= 0 || ac->session > 8) {
835 pr_err("%s:Session ID is invalid, session = %d\n", __func__,
836 ac->session);
837 return -EINVAL;
838 }
Jay Wangcd1d37d2012-10-03 16:17:18 -0700839
840 payload = data->payload;
841 if ((atomic_read(&ac->nowait_cmd_cnt) > 0) &&
842 is_no_wait_cmd_rsp(data->opcode, payload)) {
Jay Wang0668d1062012-07-11 18:53:21 -0700843 pr_debug("%s: nowait_cmd_cnt %d\n",
844 __func__,
845 atomic_read(&ac->nowait_cmd_cnt));
846 atomic_dec(&ac->nowait_cmd_cnt);
847 wakeup_flag = 0;
848 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700849
850 if (data->opcode == RESET_EVENTS) {
851 pr_debug("q6asm_callback: Reset event is received: %d %d apr[%p]\n",
852 data->reset_event, data->reset_proc, ac->apr);
Laxminath Kasam692c6542012-02-21 11:17:47 +0530853 if (ac->cb)
854 ac->cb(data->opcode, data->token,
855 (uint32_t *)data->payload, ac->priv);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700856 apr_reset(ac->apr);
857 return 0;
858 }
859
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700860 pr_debug("%s: session[%d]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n",
861 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700862 ac->session, data->opcode,
863 data->token, data->payload_size, data->src_port,
864 data->dest_port);
865
866 if (data->opcode == APR_BASIC_RSP_RESULT) {
867 token = data->token;
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700868 pr_debug("%s payload[0]:%x", __func__, payload[0]);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700869 switch (payload[0]) {
870 case ASM_STREAM_CMD_SET_PP_PARAMS:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700871 if (rtac_make_asm_callback(ac->session, payload,
872 data->payload_size))
873 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700874 case ASM_SESSION_CMD_PAUSE:
875 case ASM_DATA_CMD_EOS:
876 case ASM_STREAM_CMD_CLOSE:
877 case ASM_STREAM_CMD_FLUSH:
878 case ASM_SESSION_CMD_RUN:
879 case ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS:
880 case ASM_STREAM_CMD_FLUSH_READBUFS:
881 pr_debug("%s:Payload = [0x%x]\n", __func__, payload[0]);
882 if (token != ac->session) {
883 pr_err("%s:Invalid session[%d] rxed expected[%d]",
884 __func__, token, ac->session);
885 return -EINVAL;
886 }
887 case ASM_STREAM_CMD_OPEN_READ:
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700888 case ASM_STREAM_CMD_OPEN_READ_V2_1:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700889 case ASM_STREAM_CMD_OPEN_WRITE:
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700890 case ASM_STREAM_CMD_OPEN_WRITE_V2_1:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700891 case ASM_STREAM_CMD_OPEN_READWRITE:
Laxminath Kasam20824502013-01-07 14:33:56 +0530892 case ASM_STREAM_CMD_OPEN_LOOPBACK:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700893 case ASM_DATA_CMD_MEDIA_FORMAT_UPDATE:
894 case ASM_STREAM_CMD_SET_ENCDEC_PARAM:
Santosh Mardi23321202012-03-22 04:33:25 +0530895 case ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED:
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -0700896 case ASM_STREAM_CMD_OPEN_READ_COMPRESSED:
Laxminath Kasamf16d3fd2012-12-19 14:54:14 +0530897 if (payload[0] == ASM_STREAM_CMD_CLOSE) {
898 atomic_set(&ac->cmd_close_state, 0);
899 wake_up(&ac->cmd_wait);
900 } else if (atomic_read(&ac->cmd_state) &&
901 wakeup_flag) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700902 atomic_set(&ac->cmd_state, 0);
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700903 if (payload[1] == ADSP_EUNSUPPORTED) {
904 pr_debug("paload[1]:%d unsupported",
905 payload[1]);
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530906 atomic_set(&ac->cmd_response, 1);
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700907 }
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530908 else
909 atomic_set(&ac->cmd_response, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700910 wake_up(&ac->cmd_wait);
911 }
912 if (ac->cb)
913 ac->cb(data->opcode, data->token,
914 (uint32_t *)data->payload, ac->priv);
915 break;
916 default:
917 pr_debug("%s:command[0x%x] not expecting rsp\n",
918 __func__, payload[0]);
919 break;
920 }
921 return 0;
922 }
923
924 switch (data->opcode) {
925 case ASM_DATA_EVENT_WRITE_DONE:{
926 struct audio_port_data *port = &ac->port[IN];
927 pr_debug("%s: Rxed opcode[0x%x] status[0x%x] token[%d]",
928 __func__, payload[0], payload[1],
929 data->token);
930 if (ac->io_mode == SYNC_IO_MODE) {
931 if (port->buf == NULL) {
932 pr_err("%s: Unexpected Write Done\n",
933 __func__);
934 return -EINVAL;
935 }
936 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
937 if (port->buf[data->token].phys !=
938 payload[0]) {
939 pr_err("Buf expected[%p]rxed[%p]\n",\
940 (void *)port->buf[data->token].phys,\
941 (void *)payload[0]);
942 spin_unlock_irqrestore(&port->dsp_lock,
943 dsp_flags);
944 return -EINVAL;
945 }
946 token = data->token;
947 port->buf[token].used = 1;
948 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
Rajesha Kini3498c932011-07-19 19:58:27 +0530949#ifdef CONFIG_DEBUG_FS
950 if (out_enable_flag) {
951 /* For first Write done log the time and reset
952 out_cold_index*/
953 if (out_cold_index != 1) {
954 do_gettimeofday(&out_cold_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700955 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",
956 out_cold_tv.tv_sec,
Rajesha Kini3498c932011-07-19 19:58:27 +0530957 out_cold_tv.tv_usec);
958 out_cold_index = 1;
959 }
960 pr_debug("out_enable_flag %ld",\
961 out_enable_flag);
962 }
963#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700964 for (i = 0; i < port->max_buf_cnt; i++)
965 pr_debug("%d ", port->buf[i].used);
966
967 }
968 break;
969 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700970 case ASM_STREAM_CMDRSP_GET_PP_PARAMS:
971 rtac_make_asm_callback(ac->session, payload,
972 data->payload_size);
973 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700974 case ASM_DATA_EVENT_READ_DONE:{
975
976 struct audio_port_data *port = &ac->port[OUT];
Rajesha Kini3498c932011-07-19 19:58:27 +0530977#ifdef CONFIG_DEBUG_FS
978 if (in_enable_flag) {
979 /* when in_cont_index == 7, DSP would be
980 * writing into the 8th 512 byte buffer and this
981 * timestamp is tapped here.Once done it then writes
982 * to 9th 512 byte buffer.These two buffers(8th, 9th)
983 * reach the test application in 5th iteration and that
984 * timestamp is tapped at user level. The difference
985 * of these two timestamps gives us the time between
986 * the time at which dsp started filling the sample
987 * required and when it reached the test application.
988 * Hence continuous input latency
989 */
990 if (in_cont_index == 7) {
991 do_gettimeofday(&in_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700992 pr_err("In_CONT:previous read buffer done at %ld sec %ld microsec\n",
Sriranjan Srikantam74753532011-10-03 14:48:37 -0700993 in_cont_tv.tv_sec, in_cont_tv.tv_usec);
Rajesha Kini3498c932011-07-19 19:58:27 +0530994 }
995 }
996#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700997 pr_debug("%s:R-D: status=%d buff_add=%x act_size=%d offset=%d\n",
998 __func__, payload[READDONE_IDX_STATUS],
999 payload[READDONE_IDX_BUFFER],
1000 payload[READDONE_IDX_SIZE],
1001 payload[READDONE_IDX_OFFSET]);
1002 pr_debug("%s:R-D:msw_ts=%d lsw_ts=%d flags=%d id=%d num=%d\n",
1003 __func__, payload[READDONE_IDX_MSW_TS],
1004 payload[READDONE_IDX_LSW_TS],
1005 payload[READDONE_IDX_FLAGS],
1006 payload[READDONE_IDX_ID],
1007 payload[READDONE_IDX_NUMFRAMES]);
Rajesha Kini3498c932011-07-19 19:58:27 +05301008#ifdef CONFIG_DEBUG_FS
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001009 if (in_enable_flag)
Rajesha Kini3498c932011-07-19 19:58:27 +05301010 in_cont_index++;
Rajesha Kini3498c932011-07-19 19:58:27 +05301011#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001012 if (ac->io_mode == SYNC_IO_MODE) {
1013 if (port->buf == NULL) {
1014 pr_err("%s: Unexpected Write Done\n", __func__);
1015 return -EINVAL;
1016 }
1017 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
1018 token = data->token;
1019 port->buf[token].used = 0;
1020 if (port->buf[token].phys !=
1021 payload[READDONE_IDX_BUFFER]) {
1022 pr_err("Buf expected[%p]rxed[%p]\n",\
1023 (void *)port->buf[token].phys,\
1024 (void *)payload[READDONE_IDX_BUFFER]);
1025 spin_unlock_irqrestore(&port->dsp_lock,
1026 dsp_flags);
1027 break;
1028 }
1029 port->buf[token].actual_size =
1030 payload[READDONE_IDX_SIZE];
1031 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
1032 }
1033 break;
1034 }
1035 case ASM_DATA_EVENT_EOS:
1036 case ASM_DATA_CMDRSP_EOS:
1037 pr_debug("%s:EOS ACK received: rxed opcode[0x%x]\n",
1038 __func__, data->opcode);
1039 break;
1040 case ASM_STREAM_CMDRSP_GET_ENCDEC_PARAM:
1041 break;
1042 case ASM_SESSION_EVENT_TX_OVERFLOW:
1043 pr_err("ASM_SESSION_EVENT_TX_OVERFLOW\n");
1044 break;
1045 case ASM_SESSION_CMDRSP_GET_SESSION_TIME:
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001046 pr_debug("%s: ASM_SESSION_CMDRSP_GET_SESSION_TIME, payload[0] = %d, payload[1] = %d, payload[2] = %d\n",
1047 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001048 payload[0], payload[1], payload[2]);
1049 ac->time_stamp = (uint64_t)(((uint64_t)payload[1] << 32) |
1050 payload[2]);
1051 if (atomic_read(&ac->time_flag)) {
1052 atomic_set(&ac->time_flag, 0);
1053 wake_up(&ac->time_wait);
1054 }
1055 break;
1056 case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY:
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301057 case ASM_DATA_EVENT_ENC_SR_CM_NOTIFY:
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001058 pr_debug("%s: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, payload[0] = %d, payload[1] = %d, payload[2] = %d, payload[3] = %d\n",
1059 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001060 payload[0], payload[1], payload[2],
1061 payload[3]);
1062 break;
1063 }
1064 if (ac->cb)
1065 ac->cb(data->opcode, data->token,
1066 data->payload, ac->priv);
1067
1068 return 0;
1069}
1070
1071void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac, uint32_t *size,
1072 uint32_t *index)
1073{
1074 void *data;
1075 unsigned char idx;
1076 struct audio_port_data *port;
1077
1078 if (!ac || ((dir != IN) && (dir != OUT)))
1079 return NULL;
1080
1081 if (ac->io_mode == SYNC_IO_MODE) {
1082 port = &ac->port[dir];
1083
1084 mutex_lock(&port->lock);
1085 idx = port->cpu_buf;
1086 if (port->buf == NULL) {
1087 pr_debug("%s:Buffer pointer null\n", __func__);
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -08001088 mutex_unlock(&port->lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001089 return NULL;
1090 }
1091 /* dir 0: used = 0 means buf in use
1092 dir 1: used = 1 means buf in use */
1093 if (port->buf[idx].used == dir) {
1094 /* To make it more robust, we could loop and get the
1095 next avail buf, its risky though */
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001096 pr_debug("%s:Next buf idx[0x%x] not available,dir[%d]\n",
1097 __func__, idx, dir);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001098 mutex_unlock(&port->lock);
1099 return NULL;
1100 }
1101 *size = port->buf[idx].actual_size;
1102 *index = port->cpu_buf;
1103 data = port->buf[idx].data;
1104 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1105 __func__,
1106 ac->session,
1107 port->cpu_buf,
1108 data, *size);
1109 /* By default increase the cpu_buf cnt
1110 user accesses this function,increase cpu
1111 buf(to avoid another api)*/
1112 port->buf[idx].used = dir;
1113 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1114 mutex_unlock(&port->lock);
1115 return data;
1116 }
1117 return NULL;
1118}
1119
Jay Wang9cf59a02011-08-10 16:58:40 -07001120void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
1121 uint32_t *size, uint32_t *index)
1122{
1123 void *data;
1124 unsigned char idx;
1125 struct audio_port_data *port;
1126
1127 if (!ac || ((dir != IN) && (dir != OUT)))
1128 return NULL;
1129
1130 port = &ac->port[dir];
1131
1132 idx = port->cpu_buf;
1133 if (port->buf == NULL) {
1134 pr_debug("%s:Buffer pointer null\n", __func__);
1135 return NULL;
1136 }
1137 /*
1138 * dir 0: used = 0 means buf in use
1139 * dir 1: used = 1 means buf in use
1140 */
1141 if (port->buf[idx].used == dir) {
1142 /*
1143 * To make it more robust, we could loop and get the
1144 * next avail buf, its risky though
1145 */
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001146 pr_debug("%s:Next buf idx[0x%x] not available, dir[%d]\n",
1147 __func__, idx, dir);
Jay Wang9cf59a02011-08-10 16:58:40 -07001148 return NULL;
1149 }
1150 *size = port->buf[idx].actual_size;
1151 *index = port->cpu_buf;
1152 data = port->buf[idx].data;
1153 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1154 __func__, ac->session, port->cpu_buf,
1155 data, *size);
1156 /*
1157 * By default increase the cpu_buf cnt
1158 * user accesses this function,increase cpu
1159 * buf(to avoid another api)
1160 */
1161 port->buf[idx].used = dir;
1162 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1163 return data;
1164}
1165
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001166int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac)
1167{
1168 int ret = -1;
1169 struct audio_port_data *port;
1170 uint32_t idx;
1171
1172 if (!ac || (dir != OUT))
1173 return ret;
1174
1175 if (ac->io_mode == SYNC_IO_MODE) {
1176 port = &ac->port[dir];
1177
1178 mutex_lock(&port->lock);
1179 idx = port->dsp_buf;
1180
1181 if (port->buf[idx].used == (dir ^ 1)) {
1182 /* To make it more robust, we could loop and get the
1183 next avail buf, its risky though */
1184 pr_err("Next buf idx[0x%x] not available, dir[%d]\n",
1185 idx, dir);
1186 mutex_unlock(&port->lock);
1187 return ret;
1188 }
1189 pr_debug("%s: session[%d]dsp_buf=%d cpu_buf=%d\n", __func__,
1190 ac->session, port->dsp_buf, port->cpu_buf);
1191 ret = ((port->dsp_buf != port->cpu_buf) ? 0 : -1);
1192 mutex_unlock(&port->lock);
1193 }
1194 return ret;
1195}
1196
1197static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
1198 uint32_t pkt_size, uint32_t cmd_flg)
1199{
1200 pr_debug("%s:session=%d pkt size=%d cmd_flg=%d\n", __func__, pkt_size,
1201 cmd_flg, ac->session);
1202 mutex_lock(&ac->cmd_lock);
1203 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1204 APR_HDR_LEN(sizeof(struct apr_hdr)),\
1205 APR_PKT_VER);
1206 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
1207 hdr->src_domain = APR_DOMAIN_APPS;
1208 hdr->dest_svc = APR_SVC_ASM;
1209 hdr->dest_domain = APR_DOMAIN_ADSP;
1210 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
1211 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
1212 if (cmd_flg) {
1213 hdr->token = ac->session;
1214 atomic_set(&ac->cmd_state, 1);
1215 }
1216 hdr->pkt_size = pkt_size;
1217 mutex_unlock(&ac->cmd_lock);
1218 return;
1219}
1220
1221static void q6asm_add_mmaphdr(struct apr_hdr *hdr, uint32_t pkt_size,
1222 uint32_t cmd_flg)
1223{
1224 pr_debug("%s:pkt size=%d cmd_flg=%d\n", __func__, pkt_size, cmd_flg);
1225 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1226 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1227 hdr->src_port = 0;
1228 hdr->dest_port = 0;
1229 if (cmd_flg) {
1230 hdr->token = 0;
1231 atomic_set(&this_mmap.cmd_state, 1);
1232 }
1233 hdr->pkt_size = pkt_size;
1234 return;
1235}
1236
1237int q6asm_open_read(struct audio_client *ac,
1238 uint32_t format)
1239{
1240 int rc = 0x00;
1241 struct asm_stream_cmd_open_read open;
Rajesha Kini3498c932011-07-19 19:58:27 +05301242#ifdef CONFIG_DEBUG_FS
1243 in_cont_index = 0;
1244#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001245 if ((ac == NULL) || (ac->apr == NULL)) {
1246 pr_err("%s: APR handle NULL\n", __func__);
1247 return -EINVAL;
1248 }
1249 pr_debug("%s:session[%d]", __func__, ac->session);
1250
1251 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1252 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ;
1253 /* Stream prio : High, provide meta info with encoded frames */
1254 open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1255
1256 open.pre_proc_top = get_asm_topology();
1257 if (open.pre_proc_top == 0)
1258 open.pre_proc_top = DEFAULT_POPP_TOPOLOGY;
1259
1260 switch (format) {
1261 case FORMAT_LINEAR_PCM:
1262 open.uMode = STREAM_PRIORITY_HIGH;
1263 open.format = LINEAR_PCM;
1264 break;
Mingming Yin647e9ea2012-03-17 19:56:10 -07001265 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1266 open.uMode = STREAM_PRIORITY_HIGH;
1267 open.format = MULTI_CHANNEL_PCM;
1268 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001269 case FORMAT_MPEG4_AAC:
1270 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1271 open.format = MPEG4_AAC;
1272 break;
1273 case FORMAT_V13K:
1274 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1275 open.format = V13K_FS;
1276 break;
1277 case FORMAT_EVRC:
1278 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1279 open.format = EVRC_FS;
1280 break;
1281 case FORMAT_AMRNB:
1282 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1283 open.format = AMRNB_FS;
1284 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301285 case FORMAT_AMRWB:
1286 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1287 open.format = AMRWB_FS;
1288 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001289 default:
1290 pr_err("Invalid format[%d]\n", format);
1291 goto fail_cmd;
1292 }
1293 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1294 if (rc < 0) {
1295 pr_err("open failed op[0x%x]rc[%d]\n", \
1296 open.hdr.opcode, rc);
1297 goto fail_cmd;
1298 }
1299 rc = wait_event_timeout(ac->cmd_wait,
1300 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1301 if (!rc) {
1302 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1303 rc);
1304 goto fail_cmd;
1305 }
1306 return 0;
1307fail_cmd:
1308 return -EINVAL;
1309}
1310
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -07001311int q6asm_open_read_v2_1(struct audio_client *ac,
1312 uint32_t format)
1313{
1314 int rc = 0x00;
1315 struct asm_stream_cmd_open_read_v2_1 open;
1316#ifdef CONFIG_DEBUG_FS
1317 in_cont_index = 0;
1318#endif
1319 if ((ac == NULL) || (ac->apr == NULL)) {
1320 pr_err("%s: APR handle NULL\n", __func__);
1321 return -EINVAL;
1322 }
1323 pr_debug("%s:session[%d]", __func__, ac->session);
1324
1325 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1326 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_V2_1;
1327 open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1328 open.pre_proc_top = get_asm_topology();
1329 if (open.pre_proc_top == 0)
1330 open.pre_proc_top = DEFAULT_POPP_TOPOLOGY;
1331
1332 switch (format) {
1333 case FORMAT_LINEAR_PCM:
1334 open.uMode = STREAM_PRIORITY_HIGH;
1335 open.format = LINEAR_PCM;
1336 break;
1337 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1338 open.uMode = STREAM_PRIORITY_HIGH;
1339 open.format = MULTI_CHANNEL_PCM;
1340 break;
1341 case FORMAT_MPEG4_AAC:
1342 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1343 open.format = MPEG4_AAC;
1344 break;
1345 case FORMAT_V13K:
1346 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1347 open.format = V13K_FS;
1348 break;
1349 case FORMAT_EVRC:
1350 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1351 open.format = EVRC_FS;
1352 break;
1353 case FORMAT_AMRNB:
1354 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1355 open.format = AMRNB_FS;
1356 break;
1357 case FORMAT_AMRWB:
1358 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1359 open.format = AMRWB_FS;
1360 break;
1361 default:
1362 pr_err("Invalid format[%d]\n", format);
1363 goto fail_cmd;
1364 }
1365 open.uMode = ASM_OPEN_READ_PERF_MODE_BIT;
1366 open.bits_per_sample = PCM_BITS_PER_SAMPLE;
1367 open.reserved = 0;
1368 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1369 if (rc < 0) {
1370 pr_err("open failed op[0x%x]rc[%d]\n", \
1371 open.hdr.opcode, rc);
1372 goto fail_cmd;
1373 }
1374 rc = wait_event_timeout(ac->cmd_wait,
1375 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1376 if (!rc) {
1377 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1378 rc);
1379 goto fail_cmd;
1380 }
1381 return 0;
1382fail_cmd:
1383 return -EINVAL;
1384}
1385
1386
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07001387int q6asm_open_read_compressed(struct audio_client *ac,
1388 uint32_t frames_per_buffer, uint32_t meta_data_mode)
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -07001389{
1390 int rc = 0x00;
1391 struct asm_stream_cmd_open_read_compressed open;
1392#ifdef CONFIG_DEBUG_FS
1393 in_cont_index = 0;
1394#endif
1395 if ((ac == NULL) || (ac->apr == NULL)) {
1396 pr_err("%s: APR handle NULL\n", __func__);
1397 return -EINVAL;
1398 }
1399 pr_debug("%s:session[%d]", __func__, ac->session);
1400
1401 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1402 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_COMPRESSED;
1403 /* hardcoded as following*/
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07001404 open.frame_per_buf = frames_per_buffer;
1405 open.uMode = meta_data_mode;
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -07001406
1407 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1408 if (rc < 0) {
1409 pr_err("open failed op[0x%x]rc[%d]\n", open.hdr.opcode, rc);
1410 goto fail_cmd;
1411 }
1412 rc = wait_event_timeout(ac->cmd_wait,
1413 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1414 if (!rc) {
1415 pr_err("%s: timeout. waited for OPEN_READ_COMPRESSED rc[%d]\n",
1416 __func__, rc);
1417 goto fail_cmd;
1418 }
1419 return 0;
1420fail_cmd:
1421 return -EINVAL;
1422}
1423
Santosh Mardi23321202012-03-22 04:33:25 +05301424int q6asm_open_write_compressed(struct audio_client *ac, uint32_t format)
1425{
1426 int rc = 0x00;
1427 struct asm_stream_cmd_open_write_compressed open;
1428
1429 if ((ac == NULL) || (ac->apr == NULL)) {
1430 pr_err("%s: APR handle NULL\n", __func__);
1431 return -EINVAL;
1432 }
1433 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1434 format);
1435
1436 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1437
1438 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED;
1439
1440 switch (format) {
1441 case FORMAT_AC3:
1442 open.format = AC3_DECODER;
1443 break;
1444 case FORMAT_EAC3:
1445 open.format = EAC3_DECODER;
1446 break;
1447 case FORMAT_MP3:
1448 open.format = MP3;
1449 break;
1450 case FORMAT_DTS:
1451 open.format = DTS;
1452 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05301453 case FORMAT_DTS_LBR:
1454 open.format = DTS_LBR;
1455 break;
Santosh Mardi23321202012-03-22 04:33:25 +05301456 case FORMAT_AAC:
1457 open.format = MPEG4_AAC;
1458 break;
1459 case FORMAT_ATRAC:
1460 open.format = ATRAC;
1461 break;
1462 case FORMAT_WMA_V10PRO:
1463 open.format = WMA_V10PRO;
1464 break;
1465 case FORMAT_MAT:
1466 open.format = MAT;
1467 break;
1468 default:
1469 pr_err("%s: Invalid format[%d]\n", __func__, format);
1470 goto fail_cmd;
1471 }
1472 /*Below flag indicates the DSP that Compressed audio input
1473 stream is not IEC 61937 or IEC 60958 packetizied*/
1474 open.flags = 0x00000000;
1475 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1476 if (rc < 0) {
1477 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1478 __func__, open.hdr.opcode, rc);
1479 goto fail_cmd;
1480 }
1481 rc = wait_event_timeout(ac->cmd_wait,
1482 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1483 if (!rc) {
1484 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1485 rc);
1486 goto fail_cmd;
1487 }
1488 return 0;
1489fail_cmd:
1490 return -EINVAL;
1491}
1492
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001493int q6asm_open_write(struct audio_client *ac, uint32_t format)
1494{
1495 int rc = 0x00;
1496 struct asm_stream_cmd_open_write open;
1497
1498 if ((ac == NULL) || (ac->apr == NULL)) {
1499 pr_err("%s: APR handle NULL\n", __func__);
1500 return -EINVAL;
1501 }
1502 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1503 format);
1504
1505 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1506
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -07001507 if (ac->perf_mode) {
1508 pr_debug("%s In Performance/lowlatency mode", __func__);
1509 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_V2_1;
1510 open.uMode = ASM_OPEN_WRITE_PERF_MODE_BIT;
1511 /* source endpoint : matrix */
1512 open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1513 open.stream_handle = PCM_BITS_PER_SAMPLE;
1514 } else {
1515 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE;
1516 open.uMode = STREAM_PRIORITY_HIGH;
1517 /* source endpoint : matrix */
1518 open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1519 open.stream_handle = 0x00;
1520 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001521 open.post_proc_top = get_asm_topology();
1522 if (open.post_proc_top == 0)
1523 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1524
1525 switch (format) {
1526 case FORMAT_LINEAR_PCM:
1527 open.format = LINEAR_PCM;
1528 break;
Kiran Kandi5e809b02012-01-31 00:24:33 -08001529 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1530 open.format = MULTI_CHANNEL_PCM;
1531 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001532 case FORMAT_MPEG4_AAC:
1533 open.format = MPEG4_AAC;
1534 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001535 case FORMAT_MPEG4_MULTI_AAC:
1536 open.format = MPEG4_MULTI_AAC;
1537 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001538 case FORMAT_WMA_V9:
1539 open.format = WMA_V9;
1540 break;
1541 case FORMAT_WMA_V10PRO:
1542 open.format = WMA_V10PRO;
1543 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05301544 case FORMAT_MP3:
1545 open.format = MP3;
1546 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05301547 case FORMAT_DTS:
1548 open.format = DTS;
1549 break;
1550 case FORMAT_DTS_LBR:
1551 open.format = DTS_LBR;
1552 break;
Ajit Khare43fd8832012-08-07 13:19:44 -07001553 case FORMAT_AMRWB:
1554 open.format = AMRWB_FS;
1555 pr_debug("q6asm_open_write FORMAT_AMRWB");
1556 break;
1557 case FORMAT_AMR_WB_PLUS:
1558 open.format = AMR_WB_PLUS;
1559 pr_debug("q6asm_open_write FORMAT_AMR_WB_PLUS");
1560 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001561 default:
1562 pr_err("%s: Invalid format[%d]\n", __func__, format);
1563 goto fail_cmd;
1564 }
1565 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1566 if (rc < 0) {
1567 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1568 __func__, open.hdr.opcode, rc);
1569 goto fail_cmd;
1570 }
1571 rc = wait_event_timeout(ac->cmd_wait,
1572 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1573 if (!rc) {
1574 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1575 rc);
1576 goto fail_cmd;
1577 }
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +05301578 if (atomic_read(&ac->cmd_response)) {
1579 pr_err("%s: format = %x not supported\n", __func__, format);
1580 goto fail_cmd;
1581 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001582 return 0;
1583fail_cmd:
1584 return -EINVAL;
1585}
1586
1587int q6asm_open_read_write(struct audio_client *ac,
1588 uint32_t rd_format,
1589 uint32_t wr_format)
1590{
1591 int rc = 0x00;
1592 struct asm_stream_cmd_open_read_write open;
1593
1594 if ((ac == NULL) || (ac->apr == NULL)) {
1595 pr_err("APR handle NULL\n");
1596 return -EINVAL;
1597 }
1598 pr_debug("%s: session[%d]", __func__, ac->session);
1599 pr_debug("wr_format[0x%x]rd_format[0x%x]",
1600 wr_format, rd_format);
1601
1602 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1603 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE;
1604
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301605 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_NORMAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001606 /* source endpoint : matrix */
1607 open.post_proc_top = get_asm_topology();
1608 if (open.post_proc_top == 0)
1609 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1610
1611 switch (wr_format) {
1612 case FORMAT_LINEAR_PCM:
1613 open.write_format = LINEAR_PCM;
1614 break;
1615 case FORMAT_MPEG4_AAC:
1616 open.write_format = MPEG4_AAC;
1617 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001618 case FORMAT_MPEG4_MULTI_AAC:
1619 open.write_format = MPEG4_MULTI_AAC;
1620 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001621 case FORMAT_WMA_V9:
1622 open.write_format = WMA_V9;
1623 break;
1624 case FORMAT_WMA_V10PRO:
1625 open.write_format = WMA_V10PRO;
1626 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301627 case FORMAT_AMRNB:
1628 open.write_format = AMRNB_FS;
1629 break;
1630 case FORMAT_AMRWB:
1631 open.write_format = AMRWB_FS;
1632 break;
Ajit Khare7277bb72012-10-31 16:34:22 -07001633 case FORMAT_AMR_WB_PLUS:
1634 open.write_format = AMR_WB_PLUS;
1635 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301636 case FORMAT_V13K:
1637 open.write_format = V13K_FS;
1638 break;
1639 case FORMAT_EVRC:
1640 open.write_format = EVRC_FS;
1641 break;
1642 case FORMAT_EVRCB:
1643 open.write_format = EVRCB_FS;
1644 break;
1645 case FORMAT_EVRCWB:
1646 open.write_format = EVRCWB_FS;
1647 break;
1648 case FORMAT_MP3:
1649 open.write_format = MP3;
1650 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001651 default:
1652 pr_err("Invalid format[%d]\n", wr_format);
1653 goto fail_cmd;
1654 }
1655
1656 switch (rd_format) {
1657 case FORMAT_LINEAR_PCM:
1658 open.read_format = LINEAR_PCM;
1659 break;
1660 case FORMAT_MPEG4_AAC:
1661 open.read_format = MPEG4_AAC;
1662 break;
1663 case FORMAT_V13K:
1664 open.read_format = V13K_FS;
1665 break;
1666 case FORMAT_EVRC:
1667 open.read_format = EVRC_FS;
1668 break;
1669 case FORMAT_AMRNB:
1670 open.read_format = AMRNB_FS;
1671 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301672 case FORMAT_AMRWB:
1673 open.read_format = AMRWB_FS;
1674 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001675 default:
1676 pr_err("Invalid format[%d]\n", rd_format);
1677 goto fail_cmd;
1678 }
1679 pr_debug("%s:rdformat[0x%x]wrformat[0x%x]\n", __func__,
1680 open.read_format, open.write_format);
1681
1682 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1683 if (rc < 0) {
1684 pr_err("open failed op[0x%x]rc[%d]\n", \
1685 open.hdr.opcode, rc);
1686 goto fail_cmd;
1687 }
1688 rc = wait_event_timeout(ac->cmd_wait,
1689 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1690 if (!rc) {
1691 pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc);
1692 goto fail_cmd;
1693 }
1694 return 0;
1695fail_cmd:
1696 return -EINVAL;
1697}
1698
Laxminath Kasam20824502013-01-07 14:33:56 +05301699int q6asm_open_loopack(struct audio_client *ac)
1700{
1701 int rc = 0x00;
1702 struct asm_stream_cmd_open_loopback open;
1703
1704 if ((ac == NULL) || (ac->apr == NULL)) {
1705 pr_err("APR handle NULL\n");
1706 return -EINVAL;
1707 }
1708 pr_debug("%s: session[%d]", __func__, ac->session);
1709
1710 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1711 open.hdr.opcode = ASM_STREAM_CMD_OPEN_LOOPBACK;
1712
1713 open.mode_flags = 0;
1714 open.src_endpointype = 0;
1715 open.sink_endpointype = 0;
1716 /* source endpoint : matrix */
1717 open.postprocopo_id = get_asm_topology();
1718 if (open.postprocopo_id == 0)
1719 open.postprocopo_id = DEFAULT_POPP_TOPOLOGY;
1720
1721 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1722 if (rc < 0) {
1723 pr_err("open failed op[0x%x]rc[%d]\n", \
1724 open.hdr.opcode, rc);
1725 goto fail_cmd;
1726 }
1727 rc = wait_event_timeout(ac->cmd_wait,
1728 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1729 if (!rc) {
1730 pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc);
1731 goto fail_cmd;
1732 }
1733 return 0;
1734fail_cmd:
1735 return -EINVAL;
1736}
1737
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001738int q6asm_run(struct audio_client *ac, uint32_t flags,
1739 uint32_t msw_ts, uint32_t lsw_ts)
1740{
1741 struct asm_stream_cmd_run run;
1742 int rc;
1743 if (!ac || ac->apr == NULL) {
1744 pr_err("APR handle NULL\n");
1745 return -EINVAL;
1746 }
1747 pr_debug("%s session[%d]", __func__, ac->session);
1748 q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
1749
1750 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1751 run.flags = flags;
1752 run.msw_ts = msw_ts;
1753 run.lsw_ts = lsw_ts;
Rajesha Kini3498c932011-07-19 19:58:27 +05301754#ifdef CONFIG_DEBUG_FS
1755 if (out_enable_flag) {
1756 do_gettimeofday(&out_cold_tv);
1757 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",\
1758 out_cold_tv.tv_sec, out_cold_tv.tv_usec);
1759 }
1760#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001761 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1762 if (rc < 0) {
1763 pr_err("Commmand run failed[%d]", rc);
1764 goto fail_cmd;
1765 }
1766
1767 rc = wait_event_timeout(ac->cmd_wait,
1768 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1769 if (!rc) {
1770 pr_err("timeout. waited for run success rc[%d]", rc);
1771 goto fail_cmd;
1772 }
1773
1774 return 0;
1775fail_cmd:
1776 return -EINVAL;
1777}
1778
1779int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
1780 uint32_t msw_ts, uint32_t lsw_ts)
1781{
1782 struct asm_stream_cmd_run run;
1783 int rc;
1784 if (!ac || ac->apr == NULL) {
1785 pr_err("%s:APR handle NULL\n", __func__);
1786 return -EINVAL;
1787 }
1788 pr_debug("session[%d]", ac->session);
1789 q6asm_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE);
1790
1791 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1792 run.flags = flags;
1793 run.msw_ts = msw_ts;
1794 run.lsw_ts = lsw_ts;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001795 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1796 if (rc < 0) {
1797 pr_err("%s:Commmand run failed[%d]", __func__, rc);
1798 return -EINVAL;
1799 }
Jay Wang0668d1062012-07-11 18:53:21 -07001800 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001801 return 0;
1802}
1803
1804
1805int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
1806 uint32_t frames_per_buf,
1807 uint32_t sample_rate, uint32_t channels,
1808 uint32_t bit_rate, uint32_t mode, uint32_t format)
1809{
1810 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1811 int rc = 0;
1812
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001813 pr_debug("%s:session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d] format[%d]",
1814 __func__, ac->session, frames_per_buf,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001815 sample_rate, channels, bit_rate, mode, format);
1816
1817 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1818
1819 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1820 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1821 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1822 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1823 enc_cfg.enc_blk.format_id = MPEG4_AAC;
1824 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_aac_read_cfg);
1825 enc_cfg.enc_blk.cfg.aac.bitrate = bit_rate;
1826 enc_cfg.enc_blk.cfg.aac.enc_mode = mode;
1827 enc_cfg.enc_blk.cfg.aac.format = format;
1828 enc_cfg.enc_blk.cfg.aac.ch_cfg = channels;
1829 enc_cfg.enc_blk.cfg.aac.sample_rate = sample_rate;
1830
1831 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1832 if (rc < 0) {
1833 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1834 rc = -EINVAL;
1835 goto fail_cmd;
1836 }
1837 rc = wait_event_timeout(ac->cmd_wait,
1838 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1839 if (!rc) {
1840 pr_err("timeout. waited for FORMAT_UPDATE\n");
1841 goto fail_cmd;
1842 }
1843 return 0;
1844fail_cmd:
1845 return -EINVAL;
1846}
1847
1848int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
1849 uint32_t rate, uint32_t channels)
1850{
1851 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1852
1853 int rc = 0;
1854
1855 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1856 ac->session, rate, channels);
1857
1858 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1859
1860 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1861 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1862 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1863 enc_cfg.enc_blk.frames_per_buf = 1;
1864 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1865 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1866 enc_cfg.enc_blk.cfg.pcm.ch_cfg = channels;
1867 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1868 enc_cfg.enc_blk.cfg.pcm.sample_rate = rate;
1869 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1870 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1871
1872 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1873 if (rc < 0) {
1874 pr_err("Comamnd open failed\n");
1875 rc = -EINVAL;
1876 goto fail_cmd;
1877 }
1878 rc = wait_event_timeout(ac->cmd_wait,
1879 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1880 if (!rc) {
1881 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1882 goto fail_cmd;
1883 }
1884 return 0;
1885fail_cmd:
1886 return -EINVAL;
1887}
1888
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001889int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac,
1890 uint32_t rate, uint32_t channels)
1891{
1892 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1893
1894 int rc = 0;
1895
1896 pr_debug("%s: Session %d, rate = %d, channels = %d, setting the rate and channels to 0 for native\n",
1897 __func__, ac->session, rate, channels);
1898
1899 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1900
1901 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1902 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1903 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1904 enc_cfg.enc_blk.frames_per_buf = 1;
1905 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1906 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1907 enc_cfg.enc_blk.cfg.pcm.ch_cfg = 0;/*channels;*/
1908 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1909 enc_cfg.enc_blk.cfg.pcm.sample_rate = 0;/*rate;*/
1910 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1911 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1912
1913 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1914 if (rc < 0) {
1915 pr_err("Comamnd open failed\n");
1916 rc = -EINVAL;
1917 goto fail_cmd;
1918 }
1919 rc = wait_event_timeout(ac->cmd_wait,
1920 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1921 if (!rc) {
1922 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1923 goto fail_cmd;
1924 }
1925 return 0;
1926fail_cmd:
1927 return -EINVAL;
1928}
1929
Mingming Yin647e9ea2012-03-17 19:56:10 -07001930int q6asm_enc_cfg_blk_multi_ch_pcm(struct audio_client *ac,
1931 uint32_t rate, uint32_t channels)
1932{
1933 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1934
1935 int rc = 0;
1936
1937 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1938 ac->session, rate, channels);
1939
1940 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1941
1942 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1943 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1944 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1945 enc_cfg.enc_blk.frames_per_buf = 1;
1946 enc_cfg.enc_blk.format_id = MULTI_CHANNEL_PCM;
1947 enc_cfg.enc_blk.cfg_size =
1948 sizeof(struct asm_multi_channel_pcm_fmt_blk);
1949 enc_cfg.enc_blk.cfg.mpcm.num_channels = channels;
1950 enc_cfg.enc_blk.cfg.mpcm.bits_per_sample = 16;
1951 enc_cfg.enc_blk.cfg.mpcm.sample_rate = rate;
1952 enc_cfg.enc_blk.cfg.mpcm.is_signed = 1;
1953 enc_cfg.enc_blk.cfg.mpcm.is_interleaved = 1;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07001954 if (channels == 1) {
1955 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1956 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = 0;
1957 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0;
1958 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
1959 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1960 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1961 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1962 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1963 } else if (channels == 2) {
Subhash Chandra Bose Naripeddy8477d222012-06-12 00:30:54 -07001964 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1965 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1966 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0;
1967 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
1968 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1969 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1970 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1971 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1972 } else if (channels == 4) {
1973 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1974 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1975 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_RB;
1976 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_LB;
1977 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1978 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1979 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1980 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1981 } else if (channels == 6) {
1982 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1983 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1984 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
1985 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
1986 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
1987 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
1988 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1989 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1990 } else if (channels == 8) {
1991 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1992 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1993 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
1994 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
1995 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
1996 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
1997 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = PCM_CHANNEL_FLC;
1998 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = PCM_CHANNEL_FRC;
1999 }
Mingming Yin647e9ea2012-03-17 19:56:10 -07002000
2001 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2002 if (rc < 0) {
2003 pr_err("Comamnd open failed\n");
2004 rc = -EINVAL;
2005 goto fail_cmd;
2006 }
2007 rc = wait_event_timeout(ac->cmd_wait,
2008 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2009 if (!rc) {
2010 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
2011 goto fail_cmd;
2012 }
2013 return 0;
2014fail_cmd:
2015 return -EINVAL;
2016}
2017
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002018int q6asm_enable_sbrps(struct audio_client *ac,
2019 uint32_t sbr_ps_enable)
2020{
2021 struct asm_stream_cmd_encdec_sbr sbrps;
2022
2023 int rc = 0;
2024
2025 pr_debug("%s: Session %d\n", __func__, ac->session);
2026
2027 q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
2028
2029 sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2030 sbrps.param_id = ASM_ENABLE_SBR_PS;
2031 sbrps.param_size = sizeof(struct asm_sbr_ps);
2032 sbrps.sbr_ps.enable = sbr_ps_enable;
2033
2034 rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
2035 if (rc < 0) {
2036 pr_err("Command opcode[0x%x]paramid[0x%x] failed\n",
2037 ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2038 ASM_ENABLE_SBR_PS);
2039 rc = -EINVAL;
2040 goto fail_cmd;
2041 }
2042 rc = wait_event_timeout(ac->cmd_wait,
2043 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2044 if (!rc) {
2045 pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode);
2046 goto fail_cmd;
2047 }
2048 return 0;
2049fail_cmd:
2050 return -EINVAL;
2051}
2052
Swaminathan Sathappan70765cd2011-07-19 18:42:47 -07002053int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
2054 uint16_t sce_left, uint16_t sce_right)
2055{
2056 struct asm_stream_cmd_encdec_dualmono dual_mono;
2057
2058 int rc = 0;
2059
2060 pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
2061 __func__, ac->session, sce_left, sce_right);
2062
2063 q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
2064
2065 dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2066 dual_mono.param_id = ASM_CONFIGURE_DUAL_MONO;
2067 dual_mono.param_size = sizeof(struct asm_dual_mono);
2068 dual_mono.channel_map.sce_left = sce_left;
2069 dual_mono.channel_map.sce_right = sce_right;
2070
2071 rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
2072 if (rc < 0) {
2073 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2074 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2075 ASM_CONFIGURE_DUAL_MONO);
2076 rc = -EINVAL;
2077 goto fail_cmd;
2078 }
2079 rc = wait_event_timeout(ac->cmd_wait,
2080 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2081 if (!rc) {
2082 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2083 dual_mono.hdr.opcode);
2084 goto fail_cmd;
2085 }
2086 return 0;
2087fail_cmd:
2088 return -EINVAL;
2089}
2090
Amal Paul6e0f7982013-02-21 19:36:35 -08002091int q6asm_cfg_aac_sel_mix_coef(struct audio_client *ac, uint32_t mix_coeff)
2092{
2093 struct asm_aac_stereo_mix_coeff_selection_param aac_mix_coeff;
2094 int rc = 0;
2095 q6asm_add_hdr(ac, &aac_mix_coeff.hdr, sizeof(aac_mix_coeff), TRUE);
2096 aac_mix_coeff.hdr.opcode =
2097 ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2098 aac_mix_coeff.param_id =
2099 ASM_PARAM_ID_AAC_STEREO_MIX_COEFF_SELECTION_FLAG;
2100 aac_mix_coeff.param_size =
2101 sizeof(struct asm_aac_stereo_mix_coeff_selection_param);
2102 aac_mix_coeff.aac_stereo_mix_coeff_flag = mix_coeff;
2103 pr_debug("%s, mix_coeff = %u", __func__, mix_coeff);
2104 rc = apr_send_pkt(ac->apr, (uint32_t *) &aac_mix_coeff);
2105 if (rc < 0) {
2106 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2107 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2108 ASM_PARAM_ID_AAC_STEREO_MIX_COEFF_SELECTION_FLAG);
2109 rc = -EINVAL;
2110 goto fail_cmd;
2111 }
2112 rc = wait_event_timeout(ac->cmd_wait,
2113 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2114 if (!rc) {
2115 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2116 aac_mix_coeff.hdr.opcode);
2117 goto fail_cmd;
2118 }
2119 return 0;
2120fail_cmd:
2121 return -EINVAL;
2122}
2123
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002124int q6asm_set_encdec_chan_map(struct audio_client *ac,
2125 uint32_t num_channels)
2126{
2127 struct asm_stream_cmd_encdec_channelmap chan_map;
2128 u8 *channel_mapping;
2129
2130 int rc = 0;
2131
2132 pr_debug("%s: Session %d, num_channels = %d\n",
2133 __func__, ac->session, num_channels);
2134
2135 q6asm_add_hdr(ac, &chan_map.hdr, sizeof(chan_map), TRUE);
2136
2137 chan_map.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2138 chan_map.param_id = ASM_ENCDEC_DEC_CHAN_MAP;
2139 chan_map.param_size = sizeof(struct asm_dec_chan_map);
2140 chan_map.chan_map.num_channels = num_channels;
2141
2142 channel_mapping =
2143 chan_map.chan_map.channel_mapping;
2144
2145 memset(channel_mapping, PCM_CHANNEL_NULL, MAX_CHAN_MAP_CHANNELS);
2146 if (num_channels == 1) {
2147 channel_mapping[0] = PCM_CHANNEL_FL;
2148 } else if (num_channels == 2) {
2149 channel_mapping[0] = PCM_CHANNEL_FL;
2150 channel_mapping[1] = PCM_CHANNEL_FR;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002151 } else if (num_channels == 4) {
2152 channel_mapping[0] = PCM_CHANNEL_FL;
2153 channel_mapping[1] = PCM_CHANNEL_FR;
2154 channel_mapping[1] = PCM_CHANNEL_LB;
2155 channel_mapping[1] = PCM_CHANNEL_RB;
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002156 } else if (num_channels == 6) {
2157 channel_mapping[0] = PCM_CHANNEL_FC;
2158 channel_mapping[1] = PCM_CHANNEL_FL;
2159 channel_mapping[2] = PCM_CHANNEL_FR;
2160 channel_mapping[3] = PCM_CHANNEL_LB;
2161 channel_mapping[4] = PCM_CHANNEL_RB;
2162 channel_mapping[5] = PCM_CHANNEL_LFE;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002163 } else if (num_channels == 8) {
2164 channel_mapping[0] = PCM_CHANNEL_FC;
2165 channel_mapping[1] = PCM_CHANNEL_FL;
2166 channel_mapping[2] = PCM_CHANNEL_FR;
2167 channel_mapping[3] = PCM_CHANNEL_LB;
2168 channel_mapping[4] = PCM_CHANNEL_RB;
2169 channel_mapping[5] = PCM_CHANNEL_LFE;
2170 channel_mapping[6] = PCM_CHANNEL_FLC;
2171 channel_mapping[7] = PCM_CHANNEL_FRC;
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002172 } else {
2173 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2174 num_channels);
2175 rc = -EINVAL;
2176 goto fail_cmd;
2177 }
2178
2179 rc = apr_send_pkt(ac->apr, (uint32_t *) &chan_map);
2180 if (rc < 0) {
2181 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2182 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2183 ASM_ENCDEC_DEC_CHAN_MAP);
2184 goto fail_cmd;
2185 }
2186 rc = wait_event_timeout(ac->cmd_wait,
2187 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2188 if (!rc) {
2189 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2190 chan_map.hdr.opcode);
2191 rc = -ETIMEDOUT;
2192 goto fail_cmd;
2193 }
2194 return 0;
2195fail_cmd:
2196 return rc;
2197}
2198
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002199int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
2200 uint16_t min_rate, uint16_t max_rate,
2201 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
2202{
2203 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2204 int rc = 0;
2205
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002206 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]",
2207 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002208 ac->session, frames_per_buf, min_rate, max_rate,
2209 reduced_rate_level, rate_modulation_cmd);
2210
2211 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2212
2213 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2214
2215 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2216 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2217
2218 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2219 enc_cfg.enc_blk.format_id = V13K_FS;
2220 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg);
2221 enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate;
2222 enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate;
2223 enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level;
2224 enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_cmd = rate_modulation_cmd;
2225
2226 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2227 if (rc < 0) {
2228 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2229 goto fail_cmd;
2230 }
2231 rc = wait_event_timeout(ac->cmd_wait,
2232 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2233 if (!rc) {
2234 pr_err("timeout. waited for FORMAT_UPDATE\n");
2235 goto fail_cmd;
2236 }
2237 return 0;
2238fail_cmd:
2239 return -EINVAL;
2240}
2241
2242int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
2243 uint16_t min_rate, uint16_t max_rate,
2244 uint16_t rate_modulation_cmd)
2245{
2246 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2247 int rc = 0;
2248
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002249 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] rate_modulation_cmd[0x%4x]",
2250 __func__, ac->session,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002251 frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
2252
2253 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2254
2255 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2256
2257 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2258 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2259
2260 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2261 enc_cfg.enc_blk.format_id = EVRC_FS;
2262 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg);
2263 enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate;
2264 enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate;
2265 enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd;
2266 enc_cfg.enc_blk.cfg.evrc.reserved = 0;
2267
2268 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2269 if (rc < 0) {
2270 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2271 goto fail_cmd;
2272 }
2273 rc = wait_event_timeout(ac->cmd_wait,
2274 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2275 if (!rc) {
2276 pr_err("timeout. waited for FORMAT_UPDATE\n");
2277 goto fail_cmd;
2278 }
2279 return 0;
2280fail_cmd:
2281 return -EINVAL;
2282}
2283
2284int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
2285 uint16_t band_mode, uint16_t dtx_enable)
2286{
2287 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2288 int rc = 0;
2289
2290 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2291 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2292
2293 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2294
2295 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2296
2297 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2298 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2299
2300 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2301 enc_cfg.enc_blk.format_id = AMRNB_FS;
2302 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg);
2303 enc_cfg.enc_blk.cfg.amrnb.mode = band_mode;
2304 enc_cfg.enc_blk.cfg.amrnb.dtx_mode = dtx_enable;
2305
2306 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2307 if (rc < 0) {
2308 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2309 goto fail_cmd;
2310 }
2311 rc = wait_event_timeout(ac->cmd_wait,
2312 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2313 if (!rc) {
2314 pr_err("timeout. waited for FORMAT_UPDATE\n");
2315 goto fail_cmd;
2316 }
2317 return 0;
2318fail_cmd:
2319 return -EINVAL;
2320}
2321
Alex Wong2caeecc2011-10-28 10:52:15 +05302322int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
2323 uint16_t band_mode, uint16_t dtx_enable)
2324{
2325 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2326 int rc = 0;
2327
2328 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2329 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2330
2331 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2332
2333 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2334
2335 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2336 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2337
2338 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2339 enc_cfg.enc_blk.format_id = AMRWB_FS;
2340 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrwb_read_cfg);
2341 enc_cfg.enc_blk.cfg.amrwb.mode = band_mode;
2342 enc_cfg.enc_blk.cfg.amrwb.dtx_mode = dtx_enable;
2343
2344 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2345 if (rc < 0) {
2346 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2347 goto fail_cmd;
2348 }
2349 rc = wait_event_timeout(ac->cmd_wait,
2350 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2351 if (!rc) {
2352 pr_err("timeout. waited for FORMAT_UPDATE\n");
2353 goto fail_cmd;
2354 }
2355 return 0;
2356fail_cmd:
2357 return -EINVAL;
2358}
2359
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002360int q6asm_media_format_block_pcm(struct audio_client *ac,
2361 uint32_t rate, uint32_t channels)
2362{
2363 struct asm_stream_media_format_update fmt;
2364 int rc = 0;
2365
2366 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2367 channels);
2368
2369 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2370
2371 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2372
2373 fmt.format = LINEAR_PCM;
2374 fmt.cfg_size = sizeof(struct asm_pcm_cfg);
2375 fmt.write_cfg.pcm_cfg.ch_cfg = channels;
2376 fmt.write_cfg.pcm_cfg.bits_per_sample = 16;
2377 fmt.write_cfg.pcm_cfg.sample_rate = rate;
2378 fmt.write_cfg.pcm_cfg.is_signed = 1;
2379 fmt.write_cfg.pcm_cfg.interleaved = 1;
2380
2381 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2382 if (rc < 0) {
2383 pr_err("%s:Comamnd open failed\n", __func__);
2384 goto fail_cmd;
2385 }
2386 rc = wait_event_timeout(ac->cmd_wait,
2387 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2388 if (!rc) {
2389 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2390 goto fail_cmd;
2391 }
2392 return 0;
2393fail_cmd:
2394 return -EINVAL;
2395}
2396
Kiran Kandi5e809b02012-01-31 00:24:33 -08002397int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
2398 uint32_t rate, uint32_t channels)
2399{
2400 struct asm_stream_media_format_update fmt;
2401 u8 *channel_mapping;
2402 int rc = 0;
2403
2404 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2405 channels);
2406
2407 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2408
2409 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2410
2411 fmt.format = MULTI_CHANNEL_PCM;
2412 fmt.cfg_size = sizeof(struct asm_multi_channel_pcm_fmt_blk);
2413 fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels;
2414 fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = 16;
2415 fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate;
2416 fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1;
2417 fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1;
2418 channel_mapping =
2419 fmt.write_cfg.multi_ch_pcm_cfg.channel_mapping;
2420
2421 memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
2422
2423 if (channels == 1) {
2424 channel_mapping[0] = PCM_CHANNEL_FL;
2425 } else if (channels == 2) {
2426 channel_mapping[0] = PCM_CHANNEL_FL;
2427 channel_mapping[1] = PCM_CHANNEL_FR;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002428 } else if (channels == 4) {
2429 channel_mapping[0] = PCM_CHANNEL_FL;
2430 channel_mapping[1] = PCM_CHANNEL_FR;
2431 channel_mapping[1] = PCM_CHANNEL_LB;
2432 channel_mapping[1] = PCM_CHANNEL_RB;
Kiran Kandi5e809b02012-01-31 00:24:33 -08002433 } else if (channels == 6) {
SathishKumar Mani6074b772012-09-26 13:49:49 -07002434 channel_mapping[0] = PCM_CHANNEL_FL;
2435 channel_mapping[1] = PCM_CHANNEL_FR;
2436 channel_mapping[2] = PCM_CHANNEL_FC;
2437 channel_mapping[3] = PCM_CHANNEL_LFE;
2438 channel_mapping[4] = PCM_CHANNEL_LB;
2439 channel_mapping[5] = PCM_CHANNEL_RB;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002440 } else if (channels == 8) {
2441 channel_mapping[0] = PCM_CHANNEL_FC;
2442 channel_mapping[1] = PCM_CHANNEL_FL;
2443 channel_mapping[2] = PCM_CHANNEL_FR;
2444 channel_mapping[3] = PCM_CHANNEL_LB;
2445 channel_mapping[4] = PCM_CHANNEL_RB;
2446 channel_mapping[5] = PCM_CHANNEL_LFE;
2447 channel_mapping[6] = PCM_CHANNEL_FLC;
2448 channel_mapping[7] = PCM_CHANNEL_FRC;
Kiran Kandi5e809b02012-01-31 00:24:33 -08002449 } else {
2450 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2451 channels);
2452 return -EINVAL;
2453 }
2454
2455 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2456 if (rc < 0) {
2457 pr_err("%s:Comamnd open failed\n", __func__);
2458 goto fail_cmd;
2459 }
2460 rc = wait_event_timeout(ac->cmd_wait,
2461 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2462 if (!rc) {
2463 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2464 goto fail_cmd;
2465 }
2466 return 0;
2467fail_cmd:
2468 return -EINVAL;
2469}
2470
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002471int q6asm_media_format_block_aac(struct audio_client *ac,
2472 struct asm_aac_cfg *cfg)
2473{
2474 struct asm_stream_media_format_update fmt;
2475 int rc = 0;
2476
2477 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2478 cfg->sample_rate, cfg->ch_cfg);
2479
2480 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2481
2482 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2483
2484 fmt.format = MPEG4_AAC;
2485 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2486 fmt.write_cfg.aac_cfg.format = cfg->format;
2487 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2488 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2489 fmt.write_cfg.aac_cfg.section_data_resilience =
2490 cfg->section_data_resilience;
2491 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2492 cfg->scalefactor_data_resilience;
2493 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2494 cfg->spectral_data_resilience;
2495 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2496 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2497 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2498 __func__, fmt.format, fmt.cfg_size,
2499 fmt.write_cfg.aac_cfg.format,
2500 fmt.write_cfg.aac_cfg.aot,
2501 fmt.write_cfg.aac_cfg.ch_cfg,
2502 fmt.write_cfg.aac_cfg.sample_rate);
2503 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2504 if (rc < 0) {
2505 pr_err("%s:Comamnd open failed\n", __func__);
2506 goto fail_cmd;
2507 }
2508 rc = wait_event_timeout(ac->cmd_wait,
2509 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2510 if (!rc) {
2511 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2512 goto fail_cmd;
2513 }
2514 return 0;
2515fail_cmd:
2516 return -EINVAL;
2517}
2518
Ajit Khare43fd8832012-08-07 13:19:44 -07002519int q6asm_media_format_block_amrwbplus(struct audio_client *ac,
2520 struct asm_amrwbplus_cfg *cfg)
2521{
2522 struct asm_stream_media_format_update fmt;
2523 int rc = 0;
2524 pr_debug("q6asm_media_format_block_amrwbplus");
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002525
Ajit Khare43fd8832012-08-07 13:19:44 -07002526 pr_debug("%s:session[%d]band-mode[%d]frame-fmt[%d]ch[%d]\n",
2527 __func__,
2528 ac->session,
2529 cfg->amr_band_mode,
2530 cfg->amr_frame_fmt,
2531 cfg->num_channels);
2532
2533 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2534
2535 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2536
2537 fmt.format = AMR_WB_PLUS;
2538 fmt.cfg_size = cfg->size_bytes;
2539
2540 fmt.write_cfg.amrwbplus_cfg.size_bytes = cfg->size_bytes;
2541 fmt.write_cfg.amrwbplus_cfg.version = cfg->version;
2542 fmt.write_cfg.amrwbplus_cfg.num_channels = cfg->num_channels;
2543 fmt.write_cfg.amrwbplus_cfg.amr_band_mode = cfg->amr_band_mode;
2544 fmt.write_cfg.amrwbplus_cfg.amr_dtx_mode = cfg->amr_dtx_mode;
2545 fmt.write_cfg.amrwbplus_cfg.amr_frame_fmt = cfg->amr_frame_fmt;
2546 fmt.write_cfg.amrwbplus_cfg.amr_lsf_idx = cfg->amr_lsf_idx;
2547
2548 pr_debug("%s: num_channels=%x amr_band_mode=%d amr_frame_fmt=%d\n",
2549 __func__,
2550 cfg->num_channels,
2551 cfg->amr_band_mode,
2552 cfg->amr_frame_fmt);
2553
2554 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2555 if (rc < 0) {
2556 pr_err("%s:Comamnd media format update failed..\n", __func__);
2557 goto fail_cmd;
2558 }
2559 rc = wait_event_timeout(ac->cmd_wait,
2560 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2561 if (!rc) {
2562 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2563 goto fail_cmd;
2564 }
2565 return 0;
2566fail_cmd:
2567 return -EINVAL;
2568}
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002569int q6asm_media_format_block_multi_aac(struct audio_client *ac,
2570 struct asm_aac_cfg *cfg)
2571{
2572 struct asm_stream_media_format_update fmt;
2573 int rc = 0;
2574
2575 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2576 cfg->sample_rate, cfg->ch_cfg);
2577
2578 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2579
2580 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2581
2582 fmt.format = MPEG4_MULTI_AAC;
2583 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2584 fmt.write_cfg.aac_cfg.format = cfg->format;
2585 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2586 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2587 fmt.write_cfg.aac_cfg.section_data_resilience =
2588 cfg->section_data_resilience;
2589 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2590 cfg->scalefactor_data_resilience;
2591 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2592 cfg->spectral_data_resilience;
2593 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2594 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2595 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2596 __func__, fmt.format, fmt.cfg_size,
2597 fmt.write_cfg.aac_cfg.format,
2598 fmt.write_cfg.aac_cfg.aot,
2599 fmt.write_cfg.aac_cfg.ch_cfg,
2600 fmt.write_cfg.aac_cfg.sample_rate);
2601 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2602 if (rc < 0) {
2603 pr_err("%s:Comamnd open failed\n", __func__);
2604 goto fail_cmd;
2605 }
2606 rc = wait_event_timeout(ac->cmd_wait,
2607 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2608 if (!rc) {
2609 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2610 goto fail_cmd;
2611 }
2612 return 0;
2613fail_cmd:
2614 return -EINVAL;
2615}
2616
2617
Alex Wong2caeecc2011-10-28 10:52:15 +05302618
2619int q6asm_media_format_block(struct audio_client *ac, uint32_t format)
2620{
2621
2622 struct asm_stream_media_format_update fmt;
2623 int rc = 0;
2624
2625 pr_debug("%s:session[%d] format[0x%x]\n", __func__,
2626 ac->session, format);
2627
2628 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2629 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302630 switch (format) {
2631 case FORMAT_V13K:
2632 fmt.format = V13K_FS;
2633 break;
2634 case FORMAT_EVRC:
2635 fmt.format = EVRC_FS;
2636 break;
2637 case FORMAT_AMRWB:
2638 fmt.format = AMRWB_FS;
2639 break;
Ajit Khare43fd8832012-08-07 13:19:44 -07002640 case FORMAT_AMR_WB_PLUS:
2641 fmt.format = AMR_WB_PLUS;
2642 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302643 case FORMAT_AMRNB:
2644 fmt.format = AMRNB_FS;
2645 break;
2646 case FORMAT_MP3:
2647 fmt.format = MP3;
2648 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05302649 case FORMAT_DTS:
2650 fmt.format = DTS;
2651 break;
2652 case FORMAT_DTS_LBR:
2653 fmt.format = DTS_LBR;
2654 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302655 default:
2656 pr_err("Invalid format[%d]\n", format);
2657 goto fail_cmd;
2658 }
Alex Wong2caeecc2011-10-28 10:52:15 +05302659 fmt.cfg_size = 0;
2660
2661 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2662 if (rc < 0) {
2663 pr_err("%s:Comamnd open failed\n", __func__);
2664 goto fail_cmd;
2665 }
2666 rc = wait_event_timeout(ac->cmd_wait,
2667 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2668 if (!rc) {
2669 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2670 goto fail_cmd;
2671 }
2672 return 0;
2673fail_cmd:
2674 return -EINVAL;
2675}
2676
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002677int q6asm_media_format_block_wma(struct audio_client *ac,
2678 void *cfg)
2679{
2680 struct asm_stream_media_format_update fmt;
2681 struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
2682 int rc = 0;
2683
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002684 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 -07002685 ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
2686 wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
2687 wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
2688 wma_cfg->ch_mask, wma_cfg->encode_opt);
2689
2690 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2691
2692 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2693
2694 fmt.format = WMA_V9;
2695 fmt.cfg_size = sizeof(struct asm_wma_cfg);
2696 fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag;
2697 fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg;
2698 fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate;
2699 fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
2700 fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align;
2701 fmt.write_cfg.wma_cfg.valid_bits_per_sample =
2702 wma_cfg->valid_bits_per_sample;
2703 fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask;
2704 fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt;
2705 fmt.write_cfg.wma_cfg.adv_encode_opt = 0;
2706 fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0;
2707 fmt.write_cfg.wma_cfg.drc_peak_ref = 0;
2708 fmt.write_cfg.wma_cfg.drc_peak_target = 0;
2709 fmt.write_cfg.wma_cfg.drc_ave_ref = 0;
2710 fmt.write_cfg.wma_cfg.drc_ave_target = 0;
2711
2712 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2713 if (rc < 0) {
2714 pr_err("%s:Comamnd open failed\n", __func__);
2715 goto fail_cmd;
2716 }
2717 rc = wait_event_timeout(ac->cmd_wait,
2718 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2719 if (!rc) {
2720 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2721 goto fail_cmd;
2722 }
2723 return 0;
2724fail_cmd:
2725 return -EINVAL;
2726}
2727
2728int q6asm_media_format_block_wmapro(struct audio_client *ac,
2729 void *cfg)
2730{
2731 struct asm_stream_media_format_update fmt;
2732 struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
2733 int rc = 0;
2734
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002735 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 -07002736 ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
2737 wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
2738 wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
2739 wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
2740 wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
2741
2742 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2743
2744 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2745
2746 fmt.format = WMA_V10PRO;
2747 fmt.cfg_size = sizeof(struct asm_wmapro_cfg);
2748 fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag;
2749 fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg;
2750 fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate;
2751 fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec =
2752 wmapro_cfg->avg_bytes_per_sec;
2753 fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align;
2754 fmt.write_cfg.wmapro_cfg.valid_bits_per_sample =
2755 wmapro_cfg->valid_bits_per_sample;
2756 fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask;
2757 fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt;
2758 fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt;
2759 fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2;
2760 fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0;
2761 fmt.write_cfg.wmapro_cfg.drc_peak_target = 0;
2762 fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0;
2763 fmt.write_cfg.wmapro_cfg.drc_ave_target = 0;
2764
2765 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2766 if (rc < 0) {
2767 pr_err("%s:Comamnd open failed\n", __func__);
2768 goto fail_cmd;
2769 }
2770 rc = wait_event_timeout(ac->cmd_wait,
2771 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2772 if (!rc) {
2773 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2774 goto fail_cmd;
2775 }
2776 return 0;
2777fail_cmd:
2778 return -EINVAL;
2779}
2780
2781int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
2782 uint32_t bufsz, uint32_t bufcnt)
2783{
2784 struct asm_stream_cmd_memory_map mem_map;
2785 int rc = 0;
2786
2787 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2788 pr_err("APR handle NULL\n");
2789 return -EINVAL;
2790 }
2791
2792 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2793
2794 mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP;
2795
2796 mem_map.buf_add = buf_add;
2797 mem_map.buf_size = bufsz * bufcnt;
2798 mem_map.mempool_id = 0; /* EBI */
2799 mem_map.reserved = 0;
2800
2801 q6asm_add_mmaphdr(&mem_map.hdr,
2802 sizeof(struct asm_stream_cmd_memory_map), TRUE);
2803
2804 pr_debug("buf add[%x] buf_add_parameter[%x]\n",
2805 mem_map.buf_add, buf_add);
2806
2807 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map);
2808 if (rc < 0) {
2809 pr_err("mem_map op[0x%x]rc[%d]\n",
2810 mem_map.hdr.opcode, rc);
2811 rc = -EINVAL;
2812 goto fail_cmd;
2813 }
2814
2815 rc = wait_event_timeout(this_mmap.cmd_wait,
2816 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2817 if (!rc) {
2818 pr_err("timeout. waited for memory_map\n");
2819 rc = -EINVAL;
2820 goto fail_cmd;
2821 }
2822 rc = 0;
2823fail_cmd:
2824 return rc;
2825}
2826
2827int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
2828{
2829 struct asm_stream_cmd_memory_unmap mem_unmap;
2830 int rc = 0;
2831
2832 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2833 pr_err("APR handle NULL\n");
2834 return -EINVAL;
2835 }
2836 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2837
2838 q6asm_add_mmaphdr(&mem_unmap.hdr,
2839 sizeof(struct asm_stream_cmd_memory_unmap), TRUE);
2840 mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP;
2841 mem_unmap.buf_add = buf_add;
2842
2843 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_unmap);
2844 if (rc < 0) {
2845 pr_err("mem_unmap op[0x%x]rc[%d]\n",
2846 mem_unmap.hdr.opcode, rc);
2847 rc = -EINVAL;
2848 goto fail_cmd;
2849 }
2850
2851 rc = wait_event_timeout(this_mmap.cmd_wait,
2852 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2853 if (!rc) {
2854 pr_err("timeout. waited for memory_map\n");
2855 rc = -EINVAL;
2856 goto fail_cmd;
2857 }
2858 rc = 0;
2859fail_cmd:
2860 return rc;
2861}
2862
2863int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
2864{
2865 void *vol_cmd = NULL;
2866 void *payload = NULL;
2867 struct asm_pp_params_command *cmd = NULL;
2868 struct asm_lrchannel_gain_params *lrgain = NULL;
2869 int sz = 0;
2870 int rc = 0;
2871
2872 sz = sizeof(struct asm_pp_params_command) +
2873 + sizeof(struct asm_lrchannel_gain_params);
2874 vol_cmd = kzalloc(sz, GFP_KERNEL);
2875 if (vol_cmd == NULL) {
2876 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2877 rc = -EINVAL;
2878 return rc;
2879 }
2880 cmd = (struct asm_pp_params_command *)vol_cmd;
2881 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2882 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2883 cmd->payload = NULL;
2884 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2885 sizeof(struct asm_lrchannel_gain_params);
2886 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2887 cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID;
2888 cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params);
2889 cmd->params.reserved = 0;
2890
2891 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2892 lrgain = (struct asm_lrchannel_gain_params *)payload;
2893
2894 lrgain->left_gain = left_gain;
2895 lrgain->right_gain = right_gain;
2896 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2897 if (rc < 0) {
2898 pr_err("%s: Volume Command failed\n", __func__);
2899 rc = -EINVAL;
2900 goto fail_cmd;
2901 }
2902
2903 rc = wait_event_timeout(ac->cmd_wait,
2904 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2905 if (!rc) {
2906 pr_err("%s: timeout in sending volume command to apr\n",
2907 __func__);
2908 rc = -EINVAL;
2909 goto fail_cmd;
2910 }
2911 rc = 0;
2912fail_cmd:
2913 kfree(vol_cmd);
2914 return rc;
2915}
2916
2917static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
2918 uint32_t bufsz, uint32_t bufcnt)
2919{
2920 struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL;
2921 struct asm_memory_map_regions *mregions = NULL;
2922 struct audio_port_data *port = NULL;
2923 struct audio_buffer *ab = NULL;
2924 void *mmap_region_cmd = NULL;
2925 void *payload = NULL;
2926 int rc = 0;
2927 int i = 0;
2928 int cmd_size = 0;
2929
2930 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2931 pr_err("APR handle NULL\n");
2932 return -EINVAL;
2933 }
2934 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2935
2936 cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions)
2937 + sizeof(struct asm_memory_map_regions) * bufcnt;
2938
2939 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302940 if (mmap_region_cmd == NULL) {
2941 pr_err("%s: Mem alloc failed\n", __func__);
2942 rc = -EINVAL;
2943 return rc;
2944 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002945 mmap_regions = (struct asm_stream_cmd_memory_map_regions *)
2946 mmap_region_cmd;
2947 q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE);
2948 mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS;
2949 mmap_regions->mempool_id = 0;
2950 mmap_regions->nregions = bufcnt & 0x00ff;
2951 pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions);
2952 payload = ((u8 *) mmap_region_cmd +
2953 sizeof(struct asm_stream_cmd_memory_map_regions));
2954 mregions = (struct asm_memory_map_regions *)payload;
2955
2956 port = &ac->port[dir];
2957 for (i = 0; i < bufcnt; i++) {
2958 ab = &port->buf[i];
2959 mregions->phys = ab->phys;
2960 mregions->buf_size = ab->size;
2961 ++mregions;
2962 }
2963
2964 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) mmap_region_cmd);
2965 if (rc < 0) {
2966 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2967 mmap_regions->hdr.opcode, rc);
2968 rc = -EINVAL;
2969 goto fail_cmd;
2970 }
2971
2972 rc = wait_event_timeout(this_mmap.cmd_wait,
2973 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2974 if (!rc) {
2975 pr_err("timeout. waited for memory_map\n");
2976 rc = -EINVAL;
2977 goto fail_cmd;
2978 }
2979 rc = 0;
2980fail_cmd:
2981 kfree(mmap_region_cmd);
2982 return rc;
2983}
2984
2985static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
2986 uint32_t bufsz, uint32_t bufcnt)
2987{
2988 struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL;
2989 struct asm_memory_unmap_regions *mregions = NULL;
2990 struct audio_port_data *port = NULL;
2991 struct audio_buffer *ab = NULL;
2992 void *unmap_region_cmd = NULL;
2993 void *payload = NULL;
2994 int rc = 0;
2995 int i = 0;
2996 int cmd_size = 0;
2997
2998 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2999 pr_err("APR handle NULL\n");
3000 return -EINVAL;
3001 }
3002 pr_debug("%s: Session[%d]\n", __func__, ac->session);
3003
3004 cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) +
3005 sizeof(struct asm_memory_unmap_regions) * bufcnt;
3006
3007 unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05303008 if (unmap_region_cmd == NULL) {
3009 pr_err("%s: Mem alloc failed\n", __func__);
3010 rc = -EINVAL;
3011 return rc;
3012 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003013 unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *)
3014 unmap_region_cmd;
3015 q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE);
3016 unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS;
3017 unmap_regions->nregions = bufcnt & 0x00ff;
3018 pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions);
3019 payload = ((u8 *) unmap_region_cmd +
3020 sizeof(struct asm_stream_cmd_memory_unmap_regions));
3021 mregions = (struct asm_memory_unmap_regions *)payload;
3022 port = &ac->port[dir];
3023 for (i = 0; i < bufcnt; i++) {
3024 ab = &port->buf[i];
3025 mregions->phys = ab->phys;
3026 ++mregions;
3027 }
3028
3029 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd);
3030 if (rc < 0) {
3031 pr_err("mmap_regions op[0x%x]rc[%d]\n",
3032 unmap_regions->hdr.opcode, rc);
3033 goto fail_cmd;
3034 }
3035
3036 rc = wait_event_timeout(this_mmap.cmd_wait,
3037 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
3038 if (!rc) {
3039 pr_err("timeout. waited for memory_unmap\n");
3040 goto fail_cmd;
3041 }
3042 rc = 0;
3043
3044fail_cmd:
3045 kfree(unmap_region_cmd);
3046 return rc;
3047}
3048
3049int q6asm_set_mute(struct audio_client *ac, int muteflag)
3050{
3051 void *vol_cmd = NULL;
3052 void *payload = NULL;
3053 struct asm_pp_params_command *cmd = NULL;
3054 struct asm_mute_params *mute = NULL;
3055 int sz = 0;
3056 int rc = 0;
3057
3058 sz = sizeof(struct asm_pp_params_command) +
3059 + sizeof(struct asm_mute_params);
3060 vol_cmd = kzalloc(sz, GFP_KERNEL);
3061 if (vol_cmd == NULL) {
3062 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3063 rc = -EINVAL;
3064 return rc;
3065 }
3066 cmd = (struct asm_pp_params_command *)vol_cmd;
3067 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3068 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3069 cmd->payload = NULL;
3070 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3071 sizeof(struct asm_mute_params);
3072 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3073 cmd->params.param_id = MUTE_CONFIG_PARAM_ID;
3074 cmd->params.param_size = sizeof(struct asm_mute_params);
3075 cmd->params.reserved = 0;
3076
3077 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3078 mute = (struct asm_mute_params *)payload;
3079
3080 mute->muteflag = muteflag;
3081 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3082 if (rc < 0) {
3083 pr_err("%s: Mute Command failed\n", __func__);
3084 rc = -EINVAL;
3085 goto fail_cmd;
3086 }
3087
3088 rc = wait_event_timeout(ac->cmd_wait,
3089 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3090 if (!rc) {
3091 pr_err("%s: timeout in sending mute command to apr\n",
3092 __func__);
3093 rc = -EINVAL;
3094 goto fail_cmd;
3095 }
3096 rc = 0;
3097fail_cmd:
3098 kfree(vol_cmd);
3099 return rc;
3100}
3101
3102int q6asm_set_volume(struct audio_client *ac, int volume)
3103{
3104 void *vol_cmd = NULL;
3105 void *payload = NULL;
3106 struct asm_pp_params_command *cmd = NULL;
3107 struct asm_master_gain_params *mgain = NULL;
3108 int sz = 0;
3109 int rc = 0;
3110
3111 sz = sizeof(struct asm_pp_params_command) +
3112 + sizeof(struct asm_master_gain_params);
3113 vol_cmd = kzalloc(sz, GFP_KERNEL);
3114 if (vol_cmd == NULL) {
3115 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3116 rc = -EINVAL;
3117 return rc;
3118 }
3119 cmd = (struct asm_pp_params_command *)vol_cmd;
3120 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3121 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3122 cmd->payload = NULL;
3123 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3124 sizeof(struct asm_master_gain_params);
3125 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3126 cmd->params.param_id = MASTER_GAIN_PARAM_ID;
3127 cmd->params.param_size = sizeof(struct asm_master_gain_params);
3128 cmd->params.reserved = 0;
3129
3130 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3131 mgain = (struct asm_master_gain_params *)payload;
3132
3133 mgain->master_gain = volume;
3134 mgain->padding = 0x00;
3135 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3136 if (rc < 0) {
3137 pr_err("%s: Volume Command failed\n", __func__);
3138 rc = -EINVAL;
3139 goto fail_cmd;
3140 }
3141
3142 rc = wait_event_timeout(ac->cmd_wait,
3143 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3144 if (!rc) {
3145 pr_err("%s: timeout in sending volume command to apr\n",
3146 __func__);
3147 rc = -EINVAL;
3148 goto fail_cmd;
3149 }
3150 rc = 0;
3151fail_cmd:
3152 kfree(vol_cmd);
3153 return rc;
3154}
3155
3156int q6asm_set_softpause(struct audio_client *ac,
3157 struct asm_softpause_params *pause_param)
3158{
3159 void *vol_cmd = NULL;
3160 void *payload = NULL;
3161 struct asm_pp_params_command *cmd = NULL;
3162 struct asm_softpause_params *params = NULL;
3163 int sz = 0;
3164 int rc = 0;
3165
3166 sz = sizeof(struct asm_pp_params_command) +
3167 + sizeof(struct asm_softpause_params);
3168 vol_cmd = kzalloc(sz, GFP_KERNEL);
3169 if (vol_cmd == NULL) {
3170 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3171 rc = -EINVAL;
3172 return rc;
3173 }
3174 cmd = (struct asm_pp_params_command *)vol_cmd;
3175 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3176 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3177 cmd->payload = NULL;
3178 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3179 sizeof(struct asm_softpause_params);
3180 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3181 cmd->params.param_id = SOFT_PAUSE_PARAM_ID;
3182 cmd->params.param_size = sizeof(struct asm_softpause_params);
3183 cmd->params.reserved = 0;
3184
3185 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3186 params = (struct asm_softpause_params *)payload;
3187
3188 params->enable = pause_param->enable;
3189 params->period = pause_param->period;
3190 params->step = pause_param->step;
3191 params->rampingcurve = pause_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003192 pr_debug("%s: soft Pause Command: enable = %d, period = %d, step = %d, curve = %d\n",
3193 __func__, params->enable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003194 params->period, params->step, params->rampingcurve);
3195 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3196 if (rc < 0) {
3197 pr_err("%s: Volume Command(soft_pause) failed\n", __func__);
3198 rc = -EINVAL;
3199 goto fail_cmd;
3200 }
3201
3202 rc = wait_event_timeout(ac->cmd_wait,
3203 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3204 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003205 pr_err("%s: timeout in sending volume command(soft_pause) to apr\n",
3206 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003207 rc = -EINVAL;
3208 goto fail_cmd;
3209 }
3210 rc = 0;
3211fail_cmd:
3212 kfree(vol_cmd);
3213 return rc;
3214}
3215
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003216int q6asm_set_softvolume(struct audio_client *ac,
3217 struct asm_softvolume_params *softvol_param)
3218{
3219 void *vol_cmd = NULL;
3220 void *payload = NULL;
3221 struct asm_pp_params_command *cmd = NULL;
3222 struct asm_softvolume_params *params = NULL;
3223 int sz = 0;
3224 int rc = 0;
3225
3226 sz = sizeof(struct asm_pp_params_command) +
3227 + sizeof(struct asm_softvolume_params);
3228 vol_cmd = kzalloc(sz, GFP_KERNEL);
3229 if (vol_cmd == NULL) {
3230 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3231 rc = -EINVAL;
3232 return rc;
3233 }
3234 cmd = (struct asm_pp_params_command *)vol_cmd;
3235 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3236 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3237 cmd->payload = NULL;
3238 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3239 sizeof(struct asm_softvolume_params);
3240 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3241 cmd->params.param_id = SOFT_VOLUME_PARAM_ID;
3242 cmd->params.param_size = sizeof(struct asm_softvolume_params);
3243 cmd->params.reserved = 0;
3244
3245 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3246 params = (struct asm_softvolume_params *)payload;
3247
3248 params->period = softvol_param->period;
3249 params->step = softvol_param->step;
3250 params->rampingcurve = softvol_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003251 pr_debug("%s: soft Volume:opcode = %d,payload_sz =%d,module_id =%d, param_id = %d, param_sz = %d\n",
3252 __func__,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003253 cmd->hdr.opcode, cmd->payload_size,
3254 cmd->params.module_id, cmd->params.param_id,
3255 cmd->params.param_size);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003256 pr_debug("%s: soft Volume Command: period = %d, step = %d, curve = %d\n",
3257 __func__, params->period,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003258 params->step, params->rampingcurve);
3259 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3260 if (rc < 0) {
3261 pr_err("%s: Volume Command(soft_volume) failed\n", __func__);
3262 rc = -EINVAL;
3263 goto fail_cmd;
3264 }
3265
3266 rc = wait_event_timeout(ac->cmd_wait,
3267 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3268 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003269 pr_err("%s: timeout in sending volume command(soft_volume) to apr\n",
3270 __func__);
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003271 rc = -EINVAL;
3272 goto fail_cmd;
3273 }
3274 rc = 0;
3275fail_cmd:
3276 kfree(vol_cmd);
3277 return rc;
3278}
3279
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003280int q6asm_equalizer(struct audio_client *ac, void *eq)
3281{
3282 void *eq_cmd = NULL;
3283 void *payload = NULL;
3284 struct asm_pp_params_command *cmd = NULL;
3285 struct asm_equalizer_params *equalizer = NULL;
3286 struct msm_audio_eq_stream_config *eq_params = NULL;
3287 int i = 0;
3288 int sz = 0;
3289 int rc = 0;
3290
3291 sz = sizeof(struct asm_pp_params_command) +
3292 + sizeof(struct asm_equalizer_params);
3293 eq_cmd = kzalloc(sz, GFP_KERNEL);
3294 if (eq_cmd == NULL) {
3295 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3296 rc = -EINVAL;
3297 goto fail_cmd;
3298 }
3299 eq_params = (struct msm_audio_eq_stream_config *) eq;
3300 cmd = (struct asm_pp_params_command *)eq_cmd;
3301 q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE);
3302 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3303 cmd->payload = NULL;
3304 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3305 sizeof(struct asm_equalizer_params);
3306 cmd->params.module_id = EQUALIZER_MODULE_ID;
3307 cmd->params.param_id = EQUALIZER_PARAM_ID;
3308 cmd->params.param_size = sizeof(struct asm_equalizer_params);
3309 cmd->params.reserved = 0;
3310 payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command));
3311 equalizer = (struct asm_equalizer_params *)payload;
3312
3313 equalizer->enable = eq_params->enable;
3314 equalizer->num_bands = eq_params->num_bands;
3315 pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
3316 eq_params->num_bands);
3317 for (i = 0; i < eq_params->num_bands; i++) {
3318 equalizer->eq_bands[i].band_idx =
3319 eq_params->eq_bands[i].band_idx;
3320 equalizer->eq_bands[i].filter_type =
3321 eq_params->eq_bands[i].filter_type;
3322 equalizer->eq_bands[i].center_freq_hz =
3323 eq_params->eq_bands[i].center_freq_hz;
3324 equalizer->eq_bands[i].filter_gain =
3325 eq_params->eq_bands[i].filter_gain;
3326 equalizer->eq_bands[i].q_factor =
3327 eq_params->eq_bands[i].q_factor;
3328 pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
3329 eq_params->eq_bands[i].filter_type, i);
3330 pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
3331 eq_params->eq_bands[i].center_freq_hz, i);
3332 pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
3333 eq_params->eq_bands[i].filter_gain, i);
3334 pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
3335 eq_params->eq_bands[i].q_factor, i);
3336 }
3337 rc = apr_send_pkt(ac->apr, (uint32_t *) eq_cmd);
3338 if (rc < 0) {
3339 pr_err("%s: Equalizer Command failed\n", __func__);
3340 rc = -EINVAL;
3341 goto fail_cmd;
3342 }
3343
3344 rc = wait_event_timeout(ac->cmd_wait,
3345 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3346 if (!rc) {
3347 pr_err("%s: timeout in sending equalizer command to apr\n",
3348 __func__);
3349 rc = -EINVAL;
3350 goto fail_cmd;
3351 }
3352 rc = 0;
3353fail_cmd:
3354 kfree(eq_cmd);
3355 return rc;
3356}
3357
3358int q6asm_read(struct audio_client *ac)
3359{
3360 struct asm_stream_cmd_read read;
3361 struct audio_buffer *ab;
3362 int dsp_buf;
3363 struct audio_port_data *port;
3364 int rc;
3365 if (!ac || ac->apr == NULL) {
3366 pr_err("APR handle NULL\n");
3367 return -EINVAL;
3368 }
3369 if (ac->io_mode == SYNC_IO_MODE) {
3370 port = &ac->port[OUT];
3371
3372 q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
3373
3374 mutex_lock(&port->lock);
3375
3376 dsp_buf = port->dsp_buf;
3377 ab = &port->buf[dsp_buf];
3378
3379 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3380 __func__,
3381 ac->session,
3382 dsp_buf,
3383 (void *)port->buf[dsp_buf].data,
3384 port->cpu_buf,
3385 (void *)port->buf[port->cpu_buf].phys);
3386
3387 read.hdr.opcode = ASM_DATA_CMD_READ;
3388 read.buf_add = ab->phys;
3389 read.buf_size = ab->size;
3390 read.uid = port->dsp_buf;
3391 read.hdr.token = port->dsp_buf;
3392
3393 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3394 mutex_unlock(&port->lock);
3395 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3396 read.buf_add,
3397 read.hdr.token,
3398 read.uid);
3399 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3400 if (rc < 0) {
3401 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3402 goto fail_cmd;
3403 }
3404 return 0;
3405 }
3406fail_cmd:
3407 return -EINVAL;
3408}
3409
3410int q6asm_read_nolock(struct audio_client *ac)
3411{
3412 struct asm_stream_cmd_read read;
3413 struct audio_buffer *ab;
3414 int dsp_buf;
3415 struct audio_port_data *port;
3416 int rc;
3417 if (!ac || ac->apr == NULL) {
3418 pr_err("APR handle NULL\n");
3419 return -EINVAL;
3420 }
3421 if (ac->io_mode == SYNC_IO_MODE) {
3422 port = &ac->port[OUT];
3423
3424 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3425
3426
3427 dsp_buf = port->dsp_buf;
3428 ab = &port->buf[dsp_buf];
3429
3430 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3431 __func__,
3432 ac->session,
3433 dsp_buf,
3434 (void *)port->buf[dsp_buf].data,
3435 port->cpu_buf,
3436 (void *)port->buf[port->cpu_buf].phys);
3437
3438 read.hdr.opcode = ASM_DATA_CMD_READ;
3439 read.buf_add = ab->phys;
3440 read.buf_size = ab->size;
3441 read.uid = port->dsp_buf;
3442 read.hdr.token = port->dsp_buf;
3443
3444 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3445 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3446 read.buf_add,
3447 read.hdr.token,
3448 read.uid);
3449 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3450 if (rc < 0) {
3451 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3452 goto fail_cmd;
3453 }
3454 return 0;
3455 }
3456fail_cmd:
3457 return -EINVAL;
3458}
3459
3460
3461static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
3462 uint32_t pkt_size, uint32_t cmd_flg)
3463{
3464 pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg,
3465 ac->session);
3466 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
3467 APR_HDR_LEN(sizeof(struct apr_hdr)),\
3468 APR_PKT_VER);
3469 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
3470 hdr->src_domain = APR_DOMAIN_APPS;
3471 hdr->dest_svc = APR_SVC_ASM;
3472 hdr->dest_domain = APR_DOMAIN_ADSP;
3473 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
3474 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
3475 if (cmd_flg) {
3476 hdr->token = ac->session;
3477 atomic_set(&ac->cmd_state, 1);
3478 }
3479 hdr->pkt_size = pkt_size;
3480 return;
3481}
3482
3483int q6asm_async_write(struct audio_client *ac,
3484 struct audio_aio_write_param *param)
3485{
3486 int rc = 0;
3487 struct asm_stream_cmd_write write;
3488
3489 if (!ac || ac->apr == NULL) {
3490 pr_err("%s: APR handle NULL\n", __func__);
3491 return -EINVAL;
3492 }
3493
3494 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE);
3495
3496 /* Pass physical address as token for AIO scheme */
3497 write.hdr.token = param->uid;
3498 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3499 write.buf_add = param->paddr;
3500 write.avail_bytes = param->len;
3501 write.uid = param->uid;
3502 write.msw_ts = param->msw_ts;
3503 write.lsw_ts = param->lsw_ts;
3504 /* Use 0xFF00 for disabling timestamps */
3505 if (param->flags == 0xFF00)
3506 write.uflags = (0x00000000 | (param->flags & 0x800000FF));
3507 else
3508 write.uflags = (0x80000000 | param->flags);
3509
3510 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3511 write.buf_add, write.avail_bytes);
3512
3513 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3514 if (rc < 0) {
3515 pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__,
3516 write.hdr.opcode, rc);
3517 goto fail_cmd;
3518 }
3519 return 0;
3520fail_cmd:
3521 return -EINVAL;
3522}
3523
3524int q6asm_async_read(struct audio_client *ac,
3525 struct audio_aio_read_param *param)
3526{
3527 int rc = 0;
3528 struct asm_stream_cmd_read read;
3529
3530 if (!ac || ac->apr == NULL) {
3531 pr_err("%s: APR handle NULL\n", __func__);
3532 return -EINVAL;
3533 }
3534
3535 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3536
3537 /* Pass physical address as token for AIO scheme */
3538 read.hdr.token = param->paddr;
3539 read.hdr.opcode = ASM_DATA_CMD_READ;
3540 read.buf_add = param->paddr;
3541 read.buf_size = param->len;
3542 read.uid = param->uid;
3543
3544 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3545 read.buf_add, read.buf_size);
3546
3547 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3548 if (rc < 0) {
3549 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3550 read.hdr.opcode, rc);
3551 goto fail_cmd;
3552 }
3553 return 0;
3554fail_cmd:
3555 return -EINVAL;
3556}
3557
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07003558int q6asm_async_read_compressed(struct audio_client *ac,
3559 struct audio_aio_read_param *param)
3560{
3561 int rc = 0;
3562 struct asm_stream_cmd_read read;
3563
3564 if (!ac || ac->apr == NULL) {
3565 pr_err("%s: APR handle NULL\n", __func__);
3566 return -EINVAL;
3567 }
3568
3569 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3570
3571 /* Pass physical address as token for AIO scheme */
3572 read.hdr.token = param->paddr;
3573 read.hdr.opcode = ASM_DATA_CMD_READ_COMPRESSED;
3574 read.buf_add = param->paddr;
3575 read.buf_size = param->len;
3576 read.uid = param->uid;
3577
3578 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3579 read.buf_add, read.buf_size);
3580
3581 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3582 if (rc < 0) {
3583 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3584 read.hdr.opcode, rc);
3585 goto fail_cmd;
3586 }
3587 return 0;
3588fail_cmd:
3589 return -EINVAL;
3590}
3591
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003592int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3593 uint32_t lsw_ts, uint32_t flags)
3594{
3595 int rc = 0;
3596 struct asm_stream_cmd_write write;
3597 struct audio_port_data *port;
3598 struct audio_buffer *ab;
3599 int dsp_buf = 0;
3600
3601 if (!ac || ac->apr == NULL) {
3602 pr_err("APR handle NULL\n");
3603 return -EINVAL;
3604 }
3605 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3606 if (ac->io_mode == SYNC_IO_MODE) {
3607 port = &ac->port[IN];
3608
3609 q6asm_add_hdr(ac, &write.hdr, sizeof(write),
3610 FALSE);
3611 mutex_lock(&port->lock);
3612
3613 dsp_buf = port->dsp_buf;
3614 ab = &port->buf[dsp_buf];
3615
3616 write.hdr.token = port->dsp_buf;
3617 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3618 write.buf_add = ab->phys;
3619 write.avail_bytes = len;
3620 write.uid = port->dsp_buf;
3621 write.msw_ts = msw_ts;
3622 write.lsw_ts = lsw_ts;
3623 /* Use 0xFF00 for disabling timestamps */
3624 if (flags == 0xFF00)
3625 write.uflags = (0x00000000 | (flags & 0x800000FF));
3626 else
3627 write.uflags = (0x80000000 | flags);
3628 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3629
3630 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3631 , __func__,
3632 ab->phys,
3633 write.buf_add,
3634 write.hdr.token,
3635 write.uid);
3636 mutex_unlock(&port->lock);
Rajesha Kini3498c932011-07-19 19:58:27 +05303637#ifdef CONFIG_DEBUG_FS
3638 if (out_enable_flag) {
3639 char zero_pattern[2] = {0x00, 0x00};
3640 /* If First two byte is non zero and last two byte
3641 is zero then it is warm output pattern */
3642 if ((strncmp(((char *)ab->data), zero_pattern, 2)) &&
3643 (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3644 do_gettimeofday(&out_warm_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003645 pr_debug("WARM:apr_send_pkt at %ld sec %ld microsec\n",
3646 out_warm_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303647 out_warm_tv.tv_usec);
3648 pr_debug("Warm Pattern Matched");
3649 }
3650 /* If First two byte is zero and last two byte is
3651 non zero then it is cont ouput pattern */
3652 else if ((!strncmp(((char *)ab->data), zero_pattern, 2))
3653 && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3654 do_gettimeofday(&out_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003655 pr_debug("CONT:apr_send_pkt at %ld sec %ld microsec\n",
3656 out_cont_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303657 out_cont_tv.tv_usec);
3658 pr_debug("Cont Pattern Matched");
3659 }
3660 }
3661#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003662 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3663 if (rc < 0) {
3664 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3665 goto fail_cmd;
3666 }
3667 pr_debug("%s: WRITE SUCCESS\n", __func__);
3668 return 0;
3669 }
3670fail_cmd:
3671 return -EINVAL;
3672}
3673
3674int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3675 uint32_t lsw_ts, uint32_t flags)
3676{
3677 int rc = 0;
3678 struct asm_stream_cmd_write write;
3679 struct audio_port_data *port;
3680 struct audio_buffer *ab;
3681 int dsp_buf = 0;
3682
3683 if (!ac || ac->apr == NULL) {
3684 pr_err("APR handle NULL\n");
3685 return -EINVAL;
3686 }
3687 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3688 if (ac->io_mode == SYNC_IO_MODE) {
3689 port = &ac->port[IN];
3690
3691 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
3692 FALSE);
3693
3694 dsp_buf = port->dsp_buf;
3695 ab = &port->buf[dsp_buf];
3696
3697 write.hdr.token = port->dsp_buf;
3698 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3699 write.buf_add = ab->phys;
3700 write.avail_bytes = len;
3701 write.uid = port->dsp_buf;
3702 write.msw_ts = msw_ts;
3703 write.lsw_ts = lsw_ts;
3704 /* Use 0xFF00 for disabling timestamps */
3705 if (flags == 0xFF00)
3706 write.uflags = (0x00000000 | (flags & 0x800000FF));
3707 else
3708 write.uflags = (0x80000000 | flags);
3709 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3710
3711 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3712 , __func__,
3713 ab->phys,
3714 write.buf_add,
3715 write.hdr.token,
3716 write.uid);
3717
3718 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3719 if (rc < 0) {
3720 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3721 goto fail_cmd;
3722 }
3723 pr_debug("%s: WRITE SUCCESS\n", __func__);
3724 return 0;
3725 }
3726fail_cmd:
3727 return -EINVAL;
3728}
3729
Patrick Lai3aabeae2013-01-06 00:52:34 -08003730int q6asm_get_session_time(struct audio_client *ac, uint64_t *tstamp)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003731{
3732 struct apr_hdr hdr;
3733 int rc;
3734
Patrick Lai3aabeae2013-01-06 00:52:34 -08003735 if (!ac || ac->apr == NULL || tstamp == NULL) {
3736 pr_err("APR handle or tstamp NULL\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003737 return -EINVAL;
3738 }
Swaminathan Sathappanc7f98992012-07-09 11:07:12 -07003739 q6asm_add_hdr(ac, &hdr, sizeof(hdr), FALSE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003740 hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME;
3741 atomic_set(&ac->time_flag, 1);
3742
3743 pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
3744 ac->session,
3745 hdr.opcode);
3746 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3747 if (rc < 0) {
3748 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3749 goto fail_cmd;
3750 }
3751 rc = wait_event_timeout(ac->time_wait,
3752 (atomic_read(&ac->time_flag) == 0), 5*HZ);
3753 if (!rc) {
3754 pr_err("%s: timeout in getting session time from DSP\n",
3755 __func__);
3756 goto fail_cmd;
3757 }
Patrick Lai3aabeae2013-01-06 00:52:34 -08003758
3759 *tstamp = ac->time_stamp;
3760 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003761
3762fail_cmd:
3763 return -EINVAL;
3764}
3765
3766int q6asm_cmd(struct audio_client *ac, int cmd)
3767{
3768 struct apr_hdr hdr;
3769 int rc;
3770 atomic_t *state;
3771 int cnt = 0;
3772
3773 if (!ac || ac->apr == NULL) {
3774 pr_err("APR handle NULL\n");
3775 return -EINVAL;
3776 }
3777 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3778 switch (cmd) {
3779 case CMD_PAUSE:
3780 pr_debug("%s:CMD_PAUSE\n", __func__);
3781 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3782 state = &ac->cmd_state;
3783 break;
3784 case CMD_FLUSH:
3785 pr_debug("%s:CMD_FLUSH\n", __func__);
3786 hdr.opcode = ASM_STREAM_CMD_FLUSH;
3787 state = &ac->cmd_state;
3788 break;
3789 case CMD_OUT_FLUSH:
3790 pr_debug("%s:CMD_OUT_FLUSH\n", __func__);
3791 hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
3792 state = &ac->cmd_state;
3793 break;
3794 case CMD_EOS:
3795 pr_debug("%s:CMD_EOS\n", __func__);
3796 hdr.opcode = ASM_DATA_CMD_EOS;
3797 atomic_set(&ac->cmd_state, 0);
3798 state = &ac->cmd_state;
3799 break;
3800 case CMD_CLOSE:
3801 pr_debug("%s:CMD_CLOSE\n", __func__);
3802 hdr.opcode = ASM_STREAM_CMD_CLOSE;
Laxminath Kasamf16d3fd2012-12-19 14:54:14 +05303803 atomic_set(&ac->cmd_close_state, 1);
3804 state = &ac->cmd_close_state;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003805 break;
3806 default:
3807 pr_err("Invalid format[%d]\n", cmd);
3808 goto fail_cmd;
3809 }
3810 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3811 ac->session,
3812 hdr.opcode);
3813 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3814 if (rc < 0) {
3815 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3816 goto fail_cmd;
3817 }
3818 rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ);
3819 if (!rc) {
3820 pr_err("timeout. waited for response opcode[0x%x]\n",
3821 hdr.opcode);
3822 goto fail_cmd;
3823 }
3824 if (cmd == CMD_FLUSH)
3825 q6asm_reset_buf_state(ac);
3826 if (cmd == CMD_CLOSE) {
3827 /* check if DSP return all buffers */
3828 if (ac->port[IN].buf) {
3829 for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
3830 cnt++) {
3831 if (ac->port[IN].buf[cnt].used == IN) {
3832 pr_debug("Write Buf[%d] not returned\n",
3833 cnt);
3834 }
3835 }
3836 }
3837 if (ac->port[OUT].buf) {
3838 for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
3839 if (ac->port[OUT].buf[cnt].used == OUT) {
3840 pr_debug("Read Buf[%d] not returned\n",
3841 cnt);
3842 }
3843 }
3844 }
3845 }
3846 return 0;
3847fail_cmd:
3848 return -EINVAL;
3849}
3850
3851int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
3852{
3853 struct apr_hdr hdr;
3854 int rc;
3855
3856 if (!ac || ac->apr == NULL) {
3857 pr_err("%s:APR handle NULL\n", __func__);
3858 return -EINVAL;
3859 }
3860 q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE);
3861 switch (cmd) {
3862 case CMD_PAUSE:
3863 pr_debug("%s:CMD_PAUSE\n", __func__);
3864 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3865 break;
3866 case CMD_EOS:
3867 pr_debug("%s:CMD_EOS\n", __func__);
3868 hdr.opcode = ASM_DATA_CMD_EOS;
3869 break;
3870 default:
3871 pr_err("%s:Invalid format[%d]\n", __func__, cmd);
3872 goto fail_cmd;
3873 }
3874 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3875 ac->session,
3876 hdr.opcode);
Jay Wang0668d1062012-07-11 18:53:21 -07003877
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003878 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3879 if (rc < 0) {
3880 pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
3881 goto fail_cmd;
3882 }
Jay Wang0668d1062012-07-11 18:53:21 -07003883 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003884 return 0;
3885fail_cmd:
3886 return -EINVAL;
3887}
3888
3889static void q6asm_reset_buf_state(struct audio_client *ac)
3890{
3891 int cnt = 0;
3892 int loopcnt = 0;
3893 struct audio_port_data *port = NULL;
3894
3895 if (ac->io_mode == SYNC_IO_MODE) {
3896 mutex_lock(&ac->cmd_lock);
3897 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
3898 port = &ac->port[loopcnt];
3899 cnt = port->max_buf_cnt - 1;
3900 port->dsp_buf = 0;
3901 port->cpu_buf = 0;
3902 while (cnt >= 0) {
3903 if (!port->buf)
3904 continue;
3905 port->buf[cnt].used = 1;
3906 cnt--;
3907 }
3908 }
3909 mutex_unlock(&ac->cmd_lock);
3910 }
3911}
3912
3913int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
3914{
3915 struct asm_stream_cmd_reg_tx_overflow_event tx_overflow;
3916 int rc;
3917
3918 if (!ac || ac->apr == NULL) {
3919 pr_err("APR handle NULL\n");
3920 return -EINVAL;
3921 }
3922 pr_debug("%s:session[%d]enable[%d]\n", __func__,
3923 ac->session, enable);
3924 q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
3925
3926 tx_overflow.hdr.opcode = \
3927 ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS;
3928 /* tx overflow event: enable */
3929 tx_overflow.enable = enable;
3930
3931 rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
3932 if (rc < 0) {
3933 pr_err("tx overflow op[0x%x]rc[%d]\n", \
3934 tx_overflow.hdr.opcode, rc);
3935 goto fail_cmd;
3936 }
3937 rc = wait_event_timeout(ac->cmd_wait,
3938 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3939 if (!rc) {
3940 pr_err("timeout. waited for tx overflow\n");
3941 goto fail_cmd;
3942 }
3943 return 0;
3944fail_cmd:
3945 return -EINVAL;
3946}
3947
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003948int q6asm_get_apr_service_id(int session_id)
3949{
3950 pr_debug("%s\n", __func__);
3951
Shiv Maliyappanahallia84982a2012-01-19 15:25:04 -08003952 if (session_id < 0 || session_id > SESSION_MAX) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003953 pr_err("%s: invalid session_id = %d\n", __func__, session_id);
3954 return -EINVAL;
3955 }
3956
3957 return ((struct apr_svc *)session[session_id]->apr)->id;
3958}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003959
3960
3961static int __init q6asm_init(void)
3962{
3963 pr_debug("%s\n", __func__);
3964 init_waitqueue_head(&this_mmap.cmd_wait);
3965 memset(session, 0, sizeof(session));
Rajesha Kini3498c932011-07-19 19:58:27 +05303966#ifdef CONFIG_DEBUG_FS
3967 out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
3968 out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
Glenn Kasten5dfda802012-10-04 16:40:27 -07003969 0664,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303970 NULL, NULL, &audio_output_latency_debug_fops);
3971 if (IS_ERR(out_dentry))
3972 pr_err("debugfs_create_file failed\n");
3973 in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
3974 in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
Glenn Kasten5dfda802012-10-04 16:40:27 -07003975 0664,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303976 NULL, NULL, &audio_input_latency_debug_fops);
3977 if (IS_ERR(in_dentry))
3978 pr_err("debugfs_create_file failed\n");
3979#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003980 return 0;
3981}
3982
3983device_initcall(q6asm_init);