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