blob: 20bd0f5db2791552a11d7553683b410be1f99feb [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;
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700212 ac->perf_mode = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700213 return;
214}
215
216int q6asm_audio_client_buf_free(unsigned int dir,
217 struct audio_client *ac)
218{
219 struct audio_port_data *port;
220 int cnt = 0;
221 int rc = 0;
222 pr_debug("%s: Session id %d\n", __func__, ac->session);
223 mutex_lock(&ac->cmd_lock);
224 if (ac->io_mode == SYNC_IO_MODE) {
225 port = &ac->port[dir];
226 if (!port->buf) {
227 mutex_unlock(&ac->cmd_lock);
228 return 0;
229 }
230 cnt = port->max_buf_cnt - 1;
231
232 if (cnt >= 0) {
233 rc = q6asm_memory_unmap_regions(ac, dir,
234 port->buf[0].size,
235 port->max_buf_cnt);
236 if (rc < 0)
237 pr_err("%s CMD Memory_unmap_regions failed\n",
238 __func__);
239 }
240
241 while (cnt >= 0) {
242 if (port->buf[cnt].data) {
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800243#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
244 ion_unmap_kernel(port->buf[cnt].client,
245 port->buf[cnt].handle);
246 ion_free(port->buf[cnt].client,
247 port->buf[cnt].handle);
248 ion_client_destroy(port->buf[cnt].client);
249#else
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700250 pr_debug("%s:data[%p]phys[%p][%p] cnt[%d] mem_buffer[%p]\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700251 __func__, (void *)port->buf[cnt].data,
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700252 (void *)port->buf[cnt].phys,
253 (void *)&port->buf[cnt].phys, cnt,
254 (void *)port->buf[cnt].mem_buffer);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700255 if (IS_ERR((void *)port->buf[cnt].mem_buffer))
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700256 pr_err("%s:mem buffer invalid, error = %ld\n",
257 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700258 PTR_ERR((void *)port->buf[cnt].mem_buffer));
259 else {
Laura Abbottea3e7b62012-04-30 15:59:21 -0700260 if (iounmap(
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700261 port->buf[cnt].mem_buffer) < 0)
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700262 pr_err("%s: unmap buffer failed\n",
263 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700264 }
265 free_contiguous_memory_by_paddr(
266 port->buf[cnt].phys);
267
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800268#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700269 port->buf[cnt].data = NULL;
270 port->buf[cnt].phys = 0;
271 --(port->max_buf_cnt);
272 }
273 --cnt;
274 }
275 kfree(port->buf);
276 port->buf = NULL;
277 }
278 mutex_unlock(&ac->cmd_lock);
279 return 0;
280}
281
282int q6asm_audio_client_buf_free_contiguous(unsigned int dir,
283 struct audio_client *ac)
284{
285 struct audio_port_data *port;
286 int cnt = 0;
287 int rc = 0;
288 pr_debug("%s: Session id %d\n", __func__, ac->session);
289 mutex_lock(&ac->cmd_lock);
290 port = &ac->port[dir];
291 if (!port->buf) {
292 mutex_unlock(&ac->cmd_lock);
293 return 0;
294 }
295 cnt = port->max_buf_cnt - 1;
296
297 if (cnt >= 0) {
Deepa Madiregama7d52a402011-07-13 20:28:36 +0530298 rc = q6asm_memory_unmap(ac, port->buf[0].phys, dir);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700299 if (rc < 0)
300 pr_err("%s CMD Memory_unmap_regions failed\n",
301 __func__);
302 }
303
304 if (port->buf[0].data) {
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800305#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
306 ion_unmap_kernel(port->buf[0].client, port->buf[0].handle);
307 ion_free(port->buf[0].client, port->buf[0].handle);
308 ion_client_destroy(port->buf[0].client);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700309 pr_debug("%s:data[%p]phys[%p][%p], client[%p] handle[%p]\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800310 __func__,
311 (void *)port->buf[0].data,
312 (void *)port->buf[0].phys,
313 (void *)&port->buf[0].phys,
314 (void *)port->buf[0].client,
315 (void *)port->buf[0].handle);
316#else
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700317 pr_debug("%s:data[%p]phys[%p][%p] mem_buffer[%p]\n",
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700318 __func__,
319 (void *)port->buf[0].data,
320 (void *)port->buf[0].phys,
321 (void *)&port->buf[0].phys,
322 (void *)port->buf[0].mem_buffer);
323 if (IS_ERR((void *)port->buf[0].mem_buffer))
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700324 pr_err("%s:mem buffer invalid, error = %ld\n",
325 __func__,
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700326 PTR_ERR((void *)port->buf[0].mem_buffer));
327 else {
Laura Abbottea3e7b62012-04-30 15:59:21 -0700328 if (iounmap(
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700329 port->buf[0].mem_buffer) < 0)
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700330 pr_err("%s: unmap buffer failed\n", __func__);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700331 }
332 free_contiguous_memory_by_paddr(port->buf[0].phys);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800333#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700334 }
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700335
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700336 while (cnt >= 0) {
337 port->buf[cnt].data = NULL;
338 port->buf[cnt].phys = 0;
339 cnt--;
340 }
341 port->max_buf_cnt = 0;
342 kfree(port->buf);
343 port->buf = NULL;
344 mutex_unlock(&ac->cmd_lock);
345 return 0;
346}
347
348void q6asm_audio_client_free(struct audio_client *ac)
349{
350 int loopcnt;
351 struct audio_port_data *port;
352 if (!ac || !ac->session)
353 return;
354 pr_debug("%s: Session id %d\n", __func__, ac->session);
355 if (ac->io_mode == SYNC_IO_MODE) {
356 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
357 port = &ac->port[loopcnt];
358 if (!port->buf)
359 continue;
360 pr_debug("%s:loopcnt = %d\n", __func__, loopcnt);
361 q6asm_audio_client_buf_free(loopcnt, ac);
362 }
363 }
364
365 apr_deregister(ac->apr);
366 q6asm_session_free(ac);
367
368 pr_debug("%s: APR De-Register\n", __func__);
369 if (atomic_read(&this_mmap.ref_cnt) <= 0) {
370 pr_err("%s: APR Common Port Already Closed\n", __func__);
371 goto done;
372 }
373
374 atomic_dec(&this_mmap.ref_cnt);
375 if (atomic_read(&this_mmap.ref_cnt) == 0) {
376 apr_deregister(this_mmap.apr);
377 pr_debug("%s:APR De-Register common port\n", __func__);
378 }
379done:
380 kfree(ac);
381 return;
382}
383
384int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode)
385{
386 if (ac == NULL) {
387 pr_err("%s APR handle NULL\n", __func__);
388 return -EINVAL;
389 }
390 if ((mode == ASYNC_IO_MODE) || (mode == SYNC_IO_MODE)) {
391 ac->io_mode = mode;
392 pr_debug("%s:Set Mode to %d\n", __func__, ac->io_mode);
393 return 0;
394 } else {
395 pr_err("%s:Not an valid IO Mode:%d\n", __func__, ac->io_mode);
396 return -EINVAL;
397 }
398}
399
400struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv)
401{
402 struct audio_client *ac;
403 int n;
404 int lcnt = 0;
405
406 ac = kzalloc(sizeof(struct audio_client), GFP_KERNEL);
407 if (!ac)
408 return NULL;
409 n = q6asm_session_alloc(ac);
410 if (n <= 0)
411 goto fail_session;
412 ac->session = n;
413 ac->cb = cb;
414 ac->priv = priv;
415 ac->io_mode = SYNC_IO_MODE;
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700416 ac->perf_mode = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700417 ac->apr = apr_register("ADSP", "ASM", \
418 (apr_fn)q6asm_callback,\
419 ((ac->session) << 8 | 0x0001),\
420 ac);
421
422 if (ac->apr == NULL) {
423 pr_err("%s Registration with APR failed\n", __func__);
424 goto fail;
425 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700426 rtac_set_asm_handle(n, ac->apr);
Ben Rombergerfce8f512011-07-18 16:46:09 -0700427
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700428 pr_debug("%s Registering the common port with APR\n", __func__);
429 if (atomic_read(&this_mmap.ref_cnt) == 0) {
430 this_mmap.apr = apr_register("ADSP", "ASM", \
431 (apr_fn)q6asm_mmapcallback,\
432 0x0FFFFFFFF, &this_mmap);
433 if (this_mmap.apr == NULL) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700434 pr_debug("%s Unable to register APR ASM common port\n",
435 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700436 goto fail;
437 }
438 }
439
440 atomic_inc(&this_mmap.ref_cnt);
441 init_waitqueue_head(&ac->cmd_wait);
442 init_waitqueue_head(&ac->time_wait);
443 atomic_set(&ac->time_flag, 1);
444 mutex_init(&ac->cmd_lock);
445 for (lcnt = 0; lcnt <= OUT; lcnt++) {
446 mutex_init(&ac->port[lcnt].lock);
447 spin_lock_init(&ac->port[lcnt].dsp_lock);
448 }
449 atomic_set(&ac->cmd_state, 0);
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530450 atomic_set(&ac->cmd_response, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700451
452 pr_debug("%s: session[%d]\n", __func__, ac->session);
453
454 return ac;
455fail:
456 q6asm_audio_client_free(ac);
457 return NULL;
458fail_session:
459 kfree(ac);
460 return NULL;
461}
462
Ben Romberger61754dc2011-10-31 18:25:41 -0700463struct audio_client *q6asm_get_audio_client(int session_id)
464{
465 if ((session_id <= 0) || (session_id > SESSION_MAX)) {
466 pr_err("%s: invalid session: %d\n", __func__, session_id);
467 goto err;
468 }
469
470 if (!session[session_id]) {
471 pr_err("%s: session not active: %d\n", __func__, session_id);
472 goto err;
473 }
474
475 return session[session_id];
476err:
477 return NULL;
478}
479
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700480int q6asm_audio_client_buf_alloc(unsigned int dir,
481 struct audio_client *ac,
482 unsigned int bufsz,
483 unsigned int bufcnt)
484{
485 int cnt = 0;
486 int rc = 0;
487 struct audio_buffer *buf;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800488#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
489 int len;
490#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700491
492 if (!(ac) || ((dir != IN) && (dir != OUT)))
493 return -EINVAL;
494
495 pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n", __func__, ac->session,
496 bufsz, bufcnt);
497
498 if (ac->session <= 0 || ac->session > 8)
499 goto fail;
500
501 if (ac->io_mode == SYNC_IO_MODE) {
502 if (ac->port[dir].buf) {
503 pr_debug("%s: buffer already allocated\n", __func__);
504 return 0;
505 }
506 mutex_lock(&ac->cmd_lock);
507 buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
508 GFP_KERNEL);
509
510 if (!buf) {
511 mutex_unlock(&ac->cmd_lock);
512 goto fail;
513 }
514
515 ac->port[dir].buf = buf;
516
517 while (cnt < bufcnt) {
518 if (bufsz > 0) {
519 if (!buf[cnt].data) {
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800520#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
521 buf[cnt].client = msm_ion_client_create
522 (UINT_MAX, "audio_client");
523 if (IS_ERR_OR_NULL((void *)
524 buf[cnt].client)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700525 pr_err("%s: ION create client for AUDIO failed\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800526 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700527 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800528 goto fail;
529 }
530 buf[cnt].handle = ion_alloc
531 (buf[cnt].client, bufsz, SZ_4K,
Hanumant Singh2ac41c92012-08-29 18:39:44 -0700532 (0x1 << ION_AUDIO_HEAP_ID), 0);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800533 if (IS_ERR_OR_NULL((void *)
534 buf[cnt].handle)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700535 pr_err("%s: ION memory allocation for AUDIO failed\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800536 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700537 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800538 goto fail;
539 }
540
541 rc = ion_phys(buf[cnt].client,
542 buf[cnt].handle,
543 (ion_phys_addr_t *)
544 &buf[cnt].phys,
545 (size_t *)&len);
546 if (rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700547 pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800548 __func__, rc);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700549 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800550 goto fail;
551 }
552
553 buf[cnt].data = ion_map_kernel
554 (buf[cnt].client, buf[cnt].handle,
555 0);
556 if (IS_ERR_OR_NULL((void *)
557 buf[cnt].data)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700558 pr_err("%s: ION memory mapping for AUDIO failed\n",
559 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700560 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800561 goto fail;
562 }
563 memset((void *)buf[cnt].data, 0, bufsz);
564#else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700565 unsigned int flags = 0;
566 buf[cnt].phys =
567 allocate_contiguous_ebi_nomap(bufsz,
568 SZ_4K);
569 if (!buf[cnt].phys) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700570 pr_err("%s:Buf alloc failed size=%d\n",
571 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700572 bufsz);
573 mutex_unlock(&ac->cmd_lock);
574 goto fail;
575 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700576 buf[cnt].mem_buffer =
Laura Abbottea3e7b62012-04-30 15:59:21 -0700577 ioremap(buf[cnt].phys, bufsz);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700578 if (IS_ERR(
579 (void *)buf[cnt].mem_buffer)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700580 pr_err("%s:map_buffer failed, error = %ld\n",
581 __func__,
582 PTR_ERR((void *)buf[cnt].mem_buffer));
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -0800583 mutex_unlock(&ac->cmd_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700584 goto fail;
585 }
586 buf[cnt].data =
Laura Abbottea3e7b62012-04-30 15:59:21 -0700587 buf[cnt].mem_buffer;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700588 if (!buf[cnt].data) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700589 pr_err("%s:invalid vaddr, iomap failed\n",
590 __func__);
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -0800591 mutex_unlock(&ac->cmd_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700592 goto fail;
593 }
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800594#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700595 buf[cnt].used = 1;
596 buf[cnt].size = bufsz;
597 buf[cnt].actual_size = bufsz;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800598 pr_debug("%s data[%p]phys[%p][%p]\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700599 __func__,
600 (void *)buf[cnt].data,
601 (void *)buf[cnt].phys,
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800602 (void *)&buf[cnt].phys);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700603 cnt++;
604 }
605 }
606 }
607 ac->port[dir].max_buf_cnt = cnt;
608
609 mutex_unlock(&ac->cmd_lock);
610 rc = q6asm_memory_map_regions(ac, dir, bufsz, cnt);
611 if (rc < 0) {
612 pr_err("%s:CMD Memory_map_regions failed\n", __func__);
613 goto fail;
614 }
615 }
616 return 0;
617fail:
618 q6asm_audio_client_buf_free(dir, ac);
619 return -EINVAL;
620}
621
622int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir,
623 struct audio_client *ac,
624 unsigned int bufsz,
625 unsigned int bufcnt)
626{
627 int cnt = 0;
628 int rc = 0;
629 struct audio_buffer *buf;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800630#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
631 int len;
632#else
633 int flags = 0;
634#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700635 if (!(ac) || ((dir != IN) && (dir != OUT)))
636 return -EINVAL;
637
638 pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n",
639 __func__, ac->session,
640 bufsz, bufcnt);
641
642 if (ac->session <= 0 || ac->session > 8)
643 goto fail;
644
645 if (ac->port[dir].buf) {
646 pr_debug("%s: buffer already allocated\n", __func__);
647 return 0;
648 }
649 mutex_lock(&ac->cmd_lock);
650 buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
651 GFP_KERNEL);
652
653 if (!buf) {
654 mutex_unlock(&ac->cmd_lock);
655 goto fail;
656 }
657
658 ac->port[dir].buf = buf;
659
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800660#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
661 buf[0].client = msm_ion_client_create(UINT_MAX, "audio_client");
662 if (IS_ERR_OR_NULL((void *)buf[0].client)) {
663 pr_err("%s: ION create client for AUDIO failed\n", __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700664 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800665 goto fail;
666 }
667 buf[0].handle = ion_alloc(buf[0].client, bufsz * bufcnt, SZ_4K,
Hanumant Singh2ac41c92012-08-29 18:39:44 -0700668 (0x1 << ION_AUDIO_HEAP_ID), 0);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800669 if (IS_ERR_OR_NULL((void *) buf[0].handle)) {
670 pr_err("%s: ION memory allocation for AUDIO failed\n",
671 __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700672 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800673 goto fail;
674 }
675
676 rc = ion_phys(buf[0].client, buf[0].handle,
677 (ion_phys_addr_t *)&buf[0].phys, (size_t *)&len);
678 if (rc) {
679 pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
680 __func__, rc);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700681 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800682 goto fail;
683 }
684
685 buf[0].data = ion_map_kernel(buf[0].client, buf[0].handle, 0);
686 if (IS_ERR_OR_NULL((void *) buf[0].data)) {
687 pr_err("%s: ION memory mapping for AUDIO failed\n", __func__);
Swaminathan Sathappan349fed62012-05-22 15:04:43 -0700688 mutex_unlock(&ac->cmd_lock);
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800689 goto fail;
690 }
691 memset((void *)buf[0].data, 0, (bufsz * bufcnt));
692#else
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700693 buf[0].phys = allocate_contiguous_ebi_nomap(bufsz * bufcnt,
694 SZ_4K);
695 if (!buf[0].phys) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700696 pr_err("%s:Buf alloc failed size=%d, bufcnt=%d\n",
697 __func__, bufsz, bufcnt);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700698 mutex_unlock(&ac->cmd_lock);
699 goto fail;
700 }
701
Laura Abbottea3e7b62012-04-30 15:59:21 -0700702 buf[0].mem_buffer = ioremap(buf[0].phys, bufsz * bufcnt);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700703 if (IS_ERR((void *)buf[cnt].mem_buffer)) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700704 pr_err("%s:map_buffer failed, error = %ld\n",
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700705 __func__, PTR_ERR((void *)buf[0].mem_buffer));
706
707 mutex_unlock(&ac->cmd_lock);
708 goto fail;
709 }
Laura Abbottea3e7b62012-04-30 15:59:21 -0700710 buf[0].data = buf[0].mem_buffer;
Swaminathan Sathappanbdc55082012-02-16 22:47:40 -0800711#endif
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700712 if (!buf[0].data) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700713 pr_err("%s:invalid vaddr, iomap failed\n", __func__);
Harmandeep Singh2f7c23c2011-11-04 11:57:35 -0700714 mutex_unlock(&ac->cmd_lock);
715 goto fail;
716 }
717
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700718 buf[0].used = dir ^ 1;
719 buf[0].size = bufsz;
720 buf[0].actual_size = bufsz;
721 cnt = 1;
722 while (cnt < bufcnt) {
723 if (bufsz > 0) {
724 buf[cnt].data = buf[0].data + (cnt * bufsz);
725 buf[cnt].phys = buf[0].phys + (cnt * bufsz);
726 if (!buf[cnt].data) {
727 pr_err("%s Buf alloc failed\n",
728 __func__);
729 mutex_unlock(&ac->cmd_lock);
730 goto fail;
731 }
732 buf[cnt].used = dir ^ 1;
733 buf[cnt].size = bufsz;
734 buf[cnt].actual_size = bufsz;
735 pr_debug("%s data[%p]phys[%p][%p]\n", __func__,
736 (void *)buf[cnt].data,
737 (void *)buf[cnt].phys,
738 (void *)&buf[cnt].phys);
739 }
740 cnt++;
741 }
742 ac->port[dir].max_buf_cnt = cnt;
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -0700743
744 pr_debug("%s ac->port[%d].max_buf_cnt[%d]\n", __func__, dir,
745 ac->port[dir].max_buf_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700746 mutex_unlock(&ac->cmd_lock);
747 rc = q6asm_memory_map(ac, buf[0].phys, dir, bufsz, cnt);
748 if (rc < 0) {
749 pr_err("%s:CMD Memory_map_regions failed\n", __func__);
750 goto fail;
751 }
752 return 0;
753fail:
754 q6asm_audio_client_buf_free_contiguous(dir, ac);
755 return -EINVAL;
756}
757
758static int32_t q6asm_mmapcallback(struct apr_client_data *data, void *priv)
759{
760 uint32_t token;
761 uint32_t *payload = data->payload;
762
763 if (data->opcode == RESET_EVENTS) {
764 pr_debug("%s: Reset event is received: %d %d apr[%p]\n",
765 __func__,
766 data->reset_event,
767 data->reset_proc,
768 this_mmap.apr);
769 apr_reset(this_mmap.apr);
770 this_mmap.apr = NULL;
771 atomic_set(&this_mmap.cmd_state, 0);
772 return 0;
773 }
774
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700775 pr_debug("%s:ptr0[0x%x]ptr1[0x%x]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n",
776 __func__, payload[0], payload[1], data->opcode, data->token,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700777 data->payload_size, data->src_port, data->dest_port);
778
779 if (data->opcode == APR_BASIC_RSP_RESULT) {
780 token = data->token;
781 switch (payload[0]) {
782 case ASM_SESSION_CMD_MEMORY_MAP:
783 case ASM_SESSION_CMD_MEMORY_UNMAP:
784 case ASM_SESSION_CMD_MEMORY_MAP_REGIONS:
785 case ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS:
786 pr_debug("%s:command[0x%x]success [0x%x]\n",
787 __func__, payload[0], payload[1]);
788 if (atomic_read(&this_mmap.cmd_state)) {
789 atomic_set(&this_mmap.cmd_state, 0);
790 wake_up(&this_mmap.cmd_wait);
791 }
792 break;
793 default:
794 pr_debug("%s:command[0x%x] not expecting rsp\n",
795 __func__, payload[0]);
796 break;
797 }
798 }
799 return 0;
800}
801
Jay Wangcd1d37d2012-10-03 16:17:18 -0700802static int32_t is_no_wait_cmd_rsp(uint32_t opcode, uint32_t *cmd_type)
803{
804 if (opcode == APR_BASIC_RSP_RESULT) {
805 if (cmd_type != NULL) {
806 switch (cmd_type[0]) {
807 case ASM_SESSION_CMD_RUN:
808 case ASM_SESSION_CMD_PAUSE:
809 case ASM_DATA_CMD_EOS:
810 return 1;
811 default:
812 break;
813 }
814 } else
815 pr_err("%s: null pointer!", __func__);
816 } else if (opcode == ASM_DATA_CMDRSP_EOS)
817 return 1;
818
819 return 0;
820}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700821
822static int32_t q6asm_callback(struct apr_client_data *data, void *priv)
823{
824 int i = 0;
825 struct audio_client *ac = (struct audio_client *)priv;
826 uint32_t token;
827 unsigned long dsp_flags;
828 uint32_t *payload;
Jay Wang0668d1062012-07-11 18:53:21 -0700829 uint32_t wakeup_flag = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700830
831
832 if ((ac == NULL) || (data == NULL)) {
833 pr_err("ac or priv NULL\n");
834 return -EINVAL;
835 }
836 if (ac->session <= 0 || ac->session > 8) {
837 pr_err("%s:Session ID is invalid, session = %d\n", __func__,
838 ac->session);
839 return -EINVAL;
840 }
Jay Wangcd1d37d2012-10-03 16:17:18 -0700841
842 payload = data->payload;
843 if ((atomic_read(&ac->nowait_cmd_cnt) > 0) &&
844 is_no_wait_cmd_rsp(data->opcode, payload)) {
Jay Wang0668d1062012-07-11 18:53:21 -0700845 pr_debug("%s: nowait_cmd_cnt %d\n",
846 __func__,
847 atomic_read(&ac->nowait_cmd_cnt));
848 atomic_dec(&ac->nowait_cmd_cnt);
849 wakeup_flag = 0;
850 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700851
852 if (data->opcode == RESET_EVENTS) {
853 pr_debug("q6asm_callback: Reset event is received: %d %d apr[%p]\n",
854 data->reset_event, data->reset_proc, ac->apr);
Laxminath Kasam692c6542012-02-21 11:17:47 +0530855 if (ac->cb)
856 ac->cb(data->opcode, data->token,
857 (uint32_t *)data->payload, ac->priv);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700858 apr_reset(ac->apr);
859 return 0;
860 }
861
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700862 pr_debug("%s: session[%d]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n",
863 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700864 ac->session, data->opcode,
865 data->token, data->payload_size, data->src_port,
866 data->dest_port);
867
868 if (data->opcode == APR_BASIC_RSP_RESULT) {
869 token = data->token;
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700870 pr_debug("%s payload[0]:%x", __func__, payload[0]);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700871 switch (payload[0]) {
872 case ASM_STREAM_CMD_SET_PP_PARAMS:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700873 if (rtac_make_asm_callback(ac->session, payload,
874 data->payload_size))
875 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700876 case ASM_SESSION_CMD_PAUSE:
877 case ASM_DATA_CMD_EOS:
878 case ASM_STREAM_CMD_CLOSE:
879 case ASM_STREAM_CMD_FLUSH:
880 case ASM_SESSION_CMD_RUN:
881 case ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS:
882 case ASM_STREAM_CMD_FLUSH_READBUFS:
883 pr_debug("%s:Payload = [0x%x]\n", __func__, payload[0]);
884 if (token != ac->session) {
885 pr_err("%s:Invalid session[%d] rxed expected[%d]",
886 __func__, token, ac->session);
887 return -EINVAL;
888 }
889 case ASM_STREAM_CMD_OPEN_READ:
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700890 case ASM_STREAM_CMD_OPEN_READ_V2_1:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700891 case ASM_STREAM_CMD_OPEN_WRITE:
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700892 case ASM_STREAM_CMD_OPEN_WRITE_V2_1:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700893 case ASM_STREAM_CMD_OPEN_READWRITE:
894 case ASM_DATA_CMD_MEDIA_FORMAT_UPDATE:
895 case ASM_STREAM_CMD_SET_ENCDEC_PARAM:
Santosh Mardi23321202012-03-22 04:33:25 +0530896 case ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED:
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -0700897 case ASM_STREAM_CMD_OPEN_READ_COMPRESSED:
Jay Wang0668d1062012-07-11 18:53:21 -0700898 if (atomic_read(&ac->cmd_state) && wakeup_flag) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700899 atomic_set(&ac->cmd_state, 0);
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700900 if (payload[1] == ADSP_EUNSUPPORTED) {
901 pr_debug("paload[1]:%d unsupported",
902 payload[1]);
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530903 atomic_set(&ac->cmd_response, 1);
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -0700904 }
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +0530905 else
906 atomic_set(&ac->cmd_response, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700907 wake_up(&ac->cmd_wait);
908 }
909 if (ac->cb)
910 ac->cb(data->opcode, data->token,
911 (uint32_t *)data->payload, ac->priv);
912 break;
913 default:
914 pr_debug("%s:command[0x%x] not expecting rsp\n",
915 __func__, payload[0]);
916 break;
917 }
918 return 0;
919 }
920
921 switch (data->opcode) {
922 case ASM_DATA_EVENT_WRITE_DONE:{
923 struct audio_port_data *port = &ac->port[IN];
924 pr_debug("%s: Rxed opcode[0x%x] status[0x%x] token[%d]",
925 __func__, payload[0], payload[1],
926 data->token);
927 if (ac->io_mode == SYNC_IO_MODE) {
928 if (port->buf == NULL) {
929 pr_err("%s: Unexpected Write Done\n",
930 __func__);
931 return -EINVAL;
932 }
933 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
934 if (port->buf[data->token].phys !=
935 payload[0]) {
936 pr_err("Buf expected[%p]rxed[%p]\n",\
937 (void *)port->buf[data->token].phys,\
938 (void *)payload[0]);
939 spin_unlock_irqrestore(&port->dsp_lock,
940 dsp_flags);
941 return -EINVAL;
942 }
943 token = data->token;
944 port->buf[token].used = 1;
945 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
Rajesha Kini3498c932011-07-19 19:58:27 +0530946#ifdef CONFIG_DEBUG_FS
947 if (out_enable_flag) {
948 /* For first Write done log the time and reset
949 out_cold_index*/
950 if (out_cold_index != 1) {
951 do_gettimeofday(&out_cold_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700952 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",
953 out_cold_tv.tv_sec,
Rajesha Kini3498c932011-07-19 19:58:27 +0530954 out_cold_tv.tv_usec);
955 out_cold_index = 1;
956 }
957 pr_debug("out_enable_flag %ld",\
958 out_enable_flag);
959 }
960#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700961 for (i = 0; i < port->max_buf_cnt; i++)
962 pr_debug("%d ", port->buf[i].used);
963
964 }
965 break;
966 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700967 case ASM_STREAM_CMDRSP_GET_PP_PARAMS:
968 rtac_make_asm_callback(ac->session, payload,
969 data->payload_size);
970 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700971 case ASM_DATA_EVENT_READ_DONE:{
972
973 struct audio_port_data *port = &ac->port[OUT];
Rajesha Kini3498c932011-07-19 19:58:27 +0530974#ifdef CONFIG_DEBUG_FS
975 if (in_enable_flag) {
976 /* when in_cont_index == 7, DSP would be
977 * writing into the 8th 512 byte buffer and this
978 * timestamp is tapped here.Once done it then writes
979 * to 9th 512 byte buffer.These two buffers(8th, 9th)
980 * reach the test application in 5th iteration and that
981 * timestamp is tapped at user level. The difference
982 * of these two timestamps gives us the time between
983 * the time at which dsp started filling the sample
984 * required and when it reached the test application.
985 * Hence continuous input latency
986 */
987 if (in_cont_index == 7) {
988 do_gettimeofday(&in_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -0700989 pr_err("In_CONT:previous read buffer done at %ld sec %ld microsec\n",
Sriranjan Srikantam74753532011-10-03 14:48:37 -0700990 in_cont_tv.tv_sec, in_cont_tv.tv_usec);
Rajesha Kini3498c932011-07-19 19:58:27 +0530991 }
992 }
993#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700994 pr_debug("%s:R-D: status=%d buff_add=%x act_size=%d offset=%d\n",
995 __func__, payload[READDONE_IDX_STATUS],
996 payload[READDONE_IDX_BUFFER],
997 payload[READDONE_IDX_SIZE],
998 payload[READDONE_IDX_OFFSET]);
999 pr_debug("%s:R-D:msw_ts=%d lsw_ts=%d flags=%d id=%d num=%d\n",
1000 __func__, payload[READDONE_IDX_MSW_TS],
1001 payload[READDONE_IDX_LSW_TS],
1002 payload[READDONE_IDX_FLAGS],
1003 payload[READDONE_IDX_ID],
1004 payload[READDONE_IDX_NUMFRAMES]);
Rajesha Kini3498c932011-07-19 19:58:27 +05301005#ifdef CONFIG_DEBUG_FS
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001006 if (in_enable_flag)
Rajesha Kini3498c932011-07-19 19:58:27 +05301007 in_cont_index++;
Rajesha Kini3498c932011-07-19 19:58:27 +05301008#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001009 if (ac->io_mode == SYNC_IO_MODE) {
1010 if (port->buf == NULL) {
1011 pr_err("%s: Unexpected Write Done\n", __func__);
1012 return -EINVAL;
1013 }
1014 spin_lock_irqsave(&port->dsp_lock, dsp_flags);
1015 token = data->token;
1016 port->buf[token].used = 0;
1017 if (port->buf[token].phys !=
1018 payload[READDONE_IDX_BUFFER]) {
1019 pr_err("Buf expected[%p]rxed[%p]\n",\
1020 (void *)port->buf[token].phys,\
1021 (void *)payload[READDONE_IDX_BUFFER]);
1022 spin_unlock_irqrestore(&port->dsp_lock,
1023 dsp_flags);
1024 break;
1025 }
1026 port->buf[token].actual_size =
1027 payload[READDONE_IDX_SIZE];
1028 spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
1029 }
1030 break;
1031 }
1032 case ASM_DATA_EVENT_EOS:
1033 case ASM_DATA_CMDRSP_EOS:
1034 pr_debug("%s:EOS ACK received: rxed opcode[0x%x]\n",
1035 __func__, data->opcode);
1036 break;
1037 case ASM_STREAM_CMDRSP_GET_ENCDEC_PARAM:
1038 break;
1039 case ASM_SESSION_EVENT_TX_OVERFLOW:
1040 pr_err("ASM_SESSION_EVENT_TX_OVERFLOW\n");
1041 break;
1042 case ASM_SESSION_CMDRSP_GET_SESSION_TIME:
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001043 pr_debug("%s: ASM_SESSION_CMDRSP_GET_SESSION_TIME, payload[0] = %d, payload[1] = %d, payload[2] = %d\n",
1044 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001045 payload[0], payload[1], payload[2]);
1046 ac->time_stamp = (uint64_t)(((uint64_t)payload[1] << 32) |
1047 payload[2]);
1048 if (atomic_read(&ac->time_flag)) {
1049 atomic_set(&ac->time_flag, 0);
1050 wake_up(&ac->time_wait);
1051 }
1052 break;
1053 case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY:
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301054 case ASM_DATA_EVENT_ENC_SR_CM_NOTIFY:
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001055 pr_debug("%s: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, payload[0] = %d, payload[1] = %d, payload[2] = %d, payload[3] = %d\n",
1056 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001057 payload[0], payload[1], payload[2],
1058 payload[3]);
1059 break;
1060 }
1061 if (ac->cb)
1062 ac->cb(data->opcode, data->token,
1063 data->payload, ac->priv);
1064
1065 return 0;
1066}
1067
1068void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac, uint32_t *size,
1069 uint32_t *index)
1070{
1071 void *data;
1072 unsigned char idx;
1073 struct audio_port_data *port;
1074
1075 if (!ac || ((dir != IN) && (dir != OUT)))
1076 return NULL;
1077
1078 if (ac->io_mode == SYNC_IO_MODE) {
1079 port = &ac->port[dir];
1080
1081 mutex_lock(&port->lock);
1082 idx = port->cpu_buf;
1083 if (port->buf == NULL) {
1084 pr_debug("%s:Buffer pointer null\n", __func__);
Jayasena Sangaraboina466e6b92012-01-17 21:10:55 -08001085 mutex_unlock(&port->lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001086 return NULL;
1087 }
1088 /* dir 0: used = 0 means buf in use
1089 dir 1: used = 1 means buf in use */
1090 if (port->buf[idx].used == dir) {
1091 /* To make it more robust, we could loop and get the
1092 next avail buf, its risky though */
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001093 pr_debug("%s:Next buf idx[0x%x] not available,dir[%d]\n",
1094 __func__, idx, dir);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001095 mutex_unlock(&port->lock);
1096 return NULL;
1097 }
1098 *size = port->buf[idx].actual_size;
1099 *index = port->cpu_buf;
1100 data = port->buf[idx].data;
1101 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1102 __func__,
1103 ac->session,
1104 port->cpu_buf,
1105 data, *size);
1106 /* By default increase the cpu_buf cnt
1107 user accesses this function,increase cpu
1108 buf(to avoid another api)*/
1109 port->buf[idx].used = dir;
1110 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1111 mutex_unlock(&port->lock);
1112 return data;
1113 }
1114 return NULL;
1115}
1116
Jay Wang9cf59a02011-08-10 16:58:40 -07001117void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
1118 uint32_t *size, uint32_t *index)
1119{
1120 void *data;
1121 unsigned char idx;
1122 struct audio_port_data *port;
1123
1124 if (!ac || ((dir != IN) && (dir != OUT)))
1125 return NULL;
1126
1127 port = &ac->port[dir];
1128
1129 idx = port->cpu_buf;
1130 if (port->buf == NULL) {
1131 pr_debug("%s:Buffer pointer null\n", __func__);
1132 return NULL;
1133 }
1134 /*
1135 * dir 0: used = 0 means buf in use
1136 * dir 1: used = 1 means buf in use
1137 */
1138 if (port->buf[idx].used == dir) {
1139 /*
1140 * To make it more robust, we could loop and get the
1141 * next avail buf, its risky though
1142 */
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001143 pr_debug("%s:Next buf idx[0x%x] not available, dir[%d]\n",
1144 __func__, idx, dir);
Jay Wang9cf59a02011-08-10 16:58:40 -07001145 return NULL;
1146 }
1147 *size = port->buf[idx].actual_size;
1148 *index = port->cpu_buf;
1149 data = port->buf[idx].data;
1150 pr_debug("%s:session[%d]index[%d] data[%p]size[%d]\n",
1151 __func__, ac->session, port->cpu_buf,
1152 data, *size);
1153 /*
1154 * By default increase the cpu_buf cnt
1155 * user accesses this function,increase cpu
1156 * buf(to avoid another api)
1157 */
1158 port->buf[idx].used = dir;
1159 port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
1160 return data;
1161}
1162
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001163int q6asm_is_dsp_buf_avail(int dir, struct audio_client *ac)
1164{
1165 int ret = -1;
1166 struct audio_port_data *port;
1167 uint32_t idx;
1168
1169 if (!ac || (dir != OUT))
1170 return ret;
1171
1172 if (ac->io_mode == SYNC_IO_MODE) {
1173 port = &ac->port[dir];
1174
1175 mutex_lock(&port->lock);
1176 idx = port->dsp_buf;
1177
1178 if (port->buf[idx].used == (dir ^ 1)) {
1179 /* To make it more robust, we could loop and get the
1180 next avail buf, its risky though */
1181 pr_err("Next buf idx[0x%x] not available, dir[%d]\n",
1182 idx, dir);
1183 mutex_unlock(&port->lock);
1184 return ret;
1185 }
1186 pr_debug("%s: session[%d]dsp_buf=%d cpu_buf=%d\n", __func__,
1187 ac->session, port->dsp_buf, port->cpu_buf);
1188 ret = ((port->dsp_buf != port->cpu_buf) ? 0 : -1);
1189 mutex_unlock(&port->lock);
1190 }
1191 return ret;
1192}
1193
1194static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
1195 uint32_t pkt_size, uint32_t cmd_flg)
1196{
1197 pr_debug("%s:session=%d pkt size=%d cmd_flg=%d\n", __func__, pkt_size,
1198 cmd_flg, ac->session);
1199 mutex_lock(&ac->cmd_lock);
1200 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1201 APR_HDR_LEN(sizeof(struct apr_hdr)),\
1202 APR_PKT_VER);
1203 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
1204 hdr->src_domain = APR_DOMAIN_APPS;
1205 hdr->dest_svc = APR_SVC_ASM;
1206 hdr->dest_domain = APR_DOMAIN_ADSP;
1207 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
1208 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
1209 if (cmd_flg) {
1210 hdr->token = ac->session;
1211 atomic_set(&ac->cmd_state, 1);
1212 }
1213 hdr->pkt_size = pkt_size;
1214 mutex_unlock(&ac->cmd_lock);
1215 return;
1216}
1217
1218static void q6asm_add_mmaphdr(struct apr_hdr *hdr, uint32_t pkt_size,
1219 uint32_t cmd_flg)
1220{
1221 pr_debug("%s:pkt size=%d cmd_flg=%d\n", __func__, pkt_size, cmd_flg);
1222 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
1223 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1224 hdr->src_port = 0;
1225 hdr->dest_port = 0;
1226 if (cmd_flg) {
1227 hdr->token = 0;
1228 atomic_set(&this_mmap.cmd_state, 1);
1229 }
1230 hdr->pkt_size = pkt_size;
1231 return;
1232}
1233
1234int q6asm_open_read(struct audio_client *ac,
1235 uint32_t format)
1236{
1237 int rc = 0x00;
1238 struct asm_stream_cmd_open_read open;
Rajesha Kini3498c932011-07-19 19:58:27 +05301239#ifdef CONFIG_DEBUG_FS
1240 in_cont_index = 0;
1241#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001242 if ((ac == NULL) || (ac->apr == NULL)) {
1243 pr_err("%s: APR handle NULL\n", __func__);
1244 return -EINVAL;
1245 }
1246 pr_debug("%s:session[%d]", __func__, ac->session);
1247
1248 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1249 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ;
1250 /* Stream prio : High, provide meta info with encoded frames */
1251 open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1252
1253 open.pre_proc_top = get_asm_topology();
1254 if (open.pre_proc_top == 0)
1255 open.pre_proc_top = DEFAULT_POPP_TOPOLOGY;
1256
1257 switch (format) {
1258 case FORMAT_LINEAR_PCM:
1259 open.uMode = STREAM_PRIORITY_HIGH;
1260 open.format = LINEAR_PCM;
1261 break;
Mingming Yin647e9ea2012-03-17 19:56:10 -07001262 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1263 open.uMode = STREAM_PRIORITY_HIGH;
1264 open.format = MULTI_CHANNEL_PCM;
1265 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001266 case FORMAT_MPEG4_AAC:
1267 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1268 open.format = MPEG4_AAC;
1269 break;
1270 case FORMAT_V13K:
1271 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1272 open.format = V13K_FS;
1273 break;
1274 case FORMAT_EVRC:
1275 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1276 open.format = EVRC_FS;
1277 break;
1278 case FORMAT_AMRNB:
1279 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1280 open.format = AMRNB_FS;
1281 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301282 case FORMAT_AMRWB:
1283 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1284 open.format = AMRWB_FS;
1285 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001286 default:
1287 pr_err("Invalid format[%d]\n", format);
1288 goto fail_cmd;
1289 }
1290 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1291 if (rc < 0) {
1292 pr_err("open failed op[0x%x]rc[%d]\n", \
1293 open.hdr.opcode, rc);
1294 goto fail_cmd;
1295 }
1296 rc = wait_event_timeout(ac->cmd_wait,
1297 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1298 if (!rc) {
1299 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1300 rc);
1301 goto fail_cmd;
1302 }
1303 return 0;
1304fail_cmd:
1305 return -EINVAL;
1306}
1307
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -07001308int q6asm_open_read_v2_1(struct audio_client *ac,
1309 uint32_t format)
1310{
1311 int rc = 0x00;
1312 struct asm_stream_cmd_open_read_v2_1 open;
1313#ifdef CONFIG_DEBUG_FS
1314 in_cont_index = 0;
1315#endif
1316 if ((ac == NULL) || (ac->apr == NULL)) {
1317 pr_err("%s: APR handle NULL\n", __func__);
1318 return -EINVAL;
1319 }
1320 pr_debug("%s:session[%d]", __func__, ac->session);
1321
1322 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1323 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_V2_1;
1324 open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1325 open.pre_proc_top = get_asm_topology();
1326 if (open.pre_proc_top == 0)
1327 open.pre_proc_top = DEFAULT_POPP_TOPOLOGY;
1328
1329 switch (format) {
1330 case FORMAT_LINEAR_PCM:
1331 open.uMode = STREAM_PRIORITY_HIGH;
1332 open.format = LINEAR_PCM;
1333 break;
1334 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1335 open.uMode = STREAM_PRIORITY_HIGH;
1336 open.format = MULTI_CHANNEL_PCM;
1337 break;
1338 case FORMAT_MPEG4_AAC:
1339 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1340 open.format = MPEG4_AAC;
1341 break;
1342 case FORMAT_V13K:
1343 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1344 open.format = V13K_FS;
1345 break;
1346 case FORMAT_EVRC:
1347 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1348 open.format = EVRC_FS;
1349 break;
1350 case FORMAT_AMRNB:
1351 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1352 open.format = AMRNB_FS;
1353 break;
1354 case FORMAT_AMRWB:
1355 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
1356 open.format = AMRWB_FS;
1357 break;
1358 default:
1359 pr_err("Invalid format[%d]\n", format);
1360 goto fail_cmd;
1361 }
1362 open.uMode = ASM_OPEN_READ_PERF_MODE_BIT;
1363 open.bits_per_sample = PCM_BITS_PER_SAMPLE;
1364 open.reserved = 0;
1365 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1366 if (rc < 0) {
1367 pr_err("open failed op[0x%x]rc[%d]\n", \
1368 open.hdr.opcode, rc);
1369 goto fail_cmd;
1370 }
1371 rc = wait_event_timeout(ac->cmd_wait,
1372 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1373 if (!rc) {
1374 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1375 rc);
1376 goto fail_cmd;
1377 }
1378 return 0;
1379fail_cmd:
1380 return -EINVAL;
1381}
1382
1383
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07001384int q6asm_open_read_compressed(struct audio_client *ac,
1385 uint32_t frames_per_buffer, uint32_t meta_data_mode)
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -07001386{
1387 int rc = 0x00;
1388 struct asm_stream_cmd_open_read_compressed open;
1389#ifdef CONFIG_DEBUG_FS
1390 in_cont_index = 0;
1391#endif
1392 if ((ac == NULL) || (ac->apr == NULL)) {
1393 pr_err("%s: APR handle NULL\n", __func__);
1394 return -EINVAL;
1395 }
1396 pr_debug("%s:session[%d]", __func__, ac->session);
1397
1398 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1399 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_COMPRESSED;
1400 /* hardcoded as following*/
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07001401 open.frame_per_buf = frames_per_buffer;
1402 open.uMode = meta_data_mode;
Subhash Chandra Bose Naripeddy8f846892012-06-12 11:29:18 -07001403
1404 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1405 if (rc < 0) {
1406 pr_err("open failed op[0x%x]rc[%d]\n", open.hdr.opcode, rc);
1407 goto fail_cmd;
1408 }
1409 rc = wait_event_timeout(ac->cmd_wait,
1410 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1411 if (!rc) {
1412 pr_err("%s: timeout. waited for OPEN_READ_COMPRESSED rc[%d]\n",
1413 __func__, rc);
1414 goto fail_cmd;
1415 }
1416 return 0;
1417fail_cmd:
1418 return -EINVAL;
1419}
1420
Santosh Mardi23321202012-03-22 04:33:25 +05301421int q6asm_open_write_compressed(struct audio_client *ac, uint32_t format)
1422{
1423 int rc = 0x00;
1424 struct asm_stream_cmd_open_write_compressed open;
1425
1426 if ((ac == NULL) || (ac->apr == NULL)) {
1427 pr_err("%s: APR handle NULL\n", __func__);
1428 return -EINVAL;
1429 }
1430 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1431 format);
1432
1433 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1434
1435 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED;
1436
1437 switch (format) {
1438 case FORMAT_AC3:
1439 open.format = AC3_DECODER;
1440 break;
1441 case FORMAT_EAC3:
1442 open.format = EAC3_DECODER;
1443 break;
1444 case FORMAT_MP3:
1445 open.format = MP3;
1446 break;
1447 case FORMAT_DTS:
1448 open.format = DTS;
1449 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05301450 case FORMAT_DTS_LBR:
1451 open.format = DTS_LBR;
1452 break;
Santosh Mardi23321202012-03-22 04:33:25 +05301453 case FORMAT_AAC:
1454 open.format = MPEG4_AAC;
1455 break;
1456 case FORMAT_ATRAC:
1457 open.format = ATRAC;
1458 break;
1459 case FORMAT_WMA_V10PRO:
1460 open.format = WMA_V10PRO;
1461 break;
1462 case FORMAT_MAT:
1463 open.format = MAT;
1464 break;
1465 default:
1466 pr_err("%s: Invalid format[%d]\n", __func__, format);
1467 goto fail_cmd;
1468 }
1469 /*Below flag indicates the DSP that Compressed audio input
1470 stream is not IEC 61937 or IEC 60958 packetizied*/
1471 open.flags = 0x00000000;
1472 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1473 if (rc < 0) {
1474 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1475 __func__, open.hdr.opcode, rc);
1476 goto fail_cmd;
1477 }
1478 rc = wait_event_timeout(ac->cmd_wait,
1479 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1480 if (!rc) {
1481 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1482 rc);
1483 goto fail_cmd;
1484 }
1485 return 0;
1486fail_cmd:
1487 return -EINVAL;
1488}
1489
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001490int q6asm_open_write(struct audio_client *ac, uint32_t format)
1491{
1492 int rc = 0x00;
1493 struct asm_stream_cmd_open_write open;
1494
1495 if ((ac == NULL) || (ac->apr == NULL)) {
1496 pr_err("%s: APR handle NULL\n", __func__);
1497 return -EINVAL;
1498 }
1499 pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
1500 format);
1501
1502 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1503
Jayasena Sangaraboina99bf09c2012-07-17 12:03:08 -07001504 if (ac->perf_mode) {
1505 pr_debug("%s In Performance/lowlatency mode", __func__);
1506 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_V2_1;
1507 open.uMode = ASM_OPEN_WRITE_PERF_MODE_BIT;
1508 /* source endpoint : matrix */
1509 open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1510 open.stream_handle = PCM_BITS_PER_SAMPLE;
1511 } else {
1512 open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE;
1513 open.uMode = STREAM_PRIORITY_HIGH;
1514 /* source endpoint : matrix */
1515 open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
1516 open.stream_handle = 0x00;
1517 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001518 open.post_proc_top = get_asm_topology();
1519 if (open.post_proc_top == 0)
1520 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1521
1522 switch (format) {
1523 case FORMAT_LINEAR_PCM:
1524 open.format = LINEAR_PCM;
1525 break;
Kiran Kandi5e809b02012-01-31 00:24:33 -08001526 case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
1527 open.format = MULTI_CHANNEL_PCM;
1528 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001529 case FORMAT_MPEG4_AAC:
1530 open.format = MPEG4_AAC;
1531 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001532 case FORMAT_MPEG4_MULTI_AAC:
1533 open.format = MPEG4_MULTI_AAC;
1534 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001535 case FORMAT_WMA_V9:
1536 open.format = WMA_V9;
1537 break;
1538 case FORMAT_WMA_V10PRO:
1539 open.format = WMA_V10PRO;
1540 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05301541 case FORMAT_MP3:
1542 open.format = MP3;
1543 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05301544 case FORMAT_DTS:
1545 open.format = DTS;
1546 break;
1547 case FORMAT_DTS_LBR:
1548 open.format = DTS_LBR;
1549 break;
Ajit Khare43fd8832012-08-07 13:19:44 -07001550 case FORMAT_AMRWB:
1551 open.format = AMRWB_FS;
1552 pr_debug("q6asm_open_write FORMAT_AMRWB");
1553 break;
1554 case FORMAT_AMR_WB_PLUS:
1555 open.format = AMR_WB_PLUS;
1556 pr_debug("q6asm_open_write FORMAT_AMR_WB_PLUS");
1557 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001558 default:
1559 pr_err("%s: Invalid format[%d]\n", __func__, format);
1560 goto fail_cmd;
1561 }
1562 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1563 if (rc < 0) {
1564 pr_err("%s: open failed op[0x%x]rc[%d]\n", \
1565 __func__, open.hdr.opcode, rc);
1566 goto fail_cmd;
1567 }
1568 rc = wait_event_timeout(ac->cmd_wait,
1569 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1570 if (!rc) {
1571 pr_err("%s: timeout. waited for OPEN_WRITE rc[%d]\n", __func__,
1572 rc);
1573 goto fail_cmd;
1574 }
Srikanth Uyyalaa50b51d2012-07-02 16:02:24 +05301575 if (atomic_read(&ac->cmd_response)) {
1576 pr_err("%s: format = %x not supported\n", __func__, format);
1577 goto fail_cmd;
1578 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001579 return 0;
1580fail_cmd:
1581 return -EINVAL;
1582}
1583
1584int q6asm_open_read_write(struct audio_client *ac,
1585 uint32_t rd_format,
1586 uint32_t wr_format)
1587{
1588 int rc = 0x00;
1589 struct asm_stream_cmd_open_read_write open;
1590
1591 if ((ac == NULL) || (ac->apr == NULL)) {
1592 pr_err("APR handle NULL\n");
1593 return -EINVAL;
1594 }
1595 pr_debug("%s: session[%d]", __func__, ac->session);
1596 pr_debug("wr_format[0x%x]rd_format[0x%x]",
1597 wr_format, rd_format);
1598
1599 q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
1600 open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE;
1601
Deepa Madiregama55cbf782011-09-10 05:44:39 +05301602 open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_NORMAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001603 /* source endpoint : matrix */
1604 open.post_proc_top = get_asm_topology();
1605 if (open.post_proc_top == 0)
1606 open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
1607
1608 switch (wr_format) {
1609 case FORMAT_LINEAR_PCM:
1610 open.write_format = LINEAR_PCM;
1611 break;
1612 case FORMAT_MPEG4_AAC:
1613 open.write_format = MPEG4_AAC;
1614 break;
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07001615 case FORMAT_MPEG4_MULTI_AAC:
1616 open.write_format = MPEG4_MULTI_AAC;
1617 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001618 case FORMAT_WMA_V9:
1619 open.write_format = WMA_V9;
1620 break;
1621 case FORMAT_WMA_V10PRO:
1622 open.write_format = WMA_V10PRO;
1623 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301624 case FORMAT_AMRNB:
1625 open.write_format = AMRNB_FS;
1626 break;
1627 case FORMAT_AMRWB:
1628 open.write_format = AMRWB_FS;
1629 break;
1630 case FORMAT_V13K:
1631 open.write_format = V13K_FS;
1632 break;
1633 case FORMAT_EVRC:
1634 open.write_format = EVRC_FS;
1635 break;
1636 case FORMAT_EVRCB:
1637 open.write_format = EVRCB_FS;
1638 break;
1639 case FORMAT_EVRCWB:
1640 open.write_format = EVRCWB_FS;
1641 break;
1642 case FORMAT_MP3:
1643 open.write_format = MP3;
1644 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001645 default:
1646 pr_err("Invalid format[%d]\n", wr_format);
1647 goto fail_cmd;
1648 }
1649
1650 switch (rd_format) {
1651 case FORMAT_LINEAR_PCM:
1652 open.read_format = LINEAR_PCM;
1653 break;
1654 case FORMAT_MPEG4_AAC:
1655 open.read_format = MPEG4_AAC;
1656 break;
1657 case FORMAT_V13K:
1658 open.read_format = V13K_FS;
1659 break;
1660 case FORMAT_EVRC:
1661 open.read_format = EVRC_FS;
1662 break;
1663 case FORMAT_AMRNB:
1664 open.read_format = AMRNB_FS;
1665 break;
Alex Wong2caeecc2011-10-28 10:52:15 +05301666 case FORMAT_AMRWB:
1667 open.read_format = AMRWB_FS;
1668 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001669 default:
1670 pr_err("Invalid format[%d]\n", rd_format);
1671 goto fail_cmd;
1672 }
1673 pr_debug("%s:rdformat[0x%x]wrformat[0x%x]\n", __func__,
1674 open.read_format, open.write_format);
1675
1676 rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
1677 if (rc < 0) {
1678 pr_err("open failed op[0x%x]rc[%d]\n", \
1679 open.hdr.opcode, rc);
1680 goto fail_cmd;
1681 }
1682 rc = wait_event_timeout(ac->cmd_wait,
1683 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1684 if (!rc) {
1685 pr_err("timeout. waited for OPEN_WRITE rc[%d]\n", rc);
1686 goto fail_cmd;
1687 }
1688 return 0;
1689fail_cmd:
1690 return -EINVAL;
1691}
1692
1693int q6asm_run(struct audio_client *ac, uint32_t flags,
1694 uint32_t msw_ts, uint32_t lsw_ts)
1695{
1696 struct asm_stream_cmd_run run;
1697 int rc;
1698 if (!ac || ac->apr == NULL) {
1699 pr_err("APR handle NULL\n");
1700 return -EINVAL;
1701 }
1702 pr_debug("%s session[%d]", __func__, ac->session);
1703 q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
1704
1705 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1706 run.flags = flags;
1707 run.msw_ts = msw_ts;
1708 run.lsw_ts = lsw_ts;
Rajesha Kini3498c932011-07-19 19:58:27 +05301709#ifdef CONFIG_DEBUG_FS
1710 if (out_enable_flag) {
1711 do_gettimeofday(&out_cold_tv);
1712 pr_debug("COLD: apr_send_pkt at %ld sec %ld microsec\n",\
1713 out_cold_tv.tv_sec, out_cold_tv.tv_usec);
1714 }
1715#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001716 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1717 if (rc < 0) {
1718 pr_err("Commmand run failed[%d]", rc);
1719 goto fail_cmd;
1720 }
1721
1722 rc = wait_event_timeout(ac->cmd_wait,
1723 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1724 if (!rc) {
1725 pr_err("timeout. waited for run success rc[%d]", rc);
1726 goto fail_cmd;
1727 }
1728
1729 return 0;
1730fail_cmd:
1731 return -EINVAL;
1732}
1733
1734int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
1735 uint32_t msw_ts, uint32_t lsw_ts)
1736{
1737 struct asm_stream_cmd_run run;
1738 int rc;
1739 if (!ac || ac->apr == NULL) {
1740 pr_err("%s:APR handle NULL\n", __func__);
1741 return -EINVAL;
1742 }
1743 pr_debug("session[%d]", ac->session);
1744 q6asm_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE);
1745
1746 run.hdr.opcode = ASM_SESSION_CMD_RUN;
1747 run.flags = flags;
1748 run.msw_ts = msw_ts;
1749 run.lsw_ts = lsw_ts;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001750 rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
1751 if (rc < 0) {
1752 pr_err("%s:Commmand run failed[%d]", __func__, rc);
1753 return -EINVAL;
1754 }
Jay Wang0668d1062012-07-11 18:53:21 -07001755 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001756 return 0;
1757}
1758
1759
1760int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
1761 uint32_t frames_per_buf,
1762 uint32_t sample_rate, uint32_t channels,
1763 uint32_t bit_rate, uint32_t mode, uint32_t format)
1764{
1765 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1766 int rc = 0;
1767
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001768 pr_debug("%s:session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d] format[%d]",
1769 __func__, ac->session, frames_per_buf,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001770 sample_rate, channels, bit_rate, mode, format);
1771
1772 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1773
1774 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1775 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1776 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1777 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
1778 enc_cfg.enc_blk.format_id = MPEG4_AAC;
1779 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_aac_read_cfg);
1780 enc_cfg.enc_blk.cfg.aac.bitrate = bit_rate;
1781 enc_cfg.enc_blk.cfg.aac.enc_mode = mode;
1782 enc_cfg.enc_blk.cfg.aac.format = format;
1783 enc_cfg.enc_blk.cfg.aac.ch_cfg = channels;
1784 enc_cfg.enc_blk.cfg.aac.sample_rate = sample_rate;
1785
1786 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1787 if (rc < 0) {
1788 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
1789 rc = -EINVAL;
1790 goto fail_cmd;
1791 }
1792 rc = wait_event_timeout(ac->cmd_wait,
1793 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1794 if (!rc) {
1795 pr_err("timeout. waited for FORMAT_UPDATE\n");
1796 goto fail_cmd;
1797 }
1798 return 0;
1799fail_cmd:
1800 return -EINVAL;
1801}
1802
1803int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
1804 uint32_t rate, uint32_t channels)
1805{
1806 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1807
1808 int rc = 0;
1809
1810 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1811 ac->session, rate, channels);
1812
1813 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1814
1815 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1816 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1817 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1818 enc_cfg.enc_blk.frames_per_buf = 1;
1819 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1820 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1821 enc_cfg.enc_blk.cfg.pcm.ch_cfg = channels;
1822 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1823 enc_cfg.enc_blk.cfg.pcm.sample_rate = rate;
1824 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1825 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1826
1827 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1828 if (rc < 0) {
1829 pr_err("Comamnd open failed\n");
1830 rc = -EINVAL;
1831 goto fail_cmd;
1832 }
1833 rc = wait_event_timeout(ac->cmd_wait,
1834 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1835 if (!rc) {
1836 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1837 goto fail_cmd;
1838 }
1839 return 0;
1840fail_cmd:
1841 return -EINVAL;
1842}
1843
Harmandeep Singheaf59b42012-06-05 21:46:02 -07001844int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac,
1845 uint32_t rate, uint32_t channels)
1846{
1847 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1848
1849 int rc = 0;
1850
1851 pr_debug("%s: Session %d, rate = %d, channels = %d, setting the rate and channels to 0 for native\n",
1852 __func__, ac->session, rate, channels);
1853
1854 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1855
1856 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1857 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1858 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1859 enc_cfg.enc_blk.frames_per_buf = 1;
1860 enc_cfg.enc_blk.format_id = LINEAR_PCM;
1861 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
1862 enc_cfg.enc_blk.cfg.pcm.ch_cfg = 0;/*channels;*/
1863 enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
1864 enc_cfg.enc_blk.cfg.pcm.sample_rate = 0;/*rate;*/
1865 enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
1866 enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
1867
1868 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1869 if (rc < 0) {
1870 pr_err("Comamnd open failed\n");
1871 rc = -EINVAL;
1872 goto fail_cmd;
1873 }
1874 rc = wait_event_timeout(ac->cmd_wait,
1875 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1876 if (!rc) {
1877 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1878 goto fail_cmd;
1879 }
1880 return 0;
1881fail_cmd:
1882 return -EINVAL;
1883}
1884
Mingming Yin647e9ea2012-03-17 19:56:10 -07001885int q6asm_enc_cfg_blk_multi_ch_pcm(struct audio_client *ac,
1886 uint32_t rate, uint32_t channels)
1887{
1888 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
1889
1890 int rc = 0;
1891
1892 pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
1893 ac->session, rate, channels);
1894
1895 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
1896
1897 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1898 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
1899 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
1900 enc_cfg.enc_blk.frames_per_buf = 1;
1901 enc_cfg.enc_blk.format_id = MULTI_CHANNEL_PCM;
1902 enc_cfg.enc_blk.cfg_size =
1903 sizeof(struct asm_multi_channel_pcm_fmt_blk);
1904 enc_cfg.enc_blk.cfg.mpcm.num_channels = channels;
1905 enc_cfg.enc_blk.cfg.mpcm.bits_per_sample = 16;
1906 enc_cfg.enc_blk.cfg.mpcm.sample_rate = rate;
1907 enc_cfg.enc_blk.cfg.mpcm.is_signed = 1;
1908 enc_cfg.enc_blk.cfg.mpcm.is_interleaved = 1;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07001909 if (channels == 1) {
1910 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1911 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = 0;
1912 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0;
1913 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
1914 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1915 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1916 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1917 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1918 } else if (channels == 2) {
Subhash Chandra Bose Naripeddy8477d222012-06-12 00:30:54 -07001919 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1920 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1921 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0;
1922 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
1923 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1924 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1925 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1926 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1927 } else if (channels == 4) {
1928 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1929 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1930 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_RB;
1931 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_LB;
1932 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
1933 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
1934 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1935 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1936 } else if (channels == 6) {
1937 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1938 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1939 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
1940 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
1941 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
1942 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
1943 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
1944 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
1945 } else if (channels == 8) {
1946 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
1947 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
1948 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
1949 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
1950 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
1951 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
1952 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = PCM_CHANNEL_FLC;
1953 enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = PCM_CHANNEL_FRC;
1954 }
Mingming Yin647e9ea2012-03-17 19:56:10 -07001955
1956 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
1957 if (rc < 0) {
1958 pr_err("Comamnd open failed\n");
1959 rc = -EINVAL;
1960 goto fail_cmd;
1961 }
1962 rc = wait_event_timeout(ac->cmd_wait,
1963 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1964 if (!rc) {
1965 pr_err("timeout opcode[0x%x] ", enc_cfg.hdr.opcode);
1966 goto fail_cmd;
1967 }
1968 return 0;
1969fail_cmd:
1970 return -EINVAL;
1971}
1972
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001973int q6asm_enable_sbrps(struct audio_client *ac,
1974 uint32_t sbr_ps_enable)
1975{
1976 struct asm_stream_cmd_encdec_sbr sbrps;
1977
1978 int rc = 0;
1979
1980 pr_debug("%s: Session %d\n", __func__, ac->session);
1981
1982 q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
1983
1984 sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
1985 sbrps.param_id = ASM_ENABLE_SBR_PS;
1986 sbrps.param_size = sizeof(struct asm_sbr_ps);
1987 sbrps.sbr_ps.enable = sbr_ps_enable;
1988
1989 rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
1990 if (rc < 0) {
1991 pr_err("Command opcode[0x%x]paramid[0x%x] failed\n",
1992 ASM_STREAM_CMD_SET_ENCDEC_PARAM,
1993 ASM_ENABLE_SBR_PS);
1994 rc = -EINVAL;
1995 goto fail_cmd;
1996 }
1997 rc = wait_event_timeout(ac->cmd_wait,
1998 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
1999 if (!rc) {
2000 pr_err("timeout opcode[0x%x] ", sbrps.hdr.opcode);
2001 goto fail_cmd;
2002 }
2003 return 0;
2004fail_cmd:
2005 return -EINVAL;
2006}
2007
Swaminathan Sathappan70765cd2011-07-19 18:42:47 -07002008int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
2009 uint16_t sce_left, uint16_t sce_right)
2010{
2011 struct asm_stream_cmd_encdec_dualmono dual_mono;
2012
2013 int rc = 0;
2014
2015 pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
2016 __func__, ac->session, sce_left, sce_right);
2017
2018 q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
2019
2020 dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2021 dual_mono.param_id = ASM_CONFIGURE_DUAL_MONO;
2022 dual_mono.param_size = sizeof(struct asm_dual_mono);
2023 dual_mono.channel_map.sce_left = sce_left;
2024 dual_mono.channel_map.sce_right = sce_right;
2025
2026 rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
2027 if (rc < 0) {
2028 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2029 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2030 ASM_CONFIGURE_DUAL_MONO);
2031 rc = -EINVAL;
2032 goto fail_cmd;
2033 }
2034 rc = wait_event_timeout(ac->cmd_wait,
2035 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2036 if (!rc) {
2037 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2038 dual_mono.hdr.opcode);
2039 goto fail_cmd;
2040 }
2041 return 0;
2042fail_cmd:
2043 return -EINVAL;
2044}
2045
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002046int q6asm_set_encdec_chan_map(struct audio_client *ac,
2047 uint32_t num_channels)
2048{
2049 struct asm_stream_cmd_encdec_channelmap chan_map;
2050 u8 *channel_mapping;
2051
2052 int rc = 0;
2053
2054 pr_debug("%s: Session %d, num_channels = %d\n",
2055 __func__, ac->session, num_channels);
2056
2057 q6asm_add_hdr(ac, &chan_map.hdr, sizeof(chan_map), TRUE);
2058
2059 chan_map.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2060 chan_map.param_id = ASM_ENCDEC_DEC_CHAN_MAP;
2061 chan_map.param_size = sizeof(struct asm_dec_chan_map);
2062 chan_map.chan_map.num_channels = num_channels;
2063
2064 channel_mapping =
2065 chan_map.chan_map.channel_mapping;
2066
2067 memset(channel_mapping, PCM_CHANNEL_NULL, MAX_CHAN_MAP_CHANNELS);
2068 if (num_channels == 1) {
2069 channel_mapping[0] = PCM_CHANNEL_FL;
2070 } else if (num_channels == 2) {
2071 channel_mapping[0] = PCM_CHANNEL_FL;
2072 channel_mapping[1] = PCM_CHANNEL_FR;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002073 } else if (num_channels == 4) {
2074 channel_mapping[0] = PCM_CHANNEL_FL;
2075 channel_mapping[1] = PCM_CHANNEL_FR;
2076 channel_mapping[1] = PCM_CHANNEL_LB;
2077 channel_mapping[1] = PCM_CHANNEL_RB;
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002078 } else if (num_channels == 6) {
2079 channel_mapping[0] = PCM_CHANNEL_FC;
2080 channel_mapping[1] = PCM_CHANNEL_FL;
2081 channel_mapping[2] = PCM_CHANNEL_FR;
2082 channel_mapping[3] = PCM_CHANNEL_LB;
2083 channel_mapping[4] = PCM_CHANNEL_RB;
2084 channel_mapping[5] = PCM_CHANNEL_LFE;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002085 } else if (num_channels == 8) {
2086 channel_mapping[0] = PCM_CHANNEL_FC;
2087 channel_mapping[1] = PCM_CHANNEL_FL;
2088 channel_mapping[2] = PCM_CHANNEL_FR;
2089 channel_mapping[3] = PCM_CHANNEL_LB;
2090 channel_mapping[4] = PCM_CHANNEL_RB;
2091 channel_mapping[5] = PCM_CHANNEL_LFE;
2092 channel_mapping[6] = PCM_CHANNEL_FLC;
2093 channel_mapping[7] = PCM_CHANNEL_FRC;
Swaminathan Sathappan6f530882012-05-01 16:42:22 -07002094 } else {
2095 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2096 num_channels);
2097 rc = -EINVAL;
2098 goto fail_cmd;
2099 }
2100
2101 rc = apr_send_pkt(ac->apr, (uint32_t *) &chan_map);
2102 if (rc < 0) {
2103 pr_err("%s:Command opcode[0x%x]paramid[0x%x] failed\n",
2104 __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
2105 ASM_ENCDEC_DEC_CHAN_MAP);
2106 goto fail_cmd;
2107 }
2108 rc = wait_event_timeout(ac->cmd_wait,
2109 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2110 if (!rc) {
2111 pr_err("%s:timeout opcode[0x%x]\n", __func__,
2112 chan_map.hdr.opcode);
2113 rc = -ETIMEDOUT;
2114 goto fail_cmd;
2115 }
2116 return 0;
2117fail_cmd:
2118 return rc;
2119}
2120
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002121int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
2122 uint16_t min_rate, uint16_t max_rate,
2123 uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
2124{
2125 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2126 int rc = 0;
2127
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002128 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]",
2129 __func__,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002130 ac->session, frames_per_buf, min_rate, max_rate,
2131 reduced_rate_level, rate_modulation_cmd);
2132
2133 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2134
2135 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2136
2137 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2138 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2139
2140 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2141 enc_cfg.enc_blk.format_id = V13K_FS;
2142 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg);
2143 enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate;
2144 enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate;
2145 enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level;
2146 enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_cmd = rate_modulation_cmd;
2147
2148 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2149 if (rc < 0) {
2150 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2151 goto fail_cmd;
2152 }
2153 rc = wait_event_timeout(ac->cmd_wait,
2154 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2155 if (!rc) {
2156 pr_err("timeout. waited for FORMAT_UPDATE\n");
2157 goto fail_cmd;
2158 }
2159 return 0;
2160fail_cmd:
2161 return -EINVAL;
2162}
2163
2164int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
2165 uint16_t min_rate, uint16_t max_rate,
2166 uint16_t rate_modulation_cmd)
2167{
2168 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2169 int rc = 0;
2170
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002171 pr_debug("%s:session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] rate_modulation_cmd[0x%4x]",
2172 __func__, ac->session,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002173 frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
2174
2175 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2176
2177 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2178
2179 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2180 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2181
2182 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2183 enc_cfg.enc_blk.format_id = EVRC_FS;
2184 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg);
2185 enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate;
2186 enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate;
2187 enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd;
2188 enc_cfg.enc_blk.cfg.evrc.reserved = 0;
2189
2190 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2191 if (rc < 0) {
2192 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2193 goto fail_cmd;
2194 }
2195 rc = wait_event_timeout(ac->cmd_wait,
2196 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2197 if (!rc) {
2198 pr_err("timeout. waited for FORMAT_UPDATE\n");
2199 goto fail_cmd;
2200 }
2201 return 0;
2202fail_cmd:
2203 return -EINVAL;
2204}
2205
2206int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
2207 uint16_t band_mode, uint16_t dtx_enable)
2208{
2209 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2210 int rc = 0;
2211
2212 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2213 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2214
2215 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2216
2217 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2218
2219 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2220 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2221
2222 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2223 enc_cfg.enc_blk.format_id = AMRNB_FS;
2224 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg);
2225 enc_cfg.enc_blk.cfg.amrnb.mode = band_mode;
2226 enc_cfg.enc_blk.cfg.amrnb.dtx_mode = dtx_enable;
2227
2228 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2229 if (rc < 0) {
2230 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
2231 goto fail_cmd;
2232 }
2233 rc = wait_event_timeout(ac->cmd_wait,
2234 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2235 if (!rc) {
2236 pr_err("timeout. waited for FORMAT_UPDATE\n");
2237 goto fail_cmd;
2238 }
2239 return 0;
2240fail_cmd:
2241 return -EINVAL;
2242}
2243
Alex Wong2caeecc2011-10-28 10:52:15 +05302244int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
2245 uint16_t band_mode, uint16_t dtx_enable)
2246{
2247 struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
2248 int rc = 0;
2249
2250 pr_debug("%s:session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]",
2251 __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
2252
2253 q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
2254
2255 enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
2256
2257 enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
2258 enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
2259
2260 enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
2261 enc_cfg.enc_blk.format_id = AMRWB_FS;
2262 enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrwb_read_cfg);
2263 enc_cfg.enc_blk.cfg.amrwb.mode = band_mode;
2264 enc_cfg.enc_blk.cfg.amrwb.dtx_mode = dtx_enable;
2265
2266 rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
2267 if (rc < 0) {
2268 pr_err("Comamnd %d failed\n", ASM_STREAM_CMD_SET_ENCDEC_PARAM);
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("timeout. waited for FORMAT_UPDATE\n");
2275 goto fail_cmd;
2276 }
2277 return 0;
2278fail_cmd:
2279 return -EINVAL;
2280}
2281
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002282int q6asm_media_format_block_pcm(struct audio_client *ac,
2283 uint32_t rate, uint32_t channels)
2284{
2285 struct asm_stream_media_format_update fmt;
2286 int rc = 0;
2287
2288 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2289 channels);
2290
2291 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2292
2293 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2294
2295 fmt.format = LINEAR_PCM;
2296 fmt.cfg_size = sizeof(struct asm_pcm_cfg);
2297 fmt.write_cfg.pcm_cfg.ch_cfg = channels;
2298 fmt.write_cfg.pcm_cfg.bits_per_sample = 16;
2299 fmt.write_cfg.pcm_cfg.sample_rate = rate;
2300 fmt.write_cfg.pcm_cfg.is_signed = 1;
2301 fmt.write_cfg.pcm_cfg.interleaved = 1;
2302
2303 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2304 if (rc < 0) {
2305 pr_err("%s:Comamnd open failed\n", __func__);
2306 goto fail_cmd;
2307 }
2308 rc = wait_event_timeout(ac->cmd_wait,
2309 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2310 if (!rc) {
2311 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2312 goto fail_cmd;
2313 }
2314 return 0;
2315fail_cmd:
2316 return -EINVAL;
2317}
2318
Kiran Kandi5e809b02012-01-31 00:24:33 -08002319int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
2320 uint32_t rate, uint32_t channels)
2321{
2322 struct asm_stream_media_format_update fmt;
2323 u8 *channel_mapping;
2324 int rc = 0;
2325
2326 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
2327 channels);
2328
2329 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2330
2331 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2332
2333 fmt.format = MULTI_CHANNEL_PCM;
2334 fmt.cfg_size = sizeof(struct asm_multi_channel_pcm_fmt_blk);
2335 fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels;
2336 fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = 16;
2337 fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate;
2338 fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1;
2339 fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1;
2340 channel_mapping =
2341 fmt.write_cfg.multi_ch_pcm_cfg.channel_mapping;
2342
2343 memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
2344
2345 if (channels == 1) {
2346 channel_mapping[0] = PCM_CHANNEL_FL;
2347 } else if (channels == 2) {
2348 channel_mapping[0] = PCM_CHANNEL_FL;
2349 channel_mapping[1] = PCM_CHANNEL_FR;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002350 } else if (channels == 4) {
2351 channel_mapping[0] = PCM_CHANNEL_FL;
2352 channel_mapping[1] = PCM_CHANNEL_FR;
2353 channel_mapping[1] = PCM_CHANNEL_LB;
2354 channel_mapping[1] = PCM_CHANNEL_RB;
Kiran Kandi5e809b02012-01-31 00:24:33 -08002355 } else if (channels == 6) {
SathishKumar Mani6074b772012-09-26 13:49:49 -07002356 channel_mapping[0] = PCM_CHANNEL_FL;
2357 channel_mapping[1] = PCM_CHANNEL_FR;
2358 channel_mapping[2] = PCM_CHANNEL_FC;
2359 channel_mapping[3] = PCM_CHANNEL_LFE;
2360 channel_mapping[4] = PCM_CHANNEL_LB;
2361 channel_mapping[5] = PCM_CHANNEL_RB;
Subhash Chandra Bose Naripeddy68d103a2012-08-17 21:03:19 -07002362 } else if (channels == 8) {
2363 channel_mapping[0] = PCM_CHANNEL_FC;
2364 channel_mapping[1] = PCM_CHANNEL_FL;
2365 channel_mapping[2] = PCM_CHANNEL_FR;
2366 channel_mapping[3] = PCM_CHANNEL_LB;
2367 channel_mapping[4] = PCM_CHANNEL_RB;
2368 channel_mapping[5] = PCM_CHANNEL_LFE;
2369 channel_mapping[6] = PCM_CHANNEL_FLC;
2370 channel_mapping[7] = PCM_CHANNEL_FRC;
Kiran Kandi5e809b02012-01-31 00:24:33 -08002371 } else {
2372 pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
2373 channels);
2374 return -EINVAL;
2375 }
2376
2377 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2378 if (rc < 0) {
2379 pr_err("%s:Comamnd open failed\n", __func__);
2380 goto fail_cmd;
2381 }
2382 rc = wait_event_timeout(ac->cmd_wait,
2383 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2384 if (!rc) {
2385 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2386 goto fail_cmd;
2387 }
2388 return 0;
2389fail_cmd:
2390 return -EINVAL;
2391}
2392
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002393int q6asm_media_format_block_aac(struct audio_client *ac,
2394 struct asm_aac_cfg *cfg)
2395{
2396 struct asm_stream_media_format_update fmt;
2397 int rc = 0;
2398
2399 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2400 cfg->sample_rate, cfg->ch_cfg);
2401
2402 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2403
2404 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2405
2406 fmt.format = MPEG4_AAC;
2407 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2408 fmt.write_cfg.aac_cfg.format = cfg->format;
2409 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2410 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2411 fmt.write_cfg.aac_cfg.section_data_resilience =
2412 cfg->section_data_resilience;
2413 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2414 cfg->scalefactor_data_resilience;
2415 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2416 cfg->spectral_data_resilience;
2417 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2418 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2419 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2420 __func__, fmt.format, fmt.cfg_size,
2421 fmt.write_cfg.aac_cfg.format,
2422 fmt.write_cfg.aac_cfg.aot,
2423 fmt.write_cfg.aac_cfg.ch_cfg,
2424 fmt.write_cfg.aac_cfg.sample_rate);
2425 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2426 if (rc < 0) {
2427 pr_err("%s:Comamnd open failed\n", __func__);
2428 goto fail_cmd;
2429 }
2430 rc = wait_event_timeout(ac->cmd_wait,
2431 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2432 if (!rc) {
2433 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2434 goto fail_cmd;
2435 }
2436 return 0;
2437fail_cmd:
2438 return -EINVAL;
2439}
2440
Ajit Khare43fd8832012-08-07 13:19:44 -07002441int q6asm_media_format_block_amrwbplus(struct audio_client *ac,
2442 struct asm_amrwbplus_cfg *cfg)
2443{
2444 struct asm_stream_media_format_update fmt;
2445 int rc = 0;
2446 pr_debug("q6asm_media_format_block_amrwbplus");
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002447
Ajit Khare43fd8832012-08-07 13:19:44 -07002448 pr_debug("%s:session[%d]band-mode[%d]frame-fmt[%d]ch[%d]\n",
2449 __func__,
2450 ac->session,
2451 cfg->amr_band_mode,
2452 cfg->amr_frame_fmt,
2453 cfg->num_channels);
2454
2455 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2456
2457 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2458
2459 fmt.format = AMR_WB_PLUS;
2460 fmt.cfg_size = cfg->size_bytes;
2461
2462 fmt.write_cfg.amrwbplus_cfg.size_bytes = cfg->size_bytes;
2463 fmt.write_cfg.amrwbplus_cfg.version = cfg->version;
2464 fmt.write_cfg.amrwbplus_cfg.num_channels = cfg->num_channels;
2465 fmt.write_cfg.amrwbplus_cfg.amr_band_mode = cfg->amr_band_mode;
2466 fmt.write_cfg.amrwbplus_cfg.amr_dtx_mode = cfg->amr_dtx_mode;
2467 fmt.write_cfg.amrwbplus_cfg.amr_frame_fmt = cfg->amr_frame_fmt;
2468 fmt.write_cfg.amrwbplus_cfg.amr_lsf_idx = cfg->amr_lsf_idx;
2469
2470 pr_debug("%s: num_channels=%x amr_band_mode=%d amr_frame_fmt=%d\n",
2471 __func__,
2472 cfg->num_channels,
2473 cfg->amr_band_mode,
2474 cfg->amr_frame_fmt);
2475
2476 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2477 if (rc < 0) {
2478 pr_err("%s:Comamnd media format update 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}
Bharath Ramachandramurthy4f71d502011-10-23 19:45:22 -07002491int q6asm_media_format_block_multi_aac(struct audio_client *ac,
2492 struct asm_aac_cfg *cfg)
2493{
2494 struct asm_stream_media_format_update fmt;
2495 int rc = 0;
2496
2497 pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
2498 cfg->sample_rate, cfg->ch_cfg);
2499
2500 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2501
2502 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2503
2504 fmt.format = MPEG4_MULTI_AAC;
2505 fmt.cfg_size = sizeof(struct asm_aac_cfg);
2506 fmt.write_cfg.aac_cfg.format = cfg->format;
2507 fmt.write_cfg.aac_cfg.aot = cfg->aot;
2508 fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
2509 fmt.write_cfg.aac_cfg.section_data_resilience =
2510 cfg->section_data_resilience;
2511 fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
2512 cfg->scalefactor_data_resilience;
2513 fmt.write_cfg.aac_cfg.spectral_data_resilience =
2514 cfg->spectral_data_resilience;
2515 fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
2516 fmt.write_cfg.aac_cfg.sample_rate = cfg->sample_rate;
2517 pr_info("%s:format=%x cfg_size=%d aac-cfg=%x aot=%d ch=%d sr=%d\n",
2518 __func__, fmt.format, fmt.cfg_size,
2519 fmt.write_cfg.aac_cfg.format,
2520 fmt.write_cfg.aac_cfg.aot,
2521 fmt.write_cfg.aac_cfg.ch_cfg,
2522 fmt.write_cfg.aac_cfg.sample_rate);
2523 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2524 if (rc < 0) {
2525 pr_err("%s:Comamnd open failed\n", __func__);
2526 goto fail_cmd;
2527 }
2528 rc = wait_event_timeout(ac->cmd_wait,
2529 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2530 if (!rc) {
2531 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2532 goto fail_cmd;
2533 }
2534 return 0;
2535fail_cmd:
2536 return -EINVAL;
2537}
2538
2539
Alex Wong2caeecc2011-10-28 10:52:15 +05302540
2541int q6asm_media_format_block(struct audio_client *ac, uint32_t format)
2542{
2543
2544 struct asm_stream_media_format_update fmt;
2545 int rc = 0;
2546
2547 pr_debug("%s:session[%d] format[0x%x]\n", __func__,
2548 ac->session, format);
2549
2550 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2551 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302552 switch (format) {
2553 case FORMAT_V13K:
2554 fmt.format = V13K_FS;
2555 break;
2556 case FORMAT_EVRC:
2557 fmt.format = EVRC_FS;
2558 break;
2559 case FORMAT_AMRWB:
2560 fmt.format = AMRWB_FS;
2561 break;
Ajit Khare43fd8832012-08-07 13:19:44 -07002562 case FORMAT_AMR_WB_PLUS:
2563 fmt.format = AMR_WB_PLUS;
2564 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302565 case FORMAT_AMRNB:
2566 fmt.format = AMRNB_FS;
2567 break;
2568 case FORMAT_MP3:
2569 fmt.format = MP3;
2570 break;
Srikanth Uyyala66f781a2012-06-13 23:23:25 +05302571 case FORMAT_DTS:
2572 fmt.format = DTS;
2573 break;
2574 case FORMAT_DTS_LBR:
2575 fmt.format = DTS_LBR;
2576 break;
Asish Bhattacharya305d1752011-11-01 20:38:26 +05302577 default:
2578 pr_err("Invalid format[%d]\n", format);
2579 goto fail_cmd;
2580 }
Alex Wong2caeecc2011-10-28 10:52:15 +05302581 fmt.cfg_size = 0;
2582
2583 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2584 if (rc < 0) {
2585 pr_err("%s:Comamnd open failed\n", __func__);
2586 goto fail_cmd;
2587 }
2588 rc = wait_event_timeout(ac->cmd_wait,
2589 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2590 if (!rc) {
2591 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2592 goto fail_cmd;
2593 }
2594 return 0;
2595fail_cmd:
2596 return -EINVAL;
2597}
2598
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002599int q6asm_media_format_block_wma(struct audio_client *ac,
2600 void *cfg)
2601{
2602 struct asm_stream_media_format_update fmt;
2603 struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
2604 int rc = 0;
2605
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002606 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 -07002607 ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
2608 wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
2609 wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
2610 wma_cfg->ch_mask, wma_cfg->encode_opt);
2611
2612 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2613
2614 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2615
2616 fmt.format = WMA_V9;
2617 fmt.cfg_size = sizeof(struct asm_wma_cfg);
2618 fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag;
2619 fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg;
2620 fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate;
2621 fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
2622 fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align;
2623 fmt.write_cfg.wma_cfg.valid_bits_per_sample =
2624 wma_cfg->valid_bits_per_sample;
2625 fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask;
2626 fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt;
2627 fmt.write_cfg.wma_cfg.adv_encode_opt = 0;
2628 fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0;
2629 fmt.write_cfg.wma_cfg.drc_peak_ref = 0;
2630 fmt.write_cfg.wma_cfg.drc_peak_target = 0;
2631 fmt.write_cfg.wma_cfg.drc_ave_ref = 0;
2632 fmt.write_cfg.wma_cfg.drc_ave_target = 0;
2633
2634 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2635 if (rc < 0) {
2636 pr_err("%s:Comamnd open failed\n", __func__);
2637 goto fail_cmd;
2638 }
2639 rc = wait_event_timeout(ac->cmd_wait,
2640 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2641 if (!rc) {
2642 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2643 goto fail_cmd;
2644 }
2645 return 0;
2646fail_cmd:
2647 return -EINVAL;
2648}
2649
2650int q6asm_media_format_block_wmapro(struct audio_client *ac,
2651 void *cfg)
2652{
2653 struct asm_stream_media_format_update fmt;
2654 struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
2655 int rc = 0;
2656
Harmandeep Singheaf59b42012-06-05 21:46:02 -07002657 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 -07002658 ac->session, wmapro_cfg->format_tag, wmapro_cfg->sample_rate,
2659 wmapro_cfg->ch_cfg, wmapro_cfg->avg_bytes_per_sec,
2660 wmapro_cfg->block_align, wmapro_cfg->valid_bits_per_sample,
2661 wmapro_cfg->ch_mask, wmapro_cfg->encode_opt,
2662 wmapro_cfg->adv_encode_opt, wmapro_cfg->adv_encode_opt2);
2663
2664 q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
2665
2666 fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
2667
2668 fmt.format = WMA_V10PRO;
2669 fmt.cfg_size = sizeof(struct asm_wmapro_cfg);
2670 fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag;
2671 fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg;
2672 fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate;
2673 fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec =
2674 wmapro_cfg->avg_bytes_per_sec;
2675 fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align;
2676 fmt.write_cfg.wmapro_cfg.valid_bits_per_sample =
2677 wmapro_cfg->valid_bits_per_sample;
2678 fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask;
2679 fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt;
2680 fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt;
2681 fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2;
2682 fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0;
2683 fmt.write_cfg.wmapro_cfg.drc_peak_target = 0;
2684 fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0;
2685 fmt.write_cfg.wmapro_cfg.drc_ave_target = 0;
2686
2687 rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
2688 if (rc < 0) {
2689 pr_err("%s:Comamnd open failed\n", __func__);
2690 goto fail_cmd;
2691 }
2692 rc = wait_event_timeout(ac->cmd_wait,
2693 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2694 if (!rc) {
2695 pr_err("%s:timeout. waited for FORMAT_UPDATE\n", __func__);
2696 goto fail_cmd;
2697 }
2698 return 0;
2699fail_cmd:
2700 return -EINVAL;
2701}
2702
2703int q6asm_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
2704 uint32_t bufsz, uint32_t bufcnt)
2705{
2706 struct asm_stream_cmd_memory_map mem_map;
2707 int rc = 0;
2708
2709 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2710 pr_err("APR handle NULL\n");
2711 return -EINVAL;
2712 }
2713
2714 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2715
2716 mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP;
2717
2718 mem_map.buf_add = buf_add;
2719 mem_map.buf_size = bufsz * bufcnt;
2720 mem_map.mempool_id = 0; /* EBI */
2721 mem_map.reserved = 0;
2722
2723 q6asm_add_mmaphdr(&mem_map.hdr,
2724 sizeof(struct asm_stream_cmd_memory_map), TRUE);
2725
2726 pr_debug("buf add[%x] buf_add_parameter[%x]\n",
2727 mem_map.buf_add, buf_add);
2728
2729 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map);
2730 if (rc < 0) {
2731 pr_err("mem_map op[0x%x]rc[%d]\n",
2732 mem_map.hdr.opcode, rc);
2733 rc = -EINVAL;
2734 goto fail_cmd;
2735 }
2736
2737 rc = wait_event_timeout(this_mmap.cmd_wait,
2738 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2739 if (!rc) {
2740 pr_err("timeout. waited for memory_map\n");
2741 rc = -EINVAL;
2742 goto fail_cmd;
2743 }
2744 rc = 0;
2745fail_cmd:
2746 return rc;
2747}
2748
2749int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
2750{
2751 struct asm_stream_cmd_memory_unmap mem_unmap;
2752 int rc = 0;
2753
2754 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2755 pr_err("APR handle NULL\n");
2756 return -EINVAL;
2757 }
2758 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2759
2760 q6asm_add_mmaphdr(&mem_unmap.hdr,
2761 sizeof(struct asm_stream_cmd_memory_unmap), TRUE);
2762 mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP;
2763 mem_unmap.buf_add = buf_add;
2764
2765 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_unmap);
2766 if (rc < 0) {
2767 pr_err("mem_unmap op[0x%x]rc[%d]\n",
2768 mem_unmap.hdr.opcode, rc);
2769 rc = -EINVAL;
2770 goto fail_cmd;
2771 }
2772
2773 rc = wait_event_timeout(this_mmap.cmd_wait,
2774 (atomic_read(&this_mmap.cmd_state) == 0), 5 * HZ);
2775 if (!rc) {
2776 pr_err("timeout. waited for memory_map\n");
2777 rc = -EINVAL;
2778 goto fail_cmd;
2779 }
2780 rc = 0;
2781fail_cmd:
2782 return rc;
2783}
2784
2785int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
2786{
2787 void *vol_cmd = NULL;
2788 void *payload = NULL;
2789 struct asm_pp_params_command *cmd = NULL;
2790 struct asm_lrchannel_gain_params *lrgain = NULL;
2791 int sz = 0;
2792 int rc = 0;
2793
2794 sz = sizeof(struct asm_pp_params_command) +
2795 + sizeof(struct asm_lrchannel_gain_params);
2796 vol_cmd = kzalloc(sz, GFP_KERNEL);
2797 if (vol_cmd == NULL) {
2798 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2799 rc = -EINVAL;
2800 return rc;
2801 }
2802 cmd = (struct asm_pp_params_command *)vol_cmd;
2803 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2804 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2805 cmd->payload = NULL;
2806 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2807 sizeof(struct asm_lrchannel_gain_params);
2808 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2809 cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID;
2810 cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params);
2811 cmd->params.reserved = 0;
2812
2813 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
2814 lrgain = (struct asm_lrchannel_gain_params *)payload;
2815
2816 lrgain->left_gain = left_gain;
2817 lrgain->right_gain = right_gain;
2818 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
2819 if (rc < 0) {
2820 pr_err("%s: Volume Command failed\n", __func__);
2821 rc = -EINVAL;
2822 goto fail_cmd;
2823 }
2824
2825 rc = wait_event_timeout(ac->cmd_wait,
2826 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
2827 if (!rc) {
2828 pr_err("%s: timeout in sending volume command to apr\n",
2829 __func__);
2830 rc = -EINVAL;
2831 goto fail_cmd;
2832 }
2833 rc = 0;
2834fail_cmd:
2835 kfree(vol_cmd);
2836 return rc;
2837}
2838
2839static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
2840 uint32_t bufsz, uint32_t bufcnt)
2841{
2842 struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL;
2843 struct asm_memory_map_regions *mregions = NULL;
2844 struct audio_port_data *port = NULL;
2845 struct audio_buffer *ab = NULL;
2846 void *mmap_region_cmd = NULL;
2847 void *payload = NULL;
2848 int rc = 0;
2849 int i = 0;
2850 int cmd_size = 0;
2851
2852 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2853 pr_err("APR handle NULL\n");
2854 return -EINVAL;
2855 }
2856 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2857
2858 cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions)
2859 + sizeof(struct asm_memory_map_regions) * bufcnt;
2860
2861 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302862 if (mmap_region_cmd == NULL) {
2863 pr_err("%s: Mem alloc failed\n", __func__);
2864 rc = -EINVAL;
2865 return rc;
2866 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002867 mmap_regions = (struct asm_stream_cmd_memory_map_regions *)
2868 mmap_region_cmd;
2869 q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE);
2870 mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS;
2871 mmap_regions->mempool_id = 0;
2872 mmap_regions->nregions = bufcnt & 0x00ff;
2873 pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions);
2874 payload = ((u8 *) mmap_region_cmd +
2875 sizeof(struct asm_stream_cmd_memory_map_regions));
2876 mregions = (struct asm_memory_map_regions *)payload;
2877
2878 port = &ac->port[dir];
2879 for (i = 0; i < bufcnt; i++) {
2880 ab = &port->buf[i];
2881 mregions->phys = ab->phys;
2882 mregions->buf_size = ab->size;
2883 ++mregions;
2884 }
2885
2886 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) mmap_region_cmd);
2887 if (rc < 0) {
2888 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2889 mmap_regions->hdr.opcode, rc);
2890 rc = -EINVAL;
2891 goto fail_cmd;
2892 }
2893
2894 rc = wait_event_timeout(this_mmap.cmd_wait,
2895 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2896 if (!rc) {
2897 pr_err("timeout. waited for memory_map\n");
2898 rc = -EINVAL;
2899 goto fail_cmd;
2900 }
2901 rc = 0;
2902fail_cmd:
2903 kfree(mmap_region_cmd);
2904 return rc;
2905}
2906
2907static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
2908 uint32_t bufsz, uint32_t bufcnt)
2909{
2910 struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL;
2911 struct asm_memory_unmap_regions *mregions = NULL;
2912 struct audio_port_data *port = NULL;
2913 struct audio_buffer *ab = NULL;
2914 void *unmap_region_cmd = NULL;
2915 void *payload = NULL;
2916 int rc = 0;
2917 int i = 0;
2918 int cmd_size = 0;
2919
2920 if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
2921 pr_err("APR handle NULL\n");
2922 return -EINVAL;
2923 }
2924 pr_debug("%s: Session[%d]\n", __func__, ac->session);
2925
2926 cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) +
2927 sizeof(struct asm_memory_unmap_regions) * bufcnt;
2928
2929 unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
Vasudeva Rao Thumati86edf6c2011-07-06 16:25:13 +05302930 if (unmap_region_cmd == NULL) {
2931 pr_err("%s: Mem alloc failed\n", __func__);
2932 rc = -EINVAL;
2933 return rc;
2934 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002935 unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *)
2936 unmap_region_cmd;
2937 q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE);
2938 unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS;
2939 unmap_regions->nregions = bufcnt & 0x00ff;
2940 pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions);
2941 payload = ((u8 *) unmap_region_cmd +
2942 sizeof(struct asm_stream_cmd_memory_unmap_regions));
2943 mregions = (struct asm_memory_unmap_regions *)payload;
2944 port = &ac->port[dir];
2945 for (i = 0; i < bufcnt; i++) {
2946 ab = &port->buf[i];
2947 mregions->phys = ab->phys;
2948 ++mregions;
2949 }
2950
2951 rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd);
2952 if (rc < 0) {
2953 pr_err("mmap_regions op[0x%x]rc[%d]\n",
2954 unmap_regions->hdr.opcode, rc);
2955 goto fail_cmd;
2956 }
2957
2958 rc = wait_event_timeout(this_mmap.cmd_wait,
2959 (atomic_read(&this_mmap.cmd_state) == 0), 5*HZ);
2960 if (!rc) {
2961 pr_err("timeout. waited for memory_unmap\n");
2962 goto fail_cmd;
2963 }
2964 rc = 0;
2965
2966fail_cmd:
2967 kfree(unmap_region_cmd);
2968 return rc;
2969}
2970
2971int q6asm_set_mute(struct audio_client *ac, int muteflag)
2972{
2973 void *vol_cmd = NULL;
2974 void *payload = NULL;
2975 struct asm_pp_params_command *cmd = NULL;
2976 struct asm_mute_params *mute = NULL;
2977 int sz = 0;
2978 int rc = 0;
2979
2980 sz = sizeof(struct asm_pp_params_command) +
2981 + sizeof(struct asm_mute_params);
2982 vol_cmd = kzalloc(sz, GFP_KERNEL);
2983 if (vol_cmd == NULL) {
2984 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
2985 rc = -EINVAL;
2986 return rc;
2987 }
2988 cmd = (struct asm_pp_params_command *)vol_cmd;
2989 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
2990 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
2991 cmd->payload = NULL;
2992 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
2993 sizeof(struct asm_mute_params);
2994 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
2995 cmd->params.param_id = MUTE_CONFIG_PARAM_ID;
2996 cmd->params.param_size = sizeof(struct asm_mute_params);
2997 cmd->params.reserved = 0;
2998
2999 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3000 mute = (struct asm_mute_params *)payload;
3001
3002 mute->muteflag = muteflag;
3003 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3004 if (rc < 0) {
3005 pr_err("%s: Mute Command failed\n", __func__);
3006 rc = -EINVAL;
3007 goto fail_cmd;
3008 }
3009
3010 rc = wait_event_timeout(ac->cmd_wait,
3011 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3012 if (!rc) {
3013 pr_err("%s: timeout in sending mute command to apr\n",
3014 __func__);
3015 rc = -EINVAL;
3016 goto fail_cmd;
3017 }
3018 rc = 0;
3019fail_cmd:
3020 kfree(vol_cmd);
3021 return rc;
3022}
3023
3024int q6asm_set_volume(struct audio_client *ac, int volume)
3025{
3026 void *vol_cmd = NULL;
3027 void *payload = NULL;
3028 struct asm_pp_params_command *cmd = NULL;
3029 struct asm_master_gain_params *mgain = NULL;
3030 int sz = 0;
3031 int rc = 0;
3032
3033 sz = sizeof(struct asm_pp_params_command) +
3034 + sizeof(struct asm_master_gain_params);
3035 vol_cmd = kzalloc(sz, GFP_KERNEL);
3036 if (vol_cmd == NULL) {
3037 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3038 rc = -EINVAL;
3039 return rc;
3040 }
3041 cmd = (struct asm_pp_params_command *)vol_cmd;
3042 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3043 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3044 cmd->payload = NULL;
3045 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3046 sizeof(struct asm_master_gain_params);
3047 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3048 cmd->params.param_id = MASTER_GAIN_PARAM_ID;
3049 cmd->params.param_size = sizeof(struct asm_master_gain_params);
3050 cmd->params.reserved = 0;
3051
3052 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3053 mgain = (struct asm_master_gain_params *)payload;
3054
3055 mgain->master_gain = volume;
3056 mgain->padding = 0x00;
3057 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3058 if (rc < 0) {
3059 pr_err("%s: Volume Command failed\n", __func__);
3060 rc = -EINVAL;
3061 goto fail_cmd;
3062 }
3063
3064 rc = wait_event_timeout(ac->cmd_wait,
3065 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3066 if (!rc) {
3067 pr_err("%s: timeout in sending volume command to apr\n",
3068 __func__);
3069 rc = -EINVAL;
3070 goto fail_cmd;
3071 }
3072 rc = 0;
3073fail_cmd:
3074 kfree(vol_cmd);
3075 return rc;
3076}
3077
3078int q6asm_set_softpause(struct audio_client *ac,
3079 struct asm_softpause_params *pause_param)
3080{
3081 void *vol_cmd = NULL;
3082 void *payload = NULL;
3083 struct asm_pp_params_command *cmd = NULL;
3084 struct asm_softpause_params *params = NULL;
3085 int sz = 0;
3086 int rc = 0;
3087
3088 sz = sizeof(struct asm_pp_params_command) +
3089 + sizeof(struct asm_softpause_params);
3090 vol_cmd = kzalloc(sz, GFP_KERNEL);
3091 if (vol_cmd == NULL) {
3092 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3093 rc = -EINVAL;
3094 return rc;
3095 }
3096 cmd = (struct asm_pp_params_command *)vol_cmd;
3097 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3098 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3099 cmd->payload = NULL;
3100 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3101 sizeof(struct asm_softpause_params);
3102 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3103 cmd->params.param_id = SOFT_PAUSE_PARAM_ID;
3104 cmd->params.param_size = sizeof(struct asm_softpause_params);
3105 cmd->params.reserved = 0;
3106
3107 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3108 params = (struct asm_softpause_params *)payload;
3109
3110 params->enable = pause_param->enable;
3111 params->period = pause_param->period;
3112 params->step = pause_param->step;
3113 params->rampingcurve = pause_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003114 pr_debug("%s: soft Pause Command: enable = %d, period = %d, step = %d, curve = %d\n",
3115 __func__, params->enable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003116 params->period, params->step, params->rampingcurve);
3117 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3118 if (rc < 0) {
3119 pr_err("%s: Volume Command(soft_pause) failed\n", __func__);
3120 rc = -EINVAL;
3121 goto fail_cmd;
3122 }
3123
3124 rc = wait_event_timeout(ac->cmd_wait,
3125 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3126 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003127 pr_err("%s: timeout in sending volume command(soft_pause) to apr\n",
3128 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003129 rc = -EINVAL;
3130 goto fail_cmd;
3131 }
3132 rc = 0;
3133fail_cmd:
3134 kfree(vol_cmd);
3135 return rc;
3136}
3137
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003138int q6asm_set_softvolume(struct audio_client *ac,
3139 struct asm_softvolume_params *softvol_param)
3140{
3141 void *vol_cmd = NULL;
3142 void *payload = NULL;
3143 struct asm_pp_params_command *cmd = NULL;
3144 struct asm_softvolume_params *params = NULL;
3145 int sz = 0;
3146 int rc = 0;
3147
3148 sz = sizeof(struct asm_pp_params_command) +
3149 + sizeof(struct asm_softvolume_params);
3150 vol_cmd = kzalloc(sz, GFP_KERNEL);
3151 if (vol_cmd == NULL) {
3152 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3153 rc = -EINVAL;
3154 return rc;
3155 }
3156 cmd = (struct asm_pp_params_command *)vol_cmd;
3157 q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
3158 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3159 cmd->payload = NULL;
3160 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3161 sizeof(struct asm_softvolume_params);
3162 cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
3163 cmd->params.param_id = SOFT_VOLUME_PARAM_ID;
3164 cmd->params.param_size = sizeof(struct asm_softvolume_params);
3165 cmd->params.reserved = 0;
3166
3167 payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
3168 params = (struct asm_softvolume_params *)payload;
3169
3170 params->period = softvol_param->period;
3171 params->step = softvol_param->step;
3172 params->rampingcurve = softvol_param->rampingcurve;
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003173 pr_debug("%s: soft Volume:opcode = %d,payload_sz =%d,module_id =%d, param_id = %d, param_sz = %d\n",
3174 __func__,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003175 cmd->hdr.opcode, cmd->payload_size,
3176 cmd->params.module_id, cmd->params.param_id,
3177 cmd->params.param_size);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003178 pr_debug("%s: soft Volume Command: period = %d, step = %d, curve = %d\n",
3179 __func__, params->period,
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003180 params->step, params->rampingcurve);
3181 rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
3182 if (rc < 0) {
3183 pr_err("%s: Volume Command(soft_volume) failed\n", __func__);
3184 rc = -EINVAL;
3185 goto fail_cmd;
3186 }
3187
3188 rc = wait_event_timeout(ac->cmd_wait,
3189 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3190 if (!rc) {
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003191 pr_err("%s: timeout in sending volume command(soft_volume) to apr\n",
3192 __func__);
Swaminathan Sathappanb0021cd2011-08-31 15:20:12 -07003193 rc = -EINVAL;
3194 goto fail_cmd;
3195 }
3196 rc = 0;
3197fail_cmd:
3198 kfree(vol_cmd);
3199 return rc;
3200}
3201
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003202int q6asm_equalizer(struct audio_client *ac, void *eq)
3203{
3204 void *eq_cmd = NULL;
3205 void *payload = NULL;
3206 struct asm_pp_params_command *cmd = NULL;
3207 struct asm_equalizer_params *equalizer = NULL;
3208 struct msm_audio_eq_stream_config *eq_params = NULL;
3209 int i = 0;
3210 int sz = 0;
3211 int rc = 0;
3212
3213 sz = sizeof(struct asm_pp_params_command) +
3214 + sizeof(struct asm_equalizer_params);
3215 eq_cmd = kzalloc(sz, GFP_KERNEL);
3216 if (eq_cmd == NULL) {
3217 pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
3218 rc = -EINVAL;
3219 goto fail_cmd;
3220 }
3221 eq_params = (struct msm_audio_eq_stream_config *) eq;
3222 cmd = (struct asm_pp_params_command *)eq_cmd;
3223 q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE);
3224 cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
3225 cmd->payload = NULL;
3226 cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
3227 sizeof(struct asm_equalizer_params);
3228 cmd->params.module_id = EQUALIZER_MODULE_ID;
3229 cmd->params.param_id = EQUALIZER_PARAM_ID;
3230 cmd->params.param_size = sizeof(struct asm_equalizer_params);
3231 cmd->params.reserved = 0;
3232 payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command));
3233 equalizer = (struct asm_equalizer_params *)payload;
3234
3235 equalizer->enable = eq_params->enable;
3236 equalizer->num_bands = eq_params->num_bands;
3237 pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
3238 eq_params->num_bands);
3239 for (i = 0; i < eq_params->num_bands; i++) {
3240 equalizer->eq_bands[i].band_idx =
3241 eq_params->eq_bands[i].band_idx;
3242 equalizer->eq_bands[i].filter_type =
3243 eq_params->eq_bands[i].filter_type;
3244 equalizer->eq_bands[i].center_freq_hz =
3245 eq_params->eq_bands[i].center_freq_hz;
3246 equalizer->eq_bands[i].filter_gain =
3247 eq_params->eq_bands[i].filter_gain;
3248 equalizer->eq_bands[i].q_factor =
3249 eq_params->eq_bands[i].q_factor;
3250 pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
3251 eq_params->eq_bands[i].filter_type, i);
3252 pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
3253 eq_params->eq_bands[i].center_freq_hz, i);
3254 pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
3255 eq_params->eq_bands[i].filter_gain, i);
3256 pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
3257 eq_params->eq_bands[i].q_factor, i);
3258 }
3259 rc = apr_send_pkt(ac->apr, (uint32_t *) eq_cmd);
3260 if (rc < 0) {
3261 pr_err("%s: Equalizer Command failed\n", __func__);
3262 rc = -EINVAL;
3263 goto fail_cmd;
3264 }
3265
3266 rc = wait_event_timeout(ac->cmd_wait,
3267 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3268 if (!rc) {
3269 pr_err("%s: timeout in sending equalizer command to apr\n",
3270 __func__);
3271 rc = -EINVAL;
3272 goto fail_cmd;
3273 }
3274 rc = 0;
3275fail_cmd:
3276 kfree(eq_cmd);
3277 return rc;
3278}
3279
3280int q6asm_read(struct audio_client *ac)
3281{
3282 struct asm_stream_cmd_read read;
3283 struct audio_buffer *ab;
3284 int dsp_buf;
3285 struct audio_port_data *port;
3286 int rc;
3287 if (!ac || ac->apr == NULL) {
3288 pr_err("APR handle NULL\n");
3289 return -EINVAL;
3290 }
3291 if (ac->io_mode == SYNC_IO_MODE) {
3292 port = &ac->port[OUT];
3293
3294 q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
3295
3296 mutex_lock(&port->lock);
3297
3298 dsp_buf = port->dsp_buf;
3299 ab = &port->buf[dsp_buf];
3300
3301 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3302 __func__,
3303 ac->session,
3304 dsp_buf,
3305 (void *)port->buf[dsp_buf].data,
3306 port->cpu_buf,
3307 (void *)port->buf[port->cpu_buf].phys);
3308
3309 read.hdr.opcode = ASM_DATA_CMD_READ;
3310 read.buf_add = ab->phys;
3311 read.buf_size = ab->size;
3312 read.uid = port->dsp_buf;
3313 read.hdr.token = port->dsp_buf;
3314
3315 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3316 mutex_unlock(&port->lock);
3317 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3318 read.buf_add,
3319 read.hdr.token,
3320 read.uid);
3321 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3322 if (rc < 0) {
3323 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3324 goto fail_cmd;
3325 }
3326 return 0;
3327 }
3328fail_cmd:
3329 return -EINVAL;
3330}
3331
3332int q6asm_read_nolock(struct audio_client *ac)
3333{
3334 struct asm_stream_cmd_read read;
3335 struct audio_buffer *ab;
3336 int dsp_buf;
3337 struct audio_port_data *port;
3338 int rc;
3339 if (!ac || ac->apr == NULL) {
3340 pr_err("APR handle NULL\n");
3341 return -EINVAL;
3342 }
3343 if (ac->io_mode == SYNC_IO_MODE) {
3344 port = &ac->port[OUT];
3345
3346 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3347
3348
3349 dsp_buf = port->dsp_buf;
3350 ab = &port->buf[dsp_buf];
3351
3352 pr_debug("%s:session[%d]dsp-buf[%d][%p]cpu_buf[%d][%p]\n",
3353 __func__,
3354 ac->session,
3355 dsp_buf,
3356 (void *)port->buf[dsp_buf].data,
3357 port->cpu_buf,
3358 (void *)port->buf[port->cpu_buf].phys);
3359
3360 read.hdr.opcode = ASM_DATA_CMD_READ;
3361 read.buf_add = ab->phys;
3362 read.buf_size = ab->size;
3363 read.uid = port->dsp_buf;
3364 read.hdr.token = port->dsp_buf;
3365
3366 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3367 pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
3368 read.buf_add,
3369 read.hdr.token,
3370 read.uid);
3371 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3372 if (rc < 0) {
3373 pr_err("read op[0x%x]rc[%d]\n", read.hdr.opcode, rc);
3374 goto fail_cmd;
3375 }
3376 return 0;
3377 }
3378fail_cmd:
3379 return -EINVAL;
3380}
3381
3382
3383static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
3384 uint32_t pkt_size, uint32_t cmd_flg)
3385{
3386 pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg,
3387 ac->session);
3388 hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, \
3389 APR_HDR_LEN(sizeof(struct apr_hdr)),\
3390 APR_PKT_VER);
3391 hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
3392 hdr->src_domain = APR_DOMAIN_APPS;
3393 hdr->dest_svc = APR_SVC_ASM;
3394 hdr->dest_domain = APR_DOMAIN_ADSP;
3395 hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
3396 hdr->dest_port = ((ac->session << 8) & 0xFF00) | 0x01;
3397 if (cmd_flg) {
3398 hdr->token = ac->session;
3399 atomic_set(&ac->cmd_state, 1);
3400 }
3401 hdr->pkt_size = pkt_size;
3402 return;
3403}
3404
3405int q6asm_async_write(struct audio_client *ac,
3406 struct audio_aio_write_param *param)
3407{
3408 int rc = 0;
3409 struct asm_stream_cmd_write write;
3410
3411 if (!ac || ac->apr == NULL) {
3412 pr_err("%s: APR handle NULL\n", __func__);
3413 return -EINVAL;
3414 }
3415
3416 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE);
3417
3418 /* Pass physical address as token for AIO scheme */
3419 write.hdr.token = param->uid;
3420 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3421 write.buf_add = param->paddr;
3422 write.avail_bytes = param->len;
3423 write.uid = param->uid;
3424 write.msw_ts = param->msw_ts;
3425 write.lsw_ts = param->lsw_ts;
3426 /* Use 0xFF00 for disabling timestamps */
3427 if (param->flags == 0xFF00)
3428 write.uflags = (0x00000000 | (param->flags & 0x800000FF));
3429 else
3430 write.uflags = (0x80000000 | param->flags);
3431
3432 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3433 write.buf_add, write.avail_bytes);
3434
3435 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3436 if (rc < 0) {
3437 pr_debug("[%s] write op[0x%x]rc[%d]\n", __func__,
3438 write.hdr.opcode, rc);
3439 goto fail_cmd;
3440 }
3441 return 0;
3442fail_cmd:
3443 return -EINVAL;
3444}
3445
3446int q6asm_async_read(struct audio_client *ac,
3447 struct audio_aio_read_param *param)
3448{
3449 int rc = 0;
3450 struct asm_stream_cmd_read read;
3451
3452 if (!ac || ac->apr == NULL) {
3453 pr_err("%s: APR handle NULL\n", __func__);
3454 return -EINVAL;
3455 }
3456
3457 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3458
3459 /* Pass physical address as token for AIO scheme */
3460 read.hdr.token = param->paddr;
3461 read.hdr.opcode = ASM_DATA_CMD_READ;
3462 read.buf_add = param->paddr;
3463 read.buf_size = param->len;
3464 read.uid = param->uid;
3465
3466 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3467 read.buf_add, read.buf_size);
3468
3469 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3470 if (rc < 0) {
3471 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3472 read.hdr.opcode, rc);
3473 goto fail_cmd;
3474 }
3475 return 0;
3476fail_cmd:
3477 return -EINVAL;
3478}
3479
Subhash Chandra Bose Naripeddy694b7d92012-06-20 20:46:13 -07003480int q6asm_async_read_compressed(struct audio_client *ac,
3481 struct audio_aio_read_param *param)
3482{
3483 int rc = 0;
3484 struct asm_stream_cmd_read read;
3485
3486 if (!ac || ac->apr == NULL) {
3487 pr_err("%s: APR handle NULL\n", __func__);
3488 return -EINVAL;
3489 }
3490
3491 q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
3492
3493 /* Pass physical address as token for AIO scheme */
3494 read.hdr.token = param->paddr;
3495 read.hdr.opcode = ASM_DATA_CMD_READ_COMPRESSED;
3496 read.buf_add = param->paddr;
3497 read.buf_size = param->len;
3498 read.uid = param->uid;
3499
3500 pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
3501 read.buf_add, read.buf_size);
3502
3503 rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
3504 if (rc < 0) {
3505 pr_debug("[%s] read op[0x%x]rc[%d]\n", __func__,
3506 read.hdr.opcode, rc);
3507 goto fail_cmd;
3508 }
3509 return 0;
3510fail_cmd:
3511 return -EINVAL;
3512}
3513
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003514int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3515 uint32_t lsw_ts, uint32_t flags)
3516{
3517 int rc = 0;
3518 struct asm_stream_cmd_write write;
3519 struct audio_port_data *port;
3520 struct audio_buffer *ab;
3521 int dsp_buf = 0;
3522
3523 if (!ac || ac->apr == NULL) {
3524 pr_err("APR handle NULL\n");
3525 return -EINVAL;
3526 }
3527 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3528 if (ac->io_mode == SYNC_IO_MODE) {
3529 port = &ac->port[IN];
3530
3531 q6asm_add_hdr(ac, &write.hdr, sizeof(write),
3532 FALSE);
3533 mutex_lock(&port->lock);
3534
3535 dsp_buf = port->dsp_buf;
3536 ab = &port->buf[dsp_buf];
3537
3538 write.hdr.token = port->dsp_buf;
3539 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3540 write.buf_add = ab->phys;
3541 write.avail_bytes = len;
3542 write.uid = port->dsp_buf;
3543 write.msw_ts = msw_ts;
3544 write.lsw_ts = lsw_ts;
3545 /* Use 0xFF00 for disabling timestamps */
3546 if (flags == 0xFF00)
3547 write.uflags = (0x00000000 | (flags & 0x800000FF));
3548 else
3549 write.uflags = (0x80000000 | flags);
3550 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3551
3552 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3553 , __func__,
3554 ab->phys,
3555 write.buf_add,
3556 write.hdr.token,
3557 write.uid);
3558 mutex_unlock(&port->lock);
Rajesha Kini3498c932011-07-19 19:58:27 +05303559#ifdef CONFIG_DEBUG_FS
3560 if (out_enable_flag) {
3561 char zero_pattern[2] = {0x00, 0x00};
3562 /* If First two byte is non zero and last two byte
3563 is zero then it is warm output pattern */
3564 if ((strncmp(((char *)ab->data), zero_pattern, 2)) &&
3565 (!strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3566 do_gettimeofday(&out_warm_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003567 pr_debug("WARM:apr_send_pkt at %ld sec %ld microsec\n",
3568 out_warm_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303569 out_warm_tv.tv_usec);
3570 pr_debug("Warm Pattern Matched");
3571 }
3572 /* If First two byte is zero and last two byte is
3573 non zero then it is cont ouput pattern */
3574 else if ((!strncmp(((char *)ab->data), zero_pattern, 2))
3575 && (strncmp(((char *)ab->data + 2), zero_pattern, 2))) {
3576 do_gettimeofday(&out_cont_tv);
Harmandeep Singheaf59b42012-06-05 21:46:02 -07003577 pr_debug("CONT:apr_send_pkt at %ld sec %ld microsec\n",
3578 out_cont_tv.tv_sec,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303579 out_cont_tv.tv_usec);
3580 pr_debug("Cont Pattern Matched");
3581 }
3582 }
3583#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003584 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3585 if (rc < 0) {
3586 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3587 goto fail_cmd;
3588 }
3589 pr_debug("%s: WRITE SUCCESS\n", __func__);
3590 return 0;
3591 }
3592fail_cmd:
3593 return -EINVAL;
3594}
3595
3596int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
3597 uint32_t lsw_ts, uint32_t flags)
3598{
3599 int rc = 0;
3600 struct asm_stream_cmd_write write;
3601 struct audio_port_data *port;
3602 struct audio_buffer *ab;
3603 int dsp_buf = 0;
3604
3605 if (!ac || ac->apr == NULL) {
3606 pr_err("APR handle NULL\n");
3607 return -EINVAL;
3608 }
3609 pr_debug("%s: session[%d] len=%d", __func__, ac->session, len);
3610 if (ac->io_mode == SYNC_IO_MODE) {
3611 port = &ac->port[IN];
3612
3613 q6asm_add_hdr_async(ac, &write.hdr, sizeof(write),
3614 FALSE);
3615
3616 dsp_buf = port->dsp_buf;
3617 ab = &port->buf[dsp_buf];
3618
3619 write.hdr.token = port->dsp_buf;
3620 write.hdr.opcode = ASM_DATA_CMD_WRITE;
3621 write.buf_add = ab->phys;
3622 write.avail_bytes = len;
3623 write.uid = port->dsp_buf;
3624 write.msw_ts = msw_ts;
3625 write.lsw_ts = lsw_ts;
3626 /* Use 0xFF00 for disabling timestamps */
3627 if (flags == 0xFF00)
3628 write.uflags = (0x00000000 | (flags & 0x800000FF));
3629 else
3630 write.uflags = (0x80000000 | flags);
3631 port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
3632
3633 pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x]buf_id[0x%x]"
3634 , __func__,
3635 ab->phys,
3636 write.buf_add,
3637 write.hdr.token,
3638 write.uid);
3639
3640 rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
3641 if (rc < 0) {
3642 pr_err("write op[0x%x]rc[%d]\n", write.hdr.opcode, rc);
3643 goto fail_cmd;
3644 }
3645 pr_debug("%s: WRITE SUCCESS\n", __func__);
3646 return 0;
3647 }
3648fail_cmd:
3649 return -EINVAL;
3650}
3651
3652uint64_t q6asm_get_session_time(struct audio_client *ac)
3653{
3654 struct apr_hdr hdr;
3655 int rc;
3656
3657 if (!ac || ac->apr == NULL) {
3658 pr_err("APR handle NULL\n");
3659 return -EINVAL;
3660 }
Swaminathan Sathappanc7f98992012-07-09 11:07:12 -07003661 q6asm_add_hdr(ac, &hdr, sizeof(hdr), FALSE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003662 hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME;
3663 atomic_set(&ac->time_flag, 1);
3664
3665 pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
3666 ac->session,
3667 hdr.opcode);
3668 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3669 if (rc < 0) {
3670 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3671 goto fail_cmd;
3672 }
3673 rc = wait_event_timeout(ac->time_wait,
3674 (atomic_read(&ac->time_flag) == 0), 5*HZ);
3675 if (!rc) {
3676 pr_err("%s: timeout in getting session time from DSP\n",
3677 __func__);
3678 goto fail_cmd;
3679 }
3680 return ac->time_stamp;
3681
3682fail_cmd:
3683 return -EINVAL;
3684}
3685
3686int q6asm_cmd(struct audio_client *ac, int cmd)
3687{
3688 struct apr_hdr hdr;
3689 int rc;
3690 atomic_t *state;
3691 int cnt = 0;
3692
3693 if (!ac || ac->apr == NULL) {
3694 pr_err("APR handle NULL\n");
3695 return -EINVAL;
3696 }
3697 q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
3698 switch (cmd) {
3699 case CMD_PAUSE:
3700 pr_debug("%s:CMD_PAUSE\n", __func__);
3701 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3702 state = &ac->cmd_state;
3703 break;
3704 case CMD_FLUSH:
3705 pr_debug("%s:CMD_FLUSH\n", __func__);
3706 hdr.opcode = ASM_STREAM_CMD_FLUSH;
3707 state = &ac->cmd_state;
3708 break;
3709 case CMD_OUT_FLUSH:
3710 pr_debug("%s:CMD_OUT_FLUSH\n", __func__);
3711 hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
3712 state = &ac->cmd_state;
3713 break;
3714 case CMD_EOS:
3715 pr_debug("%s:CMD_EOS\n", __func__);
3716 hdr.opcode = ASM_DATA_CMD_EOS;
3717 atomic_set(&ac->cmd_state, 0);
3718 state = &ac->cmd_state;
3719 break;
3720 case CMD_CLOSE:
3721 pr_debug("%s:CMD_CLOSE\n", __func__);
3722 hdr.opcode = ASM_STREAM_CMD_CLOSE;
3723 state = &ac->cmd_state;
3724 break;
3725 default:
3726 pr_err("Invalid format[%d]\n", cmd);
3727 goto fail_cmd;
3728 }
3729 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3730 ac->session,
3731 hdr.opcode);
3732 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3733 if (rc < 0) {
3734 pr_err("Commmand 0x%x failed\n", hdr.opcode);
3735 goto fail_cmd;
3736 }
3737 rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) == 0), 5*HZ);
3738 if (!rc) {
3739 pr_err("timeout. waited for response opcode[0x%x]\n",
3740 hdr.opcode);
3741 goto fail_cmd;
3742 }
3743 if (cmd == CMD_FLUSH)
3744 q6asm_reset_buf_state(ac);
3745 if (cmd == CMD_CLOSE) {
3746 /* check if DSP return all buffers */
3747 if (ac->port[IN].buf) {
3748 for (cnt = 0; cnt < ac->port[IN].max_buf_cnt;
3749 cnt++) {
3750 if (ac->port[IN].buf[cnt].used == IN) {
3751 pr_debug("Write Buf[%d] not returned\n",
3752 cnt);
3753 }
3754 }
3755 }
3756 if (ac->port[OUT].buf) {
3757 for (cnt = 0; cnt < ac->port[OUT].max_buf_cnt; cnt++) {
3758 if (ac->port[OUT].buf[cnt].used == OUT) {
3759 pr_debug("Read Buf[%d] not returned\n",
3760 cnt);
3761 }
3762 }
3763 }
3764 }
3765 return 0;
3766fail_cmd:
3767 return -EINVAL;
3768}
3769
3770int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
3771{
3772 struct apr_hdr hdr;
3773 int rc;
3774
3775 if (!ac || ac->apr == NULL) {
3776 pr_err("%s:APR handle NULL\n", __func__);
3777 return -EINVAL;
3778 }
3779 q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE);
3780 switch (cmd) {
3781 case CMD_PAUSE:
3782 pr_debug("%s:CMD_PAUSE\n", __func__);
3783 hdr.opcode = ASM_SESSION_CMD_PAUSE;
3784 break;
3785 case CMD_EOS:
3786 pr_debug("%s:CMD_EOS\n", __func__);
3787 hdr.opcode = ASM_DATA_CMD_EOS;
3788 break;
3789 default:
3790 pr_err("%s:Invalid format[%d]\n", __func__, cmd);
3791 goto fail_cmd;
3792 }
3793 pr_debug("%s:session[%d]opcode[0x%x] ", __func__,
3794 ac->session,
3795 hdr.opcode);
Jay Wang0668d1062012-07-11 18:53:21 -07003796
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003797 rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
3798 if (rc < 0) {
3799 pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
3800 goto fail_cmd;
3801 }
Jay Wang0668d1062012-07-11 18:53:21 -07003802 atomic_inc(&ac->nowait_cmd_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003803 return 0;
3804fail_cmd:
3805 return -EINVAL;
3806}
3807
3808static void q6asm_reset_buf_state(struct audio_client *ac)
3809{
3810 int cnt = 0;
3811 int loopcnt = 0;
3812 struct audio_port_data *port = NULL;
3813
3814 if (ac->io_mode == SYNC_IO_MODE) {
3815 mutex_lock(&ac->cmd_lock);
3816 for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
3817 port = &ac->port[loopcnt];
3818 cnt = port->max_buf_cnt - 1;
3819 port->dsp_buf = 0;
3820 port->cpu_buf = 0;
3821 while (cnt >= 0) {
3822 if (!port->buf)
3823 continue;
3824 port->buf[cnt].used = 1;
3825 cnt--;
3826 }
3827 }
3828 mutex_unlock(&ac->cmd_lock);
3829 }
3830}
3831
3832int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
3833{
3834 struct asm_stream_cmd_reg_tx_overflow_event tx_overflow;
3835 int rc;
3836
3837 if (!ac || ac->apr == NULL) {
3838 pr_err("APR handle NULL\n");
3839 return -EINVAL;
3840 }
3841 pr_debug("%s:session[%d]enable[%d]\n", __func__,
3842 ac->session, enable);
3843 q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
3844
3845 tx_overflow.hdr.opcode = \
3846 ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS;
3847 /* tx overflow event: enable */
3848 tx_overflow.enable = enable;
3849
3850 rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
3851 if (rc < 0) {
3852 pr_err("tx overflow op[0x%x]rc[%d]\n", \
3853 tx_overflow.hdr.opcode, rc);
3854 goto fail_cmd;
3855 }
3856 rc = wait_event_timeout(ac->cmd_wait,
3857 (atomic_read(&ac->cmd_state) == 0), 5*HZ);
3858 if (!rc) {
3859 pr_err("timeout. waited for tx overflow\n");
3860 goto fail_cmd;
3861 }
3862 return 0;
3863fail_cmd:
3864 return -EINVAL;
3865}
3866
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003867int q6asm_get_apr_service_id(int session_id)
3868{
3869 pr_debug("%s\n", __func__);
3870
Shiv Maliyappanahallia84982a2012-01-19 15:25:04 -08003871 if (session_id < 0 || session_id > SESSION_MAX) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003872 pr_err("%s: invalid session_id = %d\n", __func__, session_id);
3873 return -EINVAL;
3874 }
3875
3876 return ((struct apr_svc *)session[session_id]->apr)->id;
3877}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003878
3879
3880static int __init q6asm_init(void)
3881{
3882 pr_debug("%s\n", __func__);
3883 init_waitqueue_head(&this_mmap.cmd_wait);
3884 memset(session, 0, sizeof(session));
Rajesha Kini3498c932011-07-19 19:58:27 +05303885#ifdef CONFIG_DEBUG_FS
3886 out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
3887 out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
Glenn Kasten5dfda802012-10-04 16:40:27 -07003888 0664,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303889 NULL, NULL, &audio_output_latency_debug_fops);
3890 if (IS_ERR(out_dentry))
3891 pr_err("debugfs_create_file failed\n");
3892 in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
3893 in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
Glenn Kasten5dfda802012-10-04 16:40:27 -07003894 0664,\
Rajesha Kini3498c932011-07-19 19:58:27 +05303895 NULL, NULL, &audio_input_latency_debug_fops);
3896 if (IS_ERR(in_dentry))
3897 pr_err("debugfs_create_file failed\n");
3898#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003899 return 0;
3900}
3901
3902device_initcall(q6asm_init);