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